FreeBSD kernel usb device Code
u3g.c File Reference
#include <sys/param.h>
#include <sys/eventhandler.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/queue.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_cdc.h>
#include "usbdevs.h"
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_msctest.h>
#include <dev/usb/serial/usb_serial.h>
#include <dev/usb/quirk/usb_quirk.h>
Include dependency graph for u3g.c:

Go to the source code of this file.

Data Structures

struct  u3g_softc
 

Macros

#define USB_DEBUG_VAR   u3g_debug
 
#define U3G_MAXPORTS   12
 
#define U3G_CONFIG_INDEX   0
 
#define U3G_BSIZE   2048
 
#define U3G_TXSIZE   (U3G_BSIZE / U3G_TXFRAMES)
 
#define U3G_TXFRAMES   4
 
#define U3GINIT_HUAWEI   1 /* Requires Huawei init command */
 
#define U3GINIT_SIERRA   2 /* Requires Sierra init command */
 
#define U3GINIT_SCSIEJECT   3 /* Requires SCSI eject command */
 
#define U3GINIT_REZERO   4 /* Requires SCSI rezero command */
 
#define U3GINIT_ZTESTOR   5 /* Requires ZTE SCSI command */
 
#define U3GINIT_CMOTECH   6 /* Requires CMOTECH SCSI command */
 
#define U3GINIT_WAIT   7 /* Device reappears after a delay */
 
#define U3GINIT_SAEL_M460   8 /* Requires vendor init */
 
#define U3GINIT_HUAWEISCSI   9 /* Requires Huawei SCSI init command */
 
#define U3GINIT_HUAWEISCSI2   10 /* Requires Huawei SCSI init command (2) */
 
#define U3GINIT_TCT   11 /* Requires TCT Mobile init command */
 
#define U3G_DEV(v, p, i)   { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) }
 

Enumerations

enum  { U3G_BULK_WR , U3G_BULK_RD , U3G_INTR , U3G_N_TRANSFER }
 

Functions

static void u3g_free_softc (struct u3g_softc *)
 
static void u3g_cfg_get_status (struct ucom_softc *, uint8_t *, uint8_t *)
 
static void u3g_cfg_set_dtr (struct ucom_softc *, uint8_t)
 
static void u3g_cfg_set_rts (struct ucom_softc *, uint8_t)
 
static void u3g_start_read (struct ucom_softc *ucom)
 
static void u3g_stop_read (struct ucom_softc *ucom)
 
static void u3g_start_write (struct ucom_softc *ucom)
 
static void u3g_stop_write (struct ucom_softc *ucom)
 
static void u3g_poll (struct ucom_softc *ucom)
 
static void u3g_free (struct ucom_softc *ucom)
 
static void u3g_test_autoinst (void *, struct usb_device *, struct usb_attach_arg *)
 
static int u3g_driver_loaded (struct module *mod, int what, void *arg)
 
 DRIVER_MODULE (u3g, uhub, u3g_driver, u3g_devclass, u3g_driver_loaded, 0)
 
 MODULE_DEPEND (u3g, ucom, 1, 1, 1)
 
 MODULE_DEPEND (u3g, usb, 1, 1, 1)
 
 MODULE_VERSION (u3g, 1)
 
 USB_PNP_HOST_INFO (u3g_devs)
 
static int u3g_sierra_init (struct usb_device *udev)
 
static int u3g_huawei_init (struct usb_device *udev)
 
static int u3g_huawei_is_cdce (uint16_t idVendor, uint8_t bInterfaceSubClass, uint8_t bInterfaceProtocol)
 
static void u3g_sael_m460_init (struct usb_device *udev)
 
static int u3g_probe (device_t self)
 
static int u3g_attach (device_t dev)
 
static int u3g_detach (device_t dev)
 
 UCOM_UNLOAD_DRAIN (u3g)
 
static void u3g_write_callback (struct usb_xfer *xfer, usb_error_t error)
 
static void u3g_read_callback (struct usb_xfer *xfer, usb_error_t error)
 
static void u3g_cfg_set_line (struct ucom_softc *ucom)
 
static void u3g_intr_callback (struct usb_xfer *xfer, usb_error_t error)
 

Variables

static device_probe_t u3g_probe
 
static device_attach_t u3g_attach
 
static device_detach_t u3g_detach
 
static usb_callback_t u3g_write_callback
 
static usb_callback_t u3g_read_callback
 
static usb_callback_t u3g_intr_callback
 
static eventhandler_tag u3g_etag
 
static const struct usb_config u3g_config [U3G_N_TRANSFER]
 
static const struct ucom_callback u3g_callback
 
static device_method_t u3g_methods []
 
static devclass_t u3g_devclass
 
static driver_t u3g_driver
 
static const STRUCT_USB_HOST_ID u3g_devs []
 

Macro Definition Documentation

◆ U3G_BSIZE

#define U3G_BSIZE   2048

Definition at line 77 of file u3g.c.

◆ U3G_CONFIG_INDEX

#define U3G_CONFIG_INDEX   0

Definition at line 76 of file u3g.c.

◆ U3G_DEV

#define U3G_DEV (   v,
  p,
 
)    { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) }

◆ U3G_MAXPORTS

#define U3G_MAXPORTS   12

Definition at line 75 of file u3g.c.

◆ U3G_TXFRAMES

#define U3G_TXFRAMES   4

Definition at line 79 of file u3g.c.

◆ U3G_TXSIZE

#define U3G_TXSIZE   (U3G_BSIZE / U3G_TXFRAMES)

Definition at line 78 of file u3g.c.

◆ U3GINIT_CMOTECH

#define U3GINIT_CMOTECH   6 /* Requires CMOTECH SCSI command */

Definition at line 87 of file u3g.c.

◆ U3GINIT_HUAWEI

#define U3GINIT_HUAWEI   1 /* Requires Huawei init command */

Definition at line 82 of file u3g.c.

◆ U3GINIT_HUAWEISCSI

#define U3GINIT_HUAWEISCSI   9 /* Requires Huawei SCSI init command */

Definition at line 90 of file u3g.c.

◆ U3GINIT_HUAWEISCSI2

#define U3GINIT_HUAWEISCSI2   10 /* Requires Huawei SCSI init command (2) */

Definition at line 91 of file u3g.c.

◆ U3GINIT_REZERO

#define U3GINIT_REZERO   4 /* Requires SCSI rezero command */

Definition at line 85 of file u3g.c.

◆ U3GINIT_SAEL_M460

#define U3GINIT_SAEL_M460   8 /* Requires vendor init */

Definition at line 89 of file u3g.c.

◆ U3GINIT_SCSIEJECT

#define U3GINIT_SCSIEJECT   3 /* Requires SCSI eject command */

Definition at line 84 of file u3g.c.

◆ U3GINIT_SIERRA

#define U3GINIT_SIERRA   2 /* Requires Sierra init command */

Definition at line 83 of file u3g.c.

◆ U3GINIT_TCT

#define U3GINIT_TCT   11 /* Requires TCT Mobile init command */

Definition at line 92 of file u3g.c.

◆ U3GINIT_WAIT

#define U3GINIT_WAIT   7 /* Device reappears after a delay */

Definition at line 88 of file u3g.c.

◆ U3GINIT_ZTESTOR

#define U3GINIT_ZTESTOR   5 /* Requires ZTE SCSI command */

Definition at line 86 of file u3g.c.

◆ USB_DEBUG_VAR

#define USB_DEBUG_VAR   u3g_debug

Definition at line 58 of file u3g.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
U3G_BULK_WR 
U3G_BULK_RD 
U3G_INTR 
U3G_N_TRANSFER 

Definition at line 94 of file u3g.c.

Function Documentation

◆ DRIVER_MODULE()

DRIVER_MODULE ( u3g  ,
uhub  ,
u3g_driver  ,
u3g_devclass  ,
u3g_driver_loaded  ,
 
)

◆ MODULE_DEPEND() [1/2]

MODULE_DEPEND ( u3g  ,
ucom  ,
,
,
 
)

◆ MODULE_DEPEND() [2/2]

MODULE_DEPEND ( u3g  ,
usb  ,
,
,
 
)

◆ MODULE_VERSION()

MODULE_VERSION ( u3g  ,
 
)

◆ u3g_attach()

◆ u3g_cfg_get_status()

static void u3g_cfg_get_status ( struct ucom_softc ucom,
uint8_t *  lsr,
uint8_t *  msr 
)
static

◆ u3g_cfg_set_dtr()

static void u3g_cfg_set_dtr ( struct ucom_softc ucom,
uint8_t  onoff 
)
static

Definition at line 1189 of file u3g.c.

References DPRINTF, u3g_softc::sc_line, ucom_softc::sc_parent, ucom_softc::sc_subunit, u3g_cfg_set_line(), and UCDC_LINE_DTR.

Here is the call graph for this function:

◆ u3g_cfg_set_line()

static void u3g_cfg_set_line ( struct ucom_softc ucom)
static

◆ u3g_cfg_set_rts()

static void u3g_cfg_set_rts ( struct ucom_softc ucom,
uint8_t  onoff 
)
static

Definition at line 1204 of file u3g.c.

References DPRINTF, u3g_softc::sc_line, ucom_softc::sc_parent, ucom_softc::sc_subunit, u3g_cfg_set_line(), and UCDC_LINE_RTS.

Here is the call graph for this function:

◆ u3g_detach()

static int u3g_detach ( device_t  dev)
static

Definition at line 1018 of file u3g.c.

References dev, DPRINTF, u3g_softc::sc_super_ucom, u3g_softc::sc_ucom, u3g_softc::sc_xfer, u3g_free_softc(), U3G_MAXPORTS, U3G_N_TRANSFER, ucom_detach(), and usbd_transfer_unsetup().

Here is the call graph for this function:

◆ u3g_driver_loaded()

static int u3g_driver_loaded ( struct module *  mod,
int  what,
void *  arg 
)
static

Definition at line 865 of file u3g.c.

References u3g_etag, and u3g_test_autoinst().

Here is the call graph for this function:

◆ u3g_free()

static void u3g_free ( struct ucom_softc ucom)
static

Definition at line 1050 of file u3g.c.

References ucom_softc::sc_parent, and u3g_free_softc().

Here is the call graph for this function:

◆ u3g_free_softc()

static void u3g_free_softc ( struct u3g_softc sc)
static

Definition at line 1041 of file u3g.c.

References u3g_softc::sc_mtx, u3g_softc::sc_super_ucom, and ucom_unref().

Referenced by u3g_detach(), and u3g_free().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ u3g_huawei_init()

static int u3g_huawei_init ( struct usb_device udev)
static

Definition at line 628 of file u3g.c.

References req, UF_DEVICE_REMOTE_WAKEUP, UHF_PORT_SUSPEND, UR_SET_FEATURE, USB_MS_HZ, usbd_do_request_flags(), USETW, and UT_WRITE_DEVICE.

Referenced by u3g_test_autoinst().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ u3g_huawei_is_cdce()

static int u3g_huawei_is_cdce ( uint16_t  idVendor,
uint8_t  bInterfaceSubClass,
uint8_t  bInterfaceProtocol 
)
static

Definition at line 646 of file u3g.c.

References bInterfaceProtocol, bInterfaceSubClass, and idVendor.

Referenced by u3g_attach(), and u3g_probe().

Here is the caller graph for this function:

◆ u3g_intr_callback()

◆ u3g_poll()

static void u3g_poll ( struct ucom_softc ucom)
static

Definition at line 1287 of file u3g.c.

References ucom_softc::sc_parent, ucom_softc::sc_subunit, u3g_softc::sc_xfer, U3G_N_TRANSFER, and usbd_transfer_poll().

Here is the call graph for this function:

◆ u3g_probe()

◆ u3g_read_callback()

static void u3g_read_callback ( struct usb_xfer xfer,
usb_error_t  error 
)
static

◆ u3g_sael_m460_init()

static void u3g_sael_m460_init ( struct usb_device udev)
static

Definition at line 685 of file u3g.c.

References len, n, req, UE_DIR_IN, UGETW, USB_ERR_TIMEOUT, usbd_do_request, and usbd_req_set_alt_interface_no().

Referenced by u3g_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ u3g_sierra_init()

static int u3g_sierra_init ( struct usb_device udev)
static

Definition at line 610 of file u3g.c.

References req, UF_DEVICE_REMOTE_WAKEUP, UHF_PORT_CONNECTION, UR_SET_INTERFACE, USB_MS_HZ, usbd_do_request_flags(), USETW, and UT_VENDOR.

Referenced by u3g_test_autoinst().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ u3g_start_read()

static void u3g_start_read ( struct ucom_softc ucom)
static

Definition at line 1056 of file u3g.c.

References ucom_softc::sc_parent, ucom_softc::sc_subunit, u3g_softc::sc_xfer, U3G_BULK_RD, U3G_INTR, and usbd_transfer_start().

Here is the call graph for this function:

◆ u3g_start_write()

static void u3g_start_write ( struct ucom_softc ucom)
static

Definition at line 1080 of file u3g.c.

References ucom_softc::sc_parent, ucom_softc::sc_subunit, u3g_softc::sc_xfer, U3G_BULK_WR, and usbd_transfer_start().

Here is the call graph for this function:

◆ u3g_stop_read()

static void u3g_stop_read ( struct ucom_softc ucom)
static

Definition at line 1068 of file u3g.c.

References ucom_softc::sc_parent, ucom_softc::sc_subunit, u3g_softc::sc_xfer, U3G_BULK_RD, U3G_INTR, and usbd_transfer_stop().

Here is the call graph for this function:

◆ u3g_stop_write()

static void u3g_stop_write ( struct ucom_softc ucom)
static

Definition at line 1088 of file u3g.c.

References ucom_softc::sc_parent, ucom_softc::sc_subunit, u3g_softc::sc_xfer, U3G_BULK_WR, and usbd_transfer_stop().

Here is the call graph for this function:

◆ u3g_test_autoinst()

◆ u3g_write_callback()

◆ UCOM_UNLOAD_DRAIN()

UCOM_UNLOAD_DRAIN ( u3g  )

◆ USB_PNP_HOST_INFO()

USB_PNP_HOST_INFO ( u3g_devs  )

Variable Documentation

◆ u3g_attach

device_attach_t u3g_attach
static

Definition at line 118 of file u3g.c.

◆ u3g_callback

const struct ucom_callback u3g_callback
static
Initial value:
= {
.ucom_cfg_get_status = &u3g_cfg_get_status,
.ucom_cfg_set_dtr = &u3g_cfg_set_dtr,
.ucom_cfg_set_rts = &u3g_cfg_set_rts,
.ucom_start_read = &u3g_start_read,
.ucom_stop_read = &u3g_stop_read,
.ucom_start_write = &u3g_start_write,
.ucom_stop_write = &u3g_stop_write,
.ucom_poll = &u3g_poll,
.ucom_free = &u3g_free,
}
static void u3g_stop_write(struct ucom_softc *ucom)
Definition: u3g.c:1088
static void u3g_free(struct ucom_softc *ucom)
Definition: u3g.c:1050
static void u3g_cfg_set_rts(struct ucom_softc *, uint8_t)
Definition: u3g.c:1204
static void u3g_cfg_set_dtr(struct ucom_softc *, uint8_t)
Definition: u3g.c:1189
static void u3g_start_read(struct ucom_softc *ucom)
Definition: u3g.c:1056
static void u3g_start_write(struct ucom_softc *ucom)
Definition: u3g.c:1080
static void u3g_stop_read(struct ucom_softc *ucom)
Definition: u3g.c:1068
static void u3g_cfg_get_status(struct ucom_softc *, uint8_t *, uint8_t *)
Definition: u3g.c:1162
static void u3g_poll(struct ucom_softc *ucom)
Definition: u3g.c:1287

Definition at line 172 of file u3g.c.

Referenced by u3g_attach().

◆ u3g_config

const struct usb_config u3g_config[U3G_N_TRANSFER]
static
Initial value:
= {
.type = UE_BULK,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_OUT,
.bufsize = U3G_BSIZE,
.frames = U3G_TXFRAMES,
.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
.callback = &u3g_write_callback,
},
.type = UE_BULK,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_IN,
.bufsize = U3G_BSIZE,
.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
.callback = &u3g_read_callback,
},
[U3G_INTR] = {
.type = UE_INTERRUPT,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_IN,
.flags = {.pipe_bof = 1,.short_xfer_ok = 1,.no_pipe_ok = 1,},
.bufsize = 0,
.callback = &u3g_intr_callback,
},
}
static usb_callback_t u3g_intr_callback
Definition: u3g.c:124
static usb_callback_t u3g_read_callback
Definition: u3g.c:123
@ U3G_BULK_WR
Definition: u3g.c:95
@ U3G_INTR
Definition: u3g.c:97
@ U3G_BULK_RD
Definition: u3g.c:96
#define U3G_BSIZE
Definition: u3g.c:77
static usb_callback_t u3g_write_callback
Definition: u3g.c:122
#define U3G_TXFRAMES
Definition: u3g.c:79
#define UE_INTERRUPT
Definition: usb.h:544
#define UE_ADDR_ANY
Definition: usb.h:537
#define UE_BULK
Definition: usb.h:543
#define UE_DIR_IN
Definition: usb.h:531
#define UE_DIR_OUT
Definition: usb.h:532

Definition at line 142 of file u3g.c.

Referenced by u3g_attach().

◆ u3g_detach

device_detach_t u3g_detach
static

Definition at line 119 of file u3g.c.

Referenced by u3g_attach().

◆ u3g_devclass

devclass_t u3g_devclass
static

Definition at line 191 of file u3g.c.

◆ u3g_devs

const STRUCT_USB_HOST_ID u3g_devs[]
static

Definition at line 199 of file u3g.c.

Referenced by u3g_probe(), and u3g_test_autoinst().

◆ u3g_driver

driver_t u3g_driver
static
Initial value:
= {
.name = "u3g",
.methods = u3g_methods,
.size = sizeof(struct u3g_softc),
}
Definition: u3g.c:101
static device_method_t u3g_methods[]
Definition: u3g.c:184

Definition at line 193 of file u3g.c.

◆ u3g_etag

eventhandler_tag u3g_etag
static

Definition at line 140 of file u3g.c.

Referenced by u3g_driver_loaded().

◆ u3g_intr_callback

usb_callback_t u3g_intr_callback
static

Definition at line 124 of file u3g.c.

◆ u3g_methods

device_method_t u3g_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, u3g_probe),
DEVMETHOD(device_attach, u3g_attach),
DEVMETHOD(device_detach, u3g_detach),
DEVMETHOD_END
}
static device_probe_t u3g_probe
Definition: u3g.c:117
static device_detach_t u3g_detach
Definition: u3g.c:119
static device_attach_t u3g_attach
Definition: u3g.c:118

Definition at line 184 of file u3g.c.

◆ u3g_probe

device_probe_t u3g_probe
static

Definition at line 117 of file u3g.c.

◆ u3g_read_callback

usb_callback_t u3g_read_callback
static

Definition at line 123 of file u3g.c.

◆ u3g_write_callback

usb_callback_t u3g_write_callback
static

Definition at line 122 of file u3g.c.