pm8001_init.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  1. /*
  2. * PMC-Sierra PM8001/8081/8088/8089 SAS/SATA based host adapters driver
  3. *
  4. * Copyright (c) 2008-2009 USI Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions, and the following disclaimer,
  12. * without modification.
  13. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  14. * substantially similar to the "NO WARRANTY" disclaimer below
  15. * ("Disclaimer") and any redistribution must be conditioned upon
  16. * including a substantially similar Disclaimer requirement for further
  17. * binary redistribution.
  18. * 3. Neither the names of the above-listed copyright holders nor the names
  19. * of any contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * Alternatively, this software may be distributed under the terms of the
  23. * GNU General Public License ("GPL") version 2 as published by the Free
  24. * Software Foundation.
  25. *
  26. * NO WARRANTY
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  36. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGES.
  38. *
  39. */
  40. #include <linux/slab.h>
  41. #include "pm8001_sas.h"
  42. #include "pm8001_chips.h"
  43. static struct scsi_transport_template *pm8001_stt;
  44. /**
  45. * chip info structure to identify chip key functionality as
  46. * encryption available/not, no of ports, hw specific function ref
  47. */
  48. static const struct pm8001_chip_info pm8001_chips[] = {
  49. [chip_8001] = {0, 8, &pm8001_8001_dispatch,},
  50. [chip_8008] = {0, 8, &pm8001_80xx_dispatch,},
  51. [chip_8009] = {1, 8, &pm8001_80xx_dispatch,},
  52. [chip_8018] = {0, 16, &pm8001_80xx_dispatch,},
  53. [chip_8019] = {1, 16, &pm8001_80xx_dispatch,},
  54. [chip_8074] = {0, 8, &pm8001_80xx_dispatch,},
  55. [chip_8076] = {0, 16, &pm8001_80xx_dispatch,},
  56. [chip_8077] = {0, 16, &pm8001_80xx_dispatch,},
  57. [chip_8006] = {0, 16, &pm8001_80xx_dispatch,},
  58. [chip_8070] = {0, 8, &pm8001_80xx_dispatch,},
  59. [chip_8072] = {0, 16, &pm8001_80xx_dispatch,},
  60. };
  61. static int pm8001_id;
  62. LIST_HEAD(hba_list);
  63. struct workqueue_struct *pm8001_wq;
  64. /**
  65. * The main structure which LLDD must register for scsi core.
  66. */
  67. static struct scsi_host_template pm8001_sht = {
  68. .module = THIS_MODULE,
  69. .name = DRV_NAME,
  70. .queuecommand = sas_queuecommand,
  71. .target_alloc = sas_target_alloc,
  72. .slave_configure = sas_slave_configure,
  73. .scan_finished = pm8001_scan_finished,
  74. .scan_start = pm8001_scan_start,
  75. .change_queue_depth = sas_change_queue_depth,
  76. .bios_param = sas_bios_param,
  77. .can_queue = 1,
  78. .this_id = -1,
  79. .sg_tablesize = SG_ALL,
  80. .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
  81. .use_clustering = ENABLE_CLUSTERING,
  82. .eh_device_reset_handler = sas_eh_device_reset_handler,
  83. .eh_bus_reset_handler = sas_eh_bus_reset_handler,
  84. .target_destroy = sas_target_destroy,
  85. .ioctl = sas_ioctl,
  86. .shost_attrs = pm8001_host_attrs,
  87. .track_queue_depth = 1,
  88. };
  89. /**
  90. * Sas layer call this function to execute specific task.
  91. */
  92. static struct sas_domain_function_template pm8001_transport_ops = {
  93. .lldd_dev_found = pm8001_dev_found,
  94. .lldd_dev_gone = pm8001_dev_gone,
  95. .lldd_execute_task = pm8001_queue_command,
  96. .lldd_control_phy = pm8001_phy_control,
  97. .lldd_abort_task = pm8001_abort_task,
  98. .lldd_abort_task_set = pm8001_abort_task_set,
  99. .lldd_clear_aca = pm8001_clear_aca,
  100. .lldd_clear_task_set = pm8001_clear_task_set,
  101. .lldd_I_T_nexus_reset = pm8001_I_T_nexus_reset,
  102. .lldd_lu_reset = pm8001_lu_reset,
  103. .lldd_query_task = pm8001_query_task,
  104. };
  105. /**
  106. *pm8001_phy_init - initiate our adapter phys
  107. *@pm8001_ha: our hba structure.
  108. *@phy_id: phy id.
  109. */
  110. static void pm8001_phy_init(struct pm8001_hba_info *pm8001_ha, int phy_id)
  111. {
  112. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  113. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  114. phy->phy_state = 0;
  115. phy->pm8001_ha = pm8001_ha;
  116. sas_phy->enabled = (phy_id < pm8001_ha->chip->n_phy) ? 1 : 0;
  117. sas_phy->class = SAS;
  118. sas_phy->iproto = SAS_PROTOCOL_ALL;
  119. sas_phy->tproto = 0;
  120. sas_phy->type = PHY_TYPE_PHYSICAL;
  121. sas_phy->role = PHY_ROLE_INITIATOR;
  122. sas_phy->oob_mode = OOB_NOT_CONNECTED;
  123. sas_phy->linkrate = SAS_LINK_RATE_UNKNOWN;
  124. sas_phy->id = phy_id;
  125. sas_phy->sas_addr = &pm8001_ha->sas_addr[0];
  126. sas_phy->frame_rcvd = &phy->frame_rcvd[0];
  127. sas_phy->ha = (struct sas_ha_struct *)pm8001_ha->shost->hostdata;
  128. sas_phy->lldd_phy = phy;
  129. }
  130. /**
  131. *pm8001_free - free hba
  132. *@pm8001_ha: our hba structure.
  133. *
  134. */
  135. static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
  136. {
  137. int i;
  138. if (!pm8001_ha)
  139. return;
  140. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  141. if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
  142. pci_free_consistent(pm8001_ha->pdev,
  143. (pm8001_ha->memoryMap.region[i].total_len +
  144. pm8001_ha->memoryMap.region[i].alignment),
  145. pm8001_ha->memoryMap.region[i].virt_ptr,
  146. pm8001_ha->memoryMap.region[i].phys_addr);
  147. }
  148. }
  149. PM8001_CHIP_DISP->chip_iounmap(pm8001_ha);
  150. if (pm8001_ha->shost)
  151. scsi_host_put(pm8001_ha->shost);
  152. flush_workqueue(pm8001_wq);
  153. kfree(pm8001_ha->tags);
  154. kfree(pm8001_ha);
  155. }
  156. #ifdef PM8001_USE_TASKLET
  157. /**
  158. * tasklet for 64 msi-x interrupt handler
  159. * @opaque: the passed general host adapter struct
  160. * Note: pm8001_tasklet is common for pm8001 & pm80xx
  161. */
  162. static void pm8001_tasklet(unsigned long opaque)
  163. {
  164. struct pm8001_hba_info *pm8001_ha;
  165. struct isr_param *irq_vector;
  166. irq_vector = (struct isr_param *)opaque;
  167. pm8001_ha = irq_vector->drv_inst;
  168. if (unlikely(!pm8001_ha))
  169. BUG_ON(1);
  170. PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
  171. }
  172. #endif
  173. /**
  174. * pm8001_interrupt_handler_msix - main MSIX interrupt handler.
  175. * It obtains the vector number and calls the equivalent bottom
  176. * half or services directly.
  177. * @opaque: the passed outbound queue/vector. Host structure is
  178. * retrieved from the same.
  179. */
  180. static irqreturn_t pm8001_interrupt_handler_msix(int irq, void *opaque)
  181. {
  182. struct isr_param *irq_vector;
  183. struct pm8001_hba_info *pm8001_ha;
  184. irqreturn_t ret = IRQ_HANDLED;
  185. irq_vector = (struct isr_param *)opaque;
  186. pm8001_ha = irq_vector->drv_inst;
  187. if (unlikely(!pm8001_ha))
  188. return IRQ_NONE;
  189. if (!PM8001_CHIP_DISP->is_our_interupt(pm8001_ha))
  190. return IRQ_NONE;
  191. #ifdef PM8001_USE_TASKLET
  192. tasklet_schedule(&pm8001_ha->tasklet[irq_vector->irq_id]);
  193. #else
  194. ret = PM8001_CHIP_DISP->isr(pm8001_ha, irq_vector->irq_id);
  195. #endif
  196. return ret;
  197. }
  198. /**
  199. * pm8001_interrupt_handler_intx - main INTx interrupt handler.
  200. * @dev_id: sas_ha structure. The HBA is retrieved from sas_has structure.
  201. */
  202. static irqreturn_t pm8001_interrupt_handler_intx(int irq, void *dev_id)
  203. {
  204. struct pm8001_hba_info *pm8001_ha;
  205. irqreturn_t ret = IRQ_HANDLED;
  206. struct sas_ha_struct *sha = dev_id;
  207. pm8001_ha = sha->lldd_ha;
  208. if (unlikely(!pm8001_ha))
  209. return IRQ_NONE;
  210. if (!PM8001_CHIP_DISP->is_our_interupt(pm8001_ha))
  211. return IRQ_NONE;
  212. #ifdef PM8001_USE_TASKLET
  213. tasklet_schedule(&pm8001_ha->tasklet[0]);
  214. #else
  215. ret = PM8001_CHIP_DISP->isr(pm8001_ha, 0);
  216. #endif
  217. return ret;
  218. }
  219. /**
  220. * pm8001_alloc - initiate our hba structure and 6 DMAs area.
  221. * @pm8001_ha:our hba structure.
  222. *
  223. */
  224. static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
  225. const struct pci_device_id *ent)
  226. {
  227. int i;
  228. spin_lock_init(&pm8001_ha->lock);
  229. spin_lock_init(&pm8001_ha->bitmap_lock);
  230. PM8001_INIT_DBG(pm8001_ha,
  231. pm8001_printk("pm8001_alloc: PHY:%x\n",
  232. pm8001_ha->chip->n_phy));
  233. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  234. pm8001_phy_init(pm8001_ha, i);
  235. pm8001_ha->port[i].wide_port_phymap = 0;
  236. pm8001_ha->port[i].port_attached = 0;
  237. pm8001_ha->port[i].port_state = 0;
  238. INIT_LIST_HEAD(&pm8001_ha->port[i].list);
  239. }
  240. pm8001_ha->tags = kzalloc(PM8001_MAX_CCB, GFP_KERNEL);
  241. if (!pm8001_ha->tags)
  242. goto err_out;
  243. /* MPI Memory region 1 for AAP Event Log for fw */
  244. pm8001_ha->memoryMap.region[AAP1].num_elements = 1;
  245. pm8001_ha->memoryMap.region[AAP1].element_size = PM8001_EVENT_LOG_SIZE;
  246. pm8001_ha->memoryMap.region[AAP1].total_len = PM8001_EVENT_LOG_SIZE;
  247. pm8001_ha->memoryMap.region[AAP1].alignment = 32;
  248. /* MPI Memory region 2 for IOP Event Log for fw */
  249. pm8001_ha->memoryMap.region[IOP].num_elements = 1;
  250. pm8001_ha->memoryMap.region[IOP].element_size = PM8001_EVENT_LOG_SIZE;
  251. pm8001_ha->memoryMap.region[IOP].total_len = PM8001_EVENT_LOG_SIZE;
  252. pm8001_ha->memoryMap.region[IOP].alignment = 32;
  253. for (i = 0; i < PM8001_MAX_SPCV_INB_NUM; i++) {
  254. /* MPI Memory region 3 for consumer Index of inbound queues */
  255. pm8001_ha->memoryMap.region[CI+i].num_elements = 1;
  256. pm8001_ha->memoryMap.region[CI+i].element_size = 4;
  257. pm8001_ha->memoryMap.region[CI+i].total_len = 4;
  258. pm8001_ha->memoryMap.region[CI+i].alignment = 4;
  259. if ((ent->driver_data) != chip_8001) {
  260. /* MPI Memory region 5 inbound queues */
  261. pm8001_ha->memoryMap.region[IB+i].num_elements =
  262. PM8001_MPI_QUEUE;
  263. pm8001_ha->memoryMap.region[IB+i].element_size = 128;
  264. pm8001_ha->memoryMap.region[IB+i].total_len =
  265. PM8001_MPI_QUEUE * 128;
  266. pm8001_ha->memoryMap.region[IB+i].alignment = 128;
  267. } else {
  268. pm8001_ha->memoryMap.region[IB+i].num_elements =
  269. PM8001_MPI_QUEUE;
  270. pm8001_ha->memoryMap.region[IB+i].element_size = 64;
  271. pm8001_ha->memoryMap.region[IB+i].total_len =
  272. PM8001_MPI_QUEUE * 64;
  273. pm8001_ha->memoryMap.region[IB+i].alignment = 64;
  274. }
  275. }
  276. for (i = 0; i < PM8001_MAX_SPCV_OUTB_NUM; i++) {
  277. /* MPI Memory region 4 for producer Index of outbound queues */
  278. pm8001_ha->memoryMap.region[PI+i].num_elements = 1;
  279. pm8001_ha->memoryMap.region[PI+i].element_size = 4;
  280. pm8001_ha->memoryMap.region[PI+i].total_len = 4;
  281. pm8001_ha->memoryMap.region[PI+i].alignment = 4;
  282. if (ent->driver_data != chip_8001) {
  283. /* MPI Memory region 6 Outbound queues */
  284. pm8001_ha->memoryMap.region[OB+i].num_elements =
  285. PM8001_MPI_QUEUE;
  286. pm8001_ha->memoryMap.region[OB+i].element_size = 128;
  287. pm8001_ha->memoryMap.region[OB+i].total_len =
  288. PM8001_MPI_QUEUE * 128;
  289. pm8001_ha->memoryMap.region[OB+i].alignment = 128;
  290. } else {
  291. /* MPI Memory region 6 Outbound queues */
  292. pm8001_ha->memoryMap.region[OB+i].num_elements =
  293. PM8001_MPI_QUEUE;
  294. pm8001_ha->memoryMap.region[OB+i].element_size = 64;
  295. pm8001_ha->memoryMap.region[OB+i].total_len =
  296. PM8001_MPI_QUEUE * 64;
  297. pm8001_ha->memoryMap.region[OB+i].alignment = 64;
  298. }
  299. }
  300. /* Memory region write DMA*/
  301. pm8001_ha->memoryMap.region[NVMD].num_elements = 1;
  302. pm8001_ha->memoryMap.region[NVMD].element_size = 4096;
  303. pm8001_ha->memoryMap.region[NVMD].total_len = 4096;
  304. /* Memory region for devices*/
  305. pm8001_ha->memoryMap.region[DEV_MEM].num_elements = 1;
  306. pm8001_ha->memoryMap.region[DEV_MEM].element_size = PM8001_MAX_DEVICES *
  307. sizeof(struct pm8001_device);
  308. pm8001_ha->memoryMap.region[DEV_MEM].total_len = PM8001_MAX_DEVICES *
  309. sizeof(struct pm8001_device);
  310. /* Memory region for ccb_info*/
  311. pm8001_ha->memoryMap.region[CCB_MEM].num_elements = 1;
  312. pm8001_ha->memoryMap.region[CCB_MEM].element_size = PM8001_MAX_CCB *
  313. sizeof(struct pm8001_ccb_info);
  314. pm8001_ha->memoryMap.region[CCB_MEM].total_len = PM8001_MAX_CCB *
  315. sizeof(struct pm8001_ccb_info);
  316. /* Memory region for fw flash */
  317. pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096;
  318. pm8001_ha->memoryMap.region[FORENSIC_MEM].num_elements = 1;
  319. pm8001_ha->memoryMap.region[FORENSIC_MEM].total_len = 0x10000;
  320. pm8001_ha->memoryMap.region[FORENSIC_MEM].element_size = 0x10000;
  321. pm8001_ha->memoryMap.region[FORENSIC_MEM].alignment = 0x10000;
  322. for (i = 0; i < USI_MAX_MEMCNT; i++) {
  323. if (pm8001_mem_alloc(pm8001_ha->pdev,
  324. &pm8001_ha->memoryMap.region[i].virt_ptr,
  325. &pm8001_ha->memoryMap.region[i].phys_addr,
  326. &pm8001_ha->memoryMap.region[i].phys_addr_hi,
  327. &pm8001_ha->memoryMap.region[i].phys_addr_lo,
  328. pm8001_ha->memoryMap.region[i].total_len,
  329. pm8001_ha->memoryMap.region[i].alignment) != 0) {
  330. PM8001_FAIL_DBG(pm8001_ha,
  331. pm8001_printk("Mem%d alloc failed\n",
  332. i));
  333. goto err_out;
  334. }
  335. }
  336. pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr;
  337. for (i = 0; i < PM8001_MAX_DEVICES; i++) {
  338. pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
  339. pm8001_ha->devices[i].id = i;
  340. pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
  341. pm8001_ha->devices[i].running_req = 0;
  342. }
  343. pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr;
  344. for (i = 0; i < PM8001_MAX_CCB; i++) {
  345. pm8001_ha->ccb_info[i].ccb_dma_handle =
  346. pm8001_ha->memoryMap.region[CCB_MEM].phys_addr +
  347. i * sizeof(struct pm8001_ccb_info);
  348. pm8001_ha->ccb_info[i].task = NULL;
  349. pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
  350. pm8001_ha->ccb_info[i].device = NULL;
  351. ++pm8001_ha->tags_num;
  352. }
  353. pm8001_ha->flags = PM8001F_INIT_TIME;
  354. /* Initialize tags */
  355. pm8001_tag_init(pm8001_ha);
  356. return 0;
  357. err_out:
  358. return 1;
  359. }
  360. /**
  361. * pm8001_ioremap - remap the pci high physical address to kernal virtual
  362. * address so that we can access them.
  363. * @pm8001_ha:our hba structure.
  364. */
  365. static int pm8001_ioremap(struct pm8001_hba_info *pm8001_ha)
  366. {
  367. u32 bar;
  368. u32 logicalBar = 0;
  369. struct pci_dev *pdev;
  370. pdev = pm8001_ha->pdev;
  371. /* map pci mem (PMC pci base 0-3)*/
  372. for (bar = 0; bar < 6; bar++) {
  373. /*
  374. ** logical BARs for SPC:
  375. ** bar 0 and 1 - logical BAR0
  376. ** bar 2 and 3 - logical BAR1
  377. ** bar4 - logical BAR2
  378. ** bar5 - logical BAR3
  379. ** Skip the appropriate assignments:
  380. */
  381. if ((bar == 1) || (bar == 3))
  382. continue;
  383. if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
  384. pm8001_ha->io_mem[logicalBar].membase =
  385. pci_resource_start(pdev, bar);
  386. pm8001_ha->io_mem[logicalBar].membase &=
  387. (u32)PCI_BASE_ADDRESS_MEM_MASK;
  388. pm8001_ha->io_mem[logicalBar].memsize =
  389. pci_resource_len(pdev, bar);
  390. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  391. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  392. pm8001_ha->io_mem[logicalBar].memsize);
  393. PM8001_INIT_DBG(pm8001_ha,
  394. pm8001_printk("PCI: bar %d, logicalBar %d ",
  395. bar, logicalBar));
  396. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  397. "base addr %llx virt_addr=%llx len=%d\n",
  398. (u64)pm8001_ha->io_mem[logicalBar].membase,
  399. (u64)(unsigned long)
  400. pm8001_ha->io_mem[logicalBar].memvirtaddr,
  401. pm8001_ha->io_mem[logicalBar].memsize));
  402. } else {
  403. pm8001_ha->io_mem[logicalBar].membase = 0;
  404. pm8001_ha->io_mem[logicalBar].memsize = 0;
  405. pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
  406. }
  407. logicalBar++;
  408. }
  409. return 0;
  410. }
  411. /**
  412. * pm8001_pci_alloc - initialize our ha card structure
  413. * @pdev: pci device.
  414. * @ent: ent
  415. * @shost: scsi host struct which has been initialized before.
  416. */
  417. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  418. const struct pci_device_id *ent,
  419. struct Scsi_Host *shost)
  420. {
  421. struct pm8001_hba_info *pm8001_ha;
  422. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  423. int j;
  424. pm8001_ha = sha->lldd_ha;
  425. if (!pm8001_ha)
  426. return NULL;
  427. pm8001_ha->pdev = pdev;
  428. pm8001_ha->dev = &pdev->dev;
  429. pm8001_ha->chip_id = ent->driver_data;
  430. pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
  431. pm8001_ha->irq = pdev->irq;
  432. pm8001_ha->sas = sha;
  433. pm8001_ha->shost = shost;
  434. pm8001_ha->id = pm8001_id++;
  435. pm8001_ha->logging_level = 0x01;
  436. sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
  437. /* IOMB size is 128 for 8088/89 controllers */
  438. if (pm8001_ha->chip_id != chip_8001)
  439. pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
  440. else
  441. pm8001_ha->iomb_size = IOMB_SIZE_SPC;
  442. #ifdef PM8001_USE_TASKLET
  443. /* Tasklet for non msi-x interrupt handler */
  444. if ((!pdev->msix_cap || !pci_msi_enabled())
  445. || (pm8001_ha->chip_id == chip_8001))
  446. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  447. (unsigned long)&(pm8001_ha->irq_vector[0]));
  448. else
  449. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  450. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  451. (unsigned long)&(pm8001_ha->irq_vector[j]));
  452. #endif
  453. pm8001_ioremap(pm8001_ha);
  454. if (!pm8001_alloc(pm8001_ha, ent))
  455. return pm8001_ha;
  456. pm8001_free(pm8001_ha);
  457. return NULL;
  458. }
  459. /**
  460. * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
  461. * @pdev: pci device.
  462. */
  463. static int pci_go_44(struct pci_dev *pdev)
  464. {
  465. int rc;
  466. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
  467. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
  468. if (rc) {
  469. rc = pci_set_consistent_dma_mask(pdev,
  470. DMA_BIT_MASK(32));
  471. if (rc) {
  472. dev_printk(KERN_ERR, &pdev->dev,
  473. "44-bit DMA enable failed\n");
  474. return rc;
  475. }
  476. }
  477. } else {
  478. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  479. if (rc) {
  480. dev_printk(KERN_ERR, &pdev->dev,
  481. "32-bit DMA enable failed\n");
  482. return rc;
  483. }
  484. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  485. if (rc) {
  486. dev_printk(KERN_ERR, &pdev->dev,
  487. "32-bit consistent DMA enable failed\n");
  488. return rc;
  489. }
  490. }
  491. return rc;
  492. }
  493. /**
  494. * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
  495. * @shost: scsi host which has been allocated outside.
  496. * @chip_info: our ha struct.
  497. */
  498. static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
  499. const struct pm8001_chip_info *chip_info)
  500. {
  501. int phy_nr, port_nr;
  502. struct asd_sas_phy **arr_phy;
  503. struct asd_sas_port **arr_port;
  504. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  505. phy_nr = chip_info->n_phy;
  506. port_nr = phy_nr;
  507. memset(sha, 0x00, sizeof(*sha));
  508. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  509. if (!arr_phy)
  510. goto exit;
  511. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  512. if (!arr_port)
  513. goto exit_free2;
  514. sha->sas_phy = arr_phy;
  515. sha->sas_port = arr_port;
  516. sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
  517. if (!sha->lldd_ha)
  518. goto exit_free1;
  519. shost->transportt = pm8001_stt;
  520. shost->max_id = PM8001_MAX_DEVICES;
  521. shost->max_lun = 8;
  522. shost->max_channel = 0;
  523. shost->unique_id = pm8001_id;
  524. shost->max_cmd_len = 16;
  525. shost->can_queue = PM8001_CAN_QUEUE;
  526. shost->cmd_per_lun = 32;
  527. return 0;
  528. exit_free1:
  529. kfree(arr_port);
  530. exit_free2:
  531. kfree(arr_phy);
  532. exit:
  533. return -1;
  534. }
  535. /**
  536. * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
  537. * @shost: scsi host which has been allocated outside
  538. * @chip_info: our ha struct.
  539. */
  540. static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  541. const struct pm8001_chip_info *chip_info)
  542. {
  543. int i = 0;
  544. struct pm8001_hba_info *pm8001_ha;
  545. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  546. pm8001_ha = sha->lldd_ha;
  547. for (i = 0; i < chip_info->n_phy; i++) {
  548. sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
  549. sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
  550. }
  551. sha->sas_ha_name = DRV_NAME;
  552. sha->dev = pm8001_ha->dev;
  553. sha->lldd_module = THIS_MODULE;
  554. sha->sas_addr = &pm8001_ha->sas_addr[0];
  555. sha->num_phys = chip_info->n_phy;
  556. sha->core.shost = shost;
  557. }
  558. /**
  559. * pm8001_init_sas_add - initialize sas address
  560. * @chip_info: our ha struct.
  561. *
  562. * Currently we just set the fixed SAS address to our HBA,for manufacture,
  563. * it should read from the EEPROM
  564. */
  565. static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
  566. {
  567. u8 i, j;
  568. #ifdef PM8001_READ_VPD
  569. /* For new SPC controllers WWN is stored in flash vpd
  570. * For SPC/SPCve controllers WWN is stored in EEPROM
  571. * For Older SPC WWN is stored in NVMD
  572. */
  573. DECLARE_COMPLETION_ONSTACK(completion);
  574. struct pm8001_ioctl_payload payload;
  575. u16 deviceid;
  576. int rc;
  577. pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
  578. pm8001_ha->nvmd_completion = &completion;
  579. if (pm8001_ha->chip_id == chip_8001) {
  580. if (deviceid == 0x8081 || deviceid == 0x0042) {
  581. payload.minor_function = 4;
  582. payload.length = 4096;
  583. } else {
  584. payload.minor_function = 0;
  585. payload.length = 128;
  586. }
  587. } else if ((pm8001_ha->chip_id == chip_8070 ||
  588. pm8001_ha->chip_id == chip_8072) &&
  589. pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
  590. payload.minor_function = 4;
  591. payload.length = 4096;
  592. } else {
  593. payload.minor_function = 1;
  594. payload.length = 4096;
  595. }
  596. payload.offset = 0;
  597. payload.func_specific = kzalloc(payload.length, GFP_KERNEL);
  598. if (!payload.func_specific) {
  599. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("mem alloc fail\n"));
  600. return;
  601. }
  602. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  603. if (rc) {
  604. kfree(payload.func_specific);
  605. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
  606. return;
  607. }
  608. wait_for_completion(&completion);
  609. for (i = 0, j = 0; i <= 7; i++, j++) {
  610. if (pm8001_ha->chip_id == chip_8001) {
  611. if (deviceid == 0x8081)
  612. pm8001_ha->sas_addr[j] =
  613. payload.func_specific[0x704 + i];
  614. else if (deviceid == 0x0042)
  615. pm8001_ha->sas_addr[j] =
  616. payload.func_specific[0x010 + i];
  617. } else if ((pm8001_ha->chip_id == chip_8070 ||
  618. pm8001_ha->chip_id == chip_8072) &&
  619. pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
  620. pm8001_ha->sas_addr[j] =
  621. payload.func_specific[0x010 + i];
  622. } else
  623. pm8001_ha->sas_addr[j] =
  624. payload.func_specific[0x804 + i];
  625. }
  626. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  627. memcpy(&pm8001_ha->phy[i].dev_sas_addr,
  628. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  629. PM8001_INIT_DBG(pm8001_ha,
  630. pm8001_printk("phy %d sas_addr = %016llx\n", i,
  631. pm8001_ha->phy[i].dev_sas_addr));
  632. }
  633. kfree(payload.func_specific);
  634. #else
  635. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  636. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  637. pm8001_ha->phy[i].dev_sas_addr =
  638. cpu_to_be64((u64)
  639. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  640. }
  641. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  642. SAS_ADDR_SIZE);
  643. #endif
  644. }
  645. /*
  646. * pm8001_get_phy_settings_info : Read phy setting values.
  647. * @pm8001_ha : our hba.
  648. */
  649. static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
  650. {
  651. #ifdef PM8001_READ_VPD
  652. /*OPTION ROM FLASH read for the SPC cards */
  653. DECLARE_COMPLETION_ONSTACK(completion);
  654. struct pm8001_ioctl_payload payload;
  655. int rc;
  656. pm8001_ha->nvmd_completion = &completion;
  657. /* SAS ADDRESS read from flash / EEPROM */
  658. payload.minor_function = 6;
  659. payload.offset = 0;
  660. payload.length = 4096;
  661. payload.func_specific = kzalloc(4096, GFP_KERNEL);
  662. if (!payload.func_specific)
  663. return -ENOMEM;
  664. /* Read phy setting values from flash */
  665. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  666. if (rc) {
  667. kfree(payload.func_specific);
  668. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
  669. return -ENOMEM;
  670. }
  671. wait_for_completion(&completion);
  672. pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
  673. kfree(payload.func_specific);
  674. #endif
  675. return 0;
  676. }
  677. struct pm8001_mpi3_phy_pg_trx_config {
  678. u32 LaneLosCfg;
  679. u32 LanePgaCfg1;
  680. u32 LanePisoCfg1;
  681. u32 LanePisoCfg2;
  682. u32 LanePisoCfg3;
  683. u32 LanePisoCfg4;
  684. u32 LanePisoCfg5;
  685. u32 LanePisoCfg6;
  686. u32 LaneBctCtrl;
  687. };
  688. /**
  689. * pm8001_get_internal_phy_settings : Retrieves the internal PHY settings
  690. * @pm8001_ha : our adapter
  691. * @phycfg : PHY config page to populate
  692. */
  693. static
  694. void pm8001_get_internal_phy_settings(struct pm8001_hba_info *pm8001_ha,
  695. struct pm8001_mpi3_phy_pg_trx_config *phycfg)
  696. {
  697. phycfg->LaneLosCfg = 0x00000132;
  698. phycfg->LanePgaCfg1 = 0x00203949;
  699. phycfg->LanePisoCfg1 = 0x000000FF;
  700. phycfg->LanePisoCfg2 = 0xFF000001;
  701. phycfg->LanePisoCfg3 = 0xE7011300;
  702. phycfg->LanePisoCfg4 = 0x631C40C0;
  703. phycfg->LanePisoCfg5 = 0xF8102036;
  704. phycfg->LanePisoCfg6 = 0xF74A1000;
  705. phycfg->LaneBctCtrl = 0x00FB33F8;
  706. }
  707. /**
  708. * pm8001_get_external_phy_settings : Retrieves the external PHY settings
  709. * @pm8001_ha : our adapter
  710. * @phycfg : PHY config page to populate
  711. */
  712. static
  713. void pm8001_get_external_phy_settings(struct pm8001_hba_info *pm8001_ha,
  714. struct pm8001_mpi3_phy_pg_trx_config *phycfg)
  715. {
  716. phycfg->LaneLosCfg = 0x00000132;
  717. phycfg->LanePgaCfg1 = 0x00203949;
  718. phycfg->LanePisoCfg1 = 0x000000FF;
  719. phycfg->LanePisoCfg2 = 0xFF000001;
  720. phycfg->LanePisoCfg3 = 0xE7011300;
  721. phycfg->LanePisoCfg4 = 0x63349140;
  722. phycfg->LanePisoCfg5 = 0xF8102036;
  723. phycfg->LanePisoCfg6 = 0xF80D9300;
  724. phycfg->LaneBctCtrl = 0x00FB33F8;
  725. }
  726. /**
  727. * pm8001_get_phy_mask : Retrieves the mask that denotes if a PHY is int/ext
  728. * @pm8001_ha : our adapter
  729. * @phymask : The PHY mask
  730. */
  731. static
  732. void pm8001_get_phy_mask(struct pm8001_hba_info *pm8001_ha, int *phymask)
  733. {
  734. switch (pm8001_ha->pdev->subsystem_device) {
  735. case 0x0070: /* H1280 - 8 external 0 internal */
  736. case 0x0072: /* H12F0 - 16 external 0 internal */
  737. *phymask = 0x0000;
  738. break;
  739. case 0x0071: /* H1208 - 0 external 8 internal */
  740. case 0x0073: /* H120F - 0 external 16 internal */
  741. *phymask = 0xFFFF;
  742. break;
  743. case 0x0080: /* H1244 - 4 external 4 internal */
  744. *phymask = 0x00F0;
  745. break;
  746. case 0x0081: /* H1248 - 4 external 8 internal */
  747. *phymask = 0x0FF0;
  748. break;
  749. case 0x0082: /* H1288 - 8 external 8 internal */
  750. *phymask = 0xFF00;
  751. break;
  752. default:
  753. PM8001_INIT_DBG(pm8001_ha,
  754. pm8001_printk("Unknown subsystem device=0x%.04x",
  755. pm8001_ha->pdev->subsystem_device));
  756. }
  757. }
  758. /**
  759. * pm8001_set_phy_settings_ven_117c_12Gb : Configure ATTO 12Gb PHY settings
  760. * @pm8001_ha : our adapter
  761. */
  762. static
  763. int pm8001_set_phy_settings_ven_117c_12G(struct pm8001_hba_info *pm8001_ha)
  764. {
  765. struct pm8001_mpi3_phy_pg_trx_config phycfg_int;
  766. struct pm8001_mpi3_phy_pg_trx_config phycfg_ext;
  767. int phymask = 0;
  768. int i = 0;
  769. memset(&phycfg_int, 0, sizeof(phycfg_int));
  770. memset(&phycfg_ext, 0, sizeof(phycfg_ext));
  771. pm8001_get_internal_phy_settings(pm8001_ha, &phycfg_int);
  772. pm8001_get_external_phy_settings(pm8001_ha, &phycfg_ext);
  773. pm8001_get_phy_mask(pm8001_ha, &phymask);
  774. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  775. if (phymask & (1 << i)) {/* Internal PHY */
  776. pm8001_set_phy_profile_single(pm8001_ha, i,
  777. sizeof(phycfg_int) / sizeof(u32),
  778. (u32 *)&phycfg_int);
  779. } else { /* External PHY */
  780. pm8001_set_phy_profile_single(pm8001_ha, i,
  781. sizeof(phycfg_ext) / sizeof(u32),
  782. (u32 *)&phycfg_ext);
  783. }
  784. }
  785. return 0;
  786. }
  787. /**
  788. * pm8001_configure_phy_settings : Configures PHY settings based on vendor ID.
  789. * @pm8001_ha : our hba.
  790. */
  791. static int pm8001_configure_phy_settings(struct pm8001_hba_info *pm8001_ha)
  792. {
  793. switch (pm8001_ha->pdev->subsystem_vendor) {
  794. case PCI_VENDOR_ID_ATTO:
  795. if (pm8001_ha->pdev->device == 0x0042) /* 6Gb */
  796. return 0;
  797. else
  798. return pm8001_set_phy_settings_ven_117c_12G(pm8001_ha);
  799. case PCI_VENDOR_ID_ADAPTEC2:
  800. case 0:
  801. return 0;
  802. default:
  803. return pm8001_get_phy_settings_info(pm8001_ha);
  804. }
  805. }
  806. #ifdef PM8001_USE_MSIX
  807. /**
  808. * pm8001_setup_msix - enable MSI-X interrupt
  809. * @chip_info: our ha struct.
  810. * @irq_handler: irq_handler
  811. */
  812. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  813. {
  814. u32 i = 0, j = 0;
  815. u32 number_of_intr;
  816. int flag = 0;
  817. u32 max_entry;
  818. int rc;
  819. static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
  820. /* SPCv controllers supports 64 msi-x */
  821. if (pm8001_ha->chip_id == chip_8001) {
  822. number_of_intr = 1;
  823. } else {
  824. number_of_intr = PM8001_MAX_MSIX_VEC;
  825. flag &= ~IRQF_SHARED;
  826. }
  827. max_entry = sizeof(pm8001_ha->msix_entries) /
  828. sizeof(pm8001_ha->msix_entries[0]);
  829. for (i = 0; i < max_entry ; i++)
  830. pm8001_ha->msix_entries[i].entry = i;
  831. rc = pci_enable_msix_exact(pm8001_ha->pdev, pm8001_ha->msix_entries,
  832. number_of_intr);
  833. pm8001_ha->number_of_intr = number_of_intr;
  834. if (rc)
  835. return rc;
  836. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  837. "pci_enable_msix_exact request ret:%d no of intr %d\n",
  838. rc, pm8001_ha->number_of_intr));
  839. for (i = 0; i < number_of_intr; i++) {
  840. snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
  841. DRV_NAME"%d", i);
  842. pm8001_ha->irq_vector[i].irq_id = i;
  843. pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
  844. rc = request_irq(pm8001_ha->msix_entries[i].vector,
  845. pm8001_interrupt_handler_msix, flag,
  846. intr_drvname[i], &(pm8001_ha->irq_vector[i]));
  847. if (rc) {
  848. for (j = 0; j < i; j++) {
  849. free_irq(pm8001_ha->msix_entries[j].vector,
  850. &(pm8001_ha->irq_vector[i]));
  851. }
  852. pci_disable_msix(pm8001_ha->pdev);
  853. break;
  854. }
  855. }
  856. return rc;
  857. }
  858. #endif
  859. /**
  860. * pm8001_request_irq - register interrupt
  861. * @chip_info: our ha struct.
  862. */
  863. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  864. {
  865. struct pci_dev *pdev;
  866. int rc;
  867. pdev = pm8001_ha->pdev;
  868. #ifdef PM8001_USE_MSIX
  869. if (pdev->msix_cap && pci_msi_enabled())
  870. return pm8001_setup_msix(pm8001_ha);
  871. else {
  872. PM8001_INIT_DBG(pm8001_ha,
  873. pm8001_printk("MSIX not supported!!!\n"));
  874. goto intx;
  875. }
  876. #endif
  877. intx:
  878. /* initialize the INT-X interrupt */
  879. pm8001_ha->irq_vector[0].irq_id = 0;
  880. pm8001_ha->irq_vector[0].drv_inst = pm8001_ha;
  881. rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
  882. DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
  883. return rc;
  884. }
  885. /**
  886. * pm8001_pci_probe - probe supported device
  887. * @pdev: pci device which kernel has been prepared for.
  888. * @ent: pci device id
  889. *
  890. * This function is the main initialization function, when register a new
  891. * pci driver it is invoked, all struct an hardware initilization should be done
  892. * here, also, register interrupt
  893. */
  894. static int pm8001_pci_probe(struct pci_dev *pdev,
  895. const struct pci_device_id *ent)
  896. {
  897. unsigned int rc;
  898. u32 pci_reg;
  899. u8 i = 0;
  900. struct pm8001_hba_info *pm8001_ha;
  901. struct Scsi_Host *shost = NULL;
  902. const struct pm8001_chip_info *chip;
  903. dev_printk(KERN_INFO, &pdev->dev,
  904. "pm80xx: driver version %s\n", DRV_VERSION);
  905. rc = pci_enable_device(pdev);
  906. if (rc)
  907. goto err_out_enable;
  908. pci_set_master(pdev);
  909. /*
  910. * Enable pci slot busmaster by setting pci command register.
  911. * This is required by FW for Cyclone card.
  912. */
  913. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  914. pci_reg |= 0x157;
  915. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  916. rc = pci_request_regions(pdev, DRV_NAME);
  917. if (rc)
  918. goto err_out_disable;
  919. rc = pci_go_44(pdev);
  920. if (rc)
  921. goto err_out_regions;
  922. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  923. if (!shost) {
  924. rc = -ENOMEM;
  925. goto err_out_regions;
  926. }
  927. chip = &pm8001_chips[ent->driver_data];
  928. SHOST_TO_SAS_HA(shost) =
  929. kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  930. if (!SHOST_TO_SAS_HA(shost)) {
  931. rc = -ENOMEM;
  932. goto err_out_free_host;
  933. }
  934. rc = pm8001_prep_sas_ha_init(shost, chip);
  935. if (rc) {
  936. rc = -ENOMEM;
  937. goto err_out_free;
  938. }
  939. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  940. /* ent->driver variable is used to differentiate between controllers */
  941. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  942. if (!pm8001_ha) {
  943. rc = -ENOMEM;
  944. goto err_out_free;
  945. }
  946. list_add_tail(&pm8001_ha->list, &hba_list);
  947. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  948. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  949. if (rc) {
  950. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  951. "chip_init failed [ret: %d]\n", rc));
  952. goto err_out_ha_free;
  953. }
  954. rc = scsi_add_host(shost, &pdev->dev);
  955. if (rc)
  956. goto err_out_ha_free;
  957. rc = pm8001_request_irq(pm8001_ha);
  958. if (rc) {
  959. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  960. "pm8001_request_irq failed [ret: %d]\n", rc));
  961. goto err_out_shost;
  962. }
  963. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  964. if (pm8001_ha->chip_id != chip_8001) {
  965. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  966. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  967. /* setup thermal configuration. */
  968. pm80xx_set_thermal_config(pm8001_ha);
  969. }
  970. pm8001_init_sas_add(pm8001_ha);
  971. /* phy setting support for motherboard controller */
  972. if (pm8001_configure_phy_settings(pm8001_ha))
  973. goto err_out_shost;
  974. pm8001_post_sas_ha_init(shost, chip);
  975. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  976. if (rc)
  977. goto err_out_shost;
  978. scsi_scan_host(pm8001_ha->shost);
  979. return 0;
  980. err_out_shost:
  981. scsi_remove_host(pm8001_ha->shost);
  982. err_out_ha_free:
  983. pm8001_free(pm8001_ha);
  984. err_out_free:
  985. kfree(SHOST_TO_SAS_HA(shost));
  986. err_out_free_host:
  987. kfree(shost);
  988. err_out_regions:
  989. pci_release_regions(pdev);
  990. err_out_disable:
  991. pci_disable_device(pdev);
  992. err_out_enable:
  993. return rc;
  994. }
  995. static void pm8001_pci_remove(struct pci_dev *pdev)
  996. {
  997. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  998. struct pm8001_hba_info *pm8001_ha;
  999. int i, j;
  1000. pm8001_ha = sha->lldd_ha;
  1001. scsi_remove_host(pm8001_ha->shost);
  1002. sas_unregister_ha(sha);
  1003. sas_remove_host(pm8001_ha->shost);
  1004. list_del(&pm8001_ha->list);
  1005. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1006. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1007. #ifdef PM8001_USE_MSIX
  1008. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1009. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  1010. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1011. free_irq(pm8001_ha->msix_entries[i].vector,
  1012. &(pm8001_ha->irq_vector[i]));
  1013. pci_disable_msix(pdev);
  1014. #else
  1015. free_irq(pm8001_ha->irq, sha);
  1016. #endif
  1017. #ifdef PM8001_USE_TASKLET
  1018. /* For non-msix and msix interrupts */
  1019. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1020. (pm8001_ha->chip_id == chip_8001))
  1021. tasklet_kill(&pm8001_ha->tasklet[0]);
  1022. else
  1023. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1024. tasklet_kill(&pm8001_ha->tasklet[j]);
  1025. #endif
  1026. pm8001_free(pm8001_ha);
  1027. kfree(sha->sas_phy);
  1028. kfree(sha->sas_port);
  1029. kfree(sha);
  1030. pci_release_regions(pdev);
  1031. pci_disable_device(pdev);
  1032. }
  1033. /**
  1034. * pm8001_pci_suspend - power management suspend main entry point
  1035. * @pdev: PCI device struct
  1036. * @state: PM state change to (usually PCI_D3)
  1037. *
  1038. * Returns 0 success, anything else error.
  1039. */
  1040. static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1041. {
  1042. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1043. struct pm8001_hba_info *pm8001_ha;
  1044. int i, j;
  1045. u32 device_state;
  1046. pm8001_ha = sha->lldd_ha;
  1047. sas_suspend_ha(sha);
  1048. flush_workqueue(pm8001_wq);
  1049. scsi_block_requests(pm8001_ha->shost);
  1050. if (!pdev->pm_cap) {
  1051. dev_err(&pdev->dev, " PCI PM not supported\n");
  1052. return -ENODEV;
  1053. }
  1054. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1055. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1056. #ifdef PM8001_USE_MSIX
  1057. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1058. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  1059. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1060. free_irq(pm8001_ha->msix_entries[i].vector,
  1061. &(pm8001_ha->irq_vector[i]));
  1062. pci_disable_msix(pdev);
  1063. #else
  1064. free_irq(pm8001_ha->irq, sha);
  1065. #endif
  1066. #ifdef PM8001_USE_TASKLET
  1067. /* For non-msix and msix interrupts */
  1068. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1069. (pm8001_ha->chip_id == chip_8001))
  1070. tasklet_kill(&pm8001_ha->tasklet[0]);
  1071. else
  1072. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1073. tasklet_kill(&pm8001_ha->tasklet[j]);
  1074. #endif
  1075. device_state = pci_choose_state(pdev, state);
  1076. pm8001_printk("pdev=0x%p, slot=%s, entering "
  1077. "operating state [D%d]\n", pdev,
  1078. pm8001_ha->name, device_state);
  1079. pci_save_state(pdev);
  1080. pci_disable_device(pdev);
  1081. pci_set_power_state(pdev, device_state);
  1082. return 0;
  1083. }
  1084. /**
  1085. * pm8001_pci_resume - power management resume main entry point
  1086. * @pdev: PCI device struct
  1087. *
  1088. * Returns 0 success, anything else error.
  1089. */
  1090. static int pm8001_pci_resume(struct pci_dev *pdev)
  1091. {
  1092. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1093. struct pm8001_hba_info *pm8001_ha;
  1094. int rc;
  1095. u8 i = 0, j;
  1096. u32 device_state;
  1097. DECLARE_COMPLETION_ONSTACK(completion);
  1098. pm8001_ha = sha->lldd_ha;
  1099. device_state = pdev->current_state;
  1100. pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
  1101. "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
  1102. pci_set_power_state(pdev, PCI_D0);
  1103. pci_enable_wake(pdev, PCI_D0, 0);
  1104. pci_restore_state(pdev);
  1105. rc = pci_enable_device(pdev);
  1106. if (rc) {
  1107. pm8001_printk("slot=%s Enable device failed during resume\n",
  1108. pm8001_ha->name);
  1109. goto err_out_enable;
  1110. }
  1111. pci_set_master(pdev);
  1112. rc = pci_go_44(pdev);
  1113. if (rc)
  1114. goto err_out_disable;
  1115. sas_prep_resume_ha(sha);
  1116. /* chip soft rst only for spc */
  1117. if (pm8001_ha->chip_id == chip_8001) {
  1118. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1119. PM8001_INIT_DBG(pm8001_ha,
  1120. pm8001_printk("chip soft reset successful\n"));
  1121. }
  1122. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  1123. if (rc)
  1124. goto err_out_disable;
  1125. /* disable all the interrupt bits */
  1126. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1127. rc = pm8001_request_irq(pm8001_ha);
  1128. if (rc)
  1129. goto err_out_disable;
  1130. #ifdef PM8001_USE_TASKLET
  1131. /* Tasklet for non msi-x interrupt handler */
  1132. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1133. (pm8001_ha->chip_id == chip_8001))
  1134. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  1135. (unsigned long)&(pm8001_ha->irq_vector[0]));
  1136. else
  1137. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1138. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  1139. (unsigned long)&(pm8001_ha->irq_vector[j]));
  1140. #endif
  1141. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  1142. if (pm8001_ha->chip_id != chip_8001) {
  1143. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  1144. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  1145. }
  1146. /* Chip documentation for the 8070 and 8072 SPCv */
  1147. /* states that a 500ms minimum delay is required */
  1148. /* before issuing commands. Otherwise, the firmare */
  1149. /* will enter an unrecoverable state. */
  1150. if (pm8001_ha->chip_id == chip_8070 ||
  1151. pm8001_ha->chip_id == chip_8072) {
  1152. mdelay(500);
  1153. }
  1154. /* Spin up the PHYs */
  1155. pm8001_ha->flags = PM8001F_RUN_TIME;
  1156. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  1157. pm8001_ha->phy[i].enable_completion = &completion;
  1158. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
  1159. wait_for_completion(&completion);
  1160. }
  1161. sas_resume_ha(sha);
  1162. return 0;
  1163. err_out_disable:
  1164. scsi_remove_host(pm8001_ha->shost);
  1165. pci_disable_device(pdev);
  1166. err_out_enable:
  1167. return rc;
  1168. }
  1169. /* update of pci device, vendor id and driver data with
  1170. * unique value for each of the controller
  1171. */
  1172. static struct pci_device_id pm8001_pci_table[] = {
  1173. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  1174. { PCI_VDEVICE(PMC_Sierra, 0x8006), chip_8006 },
  1175. { PCI_VDEVICE(ADAPTEC2, 0x8006), chip_8006 },
  1176. { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
  1177. /* Support for SPC/SPCv/SPCve controllers */
  1178. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  1179. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  1180. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  1181. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  1182. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  1183. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  1184. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  1185. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  1186. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  1187. { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
  1188. { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
  1189. { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
  1190. { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
  1191. { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
  1192. { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
  1193. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1194. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  1195. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1196. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  1197. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1198. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  1199. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1200. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  1201. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1202. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  1203. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1204. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  1205. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1206. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  1207. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1208. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  1209. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1210. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  1211. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1212. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  1213. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1214. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
  1215. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1216. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
  1217. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1218. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
  1219. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1220. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
  1221. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1222. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
  1223. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1224. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
  1225. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1226. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
  1227. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1228. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
  1229. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1230. PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
  1231. { PCI_VENDOR_ID_ATTO, 0x8070,
  1232. PCI_VENDOR_ID_ATTO, 0x0070, 0, 0, chip_8070 },
  1233. { PCI_VENDOR_ID_ATTO, 0x8070,
  1234. PCI_VENDOR_ID_ATTO, 0x0071, 0, 0, chip_8070 },
  1235. { PCI_VENDOR_ID_ATTO, 0x8072,
  1236. PCI_VENDOR_ID_ATTO, 0x0072, 0, 0, chip_8072 },
  1237. { PCI_VENDOR_ID_ATTO, 0x8072,
  1238. PCI_VENDOR_ID_ATTO, 0x0073, 0, 0, chip_8072 },
  1239. { PCI_VENDOR_ID_ATTO, 0x8070,
  1240. PCI_VENDOR_ID_ATTO, 0x0080, 0, 0, chip_8070 },
  1241. { PCI_VENDOR_ID_ATTO, 0x8072,
  1242. PCI_VENDOR_ID_ATTO, 0x0081, 0, 0, chip_8072 },
  1243. { PCI_VENDOR_ID_ATTO, 0x8072,
  1244. PCI_VENDOR_ID_ATTO, 0x0082, 0, 0, chip_8072 },
  1245. {} /* terminate list */
  1246. };
  1247. static struct pci_driver pm8001_pci_driver = {
  1248. .name = DRV_NAME,
  1249. .id_table = pm8001_pci_table,
  1250. .probe = pm8001_pci_probe,
  1251. .remove = pm8001_pci_remove,
  1252. .suspend = pm8001_pci_suspend,
  1253. .resume = pm8001_pci_resume,
  1254. };
  1255. /**
  1256. * pm8001_init - initialize scsi transport template
  1257. */
  1258. static int __init pm8001_init(void)
  1259. {
  1260. int rc = -ENOMEM;
  1261. pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
  1262. if (!pm8001_wq)
  1263. goto err;
  1264. pm8001_id = 0;
  1265. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  1266. if (!pm8001_stt)
  1267. goto err_wq;
  1268. rc = pci_register_driver(&pm8001_pci_driver);
  1269. if (rc)
  1270. goto err_tp;
  1271. return 0;
  1272. err_tp:
  1273. sas_release_transport(pm8001_stt);
  1274. err_wq:
  1275. destroy_workqueue(pm8001_wq);
  1276. err:
  1277. return rc;
  1278. }
  1279. static void __exit pm8001_exit(void)
  1280. {
  1281. pci_unregister_driver(&pm8001_pci_driver);
  1282. sas_release_transport(pm8001_stt);
  1283. destroy_workqueue(pm8001_wq);
  1284. }
  1285. module_init(pm8001_init);
  1286. module_exit(pm8001_exit);
  1287. MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
  1288. MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>");
  1289. MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
  1290. MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
  1291. MODULE_DESCRIPTION(
  1292. "PMC-Sierra PM8001/8006/8081/8088/8089/8074/8076/8077/8070/8072 "
  1293. "SAS/SATA controller driver");
  1294. MODULE_VERSION(DRV_VERSION);
  1295. MODULE_LICENSE("GPL");
  1296. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);