pm8001_init.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. /*
  2. * PMC-Sierra PM8001/8081/8088/8089 SAS/SATA based host adapters driver
  3. *
  4. * Copyright (c) 2008-2009 USI Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions, and the following disclaimer,
  12. * without modification.
  13. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  14. * substantially similar to the "NO WARRANTY" disclaimer below
  15. * ("Disclaimer") and any redistribution must be conditioned upon
  16. * including a substantially similar Disclaimer requirement for further
  17. * binary redistribution.
  18. * 3. Neither the names of the above-listed copyright holders nor the names
  19. * of any contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * Alternatively, this software may be distributed under the terms of the
  23. * GNU General Public License ("GPL") version 2 as published by the Free
  24. * Software Foundation.
  25. *
  26. * NO WARRANTY
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  36. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGES.
  38. *
  39. */
  40. #include <linux/slab.h>
  41. #include "pm8001_sas.h"
  42. #include "pm8001_chips.h"
  43. static struct scsi_transport_template *pm8001_stt;
  44. /**
  45. * chip info structure to identify chip key functionality as
  46. * encryption available/not, no of ports, hw specific function ref
  47. */
  48. static const struct pm8001_chip_info pm8001_chips[] = {
  49. [chip_8001] = {0, 8, &pm8001_8001_dispatch,},
  50. [chip_8008] = {0, 8, &pm8001_80xx_dispatch,},
  51. [chip_8009] = {1, 8, &pm8001_80xx_dispatch,},
  52. [chip_8018] = {0, 16, &pm8001_80xx_dispatch,},
  53. [chip_8019] = {1, 16, &pm8001_80xx_dispatch,},
  54. [chip_8074] = {0, 8, &pm8001_80xx_dispatch,},
  55. [chip_8076] = {0, 16, &pm8001_80xx_dispatch,},
  56. [chip_8077] = {0, 16, &pm8001_80xx_dispatch,},
  57. };
  58. static int pm8001_id;
  59. LIST_HEAD(hba_list);
  60. struct workqueue_struct *pm8001_wq;
  61. /**
  62. * The main structure which LLDD must register for scsi core.
  63. */
  64. static struct scsi_host_template pm8001_sht = {
  65. .module = THIS_MODULE,
  66. .name = DRV_NAME,
  67. .queuecommand = sas_queuecommand,
  68. .target_alloc = sas_target_alloc,
  69. .slave_configure = sas_slave_configure,
  70. .scan_finished = pm8001_scan_finished,
  71. .scan_start = pm8001_scan_start,
  72. .change_queue_depth = sas_change_queue_depth,
  73. .change_queue_type = sas_change_queue_type,
  74. .bios_param = sas_bios_param,
  75. .can_queue = 1,
  76. .cmd_per_lun = 1,
  77. .this_id = -1,
  78. .sg_tablesize = SG_ALL,
  79. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  80. .use_clustering = ENABLE_CLUSTERING,
  81. .eh_device_reset_handler = sas_eh_device_reset_handler,
  82. .eh_bus_reset_handler = sas_eh_bus_reset_handler,
  83. .target_destroy = sas_target_destroy,
  84. .ioctl = sas_ioctl,
  85. .shost_attrs = pm8001_host_attrs,
  86. };
  87. /**
  88. * Sas layer call this function to execute specific task.
  89. */
  90. static struct sas_domain_function_template pm8001_transport_ops = {
  91. .lldd_dev_found = pm8001_dev_found,
  92. .lldd_dev_gone = pm8001_dev_gone,
  93. .lldd_execute_task = pm8001_queue_command,
  94. .lldd_control_phy = pm8001_phy_control,
  95. .lldd_abort_task = pm8001_abort_task,
  96. .lldd_abort_task_set = pm8001_abort_task_set,
  97. .lldd_clear_aca = pm8001_clear_aca,
  98. .lldd_clear_task_set = pm8001_clear_task_set,
  99. .lldd_I_T_nexus_reset = pm8001_I_T_nexus_reset,
  100. .lldd_lu_reset = pm8001_lu_reset,
  101. .lldd_query_task = pm8001_query_task,
  102. };
  103. /**
  104. *pm8001_phy_init - initiate our adapter phys
  105. *@pm8001_ha: our hba structure.
  106. *@phy_id: phy id.
  107. */
  108. static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id)
  109. {
  110. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  111. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  112. phy->phy_state = 0;
  113. phy->pm8001_ha = pm8001_ha;
  114. sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0;
  115. sas_phy->class = SAS;
  116. sas_phy->iproto = SAS_PROTOCOL_ALL;
  117. sas_phy->tproto = 0;
  118. sas_phy->type = PHY_TYPE_PHYSICAL;
  119. sas_phy->role = PHY_ROLE_INITIATOR;
  120. sas_phy->oob_mode = OOB_NOT_CONNECTED;
  121. sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
  122. sas_phy->id = phy_id;
  123. sas_phy->sas_addr = &pm8001_ha->sas_addr[0];
  124. sas_phy->frame_rcvd = &phy->frame_rcvd[0];
  125. sas_phy->ha = (struct sas_ha_struct *)pm8001_ha->shost->hostdata;
  126. sas_phy->lldd_phy = phy;
  127. }
  128. /**
  129. *pm8001_free - free hba
  130. *@pm8001_ha: our hba structure.
  131. *
  132. */
  133. static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
  134. {
  135. int i;
  136. if (!pm8001_ha)
  137. return;
  138. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  139. if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
  140. pci_free_consistent(pm8001_ha->pdev,
  141. (pm8001_ha->memoryMap.region[i].total_len +
  142. pm8001_ha->memoryMap.region[i].alignment),
  143. pm8001_ha->memoryMap.region[i].virt_ptr,
  144. pm8001_ha->memoryMap.region[i].phys_addr);
  145. }
  146. }
  147. PM8001_CHIP_DISP->chip_iounmap(pm8001_ha);
  148. if (pm8001_ha->shost)
  149. scsi_host_put(pm8001_ha->shost);
  150. flush_workqueue(pm8001_wq);
  151. kfree(pm8001_ha->tags);
  152. kfree(pm8001_ha);
  153. }
  154. #ifdef PM8001_USE_TASKLET
  155. /**
  156. * tasklet for 64 msi-x interrupt handler
  157. * @opaque: the passed general host adapter struct
  158. * Note: pm8001_tasklet is common for pm8001 & pm80xx
  159. */
  160. static void pm8001_tasklet(unsigned long opaque)
  161. {
  162. struct pm8001_hba_info *pm8001_ha;
  163. struct isr_param *irq_vector;
  164. irq_vector = (struct isr_param *)opaque;
  165. pm8001_ha = irq_vector->drv_inst;
  166. if (unlikely(!pm8001_ha))
  167. BUG_ON(1);
  168. PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
  169. }
  170. #endif
  171. /**
  172. * pm8001_interrupt_handler_msix - main MSIX interrupt handler.
  173. * It obtains the vector number and calls the equivalent bottom
  174. * half or services directly.
  175. * @opaque: the passed outbound queue/vector. Host structure is
  176. * retrieved from the same.
  177. */
  178. static irqreturn_t pm8001_interrupt_handler_msix(int irq, void *opaque)
  179. {
  180. struct isr_param *irq_vector;
  181. struct pm8001_hba_info *pm8001_ha;
  182. irqreturn_t ret = IRQ_HANDLED;
  183. irq_vector = (struct isr_param *)opaque;
  184. pm8001_ha = irq_vector->drv_inst;
  185. if (unlikely(!pm8001_ha))
  186. return IRQ_NONE;
  187. if (!PM8001_CHIP_DISP->is_our_interupt(pm8001_ha))
  188. return IRQ_NONE;
  189. #ifdef PM8001_USE_TASKLET
  190. tasklet_schedule(&pm8001_ha->tasklet[irq_vector->irq_id]);
  191. #else
  192. ret = PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
  193. #endif
  194. return ret;
  195. }
  196. /**
  197. * pm8001_interrupt_handler_intx - main INTx interrupt handler.
  198. * @dev_id: sas_ha structure. The HBA is retrieved from sas_has structure.
  199. */
  200. static irqreturn_t pm8001_interrupt_handler_intx(int irq, void *dev_id)
  201. {
  202. struct pm8001_hba_info *pm8001_ha;
  203. irqreturn_t ret = IRQ_HANDLED;
  204. struct sas_ha_struct *sha = dev_id;
  205. pm8001_ha = sha->lldd_ha;
  206. if (unlikely(!pm8001_ha))
  207. return IRQ_NONE;
  208. if (!PM8001_CHIP_DISP->is_our_interupt(pm8001_ha))
  209. return IRQ_NONE;
  210. #ifdef PM8001_USE_TASKLET
  211. tasklet_schedule(&pm8001_ha->tasklet[0]);
  212. #else
  213. ret = PM8001_CHIP_DISP->isr(pm8001_ha, 0);
  214. #endif
  215. return ret;
  216. }
  217. /**
  218. * pm8001_alloc - initiate our hba structure and 6 DMAs area.
  219. * @pm8001_ha:our hba structure.
  220. *
  221. */
  222. static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
  223. const struct pci_device_id *ent)
  224. {
  225. int i;
  226. spin_lock_init(&pm8001_ha->lock);
  227. PM8001_INIT_DBG(pm8001_ha,
  228. pm8001_printk("pm8001_alloc: PHY:%x\n",
  229. pm8001_ha->chip->n_phy));
  230. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  231. pm8001_phy_init(pm8001_ha, i);
  232. pm8001_ha->port[i].wide_port_phymap = 0;
  233. pm8001_ha->port[i].port_attached = 0;
  234. pm8001_ha->port[i].port_state = 0;
  235. INIT_LIST_HEAD(&pm8001_ha->port[i].list);
  236. }
  237. pm8001_ha->tags = kzalloc(PM8001_MAX_CCB, GFP_KERNEL);
  238. if (!pm8001_ha->tags)
  239. goto err_out;
  240. /* MPI Memory region 1 for AAP Event Log for fw */
  241. pm8001_ha->memoryMap.region[AAP1].num_elements = 1;
  242. pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE;
  243. pm8001_ha->memoryMap.region[AAP1].total_len = PM8001_EVENT_LOG_SIZE;
  244. pm8001_ha->memoryMap.region[AAP1].alignment = 32;
  245. /* MPI Memory region 2 for IOP Event Log for fw */
  246. pm8001_ha->memoryMap.region[IOP].num_elements = 1;
  247. pm8001_ha->memoryMap.region[IOP].element_size = PM8001_EVENT_LOG_SIZE;
  248. pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE;
  249. pm8001_ha->memoryMap.region[IOP].alignment = 32;
  250. for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) {
  251. /* MPI Memory region 3 for consumer Index of inbound queues */
  252. pm8001_ha->memoryMap.region[CI+i].num_elements = 1;
  253. pm8001_ha->memoryMap.region[CI+i].element_size = 4;
  254. pm8001_ha->memoryMap.region[CI+i].total_len = 4;
  255. pm8001_ha->memoryMap.region[CI+i].alignment = 4;
  256. if ((ent->driver_data) != chip_8001) {
  257. /* MPI Memory region 5 inbound queues */
  258. pm8001_ha->memoryMap.region[IB+i].num_elements =
  259. PM8001_MPI_QUEUE;
  260. pm8001_ha->memoryMap.region[IB+i].element_size = 128;
  261. pm8001_ha->memoryMap.region[IB+i].total_len =
  262. PM8001_MPI_QUEUE * 128;
  263. pm8001_ha->memoryMap.region[IB+i].alignment = 128;
  264. } else {
  265. pm8001_ha->memoryMap.region[IB+i].num_elements =
  266. PM8001_MPI_QUEUE;
  267. pm8001_ha->memoryMap.region[IB+i].element_size = 64;
  268. pm8001_ha->memoryMap.region[IB+i].total_len =
  269. PM8001_MPI_QUEUE * 64;
  270. pm8001_ha->memoryMap.region[IB+i].alignment = 64;
  271. }
  272. }
  273. for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) {
  274. /* MPI Memory region 4 for producer Index of outbound queues */
  275. pm8001_ha->memoryMap.region[PI+i].num_elements = 1;
  276. pm8001_ha->memoryMap.region[PI+i].element_size = 4;
  277. pm8001_ha->memoryMap.region[PI+i].total_len = 4;
  278. pm8001_ha->memoryMap.region[PI+i].alignment = 4;
  279. if (ent->driver_data != chip_8001) {
  280. /* MPI Memory region 6 Outbound queues */
  281. pm8001_ha->memoryMap.region[OB+i].num_elements =
  282. PM8001_MPI_QUEUE;
  283. pm8001_ha->memoryMap.region[OB+i].element_size = 128;
  284. pm8001_ha->memoryMap.region[OB+i].total_len =
  285. PM8001_MPI_QUEUE * 128;
  286. pm8001_ha->memoryMap.region[OB+i].alignment = 128;
  287. } else {
  288. /* MPI Memory region 6 Outbound queues */
  289. pm8001_ha->memoryMap.region[OB+i].num_elements =
  290. PM8001_MPI_QUEUE;
  291. pm8001_ha->memoryMap.region[OB+i].element_size = 64;
  292. pm8001_ha->memoryMap.region[OB+i].total_len =
  293. PM8001_MPI_QUEUE * 64;
  294. pm8001_ha->memoryMap.region[OB+i].alignment = 64;
  295. }
  296. }
  297. /* Memory region write DMA*/
  298. pm8001_ha->memoryMap.region[NVMD].num_elements = 1;
  299. pm8001_ha->memoryMap.region[NVMD].element_size = 4096;
  300. pm8001_ha->memoryMap.region[NVMD].total_len = 4096;
  301. /* Memory region for devices*/
  302. pm8001_ha->memoryMap.region[DEV_MEM].num_elements = 1;
  303. pm8001_ha->memoryMap.region[DEV_MEM].element_size = PM8001_MAX_DEVICES *
  304. sizeof(struct pm8001_device);
  305. pm8001_ha->memoryMap.region[DEV_MEM].total_len = PM8001_MAX_DEVICES *
  306. sizeof(struct pm8001_device);
  307. /* Memory region for ccb_info*/
  308. pm8001_ha->memoryMap.region[CCB_MEM].num_elements = 1;
  309. pm8001_ha->memoryMap.region[CCB_MEM].element_size = PM8001_MAX_CCB *
  310. sizeof(struct pm8001_ccb_info);
  311. pm8001_ha->memoryMap.region[CCB_MEM].total_len = PM8001_MAX_CCB *
  312. sizeof(struct pm8001_ccb_info);
  313. /* Memory region for fw flash */
  314. pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096;
  315. pm8001_ha->memoryMap.region[FORENSIC_MEM].num_elements = 1;
  316. pm8001_ha->memoryMap.region[FORENSIC_MEM].total_len = 0x10000;
  317. pm8001_ha->memoryMap.region[FORENSIC_MEM].element_size = 0x10000;
  318. pm8001_ha->memoryMap.region[FORENSIC_MEM].alignment = 0x10000;
  319. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  320. if (pm8001_mem_alloc(pm8001_ha->pdev,
  321. &pm8001_ha->memoryMap.region[i].virt_ptr,
  322. &pm8001_ha->memoryMap.region[i].phys_addr,
  323. &pm8001_ha->memoryMap.region[i].phys_addr_hi,
  324. &pm8001_ha->memoryMap.region[i].phys_addr_lo,
  325. pm8001_ha->memoryMap.region[i].total_len,
  326. pm8001_ha->memoryMap.region[i].alignment) != 0) {
  327. PM8001_FAIL_DBG(pm8001_ha,
  328. pm8001_printk("Mem%d alloc failed\n",
  329. i));
  330. goto err_out;
  331. }
  332. }
  333. pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr;
  334. for (i = 0; i < PM8001_MAX_DEVICES; i++) {
  335. pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
  336. pm8001_ha->devices[i].id = i;
  337. pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
  338. pm8001_ha->devices[i].running_req = 0;
  339. }
  340. pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr;
  341. for (i = 0; i < PM8001_MAX_CCB; i++) {
  342. pm8001_ha->ccb_info[i].ccb_dma_handle =
  343. pm8001_ha->memoryMap.region[CCB_MEM].phys_addr +
  344. i * sizeof(struct pm8001_ccb_info);
  345. pm8001_ha->ccb_info[i].task = NULL;
  346. pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
  347. pm8001_ha->ccb_info[i].device = NULL;
  348. ++pm8001_ha->tags_num;
  349. }
  350. pm8001_ha->flags = PM8001F_INIT_TIME;
  351. /* Initialize tags */
  352. pm8001_tag_init(pm8001_ha);
  353. return 0;
  354. err_out:
  355. return 1;
  356. }
  357. /**
  358. * pm8001_ioremap - remap the pci high physical address to kernal virtual
  359. * address so that we can access them.
  360. * @pm8001_ha:our hba structure.
  361. */
  362. static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
  363. {
  364. u32 bar;
  365. u32 logicalBar = 0;
  366. struct pci_dev *pdev;
  367. pdev = pm8001_ha->pdev;
  368. /* map pci mem (PMC pci base 0-3)*/
  369. for (bar = 0; bar < 6; bar++) {
  370. /*
  371. ** logical BARs for SPC:
  372. ** bar 0 and 1 - logical BAR0
  373. ** bar 2 and 3 - logical BAR1
  374. ** bar4 - logical BAR2
  375. ** bar5 - logical BAR3
  376. ** Skip the appropriate assignments:
  377. */
  378. if ((bar == 1) || (bar == 3))
  379. continue;
  380. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  381. pm8001_ha->io_mem[logicalBar].membase =
  382. pci_resource_start(pdev, bar);
  383. pm8001_ha->io_mem[logicalBar].membase &=
  384. (u32)PCI_BASE_ADDRESS_MEM_MASK;
  385. pm8001_ha->io_mem[logicalBar].memsize =
  386. pci_resource_len(pdev, bar);
  387. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  388. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  389. pm8001_ha->io_mem[logicalBar].memsize);
  390. PM8001_INIT_DBG(pm8001_ha,
  391. pm8001_printk("PCI: bar %d, logicalBar %d ",
  392. bar, logicalBar));
  393. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  394. "base addr %llx virt_addr=%llx len=%d\n",
  395. (u64)pm8001_ha->io_mem[logicalBar].membase,
  396. (u64)(unsigned long)
  397. pm8001_ha->io_mem[logicalBar].memvirtaddr,
  398. pm8001_ha->io_mem[logicalBar].memsize));
  399. } else {
  400. pm8001_ha->io_mem[logicalBar].membase = 0;
  401. pm8001_ha->io_mem[logicalBar].memsize = 0;
  402. pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
  403. }
  404. logicalBar++;
  405. }
  406. return 0;
  407. }
  408. /**
  409. * pm8001_pci_alloc - initialize our ha card structure
  410. * @pdev: pci device.
  411. * @ent: ent
  412. * @shost: scsi host struct which has been initialized before.
  413. */
  414. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  415. const struct pci_device_id *ent,
  416. struct Scsi_Host *shost)
  417. {
  418. struct pm8001_hba_info *pm8001_ha;
  419. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  420. int j;
  421. pm8001_ha = sha->lldd_ha;
  422. if (!pm8001_ha)
  423. return NULL;
  424. pm8001_ha->pdev = pdev;
  425. pm8001_ha->dev = &pdev->dev;
  426. pm8001_ha->chip_id = ent->driver_data;
  427. pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
  428. pm8001_ha->irq = pdev->irq;
  429. pm8001_ha->sas = sha;
  430. pm8001_ha->shost = shost;
  431. pm8001_ha->id = pm8001_id++;
  432. pm8001_ha->logging_level = 0x01;
  433. sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
  434. /* IOMB size is 128 for 8088/89 controllers */
  435. if (pm8001_ha->chip_id != chip_8001)
  436. pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
  437. else
  438. pm8001_ha->iomb_size = IOMB_SIZE_SPC;
  439. #ifdef PM8001_USE_TASKLET
  440. /* Tasklet for non msi-x interrupt handler */
  441. if ((!pdev->msix_cap) || (pm8001_ha->chip_id == chip_8001))
  442. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  443. (unsigned long)&(pm8001_ha->irq_vector[0]));
  444. else
  445. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  446. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  447. (unsigned long)&(pm8001_ha->irq_vector[j]));
  448. #endif
  449. pm8001_ioremap(pm8001_ha);
  450. if (!pm8001_alloc(pm8001_ha, ent))
  451. return pm8001_ha;
  452. pm8001_free(pm8001_ha);
  453. return NULL;
  454. }
  455. /**
  456. * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
  457. * @pdev: pci device.
  458. */
  459. static int pci_go_44(struct pci_dev *pdev)
  460. {
  461. int rc;
  462. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
  463. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
  464. if (rc) {
  465. rc = pci_set_consistent_dma_mask(pdev,
  466. DMA_BIT_MASK(32));
  467. if (rc) {
  468. dev_printk(KERN_ERR, &pdev->dev,
  469. "44-bit DMA enable failed\n");
  470. return rc;
  471. }
  472. }
  473. } else {
  474. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  475. if (rc) {
  476. dev_printk(KERN_ERR, &pdev->dev,
  477. "32-bit DMA enable failed\n");
  478. return rc;
  479. }
  480. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  481. if (rc) {
  482. dev_printk(KERN_ERR, &pdev->dev,
  483. "32-bit consistent DMA enable failed\n");
  484. return rc;
  485. }
  486. }
  487. return rc;
  488. }
  489. /**
  490. * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
  491. * @shost: scsi host which has been allocated outside.
  492. * @chip_info: our ha struct.
  493. */
  494. static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
  495. const struct pm8001_chip_info *chip_info)
  496. {
  497. int phy_nr, port_nr;
  498. struct asd_sas_phy **arr_phy;
  499. struct asd_sas_port **arr_port;
  500. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  501. phy_nr = chip_info->n_phy;
  502. port_nr = phy_nr;
  503. memset(sha, 0x00, sizeof(*sha));
  504. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  505. if (!arr_phy)
  506. goto exit;
  507. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  508. if (!arr_port)
  509. goto exit_free2;
  510. sha->sas_phy = arr_phy;
  511. sha->sas_port = arr_port;
  512. sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
  513. if (!sha->lldd_ha)
  514. goto exit_free1;
  515. shost->transportt = pm8001_stt;
  516. shost->max_id = PM8001_MAX_DEVICES;
  517. shost->max_lun = 8;
  518. shost->max_channel = 0;
  519. shost->unique_id = pm8001_id;
  520. shost->max_cmd_len = 16;
  521. shost->can_queue = PM8001_CAN_QUEUE;
  522. shost->cmd_per_lun = 32;
  523. return 0;
  524. exit_free1:
  525. kfree(arr_port);
  526. exit_free2:
  527. kfree(arr_phy);
  528. exit:
  529. return -1;
  530. }
  531. /**
  532. * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
  533. * @shost: scsi host which has been allocated outside
  534. * @chip_info: our ha struct.
  535. */
  536. static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  537. const struct pm8001_chip_info *chip_info)
  538. {
  539. int i = 0;
  540. struct pm8001_hba_info *pm8001_ha;
  541. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  542. pm8001_ha = sha->lldd_ha;
  543. for (i = 0; i < chip_info->n_phy; i++) {
  544. sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
  545. sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
  546. }
  547. sha->sas_ha_name = DRV_NAME;
  548. sha->dev = pm8001_ha->dev;
  549. sha->lldd_module = THIS_MODULE;
  550. sha->sas_addr = &pm8001_ha->sas_addr[0];
  551. sha->num_phys = chip_info->n_phy;
  552. sha->lldd_max_execute_num = 1;
  553. sha->lldd_queue_size = PM8001_CAN_QUEUE;
  554. sha->core.shost = shost;
  555. }
  556. /**
  557. * pm8001_init_sas_add - initialize sas address
  558. * @chip_info: our ha struct.
  559. *
  560. * Currently we just set the fixed SAS address to our HBA,for manufacture,
  561. * it should read from the EEPROM
  562. */
  563. static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
  564. {
  565. u8 i, j;
  566. #ifdef PM8001_READ_VPD
  567. /* For new SPC controllers WWN is stored in flash vpd
  568. * For SPC/SPCve controllers WWN is stored in EEPROM
  569. * For Older SPC WWN is stored in NVMD
  570. */
  571. DECLARE_COMPLETION_ONSTACK(completion);
  572. struct pm8001_ioctl_payload payload;
  573. u16 deviceid;
  574. pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
  575. pm8001_ha->nvmd_completion = &completion;
  576. if (pm8001_ha->chip_id == chip_8001) {
  577. if (deviceid == 0x8081) {
  578. payload.minor_function = 4;
  579. payload.length = 4096;
  580. } else {
  581. payload.minor_function = 0;
  582. payload.length = 128;
  583. }
  584. } else {
  585. payload.minor_function = 1;
  586. payload.length = 4096;
  587. }
  588. payload.offset = 0;
  589. payload.func_specific = kzalloc(payload.length, GFP_KERNEL);
  590. PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  591. wait_for_completion(&completion);
  592. for (i = 0, j = 0; i <= 7; i++, j++) {
  593. if (pm8001_ha->chip_id == chip_8001) {
  594. if (deviceid == 0x8081)
  595. pm8001_ha->sas_addr[j] =
  596. payload.func_specific[0x704 + i];
  597. } else
  598. pm8001_ha->sas_addr[j] =
  599. payload.func_specific[0x804 + i];
  600. }
  601. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  602. memcpy(&pm8001_ha->phy[i].dev_sas_addr,
  603. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  604. PM8001_INIT_DBG(pm8001_ha,
  605. pm8001_printk("phy %d sas_addr = %016llx\n", i,
  606. pm8001_ha->phy[i].dev_sas_addr));
  607. }
  608. #else
  609. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  610. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  611. pm8001_ha->phy[i].dev_sas_addr =
  612. cpu_to_be64((u64)
  613. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  614. }
  615. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  616. SAS_ADDR_SIZE);
  617. #endif
  618. }
  619. /*
  620. * pm8001_get_phy_settings_info : Read phy setting values.
  621. * @pm8001_ha : our hba.
  622. */
  623. void pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
  624. {
  625. #ifdef PM8001_READ_VPD
  626. /*OPTION ROM FLASH read for the SPC cards */
  627. DECLARE_COMPLETION_ONSTACK(completion);
  628. struct pm8001_ioctl_payload payload;
  629. pm8001_ha->nvmd_completion = &completion;
  630. /* SAS ADDRESS read from flash / EEPROM */
  631. payload.minor_function = 6;
  632. payload.offset = 0;
  633. payload.length = 4096;
  634. payload.func_specific = kzalloc(4096, GFP_KERNEL);
  635. /* Read phy setting values from flash */
  636. PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  637. wait_for_completion(&completion);
  638. pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
  639. #endif
  640. }
  641. #ifdef PM8001_USE_MSIX
  642. /**
  643. * pm8001_setup_msix - enable MSI-X interrupt
  644. * @chip_info: our ha struct.
  645. * @irq_handler: irq_handler
  646. */
  647. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  648. {
  649. u32 i = 0, j = 0;
  650. u32 number_of_intr;
  651. int flag = 0;
  652. u32 max_entry;
  653. int rc;
  654. static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
  655. /* SPCv controllers supports 64 msi-x */
  656. if (pm8001_ha->chip_id == chip_8001) {
  657. number_of_intr = 1;
  658. flag |= IRQF_DISABLED;
  659. } else {
  660. number_of_intr = PM8001_MAX_MSIX_VEC;
  661. flag &= ~IRQF_SHARED;
  662. flag |= IRQF_DISABLED;
  663. }
  664. max_entry = sizeof(pm8001_ha->msix_entries) /
  665. sizeof(pm8001_ha->msix_entries[0]);
  666. for (i = 0; i < max_entry ; i++)
  667. pm8001_ha->msix_entries[i].entry = i;
  668. rc = pci_enable_msix(pm8001_ha->pdev, pm8001_ha->msix_entries,
  669. number_of_intr);
  670. pm8001_ha->number_of_intr = number_of_intr;
  671. if (!rc) {
  672. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  673. "pci_enable_msix request ret:%d no of intr %d\n",
  674. rc, pm8001_ha->number_of_intr));
  675. for (i = 0; i < number_of_intr; i++) {
  676. snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
  677. DRV_NAME"%d", i);
  678. pm8001_ha->irq_vector[i].irq_id = i;
  679. pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
  680. if (request_irq(pm8001_ha->msix_entries[i].vector,
  681. pm8001_interrupt_handler_msix, flag,
  682. intr_drvname[i], &(pm8001_ha->irq_vector[i]))) {
  683. for (j = 0; j < i; j++)
  684. free_irq(
  685. pm8001_ha->msix_entries[j].vector,
  686. &(pm8001_ha->irq_vector[i]));
  687. pci_disable_msix(pm8001_ha->pdev);
  688. break;
  689. }
  690. }
  691. }
  692. return rc;
  693. }
  694. #endif
  695. /**
  696. * pm8001_request_irq - register interrupt
  697. * @chip_info: our ha struct.
  698. */
  699. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  700. {
  701. struct pci_dev *pdev;
  702. int rc;
  703. pdev = pm8001_ha->pdev;
  704. #ifdef PM8001_USE_MSIX
  705. if (pdev->msix_cap)
  706. return pm8001_setup_msix(pm8001_ha);
  707. else {
  708. PM8001_INIT_DBG(pm8001_ha,
  709. pm8001_printk("MSIX not supported!!!\n"));
  710. goto intx;
  711. }
  712. #endif
  713. intx:
  714. /* initialize the INT-X interrupt */
  715. rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
  716. DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
  717. return rc;
  718. }
  719. /**
  720. * pm8001_pci_probe - probe supported device
  721. * @pdev: pci device which kernel has been prepared for.
  722. * @ent: pci device id
  723. *
  724. * This function is the main initialization function, when register a new
  725. * pci driver it is invoked, all struct an hardware initilization should be done
  726. * here, also, register interrupt
  727. */
  728. static int pm8001_pci_probe(struct pci_dev *pdev,
  729. const struct pci_device_id *ent)
  730. {
  731. unsigned int rc;
  732. u32 pci_reg;
  733. u8 i = 0;
  734. struct pm8001_hba_info *pm8001_ha;
  735. struct Scsi_Host *shost = NULL;
  736. const struct pm8001_chip_info *chip;
  737. dev_printk(KERN_INFO, &pdev->dev,
  738. "pm80xx: driver version %s\n", DRV_VERSION);
  739. rc = pci_enable_device(pdev);
  740. if (rc)
  741. goto err_out_enable;
  742. pci_set_master(pdev);
  743. /*
  744. * Enable pci slot busmaster by setting pci command register.
  745. * This is required by FW for Cyclone card.
  746. */
  747. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  748. pci_reg |= 0x157;
  749. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  750. rc = pci_request_regions(pdev, DRV_NAME);
  751. if (rc)
  752. goto err_out_disable;
  753. rc = pci_go_44(pdev);
  754. if (rc)
  755. goto err_out_regions;
  756. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  757. if (!shost) {
  758. rc = -ENOMEM;
  759. goto err_out_regions;
  760. }
  761. chip = &pm8001_chips[ent->driver_data];
  762. SHOST_TO_SAS_HA(shost) =
  763. kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  764. if (!SHOST_TO_SAS_HA(shost)) {
  765. rc = -ENOMEM;
  766. goto err_out_free_host;
  767. }
  768. rc = pm8001_prep_sas_ha_init(shost, chip);
  769. if (rc) {
  770. rc = -ENOMEM;
  771. goto err_out_free;
  772. }
  773. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  774. /* ent->driver variable is used to differentiate between controllers */
  775. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  776. if (!pm8001_ha) {
  777. rc = -ENOMEM;
  778. goto err_out_free;
  779. }
  780. list_add_tail(&pm8001_ha->list, &hba_list);
  781. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  782. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  783. if (rc) {
  784. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  785. "chip_init failed [ret: %d]\n", rc));
  786. goto err_out_ha_free;
  787. }
  788. rc = scsi_add_host(shost, &pdev->dev);
  789. if (rc)
  790. goto err_out_ha_free;
  791. rc = pm8001_request_irq(pm8001_ha);
  792. if (rc) {
  793. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  794. "pm8001_request_irq failed [ret: %d]\n", rc));
  795. goto err_out_shost;
  796. }
  797. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  798. if (pm8001_ha->chip_id != chip_8001) {
  799. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  800. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  801. /* setup thermal configuration. */
  802. pm80xx_set_thermal_config(pm8001_ha);
  803. }
  804. pm8001_init_sas_add(pm8001_ha);
  805. /* phy setting support for motherboard controller */
  806. if (pdev->subsystem_vendor != PCI_VENDOR_ID_ADAPTEC2 &&
  807. pdev->subsystem_vendor != 0)
  808. pm8001_get_phy_settings_info(pm8001_ha);
  809. pm8001_post_sas_ha_init(shost, chip);
  810. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  811. if (rc)
  812. goto err_out_shost;
  813. scsi_scan_host(pm8001_ha->shost);
  814. return 0;
  815. err_out_shost:
  816. scsi_remove_host(pm8001_ha->shost);
  817. err_out_ha_free:
  818. pm8001_free(pm8001_ha);
  819. err_out_free:
  820. kfree(SHOST_TO_SAS_HA(shost));
  821. err_out_free_host:
  822. kfree(shost);
  823. err_out_regions:
  824. pci_release_regions(pdev);
  825. err_out_disable:
  826. pci_disable_device(pdev);
  827. err_out_enable:
  828. return rc;
  829. }
  830. static void pm8001_pci_remove(struct pci_dev *pdev)
  831. {
  832. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  833. struct pm8001_hba_info *pm8001_ha;
  834. int i, j;
  835. pm8001_ha = sha->lldd_ha;
  836. sas_unregister_ha(sha);
  837. sas_remove_host(pm8001_ha->shost);
  838. list_del(&pm8001_ha->list);
  839. scsi_remove_host(pm8001_ha->shost);
  840. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  841. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  842. #ifdef PM8001_USE_MSIX
  843. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  844. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  845. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  846. free_irq(pm8001_ha->msix_entries[i].vector,
  847. &(pm8001_ha->irq_vector[i]));
  848. pci_disable_msix(pdev);
  849. #else
  850. free_irq(pm8001_ha->irq, sha);
  851. #endif
  852. #ifdef PM8001_USE_TASKLET
  853. /* For non-msix and msix interrupts */
  854. if ((!pdev->msix_cap) || (pm8001_ha->chip_id == chip_8001))
  855. tasklet_kill(&pm8001_ha->tasklet[0]);
  856. else
  857. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  858. tasklet_kill(&pm8001_ha->tasklet[j]);
  859. #endif
  860. pm8001_free(pm8001_ha);
  861. kfree(sha->sas_phy);
  862. kfree(sha->sas_port);
  863. kfree(sha);
  864. pci_release_regions(pdev);
  865. pci_disable_device(pdev);
  866. }
  867. /**
  868. * pm8001_pci_suspend - power management suspend main entry point
  869. * @pdev: PCI device struct
  870. * @state: PM state change to (usually PCI_D3)
  871. *
  872. * Returns 0 success, anything else error.
  873. */
  874. static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  875. {
  876. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  877. struct pm8001_hba_info *pm8001_ha;
  878. int i, j;
  879. u32 device_state;
  880. pm8001_ha = sha->lldd_ha;
  881. flush_workqueue(pm8001_wq);
  882. scsi_block_requests(pm8001_ha->shost);
  883. if (!pdev->pm_cap) {
  884. dev_err(&pdev->dev, " PCI PM not supported\n");
  885. return -ENODEV;
  886. }
  887. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  888. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  889. #ifdef PM8001_USE_MSIX
  890. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  891. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  892. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  893. free_irq(pm8001_ha->msix_entries[i].vector,
  894. &(pm8001_ha->irq_vector[i]));
  895. pci_disable_msix(pdev);
  896. #else
  897. free_irq(pm8001_ha->irq, sha);
  898. #endif
  899. #ifdef PM8001_USE_TASKLET
  900. /* For non-msix and msix interrupts */
  901. if ((!pdev->msix_cap) || (pm8001_ha->chip_id == chip_8001))
  902. tasklet_kill(&pm8001_ha->tasklet[0]);
  903. else
  904. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  905. tasklet_kill(&pm8001_ha->tasklet[j]);
  906. #endif
  907. device_state = pci_choose_state(pdev, state);
  908. pm8001_printk("pdev=0x%p, slot=%s, entering "
  909. "operating state [D%d]\n", pdev,
  910. pm8001_ha->name, device_state);
  911. pci_save_state(pdev);
  912. pci_disable_device(pdev);
  913. pci_set_power_state(pdev, device_state);
  914. return 0;
  915. }
  916. /**
  917. * pm8001_pci_resume - power management resume main entry point
  918. * @pdev: PCI device struct
  919. *
  920. * Returns 0 success, anything else error.
  921. */
  922. static int pm8001_pci_resume(struct pci_dev *pdev)
  923. {
  924. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  925. struct pm8001_hba_info *pm8001_ha;
  926. int rc;
  927. u8 i = 0, j;
  928. u32 device_state;
  929. pm8001_ha = sha->lldd_ha;
  930. device_state = pdev->current_state;
  931. pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
  932. "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
  933. pci_set_power_state(pdev, PCI_D0);
  934. pci_enable_wake(pdev, PCI_D0, 0);
  935. pci_restore_state(pdev);
  936. rc = pci_enable_device(pdev);
  937. if (rc) {
  938. pm8001_printk("slot=%s Enable device failed during resume\n",
  939. pm8001_ha->name);
  940. goto err_out_enable;
  941. }
  942. pci_set_master(pdev);
  943. rc = pci_go_44(pdev);
  944. if (rc)
  945. goto err_out_disable;
  946. /* chip soft rst only for spc */
  947. if (pm8001_ha->chip_id == chip_8001) {
  948. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  949. PM8001_INIT_DBG(pm8001_ha,
  950. pm8001_printk("chip soft reset successful\n"));
  951. }
  952. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  953. if (rc)
  954. goto err_out_disable;
  955. /* disable all the interrupt bits */
  956. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  957. rc = pm8001_request_irq(pm8001_ha);
  958. if (rc)
  959. goto err_out_disable;
  960. #ifdef PM8001_USE_TASKLET
  961. /* Tasklet for non msi-x interrupt handler */
  962. if ((!pdev->msix_cap) || (pm8001_ha->chip_id == chip_8001))
  963. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  964. (unsigned long)&(pm8001_ha->irq_vector[0]));
  965. else
  966. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  967. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  968. (unsigned long)&(pm8001_ha->irq_vector[j]));
  969. #endif
  970. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  971. if (pm8001_ha->chip_id != chip_8001) {
  972. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  973. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  974. }
  975. scsi_unblock_requests(pm8001_ha->shost);
  976. return 0;
  977. err_out_disable:
  978. scsi_remove_host(pm8001_ha->shost);
  979. pci_disable_device(pdev);
  980. err_out_enable:
  981. return rc;
  982. }
  983. /* update of pci device, vendor id and driver data with
  984. * unique value for each of the controller
  985. */
  986. static struct pci_device_id pm8001_pci_table[] = {
  987. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  988. {
  989. PCI_DEVICE(0x117c, 0x0042),
  990. .driver_data = chip_8001
  991. },
  992. /* Support for SPC/SPCv/SPCve controllers */
  993. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  994. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  995. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  996. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  997. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  998. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  999. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  1000. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  1001. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  1002. { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
  1003. { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
  1004. { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
  1005. { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
  1006. { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
  1007. { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
  1008. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1009. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  1010. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1011. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  1012. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1013. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  1014. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1015. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  1016. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1017. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  1018. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1019. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  1020. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1021. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  1022. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1023. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  1024. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1025. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  1026. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1027. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  1028. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1029. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
  1030. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1031. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
  1032. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1033. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
  1034. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1035. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
  1036. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1037. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
  1038. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1039. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
  1040. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1041. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
  1042. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1043. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
  1044. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1045. PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
  1046. {} /* terminate list */
  1047. };
  1048. static struct pci_driver pm8001_pci_driver = {
  1049. .name = DRV_NAME,
  1050. .id_table = pm8001_pci_table,
  1051. .probe = pm8001_pci_probe,
  1052. .remove = pm8001_pci_remove,
  1053. .suspend = pm8001_pci_suspend,
  1054. .resume = pm8001_pci_resume,
  1055. };
  1056. /**
  1057. * pm8001_init - initialize scsi transport template
  1058. */
  1059. static int __init pm8001_init(void)
  1060. {
  1061. int rc = -ENOMEM;
  1062. pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
  1063. if (!pm8001_wq)
  1064. goto err;
  1065. pm8001_id = 0;
  1066. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  1067. if (!pm8001_stt)
  1068. goto err_wq;
  1069. rc = pci_register_driver(&pm8001_pci_driver);
  1070. if (rc)
  1071. goto err_tp;
  1072. return 0;
  1073. err_tp:
  1074. sas_release_transport(pm8001_stt);
  1075. err_wq:
  1076. destroy_workqueue(pm8001_wq);
  1077. err:
  1078. return rc;
  1079. }
  1080. static void __exit pm8001_exit(void)
  1081. {
  1082. pci_unregister_driver(&pm8001_pci_driver);
  1083. sas_release_transport(pm8001_stt);
  1084. destroy_workqueue(pm8001_wq);
  1085. }
  1086. module_init(pm8001_init);
  1087. module_exit(pm8001_exit);
  1088. MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
  1089. MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>");
  1090. MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
  1091. MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
  1092. MODULE_DESCRIPTION(
  1093. "PMC-Sierra PM8001/8081/8088/8089/8074/8076/8077 "
  1094. "SAS/SATA controller driver");
  1095. MODULE_VERSION(DRV_VERSION);
  1096. MODULE_LICENSE("GPL");
  1097. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);