pm8001_init.c 31 KB

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