pm8001_init.c 36 KB

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