megaraid_sas_fusion.c 61 KB

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