megaraid_sas_fusion.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252
  1. /*
  2. * Linux MegaRAID driver for SAS based RAID controllers
  3. *
  4. * Copyright (c) 2009-2011 LSI Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * FILE: megaraid_sas_fusion.c
  21. *
  22. * Authors: LSI Corporation
  23. * Sumant Patro
  24. * Adam Radford <linuxraid@lsi.com>
  25. *
  26. * Send feedback to: <megaraidlinux@lsi.com>
  27. *
  28. * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035
  29. * ATTN: Linuxraid
  30. */
  31. #include <linux/kernel.h>
  32. #include <linux/types.h>
  33. #include <linux/pci.h>
  34. #include <linux/list.h>
  35. #include <linux/moduleparam.h>
  36. #include <linux/module.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/delay.h>
  40. #include <linux/uio.h>
  41. #include <linux/uaccess.h>
  42. #include <linux/fs.h>
  43. #include <linux/compat.h>
  44. #include <linux/blkdev.h>
  45. #include <linux/mutex.h>
  46. #include <linux/poll.h>
  47. #include <scsi/scsi.h>
  48. #include <scsi/scsi_cmnd.h>
  49. #include <scsi/scsi_device.h>
  50. #include <scsi/scsi_host.h>
  51. #include "megaraid_sas_fusion.h"
  52. #include "megaraid_sas.h"
  53. extern void megasas_free_cmds(struct megasas_instance *instance);
  54. extern struct megasas_cmd *megasas_get_cmd(struct megasas_instance
  55. *instance);
  56. extern void
  57. megasas_complete_cmd(struct megasas_instance *instance,
  58. struct megasas_cmd *cmd, u8 alt_status);
  59. int megasas_is_ldio(struct scsi_cmnd *cmd);
  60. int
  61. wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd);
  62. void
  63. megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd);
  64. int megasas_alloc_cmds(struct megasas_instance *instance);
  65. int
  66. megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs);
  67. int
  68. megasas_issue_polled(struct megasas_instance *instance,
  69. struct megasas_cmd *cmd);
  70. u8
  71. MR_BuildRaidContext(struct IO_REQUEST_INFO *io_info,
  72. struct RAID_CONTEXT *pRAID_Context,
  73. struct MR_FW_RAID_MAP_ALL *map);
  74. u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_FW_RAID_MAP_ALL *map);
  75. struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_FW_RAID_MAP_ALL *map);
  76. u16 MR_GetLDTgtId(u32 ld, struct MR_FW_RAID_MAP_ALL *map);
  77. void
  78. megasas_check_and_restore_queue_depth(struct megasas_instance *instance);
  79. u8 MR_ValidateMapInfo(struct MR_FW_RAID_MAP_ALL *map,
  80. struct LD_LOAD_BALANCE_INFO *lbInfo);
  81. u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo,
  82. struct IO_REQUEST_INFO *in_info);
  83. int megasas_transition_to_ready(struct megasas_instance *instance);
  84. void megaraid_sas_kill_hba(struct megasas_instance *instance);
  85. extern u32 megasas_dbg_lvl;
  86. /**
  87. * megasas_enable_intr_fusion - Enables interrupts
  88. * @regs: MFI register set
  89. */
  90. void
  91. megasas_enable_intr_fusion(struct megasas_register_set __iomem *regs)
  92. {
  93. writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
  94. /* Dummy readl to force pci flush */
  95. readl(&regs->outbound_intr_mask);
  96. }
  97. /**
  98. * megasas_disable_intr_fusion - Disables interrupt
  99. * @regs: MFI register set
  100. */
  101. void
  102. megasas_disable_intr_fusion(struct megasas_register_set __iomem *regs)
  103. {
  104. u32 mask = 0xFFFFFFFF;
  105. u32 status;
  106. writel(mask, &regs->outbound_intr_mask);
  107. /* Dummy readl to force pci flush */
  108. status = readl(&regs->outbound_intr_mask);
  109. }
  110. int
  111. megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs)
  112. {
  113. u32 status;
  114. /*
  115. * Check if it is our interrupt
  116. */
  117. status = readl(&regs->outbound_intr_status);
  118. if (status & 1) {
  119. writel(status, &regs->outbound_intr_status);
  120. readl(&regs->outbound_intr_status);
  121. return 1;
  122. }
  123. if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK))
  124. return 0;
  125. /*
  126. * dummy read to flush PCI
  127. */
  128. readl(&regs->outbound_intr_status);
  129. return 1;
  130. }
  131. /**
  132. * megasas_get_cmd_fusion - Get a command from the free pool
  133. * @instance: Adapter soft state
  134. *
  135. * Returns a free command from the pool
  136. */
  137. struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance
  138. *instance)
  139. {
  140. unsigned long flags;
  141. struct fusion_context *fusion =
  142. (struct fusion_context *)instance->ctrl_context;
  143. struct megasas_cmd_fusion *cmd = NULL;
  144. spin_lock_irqsave(&fusion->cmd_pool_lock, flags);
  145. if (!list_empty(&fusion->cmd_pool)) {
  146. cmd = list_entry((&fusion->cmd_pool)->next,
  147. struct megasas_cmd_fusion, list);
  148. list_del_init(&cmd->list);
  149. } else {
  150. printk(KERN_ERR "megasas: Command pool (fusion) empty!\n");
  151. }
  152. spin_unlock_irqrestore(&fusion->cmd_pool_lock, flags);
  153. return cmd;
  154. }
  155. /**
  156. * megasas_return_cmd_fusion - Return a cmd to free command pool
  157. * @instance: Adapter soft state
  158. * @cmd: Command packet to be returned to free command pool
  159. */
  160. static inline void
  161. megasas_return_cmd_fusion(struct megasas_instance *instance,
  162. struct megasas_cmd_fusion *cmd)
  163. {
  164. unsigned long flags;
  165. struct fusion_context *fusion =
  166. (struct fusion_context *)instance->ctrl_context;
  167. spin_lock_irqsave(&fusion->cmd_pool_lock, flags);
  168. cmd->scmd = NULL;
  169. cmd->sync_cmd_idx = (u32)ULONG_MAX;
  170. list_add_tail(&cmd->list, &fusion->cmd_pool);
  171. spin_unlock_irqrestore(&fusion->cmd_pool_lock, flags);
  172. }
  173. /**
  174. * megasas_teardown_frame_pool_fusion - Destroy the cmd frame DMA pool
  175. * @instance: Adapter soft state
  176. */
  177. static void megasas_teardown_frame_pool_fusion(
  178. struct megasas_instance *instance)
  179. {
  180. int i;
  181. struct fusion_context *fusion = instance->ctrl_context;
  182. u16 max_cmd = instance->max_fw_cmds;
  183. struct megasas_cmd_fusion *cmd;
  184. if (!fusion->sg_dma_pool || !fusion->sense_dma_pool) {
  185. printk(KERN_ERR "megasas: dma pool is null. SG Pool %p, "
  186. "sense pool : %p\n", fusion->sg_dma_pool,
  187. fusion->sense_dma_pool);
  188. return;
  189. }
  190. /*
  191. * Return all frames to pool
  192. */
  193. for (i = 0; i < max_cmd; i++) {
  194. cmd = fusion->cmd_list[i];
  195. if (cmd->sg_frame)
  196. pci_pool_free(fusion->sg_dma_pool, cmd->sg_frame,
  197. cmd->sg_frame_phys_addr);
  198. if (cmd->sense)
  199. pci_pool_free(fusion->sense_dma_pool, cmd->sense,
  200. cmd->sense_phys_addr);
  201. }
  202. /*
  203. * Now destroy the pool itself
  204. */
  205. pci_pool_destroy(fusion->sg_dma_pool);
  206. pci_pool_destroy(fusion->sense_dma_pool);
  207. fusion->sg_dma_pool = NULL;
  208. fusion->sense_dma_pool = NULL;
  209. }
  210. /**
  211. * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool
  212. * @instance: Adapter soft state
  213. */
  214. void
  215. megasas_free_cmds_fusion(struct megasas_instance *instance)
  216. {
  217. int i;
  218. struct fusion_context *fusion = instance->ctrl_context;
  219. u32 max_cmds, req_sz, reply_sz, io_frames_sz;
  220. req_sz = fusion->request_alloc_sz;
  221. reply_sz = fusion->reply_alloc_sz;
  222. io_frames_sz = fusion->io_frames_alloc_sz;
  223. max_cmds = instance->max_fw_cmds;
  224. /* Free descriptors and request Frames memory */
  225. if (fusion->req_frames_desc)
  226. dma_free_coherent(&instance->pdev->dev, req_sz,
  227. fusion->req_frames_desc,
  228. fusion->req_frames_desc_phys);
  229. if (fusion->reply_frames_desc) {
  230. pci_pool_free(fusion->reply_frames_desc_pool,
  231. fusion->reply_frames_desc,
  232. fusion->reply_frames_desc_phys);
  233. pci_pool_destroy(fusion->reply_frames_desc_pool);
  234. }
  235. if (fusion->io_request_frames) {
  236. pci_pool_free(fusion->io_request_frames_pool,
  237. fusion->io_request_frames,
  238. fusion->io_request_frames_phys);
  239. pci_pool_destroy(fusion->io_request_frames_pool);
  240. }
  241. /* Free the Fusion frame pool */
  242. megasas_teardown_frame_pool_fusion(instance);
  243. /* Free all the commands in the cmd_list */
  244. for (i = 0; i < max_cmds; i++)
  245. kfree(fusion->cmd_list[i]);
  246. /* Free the cmd_list buffer itself */
  247. kfree(fusion->cmd_list);
  248. fusion->cmd_list = NULL;
  249. INIT_LIST_HEAD(&fusion->cmd_pool);
  250. }
  251. /**
  252. * megasas_create_frame_pool_fusion - Creates DMA pool for cmd frames
  253. * @instance: Adapter soft state
  254. *
  255. */
  256. static int megasas_create_frame_pool_fusion(struct megasas_instance *instance)
  257. {
  258. int i;
  259. u32 max_cmd;
  260. struct fusion_context *fusion;
  261. struct megasas_cmd_fusion *cmd;
  262. u32 total_sz_chain_frame;
  263. fusion = instance->ctrl_context;
  264. max_cmd = instance->max_fw_cmds;
  265. total_sz_chain_frame = MEGASAS_MAX_SZ_CHAIN_FRAME;
  266. /*
  267. * Use DMA pool facility provided by PCI layer
  268. */
  269. fusion->sg_dma_pool = pci_pool_create("megasas sg pool fusion",
  270. instance->pdev,
  271. total_sz_chain_frame, 4,
  272. 0);
  273. if (!fusion->sg_dma_pool) {
  274. printk(KERN_DEBUG "megasas: failed to setup request pool "
  275. "fusion\n");
  276. return -ENOMEM;
  277. }
  278. fusion->sense_dma_pool = pci_pool_create("megasas sense pool fusion",
  279. instance->pdev,
  280. SCSI_SENSE_BUFFERSIZE, 64, 0);
  281. if (!fusion->sense_dma_pool) {
  282. printk(KERN_DEBUG "megasas: failed to setup sense pool "
  283. "fusion\n");
  284. pci_pool_destroy(fusion->sg_dma_pool);
  285. fusion->sg_dma_pool = NULL;
  286. return -ENOMEM;
  287. }
  288. /*
  289. * Allocate and attach a frame to each of the commands in cmd_list
  290. */
  291. for (i = 0; i < max_cmd; i++) {
  292. cmd = fusion->cmd_list[i];
  293. cmd->sg_frame = pci_pool_alloc(fusion->sg_dma_pool,
  294. GFP_KERNEL,
  295. &cmd->sg_frame_phys_addr);
  296. cmd->sense = pci_pool_alloc(fusion->sense_dma_pool,
  297. GFP_KERNEL, &cmd->sense_phys_addr);
  298. /*
  299. * megasas_teardown_frame_pool_fusion() takes care of freeing
  300. * whatever has been allocated
  301. */
  302. if (!cmd->sg_frame || !cmd->sense) {
  303. printk(KERN_DEBUG "megasas: pci_pool_alloc failed\n");
  304. megasas_teardown_frame_pool_fusion(instance);
  305. return -ENOMEM;
  306. }
  307. }
  308. return 0;
  309. }
  310. /**
  311. * megasas_alloc_cmds_fusion - Allocates the command packets
  312. * @instance: Adapter soft state
  313. *
  314. *
  315. * Each frame has a 32-bit field called context. This context is used to get
  316. * back the megasas_cmd_fusion from the frame when a frame gets completed
  317. * In this driver, the 32 bit values are the indices into an array cmd_list.
  318. * This array is used only to look up the megasas_cmd_fusion given the context.
  319. * The free commands themselves are maintained in a linked list called cmd_pool.
  320. *
  321. * cmds are formed in the io_request and sg_frame members of the
  322. * megasas_cmd_fusion. The context field is used to get a request descriptor
  323. * and is used as SMID of the cmd.
  324. * SMID value range is from 1 to max_fw_cmds.
  325. */
  326. int
  327. megasas_alloc_cmds_fusion(struct megasas_instance *instance)
  328. {
  329. int i, j;
  330. u32 max_cmd, io_frames_sz;
  331. struct fusion_context *fusion;
  332. struct megasas_cmd_fusion *cmd;
  333. union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
  334. u32 offset;
  335. dma_addr_t io_req_base_phys;
  336. u8 *io_req_base;
  337. fusion = instance->ctrl_context;
  338. max_cmd = instance->max_fw_cmds;
  339. fusion->req_frames_desc =
  340. dma_alloc_coherent(&instance->pdev->dev,
  341. fusion->request_alloc_sz,
  342. &fusion->req_frames_desc_phys, GFP_KERNEL);
  343. if (!fusion->req_frames_desc) {
  344. printk(KERN_ERR "megasas; Could not allocate memory for "
  345. "request_frames\n");
  346. goto fail_req_desc;
  347. }
  348. fusion->reply_frames_desc_pool =
  349. pci_pool_create("reply_frames pool", instance->pdev,
  350. fusion->reply_alloc_sz, 16, 0);
  351. if (!fusion->reply_frames_desc_pool) {
  352. printk(KERN_ERR "megasas; Could not allocate memory for "
  353. "reply_frame pool\n");
  354. goto fail_reply_desc;
  355. }
  356. fusion->reply_frames_desc =
  357. pci_pool_alloc(fusion->reply_frames_desc_pool, GFP_KERNEL,
  358. &fusion->reply_frames_desc_phys);
  359. if (!fusion->reply_frames_desc) {
  360. printk(KERN_ERR "megasas; Could not allocate memory for "
  361. "reply_frame pool\n");
  362. pci_pool_destroy(fusion->reply_frames_desc_pool);
  363. goto fail_reply_desc;
  364. }
  365. reply_desc = fusion->reply_frames_desc;
  366. for (i = 0; i < fusion->reply_q_depth; i++, reply_desc++)
  367. reply_desc->Words = ULLONG_MAX;
  368. io_frames_sz = fusion->io_frames_alloc_sz;
  369. fusion->io_request_frames_pool =
  370. pci_pool_create("io_request_frames pool", instance->pdev,
  371. fusion->io_frames_alloc_sz, 16, 0);
  372. if (!fusion->io_request_frames_pool) {
  373. printk(KERN_ERR "megasas: Could not allocate memory for "
  374. "io_request_frame pool\n");
  375. goto fail_io_frames;
  376. }
  377. fusion->io_request_frames =
  378. pci_pool_alloc(fusion->io_request_frames_pool, GFP_KERNEL,
  379. &fusion->io_request_frames_phys);
  380. if (!fusion->io_request_frames) {
  381. printk(KERN_ERR "megasas: Could not allocate memory for "
  382. "io_request_frames frames\n");
  383. pci_pool_destroy(fusion->io_request_frames_pool);
  384. goto fail_io_frames;
  385. }
  386. /*
  387. * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers.
  388. * Allocate the dynamic array first and then allocate individual
  389. * commands.
  390. */
  391. fusion->cmd_list = kmalloc(sizeof(struct megasas_cmd_fusion *)
  392. *max_cmd, GFP_KERNEL);
  393. if (!fusion->cmd_list) {
  394. printk(KERN_DEBUG "megasas: out of memory. Could not alloc "
  395. "memory for cmd_list_fusion\n");
  396. goto fail_cmd_list;
  397. }
  398. memset(fusion->cmd_list, 0, sizeof(struct megasas_cmd_fusion *)
  399. *max_cmd);
  400. max_cmd = instance->max_fw_cmds;
  401. for (i = 0; i < max_cmd; i++) {
  402. fusion->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd_fusion),
  403. GFP_KERNEL);
  404. if (!fusion->cmd_list[i]) {
  405. printk(KERN_ERR "Could not alloc cmd list fusion\n");
  406. for (j = 0; j < i; j++)
  407. kfree(fusion->cmd_list[j]);
  408. kfree(fusion->cmd_list);
  409. fusion->cmd_list = NULL;
  410. goto fail_cmd_list;
  411. }
  412. }
  413. /* The first 256 bytes (SMID 0) is not used. Don't add to cmd list */
  414. io_req_base = fusion->io_request_frames +
  415. MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
  416. io_req_base_phys = fusion->io_request_frames_phys +
  417. MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
  418. /*
  419. * Add all the commands to command pool (fusion->cmd_pool)
  420. */
  421. /* SMID 0 is reserved. Set SMID/index from 1 */
  422. for (i = 0; i < max_cmd; i++) {
  423. cmd = fusion->cmd_list[i];
  424. offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i;
  425. memset(cmd, 0, sizeof(struct megasas_cmd_fusion));
  426. cmd->index = i + 1;
  427. cmd->scmd = NULL;
  428. cmd->sync_cmd_idx = (u32)ULONG_MAX; /* Set to Invalid */
  429. cmd->instance = instance;
  430. cmd->io_request =
  431. (struct MPI2_RAID_SCSI_IO_REQUEST *)
  432. (io_req_base + offset);
  433. memset(cmd->io_request, 0,
  434. sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
  435. cmd->io_request_phys_addr = io_req_base_phys + offset;
  436. list_add_tail(&cmd->list, &fusion->cmd_pool);
  437. }
  438. /*
  439. * Create a frame pool and assign one frame to each cmd
  440. */
  441. if (megasas_create_frame_pool_fusion(instance)) {
  442. printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n");
  443. megasas_free_cmds_fusion(instance);
  444. goto fail_req_desc;
  445. }
  446. return 0;
  447. fail_cmd_list:
  448. pci_pool_free(fusion->io_request_frames_pool, fusion->io_request_frames,
  449. fusion->io_request_frames_phys);
  450. pci_pool_destroy(fusion->io_request_frames_pool);
  451. fail_io_frames:
  452. dma_free_coherent(&instance->pdev->dev, fusion->request_alloc_sz,
  453. fusion->reply_frames_desc,
  454. fusion->reply_frames_desc_phys);
  455. pci_pool_free(fusion->reply_frames_desc_pool,
  456. fusion->reply_frames_desc,
  457. fusion->reply_frames_desc_phys);
  458. pci_pool_destroy(fusion->reply_frames_desc_pool);
  459. fail_reply_desc:
  460. dma_free_coherent(&instance->pdev->dev, fusion->request_alloc_sz,
  461. fusion->req_frames_desc,
  462. fusion->req_frames_desc_phys);
  463. fail_req_desc:
  464. return -ENOMEM;
  465. }
  466. /**
  467. * wait_and_poll - Issues a polling command
  468. * @instance: Adapter soft state
  469. * @cmd: Command packet to be issued
  470. *
  471. * For polling, MFI requires the cmd_status to be set to 0xFF before posting.
  472. */
  473. int
  474. wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd)
  475. {
  476. int i;
  477. struct megasas_header *frame_hdr = &cmd->frame->hdr;
  478. u32 msecs = MFI_POLL_TIMEOUT_SECS * 1000;
  479. /*
  480. * Wait for cmd_status to change
  481. */
  482. for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) {
  483. rmb();
  484. msleep(20);
  485. }
  486. if (frame_hdr->cmd_status == 0xff)
  487. return -ETIME;
  488. return 0;
  489. }
  490. /**
  491. * megasas_ioc_init_fusion - Initializes the FW
  492. * @instance: Adapter soft state
  493. *
  494. * Issues the IOC Init cmd
  495. */
  496. int
  497. megasas_ioc_init_fusion(struct megasas_instance *instance)
  498. {
  499. struct megasas_init_frame *init_frame;
  500. struct MPI2_IOC_INIT_REQUEST *IOCInitMessage;
  501. dma_addr_t ioc_init_handle;
  502. u32 context;
  503. struct megasas_cmd *cmd;
  504. u8 ret;
  505. struct fusion_context *fusion;
  506. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  507. int i;
  508. struct megasas_header *frame_hdr;
  509. fusion = instance->ctrl_context;
  510. cmd = megasas_get_cmd(instance);
  511. if (!cmd) {
  512. printk(KERN_ERR "Could not allocate cmd for INIT Frame\n");
  513. ret = 1;
  514. goto fail_get_cmd;
  515. }
  516. IOCInitMessage =
  517. dma_alloc_coherent(&instance->pdev->dev,
  518. sizeof(struct MPI2_IOC_INIT_REQUEST),
  519. &ioc_init_handle, GFP_KERNEL);
  520. if (!IOCInitMessage) {
  521. printk(KERN_ERR "Could not allocate memory for "
  522. "IOCInitMessage\n");
  523. ret = 1;
  524. goto fail_fw_init;
  525. }
  526. memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST));
  527. IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT;
  528. IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER;
  529. IOCInitMessage->MsgVersion = MPI2_VERSION;
  530. IOCInitMessage->HeaderVersion = MPI2_HEADER_VERSION;
  531. IOCInitMessage->SystemRequestFrameSize =
  532. MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE / 4;
  533. IOCInitMessage->ReplyDescriptorPostQueueDepth = fusion->reply_q_depth;
  534. IOCInitMessage->ReplyDescriptorPostQueueAddress =
  535. fusion->reply_frames_desc_phys;
  536. IOCInitMessage->SystemRequestFrameBaseAddress =
  537. fusion->io_request_frames_phys;
  538. init_frame = (struct megasas_init_frame *)cmd->frame;
  539. memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
  540. frame_hdr = &cmd->frame->hdr;
  541. context = init_frame->context;
  542. init_frame->context = context;
  543. frame_hdr->cmd_status = 0xFF;
  544. frame_hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
  545. init_frame->cmd = MFI_CMD_INIT;
  546. init_frame->cmd_status = 0xFF;
  547. init_frame->queue_info_new_phys_addr_lo = ioc_init_handle;
  548. init_frame->data_xfer_len = sizeof(struct MPI2_IOC_INIT_REQUEST);
  549. req_desc =
  550. (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)fusion->req_frames_desc;
  551. req_desc->Words = cmd->frame_phys_addr;
  552. req_desc->MFAIo.RequestFlags =
  553. (MEGASAS_REQ_DESCRIPT_FLAGS_MFA <<
  554. MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  555. /*
  556. * disable the intr before firing the init frame
  557. */
  558. instance->instancet->disable_intr(instance->reg_set);
  559. for (i = 0; i < (10 * 1000); i += 20) {
  560. if (readl(&instance->reg_set->doorbell) & 1)
  561. msleep(20);
  562. else
  563. break;
  564. }
  565. instance->instancet->fire_cmd(instance, req_desc->u.low,
  566. req_desc->u.high, instance->reg_set);
  567. wait_and_poll(instance, cmd);
  568. frame_hdr = &cmd->frame->hdr;
  569. if (frame_hdr->cmd_status != 0) {
  570. ret = 1;
  571. goto fail_fw_init;
  572. }
  573. printk(KERN_ERR "megasas:IOC Init cmd success\n");
  574. ret = 0;
  575. fail_fw_init:
  576. megasas_return_cmd(instance, cmd);
  577. if (IOCInitMessage)
  578. dma_free_coherent(&instance->pdev->dev,
  579. sizeof(struct MPI2_IOC_INIT_REQUEST),
  580. IOCInitMessage, ioc_init_handle);
  581. fail_get_cmd:
  582. return ret;
  583. }
  584. /*
  585. * megasas_return_cmd_for_smid - Returns a cmd_fusion for a SMID
  586. * @instance: Adapter soft state
  587. *
  588. */
  589. void
  590. megasas_return_cmd_for_smid(struct megasas_instance *instance, u16 smid)
  591. {
  592. struct fusion_context *fusion;
  593. struct megasas_cmd_fusion *cmd;
  594. fusion = instance->ctrl_context;
  595. cmd = fusion->cmd_list[smid - 1];
  596. megasas_return_cmd_fusion(instance, cmd);
  597. }
  598. /*
  599. * megasas_get_ld_map_info - Returns FW's ld_map structure
  600. * @instance: Adapter soft state
  601. * @pend: Pend the command or not
  602. * Issues an internal command (DCMD) to get the FW's controller PD
  603. * list structure. This information is mainly used to find out SYSTEM
  604. * supported by the FW.
  605. */
  606. static int
  607. megasas_get_ld_map_info(struct megasas_instance *instance)
  608. {
  609. int ret = 0;
  610. struct megasas_cmd *cmd;
  611. struct megasas_dcmd_frame *dcmd;
  612. struct MR_FW_RAID_MAP_ALL *ci;
  613. dma_addr_t ci_h = 0;
  614. u32 size_map_info;
  615. struct fusion_context *fusion;
  616. cmd = megasas_get_cmd(instance);
  617. if (!cmd) {
  618. printk(KERN_DEBUG "megasas: Failed to get cmd for map info.\n");
  619. return -ENOMEM;
  620. }
  621. fusion = instance->ctrl_context;
  622. if (!fusion) {
  623. megasas_return_cmd(instance, cmd);
  624. return 1;
  625. }
  626. dcmd = &cmd->frame->dcmd;
  627. size_map_info = sizeof(struct MR_FW_RAID_MAP) +
  628. (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1));
  629. ci = fusion->ld_map[(instance->map_id & 1)];
  630. ci_h = fusion->ld_map_phys[(instance->map_id & 1)];
  631. if (!ci) {
  632. printk(KERN_DEBUG "Failed to alloc mem for ld_map_info\n");
  633. megasas_return_cmd(instance, cmd);
  634. return -ENOMEM;
  635. }
  636. memset(ci, 0, sizeof(*ci));
  637. memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
  638. dcmd->cmd = MFI_CMD_DCMD;
  639. dcmd->cmd_status = 0xFF;
  640. dcmd->sge_count = 1;
  641. dcmd->flags = MFI_FRAME_DIR_READ;
  642. dcmd->timeout = 0;
  643. dcmd->pad_0 = 0;
  644. dcmd->data_xfer_len = size_map_info;
  645. dcmd->opcode = MR_DCMD_LD_MAP_GET_INFO;
  646. dcmd->sgl.sge32[0].phys_addr = ci_h;
  647. dcmd->sgl.sge32[0].length = size_map_info;
  648. if (!megasas_issue_polled(instance, cmd))
  649. ret = 0;
  650. else {
  651. printk(KERN_ERR "megasas: Get LD Map Info Failed\n");
  652. ret = -1;
  653. }
  654. megasas_return_cmd(instance, cmd);
  655. return ret;
  656. }
  657. u8
  658. megasas_get_map_info(struct megasas_instance *instance)
  659. {
  660. struct fusion_context *fusion = instance->ctrl_context;
  661. fusion->fast_path_io = 0;
  662. if (!megasas_get_ld_map_info(instance)) {
  663. if (MR_ValidateMapInfo(fusion->ld_map[(instance->map_id & 1)],
  664. fusion->load_balance_info)) {
  665. fusion->fast_path_io = 1;
  666. return 0;
  667. }
  668. }
  669. return 1;
  670. }
  671. /*
  672. * megasas_sync_map_info - Returns FW's ld_map structure
  673. * @instance: Adapter soft state
  674. *
  675. * Issues an internal command (DCMD) to get the FW's controller PD
  676. * list structure. This information is mainly used to find out SYSTEM
  677. * supported by the FW.
  678. */
  679. int
  680. megasas_sync_map_info(struct megasas_instance *instance)
  681. {
  682. int ret = 0, i;
  683. struct megasas_cmd *cmd;
  684. struct megasas_dcmd_frame *dcmd;
  685. u32 size_sync_info, num_lds;
  686. struct fusion_context *fusion;
  687. struct MR_LD_TARGET_SYNC *ci = NULL;
  688. struct MR_FW_RAID_MAP_ALL *map;
  689. struct MR_LD_RAID *raid;
  690. struct MR_LD_TARGET_SYNC *ld_sync;
  691. dma_addr_t ci_h = 0;
  692. u32 size_map_info;
  693. cmd = megasas_get_cmd(instance);
  694. if (!cmd) {
  695. printk(KERN_DEBUG "megasas: Failed to get cmd for sync"
  696. "info.\n");
  697. return -ENOMEM;
  698. }
  699. fusion = instance->ctrl_context;
  700. if (!fusion) {
  701. megasas_return_cmd(instance, cmd);
  702. return 1;
  703. }
  704. map = fusion->ld_map[instance->map_id & 1];
  705. num_lds = map->raidMap.ldCount;
  706. dcmd = &cmd->frame->dcmd;
  707. size_sync_info = sizeof(struct MR_LD_TARGET_SYNC) *num_lds;
  708. memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
  709. ci = (struct MR_LD_TARGET_SYNC *)
  710. fusion->ld_map[(instance->map_id - 1) & 1];
  711. memset(ci, 0, sizeof(struct MR_FW_RAID_MAP_ALL));
  712. ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1];
  713. ld_sync = (struct MR_LD_TARGET_SYNC *)ci;
  714. for (i = 0; i < num_lds; i++, ld_sync++) {
  715. raid = MR_LdRaidGet(i, map);
  716. ld_sync->targetId = MR_GetLDTgtId(i, map);
  717. ld_sync->seqNum = raid->seqNum;
  718. }
  719. size_map_info = sizeof(struct MR_FW_RAID_MAP) +
  720. (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1));
  721. dcmd->cmd = MFI_CMD_DCMD;
  722. dcmd->cmd_status = 0xFF;
  723. dcmd->sge_count = 1;
  724. dcmd->flags = MFI_FRAME_DIR_WRITE;
  725. dcmd->timeout = 0;
  726. dcmd->pad_0 = 0;
  727. dcmd->data_xfer_len = size_map_info;
  728. dcmd->mbox.b[0] = num_lds;
  729. dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG;
  730. dcmd->opcode = MR_DCMD_LD_MAP_GET_INFO;
  731. dcmd->sgl.sge32[0].phys_addr = ci_h;
  732. dcmd->sgl.sge32[0].length = size_map_info;
  733. instance->map_update_cmd = cmd;
  734. instance->instancet->issue_dcmd(instance, cmd);
  735. return ret;
  736. }
  737. /**
  738. * megasas_init_adapter_fusion - Initializes the FW
  739. * @instance: Adapter soft state
  740. *
  741. * This is the main function for initializing firmware.
  742. */
  743. u32
  744. megasas_init_adapter_fusion(struct megasas_instance *instance)
  745. {
  746. struct megasas_register_set __iomem *reg_set;
  747. struct fusion_context *fusion;
  748. u32 max_cmd;
  749. int i = 0;
  750. fusion = instance->ctrl_context;
  751. reg_set = instance->reg_set;
  752. /*
  753. * Get various operational parameters from status register
  754. */
  755. instance->max_fw_cmds =
  756. instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
  757. instance->max_fw_cmds = min(instance->max_fw_cmds, (u16)1008);
  758. /*
  759. * Reduce the max supported cmds by 1. This is to ensure that the
  760. * reply_q_sz (1 more than the max cmd that driver may send)
  761. * does not exceed max cmds that the FW can support
  762. */
  763. instance->max_fw_cmds = instance->max_fw_cmds-1;
  764. /* Only internal cmds (DCMD) need to have MFI frames */
  765. instance->max_mfi_cmds = MEGASAS_INT_CMDS;
  766. max_cmd = instance->max_fw_cmds;
  767. fusion->reply_q_depth = ((max_cmd + 1 + 15)/16)*16;
  768. fusion->request_alloc_sz =
  769. sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *max_cmd;
  770. fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)
  771. *(fusion->reply_q_depth);
  772. fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE +
  773. (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE *
  774. (max_cmd + 1)); /* Extra 1 for SMID 0 */
  775. fusion->max_sge_in_main_msg =
  776. (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
  777. offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16;
  778. fusion->max_sge_in_chain =
  779. MEGASAS_MAX_SZ_CHAIN_FRAME / sizeof(union MPI2_SGE_IO_UNION);
  780. instance->max_num_sge = fusion->max_sge_in_main_msg +
  781. fusion->max_sge_in_chain - 2;
  782. /* Used for pass thru MFI frame (DCMD) */
  783. fusion->chain_offset_mfi_pthru =
  784. offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16;
  785. fusion->chain_offset_io_request =
  786. (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
  787. sizeof(union MPI2_SGE_IO_UNION))/16;
  788. fusion->last_reply_idx = 0;
  789. /*
  790. * Allocate memory for descriptors
  791. * Create a pool of commands
  792. */
  793. if (megasas_alloc_cmds(instance))
  794. goto fail_alloc_mfi_cmds;
  795. if (megasas_alloc_cmds_fusion(instance))
  796. goto fail_alloc_cmds;
  797. if (megasas_ioc_init_fusion(instance))
  798. goto fail_ioc_init;
  799. instance->flag_ieee = 1;
  800. fusion->map_sz = sizeof(struct MR_FW_RAID_MAP) +
  801. (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1));
  802. fusion->fast_path_io = 0;
  803. for (i = 0; i < 2; i++) {
  804. fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev,
  805. fusion->map_sz,
  806. &fusion->ld_map_phys[i],
  807. GFP_KERNEL);
  808. if (!fusion->ld_map[i]) {
  809. printk(KERN_ERR "megasas: Could not allocate memory "
  810. "for map info\n");
  811. goto fail_map_info;
  812. }
  813. }
  814. if (!megasas_get_map_info(instance))
  815. megasas_sync_map_info(instance);
  816. return 0;
  817. fail_map_info:
  818. if (i == 1)
  819. dma_free_coherent(&instance->pdev->dev, fusion->map_sz,
  820. fusion->ld_map[0], fusion->ld_map_phys[0]);
  821. fail_ioc_init:
  822. megasas_free_cmds_fusion(instance);
  823. fail_alloc_cmds:
  824. megasas_free_cmds(instance);
  825. fail_alloc_mfi_cmds:
  826. return 1;
  827. }
  828. /**
  829. * megasas_fire_cmd_fusion - Sends command to the FW
  830. * @frame_phys_addr : Physical address of cmd
  831. * @frame_count : Number of frames for the command
  832. * @regs : MFI register set
  833. */
  834. void
  835. megasas_fire_cmd_fusion(struct megasas_instance *instance,
  836. dma_addr_t req_desc_lo,
  837. u32 req_desc_hi,
  838. struct megasas_register_set __iomem *regs)
  839. {
  840. unsigned long flags;
  841. spin_lock_irqsave(&instance->hba_lock, flags);
  842. writel(req_desc_lo,
  843. &(regs)->inbound_low_queue_port);
  844. writel(req_desc_hi, &(regs)->inbound_high_queue_port);
  845. spin_unlock_irqrestore(&instance->hba_lock, flags);
  846. }
  847. /**
  848. * map_cmd_status - Maps FW cmd status to OS cmd status
  849. * @cmd : Pointer to cmd
  850. * @status : status of cmd returned by FW
  851. * @ext_status : ext status of cmd returned by FW
  852. */
  853. void
  854. map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status)
  855. {
  856. switch (status) {
  857. case MFI_STAT_OK:
  858. cmd->scmd->result = DID_OK << 16;
  859. break;
  860. case MFI_STAT_SCSI_IO_FAILED:
  861. case MFI_STAT_LD_INIT_IN_PROGRESS:
  862. cmd->scmd->result = (DID_ERROR << 16) | ext_status;
  863. break;
  864. case MFI_STAT_SCSI_DONE_WITH_ERROR:
  865. cmd->scmd->result = (DID_OK << 16) | ext_status;
  866. if (ext_status == SAM_STAT_CHECK_CONDITION) {
  867. memset(cmd->scmd->sense_buffer, 0,
  868. SCSI_SENSE_BUFFERSIZE);
  869. memcpy(cmd->scmd->sense_buffer, cmd->sense,
  870. SCSI_SENSE_BUFFERSIZE);
  871. cmd->scmd->result |= DRIVER_SENSE << 24;
  872. }
  873. break;
  874. case MFI_STAT_LD_OFFLINE:
  875. case MFI_STAT_DEVICE_NOT_FOUND:
  876. cmd->scmd->result = DID_BAD_TARGET << 16;
  877. break;
  878. default:
  879. printk(KERN_DEBUG "megasas: FW status %#x\n", status);
  880. cmd->scmd->result = DID_ERROR << 16;
  881. break;
  882. }
  883. }
  884. /**
  885. * megasas_make_sgl_fusion - Prepares 32-bit SGL
  886. * @instance: Adapter soft state
  887. * @scp: SCSI command from the mid-layer
  888. * @sgl_ptr: SGL to be filled in
  889. * @cmd: cmd we are working on
  890. *
  891. * If successful, this function returns the number of SG elements.
  892. */
  893. static int
  894. megasas_make_sgl_fusion(struct megasas_instance *instance,
  895. struct scsi_cmnd *scp,
  896. struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
  897. struct megasas_cmd_fusion *cmd)
  898. {
  899. int i, sg_processed;
  900. int sge_count, sge_idx;
  901. struct scatterlist *os_sgl;
  902. struct fusion_context *fusion;
  903. fusion = instance->ctrl_context;
  904. cmd->io_request->ChainOffset = 0;
  905. sge_count = scsi_dma_map(scp);
  906. BUG_ON(sge_count < 0);
  907. if (sge_count > instance->max_num_sge || !sge_count)
  908. return sge_count;
  909. if (sge_count > fusion->max_sge_in_main_msg) {
  910. /* One element to store the chain info */
  911. sge_idx = fusion->max_sge_in_main_msg - 1;
  912. } else
  913. sge_idx = sge_count;
  914. scsi_for_each_sg(scp, os_sgl, sge_count, i) {
  915. sgl_ptr->Length = sg_dma_len(os_sgl);
  916. sgl_ptr->Address = sg_dma_address(os_sgl);
  917. sgl_ptr->Flags = 0;
  918. sgl_ptr++;
  919. sg_processed = i + 1;
  920. if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) &&
  921. (sge_count > fusion->max_sge_in_main_msg)) {
  922. struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
  923. cmd->io_request->ChainOffset =
  924. fusion->chain_offset_io_request;
  925. sg_chain = sgl_ptr;
  926. /* Prepare chain element */
  927. sg_chain->NextChainOffset = 0;
  928. sg_chain->Flags = (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
  929. MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
  930. sg_chain->Length = (sizeof(union MPI2_SGE_IO_UNION)
  931. *(sge_count - sg_processed));
  932. sg_chain->Address = cmd->sg_frame_phys_addr;
  933. sgl_ptr =
  934. (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame;
  935. }
  936. }
  937. return sge_count;
  938. }
  939. /**
  940. * megasas_set_pd_lba - Sets PD LBA
  941. * @cdb: CDB
  942. * @cdb_len: cdb length
  943. * @start_blk: Start block of IO
  944. *
  945. * Used to set the PD LBA in CDB for FP IOs
  946. */
  947. void
  948. megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
  949. struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp,
  950. struct MR_FW_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
  951. {
  952. struct MR_LD_RAID *raid;
  953. u32 ld;
  954. u64 start_blk = io_info->pdBlock;
  955. u8 *cdb = io_request->CDB.CDB32;
  956. u32 num_blocks = io_info->numBlocks;
  957. u8 opcode, flagvals, groupnum, control;
  958. /* Check if T10 PI (DIF) is enabled for this LD */
  959. ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr);
  960. raid = MR_LdRaidGet(ld, local_map_ptr);
  961. if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) {
  962. memset(cdb, 0, sizeof(io_request->CDB.CDB32));
  963. cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD;
  964. cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN;
  965. if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
  966. cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32;
  967. else
  968. cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32;
  969. cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL;
  970. /* LBA */
  971. cdb[12] = (u8)((start_blk >> 56) & 0xff);
  972. cdb[13] = (u8)((start_blk >> 48) & 0xff);
  973. cdb[14] = (u8)((start_blk >> 40) & 0xff);
  974. cdb[15] = (u8)((start_blk >> 32) & 0xff);
  975. cdb[16] = (u8)((start_blk >> 24) & 0xff);
  976. cdb[17] = (u8)((start_blk >> 16) & 0xff);
  977. cdb[18] = (u8)((start_blk >> 8) & 0xff);
  978. cdb[19] = (u8)(start_blk & 0xff);
  979. /* Logical block reference tag */
  980. io_request->CDB.EEDP32.PrimaryReferenceTag =
  981. cpu_to_be32(ref_tag);
  982. io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0xffff;
  983. io_request->DataLength = num_blocks * 512;
  984. io_request->IoFlags = 32; /* Specify 32-byte cdb */
  985. /* Transfer length */
  986. cdb[28] = (u8)((num_blocks >> 24) & 0xff);
  987. cdb[29] = (u8)((num_blocks >> 16) & 0xff);
  988. cdb[30] = (u8)((num_blocks >> 8) & 0xff);
  989. cdb[31] = (u8)(num_blocks & 0xff);
  990. /* set SCSI IO EEDPFlags */
  991. if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) {
  992. io_request->EEDPFlags =
  993. MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  994. MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
  995. MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP |
  996. MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG |
  997. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  998. } else {
  999. io_request->EEDPFlags =
  1000. MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  1001. MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
  1002. }
  1003. io_request->Control |= (0x4 << 26);
  1004. io_request->EEDPBlockSize = MEGASAS_EEDPBLOCKSIZE;
  1005. } else {
  1006. /* Some drives don't support 16/12 byte CDB's, convert to 10 */
  1007. if (((cdb_len == 12) || (cdb_len == 16)) &&
  1008. (start_blk <= 0xffffffff)) {
  1009. if (cdb_len == 16) {
  1010. opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10;
  1011. flagvals = cdb[1];
  1012. groupnum = cdb[14];
  1013. control = cdb[15];
  1014. } else {
  1015. opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10;
  1016. flagvals = cdb[1];
  1017. groupnum = cdb[10];
  1018. control = cdb[11];
  1019. }
  1020. memset(cdb, 0, sizeof(io_request->CDB.CDB32));
  1021. cdb[0] = opcode;
  1022. cdb[1] = flagvals;
  1023. cdb[6] = groupnum;
  1024. cdb[9] = control;
  1025. /* Transfer length */
  1026. cdb[8] = (u8)(num_blocks & 0xff);
  1027. cdb[7] = (u8)((num_blocks >> 8) & 0xff);
  1028. cdb_len = 10;
  1029. }
  1030. /* Normal case, just load LBA here */
  1031. switch (cdb_len) {
  1032. case 6:
  1033. {
  1034. u8 val = cdb[1] & 0xE0;
  1035. cdb[3] = (u8)(start_blk & 0xff);
  1036. cdb[2] = (u8)((start_blk >> 8) & 0xff);
  1037. cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f);
  1038. break;
  1039. }
  1040. case 10:
  1041. cdb[5] = (u8)(start_blk & 0xff);
  1042. cdb[4] = (u8)((start_blk >> 8) & 0xff);
  1043. cdb[3] = (u8)((start_blk >> 16) & 0xff);
  1044. cdb[2] = (u8)((start_blk >> 24) & 0xff);
  1045. break;
  1046. case 12:
  1047. cdb[5] = (u8)(start_blk & 0xff);
  1048. cdb[4] = (u8)((start_blk >> 8) & 0xff);
  1049. cdb[3] = (u8)((start_blk >> 16) & 0xff);
  1050. cdb[2] = (u8)((start_blk >> 24) & 0xff);
  1051. break;
  1052. case 16:
  1053. cdb[9] = (u8)(start_blk & 0xff);
  1054. cdb[8] = (u8)((start_blk >> 8) & 0xff);
  1055. cdb[7] = (u8)((start_blk >> 16) & 0xff);
  1056. cdb[6] = (u8)((start_blk >> 24) & 0xff);
  1057. cdb[5] = (u8)((start_blk >> 32) & 0xff);
  1058. cdb[4] = (u8)((start_blk >> 40) & 0xff);
  1059. cdb[3] = (u8)((start_blk >> 48) & 0xff);
  1060. cdb[2] = (u8)((start_blk >> 56) & 0xff);
  1061. break;
  1062. }
  1063. }
  1064. }
  1065. /**
  1066. * megasas_build_ldio_fusion - Prepares IOs to devices
  1067. * @instance: Adapter soft state
  1068. * @scp: SCSI command
  1069. * @cmd: Command to be prepared
  1070. *
  1071. * Prepares the io_request and chain elements (sg_frame) for IO
  1072. * The IO can be for PD (Fast Path) or LD
  1073. */
  1074. void
  1075. megasas_build_ldio_fusion(struct megasas_instance *instance,
  1076. struct scsi_cmnd *scp,
  1077. struct megasas_cmd_fusion *cmd)
  1078. {
  1079. u8 fp_possible;
  1080. u32 start_lba_lo, start_lba_hi, device_id;
  1081. struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
  1082. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1083. struct IO_REQUEST_INFO io_info;
  1084. struct fusion_context *fusion;
  1085. struct MR_FW_RAID_MAP_ALL *local_map_ptr;
  1086. device_id = MEGASAS_DEV_INDEX(instance, scp);
  1087. fusion = instance->ctrl_context;
  1088. io_request = cmd->io_request;
  1089. io_request->RaidContext.VirtualDiskTgtId = device_id;
  1090. io_request->RaidContext.status = 0;
  1091. io_request->RaidContext.exStatus = 0;
  1092. req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc;
  1093. start_lba_lo = 0;
  1094. start_lba_hi = 0;
  1095. fp_possible = 0;
  1096. /*
  1097. * 6-byte READ(0x08) or WRITE(0x0A) cdb
  1098. */
  1099. if (scp->cmd_len == 6) {
  1100. io_request->DataLength = (u32) scp->cmnd[4];
  1101. start_lba_lo = ((u32) scp->cmnd[1] << 16) |
  1102. ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3];
  1103. start_lba_lo &= 0x1FFFFF;
  1104. }
  1105. /*
  1106. * 10-byte READ(0x28) or WRITE(0x2A) cdb
  1107. */
  1108. else if (scp->cmd_len == 10) {
  1109. io_request->DataLength = (u32) scp->cmnd[8] |
  1110. ((u32) scp->cmnd[7] << 8);
  1111. start_lba_lo = ((u32) scp->cmnd[2] << 24) |
  1112. ((u32) scp->cmnd[3] << 16) |
  1113. ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
  1114. }
  1115. /*
  1116. * 12-byte READ(0xA8) or WRITE(0xAA) cdb
  1117. */
  1118. else if (scp->cmd_len == 12) {
  1119. io_request->DataLength = ((u32) scp->cmnd[6] << 24) |
  1120. ((u32) scp->cmnd[7] << 16) |
  1121. ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
  1122. start_lba_lo = ((u32) scp->cmnd[2] << 24) |
  1123. ((u32) scp->cmnd[3] << 16) |
  1124. ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
  1125. }
  1126. /*
  1127. * 16-byte READ(0x88) or WRITE(0x8A) cdb
  1128. */
  1129. else if (scp->cmd_len == 16) {
  1130. io_request->DataLength = ((u32) scp->cmnd[10] << 24) |
  1131. ((u32) scp->cmnd[11] << 16) |
  1132. ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13];
  1133. start_lba_lo = ((u32) scp->cmnd[6] << 24) |
  1134. ((u32) scp->cmnd[7] << 16) |
  1135. ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
  1136. start_lba_hi = ((u32) scp->cmnd[2] << 24) |
  1137. ((u32) scp->cmnd[3] << 16) |
  1138. ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
  1139. }
  1140. memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO));
  1141. io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
  1142. io_info.numBlocks = io_request->DataLength;
  1143. io_info.ldTgtId = device_id;
  1144. if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
  1145. io_info.isRead = 1;
  1146. local_map_ptr = fusion->ld_map[(instance->map_id & 1)];
  1147. if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >=
  1148. MAX_LOGICAL_DRIVES) || (!fusion->fast_path_io)) {
  1149. io_request->RaidContext.regLockFlags = 0;
  1150. fp_possible = 0;
  1151. } else {
  1152. if (MR_BuildRaidContext(&io_info, &io_request->RaidContext,
  1153. local_map_ptr))
  1154. fp_possible = io_info.fpOkForIo;
  1155. }
  1156. if (fp_possible) {
  1157. megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
  1158. local_map_ptr, start_lba_lo);
  1159. io_request->DataLength = scsi_bufflen(scp);
  1160. io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  1161. cmd->request_desc->SCSIIO.RequestFlags =
  1162. (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
  1163. << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1164. if ((fusion->load_balance_info[device_id].loadBalanceFlag) &&
  1165. (io_info.isRead)) {
  1166. io_info.devHandle =
  1167. get_updated_dev_handle(
  1168. &fusion->load_balance_info[device_id],
  1169. &io_info);
  1170. scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
  1171. } else
  1172. scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
  1173. cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
  1174. io_request->DevHandle = io_info.devHandle;
  1175. } else {
  1176. io_request->RaidContext.timeoutValue =
  1177. local_map_ptr->raidMap.fpPdIoTimeoutSec;
  1178. io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
  1179. io_request->DevHandle = device_id;
  1180. cmd->request_desc->SCSIIO.RequestFlags =
  1181. (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
  1182. << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1183. } /* Not FP */
  1184. }
  1185. /**
  1186. * megasas_build_dcdb_fusion - Prepares IOs to devices
  1187. * @instance: Adapter soft state
  1188. * @scp: SCSI command
  1189. * @cmd: Command to be prepared
  1190. *
  1191. * Prepares the io_request frame for non-io cmds
  1192. */
  1193. static void
  1194. megasas_build_dcdb_fusion(struct megasas_instance *instance,
  1195. struct scsi_cmnd *scmd,
  1196. struct megasas_cmd_fusion *cmd)
  1197. {
  1198. u32 device_id;
  1199. struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
  1200. u16 pd_index = 0;
  1201. struct MR_FW_RAID_MAP_ALL *local_map_ptr;
  1202. struct fusion_context *fusion = instance->ctrl_context;
  1203. io_request = cmd->io_request;
  1204. device_id = MEGASAS_DEV_INDEX(instance, scmd);
  1205. pd_index = (scmd->device->channel * MEGASAS_MAX_DEV_PER_CHANNEL)
  1206. +scmd->device->id;
  1207. local_map_ptr = fusion->ld_map[(instance->map_id & 1)];
  1208. /* Check if this is a system PD I/O */
  1209. if (instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) {
  1210. io_request->Function = 0;
  1211. io_request->DevHandle =
  1212. local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
  1213. io_request->RaidContext.timeoutValue =
  1214. local_map_ptr->raidMap.fpPdIoTimeoutSec;
  1215. io_request->RaidContext.regLockFlags = 0;
  1216. io_request->RaidContext.regLockRowLBA = 0;
  1217. io_request->RaidContext.regLockLength = 0;
  1218. io_request->RaidContext.RAIDFlags =
  1219. MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD <<
  1220. MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
  1221. cmd->request_desc->SCSIIO.RequestFlags =
  1222. (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
  1223. MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1224. } else {
  1225. io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
  1226. io_request->DevHandle = device_id;
  1227. cmd->request_desc->SCSIIO.RequestFlags =
  1228. (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
  1229. MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1230. }
  1231. io_request->RaidContext.VirtualDiskTgtId = device_id;
  1232. io_request->LUN[1] = scmd->device->lun;
  1233. io_request->DataLength = scsi_bufflen(scmd);
  1234. }
  1235. /**
  1236. * megasas_build_io_fusion - Prepares IOs to devices
  1237. * @instance: Adapter soft state
  1238. * @scp: SCSI command
  1239. * @cmd: Command to be prepared
  1240. *
  1241. * Invokes helper functions to prepare request frames
  1242. * and sets flags appropriate for IO/Non-IO cmd
  1243. */
  1244. int
  1245. megasas_build_io_fusion(struct megasas_instance *instance,
  1246. struct scsi_cmnd *scp,
  1247. struct megasas_cmd_fusion *cmd)
  1248. {
  1249. u32 device_id, sge_count;
  1250. struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
  1251. device_id = MEGASAS_DEV_INDEX(instance, scp);
  1252. /* Zero out some fields so they don't get reused */
  1253. io_request->LUN[1] = 0;
  1254. io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
  1255. io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
  1256. io_request->EEDPFlags = 0;
  1257. io_request->Control = 0;
  1258. io_request->EEDPBlockSize = 0;
  1259. io_request->IoFlags = 0;
  1260. io_request->RaidContext.RAIDFlags = 0;
  1261. memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
  1262. /*
  1263. * Just the CDB length,rest of the Flags are zero
  1264. * This will be modified for FP in build_ldio_fusion
  1265. */
  1266. io_request->IoFlags = scp->cmd_len;
  1267. if (megasas_is_ldio(scp))
  1268. megasas_build_ldio_fusion(instance, scp, cmd);
  1269. else
  1270. megasas_build_dcdb_fusion(instance, scp, cmd);
  1271. /*
  1272. * Construct SGL
  1273. */
  1274. sge_count =
  1275. megasas_make_sgl_fusion(instance, scp,
  1276. (struct MPI25_IEEE_SGE_CHAIN64 *)
  1277. &io_request->SGL, cmd);
  1278. if (sge_count > instance->max_num_sge) {
  1279. printk(KERN_ERR "megasas: Error. sge_count (0x%x) exceeds "
  1280. "max (0x%x) allowed\n", sge_count,
  1281. instance->max_num_sge);
  1282. return 1;
  1283. }
  1284. io_request->RaidContext.numSGE = sge_count;
  1285. io_request->SGLFlags = MPI2_SGE_FLAGS_64_BIT_ADDRESSING;
  1286. if (scp->sc_data_direction == PCI_DMA_TODEVICE)
  1287. io_request->Control |= MPI2_SCSIIO_CONTROL_WRITE;
  1288. else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
  1289. io_request->Control |= MPI2_SCSIIO_CONTROL_READ;
  1290. io_request->SGLOffset0 =
  1291. offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4;
  1292. io_request->SenseBufferLowAddress = cmd->sense_phys_addr;
  1293. io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
  1294. cmd->scmd = scp;
  1295. scp->SCp.ptr = (char *)cmd;
  1296. return 0;
  1297. }
  1298. union MEGASAS_REQUEST_DESCRIPTOR_UNION *
  1299. megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
  1300. {
  1301. u8 *p;
  1302. struct fusion_context *fusion;
  1303. if (index >= instance->max_fw_cmds) {
  1304. printk(KERN_ERR "megasas: Invalid SMID (0x%x)request for "
  1305. "descriptor\n", index);
  1306. return NULL;
  1307. }
  1308. fusion = instance->ctrl_context;
  1309. p = fusion->req_frames_desc
  1310. +sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *index;
  1311. return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
  1312. }
  1313. /**
  1314. * megasas_build_and_issue_cmd_fusion -Main routine for building and
  1315. * issuing non IOCTL cmd
  1316. * @instance: Adapter soft state
  1317. * @scmd: pointer to scsi cmd from OS
  1318. */
  1319. static u32
  1320. megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
  1321. struct scsi_cmnd *scmd)
  1322. {
  1323. struct megasas_cmd_fusion *cmd;
  1324. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1325. u32 index;
  1326. struct fusion_context *fusion;
  1327. fusion = instance->ctrl_context;
  1328. cmd = megasas_get_cmd_fusion(instance);
  1329. if (!cmd)
  1330. return SCSI_MLQUEUE_HOST_BUSY;
  1331. index = cmd->index;
  1332. req_desc = megasas_get_request_descriptor(instance, index-1);
  1333. if (!req_desc)
  1334. return 1;
  1335. req_desc->Words = 0;
  1336. cmd->request_desc = req_desc;
  1337. cmd->request_desc->Words = 0;
  1338. if (megasas_build_io_fusion(instance, scmd, cmd)) {
  1339. megasas_return_cmd_fusion(instance, cmd);
  1340. printk(KERN_ERR "megasas: Error building command.\n");
  1341. cmd->request_desc = NULL;
  1342. return 1;
  1343. }
  1344. req_desc = cmd->request_desc;
  1345. req_desc->SCSIIO.SMID = index;
  1346. if (cmd->io_request->ChainOffset != 0 &&
  1347. cmd->io_request->ChainOffset != 0xF)
  1348. printk(KERN_ERR "megasas: The chain offset value is not "
  1349. "correct : %x\n", cmd->io_request->ChainOffset);
  1350. /*
  1351. * Issue the command to the FW
  1352. */
  1353. atomic_inc(&instance->fw_outstanding);
  1354. instance->instancet->fire_cmd(instance,
  1355. req_desc->u.low, req_desc->u.high,
  1356. instance->reg_set);
  1357. return 0;
  1358. }
  1359. /**
  1360. * complete_cmd_fusion - Completes command
  1361. * @instance: Adapter soft state
  1362. * Completes all commands that is in reply descriptor queue
  1363. */
  1364. int
  1365. complete_cmd_fusion(struct megasas_instance *instance)
  1366. {
  1367. union MPI2_REPLY_DESCRIPTORS_UNION *desc;
  1368. struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc;
  1369. struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
  1370. struct fusion_context *fusion;
  1371. struct megasas_cmd *cmd_mfi;
  1372. struct megasas_cmd_fusion *cmd_fusion;
  1373. u16 smid, num_completed;
  1374. u8 reply_descript_type, arm;
  1375. u32 status, extStatus, device_id;
  1376. union desc_value d_val;
  1377. struct LD_LOAD_BALANCE_INFO *lbinfo;
  1378. fusion = instance->ctrl_context;
  1379. if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR)
  1380. return IRQ_HANDLED;
  1381. desc = fusion->reply_frames_desc;
  1382. desc += fusion->last_reply_idx;
  1383. reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
  1384. d_val.word = desc->Words;
  1385. reply_descript_type = reply_desc->ReplyFlags &
  1386. MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
  1387. if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
  1388. return IRQ_NONE;
  1389. d_val.word = desc->Words;
  1390. num_completed = 0;
  1391. while ((d_val.u.low != UINT_MAX) && (d_val.u.high != UINT_MAX)) {
  1392. smid = reply_desc->SMID;
  1393. cmd_fusion = fusion->cmd_list[smid - 1];
  1394. scsi_io_req =
  1395. (struct MPI2_RAID_SCSI_IO_REQUEST *)
  1396. cmd_fusion->io_request;
  1397. if (cmd_fusion->scmd)
  1398. cmd_fusion->scmd->SCp.ptr = NULL;
  1399. status = scsi_io_req->RaidContext.status;
  1400. extStatus = scsi_io_req->RaidContext.exStatus;
  1401. switch (scsi_io_req->Function) {
  1402. case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/
  1403. /* Update load balancing info */
  1404. device_id = MEGASAS_DEV_INDEX(instance,
  1405. cmd_fusion->scmd);
  1406. lbinfo = &fusion->load_balance_info[device_id];
  1407. if (cmd_fusion->scmd->SCp.Status &
  1408. MEGASAS_LOAD_BALANCE_FLAG) {
  1409. arm = lbinfo->raid1DevHandle[0] ==
  1410. cmd_fusion->io_request->DevHandle ? 0 :
  1411. 1;
  1412. atomic_dec(&lbinfo->scsi_pending_cmds[arm]);
  1413. cmd_fusion->scmd->SCp.Status &=
  1414. ~MEGASAS_LOAD_BALANCE_FLAG;
  1415. }
  1416. if (reply_descript_type ==
  1417. MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) {
  1418. if (megasas_dbg_lvl == 5)
  1419. printk(KERN_ERR "\nmegasas: FAST Path "
  1420. "IO Success\n");
  1421. }
  1422. /* Fall thru and complete IO */
  1423. case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
  1424. /* Map the FW Cmd Status */
  1425. map_cmd_status(cmd_fusion, status, extStatus);
  1426. scsi_dma_unmap(cmd_fusion->scmd);
  1427. cmd_fusion->scmd->scsi_done(cmd_fusion->scmd);
  1428. scsi_io_req->RaidContext.status = 0;
  1429. scsi_io_req->RaidContext.exStatus = 0;
  1430. megasas_return_cmd_fusion(instance, cmd_fusion);
  1431. atomic_dec(&instance->fw_outstanding);
  1432. break;
  1433. case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
  1434. cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
  1435. megasas_complete_cmd(instance, cmd_mfi, DID_OK);
  1436. cmd_fusion->flags = 0;
  1437. megasas_return_cmd_fusion(instance, cmd_fusion);
  1438. break;
  1439. }
  1440. fusion->last_reply_idx++;
  1441. if (fusion->last_reply_idx >= fusion->reply_q_depth)
  1442. fusion->last_reply_idx = 0;
  1443. desc->Words = ULLONG_MAX;
  1444. num_completed++;
  1445. /* Get the next reply descriptor */
  1446. if (!fusion->last_reply_idx)
  1447. desc = fusion->reply_frames_desc;
  1448. else
  1449. desc++;
  1450. reply_desc =
  1451. (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
  1452. d_val.word = desc->Words;
  1453. reply_descript_type = reply_desc->ReplyFlags &
  1454. MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
  1455. if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
  1456. break;
  1457. }
  1458. if (!num_completed)
  1459. return IRQ_NONE;
  1460. wmb();
  1461. writel(fusion->last_reply_idx,
  1462. &instance->reg_set->reply_post_host_index);
  1463. megasas_check_and_restore_queue_depth(instance);
  1464. return IRQ_HANDLED;
  1465. }
  1466. /**
  1467. * megasas_complete_cmd_dpc_fusion - Completes command
  1468. * @instance: Adapter soft state
  1469. *
  1470. * Tasklet to complete cmds
  1471. */
  1472. void
  1473. megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
  1474. {
  1475. struct megasas_instance *instance =
  1476. (struct megasas_instance *)instance_addr;
  1477. unsigned long flags;
  1478. /* If we have already declared adapter dead, donot complete cmds */
  1479. spin_lock_irqsave(&instance->hba_lock, flags);
  1480. if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
  1481. spin_unlock_irqrestore(&instance->hba_lock, flags);
  1482. return;
  1483. }
  1484. spin_unlock_irqrestore(&instance->hba_lock, flags);
  1485. spin_lock_irqsave(&instance->completion_lock, flags);
  1486. complete_cmd_fusion(instance);
  1487. spin_unlock_irqrestore(&instance->completion_lock, flags);
  1488. }
  1489. /**
  1490. * megasas_isr_fusion - isr entry point
  1491. */
  1492. irqreturn_t megasas_isr_fusion(int irq, void *devp)
  1493. {
  1494. struct megasas_instance *instance = (struct megasas_instance *)devp;
  1495. u32 mfiStatus, fw_state;
  1496. if (!instance->msi_flag) {
  1497. mfiStatus = instance->instancet->clear_intr(instance->reg_set);
  1498. if (!mfiStatus)
  1499. return IRQ_NONE;
  1500. }
  1501. /* If we are resetting, bail */
  1502. if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags))
  1503. return IRQ_HANDLED;
  1504. if (!complete_cmd_fusion(instance)) {
  1505. /* If we didn't complete any commands, check for FW fault */
  1506. fw_state = instance->instancet->read_fw_status_reg(
  1507. instance->reg_set) & MFI_STATE_MASK;
  1508. if (fw_state == MFI_STATE_FAULT)
  1509. schedule_work(&instance->work_init);
  1510. }
  1511. return IRQ_HANDLED;
  1512. }
  1513. /**
  1514. * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
  1515. * @instance: Adapter soft state
  1516. * mfi_cmd: megasas_cmd pointer
  1517. *
  1518. */
  1519. u8
  1520. build_mpt_mfi_pass_thru(struct megasas_instance *instance,
  1521. struct megasas_cmd *mfi_cmd)
  1522. {
  1523. struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain;
  1524. struct MPI2_RAID_SCSI_IO_REQUEST *io_req;
  1525. struct megasas_cmd_fusion *cmd;
  1526. struct fusion_context *fusion;
  1527. struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr;
  1528. cmd = megasas_get_cmd_fusion(instance);
  1529. if (!cmd)
  1530. return 1;
  1531. /* Save the smid. To be used for returning the cmd */
  1532. mfi_cmd->context.smid = cmd->index;
  1533. cmd->sync_cmd_idx = mfi_cmd->index;
  1534. /*
  1535. * For cmds where the flag is set, store the flag and check
  1536. * on completion. For cmds with this flag, don't call
  1537. * megasas_complete_cmd
  1538. */
  1539. if (frame_hdr->flags & MFI_FRAME_DONT_POST_IN_REPLY_QUEUE)
  1540. cmd->flags = MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
  1541. fusion = instance->ctrl_context;
  1542. io_req = cmd->io_request;
  1543. mpi25_ieee_chain =
  1544. (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
  1545. io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST;
  1546. io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST,
  1547. SGL) / 4;
  1548. io_req->ChainOffset = fusion->chain_offset_mfi_pthru;
  1549. mpi25_ieee_chain->Address = mfi_cmd->frame_phys_addr;
  1550. mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
  1551. MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
  1552. mpi25_ieee_chain->Length = MEGASAS_MAX_SZ_CHAIN_FRAME;
  1553. return 0;
  1554. }
  1555. /**
  1556. * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
  1557. * @instance: Adapter soft state
  1558. * @cmd: mfi cmd to build
  1559. *
  1560. */
  1561. union MEGASAS_REQUEST_DESCRIPTOR_UNION *
  1562. build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
  1563. {
  1564. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1565. u16 index;
  1566. if (build_mpt_mfi_pass_thru(instance, cmd)) {
  1567. printk(KERN_ERR "Couldn't build MFI pass thru cmd\n");
  1568. return NULL;
  1569. }
  1570. index = cmd->context.smid;
  1571. req_desc = megasas_get_request_descriptor(instance, index - 1);
  1572. if (!req_desc)
  1573. return NULL;
  1574. req_desc->Words = 0;
  1575. req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
  1576. MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1577. req_desc->SCSIIO.SMID = index;
  1578. return req_desc;
  1579. }
  1580. /**
  1581. * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
  1582. * @instance: Adapter soft state
  1583. * @cmd: mfi cmd pointer
  1584. *
  1585. */
  1586. void
  1587. megasas_issue_dcmd_fusion(struct megasas_instance *instance,
  1588. struct megasas_cmd *cmd)
  1589. {
  1590. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1591. union desc_value d_val;
  1592. req_desc = build_mpt_cmd(instance, cmd);
  1593. if (!req_desc) {
  1594. printk(KERN_ERR "Couldn't issue MFI pass thru cmd\n");
  1595. return;
  1596. }
  1597. d_val.word = req_desc->Words;
  1598. instance->instancet->fire_cmd(instance, req_desc->u.low,
  1599. req_desc->u.high, instance->reg_set);
  1600. }
  1601. /**
  1602. * megasas_release_fusion - Reverses the FW initialization
  1603. * @intance: Adapter soft state
  1604. */
  1605. void
  1606. megasas_release_fusion(struct megasas_instance *instance)
  1607. {
  1608. megasas_free_cmds(instance);
  1609. megasas_free_cmds_fusion(instance);
  1610. iounmap(instance->reg_set);
  1611. pci_release_selected_regions(instance->pdev, instance->bar);
  1612. }
  1613. /**
  1614. * megasas_read_fw_status_reg_fusion - returns the current FW status value
  1615. * @regs: MFI register set
  1616. */
  1617. static u32
  1618. megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem *regs)
  1619. {
  1620. return readl(&(regs)->outbound_scratch_pad);
  1621. }
  1622. /**
  1623. * megasas_adp_reset_fusion - For controller reset
  1624. * @regs: MFI register set
  1625. */
  1626. static int
  1627. megasas_adp_reset_fusion(struct megasas_instance *instance,
  1628. struct megasas_register_set __iomem *regs)
  1629. {
  1630. return 0;
  1631. }
  1632. /**
  1633. * megasas_check_reset_fusion - For controller reset check
  1634. * @regs: MFI register set
  1635. */
  1636. static int
  1637. megasas_check_reset_fusion(struct megasas_instance *instance,
  1638. struct megasas_register_set __iomem *regs)
  1639. {
  1640. return 0;
  1641. }
  1642. /* This function waits for outstanding commands on fusion to complete */
  1643. int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance)
  1644. {
  1645. int i, outstanding, retval = 0;
  1646. u32 fw_state, wait_time = MEGASAS_RESET_WAIT_TIME;
  1647. for (i = 0; i < wait_time; i++) {
  1648. /* Check if firmware is in fault state */
  1649. fw_state = instance->instancet->read_fw_status_reg(
  1650. instance->reg_set) & MFI_STATE_MASK;
  1651. if (fw_state == MFI_STATE_FAULT) {
  1652. printk(KERN_WARNING "megasas: Found FW in FAULT state,"
  1653. " will reset adapter.\n");
  1654. retval = 1;
  1655. goto out;
  1656. }
  1657. outstanding = atomic_read(&instance->fw_outstanding);
  1658. if (!outstanding)
  1659. goto out;
  1660. if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
  1661. printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
  1662. "commands to complete\n", i, outstanding);
  1663. megasas_complete_cmd_dpc_fusion(
  1664. (unsigned long)instance);
  1665. }
  1666. msleep(1000);
  1667. }
  1668. if (atomic_read(&instance->fw_outstanding)) {
  1669. printk("megaraid_sas: pending commands remain after waiting, "
  1670. "will reset adapter.\n");
  1671. retval = 1;
  1672. }
  1673. out:
  1674. return retval;
  1675. }
  1676. void megasas_reset_reply_desc(struct megasas_instance *instance)
  1677. {
  1678. int i;
  1679. struct fusion_context *fusion;
  1680. union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
  1681. fusion = instance->ctrl_context;
  1682. fusion->last_reply_idx = 0;
  1683. reply_desc = fusion->reply_frames_desc;
  1684. for (i = 0 ; i < fusion->reply_q_depth; i++, reply_desc++)
  1685. reply_desc->Words = ULLONG_MAX;
  1686. }
  1687. /* Core fusion reset function */
  1688. int megasas_reset_fusion(struct Scsi_Host *shost)
  1689. {
  1690. int retval = SUCCESS, i, j, retry = 0;
  1691. struct megasas_instance *instance;
  1692. struct megasas_cmd_fusion *cmd_fusion;
  1693. struct fusion_context *fusion;
  1694. struct megasas_cmd *cmd_mfi;
  1695. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1696. u32 host_diag, abs_state;
  1697. instance = (struct megasas_instance *)shost->hostdata;
  1698. fusion = instance->ctrl_context;
  1699. mutex_lock(&instance->reset_mutex);
  1700. set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
  1701. instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT;
  1702. instance->instancet->disable_intr(instance->reg_set);
  1703. msleep(1000);
  1704. if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
  1705. printk(KERN_WARNING "megaraid_sas: Hardware critical error, "
  1706. "returning FAILED.\n");
  1707. retval = FAILED;
  1708. goto out;
  1709. }
  1710. /* First try waiting for commands to complete */
  1711. if (megasas_wait_for_outstanding_fusion(instance)) {
  1712. printk(KERN_WARNING "megaraid_sas: resetting fusion "
  1713. "adapter.\n");
  1714. /* Now return commands back to the OS */
  1715. for (i = 0 ; i < instance->max_fw_cmds; i++) {
  1716. cmd_fusion = fusion->cmd_list[i];
  1717. if (cmd_fusion->scmd) {
  1718. scsi_dma_unmap(cmd_fusion->scmd);
  1719. cmd_fusion->scmd->result = (DID_RESET << 16);
  1720. cmd_fusion->scmd->scsi_done(cmd_fusion->scmd);
  1721. megasas_return_cmd_fusion(instance, cmd_fusion);
  1722. atomic_dec(&instance->fw_outstanding);
  1723. }
  1724. }
  1725. if (instance->disableOnlineCtrlReset == 1) {
  1726. /* Reset not supported, kill adapter */
  1727. printk(KERN_WARNING "megaraid_sas: Reset not supported"
  1728. ", killing adapter.\n");
  1729. megaraid_sas_kill_hba(instance);
  1730. instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
  1731. retval = FAILED;
  1732. goto out;
  1733. }
  1734. /* Now try to reset the chip */
  1735. for (i = 0; i < MEGASAS_FUSION_MAX_RESET_TRIES; i++) {
  1736. writel(MPI2_WRSEQ_FLUSH_KEY_VALUE,
  1737. &instance->reg_set->fusion_seq_offset);
  1738. writel(MPI2_WRSEQ_1ST_KEY_VALUE,
  1739. &instance->reg_set->fusion_seq_offset);
  1740. writel(MPI2_WRSEQ_2ND_KEY_VALUE,
  1741. &instance->reg_set->fusion_seq_offset);
  1742. writel(MPI2_WRSEQ_3RD_KEY_VALUE,
  1743. &instance->reg_set->fusion_seq_offset);
  1744. writel(MPI2_WRSEQ_4TH_KEY_VALUE,
  1745. &instance->reg_set->fusion_seq_offset);
  1746. writel(MPI2_WRSEQ_5TH_KEY_VALUE,
  1747. &instance->reg_set->fusion_seq_offset);
  1748. writel(MPI2_WRSEQ_6TH_KEY_VALUE,
  1749. &instance->reg_set->fusion_seq_offset);
  1750. /* Check that the diag write enable (DRWE) bit is on */
  1751. host_diag = readl(&instance->reg_set->fusion_host_diag);
  1752. while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) {
  1753. msleep(100);
  1754. host_diag =
  1755. readl(&instance->reg_set->fusion_host_diag);
  1756. if (retry++ == 100) {
  1757. printk(KERN_WARNING "megaraid_sas: "
  1758. "Host diag unlock failed!\n");
  1759. break;
  1760. }
  1761. }
  1762. if (!(host_diag & HOST_DIAG_WRITE_ENABLE))
  1763. continue;
  1764. /* Send chip reset command */
  1765. writel(host_diag | HOST_DIAG_RESET_ADAPTER,
  1766. &instance->reg_set->fusion_host_diag);
  1767. msleep(3000);
  1768. /* Make sure reset adapter bit is cleared */
  1769. host_diag = readl(&instance->reg_set->fusion_host_diag);
  1770. retry = 0;
  1771. while (host_diag & HOST_DIAG_RESET_ADAPTER) {
  1772. msleep(100);
  1773. host_diag =
  1774. readl(&instance->reg_set->fusion_host_diag);
  1775. if (retry++ == 1000) {
  1776. printk(KERN_WARNING "megaraid_sas: "
  1777. "Diag reset adapter never "
  1778. "cleared!\n");
  1779. break;
  1780. }
  1781. }
  1782. if (host_diag & HOST_DIAG_RESET_ADAPTER)
  1783. continue;
  1784. abs_state =
  1785. instance->instancet->read_fw_status_reg(
  1786. instance->reg_set);
  1787. retry = 0;
  1788. while ((abs_state <= MFI_STATE_FW_INIT) &&
  1789. (retry++ < 1000)) {
  1790. msleep(100);
  1791. abs_state =
  1792. instance->instancet->read_fw_status_reg(
  1793. instance->reg_set);
  1794. }
  1795. if (abs_state <= MFI_STATE_FW_INIT) {
  1796. printk(KERN_WARNING "megaraid_sas: firmware "
  1797. "state < MFI_STATE_FW_INIT, state = "
  1798. "0x%x\n", abs_state);
  1799. continue;
  1800. }
  1801. /* Wait for FW to become ready */
  1802. if (megasas_transition_to_ready(instance)) {
  1803. printk(KERN_WARNING "megaraid_sas: Failed to "
  1804. "transition controller to ready.\n");
  1805. continue;
  1806. }
  1807. megasas_reset_reply_desc(instance);
  1808. if (megasas_ioc_init_fusion(instance)) {
  1809. printk(KERN_WARNING "megaraid_sas: "
  1810. "megasas_ioc_init_fusion() failed!\n");
  1811. continue;
  1812. }
  1813. instance->instancet->enable_intr(instance->reg_set);
  1814. instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
  1815. /* Re-fire management commands */
  1816. for (j = 0 ; j < instance->max_fw_cmds; j++) {
  1817. cmd_fusion = fusion->cmd_list[j];
  1818. if (cmd_fusion->sync_cmd_idx !=
  1819. (u32)ULONG_MAX) {
  1820. cmd_mfi =
  1821. instance->
  1822. cmd_list[cmd_fusion->sync_cmd_idx];
  1823. if (cmd_mfi->frame->dcmd.opcode ==
  1824. MR_DCMD_LD_MAP_GET_INFO) {
  1825. megasas_return_cmd(instance,
  1826. cmd_mfi);
  1827. megasas_return_cmd_fusion(
  1828. instance, cmd_fusion);
  1829. } else {
  1830. req_desc =
  1831. megasas_get_request_descriptor(
  1832. instance,
  1833. cmd_mfi->context.smid
  1834. -1);
  1835. if (!req_desc)
  1836. printk(KERN_WARNING
  1837. "req_desc NULL"
  1838. "\n");
  1839. else {
  1840. instance->instancet->
  1841. fire_cmd(instance,
  1842. req_desc->
  1843. u.low,
  1844. req_desc->
  1845. u.high,
  1846. instance->
  1847. reg_set);
  1848. }
  1849. }
  1850. }
  1851. }
  1852. /* Reset load balance info */
  1853. memset(fusion->load_balance_info, 0,
  1854. sizeof(struct LD_LOAD_BALANCE_INFO)
  1855. *MAX_LOGICAL_DRIVES);
  1856. if (!megasas_get_map_info(instance))
  1857. megasas_sync_map_info(instance);
  1858. /* Adapter reset completed successfully */
  1859. printk(KERN_WARNING "megaraid_sas: Reset "
  1860. "successful.\n");
  1861. retval = SUCCESS;
  1862. goto out;
  1863. }
  1864. /* Reset failed, kill the adapter */
  1865. printk(KERN_WARNING "megaraid_sas: Reset failed, killing "
  1866. "adapter.\n");
  1867. megaraid_sas_kill_hba(instance);
  1868. retval = FAILED;
  1869. } else {
  1870. instance->instancet->enable_intr(instance->reg_set);
  1871. instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
  1872. }
  1873. out:
  1874. clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
  1875. mutex_unlock(&instance->reset_mutex);
  1876. return retval;
  1877. }
  1878. /* Fusion OCR work queue */
  1879. void megasas_fusion_ocr_wq(struct work_struct *work)
  1880. {
  1881. struct megasas_instance *instance =
  1882. container_of(work, struct megasas_instance, work_init);
  1883. megasas_reset_fusion(instance->host);
  1884. }
  1885. struct megasas_instance_template megasas_instance_template_fusion = {
  1886. .fire_cmd = megasas_fire_cmd_fusion,
  1887. .enable_intr = megasas_enable_intr_fusion,
  1888. .disable_intr = megasas_disable_intr_fusion,
  1889. .clear_intr = megasas_clear_intr_fusion,
  1890. .read_fw_status_reg = megasas_read_fw_status_reg_fusion,
  1891. .adp_reset = megasas_adp_reset_fusion,
  1892. .check_reset = megasas_check_reset_fusion,
  1893. .service_isr = megasas_isr_fusion,
  1894. .tasklet = megasas_complete_cmd_dpc_fusion,
  1895. .init_adapter = megasas_init_adapter_fusion,
  1896. .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion,
  1897. .issue_dcmd = megasas_issue_dcmd_fusion,
  1898. };