megaraid_sas_fusion.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  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_alloc_cmds:
  817. fail_alloc_mfi_cmds:
  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. return 1;
  824. }
  825. /**
  826. * megasas_fire_cmd_fusion - Sends command to the FW
  827. * @frame_phys_addr : Physical address of cmd
  828. * @frame_count : Number of frames for the command
  829. * @regs : MFI register set
  830. */
  831. void
  832. megasas_fire_cmd_fusion(struct megasas_instance *instance,
  833. dma_addr_t req_desc_lo,
  834. u32 req_desc_hi,
  835. struct megasas_register_set __iomem *regs)
  836. {
  837. unsigned long flags;
  838. spin_lock_irqsave(&instance->hba_lock, flags);
  839. writel(req_desc_lo,
  840. &(regs)->inbound_low_queue_port);
  841. writel(req_desc_hi, &(regs)->inbound_high_queue_port);
  842. spin_unlock_irqrestore(&instance->hba_lock, flags);
  843. }
  844. /**
  845. * map_cmd_status - Maps FW cmd status to OS cmd status
  846. * @cmd : Pointer to cmd
  847. * @status : status of cmd returned by FW
  848. * @ext_status : ext status of cmd returned by FW
  849. */
  850. void
  851. map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status)
  852. {
  853. switch (status) {
  854. case MFI_STAT_OK:
  855. cmd->scmd->result = DID_OK << 16;
  856. break;
  857. case MFI_STAT_SCSI_IO_FAILED:
  858. case MFI_STAT_LD_INIT_IN_PROGRESS:
  859. cmd->scmd->result = (DID_ERROR << 16) | ext_status;
  860. break;
  861. case MFI_STAT_SCSI_DONE_WITH_ERROR:
  862. cmd->scmd->result = (DID_OK << 16) | ext_status;
  863. if (ext_status == SAM_STAT_CHECK_CONDITION) {
  864. memset(cmd->scmd->sense_buffer, 0,
  865. SCSI_SENSE_BUFFERSIZE);
  866. memcpy(cmd->scmd->sense_buffer, cmd->sense,
  867. SCSI_SENSE_BUFFERSIZE);
  868. cmd->scmd->result |= DRIVER_SENSE << 24;
  869. }
  870. break;
  871. case MFI_STAT_LD_OFFLINE:
  872. case MFI_STAT_DEVICE_NOT_FOUND:
  873. cmd->scmd->result = DID_BAD_TARGET << 16;
  874. break;
  875. default:
  876. printk(KERN_DEBUG "megasas: FW status %#x\n", status);
  877. cmd->scmd->result = DID_ERROR << 16;
  878. break;
  879. }
  880. }
  881. /**
  882. * megasas_make_sgl_fusion - Prepares 32-bit SGL
  883. * @instance: Adapter soft state
  884. * @scp: SCSI command from the mid-layer
  885. * @sgl_ptr: SGL to be filled in
  886. * @cmd: cmd we are working on
  887. *
  888. * If successful, this function returns the number of SG elements.
  889. */
  890. static int
  891. megasas_make_sgl_fusion(struct megasas_instance *instance,
  892. struct scsi_cmnd *scp,
  893. struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
  894. struct megasas_cmd_fusion *cmd)
  895. {
  896. int i, sg_processed;
  897. int sge_count, sge_idx;
  898. struct scatterlist *os_sgl;
  899. struct fusion_context *fusion;
  900. fusion = instance->ctrl_context;
  901. cmd->io_request->ChainOffset = 0;
  902. sge_count = scsi_dma_map(scp);
  903. BUG_ON(sge_count < 0);
  904. if (sge_count > instance->max_num_sge || !sge_count)
  905. return sge_count;
  906. if (sge_count > fusion->max_sge_in_main_msg) {
  907. /* One element to store the chain info */
  908. sge_idx = fusion->max_sge_in_main_msg - 1;
  909. } else
  910. sge_idx = sge_count;
  911. scsi_for_each_sg(scp, os_sgl, sge_count, i) {
  912. sgl_ptr->Length = sg_dma_len(os_sgl);
  913. sgl_ptr->Address = sg_dma_address(os_sgl);
  914. sgl_ptr->Flags = 0;
  915. sgl_ptr++;
  916. sg_processed = i + 1;
  917. if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) &&
  918. (sge_count > fusion->max_sge_in_main_msg)) {
  919. struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
  920. cmd->io_request->ChainOffset =
  921. fusion->chain_offset_io_request;
  922. sg_chain = sgl_ptr;
  923. /* Prepare chain element */
  924. sg_chain->NextChainOffset = 0;
  925. sg_chain->Flags = (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
  926. MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
  927. sg_chain->Length = (sizeof(union MPI2_SGE_IO_UNION)
  928. *(sge_count - sg_processed));
  929. sg_chain->Address = cmd->sg_frame_phys_addr;
  930. sgl_ptr =
  931. (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame;
  932. }
  933. }
  934. return sge_count;
  935. }
  936. /**
  937. * megasas_set_pd_lba - Sets PD LBA
  938. * @cdb: CDB
  939. * @cdb_len: cdb length
  940. * @start_blk: Start block of IO
  941. *
  942. * Used to set the PD LBA in CDB for FP IOs
  943. */
  944. void
  945. megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
  946. struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp,
  947. struct MR_FW_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
  948. {
  949. struct MR_LD_RAID *raid;
  950. u32 ld;
  951. u64 start_blk = io_info->pdBlock;
  952. u8 *cdb = io_request->CDB.CDB32;
  953. u32 num_blocks = io_info->numBlocks;
  954. u8 opcode, flagvals, groupnum, control;
  955. /* Check if T10 PI (DIF) is enabled for this LD */
  956. ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr);
  957. raid = MR_LdRaidGet(ld, local_map_ptr);
  958. if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) {
  959. memset(cdb, 0, sizeof(io_request->CDB.CDB32));
  960. cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD;
  961. cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN;
  962. if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
  963. cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32;
  964. else
  965. cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32;
  966. cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL;
  967. /* LBA */
  968. cdb[12] = (u8)((start_blk >> 56) & 0xff);
  969. cdb[13] = (u8)((start_blk >> 48) & 0xff);
  970. cdb[14] = (u8)((start_blk >> 40) & 0xff);
  971. cdb[15] = (u8)((start_blk >> 32) & 0xff);
  972. cdb[16] = (u8)((start_blk >> 24) & 0xff);
  973. cdb[17] = (u8)((start_blk >> 16) & 0xff);
  974. cdb[18] = (u8)((start_blk >> 8) & 0xff);
  975. cdb[19] = (u8)(start_blk & 0xff);
  976. /* Logical block reference tag */
  977. io_request->CDB.EEDP32.PrimaryReferenceTag =
  978. cpu_to_be32(ref_tag);
  979. io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0xffff;
  980. io_request->DataLength = num_blocks * 512;
  981. io_request->IoFlags = 32; /* Specify 32-byte cdb */
  982. /* Transfer length */
  983. cdb[28] = (u8)((num_blocks >> 24) & 0xff);
  984. cdb[29] = (u8)((num_blocks >> 16) & 0xff);
  985. cdb[30] = (u8)((num_blocks >> 8) & 0xff);
  986. cdb[31] = (u8)(num_blocks & 0xff);
  987. /* set SCSI IO EEDPFlags */
  988. if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) {
  989. io_request->EEDPFlags =
  990. MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  991. MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
  992. MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP |
  993. MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG |
  994. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  995. } else {
  996. io_request->EEDPFlags =
  997. MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  998. MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
  999. }
  1000. io_request->Control |= (0x4 << 26);
  1001. io_request->EEDPBlockSize = MEGASAS_EEDPBLOCKSIZE;
  1002. } else {
  1003. /* Some drives don't support 16/12 byte CDB's, convert to 10 */
  1004. if (((cdb_len == 12) || (cdb_len == 16)) &&
  1005. (start_blk <= 0xffffffff)) {
  1006. if (cdb_len == 16) {
  1007. opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10;
  1008. flagvals = cdb[1];
  1009. groupnum = cdb[14];
  1010. control = cdb[15];
  1011. } else {
  1012. opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10;
  1013. flagvals = cdb[1];
  1014. groupnum = cdb[10];
  1015. control = cdb[11];
  1016. }
  1017. memset(cdb, 0, sizeof(io_request->CDB.CDB32));
  1018. cdb[0] = opcode;
  1019. cdb[1] = flagvals;
  1020. cdb[6] = groupnum;
  1021. cdb[9] = control;
  1022. /* Transfer length */
  1023. cdb[8] = (u8)(num_blocks & 0xff);
  1024. cdb[7] = (u8)((num_blocks >> 8) & 0xff);
  1025. cdb_len = 10;
  1026. }
  1027. /* Normal case, just load LBA here */
  1028. switch (cdb_len) {
  1029. case 6:
  1030. {
  1031. u8 val = cdb[1] & 0xE0;
  1032. cdb[3] = (u8)(start_blk & 0xff);
  1033. cdb[2] = (u8)((start_blk >> 8) & 0xff);
  1034. cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f);
  1035. break;
  1036. }
  1037. case 10:
  1038. cdb[5] = (u8)(start_blk & 0xff);
  1039. cdb[4] = (u8)((start_blk >> 8) & 0xff);
  1040. cdb[3] = (u8)((start_blk >> 16) & 0xff);
  1041. cdb[2] = (u8)((start_blk >> 24) & 0xff);
  1042. break;
  1043. case 12:
  1044. cdb[5] = (u8)(start_blk & 0xff);
  1045. cdb[4] = (u8)((start_blk >> 8) & 0xff);
  1046. cdb[3] = (u8)((start_blk >> 16) & 0xff);
  1047. cdb[2] = (u8)((start_blk >> 24) & 0xff);
  1048. break;
  1049. case 16:
  1050. cdb[9] = (u8)(start_blk & 0xff);
  1051. cdb[8] = (u8)((start_blk >> 8) & 0xff);
  1052. cdb[7] = (u8)((start_blk >> 16) & 0xff);
  1053. cdb[6] = (u8)((start_blk >> 24) & 0xff);
  1054. cdb[5] = (u8)((start_blk >> 32) & 0xff);
  1055. cdb[4] = (u8)((start_blk >> 40) & 0xff);
  1056. cdb[3] = (u8)((start_blk >> 48) & 0xff);
  1057. cdb[2] = (u8)((start_blk >> 56) & 0xff);
  1058. break;
  1059. }
  1060. }
  1061. }
  1062. /**
  1063. * megasas_build_ldio_fusion - Prepares IOs to devices
  1064. * @instance: Adapter soft state
  1065. * @scp: SCSI command
  1066. * @cmd: Command to be prepared
  1067. *
  1068. * Prepares the io_request and chain elements (sg_frame) for IO
  1069. * The IO can be for PD (Fast Path) or LD
  1070. */
  1071. void
  1072. megasas_build_ldio_fusion(struct megasas_instance *instance,
  1073. struct scsi_cmnd *scp,
  1074. struct megasas_cmd_fusion *cmd)
  1075. {
  1076. u8 fp_possible;
  1077. u32 start_lba_lo, start_lba_hi, device_id;
  1078. struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
  1079. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1080. struct IO_REQUEST_INFO io_info;
  1081. struct fusion_context *fusion;
  1082. struct MR_FW_RAID_MAP_ALL *local_map_ptr;
  1083. device_id = MEGASAS_DEV_INDEX(instance, scp);
  1084. fusion = instance->ctrl_context;
  1085. io_request = cmd->io_request;
  1086. io_request->RaidContext.VirtualDiskTgtId = device_id;
  1087. io_request->RaidContext.status = 0;
  1088. io_request->RaidContext.exStatus = 0;
  1089. req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc;
  1090. start_lba_lo = 0;
  1091. start_lba_hi = 0;
  1092. fp_possible = 0;
  1093. /*
  1094. * 6-byte READ(0x08) or WRITE(0x0A) cdb
  1095. */
  1096. if (scp->cmd_len == 6) {
  1097. io_request->DataLength = (u32) scp->cmnd[4];
  1098. start_lba_lo = ((u32) scp->cmnd[1] << 16) |
  1099. ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3];
  1100. start_lba_lo &= 0x1FFFFF;
  1101. }
  1102. /*
  1103. * 10-byte READ(0x28) or WRITE(0x2A) cdb
  1104. */
  1105. else if (scp->cmd_len == 10) {
  1106. io_request->DataLength = (u32) scp->cmnd[8] |
  1107. ((u32) scp->cmnd[7] << 8);
  1108. start_lba_lo = ((u32) scp->cmnd[2] << 24) |
  1109. ((u32) scp->cmnd[3] << 16) |
  1110. ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
  1111. }
  1112. /*
  1113. * 12-byte READ(0xA8) or WRITE(0xAA) cdb
  1114. */
  1115. else if (scp->cmd_len == 12) {
  1116. io_request->DataLength = ((u32) scp->cmnd[6] << 24) |
  1117. ((u32) scp->cmnd[7] << 16) |
  1118. ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
  1119. start_lba_lo = ((u32) scp->cmnd[2] << 24) |
  1120. ((u32) scp->cmnd[3] << 16) |
  1121. ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
  1122. }
  1123. /*
  1124. * 16-byte READ(0x88) or WRITE(0x8A) cdb
  1125. */
  1126. else if (scp->cmd_len == 16) {
  1127. io_request->DataLength = ((u32) scp->cmnd[10] << 24) |
  1128. ((u32) scp->cmnd[11] << 16) |
  1129. ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13];
  1130. start_lba_lo = ((u32) scp->cmnd[6] << 24) |
  1131. ((u32) scp->cmnd[7] << 16) |
  1132. ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
  1133. start_lba_hi = ((u32) scp->cmnd[2] << 24) |
  1134. ((u32) scp->cmnd[3] << 16) |
  1135. ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
  1136. }
  1137. memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO));
  1138. io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
  1139. io_info.numBlocks = io_request->DataLength;
  1140. io_info.ldTgtId = device_id;
  1141. if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
  1142. io_info.isRead = 1;
  1143. local_map_ptr = fusion->ld_map[(instance->map_id & 1)];
  1144. if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >=
  1145. MAX_LOGICAL_DRIVES) || (!fusion->fast_path_io)) {
  1146. io_request->RaidContext.regLockFlags = 0;
  1147. fp_possible = 0;
  1148. } else {
  1149. if (MR_BuildRaidContext(&io_info, &io_request->RaidContext,
  1150. local_map_ptr))
  1151. fp_possible = io_info.fpOkForIo;
  1152. }
  1153. if (fp_possible) {
  1154. megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
  1155. local_map_ptr, start_lba_lo);
  1156. io_request->DataLength = scsi_bufflen(scp);
  1157. io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  1158. cmd->request_desc->SCSIIO.RequestFlags =
  1159. (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
  1160. << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1161. if ((fusion->load_balance_info[device_id].loadBalanceFlag) &&
  1162. (io_info.isRead)) {
  1163. io_info.devHandle =
  1164. get_updated_dev_handle(
  1165. &fusion->load_balance_info[device_id],
  1166. &io_info);
  1167. scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
  1168. } else
  1169. scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
  1170. cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
  1171. io_request->DevHandle = io_info.devHandle;
  1172. } else {
  1173. io_request->RaidContext.timeoutValue =
  1174. local_map_ptr->raidMap.fpPdIoTimeoutSec;
  1175. io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
  1176. io_request->DevHandle = device_id;
  1177. cmd->request_desc->SCSIIO.RequestFlags =
  1178. (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
  1179. << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1180. } /* Not FP */
  1181. }
  1182. /**
  1183. * megasas_build_dcdb_fusion - Prepares IOs to devices
  1184. * @instance: Adapter soft state
  1185. * @scp: SCSI command
  1186. * @cmd: Command to be prepared
  1187. *
  1188. * Prepares the io_request frame for non-io cmds
  1189. */
  1190. static void
  1191. megasas_build_dcdb_fusion(struct megasas_instance *instance,
  1192. struct scsi_cmnd *scmd,
  1193. struct megasas_cmd_fusion *cmd)
  1194. {
  1195. u32 device_id;
  1196. struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
  1197. u16 pd_index = 0;
  1198. struct MR_FW_RAID_MAP_ALL *local_map_ptr;
  1199. struct fusion_context *fusion = instance->ctrl_context;
  1200. io_request = cmd->io_request;
  1201. device_id = MEGASAS_DEV_INDEX(instance, scmd);
  1202. pd_index = (scmd->device->channel * MEGASAS_MAX_DEV_PER_CHANNEL)
  1203. +scmd->device->id;
  1204. local_map_ptr = fusion->ld_map[(instance->map_id & 1)];
  1205. /* Check if this is a system PD I/O */
  1206. if ((instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) &&
  1207. (instance->pd_list[pd_index].driveType == TYPE_DISK)) {
  1208. io_request->Function = 0;
  1209. io_request->DevHandle =
  1210. local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
  1211. io_request->RaidContext.timeoutValue =
  1212. local_map_ptr->raidMap.fpPdIoTimeoutSec;
  1213. io_request->RaidContext.regLockFlags = 0;
  1214. io_request->RaidContext.regLockRowLBA = 0;
  1215. io_request->RaidContext.regLockLength = 0;
  1216. io_request->RaidContext.RAIDFlags =
  1217. MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD <<
  1218. MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
  1219. cmd->request_desc->SCSIIO.RequestFlags =
  1220. (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
  1221. MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1222. } else {
  1223. io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
  1224. io_request->DevHandle = device_id;
  1225. cmd->request_desc->SCSIIO.RequestFlags =
  1226. (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
  1227. MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1228. }
  1229. io_request->RaidContext.VirtualDiskTgtId = device_id;
  1230. io_request->LUN[0] = scmd->device->lun;
  1231. io_request->DataLength = scsi_bufflen(scmd);
  1232. }
  1233. /**
  1234. * megasas_build_io_fusion - Prepares IOs to devices
  1235. * @instance: Adapter soft state
  1236. * @scp: SCSI command
  1237. * @cmd: Command to be prepared
  1238. *
  1239. * Invokes helper functions to prepare request frames
  1240. * and sets flags appropriate for IO/Non-IO cmd
  1241. */
  1242. int
  1243. megasas_build_io_fusion(struct megasas_instance *instance,
  1244. struct scsi_cmnd *scp,
  1245. struct megasas_cmd_fusion *cmd)
  1246. {
  1247. u32 device_id, sge_count;
  1248. struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
  1249. device_id = MEGASAS_DEV_INDEX(instance, scp);
  1250. /* Zero out some fields so they don't get reused */
  1251. io_request->LUN[0] = 0;
  1252. io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
  1253. io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
  1254. io_request->EEDPFlags = 0;
  1255. io_request->Control = 0;
  1256. io_request->EEDPBlockSize = 0;
  1257. io_request->IoFlags = 0;
  1258. io_request->RaidContext.RAIDFlags = 0;
  1259. memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
  1260. /*
  1261. * Just the CDB length,rest of the Flags are zero
  1262. * This will be modified for FP in build_ldio_fusion
  1263. */
  1264. io_request->IoFlags = scp->cmd_len;
  1265. if (megasas_is_ldio(scp))
  1266. megasas_build_ldio_fusion(instance, scp, cmd);
  1267. else
  1268. megasas_build_dcdb_fusion(instance, scp, cmd);
  1269. /*
  1270. * Construct SGL
  1271. */
  1272. sge_count =
  1273. megasas_make_sgl_fusion(instance, scp,
  1274. (struct MPI25_IEEE_SGE_CHAIN64 *)
  1275. &io_request->SGL, cmd);
  1276. if (sge_count > instance->max_num_sge) {
  1277. printk(KERN_ERR "megasas: Error. sge_count (0x%x) exceeds "
  1278. "max (0x%x) allowed\n", sge_count,
  1279. instance->max_num_sge);
  1280. return 1;
  1281. }
  1282. io_request->RaidContext.numSGE = sge_count;
  1283. io_request->SGLFlags = MPI2_SGE_FLAGS_64_BIT_ADDRESSING;
  1284. if (scp->sc_data_direction == PCI_DMA_TODEVICE)
  1285. io_request->Control |= MPI2_SCSIIO_CONTROL_WRITE;
  1286. else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
  1287. io_request->Control |= MPI2_SCSIIO_CONTROL_READ;
  1288. io_request->SGLOffset0 =
  1289. offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4;
  1290. io_request->SenseBufferLowAddress = cmd->sense_phys_addr;
  1291. io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
  1292. cmd->scmd = scp;
  1293. scp->SCp.ptr = (char *)cmd;
  1294. return 0;
  1295. }
  1296. union MEGASAS_REQUEST_DESCRIPTOR_UNION *
  1297. megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
  1298. {
  1299. u8 *p;
  1300. struct fusion_context *fusion;
  1301. if (index >= instance->max_fw_cmds) {
  1302. printk(KERN_ERR "megasas: Invalid SMID (0x%x)request for "
  1303. "descriptor\n", index);
  1304. return NULL;
  1305. }
  1306. fusion = instance->ctrl_context;
  1307. p = fusion->req_frames_desc
  1308. +sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *index;
  1309. return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
  1310. }
  1311. /**
  1312. * megasas_build_and_issue_cmd_fusion -Main routine for building and
  1313. * issuing non IOCTL cmd
  1314. * @instance: Adapter soft state
  1315. * @scmd: pointer to scsi cmd from OS
  1316. */
  1317. static u32
  1318. megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
  1319. struct scsi_cmnd *scmd)
  1320. {
  1321. struct megasas_cmd_fusion *cmd;
  1322. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1323. u32 index;
  1324. struct fusion_context *fusion;
  1325. fusion = instance->ctrl_context;
  1326. cmd = megasas_get_cmd_fusion(instance);
  1327. if (!cmd)
  1328. return SCSI_MLQUEUE_HOST_BUSY;
  1329. index = cmd->index;
  1330. req_desc = megasas_get_request_descriptor(instance, index-1);
  1331. if (!req_desc)
  1332. return 1;
  1333. req_desc->Words = 0;
  1334. cmd->request_desc = req_desc;
  1335. cmd->request_desc->Words = 0;
  1336. if (megasas_build_io_fusion(instance, scmd, cmd)) {
  1337. megasas_return_cmd_fusion(instance, cmd);
  1338. printk(KERN_ERR "megasas: Error building command.\n");
  1339. cmd->request_desc = NULL;
  1340. return 1;
  1341. }
  1342. req_desc = cmd->request_desc;
  1343. req_desc->SCSIIO.SMID = index;
  1344. if (cmd->io_request->ChainOffset != 0 &&
  1345. cmd->io_request->ChainOffset != 0xF)
  1346. printk(KERN_ERR "megasas: The chain offset value is not "
  1347. "correct : %x\n", cmd->io_request->ChainOffset);
  1348. /*
  1349. * Issue the command to the FW
  1350. */
  1351. atomic_inc(&instance->fw_outstanding);
  1352. instance->instancet->fire_cmd(instance,
  1353. req_desc->u.low, req_desc->u.high,
  1354. instance->reg_set);
  1355. return 0;
  1356. }
  1357. /**
  1358. * complete_cmd_fusion - Completes command
  1359. * @instance: Adapter soft state
  1360. * Completes all commands that is in reply descriptor queue
  1361. */
  1362. int
  1363. complete_cmd_fusion(struct megasas_instance *instance)
  1364. {
  1365. union MPI2_REPLY_DESCRIPTORS_UNION *desc;
  1366. struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc;
  1367. struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
  1368. struct fusion_context *fusion;
  1369. struct megasas_cmd *cmd_mfi;
  1370. struct megasas_cmd_fusion *cmd_fusion;
  1371. u16 smid, num_completed;
  1372. u8 reply_descript_type, arm;
  1373. u32 status, extStatus, device_id;
  1374. union desc_value d_val;
  1375. struct LD_LOAD_BALANCE_INFO *lbinfo;
  1376. fusion = instance->ctrl_context;
  1377. if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR)
  1378. return IRQ_HANDLED;
  1379. desc = fusion->reply_frames_desc;
  1380. desc += fusion->last_reply_idx;
  1381. reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
  1382. d_val.word = desc->Words;
  1383. reply_descript_type = reply_desc->ReplyFlags &
  1384. MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
  1385. if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
  1386. return IRQ_NONE;
  1387. d_val.word = desc->Words;
  1388. num_completed = 0;
  1389. while ((d_val.u.low != UINT_MAX) && (d_val.u.high != UINT_MAX)) {
  1390. smid = reply_desc->SMID;
  1391. cmd_fusion = fusion->cmd_list[smid - 1];
  1392. scsi_io_req =
  1393. (struct MPI2_RAID_SCSI_IO_REQUEST *)
  1394. cmd_fusion->io_request;
  1395. if (cmd_fusion->scmd)
  1396. cmd_fusion->scmd->SCp.ptr = NULL;
  1397. status = scsi_io_req->RaidContext.status;
  1398. extStatus = scsi_io_req->RaidContext.exStatus;
  1399. switch (scsi_io_req->Function) {
  1400. case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/
  1401. /* Update load balancing info */
  1402. device_id = MEGASAS_DEV_INDEX(instance,
  1403. cmd_fusion->scmd);
  1404. lbinfo = &fusion->load_balance_info[device_id];
  1405. if (cmd_fusion->scmd->SCp.Status &
  1406. MEGASAS_LOAD_BALANCE_FLAG) {
  1407. arm = lbinfo->raid1DevHandle[0] ==
  1408. cmd_fusion->io_request->DevHandle ? 0 :
  1409. 1;
  1410. atomic_dec(&lbinfo->scsi_pending_cmds[arm]);
  1411. cmd_fusion->scmd->SCp.Status &=
  1412. ~MEGASAS_LOAD_BALANCE_FLAG;
  1413. }
  1414. if (reply_descript_type ==
  1415. MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) {
  1416. if (megasas_dbg_lvl == 5)
  1417. printk(KERN_ERR "\nmegasas: FAST Path "
  1418. "IO Success\n");
  1419. }
  1420. /* Fall thru and complete IO */
  1421. case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
  1422. /* Map the FW Cmd Status */
  1423. map_cmd_status(cmd_fusion, status, extStatus);
  1424. scsi_dma_unmap(cmd_fusion->scmd);
  1425. cmd_fusion->scmd->scsi_done(cmd_fusion->scmd);
  1426. scsi_io_req->RaidContext.status = 0;
  1427. scsi_io_req->RaidContext.exStatus = 0;
  1428. megasas_return_cmd_fusion(instance, cmd_fusion);
  1429. atomic_dec(&instance->fw_outstanding);
  1430. break;
  1431. case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
  1432. cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
  1433. megasas_complete_cmd(instance, cmd_mfi, DID_OK);
  1434. cmd_fusion->flags = 0;
  1435. megasas_return_cmd_fusion(instance, cmd_fusion);
  1436. break;
  1437. }
  1438. fusion->last_reply_idx++;
  1439. if (fusion->last_reply_idx >= fusion->reply_q_depth)
  1440. fusion->last_reply_idx = 0;
  1441. desc->Words = ULLONG_MAX;
  1442. num_completed++;
  1443. /* Get the next reply descriptor */
  1444. if (!fusion->last_reply_idx)
  1445. desc = fusion->reply_frames_desc;
  1446. else
  1447. desc++;
  1448. reply_desc =
  1449. (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
  1450. d_val.word = desc->Words;
  1451. reply_descript_type = reply_desc->ReplyFlags &
  1452. MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
  1453. if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
  1454. break;
  1455. }
  1456. if (!num_completed)
  1457. return IRQ_NONE;
  1458. wmb();
  1459. writel(fusion->last_reply_idx,
  1460. &instance->reg_set->reply_post_host_index);
  1461. return IRQ_HANDLED;
  1462. }
  1463. /**
  1464. * megasas_complete_cmd_dpc_fusion - Completes command
  1465. * @instance: Adapter soft state
  1466. *
  1467. * Tasklet to complete cmds
  1468. */
  1469. void
  1470. megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
  1471. {
  1472. struct megasas_instance *instance =
  1473. (struct megasas_instance *)instance_addr;
  1474. unsigned long flags;
  1475. /* If we have already declared adapter dead, donot complete cmds */
  1476. spin_lock_irqsave(&instance->hba_lock, flags);
  1477. if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
  1478. spin_unlock_irqrestore(&instance->hba_lock, flags);
  1479. return;
  1480. }
  1481. spin_unlock_irqrestore(&instance->hba_lock, flags);
  1482. spin_lock_irqsave(&instance->completion_lock, flags);
  1483. complete_cmd_fusion(instance);
  1484. spin_unlock_irqrestore(&instance->completion_lock, flags);
  1485. }
  1486. /**
  1487. * megasas_isr_fusion - isr entry point
  1488. */
  1489. irqreturn_t megasas_isr_fusion(int irq, void *devp)
  1490. {
  1491. struct megasas_instance *instance = (struct megasas_instance *)devp;
  1492. u32 mfiStatus, fw_state;
  1493. if (!instance->msi_flag) {
  1494. mfiStatus = instance->instancet->clear_intr(instance->reg_set);
  1495. if (!mfiStatus)
  1496. return IRQ_NONE;
  1497. }
  1498. /* If we are resetting, bail */
  1499. if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags))
  1500. return IRQ_HANDLED;
  1501. if (!complete_cmd_fusion(instance)) {
  1502. /* If we didn't complete any commands, check for FW fault */
  1503. fw_state = instance->instancet->read_fw_status_reg(
  1504. instance->reg_set) & MFI_STATE_MASK;
  1505. if (fw_state == MFI_STATE_FAULT)
  1506. schedule_work(&instance->work_init);
  1507. }
  1508. return IRQ_HANDLED;
  1509. }
  1510. /**
  1511. * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
  1512. * @instance: Adapter soft state
  1513. * mfi_cmd: megasas_cmd pointer
  1514. *
  1515. */
  1516. u8
  1517. build_mpt_mfi_pass_thru(struct megasas_instance *instance,
  1518. struct megasas_cmd *mfi_cmd)
  1519. {
  1520. struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain;
  1521. struct MPI2_RAID_SCSI_IO_REQUEST *io_req;
  1522. struct megasas_cmd_fusion *cmd;
  1523. struct fusion_context *fusion;
  1524. struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr;
  1525. cmd = megasas_get_cmd_fusion(instance);
  1526. if (!cmd)
  1527. return 1;
  1528. /* Save the smid. To be used for returning the cmd */
  1529. mfi_cmd->context.smid = cmd->index;
  1530. cmd->sync_cmd_idx = mfi_cmd->index;
  1531. /*
  1532. * For cmds where the flag is set, store the flag and check
  1533. * on completion. For cmds with this flag, don't call
  1534. * megasas_complete_cmd
  1535. */
  1536. if (frame_hdr->flags & MFI_FRAME_DONT_POST_IN_REPLY_QUEUE)
  1537. cmd->flags = MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
  1538. fusion = instance->ctrl_context;
  1539. io_req = cmd->io_request;
  1540. mpi25_ieee_chain =
  1541. (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
  1542. io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST;
  1543. io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST,
  1544. SGL) / 4;
  1545. io_req->ChainOffset = fusion->chain_offset_mfi_pthru;
  1546. mpi25_ieee_chain->Address = mfi_cmd->frame_phys_addr;
  1547. mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
  1548. MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
  1549. mpi25_ieee_chain->Length = MEGASAS_MAX_SZ_CHAIN_FRAME;
  1550. return 0;
  1551. }
  1552. /**
  1553. * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
  1554. * @instance: Adapter soft state
  1555. * @cmd: mfi cmd to build
  1556. *
  1557. */
  1558. union MEGASAS_REQUEST_DESCRIPTOR_UNION *
  1559. build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
  1560. {
  1561. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1562. u16 index;
  1563. if (build_mpt_mfi_pass_thru(instance, cmd)) {
  1564. printk(KERN_ERR "Couldn't build MFI pass thru cmd\n");
  1565. return NULL;
  1566. }
  1567. index = cmd->context.smid;
  1568. req_desc = megasas_get_request_descriptor(instance, index - 1);
  1569. if (!req_desc)
  1570. return NULL;
  1571. req_desc->Words = 0;
  1572. req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
  1573. MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
  1574. req_desc->SCSIIO.SMID = index;
  1575. return req_desc;
  1576. }
  1577. /**
  1578. * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
  1579. * @instance: Adapter soft state
  1580. * @cmd: mfi cmd pointer
  1581. *
  1582. */
  1583. void
  1584. megasas_issue_dcmd_fusion(struct megasas_instance *instance,
  1585. struct megasas_cmd *cmd)
  1586. {
  1587. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1588. union desc_value d_val;
  1589. req_desc = build_mpt_cmd(instance, cmd);
  1590. if (!req_desc) {
  1591. printk(KERN_ERR "Couldn't issue MFI pass thru cmd\n");
  1592. return;
  1593. }
  1594. d_val.word = req_desc->Words;
  1595. instance->instancet->fire_cmd(instance, req_desc->u.low,
  1596. req_desc->u.high, instance->reg_set);
  1597. }
  1598. /**
  1599. * megasas_release_fusion - Reverses the FW initialization
  1600. * @intance: Adapter soft state
  1601. */
  1602. void
  1603. megasas_release_fusion(struct megasas_instance *instance)
  1604. {
  1605. megasas_free_cmds(instance);
  1606. megasas_free_cmds_fusion(instance);
  1607. iounmap(instance->reg_set);
  1608. pci_release_selected_regions(instance->pdev, instance->bar);
  1609. }
  1610. /**
  1611. * megasas_read_fw_status_reg_fusion - returns the current FW status value
  1612. * @regs: MFI register set
  1613. */
  1614. static u32
  1615. megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem *regs)
  1616. {
  1617. return readl(&(regs)->outbound_scratch_pad);
  1618. }
  1619. /**
  1620. * megasas_adp_reset_fusion - For controller reset
  1621. * @regs: MFI register set
  1622. */
  1623. static int
  1624. megasas_adp_reset_fusion(struct megasas_instance *instance,
  1625. struct megasas_register_set __iomem *regs)
  1626. {
  1627. return 0;
  1628. }
  1629. /**
  1630. * megasas_check_reset_fusion - For controller reset check
  1631. * @regs: MFI register set
  1632. */
  1633. static int
  1634. megasas_check_reset_fusion(struct megasas_instance *instance,
  1635. struct megasas_register_set __iomem *regs)
  1636. {
  1637. return 0;
  1638. }
  1639. /* This function waits for outstanding commands on fusion to complete */
  1640. int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance)
  1641. {
  1642. int i, outstanding, retval = 0;
  1643. u32 fw_state, wait_time = MEGASAS_RESET_WAIT_TIME;
  1644. for (i = 0; i < wait_time; i++) {
  1645. /* Check if firmware is in fault state */
  1646. fw_state = instance->instancet->read_fw_status_reg(
  1647. instance->reg_set) & MFI_STATE_MASK;
  1648. if (fw_state == MFI_STATE_FAULT) {
  1649. printk(KERN_WARNING "megasas: Found FW in FAULT state,"
  1650. " will reset adapter.\n");
  1651. retval = 1;
  1652. goto out;
  1653. }
  1654. outstanding = atomic_read(&instance->fw_outstanding);
  1655. if (!outstanding)
  1656. goto out;
  1657. if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
  1658. printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
  1659. "commands to complete\n", i, outstanding);
  1660. megasas_complete_cmd_dpc_fusion(
  1661. (unsigned long)instance);
  1662. }
  1663. msleep(1000);
  1664. }
  1665. if (atomic_read(&instance->fw_outstanding)) {
  1666. printk("megaraid_sas: pending commands remain after waiting, "
  1667. "will reset adapter.\n");
  1668. retval = 1;
  1669. }
  1670. out:
  1671. return retval;
  1672. }
  1673. void megasas_reset_reply_desc(struct megasas_instance *instance)
  1674. {
  1675. int i;
  1676. struct fusion_context *fusion;
  1677. union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
  1678. fusion = instance->ctrl_context;
  1679. fusion->last_reply_idx = 0;
  1680. reply_desc = fusion->reply_frames_desc;
  1681. for (i = 0 ; i < fusion->reply_q_depth; i++, reply_desc++)
  1682. reply_desc->Words = ULLONG_MAX;
  1683. }
  1684. /* Core fusion reset function */
  1685. int megasas_reset_fusion(struct Scsi_Host *shost)
  1686. {
  1687. int retval = SUCCESS, i, j, retry = 0;
  1688. struct megasas_instance *instance;
  1689. struct megasas_cmd_fusion *cmd_fusion;
  1690. struct fusion_context *fusion;
  1691. struct megasas_cmd *cmd_mfi;
  1692. union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
  1693. u32 host_diag, abs_state;
  1694. instance = (struct megasas_instance *)shost->hostdata;
  1695. fusion = instance->ctrl_context;
  1696. mutex_lock(&instance->reset_mutex);
  1697. set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
  1698. instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT;
  1699. instance->instancet->disable_intr(instance->reg_set);
  1700. msleep(1000);
  1701. if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
  1702. printk(KERN_WARNING "megaraid_sas: Hardware critical error, "
  1703. "returning FAILED.\n");
  1704. retval = FAILED;
  1705. goto out;
  1706. }
  1707. /* First try waiting for commands to complete */
  1708. if (megasas_wait_for_outstanding_fusion(instance)) {
  1709. printk(KERN_WARNING "megaraid_sas: resetting fusion "
  1710. "adapter.\n");
  1711. /* Now return commands back to the OS */
  1712. for (i = 0 ; i < instance->max_fw_cmds; i++) {
  1713. cmd_fusion = fusion->cmd_list[i];
  1714. if (cmd_fusion->scmd) {
  1715. scsi_dma_unmap(cmd_fusion->scmd);
  1716. cmd_fusion->scmd->result = (DID_RESET << 16);
  1717. cmd_fusion->scmd->scsi_done(cmd_fusion->scmd);
  1718. megasas_return_cmd_fusion(instance, cmd_fusion);
  1719. atomic_dec(&instance->fw_outstanding);
  1720. }
  1721. }
  1722. if (instance->disableOnlineCtrlReset == 1) {
  1723. /* Reset not supported, kill adapter */
  1724. printk(KERN_WARNING "megaraid_sas: Reset not supported"
  1725. ", killing adapter.\n");
  1726. megaraid_sas_kill_hba(instance);
  1727. instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
  1728. retval = FAILED;
  1729. goto out;
  1730. }
  1731. /* Now try to reset the chip */
  1732. for (i = 0; i < MEGASAS_FUSION_MAX_RESET_TRIES; i++) {
  1733. writel(MPI2_WRSEQ_FLUSH_KEY_VALUE,
  1734. &instance->reg_set->fusion_seq_offset);
  1735. writel(MPI2_WRSEQ_1ST_KEY_VALUE,
  1736. &instance->reg_set->fusion_seq_offset);
  1737. writel(MPI2_WRSEQ_2ND_KEY_VALUE,
  1738. &instance->reg_set->fusion_seq_offset);
  1739. writel(MPI2_WRSEQ_3RD_KEY_VALUE,
  1740. &instance->reg_set->fusion_seq_offset);
  1741. writel(MPI2_WRSEQ_4TH_KEY_VALUE,
  1742. &instance->reg_set->fusion_seq_offset);
  1743. writel(MPI2_WRSEQ_5TH_KEY_VALUE,
  1744. &instance->reg_set->fusion_seq_offset);
  1745. writel(MPI2_WRSEQ_6TH_KEY_VALUE,
  1746. &instance->reg_set->fusion_seq_offset);
  1747. /* Check that the diag write enable (DRWE) bit is on */
  1748. host_diag = readl(&instance->reg_set->fusion_host_diag);
  1749. while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) {
  1750. msleep(100);
  1751. host_diag =
  1752. readl(&instance->reg_set->fusion_host_diag);
  1753. if (retry++ == 100) {
  1754. printk(KERN_WARNING "megaraid_sas: "
  1755. "Host diag unlock failed!\n");
  1756. break;
  1757. }
  1758. }
  1759. if (!(host_diag & HOST_DIAG_WRITE_ENABLE))
  1760. continue;
  1761. /* Send chip reset command */
  1762. writel(host_diag | HOST_DIAG_RESET_ADAPTER,
  1763. &instance->reg_set->fusion_host_diag);
  1764. msleep(3000);
  1765. /* Make sure reset adapter bit is cleared */
  1766. host_diag = readl(&instance->reg_set->fusion_host_diag);
  1767. retry = 0;
  1768. while (host_diag & HOST_DIAG_RESET_ADAPTER) {
  1769. msleep(100);
  1770. host_diag =
  1771. readl(&instance->reg_set->fusion_host_diag);
  1772. if (retry++ == 1000) {
  1773. printk(KERN_WARNING "megaraid_sas: "
  1774. "Diag reset adapter never "
  1775. "cleared!\n");
  1776. break;
  1777. }
  1778. }
  1779. if (host_diag & HOST_DIAG_RESET_ADAPTER)
  1780. continue;
  1781. abs_state =
  1782. instance->instancet->read_fw_status_reg(
  1783. instance->reg_set);
  1784. retry = 0;
  1785. while ((abs_state <= MFI_STATE_FW_INIT) &&
  1786. (retry++ < 1000)) {
  1787. msleep(100);
  1788. abs_state =
  1789. instance->instancet->read_fw_status_reg(
  1790. instance->reg_set);
  1791. }
  1792. if (abs_state <= MFI_STATE_FW_INIT) {
  1793. printk(KERN_WARNING "megaraid_sas: firmware "
  1794. "state < MFI_STATE_FW_INIT, state = "
  1795. "0x%x\n", abs_state);
  1796. continue;
  1797. }
  1798. /* Wait for FW to become ready */
  1799. if (megasas_transition_to_ready(instance)) {
  1800. printk(KERN_WARNING "megaraid_sas: Failed to "
  1801. "transition controller to ready.\n");
  1802. continue;
  1803. }
  1804. megasas_reset_reply_desc(instance);
  1805. if (megasas_ioc_init_fusion(instance)) {
  1806. printk(KERN_WARNING "megaraid_sas: "
  1807. "megasas_ioc_init_fusion() failed!\n");
  1808. continue;
  1809. }
  1810. instance->instancet->enable_intr(instance->reg_set);
  1811. instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
  1812. /* Re-fire management commands */
  1813. for (j = 0 ; j < instance->max_fw_cmds; j++) {
  1814. cmd_fusion = fusion->cmd_list[j];
  1815. if (cmd_fusion->sync_cmd_idx !=
  1816. (u32)ULONG_MAX) {
  1817. cmd_mfi =
  1818. instance->
  1819. cmd_list[cmd_fusion->sync_cmd_idx];
  1820. if (cmd_mfi->frame->dcmd.opcode ==
  1821. MR_DCMD_LD_MAP_GET_INFO) {
  1822. megasas_return_cmd(instance,
  1823. cmd_mfi);
  1824. megasas_return_cmd_fusion(
  1825. instance, cmd_fusion);
  1826. } else {
  1827. req_desc =
  1828. megasas_get_request_descriptor(
  1829. instance,
  1830. cmd_mfi->context.smid
  1831. -1);
  1832. if (!req_desc)
  1833. printk(KERN_WARNING
  1834. "req_desc NULL"
  1835. "\n");
  1836. else {
  1837. instance->instancet->
  1838. fire_cmd(instance,
  1839. req_desc->
  1840. u.low,
  1841. req_desc->
  1842. u.high,
  1843. instance->
  1844. reg_set);
  1845. }
  1846. }
  1847. }
  1848. }
  1849. /* Reset load balance info */
  1850. memset(fusion->load_balance_info, 0,
  1851. sizeof(struct LD_LOAD_BALANCE_INFO)
  1852. *MAX_LOGICAL_DRIVES);
  1853. if (!megasas_get_map_info(instance))
  1854. megasas_sync_map_info(instance);
  1855. /* Adapter reset completed successfully */
  1856. printk(KERN_WARNING "megaraid_sas: Reset "
  1857. "successful.\n");
  1858. retval = SUCCESS;
  1859. goto out;
  1860. }
  1861. /* Reset failed, kill the adapter */
  1862. printk(KERN_WARNING "megaraid_sas: Reset failed, killing "
  1863. "adapter.\n");
  1864. megaraid_sas_kill_hba(instance);
  1865. retval = FAILED;
  1866. } else {
  1867. instance->instancet->enable_intr(instance->reg_set);
  1868. instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
  1869. }
  1870. out:
  1871. clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
  1872. mutex_unlock(&instance->reset_mutex);
  1873. return retval;
  1874. }
  1875. /* Fusion OCR work queue */
  1876. void megasas_fusion_ocr_wq(struct work_struct *work)
  1877. {
  1878. struct megasas_instance *instance =
  1879. container_of(work, struct megasas_instance, work_init);
  1880. megasas_reset_fusion(instance->host);
  1881. }
  1882. struct megasas_instance_template megasas_instance_template_fusion = {
  1883. .fire_cmd = megasas_fire_cmd_fusion,
  1884. .enable_intr = megasas_enable_intr_fusion,
  1885. .disable_intr = megasas_disable_intr_fusion,
  1886. .clear_intr = megasas_clear_intr_fusion,
  1887. .read_fw_status_reg = megasas_read_fw_status_reg_fusion,
  1888. .adp_reset = megasas_adp_reset_fusion,
  1889. .check_reset = megasas_check_reset_fusion,
  1890. .service_isr = megasas_isr_fusion,
  1891. .tasklet = megasas_complete_cmd_dpc_fusion,
  1892. .init_adapter = megasas_init_adapter_fusion,
  1893. .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion,
  1894. .issue_dcmd = megasas_issue_dcmd_fusion,
  1895. };