urio.c (193045) | urio.c (194228) |
---|---|
1/*- 2 * Copyright (c) 2000 Iwasa Kazmi 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 * 26 * This code is based on ugen.c and ulpt.c developed by Lennart Augustsson. 27 * This code includes software developed by the NetBSD Foundation, Inc. and 28 * its contributors. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2000 Iwasa Kazmi 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 * 26 * This code is based on ugen.c and ulpt.c developed by Lennart Augustsson. 27 * This code includes software developed by the NetBSD Foundation, Inc. and 28 * its contributors. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sys/dev/usb/storage/urio.c 193045 2009-05-29 18:46:57Z thompsa $"); | 32__FBSDID("$FreeBSD: head/sys/dev/usb/storage/urio.c 194228 2009-06-15 01:02:43Z thompsa $"); |
33 34 35/* 36 * 2000/3/24 added NetBSD/OpenBSD support (from Alex Nemirovsky) 37 * 2000/3/07 use two bulk-pipe handles for read and write (Dirk) 38 * 2000/3/06 change major number(143), and copyright header 39 * some fix for 4.0 (Dirk) 40 * 2000/3/05 codes for FreeBSD 4.x - CURRENT (Thanks to Dirk-Willem van Gulik) --- 163 unchanged lines hidden (view full) --- 204 205static int 206urio_attach(device_t dev) 207{ 208 struct usb_attach_arg *uaa = device_get_ivars(dev); 209 struct urio_softc *sc = device_get_softc(dev); 210 int error; 211 | 33 34 35/* 36 * 2000/3/24 added NetBSD/OpenBSD support (from Alex Nemirovsky) 37 * 2000/3/07 use two bulk-pipe handles for read and write (Dirk) 38 * 2000/3/06 change major number(143), and copyright header 39 * some fix for 4.0 (Dirk) 40 * 2000/3/05 codes for FreeBSD 4.x - CURRENT (Thanks to Dirk-Willem van Gulik) --- 163 unchanged lines hidden (view full) --- 204 205static int 206urio_attach(device_t dev) 207{ 208 struct usb_attach_arg *uaa = device_get_ivars(dev); 209 struct urio_softc *sc = device_get_softc(dev); 210 int error; 211 |
212 device_set_usb2_desc(dev); | 212 device_set_usb_desc(dev); |
213 214 sc->sc_udev = uaa->device; 215 216 mtx_init(&sc->sc_mtx, "urio lock", NULL, MTX_DEF | MTX_RECURSE); 217 218 snprintf(sc->sc_name, sizeof(sc->sc_name), 219 "%s", device_get_nameunit(dev)); 220 | 213 214 sc->sc_udev = uaa->device; 215 216 mtx_init(&sc->sc_mtx, "urio lock", NULL, MTX_DEF | MTX_RECURSE); 217 218 snprintf(sc->sc_name, sizeof(sc->sc_name), 219 "%s", device_get_nameunit(dev)); 220 |
221 error = usb2_transfer_setup(uaa->device, | 221 error = usbd_transfer_setup(uaa->device, |
222 &uaa->info.bIfaceIndex, sc->sc_xfer, 223 urio_config, URIO_T_MAX, sc, &sc->sc_mtx); 224 225 if (error) { | 222 &uaa->info.bIfaceIndex, sc->sc_xfer, 223 urio_config, URIO_T_MAX, sc, &sc->sc_mtx); 224 225 if (error) { |
226 DPRINTF("error=%s\n", usb2_errstr(error)); | 226 DPRINTF("error=%s\n", usbd_errstr(error)); |
227 goto detach; 228 } 229 | 227 goto detach; 228 } 229 |
230 error = usb2_fifo_attach(uaa->device, sc, &sc->sc_mtx, | 230 error = usb_fifo_attach(uaa->device, sc, &sc->sc_mtx, |
231 &urio_fifo_methods, &sc->sc_fifo, 232 device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex, 233 UID_ROOT, GID_OPERATOR, 0644); 234 if (error) { 235 goto detach; 236 } 237 return (0); /* success */ 238 --- 8 unchanged lines hidden (view full) --- 247 struct urio_softc *sc = xfer->priv_sc; 248 struct usb_fifo *f = sc->sc_fifo.fp[USB_FIFO_TX]; 249 uint32_t actlen; 250 251 switch (USB_GET_STATE(xfer)) { 252 case USB_ST_TRANSFERRED: 253 case USB_ST_SETUP: 254 if (sc->sc_flags & URIO_FLAG_WRITE_STALL) { | 231 &urio_fifo_methods, &sc->sc_fifo, 232 device_get_unit(dev), 0 - 1, uaa->info.bIfaceIndex, 233 UID_ROOT, GID_OPERATOR, 0644); 234 if (error) { 235 goto detach; 236 } 237 return (0); /* success */ 238 --- 8 unchanged lines hidden (view full) --- 247 struct urio_softc *sc = xfer->priv_sc; 248 struct usb_fifo *f = sc->sc_fifo.fp[USB_FIFO_TX]; 249 uint32_t actlen; 250 251 switch (USB_GET_STATE(xfer)) { 252 case USB_ST_TRANSFERRED: 253 case USB_ST_SETUP: 254 if (sc->sc_flags & URIO_FLAG_WRITE_STALL) { |
255 usb2_transfer_start(sc->sc_xfer[URIO_T_WR_CS]); | 255 usbd_transfer_start(sc->sc_xfer[URIO_T_WR_CS]); |
256 return; 257 } | 256 return; 257 } |
258 if (usb2_fifo_get_data(f, xfer->frbuffers, 0, | 258 if (usb_fifo_get_data(f, xfer->frbuffers, 0, |
259 xfer->max_data_length, &actlen, 0)) { 260 261 xfer->frlengths[0] = actlen; | 259 xfer->max_data_length, &actlen, 0)) { 260 261 xfer->frlengths[0] = actlen; |
262 usb2_start_hardware(xfer); | 262 usbd_transfer_submit(xfer); |
263 } 264 return; 265 266 default: /* Error */ 267 if (xfer->error != USB_ERR_CANCELLED) { 268 /* try to clear stall first */ 269 sc->sc_flags |= URIO_FLAG_WRITE_STALL; | 263 } 264 return; 265 266 default: /* Error */ 267 if (xfer->error != USB_ERR_CANCELLED) { 268 /* try to clear stall first */ 269 sc->sc_flags |= URIO_FLAG_WRITE_STALL; |
270 usb2_transfer_start(sc->sc_xfer[URIO_T_WR_CS]); | 270 usbd_transfer_start(sc->sc_xfer[URIO_T_WR_CS]); |
271 } 272 return; 273 } 274} 275 276static void 277urio_write_clear_stall_callback(struct usb_xfer *xfer) 278{ 279 struct urio_softc *sc = xfer->priv_sc; 280 struct usb_xfer *xfer_other = sc->sc_xfer[URIO_T_WR]; 281 | 271 } 272 return; 273 } 274} 275 276static void 277urio_write_clear_stall_callback(struct usb_xfer *xfer) 278{ 279 struct urio_softc *sc = xfer->priv_sc; 280 struct usb_xfer *xfer_other = sc->sc_xfer[URIO_T_WR]; 281 |
282 if (usb2_clear_stall_callback(xfer, xfer_other)) { | 282 if (usbd_clear_stall_callback(xfer, xfer_other)) { |
283 DPRINTF("stall cleared\n"); 284 sc->sc_flags &= ~URIO_FLAG_WRITE_STALL; | 283 DPRINTF("stall cleared\n"); 284 sc->sc_flags &= ~URIO_FLAG_WRITE_STALL; |
285 usb2_transfer_start(xfer_other); | 285 usbd_transfer_start(xfer_other); |
286 } 287} 288 289static void 290urio_read_callback(struct usb_xfer *xfer) 291{ 292 struct urio_softc *sc = xfer->priv_sc; 293 struct usb_fifo *f = sc->sc_fifo.fp[USB_FIFO_RX]; 294 295 switch (USB_GET_STATE(xfer)) { 296 case USB_ST_TRANSFERRED: | 286 } 287} 288 289static void 290urio_read_callback(struct usb_xfer *xfer) 291{ 292 struct urio_softc *sc = xfer->priv_sc; 293 struct usb_fifo *f = sc->sc_fifo.fp[USB_FIFO_RX]; 294 295 switch (USB_GET_STATE(xfer)) { 296 case USB_ST_TRANSFERRED: |
297 usb2_fifo_put_data(f, xfer->frbuffers, 0, | 297 usb_fifo_put_data(f, xfer->frbuffers, 0, |
298 xfer->actlen, 1); 299 300 case USB_ST_SETUP: 301 if (sc->sc_flags & URIO_FLAG_READ_STALL) { | 298 xfer->actlen, 1); 299 300 case USB_ST_SETUP: 301 if (sc->sc_flags & URIO_FLAG_READ_STALL) { |
302 usb2_transfer_start(sc->sc_xfer[URIO_T_RD_CS]); | 302 usbd_transfer_start(sc->sc_xfer[URIO_T_RD_CS]); |
303 return; 304 } | 303 return; 304 } |
305 if (usb2_fifo_put_bytes_max(f) != 0) { | 305 if (usb_fifo_put_bytes_max(f) != 0) { |
306 xfer->frlengths[0] = xfer->max_data_length; | 306 xfer->frlengths[0] = xfer->max_data_length; |
307 usb2_start_hardware(xfer); | 307 usbd_transfer_submit(xfer); |
308 } 309 return; 310 311 default: /* Error */ 312 if (xfer->error != USB_ERR_CANCELLED) { 313 /* try to clear stall first */ 314 sc->sc_flags |= URIO_FLAG_READ_STALL; | 308 } 309 return; 310 311 default: /* Error */ 312 if (xfer->error != USB_ERR_CANCELLED) { 313 /* try to clear stall first */ 314 sc->sc_flags |= URIO_FLAG_READ_STALL; |
315 usb2_transfer_start(sc->sc_xfer[URIO_T_RD_CS]); | 315 usbd_transfer_start(sc->sc_xfer[URIO_T_RD_CS]); |
316 } 317 return; 318 } 319} 320 321static void 322urio_read_clear_stall_callback(struct usb_xfer *xfer) 323{ 324 struct urio_softc *sc = xfer->priv_sc; 325 struct usb_xfer *xfer_other = sc->sc_xfer[URIO_T_RD]; 326 | 316 } 317 return; 318 } 319} 320 321static void 322urio_read_clear_stall_callback(struct usb_xfer *xfer) 323{ 324 struct urio_softc *sc = xfer->priv_sc; 325 struct usb_xfer *xfer_other = sc->sc_xfer[URIO_T_RD]; 326 |
327 if (usb2_clear_stall_callback(xfer, xfer_other)) { | 327 if (usbd_clear_stall_callback(xfer, xfer_other)) { |
328 DPRINTF("stall cleared\n"); 329 sc->sc_flags &= ~URIO_FLAG_READ_STALL; | 328 DPRINTF("stall cleared\n"); 329 sc->sc_flags &= ~URIO_FLAG_READ_STALL; |
330 usb2_transfer_start(xfer_other); | 330 usbd_transfer_start(xfer_other); |
331 } 332} 333 334static void 335urio_start_read(struct usb_fifo *fifo) 336{ 337 struct urio_softc *sc = fifo->priv_sc0; 338 | 331 } 332} 333 334static void 335urio_start_read(struct usb_fifo *fifo) 336{ 337 struct urio_softc *sc = fifo->priv_sc0; 338 |
339 usb2_transfer_start(sc->sc_xfer[URIO_T_RD]); | 339 usbd_transfer_start(sc->sc_xfer[URIO_T_RD]); |
340} 341 342static void 343urio_stop_read(struct usb_fifo *fifo) 344{ 345 struct urio_softc *sc = fifo->priv_sc0; 346 | 340} 341 342static void 343urio_stop_read(struct usb_fifo *fifo) 344{ 345 struct urio_softc *sc = fifo->priv_sc0; 346 |
347 usb2_transfer_stop(sc->sc_xfer[URIO_T_RD_CS]); 348 usb2_transfer_stop(sc->sc_xfer[URIO_T_RD]); | 347 usbd_transfer_stop(sc->sc_xfer[URIO_T_RD_CS]); 348 usbd_transfer_stop(sc->sc_xfer[URIO_T_RD]); |
349} 350 351static void 352urio_start_write(struct usb_fifo *fifo) 353{ 354 struct urio_softc *sc = fifo->priv_sc0; 355 | 349} 350 351static void 352urio_start_write(struct usb_fifo *fifo) 353{ 354 struct urio_softc *sc = fifo->priv_sc0; 355 |
356 usb2_transfer_start(sc->sc_xfer[URIO_T_WR]); | 356 usbd_transfer_start(sc->sc_xfer[URIO_T_WR]); |
357} 358 359static void 360urio_stop_write(struct usb_fifo *fifo) 361{ 362 struct urio_softc *sc = fifo->priv_sc0; 363 | 357} 358 359static void 360urio_stop_write(struct usb_fifo *fifo) 361{ 362 struct urio_softc *sc = fifo->priv_sc0; 363 |
364 usb2_transfer_stop(sc->sc_xfer[URIO_T_WR_CS]); 365 usb2_transfer_stop(sc->sc_xfer[URIO_T_WR]); | 364 usbd_transfer_stop(sc->sc_xfer[URIO_T_WR_CS]); 365 usbd_transfer_stop(sc->sc_xfer[URIO_T_WR]); |
366} 367 368static int 369urio_open(struct usb_fifo *fifo, int fflags) 370{ 371 struct urio_softc *sc = fifo->priv_sc0; 372 373 if ((fflags & (FWRITE | FREAD)) != (FWRITE | FREAD)) { 374 return (EACCES); 375 } 376 if (fflags & FREAD) { 377 /* clear stall first */ 378 mtx_lock(&sc->sc_mtx); 379 sc->sc_flags |= URIO_FLAG_READ_STALL; 380 mtx_unlock(&sc->sc_mtx); 381 | 366} 367 368static int 369urio_open(struct usb_fifo *fifo, int fflags) 370{ 371 struct urio_softc *sc = fifo->priv_sc0; 372 373 if ((fflags & (FWRITE | FREAD)) != (FWRITE | FREAD)) { 374 return (EACCES); 375 } 376 if (fflags & FREAD) { 377 /* clear stall first */ 378 mtx_lock(&sc->sc_mtx); 379 sc->sc_flags |= URIO_FLAG_READ_STALL; 380 mtx_unlock(&sc->sc_mtx); 381 |
382 if (usb2_fifo_alloc_buffer(fifo, | 382 if (usb_fifo_alloc_buffer(fifo, |
383 sc->sc_xfer[URIO_T_RD]->max_data_length, 384 URIO_IFQ_MAXLEN)) { 385 return (ENOMEM); 386 } 387 } 388 if (fflags & FWRITE) { 389 /* clear stall first */ 390 sc->sc_flags |= URIO_FLAG_WRITE_STALL; 391 | 383 sc->sc_xfer[URIO_T_RD]->max_data_length, 384 URIO_IFQ_MAXLEN)) { 385 return (ENOMEM); 386 } 387 } 388 if (fflags & FWRITE) { 389 /* clear stall first */ 390 sc->sc_flags |= URIO_FLAG_WRITE_STALL; 391 |
392 if (usb2_fifo_alloc_buffer(fifo, | 392 if (usb_fifo_alloc_buffer(fifo, |
393 sc->sc_xfer[URIO_T_WR]->max_data_length, 394 URIO_IFQ_MAXLEN)) { 395 return (ENOMEM); 396 } 397 } 398 return (0); /* success */ 399} 400 401static void 402urio_close(struct usb_fifo *fifo, int fflags) 403{ 404 if (fflags & (FREAD | FWRITE)) { | 393 sc->sc_xfer[URIO_T_WR]->max_data_length, 394 URIO_IFQ_MAXLEN)) { 395 return (ENOMEM); 396 } 397 } 398 return (0); /* success */ 399} 400 401static void 402urio_close(struct usb_fifo *fifo, int fflags) 403{ 404 if (fflags & (FREAD | FWRITE)) { |
405 usb2_fifo_free_buffer(fifo); | 405 usb_fifo_free_buffer(fifo); |
406 } 407} 408 409static int 410urio_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr, 411 int fflags) 412{ 413 struct usb_ctl_request ur; --- 46 unchanged lines hidden (view full) --- 460 461static int 462urio_detach(device_t dev) 463{ 464 struct urio_softc *sc = device_get_softc(dev); 465 466 DPRINTF("\n"); 467 | 406 } 407} 408 409static int 410urio_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr, 411 int fflags) 412{ 413 struct usb_ctl_request ur; --- 46 unchanged lines hidden (view full) --- 460 461static int 462urio_detach(device_t dev) 463{ 464 struct urio_softc *sc = device_get_softc(dev); 465 466 DPRINTF("\n"); 467 |
468 usb2_fifo_detach(&sc->sc_fifo); | 468 usb_fifo_detach(&sc->sc_fifo); |
469 | 469 |
470 usb2_transfer_unsetup(sc->sc_xfer, URIO_T_MAX); | 470 usbd_transfer_unsetup(sc->sc_xfer, URIO_T_MAX); |
471 472 mtx_destroy(&sc->sc_mtx); 473 474 return (0); 475} | 471 472 mtx_destroy(&sc->sc_mtx); 473 474 return (0); 475} |