pm8001_init.c 45 KB

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