pm8001_init.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  315. if (pm8001_mem_alloc(pm8001_ha->pdev,
  316. &pm8001_ha->memoryMap.region[i].virt_ptr,
  317. &pm8001_ha->memoryMap.region[i].phys_addr,
  318. &pm8001_ha->memoryMap.region[i].phys_addr_hi,
  319. &pm8001_ha->memoryMap.region[i].phys_addr_lo,
  320. pm8001_ha->memoryMap.region[i].total_len,
  321. pm8001_ha->memoryMap.region[i].alignment) != 0) {
  322. PM8001_FAIL_DBG(pm8001_ha,
  323. pm8001_printk("Mem%d alloc failed\n",
  324. i));
  325. goto err_out;
  326. }
  327. }
  328. pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr;
  329. for (i = 0; i < PM8001_MAX_DEVICES; i++) {
  330. pm8001_ha->devices[i].dev_type = NO_DEVICE;
  331. pm8001_ha->devices[i].id = i;
  332. pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
  333. pm8001_ha->devices[i].running_req = 0;
  334. }
  335. pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr;
  336. for (i = 0; i < PM8001_MAX_CCB; i++) {
  337. pm8001_ha->ccb_info[i].ccb_dma_handle =
  338. pm8001_ha->memoryMap.region[CCB_MEM].phys_addr +
  339. i * sizeof(struct pm8001_ccb_info);
  340. pm8001_ha->ccb_info[i].task = NULL;
  341. pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
  342. pm8001_ha->ccb_info[i].device = NULL;
  343. ++pm8001_ha->tags_num;
  344. }
  345. pm8001_ha->flags = PM8001F_INIT_TIME;
  346. /* Initialize tags */
  347. pm8001_tag_init(pm8001_ha);
  348. return 0;
  349. err_out:
  350. return 1;
  351. }
  352. /**
  353. * pm8001_ioremap - remap the pci high physical address to kernal virtual
  354. * address so that we can access them.
  355. * @pm8001_ha:our hba structure.
  356. */
  357. static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
  358. {
  359. u32 bar;
  360. u32 logicalBar = 0;
  361. struct pci_dev *pdev;
  362. pdev = pm8001_ha->pdev;
  363. /* map pci mem (PMC pci base 0-3)*/
  364. for (bar = 0; bar < 6; bar++) {
  365. /*
  366. ** logical BARs for SPC:
  367. ** bar 0 and 1 - logical BAR0
  368. ** bar 2 and 3 - logical BAR1
  369. ** bar4 - logical BAR2
  370. ** bar5 - logical BAR3
  371. ** Skip the appropriate assignments:
  372. */
  373. if ((bar == 1) || (bar == 3))
  374. continue;
  375. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  376. pm8001_ha->io_mem[logicalBar].membase =
  377. pci_resource_start(pdev, bar);
  378. pm8001_ha->io_mem[logicalBar].membase &=
  379. (u32)PCI_BASE_ADDRESS_MEM_MASK;
  380. pm8001_ha->io_mem[logicalBar].memsize =
  381. pci_resource_len(pdev, bar);
  382. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  383. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  384. pm8001_ha->io_mem[logicalBar].memsize);
  385. PM8001_INIT_DBG(pm8001_ha,
  386. pm8001_printk("PCI: bar %d, logicalBar %d ",
  387. bar, logicalBar));
  388. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  389. "base addr %llx virt_addr=%llx len=%d\n",
  390. (u64)pm8001_ha->io_mem[logicalBar].membase,
  391. (u64)pm8001_ha->io_mem[logicalBar].memvirtaddr,
  392. pm8001_ha->io_mem[logicalBar].memsize));
  393. } else {
  394. pm8001_ha->io_mem[logicalBar].membase = 0;
  395. pm8001_ha->io_mem[logicalBar].memsize = 0;
  396. pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
  397. }
  398. logicalBar++;
  399. }
  400. return 0;
  401. }
  402. /**
  403. * pm8001_pci_alloc - initialize our ha card structure
  404. * @pdev: pci device.
  405. * @ent: ent
  406. * @shost: scsi host struct which has been initialized before.
  407. */
  408. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  409. const struct pci_device_id *ent,
  410. struct Scsi_Host *shost)
  411. {
  412. struct pm8001_hba_info *pm8001_ha;
  413. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  414. pm8001_ha = sha->lldd_ha;
  415. if (!pm8001_ha)
  416. return NULL;
  417. pm8001_ha->pdev = pdev;
  418. pm8001_ha->dev = &pdev->dev;
  419. pm8001_ha->chip_id = ent->driver_data;
  420. pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
  421. pm8001_ha->irq = pdev->irq;
  422. pm8001_ha->sas = sha;
  423. pm8001_ha->shost = shost;
  424. pm8001_ha->id = pm8001_id++;
  425. pm8001_ha->logging_level = 0x01;
  426. sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
  427. /* IOMB size is 128 for 8088/89 controllers */
  428. if (pm8001_ha->chip_id != chip_8001)
  429. pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
  430. else
  431. pm8001_ha->iomb_size = IOMB_SIZE_SPC;
  432. #ifdef PM8001_USE_TASKLET
  433. /**
  434. * default tasklet for non msi-x interrupt handler/first msi-x
  435. * interrupt handler
  436. **/
  437. tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet,
  438. (unsigned long)pm8001_ha);
  439. #endif
  440. pm8001_ioremap(pm8001_ha);
  441. if (!pm8001_alloc(pm8001_ha, ent))
  442. return pm8001_ha;
  443. pm8001_free(pm8001_ha);
  444. return NULL;
  445. }
  446. /**
  447. * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
  448. * @pdev: pci device.
  449. */
  450. static int pci_go_44(struct pci_dev *pdev)
  451. {
  452. int rc;
  453. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
  454. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
  455. if (rc) {
  456. rc = pci_set_consistent_dma_mask(pdev,
  457. DMA_BIT_MASK(32));
  458. if (rc) {
  459. dev_printk(KERN_ERR, &pdev->dev,
  460. "44-bit DMA enable failed\n");
  461. return rc;
  462. }
  463. }
  464. } else {
  465. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  466. if (rc) {
  467. dev_printk(KERN_ERR, &pdev->dev,
  468. "32-bit DMA enable failed\n");
  469. return rc;
  470. }
  471. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  472. if (rc) {
  473. dev_printk(KERN_ERR, &pdev->dev,
  474. "32-bit consistent DMA enable failed\n");
  475. return rc;
  476. }
  477. }
  478. return rc;
  479. }
  480. /**
  481. * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
  482. * @shost: scsi host which has been allocated outside.
  483. * @chip_info: our ha struct.
  484. */
  485. static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
  486. const struct pm8001_chip_info *chip_info)
  487. {
  488. int phy_nr, port_nr;
  489. struct asd_sas_phy **arr_phy;
  490. struct asd_sas_port **arr_port;
  491. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  492. phy_nr = chip_info->n_phy;
  493. port_nr = phy_nr;
  494. memset(sha, 0x00, sizeof(*sha));
  495. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  496. if (!arr_phy)
  497. goto exit;
  498. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  499. if (!arr_port)
  500. goto exit_free2;
  501. sha->sas_phy = arr_phy;
  502. sha->sas_port = arr_port;
  503. sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
  504. if (!sha->lldd_ha)
  505. goto exit_free1;
  506. shost->transportt = pm8001_stt;
  507. shost->max_id = PM8001_MAX_DEVICES;
  508. shost->max_lun = 8;
  509. shost->max_channel = 0;
  510. shost->unique_id = pm8001_id;
  511. shost->max_cmd_len = 16;
  512. shost->can_queue = PM8001_CAN_QUEUE;
  513. shost->cmd_per_lun = 32;
  514. return 0;
  515. exit_free1:
  516. kfree(arr_port);
  517. exit_free2:
  518. kfree(arr_phy);
  519. exit:
  520. return -1;
  521. }
  522. /**
  523. * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
  524. * @shost: scsi host which has been allocated outside
  525. * @chip_info: our ha struct.
  526. */
  527. static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  528. const struct pm8001_chip_info *chip_info)
  529. {
  530. int i = 0;
  531. struct pm8001_hba_info *pm8001_ha;
  532. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  533. pm8001_ha = sha->lldd_ha;
  534. for (i = 0; i < chip_info->n_phy; i++) {
  535. sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
  536. sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
  537. }
  538. sha->sas_ha_name = DRV_NAME;
  539. sha->dev = pm8001_ha->dev;
  540. sha->lldd_module = THIS_MODULE;
  541. sha->sas_addr = &pm8001_ha->sas_addr[0];
  542. sha->num_phys = chip_info->n_phy;
  543. sha->lldd_max_execute_num = 1;
  544. sha->lldd_queue_size = PM8001_CAN_QUEUE;
  545. sha->core.shost = shost;
  546. }
  547. /**
  548. * pm8001_init_sas_add - initialize sas address
  549. * @chip_info: our ha struct.
  550. *
  551. * Currently we just set the fixed SAS address to our HBA,for manufacture,
  552. * it should read from the EEPROM
  553. */
  554. static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
  555. {
  556. u8 i;
  557. #ifdef PM8001_READ_VPD
  558. DECLARE_COMPLETION_ONSTACK(completion);
  559. struct pm8001_ioctl_payload payload;
  560. pm8001_ha->nvmd_completion = &completion;
  561. payload.minor_function = 0;
  562. payload.length = 128;
  563. payload.func_specific = kzalloc(128, GFP_KERNEL);
  564. PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  565. wait_for_completion(&completion);
  566. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  567. memcpy(&pm8001_ha->phy[i].dev_sas_addr, pm8001_ha->sas_addr,
  568. SAS_ADDR_SIZE);
  569. PM8001_INIT_DBG(pm8001_ha,
  570. pm8001_printk("phy %d sas_addr = %016llx \n", i,
  571. pm8001_ha->phy[i].dev_sas_addr));
  572. }
  573. #else
  574. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  575. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  576. pm8001_ha->phy[i].dev_sas_addr =
  577. cpu_to_be64((u64)
  578. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  579. }
  580. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  581. SAS_ADDR_SIZE);
  582. #endif
  583. }
  584. #ifdef PM8001_USE_MSIX
  585. /**
  586. * pm8001_setup_msix - enable MSI-X interrupt
  587. * @chip_info: our ha struct.
  588. * @irq_handler: irq_handler
  589. */
  590. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  591. {
  592. u32 i = 0, j = 0;
  593. u32 number_of_intr;
  594. int flag = 0;
  595. u32 max_entry;
  596. int rc;
  597. static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
  598. /* SPCv controllers supports 64 msi-x */
  599. if (pm8001_ha->chip_id == chip_8001) {
  600. number_of_intr = 1;
  601. flag |= IRQF_DISABLED;
  602. } else {
  603. number_of_intr = PM8001_MAX_MSIX_VEC;
  604. flag &= ~IRQF_SHARED;
  605. flag |= IRQF_DISABLED;
  606. }
  607. max_entry = sizeof(pm8001_ha->msix_entries) /
  608. sizeof(pm8001_ha->msix_entries[0]);
  609. for (i = 0; i < max_entry ; i++)
  610. pm8001_ha->msix_entries[i].entry = i;
  611. rc = pci_enable_msix(pm8001_ha->pdev, pm8001_ha->msix_entries,
  612. number_of_intr);
  613. pm8001_ha->number_of_intr = number_of_intr;
  614. if (!rc) {
  615. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  616. "pci_enable_msix request ret:%d no of intr %d\n",
  617. rc, pm8001_ha->number_of_intr));
  618. for (i = 0; i < number_of_intr; i++)
  619. pm8001_ha->outq[i] = i;
  620. for (i = 0; i < number_of_intr; i++) {
  621. snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
  622. DRV_NAME"%d", i);
  623. if (request_irq(pm8001_ha->msix_entries[i].vector,
  624. pm8001_interrupt_handler_msix, flag,
  625. intr_drvname[i], &pm8001_ha->outq[i])) {
  626. for (j = 0; j < i; j++)
  627. free_irq(
  628. pm8001_ha->msix_entries[j].vector,
  629. &pm8001_ha->outq[j]);
  630. pci_disable_msix(pm8001_ha->pdev);
  631. break;
  632. }
  633. }
  634. }
  635. return rc;
  636. }
  637. #endif
  638. /**
  639. * pm8001_request_irq - register interrupt
  640. * @chip_info: our ha struct.
  641. */
  642. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  643. {
  644. struct pci_dev *pdev;
  645. int rc;
  646. pdev = pm8001_ha->pdev;
  647. #ifdef PM8001_USE_MSIX
  648. if (pci_find_capability(pdev, PCI_CAP_ID_MSIX))
  649. return pm8001_setup_msix(pm8001_ha);
  650. else {
  651. PM8001_INIT_DBG(pm8001_ha,
  652. pm8001_printk("MSIX not supported!!!\n"));
  653. goto intx;
  654. }
  655. #endif
  656. intx:
  657. /* initialize the INT-X interrupt */
  658. rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
  659. DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
  660. return rc;
  661. }
  662. /**
  663. * pm8001_pci_probe - probe supported device
  664. * @pdev: pci device which kernel has been prepared for.
  665. * @ent: pci device id
  666. *
  667. * This function is the main initialization function, when register a new
  668. * pci driver it is invoked, all struct an hardware initilization should be done
  669. * here, also, register interrupt
  670. */
  671. static int pm8001_pci_probe(struct pci_dev *pdev,
  672. const struct pci_device_id *ent)
  673. {
  674. unsigned int rc;
  675. u32 pci_reg;
  676. u8 i = 0;
  677. struct pm8001_hba_info *pm8001_ha;
  678. struct Scsi_Host *shost = NULL;
  679. const struct pm8001_chip_info *chip;
  680. dev_printk(KERN_INFO, &pdev->dev,
  681. "pm8001: driver version %s\n", DRV_VERSION);
  682. rc = pci_enable_device(pdev);
  683. if (rc)
  684. goto err_out_enable;
  685. pci_set_master(pdev);
  686. /*
  687. * Enable pci slot busmaster by setting pci command register.
  688. * This is required by FW for Cyclone card.
  689. */
  690. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  691. pci_reg |= 0x157;
  692. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  693. rc = pci_request_regions(pdev, DRV_NAME);
  694. if (rc)
  695. goto err_out_disable;
  696. rc = pci_go_44(pdev);
  697. if (rc)
  698. goto err_out_regions;
  699. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  700. if (!shost) {
  701. rc = -ENOMEM;
  702. goto err_out_regions;
  703. }
  704. chip = &pm8001_chips[ent->driver_data];
  705. SHOST_TO_SAS_HA(shost) =
  706. kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  707. if (!SHOST_TO_SAS_HA(shost)) {
  708. rc = -ENOMEM;
  709. goto err_out_free_host;
  710. }
  711. rc = pm8001_prep_sas_ha_init(shost, chip);
  712. if (rc) {
  713. rc = -ENOMEM;
  714. goto err_out_free;
  715. }
  716. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  717. /* ent->driver variable is used to differentiate between controllers */
  718. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  719. if (!pm8001_ha) {
  720. rc = -ENOMEM;
  721. goto err_out_free;
  722. }
  723. list_add_tail(&pm8001_ha->list, &hba_list);
  724. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  725. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  726. if (rc)
  727. goto err_out_ha_free;
  728. rc = scsi_add_host(shost, &pdev->dev);
  729. if (rc)
  730. goto err_out_ha_free;
  731. rc = pm8001_request_irq(pm8001_ha);
  732. if (rc)
  733. goto err_out_shost;
  734. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  735. if (pm8001_ha->chip_id != chip_8001) {
  736. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  737. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  738. }
  739. pm8001_init_sas_add(pm8001_ha);
  740. pm8001_post_sas_ha_init(shost, chip);
  741. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  742. if (rc)
  743. goto err_out_shost;
  744. scsi_scan_host(pm8001_ha->shost);
  745. return 0;
  746. err_out_shost:
  747. scsi_remove_host(pm8001_ha->shost);
  748. err_out_ha_free:
  749. pm8001_free(pm8001_ha);
  750. err_out_free:
  751. kfree(SHOST_TO_SAS_HA(shost));
  752. err_out_free_host:
  753. kfree(shost);
  754. err_out_regions:
  755. pci_release_regions(pdev);
  756. err_out_disable:
  757. pci_disable_device(pdev);
  758. err_out_enable:
  759. return rc;
  760. }
  761. static void pm8001_pci_remove(struct pci_dev *pdev)
  762. {
  763. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  764. struct pm8001_hba_info *pm8001_ha;
  765. int i;
  766. pm8001_ha = sha->lldd_ha;
  767. pci_set_drvdata(pdev, NULL);
  768. sas_unregister_ha(sha);
  769. sas_remove_host(pm8001_ha->shost);
  770. list_del(&pm8001_ha->list);
  771. scsi_remove_host(pm8001_ha->shost);
  772. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  773. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  774. #ifdef PM8001_USE_MSIX
  775. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  776. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  777. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  778. free_irq(pm8001_ha->msix_entries[i].vector,
  779. &pm8001_ha->outq[i]);
  780. pci_disable_msix(pdev);
  781. #else
  782. free_irq(pm8001_ha->irq, sha);
  783. #endif
  784. #ifdef PM8001_USE_TASKLET
  785. tasklet_kill(&pm8001_ha->tasklet);
  786. #endif
  787. pm8001_free(pm8001_ha);
  788. kfree(sha->sas_phy);
  789. kfree(sha->sas_port);
  790. kfree(sha);
  791. pci_release_regions(pdev);
  792. pci_disable_device(pdev);
  793. }
  794. /**
  795. * pm8001_pci_suspend - power management suspend main entry point
  796. * @pdev: PCI device struct
  797. * @state: PM state change to (usually PCI_D3)
  798. *
  799. * Returns 0 success, anything else error.
  800. */
  801. static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  802. {
  803. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  804. struct pm8001_hba_info *pm8001_ha;
  805. int i , pos;
  806. u32 device_state;
  807. pm8001_ha = sha->lldd_ha;
  808. flush_workqueue(pm8001_wq);
  809. scsi_block_requests(pm8001_ha->shost);
  810. pos = pci_find_capability(pdev, PCI_CAP_ID_PM);
  811. if (pos == 0) {
  812. printk(KERN_ERR " PCI PM not supported\n");
  813. return -ENODEV;
  814. }
  815. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  816. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  817. #ifdef PM8001_USE_MSIX
  818. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  819. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  820. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  821. free_irq(pm8001_ha->msix_entries[i].vector,
  822. &pm8001_ha->outq[i]);
  823. pci_disable_msix(pdev);
  824. #else
  825. free_irq(pm8001_ha->irq, sha);
  826. #endif
  827. #ifdef PM8001_USE_TASKLET
  828. tasklet_kill(&pm8001_ha->tasklet);
  829. #endif
  830. device_state = pci_choose_state(pdev, state);
  831. pm8001_printk("pdev=0x%p, slot=%s, entering "
  832. "operating state [D%d]\n", pdev,
  833. pm8001_ha->name, device_state);
  834. pci_save_state(pdev);
  835. pci_disable_device(pdev);
  836. pci_set_power_state(pdev, device_state);
  837. return 0;
  838. }
  839. /**
  840. * pm8001_pci_resume - power management resume main entry point
  841. * @pdev: PCI device struct
  842. *
  843. * Returns 0 success, anything else error.
  844. */
  845. static int pm8001_pci_resume(struct pci_dev *pdev)
  846. {
  847. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  848. struct pm8001_hba_info *pm8001_ha;
  849. int rc;
  850. u8 i = 0;
  851. u32 device_state;
  852. pm8001_ha = sha->lldd_ha;
  853. device_state = pdev->current_state;
  854. pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
  855. "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
  856. pci_set_power_state(pdev, PCI_D0);
  857. pci_enable_wake(pdev, PCI_D0, 0);
  858. pci_restore_state(pdev);
  859. rc = pci_enable_device(pdev);
  860. if (rc) {
  861. pm8001_printk("slot=%s Enable device failed during resume\n",
  862. pm8001_ha->name);
  863. goto err_out_enable;
  864. }
  865. pci_set_master(pdev);
  866. rc = pci_go_44(pdev);
  867. if (rc)
  868. goto err_out_disable;
  869. /* chip soft rst only for spc */
  870. if (pm8001_ha->chip_id == chip_8001) {
  871. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  872. PM8001_INIT_DBG(pm8001_ha,
  873. pm8001_printk("chip soft reset successful\n"));
  874. }
  875. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  876. if (rc)
  877. goto err_out_disable;
  878. /* disable all the interrupt bits */
  879. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  880. rc = pm8001_request_irq(pm8001_ha);
  881. if (rc)
  882. goto err_out_disable;
  883. #ifdef PM8001_USE_TASKLET
  884. /* default tasklet for non msi-x interrupt handler/first msi-x
  885. * interrupt handler */
  886. tasklet_init(&pm8001_ha->tasklet, pm8001_tasklet,
  887. (unsigned long)pm8001_ha);
  888. #endif
  889. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  890. if (pm8001_ha->chip_id != chip_8001) {
  891. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  892. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  893. }
  894. scsi_unblock_requests(pm8001_ha->shost);
  895. return 0;
  896. err_out_disable:
  897. scsi_remove_host(pm8001_ha->shost);
  898. pci_disable_device(pdev);
  899. err_out_enable:
  900. return rc;
  901. }
  902. /* update of pci device, vendor id and driver data with
  903. * unique value for each of the controller
  904. */
  905. static struct pci_device_id pm8001_pci_table[] = {
  906. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  907. {
  908. PCI_DEVICE(0x117c, 0x0042),
  909. .driver_data = chip_8001
  910. },
  911. /* Support for SPC/SPCv/SPCve controllers */
  912. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  913. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  914. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  915. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  916. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  917. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  918. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  919. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  920. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  921. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  922. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  923. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  924. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  925. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  926. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  927. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  928. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  929. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  930. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  931. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  932. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  933. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  934. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  935. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  936. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  937. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  938. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  939. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  940. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  941. {} /* terminate list */
  942. };
  943. static struct pci_driver pm8001_pci_driver = {
  944. .name = DRV_NAME,
  945. .id_table = pm8001_pci_table,
  946. .probe = pm8001_pci_probe,
  947. .remove = pm8001_pci_remove,
  948. .suspend = pm8001_pci_suspend,
  949. .resume = pm8001_pci_resume,
  950. };
  951. /**
  952. * pm8001_init - initialize scsi transport template
  953. */
  954. static int __init pm8001_init(void)
  955. {
  956. int rc = -ENOMEM;
  957. pm8001_wq = alloc_workqueue("pm8001", 0, 0);
  958. if (!pm8001_wq)
  959. goto err;
  960. pm8001_id = 0;
  961. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  962. if (!pm8001_stt)
  963. goto err_wq;
  964. rc = pci_register_driver(&pm8001_pci_driver);
  965. if (rc)
  966. goto err_tp;
  967. return 0;
  968. err_tp:
  969. sas_release_transport(pm8001_stt);
  970. err_wq:
  971. destroy_workqueue(pm8001_wq);
  972. err:
  973. return rc;
  974. }
  975. static void __exit pm8001_exit(void)
  976. {
  977. pci_unregister_driver(&pm8001_pci_driver);
  978. sas_release_transport(pm8001_stt);
  979. destroy_workqueue(pm8001_wq);
  980. }
  981. module_init(pm8001_init);
  982. module_exit(pm8001_exit);
  983. MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
  984. MODULE_DESCRIPTION(
  985. "PMC-Sierra PM8001/8081/8088/8089 SAS/SATA controller driver");
  986. MODULE_VERSION(DRV_VERSION);
  987. MODULE_LICENSE("GPL");
  988. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);