📄 mptsas.c
字号:
error = sas_phy_add(port); if (error) { sas_phy_free(port); return error; } if (phy_info->attached.handle) { struct sas_rphy *rphy; rphy = sas_rphy_alloc(port); if (!rphy) return 0; /* non-fatal: an rphy can be added later */ mptsas_parse_device_info(&rphy->identify, &phy_info->attached); error = sas_rphy_add(rphy); if (error) { sas_rphy_free(rphy); return error; } phy_info->rphy = rphy; } return 0;}static intmptsas_probe_hba_phys(MPT_ADAPTER *ioc, int *index){ struct mptsas_portinfo *port_info; u32 handle = 0xFFFF; int error = -ENOMEM, i; port_info = kmalloc(sizeof(*port_info), GFP_KERNEL); if (!port_info) goto out; memset(port_info, 0, sizeof(*port_info)); error = mptsas_sas_io_unit_pg0(ioc, port_info); if (error) goto out_free_port_info; list_add_tail(&port_info->list, &ioc->sas_topology); for (i = 0; i < port_info->num_phys; i++) { mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i], (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER << MPI_SAS_PHY_PGAD_FORM_SHIFT), i); mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify, (MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE << MPI_SAS_DEVICE_PGAD_FORM_SHIFT), handle); port_info->phy_info[i].identify.phy_id = port_info->phy_info[i].phy_id; handle = port_info->phy_info[i].identify.handle; if (port_info->phy_info[i].attached.handle) { mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].attached, (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << MPI_SAS_DEVICE_PGAD_FORM_SHIFT), port_info->phy_info[i].attached.handle); } mptsas_probe_one_phy(&ioc->sh->shost_gendev, &port_info->phy_info[i], *index, 1); (*index)++; } return 0; out_free_port_info: kfree(port_info); out: return error;}static intmptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle, int *index){ struct mptsas_portinfo *port_info, *p; int error = -ENOMEM, i, j; port_info = kmalloc(sizeof(*port_info), GFP_KERNEL); if (!port_info) goto out; memset(port_info, 0, sizeof(*port_info)); error = mptsas_sas_expander_pg0(ioc, port_info, (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE << MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle); if (error) goto out_free_port_info; *handle = port_info->handle; list_add_tail(&port_info->list, &ioc->sas_topology); for (i = 0; i < port_info->num_phys; i++) { struct device *parent; mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i], (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM << MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle); if (port_info->phy_info[i].identify.handle) { mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify, (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << MPI_SAS_DEVICE_PGAD_FORM_SHIFT), port_info->phy_info[i].identify.handle); port_info->phy_info[i].identify.phy_id = port_info->phy_info[i].phy_id; } if (port_info->phy_info[i].attached.handle) { mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].attached, (MPI_SAS_DEVICE_PGAD_FORM_HANDLE << MPI_SAS_DEVICE_PGAD_FORM_SHIFT), port_info->phy_info[i].attached.handle); } /* * If we find a parent port handle this expander is * attached to another expander, else it hangs of the * HBA phys. */ parent = &ioc->sh->shost_gendev; list_for_each_entry(p, &ioc->sas_topology, list) { for (j = 0; j < p->num_phys; j++) { if (port_info->phy_info[i].identify.handle == p->phy_info[j].attached.handle) parent = &p->phy_info[j].rphy->dev; } } mptsas_probe_one_phy(parent, &port_info->phy_info[i], *index, 0); (*index)++; } return 0; out_free_port_info: kfree(port_info); out: return error;}static voidmptsas_scan_sas_topology(MPT_ADAPTER *ioc){ u32 handle = 0xFFFF; int index = 0; mptsas_probe_hba_phys(ioc, &index); while (!mptsas_probe_expander_phys(ioc, &handle, &index)) ;}static intmptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id){ struct Scsi_Host *sh; MPT_SCSI_HOST *hd; MPT_ADAPTER *ioc; unsigned long flags; int sz, ii; int numSGE = 0; int scale; int ioc_cap; u8 *mem; int error=0; int r; r = mpt_attach(pdev,id); if (r) return r; ioc = pci_get_drvdata(pdev); ioc->DoneCtx = mptsasDoneCtx; ioc->TaskCtx = mptsasTaskCtx; ioc->InternalCtx = mptsasInternalCtx; /* Added sanity check on readiness of the MPT adapter. */ if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) { printk(MYIOC_s_WARN_FMT "Skipping because it's not operational!\n", ioc->name); return -ENODEV; } if (!ioc->active) { printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n", ioc->name); return -ENODEV; } /* Sanity check - ensure at least 1 port is INITIATOR capable */ ioc_cap = 0; for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) { if (ioc->pfacts[ii].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) ioc_cap++; } if (!ioc_cap) { printk(MYIOC_s_WARN_FMT "Skipping ioc=%p because SCSI Initiator mode " "is NOT enabled!\n", ioc->name, ioc); return 0; } sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST)); if (!sh) { printk(MYIOC_s_WARN_FMT "Unable to register controller with SCSI subsystem\n", ioc->name); return -1; } spin_lock_irqsave(&ioc->FreeQlock, flags); /* Attach the SCSI Host to the IOC structure */ ioc->sh = sh; sh->io_port = 0; sh->n_io_port = 0; sh->irq = 0; /* set 16 byte cdb's */ sh->max_cmd_len = 16; sh->max_id = ioc->pfacts->MaxDevices + 1; sh->transportt = mptsas_transport_template; sh->max_lun = MPT_LAST_LUN + 1; sh->max_channel = 0; sh->this_id = ioc->pfacts[0].PortSCSIID; /* Required entry. */ sh->unique_id = ioc->id; INIT_LIST_HEAD(&ioc->sas_topology); init_MUTEX(&ioc->sas_mgmt.mutex); init_completion(&ioc->sas_mgmt.done); /* Verify that we won't exceed the maximum * number of chain buffers * We can optimize: ZZ = req_sz/sizeof(SGE) * For 32bit SGE's: * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ * + (req_sz - 64)/sizeof(SGE) * A slightly different algorithm is required for * 64bit SGEs. */ scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32)); if (sizeof(dma_addr_t) == sizeof(u64)) { numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32)); } else { numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32)); } if (numSGE < sh->sg_tablesize) { /* Reset this value */ dprintk((MYIOC_s_INFO_FMT "Resetting sg_tablesize to %d from %d\n", ioc->name, numSGE, sh->sg_tablesize)); sh->sg_tablesize = numSGE; } spin_unlock_irqrestore(&ioc->FreeQlock, flags); hd = (MPT_SCSI_HOST *) sh->hostdata; hd->ioc = ioc; /* SCSI needs scsi_cmnd lookup table! * (with size equal to req_depth*PtrSz!) */ sz = ioc->req_depth * sizeof(void *); mem = kmalloc(sz, GFP_ATOMIC); if (mem == NULL) { error = -ENOMEM; goto mptsas_probe_failed; } memset(mem, 0, sz); hd->ScsiLookup = (struct scsi_cmnd **) mem; dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p, sz=%d\n", ioc->name, hd->ScsiLookup, sz)); /* Allocate memory for the device structures. * A non-Null pointer at an offset * indicates a device exists. * max_id = 1 + maximum id (hosts.h) */ sz = sh->max_id * sizeof(void *); mem = kmalloc(sz, GFP_ATOMIC); if (mem == NULL) { error = -ENOMEM; goto mptsas_probe_failed; } memset(mem, 0, sz); hd->Targets = (VirtDevice **) mem; dprintk((KERN_INFO " Targets @ %p, sz=%d\n", hd->Targets, sz)); /* Clear the TM flags */ hd->tmPending = 0; hd->tmState = TM_STATE_NONE; hd->resetPending = 0; hd->abortSCpnt = NULL; /* Clear the pointer used to store * single-threaded commands, i.e., those * issued during a bus scan, dv and * configuration pages. */ hd->cmdPtr = NULL; /* Initialize this SCSI Hosts' timers * To use, set the timer expires field * and add_timer */ init_timer(&hd->timer); hd->timer.data = (unsigned long) hd; hd->timer.function = mptscsih_timer_expired; hd->mpt_pq_filter = mpt_pq_filter; ioc->sas_data.ptClear = mpt_pt_clear; if (ioc->sas_data.ptClear==1) { mptbase_sas_persist_operation( ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT); } ddvprintk((MYIOC_s_INFO_FMT "mpt_pq_filter %x mpt_pq_filter %x\n", ioc->name, mpt_pq_filter, mpt_pq_filter)); init_waitqueue_head(&hd->scandv_waitq); hd->scandv_wait_done = 0; hd->last_queue_full = 0; error = scsi_add_host(sh, &ioc->pcidev->dev); if (error) { dprintk((KERN_ERR MYNAM "scsi_add_host failed\n")); goto mptsas_probe_failed; } mptsas_scan_sas_topology(ioc); return 0;mptsas_probe_failed: mptscsih_remove(pdev); return error;}static void __devexit mptsas_remove(struct pci_dev *pdev){ MPT_ADAPTER *ioc = pci_get_drvdata(pdev); struct mptsas_portinfo *p, *n; sas_remove_host(ioc->sh); list_for_each_entry_safe(p, n, &ioc->sas_topology, list) { list_del(&p->list); kfree(p); } mptscsih_remove(pdev);}static struct pci_device_id mptsas_pci_table[] = { { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064, PCI_ANY_ID, PCI_ANY_ID }, { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066, PCI_ANY_ID, PCI_ANY_ID }, { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068, PCI_ANY_ID, PCI_ANY_ID }, { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064E, PCI_ANY_ID, PCI_ANY_ID }, { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066E, PCI_ANY_ID, PCI_ANY_ID }, { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068E, PCI_ANY_ID, PCI_ANY_ID }, {0} /* Terminating entry */};MODULE_DEVICE_TABLE(pci, mptsas_pci_table);static struct pci_driver mptsas_driver = { .name = "mptsas", .id_table = mptsas_pci_table, .probe = mptsas_probe, .remove = __devexit_p(mptsas_remove), .shutdown = mptscsih_shutdown,#ifdef CONFIG_PM .suspend = mptscsih_suspend, .resume = mptscsih_resume,#endif};static int __initmptsas_init(void){ show_mptmod_ver(my_NAME, my_VERSION); mptsas_transport_template = sas_attach_transport(&mptsas_transport_functions); if (!mptsas_transport_template) return -ENODEV; mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER); mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER); mptsasInternalCtx = mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER); mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER); if (mpt_event_register(mptsasDoneCtx, mptscsih_event_process) == 0) { devtprintk((KERN_INFO MYNAM ": Registered for IOC event notifications\n")); } if (mpt_reset_register(mptsasDoneCtx, mptscsih_ioc_reset) == 0) { dprintk((KERN_INFO MYNAM ": Registered for IOC reset notifications\n")); } return pci_register_driver(&mptsas_driver);}static void __exitmptsas_exit(void){ pci_unregister_driver(&mptsas_driver); sas_release_transport(mptsas_transport_template); mpt_reset_deregister(mptsasDoneCtx); mpt_event_deregister(mptsasDoneCtx); mpt_deregister(mptsasMgmtCtx); mpt_deregister(mptsasInternalCtx); mpt_deregister(mptsasTaskCtx); mpt_deregister(mptsasDoneCtx);}module_init(mptsas_init);module_exit(mptsas_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -