pm8001_init.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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. pm8001_ha->memoryMap.region[FORENSIC_MEM].num_elements = 1;
  320. pm8001_ha->memoryMap.region[FORENSIC_MEM].total_len = 0x10000;
  321. pm8001_ha->memoryMap.region[FORENSIC_MEM].element_size = 0x10000;
  322. pm8001_ha->memoryMap.region[FORENSIC_MEM].alignment = 0x10000;
  323. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  324. if (pm8001_mem_alloc(pm8001_ha->pdev,
  325. &pm8001_ha->memoryMap.region[i].virt_ptr,
  326. &pm8001_ha->memoryMap.region[i].phys_addr,
  327. &pm8001_ha->memoryMap.region[i].phys_addr_hi,
  328. &pm8001_ha->memoryMap.region[i].phys_addr_lo,
  329. pm8001_ha->memoryMap.region[i].total_len,
  330. pm8001_ha->memoryMap.region[i].alignment) != 0) {
  331. PM8001_FAIL_DBG(pm8001_ha,
  332. pm8001_printk("Mem%d alloc failed\n",
  333. i));
  334. goto err_out;
  335. }
  336. }
  337. pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr;
  338. for (i = 0; i < PM8001_MAX_DEVICES; i++) {
  339. pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
  340. pm8001_ha->devices[i].id = i;
  341. pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
  342. pm8001_ha->devices[i].running_req = 0;
  343. }
  344. pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr;
  345. for (i = 0; i < PM8001_MAX_CCB; i++) {
  346. pm8001_ha->ccb_info[i].ccb_dma_handle =
  347. pm8001_ha->memoryMap.region[CCB_MEM].phys_addr +
  348. i * sizeof(struct pm8001_ccb_info);
  349. pm8001_ha->ccb_info[i].task = NULL;
  350. pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
  351. pm8001_ha->ccb_info[i].device = NULL;
  352. ++pm8001_ha->tags_num;
  353. }
  354. pm8001_ha->flags = PM8001F_INIT_TIME;
  355. /* Initialize tags */
  356. pm8001_tag_init(pm8001_ha);
  357. return 0;
  358. err_out:
  359. return 1;
  360. }
  361. /**
  362. * pm8001_ioremap - remap the pci high physical address to kernal virtual
  363. * address so that we can access them.
  364. * @pm8001_ha:our hba structure.
  365. */
  366. static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
  367. {
  368. u32 bar;
  369. u32 logicalBar = 0;
  370. struct pci_dev *pdev;
  371. pdev = pm8001_ha->pdev;
  372. /* map pci mem (PMC pci base 0-3)*/
  373. for (bar = 0; bar < 6; bar++) {
  374. /*
  375. ** logical BARs for SPC:
  376. ** bar 0 and 1 - logical BAR0
  377. ** bar 2 and 3 - logical BAR1
  378. ** bar4 - logical BAR2
  379. ** bar5 - logical BAR3
  380. ** Skip the appropriate assignments:
  381. */
  382. if ((bar == 1) || (bar == 3))
  383. continue;
  384. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  385. pm8001_ha->io_mem[logicalBar].membase =
  386. pci_resource_start(pdev, bar);
  387. pm8001_ha->io_mem[logicalBar].membase &=
  388. (u32)PCI_BASE_ADDRESS_MEM_MASK;
  389. pm8001_ha->io_mem[logicalBar].memsize =
  390. pci_resource_len(pdev, bar);
  391. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  392. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  393. pm8001_ha->io_mem[logicalBar].memsize);
  394. PM8001_INIT_DBG(pm8001_ha,
  395. pm8001_printk("PCI: bar %d, logicalBar %d ",
  396. bar, logicalBar));
  397. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  398. "base addr %llx virt_addr=%llx len=%d\n",
  399. (u64)pm8001_ha->io_mem[logicalBar].membase,
  400. (u64)(unsigned long)
  401. pm8001_ha->io_mem[logicalBar].memvirtaddr,
  402. pm8001_ha->io_mem[logicalBar].memsize));
  403. } else {
  404. pm8001_ha->io_mem[logicalBar].membase = 0;
  405. pm8001_ha->io_mem[logicalBar].memsize = 0;
  406. pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
  407. }
  408. logicalBar++;
  409. }
  410. return 0;
  411. }
  412. /**
  413. * pm8001_pci_alloc - initialize our ha card structure
  414. * @pdev: pci device.
  415. * @ent: ent
  416. * @shost: scsi host struct which has been initialized before.
  417. */
  418. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  419. const struct pci_device_id *ent,
  420. struct Scsi_Host *shost)
  421. {
  422. struct pm8001_hba_info *pm8001_ha;
  423. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  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. /**
  444. * default tasklet for non msi-x interrupt handler/first msi-x
  445. * interrupt handler
  446. **/
  447. tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet,
  448. (unsigned long)pm8001_ha);
  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. pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
  576. pm8001_ha->nvmd_completion = &completion;
  577. if (pm8001_ha->chip_id == chip_8001) {
  578. if (deviceid == 0x8081) {
  579. payload.minor_function = 4;
  580. payload.length = 4096;
  581. } else {
  582. payload.minor_function = 0;
  583. payload.length = 128;
  584. }
  585. } else {
  586. payload.minor_function = 1;
  587. payload.length = 4096;
  588. }
  589. payload.offset = 0;
  590. payload.func_specific = kzalloc(payload.length, GFP_KERNEL);
  591. PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  592. wait_for_completion(&completion);
  593. for (i = 0, j = 0; i <= 7; i++, j++) {
  594. if (pm8001_ha->chip_id == chip_8001) {
  595. if (deviceid == 0x8081)
  596. pm8001_ha->sas_addr[j] =
  597. payload.func_specific[0x704 + i];
  598. } else
  599. pm8001_ha->sas_addr[j] =
  600. payload.func_specific[0x804 + i];
  601. }
  602. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  603. memcpy(&pm8001_ha->phy[i].dev_sas_addr,
  604. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  605. PM8001_INIT_DBG(pm8001_ha,
  606. pm8001_printk("phy %d sas_addr = %016llx\n", i,
  607. pm8001_ha->phy[i].dev_sas_addr));
  608. }
  609. #else
  610. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  611. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  612. pm8001_ha->phy[i].dev_sas_addr =
  613. cpu_to_be64((u64)
  614. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  615. }
  616. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  617. SAS_ADDR_SIZE);
  618. #endif
  619. }
  620. /*
  621. * pm8001_get_phy_settings_info : Read phy setting values.
  622. * @pm8001_ha : our hba.
  623. */
  624. void pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
  625. {
  626. #ifdef PM8001_READ_VPD
  627. /*OPTION ROM FLASH read for the SPC cards */
  628. DECLARE_COMPLETION_ONSTACK(completion);
  629. struct pm8001_ioctl_payload payload;
  630. pm8001_ha->nvmd_completion = &completion;
  631. /* SAS ADDRESS read from flash / EEPROM */
  632. payload.minor_function = 6;
  633. payload.offset = 0;
  634. payload.length = 4096;
  635. payload.func_specific = kzalloc(4096, GFP_KERNEL);
  636. /* Read phy setting values from flash */
  637. PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  638. wait_for_completion(&completion);
  639. pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
  640. #endif
  641. }
  642. #ifdef PM8001_USE_MSIX
  643. /**
  644. * pm8001_setup_msix - enable MSI-X interrupt
  645. * @chip_info: our ha struct.
  646. * @irq_handler: irq_handler
  647. */
  648. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  649. {
  650. u32 i = 0, j = 0;
  651. u32 number_of_intr;
  652. int flag = 0;
  653. u32 max_entry;
  654. int rc;
  655. static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
  656. /* SPCv controllers supports 64 msi-x */
  657. if (pm8001_ha->chip_id == chip_8001) {
  658. number_of_intr = 1;
  659. flag |= IRQF_DISABLED;
  660. } else {
  661. number_of_intr = PM8001_MAX_MSIX_VEC;
  662. flag &= ~IRQF_SHARED;
  663. flag |= IRQF_DISABLED;
  664. }
  665. max_entry = sizeof(pm8001_ha->msix_entries) /
  666. sizeof(pm8001_ha->msix_entries[0]);
  667. for (i = 0; i < max_entry ; i++)
  668. pm8001_ha->msix_entries[i].entry = i;
  669. rc = pci_enable_msix(pm8001_ha->pdev, pm8001_ha->msix_entries,
  670. number_of_intr);
  671. pm8001_ha->number_of_intr = number_of_intr;
  672. if (!rc) {
  673. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  674. "pci_enable_msix request ret:%d no of intr %d\n",
  675. rc, pm8001_ha->number_of_intr));
  676. for (i = 0; i < number_of_intr; i++)
  677. pm8001_ha->outq[i] = i;
  678. for (i = 0; i < number_of_intr; i++) {
  679. snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
  680. DRV_NAME"%d", i);
  681. if (request_irq(pm8001_ha->msix_entries[i].vector,
  682. pm8001_interrupt_handler_msix, flag,
  683. intr_drvname[i], &pm8001_ha->outq[i])) {
  684. for (j = 0; j < i; j++)
  685. free_irq(
  686. pm8001_ha->msix_entries[j].vector,
  687. &pm8001_ha->outq[j]);
  688. pci_disable_msix(pm8001_ha->pdev);
  689. break;
  690. }
  691. }
  692. }
  693. return rc;
  694. }
  695. #endif
  696. /**
  697. * pm8001_request_irq - register interrupt
  698. * @chip_info: our ha struct.
  699. */
  700. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  701. {
  702. struct pci_dev *pdev;
  703. int rc;
  704. pdev = pm8001_ha->pdev;
  705. #ifdef PM8001_USE_MSIX
  706. if (pdev->msix_cap)
  707. return pm8001_setup_msix(pm8001_ha);
  708. else {
  709. PM8001_INIT_DBG(pm8001_ha,
  710. pm8001_printk("MSIX not supported!!!\n"));
  711. goto intx;
  712. }
  713. #endif
  714. intx:
  715. /* initialize the INT-X interrupt */
  716. rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
  717. DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
  718. return rc;
  719. }
  720. /**
  721. * pm8001_pci_probe - probe supported device
  722. * @pdev: pci device which kernel has been prepared for.
  723. * @ent: pci device id
  724. *
  725. * This function is the main initialization function, when register a new
  726. * pci driver it is invoked, all struct an hardware initilization should be done
  727. * here, also, register interrupt
  728. */
  729. static int pm8001_pci_probe(struct pci_dev *pdev,
  730. const struct pci_device_id *ent)
  731. {
  732. unsigned int rc;
  733. u32 pci_reg;
  734. u8 i = 0;
  735. struct pm8001_hba_info *pm8001_ha;
  736. struct Scsi_Host *shost = NULL;
  737. const struct pm8001_chip_info *chip;
  738. dev_printk(KERN_INFO, &pdev->dev,
  739. "pm80xx: driver version %s\n", DRV_VERSION);
  740. rc = pci_enable_device(pdev);
  741. if (rc)
  742. goto err_out_enable;
  743. pci_set_master(pdev);
  744. /*
  745. * Enable pci slot busmaster by setting pci command register.
  746. * This is required by FW for Cyclone card.
  747. */
  748. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  749. pci_reg |= 0x157;
  750. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  751. rc = pci_request_regions(pdev, DRV_NAME);
  752. if (rc)
  753. goto err_out_disable;
  754. rc = pci_go_44(pdev);
  755. if (rc)
  756. goto err_out_regions;
  757. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  758. if (!shost) {
  759. rc = -ENOMEM;
  760. goto err_out_regions;
  761. }
  762. chip = &pm8001_chips[ent->driver_data];
  763. SHOST_TO_SAS_HA(shost) =
  764. kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  765. if (!SHOST_TO_SAS_HA(shost)) {
  766. rc = -ENOMEM;
  767. goto err_out_free_host;
  768. }
  769. rc = pm8001_prep_sas_ha_init(shost, chip);
  770. if (rc) {
  771. rc = -ENOMEM;
  772. goto err_out_free;
  773. }
  774. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  775. /* ent->driver variable is used to differentiate between controllers */
  776. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  777. if (!pm8001_ha) {
  778. rc = -ENOMEM;
  779. goto err_out_free;
  780. }
  781. list_add_tail(&pm8001_ha->list, &hba_list);
  782. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  783. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  784. if (rc) {
  785. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  786. "chip_init failed [ret: %d]\n", rc));
  787. goto err_out_ha_free;
  788. }
  789. rc = scsi_add_host(shost, &pdev->dev);
  790. if (rc)
  791. goto err_out_ha_free;
  792. rc = pm8001_request_irq(pm8001_ha);
  793. if (rc) {
  794. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  795. "pm8001_request_irq failed [ret: %d]\n", rc));
  796. goto err_out_shost;
  797. }
  798. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  799. if (pm8001_ha->chip_id != chip_8001) {
  800. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  801. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  802. /* setup thermal configuration. */
  803. pm80xx_set_thermal_config(pm8001_ha);
  804. }
  805. pm8001_init_sas_add(pm8001_ha);
  806. /* phy setting support for motherboard controller */
  807. if (pdev->subsystem_vendor != PCI_VENDOR_ID_ADAPTEC2 &&
  808. pdev->subsystem_vendor != 0)
  809. pm8001_get_phy_settings_info(pm8001_ha);
  810. pm8001_post_sas_ha_init(shost, chip);
  811. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  812. if (rc)
  813. goto err_out_shost;
  814. scsi_scan_host(pm8001_ha->shost);
  815. return 0;
  816. err_out_shost:
  817. scsi_remove_host(pm8001_ha->shost);
  818. err_out_ha_free:
  819. pm8001_free(pm8001_ha);
  820. err_out_free:
  821. kfree(SHOST_TO_SAS_HA(shost));
  822. err_out_free_host:
  823. kfree(shost);
  824. err_out_regions:
  825. pci_release_regions(pdev);
  826. err_out_disable:
  827. pci_disable_device(pdev);
  828. err_out_enable:
  829. return rc;
  830. }
  831. static void pm8001_pci_remove(struct pci_dev *pdev)
  832. {
  833. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  834. struct pm8001_hba_info *pm8001_ha;
  835. int i;
  836. pm8001_ha = sha->lldd_ha;
  837. sas_unregister_ha(sha);
  838. sas_remove_host(pm8001_ha->shost);
  839. list_del(&pm8001_ha->list);
  840. scsi_remove_host(pm8001_ha->shost);
  841. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  842. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  843. #ifdef PM8001_USE_MSIX
  844. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  845. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  846. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  847. free_irq(pm8001_ha->msix_entries[i].vector,
  848. &pm8001_ha->outq[i]);
  849. pci_disable_msix(pdev);
  850. #else
  851. free_irq(pm8001_ha->irq, sha);
  852. #endif
  853. #ifdef PM8001_USE_TASKLET
  854. tasklet_kill(&pm8001_ha->tasklet);
  855. #endif
  856. pm8001_free(pm8001_ha);
  857. kfree(sha->sas_phy);
  858. kfree(sha->sas_port);
  859. kfree(sha);
  860. pci_release_regions(pdev);
  861. pci_disable_device(pdev);
  862. }
  863. /**
  864. * pm8001_pci_suspend - power management suspend main entry point
  865. * @pdev: PCI device struct
  866. * @state: PM state change to (usually PCI_D3)
  867. *
  868. * Returns 0 success, anything else error.
  869. */
  870. static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  871. {
  872. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  873. struct pm8001_hba_info *pm8001_ha;
  874. int i;
  875. u32 device_state;
  876. pm8001_ha = sha->lldd_ha;
  877. flush_workqueue(pm8001_wq);
  878. scsi_block_requests(pm8001_ha->shost);
  879. if (!pdev->pm_cap) {
  880. dev_err(&pdev->dev, " PCI PM not supported\n");
  881. return -ENODEV;
  882. }
  883. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  884. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  885. #ifdef PM8001_USE_MSIX
  886. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  887. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  888. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  889. free_irq(pm8001_ha->msix_entries[i].vector,
  890. &pm8001_ha->outq[i]);
  891. pci_disable_msix(pdev);
  892. #else
  893. free_irq(pm8001_ha->irq, sha);
  894. #endif
  895. #ifdef PM8001_USE_TASKLET
  896. tasklet_kill(&pm8001_ha->tasklet);
  897. #endif
  898. device_state = pci_choose_state(pdev, state);
  899. pm8001_printk("pdev=0x%p, slot=%s, entering "
  900. "operating state [D%d]\n", pdev,
  901. pm8001_ha->name, device_state);
  902. pci_save_state(pdev);
  903. pci_disable_device(pdev);
  904. pci_set_power_state(pdev, device_state);
  905. return 0;
  906. }
  907. /**
  908. * pm8001_pci_resume - power management resume main entry point
  909. * @pdev: PCI device struct
  910. *
  911. * Returns 0 success, anything else error.
  912. */
  913. static int pm8001_pci_resume(struct pci_dev *pdev)
  914. {
  915. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  916. struct pm8001_hba_info *pm8001_ha;
  917. int rc;
  918. u8 i = 0;
  919. u32 device_state;
  920. pm8001_ha = sha->lldd_ha;
  921. device_state = pdev->current_state;
  922. pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
  923. "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
  924. pci_set_power_state(pdev, PCI_D0);
  925. pci_enable_wake(pdev, PCI_D0, 0);
  926. pci_restore_state(pdev);
  927. rc = pci_enable_device(pdev);
  928. if (rc) {
  929. pm8001_printk("slot=%s Enable device failed during resume\n",
  930. pm8001_ha->name);
  931. goto err_out_enable;
  932. }
  933. pci_set_master(pdev);
  934. rc = pci_go_44(pdev);
  935. if (rc)
  936. goto err_out_disable;
  937. /* chip soft rst only for spc */
  938. if (pm8001_ha->chip_id == chip_8001) {
  939. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  940. PM8001_INIT_DBG(pm8001_ha,
  941. pm8001_printk("chip soft reset successful\n"));
  942. }
  943. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  944. if (rc)
  945. goto err_out_disable;
  946. /* disable all the interrupt bits */
  947. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  948. rc = pm8001_request_irq(pm8001_ha);
  949. if (rc)
  950. goto err_out_disable;
  951. #ifdef PM8001_USE_TASKLET
  952. /* default tasklet for non msi-x interrupt handler/first msi-x
  953. * interrupt handler */
  954. tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet,
  955. (unsigned long)pm8001_ha);
  956. #endif
  957. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  958. if (pm8001_ha->chip_id != chip_8001) {
  959. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  960. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  961. }
  962. scsi_unblock_requests(pm8001_ha->shost);
  963. return 0;
  964. err_out_disable:
  965. scsi_remove_host(pm8001_ha->shost);
  966. pci_disable_device(pdev);
  967. err_out_enable:
  968. return rc;
  969. }
  970. /* update of pci device, vendor id and driver data with
  971. * unique value for each of the controller
  972. */
  973. static struct pci_device_id pm8001_pci_table[] = {
  974. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  975. {
  976. PCI_DEVICE(0x117c, 0x0042),
  977. .driver_data = chip_8001
  978. },
  979. /* Support for SPC/SPCv/SPCve controllers */
  980. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  981. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  982. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  983. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  984. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  985. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  986. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  987. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  988. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  989. { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
  990. { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
  991. { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
  992. { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
  993. { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
  994. { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
  995. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  996. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  997. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  998. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  999. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1000. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  1001. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1002. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  1003. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1004. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  1005. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1006. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  1007. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1008. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  1009. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1010. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  1011. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1012. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  1013. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1014. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  1015. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1016. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
  1017. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1018. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
  1019. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1020. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
  1021. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1022. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
  1023. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1024. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
  1025. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1026. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
  1027. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1028. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
  1029. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1030. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
  1031. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1032. PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
  1033. {} /* terminate list */
  1034. };
  1035. static struct pci_driver pm8001_pci_driver = {
  1036. .name = DRV_NAME,
  1037. .id_table = pm8001_pci_table,
  1038. .probe = pm8001_pci_probe,
  1039. .remove = pm8001_pci_remove,
  1040. .suspend = pm8001_pci_suspend,
  1041. .resume = pm8001_pci_resume,
  1042. };
  1043. /**
  1044. * pm8001_init - initialize scsi transport template
  1045. */
  1046. static int __init pm8001_init(void)
  1047. {
  1048. int rc = -ENOMEM;
  1049. pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
  1050. if (!pm8001_wq)
  1051. goto err;
  1052. pm8001_id = 0;
  1053. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  1054. if (!pm8001_stt)
  1055. goto err_wq;
  1056. rc = pci_register_driver(&pm8001_pci_driver);
  1057. if (rc)
  1058. goto err_tp;
  1059. return 0;
  1060. err_tp:
  1061. sas_release_transport(pm8001_stt);
  1062. err_wq:
  1063. destroy_workqueue(pm8001_wq);
  1064. err:
  1065. return rc;
  1066. }
  1067. static void __exit pm8001_exit(void)
  1068. {
  1069. pci_unregister_driver(&pm8001_pci_driver);
  1070. sas_release_transport(pm8001_stt);
  1071. destroy_workqueue(pm8001_wq);
  1072. }
  1073. module_init(pm8001_init);
  1074. module_exit(pm8001_exit);
  1075. MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
  1076. MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>");
  1077. MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
  1078. MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
  1079. MODULE_DESCRIPTION(
  1080. "PMC-Sierra PM8001/8081/8088/8089/8074/8076/8077 "
  1081. "SAS/SATA controller driver");
  1082. MODULE_VERSION(DRV_VERSION);
  1083. MODULE_LICENSE("GPL");
  1084. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);