Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/usb-2.6

+8610 -3866
+4 -4
arch/arm/mach-omap/usb.c
··· 288 288 static struct resource udc_resources[] = { 289 289 /* order is significant! */ 290 290 { /* registers */ 291 - .start = IO_ADDRESS(UDC_BASE), 292 - .end = IO_ADDRESS(UDC_BASE + 0xff), 291 + .start = UDC_BASE, 292 + .end = UDC_BASE + 0xff, 293 293 .flags = IORESOURCE_MEM, 294 294 }, { /* general IRQ */ 295 295 .start = IH2_BASE + 20, ··· 355 355 static struct resource otg_resources[] = { 356 356 /* order is significant! */ 357 357 { 358 - .start = IO_ADDRESS(OTG_BASE), 359 - .end = IO_ADDRESS(OTG_BASE + 0xff), 358 + .start = OTG_BASE, 359 + .end = OTG_BASE + 0xff, 360 360 .flags = IORESOURCE_MEM, 361 361 }, { 362 362 .start = IH2_BASE + 8,
+1
drivers/usb/Makefile
··· 9 9 obj-$(CONFIG_USB_MON) += mon/ 10 10 11 11 obj-$(CONFIG_USB_EHCI_HCD) += host/ 12 + obj-$(CONFIG_USB_ISP116X_HCD) += host/ 12 13 obj-$(CONFIG_USB_OHCI_HCD) += host/ 13 14 obj-$(CONFIG_USB_UHCI_HCD) += host/ 14 15 obj-$(CONFIG_USB_SL811_HCD) += host/
+40 -10
drivers/usb/atm/Kconfig
··· 1 1 # 2 - # USB ATM driver configuration 2 + # USB/ATM DSL configuration 3 3 # 4 - comment "USB ATM/DSL drivers" 4 + 5 + menu "USB DSL modem support" 5 6 depends on USB 6 7 7 8 config USB_ATM 8 - tristate "Generic USB ATM/DSL core I/O support" 9 + tristate "USB DSL modem support" 9 10 depends on USB && ATM 10 11 select CRC32 11 12 default n 12 13 help 13 - This provides a library which is used for packet I/O by USB DSL 14 - modems, such as the SpeedTouch driver below. 14 + Say Y here if you want to connect a USB Digital Subscriber Line (DSL) 15 + modem to your computer's USB port. You will then need to choose your 16 + modem from the list below. 15 17 16 18 To compile this driver as a module, choose M here: the 17 - module will be called usb_atm. 19 + module will be called usbatm. 18 20 19 21 config USB_SPEEDTOUCH 20 - tristate "Alcatel Speedtouch USB support" 21 - depends on USB && ATM 22 - select USB_ATM 22 + tristate "Speedtouch USB support" 23 + depends on USB_ATM 24 + select FW_LOADER 23 25 help 24 - Say Y here if you have an Alcatel SpeedTouch USB or SpeedTouch 330 26 + Say Y here if you have an SpeedTouch USB or SpeedTouch 330 25 27 modem. In order to use your modem you will need to install the 26 28 two parts of the firmware, extracted by the user space tools; see 27 29 <http://www.linux-usb.org/SpeedTouch/> for details. 28 30 29 31 To compile this driver as a module, choose M here: the 30 32 module will be called speedtch. 33 + 34 + config USB_CXACRU 35 + tristate "Conexant AccessRunner USB support" 36 + depends on USB_ATM 37 + select FW_LOADER 38 + help 39 + Say Y here if you have an ADSL USB modem based on the Conexant 40 + AccessRunner chipset. In order to use your modem you will need to 41 + install the firmware, extracted by the user space tools; see 42 + <http://accessrunner.sourceforge.net/> for details. 43 + 44 + To compile this driver as a module, choose M here: the 45 + module will be called cxacru. 46 + 47 + config USB_XUSBATM 48 + tristate "Other USB DSL modem support" 49 + depends on USB_ATM 50 + help 51 + Say Y here if you have a DSL USB modem not explicitly supported by 52 + another USB DSL drivers. In order to use your modem you will need to 53 + pass the vendor ID, product ID, and endpoint numbers for transmission 54 + and reception as module parameters. You may need to initialize the 55 + the modem using a user space utility (a firmware loader for example). 56 + 57 + To compile this driver as a module, choose M here: the 58 + module will be called xusbatm. 59 + 60 + endmenu
+4 -3
drivers/usb/atm/Makefile
··· 1 1 # 2 - # Makefile for the rest of the USB drivers 3 - # (the ones that don't fit into any other categories) 2 + # Makefile for USB ATM/xDSL drivers 4 3 # 5 4 6 - obj-$(CONFIG_USB_ATM) += usb_atm.o 5 + obj-$(CONFIG_USB_CXACRU) += cxacru.o 7 6 obj-$(CONFIG_USB_SPEEDTOUCH) += speedtch.o 7 + obj-$(CONFIG_USB_ATM) += usbatm.o 8 + obj-$(CONFIG_USB_XUSBATM) += xusbatm.o
+878
drivers/usb/atm/cxacru.c
··· 1 + /****************************************************************************** 2 + * cxacru.c - driver for USB ADSL modems based on 3 + * Conexant AccessRunner chipset 4 + * 5 + * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan 6 + * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru) 7 + * 8 + * 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 10 + * Software Foundation; either version 2 of the License, or (at your option) 11 + * any later version. 12 + * 13 + * This program is distributed in the hope that it will be useful, but WITHOUT 14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 + * more details. 17 + * 18 + * You should have received a copy of the GNU General Public License along with 19 + * this program; if not, write to the Free Software Foundation, Inc., 59 20 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 + * 22 + ******************************************************************************/ 23 + 24 + /* 25 + * Credit is due for Josep Comas, who created the original patch to speedtch.c 26 + * to support the different padding used by the AccessRunner (now generalized 27 + * into usbatm), and the userspace firmware loading utility. 28 + */ 29 + 30 + #include <linux/module.h> 31 + #include <linux/moduleparam.h> 32 + #include <linux/kernel.h> 33 + #include <linux/timer.h> 34 + #include <linux/errno.h> 35 + #include <linux/slab.h> 36 + #include <linux/init.h> 37 + #include <linux/device.h> /* FIXME: linux/firmware.h should include it itself */ 38 + #include <linux/firmware.h> 39 + 40 + #include "usbatm.h" 41 + 42 + #define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands" 43 + #define DRIVER_VERSION "0.2" 44 + #define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver" 45 + 46 + static const char cxacru_driver_name[] = "cxacru"; 47 + 48 + #define CXACRU_EP_CMD 0x01 /* Bulk/interrupt in/out */ 49 + #define CXACRU_EP_DATA 0x02 /* Bulk in/out */ 50 + 51 + #define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */ 52 + 53 + /* Addresses */ 54 + #define PLLFCLK_ADDR 0x00350068 55 + #define PLLBCLK_ADDR 0x0035006c 56 + #define SDRAMEN_ADDR 0x00350010 57 + #define FW_ADDR 0x00801000 58 + #define BR_ADDR 0x00180600 59 + #define SIG_ADDR 0x00180500 60 + #define BR_STACK_ADDR 0x00187f10 61 + 62 + /* Values */ 63 + #define SDRAM_ENA 0x1 64 + 65 + #define CMD_TIMEOUT 2000 /* msecs */ 66 + #define POLL_INTERVAL 5000 /* msecs */ 67 + 68 + /* commands for interaction with the modem through the control channel before 69 + * firmware is loaded */ 70 + enum cxacru_fw_request { 71 + FW_CMD_ERR, 72 + FW_GET_VER, 73 + FW_READ_MEM, 74 + FW_WRITE_MEM, 75 + FW_RMW_MEM, 76 + FW_CHECKSUM_MEM, 77 + FW_GOTO_MEM, 78 + }; 79 + 80 + /* commands for interaction with the modem through the control channel once 81 + * firmware is loaded */ 82 + enum cxacru_cm_request { 83 + CM_REQUEST_UNDEFINED = 0x80, 84 + CM_REQUEST_TEST, 85 + CM_REQUEST_CHIP_GET_MAC_ADDRESS, 86 + CM_REQUEST_CHIP_GET_DP_VERSIONS, 87 + CM_REQUEST_CHIP_ADSL_LINE_START, 88 + CM_REQUEST_CHIP_ADSL_LINE_STOP, 89 + CM_REQUEST_CHIP_ADSL_LINE_GET_STATUS, 90 + CM_REQUEST_CHIP_ADSL_LINE_GET_SPEED, 91 + CM_REQUEST_CARD_INFO_GET, 92 + CM_REQUEST_CARD_DATA_GET, 93 + CM_REQUEST_CARD_DATA_SET, 94 + CM_REQUEST_COMMAND_HW_IO, 95 + CM_REQUEST_INTERFACE_HW_IO, 96 + CM_REQUEST_CARD_SERIAL_DATA_PATH_GET, 97 + CM_REQUEST_CARD_SERIAL_DATA_PATH_SET, 98 + CM_REQUEST_CARD_CONTROLLER_VERSION_GET, 99 + CM_REQUEST_CARD_GET_STATUS, 100 + CM_REQUEST_CARD_GET_MAC_ADDRESS, 101 + CM_REQUEST_CARD_GET_DATA_LINK_STATUS, 102 + CM_REQUEST_MAX, 103 + }; 104 + 105 + /* reply codes to the commands above */ 106 + enum cxacru_cm_status { 107 + CM_STATUS_UNDEFINED, 108 + CM_STATUS_SUCCESS, 109 + CM_STATUS_ERROR, 110 + CM_STATUS_UNSUPPORTED, 111 + CM_STATUS_UNIMPLEMENTED, 112 + CM_STATUS_PARAMETER_ERROR, 113 + CM_STATUS_DBG_LOOPBACK, 114 + CM_STATUS_MAX, 115 + }; 116 + 117 + /* indices into CARD_INFO_GET return array */ 118 + enum cxacru_info_idx { 119 + CXINF_DOWNSTREAM_RATE, 120 + CXINF_UPSTREAM_RATE, 121 + CXINF_LINK_STATUS, 122 + CXINF_LINE_STATUS, 123 + CXINF_MAC_ADDRESS_HIGH, 124 + CXINF_MAC_ADDRESS_LOW, 125 + CXINF_UPSTREAM_SNR_MARGIN, 126 + CXINF_DOWNSTREAM_SNR_MARGIN, 127 + CXINF_UPSTREAM_ATTENUATION, 128 + CXINF_DOWNSTREAM_ATTENUATION, 129 + CXINF_TRANSMITTER_POWER, 130 + CXINF_UPSTREAM_BITS_PER_FRAME, 131 + CXINF_DOWNSTREAM_BITS_PER_FRAME, 132 + CXINF_STARTUP_ATTEMPTS, 133 + CXINF_UPSTREAM_CRC_ERRORS, 134 + CXINF_DOWNSTREAM_CRC_ERRORS, 135 + CXINF_UPSTREAM_FEC_ERRORS, 136 + CXINF_DOWNSTREAM_FEC_ERRORS, 137 + CXINF_UPSTREAM_HEC_ERRORS, 138 + CXINF_DOWNSTREAM_HEC_ERRORS, 139 + CXINF_LINE_STARTABLE, 140 + CXINF_MODULATION, 141 + CXINF_ADSL_HEADEND, 142 + CXINF_ADSL_HEADEND_ENVIRONMENT, 143 + CXINF_CONTROLLER_VERSION, 144 + /* dunno what the missing two mean */ 145 + CXINF_MAX = 0x1c, 146 + }; 147 + 148 + struct cxacru_modem_type { 149 + u32 pll_f_clk; 150 + u32 pll_b_clk; 151 + int boot_rom_patch; 152 + }; 153 + 154 + struct cxacru_data { 155 + struct usbatm_data *usbatm; 156 + 157 + const struct cxacru_modem_type *modem_type; 158 + 159 + int line_status; 160 + struct work_struct poll_work; 161 + 162 + /* contol handles */ 163 + struct semaphore cm_serialize; 164 + u8 *rcv_buf; 165 + u8 *snd_buf; 166 + struct urb *rcv_urb; 167 + struct urb *snd_urb; 168 + struct completion rcv_done; 169 + struct completion snd_done; 170 + }; 171 + 172 + /* the following three functions are stolen from drivers/usb/core/message.c */ 173 + static void cxacru_blocking_completion(struct urb *urb, struct pt_regs *regs) 174 + { 175 + complete((struct completion *)urb->context); 176 + } 177 + 178 + static void cxacru_timeout_kill(unsigned long data) 179 + { 180 + usb_unlink_urb((struct urb *) data); 181 + } 182 + 183 + static int cxacru_start_wait_urb(struct urb *urb, struct completion *done, 184 + int* actual_length) 185 + { 186 + struct timer_list timer; 187 + int status; 188 + 189 + init_timer(&timer); 190 + timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT); 191 + timer.data = (unsigned long) urb; 192 + timer.function = cxacru_timeout_kill; 193 + add_timer(&timer); 194 + wait_for_completion(done); 195 + status = urb->status; 196 + if (status == -ECONNRESET) 197 + status = -ETIMEDOUT; 198 + del_timer_sync(&timer); 199 + 200 + if (actual_length) 201 + *actual_length = urb->actual_length; 202 + return status; 203 + } 204 + 205 + static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm, 206 + u8 *wdata, int wsize, u8 *rdata, int rsize) 207 + { 208 + int ret, actlen; 209 + int offb, offd; 210 + const int stride = CMD_PACKET_SIZE - 4; 211 + u8 *wbuf = instance->snd_buf; 212 + u8 *rbuf = instance->rcv_buf; 213 + int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE; 214 + int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE; 215 + 216 + if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) { 217 + dbg("too big transfer requested"); 218 + ret = -ENOMEM; 219 + goto fail; 220 + } 221 + 222 + down(&instance->cm_serialize); 223 + 224 + /* submit reading urb before the writing one */ 225 + init_completion(&instance->rcv_done); 226 + ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL); 227 + if (ret < 0) { 228 + dbg("submitting read urb for cm %#x failed", cm); 229 + ret = ret; 230 + goto fail; 231 + } 232 + 233 + memset(wbuf, 0, wbuflen); 234 + /* handle wsize == 0 */ 235 + wbuf[0] = cm; 236 + for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) { 237 + wbuf[offb] = cm; 238 + memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd)); 239 + } 240 + 241 + instance->snd_urb->transfer_buffer_length = wbuflen; 242 + init_completion(&instance->snd_done); 243 + ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL); 244 + if (ret < 0) { 245 + dbg("submitting write urb for cm %#x failed", cm); 246 + ret = ret; 247 + goto fail; 248 + } 249 + 250 + ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL); 251 + if (ret < 0) { 252 + dbg("sending cm %#x failed", cm); 253 + ret = ret; 254 + goto fail; 255 + } 256 + 257 + ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen); 258 + if (ret < 0) { 259 + dbg("receiving cm %#x failed", cm); 260 + ret = ret; 261 + goto fail; 262 + } 263 + if (actlen % CMD_PACKET_SIZE || !actlen) { 264 + dbg("response is not a positive multiple of %d: %#x", 265 + CMD_PACKET_SIZE, actlen); 266 + ret = -EIO; 267 + goto fail; 268 + } 269 + 270 + /* check the return status and copy the data to the output buffer, if needed */ 271 + for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) { 272 + if (rbuf[offb] != cm) { 273 + dbg("wrong cm %#x in response", rbuf[offb]); 274 + ret = -EIO; 275 + goto fail; 276 + } 277 + if (rbuf[offb + 1] != CM_STATUS_SUCCESS) { 278 + dbg("response failed: %#x", rbuf[offb + 1]); 279 + ret = -EIO; 280 + goto fail; 281 + } 282 + if (offd >= rsize) 283 + break; 284 + memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd)); 285 + offd += stride; 286 + } 287 + 288 + ret = offd; 289 + dbg("cm %#x", cm); 290 + fail: 291 + up(&instance->cm_serialize); 292 + return ret; 293 + } 294 + 295 + static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm, 296 + u32 *data, int size) 297 + { 298 + int ret, len; 299 + u32 *buf; 300 + int offb, offd; 301 + const int stride = CMD_PACKET_SIZE / (4 * 2) - 1; 302 + int buflen = ((size - 1) / stride + 1 + size * 2) * 4; 303 + 304 + buf = kmalloc(buflen, GFP_KERNEL); 305 + if (!buf) 306 + return -ENOMEM; 307 + 308 + ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen); 309 + if (ret < 0) 310 + goto cleanup; 311 + 312 + /* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */ 313 + len = ret / 4; 314 + for (offb = 0; offb < len; ) { 315 + int l = le32_to_cpu(buf[offb++]); 316 + if (l > stride || l > (len - offb) / 2) { 317 + dbg("wrong data length %#x in response", l); 318 + ret = -EIO; 319 + goto cleanup; 320 + } 321 + while (l--) { 322 + offd = le32_to_cpu(buf[offb++]); 323 + if (offd >= size) { 324 + dbg("wrong index %#x in response", offd); 325 + ret = -EIO; 326 + goto cleanup; 327 + } 328 + data[offd] = le32_to_cpu(buf[offb++]); 329 + } 330 + } 331 + 332 + ret = 0; 333 + 334 + cleanup: 335 + kfree(buf); 336 + return ret; 337 + } 338 + 339 + static int cxacru_card_status(struct cxacru_data *instance) 340 + { 341 + int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0); 342 + if (ret < 0) { /* firmware not loaded */ 343 + dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret); 344 + return ret; 345 + } 346 + return 0; 347 + } 348 + 349 + static void cxacru_poll_status(struct cxacru_data *instance); 350 + 351 + static int cxacru_atm_start(struct usbatm_data *usbatm_instance, 352 + struct atm_dev *atm_dev) 353 + { 354 + struct cxacru_data *instance = usbatm_instance->driver_data; 355 + struct device *dev = &usbatm_instance->usb_intf->dev; 356 + /* 357 + struct atm_dev *atm_dev = usbatm_instance->atm_dev; 358 + */ 359 + int ret; 360 + 361 + dbg("cxacru_atm_start"); 362 + 363 + /* Read MAC address */ 364 + ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0, 365 + atm_dev->esi, sizeof(atm_dev->esi)); 366 + if (ret < 0) { 367 + dev_err(dev, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret); 368 + return ret; 369 + } 370 + 371 + /* start ADSL */ 372 + ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0); 373 + if (ret < 0) { 374 + dev_err(dev, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret); 375 + return ret; 376 + } 377 + 378 + /* Start status polling */ 379 + cxacru_poll_status(instance); 380 + return 0; 381 + } 382 + 383 + static void cxacru_poll_status(struct cxacru_data *instance) 384 + { 385 + u32 buf[CXINF_MAX] = {}; 386 + struct device *dev = &instance->usbatm->usb_intf->dev; 387 + struct atm_dev *atm_dev = instance->usbatm->atm_dev; 388 + int ret; 389 + 390 + ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX); 391 + if (ret < 0) { 392 + dev_warn(dev, "poll status: error %d\n", ret); 393 + goto reschedule; 394 + } 395 + 396 + if (instance->line_status == buf[CXINF_LINE_STATUS]) 397 + goto reschedule; 398 + 399 + instance->line_status = buf[CXINF_LINE_STATUS]; 400 + switch (instance->line_status) { 401 + case 0: 402 + atm_dev->signal = ATM_PHY_SIG_LOST; 403 + dev_info(dev, "ADSL line: down\n"); 404 + break; 405 + 406 + case 1: 407 + atm_dev->signal = ATM_PHY_SIG_LOST; 408 + dev_info(dev, "ADSL line: attemtping to activate\n"); 409 + break; 410 + 411 + case 2: 412 + atm_dev->signal = ATM_PHY_SIG_LOST; 413 + dev_info(dev, "ADSL line: training\n"); 414 + break; 415 + 416 + case 3: 417 + atm_dev->signal = ATM_PHY_SIG_LOST; 418 + dev_info(dev, "ADSL line: channel analysis\n"); 419 + break; 420 + 421 + case 4: 422 + atm_dev->signal = ATM_PHY_SIG_LOST; 423 + dev_info(dev, "ADSL line: exchange\n"); 424 + break; 425 + 426 + case 5: 427 + atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424; 428 + atm_dev->signal = ATM_PHY_SIG_FOUND; 429 + 430 + dev_info(dev, "ADSL line: up (%d Kib/s down | %d Kib/s up)\n", 431 + buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]); 432 + break; 433 + 434 + case 6: 435 + atm_dev->signal = ATM_PHY_SIG_LOST; 436 + dev_info(dev, "ADSL line: waiting\n"); 437 + break; 438 + 439 + case 7: 440 + atm_dev->signal = ATM_PHY_SIG_LOST; 441 + dev_info(dev, "ADSL line: initializing\n"); 442 + break; 443 + 444 + default: 445 + atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 446 + dev_info(dev, "Unknown line state %02x\n", instance->line_status); 447 + break; 448 + } 449 + reschedule: 450 + schedule_delayed_work(&instance->poll_work, msecs_to_jiffies(POLL_INTERVAL)); 451 + } 452 + 453 + static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw, 454 + u8 code1, u8 code2, u32 addr, u8 *data, int size) 455 + { 456 + int ret; 457 + u8 *buf; 458 + int offd, offb; 459 + const int stride = CMD_PACKET_SIZE - 8; 460 + 461 + buf = (u8 *) __get_free_page(GFP_KERNEL); 462 + if (!buf) 463 + return -ENOMEM; 464 + 465 + offb = offd = 0; 466 + do { 467 + int l = min_t(int, stride, size - offd); 468 + buf[offb++] = fw; 469 + buf[offb++] = l; 470 + buf[offb++] = code1; 471 + buf[offb++] = code2; 472 + *((u32 *) (buf + offb)) = cpu_to_le32(addr); 473 + offb += 4; 474 + addr += l; 475 + if(l) 476 + memcpy(buf + offb, data + offd, l); 477 + if (l < stride) 478 + memset(buf + offb + l, 0, stride - l); 479 + offb += stride; 480 + offd += stride; 481 + if ((offb >= PAGE_SIZE) || (offd >= size)) { 482 + ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD), 483 + buf, offb, NULL, CMD_TIMEOUT); 484 + if (ret < 0) { 485 + dbg("sending fw %#x failed", fw); 486 + goto cleanup; 487 + } 488 + offb = 0; 489 + } 490 + } while(offd < size); 491 + dbg("sent fw %#x", fw); 492 + 493 + ret = 0; 494 + 495 + cleanup: 496 + free_page((unsigned long) buf); 497 + return ret; 498 + } 499 + 500 + static void cxacru_upload_firmware(struct cxacru_data *instance, 501 + const struct firmware *fw, 502 + const struct firmware *bp, 503 + const struct firmware *cf) 504 + { 505 + int ret; 506 + int off; 507 + struct usb_device *usb_dev = instance->usbatm->usb_dev; 508 + struct device *dev = &instance->usbatm->usb_intf->dev; 509 + u16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct }; 510 + u32 val; 511 + 512 + dbg("cxacru_upload_firmware"); 513 + 514 + /* FirmwarePllFClkValue */ 515 + val = cpu_to_le32(instance->modem_type->pll_f_clk); 516 + ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4); 517 + if (ret) { 518 + dev_err(dev, "FirmwarePllFClkValue failed: %d\n", ret); 519 + return; 520 + } 521 + 522 + /* FirmwarePllBClkValue */ 523 + val = cpu_to_le32(instance->modem_type->pll_b_clk); 524 + ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4); 525 + if (ret) { 526 + dev_err(dev, "FirmwarePllBClkValue failed: %d\n", ret); 527 + return; 528 + } 529 + 530 + /* Enable SDRAM */ 531 + val = cpu_to_le32(SDRAM_ENA); 532 + ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4); 533 + if (ret) { 534 + dev_err(dev, "Enable SDRAM failed: %d\n", ret); 535 + return; 536 + } 537 + 538 + /* Firmware */ 539 + ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size); 540 + if (ret) { 541 + dev_err(dev, "Firmware upload failed: %d\n", ret); 542 + return; 543 + } 544 + 545 + /* Boot ROM patch */ 546 + if (instance->modem_type->boot_rom_patch) { 547 + ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size); 548 + if (ret) { 549 + dev_err(dev, "Boot ROM patching failed: %d\n", ret); 550 + return; 551 + } 552 + } 553 + 554 + /* Signature */ 555 + ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4); 556 + if (ret) { 557 + dev_err(dev, "Signature storing failed: %d\n", ret); 558 + return; 559 + } 560 + 561 + if (instance->modem_type->boot_rom_patch) { 562 + val = cpu_to_le32(BR_ADDR); 563 + ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4); 564 + } 565 + else { 566 + ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0); 567 + } 568 + if (ret) { 569 + dev_err(dev, "Passing control to firmware failed: %d\n", ret); 570 + return; 571 + } 572 + 573 + /* Delay to allow firmware to start up. */ 574 + msleep_interruptible(1000); 575 + 576 + usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD)); 577 + usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD)); 578 + usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA)); 579 + usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA)); 580 + 581 + ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0); 582 + if (ret < 0) { 583 + dev_err(dev, "modem failed to initialize: %d\n", ret); 584 + return; 585 + } 586 + 587 + /* Load config data (le32), doing one packet at a time */ 588 + if (cf) 589 + for (off = 0; off < cf->size / 4; ) { 590 + u32 buf[CMD_PACKET_SIZE / 4 - 1]; 591 + int i, len = min_t(int, cf->size / 4 - off, CMD_PACKET_SIZE / 4 / 2 - 1); 592 + buf[0] = cpu_to_le32(len); 593 + for (i = 0; i < len; i++, off++) { 594 + buf[i * 2 + 1] = cpu_to_le32(off); 595 + memcpy(buf + i * 2 + 2, cf->data + off * 4, 4); 596 + } 597 + ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET, 598 + (u8 *) buf, len, NULL, 0); 599 + if (ret < 0) { 600 + dev_err(dev, "load config data failed: %d\n", ret); 601 + return; 602 + } 603 + } 604 + 605 + msleep_interruptible(4000); 606 + } 607 + 608 + static int cxacru_find_firmware(struct cxacru_data *instance, 609 + char* phase, const struct firmware **fw_p) 610 + { 611 + struct device *dev = &instance->usbatm->usb_intf->dev; 612 + char buf[16]; 613 + 614 + sprintf(buf, "cxacru-%s.bin", phase); 615 + dbg("cxacru_find_firmware: looking for %s", buf); 616 + 617 + if (request_firmware(fw_p, buf, dev)) { 618 + dev_dbg(dev, "no stage %s firmware found\n", phase); 619 + return -ENOENT; 620 + } 621 + 622 + dev_info(dev, "found firmware %s\n", buf); 623 + 624 + return 0; 625 + } 626 + 627 + static int cxacru_heavy_init(struct usbatm_data *usbatm_instance, 628 + struct usb_interface *usb_intf) 629 + { 630 + struct device *dev = &usbatm_instance->usb_intf->dev; 631 + const struct firmware *fw, *bp, *cf; 632 + struct cxacru_data *instance = usbatm_instance->driver_data; 633 + 634 + int ret = cxacru_find_firmware(instance, "fw", &fw); 635 + if (ret) { 636 + dev_warn(dev, "firmware (cxacru-fw.bin) unavailable (hotplug misconfiguration?)\n"); 637 + return ret; 638 + } 639 + 640 + if (instance->modem_type->boot_rom_patch) { 641 + ret = cxacru_find_firmware(instance, "bp", &bp); 642 + if (ret) { 643 + dev_warn(dev, "boot ROM patch (cxacru-bp.bin) unavailable (hotplug misconfiguration?)\n"); 644 + release_firmware(fw); 645 + return ret; 646 + } 647 + } 648 + 649 + if (cxacru_find_firmware(instance, "cf", &cf)) /* optional */ 650 + cf = NULL; 651 + 652 + cxacru_upload_firmware(instance, fw, bp, cf); 653 + 654 + if (cf) 655 + release_firmware(cf); 656 + if (instance->modem_type->boot_rom_patch) 657 + release_firmware(bp); 658 + release_firmware(fw); 659 + 660 + ret = cxacru_card_status(instance); 661 + if (ret) 662 + dbg("modem initialisation failed"); 663 + else 664 + dbg("done setting up the modem"); 665 + 666 + return ret; 667 + } 668 + 669 + static int cxacru_bind(struct usbatm_data *usbatm_instance, 670 + struct usb_interface *intf, const struct usb_device_id *id, 671 + int *need_heavy_init) 672 + { 673 + struct cxacru_data *instance; 674 + struct usb_device *usb_dev = interface_to_usbdev(intf); 675 + int ret; 676 + 677 + /* instance init */ 678 + instance = kmalloc(sizeof(*instance), GFP_KERNEL); 679 + if (!instance) { 680 + dbg("cxacru_bind: no memory for instance data"); 681 + return -ENOMEM; 682 + } 683 + 684 + memset(instance, 0, sizeof(*instance)); 685 + 686 + instance->usbatm = usbatm_instance; 687 + instance->modem_type = (struct cxacru_modem_type *) id->driver_info; 688 + 689 + instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL); 690 + if (!instance->rcv_buf) { 691 + dbg("cxacru_bind: no memory for rcv_buf"); 692 + ret = -ENOMEM; 693 + goto fail; 694 + } 695 + instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL); 696 + if (!instance->snd_buf) { 697 + dbg("cxacru_bind: no memory for snd_buf"); 698 + ret = -ENOMEM; 699 + goto fail; 700 + } 701 + instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL); 702 + if (!instance->rcv_urb) { 703 + dbg("cxacru_bind: no memory for rcv_urb"); 704 + ret = -ENOMEM; 705 + goto fail; 706 + } 707 + instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL); 708 + if (!instance->snd_urb) { 709 + dbg("cxacru_bind: no memory for snd_urb"); 710 + ret = -ENOMEM; 711 + goto fail; 712 + } 713 + 714 + usb_fill_int_urb(instance->rcv_urb, 715 + usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD), 716 + instance->rcv_buf, PAGE_SIZE, 717 + cxacru_blocking_completion, &instance->rcv_done, 1); 718 + instance->rcv_urb->transfer_flags |= URB_ASYNC_UNLINK; 719 + 720 + usb_fill_int_urb(instance->snd_urb, 721 + usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD), 722 + instance->snd_buf, PAGE_SIZE, 723 + cxacru_blocking_completion, &instance->snd_done, 4); 724 + instance->snd_urb->transfer_flags |= URB_ASYNC_UNLINK; 725 + 726 + init_MUTEX(&instance->cm_serialize); 727 + 728 + INIT_WORK(&instance->poll_work, (void *)cxacru_poll_status, instance); 729 + 730 + usbatm_instance->driver_data = instance; 731 + 732 + *need_heavy_init = cxacru_card_status(instance); 733 + 734 + return 0; 735 + 736 + fail: 737 + free_page((unsigned long) instance->snd_buf); 738 + free_page((unsigned long) instance->rcv_buf); 739 + usb_free_urb(instance->snd_urb); 740 + usb_free_urb(instance->rcv_urb); 741 + kfree(instance); 742 + 743 + return ret; 744 + } 745 + 746 + static void cxacru_unbind(struct usbatm_data *usbatm_instance, 747 + struct usb_interface *intf) 748 + { 749 + struct cxacru_data *instance = usbatm_instance->driver_data; 750 + 751 + dbg("cxacru_unbind entered"); 752 + 753 + if (!instance) { 754 + dbg("cxacru_unbind: NULL instance!"); 755 + return; 756 + } 757 + 758 + while (!cancel_delayed_work(&instance->poll_work)) 759 + flush_scheduled_work(); 760 + 761 + usb_kill_urb(instance->snd_urb); 762 + usb_kill_urb(instance->rcv_urb); 763 + usb_free_urb(instance->snd_urb); 764 + usb_free_urb(instance->rcv_urb); 765 + 766 + free_page((unsigned long) instance->snd_buf); 767 + free_page((unsigned long) instance->rcv_buf); 768 + kfree(instance); 769 + 770 + usbatm_instance->driver_data = NULL; 771 + } 772 + 773 + static const struct cxacru_modem_type cxacru_cafe = { 774 + .pll_f_clk = 0x02d874df, 775 + .pll_b_clk = 0x0196a51a, 776 + .boot_rom_patch = 1, 777 + }; 778 + 779 + static const struct cxacru_modem_type cxacru_cb00 = { 780 + .pll_f_clk = 0x5, 781 + .pll_b_clk = 0x3, 782 + .boot_rom_patch = 0, 783 + }; 784 + 785 + static const struct usb_device_id cxacru_usb_ids[] = { 786 + { /* V = Conexant P = ADSL modem (Euphrates project) */ 787 + USB_DEVICE(0x0572, 0xcafe), .driver_info = (unsigned long) &cxacru_cafe 788 + }, 789 + { /* V = Conexant P = ADSL modem (Hasbani project) */ 790 + USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00 791 + }, 792 + { /* V = Conexant P = ADSL modem */ 793 + USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00 794 + }, 795 + { /* V = Conexant P = ADSL modem */ 796 + USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00 797 + }, 798 + { /* V = Olitec P = ADSL modem version 2 */ 799 + USB_DEVICE(0x08e3, 0x0100), .driver_info = (unsigned long) &cxacru_cafe 800 + }, 801 + { /* V = Olitec P = ADSL modem version 3 */ 802 + USB_DEVICE(0x08e3, 0x0102), .driver_info = (unsigned long) &cxacru_cb00 803 + }, 804 + { /* V = Trust/Amigo Technology Co. P = AMX-CA86U */ 805 + USB_DEVICE(0x0eb0, 0x3457), .driver_info = (unsigned long) &cxacru_cafe 806 + }, 807 + { /* V = Zoom P = 5510 */ 808 + USB_DEVICE(0x1803, 0x5510), .driver_info = (unsigned long) &cxacru_cb00 809 + }, 810 + { /* V = Draytek P = Vigor 318 */ 811 + USB_DEVICE(0x0675, 0x0200), .driver_info = (unsigned long) &cxacru_cb00 812 + }, 813 + { /* V = Zyxel P = 630-C1 aka OMNI ADSL USB (Annex A) */ 814 + USB_DEVICE(0x0586, 0x330a), .driver_info = (unsigned long) &cxacru_cb00 815 + }, 816 + { /* V = Zyxel P = 630-C3 aka OMNI ADSL USB (Annex B) */ 817 + USB_DEVICE(0x0586, 0x330b), .driver_info = (unsigned long) &cxacru_cb00 818 + }, 819 + { /* V = Aethra P = Starmodem UM1020 */ 820 + USB_DEVICE(0x0659, 0x0020), .driver_info = (unsigned long) &cxacru_cb00 821 + }, 822 + { /* V = Aztech Systems P = ? AKA Pirelli AUA-010 */ 823 + USB_DEVICE(0x0509, 0x0812), .driver_info = (unsigned long) &cxacru_cb00 824 + }, 825 + { /* V = Netopia P = Cayman 3341(Annex A)/3351(Annex B) */ 826 + USB_DEVICE(0x100d, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00 827 + }, 828 + { /* V = Netopia P = Cayman 3342(Annex A)/3352(Annex B) */ 829 + USB_DEVICE(0x100d, 0x3342), .driver_info = (unsigned long) &cxacru_cb00 830 + }, 831 + {} 832 + }; 833 + 834 + MODULE_DEVICE_TABLE(usb, cxacru_usb_ids); 835 + 836 + static struct usbatm_driver cxacru_driver = { 837 + .owner = THIS_MODULE, 838 + .driver_name = cxacru_driver_name, 839 + .bind = cxacru_bind, 840 + .heavy_init = cxacru_heavy_init, 841 + .unbind = cxacru_unbind, 842 + .atm_start = cxacru_atm_start, 843 + .in = CXACRU_EP_DATA, 844 + .out = CXACRU_EP_DATA, 845 + .rx_padding = 3, 846 + .tx_padding = 11, 847 + }; 848 + 849 + static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) 850 + { 851 + return usbatm_usb_probe(intf, id, &cxacru_driver); 852 + } 853 + 854 + static struct usb_driver cxacru_usb_driver = { 855 + .owner = THIS_MODULE, 856 + .name = cxacru_driver_name, 857 + .probe = cxacru_usb_probe, 858 + .disconnect = usbatm_usb_disconnect, 859 + .id_table = cxacru_usb_ids 860 + }; 861 + 862 + static int __init cxacru_init(void) 863 + { 864 + return usb_register(&cxacru_usb_driver); 865 + } 866 + 867 + static void __exit cxacru_cleanup(void) 868 + { 869 + usb_deregister(&cxacru_usb_driver); 870 + } 871 + 872 + module_init(cxacru_init); 873 + module_exit(cxacru_cleanup); 874 + 875 + MODULE_AUTHOR(DRIVER_AUTHOR); 876 + MODULE_DESCRIPTION(DRIVER_DESC); 877 + MODULE_LICENSE("GPL"); 878 + MODULE_VERSION(DRIVER_VERSION);
+549 -570
drivers/usb/atm/speedtch.c
··· 5 5 * Copyright (C) 2003, Duncan Sands 6 6 * Copyright (C) 2004, David Woodhouse 7 7 * 8 + * Based on "modem_run.c", copyright (C) 2001, Benoit Papillault 9 + * 8 10 * This program is free software; you can redistribute it and/or modify it 9 11 * under the terms of the GNU General Public License as published by the Free 10 12 * Software Foundation; either version 2 of the License, or (at your option) ··· 23 21 * 24 22 ******************************************************************************/ 25 23 24 + #include <asm/page.h> 25 + #include <linux/device.h> 26 + #include <linux/errno.h> 27 + #include <linux/firmware.h> 28 + #include <linux/gfp.h> 29 + #include <linux/init.h> 30 + #include <linux/kernel.h> 26 31 #include <linux/module.h> 27 32 #include <linux/moduleparam.h> 28 - #include <linux/gfp.h> 29 - #include <linux/kernel.h> 30 - #include <linux/sched.h> 31 - #include <linux/timer.h> 32 - #include <linux/errno.h> 33 - #include <linux/proc_fs.h> 34 33 #include <linux/slab.h> 35 - #include <linux/wait.h> 36 - #include <linux/list.h> 37 - #include <asm/processor.h> 38 - #include <asm/uaccess.h> 39 - #include <linux/smp_lock.h> 40 - #include <linux/interrupt.h> 41 - #include <linux/atm.h> 42 - #include <linux/atmdev.h> 43 - #include <linux/crc32.h> 44 - #include <linux/init.h> 45 - #include <linux/firmware.h> 34 + #include <linux/stat.h> 35 + #include <linux/timer.h> 36 + #include <linux/workqueue.h> 46 37 47 - #include "usb_atm.h" 48 - 49 - #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE) 50 - # define USE_FW_LOADER 51 - #endif 38 + #include "usbatm.h" 52 39 53 40 #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 54 - #define DRIVER_VERSION "1.8" 41 + #define DRIVER_VERSION "1.9" 55 42 #define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION 56 43 57 44 static const char speedtch_driver_name[] = "speedtch"; 58 45 59 - #define SPEEDTOUCH_VENDORID 0x06b9 60 - #define SPEEDTOUCH_PRODUCTID 0x4061 46 + #define CTRL_TIMEOUT 2000 /* milliseconds */ 47 + #define DATA_TIMEOUT 2000 /* milliseconds */ 61 48 62 - /* Timeout in jiffies */ 63 - #define CTRL_TIMEOUT 2000 64 - #define DATA_TIMEOUT 2000 49 + #define OFFSET_7 0 /* size 1 */ 50 + #define OFFSET_b 1 /* size 8 */ 51 + #define OFFSET_d 9 /* size 4 */ 52 + #define OFFSET_e 13 /* size 1 */ 53 + #define OFFSET_f 14 /* size 1 */ 54 + #define TOTAL 15 65 55 66 - #define OFFSET_7 0 /* size 1 */ 67 - #define OFFSET_b 1 /* size 8 */ 68 - #define OFFSET_d 9 /* size 4 */ 69 - #define OFFSET_e 13 /* size 1 */ 70 - #define OFFSET_f 14 /* size 1 */ 71 - #define TOTAL 15 56 + #define SIZE_7 1 57 + #define SIZE_b 8 58 + #define SIZE_d 4 59 + #define SIZE_e 1 60 + #define SIZE_f 1 72 61 73 - #define SIZE_7 1 74 - #define SIZE_b 8 75 - #define SIZE_d 4 76 - #define SIZE_e 1 77 - #define SIZE_f 1 62 + #define MIN_POLL_DELAY 5000 /* milliseconds */ 63 + #define MAX_POLL_DELAY 60000 /* milliseconds */ 78 64 79 - static int dl_512_first = 0; 80 - static int sw_buffering = 0; 65 + #define RESUBMIT_DELAY 1000 /* milliseconds */ 81 66 82 - module_param(dl_512_first, bool, 0444); 83 - MODULE_PARM_DESC(dl_512_first, "Read 512 bytes before sending firmware"); 67 + #define DEFAULT_ALTSETTING 1 68 + #define DEFAULT_DL_512_FIRST 0 69 + #define DEFAULT_SW_BUFFERING 0 84 70 85 - module_param(sw_buffering, uint, 0444); 86 - MODULE_PARM_DESC(sw_buffering, "Enable software buffering"); 71 + static int altsetting = DEFAULT_ALTSETTING; 72 + static int dl_512_first = DEFAULT_DL_512_FIRST; 73 + static int sw_buffering = DEFAULT_SW_BUFFERING; 87 74 88 - #define UDSL_IOCTL_LINE_UP 1 89 - #define UDSL_IOCTL_LINE_DOWN 2 75 + module_param(altsetting, int, S_IRUGO | S_IWUSR); 76 + MODULE_PARM_DESC(altsetting, 77 + "Alternative setting for data interface (default: " 78 + __MODULE_STRING(DEFAULT_ALTSETTING) ")"); 90 79 91 - #define SPEEDTCH_ENDPOINT_INT 0x81 92 - #define SPEEDTCH_ENDPOINT_DATA 0x07 93 - #define SPEEDTCH_ENDPOINT_FIRMWARE 0x05 80 + module_param(dl_512_first, bool, S_IRUGO | S_IWUSR); 81 + MODULE_PARM_DESC(dl_512_first, 82 + "Read 512 bytes before sending firmware (default: " 83 + __MODULE_STRING(DEFAULT_DL_512_FIRST) ")"); 84 + 85 + module_param(sw_buffering, bool, S_IRUGO | S_IWUSR); 86 + MODULE_PARM_DESC(sw_buffering, 87 + "Enable software buffering (default: " 88 + __MODULE_STRING(DEFAULT_SW_BUFFERING) ")"); 89 + 90 + #define ENDPOINT_INT 0x81 91 + #define ENDPOINT_DATA 0x07 92 + #define ENDPOINT_FIRMWARE 0x05 94 93 95 94 #define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) ) 96 95 97 - static struct usb_device_id speedtch_usb_ids[] = { 98 - {USB_DEVICE(SPEEDTOUCH_VENDORID, SPEEDTOUCH_PRODUCTID)}, 99 - {} 100 - }; 101 - 102 - MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); 103 - 104 96 struct speedtch_instance_data { 105 - struct udsl_instance_data u; 97 + struct usbatm_data *usbatm; 106 98 107 - /* Status */ 99 + struct work_struct status_checker; 100 + 101 + int poll_delay; /* milliseconds */ 102 + 103 + struct timer_list resubmit_timer; 108 104 struct urb *int_urb; 109 105 unsigned char int_data[16]; 110 - struct work_struct poll_work; 111 - struct timer_list poll_timer; 112 - }; 113 - /* USB */ 114 106 115 - static int speedtch_usb_probe(struct usb_interface *intf, 116 - const struct usb_device_id *id); 117 - static void speedtch_usb_disconnect(struct usb_interface *intf); 118 - static int speedtch_usb_ioctl(struct usb_interface *intf, unsigned int code, 119 - void *user_data); 120 - static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs); 121 - static void speedtch_poll_status(struct speedtch_instance_data *instance); 122 - 123 - static struct usb_driver speedtch_usb_driver = { 124 - .owner = THIS_MODULE, 125 - .name = speedtch_driver_name, 126 - .probe = speedtch_usb_probe, 127 - .disconnect = speedtch_usb_disconnect, 128 - .ioctl = speedtch_usb_ioctl, 129 - .id_table = speedtch_usb_ids, 107 + unsigned char scratch_buffer[TOTAL]; 130 108 }; 131 109 132 110 /*************** 133 111 ** firmware ** 134 112 ***************/ 135 113 136 - static void speedtch_got_firmware(struct speedtch_instance_data *instance, 137 - int got_it) 114 + static void speedtch_set_swbuff(struct speedtch_instance_data *instance, int state) 138 115 { 139 - int err; 140 - struct usb_interface *intf; 141 - 142 - down(&instance->u.serialize); /* vs self, speedtch_firmware_start */ 143 - if (instance->u.status == UDSL_LOADED_FIRMWARE) 144 - goto out; 145 - if (!got_it) { 146 - instance->u.status = UDSL_NO_FIRMWARE; 147 - goto out; 148 - } 149 - if ((err = usb_set_interface(instance->u.usb_dev, 1, 1)) < 0) { 150 - dbg("speedtch_got_firmware: usb_set_interface returned %d!", err); 151 - instance->u.status = UDSL_NO_FIRMWARE; 152 - goto out; 153 - } 154 - 155 - /* Set up interrupt endpoint */ 156 - intf = usb_ifnum_to_if(instance->u.usb_dev, 0); 157 - if (intf && !usb_driver_claim_interface(&speedtch_usb_driver, intf, NULL)) { 158 - 159 - instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); 160 - if (instance->int_urb) { 161 - 162 - usb_fill_int_urb(instance->int_urb, instance->u.usb_dev, 163 - usb_rcvintpipe(instance->u.usb_dev, SPEEDTCH_ENDPOINT_INT), 164 - instance->int_data, 165 - sizeof(instance->int_data), 166 - speedtch_handle_int, instance, 50); 167 - err = usb_submit_urb(instance->int_urb, GFP_KERNEL); 168 - if (err) { 169 - /* Doesn't matter; we'll poll anyway */ 170 - dbg("speedtch_got_firmware: Submission of interrupt URB failed %d", err); 171 - usb_free_urb(instance->int_urb); 172 - instance->int_urb = NULL; 173 - usb_driver_release_interface(&speedtch_usb_driver, intf); 174 - } 175 - } 176 - } 177 - /* Start status polling */ 178 - mod_timer(&instance->poll_timer, jiffies + (1 * HZ)); 179 - 180 - instance->u.status = UDSL_LOADED_FIRMWARE; 181 - tasklet_schedule(&instance->u.receive_tasklet); 182 - out: 183 - up(&instance->u.serialize); 184 - wake_up_interruptible(&instance->u.firmware_waiters); 185 - } 186 - 187 - static int speedtch_set_swbuff(struct speedtch_instance_data *instance, 188 - int state) 189 - { 190 - struct usb_device *dev = instance->u.usb_dev; 116 + struct usbatm_data *usbatm = instance->usbatm; 117 + struct usb_device *usb_dev = usbatm->usb_dev; 191 118 int ret; 192 119 193 - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 194 - 0x32, 0x40, state ? 0x01 : 0x00, 195 - 0x00, NULL, 0, 100); 196 - if (ret < 0) { 197 - printk("Warning: %sabling SW buffering: usb_control_msg returned %d\n", 198 - state ? "En" : "Dis", ret); 199 - return ret; 200 - } 201 - 202 - dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis"); 203 - return 0; 120 + ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), 121 + 0x32, 0x40, state ? 0x01 : 0x00, 0x00, NULL, 0, CTRL_TIMEOUT); 122 + if (ret < 0) 123 + usb_warn(usbatm, 124 + "%sabling SW buffering: usb_control_msg returned %d\n", 125 + state ? "En" : "Dis", ret); 126 + else 127 + dbg("speedtch_set_swbuff: %sbled SW buffering", state ? "En" : "Dis"); 204 128 } 205 129 206 130 static void speedtch_test_sequence(struct speedtch_instance_data *instance) 207 131 { 208 - struct usb_device *dev = instance->u.usb_dev; 209 - unsigned char buf[10]; 132 + struct usbatm_data *usbatm = instance->usbatm; 133 + struct usb_device *usb_dev = usbatm->usb_dev; 134 + unsigned char *buf = instance->scratch_buffer; 210 135 int ret; 211 136 212 137 /* URB 147 */ 213 138 buf[0] = 0x1c; 214 139 buf[1] = 0x50; 215 - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 216 - 0x01, 0x40, 0x0b, 0x00, buf, 2, 100); 140 + ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), 141 + 0x01, 0x40, 0x0b, 0x00, buf, 2, CTRL_TIMEOUT); 217 142 if (ret < 0) 218 - printk(KERN_WARNING "%s failed on URB147: %d\n", __func__, ret); 143 + usb_warn(usbatm, "%s failed on URB147: %d\n", __func__, ret); 219 144 220 145 /* URB 148 */ 221 146 buf[0] = 0x32; 222 147 buf[1] = 0x00; 223 - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 224 - 0x01, 0x40, 0x02, 0x00, buf, 2, 100); 148 + ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), 149 + 0x01, 0x40, 0x02, 0x00, buf, 2, CTRL_TIMEOUT); 225 150 if (ret < 0) 226 - printk(KERN_WARNING "%s failed on URB148: %d\n", __func__, ret); 151 + usb_warn(usbatm, "%s failed on URB148: %d\n", __func__, ret); 227 152 228 153 /* URB 149 */ 229 154 buf[0] = 0x01; 230 155 buf[1] = 0x00; 231 156 buf[2] = 0x01; 232 - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 233 - 0x01, 0x40, 0x03, 0x00, buf, 3, 100); 157 + ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), 158 + 0x01, 0x40, 0x03, 0x00, buf, 3, CTRL_TIMEOUT); 234 159 if (ret < 0) 235 - printk(KERN_WARNING "%s failed on URB149: %d\n", __func__, ret); 160 + usb_warn(usbatm, "%s failed on URB149: %d\n", __func__, ret); 236 161 237 162 /* URB 150 */ 238 163 buf[0] = 0x01; 239 164 buf[1] = 0x00; 240 165 buf[2] = 0x01; 241 - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 242 - 0x01, 0x40, 0x04, 0x00, buf, 3, 100); 166 + ret = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), 167 + 0x01, 0x40, 0x04, 0x00, buf, 3, CTRL_TIMEOUT); 243 168 if (ret < 0) 244 - printk(KERN_WARNING "%s failed on URB150: %d\n", __func__, ret); 169 + usb_warn(usbatm, "%s failed on URB150: %d\n", __func__, ret); 245 170 } 246 171 247 - static int speedtch_start_synchro(struct speedtch_instance_data *instance) 248 - { 249 - struct usb_device *dev = instance->u.usb_dev; 250 - unsigned char buf[2]; 251 - int ret; 252 - 253 - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 254 - 0x12, 0xc0, 0x04, 0x00, 255 - buf, sizeof(buf), CTRL_TIMEOUT); 256 - if (ret < 0) { 257 - printk(KERN_WARNING "SpeedTouch: Failed to start ADSL synchronisation: %d\n", ret); 258 - return ret; 259 - } 260 - 261 - dbg("speedtch_start_synchro: modem prodded. %d Bytes returned: %02x %02x", ret, buf[0], buf[1]); 262 - return 0; 263 - } 264 - 265 - static void speedtch_handle_int(struct urb *urb, struct pt_regs *regs) 266 - { 267 - struct speedtch_instance_data *instance = urb->context; 268 - unsigned int count = urb->actual_length; 269 - int ret; 270 - 271 - /* The magic interrupt for "up state" */ 272 - const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; 273 - /* The magic interrupt for "down state" */ 274 - const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 }; 275 - 276 - switch (urb->status) { 277 - case 0: 278 - /* success */ 279 - break; 280 - case -ECONNRESET: 281 - case -ENOENT: 282 - case -ESHUTDOWN: 283 - /* this urb is terminated; clean up */ 284 - dbg("%s - urb shutting down with status: %d", __func__, urb->status); 285 - return; 286 - default: 287 - dbg("%s - nonzero urb status received: %d", __func__, urb->status); 288 - goto exit; 289 - } 290 - 291 - if (count < 6) { 292 - dbg("%s - int packet too short", __func__); 293 - goto exit; 294 - } 295 - 296 - if (!memcmp(up_int, instance->int_data, 6)) { 297 - del_timer(&instance->poll_timer); 298 - printk(KERN_NOTICE "DSL line goes up\n"); 299 - } else if (!memcmp(down_int, instance->int_data, 6)) { 300 - printk(KERN_NOTICE "DSL line goes down\n"); 301 - } else { 302 - int i; 303 - 304 - printk(KERN_DEBUG "Unknown interrupt packet of %d bytes:", count); 305 - for (i = 0; i < count; i++) 306 - printk(" %02x", instance->int_data[i]); 307 - printk("\n"); 308 - } 309 - schedule_work(&instance->poll_work); 310 - 311 - exit: 312 - rmb(); 313 - if (!instance->int_urb) 314 - return; 315 - 316 - ret = usb_submit_urb(urb, GFP_ATOMIC); 317 - if (ret) 318 - err("%s - usb_submit_urb failed with result %d", __func__, ret); 319 - } 320 - 321 - static int speedtch_get_status(struct speedtch_instance_data *instance, 322 - unsigned char *buf) 323 - { 324 - struct usb_device *dev = instance->u.usb_dev; 325 - int ret; 326 - 327 - memset(buf, 0, TOTAL); 328 - 329 - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 330 - 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7, 331 - CTRL_TIMEOUT); 332 - if (ret < 0) { 333 - dbg("MSG 7 failed"); 334 - return ret; 335 - } 336 - 337 - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 338 - 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b, 339 - CTRL_TIMEOUT); 340 - if (ret < 0) { 341 - dbg("MSG B failed"); 342 - return ret; 343 - } 344 - 345 - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 346 - 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d, 347 - CTRL_TIMEOUT); 348 - if (ret < 0) { 349 - dbg("MSG D failed"); 350 - return ret; 351 - } 352 - 353 - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 354 - 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e, 355 - CTRL_TIMEOUT); 356 - if (ret < 0) { 357 - dbg("MSG E failed"); 358 - return ret; 359 - } 360 - 361 - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 362 - 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f, 363 - CTRL_TIMEOUT); 364 - if (ret < 0) { 365 - dbg("MSG F failed"); 366 - return ret; 367 - } 368 - 369 - return 0; 370 - } 371 - 372 - static void speedtch_poll_status(struct speedtch_instance_data *instance) 373 - { 374 - unsigned char buf[TOTAL]; 375 - int ret; 376 - 377 - ret = speedtch_get_status(instance, buf); 378 - if (ret) { 379 - printk(KERN_WARNING 380 - "SpeedTouch: Error %d fetching device status\n", ret); 381 - return; 382 - } 383 - 384 - dbg("Line state %02x", buf[OFFSET_7]); 385 - 386 - switch (buf[OFFSET_7]) { 387 - case 0: 388 - if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) { 389 - instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; 390 - printk(KERN_NOTICE "ADSL line is down\n"); 391 - /* It'll never resync again unless we ask it to... */ 392 - speedtch_start_synchro(instance); 393 - } 394 - break; 395 - 396 - case 0x08: 397 - if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { 398 - instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 399 - printk(KERN_NOTICE "ADSL line is blocked?\n"); 400 - } 401 - break; 402 - 403 - case 0x10: 404 - if (instance->u.atm_dev->signal != ATM_PHY_SIG_LOST) { 405 - instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; 406 - printk(KERN_NOTICE "ADSL line is synchronising\n"); 407 - } 408 - break; 409 - 410 - case 0x20: 411 - if (instance->u.atm_dev->signal != ATM_PHY_SIG_FOUND) { 412 - int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8) 413 - | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); 414 - int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) 415 - | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); 416 - 417 - if (!(down_speed & 0x0000ffff) && 418 - !(up_speed & 0x0000ffff)) { 419 - down_speed >>= 16; 420 - up_speed >>= 16; 421 - } 422 - instance->u.atm_dev->link_rate = down_speed * 1000 / 424; 423 - instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND; 424 - 425 - printk(KERN_NOTICE 426 - "ADSL line is up (%d Kib/s down | %d Kib/s up)\n", 427 - down_speed, up_speed); 428 - } 429 - break; 430 - 431 - default: 432 - if (instance->u.atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { 433 - instance->u.atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 434 - printk(KERN_NOTICE "Unknown line state %02x\n", buf[OFFSET_7]); 435 - } 436 - break; 437 - } 438 - } 439 - 440 - static void speedtch_timer_poll(unsigned long data) 441 - { 442 - struct speedtch_instance_data *instance = (void *)data; 443 - 444 - schedule_work(&instance->poll_work); 445 - mod_timer(&instance->poll_timer, jiffies + (5 * HZ)); 446 - } 447 - 448 - #ifdef USE_FW_LOADER 449 - static void speedtch_upload_firmware(struct speedtch_instance_data *instance, 172 + static int speedtch_upload_firmware(struct speedtch_instance_data *instance, 450 173 const struct firmware *fw1, 451 174 const struct firmware *fw2) 452 175 { 453 176 unsigned char *buffer; 454 - struct usb_device *usb_dev = instance->u.usb_dev; 177 + struct usbatm_data *usbatm = instance->usbatm; 455 178 struct usb_interface *intf; 456 - int actual_length, ret; 179 + struct usb_device *usb_dev = usbatm->usb_dev; 180 + int actual_length; 181 + int ret = 0; 457 182 int offset; 458 183 459 - dbg("speedtch_upload_firmware"); 460 - 461 - if (!(intf = usb_ifnum_to_if(usb_dev, 2))) { 462 - dbg("speedtch_upload_firmware: interface not found!"); 463 - goto fail; 464 - } 184 + usb_dbg(usbatm, "%s entered\n", __func__); 465 185 466 186 if (!(buffer = (unsigned char *)__get_free_page(GFP_KERNEL))) { 467 - dbg("speedtch_upload_firmware: no memory for buffer!"); 468 - goto fail; 187 + ret = -ENOMEM; 188 + usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__); 189 + goto out; 469 190 } 470 191 471 - /* A user-space firmware loader may already have claimed interface #2 */ 472 - if ((ret = 473 - usb_driver_claim_interface(&speedtch_usb_driver, intf, NULL)) < 0) { 474 - dbg("speedtch_upload_firmware: interface in use (%d)!", ret); 475 - goto fail_free; 192 + if (!(intf = usb_ifnum_to_if(usb_dev, 2))) { 193 + ret = -ENODEV; 194 + usb_dbg(usbatm, "%s: interface not found!\n", __func__); 195 + goto out_free; 476 196 } 477 197 478 198 /* URB 7 */ 479 199 if (dl_512_first) { /* some modems need a read before writing the firmware */ 480 - ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 200 + ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), 481 201 buffer, 0x200, &actual_length, 2000); 482 202 483 203 if (ret < 0 && ret != -ETIMEDOUT) 484 - dbg("speedtch_upload_firmware: read BLOCK0 from modem failed (%d)!", ret); 204 + usb_dbg(usbatm, "%s: read BLOCK0 from modem failed (%d)!\n", __func__, ret); 485 205 else 486 - dbg("speedtch_upload_firmware: BLOCK0 downloaded (%d bytes)", ret); 206 + usb_dbg(usbatm, "%s: BLOCK0 downloaded (%d bytes)\n", __func__, ret); 487 207 } 488 208 489 209 /* URB 8 : both leds are static green */ ··· 213 489 int thislen = min_t(int, PAGE_SIZE, fw1->size - offset); 214 490 memcpy(buffer, fw1->data + offset, thislen); 215 491 216 - ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 492 + ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), 217 493 buffer, thislen, &actual_length, DATA_TIMEOUT); 218 494 219 495 if (ret < 0) { 220 - dbg("speedtch_upload_firmware: write BLOCK1 to modem failed (%d)!", ret); 221 - goto fail_release; 496 + usb_dbg(usbatm, "%s: write BLOCK1 to modem failed (%d)!\n", __func__, ret); 497 + goto out_free; 222 498 } 223 - dbg("speedtch_upload_firmware: BLOCK1 uploaded (%zu bytes)", fw1->size); 499 + usb_dbg(usbatm, "%s: BLOCK1 uploaded (%zu bytes)\n", __func__, fw1->size); 224 500 } 225 501 226 502 /* USB led blinking green, ADSL led off */ 227 503 228 504 /* URB 11 */ 229 - ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 505 + ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), 230 506 buffer, 0x200, &actual_length, DATA_TIMEOUT); 231 507 232 508 if (ret < 0) { 233 - dbg("speedtch_upload_firmware: read BLOCK2 from modem failed (%d)!", ret); 234 - goto fail_release; 509 + usb_dbg(usbatm, "%s: read BLOCK2 from modem failed (%d)!\n", __func__, ret); 510 + goto out_free; 235 511 } 236 - dbg("speedtch_upload_firmware: BLOCK2 downloaded (%d bytes)", actual_length); 512 + usb_dbg(usbatm, "%s: BLOCK2 downloaded (%d bytes)\n", __func__, actual_length); 237 513 238 514 /* URBs 12 to 139 - USB led blinking green, ADSL led off */ 239 515 for (offset = 0; offset < fw2->size; offset += PAGE_SIZE) { 240 516 int thislen = min_t(int, PAGE_SIZE, fw2->size - offset); 241 517 memcpy(buffer, fw2->data + offset, thislen); 242 518 243 - ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 519 + ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, ENDPOINT_FIRMWARE), 244 520 buffer, thislen, &actual_length, DATA_TIMEOUT); 245 521 246 522 if (ret < 0) { 247 - dbg("speedtch_upload_firmware: write BLOCK3 to modem failed (%d)!", ret); 248 - goto fail_release; 523 + usb_dbg(usbatm, "%s: write BLOCK3 to modem failed (%d)!\n", __func__, ret); 524 + goto out_free; 249 525 } 250 526 } 251 - dbg("speedtch_upload_firmware: BLOCK3 uploaded (%zu bytes)", fw2->size); 527 + usb_dbg(usbatm, "%s: BLOCK3 uploaded (%zu bytes)\n", __func__, fw2->size); 252 528 253 529 /* USB led static green, ADSL led static red */ 254 530 255 531 /* URB 142 */ 256 - ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, SPEEDTCH_ENDPOINT_FIRMWARE), 532 + ret = usb_bulk_msg(usb_dev, usb_rcvbulkpipe(usb_dev, ENDPOINT_FIRMWARE), 257 533 buffer, 0x200, &actual_length, DATA_TIMEOUT); 258 534 259 535 if (ret < 0) { 260 - dbg("speedtch_upload_firmware: read BLOCK4 from modem failed (%d)!", ret); 261 - goto fail_release; 536 + usb_dbg(usbatm, "%s: read BLOCK4 from modem failed (%d)!\n", __func__, ret); 537 + goto out_free; 262 538 } 263 539 264 540 /* success */ 265 - dbg("speedtch_upload_firmware: BLOCK4 downloaded (%d bytes)", actual_length); 541 + usb_dbg(usbatm, "%s: BLOCK4 downloaded (%d bytes)\n", __func__, actual_length); 266 542 267 543 /* Delay to allow firmware to start up. We can do this here 268 544 because we're in our own kernel thread anyway. */ 269 - msleep(1000); 545 + msleep_interruptible(1000); 270 546 271 547 /* Enable software buffering, if requested */ 272 548 if (sw_buffering) ··· 275 551 /* Magic spell; don't ask us what this does */ 276 552 speedtch_test_sequence(instance); 277 553 278 - /* Start modem synchronisation */ 279 - if (speedtch_start_synchro(instance)) 280 - dbg("speedtch_start_synchro: failed"); 554 + ret = 0; 281 555 282 - speedtch_got_firmware(instance, 1); 283 - 556 + out_free: 284 557 free_page((unsigned long)buffer); 285 - return; 286 - 287 - fail_release: 288 - /* Only release interface #2 if uploading failed; we don't release it 289 - we succeeded. This prevents the userspace tools from trying to load 290 - the firmware themselves */ 291 - usb_driver_release_interface(&speedtch_usb_driver, intf); 292 - fail_free: 293 - free_page((unsigned long)buffer); 294 - fail: 295 - speedtch_got_firmware(instance, 0); 558 + out: 559 + return ret; 296 560 } 297 561 298 - static int speedtch_find_firmware(struct speedtch_instance_data 299 - *instance, int phase, 562 + static int speedtch_find_firmware(struct usb_interface *intf, int phase, 300 563 const struct firmware **fw_p) 301 564 { 302 - char buf[24]; 303 - const u16 bcdDevice = le16_to_cpu(instance->u.usb_dev->descriptor.bcdDevice); 565 + struct device *dev = &intf->dev; 566 + const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice); 304 567 const u8 major_revision = bcdDevice >> 8; 305 568 const u8 minor_revision = bcdDevice & 0xff; 569 + char buf[24]; 306 570 307 571 sprintf(buf, "speedtch-%d.bin.%x.%02x", phase, major_revision, minor_revision); 308 - dbg("speedtch_find_firmware: looking for %s", buf); 572 + dev_dbg(dev, "%s: looking for %s\n", __func__, buf); 309 573 310 - if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { 574 + if (request_firmware(fw_p, buf, dev)) { 311 575 sprintf(buf, "speedtch-%d.bin.%x", phase, major_revision); 312 - dbg("speedtch_find_firmware: looking for %s", buf); 576 + dev_dbg(dev, "%s: looking for %s\n", __func__, buf); 313 577 314 - if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { 578 + if (request_firmware(fw_p, buf, dev)) { 315 579 sprintf(buf, "speedtch-%d.bin", phase); 316 - dbg("speedtch_find_firmware: looking for %s", buf); 580 + dev_dbg(dev, "%s: looking for %s\n", __func__, buf); 317 581 318 - if (request_firmware(fw_p, buf, &instance->u.usb_dev->dev)) { 319 - dev_warn(&instance->u.usb_dev->dev, "no stage %d firmware found!", phase); 582 + if (request_firmware(fw_p, buf, dev)) { 583 + dev_warn(dev, "no stage %d firmware found!\n", phase); 320 584 return -ENOENT; 321 585 } 322 586 } 323 587 } 324 588 325 - dev_info(&instance->u.usb_dev->dev, "found stage %d firmware %s\n", phase, buf); 589 + dev_info(dev, "found stage %d firmware %s\n", phase, buf); 326 590 327 591 return 0; 328 592 } 329 593 330 - static int speedtch_load_firmware(void *arg) 594 + static int speedtch_heavy_init(struct usbatm_data *usbatm, struct usb_interface *intf) 331 595 { 332 596 const struct firmware *fw1, *fw2; 333 - struct speedtch_instance_data *instance = arg; 597 + struct speedtch_instance_data *instance = usbatm->driver_data; 598 + int ret; 334 599 335 - BUG_ON(!instance); 600 + if ((ret = speedtch_find_firmware(intf, 1, &fw1)) < 0) 601 + return ret; 336 602 337 - daemonize("firmware/speedtch"); 338 - 339 - if (!speedtch_find_firmware(instance, 1, &fw1)) { 340 - if (!speedtch_find_firmware(instance, 2, &fw2)) { 341 - speedtch_upload_firmware(instance, fw1, fw2); 342 - release_firmware(fw2); 343 - } 603 + if ((ret = speedtch_find_firmware(intf, 2, &fw2)) < 0) { 344 604 release_firmware(fw1); 605 + return ret; 345 606 } 346 607 347 - /* In case we failed, set state back to NO_FIRMWARE so that 348 - another later attempt may work. Otherwise, we never actually 349 - manage to recover if, for example, the firmware is on /usr and 350 - we look for it too early. */ 351 - speedtch_got_firmware(instance, 0); 608 + ret = speedtch_upload_firmware(instance, fw1, fw2); 352 609 353 - module_put(THIS_MODULE); 354 - udsl_put_instance(&instance->u); 610 + release_firmware(fw2); 611 + release_firmware(fw1); 612 + 613 + return ret; 614 + } 615 + 616 + 617 + /********** 618 + ** ATM ** 619 + **********/ 620 + 621 + static int speedtch_read_status(struct speedtch_instance_data *instance) 622 + { 623 + struct usbatm_data *usbatm = instance->usbatm; 624 + struct usb_device *usb_dev = usbatm->usb_dev; 625 + unsigned char *buf = instance->scratch_buffer; 626 + int ret; 627 + 628 + memset(buf, 0, TOTAL); 629 + 630 + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), 631 + 0x12, 0xc0, 0x07, 0x00, buf + OFFSET_7, SIZE_7, 632 + CTRL_TIMEOUT); 633 + if (ret < 0) { 634 + atm_dbg(usbatm, "%s: MSG 7 failed\n", __func__); 635 + return ret; 636 + } 637 + 638 + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), 639 + 0x12, 0xc0, 0x0b, 0x00, buf + OFFSET_b, SIZE_b, 640 + CTRL_TIMEOUT); 641 + if (ret < 0) { 642 + atm_dbg(usbatm, "%s: MSG B failed\n", __func__); 643 + return ret; 644 + } 645 + 646 + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), 647 + 0x12, 0xc0, 0x0d, 0x00, buf + OFFSET_d, SIZE_d, 648 + CTRL_TIMEOUT); 649 + if (ret < 0) { 650 + atm_dbg(usbatm, "%s: MSG D failed\n", __func__); 651 + return ret; 652 + } 653 + 654 + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), 655 + 0x01, 0xc0, 0x0e, 0x00, buf + OFFSET_e, SIZE_e, 656 + CTRL_TIMEOUT); 657 + if (ret < 0) { 658 + atm_dbg(usbatm, "%s: MSG E failed\n", __func__); 659 + return ret; 660 + } 661 + 662 + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), 663 + 0x01, 0xc0, 0x0f, 0x00, buf + OFFSET_f, SIZE_f, 664 + CTRL_TIMEOUT); 665 + if (ret < 0) { 666 + atm_dbg(usbatm, "%s: MSG F failed\n", __func__); 667 + return ret; 668 + } 669 + 355 670 return 0; 356 671 } 357 - #endif /* USE_FW_LOADER */ 358 672 359 - static void speedtch_firmware_start(struct speedtch_instance_data *instance) 673 + static int speedtch_start_synchro(struct speedtch_instance_data *instance) 360 674 { 361 - #ifdef USE_FW_LOADER 675 + struct usbatm_data *usbatm = instance->usbatm; 676 + struct usb_device *usb_dev = usbatm->usb_dev; 677 + unsigned char *buf = instance->scratch_buffer; 362 678 int ret; 363 - #endif 364 679 365 - dbg("speedtch_firmware_start"); 680 + atm_dbg(usbatm, "%s entered\n", __func__); 366 681 367 - down(&instance->u.serialize); /* vs self, speedtch_got_firmware */ 682 + memset(buf, 0, 2); 368 683 369 - if (instance->u.status >= UDSL_LOADING_FIRMWARE) { 370 - up(&instance->u.serialize); 684 + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), 685 + 0x12, 0xc0, 0x04, 0x00, 686 + buf, 2, CTRL_TIMEOUT); 687 + 688 + if (ret < 0) 689 + atm_warn(usbatm, "failed to start ADSL synchronisation: %d\n", ret); 690 + else 691 + atm_dbg(usbatm, "%s: modem prodded. %d bytes returned: %02x %02x\n", 692 + __func__, ret, buf[0], buf[1]); 693 + 694 + return ret; 695 + } 696 + 697 + static void speedtch_check_status(struct speedtch_instance_data *instance) 698 + { 699 + struct usbatm_data *usbatm = instance->usbatm; 700 + struct atm_dev *atm_dev = usbatm->atm_dev; 701 + unsigned char *buf = instance->scratch_buffer; 702 + int ret; 703 + 704 + atm_dbg(usbatm, "%s entered\n", __func__); 705 + 706 + ret = speedtch_read_status(instance); 707 + if (ret < 0) { 708 + atm_warn(usbatm, "error %d fetching device status\n", ret); 709 + if (instance->poll_delay < MAX_POLL_DELAY) 710 + instance->poll_delay *= 2; 371 711 return; 372 712 } 373 713 374 - instance->u.status = UDSL_LOADING_FIRMWARE; 375 - up(&instance->u.serialize); 714 + if (instance->poll_delay > MIN_POLL_DELAY) 715 + instance->poll_delay /= 2; 376 716 377 - #ifdef USE_FW_LOADER 378 - udsl_get_instance(&instance->u); 379 - try_module_get(THIS_MODULE); 717 + atm_dbg(usbatm, "%s: line state %02x\n", __func__, buf[OFFSET_7]); 380 718 381 - ret = kernel_thread(speedtch_load_firmware, instance, 382 - CLONE_FS | CLONE_FILES); 719 + switch (buf[OFFSET_7]) { 720 + case 0: 721 + if (atm_dev->signal != ATM_PHY_SIG_LOST) { 722 + atm_dev->signal = ATM_PHY_SIG_LOST; 723 + atm_info(usbatm, "ADSL line is down\n"); 724 + /* It'll never resync again unless we ask it to... */ 725 + ret = speedtch_start_synchro(instance); 726 + } 727 + break; 383 728 384 - if (ret >= 0) 385 - return; /* OK */ 729 + case 0x08: 730 + if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { 731 + atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 732 + atm_info(usbatm, "ADSL line is blocked?\n"); 733 + } 734 + break; 386 735 387 - dbg("speedtch_firmware_start: kernel_thread failed (%d)!", ret); 736 + case 0x10: 737 + if (atm_dev->signal != ATM_PHY_SIG_LOST) { 738 + atm_dev->signal = ATM_PHY_SIG_LOST; 739 + atm_info(usbatm, "ADSL line is synchronising\n"); 740 + } 741 + break; 388 742 389 - module_put(THIS_MODULE); 390 - udsl_put_instance(&instance->u); 391 - /* Just pretend it never happened... hope modem_run happens */ 392 - #endif /* USE_FW_LOADER */ 743 + case 0x20: 744 + if (atm_dev->signal != ATM_PHY_SIG_FOUND) { 745 + int down_speed = buf[OFFSET_b] | (buf[OFFSET_b + 1] << 8) 746 + | (buf[OFFSET_b + 2] << 16) | (buf[OFFSET_b + 3] << 24); 747 + int up_speed = buf[OFFSET_b + 4] | (buf[OFFSET_b + 5] << 8) 748 + | (buf[OFFSET_b + 6] << 16) | (buf[OFFSET_b + 7] << 24); 393 749 394 - speedtch_got_firmware(instance, 0); 750 + if (!(down_speed & 0x0000ffff) && !(up_speed & 0x0000ffff)) { 751 + down_speed >>= 16; 752 + up_speed >>= 16; 753 + } 754 + 755 + atm_dev->link_rate = down_speed * 1000 / 424; 756 + atm_dev->signal = ATM_PHY_SIG_FOUND; 757 + 758 + atm_info(usbatm, 759 + "ADSL line is up (%d Kib/s down | %d Kib/s up)\n", 760 + down_speed, up_speed); 761 + } 762 + break; 763 + 764 + default: 765 + if (atm_dev->signal != ATM_PHY_SIG_UNKNOWN) { 766 + atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 767 + atm_info(usbatm, "Unknown line state %02x\n", buf[OFFSET_7]); 768 + } 769 + break; 770 + } 395 771 } 396 772 397 - static int speedtch_firmware_wait(struct udsl_instance_data *instance) 773 + static void speedtch_status_poll(unsigned long data) 398 774 { 399 - speedtch_firmware_start((void *)instance); 775 + struct speedtch_instance_data *instance = (void *)data; 400 776 401 - if (wait_event_interruptible(instance->firmware_waiters, instance->status != UDSL_LOADING_FIRMWARE) < 0) 402 - return -ERESTARTSYS; 777 + schedule_work(&instance->status_checker); 403 778 404 - return (instance->status == UDSL_LOADED_FIRMWARE) ? 0 : -EAGAIN; 779 + /* The following check is racy, but the race is harmless */ 780 + if (instance->poll_delay < MAX_POLL_DELAY) 781 + mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(instance->poll_delay)); 782 + else 783 + atm_warn(instance->usbatm, "Too many failures - disabling line status polling\n"); 405 784 } 785 + 786 + static void speedtch_resubmit_int(unsigned long data) 787 + { 788 + struct speedtch_instance_data *instance = (void *)data; 789 + struct urb *int_urb = instance->int_urb; 790 + int ret; 791 + 792 + atm_dbg(instance->usbatm, "%s entered\n", __func__); 793 + 794 + if (int_urb) { 795 + ret = usb_submit_urb(int_urb, GFP_ATOMIC); 796 + if (!ret) 797 + schedule_work(&instance->status_checker); 798 + else { 799 + atm_dbg(instance->usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); 800 + mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); 801 + } 802 + } 803 + } 804 + 805 + static void speedtch_handle_int(struct urb *int_urb, struct pt_regs *regs) 806 + { 807 + struct speedtch_instance_data *instance = int_urb->context; 808 + struct usbatm_data *usbatm = instance->usbatm; 809 + unsigned int count = int_urb->actual_length; 810 + int ret = int_urb->status; 811 + 812 + /* The magic interrupt for "up state" */ 813 + const static unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; 814 + /* The magic interrupt for "down state" */ 815 + const static unsigned char down_int[6] = { 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00 }; 816 + 817 + atm_dbg(usbatm, "%s entered\n", __func__); 818 + 819 + if (ret < 0) { 820 + atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, ret); 821 + goto fail; 822 + } 823 + 824 + if ((count == 6) && !memcmp(up_int, instance->int_data, 6)) { 825 + del_timer(&instance->status_checker.timer); 826 + atm_info(usbatm, "DSL line goes up\n"); 827 + } else if ((count == 6) && !memcmp(down_int, instance->int_data, 6)) { 828 + atm_info(usbatm, "DSL line goes down\n"); 829 + } else { 830 + int i; 831 + 832 + atm_dbg(usbatm, "%s: unknown interrupt packet of length %d:", __func__, count); 833 + for (i = 0; i < count; i++) 834 + printk(" %02x", instance->int_data[i]); 835 + printk("\n"); 836 + goto fail; 837 + } 838 + 839 + if ((int_urb = instance->int_urb)) { 840 + ret = usb_submit_urb(int_urb, GFP_ATOMIC); 841 + schedule_work(&instance->status_checker); 842 + if (ret < 0) { 843 + atm_dbg(usbatm, "%s: usb_submit_urb failed with result %d\n", __func__, ret); 844 + goto fail; 845 + } 846 + } 847 + 848 + return; 849 + 850 + fail: 851 + if ((int_urb = instance->int_urb)) 852 + mod_timer(&instance->resubmit_timer, jiffies + msecs_to_jiffies(RESUBMIT_DELAY)); 853 + } 854 + 855 + static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_dev) 856 + { 857 + struct usb_device *usb_dev = usbatm->usb_dev; 858 + struct speedtch_instance_data *instance = usbatm->driver_data; 859 + int i, ret; 860 + unsigned char mac_str[13]; 861 + 862 + atm_dbg(usbatm, "%s entered\n", __func__); 863 + 864 + if ((ret = usb_set_interface(usb_dev, 1, altsetting)) < 0) { 865 + atm_dbg(usbatm, "%s: usb_set_interface returned %d!\n", __func__, ret); 866 + return ret; 867 + } 868 + 869 + /* Set MAC address, it is stored in the serial number */ 870 + memset(atm_dev->esi, 0, sizeof(atm_dev->esi)); 871 + if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { 872 + for (i = 0; i < 6; i++) 873 + atm_dev->esi[i] = (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1])); 874 + } 875 + 876 + /* Start modem synchronisation */ 877 + ret = speedtch_start_synchro(instance); 878 + 879 + /* Set up interrupt endpoint */ 880 + if (instance->int_urb) { 881 + ret = usb_submit_urb(instance->int_urb, GFP_KERNEL); 882 + if (ret < 0) { 883 + /* Doesn't matter; we'll poll anyway */ 884 + atm_dbg(usbatm, "%s: submission of interrupt URB failed (%d)!\n", __func__, ret); 885 + usb_free_urb(instance->int_urb); 886 + instance->int_urb = NULL; 887 + } 888 + } 889 + 890 + /* Start status polling */ 891 + mod_timer(&instance->status_checker.timer, jiffies + msecs_to_jiffies(1000)); 892 + 893 + return 0; 894 + } 895 + 896 + static void speedtch_atm_stop(struct usbatm_data *usbatm, struct atm_dev *atm_dev) 897 + { 898 + struct speedtch_instance_data *instance = usbatm->driver_data; 899 + struct urb *int_urb = instance->int_urb; 900 + 901 + atm_dbg(usbatm, "%s entered\n", __func__); 902 + 903 + del_timer_sync(&instance->status_checker.timer); 904 + 905 + /* 906 + * Since resubmit_timer and int_urb can schedule themselves and 907 + * each other, shutting them down correctly takes some care 908 + */ 909 + instance->int_urb = NULL; /* signal shutdown */ 910 + mb(); 911 + usb_kill_urb(int_urb); 912 + del_timer_sync(&instance->resubmit_timer); 913 + /* 914 + * At this point, speedtch_handle_int and speedtch_resubmit_int 915 + * can run or be running, but instance->int_urb == NULL means that 916 + * they will not reschedule 917 + */ 918 + usb_kill_urb(int_urb); 919 + del_timer_sync(&instance->resubmit_timer); 920 + usb_free_urb(int_urb); 921 + 922 + flush_scheduled_work(); 923 + } 924 + 406 925 407 926 /********** 408 927 ** USB ** 409 928 **********/ 410 929 411 - static int speedtch_usb_ioctl(struct usb_interface *intf, unsigned int code, 412 - void *user_data) 413 - { 414 - struct speedtch_instance_data *instance = usb_get_intfdata(intf); 930 + static struct usb_device_id speedtch_usb_ids[] = { 931 + {USB_DEVICE(0x06b9, 0x4061)}, 932 + {} 933 + }; 415 934 416 - dbg("speedtch_usb_ioctl entered"); 935 + MODULE_DEVICE_TABLE(usb, speedtch_usb_ids); 417 936 418 - if (!instance) { 419 - dbg("speedtch_usb_ioctl: NULL instance!"); 420 - return -ENODEV; 421 - } 937 + static int speedtch_usb_probe(struct usb_interface *, const struct usb_device_id *); 422 938 423 - switch (code) { 424 - case UDSL_IOCTL_LINE_UP: 425 - instance->u.atm_dev->signal = ATM_PHY_SIG_FOUND; 426 - speedtch_got_firmware(instance, 1); 427 - return (instance->u.status == UDSL_LOADED_FIRMWARE) ? 0 : -EIO; 428 - case UDSL_IOCTL_LINE_DOWN: 429 - instance->u.atm_dev->signal = ATM_PHY_SIG_LOST; 430 - return 0; 431 - default: 432 - return -ENOTTY; 433 - } 939 + static struct usb_driver speedtch_usb_driver = { 940 + .owner = THIS_MODULE, 941 + .name = speedtch_driver_name, 942 + .probe = speedtch_usb_probe, 943 + .disconnect = usbatm_usb_disconnect, 944 + .id_table = speedtch_usb_ids 945 + }; 946 + 947 + static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) { 948 + struct usb_interface *cur_intf; 949 + int i; 950 + 951 + for(i = 0; i < num_interfaces; i++) 952 + if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) { 953 + usb_set_intfdata(cur_intf, NULL); 954 + usb_driver_release_interface(&speedtch_usb_driver, cur_intf); 955 + } 434 956 } 435 957 436 - static int speedtch_usb_probe(struct usb_interface *intf, 437 - const struct usb_device_id *id) 958 + static int speedtch_bind(struct usbatm_data *usbatm, 959 + struct usb_interface *intf, 960 + const struct usb_device_id *id, 961 + int *need_heavy_init) 438 962 { 439 - struct usb_device *dev = interface_to_usbdev(intf); 440 - int ifnum = intf->altsetting->desc.bInterfaceNumber; 963 + struct usb_device *usb_dev = interface_to_usbdev(intf); 964 + struct usb_interface *cur_intf; 441 965 struct speedtch_instance_data *instance; 442 - unsigned char mac_str[13]; 443 - int ret, i; 444 - char buf7[SIZE_7]; 966 + int ifnum = intf->altsetting->desc.bInterfaceNumber; 967 + int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces; 968 + int i, ret; 445 969 446 - dbg("speedtch_usb_probe: trying device with vendor=0x%x, product=0x%x, ifnum %d", 447 - le16_to_cpu(dev->descriptor.idVendor), 448 - le16_to_cpu(dev->descriptor.idProduct), ifnum); 970 + usb_dbg(usbatm, "%s entered\n", __func__); 449 971 450 - if ((dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) || 451 - (ifnum != 1)) 972 + if (usb_dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) { 973 + usb_dbg(usbatm, "%s: wrong device class %d\n", __func__, usb_dev->descriptor.bDeviceClass); 452 974 return -ENODEV; 975 + } 453 976 454 - dbg("speedtch_usb_probe: device accepted"); 977 + /* claim all interfaces */ 455 978 456 - /* instance init */ 979 + for (i=0; i < num_interfaces; i++) { 980 + cur_intf = usb_ifnum_to_if(usb_dev, i); 981 + 982 + if ((i != ifnum) && cur_intf) { 983 + ret = usb_driver_claim_interface(&speedtch_usb_driver, cur_intf, usbatm); 984 + 985 + if (ret < 0) { 986 + usb_dbg(usbatm, "%s: failed to claim interface %d (%d)\n", __func__, i, ret); 987 + speedtch_release_interfaces(usb_dev, i); 988 + return ret; 989 + } 990 + } 991 + } 992 + 457 993 instance = kmalloc(sizeof(*instance), GFP_KERNEL); 994 + 458 995 if (!instance) { 459 - dbg("speedtch_usb_probe: no memory for instance data!"); 460 - return -ENOMEM; 996 + usb_dbg(usbatm, "%s: no memory for instance data!\n", __func__); 997 + ret = -ENOMEM; 998 + goto fail_release; 461 999 } 462 1000 463 1001 memset(instance, 0, sizeof(struct speedtch_instance_data)); 464 1002 465 - if ((ret = usb_set_interface(dev, 0, 0)) < 0) 466 - goto fail; 1003 + instance->usbatm = usbatm; 467 1004 468 - if ((ret = usb_set_interface(dev, 2, 0)) < 0) 469 - goto fail; 1005 + INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance); 470 1006 471 - instance->u.data_endpoint = SPEEDTCH_ENDPOINT_DATA; 472 - instance->u.firmware_wait = speedtch_firmware_wait; 473 - instance->u.driver_name = speedtch_driver_name; 1007 + instance->status_checker.timer.function = speedtch_status_poll; 1008 + instance->status_checker.timer.data = (unsigned long)instance; 1009 + instance->poll_delay = MIN_POLL_DELAY; 474 1010 475 - ret = udsl_instance_setup(dev, &instance->u); 476 - if (ret) 477 - goto fail; 1011 + init_timer(&instance->resubmit_timer); 1012 + instance->resubmit_timer.function = speedtch_resubmit_int; 1013 + instance->resubmit_timer.data = (unsigned long)instance; 478 1014 479 - init_timer(&instance->poll_timer); 480 - instance->poll_timer.function = speedtch_timer_poll; 481 - instance->poll_timer.data = (unsigned long)instance; 1015 + instance->int_urb = usb_alloc_urb(0, GFP_KERNEL); 482 1016 483 - INIT_WORK(&instance->poll_work, (void *)speedtch_poll_status, instance); 1017 + if (instance->int_urb) 1018 + usb_fill_int_urb(instance->int_urb, usb_dev, 1019 + usb_rcvintpipe(usb_dev, ENDPOINT_INT), 1020 + instance->int_data, sizeof(instance->int_data), 1021 + speedtch_handle_int, instance, 50); 1022 + else 1023 + usb_dbg(usbatm, "%s: no memory for interrupt urb!\n", __func__); 484 1024 485 - /* set MAC address, it is stored in the serial number */ 486 - memset(instance->u.atm_dev->esi, 0, sizeof(instance->u.atm_dev->esi)); 487 - if (usb_string(dev, dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) { 488 - for (i = 0; i < 6; i++) 489 - instance->u.atm_dev->esi[i] = 490 - (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1])); 491 - } 1025 + /* check whether the modem already seems to be alive */ 1026 + ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0), 1027 + 0x12, 0xc0, 0x07, 0x00, 1028 + instance->scratch_buffer + OFFSET_7, SIZE_7, 500); 492 1029 493 - /* First check whether the modem already seems to be alive */ 494 - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 495 - 0x12, 0xc0, 0x07, 0x00, buf7, SIZE_7, 500); 1030 + *need_heavy_init = (ret != SIZE_7); 496 1031 497 - if (ret == SIZE_7) { 498 - dbg("firmware appears to be already loaded"); 499 - speedtch_got_firmware(instance, 1); 500 - speedtch_poll_status(instance); 501 - } else { 502 - speedtch_firmware_start(instance); 503 - } 1032 + usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, need_heavy_init ? "not" : "already"); 504 1033 505 - usb_set_intfdata(intf, instance); 1034 + if (*need_heavy_init) 1035 + if ((ret = usb_reset_device(usb_dev)) < 0) 1036 + goto fail_free; 1037 + 1038 + usbatm->driver_data = instance; 506 1039 507 1040 return 0; 508 1041 509 - fail: 1042 + fail_free: 1043 + usb_free_urb(instance->int_urb); 510 1044 kfree(instance); 511 - 512 - return -ENOMEM; 1045 + fail_release: 1046 + speedtch_release_interfaces(usb_dev, num_interfaces); 1047 + return ret; 513 1048 } 514 1049 515 - static void speedtch_usb_disconnect(struct usb_interface *intf) 1050 + static void speedtch_unbind(struct usbatm_data *usbatm, struct usb_interface *intf) 516 1051 { 517 - struct speedtch_instance_data *instance = usb_get_intfdata(intf); 1052 + struct usb_device *usb_dev = interface_to_usbdev(intf); 1053 + struct speedtch_instance_data *instance = usbatm->driver_data; 518 1054 519 - dbg("speedtch_usb_disconnect entered"); 1055 + usb_dbg(usbatm, "%s entered\n", __func__); 520 1056 521 - if (!instance) { 522 - dbg("speedtch_usb_disconnect: NULL instance!"); 523 - return; 524 - } 525 - 526 - /*QQ need to handle disconnects on interface #2 while uploading firmware */ 527 - /*QQ and what about interface #1? */ 528 - 529 - if (instance->int_urb) { 530 - struct urb *int_urb = instance->int_urb; 531 - instance->int_urb = NULL; 532 - wmb(); 533 - usb_unlink_urb(int_urb); 534 - usb_free_urb(int_urb); 535 - } 536 - 537 - instance->int_data[0] = 1; 538 - del_timer_sync(&instance->poll_timer); 539 - wmb(); 540 - flush_scheduled_work(); 541 - 542 - udsl_instance_disconnect(&instance->u); 543 - 544 - /* clean up */ 545 - usb_set_intfdata(intf, NULL); 546 - udsl_put_instance(&instance->u); 1057 + speedtch_release_interfaces(usb_dev, usb_dev->actconfig->desc.bNumInterfaces); 1058 + usb_free_urb(instance->int_urb); 1059 + kfree(instance); 547 1060 } 1061 + 548 1062 549 1063 /*********** 550 1064 ** init ** 551 1065 ***********/ 552 1066 1067 + static struct usbatm_driver speedtch_usbatm_driver = { 1068 + .owner = THIS_MODULE, 1069 + .driver_name = speedtch_driver_name, 1070 + .bind = speedtch_bind, 1071 + .heavy_init = speedtch_heavy_init, 1072 + .unbind = speedtch_unbind, 1073 + .atm_start = speedtch_atm_start, 1074 + .atm_stop = speedtch_atm_stop, 1075 + .in = ENDPOINT_DATA, 1076 + .out = ENDPOINT_DATA 1077 + }; 1078 + 1079 + static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) 1080 + { 1081 + return usbatm_usb_probe(intf, id, &speedtch_usbatm_driver); 1082 + } 1083 + 553 1084 static int __init speedtch_usb_init(void) 554 1085 { 555 - dbg("speedtch_usb_init: driver version " DRIVER_VERSION); 1086 + dbg("%s: driver version %s", __func__, DRIVER_VERSION); 556 1087 557 1088 return usb_register(&speedtch_usb_driver); 558 1089 } 559 1090 560 1091 static void __exit speedtch_usb_cleanup(void) 561 1092 { 562 - dbg("speedtch_usb_cleanup entered"); 1093 + dbg("%s", __func__); 563 1094 564 1095 usb_deregister(&speedtch_usb_driver); 565 1096 }
-1188
drivers/usb/atm/usb_atm.c
··· 1 - /****************************************************************************** 2 - * usb_atm.c - Generic USB xDSL driver core 3 - * 4 - * Copyright (C) 2001, Alcatel 5 - * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas 6 - * Copyright (C) 2004, David Woodhouse 7 - * 8 - * 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 10 - * Software Foundation; either version 2 of the License, or (at your option) 11 - * any later version. 12 - * 13 - * This program is distributed in the hope that it will be useful, but WITHOUT 14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 - * more details. 17 - * 18 - * You should have received a copy of the GNU General Public License along with 19 - * this program; if not, write to the Free Software Foundation, Inc., 59 20 - * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 - * 22 - ******************************************************************************/ 23 - 24 - /* 25 - * Written by Johan Verrept, maintained by Duncan Sands (duncan.sands@free.fr) 26 - * 27 - * 1.7+: - See the check-in logs 28 - * 29 - * 1.6: - No longer opens a connection if the firmware is not loaded 30 - * - Added support for the speedtouch 330 31 - * - Removed the limit on the number of devices 32 - * - Module now autoloads on device plugin 33 - * - Merged relevant parts of sarlib 34 - * - Replaced the kernel thread with a tasklet 35 - * - New packet transmission code 36 - * - Changed proc file contents 37 - * - Fixed all known SMP races 38 - * - Many fixes and cleanups 39 - * - Various fixes by Oliver Neukum (oliver@neukum.name) 40 - * 41 - * 1.5A: - Version for inclusion in 2.5 series kernel 42 - * - Modifications by Richard Purdie (rpurdie@rpsys.net) 43 - * - made compatible with kernel 2.5.6 onwards by changing 44 - * udsl_usb_send_data_context->urb to a pointer and adding code 45 - * to alloc and free it 46 - * - remove_wait_queue() added to udsl_atm_processqueue_thread() 47 - * 48 - * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL. 49 - * (reported by stephen.robinson@zen.co.uk) 50 - * 51 - * 1.4: - changed the spin_lock() under interrupt to spin_lock_irqsave() 52 - * - unlink all active send urbs of a vcc that is being closed. 53 - * 54 - * 1.3.1: - added the version number 55 - * 56 - * 1.3: - Added multiple send urb support 57 - * - fixed memory leak and vcc->tx_inuse starvation bug 58 - * when not enough memory left in vcc. 59 - * 60 - * 1.2: - Fixed race condition in udsl_usb_send_data() 61 - * 1.1: - Turned off packet debugging 62 - * 63 - */ 64 - 65 - #include <linux/module.h> 66 - #include <linux/moduleparam.h> 67 - #include <linux/kernel.h> 68 - #include <linux/sched.h> 69 - #include <linux/timer.h> 70 - #include <linux/errno.h> 71 - #include <linux/proc_fs.h> 72 - #include <linux/slab.h> 73 - #include <linux/wait.h> 74 - #include <linux/list.h> 75 - #include <asm/uaccess.h> 76 - #include <linux/smp_lock.h> 77 - #include <linux/interrupt.h> 78 - #include <linux/atm.h> 79 - #include <linux/atmdev.h> 80 - #include <linux/crc32.h> 81 - #include <linux/init.h> 82 - #include <linux/firmware.h> 83 - 84 - #include "usb_atm.h" 85 - 86 - #ifdef VERBOSE_DEBUG 87 - static int udsl_print_packet(const unsigned char *data, int len); 88 - #define PACKETDEBUG(arg...) udsl_print_packet (arg) 89 - #define vdbg(arg...) dbg (arg) 90 - #else 91 - #define PACKETDEBUG(arg...) 92 - #define vdbg(arg...) 93 - #endif 94 - 95 - #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 96 - #define DRIVER_VERSION "1.8" 97 - #define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION 98 - 99 - static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS; 100 - static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS; 101 - static unsigned int num_rcv_bufs = UDSL_DEFAULT_RCV_BUFS; 102 - static unsigned int num_snd_bufs = UDSL_DEFAULT_SND_BUFS; 103 - static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE; 104 - static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE; 105 - 106 - module_param(num_rcv_urbs, uint, 0444); 107 - MODULE_PARM_DESC(num_rcv_urbs, 108 - "Number of urbs used for reception (range: 0-" 109 - __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: " 110 - __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")"); 111 - 112 - module_param(num_snd_urbs, uint, 0444); 113 - MODULE_PARM_DESC(num_snd_urbs, 114 - "Number of urbs used for transmission (range: 0-" 115 - __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: " 116 - __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")"); 117 - 118 - module_param(num_rcv_bufs, uint, 0444); 119 - MODULE_PARM_DESC(num_rcv_bufs, 120 - "Number of buffers used for reception (range: 0-" 121 - __MODULE_STRING(UDSL_MAX_RCV_BUFS) ", default: " 122 - __MODULE_STRING(UDSL_DEFAULT_RCV_BUFS) ")"); 123 - 124 - module_param(num_snd_bufs, uint, 0444); 125 - MODULE_PARM_DESC(num_snd_bufs, 126 - "Number of buffers used for transmission (range: 0-" 127 - __MODULE_STRING(UDSL_MAX_SND_BUFS) ", default: " 128 - __MODULE_STRING(UDSL_DEFAULT_SND_BUFS) ")"); 129 - 130 - module_param(rcv_buf_size, uint, 0444); 131 - MODULE_PARM_DESC(rcv_buf_size, 132 - "Size of the buffers used for reception (range: 0-" 133 - __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: " 134 - __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")"); 135 - 136 - module_param(snd_buf_size, uint, 0444); 137 - MODULE_PARM_DESC(snd_buf_size, 138 - "Size of the buffers used for transmission (range: 0-" 139 - __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: " 140 - __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")"); 141 - 142 - /* ATM */ 143 - 144 - static void udsl_atm_dev_close(struct atm_dev *dev); 145 - static int udsl_atm_open(struct atm_vcc *vcc); 146 - static void udsl_atm_close(struct atm_vcc *vcc); 147 - static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg); 148 - static int udsl_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); 149 - static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page); 150 - 151 - static struct atmdev_ops udsl_atm_devops = { 152 - .dev_close = udsl_atm_dev_close, 153 - .open = udsl_atm_open, 154 - .close = udsl_atm_close, 155 - .ioctl = udsl_atm_ioctl, 156 - .send = udsl_atm_send, 157 - .proc_read = udsl_atm_proc_read, 158 - .owner = THIS_MODULE, 159 - }; 160 - 161 - /*********** 162 - ** misc ** 163 - ***********/ 164 - 165 - static inline void udsl_pop(struct atm_vcc *vcc, struct sk_buff *skb) 166 - { 167 - if (vcc->pop) 168 - vcc->pop(vcc, skb); 169 - else 170 - dev_kfree_skb(skb); 171 - } 172 - 173 - /************* 174 - ** decode ** 175 - *************/ 176 - 177 - static inline struct udsl_vcc_data *udsl_find_vcc(struct udsl_instance_data *instance, 178 - short vpi, int vci) 179 - { 180 - struct udsl_vcc_data *vcc; 181 - 182 - list_for_each_entry(vcc, &instance->vcc_list, list) 183 - if ((vcc->vci == vci) && (vcc->vpi == vpi)) 184 - return vcc; 185 - return NULL; 186 - } 187 - 188 - static void udsl_extract_cells(struct udsl_instance_data *instance, 189 - unsigned char *source, unsigned int howmany) 190 - { 191 - struct udsl_vcc_data *cached_vcc = NULL; 192 - struct atm_vcc *vcc; 193 - struct sk_buff *sarb; 194 - struct udsl_vcc_data *vcc_data; 195 - int cached_vci = 0; 196 - unsigned int i; 197 - int pti; 198 - int vci; 199 - short cached_vpi = 0; 200 - short vpi; 201 - 202 - for (i = 0; i < howmany; 203 - i++, source += ATM_CELL_SIZE + instance->rcv_padding) { 204 - vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4); 205 - vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4); 206 - pti = (source[3] & 0x2) != 0; 207 - 208 - vdbg("udsl_extract_cells: vpi %hd, vci %d, pti %d", vpi, vci, pti); 209 - 210 - if (cached_vcc && (vci == cached_vci) && (vpi == cached_vpi)) 211 - vcc_data = cached_vcc; 212 - else if ((vcc_data = udsl_find_vcc(instance, vpi, vci))) { 213 - cached_vcc = vcc_data; 214 - cached_vpi = vpi; 215 - cached_vci = vci; 216 - } else { 217 - dbg("udsl_extract_cells: unknown vpi/vci (%hd/%d)!", vpi, vci); 218 - continue; 219 - } 220 - 221 - vcc = vcc_data->vcc; 222 - sarb = vcc_data->sarb; 223 - 224 - if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) { 225 - dbg("udsl_extract_cells: buffer overrun (sarb->len %u, vcc: 0x%p)!", sarb->len, vcc); 226 - /* discard cells already received */ 227 - skb_trim(sarb, 0); 228 - } 229 - 230 - memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD); 231 - __skb_put(sarb, ATM_CELL_PAYLOAD); 232 - 233 - if (pti) { 234 - struct sk_buff *skb; 235 - unsigned int length; 236 - unsigned int pdu_length; 237 - 238 - length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5]; 239 - 240 - /* guard against overflow */ 241 - if (length > ATM_MAX_AAL5_PDU) { 242 - dbg("udsl_extract_cells: bogus length %u (vcc: 0x%p)!", length, vcc); 243 - atomic_inc(&vcc->stats->rx_err); 244 - goto out; 245 - } 246 - 247 - pdu_length = UDSL_NUM_CELLS(length) * ATM_CELL_PAYLOAD; 248 - 249 - if (sarb->len < pdu_length) { 250 - dbg("udsl_extract_cells: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!", pdu_length, sarb->len, vcc); 251 - atomic_inc(&vcc->stats->rx_err); 252 - goto out; 253 - } 254 - 255 - if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) { 256 - dbg("udsl_extract_cells: packet failed crc check (vcc: 0x%p)!", vcc); 257 - atomic_inc(&vcc->stats->rx_err); 258 - goto out; 259 - } 260 - 261 - vdbg("udsl_extract_cells: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", length, pdu_length, vcc); 262 - 263 - if (!(skb = dev_alloc_skb(length))) { 264 - dbg("udsl_extract_cells: no memory for skb (length: %u)!", length); 265 - atomic_inc(&vcc->stats->rx_drop); 266 - goto out; 267 - } 268 - 269 - vdbg("udsl_extract_cells: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", skb, skb->truesize); 270 - 271 - if (!atm_charge(vcc, skb->truesize)) { 272 - dbg("udsl_extract_cells: failed atm_charge (skb->truesize: %u)!", skb->truesize); 273 - dev_kfree_skb(skb); 274 - goto out; /* atm_charge increments rx_drop */ 275 - } 276 - 277 - memcpy(skb->data, sarb->tail - pdu_length, length); 278 - __skb_put(skb, length); 279 - 280 - vdbg("udsl_extract_cells: sending skb 0x%p, skb->len %u, skb->truesize %u", skb, skb->len, skb->truesize); 281 - 282 - PACKETDEBUG(skb->data, skb->len); 283 - 284 - vcc->push(vcc, skb); 285 - 286 - atomic_inc(&vcc->stats->rx); 287 - out: 288 - skb_trim(sarb, 0); 289 - } 290 - } 291 - } 292 - 293 - /************* 294 - ** encode ** 295 - *************/ 296 - 297 - static inline void udsl_fill_cell_header(unsigned char *target, struct atm_vcc *vcc) 298 - { 299 - target[0] = vcc->vpi >> 4; 300 - target[1] = (vcc->vpi << 4) | (vcc->vci >> 12); 301 - target[2] = vcc->vci >> 4; 302 - target[3] = vcc->vci << 4; 303 - target[4] = 0xec; 304 - } 305 - 306 - static const unsigned char zeros[ATM_CELL_PAYLOAD]; 307 - 308 - static void udsl_groom_skb(struct atm_vcc *vcc, struct sk_buff *skb) 309 - { 310 - struct udsl_control *ctrl = UDSL_SKB(skb); 311 - unsigned int zero_padding; 312 - u32 crc; 313 - 314 - ctrl->atm_data.vcc = vcc; 315 - 316 - ctrl->num_cells = UDSL_NUM_CELLS(skb->len); 317 - ctrl->num_entire = skb->len / ATM_CELL_PAYLOAD; 318 - 319 - zero_padding = ctrl->num_cells * ATM_CELL_PAYLOAD - skb->len - ATM_AAL5_TRAILER; 320 - 321 - if (ctrl->num_entire + 1 < ctrl->num_cells) 322 - ctrl->pdu_padding = zero_padding - (ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER); 323 - else 324 - ctrl->pdu_padding = zero_padding; 325 - 326 - ctrl->aal5_trailer[0] = 0; /* UU = 0 */ 327 - ctrl->aal5_trailer[1] = 0; /* CPI = 0 */ 328 - ctrl->aal5_trailer[2] = skb->len >> 8; 329 - ctrl->aal5_trailer[3] = skb->len; 330 - 331 - crc = crc32_be(~0, skb->data, skb->len); 332 - crc = crc32_be(crc, zeros, zero_padding); 333 - crc = crc32_be(crc, ctrl->aal5_trailer, 4); 334 - crc = ~crc; 335 - 336 - ctrl->aal5_trailer[4] = crc >> 24; 337 - ctrl->aal5_trailer[5] = crc >> 16; 338 - ctrl->aal5_trailer[6] = crc >> 8; 339 - ctrl->aal5_trailer[7] = crc; 340 - } 341 - 342 - static unsigned int udsl_write_cells(struct udsl_instance_data *instance, 343 - unsigned int howmany, struct sk_buff *skb, 344 - unsigned char **target_p) 345 - { 346 - struct udsl_control *ctrl = UDSL_SKB(skb); 347 - unsigned char *target = *target_p; 348 - unsigned int nc, ne, i; 349 - 350 - vdbg("udsl_write_cells: howmany=%u, skb->len=%d, num_cells=%u, num_entire=%u, pdu_padding=%u", howmany, skb->len, ctrl->num_cells, ctrl->num_entire, ctrl->pdu_padding); 351 - 352 - nc = ctrl->num_cells; 353 - ne = min(howmany, ctrl->num_entire); 354 - 355 - for (i = 0; i < ne; i++) { 356 - udsl_fill_cell_header(target, ctrl->atm_data.vcc); 357 - target += ATM_CELL_HEADER; 358 - memcpy(target, skb->data, ATM_CELL_PAYLOAD); 359 - target += ATM_CELL_PAYLOAD; 360 - if (instance->snd_padding) { 361 - memset(target, 0, instance->snd_padding); 362 - target += instance->snd_padding; 363 - } 364 - __skb_pull(skb, ATM_CELL_PAYLOAD); 365 - } 366 - 367 - ctrl->num_entire -= ne; 368 - 369 - if (!(ctrl->num_cells -= ne) || !(howmany -= ne)) 370 - goto out; 371 - 372 - udsl_fill_cell_header(target, ctrl->atm_data.vcc); 373 - target += ATM_CELL_HEADER; 374 - memcpy(target, skb->data, skb->len); 375 - target += skb->len; 376 - __skb_pull(skb, skb->len); 377 - memset(target, 0, ctrl->pdu_padding); 378 - target += ctrl->pdu_padding; 379 - 380 - if (--ctrl->num_cells) { 381 - if (!--howmany) { 382 - ctrl->pdu_padding = ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER; 383 - goto out; 384 - } 385 - 386 - if (instance->snd_padding) { 387 - memset(target, 0, instance->snd_padding); 388 - target += instance->snd_padding; 389 - } 390 - udsl_fill_cell_header(target, ctrl->atm_data.vcc); 391 - target += ATM_CELL_HEADER; 392 - memset(target, 0, ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER); 393 - target += ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER; 394 - 395 - --ctrl->num_cells; 396 - UDSL_ASSERT(!ctrl->num_cells); 397 - } 398 - 399 - memcpy(target, ctrl->aal5_trailer, ATM_AAL5_TRAILER); 400 - target += ATM_AAL5_TRAILER; 401 - /* set pti bit in last cell */ 402 - *(target + 3 - ATM_CELL_SIZE) |= 0x2; 403 - if (instance->snd_padding) { 404 - memset(target, 0, instance->snd_padding); 405 - target += instance->snd_padding; 406 - } 407 - out: 408 - *target_p = target; 409 - return nc - ctrl->num_cells; 410 - } 411 - 412 - /************** 413 - ** receive ** 414 - **************/ 415 - 416 - static void udsl_complete_receive(struct urb *urb, struct pt_regs *regs) 417 - { 418 - struct udsl_receive_buffer *buf; 419 - struct udsl_instance_data *instance; 420 - struct udsl_receiver *rcv; 421 - unsigned long flags; 422 - 423 - if (!urb || !(rcv = urb->context)) { 424 - dbg("udsl_complete_receive: bad urb!"); 425 - return; 426 - } 427 - 428 - instance = rcv->instance; 429 - buf = rcv->buffer; 430 - 431 - buf->filled_cells = urb->actual_length / (ATM_CELL_SIZE + instance->rcv_padding); 432 - 433 - vdbg("udsl_complete_receive: urb 0x%p, status %d, actual_length %d, filled_cells %u, rcv 0x%p, buf 0x%p", urb, urb->status, urb->actual_length, buf->filled_cells, rcv, buf); 434 - 435 - UDSL_ASSERT(buf->filled_cells <= rcv_buf_size); 436 - 437 - /* may not be in_interrupt() */ 438 - spin_lock_irqsave(&instance->receive_lock, flags); 439 - list_add(&rcv->list, &instance->spare_receivers); 440 - list_add_tail(&buf->list, &instance->filled_receive_buffers); 441 - if (likely(!urb->status)) 442 - tasklet_schedule(&instance->receive_tasklet); 443 - spin_unlock_irqrestore(&instance->receive_lock, flags); 444 - } 445 - 446 - static void udsl_process_receive(unsigned long data) 447 - { 448 - struct udsl_receive_buffer *buf; 449 - struct udsl_instance_data *instance = (struct udsl_instance_data *)data; 450 - struct udsl_receiver *rcv; 451 - int err; 452 - 453 - made_progress: 454 - while (!list_empty(&instance->spare_receive_buffers)) { 455 - spin_lock_irq(&instance->receive_lock); 456 - if (list_empty(&instance->spare_receivers)) { 457 - spin_unlock_irq(&instance->receive_lock); 458 - break; 459 - } 460 - rcv = list_entry(instance->spare_receivers.next, 461 - struct udsl_receiver, list); 462 - list_del(&rcv->list); 463 - spin_unlock_irq(&instance->receive_lock); 464 - 465 - buf = list_entry(instance->spare_receive_buffers.next, 466 - struct udsl_receive_buffer, list); 467 - list_del(&buf->list); 468 - 469 - rcv->buffer = buf; 470 - 471 - usb_fill_bulk_urb(rcv->urb, instance->usb_dev, 472 - usb_rcvbulkpipe(instance->usb_dev, instance->data_endpoint), 473 - buf->base, 474 - rcv_buf_size * (ATM_CELL_SIZE + instance->rcv_padding), 475 - udsl_complete_receive, rcv); 476 - 477 - vdbg("udsl_process_receive: sending urb 0x%p, rcv 0x%p, buf 0x%p", 478 - rcv->urb, rcv, buf); 479 - 480 - if ((err = usb_submit_urb(rcv->urb, GFP_ATOMIC)) < 0) { 481 - dbg("udsl_process_receive: urb submission failed (%d)!", err); 482 - list_add(&buf->list, &instance->spare_receive_buffers); 483 - spin_lock_irq(&instance->receive_lock); 484 - list_add(&rcv->list, &instance->spare_receivers); 485 - spin_unlock_irq(&instance->receive_lock); 486 - break; 487 - } 488 - } 489 - 490 - spin_lock_irq(&instance->receive_lock); 491 - if (list_empty(&instance->filled_receive_buffers)) { 492 - spin_unlock_irq(&instance->receive_lock); 493 - return; /* done - no more buffers */ 494 - } 495 - buf = list_entry(instance->filled_receive_buffers.next, 496 - struct udsl_receive_buffer, list); 497 - list_del(&buf->list); 498 - spin_unlock_irq(&instance->receive_lock); 499 - 500 - vdbg("udsl_process_receive: processing buf 0x%p", buf); 501 - udsl_extract_cells(instance, buf->base, buf->filled_cells); 502 - list_add(&buf->list, &instance->spare_receive_buffers); 503 - goto made_progress; 504 - } 505 - 506 - /*********** 507 - ** send ** 508 - ***********/ 509 - 510 - static void udsl_complete_send(struct urb *urb, struct pt_regs *regs) 511 - { 512 - struct udsl_instance_data *instance; 513 - struct udsl_sender *snd; 514 - unsigned long flags; 515 - 516 - if (!urb || !(snd = urb->context) || !(instance = snd->instance)) { 517 - dbg("udsl_complete_send: bad urb!"); 518 - return; 519 - } 520 - 521 - vdbg("udsl_complete_send: urb 0x%p, status %d, snd 0x%p, buf 0x%p", urb, 522 - urb->status, snd, snd->buffer); 523 - 524 - /* may not be in_interrupt() */ 525 - spin_lock_irqsave(&instance->send_lock, flags); 526 - list_add(&snd->list, &instance->spare_senders); 527 - list_add(&snd->buffer->list, &instance->spare_send_buffers); 528 - tasklet_schedule(&instance->send_tasklet); 529 - spin_unlock_irqrestore(&instance->send_lock, flags); 530 - } 531 - 532 - static void udsl_process_send(unsigned long data) 533 - { 534 - struct udsl_send_buffer *buf; 535 - struct udsl_instance_data *instance = (struct udsl_instance_data *)data; 536 - struct sk_buff *skb; 537 - struct udsl_sender *snd; 538 - int err; 539 - unsigned int num_written; 540 - 541 - made_progress: 542 - spin_lock_irq(&instance->send_lock); 543 - while (!list_empty(&instance->spare_senders)) { 544 - if (!list_empty(&instance->filled_send_buffers)) { 545 - buf = list_entry(instance->filled_send_buffers.next, 546 - struct udsl_send_buffer, list); 547 - list_del(&buf->list); 548 - } else if ((buf = instance->current_buffer)) { 549 - instance->current_buffer = NULL; 550 - } else /* all buffers empty */ 551 - break; 552 - 553 - snd = list_entry(instance->spare_senders.next, 554 - struct udsl_sender, list); 555 - list_del(&snd->list); 556 - spin_unlock_irq(&instance->send_lock); 557 - 558 - snd->buffer = buf; 559 - usb_fill_bulk_urb(snd->urb, instance->usb_dev, 560 - usb_sndbulkpipe(instance->usb_dev, instance->data_endpoint), 561 - buf->base, 562 - (snd_buf_size - buf->free_cells) * (ATM_CELL_SIZE + instance->snd_padding), 563 - udsl_complete_send, snd); 564 - 565 - vdbg("udsl_process_send: submitting urb 0x%p (%d cells), snd 0x%p, buf 0x%p", 566 - snd->urb, snd_buf_size - buf->free_cells, snd, buf); 567 - 568 - if ((err = usb_submit_urb(snd->urb, GFP_ATOMIC)) < 0) { 569 - dbg("udsl_process_send: urb submission failed (%d)!", err); 570 - spin_lock_irq(&instance->send_lock); 571 - list_add(&snd->list, &instance->spare_senders); 572 - spin_unlock_irq(&instance->send_lock); 573 - list_add(&buf->list, &instance->filled_send_buffers); 574 - return; /* bail out */ 575 - } 576 - 577 - spin_lock_irq(&instance->send_lock); 578 - } /* while */ 579 - spin_unlock_irq(&instance->send_lock); 580 - 581 - if (!instance->current_skb) 582 - instance->current_skb = skb_dequeue(&instance->sndqueue); 583 - if (!instance->current_skb) 584 - return; /* done - no more skbs */ 585 - 586 - skb = instance->current_skb; 587 - 588 - if (!(buf = instance->current_buffer)) { 589 - spin_lock_irq(&instance->send_lock); 590 - if (list_empty(&instance->spare_send_buffers)) { 591 - instance->current_buffer = NULL; 592 - spin_unlock_irq(&instance->send_lock); 593 - return; /* done - no more buffers */ 594 - } 595 - buf = list_entry(instance->spare_send_buffers.next, 596 - struct udsl_send_buffer, list); 597 - list_del(&buf->list); 598 - spin_unlock_irq(&instance->send_lock); 599 - 600 - buf->free_start = buf->base; 601 - buf->free_cells = snd_buf_size; 602 - 603 - instance->current_buffer = buf; 604 - } 605 - 606 - num_written = udsl_write_cells(instance, buf->free_cells, skb, &buf->free_start); 607 - 608 - vdbg("udsl_process_send: wrote %u cells from skb 0x%p to buffer 0x%p", 609 - num_written, skb, buf); 610 - 611 - if (!(buf->free_cells -= num_written)) { 612 - list_add_tail(&buf->list, &instance->filled_send_buffers); 613 - instance->current_buffer = NULL; 614 - } 615 - 616 - vdbg("udsl_process_send: buffer contains %d cells, %d left", 617 - snd_buf_size - buf->free_cells, buf->free_cells); 618 - 619 - if (!UDSL_SKB(skb)->num_cells) { 620 - struct atm_vcc *vcc = UDSL_SKB(skb)->atm_data.vcc; 621 - 622 - udsl_pop(vcc, skb); 623 - instance->current_skb = NULL; 624 - 625 - atomic_inc(&vcc->stats->tx); 626 - } 627 - 628 - goto made_progress; 629 - } 630 - 631 - static void udsl_cancel_send(struct udsl_instance_data *instance, 632 - struct atm_vcc *vcc) 633 - { 634 - struct sk_buff *skb, *n; 635 - 636 - dbg("udsl_cancel_send entered"); 637 - spin_lock_irq(&instance->sndqueue.lock); 638 - for (skb = instance->sndqueue.next, n = skb->next; 639 - skb != (struct sk_buff *)&instance->sndqueue; 640 - skb = n, n = skb->next) 641 - if (UDSL_SKB(skb)->atm_data.vcc == vcc) { 642 - dbg("udsl_cancel_send: popping skb 0x%p", skb); 643 - __skb_unlink(skb, &instance->sndqueue); 644 - udsl_pop(vcc, skb); 645 - } 646 - spin_unlock_irq(&instance->sndqueue.lock); 647 - 648 - tasklet_disable(&instance->send_tasklet); 649 - if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm_data.vcc == vcc)) { 650 - dbg("udsl_cancel_send: popping current skb (0x%p)", skb); 651 - instance->current_skb = NULL; 652 - udsl_pop(vcc, skb); 653 - } 654 - tasklet_enable(&instance->send_tasklet); 655 - dbg("udsl_cancel_send done"); 656 - } 657 - 658 - static int udsl_atm_send(struct atm_vcc *vcc, struct sk_buff *skb) 659 - { 660 - struct udsl_instance_data *instance = vcc->dev->dev_data; 661 - int err; 662 - 663 - vdbg("udsl_atm_send called (skb 0x%p, len %u)", skb, skb->len); 664 - 665 - if (!instance) { 666 - dbg("udsl_atm_send: NULL data!"); 667 - err = -ENODEV; 668 - goto fail; 669 - } 670 - 671 - if (vcc->qos.aal != ATM_AAL5) { 672 - dbg("udsl_atm_send: unsupported ATM type %d!", vcc->qos.aal); 673 - err = -EINVAL; 674 - goto fail; 675 - } 676 - 677 - if (skb->len > ATM_MAX_AAL5_PDU) { 678 - dbg("udsl_atm_send: packet too long (%d vs %d)!", skb->len, 679 - ATM_MAX_AAL5_PDU); 680 - err = -EINVAL; 681 - goto fail; 682 - } 683 - 684 - PACKETDEBUG(skb->data, skb->len); 685 - 686 - udsl_groom_skb(vcc, skb); 687 - skb_queue_tail(&instance->sndqueue, skb); 688 - tasklet_schedule(&instance->send_tasklet); 689 - 690 - return 0; 691 - 692 - fail: 693 - udsl_pop(vcc, skb); 694 - return err; 695 - } 696 - 697 - /******************** 698 - ** bean counting ** 699 - ********************/ 700 - 701 - static void udsl_destroy_instance(struct kref *kref) 702 - { 703 - struct udsl_instance_data *instance = 704 - container_of(kref, struct udsl_instance_data, refcount); 705 - 706 - tasklet_kill(&instance->receive_tasklet); 707 - tasklet_kill(&instance->send_tasklet); 708 - usb_put_dev(instance->usb_dev); 709 - kfree(instance); 710 - } 711 - 712 - void udsl_get_instance(struct udsl_instance_data *instance) 713 - { 714 - kref_get(&instance->refcount); 715 - } 716 - 717 - void udsl_put_instance(struct udsl_instance_data *instance) 718 - { 719 - kref_put(&instance->refcount, udsl_destroy_instance); 720 - } 721 - 722 - /********** 723 - ** ATM ** 724 - **********/ 725 - 726 - static void udsl_atm_dev_close(struct atm_dev *dev) 727 - { 728 - struct udsl_instance_data *instance = dev->dev_data; 729 - 730 - dev->dev_data = NULL; 731 - udsl_put_instance(instance); 732 - } 733 - 734 - static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page) 735 - { 736 - struct udsl_instance_data *instance = atm_dev->dev_data; 737 - int left = *pos; 738 - 739 - if (!instance) { 740 - dbg("udsl_atm_proc_read: NULL instance!"); 741 - return -ENODEV; 742 - } 743 - 744 - if (!left--) 745 - return sprintf(page, "%s\n", instance->description); 746 - 747 - if (!left--) 748 - return sprintf(page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", 749 - atm_dev->esi[0], atm_dev->esi[1], 750 - atm_dev->esi[2], atm_dev->esi[3], 751 - atm_dev->esi[4], atm_dev->esi[5]); 752 - 753 - if (!left--) 754 - return sprintf(page, 755 - "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n", 756 - atomic_read(&atm_dev->stats.aal5.tx), 757 - atomic_read(&atm_dev->stats.aal5.tx_err), 758 - atomic_read(&atm_dev->stats.aal5.rx), 759 - atomic_read(&atm_dev->stats.aal5.rx_err), 760 - atomic_read(&atm_dev->stats.aal5.rx_drop)); 761 - 762 - if (!left--) { 763 - switch (atm_dev->signal) { 764 - case ATM_PHY_SIG_FOUND: 765 - sprintf(page, "Line up"); 766 - break; 767 - case ATM_PHY_SIG_LOST: 768 - sprintf(page, "Line down"); 769 - break; 770 - default: 771 - sprintf(page, "Line state unknown"); 772 - break; 773 - } 774 - 775 - if (instance->usb_dev->state == USB_STATE_NOTATTACHED) 776 - strcat(page, ", disconnected\n"); 777 - else { 778 - if (instance->status == UDSL_LOADED_FIRMWARE) 779 - strcat(page, ", firmware loaded\n"); 780 - else if (instance->status == UDSL_LOADING_FIRMWARE) 781 - strcat(page, ", firmware loading\n"); 782 - else 783 - strcat(page, ", no firmware\n"); 784 - } 785 - 786 - return strlen(page); 787 - } 788 - 789 - return 0; 790 - } 791 - 792 - static int udsl_atm_open(struct atm_vcc *vcc) 793 - { 794 - struct udsl_instance_data *instance = vcc->dev->dev_data; 795 - struct udsl_vcc_data *new; 796 - unsigned int max_pdu; 797 - int vci = vcc->vci; 798 - short vpi = vcc->vpi; 799 - int err; 800 - 801 - dbg("udsl_atm_open: vpi %hd, vci %d", vpi, vci); 802 - 803 - if (!instance) { 804 - dbg("udsl_atm_open: NULL data!"); 805 - return -ENODEV; 806 - } 807 - 808 - /* only support AAL5 */ 809 - if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0) 810 - || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) { 811 - dbg("udsl_atm_open: unsupported ATM type %d!", vcc->qos.aal); 812 - return -EINVAL; 813 - } 814 - 815 - if (instance->firmware_wait && 816 - (err = instance->firmware_wait(instance)) < 0) { 817 - dbg("udsl_atm_open: firmware not loaded (%d)!", err); 818 - return err; 819 - } 820 - 821 - down(&instance->serialize); /* vs self, udsl_atm_close */ 822 - 823 - if (udsl_find_vcc(instance, vpi, vci)) { 824 - dbg("udsl_atm_open: %hd/%d already in use!", vpi, vci); 825 - up(&instance->serialize); 826 - return -EADDRINUSE; 827 - } 828 - 829 - if (!(new = kmalloc(sizeof(struct udsl_vcc_data), GFP_KERNEL))) { 830 - dbg("udsl_atm_open: no memory for vcc_data!"); 831 - up(&instance->serialize); 832 - return -ENOMEM; 833 - } 834 - 835 - memset(new, 0, sizeof(struct udsl_vcc_data)); 836 - new->vcc = vcc; 837 - new->vpi = vpi; 838 - new->vci = vci; 839 - 840 - /* udsl_extract_cells requires at least one cell */ 841 - max_pdu = max(1, UDSL_NUM_CELLS(vcc->qos.rxtp.max_sdu)) * ATM_CELL_PAYLOAD; 842 - if (!(new->sarb = alloc_skb(max_pdu, GFP_KERNEL))) { 843 - dbg("udsl_atm_open: no memory for SAR buffer!"); 844 - kfree(new); 845 - up(&instance->serialize); 846 - return -ENOMEM; 847 - } 848 - 849 - vcc->dev_data = new; 850 - 851 - tasklet_disable(&instance->receive_tasklet); 852 - list_add(&new->list, &instance->vcc_list); 853 - tasklet_enable(&instance->receive_tasklet); 854 - 855 - set_bit(ATM_VF_ADDR, &vcc->flags); 856 - set_bit(ATM_VF_PARTIAL, &vcc->flags); 857 - set_bit(ATM_VF_READY, &vcc->flags); 858 - 859 - up(&instance->serialize); 860 - 861 - tasklet_schedule(&instance->receive_tasklet); 862 - 863 - dbg("udsl_atm_open: allocated vcc data 0x%p (max_pdu: %u)", new, max_pdu); 864 - 865 - return 0; 866 - } 867 - 868 - static void udsl_atm_close(struct atm_vcc *vcc) 869 - { 870 - struct udsl_instance_data *instance = vcc->dev->dev_data; 871 - struct udsl_vcc_data *vcc_data = vcc->dev_data; 872 - 873 - dbg("udsl_atm_close called"); 874 - 875 - if (!instance || !vcc_data) { 876 - dbg("udsl_atm_close: NULL data!"); 877 - return; 878 - } 879 - 880 - dbg("udsl_atm_close: deallocating vcc 0x%p with vpi %d vci %d", 881 - vcc_data, vcc_data->vpi, vcc_data->vci); 882 - 883 - udsl_cancel_send(instance, vcc); 884 - 885 - down(&instance->serialize); /* vs self, udsl_atm_open */ 886 - 887 - tasklet_disable(&instance->receive_tasklet); 888 - list_del(&vcc_data->list); 889 - tasklet_enable(&instance->receive_tasklet); 890 - 891 - kfree_skb(vcc_data->sarb); 892 - vcc_data->sarb = NULL; 893 - 894 - kfree(vcc_data); 895 - vcc->dev_data = NULL; 896 - 897 - vcc->vpi = ATM_VPI_UNSPEC; 898 - vcc->vci = ATM_VCI_UNSPEC; 899 - clear_bit(ATM_VF_READY, &vcc->flags); 900 - clear_bit(ATM_VF_PARTIAL, &vcc->flags); 901 - clear_bit(ATM_VF_ADDR, &vcc->flags); 902 - 903 - up(&instance->serialize); 904 - 905 - dbg("udsl_atm_close successful"); 906 - } 907 - 908 - static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd, 909 - void __user * arg) 910 - { 911 - switch (cmd) { 912 - case ATM_QUERYLOOP: 913 - return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0; 914 - default: 915 - return -ENOIOCTLCMD; 916 - } 917 - } 918 - 919 - /********** 920 - ** USB ** 921 - **********/ 922 - 923 - int udsl_instance_setup(struct usb_device *dev, 924 - struct udsl_instance_data *instance) 925 - { 926 - char *buf; 927 - int i, length; 928 - 929 - kref_init(&instance->refcount); /* one for USB */ 930 - udsl_get_instance(instance); /* one for ATM */ 931 - 932 - init_MUTEX(&instance->serialize); 933 - 934 - instance->usb_dev = dev; 935 - 936 - INIT_LIST_HEAD(&instance->vcc_list); 937 - 938 - instance->status = UDSL_NO_FIRMWARE; 939 - init_waitqueue_head(&instance->firmware_waiters); 940 - 941 - spin_lock_init(&instance->receive_lock); 942 - INIT_LIST_HEAD(&instance->spare_receivers); 943 - INIT_LIST_HEAD(&instance->filled_receive_buffers); 944 - 945 - tasklet_init(&instance->receive_tasklet, udsl_process_receive, (unsigned long)instance); 946 - INIT_LIST_HEAD(&instance->spare_receive_buffers); 947 - 948 - skb_queue_head_init(&instance->sndqueue); 949 - 950 - spin_lock_init(&instance->send_lock); 951 - INIT_LIST_HEAD(&instance->spare_senders); 952 - INIT_LIST_HEAD(&instance->spare_send_buffers); 953 - 954 - tasklet_init(&instance->send_tasklet, udsl_process_send, 955 - (unsigned long)instance); 956 - INIT_LIST_HEAD(&instance->filled_send_buffers); 957 - 958 - /* receive init */ 959 - for (i = 0; i < num_rcv_urbs; i++) { 960 - struct udsl_receiver *rcv = &(instance->receivers[i]); 961 - 962 - if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { 963 - dbg("udsl_usb_probe: no memory for receive urb %d!", i); 964 - goto fail; 965 - } 966 - 967 - rcv->instance = instance; 968 - 969 - list_add(&rcv->list, &instance->spare_receivers); 970 - } 971 - 972 - for (i = 0; i < num_rcv_bufs; i++) { 973 - struct udsl_receive_buffer *buf = 974 - &(instance->receive_buffers[i]); 975 - 976 - buf->base = kmalloc(rcv_buf_size * (ATM_CELL_SIZE + instance->rcv_padding), 977 - GFP_KERNEL); 978 - if (!buf->base) { 979 - dbg("udsl_usb_probe: no memory for receive buffer %d!", i); 980 - goto fail; 981 - } 982 - 983 - list_add(&buf->list, &instance->spare_receive_buffers); 984 - } 985 - 986 - /* send init */ 987 - for (i = 0; i < num_snd_urbs; i++) { 988 - struct udsl_sender *snd = &(instance->senders[i]); 989 - 990 - if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { 991 - dbg("udsl_usb_probe: no memory for send urb %d!", i); 992 - goto fail; 993 - } 994 - 995 - snd->instance = instance; 996 - 997 - list_add(&snd->list, &instance->spare_senders); 998 - } 999 - 1000 - for (i = 0; i < num_snd_bufs; i++) { 1001 - struct udsl_send_buffer *buf = &(instance->send_buffers[i]); 1002 - 1003 - buf->base = kmalloc(snd_buf_size * (ATM_CELL_SIZE + instance->snd_padding), 1004 - GFP_KERNEL); 1005 - if (!buf->base) { 1006 - dbg("udsl_usb_probe: no memory for send buffer %d!", i); 1007 - goto fail; 1008 - } 1009 - 1010 - list_add(&buf->list, &instance->spare_send_buffers); 1011 - } 1012 - 1013 - /* ATM init */ 1014 - instance->atm_dev = atm_dev_register(instance->driver_name, 1015 - &udsl_atm_devops, -1, NULL); 1016 - if (!instance->atm_dev) { 1017 - dbg("udsl_usb_probe: failed to register ATM device!"); 1018 - goto fail; 1019 - } 1020 - 1021 - instance->atm_dev->ci_range.vpi_bits = ATM_CI_MAX; 1022 - instance->atm_dev->ci_range.vci_bits = ATM_CI_MAX; 1023 - instance->atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 1024 - 1025 - /* temp init ATM device, set to 128kbit */ 1026 - instance->atm_dev->link_rate = 128 * 1000 / 424; 1027 - 1028 - /* device description */ 1029 - buf = instance->description; 1030 - length = sizeof(instance->description); 1031 - 1032 - if ((i = usb_string(dev, dev->descriptor.iProduct, buf, length)) < 0) 1033 - goto finish; 1034 - 1035 - buf += i; 1036 - length -= i; 1037 - 1038 - i = scnprintf(buf, length, " ("); 1039 - buf += i; 1040 - length -= i; 1041 - 1042 - if (length <= 0 || (i = usb_make_path(dev, buf, length)) < 0) 1043 - goto finish; 1044 - 1045 - buf += i; 1046 - length -= i; 1047 - 1048 - snprintf(buf, length, ")"); 1049 - 1050 - finish: 1051 - /* ready for ATM callbacks */ 1052 - wmb(); 1053 - instance->atm_dev->dev_data = instance; 1054 - 1055 - usb_get_dev(dev); 1056 - 1057 - return 0; 1058 - 1059 - fail: 1060 - for (i = 0; i < num_snd_bufs; i++) 1061 - kfree(instance->send_buffers[i].base); 1062 - 1063 - for (i = 0; i < num_snd_urbs; i++) 1064 - usb_free_urb(instance->senders[i].urb); 1065 - 1066 - for (i = 0; i < num_rcv_bufs; i++) 1067 - kfree(instance->receive_buffers[i].base); 1068 - 1069 - for (i = 0; i < num_rcv_urbs; i++) 1070 - usb_free_urb(instance->receivers[i].urb); 1071 - 1072 - return -ENOMEM; 1073 - } 1074 - 1075 - void udsl_instance_disconnect(struct udsl_instance_data *instance) 1076 - { 1077 - int i; 1078 - 1079 - dbg("udsl_instance_disconnect entered"); 1080 - 1081 - if (!instance) { 1082 - dbg("udsl_instance_disconnect: NULL instance!"); 1083 - return; 1084 - } 1085 - 1086 - /* receive finalize */ 1087 - tasklet_disable(&instance->receive_tasklet); 1088 - 1089 - for (i = 0; i < num_rcv_urbs; i++) 1090 - usb_kill_urb(instance->receivers[i].urb); 1091 - 1092 - /* no need to take the spinlock */ 1093 - INIT_LIST_HEAD(&instance->filled_receive_buffers); 1094 - INIT_LIST_HEAD(&instance->spare_receive_buffers); 1095 - 1096 - tasklet_enable(&instance->receive_tasklet); 1097 - 1098 - for (i = 0; i < num_rcv_urbs; i++) 1099 - usb_free_urb(instance->receivers[i].urb); 1100 - 1101 - for (i = 0; i < num_rcv_bufs; i++) 1102 - kfree(instance->receive_buffers[i].base); 1103 - 1104 - /* send finalize */ 1105 - tasklet_disable(&instance->send_tasklet); 1106 - 1107 - for (i = 0; i < num_snd_urbs; i++) 1108 - usb_kill_urb(instance->senders[i].urb); 1109 - 1110 - /* no need to take the spinlock */ 1111 - INIT_LIST_HEAD(&instance->spare_senders); 1112 - INIT_LIST_HEAD(&instance->spare_send_buffers); 1113 - instance->current_buffer = NULL; 1114 - 1115 - tasklet_enable(&instance->send_tasklet); 1116 - 1117 - for (i = 0; i < num_snd_urbs; i++) 1118 - usb_free_urb(instance->senders[i].urb); 1119 - 1120 - for (i = 0; i < num_snd_bufs; i++) 1121 - kfree(instance->send_buffers[i].base); 1122 - 1123 - /* ATM finalize */ 1124 - shutdown_atm_dev(instance->atm_dev); 1125 - } 1126 - 1127 - EXPORT_SYMBOL_GPL(udsl_get_instance); 1128 - EXPORT_SYMBOL_GPL(udsl_put_instance); 1129 - EXPORT_SYMBOL_GPL(udsl_instance_setup); 1130 - EXPORT_SYMBOL_GPL(udsl_instance_disconnect); 1131 - 1132 - /*********** 1133 - ** init ** 1134 - ***********/ 1135 - 1136 - static int __init udsl_usb_init(void) 1137 - { 1138 - dbg("udsl_usb_init: driver version " DRIVER_VERSION); 1139 - 1140 - if (sizeof(struct udsl_control) > sizeof(((struct sk_buff *) 0)->cb)) { 1141 - printk(KERN_ERR __FILE__ ": unusable with this kernel!\n"); 1142 - return -EIO; 1143 - } 1144 - 1145 - if ((num_rcv_urbs > UDSL_MAX_RCV_URBS) 1146 - || (num_snd_urbs > UDSL_MAX_SND_URBS) 1147 - || (num_rcv_bufs > UDSL_MAX_RCV_BUFS) 1148 - || (num_snd_bufs > UDSL_MAX_SND_BUFS) 1149 - || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE) 1150 - || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE)) 1151 - return -EINVAL; 1152 - 1153 - return 0; 1154 - } 1155 - 1156 - static void __exit udsl_usb_exit(void) 1157 - { 1158 - } 1159 - 1160 - module_init(udsl_usb_init); 1161 - module_exit(udsl_usb_exit); 1162 - 1163 - MODULE_AUTHOR(DRIVER_AUTHOR); 1164 - MODULE_DESCRIPTION(DRIVER_DESC); 1165 - MODULE_LICENSE("GPL"); 1166 - MODULE_VERSION(DRIVER_VERSION); 1167 - 1168 - /************ 1169 - ** debug ** 1170 - ************/ 1171 - 1172 - #ifdef VERBOSE_DEBUG 1173 - static int udsl_print_packet(const unsigned char *data, int len) 1174 - { 1175 - unsigned char buffer[256]; 1176 - int i = 0, j = 0; 1177 - 1178 - for (i = 0; i < len;) { 1179 - buffer[0] = '\0'; 1180 - sprintf(buffer, "%.3d :", i); 1181 - for (j = 0; (j < 16) && (i < len); j++, i++) { 1182 - sprintf(buffer, "%s %2.2x", buffer, data[i]); 1183 - } 1184 - dbg("%s", buffer); 1185 - } 1186 - return i; 1187 - } 1188 - #endif
-176
drivers/usb/atm/usb_atm.h
··· 1 - /****************************************************************************** 2 - * usb_atm.h - Generic USB xDSL driver core 3 - * 4 - * Copyright (C) 2001, Alcatel 5 - * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas 6 - * Copyright (C) 2004, David Woodhouse 7 - * 8 - * 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 10 - * Software Foundation; either version 2 of the License, or (at your option) 11 - * any later version. 12 - * 13 - * This program is distributed in the hope that it will be useful, but WITHOUT 14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 - * more details. 17 - * 18 - * You should have received a copy of the GNU General Public License along with 19 - * this program; if not, write to the Free Software Foundation, Inc., 59 20 - * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 - * 22 - ******************************************************************************/ 23 - 24 - #include <linux/config.h> 25 - #include <linux/list.h> 26 - #include <linux/kref.h> 27 - #include <linux/atm.h> 28 - #include <linux/atmdev.h> 29 - #include <asm/semaphore.h> 30 - 31 - /* 32 - #define DEBUG 33 - #define VERBOSE_DEBUG 34 - */ 35 - 36 - #if !defined (DEBUG) && defined (CONFIG_USB_DEBUG) 37 - # define DEBUG 38 - #endif 39 - 40 - #include <linux/usb.h> 41 - 42 - #ifdef DEBUG 43 - #define UDSL_ASSERT(x) BUG_ON(!(x)) 44 - #else 45 - #define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '" #x "' at line %d", __LINE__); } while(0) 46 - #endif 47 - 48 - #define UDSL_MAX_RCV_URBS 4 49 - #define UDSL_MAX_SND_URBS 4 50 - #define UDSL_MAX_RCV_BUFS 8 51 - #define UDSL_MAX_SND_BUFS 8 52 - #define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */ 53 - #define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */ 54 - #define UDSL_DEFAULT_RCV_URBS 2 55 - #define UDSL_DEFAULT_SND_URBS 2 56 - #define UDSL_DEFAULT_RCV_BUFS 4 57 - #define UDSL_DEFAULT_SND_BUFS 4 58 - #define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */ 59 - #define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */ 60 - 61 - #define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD) 62 - #define UDSL_NUM_CELLS(x) (((x) + ATM_AAL5_TRAILER + ATM_CELL_PAYLOAD - 1) / ATM_CELL_PAYLOAD) 63 - 64 - /* receive */ 65 - 66 - struct udsl_receive_buffer { 67 - struct list_head list; 68 - unsigned char *base; 69 - unsigned int filled_cells; 70 - }; 71 - 72 - struct udsl_receiver { 73 - struct list_head list; 74 - struct udsl_receive_buffer *buffer; 75 - struct urb *urb; 76 - struct udsl_instance_data *instance; 77 - }; 78 - 79 - struct udsl_vcc_data { 80 - /* vpi/vci lookup */ 81 - struct list_head list; 82 - short vpi; 83 - int vci; 84 - struct atm_vcc *vcc; 85 - 86 - /* raw cell reassembly */ 87 - struct sk_buff *sarb; 88 - }; 89 - 90 - /* send */ 91 - 92 - struct udsl_send_buffer { 93 - struct list_head list; 94 - unsigned char *base; 95 - unsigned char *free_start; 96 - unsigned int free_cells; 97 - }; 98 - 99 - struct udsl_sender { 100 - struct list_head list; 101 - struct udsl_send_buffer *buffer; 102 - struct urb *urb; 103 - struct udsl_instance_data *instance; 104 - }; 105 - 106 - struct udsl_control { 107 - struct atm_skb_data atm_data; 108 - unsigned int num_cells; 109 - unsigned int num_entire; 110 - unsigned int pdu_padding; 111 - unsigned char aal5_trailer[ATM_AAL5_TRAILER]; 112 - }; 113 - 114 - #define UDSL_SKB(x) ((struct udsl_control *)(x)->cb) 115 - 116 - /* main driver data */ 117 - 118 - enum udsl_status { 119 - UDSL_NO_FIRMWARE, 120 - UDSL_LOADING_FIRMWARE, 121 - UDSL_LOADED_FIRMWARE 122 - }; 123 - 124 - struct udsl_instance_data { 125 - struct kref refcount; 126 - struct semaphore serialize; 127 - 128 - /* USB device part */ 129 - struct usb_device *usb_dev; 130 - char description[64]; 131 - int data_endpoint; 132 - int snd_padding; 133 - int rcv_padding; 134 - const char *driver_name; 135 - 136 - /* ATM device part */ 137 - struct atm_dev *atm_dev; 138 - struct list_head vcc_list; 139 - 140 - /* firmware */ 141 - int (*firmware_wait) (struct udsl_instance_data *); 142 - enum udsl_status status; 143 - wait_queue_head_t firmware_waiters; 144 - 145 - /* receive */ 146 - struct udsl_receiver receivers[UDSL_MAX_RCV_URBS]; 147 - struct udsl_receive_buffer receive_buffers[UDSL_MAX_RCV_BUFS]; 148 - 149 - spinlock_t receive_lock; 150 - struct list_head spare_receivers; 151 - struct list_head filled_receive_buffers; 152 - 153 - struct tasklet_struct receive_tasklet; 154 - struct list_head spare_receive_buffers; 155 - 156 - /* send */ 157 - struct udsl_sender senders[UDSL_MAX_SND_URBS]; 158 - struct udsl_send_buffer send_buffers[UDSL_MAX_SND_BUFS]; 159 - 160 - struct sk_buff_head sndqueue; 161 - 162 - spinlock_t send_lock; 163 - struct list_head spare_senders; 164 - struct list_head spare_send_buffers; 165 - 166 - struct tasklet_struct send_tasklet; 167 - struct sk_buff *current_skb; /* being emptied */ 168 - struct udsl_send_buffer *current_buffer; /* being filled */ 169 - struct list_head filled_send_buffers; 170 - }; 171 - 172 - extern int udsl_instance_setup(struct usb_device *dev, 173 - struct udsl_instance_data *instance); 174 - extern void udsl_instance_disconnect(struct udsl_instance_data *instance); 175 - extern void udsl_get_instance(struct udsl_instance_data *instance); 176 - extern void udsl_put_instance(struct udsl_instance_data *instance);
+1230
drivers/usb/atm/usbatm.c
··· 1 + /****************************************************************************** 2 + * usbatm.c - Generic USB xDSL driver core 3 + * 4 + * Copyright (C) 2001, Alcatel 5 + * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas 6 + * Copyright (C) 2004, David Woodhouse, Roman Kagan 7 + * 8 + * 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 10 + * Software Foundation; either version 2 of the License, or (at your option) 11 + * any later version. 12 + * 13 + * This program is distributed in the hope that it will be useful, but WITHOUT 14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 + * more details. 17 + * 18 + * You should have received a copy of the GNU General Public License along with 19 + * this program; if not, write to the Free Software Foundation, Inc., 59 20 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 + * 22 + ******************************************************************************/ 23 + 24 + /* 25 + * Written by Johan Verrept, Duncan Sands (duncan.sands@free.fr) and David Woodhouse 26 + * 27 + * 1.7+: - See the check-in logs 28 + * 29 + * 1.6: - No longer opens a connection if the firmware is not loaded 30 + * - Added support for the speedtouch 330 31 + * - Removed the limit on the number of devices 32 + * - Module now autoloads on device plugin 33 + * - Merged relevant parts of sarlib 34 + * - Replaced the kernel thread with a tasklet 35 + * - New packet transmission code 36 + * - Changed proc file contents 37 + * - Fixed all known SMP races 38 + * - Many fixes and cleanups 39 + * - Various fixes by Oliver Neukum (oliver@neukum.name) 40 + * 41 + * 1.5A: - Version for inclusion in 2.5 series kernel 42 + * - Modifications by Richard Purdie (rpurdie@rpsys.net) 43 + * - made compatible with kernel 2.5.6 onwards by changing 44 + * usbatm_usb_send_data_context->urb to a pointer and adding code 45 + * to alloc and free it 46 + * - remove_wait_queue() added to usbatm_atm_processqueue_thread() 47 + * 48 + * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL. 49 + * (reported by stephen.robinson@zen.co.uk) 50 + * 51 + * 1.4: - changed the spin_lock() under interrupt to spin_lock_irqsave() 52 + * - unlink all active send urbs of a vcc that is being closed. 53 + * 54 + * 1.3.1: - added the version number 55 + * 56 + * 1.3: - Added multiple send urb support 57 + * - fixed memory leak and vcc->tx_inuse starvation bug 58 + * when not enough memory left in vcc. 59 + * 60 + * 1.2: - Fixed race condition in usbatm_usb_send_data() 61 + * 1.1: - Turned off packet debugging 62 + * 63 + */ 64 + 65 + #include "usbatm.h" 66 + 67 + #include <asm/uaccess.h> 68 + #include <linux/crc32.h> 69 + #include <linux/errno.h> 70 + #include <linux/init.h> 71 + #include <linux/interrupt.h> 72 + #include <linux/kernel.h> 73 + #include <linux/module.h> 74 + #include <linux/moduleparam.h> 75 + #include <linux/proc_fs.h> 76 + #include <linux/sched.h> 77 + #include <linux/signal.h> 78 + #include <linux/slab.h> 79 + #include <linux/smp_lock.h> 80 + #include <linux/stat.h> 81 + #include <linux/timer.h> 82 + #include <linux/wait.h> 83 + 84 + #ifdef VERBOSE_DEBUG 85 + static int usbatm_print_packet(const unsigned char *data, int len); 86 + #define PACKETDEBUG(arg...) usbatm_print_packet (arg) 87 + #define vdbg(arg...) dbg (arg) 88 + #else 89 + #define PACKETDEBUG(arg...) 90 + #define vdbg(arg...) 91 + #endif 92 + 93 + #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 94 + #define DRIVER_VERSION "1.9" 95 + #define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION 96 + 97 + static const char usbatm_driver_name[] = "usbatm"; 98 + 99 + #define UDSL_MAX_RCV_URBS 16 100 + #define UDSL_MAX_SND_URBS 16 101 + #define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */ 102 + #define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */ 103 + #define UDSL_DEFAULT_RCV_URBS 4 104 + #define UDSL_DEFAULT_SND_URBS 4 105 + #define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */ 106 + #define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */ 107 + 108 + #define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD) 109 + 110 + #define THROTTLE_MSECS 100 /* delay to recover processing after urb submission fails */ 111 + 112 + static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS; 113 + static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS; 114 + static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE; 115 + static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE; 116 + 117 + module_param(num_rcv_urbs, uint, S_IRUGO); 118 + MODULE_PARM_DESC(num_rcv_urbs, 119 + "Number of urbs used for reception (range: 0-" 120 + __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: " 121 + __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")"); 122 + 123 + module_param(num_snd_urbs, uint, S_IRUGO); 124 + MODULE_PARM_DESC(num_snd_urbs, 125 + "Number of urbs used for transmission (range: 0-" 126 + __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: " 127 + __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")"); 128 + 129 + module_param(rcv_buf_size, uint, S_IRUGO); 130 + MODULE_PARM_DESC(rcv_buf_size, 131 + "Size of the buffers used for reception in ATM cells (range: 1-" 132 + __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: " 133 + __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")"); 134 + 135 + module_param(snd_buf_size, uint, S_IRUGO); 136 + MODULE_PARM_DESC(snd_buf_size, 137 + "Size of the buffers used for transmission in ATM cells (range: 1-" 138 + __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: " 139 + __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")"); 140 + 141 + 142 + /* receive */ 143 + 144 + struct usbatm_vcc_data { 145 + /* vpi/vci lookup */ 146 + struct list_head list; 147 + short vpi; 148 + int vci; 149 + struct atm_vcc *vcc; 150 + 151 + /* raw cell reassembly */ 152 + struct sk_buff *sarb; 153 + }; 154 + 155 + 156 + /* send */ 157 + 158 + struct usbatm_control { 159 + struct atm_skb_data atm; 160 + u32 len; 161 + u32 crc; 162 + }; 163 + 164 + #define UDSL_SKB(x) ((struct usbatm_control *)(x)->cb) 165 + 166 + 167 + /* ATM */ 168 + 169 + static void usbatm_atm_dev_close(struct atm_dev *dev); 170 + static int usbatm_atm_open(struct atm_vcc *vcc); 171 + static void usbatm_atm_close(struct atm_vcc *vcc); 172 + static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg); 173 + static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); 174 + static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page); 175 + 176 + static struct atmdev_ops usbatm_atm_devops = { 177 + .dev_close = usbatm_atm_dev_close, 178 + .open = usbatm_atm_open, 179 + .close = usbatm_atm_close, 180 + .ioctl = usbatm_atm_ioctl, 181 + .send = usbatm_atm_send, 182 + .proc_read = usbatm_atm_proc_read, 183 + .owner = THIS_MODULE, 184 + }; 185 + 186 + 187 + /*********** 188 + ** misc ** 189 + ***********/ 190 + 191 + static inline unsigned int usbatm_pdu_length(unsigned int length) 192 + { 193 + length += ATM_CELL_PAYLOAD - 1 + ATM_AAL5_TRAILER; 194 + return length - length % ATM_CELL_PAYLOAD; 195 + } 196 + 197 + static inline void usbatm_pop(struct atm_vcc *vcc, struct sk_buff *skb) 198 + { 199 + if (vcc->pop) 200 + vcc->pop(vcc, skb); 201 + else 202 + dev_kfree_skb(skb); 203 + } 204 + 205 + 206 + /*********** 207 + ** urbs ** 208 + ************/ 209 + 210 + static inline struct urb *usbatm_pop_urb(struct usbatm_channel *channel) 211 + { 212 + struct urb *urb; 213 + 214 + spin_lock_irq(&channel->lock); 215 + if (list_empty(&channel->list)) { 216 + spin_unlock_irq(&channel->lock); 217 + return NULL; 218 + } 219 + 220 + urb = list_entry(channel->list.next, struct urb, urb_list); 221 + list_del(&urb->urb_list); 222 + spin_unlock_irq(&channel->lock); 223 + 224 + return urb; 225 + } 226 + 227 + static inline int usbatm_submit_urb(struct urb *urb) 228 + { 229 + struct usbatm_channel *channel = urb->context; 230 + int ret; 231 + 232 + vdbg("%s: submitting urb 0x%p, size %u", 233 + __func__, urb, urb->transfer_buffer_length); 234 + 235 + ret = usb_submit_urb(urb, GFP_ATOMIC); 236 + if (ret) { 237 + atm_dbg(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n", 238 + __func__, urb, ret); 239 + 240 + /* consider all errors transient and return the buffer back to the queue */ 241 + urb->status = -EAGAIN; 242 + spin_lock_irq(&channel->lock); 243 + 244 + /* must add to the front when sending; doesn't matter when receiving */ 245 + list_add(&urb->urb_list, &channel->list); 246 + 247 + spin_unlock_irq(&channel->lock); 248 + 249 + /* make sure the channel doesn't stall */ 250 + mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); 251 + } 252 + 253 + return ret; 254 + } 255 + 256 + static void usbatm_complete(struct urb *urb, struct pt_regs *regs) 257 + { 258 + struct usbatm_channel *channel = urb->context; 259 + unsigned long flags; 260 + 261 + vdbg("%s: urb 0x%p, status %d, actual_length %d", 262 + __func__, urb, urb->status, urb->actual_length); 263 + 264 + /* usually in_interrupt(), but not always */ 265 + spin_lock_irqsave(&channel->lock, flags); 266 + 267 + /* must add to the back when receiving; doesn't matter when sending */ 268 + list_add_tail(&urb->urb_list, &channel->list); 269 + 270 + spin_unlock_irqrestore(&channel->lock, flags); 271 + 272 + if (unlikely(urb->status)) 273 + /* throttle processing in case of an error */ 274 + mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); 275 + else 276 + tasklet_schedule(&channel->tasklet); 277 + } 278 + 279 + 280 + /************* 281 + ** decode ** 282 + *************/ 283 + 284 + static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance, 285 + short vpi, int vci) 286 + { 287 + struct usbatm_vcc_data *vcc; 288 + 289 + list_for_each_entry(vcc, &instance->vcc_list, list) 290 + if ((vcc->vci == vci) && (vcc->vpi == vpi)) 291 + return vcc; 292 + return NULL; 293 + } 294 + 295 + static void usbatm_extract_cells(struct usbatm_data *instance, 296 + unsigned char *source, unsigned int avail_data) 297 + { 298 + struct usbatm_vcc_data *cached_vcc = NULL; 299 + struct atm_vcc *vcc; 300 + struct sk_buff *sarb; 301 + unsigned int stride = instance->rx_channel.stride; 302 + int vci, cached_vci = 0; 303 + short vpi, cached_vpi = 0; 304 + u8 pti; 305 + 306 + for (; avail_data >= stride; avail_data -= stride, source += stride) { 307 + vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4); 308 + vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4); 309 + pti = ((source[3] & 0xe) >> 1); 310 + 311 + vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti); 312 + 313 + if ((vci != cached_vci) || (vpi != cached_vpi)) { 314 + cached_vpi = vpi; 315 + cached_vci = vci; 316 + 317 + cached_vcc = usbatm_find_vcc(instance, vpi, vci); 318 + 319 + if (!cached_vcc) 320 + atm_dbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci); 321 + } 322 + 323 + if (!cached_vcc) 324 + continue; 325 + 326 + vcc = cached_vcc->vcc; 327 + 328 + /* OAM F5 end-to-end */ 329 + if (pti == ATM_PTI_E2EF5) { 330 + atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n", __func__, vpi, vci); 331 + atomic_inc(&vcc->stats->rx_err); 332 + continue; 333 + } 334 + 335 + sarb = cached_vcc->sarb; 336 + 337 + if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) { 338 + atm_dbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n", 339 + __func__, sarb->len, vcc); 340 + /* discard cells already received */ 341 + skb_trim(sarb, 0); 342 + UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end); 343 + } 344 + 345 + memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD); 346 + __skb_put(sarb, ATM_CELL_PAYLOAD); 347 + 348 + if (pti & 1) { 349 + struct sk_buff *skb; 350 + unsigned int length; 351 + unsigned int pdu_length; 352 + 353 + length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5]; 354 + 355 + /* guard against overflow */ 356 + if (length > ATM_MAX_AAL5_PDU) { 357 + atm_dbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n", 358 + __func__, length, vcc); 359 + atomic_inc(&vcc->stats->rx_err); 360 + goto out; 361 + } 362 + 363 + pdu_length = usbatm_pdu_length(length); 364 + 365 + if (sarb->len < pdu_length) { 366 + atm_dbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n", 367 + __func__, pdu_length, sarb->len, vcc); 368 + atomic_inc(&vcc->stats->rx_err); 369 + goto out; 370 + } 371 + 372 + if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) { 373 + atm_dbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n", 374 + __func__, vcc); 375 + atomic_inc(&vcc->stats->rx_err); 376 + goto out; 377 + } 378 + 379 + vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc); 380 + 381 + if (!(skb = dev_alloc_skb(length))) { 382 + atm_dbg(instance, "%s: no memory for skb (length: %u)!\n", __func__, length); 383 + atomic_inc(&vcc->stats->rx_drop); 384 + goto out; 385 + } 386 + 387 + vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize); 388 + 389 + if (!atm_charge(vcc, skb->truesize)) { 390 + atm_dbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n", __func__, skb->truesize); 391 + dev_kfree_skb(skb); 392 + goto out; /* atm_charge increments rx_drop */ 393 + } 394 + 395 + memcpy(skb->data, sarb->tail - pdu_length, length); 396 + __skb_put(skb, length); 397 + 398 + vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u", 399 + __func__, skb, skb->len, skb->truesize); 400 + 401 + PACKETDEBUG(skb->data, skb->len); 402 + 403 + vcc->push(vcc, skb); 404 + 405 + atomic_inc(&vcc->stats->rx); 406 + out: 407 + skb_trim(sarb, 0); 408 + } 409 + } 410 + } 411 + 412 + 413 + /************* 414 + ** encode ** 415 + *************/ 416 + 417 + static unsigned int usbatm_write_cells(struct usbatm_data *instance, 418 + struct sk_buff *skb, 419 + u8 *target, unsigned int avail_space) 420 + { 421 + struct usbatm_control *ctrl = UDSL_SKB(skb); 422 + struct atm_vcc *vcc = ctrl->atm.vcc; 423 + unsigned int num_written; 424 + unsigned int stride = instance->tx_channel.stride; 425 + 426 + vdbg("%s: skb->len=%d, avail_space=%u", __func__, skb->len, avail_space); 427 + UDSL_ASSERT(!(avail_space % stride)); 428 + 429 + for (num_written = 0; num_written < avail_space && ctrl->len; 430 + num_written += stride, target += stride) { 431 + unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD); 432 + unsigned int left = ATM_CELL_PAYLOAD - data_len; 433 + u8 *ptr = target; 434 + 435 + ptr[0] = vcc->vpi >> 4; 436 + ptr[1] = (vcc->vpi << 4) | (vcc->vci >> 12); 437 + ptr[2] = vcc->vci >> 4; 438 + ptr[3] = vcc->vci << 4; 439 + ptr[4] = 0xec; 440 + ptr += ATM_CELL_HEADER; 441 + 442 + memcpy(ptr, skb->data, data_len); 443 + ptr += data_len; 444 + __skb_pull(skb, data_len); 445 + 446 + if(!left) 447 + continue; 448 + 449 + memset(ptr, 0, left); 450 + 451 + if (left >= ATM_AAL5_TRAILER) { /* trailer will go in this cell */ 452 + u8 *trailer = target + ATM_CELL_SIZE - ATM_AAL5_TRAILER; 453 + /* trailer[0] = 0; UU = 0 */ 454 + /* trailer[1] = 0; CPI = 0 */ 455 + trailer[2] = ctrl->len >> 8; 456 + trailer[3] = ctrl->len; 457 + 458 + ctrl->crc = ~ crc32_be(ctrl->crc, ptr, left - 4); 459 + 460 + trailer[4] = ctrl->crc >> 24; 461 + trailer[5] = ctrl->crc >> 16; 462 + trailer[6] = ctrl->crc >> 8; 463 + trailer[7] = ctrl->crc; 464 + 465 + target[3] |= 0x2; /* adjust PTI */ 466 + 467 + ctrl->len = 0; /* tag this skb finished */ 468 + } 469 + else 470 + ctrl->crc = crc32_be(ctrl->crc, ptr, left); 471 + } 472 + 473 + return num_written; 474 + } 475 + 476 + 477 + /************** 478 + ** receive ** 479 + **************/ 480 + 481 + static void usbatm_rx_process(unsigned long data) 482 + { 483 + struct usbatm_data *instance = (struct usbatm_data *)data; 484 + struct urb *urb; 485 + 486 + while ((urb = usbatm_pop_urb(&instance->rx_channel))) { 487 + vdbg("%s: processing urb 0x%p", __func__, urb); 488 + 489 + if (usb_pipeisoc(urb->pipe)) { 490 + int i; 491 + for (i = 0; i < urb->number_of_packets; i++) 492 + if (!urb->iso_frame_desc[i].status) 493 + usbatm_extract_cells(instance, 494 + (u8 *)urb->transfer_buffer + urb->iso_frame_desc[i].offset, 495 + urb->iso_frame_desc[i].actual_length); 496 + } 497 + else 498 + if (!urb->status) 499 + usbatm_extract_cells(instance, urb->transfer_buffer, urb->actual_length); 500 + 501 + if (usbatm_submit_urb(urb)) 502 + return; 503 + } 504 + } 505 + 506 + 507 + /*********** 508 + ** send ** 509 + ***********/ 510 + 511 + static void usbatm_tx_process(unsigned long data) 512 + { 513 + struct usbatm_data *instance = (struct usbatm_data *)data; 514 + struct sk_buff *skb = instance->current_skb; 515 + struct urb *urb = NULL; 516 + const unsigned int buf_size = instance->tx_channel.buf_size; 517 + unsigned int num_written = 0; 518 + u8 *buffer = NULL; 519 + 520 + if (!skb) 521 + skb = skb_dequeue(&instance->sndqueue); 522 + 523 + while (skb) { 524 + if (!urb) { 525 + urb = usbatm_pop_urb(&instance->tx_channel); 526 + if (!urb) 527 + break; /* no more senders */ 528 + buffer = urb->transfer_buffer; 529 + num_written = (urb->status == -EAGAIN) ? 530 + urb->transfer_buffer_length : 0; 531 + } 532 + 533 + num_written += usbatm_write_cells(instance, skb, 534 + buffer + num_written, 535 + buf_size - num_written); 536 + 537 + vdbg("%s: wrote %u bytes from skb 0x%p to urb 0x%p", 538 + __func__, num_written, skb, urb); 539 + 540 + if (!UDSL_SKB(skb)->len) { 541 + struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc; 542 + 543 + usbatm_pop(vcc, skb); 544 + atomic_inc(&vcc->stats->tx); 545 + 546 + skb = skb_dequeue(&instance->sndqueue); 547 + } 548 + 549 + if (num_written == buf_size || (!skb && num_written)) { 550 + urb->transfer_buffer_length = num_written; 551 + 552 + if (usbatm_submit_urb(urb)) 553 + break; 554 + urb = NULL; 555 + } 556 + } 557 + 558 + instance->current_skb = skb; 559 + } 560 + 561 + static void usbatm_cancel_send(struct usbatm_data *instance, 562 + struct atm_vcc *vcc) 563 + { 564 + struct sk_buff *skb, *n; 565 + 566 + atm_dbg(instance, "%s entered\n", __func__); 567 + spin_lock_irq(&instance->sndqueue.lock); 568 + for (skb = instance->sndqueue.next, n = skb->next; 569 + skb != (struct sk_buff *)&instance->sndqueue; 570 + skb = n, n = skb->next) 571 + if (UDSL_SKB(skb)->atm.vcc == vcc) { 572 + atm_dbg(instance, "%s: popping skb 0x%p\n", __func__, skb); 573 + __skb_unlink(skb, &instance->sndqueue); 574 + usbatm_pop(vcc, skb); 575 + } 576 + spin_unlock_irq(&instance->sndqueue.lock); 577 + 578 + tasklet_disable(&instance->tx_channel.tasklet); 579 + if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm.vcc == vcc)) { 580 + atm_dbg(instance, "%s: popping current skb (0x%p)\n", __func__, skb); 581 + instance->current_skb = NULL; 582 + usbatm_pop(vcc, skb); 583 + } 584 + tasklet_enable(&instance->tx_channel.tasklet); 585 + atm_dbg(instance, "%s done\n", __func__); 586 + } 587 + 588 + static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb) 589 + { 590 + struct usbatm_data *instance = vcc->dev->dev_data; 591 + struct usbatm_control *ctrl = UDSL_SKB(skb); 592 + int err; 593 + 594 + vdbg("%s called (skb 0x%p, len %u)", __func__, skb, skb->len); 595 + 596 + if (!instance) { 597 + dbg("%s: NULL data!", __func__); 598 + err = -ENODEV; 599 + goto fail; 600 + } 601 + 602 + if (vcc->qos.aal != ATM_AAL5) { 603 + atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 604 + err = -EINVAL; 605 + goto fail; 606 + } 607 + 608 + if (skb->len > ATM_MAX_AAL5_PDU) { 609 + atm_dbg(instance, "%s: packet too long (%d vs %d)!\n", 610 + __func__, skb->len, ATM_MAX_AAL5_PDU); 611 + err = -EINVAL; 612 + goto fail; 613 + } 614 + 615 + PACKETDEBUG(skb->data, skb->len); 616 + 617 + /* initialize the control block */ 618 + ctrl->atm.vcc = vcc; 619 + ctrl->len = skb->len; 620 + ctrl->crc = crc32_be(~0, skb->data, skb->len); 621 + 622 + skb_queue_tail(&instance->sndqueue, skb); 623 + tasklet_schedule(&instance->tx_channel.tasklet); 624 + 625 + return 0; 626 + 627 + fail: 628 + usbatm_pop(vcc, skb); 629 + return err; 630 + } 631 + 632 + 633 + /******************** 634 + ** bean counting ** 635 + ********************/ 636 + 637 + static void usbatm_destroy_instance(struct kref *kref) 638 + { 639 + struct usbatm_data *instance = container_of(kref, struct usbatm_data, refcount); 640 + 641 + dbg("%s", __func__); 642 + 643 + tasklet_kill(&instance->rx_channel.tasklet); 644 + tasklet_kill(&instance->tx_channel.tasklet); 645 + usb_put_dev(instance->usb_dev); 646 + kfree(instance); 647 + } 648 + 649 + void usbatm_get_instance(struct usbatm_data *instance) 650 + { 651 + dbg("%s", __func__); 652 + 653 + kref_get(&instance->refcount); 654 + } 655 + 656 + void usbatm_put_instance(struct usbatm_data *instance) 657 + { 658 + dbg("%s", __func__); 659 + 660 + kref_put(&instance->refcount, usbatm_destroy_instance); 661 + } 662 + 663 + 664 + /********** 665 + ** ATM ** 666 + **********/ 667 + 668 + static void usbatm_atm_dev_close(struct atm_dev *dev) 669 + { 670 + struct usbatm_data *instance = dev->dev_data; 671 + 672 + dbg("%s", __func__); 673 + 674 + if (!instance) 675 + return; 676 + 677 + dev->dev_data = NULL; 678 + usbatm_put_instance(instance); /* taken in usbatm_atm_init */ 679 + } 680 + 681 + static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page) 682 + { 683 + struct usbatm_data *instance = atm_dev->dev_data; 684 + int left = *pos; 685 + 686 + if (!instance) { 687 + dbg("%s: NULL instance!", __func__); 688 + return -ENODEV; 689 + } 690 + 691 + if (!left--) 692 + return sprintf(page, "%s\n", instance->description); 693 + 694 + if (!left--) 695 + return sprintf(page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", 696 + atm_dev->esi[0], atm_dev->esi[1], 697 + atm_dev->esi[2], atm_dev->esi[3], 698 + atm_dev->esi[4], atm_dev->esi[5]); 699 + 700 + if (!left--) 701 + return sprintf(page, 702 + "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n", 703 + atomic_read(&atm_dev->stats.aal5.tx), 704 + atomic_read(&atm_dev->stats.aal5.tx_err), 705 + atomic_read(&atm_dev->stats.aal5.rx), 706 + atomic_read(&atm_dev->stats.aal5.rx_err), 707 + atomic_read(&atm_dev->stats.aal5.rx_drop)); 708 + 709 + if (!left--) 710 + switch (atm_dev->signal) { 711 + case ATM_PHY_SIG_FOUND: 712 + return sprintf(page, "Line up\n"); 713 + case ATM_PHY_SIG_LOST: 714 + return sprintf(page, "Line down\n"); 715 + default: 716 + return sprintf(page, "Line state unknown\n"); 717 + } 718 + 719 + return 0; 720 + } 721 + 722 + static int usbatm_atm_open(struct atm_vcc *vcc) 723 + { 724 + struct usbatm_data *instance = vcc->dev->dev_data; 725 + struct usbatm_vcc_data *new = NULL; 726 + int ret; 727 + int vci = vcc->vci; 728 + short vpi = vcc->vpi; 729 + 730 + if (!instance) { 731 + dbg("%s: NULL data!", __func__); 732 + return -ENODEV; 733 + } 734 + 735 + atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci); 736 + 737 + /* only support AAL5 */ 738 + if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0) 739 + || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) { 740 + atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 741 + return -EINVAL; 742 + } 743 + 744 + down(&instance->serialize); /* vs self, usbatm_atm_close */ 745 + 746 + if (usbatm_find_vcc(instance, vpi, vci)) { 747 + atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci); 748 + ret = -EADDRINUSE; 749 + goto fail; 750 + } 751 + 752 + if (!(new = kmalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) { 753 + atm_dbg(instance, "%s: no memory for vcc_data!\n", __func__); 754 + ret = -ENOMEM; 755 + goto fail; 756 + } 757 + 758 + memset(new, 0, sizeof(struct usbatm_vcc_data)); 759 + new->vcc = vcc; 760 + new->vpi = vpi; 761 + new->vci = vci; 762 + 763 + new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL); 764 + if (!new->sarb) { 765 + atm_dbg(instance, "%s: no memory for SAR buffer!\n", __func__); 766 + ret = -ENOMEM; 767 + goto fail; 768 + } 769 + 770 + vcc->dev_data = new; 771 + 772 + tasklet_disable(&instance->rx_channel.tasklet); 773 + list_add(&new->list, &instance->vcc_list); 774 + tasklet_enable(&instance->rx_channel.tasklet); 775 + 776 + set_bit(ATM_VF_ADDR, &vcc->flags); 777 + set_bit(ATM_VF_PARTIAL, &vcc->flags); 778 + set_bit(ATM_VF_READY, &vcc->flags); 779 + 780 + up(&instance->serialize); 781 + 782 + atm_dbg(instance, "%s: allocated vcc data 0x%p\n", __func__, new); 783 + 784 + return 0; 785 + 786 + fail: 787 + kfree(new); 788 + up(&instance->serialize); 789 + return ret; 790 + } 791 + 792 + static void usbatm_atm_close(struct atm_vcc *vcc) 793 + { 794 + struct usbatm_data *instance = vcc->dev->dev_data; 795 + struct usbatm_vcc_data *vcc_data = vcc->dev_data; 796 + 797 + if (!instance || !vcc_data) { 798 + dbg("%s: NULL data!", __func__); 799 + return; 800 + } 801 + 802 + atm_dbg(instance, "%s entered\n", __func__); 803 + 804 + atm_dbg(instance, "%s: deallocating vcc 0x%p with vpi %d vci %d\n", 805 + __func__, vcc_data, vcc_data->vpi, vcc_data->vci); 806 + 807 + usbatm_cancel_send(instance, vcc); 808 + 809 + down(&instance->serialize); /* vs self, usbatm_atm_open */ 810 + 811 + tasklet_disable(&instance->rx_channel.tasklet); 812 + list_del(&vcc_data->list); 813 + tasklet_enable(&instance->rx_channel.tasklet); 814 + 815 + kfree_skb(vcc_data->sarb); 816 + vcc_data->sarb = NULL; 817 + 818 + kfree(vcc_data); 819 + vcc->dev_data = NULL; 820 + 821 + vcc->vpi = ATM_VPI_UNSPEC; 822 + vcc->vci = ATM_VCI_UNSPEC; 823 + clear_bit(ATM_VF_READY, &vcc->flags); 824 + clear_bit(ATM_VF_PARTIAL, &vcc->flags); 825 + clear_bit(ATM_VF_ADDR, &vcc->flags); 826 + 827 + up(&instance->serialize); 828 + 829 + atm_dbg(instance, "%s successful\n", __func__); 830 + } 831 + 832 + static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, 833 + void __user * arg) 834 + { 835 + switch (cmd) { 836 + case ATM_QUERYLOOP: 837 + return put_user(ATM_LM_NONE, (int __user *)arg) ? -EFAULT : 0; 838 + default: 839 + return -ENOIOCTLCMD; 840 + } 841 + } 842 + 843 + static int usbatm_atm_init(struct usbatm_data *instance) 844 + { 845 + struct atm_dev *atm_dev; 846 + int ret, i; 847 + 848 + /* ATM init */ 849 + atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL); 850 + if (!atm_dev) { 851 + usb_dbg(instance, "%s: failed to register ATM device!\n", __func__); 852 + return -1; 853 + } 854 + 855 + instance->atm_dev = atm_dev; 856 + 857 + atm_dev->ci_range.vpi_bits = ATM_CI_MAX; 858 + atm_dev->ci_range.vci_bits = ATM_CI_MAX; 859 + atm_dev->signal = ATM_PHY_SIG_UNKNOWN; 860 + 861 + /* temp init ATM device, set to 128kbit */ 862 + atm_dev->link_rate = 128 * 1000 / 424; 863 + 864 + if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) { 865 + atm_dbg(instance, "%s: atm_start failed: %d!\n", __func__, ret); 866 + goto fail; 867 + } 868 + 869 + /* ready for ATM callbacks */ 870 + usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */ 871 + mb(); 872 + atm_dev->dev_data = instance; 873 + 874 + /* submit all rx URBs */ 875 + for (i = 0; i < num_rcv_urbs; i++) 876 + usbatm_submit_urb(instance->urbs[i]); 877 + 878 + return 0; 879 + 880 + fail: 881 + instance->atm_dev = NULL; 882 + shutdown_atm_dev(atm_dev); /* usbatm_atm_dev_close will eventually be called */ 883 + return ret; 884 + } 885 + 886 + 887 + /********** 888 + ** USB ** 889 + **********/ 890 + 891 + static int usbatm_do_heavy_init(void *arg) 892 + { 893 + struct usbatm_data *instance = arg; 894 + int ret; 895 + 896 + daemonize(instance->driver->driver_name); 897 + allow_signal(SIGTERM); 898 + 899 + complete(&instance->thread_started); 900 + 901 + ret = instance->driver->heavy_init(instance, instance->usb_intf); 902 + 903 + if (!ret) 904 + ret = usbatm_atm_init(instance); 905 + 906 + down(&instance->serialize); 907 + instance->thread_pid = -1; 908 + up(&instance->serialize); 909 + 910 + complete_and_exit(&instance->thread_exited, ret); 911 + } 912 + 913 + static int usbatm_heavy_init(struct usbatm_data *instance) 914 + { 915 + int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL); 916 + 917 + if (ret < 0) { 918 + usb_dbg(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret); 919 + return ret; 920 + } 921 + 922 + down(&instance->serialize); 923 + instance->thread_pid = ret; 924 + up(&instance->serialize); 925 + 926 + wait_for_completion(&instance->thread_started); 927 + 928 + return 0; 929 + } 930 + 931 + static void usbatm_tasklet_schedule(unsigned long data) 932 + { 933 + tasklet_schedule((struct tasklet_struct *) data); 934 + } 935 + 936 + static inline void usbatm_init_channel(struct usbatm_channel *channel) 937 + { 938 + spin_lock_init(&channel->lock); 939 + INIT_LIST_HEAD(&channel->list); 940 + channel->delay.function = usbatm_tasklet_schedule; 941 + channel->delay.data = (unsigned long) &channel->tasklet; 942 + init_timer(&channel->delay); 943 + } 944 + 945 + int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, 946 + struct usbatm_driver *driver) 947 + { 948 + struct device *dev = &intf->dev; 949 + struct usb_device *usb_dev = interface_to_usbdev(intf); 950 + struct usbatm_data *instance; 951 + char *buf; 952 + int error = -ENOMEM; 953 + int i, length; 954 + int need_heavy; 955 + 956 + dev_dbg(dev, "%s: trying driver %s with vendor=0x%x, product=0x%x, ifnum %d\n", 957 + __func__, driver->driver_name, 958 + le16_to_cpu(usb_dev->descriptor.idVendor), 959 + le16_to_cpu(usb_dev->descriptor.idProduct), 960 + intf->altsetting->desc.bInterfaceNumber); 961 + 962 + /* instance init */ 963 + instance = kcalloc(1, sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL); 964 + if (!instance) { 965 + dev_dbg(dev, "%s: no memory for instance data!\n", __func__); 966 + return -ENOMEM; 967 + } 968 + 969 + /* public fields */ 970 + 971 + instance->driver = driver; 972 + snprintf(instance->driver_name, sizeof(instance->driver_name), driver->driver_name); 973 + 974 + instance->usb_dev = usb_dev; 975 + instance->usb_intf = intf; 976 + 977 + buf = instance->description; 978 + length = sizeof(instance->description); 979 + 980 + if ((i = usb_string(usb_dev, usb_dev->descriptor.iProduct, buf, length)) < 0) 981 + goto bind; 982 + 983 + buf += i; 984 + length -= i; 985 + 986 + i = scnprintf(buf, length, " ("); 987 + buf += i; 988 + length -= i; 989 + 990 + if (length <= 0 || (i = usb_make_path(usb_dev, buf, length)) < 0) 991 + goto bind; 992 + 993 + buf += i; 994 + length -= i; 995 + 996 + snprintf(buf, length, ")"); 997 + 998 + bind: 999 + need_heavy = 1; 1000 + if (driver->bind && (error = driver->bind(instance, intf, id, &need_heavy)) < 0) { 1001 + dev_dbg(dev, "%s: bind failed: %d!\n", __func__, error); 1002 + goto fail_free; 1003 + } 1004 + 1005 + /* private fields */ 1006 + 1007 + kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */ 1008 + init_MUTEX(&instance->serialize); 1009 + 1010 + instance->thread_pid = -1; 1011 + init_completion(&instance->thread_started); 1012 + init_completion(&instance->thread_exited); 1013 + 1014 + INIT_LIST_HEAD(&instance->vcc_list); 1015 + 1016 + usbatm_init_channel(&instance->rx_channel); 1017 + usbatm_init_channel(&instance->tx_channel); 1018 + tasklet_init(&instance->rx_channel.tasklet, usbatm_rx_process, (unsigned long)instance); 1019 + tasklet_init(&instance->tx_channel.tasklet, usbatm_tx_process, (unsigned long)instance); 1020 + instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->in); 1021 + instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->out); 1022 + instance->rx_channel.stride = ATM_CELL_SIZE + driver->rx_padding; 1023 + instance->tx_channel.stride = ATM_CELL_SIZE + driver->tx_padding; 1024 + instance->rx_channel.buf_size = rcv_buf_size * instance->rx_channel.stride; 1025 + instance->tx_channel.buf_size = snd_buf_size * instance->tx_channel.stride; 1026 + instance->rx_channel.usbatm = instance->tx_channel.usbatm = instance; 1027 + 1028 + skb_queue_head_init(&instance->sndqueue); 1029 + 1030 + for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 1031 + struct urb *urb; 1032 + u8 *buffer; 1033 + unsigned int iso_packets = 0, iso_size = 0; 1034 + struct usbatm_channel *channel = i < num_rcv_urbs ? 1035 + &instance->rx_channel : &instance->tx_channel; 1036 + 1037 + if (usb_pipeisoc(channel->endpoint)) { 1038 + /* don't expect iso out endpoints */ 1039 + iso_size = usb_maxpacket(instance->usb_dev, channel->endpoint, 0); 1040 + iso_size -= iso_size % channel->stride; /* alignment */ 1041 + BUG_ON(!iso_size); 1042 + iso_packets = (channel->buf_size - 1) / iso_size + 1; 1043 + } 1044 + 1045 + urb = usb_alloc_urb(iso_packets, GFP_KERNEL); 1046 + if (!urb) { 1047 + dev_dbg(dev, "%s: no memory for urb %d!\n", __func__, i); 1048 + goto fail_unbind; 1049 + } 1050 + 1051 + instance->urbs[i] = urb; 1052 + 1053 + buffer = kmalloc(channel->buf_size, GFP_KERNEL); 1054 + if (!buffer) { 1055 + dev_dbg(dev, "%s: no memory for buffer %d!\n", __func__, i); 1056 + goto fail_unbind; 1057 + } 1058 + memset(buffer, 0, channel->buf_size); 1059 + 1060 + usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint, 1061 + buffer, channel->buf_size, usbatm_complete, channel); 1062 + if (iso_packets) { 1063 + int j; 1064 + urb->interval = 1; 1065 + urb->transfer_flags = URB_ISO_ASAP; 1066 + urb->number_of_packets = iso_packets; 1067 + for (j = 0; j < iso_packets; j++) { 1068 + urb->iso_frame_desc[j].offset = iso_size * j; 1069 + urb->iso_frame_desc[j].length = min_t(int, iso_size, 1070 + channel->buf_size - urb->iso_frame_desc[j].offset); 1071 + } 1072 + } 1073 + 1074 + /* put all tx URBs on the list of spares */ 1075 + if (i >= num_rcv_urbs) 1076 + list_add_tail(&urb->urb_list, &channel->list); 1077 + 1078 + vdbg("%s: alloced buffer 0x%p buf size %u urb 0x%p", 1079 + __func__, urb->transfer_buffer, urb->transfer_buffer_length, urb); 1080 + } 1081 + 1082 + if (need_heavy && driver->heavy_init) { 1083 + error = usbatm_heavy_init(instance); 1084 + } else { 1085 + complete(&instance->thread_exited); /* pretend that heavy_init was run */ 1086 + error = usbatm_atm_init(instance); 1087 + } 1088 + 1089 + if (error < 0) 1090 + goto fail_unbind; 1091 + 1092 + usb_get_dev(usb_dev); 1093 + usb_set_intfdata(intf, instance); 1094 + 1095 + return 0; 1096 + 1097 + fail_unbind: 1098 + if (instance->driver->unbind) 1099 + instance->driver->unbind(instance, intf); 1100 + fail_free: 1101 + for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 1102 + if (instance->urbs[i]) 1103 + kfree(instance->urbs[i]->transfer_buffer); 1104 + usb_free_urb(instance->urbs[i]); 1105 + } 1106 + 1107 + kfree (instance); 1108 + 1109 + return error; 1110 + } 1111 + EXPORT_SYMBOL_GPL(usbatm_usb_probe); 1112 + 1113 + void usbatm_usb_disconnect(struct usb_interface *intf) 1114 + { 1115 + struct device *dev = &intf->dev; 1116 + struct usbatm_data *instance = usb_get_intfdata(intf); 1117 + int i; 1118 + 1119 + dev_dbg(dev, "%s entered\n", __func__); 1120 + 1121 + if (!instance) { 1122 + dev_dbg(dev, "%s: NULL instance!\n", __func__); 1123 + return; 1124 + } 1125 + 1126 + usb_set_intfdata(intf, NULL); 1127 + 1128 + down(&instance->serialize); 1129 + if (instance->thread_pid >= 0) 1130 + kill_proc(instance->thread_pid, SIGTERM, 1); 1131 + up(&instance->serialize); 1132 + 1133 + wait_for_completion(&instance->thread_exited); 1134 + 1135 + tasklet_disable(&instance->rx_channel.tasklet); 1136 + tasklet_disable(&instance->tx_channel.tasklet); 1137 + 1138 + for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) 1139 + usb_kill_urb(instance->urbs[i]); 1140 + 1141 + del_timer_sync(&instance->rx_channel.delay); 1142 + del_timer_sync(&instance->tx_channel.delay); 1143 + 1144 + if (instance->atm_dev && instance->driver->atm_stop) 1145 + instance->driver->atm_stop(instance, instance->atm_dev); 1146 + 1147 + if (instance->driver->unbind) 1148 + instance->driver->unbind(instance, intf); 1149 + 1150 + instance->driver_data = NULL; 1151 + 1152 + /* turn usbatm_[rt]x_process into noop */ 1153 + /* no need to take the spinlock */ 1154 + INIT_LIST_HEAD(&instance->rx_channel.list); 1155 + INIT_LIST_HEAD(&instance->tx_channel.list); 1156 + 1157 + tasklet_enable(&instance->rx_channel.tasklet); 1158 + tasklet_enable(&instance->tx_channel.tasklet); 1159 + 1160 + for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) { 1161 + kfree(instance->urbs[i]->transfer_buffer); 1162 + usb_free_urb(instance->urbs[i]); 1163 + } 1164 + 1165 + /* ATM finalize */ 1166 + if (instance->atm_dev) 1167 + shutdown_atm_dev(instance->atm_dev); 1168 + 1169 + usbatm_put_instance(instance); /* taken in usbatm_usb_probe */ 1170 + } 1171 + EXPORT_SYMBOL_GPL(usbatm_usb_disconnect); 1172 + 1173 + 1174 + /*********** 1175 + ** init ** 1176 + ***********/ 1177 + 1178 + static int __init usbatm_usb_init(void) 1179 + { 1180 + dbg("%s: driver version %s", __func__, DRIVER_VERSION); 1181 + 1182 + if (sizeof(struct usbatm_control) > sizeof(((struct sk_buff *) 0)->cb)) { 1183 + printk(KERN_ERR "%s unusable with this kernel!\n", usbatm_driver_name); 1184 + return -EIO; 1185 + } 1186 + 1187 + if ((num_rcv_urbs > UDSL_MAX_RCV_URBS) 1188 + || (num_snd_urbs > UDSL_MAX_SND_URBS) 1189 + || (rcv_buf_size < 1) 1190 + || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE) 1191 + || (snd_buf_size < 1) 1192 + || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE)) 1193 + return -EINVAL; 1194 + 1195 + return 0; 1196 + } 1197 + module_init(usbatm_usb_init); 1198 + 1199 + static void __exit usbatm_usb_exit(void) 1200 + { 1201 + dbg("%s", __func__); 1202 + } 1203 + module_exit(usbatm_usb_exit); 1204 + 1205 + MODULE_AUTHOR(DRIVER_AUTHOR); 1206 + MODULE_DESCRIPTION(DRIVER_DESC); 1207 + MODULE_LICENSE("GPL"); 1208 + MODULE_VERSION(DRIVER_VERSION); 1209 + 1210 + /************ 1211 + ** debug ** 1212 + ************/ 1213 + 1214 + #ifdef VERBOSE_DEBUG 1215 + static int usbatm_print_packet(const unsigned char *data, int len) 1216 + { 1217 + unsigned char buffer[256]; 1218 + int i = 0, j = 0; 1219 + 1220 + for (i = 0; i < len;) { 1221 + buffer[0] = '\0'; 1222 + sprintf(buffer, "%.3d :", i); 1223 + for (j = 0; (j < 16) && (i < len); j++, i++) { 1224 + sprintf(buffer, "%s %2.2x", buffer, data[i]); 1225 + } 1226 + dbg("%s", buffer); 1227 + } 1228 + return i; 1229 + } 1230 + #endif
+184
drivers/usb/atm/usbatm.h
··· 1 + /****************************************************************************** 2 + * usbatm.h - Generic USB xDSL driver core 3 + * 4 + * Copyright (C) 2001, Alcatel 5 + * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas 6 + * Copyright (C) 2004, David Woodhouse 7 + * 8 + * 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 10 + * Software Foundation; either version 2 of the License, or (at your option) 11 + * any later version. 12 + * 13 + * This program is distributed in the hope that it will be useful, but WITHOUT 14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 + * more details. 17 + * 18 + * You should have received a copy of the GNU General Public License along with 19 + * this program; if not, write to the Free Software Foundation, Inc., 59 20 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 + * 22 + ******************************************************************************/ 23 + 24 + #ifndef _USBATM_H_ 25 + #define _USBATM_H_ 26 + 27 + #include <linux/config.h> 28 + 29 + /* 30 + #define DEBUG 31 + #define VERBOSE_DEBUG 32 + */ 33 + 34 + #if !defined (DEBUG) && defined (CONFIG_USB_DEBUG) 35 + # define DEBUG 36 + #endif 37 + 38 + #include <asm/semaphore.h> 39 + #include <linux/atm.h> 40 + #include <linux/atmdev.h> 41 + #include <linux/completion.h> 42 + #include <linux/device.h> 43 + #include <linux/kref.h> 44 + #include <linux/list.h> 45 + #include <linux/stringify.h> 46 + #include <linux/usb.h> 47 + 48 + #ifdef DEBUG 49 + #define UDSL_ASSERT(x) BUG_ON(!(x)) 50 + #else 51 + #define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '%s' at line %d", __stringify(x), __LINE__); } while(0) 52 + #endif 53 + 54 + #define usb_err(instance, format, arg...) \ 55 + dev_err(&(instance)->usb_intf->dev , format , ## arg) 56 + #define usb_info(instance, format, arg...) \ 57 + dev_info(&(instance)->usb_intf->dev , format , ## arg) 58 + #define usb_warn(instance, format, arg...) \ 59 + dev_warn(&(instance)->usb_intf->dev , format , ## arg) 60 + #define usb_dbg(instance, format, arg...) \ 61 + dev_dbg(&(instance)->usb_intf->dev , format , ## arg) 62 + 63 + /* FIXME: move to dev_* once ATM is driver model aware */ 64 + #define atm_printk(level, instance, format, arg...) \ 65 + printk(level "ATM dev %d: " format , \ 66 + (instance)->atm_dev->number , ## arg) 67 + 68 + #define atm_err(instance, format, arg...) \ 69 + atm_printk(KERN_ERR, instance , format , ## arg) 70 + #define atm_info(instance, format, arg...) \ 71 + atm_printk(KERN_INFO, instance , format , ## arg) 72 + #define atm_warn(instance, format, arg...) \ 73 + atm_printk(KERN_WARNING, instance , format , ## arg) 74 + #ifdef DEBUG 75 + #define atm_dbg(instance, format, arg...) \ 76 + atm_printk(KERN_DEBUG, instance , format , ## arg) 77 + #else 78 + #define atm_dbg(instance, format, arg...) \ 79 + do {} while (0) 80 + #endif 81 + 82 + 83 + /* mini driver */ 84 + 85 + struct usbatm_data; 86 + 87 + /* 88 + * Assuming all methods exist and succeed, they are called in this order: 89 + * 90 + * bind, heavy_init, atm_start, ..., atm_stop, unbind 91 + */ 92 + 93 + struct usbatm_driver { 94 + struct module *owner; 95 + 96 + const char *driver_name; 97 + 98 + /* 99 + * init device ... can sleep, or cause probe() failure. Drivers with a heavy_init 100 + * method can avoid having it called by setting need_heavy_init to zero. 101 + */ 102 + int (*bind) (struct usbatm_data *, struct usb_interface *, 103 + const struct usb_device_id *id, int *need_heavy_init); 104 + 105 + /* additional device initialization that is too slow to be done in probe() */ 106 + int (*heavy_init) (struct usbatm_data *, struct usb_interface *); 107 + 108 + /* cleanup device ... can sleep, but can't fail */ 109 + void (*unbind) (struct usbatm_data *, struct usb_interface *); 110 + 111 + /* init ATM device ... can sleep, or cause ATM initialization failure */ 112 + int (*atm_start) (struct usbatm_data *, struct atm_dev *); 113 + 114 + /* cleanup ATM device ... can sleep, but can't fail */ 115 + void (*atm_stop) (struct usbatm_data *, struct atm_dev *); 116 + 117 + int in; /* rx endpoint */ 118 + int out; /* tx endpoint */ 119 + 120 + unsigned rx_padding; 121 + unsigned tx_padding; 122 + }; 123 + 124 + extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, 125 + struct usbatm_driver *driver); 126 + extern void usbatm_usb_disconnect(struct usb_interface *intf); 127 + 128 + 129 + struct usbatm_channel { 130 + int endpoint; /* usb pipe */ 131 + unsigned int stride; /* ATM cell size + padding */ 132 + unsigned int buf_size; /* urb buffer size */ 133 + spinlock_t lock; 134 + struct list_head list; 135 + struct tasklet_struct tasklet; 136 + struct timer_list delay; 137 + struct usbatm_data *usbatm; 138 + }; 139 + 140 + /* main driver data */ 141 + 142 + struct usbatm_data { 143 + /****************** 144 + * public fields * 145 + ******************/ 146 + 147 + /* mini driver */ 148 + struct usbatm_driver *driver; 149 + void *driver_data; 150 + char driver_name[16]; 151 + 152 + /* USB device */ 153 + struct usb_device *usb_dev; 154 + struct usb_interface *usb_intf; 155 + char description[64]; 156 + 157 + /* ATM device */ 158 + struct atm_dev *atm_dev; 159 + 160 + /******************************** 161 + * private fields - do not use * 162 + ********************************/ 163 + 164 + struct kref refcount; 165 + struct semaphore serialize; 166 + 167 + /* heavy init */ 168 + int thread_pid; 169 + struct completion thread_started; 170 + struct completion thread_exited; 171 + 172 + /* ATM device */ 173 + struct list_head vcc_list; 174 + 175 + struct usbatm_channel rx_channel; 176 + struct usbatm_channel tx_channel; 177 + 178 + struct sk_buff_head sndqueue; 179 + struct sk_buff *current_skb; /* being emptied */ 180 + 181 + struct urb *urbs[0]; 182 + }; 183 + 184 + #endif /* _USBATM_H_ */
+196
drivers/usb/atm/xusbatm.c
··· 1 + /****************************************************************************** 2 + * xusbatm.c - dumb usbatm-based driver for modems initialized in userspace 3 + * 4 + * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru) 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License as published by the Free 8 + * Software Foundation; either version 2 of the License, or (at your option) 9 + * any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, but WITHOUT 12 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 + * more details. 15 + * 16 + * You should have received a copy of the GNU General Public License along with 17 + * this program; if not, write to the Free Software Foundation, Inc., 59 18 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 + * 20 + ******************************************************************************/ 21 + 22 + #include <linux/module.h> 23 + #include <linux/netdevice.h> /* FIXME: required by linux/etherdevice.h */ 24 + #include <linux/etherdevice.h> /* for random_ether_addr() */ 25 + 26 + #include "usbatm.h" 27 + 28 + 29 + #define XUSBATM_DRIVERS_MAX 8 30 + 31 + #define XUSBATM_PARM(name, type, parmtype, desc) \ 32 + static type name[XUSBATM_DRIVERS_MAX]; \ 33 + static int num_##name; \ 34 + module_param_array(name, parmtype, &num_##name, 0444); \ 35 + MODULE_PARM_DESC(name, desc) 36 + 37 + XUSBATM_PARM(vendor, unsigned short, ushort, "USB device vendor"); 38 + XUSBATM_PARM(product, unsigned short, ushort, "USB device product"); 39 + 40 + XUSBATM_PARM(rx_endpoint, unsigned char, byte, "rx endpoint number"); 41 + XUSBATM_PARM(tx_endpoint, unsigned char, byte, "tx endpoint number"); 42 + XUSBATM_PARM(rx_padding, unsigned char, byte, "rx padding (default 0)"); 43 + XUSBATM_PARM(tx_padding, unsigned char, byte, "tx padding (default 0)"); 44 + 45 + static const char xusbatm_driver_name[] = "xusbatm"; 46 + 47 + static struct usbatm_driver xusbatm_drivers[XUSBATM_DRIVERS_MAX]; 48 + static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1]; 49 + static struct usb_driver xusbatm_usb_driver; 50 + 51 + static int usb_intf_has_ep(const struct usb_interface *intf, u8 ep) 52 + { 53 + int i, j; 54 + 55 + for (i = 0; i < intf->num_altsetting; i++) { 56 + struct usb_host_interface *alt = intf->altsetting; 57 + for (j = 0; j < alt->desc.bNumEndpoints; j++) 58 + if ((alt->endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) == ep) 59 + return 1; 60 + } 61 + return 0; 62 + } 63 + 64 + static int xusbatm_bind(struct usbatm_data *usbatm_instance, 65 + struct usb_interface *intf, const struct usb_device_id *id, 66 + int *need_heavy_init) 67 + { 68 + struct usb_device *usb_dev = interface_to_usbdev(intf); 69 + int drv_ix = id - xusbatm_usb_ids; 70 + int rx_ep_present = usb_intf_has_ep(intf, rx_endpoint[drv_ix]); 71 + int tx_ep_present = usb_intf_has_ep(intf, tx_endpoint[drv_ix]); 72 + u8 searched_ep = rx_ep_present ? tx_endpoint[drv_ix] : rx_endpoint[drv_ix]; 73 + int i, ret; 74 + 75 + usb_dbg(usbatm_instance, "%s: binding driver %d: vendor %#x product %#x" 76 + " rx: ep %#x padd %d tx: ep %#x padd %d\n", 77 + __func__, drv_ix, vendor[drv_ix], product[drv_ix], 78 + rx_endpoint[drv_ix], rx_padding[drv_ix], 79 + tx_endpoint[drv_ix], tx_padding[drv_ix]); 80 + 81 + if (!rx_ep_present && !tx_ep_present) { 82 + usb_dbg(usbatm_instance, "%s: intf #%d has neither rx (%#x) nor tx (%#x) endpoint\n", 83 + __func__, intf->altsetting->desc.bInterfaceNumber, 84 + rx_endpoint[drv_ix], tx_endpoint[drv_ix]); 85 + return -ENODEV; 86 + } 87 + 88 + if (rx_ep_present && tx_ep_present) 89 + return 0; 90 + 91 + for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) { 92 + struct usb_interface *cur_if = usb_dev->actconfig->interface[i]; 93 + 94 + if (cur_if != intf && usb_intf_has_ep(cur_if, searched_ep)) { 95 + ret = usb_driver_claim_interface(&xusbatm_usb_driver, 96 + cur_if, usbatm_instance); 97 + if (!ret) 98 + usb_err(usbatm_instance, "%s: failed to claim interface #%d (%d)\n", 99 + __func__, cur_if->altsetting->desc.bInterfaceNumber, ret); 100 + return ret; 101 + } 102 + } 103 + 104 + usb_err(usbatm_instance, "%s: no interface has endpoint %#x\n", 105 + __func__, searched_ep); 106 + return -ENODEV; 107 + } 108 + 109 + static void xusbatm_unbind(struct usbatm_data *usbatm_instance, 110 + struct usb_interface *intf) 111 + { 112 + struct usb_device *usb_dev = interface_to_usbdev(intf); 113 + int i; 114 + usb_dbg(usbatm_instance, "%s entered\n", __func__); 115 + 116 + for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) { 117 + struct usb_interface *cur_if = usb_dev->actconfig->interface[i]; 118 + usb_set_intfdata(cur_if, NULL); 119 + usb_driver_release_interface(&xusbatm_usb_driver, cur_if); 120 + } 121 + } 122 + 123 + static int xusbatm_atm_start(struct usbatm_data *usbatm_instance, 124 + struct atm_dev *atm_dev) 125 + { 126 + atm_dbg(usbatm_instance, "%s entered\n", __func__); 127 + 128 + /* use random MAC as we've no way to get it from the device */ 129 + random_ether_addr(atm_dev->esi); 130 + 131 + return 0; 132 + } 133 + 134 + 135 + static int xusbatm_usb_probe(struct usb_interface *intf, 136 + const struct usb_device_id *id) 137 + { 138 + return usbatm_usb_probe(intf, id, 139 + xusbatm_drivers + (id - xusbatm_usb_ids)); 140 + } 141 + 142 + static struct usb_driver xusbatm_usb_driver = { 143 + .owner = THIS_MODULE, 144 + .name = xusbatm_driver_name, 145 + .probe = xusbatm_usb_probe, 146 + .disconnect = usbatm_usb_disconnect, 147 + .id_table = xusbatm_usb_ids 148 + }; 149 + 150 + static int __init xusbatm_init(void) 151 + { 152 + int i; 153 + 154 + dbg("xusbatm_init"); 155 + 156 + if (!num_vendor || 157 + num_vendor != num_product || 158 + num_vendor != num_rx_endpoint || 159 + num_vendor != num_tx_endpoint) { 160 + warn("malformed module parameters"); 161 + return -EINVAL; 162 + } 163 + 164 + for (i = 0; i < num_vendor; i++) { 165 + xusbatm_usb_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 166 + xusbatm_usb_ids[i].idVendor = vendor[i]; 167 + xusbatm_usb_ids[i].idProduct = product[i]; 168 + 169 + 170 + xusbatm_drivers[i].owner = THIS_MODULE; 171 + xusbatm_drivers[i].driver_name = xusbatm_driver_name; 172 + xusbatm_drivers[i].bind = xusbatm_bind; 173 + xusbatm_drivers[i].unbind = xusbatm_unbind; 174 + xusbatm_drivers[i].atm_start = xusbatm_atm_start; 175 + xusbatm_drivers[i].in = rx_endpoint[i]; 176 + xusbatm_drivers[i].out = tx_endpoint[i]; 177 + xusbatm_drivers[i].rx_padding = rx_padding[i]; 178 + xusbatm_drivers[i].tx_padding = tx_padding[i]; 179 + } 180 + 181 + return usb_register(&xusbatm_usb_driver); 182 + } 183 + module_init(xusbatm_init); 184 + 185 + static void __exit xusbatm_exit(void) 186 + { 187 + dbg("xusbatm_exit entered"); 188 + 189 + usb_deregister(&xusbatm_usb_driver); 190 + } 191 + module_exit(xusbatm_exit); 192 + 193 + MODULE_AUTHOR("Roman Kagan, Duncan Sands"); 194 + MODULE_DESCRIPTION("Driver for USB ADSL modems initialized in userspace"); 195 + MODULE_LICENSE("GPL"); 196 + MODULE_VERSION("0.1");
+177 -36
drivers/usb/class/cdc-acm.c
··· 106 106 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0) 107 107 108 108 /* 109 + * Write buffer management. 110 + * All of these assume proper locks taken by the caller. 111 + */ 112 + 113 + static int acm_wb_alloc(struct acm *acm) 114 + { 115 + int i, wbn; 116 + struct acm_wb *wb; 117 + 118 + wbn = acm->write_current; 119 + i = 0; 120 + for (;;) { 121 + wb = &acm->wb[wbn]; 122 + if (!wb->use) { 123 + wb->use = 1; 124 + return wbn; 125 + } 126 + wbn = (wbn + 1) % ACM_NWB; 127 + if (++i >= ACM_NWB) 128 + return -1; 129 + } 130 + } 131 + 132 + static void acm_wb_free(struct acm *acm, int wbn) 133 + { 134 + acm->wb[wbn].use = 0; 135 + } 136 + 137 + static int acm_wb_is_avail(struct acm *acm) 138 + { 139 + int i, n; 140 + 141 + n = 0; 142 + for (i = 0; i < ACM_NWB; i++) { 143 + if (!acm->wb[i].use) 144 + n++; 145 + } 146 + return n; 147 + } 148 + 149 + static inline int acm_wb_is_used(struct acm *acm, int wbn) 150 + { 151 + return acm->wb[wbn].use; 152 + } 153 + 154 + /* 155 + * Finish write. 156 + */ 157 + static void acm_write_done(struct acm *acm) 158 + { 159 + unsigned long flags; 160 + int wbn; 161 + 162 + spin_lock_irqsave(&acm->write_lock, flags); 163 + acm->write_ready = 1; 164 + wbn = acm->write_current; 165 + acm_wb_free(acm, wbn); 166 + acm->write_current = (wbn + 1) % ACM_NWB; 167 + spin_unlock_irqrestore(&acm->write_lock, flags); 168 + } 169 + 170 + /* 171 + * Poke write. 172 + */ 173 + static int acm_write_start(struct acm *acm) 174 + { 175 + unsigned long flags; 176 + int wbn; 177 + struct acm_wb *wb; 178 + int rc; 179 + 180 + spin_lock_irqsave(&acm->write_lock, flags); 181 + if (!acm->dev) { 182 + spin_unlock_irqrestore(&acm->write_lock, flags); 183 + return -ENODEV; 184 + } 185 + 186 + if (!acm->write_ready) { 187 + spin_unlock_irqrestore(&acm->write_lock, flags); 188 + return 0; /* A white lie */ 189 + } 190 + 191 + wbn = acm->write_current; 192 + if (!acm_wb_is_used(acm, wbn)) { 193 + spin_unlock_irqrestore(&acm->write_lock, flags); 194 + return 0; 195 + } 196 + wb = &acm->wb[wbn]; 197 + 198 + acm->write_ready = 0; 199 + spin_unlock_irqrestore(&acm->write_lock, flags); 200 + 201 + acm->writeurb->transfer_buffer = wb->buf; 202 + acm->writeurb->transfer_dma = wb->dmah; 203 + acm->writeurb->transfer_buffer_length = wb->len; 204 + acm->writeurb->dev = acm->dev; 205 + 206 + if ((rc = usb_submit_urb(acm->writeurb, GFP_ATOMIC)) < 0) { 207 + dbg("usb_submit_urb(write bulk) failed: %d", rc); 208 + acm_write_done(acm); 209 + } 210 + return rc; 211 + } 212 + 213 + /* 109 214 * Interrupt handlers for various ACM device responses 110 215 */ 111 216 ··· 342 237 static void acm_write_bulk(struct urb *urb, struct pt_regs *regs) 343 238 { 344 239 struct acm *acm = (struct acm *)urb->context; 240 + 345 241 dbg("Entering acm_write_bulk with status %d\n", urb->status); 346 242 347 - if (!ACM_READY(acm)) 348 - goto out; 349 - 350 - if (urb->status) 351 - dbg("nonzero write bulk status received: %d", urb->status); 352 - 353 - schedule_work(&acm->work); 354 - out: 355 - acm->ready_for_write = 1; 243 + acm_write_done(acm); 244 + acm_write_start(acm); 245 + if (ACM_READY(acm)) 246 + schedule_work(&acm->work); 356 247 } 357 248 358 249 static void acm_softint(void *private) ··· 452 351 { 453 352 struct acm *acm = tty->driver_data; 454 353 int stat; 354 + unsigned long flags; 355 + int wbn; 356 + struct acm_wb *wb; 357 + 455 358 dbg("Entering acm_tty_write to write %d bytes,\n", count); 456 359 457 360 if (!ACM_READY(acm)) 458 361 return -EINVAL; 459 - if (!acm->ready_for_write) 460 - return 0; 461 362 if (!count) 462 363 return 0; 463 364 464 - count = (count > acm->writesize) ? acm->writesize : count; 465 - 466 - dbg("Get %d bytes...", count); 467 - memcpy(acm->write_buffer, buf, count); 468 - dbg(" Successfully copied.\n"); 469 - 470 - acm->writeurb->transfer_buffer_length = count; 471 - acm->writeurb->dev = acm->dev; 472 - 473 - acm->ready_for_write = 0; 474 - stat = usb_submit_urb(acm->writeurb, GFP_ATOMIC); 475 - if (stat < 0) { 476 - dbg("usb_submit_urb(write bulk) failed"); 477 - acm->ready_for_write = 1; 478 - return stat; 365 + spin_lock_irqsave(&acm->write_lock, flags); 366 + if ((wbn = acm_wb_alloc(acm)) < 0) { 367 + spin_unlock_irqrestore(&acm->write_lock, flags); 368 + acm_write_start(acm); 369 + return 0; 479 370 } 371 + wb = &acm->wb[wbn]; 480 372 373 + count = (count > acm->writesize) ? acm->writesize : count; 374 + dbg("Get %d bytes...", count); 375 + memcpy(wb->buf, buf, count); 376 + wb->len = count; 377 + spin_unlock_irqrestore(&acm->write_lock, flags); 378 + 379 + if ((stat = acm_write_start(acm)) < 0) 380 + return stat; 481 381 return count; 482 382 } 483 383 ··· 487 385 struct acm *acm = tty->driver_data; 488 386 if (!ACM_READY(acm)) 489 387 return -EINVAL; 490 - return !acm->ready_for_write ? 0 : acm->writesize; 388 + /* 389 + * Do not let the line discipline to know that we have a reserve, 390 + * or it might get too enthusiastic. 391 + */ 392 + return (acm->write_ready && acm_wb_is_avail(acm)) ? acm->writesize : 0; 491 393 } 492 394 493 395 static int acm_tty_chars_in_buffer(struct tty_struct *tty) ··· 499 393 struct acm *acm = tty->driver_data; 500 394 if (!ACM_READY(acm)) 501 395 return -EINVAL; 502 - return !acm->ready_for_write ? acm->writeurb->transfer_buffer_length : 0; 396 + /* 397 + * This is inaccurate (overcounts), but it works. 398 + */ 399 + return (ACM_NWB - acm_wb_is_avail(acm)) * acm->writesize; 503 400 } 504 401 505 402 static void acm_tty_throttle(struct tty_struct *tty) ··· 634 525 /* 635 526 * USB probe and disconnect routines. 636 527 */ 528 + 529 + /* Little helper: write buffers free */ 530 + static void acm_write_buffers_free(struct acm *acm) 531 + { 532 + int i; 533 + struct acm_wb *wb; 534 + 535 + for (wb = &acm->wb[0], i = 0; i < ACM_NWB; i++, wb++) { 536 + usb_buffer_free(acm->dev, acm->writesize, wb->buf, wb->dmah); 537 + } 538 + } 539 + 540 + /* Little helper: write buffers allocate */ 541 + static int acm_write_buffers_alloc(struct acm *acm) 542 + { 543 + int i; 544 + struct acm_wb *wb; 545 + 546 + for (wb = &acm->wb[0], i = 0; i < ACM_NWB; i++, wb++) { 547 + wb->buf = usb_buffer_alloc(acm->dev, acm->writesize, GFP_KERNEL, 548 + &wb->dmah); 549 + if (!wb->buf) { 550 + while (i != 0) { 551 + --i; 552 + --wb; 553 + usb_buffer_free(acm->dev, acm->writesize, 554 + wb->buf, wb->dmah); 555 + } 556 + return -ENOMEM; 557 + } 558 + } 559 + return 0; 560 + } 637 561 638 562 static int acm_probe (struct usb_interface *intf, 639 563 const struct usb_device_id *id) ··· 842 700 acm->bh.data = (unsigned long) acm; 843 701 INIT_WORK(&acm->work, acm_softint, acm); 844 702 spin_lock_init(&acm->throttle_lock); 845 - acm->ready_for_write = 1; 703 + spin_lock_init(&acm->write_lock); 704 + acm->write_ready = 1; 846 705 847 706 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 848 707 if (!buf) { ··· 859 716 } 860 717 acm->read_buffer = buf; 861 718 862 - buf = usb_buffer_alloc(usb_dev, acm->writesize, GFP_KERNEL, &acm->write_dma); 863 - if (!buf) { 719 + if (acm_write_buffers_alloc(acm) < 0) { 864 720 dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n"); 865 721 goto alloc_fail4; 866 722 } 867 - acm->write_buffer = buf; 868 723 869 724 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); 870 725 if (!acm->ctrlurb) { ··· 891 750 acm->readurb->transfer_dma = acm->read_dma; 892 751 893 752 usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), 894 - acm->write_buffer, acm->writesize, acm_write_bulk, acm); 753 + NULL, acm->writesize, acm_write_bulk, acm); 895 754 acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP; 896 - acm->writeurb->transfer_dma = acm->write_dma; 755 + /* acm->writeurb->transfer_dma = 0; */ 897 756 898 757 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); 899 758 ··· 916 775 alloc_fail6: 917 776 usb_free_urb(acm->ctrlurb); 918 777 alloc_fail5: 919 - usb_buffer_free(usb_dev, acm->writesize, acm->write_buffer, acm->write_dma); 778 + acm_write_buffers_free(acm); 920 779 alloc_fail4: 921 780 usb_buffer_free(usb_dev, readsize, acm->read_buffer, acm->read_dma); 922 781 alloc_fail3: ··· 947 806 948 807 flush_scheduled_work(); /* wait for acm_softint */ 949 808 950 - usb_buffer_free(usb_dev, acm->writesize, acm->write_buffer, acm->write_dma); 809 + acm_write_buffers_free(acm); 951 810 usb_buffer_free(usb_dev, acm->readsize, acm->read_buffer, acm->read_dma); 952 811 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 953 812
+22 -3
drivers/usb/class/cdc-acm.h
··· 51 51 * Internal driver structures. 52 52 */ 53 53 54 + /* 55 + * The only reason to have several buffers is to accomodate assumptions 56 + * in line disciplines. They ask for empty space amount, receive our URB size, 57 + * and proceed to issue several 1-character writes, assuming they will fit. 58 + * The very first write takes a complete URB. Fortunately, this only happens 59 + * when processing onlcr, so we only need 2 buffers. 60 + */ 61 + #define ACM_NWB 2 62 + struct acm_wb { 63 + unsigned char *buf; 64 + dma_addr_t dmah; 65 + int len; 66 + int use; 67 + }; 68 + 54 69 struct acm { 55 70 struct usb_device *dev; /* the corresponding usb device */ 56 71 struct usb_interface *control; /* control interface */ 57 72 struct usb_interface *data; /* data interface */ 58 73 struct tty_struct *tty; /* the corresponding tty */ 59 74 struct urb *ctrlurb, *readurb, *writeurb; /* urbs */ 60 - u8 *ctrl_buffer, *read_buffer, *write_buffer; /* buffers of urbs */ 61 - dma_addr_t ctrl_dma, read_dma, write_dma; /* dma handles of buffers */ 75 + u8 *ctrl_buffer, *read_buffer; /* buffers of urbs */ 76 + dma_addr_t ctrl_dma, read_dma; /* dma handles of buffers */ 77 + struct acm_wb wb[ACM_NWB]; 78 + int write_current; /* current write buffer */ 79 + int write_used; /* number of non-empty write buffers */ 80 + int write_ready; /* write urb is not running */ 81 + spinlock_t write_lock; 62 82 struct usb_cdc_line_coding line; /* bits, stop, parity */ 63 83 struct work_struct work; /* work queue entry for line discipline waking up */ 64 84 struct tasklet_struct bh; /* rx processing */ ··· 91 71 unsigned int minor; /* acm minor number */ 92 72 unsigned char throttle; /* throttled by tty layer */ 93 73 unsigned char clocal; /* termios CLOCAL */ 94 - unsigned char ready_for_write; /* write urb can be used */ 95 74 unsigned char resubmit_to_unthrottle; /* throtteling has disabled the read urb */ 96 75 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 97 76 };
+3
drivers/usb/class/usblp.c
··· 379 379 usblp->writeurb->transfer_buffer_length = 0; 380 380 usblp->wcomplete = 1; /* we begin writeable */ 381 381 usblp->rcomplete = 0; 382 + usblp->writeurb->status = 0; 383 + usblp->readurb->status = 0; 382 384 383 385 if (usblp->bidir) { 384 386 usblp->readcount = 0; ··· 753 751 schedule(); 754 752 } else { 755 753 set_current_state(TASK_RUNNING); 754 + down(&usblp->sem); 756 755 break; 757 756 } 758 757 down (&usblp->sem);
+3 -3
drivers/usb/core/devio.c
··· 784 784 for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) { 785 785 if (usb_interface_claimed(actconfig->interface[i])) { 786 786 dev_warn (&ps->dev->dev, 787 - "usbfs: interface %d claimed " 787 + "usbfs: interface %d claimed by %s " 788 788 "while '%s' sets config #%d\n", 789 789 actconfig->interface[i] 790 790 ->cur_altsetting 791 791 ->desc.bInterfaceNumber, 792 + actconfig->interface[i] 793 + ->dev.driver->name, 792 794 current->comm, u); 793 - #if 0 /* FIXME: enable in 2.6.10 or so */ 794 795 status = -EBUSY; 795 796 break; 796 - #endif 797 797 } 798 798 } 799 799 }
+175 -114
drivers/usb/core/hcd.c
··· 519 519 /*-------------------------------------------------------------------------*/ 520 520 521 521 /* 522 - * Root Hub interrupt transfers are synthesized with a timer. 523 - * Completions are called in_interrupt() but not in_irq(). 522 + * Root Hub interrupt transfers are polled using a timer if the 523 + * driver requests it; otherwise the driver is responsible for 524 + * calling usb_hcd_poll_rh_status() when an event occurs. 524 525 * 525 - * Note: some root hubs (including common UHCI based designs) can't 526 - * correctly issue port change IRQs. They're the ones that _need_ a 527 - * timer; most other root hubs don't. Some systems could save a 528 - * lot of battery power by eliminating these root hub timer IRQs. 526 + * Completions are called in_interrupt(), but they may or may not 527 + * be in_irq(). 529 528 */ 530 - 531 - static void rh_report_status (unsigned long ptr); 532 - 533 - static int rh_status_urb (struct usb_hcd *hcd, struct urb *urb) 534 - { 535 - int len = 1 + (urb->dev->maxchild / 8); 536 - 537 - /* rh_timer protected by hcd_data_lock */ 538 - if (hcd->rh_timer.data || urb->transfer_buffer_length < len) { 539 - dev_dbg (hcd->self.controller, 540 - "not queuing rh status urb, stat %d\n", 541 - urb->status); 542 - return -EINVAL; 543 - } 544 - 545 - init_timer (&hcd->rh_timer); 546 - hcd->rh_timer.function = rh_report_status; 547 - hcd->rh_timer.data = (unsigned long) urb; 548 - /* USB 2.0 spec says 256msec; this is close enough */ 549 - hcd->rh_timer.expires = jiffies + HZ/4; 550 - add_timer (&hcd->rh_timer); 551 - urb->hcpriv = hcd; /* nonzero to indicate it's queued */ 552 - return 0; 553 - } 554 - 555 - /* timer callback */ 556 - 557 - static void rh_report_status (unsigned long ptr) 529 + void usb_hcd_poll_rh_status(struct usb_hcd *hcd) 558 530 { 559 531 struct urb *urb; 560 - struct usb_hcd *hcd; 561 - int length = 0; 532 + int length; 562 533 unsigned long flags; 534 + char buffer[4]; /* Any root hubs with > 31 ports? */ 563 535 564 - urb = (struct urb *) ptr; 565 - local_irq_save (flags); 566 - spin_lock (&urb->lock); 567 - 568 - /* do nothing if the urb's been unlinked */ 569 - if (!urb->dev 570 - || urb->status != -EINPROGRESS 571 - || (hcd = urb->dev->bus->hcpriv) == NULL) { 572 - spin_unlock (&urb->lock); 573 - local_irq_restore (flags); 536 + if (!hcd->uses_new_polling && !hcd->status_urb) 574 537 return; 575 - } 576 538 577 - /* complete the status urb, or retrigger the timer */ 578 - spin_lock (&hcd_data_lock); 579 - if (urb->dev->state == USB_STATE_CONFIGURED) { 580 - length = hcd->driver->hub_status_data ( 581 - hcd, urb->transfer_buffer); 582 - if (length > 0) { 583 - hcd->rh_timer.data = 0; 584 - urb->actual_length = length; 585 - urb->status = 0; 586 - urb->hcpriv = NULL; 539 + length = hcd->driver->hub_status_data(hcd, buffer); 540 + if (length > 0) { 541 + 542 + /* try to complete the status urb */ 543 + local_irq_save (flags); 544 + spin_lock(&hcd_root_hub_lock); 545 + urb = hcd->status_urb; 546 + if (urb) { 547 + spin_lock(&urb->lock); 548 + if (urb->status == -EINPROGRESS) { 549 + hcd->poll_pending = 0; 550 + hcd->status_urb = NULL; 551 + urb->status = 0; 552 + urb->hcpriv = NULL; 553 + urb->actual_length = length; 554 + memcpy(urb->transfer_buffer, buffer, length); 555 + } else /* urb has been unlinked */ 556 + length = 0; 557 + spin_unlock(&urb->lock); 587 558 } else 588 - mod_timer (&hcd->rh_timer, jiffies + HZ/4); 589 - } 590 - spin_unlock (&hcd_data_lock); 591 - spin_unlock (&urb->lock); 559 + length = 0; 560 + spin_unlock(&hcd_root_hub_lock); 592 561 593 - /* local irqs are always blocked in completions */ 594 - if (length > 0) 595 - usb_hcd_giveback_urb (hcd, urb, NULL); 596 - local_irq_restore (flags); 562 + /* local irqs are always blocked in completions */ 563 + if (length > 0) 564 + usb_hcd_giveback_urb (hcd, urb, NULL); 565 + else 566 + hcd->poll_pending = 1; 567 + local_irq_restore (flags); 568 + } 569 + 570 + /* The USB 2.0 spec says 256 ms. This is close enough and won't 571 + * exceed that limit if HZ is 100. */ 572 + if (hcd->uses_new_polling ? hcd->poll_rh : 573 + (length == 0 && hcd->status_urb != NULL)) 574 + mod_timer (&hcd->rh_timer, jiffies + msecs_to_jiffies(250)); 575 + } 576 + EXPORT_SYMBOL_GPL(usb_hcd_poll_rh_status); 577 + 578 + /* timer callback */ 579 + static void rh_timer_func (unsigned long _hcd) 580 + { 581 + usb_hcd_poll_rh_status((struct usb_hcd *) _hcd); 597 582 } 598 583 599 584 /*-------------------------------------------------------------------------*/ 585 + 586 + static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb) 587 + { 588 + int retval; 589 + unsigned long flags; 590 + int len = 1 + (urb->dev->maxchild / 8); 591 + 592 + spin_lock_irqsave (&hcd_root_hub_lock, flags); 593 + if (urb->status != -EINPROGRESS) /* already unlinked */ 594 + retval = urb->status; 595 + else if (hcd->status_urb || urb->transfer_buffer_length < len) { 596 + dev_dbg (hcd->self.controller, "not queuing rh status urb\n"); 597 + retval = -EINVAL; 598 + } else { 599 + hcd->status_urb = urb; 600 + urb->hcpriv = hcd; /* indicate it's queued */ 601 + 602 + if (!hcd->uses_new_polling) 603 + mod_timer (&hcd->rh_timer, jiffies + 604 + msecs_to_jiffies(250)); 605 + 606 + /* If a status change has already occurred, report it ASAP */ 607 + else if (hcd->poll_pending) 608 + mod_timer (&hcd->rh_timer, jiffies); 609 + retval = 0; 610 + } 611 + spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 612 + return retval; 613 + } 600 614 601 615 static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb) 602 616 { 603 - if (usb_pipeint (urb->pipe)) { 604 - int retval; 605 - unsigned long flags; 606 - 607 - spin_lock_irqsave (&hcd_data_lock, flags); 608 - retval = rh_status_urb (hcd, urb); 609 - spin_unlock_irqrestore (&hcd_data_lock, flags); 610 - return retval; 611 - } 617 + if (usb_pipeint (urb->pipe)) 618 + return rh_queue_status (hcd, urb); 612 619 if (usb_pipecontrol (urb->pipe)) 613 620 return rh_call_control (hcd, urb); 614 - else 615 - return -EINVAL; 621 + return -EINVAL; 616 622 } 617 623 618 624 /*-------------------------------------------------------------------------*/ 619 625 626 + /* Asynchronous unlinks of root-hub control URBs are legal, but they 627 + * don't do anything. Status URB unlinks must be made in process context 628 + * with interrupts enabled. 629 + */ 620 630 static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 621 631 { 622 - unsigned long flags; 632 + if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */ 633 + if (in_interrupt()) 634 + return 0; /* nothing to do */ 623 635 624 - /* note: always a synchronous unlink */ 625 - if ((unsigned long) urb == hcd->rh_timer.data) { 626 - del_timer_sync (&hcd->rh_timer); 627 - hcd->rh_timer.data = 0; 628 - 629 - local_irq_save (flags); 630 - urb->hcpriv = NULL; 631 - usb_hcd_giveback_urb (hcd, urb, NULL); 632 - local_irq_restore (flags); 633 - 634 - } else if (usb_pipeendpoint(urb->pipe) == 0) { 635 636 spin_lock_irq(&urb->lock); /* from usb_kill_urb */ 636 637 ++urb->reject; 637 638 spin_unlock_irq(&urb->lock); ··· 643 642 spin_lock_irq(&urb->lock); 644 643 --urb->reject; 645 644 spin_unlock_irq(&urb->lock); 646 - } else 647 - return -EINVAL; 645 + 646 + } else { /* Status URB */ 647 + if (!hcd->uses_new_polling) 648 + del_timer_sync (&hcd->rh_timer); 649 + local_irq_disable (); 650 + spin_lock (&hcd_root_hub_lock); 651 + if (urb == hcd->status_urb) { 652 + hcd->status_urb = NULL; 653 + urb->hcpriv = NULL; 654 + } else 655 + urb = NULL; /* wasn't fully queued */ 656 + spin_unlock (&hcd_root_hub_lock); 657 + if (urb) 658 + usb_hcd_giveback_urb (hcd, urb, NULL); 659 + local_irq_enable (); 660 + } 648 661 649 662 return 0; 650 663 } ··· 832 817 } 833 818 834 819 /** 835 - * usb_hcd_register_root_hub - called by HCD to register its root hub 820 + * register_root_hub - called by usb_add_hcd() to register a root hub 836 821 * @usb_dev: the usb root hub device to be registered. 837 822 * @hcd: host controller for this root hub 838 823 * 839 - * The USB host controller calls this function to register the root hub 840 - * properly with the USB subsystem. It sets up the device properly in 841 - * the device tree and stores the root_hub pointer in the bus structure, 842 - * then calls usb_new_device() to register the usb device. It also 843 - * assigns the root hub's USB address (always 1). 824 + * This function registers the root hub with the USB subsystem. It sets up 825 + * the device properly in the device tree and stores the root_hub pointer 826 + * in the bus structure, then calls usb_new_device() to register the usb 827 + * device. It also assigns the root hub's USB address (always 1). 844 828 */ 845 - int usb_hcd_register_root_hub (struct usb_device *usb_dev, struct usb_hcd *hcd) 829 + static int register_root_hub (struct usb_device *usb_dev, 830 + struct usb_hcd *hcd) 846 831 { 847 832 struct device *parent_dev = hcd->self.controller; 848 833 const int devnum = 1; 849 834 int retval; 850 - 851 - /* hcd->driver->start() reported can_wakeup, probably with 852 - * assistance from board's boot firmware. 853 - * NOTE: normal devices won't enable wakeup by default. 854 - */ 855 - if (hcd->can_wakeup) 856 - dev_dbg (parent_dev, "supports USB remote wakeup\n"); 857 - hcd->remote_wakeup = hcd->can_wakeup; 858 835 859 836 usb_dev->devnum = devnum; 860 837 usb_dev->bus->devnum_next = devnum + 1; ··· 890 883 891 884 return retval; 892 885 } 893 - EXPORT_SYMBOL_GPL(usb_hcd_register_root_hub); 886 + 887 + void usb_enable_root_hub_irq (struct usb_bus *bus) 888 + { 889 + struct usb_hcd *hcd; 890 + 891 + hcd = container_of (bus, struct usb_hcd, self); 892 + if (hcd->driver->hub_irq_enable && !hcd->poll_rh && 893 + hcd->state != HC_STATE_HALT) 894 + hcd->driver->hub_irq_enable (hcd); 895 + } 894 896 895 897 896 898 /*-------------------------------------------------------------------------*/ ··· 1364 1348 1365 1349 hcd = udev->bus->hcpriv; 1366 1350 1367 - WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT); 1351 + WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT && 1352 + udev->state != USB_STATE_NOTATTACHED); 1368 1353 1369 1354 local_irq_disable (); 1370 1355 ··· 1629 1612 1630 1613 spin_lock_irqsave (&hcd_root_hub_lock, flags); 1631 1614 if (hcd->rh_registered) { 1615 + hcd->poll_rh = 0; 1616 + del_timer(&hcd->rh_timer); 1632 1617 1633 1618 /* make khubd clean up old urbs and devices */ 1634 1619 usb_set_device_state (hcd->self.root_hub, ··· 1684 1665 hcd->self.bus_name = bus_name; 1685 1666 1686 1667 init_timer(&hcd->rh_timer); 1668 + hcd->rh_timer.function = rh_timer_func; 1669 + hcd->rh_timer.data = (unsigned long) hcd; 1687 1670 1688 1671 hcd->driver = driver; 1689 1672 hcd->product_desc = (driver->product_desc) ? driver->product_desc : ··· 1715 1694 int usb_add_hcd(struct usb_hcd *hcd, 1716 1695 unsigned int irqnum, unsigned long irqflags) 1717 1696 { 1718 - int retval; 1697 + int retval; 1698 + struct usb_device *rhdev; 1719 1699 1720 1700 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); 1721 1701 ··· 1732 1710 } 1733 1711 1734 1712 if ((retval = usb_register_bus(&hcd->self)) < 0) 1735 - goto err1; 1713 + goto err_register_bus; 1736 1714 1737 1715 if (hcd->driver->irq) { 1738 1716 char buf[8], *bufp = buf; ··· 1749 1727 hcd->irq_descr, hcd)) != 0) { 1750 1728 dev_err(hcd->self.controller, 1751 1729 "request interrupt %s failed\n", bufp); 1752 - goto err2; 1730 + goto err_request_irq; 1753 1731 } 1754 1732 hcd->irq = irqnum; 1755 1733 dev_info(hcd->self.controller, "irq %s, %s 0x%08llx\n", bufp, ··· 1765 1743 (unsigned long long)hcd->rsrc_start); 1766 1744 } 1767 1745 1746 + /* Allocate the root hub before calling hcd->driver->start(), 1747 + * but don't register it until afterward so that the hardware 1748 + * is running. 1749 + */ 1750 + if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) { 1751 + dev_err(hcd->self.controller, "unable to allocate root hub\n"); 1752 + retval = -ENOMEM; 1753 + goto err_allocate_root_hub; 1754 + } 1755 + rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH : 1756 + USB_SPEED_FULL; 1757 + 1758 + /* Although in principle hcd->driver->start() might need to use rhdev, 1759 + * none of the current drivers do. 1760 + */ 1768 1761 if ((retval = hcd->driver->start(hcd)) < 0) { 1769 1762 dev_err(hcd->self.controller, "startup error %d\n", retval); 1770 - goto err3; 1763 + goto err_hcd_driver_start; 1771 1764 } 1772 1765 1766 + /* hcd->driver->start() reported can_wakeup, probably with 1767 + * assistance from board's boot firmware. 1768 + * NOTE: normal devices won't enable wakeup by default. 1769 + */ 1770 + if (hcd->can_wakeup) 1771 + dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); 1772 + hcd->remote_wakeup = hcd->can_wakeup; 1773 + 1774 + if ((retval = register_root_hub(rhdev, hcd)) != 0) 1775 + goto err_register_root_hub; 1776 + 1777 + if (hcd->uses_new_polling && hcd->poll_rh) 1778 + usb_hcd_poll_rh_status(hcd); 1773 1779 return retval; 1774 1780 1775 - err3: 1781 + err_register_root_hub: 1782 + hcd->driver->stop(hcd); 1783 + 1784 + err_hcd_driver_start: 1785 + usb_put_dev(rhdev); 1786 + 1787 + err_allocate_root_hub: 1776 1788 if (hcd->irq >= 0) 1777 1789 free_irq(irqnum, hcd); 1778 - err2: 1790 + 1791 + err_request_irq: 1779 1792 usb_deregister_bus(&hcd->self); 1780 - err1: 1793 + 1794 + err_register_bus: 1781 1795 hcd_buffer_destroy(hcd); 1782 1796 return retval; 1783 1797 } ··· 1839 1781 hcd->rh_registered = 0; 1840 1782 spin_unlock_irq (&hcd_root_hub_lock); 1841 1783 usb_disconnect(&hcd->self.root_hub); 1784 + 1785 + hcd->poll_rh = 0; 1786 + del_timer_sync(&hcd->rh_timer); 1842 1787 1843 1788 hcd->driver->stop(hcd); 1844 1789 hcd->state = HC_STATE_HALT;
+15 -4
drivers/usb/core/hcd.h
··· 65 65 const char *product_desc; /* product/vendor string */ 66 66 char irq_descr[24]; /* driver + bus # */ 67 67 68 - struct timer_list rh_timer; /* drives root hub */ 68 + struct timer_list rh_timer; /* drives root-hub polling */ 69 + struct urb *status_urb; /* the current status urb */ 69 70 70 71 /* 71 72 * hardware info/state ··· 77 76 unsigned remote_wakeup:1;/* sw should use wakeup? */ 78 77 unsigned rh_registered:1;/* is root hub registered? */ 79 78 79 + /* The next flag is a stopgap, to be removed when all the HCDs 80 + * support the new root-hub polling mechanism. */ 81 + unsigned uses_new_polling:1; 82 + unsigned poll_rh:1; /* poll for rh status? */ 83 + unsigned poll_pending:1; /* status has changed? */ 84 + 80 85 int irq; /* irq allocated */ 81 86 void __iomem *regs; /* device memory/io */ 82 87 u64 rsrc_start; /* memory/io resource start */ 83 88 u64 rsrc_len; /* memory/io resource length */ 89 + unsigned power_budget; /* in mA, 0 = no limit */ 84 90 85 91 #define HCD_BUFFER_POOLS 4 86 92 struct dma_pool *pool [HCD_BUFFER_POOLS]; ··· 215 207 int (*hub_suspend)(struct usb_hcd *); 216 208 int (*hub_resume)(struct usb_hcd *); 217 209 int (*start_port_reset)(struct usb_hcd *, unsigned port_num); 210 + void (*hub_irq_enable)(struct usb_hcd *); 211 + /* Needed only if port-change IRQs are level-triggered */ 218 212 }; 219 213 220 214 extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs); ··· 253 243 254 244 /* generic bus glue, needed for host controllers that don't use PCI */ 255 245 extern irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs *r); 246 + 256 247 extern void usb_hc_died (struct usb_hcd *hcd); 248 + extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd); 257 249 258 250 /* -------------------------------------------------------------------------- */ 259 251 ··· 353 341 354 342 extern struct usb_bus *usb_alloc_bus (struct usb_operations *); 355 343 356 - extern int usb_hcd_register_root_hub (struct usb_device *usb_dev, 357 - struct usb_hcd *hcd); 358 - 359 344 extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); 360 345 361 346 extern void usb_set_device_state(struct usb_device *udev, ··· 368 359 369 360 extern struct usb_bus *usb_bus_get (struct usb_bus *bus); 370 361 extern void usb_bus_put (struct usb_bus *bus); 362 + 363 + extern void usb_enable_root_hub_irq (struct usb_bus *bus); 371 364 372 365 extern int usb_find_interface_driver (struct usb_device *dev, 373 366 struct usb_interface *interface);
+15 -4
drivers/usb/core/hub.c
··· 643 643 message = "can't get hub status"; 644 644 goto fail; 645 645 } 646 - cpu_to_le16s(&hubstatus); 647 - if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) { 646 + le16_to_cpus(&hubstatus); 647 + if (hdev == hdev->bus->root_hub) { 648 + struct usb_hcd *hcd = 649 + container_of(hdev->bus, struct usb_hcd, self); 650 + 651 + hub->power_budget = min(500u, hcd->power_budget) / 2; 652 + } else if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) { 648 653 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n", 649 654 hub->descriptor->bHubContrCurrent); 650 655 hub->power_budget = (501 - hub->descriptor->bHubContrCurrent) 651 656 / 2; 657 + } 658 + if (hub->power_budget) 652 659 dev_dbg(hub_dev, "%dmA bus power budget for children\n", 653 660 hub->power_budget * 2); 654 - } 655 661 656 662 657 663 ret = hub_hub_status(hub, &hubstatus, &hubchange); ··· 1733 1727 struct usb_driver *driver; 1734 1728 1735 1729 intf = udev->actconfig->interface[i]; 1736 - if (intf->dev.power.power_state == PMSG_SUSPEND) 1730 + if (intf->dev.power.power_state == PMSG_ON) 1737 1731 continue; 1738 1732 if (!intf->dev.driver) { 1739 1733 /* FIXME maybe force to alt 0 */ ··· 2792 2786 } 2793 2787 2794 2788 hub->activating = 0; 2789 + 2790 + /* If this is a root hub, tell the HCD it's okay to 2791 + * re-enable port-change interrupts now. */ 2792 + if (!hdev->parent) 2793 + usb_enable_root_hub_irq(hdev->bus); 2795 2794 2796 2795 loop: 2797 2796 usb_unlock_device(hdev);
-11
drivers/usb/core/hub.h
··· 224 224 struct work_struct leds; 225 225 }; 226 226 227 - /* use this for low-powered root hubs */ 228 - static inline void 229 - hub_set_power_budget (struct usb_device *hubdev, unsigned mA) 230 - { 231 - struct usb_hub *hub; 232 - 233 - hub = (struct usb_hub *) 234 - usb_get_intfdata (hubdev->actconfig->interface[0]); 235 - hub->power_budget = min(mA,(unsigned)500)/2; 236 - } 237 - 238 227 #endif /* __LINUX_HUB_H */
+10 -1
drivers/usb/gadget/Kconfig
··· 53 53 driver on a new board. Enable these files by choosing "Y" 54 54 here. If in doubt, or to conserve kernel memory, say "N". 55 55 56 + config USB_GADGET_SELECTED 57 + boolean 58 + 56 59 # 57 60 # USB Peripheral Controller Support 58 61 # ··· 88 85 tristate 89 86 depends on USB_GADGET_NET2280 90 87 default USB_GADGET 88 + select USB_GADGET_SELECTED 91 89 92 90 config USB_GADGET_PXA2XX 93 91 boolean "PXA 25x or IXP 4xx" ··· 109 105 tristate 110 106 depends on USB_GADGET_PXA2XX 111 107 default USB_GADGET 108 + select USB_GADGET_SELECTED 112 109 113 110 # if there's only one gadget driver, using only two bulk endpoints, 114 111 # don't waste memory for the other endpoints ··· 139 134 tristate 140 135 depends on USB_GADGET_GOKU 141 136 default USB_GADGET 137 + select USB_GADGET_SELECTED 142 138 143 139 144 140 config USB_GADGET_LH7A40X ··· 152 146 tristate 153 147 depends on USB_GADGET_LH7A40X 154 148 default USB_GADGET 149 + select USB_GADGET_SELECTED 155 150 156 151 157 152 config USB_GADGET_OMAP ··· 174 167 tristate 175 168 depends on USB_GADGET_OMAP 176 169 default USB_GADGET 170 + select USB_GADGET_SELECTED 177 171 178 172 config USB_OTG 179 173 boolean "OTG Support" ··· 215 207 tristate 216 208 depends on USB_GADGET_DUMMY_HCD 217 209 default USB_GADGET 210 + select USB_GADGET_SELECTED 218 211 219 212 # NOTE: Please keep dummy_hcd LAST so that "real hardware" appears 220 213 # first and will be selected by default. ··· 235 226 # 236 227 choice 237 228 tristate "USB Gadget Drivers" 238 - depends on USB_GADGET 229 + depends on USB_GADGET && USB_GADGET_SELECTED 239 230 default USB_ETH 240 231 help 241 232 A Linux "Gadget Driver" talks to the USB Peripheral Controller
+510 -245
drivers/usb/gadget/dummy_hcd.c
··· 65 65 66 66 67 67 #define DRIVER_DESC "USB Host+Gadget Emulator" 68 - #define DRIVER_VERSION "17 Dec 2004" 68 + #define DRIVER_VERSION "02 May 2005" 69 69 70 70 static const char driver_name [] = "dummy_hcd"; 71 71 static const char driver_desc [] = "USB Host+Gadget Emulator"; ··· 141 141 }; 142 142 #define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *)) 143 143 144 + /*-------------------------------------------------------------------------*/ 145 + 144 146 #define FIFO_SIZE 64 145 147 146 148 struct urbp { 147 149 struct urb *urb; 148 150 struct list_head urbp_list; 151 + }; 152 + 153 + 154 + enum dummy_rh_state { 155 + DUMMY_RH_RESET, 156 + DUMMY_RH_SUSPENDED, 157 + DUMMY_RH_RUNNING 149 158 }; 150 159 151 160 struct dummy { ··· 170 161 struct dummy_request fifo_req; 171 162 u8 fifo_buf [FIFO_SIZE]; 172 163 u16 devstatus; 164 + unsigned udc_suspended:1; 165 + unsigned pullup:1; 166 + unsigned active:1; 167 + unsigned old_active:1; 173 168 174 169 /* 175 170 * MASTER/HOST side support 176 171 */ 172 + enum dummy_rh_state rh_state; 177 173 struct timer_list timer; 178 174 u32 port_status; 175 + u32 old_status; 179 176 unsigned resuming:1; 180 177 unsigned long re_timeout; 181 178 ··· 204 189 return dummy_to_hcd(dum)->self.controller; 205 190 } 206 191 192 + static inline struct device *udc_dev (struct dummy *dum) 193 + { 194 + return dum->gadget.dev.parent; 195 + } 196 + 207 197 static inline struct dummy *ep_to_dummy (struct dummy_ep *ep) 208 198 { 209 199 return container_of (ep->gadget, struct dummy, gadget); ··· 228 208 229 209 /*-------------------------------------------------------------------------*/ 230 210 231 - /* 232 - * This "hardware" may look a bit odd in diagnostics since it's got both 233 - * host and device sides; and it binds different drivers to each side. 234 - */ 235 - static struct platform_device the_pdev; 211 + /* SLAVE/GADGET SIDE UTILITY ROUTINES */ 236 212 237 - static struct device_driver dummy_driver = { 238 - .name = (char *) driver_name, 239 - .bus = &platform_bus_type, 240 - }; 213 + /* called with spinlock held */ 214 + static void nuke (struct dummy *dum, struct dummy_ep *ep) 215 + { 216 + while (!list_empty (&ep->queue)) { 217 + struct dummy_request *req; 218 + 219 + req = list_entry (ep->queue.next, struct dummy_request, queue); 220 + list_del_init (&req->queue); 221 + req->req.status = -ESHUTDOWN; 222 + 223 + spin_unlock (&dum->lock); 224 + req->req.complete (&ep->ep, &req->req); 225 + spin_lock (&dum->lock); 226 + } 227 + } 228 + 229 + /* caller must hold lock */ 230 + static void 231 + stop_activity (struct dummy *dum) 232 + { 233 + struct dummy_ep *ep; 234 + 235 + /* prevent any more requests */ 236 + dum->address = 0; 237 + 238 + /* The timer is left running so that outstanding URBs can fail */ 239 + 240 + /* nuke any pending requests first, so driver i/o is quiesced */ 241 + list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list) 242 + nuke (dum, ep); 243 + 244 + /* driver now does any non-usb quiescing necessary */ 245 + } 246 + 247 + /* caller must hold lock */ 248 + static void 249 + set_link_state (struct dummy *dum) 250 + { 251 + dum->active = 0; 252 + if ((dum->port_status & USB_PORT_STAT_POWER) == 0) 253 + dum->port_status = 0; 254 + 255 + /* UDC suspend must cause a disconnect */ 256 + else if (!dum->pullup || dum->udc_suspended) { 257 + dum->port_status &= ~(USB_PORT_STAT_CONNECTION | 258 + USB_PORT_STAT_ENABLE | 259 + USB_PORT_STAT_LOW_SPEED | 260 + USB_PORT_STAT_HIGH_SPEED | 261 + USB_PORT_STAT_SUSPEND); 262 + if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0) 263 + dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); 264 + } else { 265 + dum->port_status |= USB_PORT_STAT_CONNECTION; 266 + if ((dum->old_status & USB_PORT_STAT_CONNECTION) == 0) 267 + dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); 268 + if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0) 269 + dum->port_status &= ~USB_PORT_STAT_SUSPEND; 270 + else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 && 271 + dum->rh_state != DUMMY_RH_SUSPENDED) 272 + dum->active = 1; 273 + } 274 + 275 + if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0 || dum->active) 276 + dum->resuming = 0; 277 + 278 + if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0 || 279 + (dum->port_status & USB_PORT_STAT_RESET) != 0) { 280 + if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 && 281 + (dum->old_status & USB_PORT_STAT_RESET) == 0 && 282 + dum->driver) { 283 + stop_activity (dum); 284 + spin_unlock (&dum->lock); 285 + dum->driver->disconnect (&dum->gadget); 286 + spin_lock (&dum->lock); 287 + } 288 + } else if (dum->active != dum->old_active) { 289 + if (dum->old_active && dum->driver->suspend) { 290 + spin_unlock (&dum->lock); 291 + dum->driver->suspend (&dum->gadget); 292 + spin_lock (&dum->lock); 293 + } else if (!dum->old_active && dum->driver->resume) { 294 + spin_unlock (&dum->lock); 295 + dum->driver->resume (&dum->gadget); 296 + spin_lock (&dum->lock); 297 + } 298 + } 299 + 300 + dum->old_status = dum->port_status; 301 + dum->old_active = dum->active; 302 + } 241 303 242 304 /*-------------------------------------------------------------------------*/ 243 305 ··· 426 324 _ep->maxpacket = max; 427 325 ep->desc = desc; 428 326 429 - dev_dbg (dummy_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n", 327 + dev_dbg (udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n", 430 328 _ep->name, 431 329 desc->bEndpointAddress & 0x0f, 432 330 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", ··· 447 345 return retval; 448 346 } 449 347 450 - /* called with spinlock held */ 451 - static void nuke (struct dummy *dum, struct dummy_ep *ep) 452 - { 453 - while (!list_empty (&ep->queue)) { 454 - struct dummy_request *req; 455 - 456 - req = list_entry (ep->queue.next, struct dummy_request, queue); 457 - list_del_init (&req->queue); 458 - req->req.status = -ESHUTDOWN; 459 - 460 - spin_unlock (&dum->lock); 461 - req->req.complete (&ep->ep, &req->req); 462 - spin_lock (&dum->lock); 463 - } 464 - } 465 - 466 348 static int dummy_disable (struct usb_ep *_ep) 467 349 { 468 350 struct dummy_ep *ep; ··· 465 379 nuke (dum, ep); 466 380 spin_unlock_irqrestore (&dum->lock, flags); 467 381 468 - dev_dbg (dummy_dev(dum), "disabled %s\n", _ep->name); 382 + dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name); 469 383 return retval; 470 384 } 471 385 ··· 560 474 return -ESHUTDOWN; 561 475 562 476 #if 0 563 - dev_dbg (dummy_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", 477 + dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", 564 478 ep, _req, _ep->name, _req->length, _req->buf); 565 479 #endif 566 480 ··· 623 537 spin_unlock_irqrestore (&dum->lock, flags); 624 538 625 539 if (retval == 0) { 626 - dev_dbg (dummy_dev(dum), 540 + dev_dbg (udc_dev(dum), 627 541 "dequeued req %p from %s, len %d buf %p\n", 628 542 req, _ep->name, _req->length, _req->buf); 629 543 _req->complete (_ep, _req); ··· 687 601 struct dummy *dum; 688 602 689 603 dum = gadget_to_dummy (_gadget); 690 - if ((dum->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) == 0 691 - || !(dum->port_status & (1 << USB_PORT_FEAT_SUSPEND))) 604 + if (!(dum->devstatus & ( (1 << USB_DEVICE_B_HNP_ENABLE) 605 + | (1 << USB_DEVICE_REMOTE_WAKEUP)))) 692 606 return -EINVAL; 607 + if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0) 608 + return -ENOLINK; 609 + if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 && 610 + dum->rh_state != DUMMY_RH_SUSPENDED) 611 + return -EIO; 612 + 613 + /* FIXME: What if the root hub is suspended but the port isn't? */ 693 614 694 615 /* hub notices our request, issues downstream resume, etc */ 695 616 dum->resuming = 1; 696 - dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); 617 + dum->re_timeout = jiffies + msecs_to_jiffies(20); 618 + mod_timer (&dummy_to_hcd (dum)->rh_timer, dum->re_timeout); 697 619 return 0; 698 620 } 699 621 ··· 717 623 return 0; 718 624 } 719 625 626 + static int dummy_pullup (struct usb_gadget *_gadget, int value) 627 + { 628 + struct dummy *dum; 629 + unsigned long flags; 630 + 631 + dum = gadget_to_dummy (_gadget); 632 + spin_lock_irqsave (&dum->lock, flags); 633 + dum->pullup = (value != 0); 634 + set_link_state (dum); 635 + spin_unlock_irqrestore (&dum->lock, flags); 636 + 637 + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 638 + return 0; 639 + } 640 + 720 641 static const struct usb_gadget_ops dummy_ops = { 721 642 .get_frame = dummy_g_get_frame, 722 643 .wakeup = dummy_wakeup, 723 644 .set_selfpowered = dummy_set_selfpowered, 645 + .pullup = dummy_pullup, 724 646 }; 725 647 726 648 /*-------------------------------------------------------------------------*/ ··· 751 641 return 0; 752 642 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function); 753 643 } 754 - DEVICE_ATTR (function, S_IRUGO, show_function, NULL); 644 + static DEVICE_ATTR (function, S_IRUGO, show_function, NULL); 755 645 756 646 /*-------------------------------------------------------------------------*/ 757 647 ··· 768 658 * For this emulator, it might be convenient to create a usb slave device 769 659 * for each driver that registers: just add to a big root hub. 770 660 */ 771 - 772 - static void 773 - dummy_udc_release (struct device *dev) 774 - { 775 - } 776 - 777 - static void 778 - dummy_pdev_release (struct device *dev) 779 - { 780 - } 781 - 782 - static int 783 - dummy_register_udc (struct dummy *dum) 784 - { 785 - int rc; 786 - 787 - strcpy (dum->gadget.dev.bus_id, "udc"); 788 - dum->gadget.dev.parent = dummy_dev(dum); 789 - dum->gadget.dev.release = dummy_udc_release; 790 - 791 - rc = device_register (&dum->gadget.dev); 792 - if (rc == 0) 793 - device_create_file (&dum->gadget.dev, &dev_attr_function); 794 - return rc; 795 - } 796 - 797 - static void 798 - dummy_unregister_udc (struct dummy *dum) 799 - { 800 - device_remove_file (&dum->gadget.dev, &dev_attr_function); 801 - device_unregister (&dum->gadget.dev); 802 - } 803 661 804 662 int 805 663 usb_gadget_register_driver (struct usb_gadget_driver *driver) ··· 787 709 * SLAVE side init ... the layer above hardware, which 788 710 * can't enumerate without help from the driver we're binding. 789 711 */ 790 - dum->gadget.name = gadget_name; 791 - dum->gadget.ops = &dummy_ops; 792 - dum->gadget.is_dualspeed = 1; 793 712 794 713 dum->devstatus = 0; 795 - dum->resuming = 0; 796 714 797 715 INIT_LIST_HEAD (&dum->gadget.ep_list); 798 716 for (i = 0; i < DUMMY_ENDPOINTS; i++) { ··· 814 740 815 741 dum->driver = driver; 816 742 dum->gadget.dev.driver = &driver->driver; 817 - dev_dbg (dummy_dev(dum), "binding gadget driver '%s'\n", 743 + dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 818 744 driver->driver.name); 819 745 if ((retval = driver->bind (&dum->gadget)) != 0) { 820 746 dum->driver = NULL; ··· 822 748 return retval; 823 749 } 824 750 825 - // FIXME: Check these calls for errors and re-order 826 751 driver->driver.bus = dum->gadget.dev.parent->bus; 827 752 driver_register (&driver->driver); 828 - 829 753 device_bind_driver (&dum->gadget.dev); 830 754 831 755 /* khubd will enumerate this in a while */ 832 - dum->port_status |= USB_PORT_STAT_CONNECTION 833 - | (1 << USB_PORT_FEAT_C_CONNECTION); 756 + spin_lock_irq (&dum->lock); 757 + dum->pullup = 1; 758 + set_link_state (dum); 759 + spin_unlock_irq (&dum->lock); 760 + 761 + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 834 762 return 0; 835 763 } 836 764 EXPORT_SYMBOL (usb_gadget_register_driver); 837 - 838 - /* caller must hold lock */ 839 - static void 840 - stop_activity (struct dummy *dum, struct usb_gadget_driver *driver) 841 - { 842 - struct dummy_ep *ep; 843 - 844 - /* prevent any more requests */ 845 - dum->address = 0; 846 - 847 - /* The timer is left running so that outstanding URBs can fail */ 848 - 849 - /* nuke any pending requests first, so driver i/o is quiesced */ 850 - list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list) 851 - nuke (dum, ep); 852 - 853 - /* driver now does any non-usb quiescing necessary */ 854 - if (driver) { 855 - spin_unlock (&dum->lock); 856 - driver->disconnect (&dum->gadget); 857 - spin_lock (&dum->lock); 858 - } 859 - } 860 765 861 766 int 862 767 usb_gadget_unregister_driver (struct usb_gadget_driver *driver) ··· 848 795 if (!driver || driver != dum->driver) 849 796 return -EINVAL; 850 797 851 - dev_dbg (dummy_dev(dum), "unregister gadget driver '%s'\n", 798 + dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", 852 799 driver->driver.name); 853 800 854 801 spin_lock_irqsave (&dum->lock, flags); 855 - stop_activity (dum, driver); 856 - dum->port_status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | 857 - USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED); 858 - dum->port_status |= (1 << USB_PORT_FEAT_C_CONNECTION); 802 + dum->pullup = 0; 803 + set_link_state (dum); 859 804 spin_unlock_irqrestore (&dum->lock, flags); 860 805 861 806 driver->unbind (&dum->gadget); 862 807 dum->driver = NULL; 863 808 864 809 device_release_driver (&dum->gadget.dev); 865 - 866 810 driver_unregister (&driver->driver); 867 811 812 + spin_lock_irqsave (&dum->lock, flags); 813 + dum->pullup = 0; 814 + set_link_state (dum); 815 + spin_unlock_irqrestore (&dum->lock, flags); 816 + 817 + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 868 818 return 0; 869 819 } 870 820 EXPORT_SYMBOL (usb_gadget_unregister_driver); 871 821 872 822 #undef is_enabled 873 823 824 + /* just declare this in any driver that really need it */ 825 + extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode); 826 + 874 827 int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode) 875 828 { 876 829 return -ENOSYS; 877 830 } 878 831 EXPORT_SYMBOL (net2280_set_fifo_mode); 832 + 833 + 834 + /* The gadget structure is stored inside the hcd structure and will be 835 + * released along with it. */ 836 + static void 837 + dummy_gadget_release (struct device *dev) 838 + { 839 + #if 0 /* usb_bus_put isn't EXPORTed! */ 840 + struct dummy *dum = gadget_dev_to_dummy (dev); 841 + 842 + usb_bus_put (&dummy_to_hcd (dum)->self); 843 + #endif 844 + } 845 + 846 + static int dummy_udc_probe (struct device *dev) 847 + { 848 + struct dummy *dum = the_controller; 849 + int rc; 850 + 851 + dum->gadget.name = gadget_name; 852 + dum->gadget.ops = &dummy_ops; 853 + dum->gadget.is_dualspeed = 1; 854 + 855 + /* maybe claim OTG support, though we won't complete HNP */ 856 + dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0); 857 + 858 + strcpy (dum->gadget.dev.bus_id, "gadget"); 859 + dum->gadget.dev.parent = dev; 860 + dum->gadget.dev.release = dummy_gadget_release; 861 + rc = device_register (&dum->gadget.dev); 862 + if (rc < 0) 863 + return rc; 864 + 865 + #if 0 /* usb_bus_get isn't EXPORTed! */ 866 + usb_bus_get (&dummy_to_hcd (dum)->self); 867 + #endif 868 + 869 + dev_set_drvdata (dev, dum); 870 + device_create_file (&dum->gadget.dev, &dev_attr_function); 871 + return rc; 872 + } 873 + 874 + static int dummy_udc_remove (struct device *dev) 875 + { 876 + struct dummy *dum = dev_get_drvdata (dev); 877 + 878 + dev_set_drvdata (dev, NULL); 879 + device_remove_file (&dum->gadget.dev, &dev_attr_function); 880 + device_unregister (&dum->gadget.dev); 881 + return 0; 882 + } 883 + 884 + static int dummy_udc_suspend (struct device *dev, pm_message_t state, 885 + u32 level) 886 + { 887 + struct dummy *dum = dev_get_drvdata(dev); 888 + 889 + if (level != SUSPEND_DISABLE) 890 + return 0; 891 + 892 + dev_dbg (dev, "%s\n", __FUNCTION__); 893 + spin_lock_irq (&dum->lock); 894 + dum->udc_suspended = 1; 895 + set_link_state (dum); 896 + spin_unlock_irq (&dum->lock); 897 + 898 + dev->power.power_state = state; 899 + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 900 + return 0; 901 + } 902 + 903 + static int dummy_udc_resume (struct device *dev, u32 level) 904 + { 905 + struct dummy *dum = dev_get_drvdata(dev); 906 + 907 + if (level != RESUME_ENABLE) 908 + return 0; 909 + 910 + dev_dbg (dev, "%s\n", __FUNCTION__); 911 + spin_lock_irq (&dum->lock); 912 + dum->udc_suspended = 0; 913 + set_link_state (dum); 914 + spin_unlock_irq (&dum->lock); 915 + 916 + dev->power.power_state = PMSG_ON; 917 + usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 918 + return 0; 919 + } 920 + 921 + static struct device_driver dummy_udc_driver = { 922 + .name = (char *) gadget_name, 923 + .bus = &platform_bus_type, 924 + .probe = dummy_udc_probe, 925 + .remove = dummy_udc_remove, 926 + .suspend = dummy_udc_suspend, 927 + .resume = dummy_udc_resume, 928 + }; 879 929 880 930 /*-------------------------------------------------------------------------*/ 881 931 ··· 1036 880 1037 881 static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 1038 882 { 1039 - /* giveback happens automatically in timer callback */ 883 + struct dummy *dum; 884 + unsigned long flags; 885 + 886 + /* giveback happens automatically in timer callback, 887 + * so make sure the callback happens */ 888 + dum = hcd_to_dummy (hcd); 889 + spin_lock_irqsave (&dum->lock, flags); 890 + if (dum->rh_state != DUMMY_RH_RUNNING && !list_empty(&dum->urbp_list)) 891 + mod_timer (&dum->timer, jiffies); 892 + spin_unlock_irqrestore (&dum->lock, flags); 1040 893 return 0; 1041 894 } 1042 895 ··· 1190 1025 1191 1026 /* high bandwidth mode */ 1192 1027 tmp = le16_to_cpu(ep->desc->wMaxPacketSize); 1193 - tmp = le16_to_cpu (tmp); 1194 1028 tmp = (tmp >> 11) & 0x03; 1195 1029 tmp *= 8 /* applies to entire frame */; 1196 1030 limit += limit * tmp; ··· 1287 1123 if (urb->status != -EINPROGRESS) { 1288 1124 /* likely it was just unlinked */ 1289 1125 goto return_urb; 1290 - } 1126 + } else if (dum->rh_state != DUMMY_RH_RUNNING) 1127 + continue; 1291 1128 type = usb_pipetype (urb->pipe); 1292 1129 1293 1130 /* used up this frame's non-periodic bandwidth? ··· 1333 1168 struct usb_ctrlrequest setup; 1334 1169 int value = 1; 1335 1170 struct dummy_ep *ep2; 1171 + unsigned w_index; 1172 + unsigned w_value; 1336 1173 1337 1174 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1338 - le16_to_cpus (&setup.wIndex); 1339 - le16_to_cpus (&setup.wValue); 1340 - le16_to_cpus (&setup.wLength); 1341 - if (setup.wLength != urb->transfer_buffer_length) { 1175 + w_index = le16_to_cpu(setup.wIndex); 1176 + w_value = le16_to_cpu(setup.wValue); 1177 + if (le16_to_cpu(setup.wLength) != 1178 + urb->transfer_buffer_length) { 1342 1179 maybe_set_status (urb, -EOVERFLOW); 1343 1180 goto return_urb; 1344 1181 } ··· 1349 1182 list_for_each_entry (req, &ep->queue, queue) { 1350 1183 list_del_init (&req->queue); 1351 1184 req->req.status = -EOVERFLOW; 1352 - dev_dbg (dummy_dev(dum), "stale req = %p\n", 1185 + dev_dbg (udc_dev(dum), "stale req = %p\n", 1353 1186 req); 1354 1187 1355 1188 spin_unlock (&dum->lock); ··· 1370 1203 case USB_REQ_SET_ADDRESS: 1371 1204 if (setup.bRequestType != Dev_Request) 1372 1205 break; 1373 - dum->address = setup.wValue; 1206 + dum->address = w_value; 1374 1207 maybe_set_status (urb, 0); 1375 - dev_dbg (dummy_dev(dum), "set_address = %d\n", 1376 - setup.wValue); 1208 + dev_dbg (udc_dev(dum), "set_address = %d\n", 1209 + w_value); 1377 1210 value = 0; 1378 1211 break; 1379 1212 case USB_REQ_SET_FEATURE: 1380 1213 if (setup.bRequestType == Dev_Request) { 1381 1214 value = 0; 1382 - switch (setup.wValue) { 1215 + switch (w_value) { 1383 1216 case USB_DEVICE_REMOTE_WAKEUP: 1217 + break; 1218 + case USB_DEVICE_B_HNP_ENABLE: 1219 + dum->gadget.b_hnp_enable = 1; 1220 + break; 1221 + case USB_DEVICE_A_HNP_SUPPORT: 1222 + dum->gadget.a_hnp_support = 1; 1223 + break; 1224 + case USB_DEVICE_A_ALT_HNP_SUPPORT: 1225 + dum->gadget.a_alt_hnp_support 1226 + = 1; 1384 1227 break; 1385 1228 default: 1386 1229 value = -EOPNOTSUPP; 1387 1230 } 1388 1231 if (value == 0) { 1389 1232 dum->devstatus |= 1390 - (1 << setup.wValue); 1233 + (1 << w_value); 1391 1234 maybe_set_status (urb, 0); 1392 1235 } 1393 1236 1394 1237 } else if (setup.bRequestType == Ep_Request) { 1395 1238 // endpoint halt 1396 - ep2 = find_endpoint (dum, 1397 - setup.wIndex); 1239 + ep2 = find_endpoint (dum, w_index); 1398 1240 if (!ep2) { 1399 1241 value = -EOPNOTSUPP; 1400 1242 break; ··· 1415 1239 break; 1416 1240 case USB_REQ_CLEAR_FEATURE: 1417 1241 if (setup.bRequestType == Dev_Request) { 1418 - switch (setup.wValue) { 1242 + switch (w_value) { 1419 1243 case USB_DEVICE_REMOTE_WAKEUP: 1420 1244 dum->devstatus &= ~(1 << 1421 1245 USB_DEVICE_REMOTE_WAKEUP); ··· 1428 1252 } 1429 1253 } else if (setup.bRequestType == Ep_Request) { 1430 1254 // endpoint halt 1431 - ep2 = find_endpoint (dum, 1432 - setup.wIndex); 1255 + ep2 = find_endpoint (dum, w_index); 1433 1256 if (!ep2) { 1434 1257 value = -EOPNOTSUPP; 1435 1258 break; ··· 1454 1279 if (urb->transfer_buffer_length > 0) { 1455 1280 if (setup.bRequestType == 1456 1281 Ep_InRequest) { 1457 - ep2 = find_endpoint (dum, setup.wIndex); 1282 + ep2 = find_endpoint (dum, w_index); 1458 1283 if (!ep2) { 1459 1284 value = -EOPNOTSUPP; 1460 1285 break; ··· 1496 1321 1497 1322 if (value < 0) { 1498 1323 if (value != -EOPNOTSUPP) 1499 - dev_dbg (dummy_dev(dum), 1324 + dev_dbg (udc_dev(dum), 1500 1325 "setup --> %d\n", 1501 1326 value); 1502 1327 maybe_set_status (urb, -EPIPE); ··· 1552 1377 goto restart; 1553 1378 } 1554 1379 1555 - /* want a 1 msec delay here */ 1556 - if (!list_empty (&dum->urbp_list)) 1557 - mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1)); 1558 - else { 1380 + if (list_empty (&dum->urbp_list)) { 1559 1381 usb_put_dev (dum->udev); 1560 1382 dum->udev = NULL; 1383 + } else if (dum->rh_state == DUMMY_RH_RUNNING) { 1384 + /* want a 1 msec delay here */ 1385 + mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1)); 1561 1386 } 1562 1387 1563 1388 spin_unlock_irqrestore (&dum->lock, flags); ··· 1566 1391 /*-------------------------------------------------------------------------*/ 1567 1392 1568 1393 #define PORT_C_MASK \ 1569 - ((1 << USB_PORT_FEAT_C_CONNECTION) \ 1570 - | (1 << USB_PORT_FEAT_C_ENABLE) \ 1571 - | (1 << USB_PORT_FEAT_C_SUSPEND) \ 1572 - | (1 << USB_PORT_FEAT_C_OVER_CURRENT) \ 1573 - | (1 << USB_PORT_FEAT_C_RESET)) 1394 + ((USB_PORT_STAT_C_CONNECTION \ 1395 + | USB_PORT_STAT_C_ENABLE \ 1396 + | USB_PORT_STAT_C_SUSPEND \ 1397 + | USB_PORT_STAT_C_OVERCURRENT \ 1398 + | USB_PORT_STAT_C_RESET) << 16) 1574 1399 1575 1400 static int dummy_hub_status (struct usb_hcd *hcd, char *buf) 1576 1401 { 1577 1402 struct dummy *dum; 1578 1403 unsigned long flags; 1579 - int retval; 1404 + int retval = 0; 1580 1405 1581 1406 dum = hcd_to_dummy (hcd); 1582 1407 1583 1408 spin_lock_irqsave (&dum->lock, flags); 1584 - if (!(dum->port_status & PORT_C_MASK)) 1585 - retval = 0; 1586 - else { 1409 + if (hcd->state != HC_STATE_RUNNING) 1410 + goto done; 1411 + 1412 + if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { 1413 + dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); 1414 + dum->port_status &= ~USB_PORT_STAT_SUSPEND; 1415 + set_link_state (dum); 1416 + } 1417 + 1418 + if ((dum->port_status & PORT_C_MASK) != 0) { 1587 1419 *buf = (1 << 1); 1588 1420 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n", 1589 - dum->port_status); 1421 + dum->port_status); 1590 1422 retval = 1; 1423 + if (dum->rh_state == DUMMY_RH_SUSPENDED) 1424 + usb_hcd_resume_root_hub (hcd); 1591 1425 } 1426 + done: 1592 1427 spin_unlock_irqrestore (&dum->lock, flags); 1593 1428 return retval; 1594 1429 } ··· 1609 1424 memset (desc, 0, sizeof *desc); 1610 1425 desc->bDescriptorType = 0x29; 1611 1426 desc->bDescLength = 9; 1612 - desc->wHubCharacteristics = __constant_cpu_to_le16 (0x0001); 1427 + desc->wHubCharacteristics = (__force __u16) 1428 + (__constant_cpu_to_le16 (0x0001)); 1613 1429 desc->bNbrPorts = 1; 1614 1430 desc->bitmap [0] = 0xff; 1615 1431 desc->bitmap [1] = 0xff; ··· 1628 1442 int retval = 0; 1629 1443 unsigned long flags; 1630 1444 1445 + if (hcd->state != HC_STATE_RUNNING) 1446 + return -ETIMEDOUT; 1447 + 1631 1448 dum = hcd_to_dummy (hcd); 1632 1449 spin_lock_irqsave (&dum->lock, flags); 1633 1450 switch (typeReq) { ··· 1639 1450 case ClearPortFeature: 1640 1451 switch (wValue) { 1641 1452 case USB_PORT_FEAT_SUSPEND: 1642 - if (dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) { 1453 + if (dum->port_status & USB_PORT_STAT_SUSPEND) { 1643 1454 /* 20msec resume signaling */ 1644 1455 dum->resuming = 1; 1645 1456 dum->re_timeout = jiffies + 1646 - msecs_to_jiffies(20); 1457 + msecs_to_jiffies(20); 1647 1458 } 1648 1459 break; 1649 1460 case USB_PORT_FEAT_POWER: 1650 - dum->port_status = 0; 1651 - dum->resuming = 0; 1652 - stop_activity(dum, dum->driver); 1653 - break; 1461 + if (dum->port_status & USB_PORT_STAT_POWER) 1462 + dev_dbg (dummy_dev(dum), "power-off\n"); 1463 + /* FALLS THROUGH */ 1654 1464 default: 1655 1465 dum->port_status &= ~(1 << wValue); 1466 + set_link_state (dum); 1656 1467 } 1657 1468 break; 1658 1469 case GetHubDescriptor: 1659 1470 hub_descriptor ((struct usb_hub_descriptor *) buf); 1660 1471 break; 1661 1472 case GetHubStatus: 1662 - *(u32 *) buf = __constant_cpu_to_le32 (0); 1473 + *(__le32 *) buf = __constant_cpu_to_le32 (0); 1663 1474 break; 1664 1475 case GetPortStatus: 1665 1476 if (wIndex != 1) ··· 1668 1479 /* whoever resets or resumes must GetPortStatus to 1669 1480 * complete it!! 1670 1481 */ 1671 - if (dum->resuming && time_after (jiffies, dum->re_timeout)) { 1672 - dum->port_status |= (1 << USB_PORT_FEAT_C_SUSPEND); 1673 - dum->port_status &= ~(1 << USB_PORT_FEAT_SUSPEND); 1674 - dum->resuming = 0; 1675 - dum->re_timeout = 0; 1676 - if (dum->driver && dum->driver->resume) { 1677 - spin_unlock (&dum->lock); 1678 - dum->driver->resume (&dum->gadget); 1679 - spin_lock (&dum->lock); 1680 - } 1482 + if (dum->resuming && 1483 + time_after_eq (jiffies, dum->re_timeout)) { 1484 + dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); 1485 + dum->port_status &= ~USB_PORT_STAT_SUSPEND; 1681 1486 } 1682 - if ((dum->port_status & (1 << USB_PORT_FEAT_RESET)) != 0 1683 - && time_after (jiffies, dum->re_timeout)) { 1684 - dum->port_status |= (1 << USB_PORT_FEAT_C_RESET); 1685 - dum->port_status &= ~(1 << USB_PORT_FEAT_RESET); 1686 - dum->re_timeout = 0; 1687 - if (dum->driver) { 1487 + if ((dum->port_status & USB_PORT_STAT_RESET) != 0 && 1488 + time_after_eq (jiffies, dum->re_timeout)) { 1489 + dum->port_status |= (USB_PORT_STAT_C_RESET << 16); 1490 + dum->port_status &= ~USB_PORT_STAT_RESET; 1491 + if (dum->pullup) { 1688 1492 dum->port_status |= USB_PORT_STAT_ENABLE; 1689 1493 /* give it the best speed we agree on */ 1690 1494 dum->gadget.speed = dum->driver->speed; ··· 1698 1516 } 1699 1517 } 1700 1518 } 1701 - ((u16 *) buf)[0] = cpu_to_le16 (dum->port_status); 1702 - ((u16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); 1519 + set_link_state (dum); 1520 + ((__le16 *) buf)[0] = cpu_to_le16 (dum->port_status); 1521 + ((__le16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); 1703 1522 break; 1704 1523 case SetHubFeature: 1705 1524 retval = -EPIPE; ··· 1708 1525 case SetPortFeature: 1709 1526 switch (wValue) { 1710 1527 case USB_PORT_FEAT_SUSPEND: 1711 - if ((dum->port_status & (1 << USB_PORT_FEAT_SUSPEND)) 1712 - == 0) { 1713 - dum->port_status |= 1714 - (1 << USB_PORT_FEAT_SUSPEND); 1715 - if (dum->driver && dum->driver->suspend) { 1716 - spin_unlock (&dum->lock); 1717 - dum->driver->suspend (&dum->gadget); 1718 - spin_lock (&dum->lock); 1719 - } 1528 + if (dum->active) { 1529 + dum->port_status |= USB_PORT_STAT_SUSPEND; 1530 + 1531 + /* HNP would happen here; for now we 1532 + * assume b_bus_req is always true. 1533 + */ 1534 + set_link_state (dum); 1535 + if (((1 << USB_DEVICE_B_HNP_ENABLE) 1536 + & dum->devstatus) != 0) 1537 + dev_dbg (dummy_dev(dum), 1538 + "no HNP yet!\n"); 1720 1539 } 1721 1540 break; 1541 + case USB_PORT_FEAT_POWER: 1542 + dum->port_status |= USB_PORT_STAT_POWER; 1543 + set_link_state (dum); 1544 + break; 1722 1545 case USB_PORT_FEAT_RESET: 1723 - /* if it's already running, disconnect first */ 1724 - if (dum->port_status & USB_PORT_STAT_ENABLE) { 1725 - dum->port_status &= ~(USB_PORT_STAT_ENABLE 1726 - | USB_PORT_STAT_LOW_SPEED 1727 - | USB_PORT_STAT_HIGH_SPEED); 1728 - if (dum->driver) { 1729 - dev_dbg (dummy_dev(dum), 1730 - "disconnect\n"); 1731 - stop_activity (dum, dum->driver); 1732 - } 1733 - 1734 - /* FIXME test that code path! */ 1735 - } 1546 + /* if it's already enabled, disable */ 1547 + dum->port_status &= ~(USB_PORT_STAT_ENABLE 1548 + | USB_PORT_STAT_LOW_SPEED 1549 + | USB_PORT_STAT_HIGH_SPEED); 1550 + dum->devstatus = 0; 1736 1551 /* 50msec reset signaling */ 1737 1552 dum->re_timeout = jiffies + msecs_to_jiffies(50); 1738 - /* FALLTHROUGH */ 1553 + /* FALLS THROUGH */ 1739 1554 default: 1740 - dum->port_status |= (1 << wValue); 1555 + if ((dum->port_status & USB_PORT_STAT_POWER) != 0) { 1556 + dum->port_status |= (1 << wValue); 1557 + set_link_state (dum); 1558 + } 1741 1559 } 1742 1560 break; 1743 1561 ··· 1751 1567 retval = -EPIPE; 1752 1568 } 1753 1569 spin_unlock_irqrestore (&dum->lock, flags); 1570 + 1571 + if ((dum->port_status & PORT_C_MASK) != 0) 1572 + usb_hcd_poll_rh_status (hcd); 1754 1573 return retval; 1755 1574 } 1756 1575 1576 + static int dummy_hub_suspend (struct usb_hcd *hcd) 1577 + { 1578 + struct dummy *dum = hcd_to_dummy (hcd); 1579 + 1580 + spin_lock_irq (&dum->lock); 1581 + dum->rh_state = DUMMY_RH_SUSPENDED; 1582 + set_link_state (dum); 1583 + spin_unlock_irq (&dum->lock); 1584 + return 0; 1585 + } 1586 + 1587 + static int dummy_hub_resume (struct usb_hcd *hcd) 1588 + { 1589 + struct dummy *dum = hcd_to_dummy (hcd); 1590 + 1591 + spin_lock_irq (&dum->lock); 1592 + dum->rh_state = DUMMY_RH_RUNNING; 1593 + set_link_state (dum); 1594 + if (!list_empty(&dum->urbp_list)) 1595 + mod_timer (&dum->timer, jiffies); 1596 + spin_unlock_irq (&dum->lock); 1597 + return 0; 1598 + } 1757 1599 1758 1600 /*-------------------------------------------------------------------------*/ 1759 1601 ··· 1835 1625 static int dummy_start (struct usb_hcd *hcd) 1836 1626 { 1837 1627 struct dummy *dum; 1838 - struct usb_device *root; 1839 - int retval; 1840 1628 1841 1629 dum = hcd_to_dummy (hcd); 1842 1630 ··· 1847 1639 init_timer (&dum->timer); 1848 1640 dum->timer.function = dummy_timer; 1849 1641 dum->timer.data = (unsigned long) dum; 1642 + dum->rh_state = DUMMY_RH_RUNNING; 1850 1643 1851 1644 INIT_LIST_HEAD (&dum->urbp_list); 1852 1645 1853 - root = usb_alloc_dev (NULL, &hcd->self, 0); 1854 - if (!root) 1855 - return -ENOMEM; 1856 - 1857 - /* root hub enters addressed state... */ 1858 - hcd->state = HC_STATE_RUNNING; 1859 - root->speed = USB_SPEED_HIGH; 1860 - 1861 - /* ...then configured, so khubd sees us. */ 1862 - if ((retval = usb_hcd_register_root_hub (root, hcd)) != 0) { 1863 - goto err1; 1864 - } 1865 - 1866 1646 /* only show a low-power port: just 8mA */ 1867 - hub_set_power_budget (root, 8); 1647 + hcd->power_budget = 8; 1648 + hcd->state = HC_STATE_RUNNING; 1649 + hcd->uses_new_polling = 1; 1868 1650 1869 - if ((retval = dummy_register_udc (dum)) != 0) 1870 - goto err2; 1651 + #ifdef CONFIG_USB_OTG 1652 + hcd->self.otg_port = 1; 1653 + #endif 1871 1654 1872 1655 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ 1873 1656 device_create_file (dummy_dev(dum), &dev_attr_urbs); 1874 1657 return 0; 1875 - 1876 - err2: 1877 - usb_disconnect (&hcd->self.root_hub); 1878 - err1: 1879 - usb_put_dev (root); 1880 - hcd->state = HC_STATE_QUIESCING; 1881 - return retval; 1882 1658 } 1883 1659 1884 1660 static void dummy_stop (struct usb_hcd *hcd) ··· 1872 1680 dum = hcd_to_dummy (hcd); 1873 1681 1874 1682 device_remove_file (dummy_dev(dum), &dev_attr_urbs); 1875 - 1876 1683 usb_gadget_unregister_driver (dum->driver); 1877 - dummy_unregister_udc (dum); 1878 - 1879 1684 dev_info (dummy_dev(dum), "stopped\n"); 1880 1685 } 1881 1686 ··· 1900 1711 1901 1712 .hub_status_data = dummy_hub_status, 1902 1713 .hub_control = dummy_hub_control, 1714 + .hub_suspend = dummy_hub_suspend, 1715 + .hub_resume = dummy_hub_resume, 1903 1716 }; 1904 1717 1905 - static int dummy_probe (struct device *dev) 1718 + static int dummy_hcd_probe (struct device *dev) 1906 1719 { 1907 1720 struct usb_hcd *hcd; 1908 1721 int retval; ··· 1924 1733 return retval; 1925 1734 } 1926 1735 1927 - static void dummy_remove (struct device *dev) 1736 + static int dummy_hcd_remove (struct device *dev) 1928 1737 { 1929 1738 struct usb_hcd *hcd; 1930 1739 ··· 1932 1741 usb_remove_hcd (hcd); 1933 1742 usb_put_hcd (hcd); 1934 1743 the_controller = NULL; 1744 + return 0; 1935 1745 } 1746 + 1747 + static int dummy_hcd_suspend (struct device *dev, pm_message_t state, 1748 + u32 level) 1749 + { 1750 + struct usb_hcd *hcd; 1751 + 1752 + if (level != SUSPEND_DISABLE) 1753 + return 0; 1754 + 1755 + dev_dbg (dev, "%s\n", __FUNCTION__); 1756 + hcd = dev_get_drvdata (dev); 1757 + 1758 + #ifndef CONFIG_USB_SUSPEND 1759 + /* Otherwise this would never happen */ 1760 + usb_lock_device (hcd->self.root_hub); 1761 + dummy_hub_suspend (hcd); 1762 + usb_unlock_device (hcd->self.root_hub); 1763 + #endif 1764 + 1765 + hcd->state = HC_STATE_SUSPENDED; 1766 + return 0; 1767 + } 1768 + 1769 + static int dummy_hcd_resume (struct device *dev, u32 level) 1770 + { 1771 + struct usb_hcd *hcd; 1772 + 1773 + if (level != RESUME_ENABLE) 1774 + return 0; 1775 + 1776 + dev_dbg (dev, "%s\n", __FUNCTION__); 1777 + hcd = dev_get_drvdata (dev); 1778 + hcd->state = HC_STATE_RUNNING; 1779 + 1780 + #ifndef CONFIG_USB_SUSPEND 1781 + /* Otherwise this would never happen */ 1782 + usb_lock_device (hcd->self.root_hub); 1783 + dummy_hub_resume (hcd); 1784 + usb_unlock_device (hcd->self.root_hub); 1785 + #endif 1786 + 1787 + usb_hcd_poll_rh_status (hcd); 1788 + return 0; 1789 + } 1790 + 1791 + static struct device_driver dummy_hcd_driver = { 1792 + .name = (char *) driver_name, 1793 + .bus = &platform_bus_type, 1794 + .probe = dummy_hcd_probe, 1795 + .remove = dummy_hcd_remove, 1796 + .suspend = dummy_hcd_suspend, 1797 + .resume = dummy_hcd_resume, 1798 + }; 1936 1799 1937 1800 /*-------------------------------------------------------------------------*/ 1938 1801 1939 - static int dummy_pdev_detect (void) 1940 - { 1941 - int retval; 1802 + /* These don't need to do anything because the pdev structures are 1803 + * statically allocated. */ 1804 + static void 1805 + dummy_udc_release (struct device *dev) {} 1942 1806 1943 - retval = driver_register (&dummy_driver); 1944 - if (retval < 0) 1945 - return retval; 1807 + static void 1808 + dummy_hcd_release (struct device *dev) {} 1946 1809 1947 - the_pdev.name = "hc"; 1948 - the_pdev.dev.driver = &dummy_driver; 1949 - the_pdev.dev.release = dummy_pdev_release; 1810 + static struct platform_device the_udc_pdev = { 1811 + .name = (char *) gadget_name, 1812 + .id = -1, 1813 + .dev = { 1814 + .release = dummy_udc_release, 1815 + }, 1816 + }; 1950 1817 1951 - retval = platform_device_register (&the_pdev); 1952 - if (retval < 0) 1953 - driver_unregister (&dummy_driver); 1954 - return retval; 1955 - } 1956 - 1957 - static void dummy_pdev_remove (void) 1958 - { 1959 - platform_device_unregister (&the_pdev); 1960 - driver_unregister (&dummy_driver); 1961 - } 1962 - 1963 - /*-------------------------------------------------------------------------*/ 1818 + static struct platform_device the_hcd_pdev = { 1819 + .name = (char *) driver_name, 1820 + .id = -1, 1821 + .dev = { 1822 + .release = dummy_hcd_release, 1823 + }, 1824 + }; 1964 1825 1965 1826 static int __init init (void) 1966 1827 { ··· 2020 1777 2021 1778 if (usb_disabled ()) 2022 1779 return -ENODEV; 2023 - if ((retval = dummy_pdev_detect ()) != 0) 1780 + 1781 + retval = driver_register (&dummy_hcd_driver); 1782 + if (retval < 0) 2024 1783 return retval; 2025 - if ((retval = dummy_probe (&the_pdev.dev)) != 0) 2026 - dummy_pdev_remove (); 1784 + 1785 + retval = driver_register (&dummy_udc_driver); 1786 + if (retval < 0) 1787 + goto err_register_udc_driver; 1788 + 1789 + retval = platform_device_register (&the_hcd_pdev); 1790 + if (retval < 0) 1791 + goto err_register_hcd; 1792 + 1793 + retval = platform_device_register (&the_udc_pdev); 1794 + if (retval < 0) 1795 + goto err_register_udc; 1796 + return retval; 1797 + 1798 + err_register_udc: 1799 + platform_device_unregister (&the_hcd_pdev); 1800 + err_register_hcd: 1801 + driver_unregister (&dummy_udc_driver); 1802 + err_register_udc_driver: 1803 + driver_unregister (&dummy_hcd_driver); 2027 1804 return retval; 2028 1805 } 2029 1806 module_init (init); 2030 1807 2031 1808 static void __exit cleanup (void) 2032 1809 { 2033 - dummy_remove (&the_pdev.dev); 2034 - dummy_pdev_remove (); 1810 + platform_device_unregister (&the_udc_pdev); 1811 + platform_device_unregister (&the_hcd_pdev); 1812 + driver_unregister (&dummy_udc_driver); 1813 + driver_unregister (&dummy_hcd_driver); 2035 1814 } 2036 1815 module_exit (cleanup);
+138 -217
drivers/usb/gadget/ether.c
··· 84 84 */ 85 85 86 86 #define DRIVER_DESC "Ethernet Gadget" 87 - #define DRIVER_VERSION "Equinox 2004" 87 + #define DRIVER_VERSION "May Day 2005" 88 88 89 89 static const char shortname [] = "ether"; 90 90 static const char driver_desc [] = DRIVER_DESC; 91 91 92 92 #define RX_EXTRA 20 /* guard against rx overflows */ 93 93 94 - #ifdef CONFIG_USB_ETH_RNDIS 95 94 #include "rndis.h" 96 - #else 97 - #define rndis_init() 0 98 - #define rndis_exit() do{}while(0) 95 + 96 + #ifndef CONFIG_USB_ETH_RNDIS 97 + #define rndis_uninit(x) do{}while(0) 98 + #define rndis_deregister(c) do{}while(0) 99 + #define rndis_exit() do{}while(0) 99 100 #endif 100 101 101 102 /* CDC and RNDIS support the same host-chosen outgoing packet filters. */ ··· 141 140 * It also ASSUMES a self-powered device, without remote wakeup, 142 141 * although remote wakeup support would make sense. 143 142 */ 144 - static const char *EP_IN_NAME; 145 - static const char *EP_OUT_NAME; 146 - static const char *EP_STATUS_NAME; 147 143 148 144 /*-------------------------------------------------------------------------*/ 149 145 ··· 310 312 #define FS_BPS (19 * 64 * 1 * 1000 * 8) 311 313 312 314 #ifdef CONFIG_USB_GADGET_DUALSPEED 315 + #define DEVSPEED USB_SPEED_HIGH 313 316 314 317 static unsigned qmult = 5; 315 318 module_param (qmult, uint, S_IRUGO|S_IWUSR); ··· 329 330 } 330 331 331 332 #else /* full speed (low speed doesn't do bulk) */ 333 + #define DEVSPEED USB_SPEED_FULL 334 + 332 335 #define qlen(gadget) DEFAULT_QLEN 333 336 334 337 static inline int BITRATE(struct usb_gadget *g) ··· 396 395 #define STRING_SUBSET 8 397 396 #define STRING_RNDIS 9 398 397 399 - #define USB_BUFSIZ 256 /* holds our biggest descriptor */ 398 + /* holds our biggest descriptor (or RNDIS response) */ 399 + #define USB_BUFSIZ 256 400 400 401 401 /* 402 402 * This device advertises one configuration, eth_config, unless RNDIS ··· 540 538 .bDataInterface = 0x01, 541 539 }; 542 540 543 - static struct usb_cdc_acm_descriptor acm_descriptor = { 541 + static const struct usb_cdc_acm_descriptor acm_descriptor = { 544 542 .bLength = sizeof acm_descriptor, 545 543 .bDescriptorType = USB_DT_CS_INTERFACE, 546 544 .bDescriptorSubType = USB_CDC_ACM_TYPE, ··· 848 846 #else 849 847 850 848 /* if there's no high speed support, maxpacket doesn't change. */ 851 - #define ep_desc(g,hs,fs) fs 849 + #define ep_desc(g,hs,fs) (((void)(g)), (fs)) 852 850 853 851 static inline void __init hs_subset_descriptors(void) 854 852 { ··· 948 946 static void eth_start (struct eth_dev *dev, int gfp_flags); 949 947 static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags); 950 948 951 - #ifdef DEV_CONFIG_CDC 952 - static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep) 949 + static int 950 + set_ether_config (struct eth_dev *dev, int gfp_flags) 953 951 { 954 - const struct usb_endpoint_descriptor *d; 952 + int result = 0; 953 + struct usb_gadget *gadget = dev->gadget; 954 + 955 + /* status endpoint used for RNDIS and (optionally) CDC */ 956 + if (!subset_active(dev) && dev->status_ep) { 957 + dev->status = ep_desc (gadget, &hs_status_desc, 958 + &fs_status_desc); 959 + dev->status_ep->driver_data = dev; 960 + 961 + result = usb_ep_enable (dev->status_ep, dev->status); 962 + if (result != 0) { 963 + DEBUG (dev, "enable %s --> %d\n", 964 + dev->status_ep->name, result); 965 + goto done; 966 + } 967 + } 968 + 969 + dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 970 + dev->in_ep->driver_data = dev; 971 + 972 + dev->out = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); 973 + dev->out_ep->driver_data = dev; 955 974 956 975 /* With CDC, the host isn't allowed to use these two data 957 976 * endpoints in the default altsetting for the interface. ··· 982 959 * a side effect of setting a packet filter. Deactivation is 983 960 * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG. 984 961 */ 985 - 986 - /* one endpoint writes data back IN to the host */ 987 - if (strcmp (ep->name, EP_IN_NAME) == 0) { 988 - d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 989 - ep->driver_data = dev; 990 - dev->in = d; 991 - 992 - /* one endpoint just reads OUT packets */ 993 - } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { 994 - d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); 995 - ep->driver_data = dev; 996 - dev->out = d; 997 - 998 - /* optional status/notification endpoint */ 999 - } else if (EP_STATUS_NAME && 1000 - strcmp (ep->name, EP_STATUS_NAME) == 0) { 1001 - int result; 1002 - 1003 - d = ep_desc (dev->gadget, &hs_status_desc, &fs_status_desc); 1004 - result = usb_ep_enable (ep, d); 1005 - if (result < 0) 1006 - return result; 1007 - 1008 - ep->driver_data = dev; 1009 - dev->status = d; 1010 - } 1011 - return 0; 1012 - } 1013 - #endif 1014 - 1015 - #if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1016 - static inline int ether_ep_setup (struct eth_dev *dev, struct usb_ep *ep) 1017 - { 1018 - int result; 1019 - const struct usb_endpoint_descriptor *d; 1020 - 1021 - /* CDC subset is simpler: if the device is there, 1022 - * it's live with rx and tx endpoints. 1023 - * 1024 - * Do this as a shortcut for RNDIS too. 1025 - */ 1026 - 1027 - /* one endpoint writes data back IN to the host */ 1028 - if (strcmp (ep->name, EP_IN_NAME) == 0) { 1029 - d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 1030 - result = usb_ep_enable (ep, d); 1031 - if (result < 0) 1032 - return result; 1033 - 1034 - ep->driver_data = dev; 1035 - dev->in = d; 1036 - 1037 - /* one endpoint just reads OUT packets */ 1038 - } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { 1039 - d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); 1040 - result = usb_ep_enable (ep, d); 1041 - if (result < 0) 1042 - return result; 1043 - 1044 - ep->driver_data = dev; 1045 - dev->out = d; 1046 - } 1047 - 1048 - return 0; 1049 - } 1050 - #endif 1051 - 1052 - static int 1053 - set_ether_config (struct eth_dev *dev, int gfp_flags) 1054 - { 1055 - int result = 0; 1056 - struct usb_ep *ep; 1057 - struct usb_gadget *gadget = dev->gadget; 1058 - 1059 - gadget_for_each_ep (ep, gadget) { 1060 - #ifdef DEV_CONFIG_CDC 1061 - if (!dev->rndis && dev->cdc) { 1062 - result = ether_alt_ep_setup (dev, ep); 1063 - if (result == 0) 1064 - continue; 1065 - } 1066 - #endif 1067 - 1068 - #ifdef CONFIG_USB_ETH_RNDIS 1069 - if (dev->rndis && strcmp (ep->name, EP_STATUS_NAME) == 0) { 1070 - const struct usb_endpoint_descriptor *d; 1071 - d = ep_desc (gadget, &hs_status_desc, &fs_status_desc); 1072 - result = usb_ep_enable (ep, d); 1073 - if (result == 0) { 1074 - ep->driver_data = dev; 1075 - dev->status = d; 1076 - continue; 1077 - } 1078 - } else 1079 - #endif 1080 - 1081 - { 1082 - #if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1083 - result = ether_ep_setup (dev, ep); 1084 - if (result == 0) 1085 - continue; 1086 - #endif 962 + if (!cdc_active(dev)) { 963 + result = usb_ep_enable (dev->in_ep, dev->in); 964 + if (result != 0) { 965 + DEBUG(dev, "enable %s --> %d\n", 966 + dev->in_ep->name, result); 967 + goto done; 1087 968 } 1088 969 1089 - /* stop on error */ 1090 - ERROR (dev, "can't enable %s, result %d\n", ep->name, result); 1091 - break; 970 + result = usb_ep_enable (dev->out_ep, dev->out); 971 + if (result != 0) { 972 + DEBUG (dev, "enable %s --> %d\n", 973 + dev->in_ep->name, result); 974 + goto done; 975 + } 1092 976 } 1093 - if (!result && (!dev->in_ep || !dev->out_ep)) 1094 - result = -ENODEV; 1095 977 978 + done: 1096 979 if (result == 0) 1097 980 result = alloc_requests (dev, qlen (gadget), gfp_flags); 1098 981 1099 982 /* on error, disable any endpoints */ 1100 983 if (result < 0) { 1101 - #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 1102 - if (dev->status) 984 + if (!subset_active(dev)) 1103 985 (void) usb_ep_disable (dev->status_ep); 1104 - #endif 1105 986 dev->status = NULL; 1106 - #if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1107 - if (dev->rndis || !dev->cdc) { 1108 - if (dev->in) 1109 - (void) usb_ep_disable (dev->in_ep); 1110 - if (dev->out) 1111 - (void) usb_ep_disable (dev->out_ep); 1112 - } 1113 - #endif 987 + (void) usb_ep_disable (dev->in_ep); 988 + (void) usb_ep_disable (dev->out_ep); 1114 989 dev->in = NULL; 1115 990 dev->out = NULL; 1116 991 } else ··· 1016 1095 /* activate non-CDC configs right away 1017 1096 * this isn't strictly according to the RNDIS spec 1018 1097 */ 1019 - #if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) 1020 - if (dev->rndis || !dev->cdc) { 1098 + if (!cdc_active (dev)) { 1021 1099 netif_carrier_on (dev->net); 1022 1100 if (netif_running (dev->net)) { 1023 1101 spin_unlock (&dev->lock); ··· 1024 1104 spin_lock (&dev->lock); 1025 1105 } 1026 1106 } 1027 - #endif 1028 1107 1029 1108 if (result == 0) 1030 1109 DEBUG (dev, "qlen %d\n", qlen (gadget)); ··· 1043 1124 1044 1125 netif_stop_queue (dev->net); 1045 1126 netif_carrier_off (dev->net); 1127 + rndis_uninit(dev->rndis_config); 1046 1128 1047 1129 /* disable endpoints, forcing (synchronous) completion of 1048 1130 * pending i/o. then free the requests. ··· 1070 1150 if (dev->status) { 1071 1151 usb_ep_disable (dev->status_ep); 1072 1152 } 1153 + dev->rndis = 0; 1154 + dev->cdc_filter = 0; 1073 1155 dev->config = 0; 1074 1156 } 1075 1157 ··· 1084 1162 int result = 0; 1085 1163 struct usb_gadget *gadget = dev->gadget; 1086 1164 1087 - if (number == dev->config) 1088 - return 0; 1089 - 1090 1165 if (gadget_is_sa1100 (gadget) 1091 1166 && dev->config 1092 1167 && atomic_read (&dev->tx_qlen) != 0) { ··· 1093 1174 } 1094 1175 eth_reset_config (dev); 1095 1176 1096 - /* default: pass all packets, no multicast filtering */ 1097 - dev->cdc_filter = DEFAULT_FILTER; 1098 - 1099 1177 switch (number) { 1100 1178 case DEV_CONFIG_VALUE: 1101 - dev->rndis = 0; 1102 1179 result = set_ether_config (dev, gfp_flags); 1103 1180 break; 1104 1181 #ifdef CONFIG_USB_ETH_RNDIS ··· 1133 1218 dev->config = number; 1134 1219 INFO (dev, "%s speed config #%d: %d mA, %s, using %s\n", 1135 1220 speed, number, power, driver_desc, 1136 - dev->rndis 1221 + rndis_active(dev) 1137 1222 ? "RNDIS" 1138 - : (dev->cdc 1223 + : (cdc_active(dev) 1139 1224 ? "CDC Ethernet" 1140 1225 : "CDC Ethernet Subset")); 1141 1226 } ··· 1145 1230 /*-------------------------------------------------------------------------*/ 1146 1231 1147 1232 #ifdef DEV_CONFIG_CDC 1233 + 1234 + /* The interrupt endpoint is used in CDC networking models (Ethernet, ATM) 1235 + * only to notify the host about link status changes (which we support) or 1236 + * report completion of some encapsulated command (as used in RNDIS). Since 1237 + * we want this CDC Ethernet code to be vendor-neutral, we don't use that 1238 + * command mechanism; and only one status request is ever queued. 1239 + */ 1148 1240 1149 1241 static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) 1150 1242 { ··· 1181 1259 } else if (value != -ECONNRESET) 1182 1260 DEBUG (dev, "event %02x --> %d\n", 1183 1261 event->bNotificationType, value); 1184 - event->bmRequestType = 0xff; 1262 + req->context = NULL; 1185 1263 } 1186 1264 1187 1265 static void issue_start_status (struct eth_dev *dev) ··· 1198 1276 * a "cancel the whole queue" primitive since any 1199 1277 * unlink-one primitive has way too many error modes. 1200 1278 * here, we "know" toggle is already clear... 1279 + * 1280 + * FIXME iff req->context != null just dequeue it 1201 1281 */ 1202 1282 usb_ep_disable (dev->status_ep); 1203 1283 usb_ep_enable (dev->status_ep, dev->status); ··· 1216 1292 1217 1293 req->length = sizeof *event; 1218 1294 req->complete = eth_status_complete; 1295 + req->context = dev; 1296 + 1219 1297 value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC); 1220 1298 if (value < 0) 1221 1299 DEBUG (dev, "status buf queue --> %d\n", value); ··· 1277 1351 struct eth_dev *dev = get_gadget_data (gadget); 1278 1352 struct usb_request *req = dev->req; 1279 1353 int value = -EOPNOTSUPP; 1280 - u16 wIndex = (__force u16) ctrl->wIndex; 1281 - u16 wValue = (__force u16) ctrl->wValue; 1282 - u16 wLength = (__force u16) ctrl->wLength; 1354 + u16 wIndex = le16_to_cpu(ctrl->wIndex); 1355 + u16 wValue = le16_to_cpu(ctrl->wValue); 1356 + u16 wLength = le16_to_cpu(ctrl->wLength); 1283 1357 1284 1358 /* descriptors just go into the pre-allocated ep0 buffer, 1285 1359 * while config change events may enable network traffic. ··· 1350 1424 || !dev->config 1351 1425 || wIndex > 1) 1352 1426 break; 1353 - if (!dev->cdc && wIndex != 0) 1427 + if (!cdc_active(dev) && wIndex != 0) 1354 1428 break; 1355 1429 spin_lock (&dev->lock); 1356 1430 ··· 1382 1456 1383 1457 /* CDC requires the data transfers not be done from 1384 1458 * the default interface setting ... also, setting 1385 - * the non-default interface clears filters etc. 1459 + * the non-default interface resets filters etc. 1386 1460 */ 1387 1461 if (wValue == 1) { 1462 + if (!cdc_active (dev)) 1463 + break; 1388 1464 usb_ep_enable (dev->in_ep, dev->in); 1389 1465 usb_ep_enable (dev->out_ep, dev->out); 1390 1466 dev->cdc_filter = DEFAULT_FILTER; ··· 1420 1492 || !dev->config 1421 1493 || wIndex > 1) 1422 1494 break; 1423 - if (!(dev->cdc || dev->rndis) && wIndex != 0) 1495 + if (!(cdc_active(dev) || rndis_active(dev)) && wIndex != 0) 1424 1496 break; 1425 1497 1426 1498 /* for CDC, iff carrier is on, data interface is active. */ 1427 - if (dev->rndis || wIndex != 1) 1499 + if (rndis_active(dev) || wIndex != 1) 1428 1500 *(u8 *)req->buf = 0; 1429 1501 else 1430 1502 *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0; ··· 1437 1509 * wValue = packet filter bitmap 1438 1510 */ 1439 1511 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1440 - || !dev->cdc 1441 - || dev->rndis 1512 + || !cdc_active(dev) 1442 1513 || wLength != 0 1443 1514 || wIndex > 1) 1444 1515 break; ··· 1461 1534 */ 1462 1535 case USB_CDC_SEND_ENCAPSULATED_COMMAND: 1463 1536 if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1464 - || !dev->rndis 1537 + || !rndis_active(dev) 1465 1538 || wLength > USB_BUFSIZ 1466 1539 || wValue 1467 1540 || rndis_control_intf.bInterfaceNumber ··· 1476 1549 case USB_CDC_GET_ENCAPSULATED_RESPONSE: 1477 1550 if ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE) 1478 1551 == ctrl->bRequestType 1479 - && dev->rndis 1552 + && rndis_active(dev) 1480 1553 // && wLength >= 0x0400 1481 1554 && !wValue 1482 1555 && rndis_control_intf.bInterfaceNumber ··· 1615 1688 */ 1616 1689 size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA); 1617 1690 size += dev->out_ep->maxpacket - 1; 1618 - #ifdef CONFIG_USB_ETH_RNDIS 1619 - if (dev->rndis) 1691 + if (rndis_active(dev)) 1620 1692 size += sizeof (struct rndis_packet_msg_type); 1621 - #endif 1622 1693 size -= size % dev->out_ep->maxpacket; 1623 1694 1624 1695 if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) { ··· 1660 1735 /* normal completion */ 1661 1736 case 0: 1662 1737 skb_put (skb, req->actual); 1663 - #ifdef CONFIG_USB_ETH_RNDIS 1664 1738 /* we know MaxPacketsPerTransfer == 1 here */ 1665 - if (dev->rndis) 1739 + if (rndis_active(dev)) 1666 1740 status = rndis_rm_hdr (skb); 1667 - #endif 1668 1741 if (status < 0 1669 1742 || ETH_HLEN > skb->len 1670 1743 || skb->len > ETH_FRAME_LEN) { ··· 1782 1859 struct usb_request *req; 1783 1860 unsigned long flags; 1784 1861 1785 - clear_bit (WORK_RX_MEMORY, &dev->todo); 1786 - 1787 1862 /* fill unused rxq slots with some skb */ 1788 1863 spin_lock_irqsave (&dev->lock, flags); 1789 1864 while (!list_empty (&dev->rx_reqs)) { ··· 1804 1883 { 1805 1884 struct eth_dev *dev = _dev; 1806 1885 1807 - if (test_bit (WORK_RX_MEMORY, &dev->todo)) { 1886 + if (test_and_clear_bit (WORK_RX_MEMORY, &dev->todo)) { 1808 1887 if (netif_running (dev->net)) 1809 1888 rx_fill (dev, GFP_KERNEL); 1810 - else 1811 - clear_bit (WORK_RX_MEMORY, &dev->todo); 1812 1889 } 1813 1890 1814 1891 if (dev->todo) ··· 1890 1971 * or the hardware can't use skb buffers. 1891 1972 * or there's not enough space for any RNDIS headers we need 1892 1973 */ 1893 - #ifdef CONFIG_USB_ETH_RNDIS 1894 - if (dev->rndis) { 1974 + if (rndis_active(dev)) { 1895 1975 struct sk_buff *skb_rndis; 1896 1976 1897 1977 skb_rndis = skb_realloc_headroom (skb, ··· 1903 1985 rndis_add_hdr (skb); 1904 1986 length = skb->len; 1905 1987 } 1906 - #endif 1907 1988 req->buf = skb->data; 1908 1989 req->context = skb; 1909 1990 req->complete = tx_complete; ··· 1935 2018 } 1936 2019 1937 2020 if (retval) { 1938 - #ifdef CONFIG_USB_ETH_RNDIS 1939 2021 drop: 1940 - #endif 1941 2022 dev->stats.tx_dropped++; 1942 2023 dev_kfree_skb_any (skb); 1943 2024 spin_lock_irqsave (&dev->lock, flags); ··· 1951 2036 1952 2037 #ifdef CONFIG_USB_ETH_RNDIS 1953 2038 1954 - static void rndis_send_media_state (struct eth_dev *dev, int connect) 1955 - { 1956 - if (!dev) 1957 - return; 1958 - 1959 - if (connect) { 1960 - if (rndis_signal_connect (dev->rndis_config)) 1961 - return; 1962 - } else { 1963 - if (rndis_signal_disconnect (dev->rndis_config)) 1964 - return; 1965 - } 1966 - } 2039 + /* The interrupt endpoint is used in RNDIS to notify the host when messages 2040 + * other than data packets are available ... notably the REMOTE_NDIS_*_CMPLT 2041 + * messages, but also REMOTE_NDIS_INDICATE_STATUS_MSG and potentially even 2042 + * REMOTE_NDIS_KEEPALIVE_MSG. 2043 + * 2044 + * The RNDIS control queue is processed by GET_ENCAPSULATED_RESPONSE, and 2045 + * normally just one notification will be queued. 2046 + */ 2047 + 2048 + static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, unsigned); 2049 + static void eth_req_free (struct usb_ep *ep, struct usb_request *req); 1967 2050 1968 2051 static void 1969 2052 rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req) 1970 2053 { 2054 + struct eth_dev *dev = ep->driver_data; 2055 + 1971 2056 if (req->status || req->actual != req->length) 1972 - DEBUG ((struct eth_dev *) ep->driver_data, 2057 + DEBUG (dev, 1973 2058 "rndis control ack complete --> %d, %d/%d\n", 1974 2059 req->status, req->actual, req->length); 2060 + req->context = NULL; 2061 + 2062 + if (req != dev->stat_req) 2063 + eth_req_free(ep, req); 1975 2064 } 1976 2065 1977 2066 static int rndis_control_ack (struct net_device *net) ··· 1990 2071 return -ENODEV; 1991 2072 } 1992 2073 2074 + /* in case queue length > 1 */ 2075 + if (resp->context) { 2076 + resp = eth_req_alloc (dev->status_ep, 8, GFP_ATOMIC); 2077 + if (!resp) 2078 + return -ENOMEM; 2079 + } 2080 + 1993 2081 /* Send RNDIS RESPONSE_AVAILABLE notification; 1994 2082 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too 1995 2083 */ 1996 2084 resp->length = 8; 1997 2085 resp->complete = rndis_control_ack_complete; 2086 + resp->context = dev; 1998 2087 1999 2088 *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1); 2000 2089 *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0); ··· 2016 2089 return 0; 2017 2090 } 2018 2091 2092 + #else 2093 + 2094 + #define rndis_control_ack NULL 2095 + 2019 2096 #endif /* RNDIS */ 2020 2097 2021 2098 static void eth_start (struct eth_dev *dev, int gfp_flags) ··· 2032 2101 /* and open the tx floodgates */ 2033 2102 atomic_set (&dev->tx_qlen, 0); 2034 2103 netif_wake_queue (dev->net); 2035 - #ifdef CONFIG_USB_ETH_RNDIS 2036 - if (dev->rndis) { 2104 + if (rndis_active(dev)) { 2037 2105 rndis_set_param_medium (dev->rndis_config, 2038 2106 NDIS_MEDIUM_802_3, 2039 2107 BITRATE(dev->gadget)/100); 2040 - rndis_send_media_state (dev, 1); 2108 + (void) rndis_signal_connect (dev->rndis_config); 2041 2109 } 2042 - #endif 2043 2110 } 2044 2111 2045 2112 static int eth_open (struct net_device *net) ··· 2078 2149 } 2079 2150 } 2080 2151 2081 - #ifdef CONFIG_USB_ETH_RNDIS 2082 - if (dev->rndis) { 2152 + if (rndis_active(dev)) { 2083 2153 rndis_set_param_medium (dev->rndis_config, 2084 2154 NDIS_MEDIUM_802_3, 0); 2085 - rndis_send_media_state (dev, 0); 2155 + (void) rndis_signal_disconnect (dev->rndis_config); 2086 2156 } 2087 - #endif 2088 2157 2089 2158 return 0; 2090 2159 } 2091 2160 2092 2161 /*-------------------------------------------------------------------------*/ 2093 2162 2094 - static struct usb_request *eth_req_alloc (struct usb_ep *ep, unsigned size) 2163 + static struct usb_request * 2164 + eth_req_alloc (struct usb_ep *ep, unsigned size, unsigned gfp_flags) 2095 2165 { 2096 2166 struct usb_request *req; 2097 2167 2098 - req = usb_ep_alloc_request (ep, GFP_KERNEL); 2168 + req = usb_ep_alloc_request (ep, gfp_flags); 2099 2169 if (!req) 2100 2170 return NULL; 2101 2171 2102 - req->buf = kmalloc (size, GFP_KERNEL); 2172 + req->buf = kmalloc (size, gfp_flags); 2103 2173 if (!req->buf) { 2104 2174 usb_ep_free_request (ep, req); 2105 2175 req = NULL; ··· 2120 2192 struct eth_dev *dev = get_gadget_data (gadget); 2121 2193 2122 2194 DEBUG (dev, "unbind\n"); 2123 - #ifdef CONFIG_USB_ETH_RNDIS 2124 2195 rndis_deregister (dev->rndis_config); 2125 2196 rndis_exit (); 2126 - #endif 2127 2197 2128 2198 /* we've already been disconnected ... no i/o is active */ 2129 2199 if (dev->req) { ··· 2294 2368 gadget->name); 2295 2369 return -ENODEV; 2296 2370 } 2297 - EP_IN_NAME = in_ep->name; 2298 2371 in_ep->driver_data = in_ep; /* claim */ 2299 2372 2300 2373 out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc); 2301 2374 if (!out_ep) 2302 2375 goto autoconf_fail; 2303 - EP_OUT_NAME = out_ep->name; 2304 2376 out_ep->driver_data = out_ep; /* claim */ 2305 2377 2306 2378 #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) ··· 2308 2384 if (cdc || rndis) { 2309 2385 status_ep = usb_ep_autoconfig (gadget, &fs_status_desc); 2310 2386 if (status_ep) { 2311 - EP_STATUS_NAME = status_ep->name; 2312 2387 status_ep->driver_data = status_ep; /* claim */ 2313 2388 } else if (rndis) { 2314 2389 dev_err (&gadget->dev, ··· 2349 2426 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; 2350 2427 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; 2351 2428 #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 2352 - if (EP_STATUS_NAME) 2429 + if (status_ep) 2353 2430 hs_status_desc.bEndpointAddress = 2354 2431 fs_status_desc.bEndpointAddress; 2355 2432 #endif ··· 2422 2499 SET_ETHTOOL_OPS(net, &ops); 2423 2500 2424 2501 /* preallocate control message data and buffer */ 2425 - dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ); 2502 + dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ, GFP_KERNEL); 2426 2503 if (!dev->req) 2427 2504 goto fail; 2428 2505 dev->req->complete = eth_setup_complete; 2429 2506 2430 2507 /* ... and maybe likewise for status transfer */ 2508 + #ifdef DEV_CONFIG_CDC 2431 2509 if (dev->status_ep) { 2432 2510 dev->stat_req = eth_req_alloc (dev->status_ep, 2433 - STATUS_BYTECOUNT); 2511 + STATUS_BYTECOUNT, GFP_KERNEL); 2434 2512 if (!dev->stat_req) { 2435 2513 eth_req_free (gadget->ep0, dev->req); 2436 2514 goto fail; 2437 2515 } 2516 + dev->stat_req->context = NULL; 2438 2517 } 2518 + #endif 2439 2519 2440 2520 /* finish hookup to lower layer ... */ 2441 2521 dev->gadget = gadget; ··· 2452 2526 netif_stop_queue (dev->net); 2453 2527 netif_carrier_off (dev->net); 2454 2528 2455 - // SET_NETDEV_DEV (dev->net, &gadget->dev); 2529 + SET_NETDEV_DEV (dev->net, &gadget->dev); 2456 2530 status = register_netdev (dev->net); 2457 2531 if (status < 0) 2458 2532 goto fail1; 2459 2533 2460 2534 INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); 2461 2535 INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name, 2462 - EP_OUT_NAME, EP_IN_NAME, 2463 - EP_STATUS_NAME ? " STATUS " : "", 2464 - EP_STATUS_NAME ? EP_STATUS_NAME : "" 2536 + out_ep->name, in_ep->name, 2537 + status_ep ? " STATUS " : "", 2538 + status_ep ? status_ep->name : "" 2465 2539 ); 2466 2540 INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n", 2467 2541 net->dev_addr [0], net->dev_addr [1], ··· 2474 2548 dev->host_mac [2], dev->host_mac [3], 2475 2549 dev->host_mac [4], dev->host_mac [5]); 2476 2550 2477 - #ifdef CONFIG_USB_ETH_RNDIS 2478 2551 if (rndis) { 2479 2552 u32 vendorID = 0; 2480 2553 ··· 2490 2565 /* these set up a lot of the OIDs that RNDIS needs */ 2491 2566 rndis_set_host_mac (dev->rndis_config, dev->host_mac); 2492 2567 if (rndis_set_param_dev (dev->rndis_config, dev->net, 2493 - &dev->stats)) 2568 + &dev->stats, &dev->cdc_filter)) 2494 2569 goto fail0; 2495 2570 if (rndis_set_param_vendor (dev->rndis_config, vendorID, 2496 2571 manufacturer)) ··· 2501 2576 goto fail0; 2502 2577 INFO (dev, "RNDIS ready\n"); 2503 2578 } 2504 - #endif 2505 2579 2506 2580 return status; 2507 2581 ··· 2534 2610 /*-------------------------------------------------------------------------*/ 2535 2611 2536 2612 static struct usb_gadget_driver eth_driver = { 2537 - #ifdef CONFIG_USB_GADGET_DUALSPEED 2538 - .speed = USB_SPEED_HIGH, 2539 - #else 2540 - .speed = USB_SPEED_FULL, 2541 - #endif 2613 + .speed = DEVSPEED, 2614 + 2542 2615 .function = (char *) driver_desc, 2543 2616 .bind = eth_bind, 2544 2617 .unbind = eth_unbind,
+29 -32
drivers/usb/gadget/file_storage.c
··· 81 81 * removable Default false, boolean for removable media 82 82 * luns=N Default N = number of filenames, number of 83 83 * LUNs to support 84 + * stall Default determined according to the type of 85 + * USB device controller (usually true), 86 + * boolean to permit the driver to halt 87 + * bulk endpoints 84 88 * transport=XXX Default BBB, transport name (CB, CBI, or BBB) 85 89 * protocol=YYY Default SCSI, protocol name (RBC, 8020 or 86 90 * ATAPI, QIC, UFI, 8070, or SCSI; ··· 95 91 * buflen=N Default N=16384, buffer size used (will be 96 92 * rounded down to a multiple of 97 93 * PAGE_CACHE_SIZE) 98 - * stall Default determined according to the type of 99 - * USB device controller (usually true), 100 - * boolean to permit the driver to halt 101 - * bulk endpoints 102 94 * 103 95 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", 104 - * "removable", and "luns" options are available; default values are used 105 - * for everything else. 96 + * "removable", "luns", and "stall" options are available; default values 97 + * are used for everything else. 106 98 * 107 99 * The pathnames of the backing files and the ro settings are available in 108 100 * the attribute files "file" and "ro" in the lun<n> subdirectory of the ··· 342 342 int num_ros; 343 343 unsigned int nluns; 344 344 345 + int removable; 346 + int can_stall; 347 + 345 348 char *transport_parm; 346 349 char *protocol_parm; 347 - int removable; 348 350 unsigned short vendor; 349 351 unsigned short product; 350 352 unsigned short release; 351 353 unsigned int buflen; 352 - int can_stall; 353 354 354 355 int transport_type; 355 356 char *transport_name; ··· 361 360 .transport_parm = "BBB", 362 361 .protocol_parm = "SCSI", 363 362 .removable = 0, 363 + .can_stall = 1, 364 364 .vendor = DRIVER_VENDOR_ID, 365 365 .product = DRIVER_PRODUCT_ID, 366 366 .release = 0xffff, // Use controller chip type 367 367 .buflen = 16384, 368 - .can_stall = 1, 369 368 }; 370 369 371 370 ··· 380 379 381 380 module_param_named(removable, mod_data.removable, bool, S_IRUGO); 382 381 MODULE_PARM_DESC(removable, "true to simulate removable media"); 382 + 383 + module_param_named(stall, mod_data.can_stall, bool, S_IRUGO); 384 + MODULE_PARM_DESC(stall, "false to prevent bulk stalls"); 383 385 384 386 385 387 /* In the non-TEST version, only the module parameters listed above ··· 407 403 408 404 module_param_named(buflen, mod_data.buflen, uint, S_IRUGO); 409 405 MODULE_PARM_DESC(buflen, "I/O buffer size"); 410 - 411 - module_param_named(stall, mod_data.can_stall, bool, S_IRUGO); 412 - MODULE_PARM_DESC(stall, "false to prevent bulk stalls"); 413 406 414 407 #endif /* CONFIG_USB_FILE_STORAGE_TEST */ 415 408 ··· 819 818 buf[0] = val >> 24; 820 819 buf[1] = val >> 16; 821 820 buf[2] = val >> 8; 822 - buf[3] = val; 821 + buf[3] = val & 0xff; 823 822 } 824 823 825 824 ··· 1277 1276 { 1278 1277 struct usb_request *req = fsg->ep0req; 1279 1278 int value = -EOPNOTSUPP; 1280 - u16 w_index = ctrl->wIndex; 1281 - u16 w_length = ctrl->wLength; 1279 + u16 w_index = le16_to_cpu(ctrl->wIndex); 1280 + u16 w_length = le16_to_cpu(ctrl->wLength); 1282 1281 1283 1282 if (!fsg->config) 1284 1283 return value; ··· 1313 1312 } 1314 1313 VDBG(fsg, "get max LUN\n"); 1315 1314 *(u8 *) req->buf = fsg->nluns - 1; 1316 - value = min(w_length, (u16) 1); 1315 + value = 1; 1317 1316 break; 1318 1317 } 1319 1318 } ··· 1345 1344 "unknown class-specific control req " 1346 1345 "%02x.%02x v%04x i%04x l%u\n", 1347 1346 ctrl->bRequestType, ctrl->bRequest, 1348 - ctrl->wValue, w_index, w_length); 1347 + le16_to_cpu(ctrl->wValue), w_index, w_length); 1349 1348 return value; 1350 1349 } 1351 1350 ··· 1359 1358 { 1360 1359 struct usb_request *req = fsg->ep0req; 1361 1360 int value = -EOPNOTSUPP; 1362 - u16 w_index = ctrl->wIndex; 1363 - u16 w_value = ctrl->wValue; 1364 - u16 w_length = ctrl->wLength; 1361 + u16 w_index = le16_to_cpu(ctrl->wIndex); 1362 + u16 w_value = le16_to_cpu(ctrl->wValue); 1365 1363 1366 1364 /* Usually this just stores reply data in the pre-allocated ep0 buffer, 1367 1365 * but config change events will also reconfigure hardware. */ ··· 1374 1374 1375 1375 case USB_DT_DEVICE: 1376 1376 VDBG(fsg, "get device descriptor\n"); 1377 - value = min(w_length, (u16) sizeof device_desc); 1377 + value = sizeof device_desc; 1378 1378 memcpy(req->buf, &device_desc, value); 1379 1379 break; 1380 1380 #ifdef CONFIG_USB_GADGET_DUALSPEED ··· 1382 1382 VDBG(fsg, "get device qualifier\n"); 1383 1383 if (!fsg->gadget->is_dualspeed) 1384 1384 break; 1385 - value = min(w_length, (u16) sizeof dev_qualifier); 1385 + value = sizeof dev_qualifier; 1386 1386 memcpy(req->buf, &dev_qualifier, value); 1387 1387 break; 1388 1388 ··· 1401 1401 req->buf, 1402 1402 w_value >> 8, 1403 1403 w_value & 0xff); 1404 - if (value >= 0) 1405 - value = min(w_length, (u16) value); 1406 1404 break; 1407 1405 1408 1406 case USB_DT_STRING: ··· 1409 1411 /* wIndex == language code */ 1410 1412 value = usb_gadget_get_string(&stringtab, 1411 1413 w_value & 0xff, req->buf); 1412 - if (value >= 0) 1413 - value = min(w_length, (u16) value); 1414 1414 break; 1415 1415 } 1416 1416 break; ··· 1434 1438 break; 1435 1439 VDBG(fsg, "get configuration\n"); 1436 1440 *(u8 *) req->buf = fsg->config; 1437 - value = min(w_length, (u16) 1); 1441 + value = 1; 1438 1442 break; 1439 1443 1440 1444 case USB_REQ_SET_INTERFACE: ··· 1462 1466 } 1463 1467 VDBG(fsg, "get interface\n"); 1464 1468 *(u8 *) req->buf = 0; 1465 - value = min(w_length, (u16) 1); 1469 + value = 1; 1466 1470 break; 1467 1471 1468 1472 default: 1469 1473 VDBG(fsg, 1470 1474 "unknown control req %02x.%02x v%04x i%04x l%u\n", 1471 1475 ctrl->bRequestType, ctrl->bRequest, 1472 - w_value, w_index, w_length); 1476 + w_value, w_index, le16_to_cpu(ctrl->wLength)); 1473 1477 } 1474 1478 1475 1479 return value; ··· 1481 1485 { 1482 1486 struct fsg_dev *fsg = get_gadget_data(gadget); 1483 1487 int rc; 1488 + int w_length = le16_to_cpu(ctrl->wLength); 1484 1489 1485 1490 ++fsg->ep0_req_tag; // Record arrival of a new request 1486 1491 fsg->ep0req->context = NULL; ··· 1495 1498 1496 1499 /* Respond with data/status or defer until later? */ 1497 1500 if (rc >= 0 && rc != DELAYED_STATUS) { 1501 + rc = min(rc, w_length); 1498 1502 fsg->ep0req->length = rc; 1499 - fsg->ep0req->zero = (rc < ctrl->wLength && 1500 - (rc % gadget->ep0->maxpacket) == 0); 1503 + fsg->ep0req->zero = rc < w_length; 1501 1504 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ? 1502 1505 "ep0-in" : "ep0-out"); 1503 1506 rc = ep0_queue(fsg); ··· 2657 2660 } 2658 2661 } 2659 2662 2660 - /* Check that the LUN values are oonsistent */ 2663 + /* Check that the LUN values are consistent */ 2661 2664 if (transport_is_bbb()) { 2662 2665 if (fsg->lun != lun) 2663 2666 DBG(fsg, "using LUN %d from CBW, "
+17 -11
drivers/usb/gadget/goku_udc.c
··· 70 70 * seem to behave quite as expected. Used by default. 71 71 * 72 72 * OUT dma documents design problems handling the common "short packet" 73 - * transfer termination policy; it couldn't enabled by default, even 73 + * transfer termination policy; it couldn't be enabled by default, even 74 74 * if the OUT-dma abort problems had a resolution. 75 75 */ 76 76 static unsigned use_dma = 1; ··· 313 313 #if defined(CONFIG_X86) 314 314 #define USE_KMALLOC 315 315 316 - #elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) 316 + #elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT) 317 317 #define USE_KMALLOC 318 318 319 319 #elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) ··· 1524 1524 /* read SETUP packet and enter DATA stage */ 1525 1525 ctrl.bRequestType = readl(&regs->bRequestType); 1526 1526 ctrl.bRequest = readl(&regs->bRequest); 1527 - ctrl.wValue = (readl(&regs->wValueH) << 8) | readl(&regs->wValueL); 1528 - ctrl.wIndex = (readl(&regs->wIndexH) << 8) | readl(&regs->wIndexL); 1529 - ctrl.wLength = (readl(&regs->wLengthH) << 8) | readl(&regs->wLengthL); 1527 + ctrl.wValue = cpu_to_le16((readl(&regs->wValueH) << 8) 1528 + | readl(&regs->wValueL)); 1529 + ctrl.wIndex = cpu_to_le16((readl(&regs->wIndexH) << 8) 1530 + | readl(&regs->wIndexL)); 1531 + ctrl.wLength = cpu_to_le16((readl(&regs->wLengthH) << 8) 1532 + | readl(&regs->wLengthL)); 1530 1533 writel(0, &regs->SetupRecv); 1531 1534 1532 1535 nuke(&dev->ep[0], 0); ··· 1551 1548 case USB_REQ_CLEAR_FEATURE: 1552 1549 switch (ctrl.bRequestType) { 1553 1550 case USB_RECIP_ENDPOINT: 1554 - tmp = ctrl.wIndex & 0x0f; 1551 + tmp = le16_to_cpu(ctrl.wIndex) & 0x0f; 1555 1552 /* active endpoint */ 1556 1553 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0)) 1557 1554 goto stall; 1558 - if (ctrl.wIndex & USB_DIR_IN) { 1555 + if (ctrl.wIndex & __constant_cpu_to_le16( 1556 + USB_DIR_IN)) { 1559 1557 if (!dev->ep[tmp].is_in) 1560 1558 goto stall; 1561 1559 } else { 1562 1560 if (dev->ep[tmp].is_in) 1563 1561 goto stall; 1564 1562 } 1565 - if (ctrl.wValue != USB_ENDPOINT_HALT) 1563 + if (ctrl.wValue != __constant_cpu_to_le16( 1564 + USB_ENDPOINT_HALT)) 1566 1565 goto stall; 1567 1566 if (tmp) 1568 1567 goku_clear_halt(&dev->ep[tmp]); ··· 1576 1571 return; 1577 1572 case USB_RECIP_DEVICE: 1578 1573 /* device remote wakeup: always clear */ 1579 - if (ctrl.wValue != 1) 1574 + if (ctrl.wValue != __constant_cpu_to_le16(1)) 1580 1575 goto stall; 1581 1576 VDBG(dev, "clear dev remote wakeup\n"); 1582 1577 goto succeed; ··· 1594 1589 #ifdef USB_TRACE 1595 1590 VDBG(dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", 1596 1591 ctrl.bRequestType, ctrl.bRequest, 1597 - ctrl.wValue, ctrl.wIndex, ctrl.wLength); 1592 + le16_to_cpu(ctrl.wValue), le16_to_cpu(ctrl.wIndex), 1593 + le16_to_cpu(ctrl.wLength)); 1598 1594 #endif 1599 1595 1600 1596 /* hw wants to know when we're configured (or not) */ 1601 1597 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION 1602 1598 && ctrl.bRequestType == USB_RECIP_DEVICE); 1603 1599 if (unlikely(dev->req_config)) 1604 - dev->configured = (ctrl.wValue != 0); 1600 + dev->configured = (ctrl.wValue != __constant_cpu_to_le16(0)); 1605 1601 1606 1602 /* delegate everything to the gadget driver. 1607 1603 * it may respond after this irq handler returns.
+6 -6
drivers/usb/gadget/inode.c
··· 417 417 goto free1; 418 418 419 419 value = ep_io (data, kbuf, len); 420 - VDEBUG (data->dev, "%s read %d OUT, status %d\n", 421 - data->name, len, value); 420 + VDEBUG (data->dev, "%s read %zu OUT, status %d\n", 421 + data->name, len, (int) value); 422 422 if (value >= 0 && copy_to_user (buf, kbuf, value)) 423 423 value = -EFAULT; 424 424 ··· 465 465 } 466 466 467 467 value = ep_io (data, kbuf, len); 468 - VDEBUG (data->dev, "%s write %d IN, status %d\n", 469 - data->name, len, value); 468 + VDEBUG (data->dev, "%s write %zu IN, status %d\n", 469 + data->name, len, (int) value); 470 470 free1: 471 471 up (&data->lock); 472 472 kfree (kbuf); ··· 1318 1318 struct usb_request *req = dev->req; 1319 1319 int value = -EOPNOTSUPP; 1320 1320 struct usb_gadgetfs_event *event; 1321 - u16 w_value = ctrl->wValue; 1322 - u16 w_length = ctrl->wLength; 1321 + u16 w_value = le16_to_cpu(ctrl->wValue); 1322 + u16 w_length = le16_to_cpu(ctrl->wLength); 1323 1323 1324 1324 spin_lock (&dev->lock); 1325 1325 dev->setup_abort = 0;
+7 -7
drivers/usb/gadget/ndis.h
··· 47 47 #define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004 48 48 49 49 struct NDIS_PNP_CAPABILITIES { 50 - u32 Flags; 50 + __le32 Flags; 51 51 struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities; 52 52 }; 53 53 54 54 struct NDIS_PM_PACKET_PATTERN { 55 - u32 Priority; 56 - u32 Reserved; 57 - u32 MaskSize; 58 - u32 PatternOffset; 59 - u32 PatternSize; 60 - u32 PatternFlags; 55 + __le32 Priority; 56 + __le32 Reserved; 57 + __le32 MaskSize; 58 + __le32 PatternOffset; 59 + __le32 PatternSize; 60 + __le32 PatternFlags; 61 61 }; 62 62 63 63
+29 -22
drivers/usb/gadget/net2280.c
··· 448 448 #elif defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE) 449 449 #define USE_KMALLOC 450 450 451 - #elif defined(CONFIG_MIPS) && !defined(CONFIG_NONCOHERENT_IO) 451 + #elif defined(CONFIG_MIPS) && !defined(CONFIG_DMA_NONCOHERENT) 452 452 #define USE_KMALLOC 453 453 454 454 /* FIXME there are other cases, including an x86-64 one ... */ ··· 1113 1113 if (ep->in_fifo_validate) 1114 1114 dmactl |= (1 << DMA_FIFO_VALIDATE); 1115 1115 list_for_each_entry (entry, &ep->queue, queue) { 1116 - u32 dmacount; 1116 + __le32 dmacount; 1117 1117 1118 1118 if (entry == req) 1119 1119 continue; ··· 1238 1238 &ep->dma->dmadesc); 1239 1239 if (req->td->dmacount & dma_done_ie) 1240 1240 writel (readl (&ep->dma->dmacount) 1241 - | dma_done_ie, 1241 + | le32_to_cpu(dma_done_ie), 1242 1242 &ep->dma->dmacount); 1243 1243 } else { 1244 1244 struct net2280_request *prev; ··· 1778 1778 list_add_tail (&dev->ep [5].ep.ep_list, &dev->gadget.ep_list); 1779 1779 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); 1780 1780 } 1781 + 1782 + /* just declare this in any driver that really need it */ 1783 + extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode); 1781 1784 1782 1785 /** 1783 1786 * net2280_set_fifo_mode - change allocation of fifo buffers ··· 2385 2382 cpu_to_le32s (&u.raw [0]); 2386 2383 cpu_to_le32s (&u.raw [1]); 2387 2384 2388 - le16_to_cpus (&u.r.wValue); 2389 - le16_to_cpus (&u.r.wIndex); 2390 - le16_to_cpus (&u.r.wLength); 2385 + #define w_value le16_to_cpup (&u.r.wValue) 2386 + #define w_index le16_to_cpup (&u.r.wIndex) 2387 + #define w_length le16_to_cpup (&u.r.wLength) 2391 2388 2392 2389 /* ack the irq */ 2393 2390 writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0); ··· 2416 2413 switch (u.r.bRequest) { 2417 2414 case USB_REQ_GET_STATUS: { 2418 2415 struct net2280_ep *e; 2419 - u16 status; 2416 + __le32 status; 2420 2417 2421 2418 /* hw handles device and interface status */ 2422 2419 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) 2423 2420 goto delegate; 2424 - if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0 2425 - || u.r.wLength > 2) 2421 + if ((e = get_ep_by_addr (dev, w_index)) == 0 2422 + || w_length > 2) 2426 2423 goto do_stall; 2427 2424 2428 2425 if (readl (&e->regs->ep_rsp) 2429 2426 & (1 << SET_ENDPOINT_HALT)) 2430 - status = __constant_cpu_to_le16 (1); 2427 + status = __constant_cpu_to_le32 (1); 2431 2428 else 2432 - status = __constant_cpu_to_le16 (0); 2429 + status = __constant_cpu_to_le32 (0); 2433 2430 2434 2431 /* don't bother with a request object! */ 2435 2432 writel (0, &dev->epregs [0].ep_irqenb); 2436 - set_fifo_bytecount (ep, u.r.wLength); 2437 - writel (status, &dev->epregs [0].ep_data); 2433 + set_fifo_bytecount (ep, w_length); 2434 + writel ((__force u32)status, &dev->epregs [0].ep_data); 2438 2435 allow_status (ep); 2439 2436 VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status); 2440 2437 goto next_endpoints; ··· 2446 2443 /* hw handles device features */ 2447 2444 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 2448 2445 goto delegate; 2449 - if (u.r.wValue != USB_ENDPOINT_HALT 2450 - || u.r.wLength != 0) 2446 + if (w_value != USB_ENDPOINT_HALT 2447 + || w_length != 0) 2451 2448 goto do_stall; 2452 - if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) 2449 + if ((e = get_ep_by_addr (dev, w_index)) == 0) 2453 2450 goto do_stall; 2454 2451 clear_halt (e); 2455 2452 allow_status (ep); ··· 2463 2460 /* hw handles device features */ 2464 2461 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 2465 2462 goto delegate; 2466 - if (u.r.wValue != USB_ENDPOINT_HALT 2467 - || u.r.wLength != 0) 2463 + if (w_value != USB_ENDPOINT_HALT 2464 + || w_length != 0) 2468 2465 goto do_stall; 2469 - if ((e = get_ep_by_addr (dev, u.r.wIndex)) == 0) 2466 + if ((e = get_ep_by_addr (dev, w_index)) == 0) 2470 2467 goto do_stall; 2471 2468 set_halt (e); 2472 2469 allow_status (ep); ··· 2476 2473 break; 2477 2474 default: 2478 2475 delegate: 2479 - VDEBUG (dev, "setup %02x.%02x v%04x i%04x " 2476 + VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x" 2480 2477 "ep_cfg %08x\n", 2481 2478 u.r.bRequestType, u.r.bRequest, 2482 - u.r.wValue, u.r.wIndex, 2479 + w_value, w_index, w_length, 2483 2480 readl (&ep->regs->ep_cfg)); 2484 2481 spin_unlock (&dev->lock); 2485 2482 tmp = dev->driver->setup (&dev->gadget, &u.r); ··· 2499 2496 * before the host times out. 2500 2497 */ 2501 2498 } 2499 + 2500 + #undef w_value 2501 + #undef w_index 2502 + #undef w_length 2502 2503 2503 2504 next_endpoints: 2504 2505 /* endpoint data irq ? */ ··· 2660 2653 restart_dma (ep); 2661 2654 else if (ep->is_in && use_dma_chaining) { 2662 2655 struct net2280_request *req; 2663 - u32 dmacount; 2656 + __le32 dmacount; 2664 2657 2665 2658 /* the descriptor at the head of the chain 2666 2659 * may still have VALID_BIT clear; that's
+206 -97
drivers/usb/gadget/omap_udc.c
··· 52 52 #include <asm/mach-types.h> 53 53 54 54 #include <asm/arch/dma.h> 55 - #include <asm/arch/mux.h> 56 55 #include <asm/arch/usb.h> 57 56 58 57 #include "omap_udc.h" ··· 166 167 maxp = le16_to_cpu (desc->wMaxPacketSize); 167 168 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 168 169 && maxp != ep->maxpacket) 169 - || desc->wMaxPacketSize > ep->maxpacket 170 + || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket 170 171 || !desc->wMaxPacketSize) { 171 172 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 172 173 return -ERANGE; ··· 213 214 ep->has_dma = 0; 214 215 ep->lch = -1; 215 216 use_ep(ep, UDC_EP_SEL); 216 - UDC_CTRL_REG = UDC_RESET_EP; 217 + UDC_CTRL_REG = udc->clr_halt; 217 218 ep->ackwait = 0; 218 219 deselect_ep(); 219 220 ··· 252 253 } 253 254 254 255 spin_lock_irqsave(&ep->udc->lock, flags); 255 - ep->desc = 0; 256 + ep->desc = NULL; 256 257 nuke (ep, -ESHUTDOWN); 257 258 ep->ep.maxpacket = ep->maxpacket; 258 259 ep->has_dma = 0; ··· 387 388 388 389 /*-------------------------------------------------------------------------*/ 389 390 390 - #define FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL) 391 - #define FIFO_UNWRITABLE (UDC_EP_HALTED | FIFO_FULL) 391 + #define UDC_FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL) 392 + #define UDC_FIFO_UNWRITABLE (UDC_EP_HALTED | UDC_FIFO_FULL) 392 393 393 394 #define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY) 394 395 #define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY) ··· 432 433 433 434 /* PIO-IN isn't double buffered except for iso */ 434 435 ep_stat = UDC_STAT_FLG_REG; 435 - if (ep_stat & FIFO_UNWRITABLE) 436 + if (ep_stat & UDC_FIFO_UNWRITABLE) 436 437 return 0; 437 438 438 439 count = ep->ep.maxpacket; ··· 503 504 if (ep_stat & UDC_EP_HALTED) 504 505 break; 505 506 506 - if (ep_stat & FIFO_FULL) 507 + if (ep_stat & UDC_FIFO_FULL) 507 508 avail = ep->ep.maxpacket; 508 509 else { 509 510 avail = UDC_RXFSTAT_REG; ··· 537 538 538 539 /*-------------------------------------------------------------------------*/ 539 540 541 + static inline dma_addr_t dma_csac(unsigned lch) 542 + { 543 + dma_addr_t csac; 544 + 545 + /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is 546 + * read before the DMA controller finished disabling the channel. 547 + */ 548 + csac = omap_readw(OMAP_DMA_CSAC(lch)); 549 + if (csac == 0) 550 + csac = omap_readw(OMAP_DMA_CSAC(lch)); 551 + return csac; 552 + } 553 + 554 + static inline dma_addr_t dma_cdac(unsigned lch) 555 + { 556 + dma_addr_t cdac; 557 + 558 + /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is 559 + * read before the DMA controller finished disabling the channel. 560 + */ 561 + cdac = omap_readw(OMAP_DMA_CDAC(lch)); 562 + if (cdac == 0) 563 + cdac = omap_readw(OMAP_DMA_CDAC(lch)); 564 + return cdac; 565 + } 566 + 540 567 static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) 541 568 { 542 569 dma_addr_t end; ··· 573 548 if (cpu_is_omap15xx()) 574 549 return 0; 575 550 576 - end = omap_readw(OMAP_DMA_CSAC(ep->lch)); 551 + end = dma_csac(ep->lch); 577 552 if (end == ep->dma_counter) 578 553 return 0; 579 554 ··· 584 559 } 585 560 586 561 #define DMA_DEST_LAST(x) (cpu_is_omap15xx() \ 587 - ? OMAP_DMA_CSAC(x) /* really: CPC */ \ 588 - : OMAP_DMA_CDAC(x)) 562 + ? omap_readw(OMAP_DMA_CSAC(x)) /* really: CPC */ \ 563 + : dma_cdac(x)) 589 564 590 565 static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) 591 566 { 592 567 dma_addr_t end; 593 568 594 - end = omap_readw(DMA_DEST_LAST(ep->lch)); 569 + end = DMA_DEST_LAST(ep->lch); 595 570 if (end == ep->dma_counter) 596 571 return 0; 597 572 ··· 618 593 : OMAP_DMA_SYNC_ELEMENT; 619 594 620 595 /* measure length in either bytes or packets */ 621 - if ((cpu_is_omap16xx() && length <= (UDC_TXN_TSC + 1)) 596 + if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC) 622 597 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 623 598 txdma_ctrl = UDC_TXN_EOT | length; 624 599 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, ··· 627 602 length = min(length / ep->maxpacket, 628 603 (unsigned) UDC_TXN_TSC + 1); 629 604 txdma_ctrl = length; 630 - omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 631 - ep->ep.maxpacket, length, sync_mode); 605 + omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, 606 + ep->ep.maxpacket >> 1, length, sync_mode); 632 607 length *= ep->maxpacket; 633 608 } 634 609 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, 635 610 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 636 611 637 612 omap_start_dma(ep->lch); 638 - ep->dma_counter = omap_readw(OMAP_DMA_CSAC(ep->lch)); 613 + ep->dma_counter = dma_csac(ep->lch); 639 614 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel); 640 615 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl; 641 616 req->dma_bytes = length; ··· 675 650 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket; 676 651 packets = min(packets, (unsigned)UDC_RXN_TC + 1); 677 652 req->dma_bytes = packets * ep->ep.maxpacket; 678 - omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 679 - ep->ep.maxpacket, packets, 653 + omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, 654 + ep->ep.maxpacket >> 1, packets, 680 655 OMAP_DMA_SYNC_ELEMENT); 681 656 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 682 657 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 683 - ep->dma_counter = omap_readw(DMA_DEST_LAST(ep->lch)); 658 + ep->dma_counter = DMA_DEST_LAST(ep->lch); 684 659 685 660 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); 686 661 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel); ··· 788 763 reg = UDC_TXDMA_CFG_REG; 789 764 else 790 765 reg = UDC_RXDMA_CFG_REG; 791 - reg |= 1 << 12; /* "pulse" activated */ 766 + reg |= UDC_DMA_REQ; /* "pulse" activated */ 792 767 793 768 ep->dma_channel = 0; 794 769 ep->lch = -1; ··· 812 787 ep->ep.name, dma_error, ep, &ep->lch); 813 788 if (status == 0) { 814 789 UDC_TXDMA_CFG_REG = reg; 790 + /* EMIFF */ 791 + omap_set_dma_src_burst_mode(ep->lch, 792 + OMAP_DMA_DATA_BURST_4); 793 + omap_set_dma_src_data_pack(ep->lch, 1); 794 + /* TIPB */ 815 795 omap_set_dma_dest_params(ep->lch, 816 796 OMAP_DMA_PORT_TIPB, 817 797 OMAP_DMA_AMODE_CONSTANT, ··· 827 797 ep->ep.name, dma_error, ep, &ep->lch); 828 798 if (status == 0) { 829 799 UDC_RXDMA_CFG_REG = reg; 800 + /* TIPB */ 830 801 omap_set_dma_src_params(ep->lch, 831 802 OMAP_DMA_PORT_TIPB, 832 803 OMAP_DMA_AMODE_CONSTANT, 833 804 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); 805 + /* EMIFF */ 806 + omap_set_dma_dest_burst_mode(ep->lch, 807 + OMAP_DMA_DATA_BURST_4); 808 + omap_set_dma_dest_data_pack(ep->lch, 1); 834 809 } 835 810 } 836 811 if (status) ··· 891 856 if (!list_empty(&ep->queue)) 892 857 req = container_of(ep->queue.next, struct omap_req, queue); 893 858 else 894 - req = 0; 859 + req = NULL; 895 860 896 861 active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0; 897 862 ··· 900 865 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', 901 866 ep->dma_channel - 1, req); 902 867 868 + /* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before 869 + * OMAP 1710 ES2.0) where reading the DMA_CFG can clear them. 870 + */ 871 + 903 872 /* wait till current packet DMA finishes, and fifo empties */ 904 873 if (ep->bEndpointAddress & USB_DIR_IN) { 905 - UDC_TXDMA_CFG_REG &= ~mask; 874 + UDC_TXDMA_CFG_REG = (UDC_TXDMA_CFG_REG & ~mask) | UDC_DMA_REQ; 906 875 907 876 if (req) { 908 877 finish_in_dma(ep, req, -ECONNRESET); ··· 919 880 while (UDC_TXDMA_CFG_REG & mask) 920 881 udelay(10); 921 882 } else { 922 - UDC_RXDMA_CFG_REG &= ~mask; 883 + UDC_RXDMA_CFG_REG = (UDC_RXDMA_CFG_REG & ~mask) | UDC_DMA_REQ; 923 884 924 885 /* dma empties the fifo */ 925 886 while (UDC_RXDMA_CFG_REG & mask) ··· 1036 997 UDC_IRQ_EN_REG = irq_en; 1037 998 } 1038 999 1039 - /* STATUS is reverse direction */ 1040 - UDC_EP_NUM_REG = is_in 1041 - ? UDC_EP_SEL 1042 - : (UDC_EP_SEL|UDC_EP_DIR); 1000 + /* STATUS for zero length DATA stages is 1001 + * always an IN ... even for IN transfers, 1002 + * a wierd case which seem to stall OMAP. 1003 + */ 1004 + UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR); 1043 1005 UDC_CTRL_REG = UDC_CLR_EP; 1044 1006 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1045 - UDC_EP_NUM_REG = udc->ep0_in ? 0 : UDC_EP_DIR; 1007 + UDC_EP_NUM_REG = UDC_EP_DIR; 1046 1008 1047 1009 /* cleanup */ 1048 1010 udc->ep0_pending = 0; 1049 1011 done(ep, req, 0); 1050 - req = 0; 1012 + req = NULL; 1051 1013 1052 1014 /* non-empty DATA stage */ 1053 1015 } else if (is_in) { ··· 1069 1029 (is_in ? next_in_dma : next_out_dma)(ep, req); 1070 1030 else if (req) { 1071 1031 if ((is_in ? write_fifo : read_fifo)(ep, req) == 1) 1072 - req = 0; 1032 + req = NULL; 1073 1033 deselect_ep(); 1074 1034 if (!is_in) { 1075 1035 UDC_CTRL_REG = UDC_SET_FIFO_EN; ··· 1081 1041 1082 1042 irq_wait: 1083 1043 /* irq handler advances the queue */ 1084 - if (req != 0) 1044 + if (req != NULL) 1085 1045 list_add_tail(&req->queue, &ep->queue); 1086 1046 spin_unlock_irqrestore(&udc->lock, flags); 1087 1047 ··· 1180 1140 dma_channel_claim(ep, channel); 1181 1141 } else { 1182 1142 use_ep(ep, 0); 1183 - UDC_CTRL_REG = UDC_RESET_EP; 1143 + UDC_CTRL_REG = ep->udc->clr_halt; 1184 1144 ep->ackwait = 0; 1185 1145 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1186 1146 UDC_CTRL_REG = UDC_SET_FIFO_EN; ··· 1278 1238 1279 1239 static void pullup_enable(struct omap_udc *udc) 1280 1240 { 1241 + udc->gadget.dev.parent->power.power_state = PMSG_ON; 1242 + udc->gadget.dev.power.power_state = PMSG_ON; 1281 1243 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1282 1244 #ifndef CONFIG_USB_OTG 1283 1245 if (!cpu_is_omap15xx()) ··· 1424 1382 static void ep0_irq(struct omap_udc *udc, u16 irq_src) 1425 1383 { 1426 1384 struct omap_ep *ep0 = &udc->ep[0]; 1427 - struct omap_req *req = 0; 1385 + struct omap_req *req = NULL; 1428 1386 1429 1387 ep0->irqs++; 1430 1388 ··· 1480 1438 if (req) 1481 1439 done(ep0, req, 0); 1482 1440 } 1483 - req = 0; 1441 + req = NULL; 1484 1442 } else if (stat & UDC_STALL) { 1485 1443 UDC_CTRL_REG = UDC_CLR_HALT; 1486 1444 UDC_EP_NUM_REG = UDC_EP_DIR; ··· 1553 1511 u.word[3] = UDC_DATA_REG; 1554 1512 UDC_EP_NUM_REG = 0; 1555 1513 } while (UDC_IRQ_SRC_REG & UDC_SETUP); 1556 - le16_to_cpus (&u.r.wValue); 1557 - le16_to_cpus (&u.r.wIndex); 1558 - le16_to_cpus (&u.r.wLength); 1514 + 1515 + #define w_value le16_to_cpup (&u.r.wValue) 1516 + #define w_index le16_to_cpup (&u.r.wIndex) 1517 + #define w_length le16_to_cpup (&u.r.wLength) 1559 1518 1560 1519 /* Delegate almost all control requests to the gadget driver, 1561 1520 * except for a handful of ch9 status/feature requests that ··· 1572 1529 /* udc needs to know when ep != 0 is valid */ 1573 1530 if (u.r.bRequestType != USB_RECIP_DEVICE) 1574 1531 goto delegate; 1575 - if (u.r.wLength != 0) 1532 + if (w_length != 0) 1576 1533 goto do_stall; 1577 1534 udc->ep0_set_config = 1; 1578 - udc->ep0_reset_config = (u.r.wValue == 0); 1579 - VDBG("set config %d\n", u.r.wValue); 1535 + udc->ep0_reset_config = (w_value == 0); 1536 + VDBG("set config %d\n", w_value); 1580 1537 1581 1538 /* update udc NOW since gadget driver may start 1582 1539 * queueing requests immediately; clear config ··· 1592 1549 /* clear endpoint halt */ 1593 1550 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1594 1551 goto delegate; 1595 - if (u.r.wValue != USB_ENDPOINT_HALT 1596 - || u.r.wLength != 0) 1552 + if (w_value != USB_ENDPOINT_HALT 1553 + || w_length != 0) 1597 1554 goto do_stall; 1598 - ep = &udc->ep[u.r.wIndex & 0xf]; 1555 + ep = &udc->ep[w_index & 0xf]; 1599 1556 if (ep != ep0) { 1600 - if (u.r.wIndex & USB_DIR_IN) 1557 + if (w_index & USB_DIR_IN) 1601 1558 ep += 16; 1602 1559 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1603 1560 || !ep->desc) 1604 1561 goto do_stall; 1605 1562 use_ep(ep, 0); 1606 - UDC_CTRL_REG = UDC_RESET_EP; 1563 + UDC_CTRL_REG = udc->clr_halt; 1607 1564 ep->ackwait = 0; 1608 1565 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1609 1566 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1610 1567 ep->ackwait = 1 + ep->double_buf; 1611 1568 } 1569 + /* NOTE: assumes the host behaves sanely, 1570 + * only clearing real halts. Else we may 1571 + * need to kill pending transfers and then 1572 + * restart the queue... very messy for DMA! 1573 + */ 1612 1574 } 1613 1575 VDBG("%s halt cleared by host\n", ep->name); 1614 1576 goto ep0out_status_stage; ··· 1621 1573 /* set endpoint halt */ 1622 1574 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1623 1575 goto delegate; 1624 - if (u.r.wValue != USB_ENDPOINT_HALT 1625 - || u.r.wLength != 0) 1576 + if (w_value != USB_ENDPOINT_HALT 1577 + || w_length != 0) 1626 1578 goto do_stall; 1627 - ep = &udc->ep[u.r.wIndex & 0xf]; 1628 - if (u.r.wIndex & USB_DIR_IN) 1579 + ep = &udc->ep[w_index & 0xf]; 1580 + if (w_index & USB_DIR_IN) 1629 1581 ep += 16; 1630 1582 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1631 1583 || ep == ep0 || !ep->desc) ··· 1663 1615 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1664 1616 UDC_EP_NUM_REG = UDC_EP_DIR; 1665 1617 status = 0; 1666 - VDBG("GET_STATUS, interface %d\n", u.r.wIndex); 1618 + VDBG("GET_STATUS, interface %d\n", w_index); 1667 1619 /* next, status stage */ 1668 1620 break; 1669 1621 default: 1670 1622 delegate: 1671 1623 /* activate the ep0out fifo right away */ 1672 - if (!udc->ep0_in && u.r.wLength) { 1624 + if (!udc->ep0_in && w_length) { 1673 1625 UDC_EP_NUM_REG = 0; 1674 1626 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1675 1627 } ··· 1680 1632 */ 1681 1633 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n", 1682 1634 u.r.bRequestType, u.r.bRequest, 1683 - u.r.wValue, u.r.wIndex, u.r.wLength); 1635 + w_value, w_index, w_length); 1636 + 1637 + #undef w_value 1638 + #undef w_index 1639 + #undef w_length 1684 1640 1685 1641 /* The gadget driver may return an error here, 1686 1642 * causing an immediate protocol stall. ··· 2065 2013 udc->softconnect = 1; 2066 2014 2067 2015 /* hook up the driver */ 2068 - driver->driver.bus = 0; 2016 + driver->driver.bus = NULL; 2069 2017 udc->driver = driver; 2070 2018 udc->gadget.dev.driver = &driver->driver; 2071 2019 spin_unlock_irqrestore(&udc->lock, flags); ··· 2073 2021 status = driver->bind (&udc->gadget); 2074 2022 if (status) { 2075 2023 DBG("bind to %s --> %d\n", driver->driver.name, status); 2076 - udc->gadget.dev.driver = 0; 2077 - udc->driver = 0; 2024 + udc->gadget.dev.driver = NULL; 2025 + udc->driver = NULL; 2078 2026 goto done; 2079 2027 } 2080 2028 DBG("bound to driver %s\n", driver->driver.name); ··· 2087 2035 if (status < 0) { 2088 2036 ERR("can't bind to transceiver\n"); 2089 2037 driver->unbind (&udc->gadget); 2090 - udc->gadget.dev.driver = 0; 2091 - udc->driver = 0; 2038 + udc->gadget.dev.driver = NULL; 2039 + udc->driver = NULL; 2092 2040 goto done; 2093 2041 } 2094 2042 } else { ··· 2123 2071 omap_vbus_session(&udc->gadget, 0); 2124 2072 2125 2073 if (udc->transceiver) 2126 - (void) otg_set_peripheral(udc->transceiver, 0); 2074 + (void) otg_set_peripheral(udc->transceiver, NULL); 2127 2075 else 2128 2076 pullup_disable(udc); 2129 2077 ··· 2132 2080 spin_unlock_irqrestore(&udc->lock, flags); 2133 2081 2134 2082 driver->unbind(&udc->gadget); 2135 - udc->gadget.dev.driver = 0; 2136 - udc->driver = 0; 2137 - 2083 + udc->gadget.dev.driver = NULL; 2084 + udc->driver = NULL; 2138 2085 2139 2086 DBG("unregistered driver '%s'\n", driver->driver.name); 2140 2087 return status; ··· 2229 2178 2230 2179 tmp = OTG_REV_REG; 2231 2180 trans = USB_TRANSCEIVER_CTRL_REG; 2232 - seq_printf(s, "OTG rev %d.%d, transceiver_ctrl %03x\n", 2181 + seq_printf(s, "\nOTG rev %d.%d, transceiver_ctrl %05x\n", 2233 2182 tmp >> 4, tmp & 0xf, trans); 2234 2183 tmp = OTG_SYSCON_1_REG; 2235 2184 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," 2236 2185 FOURBITS "\n", tmp, 2237 2186 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R), 2238 2187 trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R), 2239 - (USB0_TRX_MODE(tmp) == 0) 2188 + (USB0_TRX_MODE(tmp) == 0 && !cpu_is_omap1710()) 2240 2189 ? "internal" 2241 2190 : trx_mode(USB0_TRX_MODE(tmp), 1), 2242 2191 (tmp & OTG_IDLE_EN) ? " !otg" : "", ··· 2286 2235 seq_printf(s, "otg_outctrl %04x" "\n", tmp); 2287 2236 tmp = OTG_TEST_REG; 2288 2237 seq_printf(s, "otg_test %04x" "\n", tmp); 2238 + return 0; 2289 2239 } 2290 2240 2291 2241 static int proc_udc_show(struct seq_file *s, void *_) ··· 2430 2378 2431 2379 static int proc_udc_open(struct inode *inode, struct file *file) 2432 2380 { 2433 - return single_open(file, proc_udc_show, 0); 2381 + return single_open(file, proc_udc_show, NULL); 2434 2382 } 2435 2383 2436 2384 static struct file_operations proc_ops = { ··· 2451 2399 2452 2400 static void remove_proc_file(void) 2453 2401 { 2454 - remove_proc_entry(proc_filename, 0); 2402 + remove_proc_entry(proc_filename, NULL); 2455 2403 } 2456 2404 2457 2405 #else ··· 2466 2414 /* Before this controller can enumerate, we need to pick an endpoint 2467 2415 * configuration, or "fifo_mode" That involves allocating 2KB of packet 2468 2416 * buffer space among the endpoints we'll be operating. 2417 + * 2418 + * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when 2419 + * UDC_SYSCON_1_REG.CFG_LOCK is set can now work. We won't use that 2420 + * capability yet though. 2469 2421 */ 2470 2422 static unsigned __init 2471 2423 omap_ep_setup(char *name, u8 addr, u8 type, ··· 2561 2505 { 2562 2506 complete(udc->done); 2563 2507 kfree (udc); 2564 - udc = 0; 2508 + udc = NULL; 2565 2509 } 2566 2510 2567 2511 static int __init ··· 2633 2577 case 1: 2634 2578 OMAP_BULK_EP("ep1in", USB_DIR_IN | 1); 2635 2579 OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); 2580 + OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16); 2581 + 2636 2582 OMAP_BULK_EP("ep3in", USB_DIR_IN | 3); 2637 2583 OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4); 2584 + OMAP_INT_EP("ep10in", USB_DIR_IN | 10, 16); 2638 2585 2639 2586 OMAP_BULK_EP("ep5in", USB_DIR_IN | 5); 2640 2587 OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5); 2588 + OMAP_INT_EP("ep11in", USB_DIR_IN | 11, 16); 2589 + 2641 2590 OMAP_BULK_EP("ep6in", USB_DIR_IN | 6); 2642 2591 OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6); 2592 + OMAP_INT_EP("ep12in", USB_DIR_IN | 12, 16); 2643 2593 2644 2594 OMAP_BULK_EP("ep7in", USB_DIR_IN | 7); 2645 2595 OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7); 2596 + OMAP_INT_EP("ep13in", USB_DIR_IN | 13, 16); 2597 + OMAP_INT_EP("ep13out", USB_DIR_OUT | 13, 16); 2598 + 2646 2599 OMAP_BULK_EP("ep8in", USB_DIR_IN | 8); 2647 2600 OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8); 2601 + OMAP_INT_EP("ep14in", USB_DIR_IN | 14, 16); 2602 + OMAP_INT_EP("ep14out", USB_DIR_OUT | 14, 16); 2648 2603 2649 - OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16); 2650 - OMAP_INT_EP("ep10out", USB_DIR_IN | 10, 16); 2651 - OMAP_INT_EP("ep11in", USB_DIR_IN | 9, 16); 2652 - OMAP_INT_EP("ep12out", USB_DIR_IN | 10, 16); 2604 + OMAP_BULK_EP("ep15in", USB_DIR_IN | 15); 2605 + OMAP_BULK_EP("ep15out", USB_DIR_OUT | 15); 2606 + 2653 2607 break; 2654 2608 2655 2609 #ifdef USE_ISO ··· 2706 2640 struct platform_device *odev = to_platform_device(dev); 2707 2641 int status = -ENODEV; 2708 2642 int hmc; 2709 - struct otg_transceiver *xceiv = 0; 2710 - const char *type = 0; 2643 + struct otg_transceiver *xceiv = NULL; 2644 + const char *type = NULL; 2711 2645 struct omap_usb_config *config = dev->platform_data; 2712 2646 2713 2647 /* NOTE: "knows" the order of the resources! */ ··· 2742 2676 FUNC_MUX_CTRL_0_REG = tmp; 2743 2677 } 2744 2678 } else { 2679 + /* The transceiver may package some GPIO logic or handle 2680 + * loopback and/or transceiverless setup; if we find one, 2681 + * use it. Except for OTG, we don't _need_ to talk to one; 2682 + * but not having one probably means no VBUS detection. 2683 + */ 2684 + xceiv = otg_get_transceiver(); 2685 + if (xceiv) 2686 + type = xceiv->label; 2687 + else if (config->otg) { 2688 + DBG("OTG requires external transceiver!\n"); 2689 + goto cleanup0; 2690 + } 2691 + 2745 2692 hmc = HMC_1610; 2746 2693 switch (hmc) { 2694 + case 0: /* POWERUP DEFAULT == 0 */ 2695 + case 4: 2696 + case 12: 2697 + case 20: 2698 + if (!cpu_is_omap1710()) { 2699 + type = "integrated"; 2700 + break; 2701 + } 2702 + /* FALL THROUGH */ 2747 2703 case 3: 2748 2704 case 11: 2749 2705 case 16: 2750 2706 case 19: 2751 2707 case 25: 2752 - xceiv = otg_get_transceiver(); 2753 2708 if (!xceiv) { 2754 2709 DBG("external transceiver not registered!\n"); 2755 - if (config->otg) 2756 - goto cleanup0; 2757 - type = "(unknown external)"; 2758 - } else 2759 - type = xceiv->label; 2760 - break; 2761 - case 0: /* POWERUP DEFAULT == 0 */ 2762 - case 4: 2763 - case 12: 2764 - case 20: 2765 - type = "INTEGRATED"; 2710 + type = "unknown"; 2711 + } 2766 2712 break; 2767 2713 case 21: /* internal loopback */ 2768 - type = "(loopback)"; 2714 + type = "loopback"; 2769 2715 break; 2770 2716 case 14: /* transceiverless */ 2771 - type = "(none)"; 2717 + if (cpu_is_omap1710()) 2718 + goto bad_on_1710; 2719 + /* FALL THROUGH */ 2720 + case 13: 2721 + case 15: 2722 + type = "no"; 2772 2723 break; 2773 2724 2774 2725 default: 2726 + bad_on_1710: 2775 2727 ERR("unrecognized UDC HMC mode %d\n", hmc); 2776 - return -ENODEV; 2728 + goto cleanup0; 2777 2729 } 2778 2730 } 2779 - INFO("hmc mode %d, transceiver %s\n", hmc, type); 2731 + INFO("hmc mode %d, %s transceiver\n", hmc, type); 2780 2732 2781 2733 /* a "gadget" abstracts/virtualizes the controller */ 2782 2734 status = omap_udc_setup(odev, xceiv); 2783 2735 if (status) { 2784 2736 goto cleanup0; 2785 2737 } 2786 - xceiv = 0; 2738 + xceiv = NULL; 2787 2739 // "udc" is now valid 2788 2740 pullup_disable(udc); 2789 2741 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) 2790 2742 udc->gadget.is_otg = (config->otg != 0); 2791 2743 #endif 2744 + 2745 + /* starting with omap1710 es2.0, clear toggle is a separate bit */ 2746 + if (UDC_REV_REG >= 0x61) 2747 + udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE; 2748 + else 2749 + udc->clr_halt = UDC_RESET_EP; 2792 2750 2793 2751 /* USB general purpose IRQ: ep0, state changes, dma, etc */ 2794 2752 status = request_irq(odev->resource[1].start, omap_udc_irq, ··· 2855 2765 2856 2766 cleanup1: 2857 2767 kfree (udc); 2858 - udc = 0; 2768 + udc = NULL; 2859 2769 2860 2770 cleanup0: 2861 2771 if (xceiv) ··· 2878 2788 pullup_disable(udc); 2879 2789 if (udc->transceiver) { 2880 2790 put_device(udc->transceiver->dev); 2881 - udc->transceiver = 0; 2791 + udc->transceiver = NULL; 2882 2792 } 2883 2793 UDC_SYSCON1_REG = 0; 2884 2794 ··· 2899 2809 return 0; 2900 2810 } 2901 2811 2902 - static int omap_udc_suspend(struct device *dev, pm_message_t state, u32 level) 2812 + /* suspend/resume/wakeup from sysfs (echo > power/state) or when the 2813 + * system is forced into deep sleep 2814 + * 2815 + * REVISIT we should probably reject suspend requests when there's a host 2816 + * session active, rather than disconnecting, at least on boards that can 2817 + * report VBUS irqs (UDC_DEVSTAT_REG.UDC_ATT). And in any case, we need to 2818 + * make host resumes and VBUS detection trigger OMAP wakeup events; that 2819 + * may involve talking to an external transceiver (e.g. isp1301). 2820 + */ 2821 + static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level) 2903 2822 { 2904 - if (level != 0) 2905 - return 0; 2823 + u32 devstat; 2906 2824 2907 - DBG("suspend, state %d\n", state); 2908 - omap_pullup(&udc->gadget, 0); 2825 + if (level != SUSPEND_POWER_DOWN) 2826 + return 0; 2827 + devstat = UDC_DEVSTAT_REG; 2828 + 2829 + /* we're requesting 48 MHz clock if the pullup is enabled 2830 + * (== we're attached to the host) and we're not suspended, 2831 + * which would prevent entry to deep sleep... 2832 + */ 2833 + if ((devstat & UDC_ATT) != 0 && (devstat & UDC_SUS) == 0) { 2834 + WARN("session active; suspend requires disconnect\n"); 2835 + omap_pullup(&udc->gadget, 0); 2836 + } 2837 + 2909 2838 udc->gadget.dev.power.power_state = PMSG_SUSPEND; 2910 2839 udc->gadget.dev.parent->power.power_state = PMSG_SUSPEND; 2911 2840 return 0; ··· 2932 2823 2933 2824 static int omap_udc_resume(struct device *dev, u32 level) 2934 2825 { 2935 - if (level != 0) 2826 + if (level != RESUME_POWER_ON) 2936 2827 return 0; 2937 2828 2938 2829 DBG("resume + wakeup/SRP\n");
+3 -1
drivers/usb/gadget/omap_udc.h
··· 20 20 #define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */ 21 21 # define UDC_CLR_HALT (1 << 7) 22 22 # define UDC_SET_HALT (1 << 6) 23 + # define UDC_CLRDATA_TOGGLE (1 << 3) 23 24 # define UDC_SET_FIFO_EN (1 << 2) 24 25 # define UDC_CLR_EP (1 << 1) 25 26 # define UDC_RESET_EP (1 << 0) ··· 100 99 101 100 /* DMA configuration registers: up to three channels in each direction. */ 102 101 #define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */ 102 + # define UDC_DMA_REQ (1 << 12) 103 103 #define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */ 104 104 #define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */ 105 105 ··· 164 162 spinlock_t lock; 165 163 struct omap_ep ep[32]; 166 164 u16 devstat; 165 + u16 clr_halt; 167 166 struct otg_transceiver *transceiver; 168 167 struct list_head iso; 169 168 unsigned softconnect:1; ··· 174 171 unsigned ep0_set_config:1; 175 172 unsigned ep0_reset_config:1; 176 173 unsigned ep0_setup:1; 177 - 178 174 struct completion *done; 179 175 }; 180 176
+27 -16
drivers/usb/gadget/pxa2xx_udc.c
··· 1 1 /* 2 2 * linux/drivers/usb/gadget/pxa2xx_udc.c 3 - * Intel PXA2xx and IXP4xx on-chip full speed USB device controllers 3 + * Intel PXA25x and IXP4xx on-chip full speed USB device controllers 4 4 * 5 5 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker) 6 6 * Copyright (C) 2003 Robert Schwebel, Pengutronix ··· 63 63 64 64 65 65 /* 66 - * This driver handles the USB Device Controller (UDC) in Intel's PXA 2xx 66 + * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x 67 67 * series processors. The UDC for the IXP 4xx series is very similar. 68 68 * There are fifteen endpoints, in addition to ep0. 69 69 * ··· 79 79 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there. 80 80 */ 81 81 82 - #define DRIVER_VERSION "14-Dec-2003" 83 - #define DRIVER_DESC "PXA 2xx USB Device Controller driver" 82 + #define DRIVER_VERSION "4-May-2005" 83 + #define DRIVER_DESC "PXA 25x USB Device Controller driver" 84 84 85 85 86 86 static const char driver_name [] = "pxa2xx_udc"; ··· 290 290 static int pxa2xx_ep_disable (struct usb_ep *_ep) 291 291 { 292 292 struct pxa2xx_ep *ep; 293 + unsigned long flags; 293 294 294 295 ep = container_of (_ep, struct pxa2xx_ep, ep); 295 296 if (!_ep || !ep->desc) { ··· 298 297 _ep ? ep->ep.name : NULL); 299 298 return -EINVAL; 300 299 } 300 + local_irq_save(flags); 301 + 301 302 nuke (ep, -ESHUTDOWN); 302 303 303 304 #ifdef USE_DMA ··· 316 313 ep->desc = NULL; 317 314 ep->stopped = 1; 318 315 316 + local_irq_restore(flags); 319 317 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name); 320 318 return 0; 321 319 } ··· 975 971 kick_dma(ep, req); 976 972 #endif 977 973 /* can the FIFO can satisfy the request immediately? */ 978 - } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0 979 - && (*ep->reg_udccs & UDCCS_BI_TFS) != 0 980 - && write_fifo(ep, req)) { 981 - req = NULL; 974 + } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) { 975 + if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0 976 + && write_fifo(ep, req)) 977 + req = NULL; 982 978 } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0 983 979 && read_fifo(ep, req)) { 984 980 req = NULL; ··· 1294 1290 "%s version: %s\nGadget driver: %s\nHost %s\n\n", 1295 1291 driver_name, DRIVER_VERSION SIZE_STR DMASTR, 1296 1292 dev->driver ? dev->driver->driver.name : "(none)", 1297 - is_usb_connected() ? "full speed" : "disconnected"); 1293 + is_vbus_present() ? "full speed" : "disconnected"); 1298 1294 size -= t; 1299 1295 next += t; 1300 1296 ··· 1343 1339 next += t; 1344 1340 } 1345 1341 1346 - if (!is_usb_connected() || !dev->driver) 1342 + if (!is_vbus_present() || !dev->driver) 1347 1343 goto done; 1348 1344 1349 1345 t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n", ··· 1458 1454 UFNRH = UFNRH_SIM; 1459 1455 1460 1456 /* if hardware supports it, disconnect from usb */ 1461 - make_usb_disappear(); 1457 + pullup_off(); 1462 1458 1463 1459 udc_clear_mask_UDCCR(UDCCR_UDE); 1464 1460 ··· 1571 1567 UICR0 &= ~UICR0_IM0; 1572 1568 1573 1569 /* if hardware supports it, pullup D+ and wait for reset */ 1574 - let_usb_appear(); 1570 + pullup_on(); 1575 1571 } 1576 1572 1577 1573 ··· 2056 2052 if (unlikely(udccr & UDCCR_SUSIR)) { 2057 2053 udc_ack_int_UDCCR(UDCCR_SUSIR); 2058 2054 handled = 1; 2059 - DBG(DBG_VERBOSE, "USB suspend%s\n", is_usb_connected() 2055 + DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present() 2060 2056 ? "" : "+disconnect"); 2061 2057 2062 - if (!is_usb_connected()) 2058 + if (!is_vbus_present()) 2063 2059 stop_activity(dev, dev->driver); 2064 2060 else if (dev->gadget.speed != USB_SPEED_UNKNOWN 2065 2061 && dev->driver ··· 2077 2073 if (dev->gadget.speed != USB_SPEED_UNKNOWN 2078 2074 && dev->driver 2079 2075 && dev->driver->resume 2080 - && is_usb_connected()) 2076 + && is_vbus_present()) 2081 2077 dev->driver->resume(&dev->gadget); 2082 2078 } 2083 2079 ··· 2513 2509 udc_disable(dev); 2514 2510 udc_reinit(dev); 2515 2511 2516 - dev->vbus = is_usb_connected(); 2512 + dev->vbus = is_vbus_present(); 2517 2513 2518 2514 /* irq setup after old hardware state is cleaned up */ 2519 2515 retval = request_irq(IRQ_USB, pxa2xx_udc_irq, ··· 2559 2555 2560 2556 return 0; 2561 2557 } 2558 + 2559 + static void pxa2xx_udc_shutdown(struct device *_dev) 2560 + { 2561 + pullup_off(); 2562 + } 2563 + 2562 2564 static int __exit pxa2xx_udc_remove(struct device *_dev) 2563 2565 { 2564 2566 struct pxa2xx_udc *dev = dev_get_drvdata(_dev); ··· 2634 2624 .name = "pxa2xx-udc", 2635 2625 .bus = &platform_bus_type, 2636 2626 .probe = pxa2xx_udc_probe, 2627 + .shutdown = pxa2xx_udc_shutdown, 2637 2628 .remove = __exit_p(pxa2xx_udc_remove), 2638 2629 .suspend = pxa2xx_udc_suspend, 2639 2630 .resume = pxa2xx_udc_resume,
+5 -5
drivers/usb/gadget/pxa2xx_udc.h
··· 177 177 178 178 static struct pxa2xx_udc *the_controller; 179 179 180 - /* one GPIO should be used to detect host disconnect */ 181 - static inline int is_usb_connected(void) 180 + /* one GPIO should be used to detect VBUS from the host */ 181 + static inline int is_vbus_present(void) 182 182 { 183 183 if (!the_controller->mach->udc_is_connected) 184 184 return 1; 185 185 return the_controller->mach->udc_is_connected(); 186 186 } 187 187 188 - /* one GPIO should force the host to see this device (or not) */ 189 - static inline void make_usb_disappear(void) 188 + /* one GPIO should control a D+ pullup, so host sees this device (or not) */ 189 + static inline void pullup_off(void) 190 190 { 191 191 if (!the_controller->mach->udc_command) 192 192 return; 193 193 the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 194 194 } 195 195 196 - static inline void let_usb_appear(void) 196 + static inline void pullup_on(void) 197 197 { 198 198 if (!the_controller->mach->udc_command) 199 199 return;
+269 -246
drivers/usb/gadget/rndis.c
··· 41 41 42 42 43 43 #undef RNDIS_PM 44 + #undef RNDIS_WAKEUP 44 45 #undef VERBOSE 45 46 46 47 #include "rndis.h" ··· 61 60 } while (0) 62 61 static int rndis_debug = 0; 63 62 64 - module_param (rndis_debug, bool, 0); 63 + module_param (rndis_debug, int, 0); 65 64 MODULE_PARM_DESC (rndis_debug, "enable debugging"); 66 65 67 66 #else ··· 79 78 static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1); 80 79 81 80 /* Function Prototypes */ 82 - static int rndis_init_response (int configNr, rndis_init_msg_type *buf); 83 - static int rndis_query_response (int configNr, rndis_query_msg_type *buf); 84 - static int rndis_set_response (int configNr, rndis_set_msg_type *buf); 85 - static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf); 86 - static int rndis_keepalive_response (int configNr, 87 - rndis_keepalive_msg_type *buf); 88 - 89 81 static rndis_resp_t *rndis_add_response (int configNr, u32 length); 90 82 91 83 84 + /* supported OIDs */ 85 + static const u32 oid_supported_list [] = 86 + { 87 + /* the general stuff */ 88 + OID_GEN_SUPPORTED_LIST, 89 + OID_GEN_HARDWARE_STATUS, 90 + OID_GEN_MEDIA_SUPPORTED, 91 + OID_GEN_MEDIA_IN_USE, 92 + OID_GEN_MAXIMUM_FRAME_SIZE, 93 + OID_GEN_LINK_SPEED, 94 + OID_GEN_TRANSMIT_BLOCK_SIZE, 95 + OID_GEN_RECEIVE_BLOCK_SIZE, 96 + OID_GEN_VENDOR_ID, 97 + OID_GEN_VENDOR_DESCRIPTION, 98 + OID_GEN_VENDOR_DRIVER_VERSION, 99 + OID_GEN_CURRENT_PACKET_FILTER, 100 + OID_GEN_MAXIMUM_TOTAL_SIZE, 101 + OID_GEN_MEDIA_CONNECT_STATUS, 102 + OID_GEN_PHYSICAL_MEDIUM, 103 + #if 0 104 + OID_GEN_RNDIS_CONFIG_PARAMETER, 105 + #endif 106 + 107 + /* the statistical stuff */ 108 + OID_GEN_XMIT_OK, 109 + OID_GEN_RCV_OK, 110 + OID_GEN_XMIT_ERROR, 111 + OID_GEN_RCV_ERROR, 112 + OID_GEN_RCV_NO_BUFFER, 113 + #ifdef RNDIS_OPTIONAL_STATS 114 + OID_GEN_DIRECTED_BYTES_XMIT, 115 + OID_GEN_DIRECTED_FRAMES_XMIT, 116 + OID_GEN_MULTICAST_BYTES_XMIT, 117 + OID_GEN_MULTICAST_FRAMES_XMIT, 118 + OID_GEN_BROADCAST_BYTES_XMIT, 119 + OID_GEN_BROADCAST_FRAMES_XMIT, 120 + OID_GEN_DIRECTED_BYTES_RCV, 121 + OID_GEN_DIRECTED_FRAMES_RCV, 122 + OID_GEN_MULTICAST_BYTES_RCV, 123 + OID_GEN_MULTICAST_FRAMES_RCV, 124 + OID_GEN_BROADCAST_BYTES_RCV, 125 + OID_GEN_BROADCAST_FRAMES_RCV, 126 + OID_GEN_RCV_CRC_ERROR, 127 + OID_GEN_TRANSMIT_QUEUE_LENGTH, 128 + #endif /* RNDIS_OPTIONAL_STATS */ 129 + 130 + /* mandatory 802.3 */ 131 + /* the general stuff */ 132 + OID_802_3_PERMANENT_ADDRESS, 133 + OID_802_3_CURRENT_ADDRESS, 134 + OID_802_3_MULTICAST_LIST, 135 + OID_802_3_MAC_OPTIONS, 136 + OID_802_3_MAXIMUM_LIST_SIZE, 137 + 138 + /* the statistical stuff */ 139 + OID_802_3_RCV_ERROR_ALIGNMENT, 140 + OID_802_3_XMIT_ONE_COLLISION, 141 + OID_802_3_XMIT_MORE_COLLISIONS, 142 + #ifdef RNDIS_OPTIONAL_STATS 143 + OID_802_3_XMIT_DEFERRED, 144 + OID_802_3_XMIT_MAX_COLLISIONS, 145 + OID_802_3_RCV_OVERRUN, 146 + OID_802_3_XMIT_UNDERRUN, 147 + OID_802_3_XMIT_HEARTBEAT_FAILURE, 148 + OID_802_3_XMIT_TIMES_CRS_LOST, 149 + OID_802_3_XMIT_LATE_COLLISIONS, 150 + #endif /* RNDIS_OPTIONAL_STATS */ 151 + 152 + #ifdef RNDIS_PM 153 + /* PM and wakeup are mandatory for USB: */ 154 + 155 + /* power management */ 156 + OID_PNP_CAPABILITIES, 157 + OID_PNP_QUERY_POWER, 158 + OID_PNP_SET_POWER, 159 + 160 + #ifdef RNDIS_WAKEUP 161 + /* wake up host */ 162 + OID_PNP_ENABLE_WAKE_UP, 163 + OID_PNP_ADD_WAKE_UP_PATTERN, 164 + OID_PNP_REMOVE_WAKE_UP_PATTERN, 165 + #endif /* RNDIS_WAKEUP */ 166 + #endif /* RNDIS_PM */ 167 + }; 168 + 169 + 92 170 /* NDIS Functions */ 93 - static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r) 171 + static int 172 + gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, 173 + rndis_resp_t *r) 94 174 { 95 175 int retval = -ENOTSUPP; 96 - u32 length = 0; 97 - __le32 *tmp; 176 + u32 length = 4; /* usually */ 177 + __le32 *outbuf; 98 178 int i, count; 99 179 rndis_query_cmplt_type *resp; 100 180 ··· 183 101 resp = (rndis_query_cmplt_type *) r->buf; 184 102 185 103 if (!resp) return -ENOMEM; 186 - 104 + 105 + if (buf_len && rndis_debug > 1) { 106 + DEBUG("query OID %08x value, len %d:\n", OID, buf_len); 107 + for (i = 0; i < buf_len; i += 16) { 108 + DEBUG ("%03d: %08x %08x %08x %08x\n", i, 109 + le32_to_cpup((__le32 *)&buf[i]), 110 + le32_to_cpup((__le32 *)&buf[i + 4]), 111 + le32_to_cpup((__le32 *)&buf[i + 8]), 112 + le32_to_cpup((__le32 *)&buf[i + 12])); 113 + } 114 + } 115 + 116 + /* response goes here, right after the header */ 117 + outbuf = (__le32 *) &resp[1]; 118 + resp->InformationBufferOffset = __constant_cpu_to_le32 (16); 119 + 187 120 switch (OID) { 188 121 189 122 /* general oids (table 4-1) */ ··· 208 111 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__); 209 112 length = sizeof (oid_supported_list); 210 113 count = length / sizeof (u32); 211 - tmp = (__le32 *) ((u8 *)resp + 24); 212 114 for (i = 0; i < count; i++) 213 - tmp[i] = cpu_to_le32 (oid_supported_list[i]); 115 + outbuf[i] = cpu_to_le32 (oid_supported_list[i]); 214 116 retval = 0; 215 117 break; 216 118 217 119 /* mandatory */ 218 120 case OID_GEN_HARDWARE_STATUS: 219 121 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__); 220 - length = 4; 221 122 /* Bogus question! 222 123 * Hardware must be ready to receive high level protocols. 223 124 * BTW: 224 125 * reddite ergo quae sunt Caesaris Caesari 225 126 * et quae sunt Dei Deo! 226 127 */ 227 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 128 + *outbuf = __constant_cpu_to_le32 (0); 228 129 retval = 0; 229 130 break; 230 131 231 132 /* mandatory */ 232 133 case OID_GEN_MEDIA_SUPPORTED: 233 134 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__); 234 - length = 4; 235 - *((__le32 *) resp + 6) = cpu_to_le32 ( 236 - rndis_per_dev_params [configNr].medium); 135 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 237 136 retval = 0; 238 137 break; 239 138 240 139 /* mandatory */ 241 140 case OID_GEN_MEDIA_IN_USE: 242 141 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__); 243 - length = 4; 244 142 /* one medium, one transport... (maybe you do it better) */ 245 - *((__le32 *) resp + 6) = cpu_to_le32 ( 246 - rndis_per_dev_params [configNr].medium); 143 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 247 144 retval = 0; 248 145 break; 249 146 ··· 245 154 case OID_GEN_MAXIMUM_FRAME_SIZE: 246 155 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__); 247 156 if (rndis_per_dev_params [configNr].dev) { 248 - length = 4; 249 - *((__le32 *) resp + 6) = cpu_to_le32 ( 157 + *outbuf = cpu_to_le32 ( 250 158 rndis_per_dev_params [configNr].dev->mtu); 251 - retval = 0; 252 - } else { 253 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 254 159 retval = 0; 255 160 } 256 161 break; 257 162 258 163 /* mandatory */ 259 164 case OID_GEN_LINK_SPEED: 260 - // DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 261 - length = 4; 165 + if (rndis_debug > 1) 166 + DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 262 167 if (rndis_per_dev_params [configNr].media_state 263 - == NDIS_MEDIA_STATE_DISCONNECTED) 264 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 168 + == NDIS_MEDIA_STATE_DISCONNECTED) 169 + *outbuf = __constant_cpu_to_le32 (0); 265 170 else 266 - *((__le32 *) resp + 6) = cpu_to_le32 ( 171 + *outbuf = cpu_to_le32 ( 267 172 rndis_per_dev_params [configNr].speed); 268 173 retval = 0; 269 174 break; ··· 268 181 case OID_GEN_TRANSMIT_BLOCK_SIZE: 269 182 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__); 270 183 if (rndis_per_dev_params [configNr].dev) { 271 - length = 4; 272 - *((__le32 *) resp + 6) = cpu_to_le32 ( 184 + *outbuf = cpu_to_le32 ( 273 185 rndis_per_dev_params [configNr].dev->mtu); 274 186 retval = 0; 275 187 } ··· 278 192 case OID_GEN_RECEIVE_BLOCK_SIZE: 279 193 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__); 280 194 if (rndis_per_dev_params [configNr].dev) { 281 - length = 4; 282 - *((__le32 *) resp + 6) = cpu_to_le32 ( 195 + *outbuf = cpu_to_le32 ( 283 196 rndis_per_dev_params [configNr].dev->mtu); 284 197 retval = 0; 285 198 } ··· 287 202 /* mandatory */ 288 203 case OID_GEN_VENDOR_ID: 289 204 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__); 290 - length = 4; 291 - *((__le32 *) resp + 6) = cpu_to_le32 ( 205 + *outbuf = cpu_to_le32 ( 292 206 rndis_per_dev_params [configNr].vendorID); 293 207 retval = 0; 294 208 break; ··· 296 212 case OID_GEN_VENDOR_DESCRIPTION: 297 213 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__); 298 214 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 299 - memcpy ((u8 *) resp + 24, 215 + memcpy (outbuf, 300 216 rndis_per_dev_params [configNr].vendorDescr, length); 301 217 retval = 0; 302 218 break; 303 219 304 220 case OID_GEN_VENDOR_DRIVER_VERSION: 305 221 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__); 306 - length = 4; 307 222 /* Created as LE */ 308 - *((__le32 *) resp + 6) = rndis_driver_version; 223 + *outbuf = rndis_driver_version; 309 224 retval = 0; 310 225 break; 311 226 312 227 /* mandatory */ 313 228 case OID_GEN_CURRENT_PACKET_FILTER: 314 229 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__); 315 - length = 4; 316 - *((__le32 *) resp + 6) = cpu_to_le32 ( 317 - rndis_per_dev_params[configNr].filter); 230 + *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); 318 231 retval = 0; 319 232 break; 320 233 321 234 /* mandatory */ 322 235 case OID_GEN_MAXIMUM_TOTAL_SIZE: 323 236 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__); 324 - length = 4; 325 - *((__le32 *) resp + 6) = __constant_cpu_to_le32( 326 - RNDIS_MAX_TOTAL_SIZE); 237 + *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); 327 238 retval = 0; 328 239 break; 329 240 330 241 /* mandatory */ 331 242 case OID_GEN_MEDIA_CONNECT_STATUS: 332 - DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 333 - length = 4; 334 - *((__le32 *) resp + 6) = cpu_to_le32 ( 335 - rndis_per_dev_params [configNr] 243 + if (rndis_debug > 1) 244 + DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 245 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 336 246 .media_state); 337 247 retval = 0; 338 248 break; 339 249 340 250 case OID_GEN_PHYSICAL_MEDIUM: 341 251 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__); 342 - length = 4; 343 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 252 + *outbuf = __constant_cpu_to_le32 (0); 344 253 retval = 0; 345 254 break; 346 255 ··· 343 266 */ 344 267 case OID_GEN_MAC_OPTIONS: /* from WinME */ 345 268 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__); 346 - length = 4; 347 - *((__le32 *) resp + 6) = __constant_cpu_to_le32( 269 + *outbuf = __constant_cpu_to_le32( 348 270 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 349 271 | NDIS_MAC_OPTION_FULL_DUPLEX); 350 272 retval = 0; ··· 353 277 354 278 /* mandatory */ 355 279 case OID_GEN_XMIT_OK: 356 - DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 280 + if (rndis_debug > 1) 281 + DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 357 282 if (rndis_per_dev_params [configNr].stats) { 358 - length = 4; 359 - *((__le32 *) resp + 6) = cpu_to_le32 ( 283 + *outbuf = cpu_to_le32 ( 360 284 rndis_per_dev_params [configNr].stats->tx_packets - 361 285 rndis_per_dev_params [configNr].stats->tx_errors - 362 286 rndis_per_dev_params [configNr].stats->tx_dropped); 363 - retval = 0; 364 - } else { 365 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 366 287 retval = 0; 367 288 } 368 289 break; 369 290 370 291 /* mandatory */ 371 292 case OID_GEN_RCV_OK: 372 - DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 293 + if (rndis_debug > 1) 294 + DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 373 295 if (rndis_per_dev_params [configNr].stats) { 374 - length = 4; 375 - *((__le32 *) resp + 6) = cpu_to_le32 ( 296 + *outbuf = cpu_to_le32 ( 376 297 rndis_per_dev_params [configNr].stats->rx_packets - 377 298 rndis_per_dev_params [configNr].stats->rx_errors - 378 299 rndis_per_dev_params [configNr].stats->rx_dropped); 379 - retval = 0; 380 - } else { 381 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 382 300 retval = 0; 383 301 } 384 302 break; 385 303 386 304 /* mandatory */ 387 305 case OID_GEN_XMIT_ERROR: 388 - DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 306 + if (rndis_debug > 1) 307 + DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 389 308 if (rndis_per_dev_params [configNr].stats) { 390 - length = 4; 391 - *((__le32 *) resp + 6) = cpu_to_le32 ( 392 - rndis_per_dev_params [configNr] 309 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 393 310 .stats->tx_errors); 394 - retval = 0; 395 - } else { 396 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 397 311 retval = 0; 398 312 } 399 313 break; 400 314 401 315 /* mandatory */ 402 316 case OID_GEN_RCV_ERROR: 403 - DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 317 + if (rndis_debug > 1) 318 + DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 404 319 if (rndis_per_dev_params [configNr].stats) { 405 - *((__le32 *) resp + 6) = cpu_to_le32 ( 406 - rndis_per_dev_params [configNr] 320 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 407 321 .stats->rx_errors); 408 - retval = 0; 409 - } else { 410 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 411 322 retval = 0; 412 323 } 413 324 break; ··· 403 340 case OID_GEN_RCV_NO_BUFFER: 404 341 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__); 405 342 if (rndis_per_dev_params [configNr].stats) { 406 - *((__le32 *) resp + 6) = cpu_to_le32 ( 407 - rndis_per_dev_params [configNr] 343 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 408 344 .stats->rx_dropped); 409 - retval = 0; 410 - } else { 411 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 412 345 retval = 0; 413 346 } 414 347 break; ··· 418 359 * divided by weight of Alpha Centauri 419 360 */ 420 361 if (rndis_per_dev_params [configNr].stats) { 421 - length = 4; 422 - *((__le32 *) resp + 6) = cpu_to_le32 ( 362 + *outbuf = cpu_to_le32 ( 423 363 (rndis_per_dev_params [configNr] 424 364 .stats->tx_packets - 425 365 rndis_per_dev_params [configNr] ··· 427 369 .stats->tx_dropped) 428 370 * 123); 429 371 retval = 0; 430 - } else { 431 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 432 - retval = 0; 433 372 } 434 373 break; 435 374 ··· 434 379 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__); 435 380 /* dito */ 436 381 if (rndis_per_dev_params [configNr].stats) { 437 - length = 4; 438 - *((__le32 *) resp + 6) = cpu_to_le32 ( 382 + *outbuf = cpu_to_le32 ( 439 383 (rndis_per_dev_params [configNr] 440 384 .stats->tx_packets - 441 385 rndis_per_dev_params [configNr] ··· 443 389 .stats->tx_dropped) 444 390 / 123); 445 391 retval = 0; 446 - } else { 447 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 448 - retval = 0; 449 392 } 450 393 break; 451 394 452 395 case OID_GEN_MULTICAST_BYTES_XMIT: 453 396 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__); 454 397 if (rndis_per_dev_params [configNr].stats) { 455 - *((__le32 *) resp + 6) = cpu_to_le32 ( 456 - rndis_per_dev_params [configNr] 398 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 457 399 .stats->multicast*1234); 458 - retval = 0; 459 - } else { 460 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 461 400 retval = 0; 462 401 } 463 402 break; ··· 458 411 case OID_GEN_MULTICAST_FRAMES_XMIT: 459 412 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__); 460 413 if (rndis_per_dev_params [configNr].stats) { 461 - *((__le32 *) resp + 6) = cpu_to_le32 ( 462 - rndis_per_dev_params [configNr] 414 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 463 415 .stats->multicast); 464 - retval = 0; 465 - } else { 466 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 467 416 retval = 0; 468 417 } 469 418 break; ··· 467 424 case OID_GEN_BROADCAST_BYTES_XMIT: 468 425 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__); 469 426 if (rndis_per_dev_params [configNr].stats) { 470 - *((__le32 *) resp + 6) = cpu_to_le32 ( 471 - rndis_per_dev_params [configNr] 427 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 472 428 .stats->tx_packets/42*255); 473 - retval = 0; 474 - } else { 475 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 476 429 retval = 0; 477 430 } 478 431 break; ··· 476 437 case OID_GEN_BROADCAST_FRAMES_XMIT: 477 438 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__); 478 439 if (rndis_per_dev_params [configNr].stats) { 479 - *((__le32 *) resp + 6) = cpu_to_le32 ( 480 - rndis_per_dev_params [configNr] 440 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 481 441 .stats->tx_packets/42); 482 - retval = 0; 483 - } else { 484 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 485 442 retval = 0; 486 443 } 487 444 break; 488 445 489 446 case OID_GEN_DIRECTED_BYTES_RCV: 490 447 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__); 491 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 448 + *outbuf = __constant_cpu_to_le32 (0); 492 449 retval = 0; 493 450 break; 494 451 495 452 case OID_GEN_DIRECTED_FRAMES_RCV: 496 453 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__); 497 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 454 + *outbuf = __constant_cpu_to_le32 (0); 498 455 retval = 0; 499 456 break; 500 457 501 458 case OID_GEN_MULTICAST_BYTES_RCV: 502 459 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__); 503 460 if (rndis_per_dev_params [configNr].stats) { 504 - *((__le32 *) resp + 6) = cpu_to_le32 ( 505 - rndis_per_dev_params [configNr] 461 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 506 462 .stats->multicast * 1111); 507 - retval = 0; 508 - } else { 509 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 510 463 retval = 0; 511 464 } 512 465 break; ··· 506 475 case OID_GEN_MULTICAST_FRAMES_RCV: 507 476 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__); 508 477 if (rndis_per_dev_params [configNr].stats) { 509 - *((__le32 *) resp + 6) = cpu_to_le32 ( 510 - rndis_per_dev_params [configNr] 478 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 511 479 .stats->multicast); 512 - retval = 0; 513 - } else { 514 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 515 480 retval = 0; 516 481 } 517 482 break; ··· 515 488 case OID_GEN_BROADCAST_BYTES_RCV: 516 489 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__); 517 490 if (rndis_per_dev_params [configNr].stats) { 518 - *((__le32 *) resp + 6) = cpu_to_le32 ( 519 - rndis_per_dev_params [configNr] 491 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 520 492 .stats->rx_packets/42*255); 521 - retval = 0; 522 - } else { 523 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 524 493 retval = 0; 525 494 } 526 495 break; ··· 524 501 case OID_GEN_BROADCAST_FRAMES_RCV: 525 502 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__); 526 503 if (rndis_per_dev_params [configNr].stats) { 527 - *((__le32 *) resp + 6) = cpu_to_le32 ( 528 - rndis_per_dev_params [configNr] 504 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 529 505 .stats->rx_packets/42); 530 - retval = 0; 531 - } else { 532 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 533 506 retval = 0; 534 507 } 535 508 break; ··· 533 514 case OID_GEN_RCV_CRC_ERROR: 534 515 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__); 535 516 if (rndis_per_dev_params [configNr].stats) { 536 - *((__le32 *) resp + 6) = cpu_to_le32 ( 537 - rndis_per_dev_params [configNr] 517 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 538 518 .stats->rx_crc_errors); 539 - retval = 0; 540 - } else { 541 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 542 519 retval = 0; 543 520 } 544 521 break; 545 522 546 523 case OID_GEN_TRANSMIT_QUEUE_LENGTH: 547 524 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__); 548 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 525 + *outbuf = __constant_cpu_to_le32 (0); 549 526 retval = 0; 550 527 break; 551 528 #endif /* RNDIS_OPTIONAL_STATS */ ··· 553 538 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__); 554 539 if (rndis_per_dev_params [configNr].dev) { 555 540 length = ETH_ALEN; 556 - memcpy ((u8 *) resp + 24, 541 + memcpy (outbuf, 557 542 rndis_per_dev_params [configNr].host_mac, 558 543 length); 559 - retval = 0; 560 - } else { 561 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 562 544 retval = 0; 563 545 } 564 546 break; ··· 565 553 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__); 566 554 if (rndis_per_dev_params [configNr].dev) { 567 555 length = ETH_ALEN; 568 - memcpy ((u8 *) resp + 24, 556 + memcpy (outbuf, 569 557 rndis_per_dev_params [configNr].host_mac, 570 558 length); 571 559 retval = 0; ··· 575 563 /* mandatory */ 576 564 case OID_802_3_MULTICAST_LIST: 577 565 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 578 - length = 4; 579 566 /* Multicast base address only */ 580 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0xE0000000); 567 + *outbuf = __constant_cpu_to_le32 (0xE0000000); 581 568 retval = 0; 582 569 break; 583 570 584 571 /* mandatory */ 585 572 case OID_802_3_MAXIMUM_LIST_SIZE: 586 573 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__); 587 - length = 4; 588 574 /* Multicast base address only */ 589 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (1); 575 + *outbuf = __constant_cpu_to_le32 (1); 590 576 retval = 0; 591 577 break; 592 578 ··· 597 587 /* mandatory */ 598 588 case OID_802_3_RCV_ERROR_ALIGNMENT: 599 589 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__); 600 - if (rndis_per_dev_params [configNr].stats) 601 - { 602 - length = 4; 603 - *((__le32 *) resp + 6) = cpu_to_le32 ( 604 - rndis_per_dev_params [configNr] 590 + if (rndis_per_dev_params [configNr].stats) { 591 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 605 592 .stats->rx_frame_errors); 606 593 retval = 0; 607 594 } ··· 607 600 /* mandatory */ 608 601 case OID_802_3_XMIT_ONE_COLLISION: 609 602 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__); 610 - length = 4; 611 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 603 + *outbuf = __constant_cpu_to_le32 (0); 612 604 retval = 0; 613 605 break; 614 606 615 607 /* mandatory */ 616 608 case OID_802_3_XMIT_MORE_COLLISIONS: 617 609 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__); 618 - length = 4; 619 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 610 + *outbuf = __constant_cpu_to_le32 (0); 620 611 retval = 0; 621 612 break; 622 613 ··· 660 655 case OID_PNP_CAPABILITIES: 661 656 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__); 662 657 663 - /* just PM, and remote wakeup on link status change 664 - * (not magic packet or pattern match) 665 - */ 658 + /* for now, no wakeup capabilities */ 666 659 length = sizeof (struct NDIS_PNP_CAPABILITIES); 667 - memset (resp, 0, length); 668 - { 669 - struct NDIS_PNP_CAPABILITIES *caps = (void *) resp; 670 - 671 - caps->Flags = NDIS_DEVICE_WAKE_UP_ENABLE; 672 - caps->WakeUpCapabilities.MinLinkChangeWakeUp 673 - = NdisDeviceStateD3; 674 - 675 - /* FIXME then use usb_gadget_wakeup(), and 676 - * set USB_CONFIG_ATT_WAKEUP in config desc 677 - */ 678 - } 660 + memset(outbuf, 0, length); 679 661 retval = 0; 680 662 break; 681 663 case OID_PNP_QUERY_POWER: 682 - DEBUG("%s: OID_PNP_QUERY_POWER\n", __FUNCTION__); 683 - /* sure, handle any power state that maps to USB suspend */ 664 + DEBUG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__, 665 + le32_to_cpup((__le32 *) buf) - 1); 666 + /* only suspend is a real power state, and 667 + * it can't be entered by OID_PNP_SET_POWER... 668 + */ 669 + length = 0; 684 670 retval = 0; 685 671 break; 686 672 #endif ··· 680 684 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", 681 685 __FUNCTION__, OID); 682 686 } 687 + if (retval < 0) 688 + length = 0; 683 689 684 - resp->InformationBufferOffset = __constant_cpu_to_le32 (16); 685 690 resp->InformationBufferLength = cpu_to_le32 (length); 686 - resp->MessageLength = cpu_to_le32 (24 + length); 687 - r->length = 24 + length; 691 + r->length = length + sizeof *resp; 692 + resp->MessageLength = cpu_to_le32 (r->length); 688 693 return retval; 689 694 } 690 695 ··· 702 705 if (!resp) 703 706 return -ENOMEM; 704 707 705 - DEBUG("set OID %08x value, len %d:\n", OID, buf_len); 706 - for (i = 0; i < buf_len; i += 16) { 707 - DEBUG ("%03d: " 708 - " %02x %02x %02x %02x" 709 - " %02x %02x %02x %02x" 710 - " %02x %02x %02x %02x" 711 - " %02x %02x %02x %02x" 712 - "\n", 713 - i, 714 - buf[i], buf [i+1], 715 - buf[i+2], buf[i+3], 716 - buf[i+4], buf [i+5], 717 - buf[i+6], buf[i+7], 718 - buf[i+8], buf [i+9], 719 - buf[i+10], buf[i+11], 720 - buf[i+12], buf [i+13], 721 - buf[i+14], buf[i+15]); 708 + if (buf_len && rndis_debug > 1) { 709 + DEBUG("set OID %08x value, len %d:\n", OID, buf_len); 710 + for (i = 0; i < buf_len; i += 16) { 711 + DEBUG ("%03d: %08x %08x %08x %08x\n", i, 712 + le32_to_cpup((__le32 *)&buf[i]), 713 + le32_to_cpup((__le32 *)&buf[i + 4]), 714 + le32_to_cpup((__le32 *)&buf[i + 8]), 715 + le32_to_cpup((__le32 *)&buf[i + 12])); 716 + } 722 717 } 723 718 719 + params = &rndis_per_dev_params [configNr]; 724 720 switch (OID) { 725 721 case OID_GEN_CURRENT_PACKET_FILTER: 726 - params = &rndis_per_dev_params [configNr]; 727 - retval = 0; 728 722 729 - /* FIXME use these NDIS_PACKET_TYPE_* bitflags to 730 - * set the cdc_filter; it's not RNDIS-specific 723 + /* these NDIS_PACKET_TYPE_* bitflags are shared with 724 + * cdc_filter; it's not RNDIS-specific 731 725 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in: 732 726 * PROMISCUOUS, DIRECTED, 733 727 * MULTICAST, ALL_MULTICAST, BROADCAST 734 728 */ 735 - params->filter = le32_to_cpup((__le32 *)buf); 729 + *params->filter = (u16) le32_to_cpup((__le32 *)buf); 736 730 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", 737 - __FUNCTION__, params->filter); 731 + __FUNCTION__, *params->filter); 738 732 739 733 /* this call has a significant side effect: it's 740 734 * what makes the packet flow start and stop, like 741 735 * activating the CDC Ethernet altsetting. 742 736 */ 743 - if (params->filter) { 737 + #ifdef RNDIS_PM 738 + update_linkstate: 739 + #endif 740 + retval = 0; 741 + if (*params->filter) { 744 742 params->state = RNDIS_DATA_INITIALIZED; 745 743 netif_carrier_on(params->dev); 746 744 if (netif_running(params->dev)) ··· 768 776 769 777 #ifdef RNDIS_PM 770 778 case OID_PNP_SET_POWER: 771 - DEBUG ("OID_PNP_SET_POWER\n"); 772 - /* sure, handle any power state that maps to USB suspend */ 773 - retval = 0; 779 + /* The only real power state is USB suspend, and RNDIS requests 780 + * can't enter it; this one isn't really about power. After 781 + * resuming, Windows forces a reset, and then SET_POWER D0. 782 + * FIXME ... then things go batty; Windows wedges itself. 783 + */ 784 + i = le32_to_cpup((__force __le32 *)buf); 785 + DEBUG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1); 786 + switch (i) { 787 + case NdisDeviceStateD0: 788 + *params->filter = params->saved_filter; 789 + goto update_linkstate; 790 + case NdisDeviceStateD3: 791 + case NdisDeviceStateD2: 792 + case NdisDeviceStateD1: 793 + params->saved_filter = *params->filter; 794 + retval = 0; 795 + break; 796 + } 774 797 break; 775 798 776 - case OID_PNP_ENABLE_WAKE_UP: 777 - /* always-connected ... */ 778 - DEBUG ("OID_PNP_ENABLE_WAKE_UP\n"); 779 - retval = 0; 780 - break; 781 - 782 - // no PM resume patterns supported (specified where?) 783 - // so OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN always fails 799 + #ifdef RNDIS_WAKEUP 800 + // no wakeup support advertised, so wakeup OIDs always fail: 801 + // - OID_PNP_ENABLE_WAKE_UP 802 + // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN 784 803 #endif 804 + 805 + #endif /* RNDIS_PM */ 785 806 786 807 default: 787 808 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n", ··· 816 811 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 817 812 818 813 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); 819 - 820 - if (!r) return -ENOMEM; 821 - 814 + if (!r) 815 + return -ENOMEM; 822 816 resp = (rndis_init_cmplt_type *) r->buf; 823 - 824 - if (!resp) return -ENOMEM; 825 817 826 818 resp->MessageType = __constant_cpu_to_le32 ( 827 819 REMOTE_NDIS_INITIALIZE_CMPLT); ··· 859 857 * oid_supported_list is the largest answer 860 858 */ 861 859 r = rndis_add_response (configNr, sizeof (oid_supported_list)); 862 - 863 - if (!r) return -ENOMEM; 860 + if (!r) 861 + return -ENOMEM; 864 862 resp = (rndis_query_cmplt_type *) r->buf; 865 863 866 - if (!resp) return -ENOMEM; 867 - 868 864 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); 869 - resp->MessageLength = __constant_cpu_to_le32 (24); 870 865 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 871 - 872 - if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), r)) { 866 + 867 + if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), 868 + le32_to_cpu(buf->InformationBufferOffset) 869 + + 8 + (u8 *) buf, 870 + le32_to_cpu(buf->InformationBufferLength), 871 + r)) { 873 872 /* OID not supported */ 874 873 resp->Status = __constant_cpu_to_le32 ( 875 874 RNDIS_STATUS_NOT_SUPPORTED); 875 + resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp); 876 876 resp->InformationBufferLength = __constant_cpu_to_le32 (0); 877 877 resp->InformationBufferOffset = __constant_cpu_to_le32 (0); 878 878 } else ··· 893 889 rndis_resp_t *r; 894 890 895 891 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); 896 - 897 - if (!r) return -ENOMEM; 892 + if (!r) 893 + return -ENOMEM; 898 894 resp = (rndis_set_cmplt_type *) r->buf; 899 - if (!resp) return -ENOMEM; 900 895 901 896 BufLength = le32_to_cpu (buf->InformationBufferLength); 902 897 BufOffset = le32_to_cpu (buf->InformationBufferOffset); ··· 933 930 rndis_resp_t *r; 934 931 935 932 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); 936 - 937 - if (!r) return -ENOMEM; 933 + if (!r) 934 + return -ENOMEM; 938 935 resp = (rndis_reset_cmplt_type *) r->buf; 939 - if (!resp) return -ENOMEM; 940 936 941 937 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); 942 938 resp->MessageLength = __constant_cpu_to_le32 (16); ··· 959 957 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 960 958 961 959 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); 960 + if (!r) 961 + return -ENOMEM; 962 962 resp = (rndis_keepalive_cmplt_type *) r->buf; 963 - if (!resp) return -ENOMEM; 964 963 965 964 resp->MessageType = __constant_cpu_to_le32 ( 966 965 REMOTE_NDIS_KEEPALIVE_CMPLT); ··· 990 987 991 988 r = rndis_add_response (configNr, 992 989 sizeof (rndis_indicate_status_msg_type)); 993 - if (!r) return -ENOMEM; 994 - 990 + if (!r) 991 + return -ENOMEM; 995 992 resp = (rndis_indicate_status_msg_type *) r->buf; 996 - if (!resp) return -ENOMEM; 997 993 998 994 resp->MessageType = __constant_cpu_to_le32 ( 999 995 REMOTE_NDIS_INDICATE_STATUS_MSG); ··· 1023 1021 RNDIS_STATUS_MEDIA_DISCONNECT); 1024 1022 } 1025 1023 1024 + void rndis_uninit (int configNr) 1025 + { 1026 + u8 *buf; 1027 + u32 length; 1028 + 1029 + if (configNr >= RNDIS_MAX_CONFIGS) 1030 + return; 1031 + rndis_per_dev_params [configNr].used = 0; 1032 + rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED; 1033 + 1034 + /* drain the response queue */ 1035 + while ((buf = rndis_get_next_response(configNr, &length))) 1036 + rndis_free_response(configNr, buf); 1037 + } 1038 + 1026 1039 void rndis_set_host_mac (int configNr, const u8 *addr) 1027 1040 { 1028 1041 rndis_per_dev_params [configNr].host_mac = addr; ··· 1063 1046 return -ENOTSUPP; 1064 1047 params = &rndis_per_dev_params [configNr]; 1065 1048 1049 + /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for 1050 + * rx/tx statistics and link status, in addition to KEEPALIVE traffic 1051 + * and normal HC level polling to see if there's any IN traffic. 1052 + */ 1053 + 1066 1054 /* For USB: responses may take up to 10 seconds */ 1067 - switch (MsgType) 1068 - { 1055 + switch (MsgType) { 1069 1056 case REMOTE_NDIS_INITIALIZE_MSG: 1070 1057 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 1071 1058 __FUNCTION__ ); ··· 1103 1082 1104 1083 case REMOTE_NDIS_KEEPALIVE_MSG: 1105 1084 /* For USB: host does this every 5 seconds */ 1106 - #ifdef VERBOSE 1107 - DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1108 - __FUNCTION__ ); 1109 - #endif 1085 + if (rndis_debug > 1) 1086 + DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1087 + __FUNCTION__ ); 1110 1088 return rndis_keepalive_response (configNr, 1111 1089 (rndis_keepalive_msg_type *) 1112 1090 buf); ··· 1172 1152 } 1173 1153 1174 1154 int rndis_set_param_dev (u8 configNr, struct net_device *dev, 1175 - struct net_device_stats *stats) 1155 + struct net_device_stats *stats, 1156 + u16 *cdc_filter) 1176 1157 { 1177 1158 DEBUG("%s:\n", __FUNCTION__ ); 1178 1159 if (!dev || !stats) return -1; ··· 1181 1160 1182 1161 rndis_per_dev_params [configNr].dev = dev; 1183 1162 rndis_per_dev_params [configNr].stats = stats; 1163 + rndis_per_dev_params [configNr].filter = cdc_filter; 1184 1164 1185 1165 return 0; 1186 1166 } ··· 1200 1178 1201 1179 int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 1202 1180 { 1203 - DEBUG("%s:\n", __FUNCTION__ ); 1181 + DEBUG("%s: %u %u\n", __FUNCTION__, medium, speed); 1204 1182 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1205 1183 1206 1184 rndis_per_dev_params [configNr].medium = medium; ··· 1264 1242 { 1265 1243 rndis_resp_t *r; 1266 1244 1245 + /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */ 1267 1246 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); 1268 1247 if (!r) return NULL; 1269 1248
+8 -87
drivers/usb/gadget/rndis.h
··· 69 69 #define OID_PNP_ENABLE_WAKE_UP 0xFD010106 70 70 71 71 72 - /* supported OIDs */ 73 - static const u32 oid_supported_list [] = 74 - { 75 - /* the general stuff */ 76 - OID_GEN_SUPPORTED_LIST, 77 - OID_GEN_HARDWARE_STATUS, 78 - OID_GEN_MEDIA_SUPPORTED, 79 - OID_GEN_MEDIA_IN_USE, 80 - OID_GEN_MAXIMUM_FRAME_SIZE, 81 - OID_GEN_LINK_SPEED, 82 - OID_GEN_TRANSMIT_BLOCK_SIZE, 83 - OID_GEN_RECEIVE_BLOCK_SIZE, 84 - OID_GEN_VENDOR_ID, 85 - OID_GEN_VENDOR_DESCRIPTION, 86 - OID_GEN_VENDOR_DRIVER_VERSION, 87 - OID_GEN_CURRENT_PACKET_FILTER, 88 - OID_GEN_MAXIMUM_TOTAL_SIZE, 89 - OID_GEN_MEDIA_CONNECT_STATUS, 90 - OID_GEN_PHYSICAL_MEDIUM, 91 - #if 0 92 - OID_GEN_RNDIS_CONFIG_PARAMETER, 93 - #endif 94 - 95 - /* the statistical stuff */ 96 - OID_GEN_XMIT_OK, 97 - OID_GEN_RCV_OK, 98 - OID_GEN_XMIT_ERROR, 99 - OID_GEN_RCV_ERROR, 100 - OID_GEN_RCV_NO_BUFFER, 101 - #ifdef RNDIS_OPTIONAL_STATS 102 - OID_GEN_DIRECTED_BYTES_XMIT, 103 - OID_GEN_DIRECTED_FRAMES_XMIT, 104 - OID_GEN_MULTICAST_BYTES_XMIT, 105 - OID_GEN_MULTICAST_FRAMES_XMIT, 106 - OID_GEN_BROADCAST_BYTES_XMIT, 107 - OID_GEN_BROADCAST_FRAMES_XMIT, 108 - OID_GEN_DIRECTED_BYTES_RCV, 109 - OID_GEN_DIRECTED_FRAMES_RCV, 110 - OID_GEN_MULTICAST_BYTES_RCV, 111 - OID_GEN_MULTICAST_FRAMES_RCV, 112 - OID_GEN_BROADCAST_BYTES_RCV, 113 - OID_GEN_BROADCAST_FRAMES_RCV, 114 - OID_GEN_RCV_CRC_ERROR, 115 - OID_GEN_TRANSMIT_QUEUE_LENGTH, 116 - #endif /* RNDIS_OPTIONAL_STATS */ 117 - 118 - /* mandatory 802.3 */ 119 - /* the general stuff */ 120 - OID_802_3_PERMANENT_ADDRESS, 121 - OID_802_3_CURRENT_ADDRESS, 122 - OID_802_3_MULTICAST_LIST, 123 - OID_802_3_MAC_OPTIONS, 124 - OID_802_3_MAXIMUM_LIST_SIZE, 125 - 126 - /* the statistical stuff */ 127 - OID_802_3_RCV_ERROR_ALIGNMENT, 128 - OID_802_3_XMIT_ONE_COLLISION, 129 - OID_802_3_XMIT_MORE_COLLISIONS, 130 - #ifdef RNDIS_OPTIONAL_STATS 131 - OID_802_3_XMIT_DEFERRED, 132 - OID_802_3_XMIT_MAX_COLLISIONS, 133 - OID_802_3_RCV_OVERRUN, 134 - OID_802_3_XMIT_UNDERRUN, 135 - OID_802_3_XMIT_HEARTBEAT_FAILURE, 136 - OID_802_3_XMIT_TIMES_CRS_LOST, 137 - OID_802_3_XMIT_LATE_COLLISIONS, 138 - #endif /* RNDIS_OPTIONAL_STATS */ 139 - 140 - #ifdef RNDIS_PM 141 - /* PM and wakeup are mandatory for USB: */ 142 - 143 - /* power management */ 144 - OID_PNP_CAPABILITIES, 145 - OID_PNP_QUERY_POWER, 146 - OID_PNP_SET_POWER, 147 - 148 - /* wake up host */ 149 - OID_PNP_ENABLE_WAKE_UP, 150 - OID_PNP_ADD_WAKE_UP_PATTERN, 151 - OID_PNP_REMOVE_WAKE_UP_PATTERN, 152 - #endif 153 - }; 154 - 155 - 156 72 typedef struct rndis_init_msg_type 157 73 { 158 74 __le32 MessageType; ··· 225 309 typedef struct rndis_params 226 310 { 227 311 u8 confignr; 228 - int used; 312 + u8 used; 313 + u16 saved_filter; 229 314 enum rndis_state state; 230 - u32 filter; 231 315 u32 medium; 232 316 u32 speed; 233 317 u32 media_state; 318 + 234 319 const u8 *host_mac; 320 + u16 *filter; 235 321 struct net_device *dev; 236 322 struct net_device_stats *stats; 323 + 237 324 u32 vendorID; 238 325 const char *vendorDescr; 239 326 int (*ack) (struct net_device *); ··· 248 329 int rndis_register (int (*rndis_control_ack) (struct net_device *)); 249 330 void rndis_deregister (int configNr); 250 331 int rndis_set_param_dev (u8 configNr, struct net_device *dev, 251 - struct net_device_stats *stats); 332 + struct net_device_stats *stats, 333 + u16 *cdc_filter); 252 334 int rndis_set_param_vendor (u8 configNr, u32 vendorID, 253 335 const char *vendorDescr); 254 336 int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); ··· 258 338 u8 *rndis_get_next_response (int configNr, u32 *length); 259 339 void rndis_free_response (int configNr, u8 *buf); 260 340 341 + void rndis_uninit (int configNr); 261 342 int rndis_signal_connect (int configNr); 262 343 int rndis_signal_disconnect (int configNr); 263 344 int rndis_state (int configNr);
+19 -17
drivers/usb/gadget/serial.c
··· 300 300 u8 type, unsigned int index, int is_otg); 301 301 302 302 static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, 303 - int kmalloc_flags); 303 + unsigned kmalloc_flags); 304 304 static void gs_free_req(struct usb_ep *ep, struct usb_request *req); 305 305 306 306 static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, 307 - int kmalloc_flags); 307 + unsigned kmalloc_flags); 308 308 static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req); 309 309 310 - static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags); 310 + static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags); 311 311 static void gs_free_ports(struct gs_dev *dev); 312 312 313 313 /* circular buffer */ 314 - static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags); 314 + static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags); 315 315 static void gs_buf_free(struct gs_buf *gb); 316 316 static void gs_buf_clear(struct gs_buf *gb); 317 317 static unsigned int gs_buf_data_avail(struct gs_buf *gb); ··· 1607 1607 int ret = -EOPNOTSUPP; 1608 1608 struct gs_dev *dev = get_gadget_data(gadget); 1609 1609 struct usb_request *req = dev->dev_ctrl_req; 1610 - u16 wIndex = ctrl->wIndex; 1611 - u16 wValue = ctrl->wValue; 1612 - u16 wLength = ctrl->wLength; 1610 + u16 wIndex = le16_to_cpu(ctrl->wIndex); 1611 + u16 wValue = le16_to_cpu(ctrl->wValue); 1612 + u16 wLength = le16_to_cpu(ctrl->wLength); 1613 1613 1614 1614 switch (ctrl->bRequestType & USB_TYPE_MASK) { 1615 1615 case USB_TYPE_STANDARD: ··· 1651 1651 int ret = -EOPNOTSUPP; 1652 1652 struct gs_dev *dev = get_gadget_data(gadget); 1653 1653 struct usb_request *req = dev->dev_ctrl_req; 1654 - u16 wIndex = ctrl->wIndex; 1655 - u16 wValue = ctrl->wValue; 1656 - u16 wLength = ctrl->wLength; 1654 + u16 wIndex = le16_to_cpu(ctrl->wIndex); 1655 + u16 wValue = le16_to_cpu(ctrl->wValue); 1656 + u16 wLength = le16_to_cpu(ctrl->wLength); 1657 1657 1658 1658 switch (ctrl->bRequest) { 1659 1659 case USB_REQ_GET_DESCRIPTOR: ··· 1782 1782 struct gs_dev *dev = get_gadget_data(gadget); 1783 1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */ 1784 1784 struct usb_request *req = dev->dev_ctrl_req; 1785 - u16 wIndex = ctrl->wIndex; 1786 - u16 wValue = ctrl->wValue; 1787 - u16 wLength = ctrl->wLength; 1785 + u16 wIndex = le16_to_cpu(ctrl->wIndex); 1786 + u16 wValue = le16_to_cpu(ctrl->wValue); 1787 + u16 wLength = le16_to_cpu(ctrl->wLength); 1788 1788 1789 1789 switch (ctrl->bRequest) { 1790 1790 case USB_CDC_REQ_SET_LINE_CODING: ··· 2119 2119 * Allocate a usb_request and its buffer. Returns a pointer to the 2120 2120 * usb_request or NULL if there is an error. 2121 2121 */ 2122 - static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, int kmalloc_flags) 2122 + static struct usb_request * 2123 + gs_alloc_req(struct usb_ep *ep, unsigned int len, unsigned kmalloc_flags) 2123 2124 { 2124 2125 struct usb_request *req; 2125 2126 ··· 2160 2159 * Allocates a request and its buffer, using the given 2161 2160 * endpoint, buffer len, and kmalloc flags. 2162 2161 */ 2163 - static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, int kmalloc_flags) 2162 + static struct gs_req_entry * 2163 + gs_alloc_req_entry(struct usb_ep *ep, unsigned len, unsigned kmalloc_flags) 2164 2164 { 2165 2165 struct gs_req_entry *req; 2166 2166 ··· 2202 2200 * 2203 2201 * The device lock is normally held when calling this function. 2204 2202 */ 2205 - static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags) 2203 + static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags) 2206 2204 { 2207 2205 int i; 2208 2206 struct gs_port *port; ··· 2284 2282 * 2285 2283 * Allocate a circular buffer and all associated memory. 2286 2284 */ 2287 - static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags) 2285 + static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags) 2288 2286 { 2289 2287 struct gs_buf *gb; 2290 2288
+3 -3
drivers/usb/gadget/zero.c
··· 919 919 struct zero_dev *dev = get_gadget_data (gadget); 920 920 struct usb_request *req = dev->req; 921 921 int value = -EOPNOTSUPP; 922 - u16 w_index = ctrl->wIndex; 923 - u16 w_value = ctrl->wValue; 924 - u16 w_length = ctrl->wLength; 922 + u16 w_index = le16_to_cpu(ctrl->wIndex); 923 + u16 w_value = le16_to_cpu(ctrl->wValue); 924 + u16 w_length = le16_to_cpu(ctrl->wLength); 925 925 926 926 /* usually this stores reply data in the pre-allocated ep0 buffer, 927 927 * but config change events will reconfigure hardware.
+13
drivers/usb/host/Kconfig
··· 49 49 50 50 This supports the EHCI implementation from TransDimension Inc. 51 51 52 + config USB_ISP116X_HCD 53 + tristate "ISP116X HCD support" 54 + depends on USB 55 + default N 56 + ---help--- 57 + The ISP1160 and ISP1161 chips are USB host controllers. Enable this 58 + option if your board has this chip. If unsure, say N. 59 + 60 + This driver does not support isochronous transfers. 61 + 62 + To compile this driver as a module, choose M here: the 63 + module will be called isp116x-hcd. 64 + 52 65 config USB_OHCI_HCD 53 66 tristate "OHCI HCD support" 54 67 depends on USB && USB_ARCH_HAS_OHCI
+1
drivers/usb/host/Makefile
··· 4 4 # 5 5 6 6 obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o 7 + obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o 7 8 obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 8 9 obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 9 10 obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o
+54 -5
drivers/usb/host/ehci-dbg.c
··· 254 254 } 255 255 256 256 return scnprintf (buf, len, 257 - "%s%sport %d status %06x%s%s sig=%s %s%s%s%s%s%s%s%s%s", 257 + "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s", 258 258 label, label [0] ? " " : "", port, status, 259 259 (status & PORT_POWER) ? " POWER" : "", 260 260 (status & PORT_OWNER) ? " OWNER" : "", ··· 644 644 if (bus->controller->power.power_state) { 645 645 size = scnprintf (next, size, 646 646 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 647 + "%s\n" 647 648 "SUSPENDED (no register access)\n", 648 649 hcd->self.controller->bus->name, 649 - hcd->self.controller->bus_id); 650 + hcd->self.controller->bus_id, 651 + hcd->product_desc); 650 652 goto done; 651 653 } 652 654 ··· 656 654 i = HC_VERSION(readl (&ehci->caps->hc_capbase)); 657 655 temp = scnprintf (next, size, 658 656 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 657 + "%s\n" 659 658 "EHCI %x.%02x, hcd state %d\n", 660 659 hcd->self.controller->bus->name, 661 660 hcd->self.controller->bus_id, 661 + hcd->product_desc, 662 662 i >> 8, i & 0x0ff, hcd->state); 663 663 size -= temp; 664 664 next += temp; 665 + 666 + #ifdef CONFIG_PCI 667 + /* EHCI 0.96 and later may have "extended capabilities" */ 668 + if (hcd->self.controller->bus == &pci_bus_type) { 669 + struct pci_dev *pdev; 670 + u32 offset, cap, cap2; 671 + unsigned count = 256/4; 672 + 673 + pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); 674 + offset = HCC_EXT_CAPS (readl (&ehci->caps->hcc_params)); 675 + while (offset && count--) { 676 + pci_read_config_dword (pdev, offset, &cap); 677 + switch (cap & 0xff) { 678 + case 1: 679 + temp = scnprintf (next, size, 680 + "ownership %08x%s%s\n", cap, 681 + (cap & (1 << 24)) ? " linux" : "", 682 + (cap & (1 << 16)) ? " firmware" : ""); 683 + size -= temp; 684 + next += temp; 685 + 686 + offset += 4; 687 + pci_read_config_dword (pdev, offset, &cap2); 688 + temp = scnprintf (next, size, 689 + "SMI sts/enable 0x%08x\n", cap2); 690 + size -= temp; 691 + next += temp; 692 + break; 693 + case 0: /* illegal reserved capability */ 694 + cap = 0; 695 + /* FALLTHROUGH */ 696 + default: /* unknown */ 697 + break; 698 + } 699 + temp = (cap >> 8) & 0xff; 700 + } 701 + } 702 + #endif 665 703 666 704 // FIXME interpret both types of params 667 705 i = readl (&ehci->caps->hcs_params); ··· 738 696 size -= temp; 739 697 next += temp; 740 698 741 - for (i = 0; i < HCS_N_PORTS (ehci->hcs_params); i++) { 742 - temp = dbg_port_buf (scratch, sizeof scratch, label, i + 1, 743 - readl (&ehci->regs->port_status [i])); 699 + for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) { 700 + temp = dbg_port_buf (scratch, sizeof scratch, label, i, 701 + readl (&ehci->regs->port_status [i - 1])); 744 702 temp = scnprintf (next, size, fmt, temp, scratch); 745 703 size -= temp; 746 704 next += temp; 705 + if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) { 706 + temp = scnprintf (next, size, 707 + " debug control %08x\n", 708 + readl (&ehci->debug->control)); 709 + size -= temp; 710 + next += temp; 711 + } 747 712 } 748 713 749 714 if (ehci->reclaim) {
+14 -44
drivers/usb/host/ehci-hcd.c
··· 304 304 */ 305 305 static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap) 306 306 { 307 + struct pci_dev *pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); 308 + 309 + /* always say Linux will own the hardware */ 310 + pci_write_config_byte(pdev, where + 3, 1); 311 + 312 + /* maybe wait a while for BIOS to respond */ 307 313 if (cap & (1 << 16)) { 308 314 int msec = 5000; 309 - struct pci_dev *pdev = 310 - to_pci_dev(ehci_to_hcd(ehci)->self.controller); 311 315 312 - /* request handoff to OS */ 313 - cap |= 1 << 24; 314 - pci_write_config_dword(pdev, where, cap); 315 - 316 - /* and wait a while for it to happen */ 317 316 do { 318 317 msleep(10); 319 318 msec -= 10; 320 319 pci_read_config_dword(pdev, where, &cap); 321 320 } while ((cap & (1 << 16)) && msec); 322 321 if (cap & (1 << 16)) { 323 - ehci_err (ehci, "BIOS handoff failed (%d, %04x)\n", 322 + ehci_err(ehci, "BIOS handoff failed (%d, %08x)\n", 324 323 where, cap); 325 324 // some BIOS versions seem buggy... 326 325 // return 1; 327 326 ehci_warn (ehci, "continuing after BIOS bug...\n"); 328 - return 0; 329 - } 330 - ehci_dbg (ehci, "BIOS handoff succeeded\n"); 327 + /* disable all SMIs, and clear "BIOS owns" flag */ 328 + pci_write_config_dword(pdev, where + 4, 0); 329 + pci_write_config_byte(pdev, where + 2, 0); 330 + } else 331 + ehci_dbg(ehci, "BIOS handoff succeeded\n"); 331 332 } 332 333 return 0; 333 334 } ··· 493 492 { 494 493 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 495 494 u32 temp; 496 - struct usb_device *udev; 497 - struct usb_bus *bus; 498 495 int retval; 499 496 u32 hcc_params; 500 497 u8 sbrn = 0; ··· 587 588 writel (0, &ehci->regs->segment); 588 589 #if 0 589 590 // this is deeply broken on almost all architectures 590 - if (!pci_set_dma_mask (to_pci_dev(hcd->self.controller), 0xffffffffffffffffULL)) 591 - ehci_info (ehci, "enabled 64bit PCI DMA\n"); 591 + if (!dma_set_mask (hcd->self.controller, DMA_64BIT_MASK)) 592 + ehci_info (ehci, "enabled 64bit DMA\n"); 592 593 #endif 593 594 } 594 595 ··· 630 631 631 632 /* set async sleep time = 10 us ... ? */ 632 633 633 - /* wire up the root hub */ 634 - bus = hcd_to_bus (hcd); 635 - udev = first ? usb_alloc_dev (NULL, bus, 0) : bus->root_hub; 636 - if (!udev) { 637 - done2: 638 - ehci_mem_cleanup (ehci); 639 - return -ENOMEM; 640 - } 641 - udev->speed = USB_SPEED_HIGH; 642 - udev->state = first ? USB_STATE_ATTACHED : USB_STATE_CONFIGURED; 643 - 644 634 /* 645 635 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices 646 636 * are explicitly handed to companion controller(s), so no TT is ··· 651 663 ((sbrn & 0xf0)>>4), (sbrn & 0x0f), 652 664 first ? "initialized" : "restarted", 653 665 temp >> 8, temp & 0xff, DRIVER_VERSION); 654 - 655 - /* 656 - * From here on, khubd concurrently accesses the root 657 - * hub; drivers will be talking to enumerated devices. 658 - * (On restart paths, khubd already knows about the root 659 - * hub and could find work as soon as we wrote FLAG_CF.) 660 - * 661 - * Before this point the HC was idle/ready. After, khubd 662 - * and device drivers may start it running. 663 - */ 664 - if (first && usb_hcd_register_root_hub (udev, hcd) != 0) { 665 - if (hcd->state == HC_STATE_RUNNING) 666 - ehci_quiesce (ehci); 667 - ehci_reset (ehci); 668 - usb_put_dev (udev); 669 - retval = -ENODEV; 670 - goto done2; 671 - } 672 666 673 667 writel (INTR_MASK, &ehci->regs->intr_enable); /* Turn On Interrupts */ 674 668
+1 -1
drivers/usb/host/ehci-hub.c
··· 1 1 /* 2 - * Copyright (c) 2001-2002 by David Brownell 2 + * Copyright (C) 2001-2004 by David Brownell 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify it 5 5 * under the terms of the GNU General Public License as published by the
+1 -1
drivers/usb/host/ehci-q.c
··· 1 1 /* 2 - * Copyright (c) 2001-2002 by David Brownell 2 + * Copyright (C) 2001-2004 by David Brownell 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify it 5 5 * under the terms of the GNU General Public License as published by the
+7 -10
drivers/usb/host/ehci-sched.c
··· 637 637 { 638 638 struct ehci_iso_stream *stream; 639 639 640 - stream = kmalloc(sizeof *stream, mem_flags); 640 + stream = kcalloc(1, sizeof *stream, mem_flags); 641 641 if (likely (stream != NULL)) { 642 - memset (stream, 0, sizeof(*stream)); 643 642 INIT_LIST_HEAD(&stream->td_list); 644 643 INIT_LIST_HEAD(&stream->free_list); 645 644 stream->next_uframe = -1; ··· 893 894 trans |= length << 16; 894 895 uframe->transaction = cpu_to_le32 (trans); 895 896 896 - /* might need to cross a buffer page within a td */ 897 + /* might need to cross a buffer page within a uframe */ 897 898 uframe->bufp = (buf & ~(u64)0x0fff); 898 899 buf += length; 899 900 if (unlikely ((uframe->bufp != (buf & ~(u64)0x0fff)))) ··· 1193 1194 { 1194 1195 int i; 1195 1196 1197 + /* it's been recently zeroed */ 1196 1198 itd->hw_next = EHCI_LIST_END; 1197 1199 itd->hw_bufp [0] = stream->buf0; 1198 1200 itd->hw_bufp [1] = stream->buf1; ··· 1210 1210 struct ehci_itd *itd, 1211 1211 struct ehci_iso_sched *iso_sched, 1212 1212 unsigned index, 1213 - u16 uframe, 1214 - int first 1213 + u16 uframe 1215 1214 ) 1216 1215 { 1217 1216 struct ehci_iso_packet *uf = &iso_sched->packet [index]; ··· 1227 1228 itd->hw_bufp_hi [pg] |= cpu_to_le32 ((u32)(uf->bufp >> 32)); 1228 1229 1229 1230 /* iso_frame_desc[].offset must be strictly increasing */ 1230 - if (unlikely (!first && uf->cross)) { 1231 + if (unlikely (uf->cross)) { 1231 1232 u64 bufp = uf->bufp + 4096; 1232 1233 itd->pg = ++pg; 1233 1234 itd->hw_bufp [pg] |= cpu_to_le32 (bufp & ~(u32)0); ··· 1256 1257 struct ehci_iso_stream *stream 1257 1258 ) 1258 1259 { 1259 - int packet, first = 1; 1260 + int packet; 1260 1261 unsigned next_uframe, uframe, frame; 1261 1262 struct ehci_iso_sched *iso_sched = urb->hcpriv; 1262 1263 struct ehci_itd *itd; ··· 1289 1290 list_move_tail (&itd->itd_list, &stream->td_list); 1290 1291 itd->stream = iso_stream_get (stream); 1291 1292 itd->urb = usb_get_urb (urb); 1292 - first = 1; 1293 1293 itd_init (stream, itd); 1294 1294 } 1295 1295 ··· 1296 1298 frame = next_uframe >> 3; 1297 1299 1298 1300 itd->usecs [uframe] = stream->usecs; 1299 - itd_patch (itd, iso_sched, packet, uframe, first); 1300 - first = 0; 1301 + itd_patch (itd, iso_sched, packet, uframe); 1301 1302 1302 1303 next_uframe += stream->interval; 1303 1304 stream->depth += stream->interval;
+1875
drivers/usb/host/isp116x-hcd.c
··· 1 + /* 2 + * ISP116x HCD (Host Controller Driver) for USB. 3 + * 4 + * Derived from the SL811 HCD, rewritten for ISP116x. 5 + * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee> 6 + * 7 + * Portions: 8 + * Copyright (C) 2004 Psion Teklogix (for NetBook PRO) 9 + * Copyright (C) 2004 David Brownell 10 + * 11 + * Periodic scheduling is based on Roman's OHCI code 12 + * Copyright (C) 1999 Roman Weissgaerber 13 + * 14 + */ 15 + 16 + /* 17 + * The driver basically works. A number of people have used it with a range 18 + * of devices. 19 + * 20 + *The driver passes all usbtests 1-14. 21 + * 22 + * Suspending/resuming of root hub via sysfs works. Remote wakeup works too. 23 + * And suspending/resuming of platform device works too. Suspend/resume 24 + * via HCD operations vector is not implemented. 25 + * 26 + * Iso transfer support is not implemented. Adding this would include 27 + * implementing recovery from the failure to service the processed ITL 28 + * fifo ram in time, which will involve chip reset. 29 + * 30 + * TODO: 31 + + More testing of suspend/resume. 32 + */ 33 + 34 + /* 35 + ISP116x chips require certain delays between accesses to its 36 + registers. The following timing options exist. 37 + 38 + 1. Configure your memory controller (the best) 39 + 2. Implement platform-specific delay function possibly 40 + combined with configuring the memory controller; see 41 + include/linux/usb-isp116x.h for more info. Some broken 42 + memory controllers line LH7A400 SMC need this. Also, 43 + uncomment for that to work the following 44 + USE_PLATFORM_DELAY macro. 45 + 3. Use ndelay (easiest, poorest). For that, uncomment 46 + the following USE_NDELAY macro. 47 + */ 48 + #define USE_PLATFORM_DELAY 49 + //#define USE_NDELAY 50 + 51 + //#define DEBUG 52 + //#define VERBOSE 53 + /* Transfer descriptors. See dump_ptd() for printout format */ 54 + //#define PTD_TRACE 55 + /* enqueuing/finishing log of urbs */ 56 + //#define URB_TRACE 57 + 58 + #include <linux/config.h> 59 + #include <linux/module.h> 60 + #include <linux/moduleparam.h> 61 + #include <linux/kernel.h> 62 + #include <linux/delay.h> 63 + #include <linux/ioport.h> 64 + #include <linux/sched.h> 65 + #include <linux/slab.h> 66 + #include <linux/smp_lock.h> 67 + #include <linux/errno.h> 68 + #include <linux/init.h> 69 + #include <linux/list.h> 70 + #include <linux/interrupt.h> 71 + #include <linux/usb.h> 72 + #include <linux/usb_isp116x.h> 73 + 74 + #include <asm/io.h> 75 + #include <asm/irq.h> 76 + #include <asm/system.h> 77 + #include <asm/byteorder.h> 78 + 79 + #ifndef DEBUG 80 + # define STUB_DEBUG_FILE 81 + #endif 82 + 83 + #include "../core/hcd.h" 84 + #include "isp116x.h" 85 + 86 + #define DRIVER_VERSION "08 Apr 2005" 87 + #define DRIVER_DESC "ISP116x USB Host Controller Driver" 88 + 89 + MODULE_DESCRIPTION(DRIVER_DESC); 90 + MODULE_LICENSE("GPL"); 91 + 92 + static const char hcd_name[] = "isp116x-hcd"; 93 + 94 + /*-----------------------------------------------------------------*/ 95 + 96 + /* 97 + Write len bytes to fifo, pad till 32-bit boundary 98 + */ 99 + static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len) 100 + { 101 + u8 *dp = (u8 *) buf; 102 + u16 *dp2 = (u16 *) buf; 103 + u16 w; 104 + int quot = len % 4; 105 + 106 + if ((unsigned long)dp2 & 1) { 107 + /* not aligned */ 108 + for (; len > 1; len -= 2) { 109 + w = *dp++; 110 + w |= *dp++ << 8; 111 + isp116x_raw_write_data16(isp116x, w); 112 + } 113 + if (len) 114 + isp116x_write_data16(isp116x, (u16) * dp); 115 + } else { 116 + /* aligned */ 117 + for (; len > 1; len -= 2) 118 + isp116x_raw_write_data16(isp116x, *dp2++); 119 + if (len) 120 + isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2)); 121 + } 122 + if (quot == 1 || quot == 2) 123 + isp116x_raw_write_data16(isp116x, 0); 124 + } 125 + 126 + /* 127 + Read len bytes from fifo and then read till 32-bit boundary. 128 + */ 129 + static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len) 130 + { 131 + u8 *dp = (u8 *) buf; 132 + u16 *dp2 = (u16 *) buf; 133 + u16 w; 134 + int quot = len % 4; 135 + 136 + if ((unsigned long)dp2 & 1) { 137 + /* not aligned */ 138 + for (; len > 1; len -= 2) { 139 + w = isp116x_raw_read_data16(isp116x); 140 + *dp++ = w & 0xff; 141 + *dp++ = (w >> 8) & 0xff; 142 + } 143 + if (len) 144 + *dp = 0xff & isp116x_read_data16(isp116x); 145 + } else { 146 + /* aligned */ 147 + for (; len > 1; len -= 2) 148 + *dp2++ = isp116x_raw_read_data16(isp116x); 149 + if (len) 150 + *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x); 151 + } 152 + if (quot == 1 || quot == 2) 153 + isp116x_raw_read_data16(isp116x); 154 + } 155 + 156 + /* 157 + Write ptd's and data for scheduled transfers into 158 + the fifo ram. Fifo must be empty and ready. 159 + */ 160 + static void pack_fifo(struct isp116x *isp116x) 161 + { 162 + struct isp116x_ep *ep; 163 + struct ptd *ptd; 164 + int buflen = isp116x->atl_last_dir == PTD_DIR_IN 165 + ? isp116x->atl_bufshrt : isp116x->atl_buflen; 166 + int ptd_count = 0; 167 + 168 + isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT); 169 + isp116x_write_reg16(isp116x, HCXFERCTR, buflen); 170 + isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET); 171 + for (ep = isp116x->atl_active; ep; ep = ep->active) { 172 + ++ptd_count; 173 + ptd = &ep->ptd; 174 + dump_ptd(ptd); 175 + dump_ptd_out_data(ptd, ep->data); 176 + isp116x_write_data16(isp116x, ptd->count); 177 + isp116x_write_data16(isp116x, ptd->mps); 178 + isp116x_write_data16(isp116x, ptd->len); 179 + isp116x_write_data16(isp116x, ptd->faddr); 180 + buflen -= sizeof(struct ptd); 181 + /* Skip writing data for last IN PTD */ 182 + if (ep->active || (isp116x->atl_last_dir != PTD_DIR_IN)) { 183 + write_ptddata_to_fifo(isp116x, ep->data, ep->length); 184 + buflen -= ALIGN(ep->length, 4); 185 + } 186 + } 187 + BUG_ON(buflen); 188 + } 189 + 190 + /* 191 + Read the processed ptd's and data from fifo ram back to 192 + URBs' buffers. Fifo must be full and done 193 + */ 194 + static void unpack_fifo(struct isp116x *isp116x) 195 + { 196 + struct isp116x_ep *ep; 197 + struct ptd *ptd; 198 + int buflen = isp116x->atl_last_dir == PTD_DIR_IN 199 + ? isp116x->atl_buflen : isp116x->atl_bufshrt; 200 + 201 + isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT); 202 + isp116x_write_reg16(isp116x, HCXFERCTR, buflen); 203 + isp116x_write_addr(isp116x, HCATLPORT); 204 + for (ep = isp116x->atl_active; ep; ep = ep->active) { 205 + ptd = &ep->ptd; 206 + ptd->count = isp116x_read_data16(isp116x); 207 + ptd->mps = isp116x_read_data16(isp116x); 208 + ptd->len = isp116x_read_data16(isp116x); 209 + ptd->faddr = isp116x_read_data16(isp116x); 210 + buflen -= sizeof(struct ptd); 211 + /* Skip reading data for last Setup or Out PTD */ 212 + if (ep->active || (isp116x->atl_last_dir == PTD_DIR_IN)) { 213 + read_ptddata_from_fifo(isp116x, ep->data, ep->length); 214 + buflen -= ALIGN(ep->length, 4); 215 + } 216 + dump_ptd(ptd); 217 + dump_ptd_in_data(ptd, ep->data); 218 + } 219 + BUG_ON(buflen); 220 + } 221 + 222 + /*---------------------------------------------------------------*/ 223 + 224 + /* 225 + Set up PTD's. 226 + */ 227 + static void preproc_atl_queue(struct isp116x *isp116x) 228 + { 229 + struct isp116x_ep *ep; 230 + struct urb *urb; 231 + struct ptd *ptd; 232 + u16 toggle, dir, len; 233 + 234 + for (ep = isp116x->atl_active; ep; ep = ep->active) { 235 + BUG_ON(list_empty(&ep->hep->urb_list)); 236 + urb = container_of(ep->hep->urb_list.next, 237 + struct urb, urb_list); 238 + ptd = &ep->ptd; 239 + len = ep->length; 240 + spin_lock(&urb->lock); 241 + ep->data = (unsigned char *)urb->transfer_buffer 242 + + urb->actual_length; 243 + 244 + switch (ep->nextpid) { 245 + case USB_PID_IN: 246 + toggle = usb_gettoggle(urb->dev, ep->epnum, 0); 247 + dir = PTD_DIR_IN; 248 + break; 249 + case USB_PID_OUT: 250 + toggle = usb_gettoggle(urb->dev, ep->epnum, 1); 251 + dir = PTD_DIR_OUT; 252 + break; 253 + case USB_PID_SETUP: 254 + toggle = 0; 255 + dir = PTD_DIR_SETUP; 256 + len = sizeof(struct usb_ctrlrequest); 257 + ep->data = urb->setup_packet; 258 + break; 259 + case USB_PID_ACK: 260 + toggle = 1; 261 + len = 0; 262 + dir = (urb->transfer_buffer_length 263 + && usb_pipein(urb->pipe)) 264 + ? PTD_DIR_OUT : PTD_DIR_IN; 265 + break; 266 + default: 267 + /* To please gcc */ 268 + toggle = dir = 0; 269 + ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__, 270 + ep->nextpid); 271 + BUG_ON(1); 272 + } 273 + 274 + ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle); 275 + ptd->mps = PTD_MPS(ep->maxpacket) 276 + | PTD_SPD(urb->dev->speed == USB_SPEED_LOW) 277 + | PTD_EP(ep->epnum); 278 + ptd->len = PTD_LEN(len) | PTD_DIR(dir); 279 + ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe)); 280 + spin_unlock(&urb->lock); 281 + if (!ep->active) { 282 + ptd->mps |= PTD_LAST_MSK; 283 + isp116x->atl_last_dir = dir; 284 + } 285 + isp116x->atl_bufshrt = sizeof(struct ptd) + isp116x->atl_buflen; 286 + isp116x->atl_buflen = isp116x->atl_bufshrt + ALIGN(len, 4); 287 + } 288 + } 289 + 290 + /* 291 + Analyze transfer results, handle partial transfers and errors 292 + */ 293 + static void postproc_atl_queue(struct isp116x *isp116x) 294 + { 295 + struct isp116x_ep *ep; 296 + struct urb *urb; 297 + struct usb_device *udev; 298 + struct ptd *ptd; 299 + int short_not_ok; 300 + u8 cc; 301 + 302 + for (ep = isp116x->atl_active; ep; ep = ep->active) { 303 + BUG_ON(list_empty(&ep->hep->urb_list)); 304 + urb = 305 + container_of(ep->hep->urb_list.next, struct urb, urb_list); 306 + udev = urb->dev; 307 + ptd = &ep->ptd; 308 + cc = PTD_GET_CC(ptd); 309 + 310 + spin_lock(&urb->lock); 311 + short_not_ok = 1; 312 + 313 + /* Data underrun is special. For allowed underrun 314 + we clear the error and continue as normal. For 315 + forbidden underrun we finish the DATA stage 316 + immediately while for control transfer, 317 + we do a STATUS stage. */ 318 + if (cc == TD_DATAUNDERRUN) { 319 + if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) { 320 + DBG("Allowed data underrun\n"); 321 + cc = TD_CC_NOERROR; 322 + short_not_ok = 0; 323 + } else { 324 + ep->error_count = 1; 325 + if (usb_pipecontrol(urb->pipe)) 326 + ep->nextpid = USB_PID_ACK; 327 + else 328 + usb_settoggle(udev, ep->epnum, 329 + ep->nextpid == 330 + USB_PID_OUT, 331 + PTD_GET_TOGGLE(ptd) ^ 1); 332 + urb->status = cc_to_error[TD_DATAUNDERRUN]; 333 + spin_unlock(&urb->lock); 334 + continue; 335 + } 336 + } 337 + /* Keep underrun error through the STATUS stage */ 338 + if (urb->status == cc_to_error[TD_DATAUNDERRUN]) 339 + cc = TD_DATAUNDERRUN; 340 + 341 + if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED 342 + && (++ep->error_count >= 3 || cc == TD_CC_STALL 343 + || cc == TD_DATAOVERRUN)) { 344 + if (urb->status == -EINPROGRESS) 345 + urb->status = cc_to_error[cc]; 346 + if (ep->nextpid == USB_PID_ACK) 347 + ep->nextpid = 0; 348 + spin_unlock(&urb->lock); 349 + continue; 350 + } 351 + /* According to usb spec, zero-length Int transfer signals 352 + finishing of the urb. Hey, does this apply only 353 + for IN endpoints? */ 354 + if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) { 355 + if (urb->status == -EINPROGRESS) 356 + urb->status = 0; 357 + spin_unlock(&urb->lock); 358 + continue; 359 + } 360 + 361 + /* Relax after previously failed, but later succeeded 362 + or correctly NAK'ed retransmission attempt */ 363 + if (ep->error_count 364 + && (cc == TD_CC_NOERROR || cc == TD_NOTACCESSED)) 365 + ep->error_count = 0; 366 + 367 + /* Take into account idiosyncracies of the isp116x chip 368 + regarding toggle bit for failed transfers */ 369 + if (ep->nextpid == USB_PID_OUT) 370 + usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd) 371 + ^ (ep->error_count > 0)); 372 + else if (ep->nextpid == USB_PID_IN) 373 + usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd) 374 + ^ (ep->error_count > 0)); 375 + 376 + switch (ep->nextpid) { 377 + case USB_PID_IN: 378 + case USB_PID_OUT: 379 + urb->actual_length += PTD_GET_COUNT(ptd); 380 + if (PTD_GET_ACTIVE(ptd) 381 + || (cc != TD_CC_NOERROR && cc < 0x0E)) 382 + break; 383 + if (urb->transfer_buffer_length != urb->actual_length) { 384 + if (short_not_ok) 385 + break; 386 + } else { 387 + if (urb->transfer_flags & URB_ZERO_PACKET 388 + && ep->nextpid == USB_PID_OUT 389 + && !(PTD_GET_COUNT(ptd) % ep->maxpacket)) { 390 + DBG("Zero packet requested\n"); 391 + break; 392 + } 393 + } 394 + /* All data for this URB is transferred, let's finish */ 395 + if (usb_pipecontrol(urb->pipe)) 396 + ep->nextpid = USB_PID_ACK; 397 + else if (urb->status == -EINPROGRESS) 398 + urb->status = 0; 399 + break; 400 + case USB_PID_SETUP: 401 + if (PTD_GET_ACTIVE(ptd) 402 + || (cc != TD_CC_NOERROR && cc < 0x0E)) 403 + break; 404 + if (urb->transfer_buffer_length == urb->actual_length) 405 + ep->nextpid = USB_PID_ACK; 406 + else if (usb_pipeout(urb->pipe)) { 407 + usb_settoggle(udev, 0, 1, 1); 408 + ep->nextpid = USB_PID_OUT; 409 + } else { 410 + usb_settoggle(udev, 0, 0, 1); 411 + ep->nextpid = USB_PID_IN; 412 + } 413 + break; 414 + case USB_PID_ACK: 415 + if (PTD_GET_ACTIVE(ptd) 416 + || (cc != TD_CC_NOERROR && cc < 0x0E)) 417 + break; 418 + if (urb->status == -EINPROGRESS) 419 + urb->status = 0; 420 + ep->nextpid = 0; 421 + break; 422 + default: 423 + BUG_ON(1); 424 + } 425 + spin_unlock(&urb->lock); 426 + } 427 + } 428 + 429 + /* 430 + Take done or failed requests out of schedule. Give back 431 + processed urbs. 432 + */ 433 + static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep, 434 + struct urb *urb, struct pt_regs *regs) 435 + __releases(isp116x->lock) __acquires(isp116x->lock) 436 + { 437 + unsigned i; 438 + 439 + urb->hcpriv = NULL; 440 + ep->error_count = 0; 441 + 442 + if (usb_pipecontrol(urb->pipe)) 443 + ep->nextpid = USB_PID_SETUP; 444 + 445 + urb_dbg(urb, "Finish"); 446 + 447 + spin_unlock(&isp116x->lock); 448 + usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, regs); 449 + spin_lock(&isp116x->lock); 450 + 451 + /* take idle endpoints out of the schedule */ 452 + if (!list_empty(&ep->hep->urb_list)) 453 + return; 454 + 455 + /* async deschedule */ 456 + if (!list_empty(&ep->schedule)) { 457 + list_del_init(&ep->schedule); 458 + return; 459 + } 460 + 461 + /* periodic deschedule */ 462 + DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch); 463 + for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) { 464 + struct isp116x_ep *temp; 465 + struct isp116x_ep **prev = &isp116x->periodic[i]; 466 + 467 + while (*prev && ((temp = *prev) != ep)) 468 + prev = &temp->next; 469 + if (*prev) 470 + *prev = ep->next; 471 + isp116x->load[i] -= ep->load; 472 + } 473 + ep->branch = PERIODIC_SIZE; 474 + isp116x_to_hcd(isp116x)->self.bandwidth_allocated -= 475 + ep->load / ep->period; 476 + 477 + /* switch irq type? */ 478 + if (!--isp116x->periodic_count) { 479 + isp116x->irqenb &= ~HCuPINT_SOF; 480 + isp116x->irqenb |= HCuPINT_ATL; 481 + } 482 + } 483 + 484 + /* 485 + Scan transfer lists, schedule transfers, send data off 486 + to chip. 487 + */ 488 + static void start_atl_transfers(struct isp116x *isp116x) 489 + { 490 + struct isp116x_ep *last_ep = NULL, *ep; 491 + struct urb *urb; 492 + u16 load = 0; 493 + int len, index, speed, byte_time; 494 + 495 + if (atomic_read(&isp116x->atl_finishing)) 496 + return; 497 + 498 + if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) 499 + return; 500 + 501 + /* FIFO not empty? */ 502 + if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL) 503 + return; 504 + 505 + isp116x->atl_active = NULL; 506 + isp116x->atl_buflen = isp116x->atl_bufshrt = 0; 507 + 508 + /* Schedule int transfers */ 509 + if (isp116x->periodic_count) { 510 + isp116x->fmindex = index = 511 + (isp116x->fmindex + 1) & (PERIODIC_SIZE - 1); 512 + if ((load = isp116x->load[index])) { 513 + /* Bring all int transfers for this frame 514 + into the active queue */ 515 + isp116x->atl_active = last_ep = 516 + isp116x->periodic[index]; 517 + while (last_ep->next) 518 + last_ep = (last_ep->active = last_ep->next); 519 + last_ep->active = NULL; 520 + } 521 + } 522 + 523 + /* Schedule control/bulk transfers */ 524 + list_for_each_entry(ep, &isp116x->async, schedule) { 525 + urb = container_of(ep->hep->urb_list.next, 526 + struct urb, urb_list); 527 + speed = urb->dev->speed; 528 + byte_time = speed == USB_SPEED_LOW 529 + ? BYTE_TIME_LOWSPEED : BYTE_TIME_FULLSPEED; 530 + 531 + if (ep->nextpid == USB_PID_SETUP) { 532 + len = sizeof(struct usb_ctrlrequest); 533 + } else if (ep->nextpid == USB_PID_ACK) { 534 + len = 0; 535 + } else { 536 + /* Find current free length ... */ 537 + len = (MAX_LOAD_LIMIT - load) / byte_time; 538 + 539 + /* ... then limit it to configured max size ... */ 540 + len = min(len, speed == USB_SPEED_LOW ? 541 + MAX_TRANSFER_SIZE_LOWSPEED : 542 + MAX_TRANSFER_SIZE_FULLSPEED); 543 + 544 + /* ... and finally cut to the multiple of MaxPacketSize, 545 + or to the real length if there's enough room. */ 546 + if (len < 547 + (urb->transfer_buffer_length - 548 + urb->actual_length)) { 549 + len -= len % ep->maxpacket; 550 + if (!len) 551 + continue; 552 + } else 553 + len = urb->transfer_buffer_length - 554 + urb->actual_length; 555 + BUG_ON(len < 0); 556 + } 557 + 558 + load += len * byte_time; 559 + if (load > MAX_LOAD_LIMIT) 560 + break; 561 + 562 + ep->active = NULL; 563 + ep->length = len; 564 + if (last_ep) 565 + last_ep->active = ep; 566 + else 567 + isp116x->atl_active = ep; 568 + last_ep = ep; 569 + } 570 + 571 + /* Avoid starving of endpoints */ 572 + if ((&isp116x->async)->next != (&isp116x->async)->prev) 573 + list_move(&isp116x->async, (&isp116x->async)->next); 574 + 575 + if (isp116x->atl_active) { 576 + preproc_atl_queue(isp116x); 577 + pack_fifo(isp116x); 578 + } 579 + } 580 + 581 + /* 582 + Finish the processed transfers 583 + */ 584 + static void finish_atl_transfers(struct isp116x *isp116x, struct pt_regs *regs) 585 + { 586 + struct isp116x_ep *ep; 587 + struct urb *urb; 588 + 589 + if (!isp116x->atl_active) 590 + return; 591 + /* Fifo not ready? */ 592 + if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE)) 593 + return; 594 + 595 + atomic_inc(&isp116x->atl_finishing); 596 + unpack_fifo(isp116x); 597 + postproc_atl_queue(isp116x); 598 + for (ep = isp116x->atl_active; ep; ep = ep->active) { 599 + urb = 600 + container_of(ep->hep->urb_list.next, struct urb, urb_list); 601 + /* USB_PID_ACK check here avoids finishing of 602 + control transfers, for which TD_DATAUNDERRUN 603 + occured, while URB_SHORT_NOT_OK was set */ 604 + if (urb && urb->status != -EINPROGRESS 605 + && ep->nextpid != USB_PID_ACK) 606 + finish_request(isp116x, ep, urb, regs); 607 + } 608 + atomic_dec(&isp116x->atl_finishing); 609 + } 610 + 611 + static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs) 612 + { 613 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 614 + u16 irqstat; 615 + irqreturn_t ret = IRQ_NONE; 616 + 617 + spin_lock(&isp116x->lock); 618 + isp116x_write_reg16(isp116x, HCuPINTENB, 0); 619 + irqstat = isp116x_read_reg16(isp116x, HCuPINT); 620 + isp116x_write_reg16(isp116x, HCuPINT, irqstat); 621 + 622 + if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) { 623 + ret = IRQ_HANDLED; 624 + finish_atl_transfers(isp116x, regs); 625 + } 626 + 627 + if (irqstat & HCuPINT_OPR) { 628 + u32 intstat = isp116x_read_reg32(isp116x, HCINTSTAT); 629 + isp116x_write_reg32(isp116x, HCINTSTAT, intstat); 630 + if (intstat & HCINT_UE) { 631 + ERR("Unrecoverable error\n"); 632 + /* What should we do here? Reset? */ 633 + } 634 + if (intstat & HCINT_RHSC) { 635 + isp116x->rhstatus = 636 + isp116x_read_reg32(isp116x, HCRHSTATUS); 637 + isp116x->rhport[0] = 638 + isp116x_read_reg32(isp116x, HCRHPORT1); 639 + isp116x->rhport[1] = 640 + isp116x_read_reg32(isp116x, HCRHPORT2); 641 + } 642 + if (intstat & HCINT_RD) { 643 + DBG("---- remote wakeup\n"); 644 + schedule_work(&isp116x->rh_resume); 645 + ret = IRQ_HANDLED; 646 + } 647 + irqstat &= ~HCuPINT_OPR; 648 + ret = IRQ_HANDLED; 649 + } 650 + 651 + if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) { 652 + start_atl_transfers(isp116x); 653 + } 654 + 655 + isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb); 656 + spin_unlock(&isp116x->lock); 657 + return ret; 658 + } 659 + 660 + /*-----------------------------------------------------------------*/ 661 + 662 + /* usb 1.1 says max 90% of a frame is available for periodic transfers. 663 + * this driver doesn't promise that much since it's got to handle an 664 + * IRQ per packet; irq handling latencies also use up that time. 665 + */ 666 + 667 + /* out of 1000 us */ 668 + #define MAX_PERIODIC_LOAD 600 669 + static int balance(struct isp116x *isp116x, u16 period, u16 load) 670 + { 671 + int i, branch = -ENOSPC; 672 + 673 + /* search for the least loaded schedule branch of that period 674 + which has enough bandwidth left unreserved. */ 675 + for (i = 0; i < period; i++) { 676 + if (branch < 0 || isp116x->load[branch] > isp116x->load[i]) { 677 + int j; 678 + 679 + for (j = i; j < PERIODIC_SIZE; j += period) { 680 + if ((isp116x->load[j] + load) 681 + > MAX_PERIODIC_LOAD) 682 + break; 683 + } 684 + if (j < PERIODIC_SIZE) 685 + continue; 686 + branch = i; 687 + } 688 + } 689 + return branch; 690 + } 691 + 692 + /* NB! ALL the code above this point runs with isp116x->lock 693 + held, irqs off 694 + */ 695 + 696 + /*-----------------------------------------------------------------*/ 697 + 698 + static int isp116x_urb_enqueue(struct usb_hcd *hcd, 699 + struct usb_host_endpoint *hep, struct urb *urb, 700 + int mem_flags) 701 + { 702 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 703 + struct usb_device *udev = urb->dev; 704 + unsigned int pipe = urb->pipe; 705 + int is_out = !usb_pipein(pipe); 706 + int type = usb_pipetype(pipe); 707 + int epnum = usb_pipeendpoint(pipe); 708 + struct isp116x_ep *ep = NULL; 709 + unsigned long flags; 710 + int i; 711 + int ret = 0; 712 + 713 + urb_dbg(urb, "Enqueue"); 714 + 715 + if (type == PIPE_ISOCHRONOUS) { 716 + ERR("Isochronous transfers not supported\n"); 717 + urb_dbg(urb, "Refused to enqueue"); 718 + return -ENXIO; 719 + } 720 + /* avoid all allocations within spinlocks: request or endpoint */ 721 + if (!hep->hcpriv) { 722 + ep = kcalloc(1, sizeof *ep, (__force unsigned)mem_flags); 723 + if (!ep) 724 + return -ENOMEM; 725 + } 726 + 727 + spin_lock_irqsave(&isp116x->lock, flags); 728 + if (!HC_IS_RUNNING(hcd->state)) { 729 + ret = -ENODEV; 730 + goto fail; 731 + } 732 + 733 + if (hep->hcpriv) 734 + ep = hep->hcpriv; 735 + else { 736 + INIT_LIST_HEAD(&ep->schedule); 737 + ep->udev = usb_get_dev(udev); 738 + ep->epnum = epnum; 739 + ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out); 740 + usb_settoggle(udev, epnum, is_out, 0); 741 + 742 + if (type == PIPE_CONTROL) { 743 + ep->nextpid = USB_PID_SETUP; 744 + } else if (is_out) { 745 + ep->nextpid = USB_PID_OUT; 746 + } else { 747 + ep->nextpid = USB_PID_IN; 748 + } 749 + 750 + if (urb->interval) { 751 + /* 752 + With INT URBs submitted, the driver works with SOF 753 + interrupt enabled and ATL interrupt disabled. After 754 + the PTDs are written to fifo ram, the chip starts 755 + fifo processing and usb transfers after the next 756 + SOF and continues until the transfers are finished 757 + (succeeded or failed) or the frame ends. Therefore, 758 + the transfers occur only in every second frame, 759 + while fifo reading/writing and data processing 760 + occur in every other second frame. */ 761 + if (urb->interval < 2) 762 + urb->interval = 2; 763 + if (urb->interval > 2 * PERIODIC_SIZE) 764 + urb->interval = 2 * PERIODIC_SIZE; 765 + ep->period = urb->interval >> 1; 766 + ep->branch = PERIODIC_SIZE; 767 + ep->load = usb_calc_bus_time(udev->speed, 768 + !is_out, 769 + (type == PIPE_ISOCHRONOUS), 770 + usb_maxpacket(udev, pipe, 771 + is_out)) / 772 + 1000; 773 + } 774 + hep->hcpriv = ep; 775 + ep->hep = hep; 776 + } 777 + 778 + /* maybe put endpoint into schedule */ 779 + switch (type) { 780 + case PIPE_CONTROL: 781 + case PIPE_BULK: 782 + if (list_empty(&ep->schedule)) 783 + list_add_tail(&ep->schedule, &isp116x->async); 784 + break; 785 + case PIPE_INTERRUPT: 786 + urb->interval = ep->period; 787 + ep->length = min((int)ep->maxpacket, 788 + urb->transfer_buffer_length); 789 + 790 + /* urb submitted for already existing endpoint */ 791 + if (ep->branch < PERIODIC_SIZE) 792 + break; 793 + 794 + ret = ep->branch = balance(isp116x, ep->period, ep->load); 795 + if (ret < 0) 796 + goto fail; 797 + ret = 0; 798 + 799 + urb->start_frame = (isp116x->fmindex & (PERIODIC_SIZE - 1)) 800 + + ep->branch; 801 + 802 + /* sort each schedule branch by period (slow before fast) 803 + to share the faster parts of the tree without needing 804 + dummy/placeholder nodes */ 805 + DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch); 806 + for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) { 807 + struct isp116x_ep **prev = &isp116x->periodic[i]; 808 + struct isp116x_ep *here = *prev; 809 + 810 + while (here && ep != here) { 811 + if (ep->period > here->period) 812 + break; 813 + prev = &here->next; 814 + here = *prev; 815 + } 816 + if (ep != here) { 817 + ep->next = here; 818 + *prev = ep; 819 + } 820 + isp116x->load[i] += ep->load; 821 + } 822 + hcd->self.bandwidth_allocated += ep->load / ep->period; 823 + 824 + /* switch over to SOFint */ 825 + if (!isp116x->periodic_count++) { 826 + isp116x->irqenb &= ~HCuPINT_ATL; 827 + isp116x->irqenb |= HCuPINT_SOF; 828 + isp116x_write_reg16(isp116x, HCuPINTENB, 829 + isp116x->irqenb); 830 + } 831 + } 832 + 833 + /* in case of unlink-during-submit */ 834 + spin_lock(&urb->lock); 835 + if (urb->status != -EINPROGRESS) { 836 + spin_unlock(&urb->lock); 837 + finish_request(isp116x, ep, urb, NULL); 838 + ret = 0; 839 + goto fail; 840 + } 841 + urb->hcpriv = hep; 842 + spin_unlock(&urb->lock); 843 + start_atl_transfers(isp116x); 844 + 845 + fail: 846 + spin_unlock_irqrestore(&isp116x->lock, flags); 847 + return ret; 848 + } 849 + 850 + /* 851 + Dequeue URBs. 852 + */ 853 + static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 854 + { 855 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 856 + struct usb_host_endpoint *hep; 857 + struct isp116x_ep *ep, *ep_act; 858 + unsigned long flags; 859 + 860 + spin_lock_irqsave(&isp116x->lock, flags); 861 + hep = urb->hcpriv; 862 + /* URB already unlinked (or never linked)? */ 863 + if (!hep) { 864 + spin_unlock_irqrestore(&isp116x->lock, flags); 865 + return 0; 866 + } 867 + ep = hep->hcpriv; 868 + WARN_ON(hep != ep->hep); 869 + 870 + /* In front of queue? */ 871 + if (ep->hep->urb_list.next == &urb->urb_list) 872 + /* active? */ 873 + for (ep_act = isp116x->atl_active; ep_act; 874 + ep_act = ep_act->active) 875 + if (ep_act == ep) { 876 + VDBG("dequeue, urb %p active; wait for irq\n", 877 + urb); 878 + urb = NULL; 879 + break; 880 + } 881 + 882 + if (urb) 883 + finish_request(isp116x, ep, urb, NULL); 884 + 885 + spin_unlock_irqrestore(&isp116x->lock, flags); 886 + return 0; 887 + } 888 + 889 + static void isp116x_endpoint_disable(struct usb_hcd *hcd, 890 + struct usb_host_endpoint *hep) 891 + { 892 + int i; 893 + struct isp116x_ep *ep = hep->hcpriv;; 894 + 895 + if (!ep) 896 + return; 897 + 898 + /* assume we'd just wait for the irq */ 899 + for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++) 900 + msleep(3); 901 + if (!list_empty(&hep->urb_list)) 902 + WARN("ep %p not empty?\n", ep); 903 + 904 + usb_put_dev(ep->udev); 905 + kfree(ep); 906 + hep->hcpriv = NULL; 907 + } 908 + 909 + static int isp116x_get_frame(struct usb_hcd *hcd) 910 + { 911 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 912 + u32 fmnum; 913 + unsigned long flags; 914 + 915 + spin_lock_irqsave(&isp116x->lock, flags); 916 + fmnum = isp116x_read_reg32(isp116x, HCFMNUM); 917 + spin_unlock_irqrestore(&isp116x->lock, flags); 918 + return (int)fmnum; 919 + } 920 + 921 + /*----------------------------------------------------------------*/ 922 + 923 + /* 924 + Adapted from ohci-hub.c. Currently we don't support autosuspend. 925 + */ 926 + static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf) 927 + { 928 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 929 + int ports, i, changed = 0; 930 + 931 + if (!HC_IS_RUNNING(hcd->state)) 932 + return -ESHUTDOWN; 933 + 934 + ports = isp116x->rhdesca & RH_A_NDP; 935 + 936 + /* init status */ 937 + if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC)) 938 + buf[0] = changed = 1; 939 + else 940 + buf[0] = 0; 941 + 942 + for (i = 0; i < ports; i++) { 943 + u32 status = isp116x->rhport[i]; 944 + 945 + if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 946 + | RH_PS_OCIC | RH_PS_PRSC)) { 947 + changed = 1; 948 + buf[0] |= 1 << (i + 1); 949 + continue; 950 + } 951 + } 952 + return changed; 953 + } 954 + 955 + static void isp116x_hub_descriptor(struct isp116x *isp116x, 956 + struct usb_hub_descriptor *desc) 957 + { 958 + u32 reg = isp116x->rhdesca; 959 + 960 + desc->bDescriptorType = 0x29; 961 + desc->bDescLength = 9; 962 + desc->bHubContrCurrent = 0; 963 + desc->bNbrPorts = (u8) (reg & 0x3); 964 + /* Power switching, device type, overcurrent. */ 965 + desc->wHubCharacteristics = 966 + (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f)); 967 + desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff); 968 + /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ 969 + desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1; 970 + desc->bitmap[1] = ~0; 971 + } 972 + 973 + /* Perform reset of a given port. 974 + It would be great to just start the reset and let the 975 + USB core to clear the reset in due time. However, 976 + root hub ports should be reset for at least 50 ms, while 977 + our chip stays in reset for about 10 ms. I.e., we must 978 + repeatedly reset it ourself here. 979 + */ 980 + static inline void root_port_reset(struct isp116x *isp116x, unsigned port) 981 + { 982 + u32 tmp; 983 + unsigned long flags, t; 984 + 985 + /* Root hub reset should be 50 ms, but some devices 986 + want it even longer. */ 987 + t = jiffies + msecs_to_jiffies(100); 988 + 989 + while (time_before(jiffies, t)) { 990 + spin_lock_irqsave(&isp116x->lock, flags); 991 + /* spin until any current reset finishes */ 992 + for (;;) { 993 + tmp = isp116x_read_reg32(isp116x, port ? 994 + HCRHPORT2 : HCRHPORT1); 995 + if (!(tmp & RH_PS_PRS)) 996 + break; 997 + udelay(500); 998 + } 999 + /* Don't reset a disconnected port */ 1000 + if (!(tmp & RH_PS_CCS)) { 1001 + spin_unlock_irqrestore(&isp116x->lock, flags); 1002 + break; 1003 + } 1004 + /* Reset lasts 10ms (claims datasheet) */ 1005 + isp116x_write_reg32(isp116x, port ? HCRHPORT2 : 1006 + HCRHPORT1, (RH_PS_PRS)); 1007 + spin_unlock_irqrestore(&isp116x->lock, flags); 1008 + msleep(10); 1009 + } 1010 + } 1011 + 1012 + /* Adapted from ohci-hub.c */ 1013 + static int isp116x_hub_control(struct usb_hcd *hcd, 1014 + u16 typeReq, 1015 + u16 wValue, u16 wIndex, char *buf, u16 wLength) 1016 + { 1017 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 1018 + int ret = 0; 1019 + unsigned long flags; 1020 + int ports = isp116x->rhdesca & RH_A_NDP; 1021 + u32 tmp = 0; 1022 + 1023 + switch (typeReq) { 1024 + case ClearHubFeature: 1025 + DBG("ClearHubFeature: "); 1026 + switch (wValue) { 1027 + case C_HUB_OVER_CURRENT: 1028 + DBG("C_HUB_OVER_CURRENT\n"); 1029 + spin_lock_irqsave(&isp116x->lock, flags); 1030 + isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC); 1031 + spin_unlock_irqrestore(&isp116x->lock, flags); 1032 + case C_HUB_LOCAL_POWER: 1033 + DBG("C_HUB_LOCAL_POWER\n"); 1034 + break; 1035 + default: 1036 + goto error; 1037 + } 1038 + break; 1039 + case SetHubFeature: 1040 + DBG("SetHubFeature: "); 1041 + switch (wValue) { 1042 + case C_HUB_OVER_CURRENT: 1043 + case C_HUB_LOCAL_POWER: 1044 + DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n"); 1045 + break; 1046 + default: 1047 + goto error; 1048 + } 1049 + break; 1050 + case GetHubDescriptor: 1051 + DBG("GetHubDescriptor\n"); 1052 + isp116x_hub_descriptor(isp116x, 1053 + (struct usb_hub_descriptor *)buf); 1054 + break; 1055 + case GetHubStatus: 1056 + DBG("GetHubStatus\n"); 1057 + *(__le32 *) buf = cpu_to_le32(0); 1058 + break; 1059 + case GetPortStatus: 1060 + DBG("GetPortStatus\n"); 1061 + if (!wIndex || wIndex > ports) 1062 + goto error; 1063 + tmp = isp116x->rhport[--wIndex]; 1064 + *(__le32 *) buf = cpu_to_le32(tmp); 1065 + DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp); 1066 + break; 1067 + case ClearPortFeature: 1068 + DBG("ClearPortFeature: "); 1069 + if (!wIndex || wIndex > ports) 1070 + goto error; 1071 + wIndex--; 1072 + 1073 + switch (wValue) { 1074 + case USB_PORT_FEAT_ENABLE: 1075 + DBG("USB_PORT_FEAT_ENABLE\n"); 1076 + tmp = RH_PS_CCS; 1077 + break; 1078 + case USB_PORT_FEAT_C_ENABLE: 1079 + DBG("USB_PORT_FEAT_C_ENABLE\n"); 1080 + tmp = RH_PS_PESC; 1081 + break; 1082 + case USB_PORT_FEAT_SUSPEND: 1083 + DBG("USB_PORT_FEAT_SUSPEND\n"); 1084 + tmp = RH_PS_POCI; 1085 + break; 1086 + case USB_PORT_FEAT_C_SUSPEND: 1087 + DBG("USB_PORT_FEAT_C_SUSPEND\n"); 1088 + tmp = RH_PS_PSSC; 1089 + break; 1090 + case USB_PORT_FEAT_POWER: 1091 + DBG("USB_PORT_FEAT_POWER\n"); 1092 + tmp = RH_PS_LSDA; 1093 + break; 1094 + case USB_PORT_FEAT_C_CONNECTION: 1095 + DBG("USB_PORT_FEAT_C_CONNECTION\n"); 1096 + tmp = RH_PS_CSC; 1097 + break; 1098 + case USB_PORT_FEAT_C_OVER_CURRENT: 1099 + DBG("USB_PORT_FEAT_C_OVER_CURRENT\n"); 1100 + tmp = RH_PS_OCIC; 1101 + break; 1102 + case USB_PORT_FEAT_C_RESET: 1103 + DBG("USB_PORT_FEAT_C_RESET\n"); 1104 + tmp = RH_PS_PRSC; 1105 + break; 1106 + default: 1107 + goto error; 1108 + } 1109 + spin_lock_irqsave(&isp116x->lock, flags); 1110 + isp116x_write_reg32(isp116x, wIndex 1111 + ? HCRHPORT2 : HCRHPORT1, tmp); 1112 + isp116x->rhport[wIndex] = 1113 + isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1); 1114 + spin_unlock_irqrestore(&isp116x->lock, flags); 1115 + break; 1116 + case SetPortFeature: 1117 + DBG("SetPortFeature: "); 1118 + if (!wIndex || wIndex > ports) 1119 + goto error; 1120 + wIndex--; 1121 + switch (wValue) { 1122 + case USB_PORT_FEAT_SUSPEND: 1123 + DBG("USB_PORT_FEAT_SUSPEND\n"); 1124 + spin_lock_irqsave(&isp116x->lock, flags); 1125 + isp116x_write_reg32(isp116x, wIndex 1126 + ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS); 1127 + break; 1128 + case USB_PORT_FEAT_POWER: 1129 + DBG("USB_PORT_FEAT_POWER\n"); 1130 + spin_lock_irqsave(&isp116x->lock, flags); 1131 + isp116x_write_reg32(isp116x, wIndex 1132 + ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS); 1133 + break; 1134 + case USB_PORT_FEAT_RESET: 1135 + DBG("USB_PORT_FEAT_RESET\n"); 1136 + root_port_reset(isp116x, wIndex); 1137 + spin_lock_irqsave(&isp116x->lock, flags); 1138 + break; 1139 + default: 1140 + goto error; 1141 + } 1142 + isp116x->rhport[wIndex] = 1143 + isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1); 1144 + spin_unlock_irqrestore(&isp116x->lock, flags); 1145 + break; 1146 + 1147 + default: 1148 + error: 1149 + /* "protocol stall" on error */ 1150 + DBG("PROTOCOL STALL\n"); 1151 + ret = -EPIPE; 1152 + } 1153 + return ret; 1154 + } 1155 + 1156 + #ifdef CONFIG_PM 1157 + 1158 + static int isp116x_hub_suspend(struct usb_hcd *hcd) 1159 + { 1160 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 1161 + unsigned long flags; 1162 + u32 val; 1163 + int ret = 0; 1164 + 1165 + spin_lock_irqsave(&isp116x->lock, flags); 1166 + 1167 + val = isp116x_read_reg32(isp116x, HCCONTROL); 1168 + switch (val & HCCONTROL_HCFS) { 1169 + case HCCONTROL_USB_OPER: 1170 + hcd->state = HC_STATE_QUIESCING; 1171 + val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE); 1172 + val |= HCCONTROL_USB_SUSPEND; 1173 + if (hcd->remote_wakeup) 1174 + val |= HCCONTROL_RWE; 1175 + /* Wait for usb transfers to finish */ 1176 + mdelay(2); 1177 + isp116x_write_reg32(isp116x, HCCONTROL, val); 1178 + hcd->state = HC_STATE_SUSPENDED; 1179 + /* Wait for devices to suspend */ 1180 + mdelay(5); 1181 + case HCCONTROL_USB_SUSPEND: 1182 + break; 1183 + case HCCONTROL_USB_RESUME: 1184 + isp116x_write_reg32(isp116x, HCCONTROL, 1185 + (val & ~HCCONTROL_HCFS) | 1186 + HCCONTROL_USB_RESET); 1187 + case HCCONTROL_USB_RESET: 1188 + ret = -EBUSY; 1189 + break; 1190 + default: 1191 + ret = -EINVAL; 1192 + } 1193 + 1194 + spin_unlock_irqrestore(&isp116x->lock, flags); 1195 + return ret; 1196 + } 1197 + 1198 + static int isp116x_hub_resume(struct usb_hcd *hcd) 1199 + { 1200 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 1201 + u32 val; 1202 + int ret = -EINPROGRESS; 1203 + 1204 + msleep(5); 1205 + spin_lock_irq(&isp116x->lock); 1206 + 1207 + val = isp116x_read_reg32(isp116x, HCCONTROL); 1208 + switch (val & HCCONTROL_HCFS) { 1209 + case HCCONTROL_USB_SUSPEND: 1210 + val &= ~HCCONTROL_HCFS; 1211 + val |= HCCONTROL_USB_RESUME; 1212 + isp116x_write_reg32(isp116x, HCCONTROL, val); 1213 + case HCCONTROL_USB_RESUME: 1214 + break; 1215 + case HCCONTROL_USB_OPER: 1216 + /* Without setting power_state here the 1217 + SUSPENDED state won't be removed from 1218 + sysfs/usbN/power.state as a response to remote 1219 + wakeup. Maybe in the future. */ 1220 + hcd->self.root_hub->dev.power.power_state = PMSG_ON; 1221 + ret = 0; 1222 + break; 1223 + default: 1224 + ret = -EBUSY; 1225 + } 1226 + 1227 + if (ret != -EINPROGRESS) { 1228 + spin_unlock_irq(&isp116x->lock); 1229 + return ret; 1230 + } 1231 + 1232 + val = isp116x->rhdesca & RH_A_NDP; 1233 + while (val--) { 1234 + u32 stat = 1235 + isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1); 1236 + /* force global, not selective, resume */ 1237 + if (!(stat & RH_PS_PSS)) 1238 + continue; 1239 + DBG("%s: Resuming port %d\n", __func__, val); 1240 + isp116x_write_reg32(isp116x, RH_PS_POCI, val 1241 + ? HCRHPORT2 : HCRHPORT1); 1242 + } 1243 + spin_unlock_irq(&isp116x->lock); 1244 + 1245 + hcd->state = HC_STATE_RESUMING; 1246 + mdelay(20); 1247 + 1248 + /* Go operational */ 1249 + spin_lock_irq(&isp116x->lock); 1250 + val = isp116x_read_reg32(isp116x, HCCONTROL); 1251 + isp116x_write_reg32(isp116x, HCCONTROL, 1252 + (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER); 1253 + spin_unlock_irq(&isp116x->lock); 1254 + /* see analogous comment above */ 1255 + hcd->self.root_hub->dev.power.power_state = PMSG_ON; 1256 + hcd->state = HC_STATE_RUNNING; 1257 + 1258 + return 0; 1259 + } 1260 + 1261 + static void isp116x_rh_resume(void *_hcd) 1262 + { 1263 + struct usb_hcd *hcd = _hcd; 1264 + 1265 + usb_resume_device(hcd->self.root_hub); 1266 + } 1267 + 1268 + #else 1269 + 1270 + #define isp116x_hub_suspend NULL 1271 + #define isp116x_hub_resume NULL 1272 + 1273 + static void isp116x_rh_resume(void *_hcd) 1274 + { 1275 + } 1276 + 1277 + #endif 1278 + 1279 + /*-----------------------------------------------------------------*/ 1280 + 1281 + #ifdef STUB_DEBUG_FILE 1282 + 1283 + static inline void create_debug_file(struct isp116x *isp116x) 1284 + { 1285 + } 1286 + 1287 + static inline void remove_debug_file(struct isp116x *isp116x) 1288 + { 1289 + } 1290 + 1291 + #else 1292 + 1293 + #include <linux/proc_fs.h> 1294 + #include <linux/seq_file.h> 1295 + 1296 + static void dump_irq(struct seq_file *s, char *label, u16 mask) 1297 + { 1298 + seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask, 1299 + mask & HCuPINT_CLKRDY ? " clkrdy" : "", 1300 + mask & HCuPINT_SUSP ? " susp" : "", 1301 + mask & HCuPINT_OPR ? " opr" : "", 1302 + mask & HCuPINT_AIIEOT ? " eot" : "", 1303 + mask & HCuPINT_ATL ? " atl" : "", 1304 + mask & HCuPINT_SOF ? " sof" : ""); 1305 + } 1306 + 1307 + static void dump_int(struct seq_file *s, char *label, u32 mask) 1308 + { 1309 + seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask, 1310 + mask & HCINT_MIE ? " MIE" : "", 1311 + mask & HCINT_RHSC ? " rhsc" : "", 1312 + mask & HCINT_FNO ? " fno" : "", 1313 + mask & HCINT_UE ? " ue" : "", 1314 + mask & HCINT_RD ? " rd" : "", 1315 + mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : ""); 1316 + } 1317 + 1318 + static int proc_isp116x_show(struct seq_file *s, void *unused) 1319 + { 1320 + struct isp116x *isp116x = s->private; 1321 + struct isp116x_ep *ep; 1322 + struct urb *urb; 1323 + unsigned i; 1324 + char *str; 1325 + 1326 + seq_printf(s, "%s\n%s version %s\n", 1327 + isp116x_to_hcd(isp116x)->product_desc, hcd_name, 1328 + DRIVER_VERSION); 1329 + 1330 + if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) { 1331 + seq_printf(s, "HCD is suspended\n"); 1332 + return 0; 1333 + } 1334 + if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) { 1335 + seq_printf(s, "HCD not running\n"); 1336 + return 0; 1337 + } 1338 + 1339 + spin_lock_irq(&isp116x->lock); 1340 + 1341 + dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB)); 1342 + dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT)); 1343 + dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB)); 1344 + dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT)); 1345 + 1346 + list_for_each_entry(ep, &isp116x->async, schedule) { 1347 + 1348 + switch (ep->nextpid) { 1349 + case USB_PID_IN: 1350 + str = "in"; 1351 + break; 1352 + case USB_PID_OUT: 1353 + str = "out"; 1354 + break; 1355 + case USB_PID_SETUP: 1356 + str = "setup"; 1357 + break; 1358 + case USB_PID_ACK: 1359 + str = "status"; 1360 + break; 1361 + default: 1362 + str = "?"; 1363 + break; 1364 + }; 1365 + seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep, 1366 + ep->epnum, str, ep->maxpacket); 1367 + list_for_each_entry(urb, &ep->hep->urb_list, urb_list) { 1368 + seq_printf(s, " urb%p, %d/%d\n", urb, 1369 + urb->actual_length, 1370 + urb->transfer_buffer_length); 1371 + } 1372 + } 1373 + if (!list_empty(&isp116x->async)) 1374 + seq_printf(s, "\n"); 1375 + 1376 + seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE); 1377 + 1378 + for (i = 0; i < PERIODIC_SIZE; i++) { 1379 + ep = isp116x->periodic[i]; 1380 + if (!ep) 1381 + continue; 1382 + seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]); 1383 + 1384 + /* DUMB: prints shared entries multiple times */ 1385 + do { 1386 + seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n", 1387 + ep->period, ep, 1388 + (ep->udev->speed == 1389 + USB_SPEED_FULL) ? "" : "ls ", 1390 + ep->udev->devnum, ep->epnum, 1391 + (ep->epnum == 1392 + 0) ? "" : ((ep->nextpid == 1393 + USB_PID_IN) ? "in" : "out"), 1394 + ep->maxpacket); 1395 + ep = ep->next; 1396 + } while (ep); 1397 + } 1398 + spin_unlock_irq(&isp116x->lock); 1399 + seq_printf(s, "\n"); 1400 + 1401 + return 0; 1402 + } 1403 + 1404 + static int proc_isp116x_open(struct inode *inode, struct file *file) 1405 + { 1406 + return single_open(file, proc_isp116x_show, PDE(inode)->data); 1407 + } 1408 + 1409 + static struct file_operations proc_ops = { 1410 + .open = proc_isp116x_open, 1411 + .read = seq_read, 1412 + .llseek = seq_lseek, 1413 + .release = single_release, 1414 + }; 1415 + 1416 + /* expect just one isp116x per system */ 1417 + static const char proc_filename[] = "driver/isp116x"; 1418 + 1419 + static void create_debug_file(struct isp116x *isp116x) 1420 + { 1421 + struct proc_dir_entry *pde; 1422 + 1423 + pde = create_proc_entry(proc_filename, 0, NULL); 1424 + if (pde == NULL) 1425 + return; 1426 + 1427 + pde->proc_fops = &proc_ops; 1428 + pde->data = isp116x; 1429 + isp116x->pde = pde; 1430 + } 1431 + 1432 + static void remove_debug_file(struct isp116x *isp116x) 1433 + { 1434 + if (isp116x->pde) 1435 + remove_proc_entry(proc_filename, NULL); 1436 + } 1437 + 1438 + #endif 1439 + 1440 + /*-----------------------------------------------------------------*/ 1441 + 1442 + /* 1443 + Software reset - can be called from any contect. 1444 + */ 1445 + static int isp116x_sw_reset(struct isp116x *isp116x) 1446 + { 1447 + int retries = 15; 1448 + unsigned long flags; 1449 + int ret = 0; 1450 + 1451 + spin_lock_irqsave(&isp116x->lock, flags); 1452 + isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC); 1453 + isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR); 1454 + while (--retries) { 1455 + /* It usually resets within 1 ms */ 1456 + mdelay(1); 1457 + if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR)) 1458 + break; 1459 + } 1460 + if (!retries) { 1461 + ERR("Software reset timeout\n"); 1462 + ret = -ETIME; 1463 + } 1464 + spin_unlock_irqrestore(&isp116x->lock, flags); 1465 + return ret; 1466 + } 1467 + 1468 + /* 1469 + Reset. Tries to perform platform-specific hardware 1470 + reset first; falls back to software reset. 1471 + */ 1472 + static int isp116x_reset(struct usb_hcd *hcd) 1473 + { 1474 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 1475 + unsigned long t; 1476 + u16 clkrdy = 0; 1477 + int ret = 0, timeout = 15 /* ms */ ; 1478 + 1479 + if (isp116x->board && isp116x->board->reset) { 1480 + /* Hardware reset */ 1481 + isp116x->board->reset(hcd->self.controller, 1); 1482 + msleep(10); 1483 + if (isp116x->board->clock) 1484 + isp116x->board->clock(hcd->self.controller, 1); 1485 + msleep(1); 1486 + isp116x->board->reset(hcd->self.controller, 0); 1487 + } else 1488 + ret = isp116x_sw_reset(isp116x); 1489 + 1490 + if (ret) 1491 + return ret; 1492 + 1493 + t = jiffies + msecs_to_jiffies(timeout); 1494 + while (time_before_eq(jiffies, t)) { 1495 + msleep(4); 1496 + spin_lock_irq(&isp116x->lock); 1497 + clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY; 1498 + spin_unlock_irq(&isp116x->lock); 1499 + if (clkrdy) 1500 + break; 1501 + } 1502 + if (!clkrdy) { 1503 + ERR("Clock not ready after 20ms\n"); 1504 + /* After sw_reset the clock won't report to be ready, if 1505 + H_WAKEUP pin is high. */ 1506 + if (!isp116x->board || !isp116x->board->reset) 1507 + ERR("The driver does not support hardware wakeup.\n"); 1508 + ERR("Please make sure that the H_WAKEUP pin " 1509 + "is pulled low!\n"); 1510 + ret = -ENODEV; 1511 + } 1512 + return ret; 1513 + } 1514 + 1515 + static void isp116x_stop(struct usb_hcd *hcd) 1516 + { 1517 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 1518 + unsigned long flags; 1519 + u32 val; 1520 + 1521 + spin_lock_irqsave(&isp116x->lock, flags); 1522 + isp116x_write_reg16(isp116x, HCuPINTENB, 0); 1523 + 1524 + /* Switch off ports' power, some devices don't come up 1525 + after next 'insmod' without this */ 1526 + val = isp116x_read_reg32(isp116x, HCRHDESCA); 1527 + val &= ~(RH_A_NPS | RH_A_PSM); 1528 + isp116x_write_reg32(isp116x, HCRHDESCA, val); 1529 + isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS); 1530 + spin_unlock_irqrestore(&isp116x->lock, flags); 1531 + 1532 + /* Put the chip into reset state */ 1533 + if (isp116x->board && isp116x->board->reset) 1534 + isp116x->board->reset(hcd->self.controller, 0); 1535 + else 1536 + isp116x_sw_reset(isp116x); 1537 + 1538 + /* Stop the clock */ 1539 + if (isp116x->board && isp116x->board->clock) 1540 + isp116x->board->clock(hcd->self.controller, 0); 1541 + } 1542 + 1543 + /* 1544 + Configure the chip. The chip must be successfully reset by now. 1545 + */ 1546 + static int isp116x_start(struct usb_hcd *hcd) 1547 + { 1548 + struct isp116x *isp116x = hcd_to_isp116x(hcd); 1549 + struct isp116x_platform_data *board = isp116x->board; 1550 + u32 val; 1551 + unsigned long flags; 1552 + 1553 + spin_lock_irqsave(&isp116x->lock, flags); 1554 + 1555 + /* clear interrupt status and disable all interrupt sources */ 1556 + isp116x_write_reg16(isp116x, HCuPINT, 0xff); 1557 + isp116x_write_reg16(isp116x, HCuPINTENB, 0); 1558 + 1559 + val = isp116x_read_reg16(isp116x, HCCHIPID); 1560 + if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) { 1561 + ERR("Invalid chip ID %04x\n", val); 1562 + spin_unlock_irqrestore(&isp116x->lock, flags); 1563 + return -ENODEV; 1564 + } 1565 + 1566 + isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE); 1567 + isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE); 1568 + 1569 + /* ----- HW conf */ 1570 + val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1); 1571 + if (board->sel15Kres) 1572 + val |= HCHWCFG_15KRSEL; 1573 + /* Remote wakeup won't work without working clock */ 1574 + if (board->clknotstop || board->remote_wakeup_enable) 1575 + val |= HCHWCFG_CLKNOTSTOP; 1576 + if (board->oc_enable) 1577 + val |= HCHWCFG_ANALOG_OC; 1578 + if (board->int_act_high) 1579 + val |= HCHWCFG_INT_POL; 1580 + if (board->int_edge_triggered) 1581 + val |= HCHWCFG_INT_TRIGGER; 1582 + isp116x_write_reg16(isp116x, HCHWCFG, val); 1583 + 1584 + /* ----- Root hub conf */ 1585 + val = 0; 1586 + /* AN10003_1.pdf recommends NPS to be always 1 */ 1587 + if (board->no_power_switching) 1588 + val |= RH_A_NPS; 1589 + if (board->power_switching_mode) 1590 + val |= RH_A_PSM; 1591 + if (board->potpg) 1592 + val |= (board->potpg << 24) & RH_A_POTPGT; 1593 + else 1594 + val |= (25 << 24) & RH_A_POTPGT; 1595 + isp116x_write_reg32(isp116x, HCRHDESCA, val); 1596 + isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA); 1597 + 1598 + val = RH_B_PPCM; 1599 + isp116x_write_reg32(isp116x, HCRHDESCB, val); 1600 + isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB); 1601 + 1602 + val = 0; 1603 + if (board->remote_wakeup_enable) { 1604 + hcd->can_wakeup = 1; 1605 + val |= RH_HS_DRWE; 1606 + } 1607 + isp116x_write_reg32(isp116x, HCRHSTATUS, val); 1608 + isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS); 1609 + 1610 + isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf); 1611 + 1612 + hcd->state = HC_STATE_RUNNING; 1613 + 1614 + /* Set up interrupts */ 1615 + isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE; 1616 + if (board->remote_wakeup_enable) 1617 + isp116x->intenb |= HCINT_RD; 1618 + isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */ 1619 + isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb); 1620 + isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb); 1621 + 1622 + /* Go operational */ 1623 + val = HCCONTROL_USB_OPER; 1624 + /* Remote wakeup connected - NOT SUPPORTED */ 1625 + /* if (board->remote_wakeup_connected) 1626 + val |= HCCONTROL_RWC; */ 1627 + if (board->remote_wakeup_enable) 1628 + val |= HCCONTROL_RWE; 1629 + isp116x_write_reg32(isp116x, HCCONTROL, val); 1630 + 1631 + /* Disable ports to avoid race in device enumeration */ 1632 + isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS); 1633 + isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS); 1634 + 1635 + isp116x_show_regs(isp116x); 1636 + spin_unlock_irqrestore(&isp116x->lock, flags); 1637 + return 0; 1638 + } 1639 + 1640 + /*-----------------------------------------------------------------*/ 1641 + 1642 + static struct hc_driver isp116x_hc_driver = { 1643 + .description = hcd_name, 1644 + .product_desc = "ISP116x Host Controller", 1645 + .hcd_priv_size = sizeof(struct isp116x), 1646 + 1647 + .irq = isp116x_irq, 1648 + .flags = HCD_USB11, 1649 + 1650 + .reset = isp116x_reset, 1651 + .start = isp116x_start, 1652 + .stop = isp116x_stop, 1653 + 1654 + .urb_enqueue = isp116x_urb_enqueue, 1655 + .urb_dequeue = isp116x_urb_dequeue, 1656 + .endpoint_disable = isp116x_endpoint_disable, 1657 + 1658 + .get_frame_number = isp116x_get_frame, 1659 + 1660 + .hub_status_data = isp116x_hub_status_data, 1661 + .hub_control = isp116x_hub_control, 1662 + .hub_suspend = isp116x_hub_suspend, 1663 + .hub_resume = isp116x_hub_resume, 1664 + }; 1665 + 1666 + /*----------------------------------------------------------------*/ 1667 + 1668 + static int __init_or_module isp116x_remove(struct device *dev) 1669 + { 1670 + struct usb_hcd *hcd = dev_get_drvdata(dev); 1671 + struct isp116x *isp116x; 1672 + struct platform_device *pdev; 1673 + struct resource *res; 1674 + 1675 + if(!hcd) 1676 + return 0; 1677 + isp116x = hcd_to_isp116x(hcd); 1678 + pdev = container_of(dev, struct platform_device, dev); 1679 + remove_debug_file(isp116x); 1680 + usb_remove_hcd(hcd); 1681 + 1682 + iounmap(isp116x->data_reg); 1683 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1684 + release_mem_region(res->start, 2); 1685 + iounmap(isp116x->addr_reg); 1686 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1687 + release_mem_region(res->start, 2); 1688 + 1689 + usb_put_hcd(hcd); 1690 + return 0; 1691 + } 1692 + 1693 + #define resource_len(r) (((r)->end - (r)->start) + 1) 1694 + 1695 + static int __init isp116x_probe(struct device *dev) 1696 + { 1697 + struct usb_hcd *hcd; 1698 + struct isp116x *isp116x; 1699 + struct platform_device *pdev; 1700 + struct resource *addr, *data; 1701 + void __iomem *addr_reg; 1702 + void __iomem *data_reg; 1703 + int irq; 1704 + int ret = 0; 1705 + 1706 + pdev = container_of(dev, struct platform_device, dev); 1707 + if (pdev->num_resources < 3) { 1708 + ret = -ENODEV; 1709 + goto err1; 1710 + } 1711 + 1712 + data = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1713 + addr = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1714 + irq = platform_get_irq(pdev, 0); 1715 + if (!addr || !data || irq < 0) { 1716 + ret = -ENODEV; 1717 + goto err1; 1718 + } 1719 + 1720 + if (dev->dma_mask) { 1721 + DBG("DMA not supported\n"); 1722 + ret = -EINVAL; 1723 + goto err1; 1724 + } 1725 + 1726 + if (!request_mem_region(addr->start, 2, hcd_name)) { 1727 + ret = -EBUSY; 1728 + goto err1; 1729 + } 1730 + addr_reg = ioremap(addr->start, resource_len(addr)); 1731 + if (addr_reg == NULL) { 1732 + ret = -ENOMEM; 1733 + goto err2; 1734 + } 1735 + if (!request_mem_region(data->start, 2, hcd_name)) { 1736 + ret = -EBUSY; 1737 + goto err3; 1738 + } 1739 + data_reg = ioremap(data->start, resource_len(data)); 1740 + if (data_reg == NULL) { 1741 + ret = -ENOMEM; 1742 + goto err4; 1743 + } 1744 + 1745 + /* allocate and initialize hcd */ 1746 + hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id); 1747 + if (!hcd) { 1748 + ret = -ENOMEM; 1749 + goto err5; 1750 + } 1751 + /* this rsrc_start is bogus */ 1752 + hcd->rsrc_start = addr->start; 1753 + isp116x = hcd_to_isp116x(hcd); 1754 + isp116x->data_reg = data_reg; 1755 + isp116x->addr_reg = addr_reg; 1756 + spin_lock_init(&isp116x->lock); 1757 + INIT_LIST_HEAD(&isp116x->async); 1758 + INIT_WORK(&isp116x->rh_resume, isp116x_rh_resume, hcd); 1759 + isp116x->board = dev->platform_data; 1760 + 1761 + if (!isp116x->board) { 1762 + ERR("Platform data structure not initialized\n"); 1763 + ret = -ENODEV; 1764 + goto err6; 1765 + } 1766 + if (isp116x_check_platform_delay(isp116x)) { 1767 + ERR("USE_PLATFORM_DELAY defined, but delay function not " 1768 + "implemented.\n"); 1769 + ERR("See comments in drivers/usb/host/isp116x-hcd.c\n"); 1770 + ret = -ENODEV; 1771 + goto err6; 1772 + } 1773 + 1774 + ret = usb_add_hcd(hcd, irq, SA_INTERRUPT); 1775 + if (ret != 0) 1776 + goto err6; 1777 + 1778 + create_debug_file(isp116x); 1779 + return 0; 1780 + 1781 + err6: 1782 + usb_put_hcd(hcd); 1783 + err5: 1784 + iounmap(data_reg); 1785 + err4: 1786 + release_mem_region(data->start, 2); 1787 + err3: 1788 + iounmap(addr_reg); 1789 + err2: 1790 + release_mem_region(addr->start, 2); 1791 + err1: 1792 + ERR("init error, %d\n", ret); 1793 + return ret; 1794 + } 1795 + 1796 + #ifdef CONFIG_PM 1797 + /* 1798 + Suspend of platform device 1799 + */ 1800 + static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase) 1801 + { 1802 + int ret = 0; 1803 + struct usb_hcd *hcd = dev_get_drvdata(dev); 1804 + 1805 + VDBG("%s: state %x, phase %x\n", __func__, state, phase); 1806 + 1807 + if (phase != SUSPEND_DISABLE && phase != SUSPEND_POWER_DOWN) 1808 + return 0; 1809 + 1810 + ret = usb_suspend_device(hcd->self.root_hub, state); 1811 + if (!ret) { 1812 + dev->power.power_state = state; 1813 + INFO("%s suspended\n", (char *)hcd_name); 1814 + } else 1815 + ERR("%s suspend failed\n", (char *)hcd_name); 1816 + 1817 + return ret; 1818 + } 1819 + 1820 + /* 1821 + Resume platform device 1822 + */ 1823 + static int isp116x_resume(struct device *dev, u32 phase) 1824 + { 1825 + int ret = 0; 1826 + struct usb_hcd *hcd = dev_get_drvdata(dev); 1827 + 1828 + VDBG("%s: state %x, phase %x\n", __func__, dev->power.power_state, 1829 + phase); 1830 + if (phase != RESUME_POWER_ON) 1831 + return 0; 1832 + 1833 + ret = usb_resume_device(hcd->self.root_hub); 1834 + if (!ret) { 1835 + dev->power.power_state = PMSG_ON; 1836 + VDBG("%s resumed\n", (char *)hcd_name); 1837 + } 1838 + return ret; 1839 + } 1840 + 1841 + #else 1842 + 1843 + #define isp116x_suspend NULL 1844 + #define isp116x_resume NULL 1845 + 1846 + #endif 1847 + 1848 + static struct device_driver isp116x_driver = { 1849 + .name = (char *)hcd_name, 1850 + .bus = &platform_bus_type, 1851 + .probe = isp116x_probe, 1852 + .remove = isp116x_remove, 1853 + .suspend = isp116x_suspend, 1854 + .resume = isp116x_resume, 1855 + }; 1856 + 1857 + /*-----------------------------------------------------------------*/ 1858 + 1859 + static int __init isp116x_init(void) 1860 + { 1861 + if (usb_disabled()) 1862 + return -ENODEV; 1863 + 1864 + INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION); 1865 + return driver_register(&isp116x_driver); 1866 + } 1867 + 1868 + module_init(isp116x_init); 1869 + 1870 + static void __exit isp116x_cleanup(void) 1871 + { 1872 + driver_unregister(&isp116x_driver); 1873 + } 1874 + 1875 + module_exit(isp116x_cleanup);
+583
drivers/usb/host/isp116x.h
··· 1 + /* 2 + * ISP116x register declarations and HCD data structures 3 + * 4 + * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee> 5 + * Portions: 6 + * Copyright (C) 2004 Lothar Wassmann 7 + * Copyright (C) 2004 Psion Teklogix 8 + * Copyright (C) 2004 David Brownell 9 + */ 10 + 11 + /* us of 1ms frame */ 12 + #define MAX_LOAD_LIMIT 850 13 + 14 + /* Full speed: max # of bytes to transfer for a single urb 15 + at a time must be < 1024 && must be multiple of 64. 16 + 832 allows transfering 4kiB within 5 frames. */ 17 + #define MAX_TRANSFER_SIZE_FULLSPEED 832 18 + 19 + /* Low speed: there is no reason to schedule in very big 20 + chunks; often the requested long transfers are for 21 + string descriptors containing short strings. */ 22 + #define MAX_TRANSFER_SIZE_LOWSPEED 64 23 + 24 + /* Bytetime (us), a rough indication of how much time it 25 + would take to transfer a byte of useful data over USB */ 26 + #define BYTE_TIME_FULLSPEED 1 27 + #define BYTE_TIME_LOWSPEED 20 28 + 29 + /* Buffer sizes */ 30 + #define ISP116x_BUF_SIZE 4096 31 + #define ISP116x_ITL_BUFSIZE 0 32 + #define ISP116x_ATL_BUFSIZE ((ISP116x_BUF_SIZE) - 2*(ISP116x_ITL_BUFSIZE)) 33 + 34 + #define ISP116x_WRITE_OFFSET 0x80 35 + 36 + /*------------ ISP116x registers/bits ------------*/ 37 + #define HCREVISION 0x00 38 + #define HCCONTROL 0x01 39 + #define HCCONTROL_HCFS (3 << 6) /* host controller 40 + functional state */ 41 + #define HCCONTROL_USB_RESET (0 << 6) 42 + #define HCCONTROL_USB_RESUME (1 << 6) 43 + #define HCCONTROL_USB_OPER (2 << 6) 44 + #define HCCONTROL_USB_SUSPEND (3 << 6) 45 + #define HCCONTROL_RWC (1 << 9) /* remote wakeup connected */ 46 + #define HCCONTROL_RWE (1 << 10) /* remote wakeup enable */ 47 + #define HCCMDSTAT 0x02 48 + #define HCCMDSTAT_HCR (1 << 0) /* host controller reset */ 49 + #define HCCMDSTAT_SOC (3 << 16) /* scheduling overrun count */ 50 + #define HCINTSTAT 0x03 51 + #define HCINT_SO (1 << 0) /* scheduling overrun */ 52 + #define HCINT_WDH (1 << 1) /* writeback of done_head */ 53 + #define HCINT_SF (1 << 2) /* start frame */ 54 + #define HCINT_RD (1 << 3) /* resume detect */ 55 + #define HCINT_UE (1 << 4) /* unrecoverable error */ 56 + #define HCINT_FNO (1 << 5) /* frame number overflow */ 57 + #define HCINT_RHSC (1 << 6) /* root hub status change */ 58 + #define HCINT_OC (1 << 30) /* ownership change */ 59 + #define HCINT_MIE (1 << 31) /* master interrupt enable */ 60 + #define HCINTENB 0x04 61 + #define HCINTDIS 0x05 62 + #define HCFMINTVL 0x0d 63 + #define HCFMREM 0x0e 64 + #define HCFMNUM 0x0f 65 + #define HCLSTHRESH 0x11 66 + #define HCRHDESCA 0x12 67 + #define RH_A_NDP (0x3 << 0) /* # downstream ports */ 68 + #define RH_A_PSM (1 << 8) /* power switching mode */ 69 + #define RH_A_NPS (1 << 9) /* no power switching */ 70 + #define RH_A_DT (1 << 10) /* device type (mbz) */ 71 + #define RH_A_OCPM (1 << 11) /* overcurrent protection 72 + mode */ 73 + #define RH_A_NOCP (1 << 12) /* no overcurrent protection */ 74 + #define RH_A_POTPGT (0xff << 24) /* power on -> power good 75 + time */ 76 + #define HCRHDESCB 0x13 77 + #define RH_B_DR (0xffff << 0) /* device removable flags */ 78 + #define RH_B_PPCM (0xffff << 16) /* port power control mask */ 79 + #define HCRHSTATUS 0x14 80 + #define RH_HS_LPS (1 << 0) /* local power status */ 81 + #define RH_HS_OCI (1 << 1) /* over current indicator */ 82 + #define RH_HS_DRWE (1 << 15) /* device remote wakeup 83 + enable */ 84 + #define RH_HS_LPSC (1 << 16) /* local power status change */ 85 + #define RH_HS_OCIC (1 << 17) /* over current indicator 86 + change */ 87 + #define RH_HS_CRWE (1 << 31) /* clear remote wakeup 88 + enable */ 89 + #define HCRHPORT1 0x15 90 + #define RH_PS_CCS (1 << 0) /* current connect status */ 91 + #define RH_PS_PES (1 << 1) /* port enable status */ 92 + #define RH_PS_PSS (1 << 2) /* port suspend status */ 93 + #define RH_PS_POCI (1 << 3) /* port over current 94 + indicator */ 95 + #define RH_PS_PRS (1 << 4) /* port reset status */ 96 + #define RH_PS_PPS (1 << 8) /* port power status */ 97 + #define RH_PS_LSDA (1 << 9) /* low speed device attached */ 98 + #define RH_PS_CSC (1 << 16) /* connect status change */ 99 + #define RH_PS_PESC (1 << 17) /* port enable status change */ 100 + #define RH_PS_PSSC (1 << 18) /* port suspend status 101 + change */ 102 + #define RH_PS_OCIC (1 << 19) /* over current indicator 103 + change */ 104 + #define RH_PS_PRSC (1 << 20) /* port reset status change */ 105 + #define HCRHPORT_CLRMASK (0x1f << 16) 106 + #define HCRHPORT2 0x16 107 + #define HCHWCFG 0x20 108 + #define HCHWCFG_15KRSEL (1 << 12) 109 + #define HCHWCFG_CLKNOTSTOP (1 << 11) 110 + #define HCHWCFG_ANALOG_OC (1 << 10) 111 + #define HCHWCFG_DACK_MODE (1 << 8) 112 + #define HCHWCFG_EOT_POL (1 << 7) 113 + #define HCHWCFG_DACK_POL (1 << 6) 114 + #define HCHWCFG_DREQ_POL (1 << 5) 115 + #define HCHWCFG_DBWIDTH_MASK (0x03 << 3) 116 + #define HCHWCFG_DBWIDTH(n) (((n) << 3) & HCHWCFG_DBWIDTH_MASK) 117 + #define HCHWCFG_INT_POL (1 << 2) 118 + #define HCHWCFG_INT_TRIGGER (1 << 1) 119 + #define HCHWCFG_INT_ENABLE (1 << 0) 120 + #define HCDMACFG 0x21 121 + #define HCDMACFG_BURST_LEN_MASK (0x03 << 5) 122 + #define HCDMACFG_BURST_LEN(n) (((n) << 5) & HCDMACFG_BURST_LEN_MASK) 123 + #define HCDMACFG_BURST_LEN_1 HCDMACFG_BURST_LEN(0) 124 + #define HCDMACFG_BURST_LEN_4 HCDMACFG_BURST_LEN(1) 125 + #define HCDMACFG_BURST_LEN_8 HCDMACFG_BURST_LEN(2) 126 + #define HCDMACFG_DMA_ENABLE (1 << 4) 127 + #define HCDMACFG_BUF_TYPE_MASK (0x07 << 1) 128 + #define HCDMACFG_CTR_SEL (1 << 2) 129 + #define HCDMACFG_ITLATL_SEL (1 << 1) 130 + #define HCDMACFG_DMA_RW_SELECT (1 << 0) 131 + #define HCXFERCTR 0x22 132 + #define HCuPINT 0x24 133 + #define HCuPINT_SOF (1 << 0) 134 + #define HCuPINT_ATL (1 << 1) 135 + #define HCuPINT_AIIEOT (1 << 2) 136 + #define HCuPINT_OPR (1 << 4) 137 + #define HCuPINT_SUSP (1 << 5) 138 + #define HCuPINT_CLKRDY (1 << 6) 139 + #define HCuPINTENB 0x25 140 + #define HCCHIPID 0x27 141 + #define HCCHIPID_MASK 0xff00 142 + #define HCCHIPID_MAGIC 0x6100 143 + #define HCSCRATCH 0x28 144 + #define HCSWRES 0x29 145 + #define HCSWRES_MAGIC 0x00f6 146 + #define HCITLBUFLEN 0x2a 147 + #define HCATLBUFLEN 0x2b 148 + #define HCBUFSTAT 0x2c 149 + #define HCBUFSTAT_ITL0_FULL (1 << 0) 150 + #define HCBUFSTAT_ITL1_FULL (1 << 1) 151 + #define HCBUFSTAT_ATL_FULL (1 << 2) 152 + #define HCBUFSTAT_ITL0_DONE (1 << 3) 153 + #define HCBUFSTAT_ITL1_DONE (1 << 4) 154 + #define HCBUFSTAT_ATL_DONE (1 << 5) 155 + #define HCRDITL0LEN 0x2d 156 + #define HCRDITL1LEN 0x2e 157 + #define HCITLPORT 0x40 158 + #define HCATLPORT 0x41 159 + 160 + /* Philips transfer descriptor */ 161 + struct ptd { 162 + u16 count; 163 + #define PTD_COUNT_MSK (0x3ff << 0) 164 + #define PTD_TOGGLE_MSK (1 << 10) 165 + #define PTD_ACTIVE_MSK (1 << 11) 166 + #define PTD_CC_MSK (0xf << 12) 167 + u16 mps; 168 + #define PTD_MPS_MSK (0x3ff << 0) 169 + #define PTD_SPD_MSK (1 << 10) 170 + #define PTD_LAST_MSK (1 << 11) 171 + #define PTD_EP_MSK (0xf << 12) 172 + u16 len; 173 + #define PTD_LEN_MSK (0x3ff << 0) 174 + #define PTD_DIR_MSK (3 << 10) 175 + #define PTD_DIR_SETUP (0) 176 + #define PTD_DIR_OUT (1) 177 + #define PTD_DIR_IN (2) 178 + #define PTD_B5_5_MSK (1 << 13) 179 + u16 faddr; 180 + #define PTD_FA_MSK (0x7f << 0) 181 + #define PTD_FMT_MSK (1 << 7) 182 + } __attribute__ ((packed, aligned(2))); 183 + 184 + /* PTD accessor macros. */ 185 + #define PTD_GET_COUNT(p) (((p)->count & PTD_COUNT_MSK) >> 0) 186 + #define PTD_COUNT(v) (((v) << 0) & PTD_COUNT_MSK) 187 + #define PTD_GET_TOGGLE(p) (((p)->count & PTD_TOGGLE_MSK) >> 10) 188 + #define PTD_TOGGLE(v) (((v) << 10) & PTD_TOGGLE_MSK) 189 + #define PTD_GET_ACTIVE(p) (((p)->count & PTD_ACTIVE_MSK) >> 11) 190 + #define PTD_ACTIVE(v) (((v) << 11) & PTD_ACTIVE_MSK) 191 + #define PTD_GET_CC(p) (((p)->count & PTD_CC_MSK) >> 12) 192 + #define PTD_CC(v) (((v) << 12) & PTD_CC_MSK) 193 + #define PTD_GET_MPS(p) (((p)->mps & PTD_MPS_MSK) >> 0) 194 + #define PTD_MPS(v) (((v) << 0) & PTD_MPS_MSK) 195 + #define PTD_GET_SPD(p) (((p)->mps & PTD_SPD_MSK) >> 10) 196 + #define PTD_SPD(v) (((v) << 10) & PTD_SPD_MSK) 197 + #define PTD_GET_LAST(p) (((p)->mps & PTD_LAST_MSK) >> 11) 198 + #define PTD_LAST(v) (((v) << 11) & PTD_LAST_MSK) 199 + #define PTD_GET_EP(p) (((p)->mps & PTD_EP_MSK) >> 12) 200 + #define PTD_EP(v) (((v) << 12) & PTD_EP_MSK) 201 + #define PTD_GET_LEN(p) (((p)->len & PTD_LEN_MSK) >> 0) 202 + #define PTD_LEN(v) (((v) << 0) & PTD_LEN_MSK) 203 + #define PTD_GET_DIR(p) (((p)->len & PTD_DIR_MSK) >> 10) 204 + #define PTD_DIR(v) (((v) << 10) & PTD_DIR_MSK) 205 + #define PTD_GET_B5_5(p) (((p)->len & PTD_B5_5_MSK) >> 13) 206 + #define PTD_B5_5(v) (((v) << 13) & PTD_B5_5_MSK) 207 + #define PTD_GET_FA(p) (((p)->faddr & PTD_FA_MSK) >> 0) 208 + #define PTD_FA(v) (((v) << 0) & PTD_FA_MSK) 209 + #define PTD_GET_FMT(p) (((p)->faddr & PTD_FMT_MSK) >> 7) 210 + #define PTD_FMT(v) (((v) << 7) & PTD_FMT_MSK) 211 + 212 + /* Hardware transfer status codes -- CC from ptd->count */ 213 + #define TD_CC_NOERROR 0x00 214 + #define TD_CC_CRC 0x01 215 + #define TD_CC_BITSTUFFING 0x02 216 + #define TD_CC_DATATOGGLEM 0x03 217 + #define TD_CC_STALL 0x04 218 + #define TD_DEVNOTRESP 0x05 219 + #define TD_PIDCHECKFAIL 0x06 220 + #define TD_UNEXPECTEDPID 0x07 221 + #define TD_DATAOVERRUN 0x08 222 + #define TD_DATAUNDERRUN 0x09 223 + /* 0x0A, 0x0B reserved for hardware */ 224 + #define TD_BUFFEROVERRUN 0x0C 225 + #define TD_BUFFERUNDERRUN 0x0D 226 + /* 0x0E, 0x0F reserved for HCD */ 227 + #define TD_NOTACCESSED 0x0F 228 + 229 + /* map PTD status codes (CC) to errno values */ 230 + static const int cc_to_error[16] = { 231 + /* No Error */ 0, 232 + /* CRC Error */ -EILSEQ, 233 + /* Bit Stuff */ -EPROTO, 234 + /* Data Togg */ -EILSEQ, 235 + /* Stall */ -EPIPE, 236 + /* DevNotResp */ -ETIMEDOUT, 237 + /* PIDCheck */ -EPROTO, 238 + /* UnExpPID */ -EPROTO, 239 + /* DataOver */ -EOVERFLOW, 240 + /* DataUnder */ -EREMOTEIO, 241 + /* (for hw) */ -EIO, 242 + /* (for hw) */ -EIO, 243 + /* BufferOver */ -ECOMM, 244 + /* BuffUnder */ -ENOSR, 245 + /* (for HCD) */ -EALREADY, 246 + /* (for HCD) */ -EALREADY 247 + }; 248 + 249 + /*--------------------------------------------------------------*/ 250 + 251 + #define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */ 252 + #define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE) 253 + 254 + struct isp116x { 255 + spinlock_t lock; 256 + struct work_struct rh_resume; 257 + 258 + void __iomem *addr_reg; 259 + void __iomem *data_reg; 260 + 261 + struct isp116x_platform_data *board; 262 + 263 + struct proc_dir_entry *pde; 264 + unsigned long stat1, stat2, stat4, stat8, stat16; 265 + 266 + /* HC registers */ 267 + u32 intenb; /* "OHCI" interrupts */ 268 + u16 irqenb; /* uP interrupts */ 269 + 270 + /* Root hub registers */ 271 + u32 rhdesca; 272 + u32 rhdescb; 273 + u32 rhstatus; 274 + u32 rhport[2]; 275 + 276 + /* async schedule: control, bulk */ 277 + struct list_head async; 278 + 279 + /* periodic schedule: int */ 280 + u16 load[PERIODIC_SIZE]; 281 + struct isp116x_ep *periodic[PERIODIC_SIZE]; 282 + unsigned periodic_count; 283 + u16 fmindex; 284 + 285 + /* Schedule for the current frame */ 286 + struct isp116x_ep *atl_active; 287 + int atl_buflen; 288 + int atl_bufshrt; 289 + int atl_last_dir; 290 + atomic_t atl_finishing; 291 + }; 292 + 293 + static inline struct isp116x *hcd_to_isp116x(struct usb_hcd *hcd) 294 + { 295 + return (struct isp116x *)(hcd->hcd_priv); 296 + } 297 + 298 + static inline struct usb_hcd *isp116x_to_hcd(struct isp116x *isp116x) 299 + { 300 + return container_of((void *)isp116x, struct usb_hcd, hcd_priv); 301 + } 302 + 303 + struct isp116x_ep { 304 + struct usb_host_endpoint *hep; 305 + struct usb_device *udev; 306 + struct ptd ptd; 307 + 308 + u8 maxpacket; 309 + u8 epnum; 310 + u8 nextpid; 311 + u16 error_count; 312 + u16 length; /* of current packet */ 313 + unsigned char *data; /* to databuf */ 314 + /* queue of active EP's (the ones scheduled for the 315 + current frame) */ 316 + struct isp116x_ep *active; 317 + 318 + /* periodic schedule */ 319 + u16 period; 320 + u16 branch; 321 + u16 load; 322 + struct isp116x_ep *next; 323 + 324 + /* async schedule */ 325 + struct list_head schedule; 326 + }; 327 + 328 + /*-------------------------------------------------------------------------*/ 329 + 330 + #ifdef DEBUG 331 + #define DBG(stuff...) printk(KERN_DEBUG "116x: " stuff) 332 + #else 333 + #define DBG(stuff...) do{}while(0) 334 + #endif 335 + 336 + #ifdef VERBOSE 337 + # define VDBG DBG 338 + #else 339 + # define VDBG(stuff...) do{}while(0) 340 + #endif 341 + 342 + #define ERR(stuff...) printk(KERN_ERR "116x: " stuff) 343 + #define WARN(stuff...) printk(KERN_WARNING "116x: " stuff) 344 + #define INFO(stuff...) printk(KERN_INFO "116x: " stuff) 345 + 346 + /* ------------------------------------------------- */ 347 + 348 + #if defined(USE_PLATFORM_DELAY) 349 + #if defined(USE_NDELAY) 350 + #error USE_PLATFORM_DELAY and USE_NDELAY simultaneously defined. 351 + #endif 352 + #define isp116x_delay(h,d) (h)->board->delay( \ 353 + isp116x_to_hcd(h)->self.controller,d) 354 + #define isp116x_check_platform_delay(h) ((h)->board->delay == NULL) 355 + #elif defined(USE_NDELAY) 356 + #define isp116x_delay(h,d) ndelay(d) 357 + #define isp116x_check_platform_delay(h) 0 358 + #else 359 + #define isp116x_delay(h,d) do{}while(0) 360 + #define isp116x_check_platform_delay(h) 0 361 + #endif 362 + 363 + #if defined(DEBUG) 364 + #define IRQ_TEST() BUG_ON(!irqs_disabled()) 365 + #else 366 + #define IRQ_TEST() do{}while(0) 367 + #endif 368 + 369 + static inline void isp116x_write_addr(struct isp116x *isp116x, unsigned reg) 370 + { 371 + IRQ_TEST(); 372 + writew(reg & 0xff, isp116x->addr_reg); 373 + isp116x_delay(isp116x, 300); 374 + } 375 + 376 + static inline void isp116x_write_data16(struct isp116x *isp116x, u16 val) 377 + { 378 + writew(val, isp116x->data_reg); 379 + isp116x_delay(isp116x, 150); 380 + } 381 + 382 + static inline void isp116x_raw_write_data16(struct isp116x *isp116x, u16 val) 383 + { 384 + __raw_writew(val, isp116x->data_reg); 385 + isp116x_delay(isp116x, 150); 386 + } 387 + 388 + static inline u16 isp116x_read_data16(struct isp116x *isp116x) 389 + { 390 + u16 val; 391 + 392 + val = readw(isp116x->data_reg); 393 + isp116x_delay(isp116x, 150); 394 + return val; 395 + } 396 + 397 + static inline u16 isp116x_raw_read_data16(struct isp116x *isp116x) 398 + { 399 + u16 val; 400 + 401 + val = __raw_readw(isp116x->data_reg); 402 + isp116x_delay(isp116x, 150); 403 + return val; 404 + } 405 + 406 + static inline void isp116x_write_data32(struct isp116x *isp116x, u32 val) 407 + { 408 + writew(val & 0xffff, isp116x->data_reg); 409 + isp116x_delay(isp116x, 150); 410 + writew(val >> 16, isp116x->data_reg); 411 + isp116x_delay(isp116x, 150); 412 + } 413 + 414 + static inline u32 isp116x_read_data32(struct isp116x *isp116x) 415 + { 416 + u32 val; 417 + 418 + val = (u32) readw(isp116x->data_reg); 419 + isp116x_delay(isp116x, 150); 420 + val |= ((u32) readw(isp116x->data_reg)) << 16; 421 + isp116x_delay(isp116x, 150); 422 + return val; 423 + } 424 + 425 + /* Let's keep register access functions out of line. Hint: 426 + we wait at least 150 ns at every access. 427 + */ 428 + static u16 isp116x_read_reg16(struct isp116x *isp116x, unsigned reg) 429 + { 430 + isp116x_write_addr(isp116x, reg); 431 + return isp116x_read_data16(isp116x); 432 + } 433 + 434 + static u32 isp116x_read_reg32(struct isp116x *isp116x, unsigned reg) 435 + { 436 + isp116x_write_addr(isp116x, reg); 437 + return isp116x_read_data32(isp116x); 438 + } 439 + 440 + static void isp116x_write_reg16(struct isp116x *isp116x, unsigned reg, 441 + unsigned val) 442 + { 443 + isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET); 444 + isp116x_write_data16(isp116x, (u16) (val & 0xffff)); 445 + } 446 + 447 + static void isp116x_write_reg32(struct isp116x *isp116x, unsigned reg, 448 + unsigned val) 449 + { 450 + isp116x_write_addr(isp116x, reg | ISP116x_WRITE_OFFSET); 451 + isp116x_write_data32(isp116x, (u32) val); 452 + } 453 + 454 + #define isp116x_show_reg(d,r) { \ 455 + if ((r) < 0x20) { \ 456 + DBG("%-12s[%02x]: %08x\n", #r, \ 457 + r, isp116x_read_reg32(d, r)); \ 458 + } else { \ 459 + DBG("%-12s[%02x]: %04x\n", #r, \ 460 + r, isp116x_read_reg16(d, r)); \ 461 + } \ 462 + } 463 + 464 + static inline void isp116x_show_regs(struct isp116x *isp116x) 465 + { 466 + isp116x_show_reg(isp116x, HCREVISION); 467 + isp116x_show_reg(isp116x, HCCONTROL); 468 + isp116x_show_reg(isp116x, HCCMDSTAT); 469 + isp116x_show_reg(isp116x, HCINTSTAT); 470 + isp116x_show_reg(isp116x, HCINTENB); 471 + isp116x_show_reg(isp116x, HCFMINTVL); 472 + isp116x_show_reg(isp116x, HCFMREM); 473 + isp116x_show_reg(isp116x, HCFMNUM); 474 + isp116x_show_reg(isp116x, HCLSTHRESH); 475 + isp116x_show_reg(isp116x, HCRHDESCA); 476 + isp116x_show_reg(isp116x, HCRHDESCB); 477 + isp116x_show_reg(isp116x, HCRHSTATUS); 478 + isp116x_show_reg(isp116x, HCRHPORT1); 479 + isp116x_show_reg(isp116x, HCRHPORT2); 480 + isp116x_show_reg(isp116x, HCHWCFG); 481 + isp116x_show_reg(isp116x, HCDMACFG); 482 + isp116x_show_reg(isp116x, HCXFERCTR); 483 + isp116x_show_reg(isp116x, HCuPINT); 484 + isp116x_show_reg(isp116x, HCuPINTENB); 485 + isp116x_show_reg(isp116x, HCCHIPID); 486 + isp116x_show_reg(isp116x, HCSCRATCH); 487 + isp116x_show_reg(isp116x, HCITLBUFLEN); 488 + isp116x_show_reg(isp116x, HCATLBUFLEN); 489 + isp116x_show_reg(isp116x, HCBUFSTAT); 490 + isp116x_show_reg(isp116x, HCRDITL0LEN); 491 + isp116x_show_reg(isp116x, HCRDITL1LEN); 492 + } 493 + 494 + #if defined(URB_TRACE) 495 + 496 + #define PIPETYPE(pipe) ({ char *__s; \ 497 + if (usb_pipecontrol(pipe)) __s = "ctrl"; \ 498 + else if (usb_pipeint(pipe)) __s = "int"; \ 499 + else if (usb_pipebulk(pipe)) __s = "bulk"; \ 500 + else __s = "iso"; \ 501 + __s;}) 502 + #define PIPEDIR(pipe) ({ usb_pipein(pipe) ? "in" : "out"; }) 503 + #define URB_NOTSHORT(urb) ({ (urb)->transfer_flags & URB_SHORT_NOT_OK ? \ 504 + "short_not_ok" : ""; }) 505 + 506 + /* print debug info about the URB */ 507 + static void urb_dbg(struct urb *urb, char *msg) 508 + { 509 + unsigned int pipe; 510 + 511 + if (!urb) { 512 + DBG("%s: zero urb\n", msg); 513 + return; 514 + } 515 + pipe = urb->pipe; 516 + DBG("%s: FA %d ep%d%s %s: len %d/%d %s\n", msg, 517 + usb_pipedevice(pipe), usb_pipeendpoint(pipe), 518 + PIPEDIR(pipe), PIPETYPE(pipe), 519 + urb->transfer_buffer_length, urb->actual_length, URB_NOTSHORT(urb)); 520 + } 521 + 522 + #else 523 + 524 + #define urb_dbg(urb,msg) do{}while(0) 525 + 526 + #endif /* ! defined(URB_TRACE) */ 527 + 528 + #if defined(PTD_TRACE) 529 + 530 + #define PTD_DIR_STR(ptd) ({char __c; \ 531 + switch(PTD_GET_DIR(ptd)){ \ 532 + case 0: __c = 's'; break; \ 533 + case 1: __c = 'o'; break; \ 534 + default: __c = 'i'; break; \ 535 + }; __c;}) 536 + 537 + /* 538 + Dump PTD info. The code documents the format 539 + perfectly, right :) 540 + */ 541 + static inline void dump_ptd(struct ptd *ptd) 542 + { 543 + printk("td: %x %d%c%d %d,%d,%d %x %x%x%x\n", 544 + PTD_GET_CC(ptd), PTD_GET_FA(ptd), 545 + PTD_DIR_STR(ptd), PTD_GET_EP(ptd), 546 + PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd), 547 + PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd), 548 + PTD_GET_SPD(ptd), PTD_GET_LAST(ptd)); 549 + } 550 + 551 + static inline void dump_ptd_out_data(struct ptd *ptd, u8 * buf) 552 + { 553 + int k; 554 + 555 + if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) { 556 + printk("-> "); 557 + for (k = 0; k < PTD_GET_LEN(ptd); ++k) 558 + printk("%02x ", ((u8 *) buf)[k]); 559 + printk("\n"); 560 + } 561 + } 562 + 563 + static inline void dump_ptd_in_data(struct ptd *ptd, u8 * buf) 564 + { 565 + int k; 566 + 567 + if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) { 568 + printk("<- "); 569 + for (k = 0; k < PTD_GET_COUNT(ptd); ++k) 570 + printk("%02x ", ((u8 *) buf)[k]); 571 + printk("\n"); 572 + } 573 + if (PTD_GET_LAST(ptd)) 574 + printk("-\n"); 575 + } 576 + 577 + #else 578 + 579 + #define dump_ptd(ptd) do{}while(0) 580 + #define dump_ptd_in_data(ptd,buf) do{}while(0) 581 + #define dump_ptd_out_data(ptd,buf) do{}while(0) 582 + 583 + #endif /* ! defined(PTD_TRACE) */
+25 -33
drivers/usb/host/ohci-hcd.c
··· 95 95 #include <linux/init.h> 96 96 #include <linux/timer.h> 97 97 #include <linux/list.h> 98 - #include <linux/interrupt.h> /* for in_interrupt () */ 99 98 #include <linux/usb.h> 100 99 #include <linux/usb_otg.h> 101 - #include "../core/hcd.h" 102 100 #include <linux/dma-mapping.h> 103 - #include <linux/dmapool.h> /* needed by ohci-mem.c when no PCI */ 101 + #include <linux/dmapool.h> 102 + #include <linux/reboot.h> 104 103 105 104 #include <asm/io.h> 106 105 #include <asm/irq.h> ··· 107 108 #include <asm/unaligned.h> 108 109 #include <asm/byteorder.h> 109 110 111 + #include "../core/hcd.h" 110 112 111 - #define DRIVER_VERSION "2004 Nov 08" 113 + #define DRIVER_VERSION "2005 April 22" 112 114 #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell" 113 115 #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver" 114 116 ··· 141 141 static void ohci_dump (struct ohci_hcd *ohci, int verbose); 142 142 static int ohci_init (struct ohci_hcd *ohci); 143 143 static void ohci_stop (struct usb_hcd *hcd); 144 + static int ohci_reboot (struct notifier_block *, unsigned long , void *); 144 145 145 146 #include "ohci-hub.c" 146 147 #include "ohci-dbg.c" ··· 421 420 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 422 421 } 423 422 423 + /* reboot notifier forcibly disables IRQs and DMA, helping kexec and 424 + * other cases where the next software may expect clean state from the 425 + * "firmware". this is bus-neutral, unlike shutdown() methods. 426 + */ 427 + static int 428 + ohci_reboot (struct notifier_block *block, unsigned long code, void *null) 429 + { 430 + struct ohci_hcd *ohci; 431 + 432 + ohci = container_of (block, struct ohci_hcd, reboot_notifier); 433 + ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 434 + ohci_usb_reset (ohci); 435 + /* flush the writes */ 436 + (void) ohci_readl (ohci, &ohci->regs->control); 437 + return 0; 438 + } 439 + 424 440 /*-------------------------------------------------------------------------* 425 441 * HC functions 426 442 *-------------------------------------------------------------------------*/ ··· 505 487 /* Start an OHCI controller, set the BUS operational 506 488 * resets USB and controller 507 489 * enable interrupts 508 - * connect the virtual root hub 509 490 */ 510 491 static int ohci_run (struct ohci_hcd *ohci) 511 492 { 512 493 u32 mask, temp; 513 - struct usb_device *udev; 514 - struct usb_bus *bus; 515 494 int first = ohci->fminterval == 0; 516 495 517 496 disable (ohci); ··· 669 654 670 655 // POTPGT delay is bits 24-31, in 2 ms units. 671 656 mdelay ((temp >> 23) & 0x1fe); 672 - bus = &ohci_to_hcd(ohci)->self; 673 657 ohci_to_hcd(ohci)->state = HC_STATE_RUNNING; 674 658 675 659 ohci_dump (ohci, 1); 676 660 677 - udev = bus->root_hub; 678 - if (udev) { 679 - return 0; 680 - } 681 - 682 - /* connect the virtual root hub */ 683 - udev = usb_alloc_dev (NULL, bus, 0); 684 - if (!udev) { 685 - disable (ohci); 686 - ohci->hc_control &= ~OHCI_CTRL_HCFS; 687 - ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 688 - return -ENOMEM; 689 - } 661 + if (ohci_to_hcd(ohci)->self.root_hub == NULL) 662 + create_debug_files (ohci); 690 663 691 - udev->speed = USB_SPEED_FULL; 692 - if (usb_hcd_register_root_hub (udev, ohci_to_hcd(ohci)) != 0) { 693 - usb_put_dev (udev); 694 - disable (ohci); 695 - ohci->hc_control &= ~OHCI_CTRL_HCFS; 696 - ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 697 - return -ENODEV; 698 - } 699 - if (ohci->power_budget) 700 - hub_set_power_budget(udev, ohci->power_budget); 701 - 702 - create_debug_files (ohci); 703 664 return 0; 704 665 } 705 666 ··· 772 781 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 773 782 774 783 remove_debug_files (ohci); 784 + unregister_reboot_notifier (&ohci->reboot_notifier); 775 785 ohci_mem_cleanup (ohci); 776 786 if (ohci->hcca) { 777 787 dma_free_coherent (hcd->self.controller,
+1
drivers/usb/host/ohci-mem.c
··· 29 29 spin_lock_init (&ohci->lock); 30 30 INIT_LIST_HEAD (&ohci->pending); 31 31 INIT_WORK (&ohci->rh_resume, ohci_rh_resume, ohci_to_hcd(ohci)); 32 + ohci->reboot_notifier.notifier_call = ohci_reboot; 32 33 } 33 34 34 35 /*-------------------------------------------------------------------------*/
+2 -2
drivers/usb/host/ohci-omap.c
··· 181 181 if (config->otg) { 182 182 ohci_to_hcd(ohci)->self.otg_port = config->otg; 183 183 /* default/minimum OTG power budget: 8 mA */ 184 - ohci->power_budget = 8; 184 + ohci_to_hcd(ohci)->power_budget = 8; 185 185 } 186 186 187 187 /* boards can use OTG transceivers in non-OTG modes */ ··· 230 230 231 231 /* TPS2045 switch for internal transceiver (port 1) */ 232 232 if (machine_is_omap_osk()) { 233 - ohci->power_budget = 250; 233 + ohci_to_hcd(ohci)->power_budget = 250; 234 234 235 235 rh &= ~RH_A_NOCP; 236 236
+1 -1
drivers/usb/host/ohci.h
··· 371 371 * other external transceivers should be software-transparent 372 372 */ 373 373 struct otg_transceiver *transceiver; 374 - unsigned power_budget; 375 374 376 375 /* 377 376 * memory management for queue data structures ··· 389 390 u32 fminterval; /* saved register */ 390 391 391 392 struct work_struct rh_resume; 393 + struct notifier_block reboot_notifier; 392 394 393 395 unsigned long flags; /* for HC bugs */ 394 396 #define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
+2 -16
drivers/usb/host/sl811-hcd.c
··· 1563 1563 sl811h_start(struct usb_hcd *hcd) 1564 1564 { 1565 1565 struct sl811 *sl811 = hcd_to_sl811(hcd); 1566 - struct usb_device *udev; 1567 1566 1568 1567 /* chip has been reset, VBUS power is off */ 1569 - 1570 - udev = usb_alloc_dev(NULL, &hcd->self, 0); 1571 - if (!udev) 1572 - return -ENOMEM; 1573 - 1574 - udev->speed = USB_SPEED_FULL; 1575 1568 hcd->state = HC_STATE_RUNNING; 1576 1569 1577 - if (sl811->board) 1570 + if (sl811->board) { 1578 1571 hcd->can_wakeup = sl811->board->can_wakeup; 1579 - 1580 - if (usb_hcd_register_root_hub(udev, hcd) != 0) { 1581 - usb_put_dev(udev); 1582 - sl811h_stop(hcd); 1583 - return -ENODEV; 1572 + hcd->power_budget = sl811->board->power * 2; 1584 1573 } 1585 - 1586 - if (sl811->board && sl811->board->power) 1587 - hub_set_power_budget(udev, sl811->board->power * 2); 1588 1574 1589 1575 /* enable power and interupts */ 1590 1576 port_power(sl811, 1);
+32
drivers/usb/host/uhci-debug.c
··· 237 237 return out - buf; 238 238 } 239 239 240 + static int uhci_show_root_hub_state(struct uhci_hcd *uhci, char *buf, int len) 241 + { 242 + char *out = buf; 243 + char *rh_state; 244 + 245 + /* Try to make sure there's enough memory */ 246 + if (len < 60) 247 + return 0; 248 + 249 + switch (uhci->rh_state) { 250 + case UHCI_RH_RESET: 251 + rh_state = "reset"; break; 252 + case UHCI_RH_SUSPENDED: 253 + rh_state = "suspended"; break; 254 + case UHCI_RH_AUTO_STOPPED: 255 + rh_state = "auto-stopped"; break; 256 + case UHCI_RH_RESUMING: 257 + rh_state = "resuming"; break; 258 + case UHCI_RH_SUSPENDING: 259 + rh_state = "suspending"; break; 260 + case UHCI_RH_RUNNING: 261 + rh_state = "running"; break; 262 + case UHCI_RH_RUNNING_NODEVS: 263 + rh_state = "running, no devs"; break; 264 + default: 265 + rh_state = "?"; break; 266 + } 267 + out += sprintf(out, "Root-hub state: %s\n", rh_state); 268 + return out - buf; 269 + } 270 + 240 271 static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len) 241 272 { 242 273 char *out = buf; ··· 439 408 440 409 spin_lock_irqsave(&uhci->lock, flags); 441 410 411 + out += uhci_show_root_hub_state(uhci, out, len - (out - buf)); 442 412 out += sprintf(out, "HC status\n"); 443 413 out += uhci_show_status(uhci, out, len - (out - buf)); 444 414
+452 -367
drivers/usb/host/uhci-hcd.c
··· 13 13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface 14 14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). 15 15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) 16 - * (C) Copyright 2004 Alan Stern, stern@rowland.harvard.edu 16 + * (C) Copyright 2004-2005 Alan Stern, stern@rowland.harvard.edu 17 17 * 18 18 * Intel documents this fairly well, and as far as I know there 19 19 * are no royalties or anything like that, but even so there are 20 20 * people who decided that they want to do the same thing in a 21 21 * completely different way. 22 22 * 23 - * WARNING! The USB documentation is downright evil. Most of it 24 - * is just crap, written by a committee. You're better off ignoring 25 - * most of it, the important stuff is: 26 - * - the low-level protocol (fairly simple but lots of small details) 27 - * - working around the horridness of the rest 28 23 */ 29 24 30 25 #include <linux/config.h> ··· 59 64 /* 60 65 * Version Information 61 66 */ 62 - #define DRIVER_VERSION "v2.2" 67 + #define DRIVER_VERSION "v2.3" 63 68 #define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, \ 64 69 Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \ 65 70 Alan Stern" ··· 84 89 85 90 static kmem_cache_t *uhci_up_cachep; /* urb_priv */ 86 91 92 + static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state); 93 + static void wakeup_rh(struct uhci_hcd *uhci); 87 94 static void uhci_get_current_frame_number(struct uhci_hcd *uhci); 88 - static void hc_state_transitions(struct uhci_hcd *uhci); 89 95 90 96 /* If a transfer is still active after this much time, turn off FSBR */ 91 97 #define IDLE_TIMEOUT msecs_to_jiffies(50) ··· 97 101 /* to make sure it doesn't hog all of the bandwidth */ 98 102 #define DEPTH_INTERVAL 5 99 103 104 + static inline void restart_timer(struct uhci_hcd *uhci) 105 + { 106 + mod_timer(&uhci->stall_timer, jiffies + msecs_to_jiffies(100)); 107 + } 108 + 100 109 #include "uhci-hub.c" 101 110 #include "uhci-debug.c" 102 111 #include "uhci-q.c" 103 112 104 - static int init_stall_timer(struct usb_hcd *hcd); 105 - 106 - static void stall_callback(unsigned long ptr) 113 + /* 114 + * Make sure the controller is completely inactive, unable to 115 + * generate interrupts or do DMA. 116 + */ 117 + static void reset_hc(struct uhci_hcd *uhci) 107 118 { 108 - struct usb_hcd *hcd = (struct usb_hcd *)ptr; 109 - struct uhci_hcd *uhci = hcd_to_uhci(hcd); 110 - struct urb_priv *up; 119 + int port; 120 + 121 + /* Turn off PIRQ enable and SMI enable. (This also turns off the 122 + * BIOS's USB Legacy Support.) Turn off all the R/WC bits too. 123 + */ 124 + pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 125 + USBLEGSUP_RWC); 126 + 127 + /* Reset the HC - this will force us to get a 128 + * new notification of any already connected 129 + * ports due to the virtual disconnect that it 130 + * implies. 131 + */ 132 + outw(USBCMD_HCRESET, uhci->io_addr + USBCMD); 133 + mb(); 134 + udelay(5); 135 + if (inw(uhci->io_addr + USBCMD) & USBCMD_HCRESET) 136 + dev_warn(uhci_dev(uhci), "HCRESET not completed yet!\n"); 137 + 138 + /* Just to be safe, disable interrupt requests and 139 + * make sure the controller is stopped. 140 + */ 141 + outw(0, uhci->io_addr + USBINTR); 142 + outw(0, uhci->io_addr + USBCMD); 143 + 144 + /* HCRESET doesn't affect the Suspend, Reset, and Resume Detect 145 + * bits in the port status and control registers. 146 + * We have to clear them by hand. 147 + */ 148 + for (port = 0; port < uhci->rh_numports; ++port) 149 + outw(0, uhci->io_addr + USBPORTSC1 + (port * 2)); 150 + 151 + uhci->port_c_suspend = uhci->suspended_ports = 152 + uhci->resuming_ports = 0; 153 + uhci->rh_state = UHCI_RH_RESET; 154 + uhci->is_stopped = UHCI_IS_STOPPED; 155 + uhci_to_hcd(uhci)->state = HC_STATE_HALT; 156 + uhci_to_hcd(uhci)->poll_rh = 0; 157 + } 158 + 159 + /* 160 + * Last rites for a defunct/nonfunctional controller 161 + * or one we don't want to use any more. 162 + */ 163 + static void hc_died(struct uhci_hcd *uhci) 164 + { 165 + reset_hc(uhci); 166 + uhci->hc_inaccessible = 1; 167 + del_timer(&uhci->stall_timer); 168 + } 169 + 170 + /* 171 + * Initialize a controller that was newly discovered or has just been 172 + * resumed. In either case we can't be sure of its previous state. 173 + */ 174 + static void check_and_reset_hc(struct uhci_hcd *uhci) 175 + { 176 + u16 legsup; 177 + unsigned int cmd, intr; 178 + 179 + /* 180 + * When restarting a suspended controller, we expect all the 181 + * settings to be the same as we left them: 182 + * 183 + * PIRQ and SMI disabled, no R/W bits set in USBLEGSUP; 184 + * Controller is stopped and configured with EGSM set; 185 + * No interrupts enabled except possibly Resume Detect. 186 + * 187 + * If any of these conditions are violated we do a complete reset. 188 + */ 189 + pci_read_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, &legsup); 190 + if (legsup & ~(USBLEGSUP_RO | USBLEGSUP_RWC)) { 191 + dev_dbg(uhci_dev(uhci), "%s: legsup = 0x%04x\n", 192 + __FUNCTION__, legsup); 193 + goto reset_needed; 194 + } 195 + 196 + cmd = inw(uhci->io_addr + USBCMD); 197 + if ((cmd & USBCMD_RS) || !(cmd & USBCMD_CF) || !(cmd & USBCMD_EGSM)) { 198 + dev_dbg(uhci_dev(uhci), "%s: cmd = 0x%04x\n", 199 + __FUNCTION__, cmd); 200 + goto reset_needed; 201 + } 202 + 203 + intr = inw(uhci->io_addr + USBINTR); 204 + if (intr & (~USBINTR_RESUME)) { 205 + dev_dbg(uhci_dev(uhci), "%s: intr = 0x%04x\n", 206 + __FUNCTION__, intr); 207 + goto reset_needed; 208 + } 209 + return; 210 + 211 + reset_needed: 212 + dev_dbg(uhci_dev(uhci), "Performing full reset\n"); 213 + reset_hc(uhci); 214 + } 215 + 216 + /* 217 + * Store the basic register settings needed by the controller. 218 + */ 219 + static void configure_hc(struct uhci_hcd *uhci) 220 + { 221 + /* Set the frame length to the default: 1 ms exactly */ 222 + outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF); 223 + 224 + /* Store the frame list base address */ 225 + outl(uhci->fl->dma_handle, uhci->io_addr + USBFLBASEADD); 226 + 227 + /* Set the current frame number */ 228 + outw(uhci->frame_number, uhci->io_addr + USBFRNUM); 229 + 230 + /* Mark controller as running before we enable interrupts */ 231 + uhci_to_hcd(uhci)->state = HC_STATE_RUNNING; 232 + mb(); 233 + 234 + /* Enable PIRQ */ 235 + pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 236 + USBLEGSUP_DEFAULT); 237 + } 238 + 239 + 240 + static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci) 241 + { 242 + int port; 243 + 244 + switch (to_pci_dev(uhci_dev(uhci))->vendor) { 245 + default: 246 + break; 247 + 248 + case PCI_VENDOR_ID_GENESYS: 249 + /* Genesys Logic's GL880S controllers don't generate 250 + * resume-detect interrupts. 251 + */ 252 + return 1; 253 + 254 + case PCI_VENDOR_ID_INTEL: 255 + /* Some of Intel's USB controllers have a bug that causes 256 + * resume-detect interrupts if any port has an over-current 257 + * condition. To make matters worse, some motherboards 258 + * hardwire unused USB ports' over-current inputs active! 259 + * To prevent problems, we will not enable resume-detect 260 + * interrupts if any ports are OC. 261 + */ 262 + for (port = 0; port < uhci->rh_numports; ++port) { 263 + if (inw(uhci->io_addr + USBPORTSC1 + port * 2) & 264 + USBPORTSC_OC) 265 + return 1; 266 + } 267 + break; 268 + } 269 + return 0; 270 + } 271 + 272 + static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state) 273 + __releases(uhci->lock) 274 + __acquires(uhci->lock) 275 + { 276 + int auto_stop; 277 + int int_enable; 278 + 279 + auto_stop = (new_state == UHCI_RH_AUTO_STOPPED); 280 + dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__, 281 + (auto_stop ? " (auto-stop)" : "")); 282 + 283 + /* If we get a suspend request when we're already auto-stopped 284 + * then there's nothing to do. 285 + */ 286 + if (uhci->rh_state == UHCI_RH_AUTO_STOPPED) { 287 + uhci->rh_state = new_state; 288 + return; 289 + } 290 + 291 + /* Enable resume-detect interrupts if they work. 292 + * Then enter Global Suspend mode, still configured. 293 + */ 294 + int_enable = (resume_detect_interrupts_are_broken(uhci) ? 295 + 0 : USBINTR_RESUME); 296 + outw(int_enable, uhci->io_addr + USBINTR); 297 + outw(USBCMD_EGSM | USBCMD_CF, uhci->io_addr + USBCMD); 298 + mb(); 299 + udelay(5); 300 + 301 + /* If we're auto-stopping then no devices have been attached 302 + * for a while, so there shouldn't be any active URBs and the 303 + * controller should stop after a few microseconds. Otherwise 304 + * we will give the controller one frame to stop. 305 + */ 306 + if (!auto_stop && !(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) { 307 + uhci->rh_state = UHCI_RH_SUSPENDING; 308 + spin_unlock_irq(&uhci->lock); 309 + msleep(1); 310 + spin_lock_irq(&uhci->lock); 311 + if (uhci->hc_inaccessible) /* Died */ 312 + return; 313 + } 314 + if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) 315 + dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n"); 316 + 317 + uhci_get_current_frame_number(uhci); 318 + smp_wmb(); 319 + 320 + uhci->rh_state = new_state; 321 + uhci->is_stopped = UHCI_IS_STOPPED; 322 + del_timer(&uhci->stall_timer); 323 + uhci_to_hcd(uhci)->poll_rh = !int_enable; 324 + 325 + uhci_scan_schedule(uhci, NULL); 326 + } 327 + 328 + static void start_rh(struct uhci_hcd *uhci) 329 + { 330 + uhci->is_stopped = 0; 331 + smp_wmb(); 332 + 333 + /* Mark it configured and running with a 64-byte max packet. 334 + * All interrupts are enabled, even though RESUME won't do anything. 335 + */ 336 + outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, uhci->io_addr + USBCMD); 337 + outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP, 338 + uhci->io_addr + USBINTR); 339 + mb(); 340 + uhci->rh_state = UHCI_RH_RUNNING; 341 + uhci_to_hcd(uhci)->poll_rh = 1; 342 + restart_timer(uhci); 343 + } 344 + 345 + static void wakeup_rh(struct uhci_hcd *uhci) 346 + __releases(uhci->lock) 347 + __acquires(uhci->lock) 348 + { 349 + dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__, 350 + uhci->rh_state == UHCI_RH_AUTO_STOPPED ? 351 + " (auto-start)" : ""); 352 + 353 + /* If we are auto-stopped then no devices are attached so there's 354 + * no need for wakeup signals. Otherwise we send Global Resume 355 + * for 20 ms. 356 + */ 357 + if (uhci->rh_state == UHCI_RH_SUSPENDED) { 358 + uhci->rh_state = UHCI_RH_RESUMING; 359 + outw(USBCMD_FGR | USBCMD_EGSM | USBCMD_CF, 360 + uhci->io_addr + USBCMD); 361 + spin_unlock_irq(&uhci->lock); 362 + msleep(20); 363 + spin_lock_irq(&uhci->lock); 364 + if (uhci->hc_inaccessible) /* Died */ 365 + return; 366 + 367 + /* End Global Resume and wait for EOP to be sent */ 368 + outw(USBCMD_CF, uhci->io_addr + USBCMD); 369 + mb(); 370 + udelay(4); 371 + if (inw(uhci->io_addr + USBCMD) & USBCMD_FGR) 372 + dev_warn(uhci_dev(uhci), "FGR not stopped yet!\n"); 373 + } 374 + 375 + start_rh(uhci); 376 + 377 + /* Restart root hub polling */ 378 + mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies); 379 + } 380 + 381 + static void stall_callback(unsigned long _uhci) 382 + { 383 + struct uhci_hcd *uhci = (struct uhci_hcd *) _uhci; 111 384 unsigned long flags; 112 385 113 386 spin_lock_irqsave(&uhci->lock, flags); 114 387 uhci_scan_schedule(uhci, NULL); 388 + check_fsbr(uhci); 115 389 116 - list_for_each_entry(up, &uhci->urb_list, urb_list) { 117 - struct urb *u = up->urb; 118 - 119 - spin_lock(&u->lock); 120 - 121 - /* Check if the FSBR timed out */ 122 - if (up->fsbr && !up->fsbr_timeout && time_after_eq(jiffies, up->fsbrtime + IDLE_TIMEOUT)) 123 - uhci_fsbr_timeout(uhci, u); 124 - 125 - spin_unlock(&u->lock); 126 - } 127 - 128 - /* Really disable FSBR */ 129 - if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) { 130 - uhci->fsbrtimeout = 0; 131 - uhci->skel_term_qh->link = UHCI_PTR_TERM; 132 - } 133 - 134 - /* Poll for and perform state transitions */ 135 - hc_state_transitions(uhci); 136 - if (unlikely(uhci->suspended_ports && uhci->state != UHCI_SUSPENDED)) 137 - uhci_check_ports(uhci); 138 - 139 - init_stall_timer(hcd); 390 + if (!uhci->is_stopped) 391 + restart_timer(uhci); 140 392 spin_unlock_irqrestore(&uhci->lock, flags); 141 - } 142 - 143 - static int init_stall_timer(struct usb_hcd *hcd) 144 - { 145 - struct uhci_hcd *uhci = hcd_to_uhci(hcd); 146 - 147 - init_timer(&uhci->stall_timer); 148 - uhci->stall_timer.function = stall_callback; 149 - uhci->stall_timer.data = (unsigned long)hcd; 150 - uhci->stall_timer.expires = jiffies + msecs_to_jiffies(100); 151 - add_timer(&uhci->stall_timer); 152 - 153 - return 0; 154 393 } 155 394 156 395 static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs) 157 396 { 158 397 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 159 - unsigned long io_addr = uhci->io_addr; 160 398 unsigned short status; 399 + unsigned long flags; 161 400 162 401 /* 163 402 * Read the interrupt status, and write it back to clear the 164 403 * interrupt cause. Contrary to the UHCI specification, the 165 404 * "HC Halted" status bit is persistent: it is RO, not R/WC. 166 405 */ 167 - status = inw(io_addr + USBSTS); 406 + status = inw(uhci->io_addr + USBSTS); 168 407 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */ 169 408 return IRQ_NONE; 170 - outw(status, io_addr + USBSTS); /* Clear it */ 409 + outw(status, uhci->io_addr + USBSTS); /* Clear it */ 171 410 172 411 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) { 173 412 if (status & USBSTS_HSE) ··· 411 180 if (status & USBSTS_HCPE) 412 181 dev_err(uhci_dev(uhci), "host controller process " 413 182 "error, something bad happened!\n"); 414 - if ((status & USBSTS_HCH) && uhci->state > 0) { 415 - dev_err(uhci_dev(uhci), "host controller halted, " 183 + if (status & USBSTS_HCH) { 184 + spin_lock_irqsave(&uhci->lock, flags); 185 + if (uhci->rh_state >= UHCI_RH_RUNNING) { 186 + dev_err(uhci_dev(uhci), 187 + "host controller halted, " 416 188 "very bad!\n"); 417 - /* FIXME: Reset the controller, fix the offending TD */ 189 + hc_died(uhci); 190 + spin_unlock_irqrestore(&uhci->lock, flags); 191 + return IRQ_HANDLED; 192 + } 193 + spin_unlock_irqrestore(&uhci->lock, flags); 418 194 } 419 195 } 420 196 421 197 if (status & USBSTS_RD) 422 - uhci->resume_detect = 1; 198 + usb_hcd_poll_rh_status(hcd); 423 199 424 - spin_lock(&uhci->lock); 200 + spin_lock_irqsave(&uhci->lock, flags); 425 201 uhci_scan_schedule(uhci, regs); 426 - spin_unlock(&uhci->lock); 202 + spin_unlock_irqrestore(&uhci->lock, flags); 427 203 428 204 return IRQ_HANDLED; 429 - } 430 - 431 - static void reset_hc(struct uhci_hcd *uhci) 432 - { 433 - unsigned long io_addr = uhci->io_addr; 434 - 435 - /* Turn off PIRQ, SMI, and all interrupts. This also turns off 436 - * the BIOS's USB Legacy Support. 437 - */ 438 - pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); 439 - outw(0, uhci->io_addr + USBINTR); 440 - 441 - /* Global reset for 50ms */ 442 - uhci->state = UHCI_RESET; 443 - outw(USBCMD_GRESET, io_addr + USBCMD); 444 - msleep(50); 445 - outw(0, io_addr + USBCMD); 446 - 447 - /* Another 10ms delay */ 448 - msleep(10); 449 - uhci->resume_detect = 0; 450 - uhci->is_stopped = UHCI_IS_STOPPED; 451 - } 452 - 453 - static void suspend_hc(struct uhci_hcd *uhci) 454 - { 455 - unsigned long io_addr = uhci->io_addr; 456 - 457 - dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 458 - uhci->state = UHCI_SUSPENDED; 459 - uhci->resume_detect = 0; 460 - outw(USBCMD_EGSM, io_addr + USBCMD); 461 - 462 - /* FIXME: Wait for the controller to actually stop */ 463 - uhci_get_current_frame_number(uhci); 464 - uhci->is_stopped = UHCI_IS_STOPPED; 465 - 466 - uhci_scan_schedule(uhci, NULL); 467 - } 468 - 469 - static void wakeup_hc(struct uhci_hcd *uhci) 470 - { 471 - unsigned long io_addr = uhci->io_addr; 472 - 473 - switch (uhci->state) { 474 - case UHCI_SUSPENDED: /* Start the resume */ 475 - dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 476 - 477 - /* Global resume for >= 20ms */ 478 - outw(USBCMD_FGR | USBCMD_EGSM, io_addr + USBCMD); 479 - uhci->state = UHCI_RESUMING_1; 480 - uhci->state_end = jiffies + msecs_to_jiffies(20); 481 - uhci->is_stopped = 0; 482 - break; 483 - 484 - case UHCI_RESUMING_1: /* End global resume */ 485 - uhci->state = UHCI_RESUMING_2; 486 - outw(0, io_addr + USBCMD); 487 - /* Falls through */ 488 - 489 - case UHCI_RESUMING_2: /* Wait for EOP to be sent */ 490 - if (inw(io_addr + USBCMD) & USBCMD_FGR) 491 - break; 492 - 493 - /* Run for at least 1 second, and 494 - * mark it configured with a 64-byte max packet */ 495 - uhci->state = UHCI_RUNNING_GRACE; 496 - uhci->state_end = jiffies + HZ; 497 - outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, 498 - io_addr + USBCMD); 499 - break; 500 - 501 - case UHCI_RUNNING_GRACE: /* Now allowed to suspend */ 502 - uhci->state = UHCI_RUNNING; 503 - break; 504 - 505 - default: 506 - break; 507 - } 508 - } 509 - 510 - static int ports_active(struct uhci_hcd *uhci) 511 - { 512 - unsigned long io_addr = uhci->io_addr; 513 - int connection = 0; 514 - int i; 515 - 516 - for (i = 0; i < uhci->rh_numports; i++) 517 - connection |= (inw(io_addr + USBPORTSC1 + i * 2) & USBPORTSC_CCS); 518 - 519 - return connection; 520 - } 521 - 522 - static int suspend_allowed(struct uhci_hcd *uhci) 523 - { 524 - unsigned long io_addr = uhci->io_addr; 525 - int i; 526 - 527 - if (to_pci_dev(uhci_dev(uhci))->vendor != PCI_VENDOR_ID_INTEL) 528 - return 1; 529 - 530 - /* Some of Intel's USB controllers have a bug that causes false 531 - * resume indications if any port has an over current condition. 532 - * To prevent problems, we will not allow a global suspend if 533 - * any ports are OC. 534 - * 535 - * Some motherboards using Intel's chipsets (but not using all 536 - * the USB ports) appear to hardwire the over current inputs active 537 - * to disable the USB ports. 538 - */ 539 - 540 - /* check for over current condition on any port */ 541 - for (i = 0; i < uhci->rh_numports; i++) { 542 - if (inw(io_addr + USBPORTSC1 + i * 2) & USBPORTSC_OC) 543 - return 0; 544 - } 545 - 546 - return 1; 547 - } 548 - 549 - static void hc_state_transitions(struct uhci_hcd *uhci) 550 - { 551 - switch (uhci->state) { 552 - case UHCI_RUNNING: 553 - 554 - /* global suspend if nothing connected for 1 second */ 555 - if (!ports_active(uhci) && suspend_allowed(uhci)) { 556 - uhci->state = UHCI_SUSPENDING_GRACE; 557 - uhci->state_end = jiffies + HZ; 558 - } 559 - break; 560 - 561 - case UHCI_SUSPENDING_GRACE: 562 - if (ports_active(uhci)) 563 - uhci->state = UHCI_RUNNING; 564 - else if (time_after_eq(jiffies, uhci->state_end)) 565 - suspend_hc(uhci); 566 - break; 567 - 568 - case UHCI_SUSPENDED: 569 - 570 - /* wakeup if requested by a device */ 571 - if (uhci->resume_detect) 572 - wakeup_hc(uhci); 573 - break; 574 - 575 - case UHCI_RESUMING_1: 576 - case UHCI_RESUMING_2: 577 - case UHCI_RUNNING_GRACE: 578 - if (time_after_eq(jiffies, uhci->state_end)) 579 - wakeup_hc(uhci); 580 - break; 581 - 582 - default: 583 - break; 584 - } 585 205 } 586 206 587 207 /* ··· 443 361 { 444 362 if (!uhci->is_stopped) 445 363 uhci->frame_number = inw(uhci->io_addr + USBFRNUM); 446 - } 447 - 448 - static int start_hc(struct uhci_hcd *uhci) 449 - { 450 - unsigned long io_addr = uhci->io_addr; 451 - int timeout = 10; 452 - 453 - /* 454 - * Reset the HC - this will force us to get a 455 - * new notification of any already connected 456 - * ports due to the virtual disconnect that it 457 - * implies. 458 - */ 459 - outw(USBCMD_HCRESET, io_addr + USBCMD); 460 - while (inw(io_addr + USBCMD) & USBCMD_HCRESET) { 461 - if (--timeout < 0) { 462 - dev_err(uhci_dev(uhci), "USBCMD_HCRESET timed out!\n"); 463 - return -ETIMEDOUT; 464 - } 465 - msleep(1); 466 - } 467 - 468 - /* Mark controller as running before we enable interrupts */ 469 - uhci_to_hcd(uhci)->state = HC_STATE_RUNNING; 470 - 471 - /* Turn on PIRQ and all interrupts */ 472 - pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 473 - USBLEGSUP_DEFAULT); 474 - outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP, 475 - io_addr + USBINTR); 476 - 477 - /* Start at frame 0 */ 478 - outw(0, io_addr + USBFRNUM); 479 - outl(uhci->fl->dma_handle, io_addr + USBFLBASEADD); 480 - 481 - /* Run and mark it configured with a 64-byte max packet */ 482 - uhci->state = UHCI_RUNNING_GRACE; 483 - uhci->state_end = jiffies + HZ; 484 - outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, io_addr + USBCMD); 485 - uhci->is_stopped = 0; 486 - 487 - return 0; 488 364 } 489 365 490 366 /* ··· 488 448 static int uhci_reset(struct usb_hcd *hcd) 489 449 { 490 450 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 451 + unsigned io_size = (unsigned) hcd->rsrc_len; 452 + int port; 491 453 492 454 uhci->io_addr = (unsigned long) hcd->rsrc_start; 493 455 494 - /* Kick BIOS off this hardware and reset, so we won't get 495 - * interrupts from any previous setup. 456 + /* The UHCI spec says devices must have 2 ports, and goes on to say 457 + * they may have more but gives no way to determine how many there 458 + * are. However according to the UHCI spec, Bit 7 of the port 459 + * status and control register is always set to 1. So we try to 460 + * use this to our advantage. Another common failure mode when 461 + * a nonexistent register is addressed is to return all ones, so 462 + * we test for that also. 496 463 */ 497 - reset_hc(uhci); 464 + for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) { 465 + unsigned int portstatus; 466 + 467 + portstatus = inw(uhci->io_addr + USBPORTSC1 + (port * 2)); 468 + if (!(portstatus & 0x0080) || portstatus == 0xffff) 469 + break; 470 + } 471 + if (debug) 472 + dev_info(uhci_dev(uhci), "detected %d ports\n", port); 473 + 474 + /* Anything greater than 7 is weird so we'll ignore it. */ 475 + if (port > UHCI_RH_MAXCHILD) { 476 + dev_info(uhci_dev(uhci), "port count misdetected? " 477 + "forcing to 2 ports\n"); 478 + port = 2; 479 + } 480 + uhci->rh_numports = port; 481 + 482 + /* Kick BIOS off this hardware and reset if the controller 483 + * isn't already safely quiescent. 484 + */ 485 + check_and_reset_hc(uhci); 498 486 return 0; 487 + } 488 + 489 + /* Make sure the controller is quiescent and that we're not using it 490 + * any more. This is mainly for the benefit of programs which, like kexec, 491 + * expect the hardware to be idle: not doing DMA or generating IRQs. 492 + * 493 + * This routine may be called in a damaged or failing kernel. Hence we 494 + * do not acquire the spinlock before shutting down the controller. 495 + */ 496 + static void uhci_shutdown(struct pci_dev *pdev) 497 + { 498 + struct usb_hcd *hcd = (struct usb_hcd *) pci_get_drvdata(pdev); 499 + 500 + hc_died(hcd_to_uhci(hcd)); 499 501 } 500 502 501 503 /* ··· 560 478 { 561 479 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 562 480 int retval = -EBUSY; 563 - int i, port; 564 - unsigned io_size; 481 + int i; 565 482 dma_addr_t dma_handle; 566 - struct usb_device *udev; 567 483 struct dentry *dentry; 568 484 569 - io_size = (unsigned) hcd->rsrc_len; 485 + hcd->uses_new_polling = 1; 486 + if (pci_find_capability(to_pci_dev(uhci_dev(uhci)), PCI_CAP_ID_PM)) 487 + hcd->can_wakeup = 1; /* Assume it supports PME# */ 570 488 571 - dentry = debugfs_create_file(hcd->self.bus_name, S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, uhci, &uhci_debug_operations); 489 + dentry = debugfs_create_file(hcd->self.bus_name, 490 + S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, uhci, 491 + &uhci_debug_operations); 572 492 if (!dentry) { 573 - dev_err(uhci_dev(uhci), "couldn't create uhci debugfs entry\n"); 493 + dev_err(uhci_dev(uhci), 494 + "couldn't create uhci debugfs entry\n"); 574 495 retval = -ENOMEM; 575 496 goto err_create_debug_entry; 576 497 } ··· 594 509 INIT_LIST_HEAD(&uhci->complete_list); 595 510 596 511 init_waitqueue_head(&uhci->waitqh); 512 + 513 + init_timer(&uhci->stall_timer); 514 + uhci->stall_timer.function = stall_callback; 515 + uhci->stall_timer.data = (unsigned long) uhci; 597 516 598 517 uhci->fl = dma_alloc_coherent(uhci_dev(uhci), sizeof(*uhci->fl), 599 518 &dma_handle, 0); ··· 625 536 goto err_create_qh_pool; 626 537 } 627 538 628 - /* Initialize the root hub */ 629 - 630 - /* UHCI specs says devices must have 2 ports, but goes on to say */ 631 - /* they may have more but give no way to determine how many they */ 632 - /* have. However, according to the UHCI spec, Bit 7 is always set */ 633 - /* to 1. So we try to use this to our advantage */ 634 - for (port = 0; port < (io_size - 0x10) / 2; port++) { 635 - unsigned int portstatus; 636 - 637 - portstatus = inw(uhci->io_addr + 0x10 + (port * 2)); 638 - if (!(portstatus & 0x0080)) 639 - break; 640 - } 641 - if (debug) 642 - dev_info(uhci_dev(uhci), "detected %d ports\n", port); 643 - 644 - /* This is experimental so anything less than 2 or greater than 8 is */ 645 - /* something weird and we'll ignore it */ 646 - if (port < 2 || port > UHCI_RH_MAXCHILD) { 647 - dev_info(uhci_dev(uhci), "port count misdetected? " 648 - "forcing to 2 ports\n"); 649 - port = 2; 650 - } 651 - 652 - uhci->rh_numports = port; 653 - 654 - udev = usb_alloc_dev(NULL, &hcd->self, 0); 655 - if (!udev) { 656 - dev_err(uhci_dev(uhci), "unable to allocate root hub\n"); 657 - goto err_alloc_root_hub; 658 - } 659 - 660 - uhci->term_td = uhci_alloc_td(uhci, udev); 539 + uhci->term_td = uhci_alloc_td(uhci); 661 540 if (!uhci->term_td) { 662 541 dev_err(uhci_dev(uhci), "unable to allocate terminating TD\n"); 663 542 goto err_alloc_term_td; 664 543 } 665 544 666 545 for (i = 0; i < UHCI_NUM_SKELQH; i++) { 667 - uhci->skelqh[i] = uhci_alloc_qh(uhci, udev); 546 + uhci->skelqh[i] = uhci_alloc_qh(uhci); 668 547 if (!uhci->skelqh[i]) { 669 548 dev_err(uhci_dev(uhci), "unable to allocate QH\n"); 670 549 goto err_alloc_skelqh; ··· 698 641 699 642 /* 700 643 * Some architectures require a full mb() to enforce completion of 701 - * the memory writes above before the I/O transfers in start_hc(). 644 + * the memory writes above before the I/O transfers in configure_hc(). 702 645 */ 703 646 mb(); 704 - if ((retval = start_hc(uhci)) != 0) 705 - goto err_alloc_skelqh; 706 647 707 - init_stall_timer(hcd); 708 - 709 - udev->speed = USB_SPEED_FULL; 710 - 711 - if (usb_hcd_register_root_hub(udev, hcd) != 0) { 712 - dev_err(uhci_dev(uhci), "unable to start root hub\n"); 713 - retval = -ENOMEM; 714 - goto err_start_root_hub; 715 - } 716 - 648 + configure_hc(uhci); 649 + start_rh(uhci); 717 650 return 0; 718 651 719 652 /* 720 653 * error exits: 721 654 */ 722 - err_start_root_hub: 723 - reset_hc(uhci); 724 - 725 - del_timer_sync(&uhci->stall_timer); 726 - 727 655 err_alloc_skelqh: 728 656 for (i = 0; i < UHCI_NUM_SKELQH; i++) 729 657 if (uhci->skelqh[i]) { ··· 720 678 uhci->term_td = NULL; 721 679 722 680 err_alloc_term_td: 723 - usb_put_dev(udev); 724 - 725 - err_alloc_root_hub: 726 681 dma_pool_destroy(uhci->qh_pool); 727 682 uhci->qh_pool = NULL; 728 683 ··· 744 705 { 745 706 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 746 707 747 - del_timer_sync(&uhci->stall_timer); 748 - reset_hc(uhci); 749 - 750 708 spin_lock_irq(&uhci->lock); 709 + reset_hc(uhci); 751 710 uhci_scan_schedule(uhci, NULL); 752 711 spin_unlock_irq(&uhci->lock); 753 - 712 + 713 + del_timer_sync(&uhci->stall_timer); 754 714 release_uhci(uhci); 755 715 } 756 716 757 717 #ifdef CONFIG_PM 758 - static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) 718 + static int uhci_rh_suspend(struct usb_hcd *hcd) 759 719 { 760 720 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 761 721 762 722 spin_lock_irq(&uhci->lock); 763 - 764 - /* Don't try to suspend broken motherboards, reset instead */ 765 - if (suspend_allowed(uhci)) 766 - suspend_hc(uhci); 767 - else { 768 - spin_unlock_irq(&uhci->lock); 769 - reset_hc(uhci); 770 - spin_lock_irq(&uhci->lock); 771 - uhci_scan_schedule(uhci, NULL); 772 - } 773 - 723 + if (!uhci->hc_inaccessible) /* Not dead */ 724 + suspend_rh(uhci, UHCI_RH_SUSPENDED); 774 725 spin_unlock_irq(&uhci->lock); 775 726 return 0; 727 + } 728 + 729 + static int uhci_rh_resume(struct usb_hcd *hcd) 730 + { 731 + struct uhci_hcd *uhci = hcd_to_uhci(hcd); 732 + int rc = 0; 733 + 734 + spin_lock_irq(&uhci->lock); 735 + if (uhci->hc_inaccessible) { 736 + if (uhci->rh_state == UHCI_RH_SUSPENDED) { 737 + dev_warn(uhci_dev(uhci), "HC isn't running!\n"); 738 + rc = -ENODEV; 739 + } 740 + /* Otherwise the HC is dead */ 741 + } else 742 + wakeup_rh(uhci); 743 + spin_unlock_irq(&uhci->lock); 744 + return rc; 745 + } 746 + 747 + static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) 748 + { 749 + struct uhci_hcd *uhci = hcd_to_uhci(hcd); 750 + int rc = 0; 751 + 752 + dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 753 + 754 + spin_lock_irq(&uhci->lock); 755 + if (uhci->hc_inaccessible) /* Dead or already suspended */ 756 + goto done; 757 + 758 + #ifndef CONFIG_USB_SUSPEND 759 + /* Otherwise this would never happen */ 760 + suspend_rh(uhci, UHCI_RH_SUSPENDED); 761 + #endif 762 + 763 + if (uhci->rh_state > UHCI_RH_SUSPENDED) { 764 + dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n"); 765 + hcd->state = HC_STATE_RUNNING; 766 + rc = -EBUSY; 767 + goto done; 768 + }; 769 + 770 + /* All PCI host controllers are required to disable IRQ generation 771 + * at the source, so we must turn off PIRQ. 772 + */ 773 + pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); 774 + uhci->hc_inaccessible = 1; 775 + 776 + /* FIXME: Enable non-PME# remote wakeup? */ 777 + 778 + done: 779 + spin_unlock_irq(&uhci->lock); 780 + if (rc == 0) 781 + del_timer_sync(&hcd->rh_timer); 782 + return rc; 776 783 } 777 784 778 785 static int uhci_resume(struct usb_hcd *hcd) 779 786 { 780 787 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 781 - int rc; 782 788 783 - pci_set_master(to_pci_dev(uhci_dev(uhci))); 789 + dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 784 790 791 + if (uhci->rh_state == UHCI_RH_RESET) /* Dead */ 792 + return 0; 785 793 spin_lock_irq(&uhci->lock); 786 794 787 - if (uhci->state == UHCI_SUSPENDED) { 795 + /* FIXME: Disable non-PME# remote wakeup? */ 788 796 789 - /* 790 - * Some systems don't maintain the UHCI register values 791 - * during a PM suspend/resume cycle, so reinitialize 792 - * the Frame Number, Framelist Base Address, Interrupt 793 - * Enable, and Legacy Support registers. 794 - */ 795 - pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 796 - 0); 797 - outw(uhci->frame_number, uhci->io_addr + USBFRNUM); 798 - outl(uhci->fl->dma_handle, uhci->io_addr + USBFLBASEADD); 799 - outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | 800 - USBINTR_SP, uhci->io_addr + USBINTR); 801 - uhci->resume_detect = 1; 802 - pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 803 - USBLEGSUP_DEFAULT); 804 - } else { 805 - spin_unlock_irq(&uhci->lock); 806 - reset_hc(uhci); 807 - if ((rc = start_hc(uhci)) != 0) 808 - return rc; 809 - spin_lock_irq(&uhci->lock); 810 - } 811 - hcd->state = HC_STATE_RUNNING; 797 + uhci->hc_inaccessible = 0; 798 + 799 + /* The BIOS may have changed the controller settings during a 800 + * system wakeup. Check it and reconfigure to avoid problems. 801 + */ 802 + check_and_reset_hc(uhci); 803 + configure_hc(uhci); 804 + 805 + #ifndef CONFIG_USB_SUSPEND 806 + /* Otherwise this would never happen */ 807 + wakeup_rh(uhci); 808 + #endif 809 + if (uhci->rh_state == UHCI_RH_RESET) 810 + suspend_rh(uhci, UHCI_RH_SUSPENDED); 812 811 813 812 spin_unlock_irq(&uhci->lock); 813 + 814 + if (hcd->poll_rh) 815 + usb_hcd_poll_rh_status(hcd); 814 816 return 0; 815 817 } 816 818 #endif ··· 868 788 static int uhci_hcd_get_frame_number(struct usb_hcd *hcd) 869 789 { 870 790 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 871 - int frame_number; 872 791 unsigned long flags; 792 + int is_stopped; 793 + int frame_number; 873 794 874 795 /* Minimize latency by avoiding the spinlock */ 875 796 local_irq_save(flags); 876 - rmb(); 877 - frame_number = (uhci->is_stopped ? uhci->frame_number : 797 + is_stopped = uhci->is_stopped; 798 + smp_rmb(); 799 + frame_number = (is_stopped ? uhci->frame_number : 878 800 inw(uhci->io_addr + USBFRNUM)); 879 801 local_irq_restore(flags); 880 802 return frame_number; ··· 899 817 #ifdef CONFIG_PM 900 818 .suspend = uhci_suspend, 901 819 .resume = uhci_resume, 820 + .hub_suspend = uhci_rh_suspend, 821 + .hub_resume = uhci_rh_resume, 902 822 #endif 903 823 .stop = uhci_stop, 904 824 ··· 929 845 930 846 .probe = usb_hcd_pci_probe, 931 847 .remove = usb_hcd_pci_remove, 848 + .shutdown = uhci_shutdown, 932 849 933 850 #ifdef CONFIG_PM 934 851 .suspend = usb_hcd_pci_suspend,
+37 -22
drivers/usb/host/uhci-hcd.h
··· 41 41 #define USBFRNUM 6 42 42 #define USBFLBASEADD 8 43 43 #define USBSOF 12 44 + #define USBSOF_DEFAULT 64 /* Frame length is exactly 1 ms */ 44 45 45 46 /* USB port status and control registers */ 46 47 #define USBPORTSC1 16 ··· 67 66 /* Legacy support register */ 68 67 #define USBLEGSUP 0xc0 69 68 #define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */ 69 + #define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */ 70 + #define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */ 70 71 71 72 #define UHCI_NULL_DATA_SIZE 0x7FF /* for UHCI controller TD */ 72 73 ··· 114 111 /* Software fields */ 115 112 dma_addr_t dma_handle; 116 113 117 - struct usb_device *dev; 118 114 struct urb_priv *urbp; 119 115 120 116 struct list_head list; /* P: uhci->frame_list_lock */ ··· 205 203 /* Software fields */ 206 204 dma_addr_t dma_handle; 207 205 208 - struct usb_device *dev; 209 206 struct urb *urb; 210 207 211 208 struct list_head list; /* P: urb->lock */ ··· 315 314 } 316 315 317 316 /* 318 - * Device states for the host controller. 317 + * States for the root hub. 319 318 * 320 319 * To prevent "bouncing" in the presence of electrical noise, 321 - * we insist on a 1-second "grace" period, before switching to 322 - * the RUNNING or SUSPENDED states, during which the state is 323 - * not allowed to change. 324 - * 325 - * The resume process is divided into substates in order to avoid 326 - * potentially length delays during the timer handler. 327 - * 328 - * States in which the host controller is halted must have values <= 0. 320 + * when there are no devices attached we delay for 1 second in the 321 + * RUNNING_NODEVS state before switching to the AUTO_STOPPED state. 322 + * 323 + * (Note that the AUTO_STOPPED state won't be necessary once the hub 324 + * driver learns to autosuspend.) 329 325 */ 330 - enum uhci_state { 331 - UHCI_RESET, 332 - UHCI_RUNNING_GRACE, /* Before RUNNING */ 333 - UHCI_RUNNING, /* The normal state */ 334 - UHCI_SUSPENDING_GRACE, /* Before SUSPENDED */ 335 - UHCI_SUSPENDED = -10, /* When no devices are attached */ 336 - UHCI_RESUMING_1, 337 - UHCI_RESUMING_2 326 + enum uhci_rh_state { 327 + /* In the following states the HC must be halted. 328 + * These two must come first */ 329 + UHCI_RH_RESET, 330 + UHCI_RH_SUSPENDED, 331 + 332 + UHCI_RH_AUTO_STOPPED, 333 + UHCI_RH_RESUMING, 334 + 335 + /* In this state the HC changes from running to halted, 336 + * so it can legally appear either way. */ 337 + UHCI_RH_SUSPENDING, 338 + 339 + /* In the following states it's an error if the HC is halted. 340 + * These two must come last */ 341 + UHCI_RH_RUNNING, /* The normal state */ 342 + UHCI_RH_RUNNING_NODEVS, /* Running with no devices attached */ 338 343 }; 339 344 340 345 /* ··· 370 363 int fsbr; /* Full-speed bandwidth reclamation */ 371 364 unsigned long fsbrtimeout; /* FSBR delay */ 372 365 373 - enum uhci_state state; /* FIXME: needs a spinlock */ 374 - unsigned long state_end; /* Time of next transition */ 366 + enum uhci_rh_state rh_state; 367 + unsigned long auto_stop_time; /* When to AUTO_STOP */ 368 + 375 369 unsigned int frame_number; /* As of last check */ 376 370 unsigned int is_stopped; 377 371 #define UHCI_IS_STOPPED 9999 /* Larger than a frame # */ 378 372 379 373 unsigned int scan_in_progress:1; /* Schedule scan is running */ 380 374 unsigned int need_rescan:1; /* Redo the schedule scan */ 381 - unsigned int resume_detect:1; /* Need a Global Resume */ 375 + unsigned int hc_inaccessible:1; /* HC is suspended or dead */ 382 376 383 377 /* Support for port suspend/resume/reset */ 384 378 unsigned long port_c_suspend; /* Bit-arrays of ports */ ··· 458 450 * #1 uhci->lock 459 451 * #2 urb->lock 460 452 */ 453 + 454 + 455 + /* Some special IDs */ 456 + 457 + #define PCI_VENDOR_ID_GENESYS 0x17a0 458 + #define PCI_DEVICE_ID_GL880S_UHCI 0x8083 459 + #define PCI_DEVICE_ID_GL880S_EHCI 0x8084 461 460 462 461 #endif
+79 -4
drivers/usb/host/uhci-hub.c
··· 33 33 /* status change bits: nonzero writes will clear */ 34 34 #define RWC_BITS (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC) 35 35 36 - static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf) 36 + /* A port that either is connected or has a changed-bit set will prevent 37 + * us from AUTO_STOPPING. 38 + */ 39 + static int any_ports_active(struct uhci_hcd *uhci) 37 40 { 38 - struct uhci_hcd *uhci = hcd_to_uhci(hcd); 41 + int port; 42 + 43 + for (port = 0; port < uhci->rh_numports; ++port) { 44 + if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & 45 + (USBPORTSC_CCS | RWC_BITS)) || 46 + test_bit(port, &uhci->port_c_suspend)) 47 + return 1; 48 + } 49 + return 0; 50 + } 51 + 52 + static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf) 53 + { 39 54 int port; 40 55 41 56 *buf = 0; ··· 59 44 test_bit(port, &uhci->port_c_suspend)) 60 45 *buf |= (1 << (port + 1)); 61 46 } 62 - if (*buf && uhci->state == UHCI_SUSPENDED) 63 - uhci->resume_detect = 1; 64 47 return !!*buf; 65 48 } 66 49 ··· 128 115 set_bit(port, &uhci->resuming_ports); 129 116 uhci->ports_timeout = jiffies + 130 117 msecs_to_jiffies(20); 118 + 119 + /* Make sure we see the port again 120 + * after the resuming period is over. */ 121 + mod_timer(&uhci_to_hcd(uhci)->rh_timer, 122 + uhci->ports_timeout); 131 123 } else if (time_after_eq(jiffies, 132 124 uhci->ports_timeout)) { 133 125 uhci_finish_suspend(uhci, port, port_addr); 134 126 } 135 127 } 136 128 } 129 + } 130 + 131 + static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf) 132 + { 133 + struct uhci_hcd *uhci = hcd_to_uhci(hcd); 134 + unsigned long flags; 135 + int status; 136 + 137 + spin_lock_irqsave(&uhci->lock, flags); 138 + if (uhci->hc_inaccessible) { 139 + status = 0; 140 + goto done; 141 + } 142 + 143 + uhci_check_ports(uhci); 144 + status = get_hub_status_data(uhci, buf); 145 + 146 + switch (uhci->rh_state) { 147 + case UHCI_RH_SUSPENDING: 148 + case UHCI_RH_SUSPENDED: 149 + /* if port change, ask to be resumed */ 150 + if (status) 151 + usb_hcd_resume_root_hub(hcd); 152 + break; 153 + 154 + case UHCI_RH_AUTO_STOPPED: 155 + /* if port change, auto start */ 156 + if (status) 157 + wakeup_rh(uhci); 158 + break; 159 + 160 + case UHCI_RH_RUNNING: 161 + /* are any devices attached? */ 162 + if (!any_ports_active(uhci)) { 163 + uhci->rh_state = UHCI_RH_RUNNING_NODEVS; 164 + uhci->auto_stop_time = jiffies + HZ; 165 + } 166 + break; 167 + 168 + case UHCI_RH_RUNNING_NODEVS: 169 + /* auto-stop if nothing connected for 1 second */ 170 + if (any_ports_active(uhci)) 171 + uhci->rh_state = UHCI_RH_RUNNING; 172 + else if (time_after_eq(jiffies, uhci->auto_stop_time)) 173 + suspend_rh(uhci, UHCI_RH_AUTO_STOPPED); 174 + break; 175 + 176 + default: 177 + break; 178 + } 179 + 180 + done: 181 + spin_unlock_irqrestore(&uhci->lock, flags); 182 + return status; 137 183 } 138 184 139 185 /* size of returned buffer is part of USB spec */ ··· 205 133 unsigned long port_addr = uhci->io_addr + USBPORTSC1 + 2 * port; 206 134 u16 wPortChange, wPortStatus; 207 135 unsigned long flags; 136 + 137 + if (uhci->hc_inaccessible) 138 + return -ETIMEDOUT; 208 139 209 140 spin_lock_irqsave(&uhci->lock, flags); 210 141 switch (typeReq) {
+36 -22
drivers/usb/host/uhci-q.c
··· 32 32 */ 33 33 static inline void uhci_set_next_interrupt(struct uhci_hcd *uhci) 34 34 { 35 + if (uhci->is_stopped) 36 + mod_timer(&uhci->stall_timer, jiffies); 35 37 uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC); 36 38 } 37 39 ··· 48 46 list_move_tail(&urbp->urb_list, &uhci->complete_list); 49 47 } 50 48 51 - static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci, struct usb_device *dev) 49 + static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) 52 50 { 53 51 dma_addr_t dma_handle; 54 52 struct uhci_td *td; ··· 63 61 td->buffer = 0; 64 62 65 63 td->frame = -1; 66 - td->dev = dev; 67 64 68 65 INIT_LIST_HEAD(&td->list); 69 66 INIT_LIST_HEAD(&td->remove_list); 70 67 INIT_LIST_HEAD(&td->fl_list); 71 - 72 - usb_get_dev(dev); 73 68 74 69 return td; 75 70 } ··· 167 168 if (!list_empty(&td->fl_list)) 168 169 dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); 169 170 170 - if (td->dev) 171 - usb_put_dev(td->dev); 172 - 173 171 dma_pool_free(uhci->td_pool, td, td->dma_handle); 174 172 } 175 173 176 - static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, struct usb_device *dev) 174 + static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci) 177 175 { 178 176 dma_addr_t dma_handle; 179 177 struct uhci_qh *qh; ··· 184 188 qh->element = UHCI_PTR_TERM; 185 189 qh->link = UHCI_PTR_TERM; 186 190 187 - qh->dev = dev; 188 191 qh->urbp = NULL; 189 192 190 193 INIT_LIST_HEAD(&qh->list); 191 194 INIT_LIST_HEAD(&qh->remove_list); 192 - 193 - usb_get_dev(dev); 194 195 195 196 return qh; 196 197 } ··· 198 205 dev_warn(uhci_dev(uhci), "qh %p list not empty!\n", qh); 199 206 if (!list_empty(&qh->remove_list)) 200 207 dev_warn(uhci_dev(uhci), "qh %p still in remove_list!\n", qh); 201 - 202 - if (qh->dev) 203 - usb_put_dev(qh->dev); 204 208 205 209 dma_pool_free(uhci->qh_pool, qh, qh->dma_handle); 206 210 } ··· 587 597 /* 588 598 * Build the TD for the control request setup packet 589 599 */ 590 - td = uhci_alloc_td(uhci, urb->dev); 600 + td = uhci_alloc_td(uhci); 591 601 if (!td) 592 602 return -ENOMEM; 593 603 ··· 616 626 if (pktsze > maxsze) 617 627 pktsze = maxsze; 618 628 619 - td = uhci_alloc_td(uhci, urb->dev); 629 + td = uhci_alloc_td(uhci); 620 630 if (!td) 621 631 return -ENOMEM; 622 632 ··· 634 644 /* 635 645 * Build the final TD for control status 636 646 */ 637 - td = uhci_alloc_td(uhci, urb->dev); 647 + td = uhci_alloc_td(uhci); 638 648 if (!td) 639 649 return -ENOMEM; 640 650 ··· 656 666 uhci_fill_td(td, status | TD_CTRL_IOC, 657 667 destination | uhci_explen(UHCI_NULL_DATA_SIZE), 0); 658 668 659 - qh = uhci_alloc_qh(uhci, urb->dev); 669 + qh = uhci_alloc_qh(uhci); 660 670 if (!qh) 661 671 return -ENOMEM; 662 672 ··· 855 865 status &= ~TD_CTRL_SPD; 856 866 } 857 867 858 - td = uhci_alloc_td(uhci, urb->dev); 868 + td = uhci_alloc_td(uhci); 859 869 if (!td) 860 870 return -ENOMEM; 861 871 ··· 881 891 */ 882 892 if (usb_pipeout(urb->pipe) && (urb->transfer_flags & URB_ZERO_PACKET) && 883 893 !len && urb->transfer_buffer_length) { 884 - td = uhci_alloc_td(uhci, urb->dev); 894 + td = uhci_alloc_td(uhci); 885 895 if (!td) 886 896 return -ENOMEM; 887 897 ··· 903 913 * flag setting. */ 904 914 td->status |= cpu_to_le32(TD_CTRL_IOC); 905 915 906 - qh = uhci_alloc_qh(uhci, urb->dev); 916 + qh = uhci_alloc_qh(uhci); 907 917 if (!qh) 908 918 return -ENOMEM; 909 919 ··· 1086 1096 if (!urb->iso_frame_desc[i].length) 1087 1097 continue; 1088 1098 1089 - td = uhci_alloc_td(uhci, urb->dev); 1099 + td = uhci_alloc_td(uhci); 1090 1100 if (!td) 1091 1101 return -ENOMEM; 1092 1102 ··· 1487 1497 rescan: 1488 1498 uhci->need_rescan = 0; 1489 1499 1500 + uhci_clear_next_interrupt(uhci); 1490 1501 uhci_get_current_frame_number(uhci); 1491 1502 1492 1503 if (uhci->frame_number + uhci->is_stopped != uhci->qh_remove_age) ··· 1527 1536 1528 1537 /* Wake up anyone waiting for an URB to complete */ 1529 1538 wake_up_all(&uhci->waitqh); 1539 + } 1540 + 1541 + static void check_fsbr(struct uhci_hcd *uhci) 1542 + { 1543 + struct urb_priv *up; 1544 + 1545 + list_for_each_entry(up, &uhci->urb_list, urb_list) { 1546 + struct urb *u = up->urb; 1547 + 1548 + spin_lock(&u->lock); 1549 + 1550 + /* Check if the FSBR timed out */ 1551 + if (up->fsbr && !up->fsbr_timeout && time_after_eq(jiffies, up->fsbrtime + IDLE_TIMEOUT)) 1552 + uhci_fsbr_timeout(uhci, u); 1553 + 1554 + spin_unlock(&u->lock); 1555 + } 1556 + 1557 + /* Really disable FSBR */ 1558 + if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) { 1559 + uhci->fsbrtimeout = 0; 1560 + uhci->skel_term_qh->link = UHCI_PTR_TERM; 1561 + } 1530 1562 }
+1
drivers/usb/input/ati_remote.c
··· 639 639 idev->id.vendor = le16_to_cpu(ati_remote->udev->descriptor.idVendor); 640 640 idev->id.product = le16_to_cpu(ati_remote->udev->descriptor.idProduct); 641 641 idev->id.version = le16_to_cpu(ati_remote->udev->descriptor.bcdDevice); 642 + idev->dev = &(ati_remote->udev->dev); 642 643 } 643 644 644 645 static int ati_remote_initialize(struct ati_remote *ati_remote)
+6 -2
drivers/usb/media/stv680.c
··· 1375 1375 (le16_to_cpu(dev->descriptor.idProduct) == USB_PENCAM_PRODUCT_ID)) { 1376 1376 camera_name = "STV0680"; 1377 1377 PDEBUG (0, "STV(i): STV0680 camera found."); 1378 + } else if ((le16_to_cpu(dev->descriptor.idVendor) == USB_CREATIVEGOMINI_VENDOR_ID) && 1379 + (le16_to_cpu(dev->descriptor.idProduct) == USB_CREATIVEGOMINI_PRODUCT_ID)) { 1380 + camera_name = "Creative WebCam Go Mini"; 1381 + PDEBUG (0, "STV(i): Creative WebCam Go Mini found."); 1378 1382 } else { 1379 - PDEBUG (0, "STV(e): Vendor/Product ID do not match STV0680 values."); 1380 - PDEBUG (0, "STV(e): Check that the STV0680 camera is connected to the computer."); 1383 + PDEBUG (0, "STV(e): Vendor/Product ID do not match STV0680 or Creative WebCam Go Mini values."); 1384 + PDEBUG (0, "STV(e): Check that the STV0680 or Creative WebCam Go Mini camera is connected to the computer."); 1381 1385 retval = -ENODEV; 1382 1386 goto error; 1383 1387 }
+5
drivers/usb/media/stv680.h
··· 41 41 42 42 #define USB_PENCAM_VENDOR_ID 0x0553 43 43 #define USB_PENCAM_PRODUCT_ID 0x0202 44 + 45 + #define USB_CREATIVEGOMINI_VENDOR_ID 0x041e 46 + #define USB_CREATIVEGOMINI_PRODUCT_ID 0x4007 47 + 44 48 #define PENCAM_TIMEOUT 1000 45 49 /* fmt 4 */ 46 50 #define STV_VIDEO_PALETTE VIDEO_PALETTE_RGB24 47 51 48 52 static struct usb_device_id device_table[] = { 49 53 {USB_DEVICE (USB_PENCAM_VENDOR_ID, USB_PENCAM_PRODUCT_ID)}, 54 + {USB_DEVICE (USB_CREATIVEGOMINI_VENDOR_ID, USB_CREATIVEGOMINI_PRODUCT_ID)}, 50 55 {} 51 56 }; 52 57 MODULE_DEVICE_TABLE (usb, device_table);
+88 -61
drivers/usb/misc/idmouse.c
··· 1 - /* Siemens ID Mouse driver v0.5 1 + /* Siemens ID Mouse driver v0.6 2 2 3 3 This program is free software; you can redistribute it and/or 4 4 modify it under the terms of the GNU General Public License as ··· 10 10 11 11 Derived from the USB Skeleton driver 1.1, 12 12 Copyright (C) 2003 Greg Kroah-Hartman (greg@kroah.com) 13 + 14 + Additional information provided by Martin Reising 15 + <Martin.Reising@natural-computing.de> 13 16 14 17 */ 15 18 ··· 28 25 #include <asm/uaccess.h> 29 26 #include <linux/usb.h> 30 27 28 + /* image constants */ 31 29 #define WIDTH 225 32 - #define HEIGHT 288 33 - #define HEADER "P5 225 288 255 " 30 + #define HEIGHT 289 31 + #define HEADER "P5 225 289 255 " 34 32 #define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1) 35 33 36 - /* Version Information */ 37 - #define DRIVER_VERSION "0.5" 34 + /* version information */ 35 + #define DRIVER_VERSION "0.6" 38 36 #define DRIVER_SHORT "idmouse" 39 37 #define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>" 40 38 #define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver" 41 39 42 - /* Siemens ID Mouse */ 43 - #define USB_IDMOUSE_VENDOR_ID 0x0681 44 - #define USB_IDMOUSE_PRODUCT_ID 0x0005 45 - 46 - /* we still need a minor number */ 40 + /* minor number for misc USB devices */ 47 41 #define USB_IDMOUSE_MINOR_BASE 132 48 42 43 + /* vendor and device IDs */ 44 + #define ID_SIEMENS 0x0681 45 + #define ID_IDMOUSE 0x0005 46 + #define ID_CHERRY 0x0010 47 + 48 + /* device ID table */ 49 49 static struct usb_device_id idmouse_table[] = { 50 - {USB_DEVICE(USB_IDMOUSE_VENDOR_ID, USB_IDMOUSE_PRODUCT_ID)}, 51 - {} /* null entry at the end */ 50 + {USB_DEVICE(ID_SIEMENS, ID_IDMOUSE)}, /* Siemens ID Mouse (Professional) */ 51 + {USB_DEVICE(ID_SIEMENS, ID_CHERRY )}, /* Cherry FingerTIP ID Board */ 52 + {} /* terminating null entry */ 52 53 }; 54 + 55 + /* sensor commands */ 56 + #define FTIP_RESET 0x20 57 + #define FTIP_ACQUIRE 0x21 58 + #define FTIP_RELEASE 0x22 59 + #define FTIP_BLINK 0x23 /* LSB of value = blink pulse width */ 60 + #define FTIP_SCROLL 0x24 61 + 62 + #define ftip_command(dev, command, value, index) \ 63 + usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), command, \ 64 + USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000) 53 65 54 66 MODULE_DEVICE_TABLE(usb, idmouse_table); 55 67 ··· 75 57 struct usb_interface *interface; /* the interface for this device */ 76 58 77 59 unsigned char *bulk_in_buffer; /* the buffer to receive data */ 78 - size_t bulk_in_size; /* the size of the receive buffer */ 60 + size_t bulk_in_size; /* the maximum bulk packet size */ 61 + size_t orig_bi_size; /* same as above, but reported by the device */ 79 62 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ 80 63 81 64 int open; /* if the port is open or not */ ··· 122 103 .id_table = idmouse_table, 123 104 }; 124 105 125 - // prevent races between open() and disconnect() 106 + /* prevent races between open() and disconnect() */ 126 107 static DECLARE_MUTEX(disconnect_sem); 127 108 128 109 static int idmouse_create_image(struct usb_idmouse *dev) ··· 131 112 int bulk_read = 0; 132 113 int result = 0; 133 114 134 - if (dev->bulk_in_size < sizeof(HEADER)) 135 - return -ENOMEM; 136 - 137 - memcpy(dev->bulk_in_buffer,HEADER,sizeof(HEADER)-1); 115 + memcpy(dev->bulk_in_buffer, HEADER, sizeof(HEADER)-1); 138 116 bytes_read += sizeof(HEADER)-1; 139 117 140 - /* Dump the setup packets. Yes, they are uncommented, simply 141 - because they were sniffed under Windows using SnoopyPro. 142 - I _guess_ that 0x22 is a kind of reset command and 0x21 143 - means init.. 144 - */ 145 - result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 146 - 0x21, 0x42, 0x0001, 0x0002, NULL, 0, 1000); 118 + /* reset the device and set a fast blink rate */ 119 + result = ftip_command(dev, FTIP_RELEASE, 0, 0); 147 120 if (result < 0) 148 - return result; 149 - result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 150 - 0x20, 0x42, 0x0001, 0x0002, NULL, 0, 1000); 121 + goto reset; 122 + result = ftip_command(dev, FTIP_BLINK, 1, 0); 151 123 if (result < 0) 152 - return result; 153 - result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 154 - 0x22, 0x42, 0x0000, 0x0002, NULL, 0, 1000); 155 - if (result < 0) 156 - return result; 124 + goto reset; 157 125 158 - result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 159 - 0x21, 0x42, 0x0001, 0x0002, NULL, 0, 1000); 126 + /* initialize the sensor - sending this command twice */ 127 + /* significantly reduces the rate of failed reads */ 128 + result = ftip_command(dev, FTIP_ACQUIRE, 0, 0); 160 129 if (result < 0) 161 - return result; 162 - result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 163 - 0x20, 0x42, 0x0001, 0x0002, NULL, 0, 1000); 130 + goto reset; 131 + result = ftip_command(dev, FTIP_ACQUIRE, 0, 0); 164 132 if (result < 0) 165 - return result; 166 - result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 167 - 0x20, 0x42, 0x0000, 0x0002, NULL, 0, 1000); 133 + goto reset; 134 + 135 + /* start the readout - sending this command twice */ 136 + /* presumably enables the high dynamic range mode */ 137 + result = ftip_command(dev, FTIP_RESET, 0, 0); 168 138 if (result < 0) 169 - return result; 139 + goto reset; 140 + result = ftip_command(dev, FTIP_RESET, 0, 0); 141 + if (result < 0) 142 + goto reset; 170 143 171 144 /* loop over a blocking bulk read to get data from the device */ 172 145 while (bytes_read < IMGSIZE) { ··· 166 155 usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr), 167 156 dev->bulk_in_buffer + bytes_read, 168 157 dev->bulk_in_size, &bulk_read, 5000); 169 - if (result < 0) 170 - return result; 171 - if (signal_pending(current)) 172 - return -EINTR; 158 + if (result < 0) { 159 + /* Maybe this error was caused by the increased packet size? */ 160 + /* Reset to the original value and tell userspace to retry. */ 161 + if (dev->bulk_in_size != dev->orig_bi_size) { 162 + dev->bulk_in_size = dev->orig_bi_size; 163 + result = -EAGAIN; 164 + } 165 + break; 166 + } 167 + if (signal_pending(current)) { 168 + result = -EINTR; 169 + break; 170 + } 173 171 bytes_read += bulk_read; 174 172 } 175 173 176 174 /* reset the device */ 177 - result = usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), 178 - 0x22, 0x42, 0x0000, 0x0002, NULL, 0, 1000); 179 - if (result < 0) 180 - return result; 175 + reset: 176 + ftip_command(dev, FTIP_RELEASE, 0, 0); 181 177 182 - /* should be IMGSIZE == 64815 */ 178 + /* check for valid image */ 179 + /* right border should be black (0x00) */ 180 + for (bytes_read = sizeof(HEADER)-1 + WIDTH-1; bytes_read < IMGSIZE; bytes_read += WIDTH) 181 + if (dev->bulk_in_buffer[bytes_read] != 0x00) 182 + return -EAGAIN; 183 + 184 + /* lower border should be white (0xFF) */ 185 + for (bytes_read = IMGSIZE-WIDTH; bytes_read < IMGSIZE-1; bytes_read++) 186 + if (dev->bulk_in_buffer[bytes_read] != 0xFF) 187 + return -EAGAIN; 188 + 189 + /* should be IMGSIZE == 65040 */ 183 190 dbg("read %d bytes fingerprint data", bytes_read); 184 - return 0; 191 + return result; 185 192 } 186 193 187 194 static inline void idmouse_delete(struct usb_idmouse *dev) ··· 311 282 312 283 dev = (struct usb_idmouse *) file->private_data; 313 284 314 - // lock this object 285 + /* lock this object */ 315 286 down (&dev->sem); 316 287 317 - // verify that the device wasn't unplugged 288 + /* verify that the device wasn't unplugged */ 318 289 if (!dev->present) { 319 290 up (&dev->sem); 320 291 return -ENODEV; ··· 325 296 return 0; 326 297 } 327 298 328 - if (count > IMGSIZE - *ppos) 329 - count = IMGSIZE - *ppos; 299 + count = min ((loff_t)count, IMGSIZE - (*ppos)); 330 300 331 301 if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) { 332 302 result = -EFAULT; ··· 334 306 *ppos += count; 335 307 } 336 308 337 - // unlock the device 309 + /* unlock the device */ 338 310 up(&dev->sem); 339 311 return result; 340 312 } ··· 346 318 struct usb_idmouse *dev = NULL; 347 319 struct usb_host_interface *iface_desc; 348 320 struct usb_endpoint_descriptor *endpoint; 349 - size_t buffer_size; 350 321 int result; 351 322 352 323 /* check if we have gotten the data or the hid interface */ ··· 371 344 USB_ENDPOINT_XFER_BULK)) { 372 345 373 346 /* we found a bulk in endpoint */ 374 - buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 375 - dev->bulk_in_size = buffer_size; 347 + dev->orig_bi_size = le16_to_cpu(endpoint->wMaxPacketSize); 348 + dev->bulk_in_size = 0x200; /* works _much_ faster */ 376 349 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; 377 350 dev->bulk_in_buffer = 378 - kmalloc(IMGSIZE + buffer_size, GFP_KERNEL); 351 + kmalloc(IMGSIZE + dev->bulk_in_size, GFP_KERNEL); 379 352 380 353 if (!dev->bulk_in_buffer) { 381 354 err("Unable to allocate input buffer.");
+52 -8
drivers/usb/misc/usbtest.c
··· 461 461 462 462 static unsigned realworld = 1; 463 463 module_param (realworld, uint, 0); 464 - MODULE_PARM_DESC (realworld, "clear to demand stricter ch9 compliance"); 464 + MODULE_PARM_DESC (realworld, "clear to demand stricter spec compliance"); 465 465 466 466 static int get_altsetting (struct usbtest_dev *dev) 467 467 { ··· 604 604 USB_DIR_IN | USB_RECIP_DEVICE, 605 605 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); 606 606 if (retval != 1 || dev->buf [0] != expected) { 607 - dev_dbg (&iface->dev, 608 - "get config --> %d (%d)\n", retval, 609 - expected); 607 + dev_dbg (&iface->dev, "get config --> %d %d (1 %d)\n", 608 + retval, dev->buf[0], expected); 610 609 return (retval < 0) ? retval : -EDOM; 611 610 } 612 611 } ··· 1242 1243 char *what = "?"; 1243 1244 struct usb_device *udev; 1244 1245 1245 - if (length > 0xffff || vary >= length) 1246 + if (length < 1 || length > 0xffff || vary >= length) 1246 1247 return -EINVAL; 1247 1248 1248 1249 buf = kmalloc(length, SLAB_KERNEL); ··· 1265 1266 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); 1266 1267 if (retval != len) { 1267 1268 what = "write"; 1269 + if (retval >= 0) { 1270 + INFO(dev, "ctrl_out, wlen %d (expected %d)\n", 1271 + retval, len); 1272 + retval = -EBADMSG; 1273 + } 1268 1274 break; 1269 1275 } 1270 1276 ··· 1279 1275 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); 1280 1276 if (retval != len) { 1281 1277 what = "read"; 1278 + if (retval >= 0) { 1279 + INFO(dev, "ctrl_out, rlen %d (expected %d)\n", 1280 + retval, len); 1281 + retval = -EBADMSG; 1282 + } 1282 1283 break; 1283 1284 } 1284 1285 ··· 1302 1293 } 1303 1294 1304 1295 len += vary; 1296 + 1297 + /* [real world] the "zero bytes IN" case isn't really used. 1298 + * hardware can easily trip up in this wierd case, since its 1299 + * status stage is IN, not OUT like other ep0in transfers. 1300 + */ 1305 1301 if (len > length) 1306 - len = 0; 1302 + len = realworld ? 1 : 0; 1307 1303 } 1308 1304 1309 1305 if (retval < 0) ··· 1532 1518 1533 1519 if (down_interruptible (&dev->sem)) 1534 1520 return -ERESTARTSYS; 1521 + 1522 + if (intf->dev.power.power_state != PMSG_ON) { 1523 + up (&dev->sem); 1524 + return -EHOSTUNREACH; 1525 + } 1535 1526 1536 1527 /* some devices, like ez-usb default devices, need a non-default 1537 1528 * altsetting to have any active endpoints. some tests change ··· 1781 1762 case 14: 1782 1763 if (!dev->info->ctrl_out) 1783 1764 break; 1784 - dev_dbg (&intf->dev, "TEST 14: %d ep0out, 0..%d vary %d\n", 1785 - param->iterations, param->length, param->vary); 1765 + dev_dbg (&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n", 1766 + param->iterations, 1767 + realworld ? 1 : 0, param->length, 1768 + param->vary); 1786 1769 retval = ctrl_out (dev, param->iterations, 1787 1770 param->length, param->vary); 1788 1771 break; ··· 1947 1926 info->alt >= 0 ? " (+alt)" : ""); 1948 1927 return 0; 1949 1928 } 1929 + 1930 + static int usbtest_suspend (struct usb_interface *intf, pm_message_t message) 1931 + { 1932 + struct usbtest_dev *dev = usb_get_intfdata (intf); 1933 + 1934 + down (&dev->sem); 1935 + intf->dev.power.power_state = PMSG_SUSPEND; 1936 + up (&dev->sem); 1937 + return 0; 1938 + } 1939 + 1940 + static int usbtest_resume (struct usb_interface *intf) 1941 + { 1942 + struct usbtest_dev *dev = usb_get_intfdata (intf); 1943 + 1944 + down (&dev->sem); 1945 + intf->dev.power.power_state = PMSG_ON; 1946 + up (&dev->sem); 1947 + return 0; 1948 + } 1949 + 1950 1950 1951 1951 static void usbtest_disconnect (struct usb_interface *intf) 1952 1952 { ··· 2157 2115 .probe = usbtest_probe, 2158 2116 .ioctl = usbtest_ioctl, 2159 2117 .disconnect = usbtest_disconnect, 2118 + .suspend = usbtest_suspend, 2119 + .resume = usbtest_resume, 2160 2120 }; 2161 2121 2162 2122 /*-------------------------------------------------------------------------*/
+1 -1
drivers/usb/net/usbnet.c
··· 1429 1429 info->ether = (void *) buf; 1430 1430 if (info->ether->bLength != sizeof *info->ether) { 1431 1431 dev_dbg (&intf->dev, "CDC ether len %u\n", 1432 - info->u->bLength); 1432 + info->ether->bLength); 1433 1433 goto bad_desc; 1434 1434 } 1435 1435 dev->net->mtu = le16_to_cpup (
+41
drivers/usb/net/zd1201.c
··· 1884 1884 kfree(zd); 1885 1885 } 1886 1886 1887 + #ifdef CONFIG_PM 1888 + 1889 + static int zd1201_suspend(struct usb_interface *interface, 1890 + pm_message_t message) 1891 + { 1892 + struct zd1201 *zd = usb_get_intfdata(interface); 1893 + 1894 + netif_device_detach(zd->dev); 1895 + 1896 + zd->was_enabled = zd->mac_enabled; 1897 + 1898 + if (zd->was_enabled) 1899 + return zd1201_disable(zd); 1900 + else 1901 + return 0; 1902 + } 1903 + 1904 + static int zd1201_resume(struct usb_interface *interface) 1905 + { 1906 + struct zd1201 *zd = usb_get_intfdata(interface); 1907 + 1908 + if (!zd || !zd->dev) 1909 + return -ENODEV; 1910 + 1911 + netif_device_attach(zd->dev); 1912 + 1913 + if (zd->was_enabled) 1914 + return zd1201_enable(zd); 1915 + else 1916 + return 0; 1917 + } 1918 + 1919 + #else 1920 + 1921 + #define zd1201_suspend NULL 1922 + #define zd1201_resume NULL 1923 + 1924 + #endif 1925 + 1887 1926 static struct usb_driver zd1201_usb = { 1888 1927 .owner = THIS_MODULE, 1889 1928 .name = "zd1201", 1890 1929 .probe = zd1201_probe, 1891 1930 .disconnect = zd1201_disconnect, 1892 1931 .id_table = zd1201_table, 1932 + .suspend = zd1201_suspend, 1933 + .resume = zd1201_resume, 1893 1934 }; 1894 1935 1895 1936 static int __init zd1201_init(void)
+1
drivers/usb/net/zd1201.h
··· 46 46 char essid[IW_ESSID_MAX_SIZE+1]; 47 47 int essidlen; 48 48 int mac_enabled; 49 + int was_enabled; 49 50 int monitor; 50 51 int encode_enabled; 51 52 int encode_restricted;
+10 -9
drivers/usb/serial/cyberjack.c
··· 213 213 return (0); 214 214 } 215 215 216 - if (port->write_urb->status == -EINPROGRESS) { 216 + spin_lock(&port->lock); 217 + if (port->write_urb_busy) { 218 + spin_unlock(&port->lock); 217 219 dbg("%s - already writing", __FUNCTION__); 218 - return (0); 220 + return 0; 219 221 } 222 + port->write_urb_busy = 1; 223 + spin_unlock(&port->lock); 220 224 221 225 spin_lock_irqsave(&priv->lock, flags); 222 226 ··· 228 224 /* To much data for buffer. Reset buffer. */ 229 225 priv->wrfilled=0; 230 226 spin_unlock_irqrestore(&priv->lock, flags); 227 + port->write_urb_busy = 0; 231 228 return (0); 232 229 } 233 230 ··· 273 268 priv->wrfilled=0; 274 269 priv->wrsent=0; 275 270 spin_unlock_irqrestore(&priv->lock, flags); 271 + port->write_urb_busy = 0; 276 272 return 0; 277 273 } 278 274 ··· 418 412 struct cyberjack_private *priv = usb_get_serial_port_data(port); 419 413 420 414 dbg("%s - port %d", __FUNCTION__, port->number); 421 - 415 + 416 + port->write_urb_busy = 0; 422 417 if (urb->status) { 423 418 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 424 419 return; ··· 430 423 /* only do something if we have more data to send */ 431 424 if( priv->wrfilled ) { 432 425 int length, blksize, result; 433 - 434 - if (port->write_urb->status == -EINPROGRESS) { 435 - dbg("%s - already writing", __FUNCTION__); 436 - spin_unlock(&priv->lock); 437 - return; 438 - } 439 426 440 427 dbg("%s - transmitting data (frame n)", __FUNCTION__); 441 428
+16 -8
drivers/usb/serial/generic.c
··· 174 174 175 175 /* only do something if we have a bulk out endpoint */ 176 176 if (serial->num_bulk_out) { 177 - if (port->write_urb->status == -EINPROGRESS) { 177 + spin_lock(&port->lock); 178 + if (port->write_urb_busy) { 179 + spin_unlock(&port->lock); 178 180 dbg("%s - already writing", __FUNCTION__); 179 - return (0); 181 + return 0; 180 182 } 183 + port->write_urb_busy = 1; 184 + spin_unlock(&port->lock); 181 185 182 186 count = (count > port->bulk_out_size) ? port->bulk_out_size : count; 183 187 ··· 199 195 usb_serial_generic_write_bulk_callback), port); 200 196 201 197 /* send the data out the bulk port */ 198 + port->write_urb_busy = 1; 202 199 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 203 - if (result) 200 + if (result) { 204 201 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 205 - else 202 + /* don't have to grab the lock here, as we will retry if != 0 */ 203 + port->write_urb_busy = 0; 204 + } else 206 205 result = count; 207 206 208 207 return result; 209 208 } 210 209 211 210 /* no bulk out, so return 0 bytes written */ 212 - return (0); 211 + return 0; 213 212 } 214 213 215 214 int usb_serial_generic_write_room (struct usb_serial_port *port) ··· 221 214 int room = 0; 222 215 223 216 dbg("%s - port %d", __FUNCTION__, port->number); 224 - 217 + 225 218 if (serial->num_bulk_out) { 226 - if (port->write_urb->status != -EINPROGRESS) 219 + if (port->write_urb_busy) 227 220 room = port->bulk_out_size; 228 221 } 229 222 ··· 239 232 dbg("%s - port %d", __FUNCTION__, port->number); 240 233 241 234 if (serial->num_bulk_out) { 242 - if (port->write_urb->status == -EINPROGRESS) 235 + if (port->write_urb_busy) 243 236 chars = port->write_urb->transfer_buffer_length; 244 237 } 245 238 ··· 298 291 299 292 dbg("%s - port %d", __FUNCTION__, port->number); 300 293 294 + port->write_urb_busy = 0; 301 295 if (urb->status) { 302 296 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 303 297 return;
-5
drivers/usb/serial/ipaq.c
··· 818 818 struct ipaq_packet *pkt, *tmp; 819 819 struct urb *urb = port->write_urb; 820 820 821 - if (urb->status == -EINPROGRESS) { 822 - /* Should never happen */ 823 - err("%s - flushing while urb is active !", __FUNCTION__); 824 - return; 825 - } 826 821 room = URBDATA_SIZE; 827 822 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) { 828 823 count = min(room, (int)(pkt->len - pkt->written));
+10 -4
drivers/usb/serial/ipw.c
··· 399 399 dbg("%s - write request of 0 bytes", __FUNCTION__); 400 400 return 0; 401 401 } 402 - 403 - /* Racy and broken, FIXME properly! */ 404 - if (port->write_urb->status == -EINPROGRESS) 402 + 403 + spin_lock(&port->lock); 404 + if (port->write_urb_busy) { 405 + spin_unlock(&port->lock); 406 + dbg("%s - already writing", __FUNCTION__); 405 407 return 0; 408 + } 409 + port->write_urb_busy = 1; 410 + spin_unlock(&port->lock); 406 411 407 412 count = min(count, port->bulk_out_size); 408 413 memcpy(port->bulk_out_buffer, buf, count); 409 414 410 415 dbg("%s count now:%d", __FUNCTION__, count); 411 - 416 + 412 417 usb_fill_bulk_urb(port->write_urb, dev, 413 418 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress), 414 419 port->write_urb->transfer_buffer, ··· 423 418 424 419 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); 425 420 if (ret != 0) { 421 + port->write_urb_busy = 0; 426 422 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __FUNCTION__, ret); 427 423 return ret; 428 424 }
+11 -5
drivers/usb/serial/ir-usb.c
··· 341 341 if (count == 0) 342 342 return 0; 343 343 344 - if (port->write_urb->status == -EINPROGRESS) { 345 - dbg ("%s - already writing", __FUNCTION__); 344 + spin_lock(&port->lock); 345 + if (port->write_urb_busy) { 346 + spin_unlock(&port->lock); 347 + dbg("%s - already writing", __FUNCTION__); 346 348 return 0; 347 349 } 350 + port->write_urb_busy = 1; 351 + spin_unlock(&port->lock); 348 352 349 353 transfer_buffer = port->write_urb->transfer_buffer; 350 354 transfer_size = min(count, port->bulk_out_size - 1); ··· 378 374 port->write_urb->transfer_flags = URB_ZERO_PACKET; 379 375 380 376 result = usb_submit_urb (port->write_urb, GFP_ATOMIC); 381 - if (result) 377 + if (result) { 378 + port->write_urb_busy = 0; 382 379 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); 383 - else 380 + } else 384 381 result = transfer_size; 385 382 386 383 return result; ··· 392 387 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 393 388 394 389 dbg("%s - port %d", __FUNCTION__, port->number); 395 - 390 + 391 + port->write_urb_busy = 0; 396 392 if (urb->status) { 397 393 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 398 394 return;
+13 -6
drivers/usb/serial/keyspan_pda.c
··· 520 520 the TX urb is in-flight (wait until it completes) 521 521 the device is full (wait until it says there is room) 522 522 */ 523 - if (port->write_urb->status == -EINPROGRESS || priv->tx_throttled ) { 524 - return( 0 ); 523 + spin_lock(&port->lock); 524 + if (port->write_urb_busy || priv->tx_throttled) { 525 + spin_unlock(&port->lock); 526 + return 0; 525 527 } 528 + port->write_urb_busy = 1; 529 + spin_unlock(&port->lock); 526 530 527 531 /* At this point the URB is in our control, nobody else can submit it 528 532 again (the only sudden transition was the one from EINPROGRESS to ··· 574 570 memcpy (port->write_urb->transfer_buffer, buf, count); 575 571 /* send the data out the bulk port */ 576 572 port->write_urb->transfer_buffer_length = count; 577 - 573 + 578 574 priv->tx_room -= count; 579 575 580 576 port->write_urb->dev = port->serial->dev; ··· 597 593 598 594 rc = count; 599 595 exit: 596 + if (rc < 0) 597 + port->write_urb_busy = 0; 600 598 return rc; 601 599 } 602 600 ··· 608 602 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 609 603 struct keyspan_pda_private *priv; 610 604 605 + port->write_urb_busy = 0; 611 606 priv = usb_get_serial_port_data(port); 612 607 613 608 /* queue up a wakeup at scheduler time */ ··· 633 626 static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port) 634 627 { 635 628 struct keyspan_pda_private *priv; 636 - 629 + 637 630 priv = usb_get_serial_port_data(port); 638 - 631 + 639 632 /* when throttled, return at least WAKEUP_CHARS to tell select() (via 640 633 n_tty.c:normal_poll() ) that we're not writeable. */ 641 - if( port->write_urb->status == -EINPROGRESS || priv->tx_throttled ) 634 + if (port->write_urb_busy || priv->tx_throttled) 642 635 return 256; 643 636 return 0; 644 637 }
+12 -5
drivers/usb/serial/omninet.c
··· 254 254 dbg("%s - write request of 0 bytes", __FUNCTION__); 255 255 return (0); 256 256 } 257 - if (wport->write_urb->status == -EINPROGRESS) { 257 + 258 + spin_lock(&port->lock); 259 + if (port->write_urb_busy) { 260 + spin_unlock(&port->lock); 258 261 dbg("%s - already writing", __FUNCTION__); 259 - return (0); 262 + return 0; 260 263 } 264 + port->write_urb_busy = 1; 265 + spin_unlock(&port->lock); 261 266 262 267 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 263 268 ··· 280 275 281 276 wport->write_urb->dev = serial->dev; 282 277 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 283 - if (result) 278 + if (result) { 279 + port->write_urb_busy = 0; 284 280 err("%s - failed submitting write urb, error %d", __FUNCTION__, result); 285 - else 281 + } else 286 282 result = count; 287 283 288 284 return result; ··· 297 291 298 292 int room = 0; // Default: no room 299 293 300 - if (wport->write_urb->status != -EINPROGRESS) 294 + if (wport->write_urb_busy) 301 295 room = wport->bulk_out_size - OMNINET_HEADERLEN; 302 296 303 297 // dbg("omninet_write_room returns %d", room); ··· 312 306 313 307 // dbg("omninet_write_bulk_callback, port %0x\n", port); 314 308 309 + port->write_urb_busy = 0; 315 310 if (urb->status) { 316 311 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); 317 312 return;
+9 -4
drivers/usb/serial/safe_serial.c
··· 299 299 dbg ("%s - write request of 0 bytes", __FUNCTION__); 300 300 return (0); 301 301 } 302 - if (port->write_urb->status == -EINPROGRESS) { 303 - dbg ("%s - already writing", __FUNCTION__); 304 - return (0); 302 + spin_lock(&port->lock); 303 + if (port->write_urb_busy) { 304 + spin_unlock(&port->lock); 305 + dbg("%s - already writing", __FUNCTION__); 306 + return 0; 305 307 } 308 + port->write_urb_busy = 1; 309 + spin_unlock(&port->lock); 306 310 307 311 packet_length = port->bulk_out_size; // get max packetsize 308 312 ··· 358 354 #endif 359 355 port->write_urb->dev = port->serial->dev; 360 356 if ((result = usb_submit_urb (port->write_urb, GFP_KERNEL))) { 357 + port->write_urb_busy = 0; 361 358 err ("%s - failed submitting write urb, error %d", __FUNCTION__, result); 362 359 return 0; 363 360 } ··· 373 368 374 369 dbg ("%s", __FUNCTION__); 375 370 376 - if (port->write_urb->status != -EINPROGRESS) 371 + if (port->write_urb_busy) 377 372 room = port->bulk_out_size - (safe ? 2 : 0); 378 373 379 374 if (room) {
+1
drivers/usb/serial/usb-serial.c
··· 1047 1047 memset(port, 0x00, sizeof(struct usb_serial_port)); 1048 1048 port->number = i + serial->minor; 1049 1049 port->serial = serial; 1050 + spin_lock_init(&port->lock); 1050 1051 INIT_WORK(&port->work, usb_serial_port_softint, port); 1051 1052 serial->port[i] = port; 1052 1053 }
+3
drivers/usb/serial/usb-serial.h
··· 69 69 * usb_serial_port: structure for the specific ports of a device. 70 70 * @serial: pointer back to the struct usb_serial owner of this port. 71 71 * @tty: pointer to the corresponding tty for this port. 72 + * @lock: spinlock to grab when updating portions of this structure. 72 73 * @number: the number of the port (the minor number). 73 74 * @interrupt_in_buffer: pointer to the interrupt in buffer for this port. 74 75 * @interrupt_in_urb: pointer to the interrupt in struct urb for this port. ··· 99 98 struct usb_serial_port { 100 99 struct usb_serial * serial; 101 100 struct tty_struct * tty; 101 + spinlock_t lock; 102 102 unsigned char number; 103 103 104 104 unsigned char * interrupt_in_buffer; ··· 119 117 unsigned char * bulk_out_buffer; 120 118 int bulk_out_size; 121 119 struct urb * write_urb; 120 + int write_urb_busy; 122 121 __u8 bulk_out_endpointAddress; 123 122 124 123 wait_queue_head_t write_wait;
+22 -32
drivers/usb/storage/scsiglue.c
··· 155 155 * If this device makes that mistake, tell the sd driver. */ 156 156 if (us->flags & US_FL_FIX_CAPACITY) 157 157 sdev->fix_capacity = 1; 158 + 159 + /* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable 160 + * Hardware Error) when any low-level error occurs, 161 + * recoverable or not. Setting this flag tells the SCSI 162 + * midlayer to retry such commands, which frequently will 163 + * succeed and fix the error. The worst this can lead to 164 + * is an occasional series of retries that will all fail. */ 165 + sdev->retry_hwerror = 1; 166 + 158 167 } else { 159 168 160 169 /* Non-disk-type devices don't need to blacklist any pages ··· 264 255 265 256 /* lock the device pointers and do the reset */ 266 257 down(&(us->dev_semaphore)); 267 - if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 268 - result = FAILED; 269 - US_DEBUGP("No reset during disconnect\n"); 270 - } else 271 - result = us->transport_reset(us); 258 + result = us->transport_reset(us); 272 259 up(&(us->dev_semaphore)); 273 260 274 - return result; 261 + return result < 0 ? FAILED : SUCCESS; 275 262 } 276 263 277 - /* This resets the device's USB port. */ 278 - /* It refuses to work if there's more than one interface in 279 - * the device, so that other users are not affected. */ 264 + /* Simulate a SCSI bus reset by resetting the device's USB port. */ 280 265 /* This is always called with scsi_lock(host) held */ 281 266 static int bus_reset(struct scsi_cmnd *srb) 282 267 { 283 268 struct us_data *us = host_to_us(srb->device->host); 284 - int result, rc; 269 + int result; 285 270 286 271 US_DEBUGP("%s called\n", __FUNCTION__); 287 272 288 - /* The USB subsystem doesn't handle synchronisation between 289 - * a device's several drivers. Therefore we reset only devices 290 - * with just one interface, which we of course own. */ 291 - 292 273 down(&(us->dev_semaphore)); 293 - if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 294 - result = -EIO; 295 - US_DEBUGP("No reset during disconnect\n"); 296 - } else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) { 297 - result = -EBUSY; 298 - US_DEBUGP("Refusing to reset a multi-interface device\n"); 299 - } else { 300 - rc = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf); 301 - if (rc < 0) { 302 - US_DEBUGP("unable to lock device for reset: %d\n", rc); 303 - result = rc; 304 - } else { 305 - result = usb_reset_device(us->pusb_dev); 306 - if (rc) 307 - usb_unlock_device(us->pusb_dev); 308 - US_DEBUGP("usb_reset_device returns %d\n", result); 309 - } 310 - } 274 + result = usb_stor_port_reset(us); 311 275 up(&(us->dev_semaphore)); 312 276 313 277 /* lock the host for the return */ ··· 300 318 for (i = 1; i < host->max_id; ++i) 301 319 scsi_report_device_reset(host, 0, i); 302 320 } 321 + } 322 + 323 + /* Report a driver-initiated bus reset to the SCSI layer. 324 + * Calling this for a SCSI-initiated reset is unnecessary but harmless. 325 + * The caller must own the SCSI host lock. */ 326 + void usb_stor_report_bus_reset(struct us_data *us) 327 + { 328 + scsi_report_bus_reset(us_to_host(us), 0); 303 329 } 304 330 305 331 /***********************************************************************
+1
drivers/usb/storage/scsiglue.h
··· 42 42 #define _SCSIGLUE_H_ 43 43 44 44 extern void usb_stor_report_device_reset(struct us_data *us); 45 + extern void usb_stor_report_bus_reset(struct us_data *us); 45 46 46 47 extern unsigned char usb_stor_sense_invalidCDB[18]; 47 48 extern struct scsi_host_template usb_stor_host_template;
+75 -41
drivers/usb/storage/transport.c
··· 266 266 NULL, 0, 3*HZ); 267 267 268 268 /* reset the endpoint toggle */ 269 - usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe), 270 - usb_pipeout(pipe), 0); 269 + if (result >= 0) 270 + usb_settoggle(us->pusb_dev, usb_pipeendpoint(pipe), 271 + usb_pipeout(pipe), 0); 271 272 272 273 US_DEBUGP("%s: result = %d\n", __FUNCTION__, result); 273 274 return result; ··· 541 540 */ 542 541 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 543 542 US_DEBUGP("-- command was aborted\n"); 544 - goto Handle_Abort; 543 + srb->result = DID_ABORT << 16; 544 + goto Handle_Errors; 545 545 } 546 546 547 547 /* if there is a transport error, reset and don't auto-sense */ 548 548 if (result == USB_STOR_TRANSPORT_ERROR) { 549 549 US_DEBUGP("-- transport indicates error, resetting\n"); 550 - us->transport_reset(us); 551 550 srb->result = DID_ERROR << 16; 552 - return; 551 + goto Handle_Errors; 553 552 } 554 553 555 554 /* if the transport provided its own sense data, don't auto-sense */ ··· 669 668 670 669 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) { 671 670 US_DEBUGP("-- auto-sense aborted\n"); 672 - goto Handle_Abort; 671 + srb->result = DID_ABORT << 16; 672 + goto Handle_Errors; 673 673 } 674 674 if (temp_result != USB_STOR_TRANSPORT_GOOD) { 675 675 US_DEBUGP("-- auto-sense failure\n"); ··· 679 677 * multi-target device, since failure of an 680 678 * auto-sense is perfectly valid 681 679 */ 682 - if (!(us->flags & US_FL_SCM_MULT_TARG)) 683 - us->transport_reset(us); 684 680 srb->result = DID_ERROR << 16; 681 + if (!(us->flags & US_FL_SCM_MULT_TARG)) 682 + goto Handle_Errors; 685 683 return; 686 684 } 687 685 ··· 722 720 723 721 return; 724 722 725 - /* abort processing: the bulk-only transport requires a reset 726 - * following an abort */ 727 - Handle_Abort: 728 - srb->result = DID_ABORT << 16; 729 - if (us->protocol == US_PR_BULK) 723 + /* Error and abort processing: try to resynchronize with the device 724 + * by issuing a port reset. If that fails, try a class-specific 725 + * device reset. */ 726 + Handle_Errors: 727 + 728 + /* Let the SCSI layer know we are doing a reset, set the 729 + * RESETTING bit, and clear the ABORTING bit so that the reset 730 + * may proceed. */ 731 + scsi_lock(us_to_host(us)); 732 + usb_stor_report_bus_reset(us); 733 + set_bit(US_FLIDX_RESETTING, &us->flags); 734 + clear_bit(US_FLIDX_ABORTING, &us->flags); 735 + scsi_unlock(us_to_host(us)); 736 + 737 + result = usb_stor_port_reset(us); 738 + if (result < 0) { 739 + scsi_lock(us_to_host(us)); 740 + usb_stor_report_device_reset(us); 741 + scsi_unlock(us_to_host(us)); 730 742 us->transport_reset(us); 743 + } 744 + clear_bit(US_FLIDX_RESETTING, &us->flags); 731 745 } 732 746 733 747 /* Stop the current URB transfer */ ··· 1142 1124 * It's handy that every transport mechanism uses the control endpoint for 1143 1125 * resets. 1144 1126 * 1145 - * Basically, we send a reset with a 20-second timeout, so we don't get 1127 + * Basically, we send a reset with a 5-second timeout, so we don't get 1146 1128 * jammed attempting to do the reset. 1147 1129 */ 1148 1130 static int usb_stor_reset_common(struct us_data *us, ··· 1151 1133 { 1152 1134 int result; 1153 1135 int result2; 1154 - int rc = FAILED; 1155 1136 1156 - /* Let the SCSI layer know we are doing a reset, set the 1157 - * RESETTING bit, and clear the ABORTING bit so that the reset 1158 - * may proceed. 1159 - */ 1160 - scsi_lock(us_to_host(us)); 1161 - usb_stor_report_device_reset(us); 1162 - set_bit(US_FLIDX_RESETTING, &us->flags); 1163 - clear_bit(US_FLIDX_ABORTING, &us->flags); 1164 - scsi_unlock(us_to_host(us)); 1137 + if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1138 + US_DEBUGP("No reset during disconnect\n"); 1139 + return -EIO; 1140 + } 1165 1141 1166 - /* A 20-second timeout may seem rather long, but a LaCie 1167 - * StudioDrive USB2 device takes 16+ seconds to get going 1168 - * following a powerup or USB attach event. 1169 - */ 1170 1142 result = usb_stor_control_msg(us, us->send_ctrl_pipe, 1171 1143 request, requesttype, value, index, data, size, 1172 - 20*HZ); 1144 + 5*HZ); 1173 1145 if (result < 0) { 1174 1146 US_DEBUGP("Soft reset failed: %d\n", result); 1175 - goto Done; 1147 + return result; 1176 1148 } 1177 1149 1178 1150 /* Give the device some time to recover from the reset, ··· 1172 1164 HZ*6); 1173 1165 if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1174 1166 US_DEBUGP("Reset interrupted by disconnect\n"); 1175 - goto Done; 1167 + return -EIO; 1176 1168 } 1177 1169 1178 1170 US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n"); ··· 1181 1173 US_DEBUGP("Soft reset: clearing bulk-out endpoint halt\n"); 1182 1174 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe); 1183 1175 1184 - /* return a result code based on the result of the control message */ 1185 - if (result < 0 || result2 < 0) { 1176 + /* return a result code based on the result of the clear-halts */ 1177 + if (result >= 0) 1178 + result = result2; 1179 + if (result < 0) 1186 1180 US_DEBUGP("Soft reset failed\n"); 1187 - goto Done; 1188 - } 1189 - US_DEBUGP("Soft reset done\n"); 1190 - rc = SUCCESS; 1191 - 1192 - Done: 1193 - clear_bit(US_FLIDX_RESETTING, &us->flags); 1194 - return rc; 1181 + else 1182 + US_DEBUGP("Soft reset done\n"); 1183 + return result; 1195 1184 } 1196 1185 1197 1186 /* This issues a CB[I] Reset to the device in question ··· 1217 1212 return usb_stor_reset_common(us, US_BULK_RESET_REQUEST, 1218 1213 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1219 1214 0, us->ifnum, NULL, 0); 1215 + } 1216 + 1217 + /* Issue a USB port reset to the device. But don't do anything if 1218 + * there's more than one interface in the device, so that other users 1219 + * are not affected. */ 1220 + int usb_stor_port_reset(struct us_data *us) 1221 + { 1222 + int result, rc; 1223 + 1224 + if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 1225 + result = -EIO; 1226 + US_DEBUGP("No reset during disconnect\n"); 1227 + } else if (us->pusb_dev->actconfig->desc.bNumInterfaces != 1) { 1228 + result = -EBUSY; 1229 + US_DEBUGP("Refusing to reset a multi-interface device\n"); 1230 + } else { 1231 + result = rc = 1232 + usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf); 1233 + if (result < 0) { 1234 + US_DEBUGP("unable to lock device for reset: %d\n", 1235 + result); 1236 + } else { 1237 + result = usb_reset_device(us->pusb_dev); 1238 + if (rc) 1239 + usb_unlock_device(us->pusb_dev); 1240 + US_DEBUGP("usb_reset_device returns %d\n", result); 1241 + } 1242 + } 1243 + return result; 1220 1244 }
+1
drivers/usb/storage/transport.h
··· 171 171 extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe, 172 172 void *buf, unsigned int length, int use_sg, int *residual); 173 173 174 + extern int usb_stor_port_reset(struct us_data *us); 174 175 #endif
+9
include/asm-arm/arch-omap/usb.h
··· 47 47 # define HMC_TLLATTACH (1 << 6) 48 48 # define OTG_HMC(w) (((w)>>0)&0x3f) 49 49 #define OTG_CTRL_REG OTG_REG32(0x0c) 50 + # define OTG_USB2_EN (1 << 29) 51 + # define OTG_USB2_DP (1 << 28) 52 + # define OTG_USB2_DM (1 << 27) 53 + # define OTG_USB1_EN (1 << 26) 54 + # define OTG_USB1_DP (1 << 25) 55 + # define OTG_USB1_DM (1 << 24) 56 + # define OTG_USB0_EN (1 << 23) 57 + # define OTG_USB0_DP (1 << 22) 58 + # define OTG_USB0_DM (1 << 21) 50 59 # define OTG_ASESSVLD (1 << 20) 51 60 # define OTG_BSESSEND (1 << 19) 52 61 # define OTG_BSESSVLD (1 << 18)
+176 -7
include/linux/usb_ch9.h
··· 6 6 * 7 7 * - the master/host side Linux-USB kernel driver API; 8 8 * - the "usbfs" user space API; and 9 - * - (eventually) a Linux "gadget" slave/device side driver API. 9 + * - the Linux "gadget" slave/device/peripheral side driver API. 10 10 * 11 11 * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems 12 12 * act either as a USB master/host or as a USB slave/device. That means 13 - * the master and slave side APIs will benefit from working well together. 13 + * the master and slave side APIs benefit from working well together. 14 + * 15 + * There's also "Wireless USB", using low power short range radios for 16 + * peripheral interconnection but otherwise building on the USB framework. 14 17 */ 15 18 16 19 #ifndef __LINUX_USB_CH9_H ··· 71 68 #define USB_REQ_SET_INTERFACE 0x0B 72 69 #define USB_REQ_SYNCH_FRAME 0x0C 73 70 71 + #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */ 72 + #define USB_REQ_GET_ENCRYPTION 0x0E 73 + #define USB_REQ_SET_HANDSHAKE 0x0F 74 + #define USB_REQ_GET_HANDSHAKE 0x10 75 + #define USB_REQ_SET_CONNECTION 0x11 76 + #define USB_REQ_SET_SECURITY_DATA 0x12 77 + #define USB_REQ_GET_SECURITY_DATA 0x13 78 + #define USB_REQ_SET_WUSB_DATA 0x14 79 + #define USB_REQ_LOOPBACK_DATA_WRITE 0x15 80 + #define USB_REQ_LOOPBACK_DATA_READ 0x16 81 + #define USB_REQ_SET_INTERFACE_DS 0x17 82 + 74 83 /* 75 84 * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and 76 85 * are read as a bit array returned by USB_REQ_GET_STATUS. (So there ··· 90 75 */ 91 76 #define USB_DEVICE_SELF_POWERED 0 /* (read only) */ 92 77 #define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */ 93 - #define USB_DEVICE_TEST_MODE 2 /* (high speed only) */ 94 - #define USB_DEVICE_B_HNP_ENABLE 3 /* dev may initiate HNP */ 95 - #define USB_DEVICE_A_HNP_SUPPORT 4 /* RH port supports HNP */ 96 - #define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* other RH port does */ 78 + #define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */ 79 + #define USB_DEVICE_BATTERY 2 /* (wireless) */ 80 + #define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */ 81 + #define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/ 82 + #define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */ 83 + #define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */ 97 84 #define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */ 98 85 99 86 #define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */ ··· 152 135 #define USB_DT_OTG 0x09 153 136 #define USB_DT_DEBUG 0x0a 154 137 #define USB_DT_INTERFACE_ASSOCIATION 0x0b 138 + /* these are from the Wireless USB spec */ 139 + #define USB_DT_SECURITY 0x0c 140 + #define USB_DT_KEY 0x0d 141 + #define USB_DT_ENCRYPTION_TYPE 0x0e 142 + #define USB_DT_BOS 0x0f 143 + #define USB_DT_DEVICE_CAPABILITY 0x10 144 + #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11 155 145 156 146 /* conventional codes for class-specific descriptors */ 157 147 #define USB_DT_CS_DEVICE 0x21 ··· 216 192 #define USB_CLASS_CSCID 0x0b /* chip+ smart card */ 217 193 #define USB_CLASS_CONTENT_SEC 0x0d /* content security */ 218 194 #define USB_CLASS_VIDEO 0x0e 195 + #define USB_CLASS_WIRELESS_CONTROLLER 0xe0 219 196 #define USB_CLASS_APP_SPEC 0xfe 220 197 #define USB_CLASS_VENDOR_SPEC 0xff 221 198 ··· 248 223 #define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */ 249 224 #define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */ 250 225 #define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */ 226 + #define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */ 251 227 252 228 /*-------------------------------------------------------------------------*/ 253 229 ··· 315 289 #define USB_ENDPOINT_XFER_ISOC 1 316 290 #define USB_ENDPOINT_XFER_BULK 2 317 291 #define USB_ENDPOINT_XFER_INT 3 292 + #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 318 293 319 294 320 295 /*-------------------------------------------------------------------------*/ ··· 379 352 380 353 /*-------------------------------------------------------------------------*/ 381 354 355 + /* USB_DT_SECURITY: group of wireless security descriptors, including 356 + * encryption types available for setting up a CC/association. 357 + */ 358 + struct usb_security_descriptor { 359 + __u8 bLength; 360 + __u8 bDescriptorType; 361 + 362 + __le16 wTotalLength; 363 + __u8 bNumEncryptionTypes; 364 + }; 365 + 366 + /*-------------------------------------------------------------------------*/ 367 + 368 + /* USB_DT_KEY: used with {GET,SET}_SECURITY_DATA; only public keys 369 + * may be retrieved. 370 + */ 371 + struct usb_key_descriptor { 372 + __u8 bLength; 373 + __u8 bDescriptorType; 374 + 375 + __u8 tTKID[3]; 376 + __u8 bReserved; 377 + __u8 bKeyData[0]; 378 + }; 379 + 380 + /*-------------------------------------------------------------------------*/ 381 + 382 + /* USB_DT_ENCRYPTION_TYPE: bundled in DT_SECURITY groups */ 383 + struct usb_encryption_descriptor { 384 + __u8 bLength; 385 + __u8 bDescriptorType; 386 + 387 + __u8 bEncryptionType; 388 + #define USB_ENC_TYPE_UNSECURE 0 389 + #define USB_ENC_TYPE_WIRED 1 /* non-wireless mode */ 390 + #define USB_ENC_TYPE_CCM_1 2 /* aes128/cbc session */ 391 + #define USB_ENC_TYPE_RSA_1 3 /* rsa3072/sha1 auth */ 392 + __u8 bEncryptionValue; /* use in SET_ENCRYPTION */ 393 + __u8 bAuthKeyIndex; 394 + }; 395 + 396 + 397 + /*-------------------------------------------------------------------------*/ 398 + 399 + /* USB_DT_BOS: group of wireless capabilities */ 400 + struct usb_bos_descriptor { 401 + __u8 bLength; 402 + __u8 bDescriptorType; 403 + 404 + __le16 wTotalLength; 405 + __u8 bNumDeviceCaps; 406 + }; 407 + 408 + /*-------------------------------------------------------------------------*/ 409 + 410 + /* USB_DT_DEVICE_CAPABILITY: grouped with BOS */ 411 + struct usb_dev_cap_header { 412 + __u8 bLength; 413 + __u8 bDescriptorType; 414 + __u8 bDevCapabilityType; 415 + }; 416 + 417 + #define USB_CAP_TYPE_WIRELESS_USB 1 418 + 419 + struct usb_wireless_cap_descriptor { /* Ultra Wide Band */ 420 + __u8 bLength; 421 + __u8 bDescriptorType; 422 + __u8 bDevCapabilityType; 423 + 424 + __u8 bmAttributes; 425 + #define USB_WIRELESS_P2P_DRD (1 << 1) 426 + #define USB_WIRELESS_BEACON_MASK (3 << 2) 427 + #define USB_WIRELESS_BEACON_SELF (1 << 2) 428 + #define USB_WIRELESS_BEACON_DIRECTED (2 << 2) 429 + #define USB_WIRELESS_BEACON_NONE (3 << 2) 430 + __le16 wPHYRates; /* bit rates, Mbps */ 431 + #define USB_WIRELESS_PHY_53 (1 << 0) /* always set */ 432 + #define USB_WIRELESS_PHY_80 (1 << 1) 433 + #define USB_WIRELESS_PHY_107 (1 << 2) /* always set */ 434 + #define USB_WIRELESS_PHY_160 (1 << 3) 435 + #define USB_WIRELESS_PHY_200 (1 << 4) /* always set */ 436 + #define USB_WIRELESS_PHY_320 (1 << 5) 437 + #define USB_WIRELESS_PHY_400 (1 << 6) 438 + #define USB_WIRELESS_PHY_480 (1 << 7) 439 + __u8 bmTFITXPowerInfo; /* TFI power levels */ 440 + __u8 bmFFITXPowerInfo; /* FFI power levels */ 441 + __le16 bmBandGroup; 442 + __u8 bReserved; 443 + }; 444 + 445 + /*-------------------------------------------------------------------------*/ 446 + 447 + /* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with 448 + * each endpoint descriptor for a wireless device 449 + */ 450 + struct usb_wireless_ep_comp_descriptor { 451 + __u8 bLength; 452 + __u8 bDescriptorType; 453 + 454 + __u8 bMaxBurst; 455 + __u8 bMaxSequence; 456 + __le16 wMaxStreamDelay; 457 + __le16 wOverTheAirPacketSize; 458 + __u8 bOverTheAirInterval; 459 + __u8 bmCompAttributes; 460 + #define USB_ENDPOINT_SWITCH_MASK 0x03 /* in bmCompAttributes */ 461 + #define USB_ENDPOINT_SWITCH_NO 0 462 + #define USB_ENDPOINT_SWITCH_SWITCH 1 463 + #define USB_ENDPOINT_SWITCH_SCALE 2 464 + }; 465 + 466 + /*-------------------------------------------------------------------------*/ 467 + 468 + /* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless 469 + * host and a device for connection set up, mutual authentication, and 470 + * exchanging short lived session keys. The handshake depends on a CC. 471 + */ 472 + struct usb_handshake { 473 + __u8 bMessageNumber; 474 + __u8 bStatus; 475 + __u8 tTKID[3]; 476 + __u8 bReserved; 477 + __u8 CDID[16]; 478 + __u8 nonce[16]; 479 + __u8 MIC[8]; 480 + }; 481 + 482 + /*-------------------------------------------------------------------------*/ 483 + 484 + /* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC). 485 + * A CC may also be set up using non-wireless secure channels (including 486 + * wired USB!), and some devices may support CCs with multiple hosts. 487 + */ 488 + struct usb_connection_context { 489 + __u8 CHID[16]; /* persistent host id */ 490 + __u8 CDID[16]; /* device id (unique w/in host context) */ 491 + __u8 CK[16]; /* connection key */ 492 + }; 493 + 494 + /*-------------------------------------------------------------------------*/ 495 + 382 496 /* USB 2.0 defines three speeds, here's how Linux identifies them */ 383 497 384 498 enum usb_device_speed { 385 499 USB_SPEED_UNKNOWN = 0, /* enumerating */ 386 500 USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */ 387 - USB_SPEED_HIGH /* usb 2.0 */ 501 + USB_SPEED_HIGH, /* usb 2.0 */ 502 + USB_SPEED_VARIABLE, /* wireless (usb 2.5) */ 388 503 }; 389 504 390 505 enum usb_device_state {
+1 -1
include/linux/usb_gadget.h
··· 711 711 * the hardware level driver. Most calls must be handled by 712 712 * the gadget driver, including descriptor and configuration 713 713 * management. The 16 bit members of the setup data are in 714 - * cpu order. Called in_interrupt; this may not sleep. Driver 714 + * USB byte order. Called in_interrupt; this may not sleep. Driver 715 715 * queues a response to ep0, or returns negative to stall. 716 716 * @disconnect: Invoked after all transfers have been stopped, 717 717 * when the host is disconnected. May be called in_interrupt; this
+47
include/linux/usb_isp116x.h
··· 1 + 2 + /* 3 + * Board initialization code should put one of these into dev->platform_data 4 + * and place the isp116x onto platform_bus. 5 + */ 6 + 7 + struct isp116x_platform_data { 8 + /* Enable internal resistors on downstream ports */ 9 + unsigned sel15Kres:1; 10 + /* Chip's internal clock won't be stopped in suspended state. 11 + Setting/unsetting this bit takes effect only if 12 + 'remote_wakeup_enable' below is not set. */ 13 + unsigned clknotstop:1; 14 + /* On-chip overcurrent protection */ 15 + unsigned oc_enable:1; 16 + /* INT output polarity */ 17 + unsigned int_act_high:1; 18 + /* INT edge or level triggered */ 19 + unsigned int_edge_triggered:1; 20 + /* WAKEUP pin connected - NOT SUPPORTED */ 21 + /* unsigned remote_wakeup_connected:1; */ 22 + /* Wakeup by devices on usb bus enabled */ 23 + unsigned remote_wakeup_enable:1; 24 + /* Switch or not to switch (keep always powered) */ 25 + unsigned no_power_switching:1; 26 + /* Ganged port power switching (0) or individual port 27 + power switching (1) */ 28 + unsigned power_switching_mode:1; 29 + /* Given port_power, msec/2 after power on till power good */ 30 + u8 potpg; 31 + /* Hardware reset set/clear. If implemented, this function must: 32 + if set == 0, deassert chip's HW reset pin 33 + otherwise, assert chip's HW reset pin */ 34 + void (*reset) (struct device * dev, int set); 35 + /* Hardware clock start/stop. If implemented, this function must: 36 + if start == 0, stop the external clock 37 + otherwise, start the external clock 38 + */ 39 + void (*clock) (struct device * dev, int start); 40 + /* Inter-io delay (ns). The chip is picky about access timings; it 41 + expects at least: 42 + 150ns delay between consecutive accesses to DATA_REG, 43 + 300ns delay between access to ADDR_REG and DATA_REG 44 + OE, WE MUST NOT be changed during these intervals 45 + */ 46 + void (*delay) (struct device * dev, int delay); 47 + };