megaraid_sas_fusion.c 61 KB

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