FreeBSD kernel usb device Code
|
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/refcount.h>
#include <sys/stdint.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include "usbdevs.h"
#include "usb_if.h"
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_da.h>
#include <cam/ctl/ctl_io.h>
#include <cam/ctl/ctl.h>
#include <cam/ctl/ctl_backend.h>
#include <cam/ctl/ctl_error.h>
#include <cam/ctl/ctl_frontend.h>
#include <cam/ctl/ctl_debug.h>
#include <cam/ctl/ctl_ha.h>
#include <cam/ctl/ctl_ioctl.h>
#include <cam/ctl/ctl_private.h>
Go to the source code of this file.
Data Structures | |
struct | cfumass_cbw_t |
struct | cfumass_csw_t |
struct | cfumass_softc |
Macros | |
#define | CFUMASS_BULK_SIZE (1U << 17) /* bytes */ |
#define | CFUMASS_T_COMMAND 0 |
#define | CFUMASS_T_DATA_OUT 1 |
#define | CFUMASS_T_DATA_IN 2 |
#define | CFUMASS_T_STATUS 3 |
#define | CFUMASS_T_MAX 4 |
#define | UR_RESET 0xff /* Bulk-Only Mass Storage Reset */ |
#define | UR_GET_MAX_LUN 0xfe /* Get Max LUN */ |
#define | CBWSIGNATURE 0x43425355 /* "USBC" */ |
#define | CBWFLAGS_OUT 0x00 |
#define | CBWFLAGS_IN 0x80 |
#define | CBWCBLENGTH 16 |
#define | CFUMASS_CBW_SIZE 31 |
#define | CSWSIGNATURE 0x53425355 /* "USBS" */ |
#define | CSWSTATUS_GOOD 0x0 |
#define | CSWSTATUS_FAILED 0x1 |
#define | CSWSTATUS_PHASE 0x2 |
#define | CFUMASS_CSW_SIZE 13 |
#define | CFUMASS_DEBUG(S, X, ...) |
#define | CFUMASS_WARN(S, X, ...) |
#define | CFUMASS_LOCK(X) mtx_lock(&X->sc_mtx) |
#define | CFUMASS_UNLOCK(X) mtx_unlock(&X->sc_mtx) |
Functions | |
__FBSDID ("$FreeBSD$") | |
SYSCTL_NODE (_hw_usb, OID_AUTO, cfumass, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "CAM Target Layer USB Mass Storage Frontend") | |
SYSCTL_INT (_hw_usb_cfumass, OID_AUTO, debug, CTLFLAG_RWTUN, &debug, 1, "Enable debug messages") | |
SYSCTL_INT (_hw_usb_cfumass, OID_AUTO, max_lun, CTLFLAG_RWTUN, &max_lun, 1, "Maximum advertised LUN number") | |
SYSCTL_INT (_hw_usb_cfumass, OID_AUTO, ignore_stop, CTLFLAG_RWTUN, &ignore_stop, 1, "Ignore START STOP UNIT with START and LOEJ bits cleared") | |
CTASSERT (sizeof(struct cfumass_cbw_t)==CFUMASS_CBW_SIZE) | |
CTASSERT (sizeof(struct cfumass_csw_t)==CFUMASS_CSW_SIZE) | |
DRIVER_MODULE (cfumass, uhub, cfumass_driver, cfumass_devclass, NULL, 0) | |
MODULE_VERSION (cfumass, 0) | |
MODULE_DEPEND (cfumass, usb, 1, 1, 1) | |
MODULE_DEPEND (cfumass, usb_template, 1, 1, 1) | |
static int | cfumass_init (void) |
static int | cfumass_shutdown (void) |
static void | cfumass_online (void *arg) |
static void | cfumass_offline (void *arg) |
static void | cfumass_datamove (union ctl_io *io) |
static void | cfumass_done (union ctl_io *io) |
CTL_FRONTEND_DECLARE (ctlcfumass, cfumass_frontend) | |
static void | cfumass_transfer_start (struct cfumass_softc *sc, uint8_t xfer_index) |
static void | cfumass_terminate (struct cfumass_softc *sc) |
static int | cfumass_probe (device_t dev) |
static int | cfumass_attach (device_t dev) |
static int | cfumass_detach (device_t dev) |
static int | cfumass_suspend (device_t dev) |
static int | cfumass_resume (device_t dev) |
static void | cfumass_transfer_stop_and_drain (struct cfumass_softc *sc, uint8_t xfer_index) |
static int | cfumass_handle_request (device_t dev, const void *preq, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate) |
static int | cfumass_quirk (struct cfumass_softc *sc, unsigned char *cdb, int cdb_len) |
static void | cfumass_t_command_callback (struct usb_xfer *xfer, usb_error_t usb_error) |
static void | cfumass_t_data_callback (struct usb_xfer *xfer, usb_error_t usb_error) |
static void | cfumass_t_status_callback (struct usb_xfer *xfer, usb_error_t usb_error) |
static void | cfumass_online (void *arg __unused) |
static void | cfumass_offline (void *arg __unused) |
Variables | |
static int | debug = 1 |
static int | max_lun = 0 |
static int | ignore_stop = 1 |
struct ctl_port | cfumass_port |
bool | cfumass_port_online |
volatile u_int | cfumass_refcount |
struct cfumass_cbw_t | __packed |
static device_probe_t | cfumass_probe |
static device_attach_t | cfumass_attach |
static device_detach_t | cfumass_detach |
static device_suspend_t | cfumass_suspend |
static device_resume_t | cfumass_resume |
static usb_handle_request_t | cfumass_handle_request |
static usb_callback_t | cfumass_t_command_callback |
static usb_callback_t | cfumass_t_data_callback |
static usb_callback_t | cfumass_t_status_callback |
static device_method_t | cfumass_methods [] |
static driver_t | cfumass_driver |
static devclass_t | cfumass_devclass |
static struct usb_config | cfumass_config [CFUMASS_T_MAX] |
static struct ctl_frontend | cfumass_frontend |
#define CFUMASS_DEBUG | ( | S, | |
X, | |||
... | |||
) |
#define CFUMASS_WARN | ( | S, | |
X, | |||
... | |||
) |
__FBSDID | ( | "$FreeBSD$" | ) |
|
static |
Definition at line 343 of file cfumass.c.
References usbd_lookup_info::bIfaceIndex, cfumass_config, CFUMASS_DEBUG, CFUMASS_LOCK, cfumass_port, cfumass_refcount, CFUMASS_T_COMMAND, CFUMASS_T_MAX, CFUMASS_T_STATUS, cfumass_transfer_start(), CFUMASS_UNLOCK, CFUMASS_WARN, dev, usb_attach_arg::device, device_set_usb_desc(), error, usb_attach_arg::info, cfumass_softc::sc_cbw, cfumass_softc::sc_csw, cfumass_softc::sc_ctl_initid, cfumass_softc::sc_dev, cfumass_softc::sc_mtx, cfumass_softc::sc_queued, cfumass_softc::sc_udev, cfumass_softc::sc_xfer, USB_POWER_MODE_SAVE, usbd_errstr(), usbd_set_power_mode(), usbd_transfer_setup(), usbd_transfer_unsetup(), and usbd_xfer_get_frame_buffer().
|
static |
Definition at line 849 of file cfumass.c.
References CBWFLAGS_IN, CBWFLAGS_OUT, CFUMASS_DEBUG, CFUMASS_LOCK, CFUMASS_T_DATA_IN, CFUMASS_T_DATA_OUT, cfumass_transfer_start(), CFUMASS_UNLOCK, CFUMASS_WARN, fail, cfumass_softc::sc_ctl_io, and cfumass_softc::sc_current_flags.
Referenced by cfumass_init().
|
static |
Definition at line 397 of file cfumass.c.
References CFUMASS_DEBUG, CFUMASS_LOCK, cfumass_port, cfumass_refcount, CFUMASS_T_MAX, cfumass_terminate(), CFUMASS_UNLOCK, CFUMASS_WARN, dev, error, cfumass_softc::sc_ctl_initid, cfumass_softc::sc_mtx, cfumass_softc::sc_xfer, and usbd_transfer_unsetup().
|
static |
Definition at line 895 of file cfumass.c.
References CFUMASS_DEBUG, CFUMASS_LOCK, CFUMASS_T_STATUS, cfumass_transfer_start(), CFUMASS_UNLOCK, cfumass_softc::sc_ctl_io, cfumass_softc::sc_current_status, and cfumass_softc::sc_queued.
Referenced by cfumass_init().
|
static |
Definition at line 496 of file cfumass.c.
References CFUMASS_DEBUG, CFUMASS_LOCK, CFUMASS_T_COMMAND, cfumass_terminate(), cfumass_transfer_start(), CFUMASS_UNLOCK, CFUMASS_WARN, dev, max_lun, offset, plen, pptr, pstate, req, UR_GET_MAX_LUN, UR_RESET, UT_READ_CLASS_INTERFACE, and UT_WRITE_CLASS_INTERFACE.
|
static |
Definition at line 948 of file cfumass.c.
References cfumass_datamove(), cfumass_done(), cfumass_frontend, cfumass_offline(), cfumass_online(), cfumass_port, cfumass_port_online, cfumass_refcount, and error.
|
static |
Definition at line 842 of file cfumass.c.
References cfumass_port_online.
|
static |
|
static |
Definition at line 835 of file cfumass.c.
References cfumass_port_online.
|
static |
|
static |
Definition at line 318 of file cfumass.c.
References dev, id, usb_attach_arg::iface, UICLASS_MASS, UIPROTO_MASS_BBB, UISUBCLASS_SCSI, usb_attach_arg::usb_mode, USB_MODE_DEVICE, and usbd_get_interface_descriptor().
|
static |
Definition at line 559 of file cfumass.c.
References CFUMASS_DEBUG, CFUMASS_T_STATUS, cfumass_transfer_start(), CFUMASS_WARN, ignore_stop, and cfumass_softc::sc_current_status.
Referenced by cfumass_t_command_callback().
|
static |
Definition at line 438 of file cfumass.c.
References CFUMASS_DEBUG, and dev.
|
static |
Definition at line 978 of file cfumass.c.
References cfumass_port, cfumass_refcount, debug, and error.
|
static |
Definition at line 427 of file cfumass.c.
References CFUMASS_DEBUG, and dev.
|
static |
Definition at line 609 of file cfumass.c.
References cfumass_cbw_t::bCBWFlags, cfumass_cbw_t::bCBWLUN, cfumass_cbw_t::bCDBLength, cfumass_cbw_t::CBWCB, CBWSIGNATURE, CFUMASS_DEBUG, CFUMASS_LOCK, cfumass_port, cfumass_port_online, cfumass_quirk(), CFUMASS_UNLOCK, CFUMASS_WARN, cfumass_cbw_t::dCBWDataTransferLength, cfumass_cbw_t::dCBWSignature, cfumass_cbw_t::dCBWTag, error, cfumass_softc::sc_cbw, cfumass_softc::sc_ctl_initid, cfumass_softc::sc_ctl_io, cfumass_softc::sc_current_flags, cfumass_softc::sc_current_residue, cfumass_softc::sc_current_stalled, cfumass_softc::sc_current_status, cfumass_softc::sc_current_tag, cfumass_softc::sc_current_transfer_length, cfumass_softc::sc_queued, UGETDW, USB_ERR_CANCELLED, USB_GET_STATE, USB_ST_SETUP, USB_ST_TRANSFERRED, usbd_errstr(), usbd_transfer_submit(), usbd_xfer_set_frame_len(), usbd_xfer_set_stall(), and usbd_xfer_softc().
|
static |
Definition at line 713 of file cfumass.c.
References CFUMASS_DEBUG, cfumass_softc::sc_ctl_io, cfumass_softc::sc_current_residue, cfumass_softc::sc_current_transfer_length, USB_ERR_CANCELLED, USB_GET_STATE, USB_ST_SETUP, USB_ST_TRANSFERRED, usbd_errstr(), usbd_transfer_submit(), usbd_xfer_max_len(), usbd_xfer_set_frame_data(), usbd_xfer_softc(), and usbd_xfer_status().
|
static |
Definition at line 786 of file cfumass.c.
References cfumass_csw_t::bCSWStatus, CFUMASS_DEBUG, CFUMASS_T_COMMAND, cfumass_transfer_start(), CSWSIGNATURE, cfumass_csw_t::dCSWDataResidue, cfumass_csw_t::dCSWSignature, cfumass_csw_t::dCSWTag, cfumass_softc::sc_csw, cfumass_softc::sc_ctl_io, cfumass_softc::sc_current_residue, cfumass_softc::sc_current_stalled, cfumass_softc::sc_current_status, cfumass_softc::sc_current_tag, USB_ERR_CANCELLED, USB_GET_STATE, USB_ST_SETUP, USB_ST_TRANSFERRED, usbd_errstr(), usbd_transfer_submit(), usbd_xfer_set_frame_len(), usbd_xfer_set_stall(), usbd_xfer_softc(), and USETDW.
|
static |
Definition at line 466 of file cfumass.c.
References CFUMASS_DEBUG, CFUMASS_T_COMMAND, CFUMASS_T_DATA_IN, CFUMASS_T_DATA_OUT, CFUMASS_T_STATUS, cfumass_transfer_stop_and_drain(), cfumass_softc::sc_ctl_io, cfumass_softc::sc_mtx, and cfumass_softc::sc_queued.
Referenced by cfumass_detach(), and cfumass_handle_request().
|
static |
Definition at line 449 of file cfumass.c.
References cfumass_softc::sc_xfer, and usbd_transfer_start().
Referenced by cfumass_attach(), cfumass_datamove(), cfumass_done(), cfumass_handle_request(), cfumass_quirk(), and cfumass_t_status_callback().
|
static |
Definition at line 456 of file cfumass.c.
References CFUMASS_LOCK, CFUMASS_UNLOCK, cfumass_softc::sc_xfer, usbd_transfer_drain(), and usbd_transfer_stop().
Referenced by cfumass_terminate().
CTASSERT | ( | sizeof(struct cfumass_cbw_t) | = =CFUMASS_CBW_SIZE | ) |
CTASSERT | ( | sizeof(struct cfumass_csw_t) | = =CFUMASS_CSW_SIZE | ) |
CTL_FRONTEND_DECLARE | ( | ctlcfumass | , |
cfumass_frontend | |||
) |
DRIVER_MODULE | ( | cfumass | , |
uhub | , | ||
cfumass_driver | , | ||
cfumass_devclass | , | ||
NULL | , | ||
0 | |||
) |
MODULE_DEPEND | ( | cfumass | , |
usb | , | ||
1 | , | ||
1 | , | ||
1 | |||
) |
MODULE_DEPEND | ( | cfumass | , |
usb_template | , | ||
1 | , | ||
1 | , | ||
1 | |||
) |
MODULE_VERSION | ( | cfumass | , |
0 | |||
) |
SYSCTL_INT | ( | _hw_usb_cfumass | , |
OID_AUTO | , | ||
debug | , | ||
CTLFLAG_RWTUN | , | ||
& | debug, | ||
1 | , | ||
"Enable debug messages" | |||
) |
SYSCTL_INT | ( | _hw_usb_cfumass | , |
OID_AUTO | , | ||
ignore_stop | , | ||
CTLFLAG_RWTUN | , | ||
& | ignore_stop, | ||
1 | , | ||
"Ignore START STOP UNIT with START and LOEJ bits cleared" | |||
) |
SYSCTL_INT | ( | _hw_usb_cfumass | , |
OID_AUTO | , | ||
max_lun | , | ||
CTLFLAG_RWTUN | , | ||
& | max_lun, | ||
1 | , | ||
"Maximum advertised LUN number" | |||
) |
SYSCTL_NODE | ( | _hw_usb | , |
OID_AUTO | , | ||
cfumass | , | ||
CTLFLAG_RW| | CTLFLAG_MPSAFE, | ||
0 | , | ||
"CAM Target Layer USB Mass Storage Frontend" | |||
) |
struct cfumass_csw_t __packed |
|
static |
Definition at line 234 of file cfumass.c.
Referenced by cfumass_attach().
|
static |
|
static |
Definition at line 287 of file cfumass.c.
Referenced by cfumass_init().
|
static |
struct ctl_port cfumass_port |
Definition at line 89 of file cfumass.c.
Referenced by cfumass_attach(), cfumass_detach(), cfumass_init(), cfumass_shutdown(), and cfumass_t_command_callback().
bool cfumass_port_online |
Definition at line 90 of file cfumass.c.
Referenced by cfumass_init(), cfumass_offline(), cfumass_online(), and cfumass_t_command_callback().
volatile u_int cfumass_refcount |
Definition at line 91 of file cfumass.c.
Referenced by cfumass_attach(), cfumass_detach(), cfumass_init(), and cfumass_shutdown().
|
static |
|
static |
|
static |
|
static |
Definition at line 73 of file cfumass.c.
Referenced by cfumass_shutdown().
|
static |
Definition at line 79 of file cfumass.c.
Referenced by cfumass_quirk().
|
static |
Definition at line 76 of file cfumass.c.
Referenced by cfumass_handle_request().