megaraid_sas_fusion.c 60 KB

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