megaraid_sas_fusion.c 62 KB

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