pm8001_init.c 36 KB

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