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

📄 mptsas.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
	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;	}	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;	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;	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->phy_id = buffer->PhyNum;	device_info->port_id = buffer->PhysicalPort;	device_info->target = buffer->TargetID;	device_info->bus = 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){	ConfigExtendedPageHeader_t hdr;	CONFIGPARMS cfg;	SasExpanderPage0_t *buffer;	dma_addr_t dma_handle;	int error;	hdr.PageVersion = MPI_SASEXPANDER0_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_EXPANDER;	cfg.cfghdr.ehdr = &hdr;	cfg.physAddr = -1;	cfg.pageAddr = form + form_specific;	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;	/* save config data */	port_info->num_phys = buffer->NumPhys;	port_info->handle = le16_to_cpu(buffer->DevHandle);	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;	} out_free_consistent:	pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,			    buffer, dma_handle); out:	return error;}static intmptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,		u32 form, u32 form_specific){	ConfigExtendedPageHeader_t hdr;	CONFIGPARMS cfg;	SasExpanderPage1_t *buffer;	dma_addr_t dma_handle;	int error;	hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;	hdr.ExtPageLength = 0;	hdr.PageNumber = 1;	hdr.Reserved1 = 0;	hdr.Reserved2 = 0;	hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;	hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;	cfg.cfghdr.ehdr = &hdr;	cfg.physAddr = -1;	cfg.pageAddr = form + form_specific;	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;	mptsas_print_expander_pg1(buffer);	/* save config data */	phy_info->phy_id = buffer->PhyIdentifier;	phy_info->port_id = buffer->PhysicalPort;	phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;	phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;	phy_info->hw_link_rate = buffer->HwLinkRate;	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 voidmptsas_parse_device_info(struct sas_identify *identify,		struct mptsas_devinfo *device_info){	u16 protocols;	identify->sas_address = device_info->sas_address;	identify->phy_identifier = device_info->phy_id;	/*	 * Fill in Phy Initiator Port Protocol.	 * Bits 6:3, more than one bit can be set, fall through cases.	 */	protocols = device_info->device_info & 0x78;	identify->initiator_port_protocols = 0;	if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)		identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;	if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)		identify->initiator_port_protocols |= SAS_PROTOCOL_STP;	if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)		identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;	if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)		identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;	/*	 * Fill in Phy Target Port Protocol.	 * Bits 10:7, more than one bit can be set, fall through cases.	 */	protocols = device_info->device_info & 0x780;	identify->target_port_protocols = 0;	if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)		identify->target_port_protocols |= SAS_PROTOCOL_SSP;	if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)		identify->target_port_protocols |= SAS_PROTOCOL_STP;	if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)		identify->target_port_protocols |= SAS_PROTOCOL_SMP;	if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)		identify->target_port_protocols |= SAS_PROTOCOL_SATA;	/*	 * Fill in Attached device type.	 */	switch (device_info->device_info &			MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {	case MPI_SAS_DEVICE_INFO_NO_DEVICE:		identify->device_type = SAS_PHY_UNUSED;		break;	case MPI_SAS_DEVICE_INFO_END_DEVICE:		identify->device_type = SAS_END_DEVICE;		break;	case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:		identify->device_type = SAS_EDGE_EXPANDER_DEVICE;		break;	case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:		identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;		break;	}}static int mptsas_probe_one_phy(struct device *dev,		struct mptsas_phyinfo *phy_info, int index, int local){	struct sas_phy *port;	int error;	port = sas_phy_alloc(dev, index);	if (!port)		return -ENOMEM;	port->port_identifier = phy_info->port_id;	mptsas_parse_device_info(&port->identify, &phy_info->identify);	/*	 * Set Negotiated link rate.	 */	switch (phy_info->negotiated_link_rate) {	case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:		port->negotiated_linkrate = SAS_PHY_DISABLED;		break;	case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:		port->negotiated_linkrate = SAS_LINK_RATE_FAILED;		break;	case MPI_SAS_IOUNIT0_RATE_1_5:		port->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;		break;	case MPI_SAS_IOUNIT0_RATE_3_0:		port->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;		break;	case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:	case MPI_SAS_IOUNIT0_RATE_UNKNOWN:	default:		port->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;		break;	}	/*	 * Set Max hardware link rate.	 */	switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {	case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:		port->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;		break;	case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:		port->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;		break;	default:		break;	}	/*	 * Set Max programmed link rate.	 */	switch (phy_info->programmed_link_rate &			MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {	case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:		port->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;		break;	case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:		port->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;		break;	default:		break;	}	/*	 * Set Min hardware link rate.	 */	switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {	case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:		port->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;		break;	case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:		port->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;		break;	default:		break;	}	/*	 * Set Min programmed link rate.	 */	switch (phy_info->programmed_link_rate &			MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {	case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:		port->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;		break;	case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:		port->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;		break;	default:		break;	}	if (local)		port->local_attached = 1;

⌨️ 快捷键说明

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