pm8001_init.c 36 KB

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