pm8001_init.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  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].memsize =
  387. pci_resource_len(pdev, bar);
  388. pm8001_ha->io_mem[logicalBar].memvirtaddr =
  389. ioremap(pm8001_ha->io_mem[logicalBar].membase,
  390. pm8001_ha->io_mem[logicalBar].memsize);
  391. PM8001_INIT_DBG(pm8001_ha,
  392. pm8001_printk("PCI: bar %d, logicalBar %d ",
  393. bar, logicalBar));
  394. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  395. "base addr %llx virt_addr=%llx len=%d\n",
  396. (u64)pm8001_ha->io_mem[logicalBar].membase,
  397. (u64)(unsigned long)
  398. pm8001_ha->io_mem[logicalBar].memvirtaddr,
  399. pm8001_ha->io_mem[logicalBar].memsize));
  400. } else {
  401. pm8001_ha->io_mem[logicalBar].membase = 0;
  402. pm8001_ha->io_mem[logicalBar].memsize = 0;
  403. pm8001_ha->io_mem[logicalBar].memvirtaddr = 0;
  404. }
  405. logicalBar++;
  406. }
  407. return 0;
  408. }
  409. /**
  410. * pm8001_pci_alloc - initialize our ha card structure
  411. * @pdev: pci device.
  412. * @ent: ent
  413. * @shost: scsi host struct which has been initialized before.
  414. */
  415. static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
  416. const struct pci_device_id *ent,
  417. struct Scsi_Host *shost)
  418. {
  419. struct pm8001_hba_info *pm8001_ha;
  420. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  421. int j;
  422. pm8001_ha = sha->lldd_ha;
  423. if (!pm8001_ha)
  424. return NULL;
  425. pm8001_ha->pdev = pdev;
  426. pm8001_ha->dev = &pdev->dev;
  427. pm8001_ha->chip_id = ent->driver_data;
  428. pm8001_ha->chip = &pm8001_chips[pm8001_ha->chip_id];
  429. pm8001_ha->irq = pdev->irq;
  430. pm8001_ha->sas = sha;
  431. pm8001_ha->shost = shost;
  432. pm8001_ha->id = pm8001_id++;
  433. pm8001_ha->logging_level = 0x01;
  434. sprintf(pm8001_ha->name, "%s%d", DRV_NAME, pm8001_ha->id);
  435. /* IOMB size is 128 for 8088/89 controllers */
  436. if (pm8001_ha->chip_id != chip_8001)
  437. pm8001_ha->iomb_size = IOMB_SIZE_SPCV;
  438. else
  439. pm8001_ha->iomb_size = IOMB_SIZE_SPC;
  440. #ifdef PM8001_USE_TASKLET
  441. /* Tasklet for non msi-x interrupt handler */
  442. if ((!pdev->msix_cap || !pci_msi_enabled())
  443. || (pm8001_ha->chip_id == chip_8001))
  444. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  445. (unsigned long)&(pm8001_ha->irq_vector[0]));
  446. else
  447. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  448. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  449. (unsigned long)&(pm8001_ha->irq_vector[j]));
  450. #endif
  451. pm8001_ioremap(pm8001_ha);
  452. if (!pm8001_alloc(pm8001_ha, ent))
  453. return pm8001_ha;
  454. pm8001_free(pm8001_ha);
  455. return NULL;
  456. }
  457. /**
  458. * pci_go_44 - pm8001 specified, its DMA is 44 bit rather than 64 bit
  459. * @pdev: pci device.
  460. */
  461. static int pci_go_44(struct pci_dev *pdev)
  462. {
  463. int rc;
  464. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
  465. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
  466. if (rc) {
  467. rc = pci_set_consistent_dma_mask(pdev,
  468. DMA_BIT_MASK(32));
  469. if (rc) {
  470. dev_printk(KERN_ERR, &pdev->dev,
  471. "44-bit DMA enable failed\n");
  472. return rc;
  473. }
  474. }
  475. } else {
  476. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  477. if (rc) {
  478. dev_printk(KERN_ERR, &pdev->dev,
  479. "32-bit DMA enable failed\n");
  480. return rc;
  481. }
  482. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  483. if (rc) {
  484. dev_printk(KERN_ERR, &pdev->dev,
  485. "32-bit consistent DMA enable failed\n");
  486. return rc;
  487. }
  488. }
  489. return rc;
  490. }
  491. /**
  492. * pm8001_prep_sas_ha_init - allocate memory in general hba struct && init them.
  493. * @shost: scsi host which has been allocated outside.
  494. * @chip_info: our ha struct.
  495. */
  496. static int pm8001_prep_sas_ha_init(struct Scsi_Host *shost,
  497. const struct pm8001_chip_info *chip_info)
  498. {
  499. int phy_nr, port_nr;
  500. struct asd_sas_phy **arr_phy;
  501. struct asd_sas_port **arr_port;
  502. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  503. phy_nr = chip_info->n_phy;
  504. port_nr = phy_nr;
  505. memset(sha, 0x00, sizeof(*sha));
  506. arr_phy = kcalloc(phy_nr, sizeof(void *), GFP_KERNEL);
  507. if (!arr_phy)
  508. goto exit;
  509. arr_port = kcalloc(port_nr, sizeof(void *), GFP_KERNEL);
  510. if (!arr_port)
  511. goto exit_free2;
  512. sha->sas_phy = arr_phy;
  513. sha->sas_port = arr_port;
  514. sha->lldd_ha = kzalloc(sizeof(struct pm8001_hba_info), GFP_KERNEL);
  515. if (!sha->lldd_ha)
  516. goto exit_free1;
  517. shost->transportt = pm8001_stt;
  518. shost->max_id = PM8001_MAX_DEVICES;
  519. shost->max_lun = 8;
  520. shost->max_channel = 0;
  521. shost->unique_id = pm8001_id;
  522. shost->max_cmd_len = 16;
  523. shost->can_queue = PM8001_CAN_QUEUE;
  524. shost->cmd_per_lun = 32;
  525. return 0;
  526. exit_free1:
  527. kfree(arr_port);
  528. exit_free2:
  529. kfree(arr_phy);
  530. exit:
  531. return -1;
  532. }
  533. /**
  534. * pm8001_post_sas_ha_init - initialize general hba struct defined in libsas
  535. * @shost: scsi host which has been allocated outside
  536. * @chip_info: our ha struct.
  537. */
  538. static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
  539. const struct pm8001_chip_info *chip_info)
  540. {
  541. int i = 0;
  542. struct pm8001_hba_info *pm8001_ha;
  543. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  544. pm8001_ha = sha->lldd_ha;
  545. for (i = 0; i < chip_info->n_phy; i++) {
  546. sha->sas_phy[i] = &pm8001_ha->phy[i].sas_phy;
  547. sha->sas_port[i] = &pm8001_ha->port[i].sas_port;
  548. }
  549. sha->sas_ha_name = DRV_NAME;
  550. sha->dev = pm8001_ha->dev;
  551. sha->lldd_module = THIS_MODULE;
  552. sha->sas_addr = &pm8001_ha->sas_addr[0];
  553. sha->num_phys = chip_info->n_phy;
  554. sha->core.shost = shost;
  555. }
  556. /**
  557. * pm8001_init_sas_add - initialize sas address
  558. * @chip_info: our ha struct.
  559. *
  560. * Currently we just set the fixed SAS address to our HBA,for manufacture,
  561. * it should read from the EEPROM
  562. */
  563. static void pm8001_init_sas_add(struct pm8001_hba_info *pm8001_ha)
  564. {
  565. u8 i, j;
  566. #ifdef PM8001_READ_VPD
  567. /* For new SPC controllers WWN is stored in flash vpd
  568. * For SPC/SPCve controllers WWN is stored in EEPROM
  569. * For Older SPC WWN is stored in NVMD
  570. */
  571. DECLARE_COMPLETION_ONSTACK(completion);
  572. struct pm8001_ioctl_payload payload;
  573. u16 deviceid;
  574. int rc;
  575. pci_read_config_word(pm8001_ha->pdev, PCI_DEVICE_ID, &deviceid);
  576. pm8001_ha->nvmd_completion = &completion;
  577. if (pm8001_ha->chip_id == chip_8001) {
  578. if (deviceid == 0x8081 || deviceid == 0x0042) {
  579. payload.minor_function = 4;
  580. payload.length = 4096;
  581. } else {
  582. payload.minor_function = 0;
  583. payload.length = 128;
  584. }
  585. } else if ((pm8001_ha->chip_id == chip_8070 ||
  586. pm8001_ha->chip_id == chip_8072) &&
  587. pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
  588. payload.minor_function = 4;
  589. payload.length = 4096;
  590. } else {
  591. payload.minor_function = 1;
  592. payload.length = 4096;
  593. }
  594. payload.offset = 0;
  595. payload.func_specific = kzalloc(payload.length, GFP_KERNEL);
  596. if (!payload.func_specific) {
  597. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("mem alloc fail\n"));
  598. return;
  599. }
  600. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  601. if (rc) {
  602. kfree(payload.func_specific);
  603. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
  604. return;
  605. }
  606. wait_for_completion(&completion);
  607. for (i = 0, j = 0; i <= 7; i++, j++) {
  608. if (pm8001_ha->chip_id == chip_8001) {
  609. if (deviceid == 0x8081)
  610. pm8001_ha->sas_addr[j] =
  611. payload.func_specific[0x704 + i];
  612. else if (deviceid == 0x0042)
  613. pm8001_ha->sas_addr[j] =
  614. payload.func_specific[0x010 + i];
  615. } else if ((pm8001_ha->chip_id == chip_8070 ||
  616. pm8001_ha->chip_id == chip_8072) &&
  617. pm8001_ha->pdev->subsystem_vendor == PCI_VENDOR_ID_ATTO) {
  618. pm8001_ha->sas_addr[j] =
  619. payload.func_specific[0x010 + i];
  620. } else
  621. pm8001_ha->sas_addr[j] =
  622. payload.func_specific[0x804 + i];
  623. }
  624. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  625. memcpy(&pm8001_ha->phy[i].dev_sas_addr,
  626. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  627. PM8001_INIT_DBG(pm8001_ha,
  628. pm8001_printk("phy %d sas_addr = %016llx\n", i,
  629. pm8001_ha->phy[i].dev_sas_addr));
  630. }
  631. kfree(payload.func_specific);
  632. #else
  633. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  634. pm8001_ha->phy[i].dev_sas_addr = 0x50010c600047f9d0ULL;
  635. pm8001_ha->phy[i].dev_sas_addr =
  636. cpu_to_be64((u64)
  637. (*(u64 *)&pm8001_ha->phy[i].dev_sas_addr));
  638. }
  639. memcpy(pm8001_ha->sas_addr, &pm8001_ha->phy[0].dev_sas_addr,
  640. SAS_ADDR_SIZE);
  641. #endif
  642. }
  643. /*
  644. * pm8001_get_phy_settings_info : Read phy setting values.
  645. * @pm8001_ha : our hba.
  646. */
  647. static int pm8001_get_phy_settings_info(struct pm8001_hba_info *pm8001_ha)
  648. {
  649. #ifdef PM8001_READ_VPD
  650. /*OPTION ROM FLASH read for the SPC cards */
  651. DECLARE_COMPLETION_ONSTACK(completion);
  652. struct pm8001_ioctl_payload payload;
  653. int rc;
  654. pm8001_ha->nvmd_completion = &completion;
  655. /* SAS ADDRESS read from flash / EEPROM */
  656. payload.minor_function = 6;
  657. payload.offset = 0;
  658. payload.length = 4096;
  659. payload.func_specific = kzalloc(4096, GFP_KERNEL);
  660. if (!payload.func_specific)
  661. return -ENOMEM;
  662. /* Read phy setting values from flash */
  663. rc = PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload);
  664. if (rc) {
  665. kfree(payload.func_specific);
  666. PM8001_INIT_DBG(pm8001_ha, pm8001_printk("nvmd failed\n"));
  667. return -ENOMEM;
  668. }
  669. wait_for_completion(&completion);
  670. pm8001_set_phy_profile(pm8001_ha, sizeof(u8), payload.func_specific);
  671. kfree(payload.func_specific);
  672. #endif
  673. return 0;
  674. }
  675. struct pm8001_mpi3_phy_pg_trx_config {
  676. u32 LaneLosCfg;
  677. u32 LanePgaCfg1;
  678. u32 LanePisoCfg1;
  679. u32 LanePisoCfg2;
  680. u32 LanePisoCfg3;
  681. u32 LanePisoCfg4;
  682. u32 LanePisoCfg5;
  683. u32 LanePisoCfg6;
  684. u32 LaneBctCtrl;
  685. };
  686. /**
  687. * pm8001_get_internal_phy_settings : Retrieves the internal PHY settings
  688. * @pm8001_ha : our adapter
  689. * @phycfg : PHY config page to populate
  690. */
  691. static
  692. void pm8001_get_internal_phy_settings(struct pm8001_hba_info *pm8001_ha,
  693. struct pm8001_mpi3_phy_pg_trx_config *phycfg)
  694. {
  695. phycfg->LaneLosCfg = 0x00000132;
  696. phycfg->LanePgaCfg1 = 0x00203949;
  697. phycfg->LanePisoCfg1 = 0x000000FF;
  698. phycfg->LanePisoCfg2 = 0xFF000001;
  699. phycfg->LanePisoCfg3 = 0xE7011300;
  700. phycfg->LanePisoCfg4 = 0x631C40C0;
  701. phycfg->LanePisoCfg5 = 0xF8102036;
  702. phycfg->LanePisoCfg6 = 0xF74A1000;
  703. phycfg->LaneBctCtrl = 0x00FB33F8;
  704. }
  705. /**
  706. * pm8001_get_external_phy_settings : Retrieves the external PHY settings
  707. * @pm8001_ha : our adapter
  708. * @phycfg : PHY config page to populate
  709. */
  710. static
  711. void pm8001_get_external_phy_settings(struct pm8001_hba_info *pm8001_ha,
  712. struct pm8001_mpi3_phy_pg_trx_config *phycfg)
  713. {
  714. phycfg->LaneLosCfg = 0x00000132;
  715. phycfg->LanePgaCfg1 = 0x00203949;
  716. phycfg->LanePisoCfg1 = 0x000000FF;
  717. phycfg->LanePisoCfg2 = 0xFF000001;
  718. phycfg->LanePisoCfg3 = 0xE7011300;
  719. phycfg->LanePisoCfg4 = 0x63349140;
  720. phycfg->LanePisoCfg5 = 0xF8102036;
  721. phycfg->LanePisoCfg6 = 0xF80D9300;
  722. phycfg->LaneBctCtrl = 0x00FB33F8;
  723. }
  724. /**
  725. * pm8001_get_phy_mask : Retrieves the mask that denotes if a PHY is int/ext
  726. * @pm8001_ha : our adapter
  727. * @phymask : The PHY mask
  728. */
  729. static
  730. void pm8001_get_phy_mask(struct pm8001_hba_info *pm8001_ha, int *phymask)
  731. {
  732. switch (pm8001_ha->pdev->subsystem_device) {
  733. case 0x0070: /* H1280 - 8 external 0 internal */
  734. case 0x0072: /* H12F0 - 16 external 0 internal */
  735. *phymask = 0x0000;
  736. break;
  737. case 0x0071: /* H1208 - 0 external 8 internal */
  738. case 0x0073: /* H120F - 0 external 16 internal */
  739. *phymask = 0xFFFF;
  740. break;
  741. case 0x0080: /* H1244 - 4 external 4 internal */
  742. *phymask = 0x00F0;
  743. break;
  744. case 0x0081: /* H1248 - 4 external 8 internal */
  745. *phymask = 0x0FF0;
  746. break;
  747. case 0x0082: /* H1288 - 8 external 8 internal */
  748. *phymask = 0xFF00;
  749. break;
  750. default:
  751. PM8001_INIT_DBG(pm8001_ha,
  752. pm8001_printk("Unknown subsystem device=0x%.04x",
  753. pm8001_ha->pdev->subsystem_device));
  754. }
  755. }
  756. /**
  757. * pm8001_set_phy_settings_ven_117c_12Gb : Configure ATTO 12Gb PHY settings
  758. * @pm8001_ha : our adapter
  759. */
  760. static
  761. int pm8001_set_phy_settings_ven_117c_12G(struct pm8001_hba_info *pm8001_ha)
  762. {
  763. struct pm8001_mpi3_phy_pg_trx_config phycfg_int;
  764. struct pm8001_mpi3_phy_pg_trx_config phycfg_ext;
  765. int phymask = 0;
  766. int i = 0;
  767. memset(&phycfg_int, 0, sizeof(phycfg_int));
  768. memset(&phycfg_ext, 0, sizeof(phycfg_ext));
  769. pm8001_get_internal_phy_settings(pm8001_ha, &phycfg_int);
  770. pm8001_get_external_phy_settings(pm8001_ha, &phycfg_ext);
  771. pm8001_get_phy_mask(pm8001_ha, &phymask);
  772. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  773. if (phymask & (1 << i)) {/* Internal PHY */
  774. pm8001_set_phy_profile_single(pm8001_ha, i,
  775. sizeof(phycfg_int) / sizeof(u32),
  776. (u32 *)&phycfg_int);
  777. } else { /* External PHY */
  778. pm8001_set_phy_profile_single(pm8001_ha, i,
  779. sizeof(phycfg_ext) / sizeof(u32),
  780. (u32 *)&phycfg_ext);
  781. }
  782. }
  783. return 0;
  784. }
  785. /**
  786. * pm8001_configure_phy_settings : Configures PHY settings based on vendor ID.
  787. * @pm8001_ha : our hba.
  788. */
  789. static int pm8001_configure_phy_settings(struct pm8001_hba_info *pm8001_ha)
  790. {
  791. switch (pm8001_ha->pdev->subsystem_vendor) {
  792. case PCI_VENDOR_ID_ATTO:
  793. if (pm8001_ha->pdev->device == 0x0042) /* 6Gb */
  794. return 0;
  795. else
  796. return pm8001_set_phy_settings_ven_117c_12G(pm8001_ha);
  797. case PCI_VENDOR_ID_ADAPTEC2:
  798. case 0:
  799. return 0;
  800. default:
  801. return pm8001_get_phy_settings_info(pm8001_ha);
  802. }
  803. }
  804. #ifdef PM8001_USE_MSIX
  805. /**
  806. * pm8001_setup_msix - enable MSI-X interrupt
  807. * @chip_info: our ha struct.
  808. * @irq_handler: irq_handler
  809. */
  810. static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
  811. {
  812. u32 i = 0, j = 0;
  813. u32 number_of_intr;
  814. int flag = 0;
  815. u32 max_entry;
  816. int rc;
  817. static char intr_drvname[PM8001_MAX_MSIX_VEC][sizeof(DRV_NAME)+3];
  818. /* SPCv controllers supports 64 msi-x */
  819. if (pm8001_ha->chip_id == chip_8001) {
  820. number_of_intr = 1;
  821. } else {
  822. number_of_intr = PM8001_MAX_MSIX_VEC;
  823. flag &= ~IRQF_SHARED;
  824. }
  825. max_entry = sizeof(pm8001_ha->msix_entries) /
  826. sizeof(pm8001_ha->msix_entries[0]);
  827. for (i = 0; i < max_entry ; i++)
  828. pm8001_ha->msix_entries[i].entry = i;
  829. rc = pci_enable_msix_exact(pm8001_ha->pdev, pm8001_ha->msix_entries,
  830. number_of_intr);
  831. pm8001_ha->number_of_intr = number_of_intr;
  832. if (rc)
  833. return rc;
  834. PM8001_INIT_DBG(pm8001_ha, pm8001_printk(
  835. "pci_enable_msix_exact request ret:%d no of intr %d\n",
  836. rc, pm8001_ha->number_of_intr));
  837. for (i = 0; i < number_of_intr; i++) {
  838. snprintf(intr_drvname[i], sizeof(intr_drvname[0]),
  839. DRV_NAME"%d", i);
  840. pm8001_ha->irq_vector[i].irq_id = i;
  841. pm8001_ha->irq_vector[i].drv_inst = pm8001_ha;
  842. rc = request_irq(pm8001_ha->msix_entries[i].vector,
  843. pm8001_interrupt_handler_msix, flag,
  844. intr_drvname[i], &(pm8001_ha->irq_vector[i]));
  845. if (rc) {
  846. for (j = 0; j < i; j++) {
  847. free_irq(pm8001_ha->msix_entries[j].vector,
  848. &(pm8001_ha->irq_vector[i]));
  849. }
  850. pci_disable_msix(pm8001_ha->pdev);
  851. break;
  852. }
  853. }
  854. return rc;
  855. }
  856. #endif
  857. /**
  858. * pm8001_request_irq - register interrupt
  859. * @chip_info: our ha struct.
  860. */
  861. static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
  862. {
  863. struct pci_dev *pdev;
  864. int rc;
  865. pdev = pm8001_ha->pdev;
  866. #ifdef PM8001_USE_MSIX
  867. if (pdev->msix_cap && pci_msi_enabled())
  868. return pm8001_setup_msix(pm8001_ha);
  869. else {
  870. PM8001_INIT_DBG(pm8001_ha,
  871. pm8001_printk("MSIX not supported!!!\n"));
  872. goto intx;
  873. }
  874. #endif
  875. intx:
  876. /* initialize the INT-X interrupt */
  877. pm8001_ha->irq_vector[0].irq_id = 0;
  878. pm8001_ha->irq_vector[0].drv_inst = pm8001_ha;
  879. rc = request_irq(pdev->irq, pm8001_interrupt_handler_intx, IRQF_SHARED,
  880. DRV_NAME, SHOST_TO_SAS_HA(pm8001_ha->shost));
  881. return rc;
  882. }
  883. /**
  884. * pm8001_pci_probe - probe supported device
  885. * @pdev: pci device which kernel has been prepared for.
  886. * @ent: pci device id
  887. *
  888. * This function is the main initialization function, when register a new
  889. * pci driver it is invoked, all struct an hardware initilization should be done
  890. * here, also, register interrupt
  891. */
  892. static int pm8001_pci_probe(struct pci_dev *pdev,
  893. const struct pci_device_id *ent)
  894. {
  895. unsigned int rc;
  896. u32 pci_reg;
  897. u8 i = 0;
  898. struct pm8001_hba_info *pm8001_ha;
  899. struct Scsi_Host *shost = NULL;
  900. const struct pm8001_chip_info *chip;
  901. dev_printk(KERN_INFO, &pdev->dev,
  902. "pm80xx: driver version %s\n", DRV_VERSION);
  903. rc = pci_enable_device(pdev);
  904. if (rc)
  905. goto err_out_enable;
  906. pci_set_master(pdev);
  907. /*
  908. * Enable pci slot busmaster by setting pci command register.
  909. * This is required by FW for Cyclone card.
  910. */
  911. pci_read_config_dword(pdev, PCI_COMMAND, &pci_reg);
  912. pci_reg |= 0x157;
  913. pci_write_config_dword(pdev, PCI_COMMAND, pci_reg);
  914. rc = pci_request_regions(pdev, DRV_NAME);
  915. if (rc)
  916. goto err_out_disable;
  917. rc = pci_go_44(pdev);
  918. if (rc)
  919. goto err_out_regions;
  920. shost = scsi_host_alloc(&pm8001_sht, sizeof(void *));
  921. if (!shost) {
  922. rc = -ENOMEM;
  923. goto err_out_regions;
  924. }
  925. chip = &pm8001_chips[ent->driver_data];
  926. SHOST_TO_SAS_HA(shost) =
  927. kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
  928. if (!SHOST_TO_SAS_HA(shost)) {
  929. rc = -ENOMEM;
  930. goto err_out_free_host;
  931. }
  932. rc = pm8001_prep_sas_ha_init(shost, chip);
  933. if (rc) {
  934. rc = -ENOMEM;
  935. goto err_out_free;
  936. }
  937. pci_set_drvdata(pdev, SHOST_TO_SAS_HA(shost));
  938. /* ent->driver variable is used to differentiate between controllers */
  939. pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
  940. if (!pm8001_ha) {
  941. rc = -ENOMEM;
  942. goto err_out_free;
  943. }
  944. list_add_tail(&pm8001_ha->list, &hba_list);
  945. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  946. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  947. if (rc) {
  948. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  949. "chip_init failed [ret: %d]\n", rc));
  950. goto err_out_ha_free;
  951. }
  952. rc = scsi_add_host(shost, &pdev->dev);
  953. if (rc)
  954. goto err_out_ha_free;
  955. rc = pm8001_request_irq(pm8001_ha);
  956. if (rc) {
  957. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk(
  958. "pm8001_request_irq failed [ret: %d]\n", rc));
  959. goto err_out_shost;
  960. }
  961. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  962. if (pm8001_ha->chip_id != chip_8001) {
  963. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  964. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  965. /* setup thermal configuration. */
  966. pm80xx_set_thermal_config(pm8001_ha);
  967. }
  968. pm8001_init_sas_add(pm8001_ha);
  969. /* phy setting support for motherboard controller */
  970. if (pm8001_configure_phy_settings(pm8001_ha))
  971. goto err_out_shost;
  972. pm8001_post_sas_ha_init(shost, chip);
  973. rc = sas_register_ha(SHOST_TO_SAS_HA(shost));
  974. if (rc)
  975. goto err_out_shost;
  976. scsi_scan_host(pm8001_ha->shost);
  977. return 0;
  978. err_out_shost:
  979. scsi_remove_host(pm8001_ha->shost);
  980. err_out_ha_free:
  981. pm8001_free(pm8001_ha);
  982. err_out_free:
  983. kfree(SHOST_TO_SAS_HA(shost));
  984. err_out_free_host:
  985. kfree(shost);
  986. err_out_regions:
  987. pci_release_regions(pdev);
  988. err_out_disable:
  989. pci_disable_device(pdev);
  990. err_out_enable:
  991. return rc;
  992. }
  993. static void pm8001_pci_remove(struct pci_dev *pdev)
  994. {
  995. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  996. struct pm8001_hba_info *pm8001_ha;
  997. int i, j;
  998. pm8001_ha = sha->lldd_ha;
  999. scsi_remove_host(pm8001_ha->shost);
  1000. sas_unregister_ha(sha);
  1001. sas_remove_host(pm8001_ha->shost);
  1002. list_del(&pm8001_ha->list);
  1003. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1004. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1005. #ifdef PM8001_USE_MSIX
  1006. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1007. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  1008. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1009. free_irq(pm8001_ha->msix_entries[i].vector,
  1010. &(pm8001_ha->irq_vector[i]));
  1011. pci_disable_msix(pdev);
  1012. #else
  1013. free_irq(pm8001_ha->irq, sha);
  1014. #endif
  1015. #ifdef PM8001_USE_TASKLET
  1016. /* For non-msix and msix interrupts */
  1017. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1018. (pm8001_ha->chip_id == chip_8001))
  1019. tasklet_kill(&pm8001_ha->tasklet[0]);
  1020. else
  1021. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1022. tasklet_kill(&pm8001_ha->tasklet[j]);
  1023. #endif
  1024. pm8001_free(pm8001_ha);
  1025. kfree(sha->sas_phy);
  1026. kfree(sha->sas_port);
  1027. kfree(sha);
  1028. pci_release_regions(pdev);
  1029. pci_disable_device(pdev);
  1030. }
  1031. /**
  1032. * pm8001_pci_suspend - power management suspend main entry point
  1033. * @pdev: PCI device struct
  1034. * @state: PM state change to (usually PCI_D3)
  1035. *
  1036. * Returns 0 success, anything else error.
  1037. */
  1038. static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1039. {
  1040. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1041. struct pm8001_hba_info *pm8001_ha;
  1042. int i, j;
  1043. u32 device_state;
  1044. pm8001_ha = sha->lldd_ha;
  1045. sas_suspend_ha(sha);
  1046. flush_workqueue(pm8001_wq);
  1047. scsi_block_requests(pm8001_ha->shost);
  1048. if (!pdev->pm_cap) {
  1049. dev_err(&pdev->dev, " PCI PM not supported\n");
  1050. return -ENODEV;
  1051. }
  1052. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1053. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1054. #ifdef PM8001_USE_MSIX
  1055. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1056. synchronize_irq(pm8001_ha->msix_entries[i].vector);
  1057. for (i = 0; i < pm8001_ha->number_of_intr; i++)
  1058. free_irq(pm8001_ha->msix_entries[i].vector,
  1059. &(pm8001_ha->irq_vector[i]));
  1060. pci_disable_msix(pdev);
  1061. #else
  1062. free_irq(pm8001_ha->irq, sha);
  1063. #endif
  1064. #ifdef PM8001_USE_TASKLET
  1065. /* For non-msix and msix interrupts */
  1066. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1067. (pm8001_ha->chip_id == chip_8001))
  1068. tasklet_kill(&pm8001_ha->tasklet[0]);
  1069. else
  1070. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1071. tasklet_kill(&pm8001_ha->tasklet[j]);
  1072. #endif
  1073. device_state = pci_choose_state(pdev, state);
  1074. pm8001_printk("pdev=0x%p, slot=%s, entering "
  1075. "operating state [D%d]\n", pdev,
  1076. pm8001_ha->name, device_state);
  1077. pci_save_state(pdev);
  1078. pci_disable_device(pdev);
  1079. pci_set_power_state(pdev, device_state);
  1080. return 0;
  1081. }
  1082. /**
  1083. * pm8001_pci_resume - power management resume main entry point
  1084. * @pdev: PCI device struct
  1085. *
  1086. * Returns 0 success, anything else error.
  1087. */
  1088. static int pm8001_pci_resume(struct pci_dev *pdev)
  1089. {
  1090. struct sas_ha_struct *sha = pci_get_drvdata(pdev);
  1091. struct pm8001_hba_info *pm8001_ha;
  1092. int rc;
  1093. u8 i = 0, j;
  1094. u32 device_state;
  1095. DECLARE_COMPLETION_ONSTACK(completion);
  1096. pm8001_ha = sha->lldd_ha;
  1097. device_state = pdev->current_state;
  1098. pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
  1099. "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
  1100. pci_set_power_state(pdev, PCI_D0);
  1101. pci_enable_wake(pdev, PCI_D0, 0);
  1102. pci_restore_state(pdev);
  1103. rc = pci_enable_device(pdev);
  1104. if (rc) {
  1105. pm8001_printk("slot=%s Enable device failed during resume\n",
  1106. pm8001_ha->name);
  1107. goto err_out_enable;
  1108. }
  1109. pci_set_master(pdev);
  1110. rc = pci_go_44(pdev);
  1111. if (rc)
  1112. goto err_out_disable;
  1113. sas_prep_resume_ha(sha);
  1114. /* chip soft rst only for spc */
  1115. if (pm8001_ha->chip_id == chip_8001) {
  1116. PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
  1117. PM8001_INIT_DBG(pm8001_ha,
  1118. pm8001_printk("chip soft reset successful\n"));
  1119. }
  1120. rc = PM8001_CHIP_DISP->chip_init(pm8001_ha);
  1121. if (rc)
  1122. goto err_out_disable;
  1123. /* disable all the interrupt bits */
  1124. PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
  1125. rc = pm8001_request_irq(pm8001_ha);
  1126. if (rc)
  1127. goto err_out_disable;
  1128. #ifdef PM8001_USE_TASKLET
  1129. /* Tasklet for non msi-x interrupt handler */
  1130. if ((!pdev->msix_cap || !pci_msi_enabled()) ||
  1131. (pm8001_ha->chip_id == chip_8001))
  1132. tasklet_init(&pm8001_ha->tasklet[0], pm8001_tasklet,
  1133. (unsigned long)&(pm8001_ha->irq_vector[0]));
  1134. else
  1135. for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
  1136. tasklet_init(&pm8001_ha->tasklet[j], pm8001_tasklet,
  1137. (unsigned long)&(pm8001_ha->irq_vector[j]));
  1138. #endif
  1139. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
  1140. if (pm8001_ha->chip_id != chip_8001) {
  1141. for (i = 1; i < pm8001_ha->number_of_intr; i++)
  1142. PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, i);
  1143. }
  1144. /* Chip documentation for the 8070 and 8072 SPCv */
  1145. /* states that a 500ms minimum delay is required */
  1146. /* before issuing commands. Otherwise, the firmware */
  1147. /* will enter an unrecoverable state. */
  1148. if (pm8001_ha->chip_id == chip_8070 ||
  1149. pm8001_ha->chip_id == chip_8072) {
  1150. mdelay(500);
  1151. }
  1152. /* Spin up the PHYs */
  1153. pm8001_ha->flags = PM8001F_RUN_TIME;
  1154. for (i = 0; i < pm8001_ha->chip->n_phy; i++) {
  1155. pm8001_ha->phy[i].enable_completion = &completion;
  1156. PM8001_CHIP_DISP->phy_start_req(pm8001_ha, i);
  1157. wait_for_completion(&completion);
  1158. }
  1159. sas_resume_ha(sha);
  1160. return 0;
  1161. err_out_disable:
  1162. scsi_remove_host(pm8001_ha->shost);
  1163. pci_disable_device(pdev);
  1164. err_out_enable:
  1165. return rc;
  1166. }
  1167. /* update of pci device, vendor id and driver data with
  1168. * unique value for each of the controller
  1169. */
  1170. static struct pci_device_id pm8001_pci_table[] = {
  1171. { PCI_VDEVICE(PMC_Sierra, 0x8001), chip_8001 },
  1172. { PCI_VDEVICE(PMC_Sierra, 0x8006), chip_8006 },
  1173. { PCI_VDEVICE(ADAPTEC2, 0x8006), chip_8006 },
  1174. { PCI_VDEVICE(ATTO, 0x0042), chip_8001 },
  1175. /* Support for SPC/SPCv/SPCve controllers */
  1176. { PCI_VDEVICE(ADAPTEC2, 0x8001), chip_8001 },
  1177. { PCI_VDEVICE(PMC_Sierra, 0x8008), chip_8008 },
  1178. { PCI_VDEVICE(ADAPTEC2, 0x8008), chip_8008 },
  1179. { PCI_VDEVICE(PMC_Sierra, 0x8018), chip_8018 },
  1180. { PCI_VDEVICE(ADAPTEC2, 0x8018), chip_8018 },
  1181. { PCI_VDEVICE(PMC_Sierra, 0x8009), chip_8009 },
  1182. { PCI_VDEVICE(ADAPTEC2, 0x8009), chip_8009 },
  1183. { PCI_VDEVICE(PMC_Sierra, 0x8019), chip_8019 },
  1184. { PCI_VDEVICE(ADAPTEC2, 0x8019), chip_8019 },
  1185. { PCI_VDEVICE(PMC_Sierra, 0x8074), chip_8074 },
  1186. { PCI_VDEVICE(ADAPTEC2, 0x8074), chip_8074 },
  1187. { PCI_VDEVICE(PMC_Sierra, 0x8076), chip_8076 },
  1188. { PCI_VDEVICE(ADAPTEC2, 0x8076), chip_8076 },
  1189. { PCI_VDEVICE(PMC_Sierra, 0x8077), chip_8077 },
  1190. { PCI_VDEVICE(ADAPTEC2, 0x8077), chip_8077 },
  1191. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1192. PCI_VENDOR_ID_ADAPTEC2, 0x0400, 0, 0, chip_8001 },
  1193. { PCI_VENDOR_ID_ADAPTEC2, 0x8081,
  1194. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8001 },
  1195. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1196. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8008 },
  1197. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1198. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8008 },
  1199. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1200. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8009 },
  1201. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1202. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8009 },
  1203. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1204. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8018 },
  1205. { PCI_VENDOR_ID_ADAPTEC2, 0x8088,
  1206. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8018 },
  1207. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1208. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8019 },
  1209. { PCI_VENDOR_ID_ADAPTEC2, 0x8089,
  1210. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8019 },
  1211. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1212. PCI_VENDOR_ID_ADAPTEC2, 0x0800, 0, 0, chip_8074 },
  1213. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1214. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8076 },
  1215. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1216. PCI_VENDOR_ID_ADAPTEC2, 0x1600, 0, 0, chip_8077 },
  1217. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1218. PCI_VENDOR_ID_ADAPTEC2, 0x0008, 0, 0, chip_8074 },
  1219. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1220. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8076 },
  1221. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1222. PCI_VENDOR_ID_ADAPTEC2, 0x0016, 0, 0, chip_8077 },
  1223. { PCI_VENDOR_ID_ADAPTEC2, 0x8076,
  1224. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8076 },
  1225. { PCI_VENDOR_ID_ADAPTEC2, 0x8077,
  1226. PCI_VENDOR_ID_ADAPTEC2, 0x0808, 0, 0, chip_8077 },
  1227. { PCI_VENDOR_ID_ADAPTEC2, 0x8074,
  1228. PCI_VENDOR_ID_ADAPTEC2, 0x0404, 0, 0, chip_8074 },
  1229. { PCI_VENDOR_ID_ATTO, 0x8070,
  1230. PCI_VENDOR_ID_ATTO, 0x0070, 0, 0, chip_8070 },
  1231. { PCI_VENDOR_ID_ATTO, 0x8070,
  1232. PCI_VENDOR_ID_ATTO, 0x0071, 0, 0, chip_8070 },
  1233. { PCI_VENDOR_ID_ATTO, 0x8072,
  1234. PCI_VENDOR_ID_ATTO, 0x0072, 0, 0, chip_8072 },
  1235. { PCI_VENDOR_ID_ATTO, 0x8072,
  1236. PCI_VENDOR_ID_ATTO, 0x0073, 0, 0, chip_8072 },
  1237. { PCI_VENDOR_ID_ATTO, 0x8070,
  1238. PCI_VENDOR_ID_ATTO, 0x0080, 0, 0, chip_8070 },
  1239. { PCI_VENDOR_ID_ATTO, 0x8072,
  1240. PCI_VENDOR_ID_ATTO, 0x0081, 0, 0, chip_8072 },
  1241. { PCI_VENDOR_ID_ATTO, 0x8072,
  1242. PCI_VENDOR_ID_ATTO, 0x0082, 0, 0, chip_8072 },
  1243. {} /* terminate list */
  1244. };
  1245. static struct pci_driver pm8001_pci_driver = {
  1246. .name = DRV_NAME,
  1247. .id_table = pm8001_pci_table,
  1248. .probe = pm8001_pci_probe,
  1249. .remove = pm8001_pci_remove,
  1250. .suspend = pm8001_pci_suspend,
  1251. .resume = pm8001_pci_resume,
  1252. };
  1253. /**
  1254. * pm8001_init - initialize scsi transport template
  1255. */
  1256. static int __init pm8001_init(void)
  1257. {
  1258. int rc = -ENOMEM;
  1259. pm8001_wq = alloc_workqueue("pm80xx", 0, 0);
  1260. if (!pm8001_wq)
  1261. goto err;
  1262. pm8001_id = 0;
  1263. pm8001_stt = sas_domain_attach_transport(&pm8001_transport_ops);
  1264. if (!pm8001_stt)
  1265. goto err_wq;
  1266. rc = pci_register_driver(&pm8001_pci_driver);
  1267. if (rc)
  1268. goto err_tp;
  1269. return 0;
  1270. err_tp:
  1271. sas_release_transport(pm8001_stt);
  1272. err_wq:
  1273. destroy_workqueue(pm8001_wq);
  1274. err:
  1275. return rc;
  1276. }
  1277. static void __exit pm8001_exit(void)
  1278. {
  1279. pci_unregister_driver(&pm8001_pci_driver);
  1280. sas_release_transport(pm8001_stt);
  1281. destroy_workqueue(pm8001_wq);
  1282. }
  1283. module_init(pm8001_init);
  1284. module_exit(pm8001_exit);
  1285. MODULE_AUTHOR("Jack Wang <jack_wang@usish.com>");
  1286. MODULE_AUTHOR("Anand Kumar Santhanam <AnandKumar.Santhanam@pmcs.com>");
  1287. MODULE_AUTHOR("Sangeetha Gnanasekaran <Sangeetha.Gnanasekaran@pmcs.com>");
  1288. MODULE_AUTHOR("Nikith Ganigarakoppal <Nikith.Ganigarakoppal@pmcs.com>");
  1289. MODULE_DESCRIPTION(
  1290. "PMC-Sierra PM8001/8006/8081/8088/8089/8074/8076/8077/8070/8072 "
  1291. "SAS/SATA controller driver");
  1292. MODULE_VERSION(DRV_VERSION);
  1293. MODULE_LICENSE("GPL");
  1294. MODULE_DEVICE_TABLE(pci, pm8001_pci_table);