pm8001_init.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  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. [chip_8006] = {0, 16, &pm8001_80xx_dispatch,},
  58. [chip_8070] = {0, 8, &pm8001_80xx_dispatch,},
  59. [chip_8072] = {0, 16, &pm8001_80xx_dispatch,},
  60. };
  61. static int pm8001_id;
  62. LIST_HEAD(hba_list);
  63. struct workqueue_struct *pm8001_wq;
  64. /**
  65. * The main structure which LLDD must register for scsi core.
  66. */
  67. static struct scsi_host_template pm8001_sht = {
  68. .module = THIS_MODULE,
  69. .name = DRV_NAME,
  70. .queuecommand = sas_queuecommand,
  71. .target_alloc = sas_target_alloc,
  72. .slave_configure = sas_slave_configure,
  73. .scan_finished = pm8001_scan_finished,
  74. .scan_start = pm8001_scan_start,
  75. .change_queue_depth = sas_change_queue_depth,
  76. .bios_param = sas_bios_param,
  77. .can_queue = 1,
  78. .this_id = -1,
  79. .sg_tablesize = SG_ALL,
  80. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  81. .use_clustering = ENABLE_CLUSTERING,
  82. .eh_device_reset_handler = sas_eh_device_reset_handler,
  83. .eh_target_reset_handler = sas_eh_target_reset_handler,
  84. .target_destroy = sas_target_destroy,
  85. .ioctl = sas_ioctl,
  86. .shost_attrs = pm8001_host_attrs,
  87. .track_queue_depth = 1,
  88. };
  89. /**
  90. * Sas layer call this function to execute specific task.
  91. */
  92. static struct sas_domain_function_template pm8001_transport_ops = {
  93. .lldd_dev_found = pm8001_dev_found,
  94. .lldd_dev_gone = pm8001_dev_gone,
  95. .lldd_execute_task = pm8001_queue_command,
  96. .lldd_control_phy = pm8001_phy_control,
  97. .lldd_abort_task = pm8001_abort_task,
  98. .lldd_abort_task_set = pm8001_abort_task_set,
  99. .lldd_clear_aca = pm8001_clear_aca,
  100. .lldd_clear_task_set = pm8001_clear_task_set,
  101. .lldd_I_T_nexus_reset = pm8001_I_T_nexus_reset,
  102. .lldd_lu_reset = pm8001_lu_reset,
  103. .lldd_query_task = pm8001_query_task,
  104. };
  105. /**
  106. *pm8001_phy_init - initiate our adapter phys
  107. *@pm8001_ha: our hba structure.
  108. *@phy_id: phy id.
  109. */
  110. static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id)
  111. {
  112. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  113. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  114. phy->phy_state = 0;
  115. phy->pm8001_ha = pm8001_ha;
  116. sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0;
  117. sas_phy->class = SAS;
  118. sas_phy->iproto = SAS_PROTOCOL_ALL;
  119. sas_phy->tproto = 0;
  120. sas_phy->type = PHY_TYPE_PHYSICAL;
  121. sas_phy->role = PHY_ROLE_INITIATOR;
  122. sas_phy->oob_mode = OOB_NOT_CONNECTED;
  123. sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
  124. sas_phy->id = phy_id;
  125. sas_phy->sas_addr = (u8 *)&phy->dev_sas_addr;
  126. sas_phy->frame_rcvd = &phy->frame_rcvd[0];
  127. sas_phy->ha = (struct sas_ha_struct *)pm8001_ha->shost->hostdata;
  128. sas_phy->lldd_phy = phy;
  129. }
  130. /**
  131. *pm8001_free - free hba
  132. *@pm8001_ha: our hba structure.
  133. *
  134. */
  135. static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
  136. {
  137. int i;
  138. if (!pm8001_ha)
  139. return;
  140. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  141. if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
  142. pci_free_consistent(pm8001_ha->pdev,
  143. (pm8001_ha->memoryMap.region[i].total_len +
  144. pm8001_ha->memoryMap.region[i].alignment),
  145. pm8001_ha->memoryMap.region[i].virt_ptr,
  146. pm8001_ha->memoryMap.region[i].phys_addr);
  147. }
  148. }
  149. PM8001_CHIP_DISP->chip_iounmap(pm8001_ha);
  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].memsize =
  385. pci_resource_len(pdev, bar);
  386. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  387. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  388. pm8001_ha->io_mem[logicalBar].memsize);
  389. PM8001_INIT_DBG(pm8001_ha,
  390. pm8001_printk("PCI: bar %d, logicalBar %d ",
  391. bar, logicalBar));
  392. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  393. "base addr %llx virt_addr=%llx len=%d\n",
  394. (u64)pm8001_ha->io_mem[logicalBar].membase,
  395. (u64)(unsigned long)
  396. pm8001_ha->io_mem[logicalBar].memvirtaddr,
  397. pm8001_ha->io_mem[logicalBar].memsize));
  398. } else {
  399. pm8001_ha->io_mem[logicalBar].membase = 0;
  400. pm8001_ha->io_mem[logicalBar].memsize = 0;
  401. pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
  402. }
  403. logicalBar++;
  404. }
  405. return 0;
  406. }
  407. /**
  408. * pm8001_pci_alloc - initialize our ha card structure
  409. * @pdev: pci device.
  410. * @ent: ent
  411. * @shost: scsi host struct which has been initialized before.
  412. */
  413. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  414. const struct pci_device_id *ent,
  415. struct Scsi_Host *shost)
  416. {
  417. struct pm8001_hba_info *pm8001_ha;
  418. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  419. int j;
  420. pm8001_ha = sha->lldd_ha;
  421. if (!pm8001_ha)
  422. return NULL;
  423. pm8001_ha->pdev = pdev;
  424. pm8001_ha->dev = &pdev->dev;
  425. pm8001_ha->chip_id = ent->driver_data;
  426. pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
  427. pm8001_ha->irq = pdev->irq;
  428. pm8001_ha->sas = sha;
  429. pm8001_ha->shost = shost;
  430. pm8001_ha->id = pm8001_id++;
  431. pm8001_ha->logging_level = 0x01;
  432. sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
  433. /* IOMB size is 128 for 8088/89 controllers */
  434. if (pm8001_ha->chip_id != chip_8001)
  435. pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
  436. else
  437. pm8001_ha->iomb_size = IOMB_SIZE_SPC;
  438. #ifdef PM8001_USE_TASKLET
  439. /* Tasklet for non msi-x interrupt handler */
  440. if ((!pdev->msix_cap || !pci_msi_enabled())
  441. || (pm8001_ha->chip_id == chip_8001))
  442. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  443. (unsigned long)&(pm8001_ha->irq_vector[0]));
  444. else
  445. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  446. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  447. (unsigned long)&(pm8001_ha->irq_vector[j]));
  448. #endif
  449. pm8001_ioremap(pm8001_ha);
  450. if (!pm8001_alloc(pm8001_ha, ent))
  451. return pm8001_ha;
  452. pm8001_free(pm8001_ha);
  453. return NULL;
  454. }
  455. /**
  456. * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
  457. * @pdev: pci device.
  458. */
  459. static int pci_go_44(struct pci_dev *pdev)
  460. {
  461. int rc;
  462. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
  463. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
  464. if (rc) {
  465. rc = pci_set_consistent_dma_mask(pdev,
  466. DMA_BIT_MASK(32));
  467. if (rc) {
  468. dev_printk(KERN_ERR, &pdev->dev,
  469. "44-bit DMA enable failed\n");
  470. return rc;
  471. }
  472. }
  473. } else {
  474. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  475. if (rc) {
  476. dev_printk(KERN_ERR, &pdev->dev,
  477. "32-bit DMA enable failed\n");
  478. return rc;
  479. }
  480. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  481. if (rc) {
  482. dev_printk(KERN_ERR, &pdev->dev,
  483. "32-bit consistent DMA enable failed\n");
  484. return rc;
  485. }
  486. }
  487. return rc;
  488. }
  489. /**
  490. * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
  491. * @shost: scsi host which has been allocated outside.
  492. * @chip_info: our ha struct.
  493. */
  494. static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
  495. const struct pm8001_chip_info *chip_info)
  496. {
  497. int phy_nr, port_nr;
  498. struct asd_sas_phy **arr_phy;
  499. struct asd_sas_port **arr_port;
  500. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  501. phy_nr = chip_info->n_phy;
  502. port_nr = phy_nr;
  503. memset(sha, 0x00, sizeof(*sha));
  504. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  505. if (!arr_phy)
  506. goto exit;
  507. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  508. if (!arr_port)
  509. goto exit_free2;
  510. sha->sas_phy = arr_phy;
  511. sha->sas_port = arr_port;
  512. sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
  513. if (!sha->lldd_ha)
  514. goto exit_free1;
  515. shost->transportt = pm8001_stt;
  516. shost->max_id = PM8001_MAX_DEVICES;
  517. shost->max_lun = 8;
  518. shost->max_channel = 0;
  519. shost->unique_id = pm8001_id;
  520. shost->max_cmd_len = 16;
  521. shost->can_queue = PM8001_CAN_QUEUE;
  522. shost->cmd_per_lun = 32;
  523. return 0;
  524. exit_free1:
  525. kfree(arr_port);
  526. exit_free2:
  527. kfree(arr_phy);
  528. exit:
  529. return -1;
  530. }
  531. /**
  532. * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
  533. * @shost: scsi host which has been allocated outside
  534. * @chip_info: our ha struct.
  535. */
  536. static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  537. const struct pm8001_chip_info *chip_info)
  538. {
  539. int i = 0;
  540. struct pm8001_hba_info *pm8001_ha;
  541. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  542. pm8001_ha = sha->lldd_ha;
  543. for (i = 0; i < chip_info->n_phy; i++) {
  544. sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
  545. sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
  546. sha->sas_phy[i]->sas_addr =
  547. (u8 *)&pm8001_ha->phy[i].dev_sas_addr;
  548. }
  549. sha->sas_ha_name = DRV_NAME;
  550. sha->dev = pm8001_ha->dev;
  551. sha->strict_wide_ports = 1;
  552. sha->lldd_module = THIS_MODULE;
  553. sha->sas_addr = &pm8001_ha->sas_addr[0];
  554. sha->num_phys = chip_info->n_phy;
  555. sha->core.shost = shost;
  556. }
  557. /**
  558. * pm8001_init_sas_add - initialize sas address
  559. * @chip_info: our ha struct.
  560. *
  561. * Currently we just set the fixed SAS address to our HBA,for manufacture,
  562. * it should read from the EEPROM
  563. */
  564. static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
  565. {
  566. u8 i, j;
  567. u8 sas_add[8];
  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 if ((pm8001_ha->chip_id == chip_8070 ||
  588. pm8001_ha->chip_id == chip_8072) &&
  589. pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
  590. payload.minor_function = 4;
  591. payload.length = 4096;
  592. } else {
  593. payload.minor_function = 1;
  594. payload.length = 4096;
  595. }
  596. payload.offset = 0;
  597. payload.func_specific = kzalloc(payload.length, GFP_KERNEL);
  598. if (!payload.func_specific) {
  599. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("mem alloc fail\n"));
  600. return;
  601. }
  602. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  603. if (rc) {
  604. kfree(payload.func_specific);
  605. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
  606. return;
  607. }
  608. wait_for_completion(&completion);
  609. for (i = 0, j = 0; i <= 7; i++, j++) {
  610. if (pm8001_ha->chip_id == chip_8001) {
  611. if (deviceid == 0x8081)
  612. pm8001_ha->sas_addr[j] =
  613. payload.func_specific[0x704 + i];
  614. else if (deviceid == 0x0042)
  615. pm8001_ha->sas_addr[j] =
  616. payload.func_specific[0x010 + i];
  617. } else if ((pm8001_ha->chip_id == chip_8070 ||
  618. pm8001_ha->chip_id == chip_8072) &&
  619. pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
  620. pm8001_ha->sas_addr[j] =
  621. payload.func_specific[0x010 + i];
  622. } else
  623. pm8001_ha->sas_addr[j] =
  624. payload.func_specific[0x804 + i];
  625. }
  626. memcpy(sas_add, pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  627. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  628. if (i && ((i % 4) == 0))
  629. sas_add[7] = sas_add[7] + 4;
  630. memcpy(&pm8001_ha->phy[i].dev_sas_addr,
  631. sas_add, SAS_ADDR_SIZE);
  632. PM8001_INIT_DBG(pm8001_ha,
  633. pm8001_printk("phy %d sas_addr = %016llx\n", i,
  634. pm8001_ha->phy[i].dev_sas_addr));
  635. }
  636. kfree(payload.func_specific);
  637. #else
  638. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  639. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  640. pm8001_ha->phy[i].dev_sas_addr =
  641. cpu_to_be64((u64)
  642. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  643. }
  644. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  645. SAS_ADDR_SIZE);
  646. #endif
  647. }
  648. /*
  649. * pm8001_get_phy_settings_info : Read phy setting values.
  650. * @pm8001_ha : our hba.
  651. */
  652. static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
  653. {
  654. #ifdef PM8001_READ_VPD
  655. /*OPTION ROM FLASH read for the SPC cards */
  656. DECLARE_COMPLETION_ONSTACK(completion);
  657. struct pm8001_ioctl_payload payload;
  658. int rc;
  659. pm8001_ha->nvmd_completion = &completion;
  660. /* SAS ADDRESS read from flash / EEPROM */
  661. payload.minor_function = 6;
  662. payload.offset = 0;
  663. payload.length = 4096;
  664. payload.func_specific = kzalloc(4096, GFP_KERNEL);
  665. if (!payload.func_specific)
  666. return -ENOMEM;
  667. /* Read phy setting values from flash */
  668. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  669. if (rc) {
  670. kfree(payload.func_specific);
  671. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
  672. return -ENOMEM;
  673. }
  674. wait_for_completion(&completion);
  675. pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
  676. kfree(payload.func_specific);
  677. #endif
  678. return 0;
  679. }
  680. struct pm8001_mpi3_phy_pg_trx_config {
  681. u32 LaneLosCfg;
  682. u32 LanePgaCfg1;
  683. u32 LanePisoCfg1;
  684. u32 LanePisoCfg2;
  685. u32 LanePisoCfg3;
  686. u32 LanePisoCfg4;
  687. u32 LanePisoCfg5;
  688. u32 LanePisoCfg6;
  689. u32 LaneBctCtrl;
  690. };
  691. /**
  692. * pm8001_get_internal_phy_settings : Retrieves the internal PHY settings
  693. * @pm8001_ha : our adapter
  694. * @phycfg : PHY config page to populate
  695. */
  696. static
  697. void pm8001_get_internal_phy_settings(struct pm8001_hba_info *pm8001_ha,
  698. struct pm8001_mpi3_phy_pg_trx_config *phycfg)
  699. {
  700. phycfg->LaneLosCfg = 0x00000132;
  701. phycfg->LanePgaCfg1 = 0x00203949;
  702. phycfg->LanePisoCfg1 = 0x000000FF;
  703. phycfg->LanePisoCfg2 = 0xFF000001;
  704. phycfg->LanePisoCfg3 = 0xE7011300;
  705. phycfg->LanePisoCfg4 = 0x631C40C0;
  706. phycfg->LanePisoCfg5 = 0xF8102036;
  707. phycfg->LanePisoCfg6 = 0xF74A1000;
  708. phycfg->LaneBctCtrl = 0x00FB33F8;
  709. }
  710. /**
  711. * pm8001_get_external_phy_settings : Retrieves the external PHY settings
  712. * @pm8001_ha : our adapter
  713. * @phycfg : PHY config page to populate
  714. */
  715. static
  716. void pm8001_get_external_phy_settings(struct pm8001_hba_info *pm8001_ha,
  717. struct pm8001_mpi3_phy_pg_trx_config *phycfg)
  718. {
  719. phycfg->LaneLosCfg = 0x00000132;
  720. phycfg->LanePgaCfg1 = 0x00203949;
  721. phycfg->LanePisoCfg1 = 0x000000FF;
  722. phycfg->LanePisoCfg2 = 0xFF000001;
  723. phycfg->LanePisoCfg3 = 0xE7011300;
  724. phycfg->LanePisoCfg4 = 0x63349140;
  725. phycfg->LanePisoCfg5 = 0xF8102036;
  726. phycfg->LanePisoCfg6 = 0xF80D9300;
  727. phycfg->LaneBctCtrl = 0x00FB33F8;
  728. }
  729. /**
  730. * pm8001_get_phy_mask : Retrieves the mask that denotes if a PHY is int/ext
  731. * @pm8001_ha : our adapter
  732. * @phymask : The PHY mask
  733. */
  734. static
  735. void pm8001_get_phy_mask(struct pm8001_hba_info *pm8001_ha, int *phymask)
  736. {
  737. switch (pm8001_ha->pdev->subsystem_device) {
  738. case 0x0070: /* H1280 - 8 external 0 internal */
  739. case 0x0072: /* H12F0 - 16 external 0 internal */
  740. *phymask = 0x0000;
  741. break;
  742. case 0x0071: /* H1208 - 0 external 8 internal */
  743. case 0x0073: /* H120F - 0 external 16 internal */
  744. *phymask = 0xFFFF;
  745. break;
  746. case 0x0080: /* H1244 - 4 external 4 internal */
  747. *phymask = 0x00F0;
  748. break;
  749. case 0x0081: /* H1248 - 4 external 8 internal */
  750. *phymask = 0x0FF0;
  751. break;
  752. case 0x0082: /* H1288 - 8 external 8 internal */
  753. *phymask = 0xFF00;
  754. break;
  755. default:
  756. PM8001_INIT_DBG(pm8001_ha,
  757. pm8001_printk("Unknown subsystem device=0x%.04x",
  758. pm8001_ha->pdev->subsystem_device));
  759. }
  760. }
  761. /**
  762. * pm8001_set_phy_settings_ven_117c_12Gb : Configure ATTO 12Gb PHY settings
  763. * @pm8001_ha : our adapter
  764. */
  765. static
  766. int pm8001_set_phy_settings_ven_117c_12G(struct pm8001_hba_info *pm8001_ha)
  767. {
  768. struct pm8001_mpi3_phy_pg_trx_config phycfg_int;
  769. struct pm8001_mpi3_phy_pg_trx_config phycfg_ext;
  770. int phymask = 0;
  771. int i = 0;
  772. memset(&phycfg_int, 0, sizeof(phycfg_int));
  773. memset(&phycfg_ext, 0, sizeof(phycfg_ext));
  774. pm8001_get_internal_phy_settings(pm8001_ha, &phycfg_int);
  775. pm8001_get_external_phy_settings(pm8001_ha, &phycfg_ext);
  776. pm8001_get_phy_mask(pm8001_ha, &phymask);
  777. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  778. if (phymask & (1 << i)) {/* Internal PHY */
  779. pm8001_set_phy_profile_single(pm8001_ha, i,
  780. sizeof(phycfg_int) / sizeof(u32),
  781. (u32 *)&phycfg_int);
  782. } else { /* External PHY */
  783. pm8001_set_phy_profile_single(pm8001_ha, i,
  784. sizeof(phycfg_ext) / sizeof(u32),
  785. (u32 *)&phycfg_ext);
  786. }
  787. }
  788. return 0;
  789. }
  790. /**
  791. * pm8001_configure_phy_settings : Configures PHY settings based on vendor ID.
  792. * @pm8001_ha : our hba.
  793. */
  794. static int pm8001_configure_phy_settings(struct pm8001_hba_info *pm8001_ha)
  795. {
  796. switch (pm8001_ha->pdev->subsystem_vendor) {
  797. case PCI_VENDOR_ID_ATTO:
  798. if (pm8001_ha->pdev->device == 0x0042) /* 6Gb */
  799. return 0;
  800. else
  801. return pm8001_set_phy_settings_ven_117c_12G(pm8001_ha);
  802. case PCI_VENDOR_ID_ADAPTEC2:
  803. case 0:
  804. return 0;
  805. default:
  806. return pm8001_get_phy_settings_info(pm8001_ha);
  807. }
  808. }
  809. #ifdef PM8001_USE_MSIX
  810. /**
  811. * pm8001_setup_msix - enable MSI-X interrupt
  812. * @chip_info: our ha struct.
  813. * @irq_handler: irq_handler
  814. */
  815. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  816. {
  817. u32 i = 0, j = 0;
  818. u32 number_of_intr;
  819. int flag = 0;
  820. int rc;
  821. static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
  822. /* SPCv controllers supports 64 msi-x */
  823. if (pm8001_ha->chip_id == chip_8001) {
  824. number_of_intr = 1;
  825. } else {
  826. number_of_intr = PM8001_MAX_MSIX_VEC;
  827. flag &= ~IRQF_SHARED;
  828. }
  829. rc = pci_alloc_irq_vectors(pm8001_ha->pdev, number_of_intr,
  830. number_of_intr, PCI_IRQ_MSIX);
  831. if (rc < 0)
  832. return rc;
  833. pm8001_ha->number_of_intr = number_of_intr;
  834. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  835. "pci_alloc_irq_vectors request ret:%d no of intr %d\n",
  836. rc, pm8001_ha->number_of_intr));
  837. for (i = 0; i < number_of_intr; i++) {
  838. snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
  839. DRV_NAME"%d", i);
  840. pm8001_ha->irq_vector[i].irq_id = i;
  841. pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
  842. rc = request_irq(pci_irq_vector(pm8001_ha->pdev, i),
  843. pm8001_interrupt_handler_msix, flag,
  844. intr_drvname[i], &(pm8001_ha->irq_vector[i]));
  845. if (rc) {
  846. for (j = 0; j < i; j++) {
  847. free_irq(pci_irq_vector(pm8001_ha->pdev, i),
  848. &(pm8001_ha->irq_vector[i]));
  849. }
  850. pci_free_irq_vectors(pm8001_ha->pdev);
  851. break;
  852. }
  853. }
  854. return rc;
  855. }
  856. #endif
  857. /**
  858. * pm8001_request_irq - register interrupt
  859. * @chip_info: our ha struct.
  860. */
  861. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  862. {
  863. struct pci_dev *pdev;
  864. int rc;
  865. pdev = pm8001_ha->pdev;
  866. #ifdef PM8001_USE_MSIX
  867. if (pdev->msix_cap && pci_msi_enabled())
  868. return pm8001_setup_msix(pm8001_ha);
  869. else {
  870. PM8001_INIT_DBG(pm8001_ha,
  871. pm8001_printk("MSIX not supported!!!\n"));
  872. goto intx;
  873. }
  874. #endif
  875. intx:
  876. /* initialize the INT-X interrupt */
  877. pm8001_ha->irq_vector[0].irq_id = 0;
  878. pm8001_ha->irq_vector[0].drv_inst = pm8001_ha;
  879. rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
  880. DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
  881. return rc;
  882. }
  883. /**
  884. * pm8001_pci_probe - probe supported device
  885. * @pdev: pci device which kernel has been prepared for.
  886. * @ent: pci device id
  887. *
  888. * This function is the main initialization function, when register a new
  889. * pci driver it is invoked, all struct an hardware initilization should be done
  890. * here, also, register interrupt
  891. */
  892. static int pm8001_pci_probe(struct pci_dev *pdev,
  893. const struct pci_device_id *ent)
  894. {
  895. unsigned int rc;
  896. u32 pci_reg;
  897. u8 i = 0;
  898. struct pm8001_hba_info *pm8001_ha;
  899. struct Scsi_Host *shost = NULL;
  900. const struct pm8001_chip_info *chip;
  901. dev_printk(KERN_INFO, &pdev->dev,
  902. "pm80xx: driver version %s\n", DRV_VERSION);
  903. rc = pci_enable_device(pdev);
  904. if (rc)
  905. goto err_out_enable;
  906. pci_set_master(pdev);
  907. /*
  908. * Enable pci slot busmaster by setting pci command register.
  909. * This is required by FW for Cyclone card.
  910. */
  911. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  912. pci_reg |= 0x157;
  913. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  914. rc = pci_request_regions(pdev, DRV_NAME);
  915. if (rc)
  916. goto err_out_disable;
  917. rc = pci_go_44(pdev);
  918. if (rc)
  919. goto err_out_regions;
  920. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  921. if (!shost) {
  922. rc = -ENOMEM;
  923. goto err_out_regions;
  924. }
  925. chip = &pm8001_chips[ent->driver_data];
  926. SHOST_TO_SAS_HA(shost) =
  927. kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  928. if (!SHOST_TO_SAS_HA(shost)) {
  929. rc = -ENOMEM;
  930. goto err_out_free_host;
  931. }
  932. rc = pm8001_prep_sas_ha_init(shost, chip);
  933. if (rc) {
  934. rc = -ENOMEM;
  935. goto err_out_free;
  936. }
  937. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  938. /* ent->driver variable is used to differentiate between controllers */
  939. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  940. if (!pm8001_ha) {
  941. rc = -ENOMEM;
  942. goto err_out_free;
  943. }
  944. list_add_tail(&pm8001_ha->list, &hba_list);
  945. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  946. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  947. if (rc) {
  948. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  949. "chip_init failed [ret: %d]\n", rc));
  950. goto err_out_ha_free;
  951. }
  952. rc = scsi_add_host(shost, &pdev->dev);
  953. if (rc)
  954. goto err_out_ha_free;
  955. rc = pm8001_request_irq(pm8001_ha);
  956. if (rc) {
  957. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  958. "pm8001_request_irq failed [ret: %d]\n", rc));
  959. goto err_out_shost;
  960. }
  961. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  962. if (pm8001_ha->chip_id != chip_8001) {
  963. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  964. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  965. /* setup thermal configuration. */
  966. pm80xx_set_thermal_config(pm8001_ha);
  967. }
  968. pm8001_init_sas_add(pm8001_ha);
  969. /* phy setting support for motherboard controller */
  970. if (pm8001_configure_phy_settings(pm8001_ha))
  971. goto err_out_shost;
  972. pm8001_post_sas_ha_init(shost, chip);
  973. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  974. if (rc)
  975. goto err_out_shost;
  976. scsi_scan_host(pm8001_ha->shost);
  977. return 0;
  978. err_out_shost:
  979. scsi_remove_host(pm8001_ha->shost);
  980. err_out_ha_free:
  981. pm8001_free(pm8001_ha);
  982. err_out_free:
  983. kfree(SHOST_TO_SAS_HA(shost));
  984. err_out_free_host:
  985. scsi_host_put(shost);
  986. err_out_regions:
  987. pci_release_regions(pdev);
  988. err_out_disable:
  989. pci_disable_device(pdev);
  990. err_out_enable:
  991. return rc;
  992. }
  993. static void pm8001_pci_remove(struct pci_dev *pdev)
  994. {
  995. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  996. struct pm8001_hba_info *pm8001_ha;
  997. int i, j;
  998. pm8001_ha = sha->lldd_ha;
  999. sas_unregister_ha(sha);
  1000. sas_remove_host(pm8001_ha->shost);
  1001. list_del(&pm8001_ha->list);
  1002. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1003. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1004. #ifdef PM8001_USE_MSIX
  1005. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1006. synchronize_irq(pci_irq_vector(pdev, i));
  1007. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1008. free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
  1009. pci_free_irq_vectors(pdev);
  1010. #else
  1011. free_irq(pm8001_ha->irq, sha);
  1012. #endif
  1013. #ifdef PM8001_USE_TASKLET
  1014. /* For non-msix and msix interrupts */
  1015. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1016. (pm8001_ha->chip_id == chip_8001))
  1017. tasklet_kill(&pm8001_ha->tasklet[0]);
  1018. else
  1019. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1020. tasklet_kill(&pm8001_ha->tasklet[j]);
  1021. #endif
  1022. scsi_host_put(pm8001_ha->shost);
  1023. pm8001_free(pm8001_ha);
  1024. kfree(sha->sas_phy);
  1025. kfree(sha->sas_port);
  1026. kfree(sha);
  1027. pci_release_regions(pdev);
  1028. pci_disable_device(pdev);
  1029. }
  1030. /**
  1031. * pm8001_pci_suspend - power management suspend main entry point
  1032. * @pdev: PCI device struct
  1033. * @state: PM state change to (usually PCI_D3)
  1034. *
  1035. * Returns 0 success, anything else error.
  1036. */
  1037. static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1038. {
  1039. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1040. struct pm8001_hba_info *pm8001_ha;
  1041. int i, j;
  1042. u32 device_state;
  1043. pm8001_ha = sha->lldd_ha;
  1044. sas_suspend_ha(sha);
  1045. flush_workqueue(pm8001_wq);
  1046. scsi_block_requests(pm8001_ha->shost);
  1047. if (!pdev->pm_cap) {
  1048. dev_err(&pdev->dev, " PCI PM not supported\n");
  1049. return -ENODEV;
  1050. }
  1051. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1052. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1053. #ifdef PM8001_USE_MSIX
  1054. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1055. synchronize_irq(pci_irq_vector(pdev, i));
  1056. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1057. free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
  1058. pci_free_irq_vectors(pdev);
  1059. #else
  1060. free_irq(pm8001_ha->irq, sha);
  1061. #endif
  1062. #ifdef PM8001_USE_TASKLET
  1063. /* For non-msix and msix interrupts */
  1064. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1065. (pm8001_ha->chip_id == chip_8001))
  1066. tasklet_kill(&pm8001_ha->tasklet[0]);
  1067. else
  1068. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1069. tasklet_kill(&pm8001_ha->tasklet[j]);
  1070. #endif
  1071. device_state = pci_choose_state(pdev, state);
  1072. pm8001_printk("pdev=0x%p, slot=%s, entering "
  1073. "operating state [D%d]\n", pdev,
  1074. pm8001_ha->name, device_state);
  1075. pci_save_state(pdev);
  1076. pci_disable_device(pdev);
  1077. pci_set_power_state(pdev, device_state);
  1078. return 0;
  1079. }
  1080. /**
  1081. * pm8001_pci_resume - power management resume main entry point
  1082. * @pdev: PCI device struct
  1083. *
  1084. * Returns 0 success, anything else error.
  1085. */
  1086. static int pm8001_pci_resume(struct pci_dev *pdev)
  1087. {
  1088. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1089. struct pm8001_hba_info *pm8001_ha;
  1090. int rc;
  1091. u8 i = 0, j;
  1092. u32 device_state;
  1093. DECLARE_COMPLETION_ONSTACK(completion);
  1094. pm8001_ha = sha->lldd_ha;
  1095. device_state = pdev->current_state;
  1096. pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
  1097. "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
  1098. pci_set_power_state(pdev, PCI_D0);
  1099. pci_enable_wake(pdev, PCI_D0, 0);
  1100. pci_restore_state(pdev);
  1101. rc = pci_enable_device(pdev);
  1102. if (rc) {
  1103. pm8001_printk("slot=%s Enable device failed during resume\n",
  1104. pm8001_ha->name);
  1105. goto err_out_enable;
  1106. }
  1107. pci_set_master(pdev);
  1108. rc = pci_go_44(pdev);
  1109. if (rc)
  1110. goto err_out_disable;
  1111. sas_prep_resume_ha(sha);
  1112. /* chip soft rst only for spc */
  1113. if (pm8001_ha->chip_id == chip_8001) {
  1114. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1115. PM8001_INIT_DBG(pm8001_ha,
  1116. pm8001_printk("chip soft reset successful\n"));
  1117. }
  1118. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  1119. if (rc)
  1120. goto err_out_disable;
  1121. /* disable all the interrupt bits */
  1122. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1123. rc = pm8001_request_irq(pm8001_ha);
  1124. if (rc)
  1125. goto err_out_disable;
  1126. #ifdef PM8001_USE_TASKLET
  1127. /* Tasklet for non msi-x interrupt handler */
  1128. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1129. (pm8001_ha->chip_id == chip_8001))
  1130. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  1131. (unsigned long)&(pm8001_ha->irq_vector[0]));
  1132. else
  1133. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1134. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  1135. (unsigned long)&(pm8001_ha->irq_vector[j]));
  1136. #endif
  1137. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  1138. if (pm8001_ha->chip_id != chip_8001) {
  1139. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  1140. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  1141. }
  1142. /* Chip documentation for the 8070 and 8072 SPCv */
  1143. /* states that a 500ms minimum delay is required */
  1144. /* before issuing commands. Otherwise, the firmware */
  1145. /* will enter an unrecoverable state. */
  1146. if (pm8001_ha->chip_id == chip_8070 ||
  1147. pm8001_ha->chip_id == chip_8072) {
  1148. mdelay(500);
  1149. }
  1150. /* Spin up the PHYs */
  1151. pm8001_ha->flags = PM8001F_RUN_TIME;
  1152. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  1153. pm8001_ha->phy[i].enable_completion = &completion;
  1154. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
  1155. wait_for_completion(&completion);
  1156. }
  1157. sas_resume_ha(sha);
  1158. return 0;
  1159. err_out_disable:
  1160. scsi_remove_host(pm8001_ha->shost);
  1161. pci_disable_device(pdev);
  1162. err_out_enable:
  1163. return rc;
  1164. }
  1165. /* update of pci device, vendor id and driver data with
  1166. * unique value for each of the controller
  1167. */
  1168. static struct pci_device_id pm8001_pci_table[] = {
  1169. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  1170. { PCI_VDEVICE(PMC_Sierra, 0x8006), chip_8006 },
  1171. { PCI_VDEVICE(ADAPTEC2, 0x8006), chip_8006 },
  1172. { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
  1173. /* Support for SPC/SPCv/SPCve controllers */
  1174. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  1175. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  1176. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  1177. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  1178. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  1179. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  1180. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  1181. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  1182. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  1183. { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
  1184. { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
  1185. { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
  1186. { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
  1187. { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
  1188. { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
  1189. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1190. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  1191. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1192. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  1193. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1194. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  1195. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1196. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  1197. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1198. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  1199. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1200. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  1201. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1202. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  1203. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1204. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  1205. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1206. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  1207. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1208. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  1209. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1210. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
  1211. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1212. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
  1213. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1214. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
  1215. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1216. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
  1217. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1218. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
  1219. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1220. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
  1221. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1222. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
  1223. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1224. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
  1225. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1226. PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
  1227. { PCI_VENDOR_ID_ATTO, 0x8070,
  1228. PCI_VENDOR_ID_ATTO, 0x0070, 0, 0, chip_8070 },
  1229. { PCI_VENDOR_ID_ATTO, 0x8070,
  1230. PCI_VENDOR_ID_ATTO, 0x0071, 0, 0, chip_8070 },
  1231. { PCI_VENDOR_ID_ATTO, 0x8072,
  1232. PCI_VENDOR_ID_ATTO, 0x0072, 0, 0, chip_8072 },
  1233. { PCI_VENDOR_ID_ATTO, 0x8072,
  1234. PCI_VENDOR_ID_ATTO, 0x0073, 0, 0, chip_8072 },
  1235. { PCI_VENDOR_ID_ATTO, 0x8070,
  1236. PCI_VENDOR_ID_ATTO, 0x0080, 0, 0, chip_8070 },
  1237. { PCI_VENDOR_ID_ATTO, 0x8072,
  1238. PCI_VENDOR_ID_ATTO, 0x0081, 0, 0, chip_8072 },
  1239. { PCI_VENDOR_ID_ATTO, 0x8072,
  1240. PCI_VENDOR_ID_ATTO, 0x0082, 0, 0, chip_8072 },
  1241. {} /* terminate list */
  1242. };
  1243. static struct pci_driver pm8001_pci_driver = {
  1244. .name = DRV_NAME,
  1245. .id_table = pm8001_pci_table,
  1246. .probe = pm8001_pci_probe,
  1247. .remove = pm8001_pci_remove,
  1248. .suspend = pm8001_pci_suspend,
  1249. .resume = pm8001_pci_resume,
  1250. };
  1251. /**
  1252. * pm8001_init - initialize scsi transport template
  1253. */
  1254. static int __init pm8001_init(void)
  1255. {
  1256. int rc = -ENOMEM;
  1257. pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
  1258. if (!pm8001_wq)
  1259. goto err;
  1260. pm8001_id = 0;
  1261. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  1262. if (!pm8001_stt)
  1263. goto err_wq;
  1264. rc = pci_register_driver(&pm8001_pci_driver);
  1265. if (rc)
  1266. goto err_tp;
  1267. return 0;
  1268. err_tp:
  1269. sas_release_transport(pm8001_stt);
  1270. err_wq:
  1271. destroy_workqueue(pm8001_wq);
  1272. err:
  1273. return rc;
  1274. }
  1275. static void __exit pm8001_exit(void)
  1276. {
  1277. pci_unregister_driver(&pm8001_pci_driver);
  1278. sas_release_transport(pm8001_stt);
  1279. destroy_workqueue(pm8001_wq);
  1280. }
  1281. module_init(pm8001_init);
  1282. module_exit(pm8001_exit);
  1283. MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
  1284. MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>");
  1285. MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
  1286. MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
  1287. MODULE_DESCRIPTION(
  1288. "PMC-Sierra PM8001/8006/8081/8088/8089/8074/8076/8077/8070/8072 "
  1289. "SAS/SATA controller driver");
  1290. MODULE_VERSION(DRV_VERSION);
  1291. MODULE_LICENSE("GPL");
  1292. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);