pm8001_init.c 34 KB

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