pm8001_init.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  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. #include "pm80xx_hwi.h"
  44. static ulong logging_level = PM8001_FAIL_LOGGING | PM8001_IOERR_LOGGING;
  45. module_param(logging_level, ulong, 0644);
  46. MODULE_PARM_DESC(logging_level, " bits for enabling logging info.");
  47. static ulong link_rate = LINKRATE_15 | LINKRATE_30 | LINKRATE_60 | LINKRATE_120;
  48. module_param(link_rate, ulong, 0644);
  49. MODULE_PARM_DESC(link_rate, "Enable link rate.\n"
  50. " 1: Link rate 1.5G\n"
  51. " 2: Link rate 3.0G\n"
  52. " 4: Link rate 6.0G\n"
  53. " 8: Link rate 12.0G\n");
  54. static struct scsi_transport_template *pm8001_stt;
  55. static int pm8001_init_ccb_tag(struct pm8001_hba_info *);
  56. /*
  57. * chip info structure to identify chip key functionality as
  58. * encryption available/not, no of ports, hw specific function ref
  59. */
  60. static const struct pm8001_chip_info pm8001_chips[] = {
  61. [chip_8001] = {0, 8, &pm8001_8001_dispatch,},
  62. [chip_8008] = {0, 8, &pm8001_80xx_dispatch,},
  63. [chip_8009] = {1, 8, &pm8001_80xx_dispatch,},
  64. [chip_8018] = {0, 16, &pm8001_80xx_dispatch,},
  65. [chip_8019] = {1, 16, &pm8001_80xx_dispatch,},
  66. [chip_8074] = {0, 8, &pm8001_80xx_dispatch,},
  67. [chip_8076] = {0, 16, &pm8001_80xx_dispatch,},
  68. [chip_8077] = {0, 16, &pm8001_80xx_dispatch,},
  69. [chip_8006] = {0, 16, &pm8001_80xx_dispatch,},
  70. [chip_8070] = {0, 8, &pm8001_80xx_dispatch,},
  71. [chip_8072] = {0, 16, &pm8001_80xx_dispatch,},
  72. };
  73. static int pm8001_id;
  74. LIST_HEAD(hba_list);
  75. struct workqueue_struct *pm8001_wq;
  76. static void pm8001_map_queues(struct Scsi_Host *shost)
  77. {
  78. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  79. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  80. struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
  81. if (pm8001_ha->number_of_intr > 1)
  82. blk_mq_pci_map_queues(qmap, pm8001_ha->pdev, 1);
  83. return blk_mq_map_queues(qmap);
  84. }
  85. /*
  86. * The main structure which LLDD must register for scsi core.
  87. */
  88. static struct scsi_host_template pm8001_sht = {
  89. .module = THIS_MODULE,
  90. .name = DRV_NAME,
  91. .proc_name = DRV_NAME,
  92. .queuecommand = sas_queuecommand,
  93. .dma_need_drain = ata_scsi_dma_need_drain,
  94. .target_alloc = sas_target_alloc,
  95. .slave_configure = sas_slave_configure,
  96. .scan_finished = pm8001_scan_finished,
  97. .scan_start = pm8001_scan_start,
  98. .change_queue_depth = sas_change_queue_depth,
  99. .bios_param = sas_bios_param,
  100. .can_queue = 1,
  101. .this_id = -1,
  102. .sg_tablesize = PM8001_MAX_DMA_SG,
  103. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  104. .eh_device_reset_handler = sas_eh_device_reset_handler,
  105. .eh_target_reset_handler = sas_eh_target_reset_handler,
  106. .slave_alloc = sas_slave_alloc,
  107. .target_destroy = sas_target_destroy,
  108. .ioctl = sas_ioctl,
  109. #ifdef CONFIG_COMPAT
  110. .compat_ioctl = sas_ioctl,
  111. #endif
  112. .shost_groups = pm8001_host_groups,
  113. .track_queue_depth = 1,
  114. .cmd_per_lun = 32,
  115. .map_queues = pm8001_map_queues,
  116. };
  117. /*
  118. * Sas layer call this function to execute specific task.
  119. */
  120. static struct sas_domain_function_template pm8001_transport_ops = {
  121. .lldd_dev_found = pm8001_dev_found,
  122. .lldd_dev_gone = pm8001_dev_gone,
  123. .lldd_execute_task = pm8001_queue_command,
  124. .lldd_control_phy = pm8001_phy_control,
  125. .lldd_abort_task = pm8001_abort_task,
  126. .lldd_abort_task_set = sas_abort_task_set,
  127. .lldd_clear_task_set = pm8001_clear_task_set,
  128. .lldd_I_T_nexus_reset = pm8001_I_T_nexus_reset,
  129. .lldd_lu_reset = pm8001_lu_reset,
  130. .lldd_query_task = pm8001_query_task,
  131. .lldd_port_formed = pm8001_port_formed,
  132. .lldd_tmf_exec_complete = pm8001_setds_completion,
  133. .lldd_tmf_aborted = pm8001_tmf_aborted,
  134. };
  135. /**
  136. * pm8001_phy_init - initiate our adapter phys
  137. * @pm8001_ha: our hba structure.
  138. * @phy_id: phy id.
  139. */
  140. static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id)
  141. {
  142. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  143. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  144. phy->phy_state = PHY_LINK_DISABLE;
  145. phy->pm8001_ha = pm8001_ha;
  146. phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  147. phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
  148. sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0;
  149. sas_phy->class = SAS;
  150. sas_phy->iproto = SAS_PROTOCOL_ALL;
  151. sas_phy->tproto = 0;
  152. sas_phy->type = PHY_TYPE_PHYSICAL;
  153. sas_phy->role = PHY_ROLE_INITIATOR;
  154. sas_phy->oob_mode = OOB_NOT_CONNECTED;
  155. sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
  156. sas_phy->id = phy_id;
  157. sas_phy->sas_addr = (u8 *)&phy->dev_sas_addr;
  158. sas_phy->frame_rcvd = &phy->frame_rcvd[0];
  159. sas_phy->ha = (struct sas_ha_struct *)pm8001_ha->shost->hostdata;
  160. sas_phy->lldd_phy = phy;
  161. }
  162. /**
  163. * pm8001_free - free hba
  164. * @pm8001_ha: our hba structure.
  165. */
  166. static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
  167. {
  168. int i;
  169. if (!pm8001_ha)
  170. return;
  171. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  172. if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
  173. dma_free_coherent(&pm8001_ha->pdev->dev,
  174. (pm8001_ha->memoryMap.region[i].total_len +
  175. pm8001_ha->memoryMap.region[i].alignment),
  176. pm8001_ha->memoryMap.region[i].virt_ptr,
  177. pm8001_ha->memoryMap.region[i].phys_addr);
  178. }
  179. }
  180. PM8001_CHIP_DISP->chip_iounmap(pm8001_ha);
  181. flush_workqueue(pm8001_wq);
  182. bitmap_free(pm8001_ha->tags);
  183. kfree(pm8001_ha);
  184. }
  185. #ifdef PM8001_USE_TASKLET
  186. /**
  187. * pm8001_tasklet() - tasklet for 64 msi-x interrupt handler
  188. * @opaque: the passed general host adapter struct
  189. * Note: pm8001_tasklet is common for pm8001 & pm80xx
  190. */
  191. static void pm8001_tasklet(unsigned long opaque)
  192. {
  193. struct pm8001_hba_info *pm8001_ha;
  194. struct isr_param *irq_vector;
  195. irq_vector = (struct isr_param *)opaque;
  196. pm8001_ha = irq_vector->drv_inst;
  197. if (unlikely(!pm8001_ha))
  198. BUG_ON(1);
  199. PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
  200. }
  201. #endif
  202. /**
  203. * pm8001_interrupt_handler_msix - main MSIX interrupt handler.
  204. * It obtains the vector number and calls the equivalent bottom
  205. * half or services directly.
  206. * @irq: interrupt number
  207. * @opaque: the passed outbound queue/vector. Host structure is
  208. * retrieved from the same.
  209. */
  210. static irqreturn_t pm8001_interrupt_handler_msix(int irq, void *opaque)
  211. {
  212. struct isr_param *irq_vector;
  213. struct pm8001_hba_info *pm8001_ha;
  214. irqreturn_t ret = IRQ_HANDLED;
  215. irq_vector = (struct isr_param *)opaque;
  216. pm8001_ha = irq_vector->drv_inst;
  217. if (unlikely(!pm8001_ha))
  218. return IRQ_NONE;
  219. if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha))
  220. return IRQ_NONE;
  221. #ifdef PM8001_USE_TASKLET
  222. tasklet_schedule(&pm8001_ha->tasklet[irq_vector->irq_id]);
  223. #else
  224. ret = PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
  225. #endif
  226. return ret;
  227. }
  228. /**
  229. * pm8001_interrupt_handler_intx - main INTx interrupt handler.
  230. * @irq: interrupt number
  231. * @dev_id: sas_ha structure. The HBA is retrieved from sas_ha structure.
  232. */
  233. static irqreturn_t pm8001_interrupt_handler_intx(int irq, void *dev_id)
  234. {
  235. struct pm8001_hba_info *pm8001_ha;
  236. irqreturn_t ret = IRQ_HANDLED;
  237. struct sas_ha_struct *sha = dev_id;
  238. pm8001_ha = sha->lldd_ha;
  239. if (unlikely(!pm8001_ha))
  240. return IRQ_NONE;
  241. if (!PM8001_CHIP_DISP->is_our_interrupt(pm8001_ha))
  242. return IRQ_NONE;
  243. #ifdef PM8001_USE_TASKLET
  244. tasklet_schedule(&pm8001_ha->tasklet[0]);
  245. #else
  246. ret = PM8001_CHIP_DISP->isr(pm8001_ha, 0);
  247. #endif
  248. return ret;
  249. }
  250. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha);
  251. /**
  252. * pm8001_alloc - initiate our hba structure and 6 DMAs area.
  253. * @pm8001_ha: our hba structure.
  254. * @ent: PCI device ID structure to match on
  255. */
  256. static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
  257. const struct pci_device_id *ent)
  258. {
  259. int i, count = 0, rc = 0;
  260. u32 ci_offset, ib_offset, ob_offset, pi_offset;
  261. struct inbound_queue_table *ibq;
  262. struct outbound_queue_table *obq;
  263. spin_lock_init(&pm8001_ha->lock);
  264. spin_lock_init(&pm8001_ha->bitmap_lock);
  265. pm8001_dbg(pm8001_ha, INIT, "pm8001_alloc: PHY:%x\n",
  266. pm8001_ha->chip->n_phy);
  267. /* Request Interrupt */
  268. rc = pm8001_request_irq(pm8001_ha);
  269. if (rc)
  270. goto err_out;
  271. count = pm8001_ha->max_q_num;
  272. /* Queues are chosen based on the number of cores/msix availability */
  273. ib_offset = pm8001_ha->ib_offset = USI_MAX_MEMCNT_BASE;
  274. ci_offset = pm8001_ha->ci_offset = ib_offset + count;
  275. ob_offset = pm8001_ha->ob_offset = ci_offset + count;
  276. pi_offset = pm8001_ha->pi_offset = ob_offset + count;
  277. pm8001_ha->max_memcnt = pi_offset + count;
  278. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  279. pm8001_phy_init(pm8001_ha, i);
  280. pm8001_ha->port[i].wide_port_phymap = 0;
  281. pm8001_ha->port[i].port_attached = 0;
  282. pm8001_ha->port[i].port_state = 0;
  283. INIT_LIST_HEAD(&pm8001_ha->port[i].list);
  284. }
  285. /* MPI Memory region 1 for AAP Event Log for fw */
  286. pm8001_ha->memoryMap.region[AAP1].num_elements = 1;
  287. pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE;
  288. pm8001_ha->memoryMap.region[AAP1].total_len = PM8001_EVENT_LOG_SIZE;
  289. pm8001_ha->memoryMap.region[AAP1].alignment = 32;
  290. /* MPI Memory region 2 for IOP Event Log for fw */
  291. pm8001_ha->memoryMap.region[IOP].num_elements = 1;
  292. pm8001_ha->memoryMap.region[IOP].element_size = PM8001_EVENT_LOG_SIZE;
  293. pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE;
  294. pm8001_ha->memoryMap.region[IOP].alignment = 32;
  295. for (i = 0; i < count; i++) {
  296. ibq = &pm8001_ha->inbnd_q_tbl[i];
  297. spin_lock_init(&ibq->iq_lock);
  298. /* MPI Memory region 3 for consumer Index of inbound queues */
  299. pm8001_ha->memoryMap.region[ci_offset+i].num_elements = 1;
  300. pm8001_ha->memoryMap.region[ci_offset+i].element_size = 4;
  301. pm8001_ha->memoryMap.region[ci_offset+i].total_len = 4;
  302. pm8001_ha->memoryMap.region[ci_offset+i].alignment = 4;
  303. if ((ent->driver_data) != chip_8001) {
  304. /* MPI Memory region 5 inbound queues */
  305. pm8001_ha->memoryMap.region[ib_offset+i].num_elements =
  306. PM8001_MPI_QUEUE;
  307. pm8001_ha->memoryMap.region[ib_offset+i].element_size
  308. = 128;
  309. pm8001_ha->memoryMap.region[ib_offset+i].total_len =
  310. PM8001_MPI_QUEUE * 128;
  311. pm8001_ha->memoryMap.region[ib_offset+i].alignment
  312. = 128;
  313. } else {
  314. pm8001_ha->memoryMap.region[ib_offset+i].num_elements =
  315. PM8001_MPI_QUEUE;
  316. pm8001_ha->memoryMap.region[ib_offset+i].element_size
  317. = 64;
  318. pm8001_ha->memoryMap.region[ib_offset+i].total_len =
  319. PM8001_MPI_QUEUE * 64;
  320. pm8001_ha->memoryMap.region[ib_offset+i].alignment = 64;
  321. }
  322. }
  323. for (i = 0; i < count; i++) {
  324. obq = &pm8001_ha->outbnd_q_tbl[i];
  325. spin_lock_init(&obq->oq_lock);
  326. /* MPI Memory region 4 for producer Index of outbound queues */
  327. pm8001_ha->memoryMap.region[pi_offset+i].num_elements = 1;
  328. pm8001_ha->memoryMap.region[pi_offset+i].element_size = 4;
  329. pm8001_ha->memoryMap.region[pi_offset+i].total_len = 4;
  330. pm8001_ha->memoryMap.region[pi_offset+i].alignment = 4;
  331. if (ent->driver_data != chip_8001) {
  332. /* MPI Memory region 6 Outbound queues */
  333. pm8001_ha->memoryMap.region[ob_offset+i].num_elements =
  334. PM8001_MPI_QUEUE;
  335. pm8001_ha->memoryMap.region[ob_offset+i].element_size
  336. = 128;
  337. pm8001_ha->memoryMap.region[ob_offset+i].total_len =
  338. PM8001_MPI_QUEUE * 128;
  339. pm8001_ha->memoryMap.region[ob_offset+i].alignment
  340. = 128;
  341. } else {
  342. /* MPI Memory region 6 Outbound queues */
  343. pm8001_ha->memoryMap.region[ob_offset+i].num_elements =
  344. PM8001_MPI_QUEUE;
  345. pm8001_ha->memoryMap.region[ob_offset+i].element_size
  346. = 64;
  347. pm8001_ha->memoryMap.region[ob_offset+i].total_len =
  348. PM8001_MPI_QUEUE * 64;
  349. pm8001_ha->memoryMap.region[ob_offset+i].alignment = 64;
  350. }
  351. }
  352. /* Memory region write DMA*/
  353. pm8001_ha->memoryMap.region[NVMD].num_elements = 1;
  354. pm8001_ha->memoryMap.region[NVMD].element_size = 4096;
  355. pm8001_ha->memoryMap.region[NVMD].total_len = 4096;
  356. /* Memory region for fw flash */
  357. pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096;
  358. pm8001_ha->memoryMap.region[FORENSIC_MEM].num_elements = 1;
  359. pm8001_ha->memoryMap.region[FORENSIC_MEM].total_len = 0x10000;
  360. pm8001_ha->memoryMap.region[FORENSIC_MEM].element_size = 0x10000;
  361. pm8001_ha->memoryMap.region[FORENSIC_MEM].alignment = 0x10000;
  362. for (i = 0; i < pm8001_ha->max_memcnt; i++) {
  363. struct mpi_mem *region = &pm8001_ha->memoryMap.region[i];
  364. if (pm8001_mem_alloc(pm8001_ha->pdev,
  365. &region->virt_ptr,
  366. &region->phys_addr,
  367. &region->phys_addr_hi,
  368. &region->phys_addr_lo,
  369. region->total_len,
  370. region->alignment) != 0) {
  371. pm8001_dbg(pm8001_ha, FAIL, "Mem%d alloc failed\n", i);
  372. goto err_out;
  373. }
  374. }
  375. /* Memory region for devices*/
  376. pm8001_ha->devices = kzalloc(PM8001_MAX_DEVICES
  377. * sizeof(struct pm8001_device), GFP_KERNEL);
  378. if (!pm8001_ha->devices) {
  379. rc = -ENOMEM;
  380. goto err_out_nodev;
  381. }
  382. for (i = 0; i < PM8001_MAX_DEVICES; i++) {
  383. pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
  384. pm8001_ha->devices[i].id = i;
  385. pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
  386. atomic_set(&pm8001_ha->devices[i].running_req, 0);
  387. }
  388. pm8001_ha->flags = PM8001F_INIT_TIME;
  389. /* Initialize tags */
  390. pm8001_tag_init(pm8001_ha);
  391. return 0;
  392. err_out_nodev:
  393. for (i = 0; i < pm8001_ha->max_memcnt; i++) {
  394. if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
  395. dma_free_coherent(&pm8001_ha->pdev->dev,
  396. (pm8001_ha->memoryMap.region[i].total_len +
  397. pm8001_ha->memoryMap.region[i].alignment),
  398. pm8001_ha->memoryMap.region[i].virt_ptr,
  399. pm8001_ha->memoryMap.region[i].phys_addr);
  400. }
  401. }
  402. err_out:
  403. return 1;
  404. }
  405. /**
  406. * pm8001_ioremap - remap the pci high physical address to kernel virtual
  407. * address so that we can access them.
  408. * @pm8001_ha: our hba structure.
  409. */
  410. static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
  411. {
  412. u32 bar;
  413. u32 logicalBar = 0;
  414. struct pci_dev *pdev;
  415. pdev = pm8001_ha->pdev;
  416. /* map pci mem (PMC pci base 0-3)*/
  417. for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
  418. /*
  419. ** logical BARs for SPC:
  420. ** bar 0 and 1 - logical BAR0
  421. ** bar 2 and 3 - logical BAR1
  422. ** bar4 - logical BAR2
  423. ** bar5 - logical BAR3
  424. ** Skip the appropriate assignments:
  425. */
  426. if ((bar == 1) || (bar == 3))
  427. continue;
  428. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  429. pm8001_ha->io_mem[logicalBar].membase =
  430. pci_resource_start(pdev, bar);
  431. pm8001_ha->io_mem[logicalBar].memsize =
  432. pci_resource_len(pdev, bar);
  433. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  434. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  435. pm8001_ha->io_mem[logicalBar].memsize);
  436. if (!pm8001_ha->io_mem[logicalBar].memvirtaddr) {
  437. pm8001_dbg(pm8001_ha, INIT,
  438. "Failed to ioremap bar %d, logicalBar %d",
  439. bar, logicalBar);
  440. return -ENOMEM;
  441. }
  442. pm8001_dbg(pm8001_ha, INIT,
  443. "base addr %llx virt_addr=%llx len=%d\n",
  444. (u64)pm8001_ha->io_mem[logicalBar].membase,
  445. (u64)(unsigned long)
  446. pm8001_ha->io_mem[logicalBar].memvirtaddr,
  447. pm8001_ha->io_mem[logicalBar].memsize);
  448. } else {
  449. pm8001_ha->io_mem[logicalBar].membase = 0;
  450. pm8001_ha->io_mem[logicalBar].memsize = 0;
  451. pm8001_ha->io_mem[logicalBar].memvirtaddr = NULL;
  452. }
  453. logicalBar++;
  454. }
  455. return 0;
  456. }
  457. /**
  458. * pm8001_pci_alloc - initialize our ha card structure
  459. * @pdev: pci device.
  460. * @ent: ent
  461. * @shost: scsi host struct which has been initialized before.
  462. */
  463. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  464. const struct pci_device_id *ent,
  465. struct Scsi_Host *shost)
  466. {
  467. struct pm8001_hba_info *pm8001_ha;
  468. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  469. int j;
  470. pm8001_ha = sha->lldd_ha;
  471. if (!pm8001_ha)
  472. return NULL;
  473. pm8001_ha->pdev = pdev;
  474. pm8001_ha->dev = &pdev->dev;
  475. pm8001_ha->chip_id = ent->driver_data;
  476. pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
  477. pm8001_ha->irq = pdev->irq;
  478. pm8001_ha->sas = sha;
  479. pm8001_ha->shost = shost;
  480. pm8001_ha->id = pm8001_id++;
  481. pm8001_ha->logging_level = logging_level;
  482. pm8001_ha->non_fatal_count = 0;
  483. if (link_rate >= 1 && link_rate <= 15)
  484. pm8001_ha->link_rate = (link_rate << 8);
  485. else {
  486. pm8001_ha->link_rate = LINKRATE_15 | LINKRATE_30 |
  487. LINKRATE_60 | LINKRATE_120;
  488. pm8001_dbg(pm8001_ha, FAIL,
  489. "Setting link rate to default value\n");
  490. }
  491. sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
  492. /* IOMB size is 128 for 8088/89 controllers */
  493. if (pm8001_ha->chip_id != chip_8001)
  494. pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
  495. else
  496. pm8001_ha->iomb_size = IOMB_SIZE_SPC;
  497. #ifdef PM8001_USE_TASKLET
  498. /* Tasklet for non msi-x interrupt handler */
  499. if ((!pdev->msix_cap || !pci_msi_enabled())
  500. || (pm8001_ha->chip_id == chip_8001))
  501. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  502. (unsigned long)&(pm8001_ha->irq_vector[0]));
  503. else
  504. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  505. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  506. (unsigned long)&(pm8001_ha->irq_vector[j]));
  507. #endif
  508. if (pm8001_ioremap(pm8001_ha))
  509. goto failed_pci_alloc;
  510. if (!pm8001_alloc(pm8001_ha, ent))
  511. return pm8001_ha;
  512. failed_pci_alloc:
  513. pm8001_free(pm8001_ha);
  514. return NULL;
  515. }
  516. /**
  517. * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
  518. * @pdev: pci device.
  519. */
  520. static int pci_go_44(struct pci_dev *pdev)
  521. {
  522. int rc;
  523. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(44));
  524. if (rc) {
  525. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  526. if (rc)
  527. dev_printk(KERN_ERR, &pdev->dev,
  528. "32-bit DMA enable failed\n");
  529. }
  530. return rc;
  531. }
  532. /**
  533. * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
  534. * @shost: scsi host which has been allocated outside.
  535. * @chip_info: our ha struct.
  536. */
  537. static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
  538. const struct pm8001_chip_info *chip_info)
  539. {
  540. int phy_nr, port_nr;
  541. struct asd_sas_phy **arr_phy;
  542. struct asd_sas_port **arr_port;
  543. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  544. phy_nr = chip_info->n_phy;
  545. port_nr = phy_nr;
  546. memset(sha, 0x00, sizeof(*sha));
  547. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  548. if (!arr_phy)
  549. goto exit;
  550. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  551. if (!arr_port)
  552. goto exit_free2;
  553. sha->sas_phy = arr_phy;
  554. sha->sas_port = arr_port;
  555. sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
  556. if (!sha->lldd_ha)
  557. goto exit_free1;
  558. shost->transportt = pm8001_stt;
  559. shost->max_id = PM8001_MAX_DEVICES;
  560. shost->unique_id = pm8001_id;
  561. shost->max_cmd_len = 16;
  562. return 0;
  563. exit_free1:
  564. kfree(arr_port);
  565. exit_free2:
  566. kfree(arr_phy);
  567. exit:
  568. return -1;
  569. }
  570. /**
  571. * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
  572. * @shost: scsi host which has been allocated outside
  573. * @chip_info: our ha struct.
  574. */
  575. static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  576. const struct pm8001_chip_info *chip_info)
  577. {
  578. int i = 0;
  579. struct pm8001_hba_info *pm8001_ha;
  580. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  581. pm8001_ha = sha->lldd_ha;
  582. for (i = 0; i < chip_info->n_phy; i++) {
  583. sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
  584. sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
  585. sha->sas_phy[i]->sas_addr =
  586. (u8 *)&pm8001_ha->phy[i].dev_sas_addr;
  587. }
  588. sha->sas_ha_name = DRV_NAME;
  589. sha->dev = pm8001_ha->dev;
  590. sha->strict_wide_ports = 1;
  591. sha->lldd_module = THIS_MODULE;
  592. sha->sas_addr = &pm8001_ha->sas_addr[0];
  593. sha->num_phys = chip_info->n_phy;
  594. sha->core.shost = shost;
  595. }
  596. /**
  597. * pm8001_init_sas_add - initialize sas address
  598. * @pm8001_ha: our ha struct.
  599. *
  600. * Currently we just set the fixed SAS address to our HBA, for manufacture,
  601. * it should read from the EEPROM
  602. */
  603. static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
  604. {
  605. u8 i, j;
  606. u8 sas_add[8];
  607. #ifdef PM8001_READ_VPD
  608. /* For new SPC controllers WWN is stored in flash vpd
  609. * For SPC/SPCve controllers WWN is stored in EEPROM
  610. * For Older SPC WWN is stored in NVMD
  611. */
  612. DECLARE_COMPLETION_ONSTACK(completion);
  613. struct pm8001_ioctl_payload payload;
  614. u16 deviceid;
  615. int rc;
  616. pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
  617. pm8001_ha->nvmd_completion = &completion;
  618. if (pm8001_ha->chip_id == chip_8001) {
  619. if (deviceid == 0x8081 || deviceid == 0x0042) {
  620. payload.minor_function = 4;
  621. payload.rd_length = 4096;
  622. } else {
  623. payload.minor_function = 0;
  624. payload.rd_length = 128;
  625. }
  626. } else if ((pm8001_ha->chip_id == chip_8070 ||
  627. pm8001_ha->chip_id == chip_8072) &&
  628. pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
  629. payload.minor_function = 4;
  630. payload.rd_length = 4096;
  631. } else {
  632. payload.minor_function = 1;
  633. payload.rd_length = 4096;
  634. }
  635. payload.offset = 0;
  636. payload.func_specific = kzalloc(payload.rd_length, GFP_KERNEL);
  637. if (!payload.func_specific) {
  638. pm8001_dbg(pm8001_ha, INIT, "mem alloc fail\n");
  639. return;
  640. }
  641. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  642. if (rc) {
  643. kfree(payload.func_specific);
  644. pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n");
  645. return;
  646. }
  647. wait_for_completion(&completion);
  648. for (i = 0, j = 0; i <= 7; i++, j++) {
  649. if (pm8001_ha->chip_id == chip_8001) {
  650. if (deviceid == 0x8081)
  651. pm8001_ha->sas_addr[j] =
  652. payload.func_specific[0x704 + i];
  653. else if (deviceid == 0x0042)
  654. pm8001_ha->sas_addr[j] =
  655. payload.func_specific[0x010 + i];
  656. } else if ((pm8001_ha->chip_id == chip_8070 ||
  657. pm8001_ha->chip_id == chip_8072) &&
  658. pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
  659. pm8001_ha->sas_addr[j] =
  660. payload.func_specific[0x010 + i];
  661. } else
  662. pm8001_ha->sas_addr[j] =
  663. payload.func_specific[0x804 + i];
  664. }
  665. memcpy(sas_add, pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  666. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  667. if (i && ((i % 4) == 0))
  668. sas_add[7] = sas_add[7] + 4;
  669. memcpy(&pm8001_ha->phy[i].dev_sas_addr,
  670. sas_add, SAS_ADDR_SIZE);
  671. pm8001_dbg(pm8001_ha, INIT, "phy %d sas_addr = %016llx\n", i,
  672. pm8001_ha->phy[i].dev_sas_addr);
  673. }
  674. kfree(payload.func_specific);
  675. #else
  676. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  677. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  678. pm8001_ha->phy[i].dev_sas_addr =
  679. cpu_to_be64((u64)
  680. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  681. }
  682. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  683. SAS_ADDR_SIZE);
  684. #endif
  685. }
  686. /*
  687. * pm8001_get_phy_settings_info : Read phy setting values.
  688. * @pm8001_ha : our hba.
  689. */
  690. static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
  691. {
  692. #ifdef PM8001_READ_VPD
  693. /*OPTION ROM FLASH read for the SPC cards */
  694. DECLARE_COMPLETION_ONSTACK(completion);
  695. struct pm8001_ioctl_payload payload;
  696. int rc;
  697. pm8001_ha->nvmd_completion = &completion;
  698. /* SAS ADDRESS read from flash / EEPROM */
  699. payload.minor_function = 6;
  700. payload.offset = 0;
  701. payload.rd_length = 4096;
  702. payload.func_specific = kzalloc(4096, GFP_KERNEL);
  703. if (!payload.func_specific)
  704. return -ENOMEM;
  705. /* Read phy setting values from flash */
  706. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  707. if (rc) {
  708. kfree(payload.func_specific);
  709. pm8001_dbg(pm8001_ha, INIT, "nvmd failed\n");
  710. return -ENOMEM;
  711. }
  712. wait_for_completion(&completion);
  713. pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
  714. kfree(payload.func_specific);
  715. #endif
  716. return 0;
  717. }
  718. struct pm8001_mpi3_phy_pg_trx_config {
  719. u32 LaneLosCfg;
  720. u32 LanePgaCfg1;
  721. u32 LanePisoCfg1;
  722. u32 LanePisoCfg2;
  723. u32 LanePisoCfg3;
  724. u32 LanePisoCfg4;
  725. u32 LanePisoCfg5;
  726. u32 LanePisoCfg6;
  727. u32 LaneBctCtrl;
  728. };
  729. /**
  730. * pm8001_get_internal_phy_settings - Retrieves the internal PHY settings
  731. * @pm8001_ha : our adapter
  732. * @phycfg : PHY config page to populate
  733. */
  734. static
  735. void pm8001_get_internal_phy_settings(struct pm8001_hba_info *pm8001_ha,
  736. struct pm8001_mpi3_phy_pg_trx_config *phycfg)
  737. {
  738. phycfg->LaneLosCfg = 0x00000132;
  739. phycfg->LanePgaCfg1 = 0x00203949;
  740. phycfg->LanePisoCfg1 = 0x000000FF;
  741. phycfg->LanePisoCfg2 = 0xFF000001;
  742. phycfg->LanePisoCfg3 = 0xE7011300;
  743. phycfg->LanePisoCfg4 = 0x631C40C0;
  744. phycfg->LanePisoCfg5 = 0xF8102036;
  745. phycfg->LanePisoCfg6 = 0xF74A1000;
  746. phycfg->LaneBctCtrl = 0x00FB33F8;
  747. }
  748. /**
  749. * pm8001_get_external_phy_settings - Retrieves the external PHY settings
  750. * @pm8001_ha : our adapter
  751. * @phycfg : PHY config page to populate
  752. */
  753. static
  754. void pm8001_get_external_phy_settings(struct pm8001_hba_info *pm8001_ha,
  755. struct pm8001_mpi3_phy_pg_trx_config *phycfg)
  756. {
  757. phycfg->LaneLosCfg = 0x00000132;
  758. phycfg->LanePgaCfg1 = 0x00203949;
  759. phycfg->LanePisoCfg1 = 0x000000FF;
  760. phycfg->LanePisoCfg2 = 0xFF000001;
  761. phycfg->LanePisoCfg3 = 0xE7011300;
  762. phycfg->LanePisoCfg4 = 0x63349140;
  763. phycfg->LanePisoCfg5 = 0xF8102036;
  764. phycfg->LanePisoCfg6 = 0xF80D9300;
  765. phycfg->LaneBctCtrl = 0x00FB33F8;
  766. }
  767. /**
  768. * pm8001_get_phy_mask - Retrieves the mask that denotes if a PHY is int/ext
  769. * @pm8001_ha : our adapter
  770. * @phymask : The PHY mask
  771. */
  772. static
  773. void pm8001_get_phy_mask(struct pm8001_hba_info *pm8001_ha, int *phymask)
  774. {
  775. switch (pm8001_ha->pdev->subsystem_device) {
  776. case 0x0070: /* H1280 - 8 external 0 internal */
  777. case 0x0072: /* H12F0 - 16 external 0 internal */
  778. *phymask = 0x0000;
  779. break;
  780. case 0x0071: /* H1208 - 0 external 8 internal */
  781. case 0x0073: /* H120F - 0 external 16 internal */
  782. *phymask = 0xFFFF;
  783. break;
  784. case 0x0080: /* H1244 - 4 external 4 internal */
  785. *phymask = 0x00F0;
  786. break;
  787. case 0x0081: /* H1248 - 4 external 8 internal */
  788. *phymask = 0x0FF0;
  789. break;
  790. case 0x0082: /* H1288 - 8 external 8 internal */
  791. *phymask = 0xFF00;
  792. break;
  793. default:
  794. pm8001_dbg(pm8001_ha, INIT,
  795. "Unknown subsystem device=0x%.04x\n",
  796. pm8001_ha->pdev->subsystem_device);
  797. }
  798. }
  799. /**
  800. * pm8001_set_phy_settings_ven_117c_12G() - Configure ATTO 12Gb PHY settings
  801. * @pm8001_ha : our adapter
  802. */
  803. static
  804. int pm8001_set_phy_settings_ven_117c_12G(struct pm8001_hba_info *pm8001_ha)
  805. {
  806. struct pm8001_mpi3_phy_pg_trx_config phycfg_int;
  807. struct pm8001_mpi3_phy_pg_trx_config phycfg_ext;
  808. int phymask = 0;
  809. int i = 0;
  810. memset(&phycfg_int, 0, sizeof(phycfg_int));
  811. memset(&phycfg_ext, 0, sizeof(phycfg_ext));
  812. pm8001_get_internal_phy_settings(pm8001_ha, &phycfg_int);
  813. pm8001_get_external_phy_settings(pm8001_ha, &phycfg_ext);
  814. pm8001_get_phy_mask(pm8001_ha, &phymask);
  815. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  816. if (phymask & (1 << i)) {/* Internal PHY */
  817. pm8001_set_phy_profile_single(pm8001_ha, i,
  818. sizeof(phycfg_int) / sizeof(u32),
  819. (u32 *)&phycfg_int);
  820. } else { /* External PHY */
  821. pm8001_set_phy_profile_single(pm8001_ha, i,
  822. sizeof(phycfg_ext) / sizeof(u32),
  823. (u32 *)&phycfg_ext);
  824. }
  825. }
  826. return 0;
  827. }
  828. /**
  829. * pm8001_configure_phy_settings - Configures PHY settings based on vendor ID.
  830. * @pm8001_ha : our hba.
  831. */
  832. static int pm8001_configure_phy_settings(struct pm8001_hba_info *pm8001_ha)
  833. {
  834. switch (pm8001_ha->pdev->subsystem_vendor) {
  835. case PCI_VENDOR_ID_ATTO:
  836. if (pm8001_ha->pdev->device == 0x0042) /* 6Gb */
  837. return 0;
  838. else
  839. return pm8001_set_phy_settings_ven_117c_12G(pm8001_ha);
  840. case PCI_VENDOR_ID_ADAPTEC2:
  841. case 0:
  842. return 0;
  843. default:
  844. return pm8001_get_phy_settings_info(pm8001_ha);
  845. }
  846. }
  847. #ifdef PM8001_USE_MSIX
  848. /**
  849. * pm8001_setup_msix - enable MSI-X interrupt
  850. * @pm8001_ha: our ha struct.
  851. */
  852. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  853. {
  854. unsigned int allocated_irq_vectors;
  855. int rc;
  856. /* SPCv controllers supports 64 msi-x */
  857. if (pm8001_ha->chip_id == chip_8001) {
  858. rc = pci_alloc_irq_vectors(pm8001_ha->pdev, 1, 1,
  859. PCI_IRQ_MSIX);
  860. } else {
  861. /*
  862. * Queue index #0 is used always for housekeeping, so don't
  863. * include in the affinity spreading.
  864. */
  865. struct irq_affinity desc = {
  866. .pre_vectors = 1,
  867. };
  868. rc = pci_alloc_irq_vectors_affinity(
  869. pm8001_ha->pdev, 2, PM8001_MAX_MSIX_VEC,
  870. PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, &desc);
  871. }
  872. allocated_irq_vectors = rc;
  873. if (rc < 0)
  874. return rc;
  875. /* Assigns the number of interrupts */
  876. pm8001_ha->number_of_intr = allocated_irq_vectors;
  877. /* Maximum queue number updating in HBA structure */
  878. pm8001_ha->max_q_num = allocated_irq_vectors;
  879. pm8001_dbg(pm8001_ha, INIT,
  880. "pci_alloc_irq_vectors request ret:%d no of intr %d\n",
  881. rc, pm8001_ha->number_of_intr);
  882. return 0;
  883. }
  884. static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha)
  885. {
  886. u32 i = 0, j = 0;
  887. int flag = 0, rc = 0;
  888. int nr_irqs = pm8001_ha->number_of_intr;
  889. if (pm8001_ha->chip_id != chip_8001)
  890. flag &= ~IRQF_SHARED;
  891. pm8001_dbg(pm8001_ha, INIT,
  892. "pci_enable_msix request number of intr %d\n",
  893. pm8001_ha->number_of_intr);
  894. if (nr_irqs > ARRAY_SIZE(pm8001_ha->intr_drvname))
  895. nr_irqs = ARRAY_SIZE(pm8001_ha->intr_drvname);
  896. for (i = 0; i < nr_irqs; i++) {
  897. snprintf(pm8001_ha->intr_drvname[i],
  898. sizeof(pm8001_ha->intr_drvname[0]),
  899. "%s-%d", pm8001_ha->name, i);
  900. pm8001_ha->irq_vector[i].irq_id = i;
  901. pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
  902. rc = request_irq(pci_irq_vector(pm8001_ha->pdev, i),
  903. pm8001_interrupt_handler_msix, flag,
  904. pm8001_ha->intr_drvname[i],
  905. &(pm8001_ha->irq_vector[i]));
  906. if (rc) {
  907. for (j = 0; j < i; j++) {
  908. free_irq(pci_irq_vector(pm8001_ha->pdev, i),
  909. &(pm8001_ha->irq_vector[i]));
  910. }
  911. pci_free_irq_vectors(pm8001_ha->pdev);
  912. break;
  913. }
  914. }
  915. return rc;
  916. }
  917. #endif
  918. /**
  919. * pm8001_request_irq - register interrupt
  920. * @pm8001_ha: our ha struct.
  921. */
  922. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  923. {
  924. struct pci_dev *pdev = pm8001_ha->pdev;
  925. #ifdef PM8001_USE_MSIX
  926. int rc;
  927. if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) {
  928. rc = pm8001_setup_msix(pm8001_ha);
  929. if (rc) {
  930. pm8001_dbg(pm8001_ha, FAIL,
  931. "pm8001_setup_irq failed [ret: %d]\n", rc);
  932. return rc;
  933. }
  934. if (pdev->msix_cap && pci_msi_enabled())
  935. return pm8001_request_msix(pm8001_ha);
  936. }
  937. pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n");
  938. #endif
  939. /* initialize the INT-X interrupt */
  940. pm8001_ha->irq_vector[0].irq_id = 0;
  941. pm8001_ha->irq_vector[0].drv_inst = pm8001_ha;
  942. return request_irq(pdev->irq, pm8001_interrupt_handler_intx,
  943. IRQF_SHARED, pm8001_ha->name,
  944. SHOST_TO_SAS_HA(pm8001_ha->shost));
  945. }
  946. /**
  947. * pm8001_pci_probe - probe supported device
  948. * @pdev: pci device which kernel has been prepared for.
  949. * @ent: pci device id
  950. *
  951. * This function is the main initialization function, when register a new
  952. * pci driver it is invoked, all struct and hardware initialization should be
  953. * done here, also, register interrupt.
  954. */
  955. static int pm8001_pci_probe(struct pci_dev *pdev,
  956. const struct pci_device_id *ent)
  957. {
  958. unsigned int rc;
  959. u32 pci_reg;
  960. u8 i = 0;
  961. struct pm8001_hba_info *pm8001_ha;
  962. struct Scsi_Host *shost = NULL;
  963. const struct pm8001_chip_info *chip;
  964. struct sas_ha_struct *sha;
  965. dev_printk(KERN_INFO, &pdev->dev,
  966. "pm80xx: driver version %s\n", DRV_VERSION);
  967. rc = pci_enable_device(pdev);
  968. if (rc)
  969. goto err_out_enable;
  970. pci_set_master(pdev);
  971. /*
  972. * Enable pci slot busmaster by setting pci command register.
  973. * This is required by FW for Cyclone card.
  974. */
  975. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  976. pci_reg |= 0x157;
  977. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  978. rc = pci_request_regions(pdev, DRV_NAME);
  979. if (rc)
  980. goto err_out_disable;
  981. rc = pci_go_44(pdev);
  982. if (rc)
  983. goto err_out_regions;
  984. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  985. if (!shost) {
  986. rc = -ENOMEM;
  987. goto err_out_regions;
  988. }
  989. chip = &pm8001_chips[ent->driver_data];
  990. sha = kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  991. if (!sha) {
  992. rc = -ENOMEM;
  993. goto err_out_free_host;
  994. }
  995. SHOST_TO_SAS_HA(shost) = sha;
  996. rc = pm8001_prep_sas_ha_init(shost, chip);
  997. if (rc) {
  998. rc = -ENOMEM;
  999. goto err_out_free;
  1000. }
  1001. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  1002. /* ent->driver variable is used to differentiate between controllers */
  1003. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  1004. if (!pm8001_ha) {
  1005. rc = -ENOMEM;
  1006. goto err_out_free;
  1007. }
  1008. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1009. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  1010. if (rc) {
  1011. pm8001_dbg(pm8001_ha, FAIL,
  1012. "chip_init failed [ret: %d]\n", rc);
  1013. goto err_out_ha_free;
  1014. }
  1015. rc = pm8001_init_ccb_tag(pm8001_ha);
  1016. if (rc)
  1017. goto err_out_enable;
  1018. PM8001_CHIP_DISP->chip_post_init(pm8001_ha);
  1019. if (pm8001_ha->number_of_intr > 1) {
  1020. shost->nr_hw_queues = pm8001_ha->number_of_intr - 1;
  1021. /*
  1022. * For now, ensure we're not sent too many commands by setting
  1023. * host_tagset. This is also required if we start using request
  1024. * tag.
  1025. */
  1026. shost->host_tagset = 1;
  1027. }
  1028. rc = scsi_add_host(shost, &pdev->dev);
  1029. if (rc)
  1030. goto err_out_ha_free;
  1031. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  1032. if (pm8001_ha->chip_id != chip_8001) {
  1033. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  1034. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  1035. /* setup thermal configuration. */
  1036. pm80xx_set_thermal_config(pm8001_ha);
  1037. }
  1038. pm8001_init_sas_add(pm8001_ha);
  1039. /* phy setting support for motherboard controller */
  1040. rc = pm8001_configure_phy_settings(pm8001_ha);
  1041. if (rc)
  1042. goto err_out_shost;
  1043. pm8001_post_sas_ha_init(shost, chip);
  1044. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  1045. if (rc) {
  1046. pm8001_dbg(pm8001_ha, FAIL,
  1047. "sas_register_ha failed [ret: %d]\n", rc);
  1048. goto err_out_shost;
  1049. }
  1050. list_add_tail(&pm8001_ha->list, &hba_list);
  1051. pm8001_ha->flags = PM8001F_RUN_TIME;
  1052. scsi_scan_host(pm8001_ha->shost);
  1053. return 0;
  1054. err_out_shost:
  1055. scsi_remove_host(pm8001_ha->shost);
  1056. err_out_ha_free:
  1057. pm8001_free(pm8001_ha);
  1058. err_out_free:
  1059. kfree(sha);
  1060. err_out_free_host:
  1061. scsi_host_put(shost);
  1062. err_out_regions:
  1063. pci_release_regions(pdev);
  1064. err_out_disable:
  1065. pci_disable_device(pdev);
  1066. err_out_enable:
  1067. return rc;
  1068. }
  1069. /**
  1070. * pm8001_init_ccb_tag - allocate memory to CCB and tag.
  1071. * @pm8001_ha: our hba card information.
  1072. */
  1073. static int pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha)
  1074. {
  1075. struct Scsi_Host *shost = pm8001_ha->shost;
  1076. struct device *dev = pm8001_ha->dev;
  1077. u32 max_out_io, ccb_count;
  1078. u32 can_queue;
  1079. int i;
  1080. max_out_io = pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io;
  1081. ccb_count = min_t(int, PM8001_MAX_CCB, max_out_io);
  1082. /* Update to the scsi host*/
  1083. can_queue = ccb_count - PM8001_RESERVE_SLOT;
  1084. shost->can_queue = can_queue;
  1085. pm8001_ha->tags = bitmap_zalloc(ccb_count, GFP_KERNEL);
  1086. if (!pm8001_ha->tags)
  1087. goto err_out;
  1088. /* Memory region for ccb_info*/
  1089. pm8001_ha->ccb_count = ccb_count;
  1090. pm8001_ha->ccb_info =
  1091. kcalloc(ccb_count, sizeof(struct pm8001_ccb_info), GFP_KERNEL);
  1092. if (!pm8001_ha->ccb_info) {
  1093. pm8001_dbg(pm8001_ha, FAIL,
  1094. "Unable to allocate memory for ccb\n");
  1095. goto err_out_noccb;
  1096. }
  1097. for (i = 0; i < ccb_count; i++) {
  1098. pm8001_ha->ccb_info[i].buf_prd = dma_alloc_coherent(dev,
  1099. sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
  1100. &pm8001_ha->ccb_info[i].ccb_dma_handle,
  1101. GFP_KERNEL);
  1102. if (!pm8001_ha->ccb_info[i].buf_prd) {
  1103. pm8001_dbg(pm8001_ha, FAIL,
  1104. "ccb prd memory allocation error\n");
  1105. goto err_out;
  1106. }
  1107. pm8001_ha->ccb_info[i].task = NULL;
  1108. pm8001_ha->ccb_info[i].ccb_tag = PM8001_INVALID_TAG;
  1109. pm8001_ha->ccb_info[i].device = NULL;
  1110. ++pm8001_ha->tags_num;
  1111. }
  1112. return 0;
  1113. err_out_noccb:
  1114. kfree(pm8001_ha->devices);
  1115. err_out:
  1116. return -ENOMEM;
  1117. }
  1118. static void pm8001_pci_remove(struct pci_dev *pdev)
  1119. {
  1120. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1121. struct pm8001_hba_info *pm8001_ha;
  1122. int i, j;
  1123. pm8001_ha = sha->lldd_ha;
  1124. sas_unregister_ha(sha);
  1125. sas_remove_host(pm8001_ha->shost);
  1126. list_del(&pm8001_ha->list);
  1127. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1128. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1129. #ifdef PM8001_USE_MSIX
  1130. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1131. synchronize_irq(pci_irq_vector(pdev, i));
  1132. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1133. free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
  1134. pci_free_irq_vectors(pdev);
  1135. #else
  1136. free_irq(pm8001_ha->irq, sha);
  1137. #endif
  1138. #ifdef PM8001_USE_TASKLET
  1139. /* For non-msix and msix interrupts */
  1140. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1141. (pm8001_ha->chip_id == chip_8001))
  1142. tasklet_kill(&pm8001_ha->tasklet[0]);
  1143. else
  1144. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1145. tasklet_kill(&pm8001_ha->tasklet[j]);
  1146. #endif
  1147. scsi_host_put(pm8001_ha->shost);
  1148. for (i = 0; i < pm8001_ha->ccb_count; i++) {
  1149. dma_free_coherent(&pm8001_ha->pdev->dev,
  1150. sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
  1151. pm8001_ha->ccb_info[i].buf_prd,
  1152. pm8001_ha->ccb_info[i].ccb_dma_handle);
  1153. }
  1154. kfree(pm8001_ha->ccb_info);
  1155. kfree(pm8001_ha->devices);
  1156. pm8001_free(pm8001_ha);
  1157. kfree(sha->sas_phy);
  1158. kfree(sha->sas_port);
  1159. kfree(sha);
  1160. pci_release_regions(pdev);
  1161. pci_disable_device(pdev);
  1162. }
  1163. /**
  1164. * pm8001_pci_suspend - power management suspend main entry point
  1165. * @dev: Device struct
  1166. *
  1167. * Return: 0 on success, anything else on error.
  1168. */
  1169. static int __maybe_unused pm8001_pci_suspend(struct device *dev)
  1170. {
  1171. struct pci_dev *pdev = to_pci_dev(dev);
  1172. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1173. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  1174. int i, j;
  1175. sas_suspend_ha(sha);
  1176. flush_workqueue(pm8001_wq);
  1177. scsi_block_requests(pm8001_ha->shost);
  1178. if (!pdev->pm_cap) {
  1179. dev_err(dev, " PCI PM not supported\n");
  1180. return -ENODEV;
  1181. }
  1182. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1183. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1184. #ifdef PM8001_USE_MSIX
  1185. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1186. synchronize_irq(pci_irq_vector(pdev, i));
  1187. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1188. free_irq(pci_irq_vector(pdev, i), &pm8001_ha->irq_vector[i]);
  1189. pci_free_irq_vectors(pdev);
  1190. #else
  1191. free_irq(pm8001_ha->irq, sha);
  1192. #endif
  1193. #ifdef PM8001_USE_TASKLET
  1194. /* For non-msix and msix interrupts */
  1195. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1196. (pm8001_ha->chip_id == chip_8001))
  1197. tasklet_kill(&pm8001_ha->tasklet[0]);
  1198. else
  1199. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1200. tasklet_kill(&pm8001_ha->tasklet[j]);
  1201. #endif
  1202. pm8001_info(pm8001_ha, "pdev=0x%p, slot=%s, entering "
  1203. "suspended state\n", pdev,
  1204. pm8001_ha->name);
  1205. return 0;
  1206. }
  1207. /**
  1208. * pm8001_pci_resume - power management resume main entry point
  1209. * @dev: Device struct
  1210. *
  1211. * Return: 0 on success, anything else on error.
  1212. */
  1213. static int __maybe_unused pm8001_pci_resume(struct device *dev)
  1214. {
  1215. struct pci_dev *pdev = to_pci_dev(dev);
  1216. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1217. struct pm8001_hba_info *pm8001_ha;
  1218. int rc;
  1219. u8 i = 0, j;
  1220. DECLARE_COMPLETION_ONSTACK(completion);
  1221. pm8001_ha = sha->lldd_ha;
  1222. pm8001_info(pm8001_ha,
  1223. "pdev=0x%p, slot=%s, resuming from previous operating state [D%d]\n",
  1224. pdev, pm8001_ha->name, pdev->current_state);
  1225. rc = pci_go_44(pdev);
  1226. if (rc)
  1227. goto err_out_disable;
  1228. sas_prep_resume_ha(sha);
  1229. /* chip soft rst only for spc */
  1230. if (pm8001_ha->chip_id == chip_8001) {
  1231. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1232. pm8001_dbg(pm8001_ha, INIT, "chip soft reset successful\n");
  1233. }
  1234. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  1235. if (rc)
  1236. goto err_out_disable;
  1237. /* disable all the interrupt bits */
  1238. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1239. rc = pm8001_request_irq(pm8001_ha);
  1240. if (rc)
  1241. goto err_out_disable;
  1242. #ifdef PM8001_USE_TASKLET
  1243. /* Tasklet for non msi-x interrupt handler */
  1244. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1245. (pm8001_ha->chip_id == chip_8001))
  1246. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  1247. (unsigned long)&(pm8001_ha->irq_vector[0]));
  1248. else
  1249. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1250. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  1251. (unsigned long)&(pm8001_ha->irq_vector[j]));
  1252. #endif
  1253. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  1254. if (pm8001_ha->chip_id != chip_8001) {
  1255. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  1256. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  1257. }
  1258. /* Chip documentation for the 8070 and 8072 SPCv */
  1259. /* states that a 500ms minimum delay is required */
  1260. /* before issuing commands. Otherwise, the firmware */
  1261. /* will enter an unrecoverable state. */
  1262. if (pm8001_ha->chip_id == chip_8070 ||
  1263. pm8001_ha->chip_id == chip_8072) {
  1264. mdelay(500);
  1265. }
  1266. /* Spin up the PHYs */
  1267. pm8001_ha->flags = PM8001F_RUN_TIME;
  1268. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  1269. pm8001_ha->phy[i].enable_completion = &completion;
  1270. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
  1271. wait_for_completion(&completion);
  1272. }
  1273. sas_resume_ha(sha);
  1274. return 0;
  1275. err_out_disable:
  1276. scsi_remove_host(pm8001_ha->shost);
  1277. return rc;
  1278. }
  1279. /* update of pci device, vendor id and driver data with
  1280. * unique value for each of the controller
  1281. */
  1282. static struct pci_device_id pm8001_pci_table[] = {
  1283. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  1284. { PCI_VDEVICE(PMC_Sierra, 0x8006), chip_8006 },
  1285. { PCI_VDEVICE(ADAPTEC2, 0x8006), chip_8006 },
  1286. { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
  1287. /* Support for SPC/SPCv/SPCve controllers */
  1288. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  1289. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  1290. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  1291. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  1292. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  1293. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  1294. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  1295. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  1296. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  1297. { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
  1298. { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
  1299. { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
  1300. { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
  1301. { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
  1302. { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
  1303. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1304. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  1305. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1306. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  1307. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1308. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  1309. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1310. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  1311. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1312. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  1313. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1314. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  1315. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1316. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  1317. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1318. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  1319. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1320. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  1321. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1322. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  1323. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1324. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
  1325. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1326. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
  1327. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1328. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
  1329. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1330. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
  1331. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1332. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
  1333. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1334. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
  1335. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1336. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
  1337. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1338. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
  1339. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1340. PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
  1341. { PCI_VENDOR_ID_ATTO, 0x8070,
  1342. PCI_VENDOR_ID_ATTO, 0x0070, 0, 0, chip_8070 },
  1343. { PCI_VENDOR_ID_ATTO, 0x8070,
  1344. PCI_VENDOR_ID_ATTO, 0x0071, 0, 0, chip_8070 },
  1345. { PCI_VENDOR_ID_ATTO, 0x8072,
  1346. PCI_VENDOR_ID_ATTO, 0x0072, 0, 0, chip_8072 },
  1347. { PCI_VENDOR_ID_ATTO, 0x8072,
  1348. PCI_VENDOR_ID_ATTO, 0x0073, 0, 0, chip_8072 },
  1349. { PCI_VENDOR_ID_ATTO, 0x8070,
  1350. PCI_VENDOR_ID_ATTO, 0x0080, 0, 0, chip_8070 },
  1351. { PCI_VENDOR_ID_ATTO, 0x8072,
  1352. PCI_VENDOR_ID_ATTO, 0x0081, 0, 0, chip_8072 },
  1353. { PCI_VENDOR_ID_ATTO, 0x8072,
  1354. PCI_VENDOR_ID_ATTO, 0x0082, 0, 0, chip_8072 },
  1355. {} /* terminate list */
  1356. };
  1357. static SIMPLE_DEV_PM_OPS(pm8001_pci_pm_ops,
  1358. pm8001_pci_suspend,
  1359. pm8001_pci_resume);
  1360. static struct pci_driver pm8001_pci_driver = {
  1361. .name = DRV_NAME,
  1362. .id_table = pm8001_pci_table,
  1363. .probe = pm8001_pci_probe,
  1364. .remove = pm8001_pci_remove,
  1365. .driver.pm = &pm8001_pci_pm_ops,
  1366. };
  1367. /**
  1368. * pm8001_init - initialize scsi transport template
  1369. */
  1370. static int __init pm8001_init(void)
  1371. {
  1372. int rc = -ENOMEM;
  1373. pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
  1374. if (!pm8001_wq)
  1375. goto err;
  1376. pm8001_id = 0;
  1377. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  1378. if (!pm8001_stt)
  1379. goto err_wq;
  1380. rc = pci_register_driver(&pm8001_pci_driver);
  1381. if (rc)
  1382. goto err_tp;
  1383. return 0;
  1384. err_tp:
  1385. sas_release_transport(pm8001_stt);
  1386. err_wq:
  1387. destroy_workqueue(pm8001_wq);
  1388. err:
  1389. return rc;
  1390. }
  1391. static void __exit pm8001_exit(void)
  1392. {
  1393. pci_unregister_driver(&pm8001_pci_driver);
  1394. sas_release_transport(pm8001_stt);
  1395. destroy_workqueue(pm8001_wq);
  1396. }
  1397. module_init(pm8001_init);
  1398. module_exit(pm8001_exit);
  1399. MODULE_AUTHOR("Jack Wang <[email protected]>");
  1400. MODULE_AUTHOR("Anand Kumar Santhanam <[email protected]>");
  1401. MODULE_AUTHOR("Sangeetha Gnanasekaran <[email protected]>");
  1402. MODULE_AUTHOR("Nikith Ganigarakoppal <[email protected]>");
  1403. MODULE_DESCRIPTION(
  1404. "PMC-Sierra PM8001/8006/8081/8088/8089/8074/8076/8077/8070/8072 "
  1405. "SAS/SATA controller driver");
  1406. MODULE_VERSION(DRV_VERSION);
  1407. MODULE_LICENSE("GPL");
  1408. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);