本文整理汇总了C++中device_get_sysctl_tree函数的典型用法代码示例。如果您正苦于以下问题:C++ device_get_sysctl_tree函数的具体用法?C++ device_get_sysctl_tree怎么用?C++ device_get_sysctl_tree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了device_get_sysctl_tree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: acpi_cpu_startup_cx
static void
acpi_cpu_startup_cx(struct acpi_cpu_softc *sc)
{
acpi_cpu_cx_list(sc);
SYSCTL_ADD_STRING(&sc->cpu_sysctl_ctx,
SYSCTL_CHILDREN(device_get_sysctl_tree(sc->cpu_dev)),
OID_AUTO, "cx_supported", CTLFLAG_RD,
sc->cpu_cx_supported, 0,
"Cx/microsecond values for supported Cx states");
SYSCTL_ADD_PROC(&sc->cpu_sysctl_ctx,
SYSCTL_CHILDREN(device_get_sysctl_tree(sc->cpu_dev)),
OID_AUTO, "cx_lowest", CTLTYPE_STRING | CTLFLAG_RW,
(void *)sc, 0, acpi_cpu_cx_lowest_sysctl, "A",
"lowest Cx sleep state to use");
SYSCTL_ADD_PROC(&sc->cpu_sysctl_ctx,
SYSCTL_CHILDREN(device_get_sysctl_tree(sc->cpu_dev)),
OID_AUTO, "cx_usage", CTLTYPE_STRING | CTLFLAG_RD,
(void *)sc, 0, acpi_cpu_usage_sysctl, "A",
"percent usage for each Cx state");
#ifdef notyet
/* Signal platform that we can handle _CST notification. */
if (!cpu_cx_generic && cpu_cst_cnt != 0) {
ACPI_LOCK(acpi);
AcpiOsWritePort(cpu_smi_cmd, cpu_cst_cnt, 8);
ACPI_UNLOCK(acpi);
}
#endif
}
示例2: ucom_set_pnpinfo_usb
void
ucom_set_pnpinfo_usb(struct ucom_super_softc *ssc, device_t dev)
{
char buf[64];
uint8_t iface_index;
struct usb_attach_arg *uaa;
snprintf(buf, sizeof(buf), "ttyname=" UCOM_TTY_PREFIX
"%d ttyports=%d", ssc->sc_unit, ssc->sc_subunits);
/* Store the PNP info in the first interface for the device */
uaa = device_get_ivars(dev);
iface_index = uaa->info.bIfaceIndex;
if (usbd_set_pnpinfo(uaa->device, iface_index, buf) != 0)
device_printf(dev, "Could not set PNP info\n");
/*
* The following information is also replicated in the PNP-info
* string which is registered above:
*/
if (ssc->sc_sysctl_ttyname == NULL) {
ssc->sc_sysctl_ttyname = SYSCTL_ADD_STRING(NULL,
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "ttyname", CTLFLAG_RD, ssc->sc_ttyname, 0,
"TTY device basename");
}
if (ssc->sc_sysctl_ttyports == NULL) {
ssc->sc_sysctl_ttyports = SYSCTL_ADD_INT(NULL,
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "ttyports", CTLFLAG_RD,
NULL, ssc->sc_subunits, "Number of ports");
}
}
示例3: acpi_sony_attach
static int
acpi_sony_attach(device_t dev)
{
struct acpi_sony_softc *sc;
int i;
sc = device_get_softc(dev);
acpi_GetInteger(acpi_get_handle(dev), ACPI_SONY_GET_PID, &sc->pid);
device_printf(dev, "PID %x\n", sc->pid);
for (i = 0 ; acpi_sony_oids[i].nodename != NULL; i++) {
if (acpi_sony_oids[i].setmethod != NULL) {
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
i, acpi_sony_oids[i].nodename ,
CTLTYPE_INT | CTLFLAG_RW,
dev, i, sysctl_acpi_sony_gen_handler, "I",
acpi_sony_oids[i].comment);
} else {
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
i, acpi_sony_oids[i].nodename ,
CTLTYPE_INT | CTLFLAG_RD,
dev, i, sysctl_acpi_sony_gen_handler, "I",
acpi_sony_oids[i].comment);
}
}
return (0);
}
示例4: initialize_tempmon
static void
initialize_tempmon(struct imx6_anatop_softc *sc)
{
uint32_t cal;
struct sysctl_ctx_list *ctx;
/*
* Fetch calibration data: a sensor count at room temperature (25C),
* a sensor count at a high temperature, and that temperature
*/
cal = fsl_ocotp_read_4(FSL_OCOTP_ANA1);
sc->temp_room_cnt = (cal & 0xFFF00000) >> 20;
sc->temp_high_cnt = (cal & 0x000FFF00) >> 8;
sc->temp_high_val = (cal & 0x000000FF) * 10;
/*
* Throttle to a lower cpu freq at 10C below the "hot" temperature, and
* reset back to max cpu freq at 5C below the trigger.
*/
sc->temp_throttle_val = sc->temp_high_val - 100;
sc->temp_throttle_trigger_cnt =
temp_to_count(sc, sc->temp_throttle_val);
sc->temp_throttle_reset_cnt =
temp_to_count(sc, sc->temp_throttle_val - 50);
/*
* Set the sensor to sample automatically at 16Hz (32.768KHz/0x800), set
* the throttle count, and begin making measurements.
*/
imx6_anatop_write_4(IMX6_ANALOG_TEMPMON_TEMPSENSE1, 0x0800);
imx6_anatop_write_4(IMX6_ANALOG_TEMPMON_TEMPSENSE0,
(sc->temp_throttle_trigger_cnt <<
IMX6_ANALOG_TEMPMON_TEMPSENSE0_ALARM_SHIFT) |
IMX6_ANALOG_TEMPMON_TEMPSENSE0_MEASURE);
/*
* XXX Note that the alarm-interrupt feature isn't working yet, so
* we'll use a callout handler to check at 10Hz. Make sure we have an
* initial temperature reading before starting up the callouts so we
* don't get a bogus reading of zero.
*/
while (sc->temp_last_cnt == 0)
temp_update_count(sc);
sc->temp_throttle_delay = 100 * SBT_1MS;
callout_init(&sc->temp_throttle_callout, 0);
callout_reset_sbt(&sc->temp_throttle_callout, sc->temp_throttle_delay,
0, tempmon_throttle_check, sc, 0);
ctx = device_get_sysctl_ctx(sc->dev);
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)),
OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD, sc, 0,
temp_sysctl_handler, "IK", "Current die temperature");
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)),
OID_AUTO, "throttle_temperature", CTLTYPE_INT | CTLFLAG_RW, sc,
0, temp_throttle_sysctl_handler, "IK",
"Throttle CPU when exceeding this temperature");
}
示例5: ow_temp_attach
static int
ow_temp_attach(device_t dev)
{
struct ow_temp_softc *sc;
sc = device_get_softc(dev);
sc->dev = dev;
sc->type = ow_get_family(dev);
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "temperature", CTLFLAG_RD | CTLTYPE_INT,
&sc->temp, 0, sysctl_handle_int,
"IK3", "Current Temperature");
SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "badcrc", CTLFLAG_RD,
&sc->bad_crc, 0,
"Number of Bad CRC on reading scratchpad");
SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "badread", CTLFLAG_RD,
&sc->bad_reads, 0,
"Number of errors on reading scratchpad");
SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "reading_interval", CTLFLAG_RW,
&sc->reading_interval, 0,
"ticks between reads");
SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "parasite", CTLFLAG_RW,
&sc->parasite, 0,
"In Parasite mode");
/*
* Just do this for unit 0 to avoid locking
* the ow bus until that code can be put
* into place.
*/
sc->temp = -1;
sc->reading_interval = 10 * hz;
mtx_init(&sc->temp_lock, "lock for doing temperature", NULL, MTX_DEF);
/* Start the thread */
if (kproc_create(ow_temp_event_thread, sc, &sc->event_thread, 0, 0,
"%s event thread", device_get_nameunit(dev))) {
device_printf(dev, "unable to create event thread.\n");
panic("cbb_create_event_thread");
}
return 0;
}
示例6: aw_sid_attach
static int
aw_sid_attach(device_t dev)
{
struct aw_sid_softc *sc;
sc = device_get_softc(dev);
if (bus_alloc_resources(dev, aw_sid_spec, &sc->res) != 0) {
device_printf(dev, "cannot allocate resources for device\n");
return (ENXIO);
}
aw_sid_sc = sc;
sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
switch (sc->type) {
case A83T_SID:
sc->root_key_off = A83T_ROOT_KEY_OFF;
break;
default:
sc->root_key_off = A10_ROOT_KEY_OFF;
break;
}
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "rootkey",
CTLTYPE_STRING | CTLFLAG_RD,
dev, AW_SID_ROOT_KEY, aw_sid_sysctl, "A", "Root Key");
return (0);
}
示例7: bcm_bsc_sysctl_init
static void
bcm_bsc_sysctl_init(struct bcm_bsc_softc *sc)
{
struct sysctl_ctx_list *ctx;
struct sysctl_oid *tree_node;
struct sysctl_oid_list *tree;
/*
* Add system sysctl tree/handlers.
*/
ctx = device_get_sysctl_ctx(sc->sc_dev);
tree_node = device_get_sysctl_tree(sc->sc_dev);
tree = SYSCTL_CHILDREN(tree_node);
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "frequency",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_bsc_clock_proc, "IU", "I2C BUS clock frequency");
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "clock_stretch",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_bsc_clkt_proc, "IU", "I2C BUS clock stretch timeout");
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "fall_edge_delay",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_bsc_fall_proc, "IU", "I2C BUS falling edge delay");
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "rise_edge_delay",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_bsc_rise_proc, "IU", "I2C BUS rising edge delay");
}
示例8: aw_ts_attach
static int
aw_ts_attach(device_t dev)
{
struct aw_ts_softc *sc;
sc = device_get_softc(dev);
sc->dev = dev;
if (bus_alloc_resources(dev, aw_ts_spec, sc->res) != 0) {
device_printf(dev, "could not allocate memory resource\n");
return (ENXIO);
}
if (bus_setup_intr(dev, sc->res[1],
INTR_TYPE_MISC | INTR_MPSAFE, NULL, aw_ts_intr, sc,
&sc->intrhand)) {
bus_release_resources(dev, aw_ts_spec, sc->res);
device_printf(dev, "cannot setup interrupt handler\n");
return (ENXIO);
}
/*
* Thoses magic values were taken from linux which take them from
* the allwinner SDK or found them by deduction
*/
switch (ofw_bus_search_compatible(dev, compat_data)->ocd_data) {
case A10_TS:
sc->temp_offset = 257000;
sc->temp_step = 133;
break;
case A13_TS:
sc->temp_offset = 144700;
sc->temp_step = 100;
break;
}
/* Enable clock and set divisers */
WRITE(sc, TP_CTRL0, TP_CTRL0_CLK_SELECT(0) |
TP_CTRL0_CLK_DIV(2) |
TP_CTRL0_FS_DIV(7) |
TP_CTRL0_TACQ(63));
/* Enable TS module */
WRITE(sc, TP_CTRL1, TP_CTRL1_MODE_EN);
/* Enable Temperature, period is ~2s */
WRITE(sc, TP_TPR, TP_TPR_TEMP_EN | TP_TPR_TEMP_PERIOD(1953));
/* Enable temp irq */
WRITE(sc, TP_FIFOC, TP_FIFOC_TEMP_IRQ_ENABLE);
/* Add sysctl */
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD,
&sc->temp_data, 0, sysctl_handle_int,
"IK3", "CPU Temperature");
return (0);
}
示例9: r21a_attach_private
static void
r21a_attach_private(struct rtwn_softc *sc)
{
struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
struct r12a_softc *rs;
rs = malloc(sizeof(struct r12a_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO);
rs->rs_flags = R12A_RXCKSUM_EN | R12A_RXCKSUM6_EN;
rs->rs_radar = 0;
SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
"radar_detection", CTLFLAG_RDTUN, &rs->rs_radar,
rs->rs_radar, "Enable radar detection (untested)");
rs->rs_fix_spur = rtwn_nop_softc_chan;
rs->rs_set_band_2ghz = r21a_set_band_2ghz;
rs->rs_set_band_5ghz = r21a_set_band_5ghz;
rs->rs_init_burstlen = r21au_init_burstlen;
rs->rs_init_ampdu_fwhw = r21a_init_ampdu_fwhw;
rs->rs_crystalcap_write = r21a_crystalcap_write;
#ifndef RTWN_WITHOUT_UCODE
rs->rs_iq_calib_fw_supported = r21a_iq_calib_fw_supported;
#endif
rs->rs_iq_calib_sw = r21a_iq_calib_sw;
rs->ampdu_max_time = 0x5e;
rs->ac_usb_dma_size = 0x01;
rs->ac_usb_dma_time = 0x10;
sc->sc_priv = rs;
}
示例10: bcm_spi_sysctl_init
static void
bcm_spi_sysctl_init(struct bcm_spi_softc *sc)
{
struct sysctl_ctx_list *ctx;
struct sysctl_oid *tree_node;
struct sysctl_oid_list *tree;
/*
* Add system sysctl tree/handlers.
*/
ctx = device_get_sysctl_ctx(sc->sc_dev);
tree_node = device_get_sysctl_tree(sc->sc_dev);
tree = SYSCTL_CHILDREN(tree_node);
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "clock",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_spi_clock_proc, "IU", "SPI BUS clock frequency");
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "cpol",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_spi_cpol_proc, "IU", "SPI BUS clock polarity");
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "cpha",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_spi_cpha_proc, "IU", "SPI BUS clock phase");
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "cspol0",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_spi_cspol0_proc, "IU", "SPI BUS chip select 0 polarity");
SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "cspol1",
CTLFLAG_RW | CTLTYPE_UINT, sc, sizeof(*sc),
bcm_spi_cspol1_proc, "IU", "SPI BUS chip select 1 polarity");
}
示例11: nvbl_attach
static int
nvbl_attach(device_t dev)
{
struct nvbl_softc *sc;
struct sysctl_ctx_list *ctx;
struct sysctl_oid *tree;
int rid;
sc = device_get_softc(dev);
rid = 0x10; /* BAR[0], for the MMIO register */
sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE | RF_SHAREABLE);
if (sc->sc_memr == NULL) {
device_printf(dev, "Could not alloc mem resource!\n");
return (ENXIO);
}
/* Turn on big-endian mode */
if (!(bus_read_stream_4(sc->sc_memr, NVIDIA_MMIO_PMC + 4) & 0x01000001)) {
bus_write_stream_4(sc->sc_memr, NVIDIA_MMIO_PMC + 4, 0x01000001);
mb();
}
ctx = device_get_sysctl_ctx(dev);
tree = device_get_sysctl_tree(dev);
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
"level", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
nvbl_sysctl, "I", "Backlight level (0-100)");
return (0);
}
示例12: iicbus_init_frequency
void
iicbus_init_frequency(device_t dev, u_int bus_freq)
{
struct iicbus_softc *sc = IICBUS_SOFTC(dev);
/*
* If a bus frequency value was passed in, use it. Otherwise initialize
* it first to the standard i2c 100KHz frequency, then override that
* from a hint if one exists.
*/
if (bus_freq > 0)
sc->bus_freq = bus_freq;
else {
sc->bus_freq = 100000;
resource_int_value(device_get_name(dev), device_get_unit(dev),
"frequency", (int *)&sc->bus_freq);
}
/*
* Set up the sysctl that allows the bus frequency to be changed.
* It is flagged as a tunable so that the user can set the value in
* loader(8), and that will override any other setting from any source.
* The sysctl tunable/value is the one most directly controlled by the
* user and thus the one that always takes precedence.
*/
SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
OID_AUTO, "frequency", CTLFLAG_RW | CTLFLAG_TUN, &sc->bus_freq,
sc->bus_freq, "Bus frequency in Hz");
}
示例13: ath_sysctl_hal_attach
/*
* This doesn't necessarily belong here (because it's HAL related, not
* driver related).
*/
void
ath_sysctl_hal_attach(struct ath_softc *sc)
{
struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hal", CTLFLAG_RD,
NULL, "Atheros HAL parameters");
child = SYSCTL_CHILDREN(tree);
sc->sc_ah->ah_config.ah_debug = 0;
SYSCTL_ADD_INT(ctx, child, OID_AUTO, "debug", CTLFLAG_RW,
&sc->sc_ah->ah_config.ah_debug, 0, "Atheros HAL debugging printfs");
sc->sc_ah->ah_config.ah_ar5416_biasadj = 0;
SYSCTL_ADD_INT(ctx, child, OID_AUTO, "ar5416_biasadj", CTLFLAG_RW,
&sc->sc_ah->ah_config.ah_ar5416_biasadj, 0,
"Enable 2GHz AR5416 direction sensitivity bias adjust");
sc->sc_ah->ah_config.ah_dma_beacon_response_time = 2;
SYSCTL_ADD_INT(ctx, child, OID_AUTO, "dma_brt", CTLFLAG_RW,
&sc->sc_ah->ah_config.ah_dma_beacon_response_time, 0,
"Atheros HAL DMA beacon response time");
sc->sc_ah->ah_config.ah_sw_beacon_response_time = 10;
SYSCTL_ADD_INT(ctx, child, OID_AUTO, "sw_brt", CTLFLAG_RW,
&sc->sc_ah->ah_config.ah_sw_beacon_response_time, 0,
"Atheros HAL software beacon response time");
sc->sc_ah->ah_config.ah_additional_swba_backoff = 0;
SYSCTL_ADD_INT(ctx, child, OID_AUTO, "swba_backoff", CTLFLAG_RW,
&sc->sc_ah->ah_config.ah_additional_swba_backoff, 0,
"Atheros HAL additional SWBA backoff time");
}
示例14: tegra124_coretemp_attach
static int
tegra124_coretemp_attach(device_t dev)
{
struct tegra124_coretemp_softc *sc;
device_t pdev;
struct sysctl_oid *oid;
struct sysctl_ctx_list *ctx;
int rv;
sc = device_get_softc(dev);
sc->dev = dev;
sc->cpu_id = device_get_unit(dev);
sc->core_max_temp = 102000;
pdev = device_get_parent(dev);
rv = tegra124_coretemp_ofw_parse(sc);
if (rv != 0)
return (rv);
ctx = device_get_sysctl_ctx(dev);
oid = SYSCTL_ADD_NODE(ctx,
SYSCTL_CHILDREN(device_get_sysctl_tree(pdev)), OID_AUTO,
"coretemp", CTLFLAG_RD, NULL, "Per-CPU thermal information");
/*
* Add the MIBs to dev.cpu.N and dev.cpu.N.coretemp.
*/
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(device_get_sysctl_tree(pdev)),
OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
dev, CORETEMP_TEMP, coretemp_get_val_sysctl, "IK",
"Current temperature");
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "delta",
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, CORETEMP_DELTA,
coretemp_get_val_sysctl, "I",
"Delta between TCC activation and current temperature");
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "resolution",
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, CORETEMP_RESOLUTION,
coretemp_get_val_sysctl, "I",
"Resolution of CPU thermal sensor");
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "tjmax",
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, CORETEMP_TJMAX,
coretemp_get_val_sysctl, "IK",
"TCC activation temperature");
return (0);
}
示例15: uhso_attach_ifnet
static int
uhso_attach_ifnet(struct uhso_softc *sc, struct usb_interface *iface, int type)
{
struct ifnet *ifp;
usb_error_t uerr;
struct sysctl_ctx_list *sctx;
struct sysctl_oid *soid;
unsigned int devunit;
uerr = usbd_transfer_setup(sc->sc_udev,
&iface->idesc->bInterfaceNumber, sc->sc_if_xfer,
uhso_ifnet_config, UHSO_IFNET_MAX, sc, &sc->sc_mtx);
if (uerr) {
UHSO_DPRINTF(0, "usbd_transfer_setup failed: %s\n",
usbd_errstr(uerr));
return (-1);
}
sc->sc_ifp = ifp = if_alloc(IFT_OTHER);
if (sc->sc_ifp == NULL) {
device_printf(sc->sc_dev, "if_alloc() failed\n");
return (-1);
}
callout_init_mtx(&sc->sc_c, &sc->sc_mtx, 0);
mtx_lock(&sc->sc_mtx);
callout_reset(&sc->sc_c, 1, uhso_if_rxflush, sc);
mtx_unlock(&sc->sc_mtx);
/*
* We create our own unit numbers for ifnet devices because the
* USB interface unit numbers can be at arbitrary positions yielding
* odd looking device names.
*/
devunit = alloc_unr(uhso_ifnet_unit);
if_initname(ifp, device_get_name(sc->sc_dev), devunit);
ifp->if_mtu = UHSO_MAX_MTU;
ifp->if_ioctl = uhso_if_ioctl;
ifp->if_init = uhso_if_init;
ifp->if_start = uhso_if_start;
ifp->if_output = uhso_if_output;
ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_NOARP;
ifp->if_softc = sc;
IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
IFQ_SET_READY(&ifp->if_snd);
if_attach(ifp);
bpfattach(ifp, DLT_RAW, 0);
sctx = device_get_sysctl_ctx(sc->sc_dev);
soid = device_get_sysctl_tree(sc->sc_dev);
/* Unlocked read... */
SYSCTL_ADD_STRING(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "netif",
CTLFLAG_RD, ifp->if_xname, 0, "Attached network interface");
return (0);
}