cam_xpt.c

来自「基于组件方式开发操作系统的OSKIT源代码」· C语言 代码 · 共 2,349 行 · 第 1/5 页

C
2,349 行
字号
	if (device != NULL) {		int s;		struct periph_list *periph_head;		periph_head = &device->periphs;				/* Release the slot for this peripheral */		s = splsoftcam();		camq_resize(&device->drvq, device->drvq.array_size - 1);		device->generation++;		SLIST_REMOVE(periph_head, periph, cam_periph, periph_links);		splx(s);	}	xsoftc.generation++;}voidxpt_announce_periph(struct cam_periph *periph, char *announce_string){	int s;	u_int mb;	struct cam_path *path;	struct ccb_trans_settings cts;	path = periph->path;	/*	 * To ensure that this is printed in one piece,	 * mask out CAM interrupts.	 */	s = splsoftcam();	printf("%s%d at %s%d bus %d target %d lun %d\n",	       periph->periph_name, periph->unit_number,	       path->bus->sim->sim_name,	       path->bus->sim->unit_number,	       path->bus->sim->bus_id,	       path->target->target_id,	       path->device->lun_id);	printf("%s%d: ", periph->periph_name, periph->unit_number);	scsi_print_inquiry(&path->device->inq_data);	if ((bootverbose)	 && (path->device->serial_num_len > 0)) {		/* Don't wrap the screen  - print only the first 60 chars */		printf("%s%d: Serial Number %.60s\n", periph->periph_name,		       periph->unit_number, path->device->serial_num);	}	xpt_setup_ccb(&cts.ccb_h, path, /*priority*/1);	cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;	cts.flags = CCB_TRANS_CURRENT_SETTINGS;	xpt_action((union ccb*)&cts);	if (cts.ccb_h.status == CAM_REQ_CMP) {		u_int speed;		u_int freq;		if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0		  && cts.sync_offset != 0) {			freq = scsi_calc_syncsrate(cts.sync_period);			speed = freq;		} else {			struct ccb_pathinq cpi;			/* Ask the SIM for its base transfer speed */			xpt_setup_ccb(&cpi.ccb_h, path, /*priority*/1);			cpi.ccb_h.func_code = XPT_PATH_INQ;			xpt_action((union ccb *)&cpi);			speed = cpi.base_transfer_speed;			freq = 0;		}		if ((cts.valid & CCB_TRANS_BUS_WIDTH_VALID) != 0)			speed *= (0x01 << cts.bus_width);		mb = speed / 1000;		if (mb > 0)			printf("%s%d: %d.%03dMB/s transfers",			       periph->periph_name, periph->unit_number,			       mb, speed % 1000);		else			printf("%s%d: %dKB/s transfers", periph->periph_name,			       periph->unit_number, (speed % 1000) * 1000);		if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0		 && cts.sync_offset != 0) {			printf(" (%d.%03dMHz, offset %d", freq / 1000,			       freq % 1000, cts.sync_offset);		}		if ((cts.valid & CCB_TRANS_BUS_WIDTH_VALID) != 0		 && cts.bus_width > 0) {			if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0			 && cts.sync_offset != 0) {				printf(", ");			} else {				printf(" (");			}			printf("%dbit)", 8 * (0x01 << cts.bus_width));		} else if ((cts.valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0			&& cts.sync_offset != 0) {			printf(")");		}		if (path->device->inq_flags & SID_CmdQue		 || path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {			printf(", Tagged Queueing Enabled");		}		printf("\n");	} else if (path->device->inq_flags & SID_CmdQue   		|| path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {		printf("%s%d: Tagged Queueing Enabled\n",		       periph->periph_name, periph->unit_number);	}	/*	 * We only want to print the caller's announce string if they've	 * passed one in..	 */	if (announce_string != NULL)		printf("%s%d: %s\n", periph->periph_name,		       periph->unit_number, announce_string);	splx(s);}static dev_match_retxptbusmatch(struct dev_match_pattern *patterns, int num_patterns,	    struct cam_eb *bus){	dev_match_ret retval;	int i;	retval = DM_RET_NONE;	/*	 * If we aren't given something to match against, that's an error.	 */	if (bus == NULL)		return(DM_RET_ERROR);	/*	 * If there are no match entries, then this bus matches no	 * matter what.	 */	if ((patterns == NULL) || (num_patterns == 0))		return(DM_RET_DESCEND | DM_RET_COPY);	for (i = 0; i < num_patterns; i++) {		struct bus_match_pattern *cur_pattern;		/*		 * If the pattern in question isn't for a bus node, we		 * aren't interested.  However, we do indicate to the		 * calling routine that we should continue descending the		 * tree, since the user wants to match against lower-level		 * EDT elements.		 */		if (patterns[i].type != DEV_MATCH_BUS) {			if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)				retval |= DM_RET_DESCEND;			continue;		}		cur_pattern = &patterns[i].pattern.bus_pattern;		/*		 * If they want to match any bus node, we give them any		 * device node.		 */		if (cur_pattern->flags == BUS_MATCH_ANY) {			/* set the copy flag */			retval |= DM_RET_COPY;			/*			 * If we've already decided on an action, go ahead			 * and return.			 */			if ((retval & DM_RET_ACTION_MASK) != DM_RET_NONE)				return(retval);		}		/*		 * Not sure why someone would do this...		 */		if (cur_pattern->flags == BUS_MATCH_NONE)			continue;		if (((cur_pattern->flags & BUS_MATCH_PATH) != 0)		 && (cur_pattern->path_id != bus->path_id))			continue;		if (((cur_pattern->flags & BUS_MATCH_BUS_ID) != 0)		 && (cur_pattern->bus_id != bus->sim->bus_id))			continue;		if (((cur_pattern->flags & BUS_MATCH_UNIT) != 0)		 && (cur_pattern->unit_number != bus->sim->unit_number))			continue;		if (((cur_pattern->flags & BUS_MATCH_NAME) != 0)		 && (strncmp(cur_pattern->dev_name, bus->sim->sim_name,			     DEV_IDLEN) != 0))			continue;		/*		 * If we get to this point, the user definitely wants 		 * information on this bus.  So tell the caller to copy the		 * data out.		 */		retval |= DM_RET_COPY;		/*		 * If the return action has been set to descend, then we		 * know that we've already seen a non-bus matching		 * expression, therefore we need to further descend the tree.		 * This won't change by continuing around the loop, so we		 * go ahead and return.  If we haven't seen a non-bus		 * matching expression, we keep going around the loop until		 * we exhaust the matching expressions.  We'll set the stop		 * flag once we fall out of the loop.		 */		if ((retval & DM_RET_ACTION_MASK) == DM_RET_DESCEND)			return(retval);	}	/*	 * If the return action hasn't been set to descend yet, that means	 * we haven't seen anything other than bus matching patterns.  So	 * tell the caller to stop descending the tree -- the user doesn't	 * want to match against lower level tree elements.	 */	if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)		retval |= DM_RET_STOP;	return(retval);}static dev_match_retxptdevicematch(struct dev_match_pattern *patterns, int num_patterns,	       struct cam_ed *device){	dev_match_ret retval;	int i;	retval = DM_RET_NONE;	/*	 * If we aren't given something to match against, that's an error.	 */	if (device == NULL)		return(DM_RET_ERROR);	/*	 * If there are no match entries, then this device matches no	 * matter what.	 */	if ((patterns == NULL) || (patterns == 0))		return(DM_RET_DESCEND | DM_RET_COPY);	for (i = 0; i < num_patterns; i++) {		struct device_match_pattern *cur_pattern;		/*		 * If the pattern in question isn't for a device node, we		 * aren't interested.		 */		if (patterns[i].type != DEV_MATCH_DEVICE) {			if ((patterns[i].type == DEV_MATCH_PERIPH)			 && ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE))				retval |= DM_RET_DESCEND;			continue;		}		cur_pattern = &patterns[i].pattern.device_pattern;		/*		 * If they want to match any device node, we give them any		 * device node.		 */		if (cur_pattern->flags == DEV_MATCH_ANY) {			/* set the copy flag */			retval |= DM_RET_COPY;						/*			 * If we've already decided on an action, go ahead			 * and return.			 */			if ((retval & DM_RET_ACTION_MASK) != DM_RET_NONE)				return(retval);		}		/*		 * Not sure why someone would do this...		 */		if (cur_pattern->flags == DEV_MATCH_NONE)			continue;		if (((cur_pattern->flags & DEV_MATCH_PATH) != 0)		 && (cur_pattern->path_id != device->target->bus->path_id))			continue;		if (((cur_pattern->flags & DEV_MATCH_TARGET) != 0)		 && (cur_pattern->target_id != device->target->target_id))			continue;		if (((cur_pattern->flags & DEV_MATCH_LUN) != 0)		 && (cur_pattern->target_lun != device->lun_id))			continue;		if (((cur_pattern->flags & DEV_MATCH_INQUIRY) != 0)		 && (cam_quirkmatch((caddr_t)&device->inq_data,				    (caddr_t)&cur_pattern->inq_pat,				    1, sizeof(cur_pattern->inq_pat),				    scsi_static_inquiry_match) == NULL))			continue;		/*		 * If we get to this point, the user definitely wants 		 * information on this device.  So tell the caller to copy		 * the data out.		 */		retval |= DM_RET_COPY;		/*		 * If the return action has been set to descend, then we		 * know that we've already seen a peripheral matching		 * expression, therefore we need to further descend the tree.		 * This won't change by continuing around the loop, so we		 * go ahead and return.  If we haven't seen a peripheral		 * matching expression, we keep going around the loop until		 * we exhaust the matching expressions.  We'll set the stop		 * flag once we fall out of the loop.		 */		if ((retval & DM_RET_ACTION_MASK) == DM_RET_DESCEND)			return(retval);	}	/*	 * If the return action hasn't been set to descend yet, that means	 * we haven't seen any peripheral matching patterns.  So tell the	 * caller to stop descending the tree -- the user doesn't want to	 * match against lower level tree elements.	 */	if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)		retval |= DM_RET_STOP;	return(retval);}/* * Match a single peripheral against any number of match patterns. */static dev_match_retxptperiphmatch(struct dev_match_pattern *patterns, int num_patterns,	       struct cam_periph *periph){	dev_match_ret retval;	int i;	/*	 * If we aren't given something to match against, that's an error.	 */	if (periph == NULL)		return(DM_RET_ERROR);	/*	 * If there are no match entries, then this peripheral matches no	 * matter what.	 */	if ((patterns == NULL) || (num_patterns == 0))		return(DM_RET_STOP | DM_RET_COPY);	/*	 * There aren't any nodes below a peripheral node, so there's no	 * reason to descend the tree any further.	 */	retval = DM_RET_STOP;	for (i = 0; i < num_patterns; i++) {		struct periph_match_pattern *cur_pattern;		/*		 * If the pattern in question isn't for a peripheral, we		 * aren't interested.		 */		if (patterns[i].type != DEV_MATCH_PERIPH)			continue;		cur_pattern = &patterns[i].pattern.periph_pattern;		/*		 * If they want to match on anything, then we will do so.		 */		if (cur_pattern->flags == PERIPH_MATCH_ANY) {			/* set the copy flag */			retval |= DM_RET_COPY;			/*			 * We've already set the return action to stop,			 * since there are no nodes below peripherals in			 * the tree.			 */			return(retval);		}		/*		 * Not sure why someone would do this...		 */		if (cur_pattern->flags == PERIPH_MATCH_NONE)			continue;		if (((cur_pattern->flags & PERIPH_MATCH_PATH) != 0)		 && (cur_pattern->path_id != periph->path->bus->path_id))			continue;		/*		 * For the target and lun id's, we have to make sure the		 * target and lun pointers aren't NULL.  The xpt peripheral		 * has a wildcard target and device.		 */		if (((cur_pattern->flags & PERIPH_MATCH_TARGET) != 0)		 && ((periph->path->target == NULL)		 ||(cur_pattern->target_id != periph->path->target->target_id)))			continue;		if (((cur_pattern->flags & PERIPH_MATCH_LUN) != 0)		 && ((periph->path->device == NULL)		 || (cur_pattern->target_lun != periph->path->device->lun_id)))			continue;		if (((cur_pattern->flags & PERIPH_MATCH_UNIT) != 0)		 && (cur_pattern->unit_number != periph->unit_number))			continue;		if (((cur_pattern->flags & PERIPH_MATCH_NAME) != 0)		 && (strncmp(cur_pattern->periph_name, periph->periph_name,			     DEV_IDLEN) != 0))			continue;		/*		 * If we get to this point, the user definitely wants 		 * information on this peripheral.  So tell the caller to		 * copy the data out.		 */		retval |= DM_RET_COPY;		/*		 * The return action has already been set to stop, since		 * peripherals don't have any nodes below them in the EDT.		 */		return(retval);	}	/*	 * If we get to this point, the peripheral that was passed in	 * doesn't match any of the patterns.	 */	return(retval);}static intxptedtbusfunc(struct cam_eb *bus, void *arg){	struct ccb_dev_match *cdm;	dev_match_ret retval;	cdm = (struct ccb_dev_match *)arg;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?