17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*112116d8Sfb  * Common Development and Distribution License (the "License").
6*112116d8Sfb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  *
21*112116d8Sfb  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
227c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * scsa2usb_ms_cbi.c:
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * This file implements USB Mass Storage Class
307c478bd9Sstevel@tonic-gate  * Control Bulk Interrupt (CB/CBI) transport v1.0
317c478bd9Sstevel@tonic-gate  * http://www.usb.org/developers/data/devclass/usbmass-cbi10.pdf
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usbai_version.h>
347c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi.h>
357c478bd9Sstevel@tonic-gate #include <sys/callb.h>		/* needed by scsa2usb.h */
367c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h>
397c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_private.h>
407c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_ugen.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <sys/usb/clients/mass_storage/usb_cbi.h>
437c478bd9Sstevel@tonic-gate #include <sys/usb/scsa2usb/scsa2usb.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Function Prototypes
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate int		scsa2usb_cbi_transport(scsa2usb_state_t *, scsa2usb_cmd_t *);
497c478bd9Sstevel@tonic-gate static int	scsa2usb_handle_cbi_status(usb_intr_req_t *);
507c478bd9Sstevel@tonic-gate static void	scsa2usb_cbi_reset_recovery(scsa2usb_state_t *);
517c478bd9Sstevel@tonic-gate static void	scsa2usb_cbi_handle_error(scsa2usb_state_t *, int, usb_cr_t);
527c478bd9Sstevel@tonic-gate static usb_intr_req_t *scsa2usb_cbi_start_intr_polling(scsa2usb_state_t *);
537c478bd9Sstevel@tonic-gate void		scsa2usb_cbi_stop_intr_polling(scsa2usb_state_t *);
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /* extern functions */
567c478bd9Sstevel@tonic-gate extern void	scsa2usb_setup_next_xfer(scsa2usb_state_t *, scsa2usb_cmd_t *);
577c478bd9Sstevel@tonic-gate extern int	scsa2usb_handle_data_start(scsa2usb_state_t *,
587c478bd9Sstevel@tonic-gate 		    scsa2usb_cmd_t *, usb_bulk_req_t *);
597c478bd9Sstevel@tonic-gate extern void	scsa2usb_handle_data_done(scsa2usb_state_t *, scsa2usb_cmd_t *,
607c478bd9Sstevel@tonic-gate 		    usb_bulk_req_t *);
617c478bd9Sstevel@tonic-gate extern usb_bulk_req_t *scsa2usb_init_bulk_req(scsa2usb_state_t *,
627c478bd9Sstevel@tonic-gate 			    size_t, uint_t, usb_req_attrs_t, usb_flags_t);
637c478bd9Sstevel@tonic-gate extern int	scsa2usb_clear_ept_stall(scsa2usb_state_t *, uint_t,
647c478bd9Sstevel@tonic-gate 		    usb_pipe_handle_t, char *);
657c478bd9Sstevel@tonic-gate extern void	scsa2usb_close_usb_pipes(scsa2usb_state_t *);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #ifdef DEBUG	/* debugging information */
687c478bd9Sstevel@tonic-gate extern void	scsa2usb_print_cdb(scsa2usb_state_t *, scsa2usb_cmd_t *);
697c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * scsa2usb_cbi_transport:
747c478bd9Sstevel@tonic-gate  *	Implements the CB/CBI state machine by these steps:
757c478bd9Sstevel@tonic-gate  *	a) Issues command to the device over control pipe.
767c478bd9Sstevel@tonic-gate  *	b) Start Data Phase if applicable
777c478bd9Sstevel@tonic-gate  *	c) Start Status Phase
787c478bd9Sstevel@tonic-gate  *
797c478bd9Sstevel@tonic-gate  *	returns TRAN_* values and not USB_SUCCESS/FAILURE
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  * scsa2usb_cbi_transport() handles the normal transitions or
827c478bd9Sstevel@tonic-gate  * continuation after clearing stalls or error recovery.
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  * Command Phase:
857c478bd9Sstevel@tonic-gate  *	prepare a valid command and transport it on default pipe
867c478bd9Sstevel@tonic-gate  *	if error on default-pipe:
877c478bd9Sstevel@tonic-gate  *		set pkt_reason to CMD_TRAN_ERR
887c478bd9Sstevel@tonic-gate  *		new pkt state is SCSA2USB_PKT_DO_COMP
897c478bd9Sstevel@tonic-gate  *		do reset recovery synchronously
907c478bd9Sstevel@tonic-gate  *	else
917c478bd9Sstevel@tonic-gate  *		proceed to data phase
927c478bd9Sstevel@tonic-gate  *
937c478bd9Sstevel@tonic-gate  * Data Phase:
947c478bd9Sstevel@tonic-gate  *	if data in:
957c478bd9Sstevel@tonic-gate  *		setup data in on bulkin
967c478bd9Sstevel@tonic-gate  *	else if data out:
977c478bd9Sstevel@tonic-gate  *		setup data out on bulkout
987c478bd9Sstevel@tonic-gate  *
997c478bd9Sstevel@tonic-gate  *	data: (in)
1007c478bd9Sstevel@tonic-gate  *		copy data transferred so far, no more data to transfer
1017c478bd9Sstevel@tonic-gate  *
1027c478bd9Sstevel@tonic-gate  *		if stall on bulkin pipe
1037c478bd9Sstevel@tonic-gate  *			terminate data transfers, set cmd_done
1047c478bd9Sstevel@tonic-gate  *			clear stall on bulkin syncrhonously
1057c478bd9Sstevel@tonic-gate  *		else if other exception
1067c478bd9Sstevel@tonic-gate  *			set pkt_reason to CMD_TRAN_ERR
1077c478bd9Sstevel@tonic-gate  *			new pkt state is SCSA2USB_PKT_DO_COMP
1087c478bd9Sstevel@tonic-gate  *			do reset recovery synchronously
1097c478bd9Sstevel@tonic-gate  *		else (no error)
1107c478bd9Sstevel@tonic-gate  *			receive status
1117c478bd9Sstevel@tonic-gate  *
1127c478bd9Sstevel@tonic-gate  *	 data: (out)
1137c478bd9Sstevel@tonic-gate  *		if stall on bulkout pipe
1147c478bd9Sstevel@tonic-gate  *			terminate data transfers
1157c478bd9Sstevel@tonic-gate  *			clear stall on bulkout synchronously USBA
1167c478bd9Sstevel@tonic-gate  *		else if other exception
1177c478bd9Sstevel@tonic-gate  *			set pkt_reason to CMD_TRAN_ERR
1187c478bd9Sstevel@tonic-gate  *			new pkt state is SCSA2USB_PKT_DO_COMP
1197c478bd9Sstevel@tonic-gate  *			do reset recovery synchronously
1207c478bd9Sstevel@tonic-gate  *		else (no error)
1217c478bd9Sstevel@tonic-gate  *			receive status
1227c478bd9Sstevel@tonic-gate  *
1237c478bd9Sstevel@tonic-gate  * Status Phase: (on Interrupt pipe for CBI devices only)
1247c478bd9Sstevel@tonic-gate  *	if error
1257c478bd9Sstevel@tonic-gate  *		if stall
1267c478bd9Sstevel@tonic-gate  *			new pkt state is SCSA2USB_PKT_DO_COMP
1277c478bd9Sstevel@tonic-gate  *			clear stall on interrupt pipe
1287c478bd9Sstevel@tonic-gate  *		else
1297c478bd9Sstevel@tonic-gate  *			set pkt_reason to CMD_TRAN_ERR
1307c478bd9Sstevel@tonic-gate  *			new pkt state is SCSA2USB_PKT_DO_COMP
1317c478bd9Sstevel@tonic-gate  *			do reset recovery synchronously
1327c478bd9Sstevel@tonic-gate  *	else (no error)
1337c478bd9Sstevel@tonic-gate  *		goto read status
1347c478bd9Sstevel@tonic-gate  *
1357c478bd9Sstevel@tonic-gate  * read status:
1367c478bd9Sstevel@tonic-gate  *	if not OK or phase error
1377c478bd9Sstevel@tonic-gate  *		new pkt state is SCSA2USB_PKT_DO_COMP
1387c478bd9Sstevel@tonic-gate  *		set pkt reason CMD_TRAN_ERR
1397c478bd9Sstevel@tonic-gate  *		reset recovery synchronously
1407c478bd9Sstevel@tonic-gate  *	else (status ok)
1417c478bd9Sstevel@tonic-gate  *		goto  SCSA2USB_PKT_DO_COMP
1427c478bd9Sstevel@tonic-gate  *
1437c478bd9Sstevel@tonic-gate  * The reset recovery walks sequentially thru device reset, clearing
1447c478bd9Sstevel@tonic-gate  * stalls and pipe resets. When the reset recovery completes we return
1457c478bd9Sstevel@tonic-gate  * to the taskq thread.
1467c478bd9Sstevel@tonic-gate  *
1477c478bd9Sstevel@tonic-gate  * Clearing stalls clears the stall condition, resets the pipe, and
1487c478bd9Sstevel@tonic-gate  * then returns to the transport.
1497c478bd9Sstevel@tonic-gate  */
1507c478bd9Sstevel@tonic-gate int
scsa2usb_cbi_transport(scsa2usb_state_t * scsa2usbp,scsa2usb_cmd_t * cmd)1517c478bd9Sstevel@tonic-gate scsa2usb_cbi_transport(scsa2usb_state_t *scsa2usbp, scsa2usb_cmd_t *cmd)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate 	int			i, rval = TRAN_ACCEPT;
1547c478bd9Sstevel@tonic-gate 	mblk_t			*data;
1557c478bd9Sstevel@tonic-gate 	usb_cr_t		completion_reason;
1567c478bd9Sstevel@tonic-gate 	usb_cb_flags_t		cb_flags;
1577c478bd9Sstevel@tonic-gate 	usb_bulk_req_t		*data_req;
1587c478bd9Sstevel@tonic-gate 	usb_intr_req_t		*status_req;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
161*112116d8Sfb 	    "scsa2usb_cbi_transport: cmd = 0x%p", (void *)cmd);
1627c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(&scsa2usbp->scsa2usb_mutex));
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate Cmd_Phase:
1657c478bd9Sstevel@tonic-gate 	if (!(SCSA2USB_DEVICE_ACCESS_OK(scsa2usbp))) {
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 		return (TRAN_FATAL_ERROR);
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/*
1717c478bd9Sstevel@tonic-gate 	 * Start command phase (C - in CBI)
1727c478bd9Sstevel@tonic-gate 	 */
1737c478bd9Sstevel@tonic-gate 	data = allocb_wait(CBI_CLASS_CMD_LEN, BPRI_LO, STR_NOSIG, NULL);
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/* Initialize the data */
1767c478bd9Sstevel@tonic-gate 	for (i = 0; i < CBI_CLASS_CMD_LEN; i++) {
1777c478bd9Sstevel@tonic-gate 		*data->b_wptr++ = cmd->cmd_cdb[i];
1787c478bd9Sstevel@tonic-gate 	}
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	SCSA2USB_PRINT_CDB(scsa2usbp, cmd);	/* print the CDB */
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	/* Send the Command to the device */
1837c478bd9Sstevel@tonic-gate 	mutex_exit(&scsa2usbp->scsa2usb_mutex);
1847c478bd9Sstevel@tonic-gate 	rval = usb_pipe_sync_ctrl_xfer(scsa2usbp->scsa2usb_dip,
1857c478bd9Sstevel@tonic-gate 	    scsa2usbp->scsa2usb_default_pipe,
1867c478bd9Sstevel@tonic-gate 	    CBI_REQUEST_TYPE,			/* bmRequestType */
1877c478bd9Sstevel@tonic-gate 	    0,					/* bRequest */
1887c478bd9Sstevel@tonic-gate 	    CBI_WVALUE,				/* wValue */
1897c478bd9Sstevel@tonic-gate 	    scsa2usbp->scsa2usb_intfc_num,	/* wIndex */
1907c478bd9Sstevel@tonic-gate 	    CBI_CLASS_CMD_LEN,			/* wLength */
1917c478bd9Sstevel@tonic-gate 	    &data,				/* data */
1927c478bd9Sstevel@tonic-gate 	    USB_ATTRS_PIPE_RESET,		/* attributes */
1937c478bd9Sstevel@tonic-gate 	    &completion_reason, &cb_flags, USB_FLAGS_SLEEP);
1947c478bd9Sstevel@tonic-gate 	mutex_enter(&scsa2usbp->scsa2usb_mutex);
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L2(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
1977c478bd9Sstevel@tonic-gate 	    "scsa2usb_cbi_transport: sent cmd = 0x%x  rval = %d",
1987c478bd9Sstevel@tonic-gate 	    cmd->cmd_cdb[SCSA2USB_OPCODE], rval);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	SCSA2USB_FREE_MSG(data);	/* get rid of the data */
2017c478bd9Sstevel@tonic-gate 	if (rval != USB_SUCCESS) {
2027c478bd9Sstevel@tonic-gate 		scsa2usb_cbi_handle_error(scsa2usbp, rval, completion_reason);
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 		return (TRAN_FATAL_ERROR);
2057c478bd9Sstevel@tonic-gate 	}
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	/*
2087c478bd9Sstevel@tonic-gate 	 * Xferred command to the device.
2097c478bd9Sstevel@tonic-gate 	 * Start data phase (B - in CBI)
2107c478bd9Sstevel@tonic-gate 	 */
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	/*
2137c478bd9Sstevel@tonic-gate 	 * we've not transferred any data yet; updated in
2147c478bd9Sstevel@tonic-gate 	 * scsa2usb_handle_data_done
2157c478bd9Sstevel@tonic-gate 	 */
2167c478bd9Sstevel@tonic-gate 	cmd->cmd_resid_xfercount = 0;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/* if data to be xferred ? */
2197c478bd9Sstevel@tonic-gate 	if (cmd->cmd_xfercount) {
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 		/* Initialize a bulk_req_t */
2227c478bd9Sstevel@tonic-gate 		data_req = scsa2usb_init_bulk_req(scsa2usbp, 0,
2237c478bd9Sstevel@tonic-gate 		    cmd->cmd_timeout, USB_ATTRS_PIPE_RESET, USB_FLAGS_SLEEP);
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 		/* start I/O to/from the device */
2267c478bd9Sstevel@tonic-gate 		rval = scsa2usb_handle_data_start(scsa2usbp, cmd,
227*112116d8Sfb 		    data_req);
2287c478bd9Sstevel@tonic-gate 		/* handle data returned */
2297c478bd9Sstevel@tonic-gate 		scsa2usb_handle_data_done(scsa2usbp, cmd,
230*112116d8Sfb 		    data_req);
2317c478bd9Sstevel@tonic-gate 		if (rval != USB_SUCCESS) {
2327c478bd9Sstevel@tonic-gate 			/*
2337c478bd9Sstevel@tonic-gate 			 * we ran into an error and it wasn't a STALL
2347c478bd9Sstevel@tonic-gate 			 */
2357c478bd9Sstevel@tonic-gate 			if (data_req->bulk_completion_reason == USB_CR_STALL) {
2367c478bd9Sstevel@tonic-gate 				if (scsa2usbp->scsa2usb_cur_pkt) {
2377c478bd9Sstevel@tonic-gate 					scsa2usbp->scsa2usb_cur_pkt->
238*112116d8Sfb 					    pkt_reason = CMD_TRAN_ERR;
2397c478bd9Sstevel@tonic-gate 				}
2407c478bd9Sstevel@tonic-gate 			} else {
2417c478bd9Sstevel@tonic-gate 				scsa2usb_cbi_handle_error(scsa2usbp,
2427c478bd9Sstevel@tonic-gate 				    rval, data_req->bulk_completion_reason);
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 				/* get rid of req */
2457c478bd9Sstevel@tonic-gate 				SCSA2USB_FREE_BULK_REQ(data_req);
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 				return (TRAN_FATAL_ERROR);
2487c478bd9Sstevel@tonic-gate 			}
2497c478bd9Sstevel@tonic-gate 		}
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 		SCSA2USB_FREE_BULK_REQ(data_req); /* get rid of bulk_req */
2527c478bd9Sstevel@tonic-gate 	}
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	/* CB devices don't do status over interrupt pipe */
2557c478bd9Sstevel@tonic-gate 	if (SCSA2USB_IS_CB(scsa2usbp)) {
2567c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
2577c478bd9Sstevel@tonic-gate 		    "scsa2usb_cbi_transport: CB done rval = %d", rval);
2587c478bd9Sstevel@tonic-gate 		goto end_it;
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	/*
2627c478bd9Sstevel@tonic-gate 	 * Start status phase (I - in CBI)
2637c478bd9Sstevel@tonic-gate 	 */
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 	/* Get Status over interrupt pipe */
2667c478bd9Sstevel@tonic-gate 	if ((status_req = scsa2usb_cbi_start_intr_polling(scsa2usbp)) == NULL) {
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 		return (TRAN_FATAL_ERROR); /* lack of better return code */
2697c478bd9Sstevel@tonic-gate 	}
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	rval = scsa2usb_handle_cbi_status(status_req);
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	usb_free_intr_req(status_req);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	/* stop interrupt pipe polling (CBI only) */
2767c478bd9Sstevel@tonic-gate 	if (SCSA2USB_IS_CBI(scsa2usbp)) {
2777c478bd9Sstevel@tonic-gate 		scsa2usb_cbi_stop_intr_polling(scsa2usbp);
2787c478bd9Sstevel@tonic-gate 	}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate end_it:
2817c478bd9Sstevel@tonic-gate 	if ((rval == USB_SUCCESS) &&		/* CSW was ok */
2827c478bd9Sstevel@tonic-gate 	    (scsa2usbp->scsa2usb_cur_pkt->pkt_reason == CMD_CMPLT) &&
2837c478bd9Sstevel@tonic-gate 	    (cmd->cmd_xfercount != 0) &&	/* more data to xfer */
2847c478bd9Sstevel@tonic-gate 	    !cmd->cmd_done) {			/* we aren't done yet */
2857c478bd9Sstevel@tonic-gate 		scsa2usb_setup_next_xfer(scsa2usbp, cmd);
2867c478bd9Sstevel@tonic-gate 		goto Cmd_Phase;
2877c478bd9Sstevel@tonic-gate 	} else {
2887c478bd9Sstevel@tonic-gate 		if (SCSA2USB_IS_CB(scsa2usbp)) {
2897c478bd9Sstevel@tonic-gate 			cmd->cmd_done = 1;
2907c478bd9Sstevel@tonic-gate 			SCSA2USB_SET_PKT_DO_COMP_STATE(scsa2usbp);
2917c478bd9Sstevel@tonic-gate 		}
2927c478bd9Sstevel@tonic-gate 	}
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	return (rval == USB_SUCCESS ? TRAN_ACCEPT : TRAN_FATAL_ERROR);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate  * scsa2usb_cbi_handle_error:
3007c478bd9Sstevel@tonic-gate  *	handle errors from transport that are not STALL conditions
3017c478bd9Sstevel@tonic-gate  */
3027c478bd9Sstevel@tonic-gate static void
scsa2usb_cbi_handle_error(scsa2usb_state_t * scsa2usbp,int rval,usb_cr_t cr)3037c478bd9Sstevel@tonic-gate scsa2usb_cbi_handle_error(scsa2usb_state_t *scsa2usbp, int rval, usb_cr_t cr)
3047c478bd9Sstevel@tonic-gate {
3057c478bd9Sstevel@tonic-gate 	struct scsi_pkt	*pkt = scsa2usbp->scsa2usb_cur_pkt;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
3087c478bd9Sstevel@tonic-gate 	    "scsa2usb_cbi_handle_error: data error %d cr = %d", rval, cr);
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	SCSA2USB_SET_PKT_DO_COMP_STATE(scsa2usbp);
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	/* do reset error recovery */
3137c478bd9Sstevel@tonic-gate 	switch (cr) {
3147c478bd9Sstevel@tonic-gate 	case USB_CR_STALL:
3157c478bd9Sstevel@tonic-gate 		if (pkt) {
3167c478bd9Sstevel@tonic-gate 			pkt->pkt_reason = CMD_TRAN_ERR;
3177c478bd9Sstevel@tonic-gate 			*(pkt->pkt_scbp) = STATUS_CHECK;
3187c478bd9Sstevel@tonic-gate 		}
3197c478bd9Sstevel@tonic-gate 		break;
3207c478bd9Sstevel@tonic-gate 	case USB_CR_TIMEOUT:
3217c478bd9Sstevel@tonic-gate 		if (pkt) {
3227c478bd9Sstevel@tonic-gate 			pkt->pkt_reason = CMD_TIMEOUT;
3237c478bd9Sstevel@tonic-gate 			pkt->pkt_statistics |= STAT_TIMEOUT;
3247c478bd9Sstevel@tonic-gate 		}
3257c478bd9Sstevel@tonic-gate 		break;
3267c478bd9Sstevel@tonic-gate 	case USB_CR_DEV_NOT_RESP:
3277c478bd9Sstevel@tonic-gate 		scsa2usb_cbi_stop_intr_polling(scsa2usbp);
3287c478bd9Sstevel@tonic-gate 		if (pkt) {
3297c478bd9Sstevel@tonic-gate 			pkt->pkt_reason = CMD_DEV_GONE;
3307c478bd9Sstevel@tonic-gate 			/* scsi_poll relies on this */
3317c478bd9Sstevel@tonic-gate 			pkt->pkt_state = STATE_GOT_BUS;
3327c478bd9Sstevel@tonic-gate 		}
3337c478bd9Sstevel@tonic-gate 		break;
3347c478bd9Sstevel@tonic-gate 	default:
3357c478bd9Sstevel@tonic-gate 		if (pkt) {
3367c478bd9Sstevel@tonic-gate 			pkt->pkt_reason = CMD_TRAN_ERR;
3377c478bd9Sstevel@tonic-gate 		}
3387c478bd9Sstevel@tonic-gate 		scsa2usb_cbi_reset_recovery(scsa2usbp);
3397c478bd9Sstevel@tonic-gate 	}
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate /*
3447c478bd9Sstevel@tonic-gate  * scsa2usb_cbi_start_intr_polling:
3457c478bd9Sstevel@tonic-gate  *	start polling asynchronously without notification
3467c478bd9Sstevel@tonic-gate  */
3477c478bd9Sstevel@tonic-gate static usb_intr_req_t *
scsa2usb_cbi_start_intr_polling(scsa2usb_state_t * scsa2usbp)3487c478bd9Sstevel@tonic-gate scsa2usb_cbi_start_intr_polling(scsa2usb_state_t *scsa2usbp)
3497c478bd9Sstevel@tonic-gate {
3507c478bd9Sstevel@tonic-gate 	int rval;
3517c478bd9Sstevel@tonic-gate 	usb_pipe_state_t   pipe_state;
3527c478bd9Sstevel@tonic-gate 	usb_intr_req_t *req = NULL;
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
3557c478bd9Sstevel@tonic-gate 	    "scsa2usb_cbi_start_intr_polling:");
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	if (!SCSA2USB_IS_CBI(scsa2usbp)) {
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 		return (NULL);
3607c478bd9Sstevel@tonic-gate 	}
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	req = usb_alloc_intr_req(scsa2usbp->scsa2usb_dip, 0, USB_FLAGS_SLEEP);
3637c478bd9Sstevel@tonic-gate 	req->intr_client_private = (usb_opaque_t)scsa2usbp;
3647c478bd9Sstevel@tonic-gate 	req->intr_attributes = USB_ATTRS_ONE_XFER | USB_ATTRS_PIPE_RESET |
365*112116d8Sfb 	    USB_ATTRS_SHORT_XFER_OK;
3667c478bd9Sstevel@tonic-gate 	req->intr_len = scsa2usbp->scsa2usb_intr_ept.wMaxPacketSize;
3677c478bd9Sstevel@tonic-gate 	req->intr_timeout = 20;	/* arbitrary large for now */
3687c478bd9Sstevel@tonic-gate 	mutex_exit(&scsa2usbp->scsa2usb_mutex);
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	if ((rval = usb_pipe_intr_xfer(scsa2usbp->scsa2usb_intr_pipe, req,
3717c478bd9Sstevel@tonic-gate 	    USB_FLAGS_SLEEP)) != USB_SUCCESS) {
3727c478bd9Sstevel@tonic-gate 		mutex_enter(&scsa2usbp->scsa2usb_mutex);
3737c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
3747c478bd9Sstevel@tonic-gate 		    "polling failed rval: %d", rval);
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 		/* clear stall */
3777c478bd9Sstevel@tonic-gate 		if (req->intr_completion_reason == USB_CR_STALL) {
3787c478bd9Sstevel@tonic-gate 			(void) scsa2usb_clear_ept_stall(scsa2usbp,
3797c478bd9Sstevel@tonic-gate 			    scsa2usbp->scsa2usb_intr_ept.bEndpointAddress,
3807c478bd9Sstevel@tonic-gate 			    scsa2usbp->scsa2usb_intr_pipe, "intr");
3817c478bd9Sstevel@tonic-gate 		}
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 		/* handle other errors here */
3847c478bd9Sstevel@tonic-gate 		scsa2usb_cbi_handle_error(scsa2usbp, rval,
3857c478bd9Sstevel@tonic-gate 		    req->intr_completion_reason);
3867c478bd9Sstevel@tonic-gate 		mutex_exit(&scsa2usbp->scsa2usb_mutex);
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 		usb_free_intr_req(req);
3897c478bd9Sstevel@tonic-gate 		req = NULL;
3907c478bd9Sstevel@tonic-gate 	}
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	rval = usb_pipe_get_state(scsa2usbp->scsa2usb_intr_pipe,
3937c478bd9Sstevel@tonic-gate 	    &pipe_state, USB_FLAGS_SLEEP);
3947c478bd9Sstevel@tonic-gate 	if (pipe_state != USB_PIPE_STATE_ACTIVE) {
3957c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
3967c478bd9Sstevel@tonic-gate 		    "intr pipes state: %d, rval: %d", pipe_state, rval);
3977c478bd9Sstevel@tonic-gate 	}
3987c478bd9Sstevel@tonic-gate 	mutex_enter(&scsa2usbp->scsa2usb_mutex);
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 	return (req);
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate /*
4057c478bd9Sstevel@tonic-gate  * scsa2usb_cbi_stop_intr_polling:
4067c478bd9Sstevel@tonic-gate  *	Stop polling on interrupt pipe (for status)
4077c478bd9Sstevel@tonic-gate  */
4087c478bd9Sstevel@tonic-gate void
scsa2usb_cbi_stop_intr_polling(scsa2usb_state_t * scsa2usbp)4097c478bd9Sstevel@tonic-gate scsa2usb_cbi_stop_intr_polling(scsa2usb_state_t *scsa2usbp)
4107c478bd9Sstevel@tonic-gate {
4117c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
4127c478bd9Sstevel@tonic-gate 	    "scsa2usb_cbi_stop_intr_polling:");
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(&scsa2usbp->scsa2usb_mutex));
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 	if (!SCSA2USB_IS_CBI(scsa2usbp)) {
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 		return;
4197c478bd9Sstevel@tonic-gate 	}
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 	if (scsa2usbp->scsa2usb_intr_pipe) {
4227c478bd9Sstevel@tonic-gate 		mutex_exit(&scsa2usbp->scsa2usb_mutex);
4237c478bd9Sstevel@tonic-gate 		usb_pipe_stop_intr_polling(scsa2usbp->scsa2usb_intr_pipe,
4247c478bd9Sstevel@tonic-gate 		    USB_FLAGS_SLEEP);
4257c478bd9Sstevel@tonic-gate 		mutex_enter(&scsa2usbp->scsa2usb_mutex);
4267c478bd9Sstevel@tonic-gate 	}
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate /*
4317c478bd9Sstevel@tonic-gate  * scsa2usb_handle_cbi_status:
4327c478bd9Sstevel@tonic-gate  *	Handle CBI status results
4337c478bd9Sstevel@tonic-gate  */
4347c478bd9Sstevel@tonic-gate static int
scsa2usb_handle_cbi_status(usb_intr_req_t * req)4357c478bd9Sstevel@tonic-gate scsa2usb_handle_cbi_status(usb_intr_req_t *req)
4367c478bd9Sstevel@tonic-gate {
4377c478bd9Sstevel@tonic-gate 	int rval = USB_SUCCESS;
4387c478bd9Sstevel@tonic-gate 	int status;
4397c478bd9Sstevel@tonic-gate 	char *msg;
4407c478bd9Sstevel@tonic-gate 	scsa2usb_cmd_t *cmd;
4417c478bd9Sstevel@tonic-gate 	scsa2usb_state_t *scsa2usbp = (scsa2usb_state_t *)
442*112116d8Sfb 	    req->intr_client_private;
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
445*112116d8Sfb 	    "scsa2usb_handle_cbi_status: req: 0x%p", (void *)req);
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(&scsa2usbp->scsa2usb_mutex));
4487c478bd9Sstevel@tonic-gate 	ASSERT(req->intr_data != NULL);
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	cmd = PKT2CMD(scsa2usbp->scsa2usb_cur_pkt);
4517c478bd9Sstevel@tonic-gate 	status = *(req->intr_data->b_rptr + 1) & CBI_STATUS_MASK;
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	/*
4547c478bd9Sstevel@tonic-gate 	 * CBI status contains ASC and ASCQ.
4557c478bd9Sstevel@tonic-gate 	 * SCMD_REQUEST_SENSE and SCMD_INQUIRY don't affect the sense data
4567c478bd9Sstevel@tonic-gate 	 * on CBI devices. So, we can ignore that info for these 2 commands.
4577c478bd9Sstevel@tonic-gate 	 *
4587c478bd9Sstevel@tonic-gate 	 * (See details in UFI spec section 3.5 - that says that INQUIRY,
4597c478bd9Sstevel@tonic-gate 	 * SEND_DIAG, and REQUEST_SENSE ought to be supported by any deivce
4607c478bd9Sstevel@tonic-gate 	 * irrespective).
4617c478bd9Sstevel@tonic-gate 	 */
4627c478bd9Sstevel@tonic-gate 	if ((cmd->cmd_cdb[SCSA2USB_OPCODE] == SCMD_REQUEST_SENSE) ||
4637c478bd9Sstevel@tonic-gate 	    (cmd->cmd_cdb[SCSA2USB_OPCODE] == SCMD_INQUIRY)) {
4647c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
4657c478bd9Sstevel@tonic-gate 		    "scsa2usb_handle_cbi_status: CBI STATUS = (0x%x, 0x%x)",
4667c478bd9Sstevel@tonic-gate 		    *(req->intr_data->b_rptr), *(req->intr_data->b_rptr+1));
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 		SCSA2USB_SET_PKT_DO_COMP_STATE(scsa2usbp);
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 		return (USB_SUCCESS);
4717c478bd9Sstevel@tonic-gate 	}
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 	switch (status) {
4747c478bd9Sstevel@tonic-gate 	case CBI_STATUS_PASS:
4757c478bd9Sstevel@tonic-gate 		msg = "PASSED";
4767c478bd9Sstevel@tonic-gate 		/* non-zero command completion interrupt */
4777c478bd9Sstevel@tonic-gate 		if (*(req->intr_data->b_rptr)) {
4787c478bd9Sstevel@tonic-gate 			*(scsa2usbp->scsa2usb_cur_pkt->pkt_scbp) = STATUS_CHECK;
4797c478bd9Sstevel@tonic-gate 			cmd->cmd_done = 1;
4807c478bd9Sstevel@tonic-gate 		}
4817c478bd9Sstevel@tonic-gate 		break;
4827c478bd9Sstevel@tonic-gate 	case CBI_STATUS_FAILED:
4837c478bd9Sstevel@tonic-gate 	case CBI_STATUS_PERSISTENT_FAIL:
4847c478bd9Sstevel@tonic-gate 		msg = (status == CBI_STATUS_PERSISTENT_FAIL) ?
485*112116d8Sfb 		    "PERSISTENT_FAILURE" : "FAILED";
4867c478bd9Sstevel@tonic-gate 		*(scsa2usbp->scsa2usb_cur_pkt->pkt_scbp) = STATUS_CHECK;
4877c478bd9Sstevel@tonic-gate 		cmd->cmd_done = 1;
4887c478bd9Sstevel@tonic-gate 		break;
4897c478bd9Sstevel@tonic-gate 	case CBI_STATUS_PHASE_ERR:
4907c478bd9Sstevel@tonic-gate 		msg = "PHASE_ERR";
4917c478bd9Sstevel@tonic-gate 		scsa2usb_cbi_reset_recovery(scsa2usbp);
4927c478bd9Sstevel@tonic-gate 		rval = USB_FAILURE;
4937c478bd9Sstevel@tonic-gate 		break;
4947c478bd9Sstevel@tonic-gate 	}
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
4977c478bd9Sstevel@tonic-gate 	    "CBI STATUS = 0x%x %s (0x%x, 0x%x)", status, msg,
4987c478bd9Sstevel@tonic-gate 	    *(req->intr_data->b_rptr), *(req->intr_data->b_rptr+1));
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 	/* we are done and ready to callback */
5017c478bd9Sstevel@tonic-gate 	SCSA2USB_SET_PKT_DO_COMP_STATE(scsa2usbp);
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	return (rval);
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate  * scsa2usb_cbi_reset_recovery:
5097c478bd9Sstevel@tonic-gate  *	Reset the USB device in case of errors.
5107c478bd9Sstevel@tonic-gate  */
5117c478bd9Sstevel@tonic-gate static void
scsa2usb_cbi_reset_recovery(scsa2usb_state_t * scsa2usbp)5127c478bd9Sstevel@tonic-gate scsa2usb_cbi_reset_recovery(scsa2usb_state_t *scsa2usbp)
5137c478bd9Sstevel@tonic-gate {
5147c478bd9Sstevel@tonic-gate 	int		i, rval;
5157c478bd9Sstevel@tonic-gate 	mblk_t		*cdb;
5167c478bd9Sstevel@tonic-gate 	usb_cr_t	completion_reason;
5177c478bd9Sstevel@tonic-gate 	usb_cb_flags_t	cb_flags;
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
520*112116d8Sfb 	    "scsa2usb_cbi_reset_recovery: (0x%p)", (void *)scsa2usbp);
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 	ASSERT(mutex_owned(&scsa2usbp->scsa2usb_mutex));
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 	if (!(SCSA2USB_DEVICE_ACCESS_OK(scsa2usbp))) {
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 		return;
5277c478bd9Sstevel@tonic-gate 	}
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	if (scsa2usbp->scsa2usb_cur_pkt) {
5307c478bd9Sstevel@tonic-gate 		scsa2usbp->scsa2usb_cur_pkt->pkt_statistics |= STAT_DEV_RESET;
5317c478bd9Sstevel@tonic-gate 	}
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	/* Allocate an mblk for CBR */
5347c478bd9Sstevel@tonic-gate 	cdb = allocb_wait(CBI_CLASS_CMD_LEN, BPRI_LO, STR_NOSIG, NULL);
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 	*cdb->b_wptr++ = SCMD_SDIAG;	/* Set it to DIAG */
5377c478bd9Sstevel@tonic-gate 	*cdb->b_wptr++ = CBI_SELF_TEST;	/* Set it to reset */
5387c478bd9Sstevel@tonic-gate 	for (i = 2; i < CBI_CLASS_CMD_LEN; i++) {
5397c478bd9Sstevel@tonic-gate 		*cdb->b_wptr++ = CBI_CBR_VALUE;	/* Set it to 0xff */
5407c478bd9Sstevel@tonic-gate 	}
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	scsa2usbp->scsa2usb_pipe_state = SCSA2USB_PIPE_DEV_RESET;
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 	/*
5457c478bd9Sstevel@tonic-gate 	 * Send a Reset request to the device
5467c478bd9Sstevel@tonic-gate 	 */
5477c478bd9Sstevel@tonic-gate 	mutex_exit(&scsa2usbp->scsa2usb_mutex);
5487c478bd9Sstevel@tonic-gate 	rval = usb_pipe_sync_ctrl_xfer(scsa2usbp->scsa2usb_dip,
5497c478bd9Sstevel@tonic-gate 	    scsa2usbp->scsa2usb_default_pipe,
5507c478bd9Sstevel@tonic-gate 	    CBI_REQUEST_TYPE,			/* bmRequestType */
5517c478bd9Sstevel@tonic-gate 	    0,					/* bRequest */
5527c478bd9Sstevel@tonic-gate 	    CBI_WVALUE,				/* wValue */
5537c478bd9Sstevel@tonic-gate 	    scsa2usbp->scsa2usb_intfc_num,	/* wIndex address */
5547c478bd9Sstevel@tonic-gate 	    CBI_CLASS_CMD_LEN,			/* wLength */
5557c478bd9Sstevel@tonic-gate 	    &cdb,				/* data to be sent */
5567c478bd9Sstevel@tonic-gate 	    0, &completion_reason, &cb_flags, 0);
5577c478bd9Sstevel@tonic-gate 	mutex_enter(&scsa2usbp->scsa2usb_mutex);
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L3(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
5607c478bd9Sstevel@tonic-gate 	    "\tCBI RESET: rval = %x cr = %x", rval, completion_reason);
5617c478bd9Sstevel@tonic-gate 	if (rval != USB_SUCCESS) {
5627c478bd9Sstevel@tonic-gate 		goto exc_exit;
5637c478bd9Sstevel@tonic-gate 	}
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	/* reset and clear STALL on bulk-in pipe */
5667c478bd9Sstevel@tonic-gate 	rval = scsa2usb_clear_ept_stall(scsa2usbp,
5677c478bd9Sstevel@tonic-gate 	    scsa2usbp->scsa2usb_bulkin_ept.bEndpointAddress,
5687c478bd9Sstevel@tonic-gate 	    scsa2usbp->scsa2usb_bulkin_pipe, "bulk-in");
5697c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L3(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
5707c478bd9Sstevel@tonic-gate 	    "\tclear stall on bulk-in pipe: %d", rval);
5717c478bd9Sstevel@tonic-gate 	if (rval != USB_SUCCESS) {
5727c478bd9Sstevel@tonic-gate 		goto exc_exit;
5737c478bd9Sstevel@tonic-gate 	}
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	/* reset and clear STALL on bulk-out pipe */
5767c478bd9Sstevel@tonic-gate 	rval = scsa2usb_clear_ept_stall(scsa2usbp,
5777c478bd9Sstevel@tonic-gate 	    scsa2usbp->scsa2usb_bulkout_ept.bEndpointAddress,
5787c478bd9Sstevel@tonic-gate 	    scsa2usbp->scsa2usb_bulkout_pipe, "bulk-out");
5797c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L3(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
5807c478bd9Sstevel@tonic-gate 	    "\tclear stall on bulk-out pipe: %d", rval);
5817c478bd9Sstevel@tonic-gate 	if (rval != USB_SUCCESS) {
5827c478bd9Sstevel@tonic-gate 		goto exc_exit;
5837c478bd9Sstevel@tonic-gate 	}
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 	/* reset and clear STALL on interrupt pipe */
5867c478bd9Sstevel@tonic-gate 	if (SCSA2USB_IS_CBI(scsa2usbp)) {
5877c478bd9Sstevel@tonic-gate 		rval = scsa2usb_clear_ept_stall(scsa2usbp,
5887c478bd9Sstevel@tonic-gate 		    scsa2usbp->scsa2usb_intr_ept.bEndpointAddress,
5897c478bd9Sstevel@tonic-gate 		    scsa2usbp->scsa2usb_intr_pipe, "intr");
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L3(DPRINT_MASK_SCSA, scsa2usbp->scsa2usb_log_handle,
5927c478bd9Sstevel@tonic-gate 		    "\tclear stall on intr pipe:  %d", rval);
5937c478bd9Sstevel@tonic-gate 	}
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate exc_exit:
5967c478bd9Sstevel@tonic-gate 	SCSA2USB_FREE_MSG(cdb);	/* Free the data */
5977c478bd9Sstevel@tonic-gate 	scsa2usbp->scsa2usb_pipe_state &= ~SCSA2USB_PIPE_DEV_RESET;
5987c478bd9Sstevel@tonic-gate }
599