⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mptsas.c

📁 LINUX 2.6.17.4的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
mptsas_slave_destroy(struct scsi_device *sdev){	struct Scsi_Host *host = sdev->host;	MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;	VirtDevice *vdev;	/*	 * Issue target reset to flush firmware outstanding commands.	 */	vdev = sdev->hostdata;	if (vdev->configured_lun){		if (mptscsih_TMHandler(hd,		     MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,		     vdev->vtarget->bus_id,		     vdev->vtarget->target_id,		     0, 0, 5 /* 5 second timeout */)		     < 0){			/* The TM request failed!			 * Fatal error case.			 */			printk(MYIOC_s_WARN_FMT		       "Error processing TaskMgmt id=%d TARGET_RESET\n",				hd->ioc->name,				vdev->vtarget->target_id);			hd->tmPending = 0;			hd->tmState = TM_STATE_NONE;		}	}	mptscsih_slave_destroy(sdev);}static struct scsi_host_template mptsas_driver_template = {	.module				= THIS_MODULE,	.proc_name			= "mptsas",	.proc_info			= mptscsih_proc_info,	.name				= "MPT SPI Host",	.info				= mptscsih_info,	.queuecommand			= mptscsih_qcmd,	.target_alloc			= mptscsih_target_alloc,	.slave_alloc			= mptsas_slave_alloc,	.slave_configure		= mptsas_slave_configure,	.target_destroy			= mptscsih_target_destroy,	.slave_destroy			= mptsas_slave_destroy,	.change_queue_depth 		= mptscsih_change_queue_depth,	.eh_abort_handler		= mptscsih_abort,	.eh_device_reset_handler	= mptscsih_dev_reset,	.eh_bus_reset_handler		= mptscsih_bus_reset,	.eh_host_reset_handler		= mptscsih_host_reset,	.bios_param			= mptscsih_bios_param,	.can_queue			= MPT_FC_CAN_QUEUE,	.this_id			= -1,	.sg_tablesize			= MPT_SCSI_SG_DEPTH,	.max_sectors			= 8192,	.cmd_per_lun			= 7,	.use_clustering			= ENABLE_CLUSTERING,};static int mptsas_get_linkerrors(struct sas_phy *phy){	MPT_ADAPTER *ioc = phy_to_ioc(phy);	ConfigExtendedPageHeader_t hdr;	CONFIGPARMS cfg;	SasPhyPage1_t *buffer;	dma_addr_t dma_handle;	int error;	hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;	hdr.ExtPageLength = 0;	hdr.PageNumber = 1 /* page number 1*/;	hdr.Reserved1 = 0;	hdr.Reserved2 = 0;	hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;	hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;	cfg.cfghdr.ehdr = &hdr;	cfg.physAddr = -1;	cfg.pageAddr = phy->identify.phy_identifier;	cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;	cfg.dir = 0;    /* read */	cfg.timeout = 10;	error = mpt_config(ioc, &cfg);	if (error)		return error;	if (!hdr.ExtPageLength)		return -ENXIO;	buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,				      &dma_handle);	if (!buffer)		return -ENOMEM;	cfg.physAddr = dma_handle;	cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;	error = mpt_config(ioc, &cfg);	if (error)		goto out_free_consistent;	mptsas_print_phy_pg1(buffer);	phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);	phy->running_disparity_error_count =		le32_to_cpu(buffer->RunningDisparityErrorCount);	phy->loss_of_dword_sync_count =		le32_to_cpu(buffer->LossDwordSynchCount);	phy->phy_reset_problem_count =		le32_to_cpu(buffer->PhyResetProblemCount); out_free_consistent:	pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,			    buffer, dma_handle);	return error;}static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,		MPT_FRAME_HDR *reply){	ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_COMMAND_GOOD;	if (reply != NULL) {		ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_RF_VALID;		memcpy(ioc->sas_mgmt.reply, reply,		    min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));	}	complete(&ioc->sas_mgmt.done);	return 1;}static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset){	MPT_ADAPTER *ioc = phy_to_ioc(phy);	SasIoUnitControlRequest_t *req;	SasIoUnitControlReply_t *reply;	MPT_FRAME_HDR *mf;	MPIHeader_t *hdr;	unsigned long timeleft;	int error = -ERESTARTSYS;	/* not implemented for expanders */	if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)		return -ENXIO;	if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))		goto out;	mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);	if (!mf) {		error = -ENOMEM;		goto out_unlock;	}	hdr = (MPIHeader_t *) mf;	req = (SasIoUnitControlRequest_t *)mf;	memset(req, 0, sizeof(SasIoUnitControlRequest_t));	req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;	req->MsgContext = hdr->MsgContext;	req->Operation = hard_reset ?		MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;	req->PhyNum = phy->identify.phy_identifier;	mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);	timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,			10 * HZ);	if (!timeleft) {		/* On timeout reset the board */		mpt_free_msg_frame(ioc, mf);		mpt_HardResetHandler(ioc, CAN_SLEEP);		error = -ETIMEDOUT;		goto out_unlock;	}	/* a reply frame is expected */	if ((ioc->sas_mgmt.status &	    MPT_IOCTL_STATUS_RF_VALID) == 0) {		error = -ENXIO;		goto out_unlock;	}	/* process the completed Reply Message Frame */	reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;	if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {		printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",		    __FUNCTION__,		    reply->IOCStatus,		    reply->IOCLogInfo);		error = -ENXIO;		goto out_unlock;	}	error = 0; out_unlock:	mutex_unlock(&ioc->sas_mgmt.mutex); out:	return error;}static intmptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier){	MPT_ADAPTER *ioc = rphy_to_ioc(rphy);	int i, error;	struct mptsas_portinfo *p;	struct mptsas_enclosure enclosure_info;	u64 enclosure_handle;	mutex_lock(&ioc->sas_topology_mutex);	list_for_each_entry(p, &ioc->sas_topology, list) {		for (i = 0; i < p->num_phys; i++) {			if (p->phy_info[i].attached.sas_address ==			    rphy->identify.sas_address) {				enclosure_handle = p->phy_info[i].					attached.handle_enclosure;				goto found_info;			}		}	}	mutex_unlock(&ioc->sas_topology_mutex);	return -ENXIO; found_info:	mutex_unlock(&ioc->sas_topology_mutex);	memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));	error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,			(MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<			 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);	if (!error)		*identifier = enclosure_info.enclosure_logical_id;	return error;}static intmptsas_get_bay_identifier(struct sas_rphy *rphy){	MPT_ADAPTER *ioc = rphy_to_ioc(rphy);	struct mptsas_portinfo *p;	int i, rc;	mutex_lock(&ioc->sas_topology_mutex);	list_for_each_entry(p, &ioc->sas_topology, list) {		for (i = 0; i < p->num_phys; i++) {			if (p->phy_info[i].attached.sas_address ==			    rphy->identify.sas_address) {				rc = p->phy_info[i].attached.slot;				goto out;			}		}	}	rc = -ENXIO; out:	mutex_unlock(&ioc->sas_topology_mutex);	return rc;}static struct sas_function_template mptsas_transport_functions = {	.get_linkerrors		= mptsas_get_linkerrors,	.get_enclosure_identifier = mptsas_get_enclosure_identifier,	.get_bay_identifier	= mptsas_get_bay_identifier,	.phy_reset		= mptsas_phy_reset,};static struct scsi_transport_template *mptsas_transport_template;static intmptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info){	ConfigExtendedPageHeader_t hdr;	CONFIGPARMS cfg;	SasIOUnitPage0_t *buffer;	dma_addr_t dma_handle;	int error, i;	hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;	hdr.ExtPageLength = 0;	hdr.PageNumber = 0;	hdr.Reserved1 = 0;	hdr.Reserved2 = 0;	hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;	hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;	cfg.cfghdr.ehdr = &hdr;	cfg.physAddr = -1;	cfg.pageAddr = 0;	cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;	cfg.dir = 0;	/* read */	cfg.timeout = 10;	error = mpt_config(ioc, &cfg);	if (error)		goto out;	if (!hdr.ExtPageLength) {		error = -ENXIO;		goto out;	}	buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,					    &dma_handle);	if (!buffer) {		error = -ENOMEM;		goto out;	}	cfg.physAddr = dma_handle;	cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;	error = mpt_config(ioc, &cfg);	if (error)		goto out_free_consistent;	port_info->num_phys = buffer->NumPhys;	port_info->phy_info = kcalloc(port_info->num_phys,		sizeof(struct mptsas_phyinfo),GFP_KERNEL);	if (!port_info->phy_info) {		error = -ENOMEM;		goto out_free_consistent;	}	if (port_info->num_phys)		port_info->handle =		    le16_to_cpu(buffer->PhyData[0].ControllerDevHandle);	for (i = 0; i < port_info->num_phys; i++) {		mptsas_print_phy_data(&buffer->PhyData[i]);		port_info->phy_info[i].phy_id = i;		port_info->phy_info[i].port_id =		    buffer->PhyData[i].Port;		port_info->phy_info[i].negotiated_link_rate =		    buffer->PhyData[i].NegotiatedLinkRate;	} out_free_consistent:	pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,			    buffer, dma_handle); out:	return error;}static intmptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,		u32 form, u32 form_specific){	ConfigExtendedPageHeader_t hdr;	CONFIGPARMS cfg;	SasPhyPage0_t *buffer;	dma_addr_t dma_handle;	int error;	hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;	hdr.ExtPageLength = 0;	hdr.PageNumber = 0;	hdr.Reserved1 = 0;	hdr.Reserved2 = 0;	hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;	hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;	cfg.cfghdr.ehdr = &hdr;	cfg.dir = 0;	/* read */	cfg.timeout = 10;	/* Get Phy Pg 0 for each Phy. */	cfg.physAddr = -1;	cfg.pageAddr = form + form_specific;	cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;	error = mpt_config(ioc, &cfg);	if (error)		goto out;	if (!hdr.ExtPageLength) {		error = -ENXIO;		goto out;	}	buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,				      &dma_handle);	if (!buffer) {		error = -ENOMEM;		goto out;	}	cfg.physAddr = dma_handle;	cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;	error = mpt_config(ioc, &cfg);	if (error)		goto out_free_consistent;	mptsas_print_phy_pg0(buffer);	phy_info->hw_link_rate = buffer->HwLinkRate;	phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;	phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);	phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle); out_free_consistent:	pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,			    buffer, dma_handle); out:	return error;}static intmptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,		u32 form, u32 form_specific){	ConfigExtendedPageHeader_t hdr;	CONFIGPARMS cfg;	SasDevicePage0_t *buffer;	dma_addr_t dma_handle;	__le64 sas_address;	int error=0;	if (ioc->sas_discovery_runtime &&		mptsas_is_end_device(device_info))			goto out;	hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;	hdr.ExtPageLength = 0;	hdr.PageNumber = 0;	hdr.Reserved1 = 0;	hdr.Reserved2 = 0;	hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;	hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;	cfg.cfghdr.ehdr = &hdr;	cfg.pageAddr = form + form_specific;	cfg.physAddr = -1;	cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;	cfg.dir = 0;	/* read */	cfg.timeout = 10;	memset(device_info, 0, sizeof(struct mptsas_devinfo));	error = mpt_config(ioc, &cfg);	if (error)		goto out;	if (!hdr.ExtPageLength) {		error = -ENXIO;		goto out;	}	buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,				      &dma_handle);	if (!buffer) {		error = -ENOMEM;		goto out;	}	cfg.physAddr = dma_handle;	cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;	error = mpt_config(ioc, &cfg);	if (error)		goto out_free_consistent;	mptsas_print_device_pg0(buffer);	device_info->handle = le16_to_cpu(buffer->DevHandle);	device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);	device_info->handle_enclosure =	    le16_to_cpu(buffer->EnclosureHandle);	device_info->slot = le16_to_cpu(buffer->Slot);	device_info->phy_id = buffer->PhyNum;	device_info->port_id = buffer->PhysicalPort;	device_info->id = buffer->TargetID;	device_info->channel = buffer->Bus;	memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));	device_info->sas_address = le64_to_cpu(sas_address);	device_info->device_info =	    le32_to_cpu(buffer->DeviceInfo); out_free_consistent:	pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,			    buffer, dma_handle); out:	return error;}static intmptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,		u32 form, u32 form_specific){

⌨️ 快捷键说明

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