megaraid_sas_fusion.c 61 KB

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