pm8001_init.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  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. .bios_param = sas_bios_param,
  74. .can_queue = 1,
  75. .this_id = -1,
  76. .sg_tablesize = SG_ALL,
  77. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  78. .use_clustering = ENABLE_CLUSTERING,
  79. .eh_device_reset_handler = sas_eh_device_reset_handler,
  80. .eh_bus_reset_handler = sas_eh_bus_reset_handler,
  81. .target_destroy = sas_target_destroy,
  82. .ioctl = sas_ioctl,
  83. .shost_attrs = pm8001_host_attrs,
  84. .use_blk_tags = 1,
  85. .track_queue_depth = 1,
  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. spin_lock_init(&pm8001_ha->bitmap_lock);
  228. PM8001_INIT_DBG(pm8001_ha,
  229. pm8001_printk("pm8001_alloc: PHY:%x\n",
  230. pm8001_ha->chip->n_phy));
  231. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  232. pm8001_phy_init(pm8001_ha, i);
  233. pm8001_ha->port[i].wide_port_phymap = 0;
  234. pm8001_ha->port[i].port_attached = 0;
  235. pm8001_ha->port[i].port_state = 0;
  236. INIT_LIST_HEAD(&pm8001_ha->port[i].list);
  237. }
  238. pm8001_ha->tags = kzalloc(PM8001_MAX_CCB, GFP_KERNEL);
  239. if (!pm8001_ha->tags)
  240. goto err_out;
  241. /* MPI Memory region 1 for AAP Event Log for fw */
  242. pm8001_ha->memoryMap.region[AAP1].num_elements = 1;
  243. pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE;
  244. pm8001_ha->memoryMap.region[AAP1].total_len = PM8001_EVENT_LOG_SIZE;
  245. pm8001_ha->memoryMap.region[AAP1].alignment = 32;
  246. /* MPI Memory region 2 for IOP Event Log for fw */
  247. pm8001_ha->memoryMap.region[IOP].num_elements = 1;
  248. pm8001_ha->memoryMap.region[IOP].element_size = PM8001_EVENT_LOG_SIZE;
  249. pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE;
  250. pm8001_ha->memoryMap.region[IOP].alignment = 32;
  251. for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) {
  252. /* MPI Memory region 3 for consumer Index of inbound queues */
  253. pm8001_ha->memoryMap.region[CI+i].num_elements = 1;
  254. pm8001_ha->memoryMap.region[CI+i].element_size = 4;
  255. pm8001_ha->memoryMap.region[CI+i].total_len = 4;
  256. pm8001_ha->memoryMap.region[CI+i].alignment = 4;
  257. if ((ent->driver_data) != chip_8001) {
  258. /* MPI Memory region 5 inbound queues */
  259. pm8001_ha->memoryMap.region[IB+i].num_elements =
  260. PM8001_MPI_QUEUE;
  261. pm8001_ha->memoryMap.region[IB+i].element_size = 128;
  262. pm8001_ha->memoryMap.region[IB+i].total_len =
  263. PM8001_MPI_QUEUE * 128;
  264. pm8001_ha->memoryMap.region[IB+i].alignment = 128;
  265. } else {
  266. pm8001_ha->memoryMap.region[IB+i].num_elements =
  267. PM8001_MPI_QUEUE;
  268. pm8001_ha->memoryMap.region[IB+i].element_size = 64;
  269. pm8001_ha->memoryMap.region[IB+i].total_len =
  270. PM8001_MPI_QUEUE * 64;
  271. pm8001_ha->memoryMap.region[IB+i].alignment = 64;
  272. }
  273. }
  274. for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) {
  275. /* MPI Memory region 4 for producer Index of outbound queues */
  276. pm8001_ha->memoryMap.region[PI+i].num_elements = 1;
  277. pm8001_ha->memoryMap.region[PI+i].element_size = 4;
  278. pm8001_ha->memoryMap.region[PI+i].total_len = 4;
  279. pm8001_ha->memoryMap.region[PI+i].alignment = 4;
  280. if (ent->driver_data != chip_8001) {
  281. /* MPI Memory region 6 Outbound queues */
  282. pm8001_ha->memoryMap.region[OB+i].num_elements =
  283. PM8001_MPI_QUEUE;
  284. pm8001_ha->memoryMap.region[OB+i].element_size = 128;
  285. pm8001_ha->memoryMap.region[OB+i].total_len =
  286. PM8001_MPI_QUEUE * 128;
  287. pm8001_ha->memoryMap.region[OB+i].alignment = 128;
  288. } else {
  289. /* MPI Memory region 6 Outbound queues */
  290. pm8001_ha->memoryMap.region[OB+i].num_elements =
  291. PM8001_MPI_QUEUE;
  292. pm8001_ha->memoryMap.region[OB+i].element_size = 64;
  293. pm8001_ha->memoryMap.region[OB+i].total_len =
  294. PM8001_MPI_QUEUE * 64;
  295. pm8001_ha->memoryMap.region[OB+i].alignment = 64;
  296. }
  297. }
  298. /* Memory region write DMA*/
  299. pm8001_ha->memoryMap.region[NVMD].num_elements = 1;
  300. pm8001_ha->memoryMap.region[NVMD].element_size = 4096;
  301. pm8001_ha->memoryMap.region[NVMD].total_len = 4096;
  302. /* Memory region for devices*/
  303. pm8001_ha->memoryMap.region[DEV_MEM].num_elements = 1;
  304. pm8001_ha->memoryMap.region[DEV_MEM].element_size = PM8001_MAX_DEVICES *
  305. sizeof(struct pm8001_device);
  306. pm8001_ha->memoryMap.region[DEV_MEM].total_len = PM8001_MAX_DEVICES *
  307. sizeof(struct pm8001_device);
  308. /* Memory region for ccb_info*/
  309. pm8001_ha->memoryMap.region[CCB_MEM].num_elements = 1;
  310. pm8001_ha->memoryMap.region[CCB_MEM].element_size = PM8001_MAX_CCB *
  311. sizeof(struct pm8001_ccb_info);
  312. pm8001_ha->memoryMap.region[CCB_MEM].total_len = PM8001_MAX_CCB *
  313. sizeof(struct pm8001_ccb_info);
  314. /* Memory region for fw flash */
  315. pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096;
  316. pm8001_ha->memoryMap.region[FORENSIC_MEM].num_elements = 1;
  317. pm8001_ha->memoryMap.region[FORENSIC_MEM].total_len = 0x10000;
  318. pm8001_ha->memoryMap.region[FORENSIC_MEM].element_size = 0x10000;
  319. pm8001_ha->memoryMap.region[FORENSIC_MEM].alignment = 0x10000;
  320. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  321. if (pm8001_mem_alloc(pm8001_ha->pdev,
  322. &pm8001_ha->memoryMap.region[i].virt_ptr,
  323. &pm8001_ha->memoryMap.region[i].phys_addr,
  324. &pm8001_ha->memoryMap.region[i].phys_addr_hi,
  325. &pm8001_ha->memoryMap.region[i].phys_addr_lo,
  326. pm8001_ha->memoryMap.region[i].total_len,
  327. pm8001_ha->memoryMap.region[i].alignment) != 0) {
  328. PM8001_FAIL_DBG(pm8001_ha,
  329. pm8001_printk("Mem%d alloc failed\n",
  330. i));
  331. goto err_out;
  332. }
  333. }
  334. pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr;
  335. for (i = 0; i < PM8001_MAX_DEVICES; i++) {
  336. pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
  337. pm8001_ha->devices[i].id = i;
  338. pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
  339. pm8001_ha->devices[i].running_req = 0;
  340. }
  341. pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr;
  342. for (i = 0; i < PM8001_MAX_CCB; i++) {
  343. pm8001_ha->ccb_info[i].ccb_dma_handle =
  344. pm8001_ha->memoryMap.region[CCB_MEM].phys_addr +
  345. i * sizeof(struct pm8001_ccb_info);
  346. pm8001_ha->ccb_info[i].task = NULL;
  347. pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
  348. pm8001_ha->ccb_info[i].device = NULL;
  349. ++pm8001_ha->tags_num;
  350. }
  351. pm8001_ha->flags = PM8001F_INIT_TIME;
  352. /* Initialize tags */
  353. pm8001_tag_init(pm8001_ha);
  354. return 0;
  355. err_out:
  356. return 1;
  357. }
  358. /**
  359. * pm8001_ioremap - remap the pci high physical address to kernal virtual
  360. * address so that we can access them.
  361. * @pm8001_ha:our hba structure.
  362. */
  363. static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
  364. {
  365. u32 bar;
  366. u32 logicalBar = 0;
  367. struct pci_dev *pdev;
  368. pdev = pm8001_ha->pdev;
  369. /* map pci mem (PMC pci base 0-3)*/
  370. for (bar = 0; bar < 6; bar++) {
  371. /*
  372. ** logical BARs for SPC:
  373. ** bar 0 and 1 - logical BAR0
  374. ** bar 2 and 3 - logical BAR1
  375. ** bar4 - logical BAR2
  376. ** bar5 - logical BAR3
  377. ** Skip the appropriate assignments:
  378. */
  379. if ((bar == 1) || (bar == 3))
  380. continue;
  381. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  382. pm8001_ha->io_mem[logicalBar].membase =
  383. pci_resource_start(pdev, bar);
  384. pm8001_ha->io_mem[logicalBar].membase &=
  385. (u32)PCI_BASE_ADDRESS_MEM_MASK;
  386. pm8001_ha->io_mem[logicalBar].memsize =
  387. pci_resource_len(pdev, bar);
  388. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  389. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  390. pm8001_ha->io_mem[logicalBar].memsize);
  391. PM8001_INIT_DBG(pm8001_ha,
  392. pm8001_printk("PCI: bar %d, logicalBar %d ",
  393. bar, logicalBar));
  394. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  395. "base addr %llx virt_addr=%llx len=%d\n",
  396. (u64)pm8001_ha->io_mem[logicalBar].membase,
  397. (u64)(unsigned long)
  398. pm8001_ha->io_mem[logicalBar].memvirtaddr,
  399. pm8001_ha->io_mem[logicalBar].memsize));
  400. } else {
  401. pm8001_ha->io_mem[logicalBar].membase = 0;
  402. pm8001_ha->io_mem[logicalBar].memsize = 0;
  403. pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
  404. }
  405. logicalBar++;
  406. }
  407. return 0;
  408. }
  409. /**
  410. * pm8001_pci_alloc - initialize our ha card structure
  411. * @pdev: pci device.
  412. * @ent: ent
  413. * @shost: scsi host struct which has been initialized before.
  414. */
  415. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  416. const struct pci_device_id *ent,
  417. struct Scsi_Host *shost)
  418. {
  419. struct pm8001_hba_info *pm8001_ha;
  420. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  421. int j;
  422. pm8001_ha = sha->lldd_ha;
  423. if (!pm8001_ha)
  424. return NULL;
  425. pm8001_ha->pdev = pdev;
  426. pm8001_ha->dev = &pdev->dev;
  427. pm8001_ha->chip_id = ent->driver_data;
  428. pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
  429. pm8001_ha->irq = pdev->irq;
  430. pm8001_ha->sas = sha;
  431. pm8001_ha->shost = shost;
  432. pm8001_ha->id = pm8001_id++;
  433. pm8001_ha->logging_level = 0x01;
  434. sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
  435. /* IOMB size is 128 for 8088/89 controllers */
  436. if (pm8001_ha->chip_id != chip_8001)
  437. pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
  438. else
  439. pm8001_ha->iomb_size = IOMB_SIZE_SPC;
  440. #ifdef PM8001_USE_TASKLET
  441. /* Tasklet for non msi-x interrupt handler */
  442. if ((!pdev->msix_cap) || (pm8001_ha->chip_id == chip_8001))
  443. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  444. (unsigned long)&(pm8001_ha->irq_vector[0]));
  445. else
  446. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  447. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  448. (unsigned long)&(pm8001_ha->irq_vector[j]));
  449. #endif
  450. pm8001_ioremap(pm8001_ha);
  451. if (!pm8001_alloc(pm8001_ha, ent))
  452. return pm8001_ha;
  453. pm8001_free(pm8001_ha);
  454. return NULL;
  455. }
  456. /**
  457. * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
  458. * @pdev: pci device.
  459. */
  460. static int pci_go_44(struct pci_dev *pdev)
  461. {
  462. int rc;
  463. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
  464. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
  465. if (rc) {
  466. rc = pci_set_consistent_dma_mask(pdev,
  467. DMA_BIT_MASK(32));
  468. if (rc) {
  469. dev_printk(KERN_ERR, &pdev->dev,
  470. "44-bit DMA enable failed\n");
  471. return rc;
  472. }
  473. }
  474. } else {
  475. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  476. if (rc) {
  477. dev_printk(KERN_ERR, &pdev->dev,
  478. "32-bit DMA enable failed\n");
  479. return rc;
  480. }
  481. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  482. if (rc) {
  483. dev_printk(KERN_ERR, &pdev->dev,
  484. "32-bit consistent DMA enable failed\n");
  485. return rc;
  486. }
  487. }
  488. return rc;
  489. }
  490. /**
  491. * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
  492. * @shost: scsi host which has been allocated outside.
  493. * @chip_info: our ha struct.
  494. */
  495. static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
  496. const struct pm8001_chip_info *chip_info)
  497. {
  498. int phy_nr, port_nr;
  499. struct asd_sas_phy **arr_phy;
  500. struct asd_sas_port **arr_port;
  501. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  502. phy_nr = chip_info->n_phy;
  503. port_nr = phy_nr;
  504. memset(sha, 0x00, sizeof(*sha));
  505. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  506. if (!arr_phy)
  507. goto exit;
  508. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  509. if (!arr_port)
  510. goto exit_free2;
  511. sha->sas_phy = arr_phy;
  512. sha->sas_port = arr_port;
  513. sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
  514. if (!sha->lldd_ha)
  515. goto exit_free1;
  516. shost->transportt = pm8001_stt;
  517. shost->max_id = PM8001_MAX_DEVICES;
  518. shost->max_lun = 8;
  519. shost->max_channel = 0;
  520. shost->unique_id = pm8001_id;
  521. shost->max_cmd_len = 16;
  522. shost->can_queue = PM8001_CAN_QUEUE;
  523. shost->cmd_per_lun = 32;
  524. return 0;
  525. exit_free1:
  526. kfree(arr_port);
  527. exit_free2:
  528. kfree(arr_phy);
  529. exit:
  530. return -1;
  531. }
  532. /**
  533. * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
  534. * @shost: scsi host which has been allocated outside
  535. * @chip_info: our ha struct.
  536. */
  537. static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  538. const struct pm8001_chip_info *chip_info)
  539. {
  540. int i = 0;
  541. struct pm8001_hba_info *pm8001_ha;
  542. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  543. pm8001_ha = sha->lldd_ha;
  544. for (i = 0; i < chip_info->n_phy; i++) {
  545. sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
  546. sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
  547. }
  548. sha->sas_ha_name = DRV_NAME;
  549. sha->dev = pm8001_ha->dev;
  550. sha->lldd_module = THIS_MODULE;
  551. sha->sas_addr = &pm8001_ha->sas_addr[0];
  552. sha->num_phys = chip_info->n_phy;
  553. sha->core.shost = shost;
  554. }
  555. /**
  556. * pm8001_init_sas_add - initialize sas address
  557. * @chip_info: our ha struct.
  558. *
  559. * Currently we just set the fixed SAS address to our HBA,for manufacture,
  560. * it should read from the EEPROM
  561. */
  562. static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
  563. {
  564. u8 i, j;
  565. #ifdef PM8001_READ_VPD
  566. /* For new SPC controllers WWN is stored in flash vpd
  567. * For SPC/SPCve controllers WWN is stored in EEPROM
  568. * For Older SPC WWN is stored in NVMD
  569. */
  570. DECLARE_COMPLETION_ONSTACK(completion);
  571. struct pm8001_ioctl_payload payload;
  572. u16 deviceid;
  573. int rc;
  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 || deviceid == 0x0042) {
  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. if (!payload.func_specific) {
  591. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("mem alloc fail\n"));
  592. return;
  593. }
  594. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  595. if (rc) {
  596. kfree(payload.func_specific);
  597. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
  598. return;
  599. }
  600. wait_for_completion(&completion);
  601. for (i = 0, j = 0; i <= 7; i++, j++) {
  602. if (pm8001_ha->chip_id == chip_8001) {
  603. if (deviceid == 0x8081)
  604. pm8001_ha->sas_addr[j] =
  605. payload.func_specific[0x704 + i];
  606. else if (deviceid == 0x0042)
  607. pm8001_ha->sas_addr[j] =
  608. payload.func_specific[0x010 + i];
  609. } else
  610. pm8001_ha->sas_addr[j] =
  611. payload.func_specific[0x804 + i];
  612. }
  613. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  614. memcpy(&pm8001_ha->phy[i].dev_sas_addr,
  615. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  616. PM8001_INIT_DBG(pm8001_ha,
  617. pm8001_printk("phy %d sas_addr = %016llx\n", i,
  618. pm8001_ha->phy[i].dev_sas_addr));
  619. }
  620. kfree(payload.func_specific);
  621. #else
  622. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  623. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  624. pm8001_ha->phy[i].dev_sas_addr =
  625. cpu_to_be64((u64)
  626. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  627. }
  628. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  629. SAS_ADDR_SIZE);
  630. #endif
  631. }
  632. /*
  633. * pm8001_get_phy_settings_info : Read phy setting values.
  634. * @pm8001_ha : our hba.
  635. */
  636. static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
  637. {
  638. #ifdef PM8001_READ_VPD
  639. /*OPTION ROM FLASH read for the SPC cards */
  640. DECLARE_COMPLETION_ONSTACK(completion);
  641. struct pm8001_ioctl_payload payload;
  642. int rc;
  643. pm8001_ha->nvmd_completion = &completion;
  644. /* SAS ADDRESS read from flash / EEPROM */
  645. payload.minor_function = 6;
  646. payload.offset = 0;
  647. payload.length = 4096;
  648. payload.func_specific = kzalloc(4096, GFP_KERNEL);
  649. if (!payload.func_specific)
  650. return -ENOMEM;
  651. /* Read phy setting values from flash */
  652. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  653. if (rc) {
  654. kfree(payload.func_specific);
  655. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
  656. return -ENOMEM;
  657. }
  658. wait_for_completion(&completion);
  659. pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
  660. kfree(payload.func_specific);
  661. #endif
  662. return 0;
  663. }
  664. #ifdef PM8001_USE_MSIX
  665. /**
  666. * pm8001_setup_msix - enable MSI-X interrupt
  667. * @chip_info: our ha struct.
  668. * @irq_handler: irq_handler
  669. */
  670. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  671. {
  672. u32 i = 0, j = 0;
  673. u32 number_of_intr;
  674. int flag = 0;
  675. u32 max_entry;
  676. int rc;
  677. static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
  678. /* SPCv controllers supports 64 msi-x */
  679. if (pm8001_ha->chip_id == chip_8001) {
  680. number_of_intr = 1;
  681. } else {
  682. number_of_intr = PM8001_MAX_MSIX_VEC;
  683. flag &= ~IRQF_SHARED;
  684. }
  685. max_entry = sizeof(pm8001_ha->msix_entries) /
  686. sizeof(pm8001_ha->msix_entries[0]);
  687. for (i = 0; i < max_entry ; i++)
  688. pm8001_ha->msix_entries[i].entry = i;
  689. rc = pci_enable_msix_exact(pm8001_ha->pdev, pm8001_ha->msix_entries,
  690. number_of_intr);
  691. pm8001_ha->number_of_intr = number_of_intr;
  692. if (rc)
  693. return rc;
  694. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  695. "pci_enable_msix_exact request ret:%d no of intr %d\n",
  696. rc, pm8001_ha->number_of_intr));
  697. for (i = 0; i < number_of_intr; i++) {
  698. snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
  699. DRV_NAME"%d", i);
  700. pm8001_ha->irq_vector[i].irq_id = i;
  701. pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
  702. rc = request_irq(pm8001_ha->msix_entries[i].vector,
  703. pm8001_interrupt_handler_msix, flag,
  704. intr_drvname[i], &(pm8001_ha->irq_vector[i]));
  705. if (rc) {
  706. for (j = 0; j < i; j++) {
  707. free_irq(pm8001_ha->msix_entries[j].vector,
  708. &(pm8001_ha->irq_vector[i]));
  709. }
  710. pci_disable_msix(pm8001_ha->pdev);
  711. break;
  712. }
  713. }
  714. return rc;
  715. }
  716. #endif
  717. /**
  718. * pm8001_request_irq - register interrupt
  719. * @chip_info: our ha struct.
  720. */
  721. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  722. {
  723. struct pci_dev *pdev;
  724. int rc;
  725. pdev = pm8001_ha->pdev;
  726. #ifdef PM8001_USE_MSIX
  727. if (pdev->msix_cap)
  728. return pm8001_setup_msix(pm8001_ha);
  729. else {
  730. PM8001_INIT_DBG(pm8001_ha,
  731. pm8001_printk("MSIX not supported!!!\n"));
  732. goto intx;
  733. }
  734. #endif
  735. intx:
  736. /* initialize the INT-X interrupt */
  737. rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
  738. DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
  739. return rc;
  740. }
  741. /**
  742. * pm8001_pci_probe - probe supported device
  743. * @pdev: pci device which kernel has been prepared for.
  744. * @ent: pci device id
  745. *
  746. * This function is the main initialization function, when register a new
  747. * pci driver it is invoked, all struct an hardware initilization should be done
  748. * here, also, register interrupt
  749. */
  750. static int pm8001_pci_probe(struct pci_dev *pdev,
  751. const struct pci_device_id *ent)
  752. {
  753. unsigned int rc;
  754. u32 pci_reg;
  755. u8 i = 0;
  756. struct pm8001_hba_info *pm8001_ha;
  757. struct Scsi_Host *shost = NULL;
  758. const struct pm8001_chip_info *chip;
  759. dev_printk(KERN_INFO, &pdev->dev,
  760. "pm80xx: driver version %s\n", DRV_VERSION);
  761. rc = pci_enable_device(pdev);
  762. if (rc)
  763. goto err_out_enable;
  764. pci_set_master(pdev);
  765. /*
  766. * Enable pci slot busmaster by setting pci command register.
  767. * This is required by FW for Cyclone card.
  768. */
  769. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  770. pci_reg |= 0x157;
  771. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  772. rc = pci_request_regions(pdev, DRV_NAME);
  773. if (rc)
  774. goto err_out_disable;
  775. rc = pci_go_44(pdev);
  776. if (rc)
  777. goto err_out_regions;
  778. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  779. if (!shost) {
  780. rc = -ENOMEM;
  781. goto err_out_regions;
  782. }
  783. chip = &pm8001_chips[ent->driver_data];
  784. SHOST_TO_SAS_HA(shost) =
  785. kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  786. if (!SHOST_TO_SAS_HA(shost)) {
  787. rc = -ENOMEM;
  788. goto err_out_free_host;
  789. }
  790. rc = pm8001_prep_sas_ha_init(shost, chip);
  791. if (rc) {
  792. rc = -ENOMEM;
  793. goto err_out_free;
  794. }
  795. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  796. /* ent->driver variable is used to differentiate between controllers */
  797. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  798. if (!pm8001_ha) {
  799. rc = -ENOMEM;
  800. goto err_out_free;
  801. }
  802. list_add_tail(&pm8001_ha->list, &hba_list);
  803. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  804. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  805. if (rc) {
  806. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  807. "chip_init failed [ret: %d]\n", rc));
  808. goto err_out_ha_free;
  809. }
  810. rc = scsi_add_host(shost, &pdev->dev);
  811. if (rc)
  812. goto err_out_ha_free;
  813. rc = pm8001_request_irq(pm8001_ha);
  814. if (rc) {
  815. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  816. "pm8001_request_irq failed [ret: %d]\n", rc));
  817. goto err_out_shost;
  818. }
  819. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  820. if (pm8001_ha->chip_id != chip_8001) {
  821. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  822. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  823. /* setup thermal configuration. */
  824. pm80xx_set_thermal_config(pm8001_ha);
  825. }
  826. pm8001_init_sas_add(pm8001_ha);
  827. /* phy setting support for motherboard controller */
  828. if (pdev->subsystem_vendor != PCI_VENDOR_ID_ADAPTEC2 &&
  829. pdev->subsystem_vendor != 0) {
  830. rc = pm8001_get_phy_settings_info(pm8001_ha);
  831. if (rc)
  832. goto err_out_shost;
  833. }
  834. pm8001_post_sas_ha_init(shost, chip);
  835. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  836. if (rc)
  837. goto err_out_shost;
  838. scsi_scan_host(pm8001_ha->shost);
  839. return 0;
  840. err_out_shost:
  841. scsi_remove_host(pm8001_ha->shost);
  842. err_out_ha_free:
  843. pm8001_free(pm8001_ha);
  844. err_out_free:
  845. kfree(SHOST_TO_SAS_HA(shost));
  846. err_out_free_host:
  847. kfree(shost);
  848. err_out_regions:
  849. pci_release_regions(pdev);
  850. err_out_disable:
  851. pci_disable_device(pdev);
  852. err_out_enable:
  853. return rc;
  854. }
  855. static void pm8001_pci_remove(struct pci_dev *pdev)
  856. {
  857. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  858. struct pm8001_hba_info *pm8001_ha;
  859. int i, j;
  860. pm8001_ha = sha->lldd_ha;
  861. sas_unregister_ha(sha);
  862. sas_remove_host(pm8001_ha->shost);
  863. list_del(&pm8001_ha->list);
  864. scsi_remove_host(pm8001_ha->shost);
  865. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  866. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  867. #ifdef PM8001_USE_MSIX
  868. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  869. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  870. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  871. free_irq(pm8001_ha->msix_entries[i].vector,
  872. &(pm8001_ha->irq_vector[i]));
  873. pci_disable_msix(pdev);
  874. #else
  875. free_irq(pm8001_ha->irq, sha);
  876. #endif
  877. #ifdef PM8001_USE_TASKLET
  878. /* For non-msix and msix interrupts */
  879. if ((!pdev->msix_cap) || (pm8001_ha->chip_id == chip_8001))
  880. tasklet_kill(&pm8001_ha->tasklet[0]);
  881. else
  882. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  883. tasklet_kill(&pm8001_ha->tasklet[j]);
  884. #endif
  885. pm8001_free(pm8001_ha);
  886. kfree(sha->sas_phy);
  887. kfree(sha->sas_port);
  888. kfree(sha);
  889. pci_release_regions(pdev);
  890. pci_disable_device(pdev);
  891. }
  892. /**
  893. * pm8001_pci_suspend - power management suspend main entry point
  894. * @pdev: PCI device struct
  895. * @state: PM state change to (usually PCI_D3)
  896. *
  897. * Returns 0 success, anything else error.
  898. */
  899. static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  900. {
  901. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  902. struct pm8001_hba_info *pm8001_ha;
  903. int i, j;
  904. u32 device_state;
  905. pm8001_ha = sha->lldd_ha;
  906. sas_suspend_ha(sha);
  907. flush_workqueue(pm8001_wq);
  908. scsi_block_requests(pm8001_ha->shost);
  909. if (!pdev->pm_cap) {
  910. dev_err(&pdev->dev, " PCI PM not supported\n");
  911. return -ENODEV;
  912. }
  913. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  914. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  915. #ifdef PM8001_USE_MSIX
  916. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  917. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  918. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  919. free_irq(pm8001_ha->msix_entries[i].vector,
  920. &(pm8001_ha->irq_vector[i]));
  921. pci_disable_msix(pdev);
  922. #else
  923. free_irq(pm8001_ha->irq, sha);
  924. #endif
  925. #ifdef PM8001_USE_TASKLET
  926. /* For non-msix and msix interrupts */
  927. if ((!pdev->msix_cap) || (pm8001_ha->chip_id == chip_8001))
  928. tasklet_kill(&pm8001_ha->tasklet[0]);
  929. else
  930. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  931. tasklet_kill(&pm8001_ha->tasklet[j]);
  932. #endif
  933. device_state = pci_choose_state(pdev, state);
  934. pm8001_printk("pdev=0x%p, slot=%s, entering "
  935. "operating state [D%d]\n", pdev,
  936. pm8001_ha->name, device_state);
  937. pci_save_state(pdev);
  938. pci_disable_device(pdev);
  939. pci_set_power_state(pdev, device_state);
  940. return 0;
  941. }
  942. /**
  943. * pm8001_pci_resume - power management resume main entry point
  944. * @pdev: PCI device struct
  945. *
  946. * Returns 0 success, anything else error.
  947. */
  948. static int pm8001_pci_resume(struct pci_dev *pdev)
  949. {
  950. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  951. struct pm8001_hba_info *pm8001_ha;
  952. int rc;
  953. u8 i = 0, j;
  954. u32 device_state;
  955. DECLARE_COMPLETION_ONSTACK(completion);
  956. pm8001_ha = sha->lldd_ha;
  957. device_state = pdev->current_state;
  958. pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
  959. "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
  960. pci_set_power_state(pdev, PCI_D0);
  961. pci_enable_wake(pdev, PCI_D0, 0);
  962. pci_restore_state(pdev);
  963. rc = pci_enable_device(pdev);
  964. if (rc) {
  965. pm8001_printk("slot=%s Enable device failed during resume\n",
  966. pm8001_ha->name);
  967. goto err_out_enable;
  968. }
  969. pci_set_master(pdev);
  970. rc = pci_go_44(pdev);
  971. if (rc)
  972. goto err_out_disable;
  973. sas_prep_resume_ha(sha);
  974. /* chip soft rst only for spc */
  975. if (pm8001_ha->chip_id == chip_8001) {
  976. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  977. PM8001_INIT_DBG(pm8001_ha,
  978. pm8001_printk("chip soft reset successful\n"));
  979. }
  980. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  981. if (rc)
  982. goto err_out_disable;
  983. /* disable all the interrupt bits */
  984. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  985. rc = pm8001_request_irq(pm8001_ha);
  986. if (rc)
  987. goto err_out_disable;
  988. #ifdef PM8001_USE_TASKLET
  989. /* Tasklet for non msi-x interrupt handler */
  990. if ((!pdev->msix_cap) || (pm8001_ha->chip_id == chip_8001))
  991. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  992. (unsigned long)&(pm8001_ha->irq_vector[0]));
  993. else
  994. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  995. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  996. (unsigned long)&(pm8001_ha->irq_vector[j]));
  997. #endif
  998. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  999. if (pm8001_ha->chip_id != chip_8001) {
  1000. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  1001. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  1002. }
  1003. pm8001_ha->flags = PM8001F_RUN_TIME;
  1004. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  1005. pm8001_ha->phy[i].enable_completion = &completion;
  1006. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
  1007. wait_for_completion(&completion);
  1008. }
  1009. sas_resume_ha(sha);
  1010. return 0;
  1011. err_out_disable:
  1012. scsi_remove_host(pm8001_ha->shost);
  1013. pci_disable_device(pdev);
  1014. err_out_enable:
  1015. return rc;
  1016. }
  1017. /* update of pci device, vendor id and driver data with
  1018. * unique value for each of the controller
  1019. */
  1020. static struct pci_device_id pm8001_pci_table[] = {
  1021. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  1022. { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
  1023. /* Support for SPC/SPCv/SPCve controllers */
  1024. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  1025. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  1026. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  1027. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  1028. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  1029. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  1030. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  1031. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  1032. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  1033. { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
  1034. { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
  1035. { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
  1036. { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
  1037. { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
  1038. { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
  1039. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1040. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  1041. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1042. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  1043. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1044. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  1045. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1046. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  1047. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1048. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  1049. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1050. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  1051. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1052. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  1053. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1054. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  1055. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1056. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  1057. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1058. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  1059. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1060. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
  1061. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1062. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
  1063. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1064. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
  1065. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1066. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
  1067. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1068. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
  1069. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1070. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
  1071. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1072. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
  1073. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1074. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
  1075. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1076. PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
  1077. {} /* terminate list */
  1078. };
  1079. static struct pci_driver pm8001_pci_driver = {
  1080. .name = DRV_NAME,
  1081. .id_table = pm8001_pci_table,
  1082. .probe = pm8001_pci_probe,
  1083. .remove = pm8001_pci_remove,
  1084. .suspend = pm8001_pci_suspend,
  1085. .resume = pm8001_pci_resume,
  1086. };
  1087. /**
  1088. * pm8001_init - initialize scsi transport template
  1089. */
  1090. static int __init pm8001_init(void)
  1091. {
  1092. int rc = -ENOMEM;
  1093. pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
  1094. if (!pm8001_wq)
  1095. goto err;
  1096. pm8001_id = 0;
  1097. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  1098. if (!pm8001_stt)
  1099. goto err_wq;
  1100. rc = pci_register_driver(&pm8001_pci_driver);
  1101. if (rc)
  1102. goto err_tp;
  1103. return 0;
  1104. err_tp:
  1105. sas_release_transport(pm8001_stt);
  1106. err_wq:
  1107. destroy_workqueue(pm8001_wq);
  1108. err:
  1109. return rc;
  1110. }
  1111. static void __exit pm8001_exit(void)
  1112. {
  1113. pci_unregister_driver(&pm8001_pci_driver);
  1114. sas_release_transport(pm8001_stt);
  1115. destroy_workqueue(pm8001_wq);
  1116. }
  1117. module_init(pm8001_init);
  1118. module_exit(pm8001_exit);
  1119. MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
  1120. MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>");
  1121. MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
  1122. MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
  1123. MODULE_DESCRIPTION(
  1124. "PMC-Sierra PM8001/8081/8088/8089/8074/8076/8077 "
  1125. "SAS/SATA controller driver");
  1126. MODULE_VERSION(DRV_VERSION);
  1127. MODULE_LICENSE("GPL");
  1128. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);