FreeBSD/sys/cam/scsi/scsi_target.c
/* Enable target mode on a LUN, given its path */
Enable target mode on a LUN, given its path
Enable target mode on a LUN given its path
static cam_status
targenable(struct targ_softc *softc, struct cam_path *path, int grp6_len,
	   int grp7_len)
{
	struct cam_periph *periph;
	struct ccb_pathinq cpi;
	cam_status	   status;
	if ((softc->state & TARG_STATE_LUN_ENABLED) != 0)
		return (CAM_LUN_ALRDY_ENA);
	xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
	cpi.ccb_h.func_code = XPT_PATH_INQ;
	xpt_action((union ccb *)&cpi);
	status = cpi.ccb_h.status & CAM_STATUS_MASK;
	if (status != CAM_REQ_CMP) {
		printf("pathinq failed, status %#x\n", status);
		goto enable_fail;
	}
	if ((cpi.target_sprt & PIT_PROCESSOR) == 0) {
		printf("controller does not support target mode\n");
		status = CAM_FUNC_NOTAVAIL;
		goto enable_fail;
	}
	if (cpi.maxio == 0)
		softc->maxio = DFLTPHYS;	
	else if (cpi.maxio > MAXPHYS)
		softc->maxio = MAXPHYS;		
	else
		softc->maxio = cpi.maxio;	
	periph = cam_periph_find(path, "targ");
	if (periph != NULL) {
		struct targ_softc *del_softc;
		del_softc = (struct targ_softc *)periph->softc;
		if ((del_softc->state & TARG_STATE_LUN_ENABLED) == 0) {
			cam_periph_invalidate(del_softc->periph);
			del_softc->periph = NULL;
		} else {
			printf("Requested path still in use by targ%d\n",
			       periph->unit_number);
			status = CAM_LUN_ALRDY_ENA;
			goto enable_fail;
		}
	}
	status = cam_periph_alloc(targctor, NULL, targdtor, targstart,
			"targ", CAM_PERIPH_BIO, path, targasync, 0, softc);
	if (status != CAM_REQ_CMP) {
		printf("cam_periph_alloc failed, status %#x\n", status);
		goto enable_fail;
	}
	if (cam_periph_find(path, "targ") == NULL) {
		panic("targenable: succeeded but no periph?");
	}
	status = targendislun(path, 1, grp6_len, grp7_len);
	if (status != CAM_REQ_CMP) {
		printf("enable lun failed, status %#x\n", status);
		goto enable_fail;
	}
	softc->state |= TARG_STATE_LUN_ENABLED;
enable_fail:
	return (status);
}
static cam_status targenable ( struct targ_softc * softc , struct cam_path * path , int grp6_len , int grp7_len ) { struct cam_periph * periph ; struct ccb_pathinq cpi ; cam_status status ; if ( ( softc -> state & TARG_STATE_LUN_ENABLED ) != 0 ) return ( CAM_LUN_ALRDY_ENA ) ; xpt_setup_ccb ( & cpi . ccb_h , path , CAM_PRIORITY_NORMAL ) ; cpi . ccb_h . func_code = XPT_PATH_INQ ; xpt_action ( ( union ccb * ) & cpi ) ; status = cpi . ccb_h . status & CAM_STATUS_MASK ; if ( status != CAM_REQ_CMP ) { printf ( " \n " , status ) ; goto enable_fail ; } if ( ( cpi . target_sprt & PIT_PROCESSOR ) == 0 ) { printf ( " \n " ) ; status = CAM_FUNC_NOTAVAIL ; goto enable_fail ; } if ( cpi . maxio == 0 ) softc -> maxio = DFLTPHYS ; else if ( cpi . maxio > MAXPHYS ) softc -> maxio = MAXPHYS ; else softc -> maxio = cpi . maxio ; periph = cam_periph_find ( path , " " ) ; if ( periph != NULL ) { struct targ_softc * del_softc ; del_softc = ( struct targ_softc * ) periph -> softc ; if ( ( del_softc -> state & TARG_STATE_LUN_ENABLED ) == 0 ) { cam_periph_invalidate ( del_softc -> periph ) ; del_softc -> periph = NULL ; } else { printf ( " \n " , periph -> unit_number ) ; status = CAM_LUN_ALRDY_ENA ; goto enable_fail ; } } status = cam_periph_alloc ( targctor , NULL , targdtor , targstart , " " , CAM_PERIPH_BIO , path , targasync , 0 , softc ) ; if ( status != CAM_REQ_CMP ) { printf ( " \n " , status ) ; goto enable_fail ; } if ( cam_periph_find ( path , " " ) == NULL ) { panic ( " " ) ; } status = targendislun ( path , 1 , grp6_len , grp7_len ) ; if ( status != CAM_REQ_CMP ) { printf ( " \n " , status ) ; goto enable_fail ; } softc -> state |= TARG_STATE_LUN_ENABLED ; enable_fail : return ( status ) ; }
Enable target mode on a LUN, given its path
Enable target mode on a LUN given its path
/* Make sure SIM supports target mode */ /* traditional default */ /* for safety */ /* real value */ /* Destroy any periph on our path if it is disabled */ /* Create a periph instance attached to this path */ /* Ensure that the periph now exists. */ /* NOTREACHED */ /* Send the enable lun message */ /*enable*/