pm8001_init.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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. };
  55. static int pm8001_id;
  56. LIST_HEAD(hba_list);
  57. struct workqueue_struct *pm8001_wq;
  58. /**
  59. * The main structure which LLDD must register for scsi core.
  60. */
  61. static struct scsi_host_template pm8001_sht = {
  62. .module = THIS_MODULE,
  63. .name = DRV_NAME,
  64. .queuecommand = sas_queuecommand,
  65. .target_alloc = sas_target_alloc,
  66. .slave_configure = sas_slave_configure,
  67. .scan_finished = pm8001_scan_finished,
  68. .scan_start = pm8001_scan_start,
  69. .change_queue_depth = sas_change_queue_depth,
  70. .change_queue_type = sas_change_queue_type,
  71. .bios_param = sas_bios_param,
  72. .can_queue = 1,
  73. .cmd_per_lun = 1,
  74. .this_id = -1,
  75. .sg_tablesize = SG_ALL,
  76. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  77. .use_clustering = ENABLE_CLUSTERING,
  78. .eh_device_reset_handler = sas_eh_device_reset_handler,
  79. .eh_bus_reset_handler = sas_eh_bus_reset_handler,
  80. .target_destroy = sas_target_destroy,
  81. .ioctl = sas_ioctl,
  82. .shost_attrs = pm8001_host_attrs,
  83. };
  84. /**
  85. * Sas layer call this function to execute specific task.
  86. */
  87. static struct sas_domain_function_template pm8001_transport_ops = {
  88. .lldd_dev_found = pm8001_dev_found,
  89. .lldd_dev_gone = pm8001_dev_gone,
  90. .lldd_execute_task = pm8001_queue_command,
  91. .lldd_control_phy = pm8001_phy_control,
  92. .lldd_abort_task = pm8001_abort_task,
  93. .lldd_abort_task_set = pm8001_abort_task_set,
  94. .lldd_clear_aca = pm8001_clear_aca,
  95. .lldd_clear_task_set = pm8001_clear_task_set,
  96. .lldd_I_T_nexus_reset = pm8001_I_T_nexus_reset,
  97. .lldd_lu_reset = pm8001_lu_reset,
  98. .lldd_query_task = pm8001_query_task,
  99. };
  100. /**
  101. *pm8001_phy_init - initiate our adapter phys
  102. *@pm8001_ha: our hba structure.
  103. *@phy_id: phy id.
  104. */
  105. static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id)
  106. {
  107. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  108. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  109. phy->phy_state = 0;
  110. phy->pm8001_ha = pm8001_ha;
  111. sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0;
  112. sas_phy->class = SAS;
  113. sas_phy->iproto = SAS_PROTOCOL_ALL;
  114. sas_phy->tproto = 0;
  115. sas_phy->type = PHY_TYPE_PHYSICAL;
  116. sas_phy->role = PHY_ROLE_INITIATOR;
  117. sas_phy->oob_mode = OOB_NOT_CONNECTED;
  118. sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
  119. sas_phy->id = phy_id;
  120. sas_phy->sas_addr = &pm8001_ha->sas_addr[0];
  121. sas_phy->frame_rcvd = &phy->frame_rcvd[0];
  122. sas_phy->ha = (struct sas_ha_struct *)pm8001_ha->shost->hostdata;
  123. sas_phy->lldd_phy = phy;
  124. }
  125. /**
  126. *pm8001_free - free hba
  127. *@pm8001_ha: our hba structure.
  128. *
  129. */
  130. static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
  131. {
  132. int i;
  133. if (!pm8001_ha)
  134. return;
  135. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  136. if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
  137. pci_free_consistent(pm8001_ha->pdev,
  138. (pm8001_ha->memoryMap.region[i].total_len +
  139. pm8001_ha->memoryMap.region[i].alignment),
  140. pm8001_ha->memoryMap.region[i].virt_ptr,
  141. pm8001_ha->memoryMap.region[i].phys_addr);
  142. }
  143. }
  144. PM8001_CHIP_DISP->chip_iounmap(pm8001_ha);
  145. if (pm8001_ha->shost)
  146. scsi_host_put(pm8001_ha->shost);
  147. flush_workqueue(pm8001_wq);
  148. kfree(pm8001_ha->tags);
  149. kfree(pm8001_ha);
  150. }
  151. #ifdef PM8001_USE_TASKLET
  152. /**
  153. * tasklet for 64 msi-x interrupt handler
  154. * @opaque: the passed general host adapter struct
  155. * Note: pm8001_tasklet is common for pm8001 & pm80xx
  156. */
  157. static void pm8001_tasklet(unsigned long opaque)
  158. {
  159. struct pm8001_hba_info *pm8001_ha;
  160. u32 vec;
  161. pm8001_ha = (struct pm8001_hba_info *)opaque;
  162. if (unlikely(!pm8001_ha))
  163. BUG_ON(1);
  164. vec = pm8001_ha->int_vector;
  165. PM8001_CHIP_DISP->isr(pm8001_ha, vec);
  166. }
  167. #endif
  168. static struct pm8001_hba_info *outq_to_hba(u8 *outq)
  169. {
  170. return container_of((outq - *outq), struct pm8001_hba_info, outq[0]);
  171. }
  172. /**
  173. * pm8001_interrupt_handler_msix - main MSIX interrupt handler.
  174. * It obtains the vector number and calls the equivalent bottom
  175. * half or services directly.
  176. * @opaque: the passed outbound queue/vector. Host structure is
  177. * retrieved from the same.
  178. */
  179. static irqreturn_t pm8001_interrupt_handler_msix(int irq, void *opaque)
  180. {
  181. struct pm8001_hba_info *pm8001_ha = outq_to_hba(opaque);
  182. u8 outq = *(u8 *)opaque;
  183. irqreturn_t ret = IRQ_HANDLED;
  184. if (unlikely(!pm8001_ha))
  185. return IRQ_NONE;
  186. if (!PM8001_CHIP_DISP->is_our_interupt(pm8001_ha))
  187. return IRQ_NONE;
  188. pm8001_ha->int_vector = outq;
  189. #ifdef PM8001_USE_TASKLET
  190. tasklet_schedule(&pm8001_ha->tasklet);
  191. #else
  192. ret = PM8001_CHIP_DISP->isr(pm8001_ha, outq);
  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. pm8001_ha->int_vector = 0;
  211. #ifdef PM8001_USE_TASKLET
  212. tasklet_schedule(&pm8001_ha->tasklet);
  213. #else
  214. ret = PM8001_CHIP_DISP->isr(pm8001_ha, 0);
  215. #endif
  216. return ret;
  217. }
  218. /**
  219. * pm8001_alloc - initiate our hba structure and 6 DMAs area.
  220. * @pm8001_ha:our hba structure.
  221. *
  222. */
  223. static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
  224. const struct pci_device_id *ent)
  225. {
  226. int i;
  227. spin_lock_init(&pm8001_ha->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. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  317. if (pm8001_mem_alloc(pm8001_ha->pdev,
  318. &pm8001_ha->memoryMap.region[i].virt_ptr,
  319. &pm8001_ha->memoryMap.region[i].phys_addr,
  320. &pm8001_ha->memoryMap.region[i].phys_addr_hi,
  321. &pm8001_ha->memoryMap.region[i].phys_addr_lo,
  322. pm8001_ha->memoryMap.region[i].total_len,
  323. pm8001_ha->memoryMap.region[i].alignment) != 0) {
  324. PM8001_FAIL_DBG(pm8001_ha,
  325. pm8001_printk("Mem%d alloc failed\n",
  326. i));
  327. goto err_out;
  328. }
  329. }
  330. pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr;
  331. for (i = 0; i < PM8001_MAX_DEVICES; i++) {
  332. pm8001_ha->devices[i].dev_type = NO_DEVICE;
  333. pm8001_ha->devices[i].id = i;
  334. pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
  335. pm8001_ha->devices[i].running_req = 0;
  336. }
  337. pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr;
  338. for (i = 0; i < PM8001_MAX_CCB; i++) {
  339. pm8001_ha->ccb_info[i].ccb_dma_handle =
  340. pm8001_ha->memoryMap.region[CCB_MEM].phys_addr +
  341. i * sizeof(struct pm8001_ccb_info);
  342. pm8001_ha->ccb_info[i].task = NULL;
  343. pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
  344. pm8001_ha->ccb_info[i].device = NULL;
  345. ++pm8001_ha->tags_num;
  346. }
  347. pm8001_ha->flags = PM8001F_INIT_TIME;
  348. /* Initialize tags */
  349. pm8001_tag_init(pm8001_ha);
  350. return 0;
  351. err_out:
  352. return 1;
  353. }
  354. /**
  355. * pm8001_ioremap - remap the pci high physical address to kernal virtual
  356. * address so that we can access them.
  357. * @pm8001_ha:our hba structure.
  358. */
  359. static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
  360. {
  361. u32 bar;
  362. u32 logicalBar = 0;
  363. struct pci_dev *pdev;
  364. pdev = pm8001_ha->pdev;
  365. /* map pci mem (PMC pci base 0-3)*/
  366. for (bar = 0; bar < 6; bar++) {
  367. /*
  368. ** logical BARs for SPC:
  369. ** bar 0 and 1 - logical BAR0
  370. ** bar 2 and 3 - logical BAR1
  371. ** bar4 - logical BAR2
  372. ** bar5 - logical BAR3
  373. ** Skip the appropriate assignments:
  374. */
  375. if ((bar == 1) || (bar == 3))
  376. continue;
  377. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  378. pm8001_ha->io_mem[logicalBar].membase =
  379. pci_resource_start(pdev, bar);
  380. pm8001_ha->io_mem[logicalBar].membase &=
  381. (u32)PCI_BASE_ADDRESS_MEM_MASK;
  382. pm8001_ha->io_mem[logicalBar].memsize =
  383. pci_resource_len(pdev, bar);
  384. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  385. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  386. pm8001_ha->io_mem[logicalBar].memsize);
  387. PM8001_INIT_DBG(pm8001_ha,
  388. pm8001_printk("PCI: bar %d, logicalBar %d ",
  389. bar, logicalBar));
  390. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  391. "base addr %llx virt_addr=%llx len=%d\n",
  392. (u64)pm8001_ha->io_mem[logicalBar].membase,
  393. (u64)pm8001_ha->io_mem[logicalBar].memvirtaddr,
  394. pm8001_ha->io_mem[logicalBar].memsize));
  395. } else {
  396. pm8001_ha->io_mem[logicalBar].membase = 0;
  397. pm8001_ha->io_mem[logicalBar].memsize = 0;
  398. pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
  399. }
  400. logicalBar++;
  401. }
  402. return 0;
  403. }
  404. /**
  405. * pm8001_pci_alloc - initialize our ha card structure
  406. * @pdev: pci device.
  407. * @ent: ent
  408. * @shost: scsi host struct which has been initialized before.
  409. */
  410. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  411. const struct pci_device_id *ent,
  412. struct Scsi_Host *shost)
  413. {
  414. struct pm8001_hba_info *pm8001_ha;
  415. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  416. pm8001_ha = sha->lldd_ha;
  417. if (!pm8001_ha)
  418. return NULL;
  419. pm8001_ha->pdev = pdev;
  420. pm8001_ha->dev = &pdev->dev;
  421. pm8001_ha->chip_id = ent->driver_data;
  422. pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
  423. pm8001_ha->irq = pdev->irq;
  424. pm8001_ha->sas = sha;
  425. pm8001_ha->shost = shost;
  426. pm8001_ha->id = pm8001_id++;
  427. pm8001_ha->logging_level = 0x01;
  428. sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
  429. /* IOMB size is 128 for 8088/89 controllers */
  430. if (pm8001_ha->chip_id != chip_8001)
  431. pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
  432. else
  433. pm8001_ha->iomb_size = IOMB_SIZE_SPC;
  434. #ifdef PM8001_USE_TASKLET
  435. /**
  436. * default tasklet for non msi-x interrupt handler/first msi-x
  437. * interrupt handler
  438. **/
  439. tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet,
  440. (unsigned long)pm8001_ha);
  441. #endif
  442. pm8001_ioremap(pm8001_ha);
  443. if (!pm8001_alloc(pm8001_ha, ent))
  444. return pm8001_ha;
  445. pm8001_free(pm8001_ha);
  446. return NULL;
  447. }
  448. /**
  449. * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
  450. * @pdev: pci device.
  451. */
  452. static int pci_go_44(struct pci_dev *pdev)
  453. {
  454. int rc;
  455. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
  456. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
  457. if (rc) {
  458. rc = pci_set_consistent_dma_mask(pdev,
  459. DMA_BIT_MASK(32));
  460. if (rc) {
  461. dev_printk(KERN_ERR, &pdev->dev,
  462. "44-bit DMA enable failed\n");
  463. return rc;
  464. }
  465. }
  466. } else {
  467. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  468. if (rc) {
  469. dev_printk(KERN_ERR, &pdev->dev,
  470. "32-bit DMA enable failed\n");
  471. return rc;
  472. }
  473. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  474. if (rc) {
  475. dev_printk(KERN_ERR, &pdev->dev,
  476. "32-bit consistent DMA enable failed\n");
  477. return rc;
  478. }
  479. }
  480. return rc;
  481. }
  482. /**
  483. * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
  484. * @shost: scsi host which has been allocated outside.
  485. * @chip_info: our ha struct.
  486. */
  487. static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
  488. const struct pm8001_chip_info *chip_info)
  489. {
  490. int phy_nr, port_nr;
  491. struct asd_sas_phy **arr_phy;
  492. struct asd_sas_port **arr_port;
  493. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  494. phy_nr = chip_info->n_phy;
  495. port_nr = phy_nr;
  496. memset(sha, 0x00, sizeof(*sha));
  497. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  498. if (!arr_phy)
  499. goto exit;
  500. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  501. if (!arr_port)
  502. goto exit_free2;
  503. sha->sas_phy = arr_phy;
  504. sha->sas_port = arr_port;
  505. sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
  506. if (!sha->lldd_ha)
  507. goto exit_free1;
  508. shost->transportt = pm8001_stt;
  509. shost->max_id = PM8001_MAX_DEVICES;
  510. shost->max_lun = 8;
  511. shost->max_channel = 0;
  512. shost->unique_id = pm8001_id;
  513. shost->max_cmd_len = 16;
  514. shost->can_queue = PM8001_CAN_QUEUE;
  515. shost->cmd_per_lun = 32;
  516. return 0;
  517. exit_free1:
  518. kfree(arr_port);
  519. exit_free2:
  520. kfree(arr_phy);
  521. exit:
  522. return -1;
  523. }
  524. /**
  525. * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
  526. * @shost: scsi host which has been allocated outside
  527. * @chip_info: our ha struct.
  528. */
  529. static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  530. const struct pm8001_chip_info *chip_info)
  531. {
  532. int i = 0;
  533. struct pm8001_hba_info *pm8001_ha;
  534. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  535. pm8001_ha = sha->lldd_ha;
  536. for (i = 0; i < chip_info->n_phy; i++) {
  537. sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
  538. sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
  539. }
  540. sha->sas_ha_name = DRV_NAME;
  541. sha->dev = pm8001_ha->dev;
  542. sha->lldd_module = THIS_MODULE;
  543. sha->sas_addr = &pm8001_ha->sas_addr[0];
  544. sha->num_phys = chip_info->n_phy;
  545. sha->lldd_max_execute_num = 1;
  546. sha->lldd_queue_size = PM8001_CAN_QUEUE;
  547. sha->core.shost = shost;
  548. }
  549. /**
  550. * pm8001_init_sas_add - initialize sas address
  551. * @chip_info: our ha struct.
  552. *
  553. * Currently we just set the fixed SAS address to our HBA,for manufacture,
  554. * it should read from the EEPROM
  555. */
  556. static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
  557. {
  558. u8 i, j;
  559. #ifdef PM8001_READ_VPD
  560. /* For new SPC controllers WWN is stored in flash vpd
  561. * For SPC/SPCve controllers WWN is stored in EEPROM
  562. * For Older SPC WWN is stored in NVMD
  563. */
  564. DECLARE_COMPLETION_ONSTACK(completion);
  565. struct pm8001_ioctl_payload payload;
  566. u16 deviceid;
  567. pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
  568. pm8001_ha->nvmd_completion = &completion;
  569. if (pm8001_ha->chip_id == chip_8001) {
  570. if (deviceid == 0x8081) {
  571. payload.minor_function = 4;
  572. payload.length = 4096;
  573. } else {
  574. payload.minor_function = 0;
  575. payload.length = 128;
  576. }
  577. } else {
  578. payload.minor_function = 1;
  579. payload.length = 4096;
  580. }
  581. payload.offset = 0;
  582. payload.func_specific = kzalloc(payload.length, GFP_KERNEL);
  583. PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  584. wait_for_completion(&completion);
  585. for (i = 0, j = 0; i <= 7; i++, j++) {
  586. if (pm8001_ha->chip_id == chip_8001) {
  587. if (deviceid == 0x8081)
  588. pm8001_ha->sas_addr[j] =
  589. payload.func_specific[0x704 + i];
  590. } else
  591. pm8001_ha->sas_addr[j] =
  592. payload.func_specific[0x804 + i];
  593. }
  594. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  595. memcpy(&pm8001_ha->phy[i].dev_sas_addr,
  596. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  597. PM8001_INIT_DBG(pm8001_ha,
  598. pm8001_printk("phy %d sas_addr = %016llx\n", i,
  599. pm8001_ha->phy[i].dev_sas_addr));
  600. }
  601. #else
  602. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  603. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  604. pm8001_ha->phy[i].dev_sas_addr =
  605. cpu_to_be64((u64)
  606. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  607. }
  608. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  609. SAS_ADDR_SIZE);
  610. #endif
  611. }
  612. #ifdef PM8001_USE_MSIX
  613. /**
  614. * pm8001_setup_msix - enable MSI-X interrupt
  615. * @chip_info: our ha struct.
  616. * @irq_handler: irq_handler
  617. */
  618. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  619. {
  620. u32 i = 0, j = 0;
  621. u32 number_of_intr;
  622. int flag = 0;
  623. u32 max_entry;
  624. int rc;
  625. static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
  626. /* SPCv controllers supports 64 msi-x */
  627. if (pm8001_ha->chip_id == chip_8001) {
  628. number_of_intr = 1;
  629. flag |= IRQF_DISABLED;
  630. } else {
  631. number_of_intr = PM8001_MAX_MSIX_VEC;
  632. flag &= ~IRQF_SHARED;
  633. flag |= IRQF_DISABLED;
  634. }
  635. max_entry = sizeof(pm8001_ha->msix_entries) /
  636. sizeof(pm8001_ha->msix_entries[0]);
  637. for (i = 0; i < max_entry ; i++)
  638. pm8001_ha->msix_entries[i].entry = i;
  639. rc = pci_enable_msix(pm8001_ha->pdev, pm8001_ha->msix_entries,
  640. number_of_intr);
  641. pm8001_ha->number_of_intr = number_of_intr;
  642. if (!rc) {
  643. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  644. "pci_enable_msix request ret:%d no of intr %d\n",
  645. rc, pm8001_ha->number_of_intr));
  646. for (i = 0; i < number_of_intr; i++)
  647. pm8001_ha->outq[i] = i;
  648. for (i = 0; i < number_of_intr; i++) {
  649. snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
  650. DRV_NAME"%d", i);
  651. if (request_irq(pm8001_ha->msix_entries[i].vector,
  652. pm8001_interrupt_handler_msix, flag,
  653. intr_drvname[i], &pm8001_ha->outq[i])) {
  654. for (j = 0; j < i; j++)
  655. free_irq(
  656. pm8001_ha->msix_entries[j].vector,
  657. &pm8001_ha->outq[j]);
  658. pci_disable_msix(pm8001_ha->pdev);
  659. break;
  660. }
  661. }
  662. }
  663. return rc;
  664. }
  665. #endif
  666. /**
  667. * pm8001_request_irq - register interrupt
  668. * @chip_info: our ha struct.
  669. */
  670. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  671. {
  672. struct pci_dev *pdev;
  673. int rc;
  674. pdev = pm8001_ha->pdev;
  675. #ifdef PM8001_USE_MSIX
  676. if (pci_find_capability(pdev, PCI_CAP_ID_MSIX))
  677. return pm8001_setup_msix(pm8001_ha);
  678. else {
  679. PM8001_INIT_DBG(pm8001_ha,
  680. pm8001_printk("MSIX not supported!!!\n"));
  681. goto intx;
  682. }
  683. #endif
  684. intx:
  685. /* initialize the INT-X interrupt */
  686. rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
  687. DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
  688. return rc;
  689. }
  690. /**
  691. * pm8001_pci_probe - probe supported device
  692. * @pdev: pci device which kernel has been prepared for.
  693. * @ent: pci device id
  694. *
  695. * This function is the main initialization function, when register a new
  696. * pci driver it is invoked, all struct an hardware initilization should be done
  697. * here, also, register interrupt
  698. */
  699. static int pm8001_pci_probe(struct pci_dev *pdev,
  700. const struct pci_device_id *ent)
  701. {
  702. unsigned int rc;
  703. u32 pci_reg;
  704. u8 i = 0;
  705. struct pm8001_hba_info *pm8001_ha;
  706. struct Scsi_Host *shost = NULL;
  707. const struct pm8001_chip_info *chip;
  708. dev_printk(KERN_INFO, &pdev->dev,
  709. "pm80xx: driver version %s\n", DRV_VERSION);
  710. rc = pci_enable_device(pdev);
  711. if (rc)
  712. goto err_out_enable;
  713. pci_set_master(pdev);
  714. /*
  715. * Enable pci slot busmaster by setting pci command register.
  716. * This is required by FW for Cyclone card.
  717. */
  718. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  719. pci_reg |= 0x157;
  720. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  721. rc = pci_request_regions(pdev, DRV_NAME);
  722. if (rc)
  723. goto err_out_disable;
  724. rc = pci_go_44(pdev);
  725. if (rc)
  726. goto err_out_regions;
  727. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  728. if (!shost) {
  729. rc = -ENOMEM;
  730. goto err_out_regions;
  731. }
  732. chip = &pm8001_chips[ent->driver_data];
  733. SHOST_TO_SAS_HA(shost) =
  734. kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  735. if (!SHOST_TO_SAS_HA(shost)) {
  736. rc = -ENOMEM;
  737. goto err_out_free_host;
  738. }
  739. rc = pm8001_prep_sas_ha_init(shost, chip);
  740. if (rc) {
  741. rc = -ENOMEM;
  742. goto err_out_free;
  743. }
  744. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  745. /* ent->driver variable is used to differentiate between controllers */
  746. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  747. if (!pm8001_ha) {
  748. rc = -ENOMEM;
  749. goto err_out_free;
  750. }
  751. list_add_tail(&pm8001_ha->list, &hba_list);
  752. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  753. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  754. if (rc) {
  755. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  756. "chip_init failed [ret: %d]\n", rc));
  757. goto err_out_ha_free;
  758. }
  759. rc = scsi_add_host(shost, &pdev->dev);
  760. if (rc)
  761. goto err_out_ha_free;
  762. rc = pm8001_request_irq(pm8001_ha);
  763. if (rc) {
  764. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  765. "pm8001_request_irq failed [ret: %d]\n", rc));
  766. goto err_out_shost;
  767. }
  768. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  769. if (pm8001_ha->chip_id != chip_8001) {
  770. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  771. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  772. }
  773. pm8001_init_sas_add(pm8001_ha);
  774. pm8001_post_sas_ha_init(shost, chip);
  775. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  776. if (rc)
  777. goto err_out_shost;
  778. scsi_scan_host(pm8001_ha->shost);
  779. return 0;
  780. err_out_shost:
  781. scsi_remove_host(pm8001_ha->shost);
  782. err_out_ha_free:
  783. pm8001_free(pm8001_ha);
  784. err_out_free:
  785. kfree(SHOST_TO_SAS_HA(shost));
  786. err_out_free_host:
  787. kfree(shost);
  788. err_out_regions:
  789. pci_release_regions(pdev);
  790. err_out_disable:
  791. pci_disable_device(pdev);
  792. err_out_enable:
  793. return rc;
  794. }
  795. static void pm8001_pci_remove(struct pci_dev *pdev)
  796. {
  797. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  798. struct pm8001_hba_info *pm8001_ha;
  799. int i;
  800. pm8001_ha = sha->lldd_ha;
  801. pci_set_drvdata(pdev, NULL);
  802. sas_unregister_ha(sha);
  803. sas_remove_host(pm8001_ha->shost);
  804. list_del(&pm8001_ha->list);
  805. scsi_remove_host(pm8001_ha->shost);
  806. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  807. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  808. #ifdef PM8001_USE_MSIX
  809. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  810. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  811. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  812. free_irq(pm8001_ha->msix_entries[i].vector,
  813. &pm8001_ha->outq[i]);
  814. pci_disable_msix(pdev);
  815. #else
  816. free_irq(pm8001_ha->irq, sha);
  817. #endif
  818. #ifdef PM8001_USE_TASKLET
  819. tasklet_kill(&pm8001_ha->tasklet);
  820. #endif
  821. pm8001_free(pm8001_ha);
  822. kfree(sha->sas_phy);
  823. kfree(sha->sas_port);
  824. kfree(sha);
  825. pci_release_regions(pdev);
  826. pci_disable_device(pdev);
  827. }
  828. /**
  829. * pm8001_pci_suspend - power management suspend main entry point
  830. * @pdev: PCI device struct
  831. * @state: PM state change to (usually PCI_D3)
  832. *
  833. * Returns 0 success, anything else error.
  834. */
  835. static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  836. {
  837. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  838. struct pm8001_hba_info *pm8001_ha;
  839. int i , pos;
  840. u32 device_state;
  841. pm8001_ha = sha->lldd_ha;
  842. flush_workqueue(pm8001_wq);
  843. scsi_block_requests(pm8001_ha->shost);
  844. pos = pci_find_capability(pdev, PCI_CAP_ID_PM);
  845. if (pos == 0) {
  846. printk(KERN_ERR " PCI PM not supported\n");
  847. return -ENODEV;
  848. }
  849. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  850. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  851. #ifdef PM8001_USE_MSIX
  852. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  853. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  854. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  855. free_irq(pm8001_ha->msix_entries[i].vector,
  856. &pm8001_ha->outq[i]);
  857. pci_disable_msix(pdev);
  858. #else
  859. free_irq(pm8001_ha->irq, sha);
  860. #endif
  861. #ifdef PM8001_USE_TASKLET
  862. tasklet_kill(&pm8001_ha->tasklet);
  863. #endif
  864. device_state = pci_choose_state(pdev, state);
  865. pm8001_printk("pdev=0x%p, slot=%s, entering "
  866. "operating state [D%d]\n", pdev,
  867. pm8001_ha->name, device_state);
  868. pci_save_state(pdev);
  869. pci_disable_device(pdev);
  870. pci_set_power_state(pdev, device_state);
  871. return 0;
  872. }
  873. /**
  874. * pm8001_pci_resume - power management resume main entry point
  875. * @pdev: PCI device struct
  876. *
  877. * Returns 0 success, anything else error.
  878. */
  879. static int pm8001_pci_resume(struct pci_dev *pdev)
  880. {
  881. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  882. struct pm8001_hba_info *pm8001_ha;
  883. int rc;
  884. u8 i = 0;
  885. u32 device_state;
  886. pm8001_ha = sha->lldd_ha;
  887. device_state = pdev->current_state;
  888. pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
  889. "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
  890. pci_set_power_state(pdev, PCI_D0);
  891. pci_enable_wake(pdev, PCI_D0, 0);
  892. pci_restore_state(pdev);
  893. rc = pci_enable_device(pdev);
  894. if (rc) {
  895. pm8001_printk("slot=%s Enable device failed during resume\n",
  896. pm8001_ha->name);
  897. goto err_out_enable;
  898. }
  899. pci_set_master(pdev);
  900. rc = pci_go_44(pdev);
  901. if (rc)
  902. goto err_out_disable;
  903. /* chip soft rst only for spc */
  904. if (pm8001_ha->chip_id == chip_8001) {
  905. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  906. PM8001_INIT_DBG(pm8001_ha,
  907. pm8001_printk("chip soft reset successful\n"));
  908. }
  909. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  910. if (rc)
  911. goto err_out_disable;
  912. /* disable all the interrupt bits */
  913. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  914. rc = pm8001_request_irq(pm8001_ha);
  915. if (rc)
  916. goto err_out_disable;
  917. #ifdef PM8001_USE_TASKLET
  918. /* default tasklet for non msi-x interrupt handler/first msi-x
  919. * interrupt handler */
  920. tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet,
  921. (unsigned long)pm8001_ha);
  922. #endif
  923. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  924. if (pm8001_ha->chip_id != chip_8001) {
  925. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  926. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  927. }
  928. scsi_unblock_requests(pm8001_ha->shost);
  929. return 0;
  930. err_out_disable:
  931. scsi_remove_host(pm8001_ha->shost);
  932. pci_disable_device(pdev);
  933. err_out_enable:
  934. return rc;
  935. }
  936. /* update of pci device, vendor id and driver data with
  937. * unique value for each of the controller
  938. */
  939. static struct pci_device_id pm8001_pci_table[] = {
  940. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  941. {
  942. PCI_DEVICE(0x117c, 0x0042),
  943. .driver_data = chip_8001
  944. },
  945. /* Support for SPC/SPCv/SPCve controllers */
  946. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  947. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  948. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  949. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  950. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  951. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  952. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  953. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  954. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  955. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  956. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  957. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  958. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  959. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  960. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  961. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  962. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  963. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  964. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  965. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  966. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  967. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  968. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  969. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  970. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  971. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  972. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  973. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  974. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  975. {} /* terminate list */
  976. };
  977. static struct pci_driver pm8001_pci_driver = {
  978. .name = DRV_NAME,
  979. .id_table = pm8001_pci_table,
  980. .probe = pm8001_pci_probe,
  981. .remove = pm8001_pci_remove,
  982. .suspend = pm8001_pci_suspend,
  983. .resume = pm8001_pci_resume,
  984. };
  985. /**
  986. * pm8001_init - initialize scsi transport template
  987. */
  988. static int __init pm8001_init(void)
  989. {
  990. int rc = -ENOMEM;
  991. pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
  992. if (!pm8001_wq)
  993. goto err;
  994. pm8001_id = 0;
  995. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  996. if (!pm8001_stt)
  997. goto err_wq;
  998. rc = pci_register_driver(&pm8001_pci_driver);
  999. if (rc)
  1000. goto err_tp;
  1001. return 0;
  1002. err_tp:
  1003. sas_release_transport(pm8001_stt);
  1004. err_wq:
  1005. destroy_workqueue(pm8001_wq);
  1006. err:
  1007. return rc;
  1008. }
  1009. static void __exit pm8001_exit(void)
  1010. {
  1011. pci_unregister_driver(&pm8001_pci_driver);
  1012. sas_release_transport(pm8001_stt);
  1013. destroy_workqueue(pm8001_wq);
  1014. }
  1015. module_init(pm8001_init);
  1016. module_exit(pm8001_exit);
  1017. MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
  1018. MODULE_DESCRIPTION(
  1019. "PMC-Sierra PM8001/8081/8088/8089 SAS/SATA controller driver");
  1020. MODULE_VERSION(DRV_VERSION);
  1021. MODULE_LICENSE("GPL");
  1022. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);