sys/dev/usbmisc/ubt/ubt.c
int
ubt_enable(struct device *self)
{
	struct ubt_softc *sc = device_get_softc(self);
	usbd_status err;
	int i, error;

	DPRINTFN(1, "%s: sc=%p\n", __func__, sc);

	if (sc->sc_enabled)
		return 0;

	crit_enter();

	/* Events */
	sc->sc_evt_buf = kmalloc(UBT_BUFSIZ_EVENT, M_USBDEV, M_NOWAIT);
	if (sc->sc_evt_buf == NULL) {
		error = ENOMEM;
		goto bad;
	}

	err = usbd_open_pipe_intr(sc->sc_iface0,
				  sc->sc_evt_addr,
				  USBD_SHORT_XFER_OK,
				  &sc->sc_evt_pipe,
				  sc,
				  sc->sc_evt_buf,
				  UBT_BUFSIZ_EVENT,
				  ubt_recv_event,
				  UBT_INTR_TIMEOUT);
	if (err != USBD_NORMAL_COMPLETION) {
		error = EIO;
		kprintf("can't open events pipe_intr\n");
		goto bad;
	}

	/* Commands */
	sc->sc_cmd_xfer = usbd_alloc_xfer(sc->sc_udev);
	if (sc->sc_cmd_xfer == NULL) {
		kprintf("can't allocate cmd_xfer\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_cmd_buf = usbd_alloc_buffer(sc->sc_cmd_xfer, UBT_BUFSIZ_CMD);
	if (sc->sc_cmd_buf == NULL) {
		kprintf("can't allocate cmd_buf\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_cmd_busy = 0;

	/* ACL read */
	err = usbd_open_pipe(sc->sc_iface0, sc->sc_aclrd_addr,
				USBD_EXCLUSIVE_USE, &sc->sc_aclrd_pipe);
	if (err != USBD_NORMAL_COMPLETION) {
		kprintf("can't open aclrd pipe\n");
		error = EIO;
		goto bad;
	}
	sc->sc_aclrd_xfer = usbd_alloc_xfer(sc->sc_udev);
	if (sc->sc_aclrd_xfer == NULL) {
		kprintf("can't allocate aclrd_xfer\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_aclrd_buf = usbd_alloc_buffer(sc->sc_aclrd_xfer, UBT_BUFSIZ_ACL);
	if (sc->sc_aclrd_buf == NULL) {
		kprintf("can't allocate aclrd_buf\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_aclrd_busy = 0;
	ubt_recv_acl_start(sc);

	/* ACL write */
	err = usbd_open_pipe(sc->sc_iface0, sc->sc_aclwr_addr,
				USBD_EXCLUSIVE_USE, &sc->sc_aclwr_pipe);
	if (err != USBD_NORMAL_COMPLETION) {
		kprintf("can't open aclwr pipe\n");
		error = EIO;
		goto bad;
	}
	sc->sc_aclwr_xfer = usbd_alloc_xfer(sc->sc_udev);
	if (sc->sc_aclwr_xfer == NULL) {
		kprintf("can't allocate aclwr_xfer\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_aclwr_buf = usbd_alloc_buffer(sc->sc_aclwr_xfer, UBT_BUFSIZ_ACL);
	if (sc->sc_aclwr_buf == NULL) {
		kprintf("can't allocate aclwr_buf\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_aclwr_busy = 0;

	/* SCO read */
	if (sc->sc_scord_size > 0) {
		err = usbd_open_pipe(sc->sc_iface1, sc->sc_scord_addr,
					USBD_EXCLUSIVE_USE, &sc->sc_scord_pipe);
		if (err != USBD_NORMAL_COMPLETION) {
			error = EIO;
			goto bad;
		}

		for (i = 0 ; i < UBT_NXFERS ; i++) {
			sc->sc_scord[i].xfer = usbd_alloc_xfer(sc->sc_udev);
			if (sc->sc_scord[i].xfer == NULL) {
				error = ENOMEM;
				goto bad;
			}
			sc->sc_scord[i].buf = usbd_alloc_buffer(sc->sc_scord[i].xfer,
						sc->sc_scord_size * UBT_NFRAMES);
			if (sc->sc_scord[i].buf == NULL) {
				error = ENOMEM;
				goto bad;
			}
			sc->sc_scord[i].softc = sc;
			sc->sc_scord[i].busy = 0;
			ubt_recv_sco_start1(sc, &sc->sc_scord[i]);
		}
	}

	/* SCO write */
	if (sc->sc_scowr_size > 0) {
		err = usbd_open_pipe(sc->sc_iface1, sc->sc_scowr_addr,
					USBD_EXCLUSIVE_USE, &sc->sc_scowr_pipe);
		if (err != USBD_NORMAL_COMPLETION) {
			error = EIO;
			goto bad;
		}

		for (i = 0 ; i < UBT_NXFERS ; i++) {
			sc->sc_scowr[i].xfer = usbd_alloc_xfer(sc->sc_udev);
			if (sc->sc_scowr[i].xfer == NULL) {
				error = ENOMEM;
				goto bad;
			}
			sc->sc_scowr[i].buf = usbd_alloc_buffer(sc->sc_scowr[i].xfer,
						sc->sc_scowr_size * UBT_NFRAMES);
			if (sc->sc_scowr[i].buf == NULL) {
				error = ENOMEM;
				goto bad;
			}
			sc->sc_scowr[i].softc = sc;
			sc->sc_scowr[i].busy = 0;
		}

		sc->sc_scowr_busy = 0;
	}

	sc->sc_enabled = 1;
	crit_exit();
	return 0;

bad:
	ubt_abortdealloc(sc);
	crit_exit();
	return error;
}
/*******************************************************************************
 *
 * Bluetooth Unit/USB callbacks
 *
 * All of this will be called at the IPL_ we specified above
 */
Bluetooth Unit/USB callbacks
All of this will be called at the IPL_ we specified above
Bluetooth Unit / USB callbacks All of this will be called at the IPL_ we specified above
int
ubt_enable(struct device *self)
{
	struct ubt_softc *sc = device_get_softc(self);
	usbd_status err;
	int i, error;
	DPRINTFN(1, "%s: sc=%p\n", __func__, sc);
	if (sc->sc_enabled)
		return 0;
	crit_enter();
	sc->sc_evt_buf = kmalloc(UBT_BUFSIZ_EVENT, M_USBDEV, M_NOWAIT);
	if (sc->sc_evt_buf == NULL) {
		error = ENOMEM;
		goto bad;
	}
	err = usbd_open_pipe_intr(sc->sc_iface0,
				  sc->sc_evt_addr,
				  USBD_SHORT_XFER_OK,
				  &sc->sc_evt_pipe,
				  sc,
				  sc->sc_evt_buf,
				  UBT_BUFSIZ_EVENT,
				  ubt_recv_event,
				  UBT_INTR_TIMEOUT);
	if (err != USBD_NORMAL_COMPLETION) {
		error = EIO;
		kprintf("can't open events pipe_intr\n");
		goto bad;
	}
	sc->sc_cmd_xfer = usbd_alloc_xfer(sc->sc_udev);
	if (sc->sc_cmd_xfer == NULL) {
		kprintf("can't allocate cmd_xfer\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_cmd_buf = usbd_alloc_buffer(sc->sc_cmd_xfer, UBT_BUFSIZ_CMD);
	if (sc->sc_cmd_buf == NULL) {
		kprintf("can't allocate cmd_buf\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_cmd_busy = 0;
	err = usbd_open_pipe(sc->sc_iface0, sc->sc_aclrd_addr,
				USBD_EXCLUSIVE_USE, &sc->sc_aclrd_pipe);
	if (err != USBD_NORMAL_COMPLETION) {
		kprintf("can't open aclrd pipe\n");
		error = EIO;
		goto bad;
	}
	sc->sc_aclrd_xfer = usbd_alloc_xfer(sc->sc_udev);
	if (sc->sc_aclrd_xfer == NULL) {
		kprintf("can't allocate aclrd_xfer\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_aclrd_buf = usbd_alloc_buffer(sc->sc_aclrd_xfer, UBT_BUFSIZ_ACL);
	if (sc->sc_aclrd_buf == NULL) {
		kprintf("can't allocate aclrd_buf\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_aclrd_busy = 0;
	ubt_recv_acl_start(sc);
	err = usbd_open_pipe(sc->sc_iface0, sc->sc_aclwr_addr,
				USBD_EXCLUSIVE_USE, &sc->sc_aclwr_pipe);
	if (err != USBD_NORMAL_COMPLETION) {
		kprintf("can't open aclwr pipe\n");
		error = EIO;
		goto bad;
	}
	sc->sc_aclwr_xfer = usbd_alloc_xfer(sc->sc_udev);
	if (sc->sc_aclwr_xfer == NULL) {
		kprintf("can't allocate aclwr_xfer\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_aclwr_buf = usbd_alloc_buffer(sc->sc_aclwr_xfer, UBT_BUFSIZ_ACL);
	if (sc->sc_aclwr_buf == NULL) {
		kprintf("can't allocate aclwr_buf\n");
		error = ENOMEM;
		goto bad;
	}
	sc->sc_aclwr_busy = 0;
	if (sc->sc_scord_size > 0) {
		err = usbd_open_pipe(sc->sc_iface1, sc->sc_scord_addr,
					USBD_EXCLUSIVE_USE, &sc->sc_scord_pipe);
		if (err != USBD_NORMAL_COMPLETION) {
			error = EIO;
			goto bad;
		}
		for (i = 0 ; i < UBT_NXFERS ; i++) {
			sc->sc_scord[i].xfer = usbd_alloc_xfer(sc->sc_udev);
			if (sc->sc_scord[i].xfer == NULL) {
				error = ENOMEM;
				goto bad;
			}
			sc->sc_scord[i].buf = usbd_alloc_buffer(sc->sc_scord[i].xfer,
						sc->sc_scord_size * UBT_NFRAMES);
			if (sc->sc_scord[i].buf == NULL) {
				error = ENOMEM;
				goto bad;
			}
			sc->sc_scord[i].softc = sc;
			sc->sc_scord[i].busy = 0;
			ubt_recv_sco_start1(sc, &sc->sc_scord[i]);
		}
	}
	if (sc->sc_scowr_size > 0) {
		err = usbd_open_pipe(sc->sc_iface1, sc->sc_scowr_addr,
					USBD_EXCLUSIVE_USE, &sc->sc_scowr_pipe);
		if (err != USBD_NORMAL_COMPLETION) {
			error = EIO;
			goto bad;
		}
		for (i = 0 ; i < UBT_NXFERS ; i++) {
			sc->sc_scowr[i].xfer = usbd_alloc_xfer(sc->sc_udev);
			if (sc->sc_scowr[i].xfer == NULL) {
				error = ENOMEM;
				goto bad;
			}
			sc->sc_scowr[i].buf = usbd_alloc_buffer(sc->sc_scowr[i].xfer,
						sc->sc_scowr_size * UBT_NFRAMES);
			if (sc->sc_scowr[i].buf == NULL) {
				error = ENOMEM;
				goto bad;
			}
			sc->sc_scowr[i].softc = sc;
			sc->sc_scowr[i].busy = 0;
		}
		sc->sc_scowr_busy = 0;
	}
	sc->sc_enabled = 1;
	crit_exit();
	return 0;
bad:
	ubt_abortdealloc(sc);
	crit_exit();
	return error;
}
int ubt_enable ( struct device * self ) { struct ubt_softc * sc = device_get_softc ( self ) ; usbd_status err ; int i , error ; DPRINTFN ( 1 , " \n " , __func__ , sc ) ; if ( sc -> sc_enabled ) return 0 ; crit_enter ( ) ; sc -> sc_evt_buf = kmalloc ( UBT_BUFSIZ_EVENT , M_USBDEV , M_NOWAIT ) ; if ( sc -> sc_evt_buf == NULL ) { error = ENOMEM ; goto bad ; } err = usbd_open_pipe_intr ( sc -> sc_iface0 , sc -> sc_evt_addr , USBD_SHORT_XFER_OK , & sc -> sc_evt_pipe , sc , sc -> sc_evt_buf , UBT_BUFSIZ_EVENT , ubt_recv_event , UBT_INTR_TIMEOUT ) ; if ( err != USBD_NORMAL_COMPLETION ) { error = EIO ; kprintf ( " \n " ) ; goto bad ; } sc -> sc_cmd_xfer = usbd_alloc_xfer ( sc -> sc_udev ) ; if ( sc -> sc_cmd_xfer == NULL ) { kprintf ( " \n " ) ; error = ENOMEM ; goto bad ; } sc -> sc_cmd_buf = usbd_alloc_buffer ( sc -> sc_cmd_xfer , UBT_BUFSIZ_CMD ) ; if ( sc -> sc_cmd_buf == NULL ) { kprintf ( " \n " ) ; error = ENOMEM ; goto bad ; } sc -> sc_cmd_busy = 0 ; err = usbd_open_pipe ( sc -> sc_iface0 , sc -> sc_aclrd_addr , USBD_EXCLUSIVE_USE , & sc -> sc_aclrd_pipe ) ; if ( err != USBD_NORMAL_COMPLETION ) { kprintf ( " \n " ) ; error = EIO ; goto bad ; } sc -> sc_aclrd_xfer = usbd_alloc_xfer ( sc -> sc_udev ) ; if ( sc -> sc_aclrd_xfer == NULL ) { kprintf ( " \n " ) ; error = ENOMEM ; goto bad ; } sc -> sc_aclrd_buf = usbd_alloc_buffer ( sc -> sc_aclrd_xfer , UBT_BUFSIZ_ACL ) ; if ( sc -> sc_aclrd_buf == NULL ) { kprintf ( " \n " ) ; error = ENOMEM ; goto bad ; } sc -> sc_aclrd_busy = 0 ; ubt_recv_acl_start ( sc ) ; err = usbd_open_pipe ( sc -> sc_iface0 , sc -> sc_aclwr_addr , USBD_EXCLUSIVE_USE , & sc -> sc_aclwr_pipe ) ; if ( err != USBD_NORMAL_COMPLETION ) { kprintf ( " \n " ) ; error = EIO ; goto bad ; } sc -> sc_aclwr_xfer = usbd_alloc_xfer ( sc -> sc_udev ) ; if ( sc -> sc_aclwr_xfer == NULL ) { kprintf ( " \n " ) ; error = ENOMEM ; goto bad ; } sc -> sc_aclwr_buf = usbd_alloc_buffer ( sc -> sc_aclwr_xfer , UBT_BUFSIZ_ACL ) ; if ( sc -> sc_aclwr_buf == NULL ) { kprintf ( " \n " ) ; error = ENOMEM ; goto bad ; } sc -> sc_aclwr_busy = 0 ; if ( sc -> sc_scord_size > 0 ) { err = usbd_open_pipe ( sc -> sc_iface1 , sc -> sc_scord_addr , USBD_EXCLUSIVE_USE , & sc -> sc_scord_pipe ) ; if ( err != USBD_NORMAL_COMPLETION ) { error = EIO ; goto bad ; } for ( i = 0 ; i < UBT_NXFERS ; i ++ ) { sc -> sc_scord [ i ] . xfer = usbd_alloc_xfer ( sc -> sc_udev ) ; if ( sc -> sc_scord [ i ] . xfer == NULL ) { error = ENOMEM ; goto bad ; } sc -> sc_scord [ i ] . buf = usbd_alloc_buffer ( sc -> sc_scord [ i ] . xfer , sc -> sc_scord_size * UBT_NFRAMES ) ; if ( sc -> sc_scord [ i ] . buf == NULL ) { error = ENOMEM ; goto bad ; } sc -> sc_scord [ i ] . softc = sc ; sc -> sc_scord [ i ] . busy = 0 ; ubt_recv_sco_start1 ( sc , & sc -> sc_scord [ i ] ) ; } } if ( sc -> sc_scowr_size > 0 ) { err = usbd_open_pipe ( sc -> sc_iface1 , sc -> sc_scowr_addr , USBD_EXCLUSIVE_USE , & sc -> sc_scowr_pipe ) ; if ( err != USBD_NORMAL_COMPLETION ) { error = EIO ; goto bad ; } for ( i = 0 ; i < UBT_NXFERS ; i ++ ) { sc -> sc_scowr [ i ] . xfer = usbd_alloc_xfer ( sc -> sc_udev ) ; if ( sc -> sc_scowr [ i ] . xfer == NULL ) { error = ENOMEM ; goto bad ; } sc -> sc_scowr [ i ] . buf = usbd_alloc_buffer ( sc -> sc_scowr [ i ] . xfer , sc -> sc_scowr_size * UBT_NFRAMES ) ; if ( sc -> sc_scowr [ i ] . buf == NULL ) { error = ENOMEM ; goto bad ; } sc -> sc_scowr [ i ] . softc = sc ; sc -> sc_scowr [ i ] . busy = 0 ; } sc -> sc_scowr_busy = 0 ; } sc -> sc_enabled = 1 ; crit_exit ( ) ; return 0 ; bad : ubt_abortdealloc ( sc ) ; crit_exit ( ) ; return error ; }
Bluetooth Unit/USB callbacks
 All of this will be called at the IPL_ we specified above
Bluetooth Unit / USB callbacks All of this will be called at the IPL_ we specified above
/* Events */ /* Commands */ /* ACL read */ /* ACL write */ /* SCO read */ /* SCO write */