mptscsih.c 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157
  1. /*
  2. * linux/drivers/message/fusion/mptscsih.c
  3. * For use with LSI Logic PCI chip/adapter(s)
  4. * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
  5. *
  6. * Copyright (c) 1999-2007 LSI Logic Corporation
  7. * (mailto:mpt_linux_developer@lsi.com)
  8. *
  9. */
  10. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  11. /*
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; version 2 of the License.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. NO WARRANTY
  20. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. solely responsible for determining the appropriateness of using and
  25. distributing the Program and assumes all risks associated with its
  26. exercise of rights under this Agreement, including but not limited to
  27. the risks and costs of program errors, damage to or loss of data,
  28. programs or equipment, and unavailability or interruption of operations.
  29. DISCLAIMER OF LIABILITY
  30. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. You should have received a copy of the GNU General Public License
  38. along with this program; if not, write to the Free Software
  39. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  40. */
  41. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  42. #include "linux_compat.h" /* linux-2.6 tweaks */
  43. #include <linux/module.h>
  44. #include <linux/kernel.h>
  45. #include <linux/init.h>
  46. #include <linux/errno.h>
  47. #include <linux/kdev_t.h>
  48. #include <linux/blkdev.h>
  49. #include <linux/delay.h> /* for mdelay */
  50. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  51. #include <linux/reboot.h> /* notifier code */
  52. #include <linux/workqueue.h>
  53. #include <scsi/scsi.h>
  54. #include <scsi/scsi_cmnd.h>
  55. #include <scsi/scsi_device.h>
  56. #include <scsi/scsi_host.h>
  57. #include <scsi/scsi_tcq.h>
  58. #include <scsi/scsi_dbg.h>
  59. #include "mptbase.h"
  60. #include "mptscsih.h"
  61. #include "lsi/mpi_log_sas.h"
  62. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  63. #define my_NAME "Fusion MPT SCSI Host driver"
  64. #define my_VERSION MPT_LINUX_VERSION_COMMON
  65. #define MYNAM "mptscsih"
  66. MODULE_AUTHOR(MODULEAUTHOR);
  67. MODULE_DESCRIPTION(my_NAME);
  68. MODULE_LICENSE("GPL");
  69. MODULE_VERSION(my_VERSION);
  70. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  71. /*
  72. * Other private/forward protos...
  73. */
  74. int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  75. static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);
  76. int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  77. static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
  78. SCSIIORequest_t *pReq, int req_idx);
  79. static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
  80. static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
  81. static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
  82. static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout );
  83. static int SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc);
  84. static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
  85. int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
  86. int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
  87. int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  88. static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
  89. static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);
  90. void mptscsih_remove(struct pci_dev *);
  91. void mptscsih_shutdown(struct pci_dev *);
  92. #ifdef CONFIG_PM
  93. int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
  94. int mptscsih_resume(struct pci_dev *pdev);
  95. #endif
  96. #define SNS_LEN(scp) sizeof((scp)->sense_buffer)
  97. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  98. /**
  99. * mptscsih_add_sge - Place a simple SGE at address pAddr.
  100. * @pAddr: virtual address for SGE
  101. * @flagslength: SGE flags and data transfer length
  102. * @dma_addr: Physical address
  103. *
  104. * This routine places a MPT request frame back on the MPT adapter's
  105. * FreeQ.
  106. */
  107. static inline void
  108. mptscsih_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
  109. {
  110. if (sizeof(dma_addr_t) == sizeof(u64)) {
  111. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  112. u32 tmp = dma_addr & 0xFFFFFFFF;
  113. pSge->FlagsLength = cpu_to_le32(flagslength);
  114. pSge->Address.Low = cpu_to_le32(tmp);
  115. tmp = (u32) ((u64)dma_addr >> 32);
  116. pSge->Address.High = cpu_to_le32(tmp);
  117. } else {
  118. SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
  119. pSge->FlagsLength = cpu_to_le32(flagslength);
  120. pSge->Address = cpu_to_le32(dma_addr);
  121. }
  122. } /* mptscsih_add_sge() */
  123. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  124. /**
  125. * mptscsih_add_chain - Place a chain SGE at address pAddr.
  126. * @pAddr: virtual address for SGE
  127. * @next: nextChainOffset value (u32's)
  128. * @length: length of next SGL segment
  129. * @dma_addr: Physical address
  130. *
  131. * This routine places a MPT request frame back on the MPT adapter's
  132. * FreeQ.
  133. */
  134. static inline void
  135. mptscsih_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
  136. {
  137. if (sizeof(dma_addr_t) == sizeof(u64)) {
  138. SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
  139. u32 tmp = dma_addr & 0xFFFFFFFF;
  140. pChain->Length = cpu_to_le16(length);
  141. pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
  142. pChain->NextChainOffset = next;
  143. pChain->Address.Low = cpu_to_le32(tmp);
  144. tmp = (u32) ((u64)dma_addr >> 32);
  145. pChain->Address.High = cpu_to_le32(tmp);
  146. } else {
  147. SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
  148. pChain->Length = cpu_to_le16(length);
  149. pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
  150. pChain->NextChainOffset = next;
  151. pChain->Address = cpu_to_le32(dma_addr);
  152. }
  153. } /* mptscsih_add_chain() */
  154. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  155. /*
  156. * mptscsih_getFreeChainBuffer - Function to get a free chain
  157. * from the MPT_SCSI_HOST FreeChainQ.
  158. * @ioc: Pointer to MPT_ADAPTER structure
  159. * @req_idx: Index of the SCSI IO request frame. (output)
  160. *
  161. * return SUCCESS or FAILED
  162. */
  163. static inline int
  164. mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
  165. {
  166. MPT_FRAME_HDR *chainBuf;
  167. unsigned long flags;
  168. int rc;
  169. int chain_idx;
  170. dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer called\n",
  171. ioc->name));
  172. spin_lock_irqsave(&ioc->FreeQlock, flags);
  173. if (!list_empty(&ioc->FreeChainQ)) {
  174. int offset;
  175. chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,
  176. u.frame.linkage.list);
  177. list_del(&chainBuf->u.frame.linkage.list);
  178. offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
  179. chain_idx = offset / ioc->req_sz;
  180. rc = SUCCESS;
  181. dsgprintk((MYIOC_s_ERR_FMT "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
  182. ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
  183. } else {
  184. rc = FAILED;
  185. chain_idx = MPT_HOST_NO_CHAIN;
  186. dfailprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer failed\n",
  187. ioc->name));
  188. }
  189. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  190. *retIndex = chain_idx;
  191. return rc;
  192. } /* mptscsih_getFreeChainBuffer() */
  193. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  194. /*
  195. * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the
  196. * SCSIIORequest_t Message Frame.
  197. * @ioc: Pointer to MPT_ADAPTER structure
  198. * @SCpnt: Pointer to scsi_cmnd structure
  199. * @pReq: Pointer to SCSIIORequest_t structure
  200. *
  201. * Returns ...
  202. */
  203. static int
  204. mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
  205. SCSIIORequest_t *pReq, int req_idx)
  206. {
  207. char *psge;
  208. char *chainSge;
  209. struct scatterlist *sg;
  210. int frm_sz;
  211. int sges_left, sg_done;
  212. int chain_idx = MPT_HOST_NO_CHAIN;
  213. int sgeOffset;
  214. int numSgeSlots, numSgeThisFrame;
  215. u32 sgflags, sgdir, thisxfer = 0;
  216. int chain_dma_off = 0;
  217. int newIndex;
  218. int ii;
  219. dma_addr_t v2;
  220. u32 RequestNB;
  221. sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;
  222. if (sgdir == MPI_SCSIIO_CONTROL_WRITE) {
  223. sgdir = MPT_TRANSFER_HOST_TO_IOC;
  224. } else {
  225. sgdir = MPT_TRANSFER_IOC_TO_HOST;
  226. }
  227. psge = (char *) &pReq->SGL;
  228. frm_sz = ioc->req_sz;
  229. /* Map the data portion, if any.
  230. * sges_left = 0 if no data transfer.
  231. */
  232. sges_left = scsi_dma_map(SCpnt);
  233. if (sges_left < 0)
  234. return FAILED;
  235. /* Handle the SG case.
  236. */
  237. sg = scsi_sglist(SCpnt);
  238. sg_done = 0;
  239. sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);
  240. chainSge = NULL;
  241. /* Prior to entering this loop - the following must be set
  242. * current MF: sgeOffset (bytes)
  243. * chainSge (Null if original MF is not a chain buffer)
  244. * sg_done (num SGE done for this MF)
  245. */
  246. nextSGEset:
  247. numSgeSlots = ((frm_sz - sgeOffset) / (sizeof(u32) + sizeof(dma_addr_t)) );
  248. numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
  249. sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | MPT_SGE_FLAGS_ADDRESSING | sgdir;
  250. /* Get first (num - 1) SG elements
  251. * Skip any SG entries with a length of 0
  252. * NOTE: at finish, sg and psge pointed to NEXT data/location positions
  253. */
  254. for (ii=0; ii < (numSgeThisFrame-1); ii++) {
  255. thisxfer = sg_dma_len(sg);
  256. if (thisxfer == 0) {
  257. sg ++; /* Get next SG element from the OS */
  258. sg_done++;
  259. continue;
  260. }
  261. v2 = sg_dma_address(sg);
  262. mptscsih_add_sge(psge, sgflags | thisxfer, v2);
  263. sg++; /* Get next SG element from the OS */
  264. psge += (sizeof(u32) + sizeof(dma_addr_t));
  265. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  266. sg_done++;
  267. }
  268. if (numSgeThisFrame == sges_left) {
  269. /* Add last element, end of buffer and end of list flags.
  270. */
  271. sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT |
  272. MPT_SGE_FLAGS_END_OF_BUFFER |
  273. MPT_SGE_FLAGS_END_OF_LIST;
  274. /* Add last SGE and set termination flags.
  275. * Note: Last SGE may have a length of 0 - which should be ok.
  276. */
  277. thisxfer = sg_dma_len(sg);
  278. v2 = sg_dma_address(sg);
  279. mptscsih_add_sge(psge, sgflags | thisxfer, v2);
  280. /*
  281. sg++;
  282. psge += (sizeof(u32) + sizeof(dma_addr_t));
  283. */
  284. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  285. sg_done++;
  286. if (chainSge) {
  287. /* The current buffer is a chain buffer,
  288. * but there is not another one.
  289. * Update the chain element
  290. * Offset and Length fields.
  291. */
  292. mptscsih_add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
  293. } else {
  294. /* The current buffer is the original MF
  295. * and there is no Chain buffer.
  296. */
  297. pReq->ChainOffset = 0;
  298. RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
  299. dsgprintk((MYIOC_s_INFO_FMT
  300. "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
  301. ioc->RequestNB[req_idx] = RequestNB;
  302. }
  303. } else {
  304. /* At least one chain buffer is needed.
  305. * Complete the first MF
  306. * - last SGE element, set the LastElement bit
  307. * - set ChainOffset (words) for orig MF
  308. * (OR finish previous MF chain buffer)
  309. * - update MFStructPtr ChainIndex
  310. * - Populate chain element
  311. * Also
  312. * Loop until done.
  313. */
  314. dsgprintk((MYIOC_s_INFO_FMT "SG: Chain Required! sg done %d\n",
  315. ioc->name, sg_done));
  316. /* Set LAST_ELEMENT flag for last non-chain element
  317. * in the buffer. Since psge points at the NEXT
  318. * SGE element, go back one SGE element, update the flags
  319. * and reset the pointer. (Note: sgflags & thisxfer are already
  320. * set properly).
  321. */
  322. if (sg_done) {
  323. u32 *ptmp = (u32 *) (psge - (sizeof(u32) + sizeof(dma_addr_t)));
  324. sgflags = le32_to_cpu(*ptmp);
  325. sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;
  326. *ptmp = cpu_to_le32(sgflags);
  327. }
  328. if (chainSge) {
  329. /* The current buffer is a chain buffer.
  330. * chainSge points to the previous Chain Element.
  331. * Update its chain element Offset and Length (must
  332. * include chain element size) fields.
  333. * Old chain element is now complete.
  334. */
  335. u8 nextChain = (u8) (sgeOffset >> 2);
  336. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  337. mptscsih_add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
  338. } else {
  339. /* The original MF buffer requires a chain buffer -
  340. * set the offset.
  341. * Last element in this MF is a chain element.
  342. */
  343. pReq->ChainOffset = (u8) (sgeOffset >> 2);
  344. RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
  345. dsgprintk((MYIOC_s_ERR_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
  346. ioc->RequestNB[req_idx] = RequestNB;
  347. }
  348. sges_left -= sg_done;
  349. /* NOTE: psge points to the beginning of the chain element
  350. * in current buffer. Get a chain buffer.
  351. */
  352. if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) {
  353. dfailprintk((MYIOC_s_INFO_FMT
  354. "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",
  355. ioc->name, pReq->CDB[0], SCpnt));
  356. return FAILED;
  357. }
  358. /* Update the tracking arrays.
  359. * If chainSge == NULL, update ReqToChain, else ChainToChain
  360. */
  361. if (chainSge) {
  362. ioc->ChainToChain[chain_idx] = newIndex;
  363. } else {
  364. ioc->ReqToChain[req_idx] = newIndex;
  365. }
  366. chain_idx = newIndex;
  367. chain_dma_off = ioc->req_sz * chain_idx;
  368. /* Populate the chainSGE for the current buffer.
  369. * - Set chain buffer pointer to psge and fill
  370. * out the Address and Flags fields.
  371. */
  372. chainSge = (char *) psge;
  373. dsgprintk((KERN_INFO " Current buff @ %p (index 0x%x)",
  374. psge, req_idx));
  375. /* Start the SGE for the next buffer
  376. */
  377. psge = (char *) (ioc->ChainBuffer + chain_dma_off);
  378. sgeOffset = 0;
  379. sg_done = 0;
  380. dsgprintk((KERN_INFO " Chain buff @ %p (index 0x%x)\n",
  381. psge, chain_idx));
  382. /* Start the SGE for the next buffer
  383. */
  384. goto nextSGEset;
  385. }
  386. return SUCCESS;
  387. } /* mptscsih_AddSGE() */
  388. static void
  389. mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
  390. U32 SlotStatus)
  391. {
  392. MPT_FRAME_HDR *mf;
  393. SEPRequest_t *SEPMsg;
  394. if (ioc->bus_type == FC)
  395. return;
  396. if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
  397. dfailprintk((MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
  398. ioc->name,__FUNCTION__));
  399. return;
  400. }
  401. SEPMsg = (SEPRequest_t *)mf;
  402. SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
  403. SEPMsg->Bus = vtarget->channel;
  404. SEPMsg->TargetID = vtarget->id;
  405. SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS;
  406. SEPMsg->SlotStatus = SlotStatus;
  407. devtverboseprintk((MYIOC_s_WARN_FMT
  408. "Sending SEP cmd=%x channel=%d id=%d\n",
  409. ioc->name, SlotStatus, SEPMsg->Bus, SEPMsg->TargetID));
  410. mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  411. }
  412. #ifdef MPT_DEBUG_REPLY
  413. /**
  414. * mptscsih_iocstatus_info_scsiio - IOCSTATUS information for SCSIIO
  415. * @ioc: Pointer to MPT_ADAPTER structure
  416. * @ioc_status: U32 IOCStatus word from IOC
  417. * @scsi_status: U8 sam status from target
  418. * @scsi_state: U8 scsi state
  419. * @sc: original scsi cmnd pointer
  420. * @mf: Pointer to MPT request frame
  421. *
  422. * Refer to lsi/mpi.h.
  423. **/
  424. static void
  425. mptscsih_iocstatus_info_scsiio(MPT_ADAPTER *ioc, u32 ioc_status,
  426. u8 scsi_status, u8 scsi_state, struct scsi_cmnd *sc)
  427. {
  428. char extend_desc[EVENT_DESCR_STR_SZ];
  429. char *desc = NULL;
  430. switch (ioc_status) {
  431. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  432. desc = "SCSI Invalid Bus";
  433. break;
  434. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  435. desc = "SCSI Invalid TargetID";
  436. break;
  437. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  438. /*
  439. * Inquiry is issued for device scanning
  440. */
  441. if (sc->cmnd[0] != 0x12)
  442. desc = "SCSI Device Not There";
  443. break;
  444. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  445. desc = "SCSI Data Overrun";
  446. break;
  447. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  448. desc = "SCSI I/O Data Error";
  449. break;
  450. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  451. desc = "SCSI Protocol Error";
  452. break;
  453. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  454. desc = "SCSI Task Terminated";
  455. break;
  456. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  457. desc = "SCSI Residual Mismatch";
  458. break;
  459. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  460. desc = "SCSI Task Management Failed";
  461. break;
  462. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  463. desc = "SCSI IOC Terminated";
  464. break;
  465. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  466. desc = "SCSI Ext Terminated";
  467. break;
  468. }
  469. if (!desc)
  470. return;
  471. snprintf(extend_desc, EVENT_DESCR_STR_SZ,
  472. "[%d:%d:%d:%d] cmd=%02Xh, sam_status=%02Xh state=%02Xh",
  473. sc->device->host->host_no,
  474. sc->device->channel, sc->device->id, sc->device->lun,
  475. sc->cmnd[0], scsi_status, scsi_state);
  476. printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s: %s\n",
  477. ioc->name, ioc_status, desc, extend_desc);
  478. }
  479. #endif
  480. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  481. /*
  482. * mptscsih_io_done - Main SCSI IO callback routine registered to
  483. * Fusion MPT (base) driver
  484. * @ioc: Pointer to MPT_ADAPTER structure
  485. * @mf: Pointer to original MPT request frame
  486. * @r: Pointer to MPT reply frame (NULL if TurboReply)
  487. *
  488. * This routine is called from mpt.c::mpt_interrupt() at the completion
  489. * of any SCSI IO request.
  490. * This routine is registered with the Fusion MPT (base) driver at driver
  491. * load/init time via the mpt_register() API call.
  492. *
  493. * Returns 1 indicating alloc'd request frame ptr should be freed.
  494. */
  495. int
  496. mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  497. {
  498. struct scsi_cmnd *sc;
  499. MPT_SCSI_HOST *hd;
  500. SCSIIORequest_t *pScsiReq;
  501. SCSIIOReply_t *pScsiReply;
  502. u16 req_idx, req_idx_MR;
  503. VirtDevice *vdev;
  504. VirtTarget *vtarget;
  505. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  506. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  507. req_idx_MR = (mr != NULL) ?
  508. le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx;
  509. if ((req_idx != req_idx_MR) ||
  510. (mf->u.frame.linkage.arg1 == 0xdeadbeaf)) {
  511. printk(MYIOC_s_ERR_FMT "Received a mf that was already freed\n",
  512. ioc->name);
  513. printk (MYIOC_s_ERR_FMT
  514. "req_idx=%x req_idx_MR=%x mf=%p mr=%p sc=%p\n",
  515. ioc->name, req_idx, req_idx_MR, mf, mr,
  516. hd->ScsiLookup[req_idx_MR]);
  517. return 0;
  518. }
  519. sc = hd->ScsiLookup[req_idx];
  520. hd->ScsiLookup[req_idx] = NULL;
  521. if (sc == NULL) {
  522. MPIHeader_t *hdr = (MPIHeader_t *)mf;
  523. /* Remark: writeSDP1 will use the ScsiDoneCtx
  524. * If a SCSI I/O cmd, device disabled by OS and
  525. * completion done. Cannot touch sc struct. Just free mem.
  526. */
  527. if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)
  528. printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",
  529. ioc->name);
  530. mptscsih_freeChainBuffers(ioc, req_idx);
  531. return 1;
  532. }
  533. if ((unsigned char *)mf != sc->host_scribble) {
  534. mptscsih_freeChainBuffers(ioc, req_idx);
  535. return 1;
  536. }
  537. sc->host_scribble = NULL;
  538. sc->result = DID_OK << 16; /* Set default reply as OK */
  539. pScsiReq = (SCSIIORequest_t *) mf;
  540. pScsiReply = (SCSIIOReply_t *) mr;
  541. if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){
  542. dmfprintk((MYIOC_s_INFO_FMT
  543. "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
  544. ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));
  545. }else{
  546. dmfprintk((MYIOC_s_INFO_FMT
  547. "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
  548. ioc->name, mf, mr, sc, req_idx));
  549. }
  550. if (pScsiReply == NULL) {
  551. /* special context reply handling */
  552. ;
  553. } else {
  554. u32 xfer_cnt;
  555. u16 status;
  556. u8 scsi_state, scsi_status;
  557. u32 log_info;
  558. status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  559. scsi_state = pScsiReply->SCSIState;
  560. scsi_status = pScsiReply->SCSIStatus;
  561. xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
  562. scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
  563. log_info = le32_to_cpu(pScsiReply->IOCLogInfo);
  564. /*
  565. * if we get a data underrun indication, yet no data was
  566. * transferred and the SCSI status indicates that the
  567. * command was never started, change the data underrun
  568. * to success
  569. */
  570. if (status == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
  571. (scsi_status == MPI_SCSI_STATUS_BUSY ||
  572. scsi_status == MPI_SCSI_STATUS_RESERVATION_CONFLICT ||
  573. scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)) {
  574. status = MPI_IOCSTATUS_SUCCESS;
  575. }
  576. if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
  577. mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
  578. /*
  579. * Look for + dump FCP ResponseInfo[]!
  580. */
  581. if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
  582. pScsiReply->ResponseInfo) {
  583. printk(KERN_NOTICE "[%d:%d:%d:%d] "
  584. "FCP_ResponseInfo=%08xh\n",
  585. sc->device->host->host_no, sc->device->channel,
  586. sc->device->id, sc->device->lun,
  587. le32_to_cpu(pScsiReply->ResponseInfo));
  588. }
  589. switch(status) {
  590. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  591. /* CHECKME!
  592. * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
  593. * But not: DID_BUS_BUSY lest one risk
  594. * killing interrupt handler:-(
  595. */
  596. sc->result = SAM_STAT_BUSY;
  597. break;
  598. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  599. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  600. sc->result = DID_BAD_TARGET << 16;
  601. break;
  602. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  603. /* Spoof to SCSI Selection Timeout! */
  604. if (ioc->bus_type != FC)
  605. sc->result = DID_NO_CONNECT << 16;
  606. /* else fibre, just stall until rescan event */
  607. else
  608. sc->result = DID_REQUEUE << 16;
  609. if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
  610. hd->sel_timeout[pScsiReq->TargetID]++;
  611. vdev = sc->device->hostdata;
  612. if (!vdev)
  613. break;
  614. vtarget = vdev->vtarget;
  615. if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) {
  616. mptscsih_issue_sep_command(ioc, vtarget,
  617. MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED);
  618. vtarget->tflags &= ~MPT_TARGET_FLAGS_LED_ON;
  619. }
  620. break;
  621. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  622. if ( ioc->bus_type == SAS ) {
  623. u16 ioc_status = le16_to_cpu(pScsiReply->IOCStatus);
  624. if (ioc_status & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
  625. if ((log_info & SAS_LOGINFO_MASK)
  626. == SAS_LOGINFO_NEXUS_LOSS) {
  627. sc->result = (DID_BUS_BUSY << 16);
  628. break;
  629. }
  630. }
  631. } else if (ioc->bus_type == FC) {
  632. /*
  633. * The FC IOC may kill a request for variety of
  634. * reasons, some of which may be recovered by a
  635. * retry, some which are unlikely to be
  636. * recovered. Return DID_ERROR instead of
  637. * DID_RESET to permit retry of the command,
  638. * just not an infinite number of them
  639. */
  640. sc->result = DID_ERROR << 16;
  641. break;
  642. }
  643. /*
  644. * Allow non-SAS & non-NEXUS_LOSS to drop into below code
  645. */
  646. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  647. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  648. /* Linux handles an unsolicited DID_RESET better
  649. * than an unsolicited DID_ABORT.
  650. */
  651. sc->result = DID_RESET << 16;
  652. break;
  653. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  654. scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
  655. if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
  656. sc->result=DID_SOFT_ERROR << 16;
  657. else /* Sufficient data transfer occurred */
  658. sc->result = (DID_OK << 16) | scsi_status;
  659. dreplyprintk((KERN_NOTICE
  660. "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
  661. sc->result, sc->device->channel, sc->device->id));
  662. break;
  663. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  664. /*
  665. * Do upfront check for valid SenseData and give it
  666. * precedence!
  667. */
  668. sc->result = (DID_OK << 16) | scsi_status;
  669. if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  670. /* Have already saved the status and sense data
  671. */
  672. ;
  673. } else {
  674. if (xfer_cnt < sc->underflow) {
  675. if (scsi_status == SAM_STAT_BUSY)
  676. sc->result = SAM_STAT_BUSY;
  677. else
  678. sc->result = DID_SOFT_ERROR << 16;
  679. }
  680. if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
  681. /* What to do?
  682. */
  683. sc->result = DID_SOFT_ERROR << 16;
  684. }
  685. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  686. /* Not real sure here either... */
  687. sc->result = DID_RESET << 16;
  688. }
  689. }
  690. dreplyprintk((KERN_NOTICE " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
  691. sc->underflow));
  692. dreplyprintk((KERN_NOTICE " ActBytesXferd=%02xh\n", xfer_cnt));
  693. /* Report Queue Full
  694. */
  695. if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
  696. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  697. break;
  698. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  699. scsi_set_resid(sc, 0);
  700. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  701. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  702. sc->result = (DID_OK << 16) | scsi_status;
  703. if (scsi_state == 0) {
  704. ;
  705. } else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  706. /*
  707. * If running against circa 200003dd 909 MPT f/w,
  708. * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
  709. * (QUEUE_FULL) returned from device! --> get 0x0000?128
  710. * and with SenseBytes set to 0.
  711. */
  712. if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
  713. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  714. }
  715. else if (scsi_state &
  716. (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
  717. ) {
  718. /*
  719. * What to do?
  720. */
  721. sc->result = DID_SOFT_ERROR << 16;
  722. }
  723. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  724. /* Not real sure here either... */
  725. sc->result = DID_RESET << 16;
  726. }
  727. else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
  728. /* Device Inq. data indicates that it supports
  729. * QTags, but rejects QTag messages.
  730. * This command completed OK.
  731. *
  732. * Not real sure here either so do nothing... */
  733. }
  734. if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
  735. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  736. /* Add handling of:
  737. * Reservation Conflict, Busy,
  738. * Command Terminated, CHECK
  739. */
  740. break;
  741. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  742. sc->result = DID_SOFT_ERROR << 16;
  743. break;
  744. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  745. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  746. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  747. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  748. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  749. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  750. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  751. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  752. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  753. default:
  754. /*
  755. * What to do?
  756. */
  757. sc->result = DID_SOFT_ERROR << 16;
  758. break;
  759. } /* switch(status) */
  760. #ifdef MPT_DEBUG_REPLY
  761. if (sc->result) {
  762. mptscsih_iocstatus_info_scsiio(ioc, status,
  763. scsi_status, scsi_state, sc);
  764. dreplyprintk(("%s: [%d:%d:%d:%d] cmd=0x%02x "
  765. "result=0x%08x\n\tiocstatus=0x%04X "
  766. "scsi_state=0x%02X scsi_status=0x%02X "
  767. "loginfo=0x%08X\n", __FUNCTION__,
  768. sc->device->host->host_no, sc->device->channel, sc->device->id,
  769. sc->device->lun, sc->cmnd[0], sc->result, status,
  770. scsi_state, scsi_status, log_info));
  771. dreplyprintk(("%s: [%d:%d:%d:%d] resid=%d "
  772. "bufflen=%d xfer_cnt=%d\n", __FUNCTION__,
  773. sc->device->host->host_no,
  774. sc->device->channel, sc->device->id,
  775. sc->device->lun, scsi_get_resid(sc),
  776. scsi_bufflen(sc), xfer_cnt));
  777. }
  778. #endif
  779. } /* end of address reply case */
  780. /* Unmap the DMA buffers, if any. */
  781. scsi_dma_unmap(sc);
  782. sc->scsi_done(sc); /* Issue the command callback */
  783. /* Free Chain buffers */
  784. mptscsih_freeChainBuffers(ioc, req_idx);
  785. return 1;
  786. }
  787. /*
  788. * mptscsih_flush_running_cmds - For each command found, search
  789. * Scsi_Host instance taskQ and reply to OS.
  790. * Called only if recovering from a FW reload.
  791. * @hd: Pointer to a SCSI HOST structure
  792. *
  793. * Returns: None.
  794. *
  795. * Must be called while new I/Os are being queued.
  796. */
  797. static void
  798. mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
  799. {
  800. MPT_ADAPTER *ioc = hd->ioc;
  801. struct scsi_cmnd *SCpnt;
  802. MPT_FRAME_HDR *mf;
  803. int ii;
  804. int max = ioc->req_depth;
  805. dprintk((KERN_INFO MYNAM ": flush_ScsiLookup called\n"));
  806. for (ii= 0; ii < max; ii++) {
  807. if ((SCpnt = hd->ScsiLookup[ii]) != NULL) {
  808. /* Command found.
  809. */
  810. /* Null ScsiLookup index
  811. */
  812. hd->ScsiLookup[ii] = NULL;
  813. mf = MPT_INDEX_2_MFPTR(ioc, ii);
  814. dmfprintk(( "flush: ScsiDone (mf=%p,sc=%p)\n",
  815. mf, SCpnt));
  816. /* Free Chain buffers */
  817. mptscsih_freeChainBuffers(ioc, ii);
  818. /* Free Message frames */
  819. mpt_free_msg_frame(ioc, mf);
  820. if ((unsigned char *)mf != SCpnt->host_scribble)
  821. continue;
  822. /* Set status, free OS resources (SG DMA buffers)
  823. * Do OS callback
  824. */
  825. scsi_dma_unmap(SCpnt);
  826. SCpnt->result = DID_RESET << 16;
  827. SCpnt->host_scribble = NULL;
  828. SCpnt->scsi_done(SCpnt); /* Issue the command callback */
  829. }
  830. }
  831. return;
  832. }
  833. /*
  834. * mptscsih_search_running_cmds - Delete any commands associated
  835. * with the specified target and lun. Function called only
  836. * when a lun is disable by mid-layer.
  837. * Do NOT access the referenced scsi_cmnd structure or
  838. * members. Will cause either a paging or NULL ptr error.
  839. * (BUT, BUT, BUT, the code does reference it! - mdr)
  840. * @hd: Pointer to a SCSI HOST structure
  841. * @vdevice: per device private data
  842. *
  843. * Returns: None.
  844. *
  845. * Called from slave_destroy.
  846. */
  847. static void
  848. mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
  849. {
  850. SCSIIORequest_t *mf = NULL;
  851. int ii;
  852. int max = hd->ioc->req_depth;
  853. struct scsi_cmnd *sc;
  854. struct scsi_lun lun;
  855. dsprintk((KERN_INFO MYNAM ": search_running channel %d id %d lun %d max %d\n",
  856. vdevice->vtarget->channel, vdevice->vtarget->id, vdevice->lun, max));
  857. for (ii=0; ii < max; ii++) {
  858. if ((sc = hd->ScsiLookup[ii]) != NULL) {
  859. mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii);
  860. if (mf == NULL)
  861. continue;
  862. int_to_scsilun(vdevice->lun, &lun);
  863. if ((mf->Bus != vdevice->vtarget->channel) ||
  864. (mf->TargetID != vdevice->vtarget->id) ||
  865. memcmp(lun.scsi_lun, mf->LUN, 8))
  866. continue;
  867. dsprintk(( "search_running: found (sc=%p, mf = %p) "
  868. "channel %d id %d, lun %d \n", hd->ScsiLookup[ii],
  869. mf, mf->Bus, mf->TargetID, vdevice->lun));
  870. /* Cleanup
  871. */
  872. hd->ScsiLookup[ii] = NULL;
  873. mptscsih_freeChainBuffers(hd->ioc, ii);
  874. mpt_free_msg_frame(hd->ioc, (MPT_FRAME_HDR *)mf);
  875. if ((unsigned char *)mf != sc->host_scribble)
  876. continue;
  877. scsi_dma_unmap(sc);
  878. sc->host_scribble = NULL;
  879. sc->result = DID_NO_CONNECT << 16;
  880. sc->scsi_done(sc);
  881. }
  882. }
  883. return;
  884. }
  885. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  886. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  887. /*
  888. * mptscsih_report_queue_full - Report QUEUE_FULL status returned
  889. * from a SCSI target device.
  890. * @sc: Pointer to scsi_cmnd structure
  891. * @pScsiReply: Pointer to SCSIIOReply_t
  892. * @pScsiReq: Pointer to original SCSI request
  893. *
  894. * This routine periodically reports QUEUE_FULL status returned from a
  895. * SCSI target device. It reports this to the console via kernel
  896. * printk() API call, not more than once every 10 seconds.
  897. */
  898. static void
  899. mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
  900. {
  901. long time = jiffies;
  902. MPT_SCSI_HOST *hd;
  903. if (sc->device == NULL)
  904. return;
  905. if (sc->device->host == NULL)
  906. return;
  907. if ((hd = (MPT_SCSI_HOST *)sc->device->host->hostdata) == NULL)
  908. return;
  909. if (time - hd->last_queue_full > 10 * HZ) {
  910. dprintk((MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
  911. hd->ioc->name, 0, sc->device->id, sc->device->lun));
  912. hd->last_queue_full = time;
  913. }
  914. }
  915. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  916. /*
  917. * mptscsih_remove - Removed scsi devices
  918. * @pdev: Pointer to pci_dev structure
  919. *
  920. *
  921. */
  922. void
  923. mptscsih_remove(struct pci_dev *pdev)
  924. {
  925. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  926. struct Scsi_Host *host = ioc->sh;
  927. MPT_SCSI_HOST *hd;
  928. int sz1;
  929. if(!host) {
  930. mpt_detach(pdev);
  931. return;
  932. }
  933. scsi_remove_host(host);
  934. if((hd = (MPT_SCSI_HOST *)host->hostdata) == NULL)
  935. return;
  936. mptscsih_shutdown(pdev);
  937. sz1=0;
  938. if (hd->ScsiLookup != NULL) {
  939. sz1 = hd->ioc->req_depth * sizeof(void *);
  940. kfree(hd->ScsiLookup);
  941. hd->ScsiLookup = NULL;
  942. }
  943. dprintk((MYIOC_s_INFO_FMT
  944. "Free'd ScsiLookup (%d) memory\n",
  945. hd->ioc->name, sz1));
  946. kfree(hd->info_kbuf);
  947. /* NULL the Scsi_Host pointer
  948. */
  949. hd->ioc->sh = NULL;
  950. scsi_host_put(host);
  951. mpt_detach(pdev);
  952. }
  953. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  954. /*
  955. * mptscsih_shutdown - reboot notifier
  956. *
  957. */
  958. void
  959. mptscsih_shutdown(struct pci_dev *pdev)
  960. {
  961. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  962. struct Scsi_Host *host = ioc->sh;
  963. MPT_SCSI_HOST *hd;
  964. if(!host)
  965. return;
  966. hd = (MPT_SCSI_HOST *)host->hostdata;
  967. }
  968. #ifdef CONFIG_PM
  969. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  970. /*
  971. * mptscsih_suspend - Fusion MPT scsi driver suspend routine.
  972. *
  973. *
  974. */
  975. int
  976. mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
  977. {
  978. mptscsih_shutdown(pdev);
  979. return mpt_suspend(pdev,state);
  980. }
  981. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  982. /*
  983. * mptscsih_resume - Fusion MPT scsi driver resume routine.
  984. *
  985. *
  986. */
  987. int
  988. mptscsih_resume(struct pci_dev *pdev)
  989. {
  990. return mpt_resume(pdev);
  991. }
  992. #endif
  993. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  994. /**
  995. * mptscsih_info - Return information about MPT adapter
  996. * @SChost: Pointer to Scsi_Host structure
  997. *
  998. * (linux scsi_host_template.info routine)
  999. *
  1000. * Returns pointer to buffer where information was written.
  1001. */
  1002. const char *
  1003. mptscsih_info(struct Scsi_Host *SChost)
  1004. {
  1005. MPT_SCSI_HOST *h;
  1006. int size = 0;
  1007. h = (MPT_SCSI_HOST *)SChost->hostdata;
  1008. if (h) {
  1009. if (h->info_kbuf == NULL)
  1010. if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
  1011. return h->info_kbuf;
  1012. h->info_kbuf[0] = '\0';
  1013. mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
  1014. h->info_kbuf[size-1] = '\0';
  1015. }
  1016. return h->info_kbuf;
  1017. }
  1018. struct info_str {
  1019. char *buffer;
  1020. int length;
  1021. int offset;
  1022. int pos;
  1023. };
  1024. static void
  1025. mptscsih_copy_mem_info(struct info_str *info, char *data, int len)
  1026. {
  1027. if (info->pos + len > info->length)
  1028. len = info->length - info->pos;
  1029. if (info->pos + len < info->offset) {
  1030. info->pos += len;
  1031. return;
  1032. }
  1033. if (info->pos < info->offset) {
  1034. data += (info->offset - info->pos);
  1035. len -= (info->offset - info->pos);
  1036. }
  1037. if (len > 0) {
  1038. memcpy(info->buffer + info->pos, data, len);
  1039. info->pos += len;
  1040. }
  1041. }
  1042. static int
  1043. mptscsih_copy_info(struct info_str *info, char *fmt, ...)
  1044. {
  1045. va_list args;
  1046. char buf[81];
  1047. int len;
  1048. va_start(args, fmt);
  1049. len = vsprintf(buf, fmt, args);
  1050. va_end(args);
  1051. mptscsih_copy_mem_info(info, buf, len);
  1052. return len;
  1053. }
  1054. static int
  1055. mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)
  1056. {
  1057. struct info_str info;
  1058. info.buffer = pbuf;
  1059. info.length = len;
  1060. info.offset = offset;
  1061. info.pos = 0;
  1062. mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);
  1063. mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
  1064. mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);
  1065. mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth);
  1066. return ((info.pos > info.offset) ? info.pos - info.offset : 0);
  1067. }
  1068. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1069. /**
  1070. * mptscsih_proc_info - Return information about MPT adapter
  1071. * @host: scsi host struct
  1072. * @buffer: if write, user data; if read, buffer for user
  1073. * @start: returns the buffer address
  1074. * @offset: if write, 0; if read, the current offset into the buffer from
  1075. * the previous read.
  1076. * @length: if write, return length;
  1077. * @func: write = 1; read = 0
  1078. *
  1079. * (linux scsi_host_template.info routine)
  1080. */
  1081. int
  1082. mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
  1083. int length, int func)
  1084. {
  1085. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  1086. MPT_ADAPTER *ioc = hd->ioc;
  1087. int size = 0;
  1088. if (func) {
  1089. /*
  1090. * write is not supported
  1091. */
  1092. } else {
  1093. if (start)
  1094. *start = buffer;
  1095. size = mptscsih_host_info(ioc, buffer, offset, length);
  1096. }
  1097. return size;
  1098. }
  1099. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1100. #define ADD_INDEX_LOG(req_ent) do { } while(0)
  1101. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1102. /**
  1103. * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
  1104. * @SCpnt: Pointer to scsi_cmnd structure
  1105. * @done: Pointer SCSI mid-layer IO completion function
  1106. *
  1107. * (linux scsi_host_template.queuecommand routine)
  1108. * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
  1109. * from a linux scsi_cmnd request and send it to the IOC.
  1110. *
  1111. * Returns 0. (rtn value discarded by linux scsi mid-layer)
  1112. */
  1113. int
  1114. mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
  1115. {
  1116. MPT_SCSI_HOST *hd;
  1117. MPT_FRAME_HDR *mf;
  1118. SCSIIORequest_t *pScsiReq;
  1119. VirtDevice *vdev = SCpnt->device->hostdata;
  1120. int lun;
  1121. u32 datalen;
  1122. u32 scsictl;
  1123. u32 scsidir;
  1124. u32 cmd_len;
  1125. int my_idx;
  1126. int ii;
  1127. hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata;
  1128. lun = SCpnt->device->lun;
  1129. SCpnt->scsi_done = done;
  1130. dmfprintk((MYIOC_s_INFO_FMT "qcmd: SCpnt=%p, done()=%p\n",
  1131. (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt, done));
  1132. if (hd->resetPending) {
  1133. dtmprintk((MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
  1134. (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt));
  1135. return SCSI_MLQUEUE_HOST_BUSY;
  1136. }
  1137. /*
  1138. * Put together a MPT SCSI request...
  1139. */
  1140. if ((mf = mpt_get_msg_frame(hd->ioc->DoneCtx, hd->ioc)) == NULL) {
  1141. dprintk((MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
  1142. hd->ioc->name));
  1143. return SCSI_MLQUEUE_HOST_BUSY;
  1144. }
  1145. pScsiReq = (SCSIIORequest_t *) mf;
  1146. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  1147. ADD_INDEX_LOG(my_idx);
  1148. /* TUR's being issued with scsictl=0x02000000 (DATA_IN)!
  1149. * Seems we may receive a buffer (datalen>0) even when there
  1150. * will be no data transfer! GRRRRR...
  1151. */
  1152. if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
  1153. datalen = scsi_bufflen(SCpnt);
  1154. scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
  1155. } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
  1156. datalen = scsi_bufflen(SCpnt);
  1157. scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
  1158. } else {
  1159. datalen = 0;
  1160. scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
  1161. }
  1162. /* Default to untagged. Once a target structure has been allocated,
  1163. * use the Inquiry data to determine if device supports tagged.
  1164. */
  1165. if (vdev
  1166. && (vdev->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
  1167. && (SCpnt->device->tagged_supported)) {
  1168. scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
  1169. } else {
  1170. scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
  1171. }
  1172. /* Use the above information to set up the message frame
  1173. */
  1174. pScsiReq->TargetID = (u8) vdev->vtarget->id;
  1175. pScsiReq->Bus = vdev->vtarget->channel;
  1176. pScsiReq->ChainOffset = 0;
  1177. if (vdev->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
  1178. pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  1179. else
  1180. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  1181. pScsiReq->CDBLength = SCpnt->cmd_len;
  1182. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1183. pScsiReq->Reserved = 0;
  1184. pScsiReq->MsgFlags = mpt_msg_flags();
  1185. int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);
  1186. pScsiReq->Control = cpu_to_le32(scsictl);
  1187. /*
  1188. * Write SCSI CDB into the message
  1189. */
  1190. cmd_len = SCpnt->cmd_len;
  1191. for (ii=0; ii < cmd_len; ii++)
  1192. pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
  1193. for (ii=cmd_len; ii < 16; ii++)
  1194. pScsiReq->CDB[ii] = 0;
  1195. /* DataLength */
  1196. pScsiReq->DataLength = cpu_to_le32(datalen);
  1197. /* SenseBuffer low address */
  1198. pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
  1199. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  1200. /* Now add the SG list
  1201. * Always have a SGE even if null length.
  1202. */
  1203. if (datalen == 0) {
  1204. /* Add a NULL SGE */
  1205. mptscsih_add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0,
  1206. (dma_addr_t) -1);
  1207. } else {
  1208. /* Add a 32 or 64 bit SGE */
  1209. if (mptscsih_AddSGE(hd->ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
  1210. goto fail;
  1211. }
  1212. SCpnt->host_scribble = (unsigned char *)mf;
  1213. hd->ScsiLookup[my_idx] = SCpnt;
  1214. mpt_put_msg_frame(hd->ioc->DoneCtx, hd->ioc, mf);
  1215. dmfprintk((MYIOC_s_INFO_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
  1216. hd->ioc->name, SCpnt, mf, my_idx));
  1217. DBG_DUMP_REQUEST_FRAME(mf)
  1218. return 0;
  1219. fail:
  1220. hd->ScsiLookup[my_idx] = NULL;
  1221. mptscsih_freeChainBuffers(hd->ioc, my_idx);
  1222. mpt_free_msg_frame(hd->ioc, mf);
  1223. return SCSI_MLQUEUE_HOST_BUSY;
  1224. }
  1225. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1226. /*
  1227. * mptscsih_freeChainBuffers - Function to free chain buffers associated
  1228. * with a SCSI IO request
  1229. * @hd: Pointer to the MPT_SCSI_HOST instance
  1230. * @req_idx: Index of the SCSI IO request frame.
  1231. *
  1232. * Called if SG chain buffer allocation fails and mptscsih callbacks.
  1233. * No return.
  1234. */
  1235. static void
  1236. mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
  1237. {
  1238. MPT_FRAME_HDR *chain;
  1239. unsigned long flags;
  1240. int chain_idx;
  1241. int next;
  1242. /* Get the first chain index and reset
  1243. * tracker state.
  1244. */
  1245. chain_idx = ioc->ReqToChain[req_idx];
  1246. ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
  1247. while (chain_idx != MPT_HOST_NO_CHAIN) {
  1248. /* Save the next chain buffer index */
  1249. next = ioc->ChainToChain[chain_idx];
  1250. /* Free this chain buffer and reset
  1251. * tracker
  1252. */
  1253. ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
  1254. chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
  1255. + (chain_idx * ioc->req_sz));
  1256. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1257. list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
  1258. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1259. dmfprintk((MYIOC_s_INFO_FMT "FreeChainBuffers (index %d)\n",
  1260. ioc->name, chain_idx));
  1261. /* handle next */
  1262. chain_idx = next;
  1263. }
  1264. return;
  1265. }
  1266. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1267. /*
  1268. * Reset Handling
  1269. */
  1270. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1271. /**
  1272. * mptscsih_TMHandler - Generic handler for SCSI Task Management.
  1273. * @hd: Pointer to MPT SCSI HOST structure
  1274. * @type: Task Management type
  1275. * @channel: channel number for task management
  1276. * @id: Logical Target ID for reset (if appropriate)
  1277. * @lun: Logical Unit for reset (if appropriate)
  1278. * @ctx2abort: Context for the task to be aborted (if appropriate)
  1279. * @timeout: timeout for task management control
  1280. *
  1281. * Fall through to mpt_HardResetHandler if: not operational, too many
  1282. * failed TM requests or handshake failure.
  1283. *
  1284. * Remark: Currently invoked from a non-interrupt thread (_bh).
  1285. *
  1286. * Remark: With old EH code, at most 1 SCSI TaskMgmt function per IOC
  1287. * will be active.
  1288. *
  1289. * Returns 0 for SUCCESS, or %FAILED.
  1290. **/
  1291. int
  1292. mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
  1293. {
  1294. MPT_ADAPTER *ioc;
  1295. int rc = -1;
  1296. u32 ioc_raw_state;
  1297. unsigned long flags;
  1298. ioc = hd->ioc;
  1299. dtmprintk((MYIOC_s_INFO_FMT "TMHandler Entered!\n", ioc->name));
  1300. // SJR - CHECKME - Can we avoid this here?
  1301. // (mpt_HardResetHandler has this check...)
  1302. spin_lock_irqsave(&ioc->diagLock, flags);
  1303. if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)) {
  1304. spin_unlock_irqrestore(&ioc->diagLock, flags);
  1305. return FAILED;
  1306. }
  1307. spin_unlock_irqrestore(&ioc->diagLock, flags);
  1308. /* Wait a fixed amount of time for the TM pending flag to be cleared.
  1309. * If we time out and not bus reset, then we return a FAILED status
  1310. * to the caller.
  1311. * The call to mptscsih_tm_pending_wait() will set the pending flag
  1312. * if we are
  1313. * successful. Otherwise, reload the FW.
  1314. */
  1315. if (mptscsih_tm_pending_wait(hd) == FAILED) {
  1316. if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
  1317. dtmprintk((KERN_INFO MYNAM ": %s: TMHandler abort: "
  1318. "Timed out waiting for last TM (%d) to complete! \n",
  1319. hd->ioc->name, hd->tmPending));
  1320. return FAILED;
  1321. } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
  1322. dtmprintk((KERN_INFO MYNAM ": %s: TMHandler target "
  1323. "reset: Timed out waiting for last TM (%d) "
  1324. "to complete! \n", hd->ioc->name,
  1325. hd->tmPending));
  1326. return FAILED;
  1327. } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
  1328. dtmprintk((KERN_INFO MYNAM ": %s: TMHandler bus reset: "
  1329. "Timed out waiting for last TM (%d) to complete! \n",
  1330. hd->ioc->name, hd->tmPending));
  1331. return FAILED;
  1332. }
  1333. } else {
  1334. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1335. hd->tmPending |= (1 << type);
  1336. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1337. }
  1338. ioc_raw_state = mpt_GetIocState(hd->ioc, 0);
  1339. if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
  1340. printk(MYIOC_s_WARN_FMT
  1341. "TM Handler for type=%x: IOC Not operational (0x%x)!\n",
  1342. ioc->name, type, ioc_raw_state);
  1343. printk(KERN_WARNING " Issuing HardReset!!\n");
  1344. if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
  1345. printk((KERN_WARNING "TMHandler: HardReset "
  1346. "FAILED!!\n"));
  1347. return FAILED;
  1348. }
  1349. if (ioc_raw_state & MPI_DOORBELL_ACTIVE) {
  1350. printk(MYIOC_s_WARN_FMT
  1351. "TM Handler for type=%x: ioc_state: "
  1352. "DOORBELL_ACTIVE (0x%x)!\n",
  1353. ioc->name, type, ioc_raw_state);
  1354. return FAILED;
  1355. }
  1356. /* Isse the Task Mgmt request.
  1357. */
  1358. if (hd->hard_resets < -1)
  1359. hd->hard_resets++;
  1360. rc = mptscsih_IssueTaskMgmt(hd, type, channel, id, lun,
  1361. ctx2abort, timeout);
  1362. if (rc)
  1363. printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n",
  1364. hd->ioc->name);
  1365. else
  1366. dtmprintk((MYIOC_s_INFO_FMT "Issue of TaskMgmt Successful!\n",
  1367. hd->ioc->name));
  1368. dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc));
  1369. return rc;
  1370. }
  1371. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1372. /**
  1373. * mptscsih_IssueTaskMgmt - Generic send Task Management function.
  1374. * @hd: Pointer to MPT_SCSI_HOST structure
  1375. * @type: Task Management type
  1376. * @channel: channel number for task management
  1377. * @id: Logical Target ID for reset (if appropriate)
  1378. * @lun: Logical Unit for reset (if appropriate)
  1379. * @ctx2abort: Context for the task to be aborted (if appropriate)
  1380. * @timeout: timeout for task management control
  1381. *
  1382. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  1383. * or a non-interrupt thread. In the former, must not call schedule().
  1384. *
  1385. * Not all fields are meaningfull for all task types.
  1386. *
  1387. * Returns 0 for SUCCESS, or FAILED.
  1388. *
  1389. **/
  1390. static int
  1391. mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
  1392. {
  1393. MPT_FRAME_HDR *mf;
  1394. SCSITaskMgmt_t *pScsiTm;
  1395. int ii;
  1396. int retval;
  1397. /* Return Fail to calling function if no message frames available.
  1398. */
  1399. if ((mf = mpt_get_msg_frame(hd->ioc->TaskCtx, hd->ioc)) == NULL) {
  1400. dfailprintk((MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
  1401. hd->ioc->name));
  1402. return FAILED;
  1403. }
  1404. dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
  1405. hd->ioc->name, mf));
  1406. /* Format the Request
  1407. */
  1408. pScsiTm = (SCSITaskMgmt_t *) mf;
  1409. pScsiTm->TargetID = id;
  1410. pScsiTm->Bus = channel;
  1411. pScsiTm->ChainOffset = 0;
  1412. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  1413. pScsiTm->Reserved = 0;
  1414. pScsiTm->TaskType = type;
  1415. pScsiTm->Reserved1 = 0;
  1416. pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
  1417. ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
  1418. int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
  1419. for (ii=0; ii < 7; ii++)
  1420. pScsiTm->Reserved2[ii] = 0;
  1421. pScsiTm->TaskMsgContext = ctx2abort;
  1422. dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt: ctx2abort (0x%08x) "
  1423. "type=%d\n", hd->ioc->name, ctx2abort, type));
  1424. DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm);
  1425. if ((retval = mpt_send_handshake_request(hd->ioc->TaskCtx, hd->ioc,
  1426. sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP)) != 0) {
  1427. dfailprintk((MYIOC_s_ERR_FMT "send_handshake FAILED!"
  1428. " (hd %p, ioc %p, mf %p, rc=%d) \n", hd->ioc->name, hd,
  1429. hd->ioc, mf, retval));
  1430. goto fail_out;
  1431. }
  1432. if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) {
  1433. dfailprintk((MYIOC_s_ERR_FMT "task management request TIMED OUT!"
  1434. " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
  1435. hd->ioc, mf));
  1436. dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
  1437. hd->ioc->name));
  1438. retval = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
  1439. dtmprintk((MYIOC_s_INFO_FMT "rc=%d \n",
  1440. hd->ioc->name, retval));
  1441. goto fail_out;
  1442. }
  1443. /*
  1444. * Handle success case, see if theres a non-zero ioc_status.
  1445. */
  1446. if (hd->tm_iocstatus == MPI_IOCSTATUS_SUCCESS ||
  1447. hd->tm_iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
  1448. hd->tm_iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
  1449. retval = 0;
  1450. else
  1451. retval = FAILED;
  1452. return retval;
  1453. fail_out:
  1454. /*
  1455. * Free task managment mf, and corresponding tm flags
  1456. */
  1457. mpt_free_msg_frame(hd->ioc, mf);
  1458. hd->tmPending = 0;
  1459. hd->tmState = TM_STATE_NONE;
  1460. return FAILED;
  1461. }
  1462. static int
  1463. mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
  1464. {
  1465. switch (ioc->bus_type) {
  1466. case FC:
  1467. return 40;
  1468. case SAS:
  1469. return 10;
  1470. case SPI:
  1471. default:
  1472. return 2;
  1473. }
  1474. }
  1475. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1476. /**
  1477. * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
  1478. * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
  1479. *
  1480. * (linux scsi_host_template.eh_abort_handler routine)
  1481. *
  1482. * Returns SUCCESS or FAILED.
  1483. **/
  1484. int
  1485. mptscsih_abort(struct scsi_cmnd * SCpnt)
  1486. {
  1487. MPT_SCSI_HOST *hd;
  1488. MPT_FRAME_HDR *mf;
  1489. u32 ctx2abort;
  1490. int scpnt_idx;
  1491. int retval;
  1492. VirtDevice *vdev;
  1493. ulong sn = SCpnt->serial_number;
  1494. /* If we can't locate our host adapter structure, return FAILED status.
  1495. */
  1496. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL) {
  1497. SCpnt->result = DID_RESET << 16;
  1498. SCpnt->scsi_done(SCpnt);
  1499. dfailprintk((KERN_INFO MYNAM ": mptscsih_abort: "
  1500. "Can't locate host! (sc=%p)\n",
  1501. SCpnt));
  1502. return FAILED;
  1503. }
  1504. /* Find this command
  1505. */
  1506. if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(SCpnt)) < 0) {
  1507. /* Cmd not found in ScsiLookup.
  1508. * Do OS callback.
  1509. */
  1510. SCpnt->result = DID_RESET << 16;
  1511. dtmprintk((KERN_INFO MYNAM ": %s: mptscsih_abort: "
  1512. "Command not in the active list! (sc=%p)\n",
  1513. hd->ioc->name, SCpnt));
  1514. return SUCCESS;
  1515. }
  1516. if (hd->resetPending)
  1517. return FAILED;
  1518. if (hd->timeouts < -1)
  1519. hd->timeouts++;
  1520. printk(KERN_WARNING MYNAM ": %s: attempting task abort! (sc=%p)\n",
  1521. hd->ioc->name, SCpnt);
  1522. scsi_print_command(SCpnt);
  1523. /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
  1524. * (the IO to be ABORT'd)
  1525. *
  1526. * NOTE: Since we do not byteswap MsgContext, we do not
  1527. * swap it here either. It is an opaque cookie to
  1528. * the controller, so it does not matter. -DaveM
  1529. */
  1530. mf = MPT_INDEX_2_MFPTR(hd->ioc, scpnt_idx);
  1531. ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
  1532. hd->abortSCpnt = SCpnt;
  1533. vdev = SCpnt->device->hostdata;
  1534. retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
  1535. vdev->vtarget->channel, vdev->vtarget->id, vdev->lun,
  1536. ctx2abort, mptscsih_get_tm_timeout(hd->ioc));
  1537. if (SCPNT_TO_LOOKUP_IDX(SCpnt) == scpnt_idx &&
  1538. SCpnt->serial_number == sn)
  1539. retval = FAILED;
  1540. printk (KERN_WARNING MYNAM ": %s: task abort: %s (sc=%p)\n",
  1541. hd->ioc->name,
  1542. ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1543. if (retval == 0)
  1544. return SUCCESS;
  1545. else
  1546. return FAILED;
  1547. }
  1548. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1549. /**
  1550. * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
  1551. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1552. *
  1553. * (linux scsi_host_template.eh_dev_reset_handler routine)
  1554. *
  1555. * Returns SUCCESS or FAILED.
  1556. **/
  1557. int
  1558. mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
  1559. {
  1560. MPT_SCSI_HOST *hd;
  1561. int retval;
  1562. VirtDevice *vdev;
  1563. /* If we can't locate our host adapter structure, return FAILED status.
  1564. */
  1565. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1566. dtmprintk((KERN_INFO MYNAM ": mptscsih_dev_reset: "
  1567. "Can't locate host! (sc=%p)\n",
  1568. SCpnt));
  1569. return FAILED;
  1570. }
  1571. if (hd->resetPending)
  1572. return FAILED;
  1573. printk(KERN_WARNING MYNAM ": %s: attempting target reset! (sc=%p)\n",
  1574. hd->ioc->name, SCpnt);
  1575. scsi_print_command(SCpnt);
  1576. vdev = SCpnt->device->hostdata;
  1577. retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
  1578. vdev->vtarget->channel, vdev->vtarget->id,
  1579. 0, 0, mptscsih_get_tm_timeout(hd->ioc));
  1580. printk (KERN_WARNING MYNAM ": %s: target reset: %s (sc=%p)\n",
  1581. hd->ioc->name,
  1582. ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1583. if (retval == 0)
  1584. return SUCCESS;
  1585. else
  1586. return FAILED;
  1587. }
  1588. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1589. /**
  1590. * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
  1591. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1592. *
  1593. * (linux scsi_host_template.eh_bus_reset_handler routine)
  1594. *
  1595. * Returns SUCCESS or FAILED.
  1596. **/
  1597. int
  1598. mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
  1599. {
  1600. MPT_SCSI_HOST *hd;
  1601. int retval;
  1602. VirtDevice *vdev;
  1603. /* If we can't locate our host adapter structure, return FAILED status.
  1604. */
  1605. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1606. dtmprintk((KERN_INFO MYNAM ": mptscsih_bus_reset: "
  1607. "Can't locate host! (sc=%p)\n",
  1608. SCpnt ) );
  1609. return FAILED;
  1610. }
  1611. printk(KERN_WARNING MYNAM ": %s: attempting bus reset! (sc=%p)\n",
  1612. hd->ioc->name, SCpnt);
  1613. scsi_print_command(SCpnt);
  1614. if (hd->timeouts < -1)
  1615. hd->timeouts++;
  1616. vdev = SCpnt->device->hostdata;
  1617. retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  1618. vdev->vtarget->channel, 0, 0, 0, mptscsih_get_tm_timeout(hd->ioc));
  1619. printk (KERN_WARNING MYNAM ": %s: bus reset: %s (sc=%p)\n",
  1620. hd->ioc->name,
  1621. ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1622. if (retval == 0)
  1623. return SUCCESS;
  1624. else
  1625. return FAILED;
  1626. }
  1627. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1628. /**
  1629. * mptscsih_host_reset - Perform a SCSI host adapter RESET (new_eh variant)
  1630. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1631. *
  1632. * (linux scsi_host_template.eh_host_reset_handler routine)
  1633. *
  1634. * Returns SUCCESS or FAILED.
  1635. */
  1636. int
  1637. mptscsih_host_reset(struct scsi_cmnd *SCpnt)
  1638. {
  1639. MPT_SCSI_HOST * hd;
  1640. int status = SUCCESS;
  1641. /* If we can't locate the host to reset, then we failed. */
  1642. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1643. dtmprintk( ( KERN_INFO MYNAM ": mptscsih_host_reset: "
  1644. "Can't locate host! (sc=%p)\n",
  1645. SCpnt ) );
  1646. return FAILED;
  1647. }
  1648. printk(KERN_WARNING MYNAM ": %s: Attempting host reset! (sc=%p)\n",
  1649. hd->ioc->name, SCpnt);
  1650. /* If our attempts to reset the host failed, then return a failed
  1651. * status. The host will be taken off line by the SCSI mid-layer.
  1652. */
  1653. if (mpt_HardResetHandler(hd->ioc, CAN_SLEEP) < 0){
  1654. status = FAILED;
  1655. } else {
  1656. /* Make sure TM pending is cleared and TM state is set to
  1657. * NONE.
  1658. */
  1659. hd->tmPending = 0;
  1660. hd->tmState = TM_STATE_NONE;
  1661. }
  1662. dtmprintk( ( KERN_INFO MYNAM ": mptscsih_host_reset: "
  1663. "Status = %s\n",
  1664. (status == SUCCESS) ? "SUCCESS" : "FAILED" ) );
  1665. return status;
  1666. }
  1667. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1668. /**
  1669. * mptscsih_tm_pending_wait - wait for pending task management request to complete
  1670. * @hd: Pointer to MPT host structure.
  1671. *
  1672. * Returns {SUCCESS,FAILED}.
  1673. */
  1674. static int
  1675. mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
  1676. {
  1677. unsigned long flags;
  1678. int loop_count = 4 * 10; /* Wait 10 seconds */
  1679. int status = FAILED;
  1680. do {
  1681. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1682. if (hd->tmState == TM_STATE_NONE) {
  1683. hd->tmState = TM_STATE_IN_PROGRESS;
  1684. hd->tmPending = 1;
  1685. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1686. status = SUCCESS;
  1687. break;
  1688. }
  1689. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1690. msleep(250);
  1691. } while (--loop_count);
  1692. return status;
  1693. }
  1694. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1695. /**
  1696. * mptscsih_tm_wait_for_completion - wait for completion of TM task
  1697. * @hd: Pointer to MPT host structure.
  1698. * @timeout: timeout value
  1699. *
  1700. * Returns {SUCCESS,FAILED}.
  1701. */
  1702. static int
  1703. mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout )
  1704. {
  1705. unsigned long flags;
  1706. int loop_count = 4 * timeout;
  1707. int status = FAILED;
  1708. do {
  1709. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1710. if(hd->tmPending == 0) {
  1711. status = SUCCESS;
  1712. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1713. break;
  1714. }
  1715. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1716. msleep(250);
  1717. } while (--loop_count);
  1718. return status;
  1719. }
  1720. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1721. static void
  1722. mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
  1723. {
  1724. char *desc;
  1725. switch (response_code) {
  1726. case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:
  1727. desc = "The task completed.";
  1728. break;
  1729. case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:
  1730. desc = "The IOC received an invalid frame status.";
  1731. break;
  1732. case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
  1733. desc = "The task type is not supported.";
  1734. break;
  1735. case MPI_SCSITASKMGMT_RSP_TM_FAILED:
  1736. desc = "The requested task failed.";
  1737. break;
  1738. case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:
  1739. desc = "The task completed successfully.";
  1740. break;
  1741. case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:
  1742. desc = "The LUN request is invalid.";
  1743. break;
  1744. case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
  1745. desc = "The task is in the IOC queue and has not been sent to target.";
  1746. break;
  1747. default:
  1748. desc = "unknown";
  1749. break;
  1750. }
  1751. printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n",
  1752. ioc->name, response_code, desc);
  1753. }
  1754. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1755. /**
  1756. * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
  1757. * @ioc: Pointer to MPT_ADAPTER structure
  1758. * @mf: Pointer to SCSI task mgmt request frame
  1759. * @mr: Pointer to SCSI task mgmt reply frame
  1760. *
  1761. * This routine is called from mptbase.c::mpt_interrupt() at the completion
  1762. * of any SCSI task management request.
  1763. * This routine is registered with the MPT (base) driver at driver
  1764. * load/init time via the mpt_register() API call.
  1765. *
  1766. * Returns 1 indicating alloc'd request frame ptr should be freed.
  1767. **/
  1768. int
  1769. mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  1770. {
  1771. SCSITaskMgmtReply_t *pScsiTmReply;
  1772. SCSITaskMgmt_t *pScsiTmReq;
  1773. MPT_SCSI_HOST *hd;
  1774. unsigned long flags;
  1775. u16 iocstatus;
  1776. u8 tmType;
  1777. u32 termination_count;
  1778. dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
  1779. ioc->name, mf, mr));
  1780. if (!ioc->sh) {
  1781. dtmprintk((MYIOC_s_WARN_FMT
  1782. "TaskMgmt Complete: NULL Scsi Host Ptr\n", ioc->name));
  1783. return 1;
  1784. }
  1785. if (mr == NULL) {
  1786. dtmprintk((MYIOC_s_WARN_FMT
  1787. "ERROR! TaskMgmt Reply: NULL Request %p\n", ioc->name, mf));
  1788. return 1;
  1789. }
  1790. hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
  1791. pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
  1792. pScsiTmReq = (SCSITaskMgmt_t*)mf;
  1793. tmType = pScsiTmReq->TaskType;
  1794. iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  1795. termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
  1796. if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
  1797. pScsiTmReply->ResponseCode)
  1798. mptscsih_taskmgmt_response_code(ioc,
  1799. pScsiTmReply->ResponseCode);
  1800. DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply);
  1801. #if defined(MPT_DEBUG_REPLY) || defined(MPT_DEBUG_TM)
  1802. printk("%s: ha=%d [%d:%d:0] task_type=0x%02X "
  1803. "iocstatus=0x%04X\n\tloginfo=0x%08X response_code=0x%02X "
  1804. "term_cmnds=%d\n", __FUNCTION__, ioc->id, pScsiTmReply->Bus,
  1805. pScsiTmReply->TargetID, pScsiTmReq->TaskType,
  1806. le16_to_cpu(pScsiTmReply->IOCStatus),
  1807. le32_to_cpu(pScsiTmReply->IOCLogInfo),pScsiTmReply->ResponseCode,
  1808. le32_to_cpu(pScsiTmReply->TerminationCount));
  1809. #endif
  1810. if (!iocstatus) {
  1811. dtmprintk((MYIOC_s_WARN_FMT " TaskMgmt SUCCESS\n", ioc->name));
  1812. hd->abortSCpnt = NULL;
  1813. goto out;
  1814. }
  1815. /* Error? (anything non-zero?) */
  1816. /* clear flags and continue.
  1817. */
  1818. switch (tmType) {
  1819. case MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
  1820. if (termination_count == 1)
  1821. iocstatus = MPI_IOCSTATUS_SCSI_TASK_TERMINATED;
  1822. hd->abortSCpnt = NULL;
  1823. break;
  1824. case MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS:
  1825. /* If an internal command is present
  1826. * or the TM failed - reload the FW.
  1827. * FC FW may respond FAILED to an ABORT
  1828. */
  1829. if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED ||
  1830. hd->cmdPtr)
  1831. if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
  1832. printk((KERN_WARNING " Firmware Reload FAILED!!\n"));
  1833. break;
  1834. case MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
  1835. default:
  1836. break;
  1837. }
  1838. out:
  1839. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1840. hd->tmPending = 0;
  1841. hd->tmState = TM_STATE_NONE;
  1842. hd->tm_iocstatus = iocstatus;
  1843. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1844. return 1;
  1845. }
  1846. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1847. /*
  1848. * This is anyones guess quite frankly.
  1849. */
  1850. int
  1851. mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
  1852. sector_t capacity, int geom[])
  1853. {
  1854. int heads;
  1855. int sectors;
  1856. sector_t cylinders;
  1857. ulong dummy;
  1858. heads = 64;
  1859. sectors = 32;
  1860. dummy = heads * sectors;
  1861. cylinders = capacity;
  1862. sector_div(cylinders,dummy);
  1863. /*
  1864. * Handle extended translation size for logical drives
  1865. * > 1Gb
  1866. */
  1867. if ((ulong)capacity >= 0x200000) {
  1868. heads = 255;
  1869. sectors = 63;
  1870. dummy = heads * sectors;
  1871. cylinders = capacity;
  1872. sector_div(cylinders,dummy);
  1873. }
  1874. /* return result */
  1875. geom[0] = heads;
  1876. geom[1] = sectors;
  1877. geom[2] = cylinders;
  1878. dprintk((KERN_NOTICE
  1879. ": bios_param: Id=%i Lun=%i Channel=%i CHS=%i/%i/%i\n",
  1880. sdev->id, sdev->lun, sdev->channel, (int)cylinders, heads, sectors));
  1881. return 0;
  1882. }
  1883. /* Search IOC page 3 to determine if this is hidden physical disk
  1884. *
  1885. */
  1886. int
  1887. mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
  1888. {
  1889. struct inactive_raid_component_info *component_info;
  1890. int i;
  1891. int rc = 0;
  1892. if (!ioc->raid_data.pIocPg3)
  1893. goto out;
  1894. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  1895. if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
  1896. (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
  1897. rc = 1;
  1898. goto out;
  1899. }
  1900. }
  1901. /*
  1902. * Check inactive list for matching phys disks
  1903. */
  1904. if (list_empty(&ioc->raid_data.inactive_list))
  1905. goto out;
  1906. down(&ioc->raid_data.inactive_list_mutex);
  1907. list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
  1908. list) {
  1909. if ((component_info->d.PhysDiskID == id) &&
  1910. (component_info->d.PhysDiskBus == channel))
  1911. rc = 1;
  1912. }
  1913. up(&ioc->raid_data.inactive_list_mutex);
  1914. out:
  1915. return rc;
  1916. }
  1917. EXPORT_SYMBOL(mptscsih_is_phys_disk);
  1918. u8
  1919. mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
  1920. {
  1921. struct inactive_raid_component_info *component_info;
  1922. int i;
  1923. int rc = -ENXIO;
  1924. if (!ioc->raid_data.pIocPg3)
  1925. goto out;
  1926. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  1927. if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
  1928. (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
  1929. rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
  1930. goto out;
  1931. }
  1932. }
  1933. /*
  1934. * Check inactive list for matching phys disks
  1935. */
  1936. if (list_empty(&ioc->raid_data.inactive_list))
  1937. goto out;
  1938. down(&ioc->raid_data.inactive_list_mutex);
  1939. list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
  1940. list) {
  1941. if ((component_info->d.PhysDiskID == id) &&
  1942. (component_info->d.PhysDiskBus == channel))
  1943. rc = component_info->d.PhysDiskNum;
  1944. }
  1945. up(&ioc->raid_data.inactive_list_mutex);
  1946. out:
  1947. return rc;
  1948. }
  1949. EXPORT_SYMBOL(mptscsih_raid_id_to_num);
  1950. /*
  1951. * OS entry point to allow for host driver to free allocated memory
  1952. * Called if no device present or device being unloaded
  1953. */
  1954. void
  1955. mptscsih_slave_destroy(struct scsi_device *sdev)
  1956. {
  1957. struct Scsi_Host *host = sdev->host;
  1958. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  1959. VirtTarget *vtarget;
  1960. VirtDevice *vdevice;
  1961. struct scsi_target *starget;
  1962. starget = scsi_target(sdev);
  1963. vtarget = starget->hostdata;
  1964. vdevice = sdev->hostdata;
  1965. mptscsih_search_running_cmds(hd, vdevice);
  1966. vtarget->num_luns--;
  1967. mptscsih_synchronize_cache(hd, vdevice);
  1968. kfree(vdevice);
  1969. sdev->hostdata = NULL;
  1970. }
  1971. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1972. /*
  1973. * mptscsih_change_queue_depth - This function will set a devices queue depth
  1974. * @sdev: per scsi_device pointer
  1975. * @qdepth: requested queue depth
  1976. *
  1977. * Adding support for new 'change_queue_depth' api.
  1978. */
  1979. int
  1980. mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
  1981. {
  1982. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
  1983. VirtTarget *vtarget;
  1984. struct scsi_target *starget;
  1985. int max_depth;
  1986. int tagged;
  1987. starget = scsi_target(sdev);
  1988. vtarget = starget->hostdata;
  1989. if (hd->ioc->bus_type == SPI) {
  1990. if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
  1991. max_depth = 1;
  1992. else if (sdev->type == TYPE_DISK &&
  1993. vtarget->minSyncFactor <= MPT_ULTRA160)
  1994. max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
  1995. else
  1996. max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
  1997. } else
  1998. max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
  1999. if (qdepth > max_depth)
  2000. qdepth = max_depth;
  2001. if (qdepth == 1)
  2002. tagged = 0;
  2003. else
  2004. tagged = MSG_SIMPLE_TAG;
  2005. scsi_adjust_queue_depth(sdev, tagged, qdepth);
  2006. return sdev->queue_depth;
  2007. }
  2008. /*
  2009. * OS entry point to adjust the queue_depths on a per-device basis.
  2010. * Called once per device the bus scan. Use it to force the queue_depth
  2011. * member to 1 if a device does not support Q tags.
  2012. * Return non-zero if fails.
  2013. */
  2014. int
  2015. mptscsih_slave_configure(struct scsi_device *sdev)
  2016. {
  2017. struct Scsi_Host *sh = sdev->host;
  2018. VirtTarget *vtarget;
  2019. VirtDevice *vdevice;
  2020. struct scsi_target *starget;
  2021. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sh->hostdata;
  2022. starget = scsi_target(sdev);
  2023. vtarget = starget->hostdata;
  2024. vdevice = sdev->hostdata;
  2025. dsprintk((MYIOC_s_INFO_FMT
  2026. "device @ %p, channel=%d, id=%d, lun=%d\n",
  2027. hd->ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
  2028. if (hd->ioc->bus_type == SPI)
  2029. dsprintk((MYIOC_s_INFO_FMT
  2030. "sdtr %d wdtr %d ppr %d inq length=%d\n",
  2031. hd->ioc->name, sdev->sdtr, sdev->wdtr,
  2032. sdev->ppr, sdev->inquiry_len));
  2033. if (sdev->id > sh->max_id) {
  2034. /* error case, should never happen */
  2035. scsi_adjust_queue_depth(sdev, 0, 1);
  2036. goto slave_configure_exit;
  2037. }
  2038. vdevice->configured_lun = 1;
  2039. mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH);
  2040. dsprintk((MYIOC_s_INFO_FMT
  2041. "Queue depth=%d, tflags=%x\n",
  2042. hd->ioc->name, sdev->queue_depth, vtarget->tflags));
  2043. if (hd->ioc->bus_type == SPI)
  2044. dsprintk((MYIOC_s_INFO_FMT
  2045. "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
  2046. hd->ioc->name, vtarget->negoFlags, vtarget->maxOffset,
  2047. vtarget->minSyncFactor));
  2048. slave_configure_exit:
  2049. dsprintk((MYIOC_s_INFO_FMT
  2050. "tagged %d, simple %d, ordered %d\n",
  2051. hd->ioc->name,sdev->tagged_supported, sdev->simple_tags,
  2052. sdev->ordered_tags));
  2053. return 0;
  2054. }
  2055. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2056. /*
  2057. * Private routines...
  2058. */
  2059. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2060. /* Utility function to copy sense data from the scsi_cmnd buffer
  2061. * to the FC and SCSI target structures.
  2062. *
  2063. */
  2064. static void
  2065. mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
  2066. {
  2067. VirtDevice *vdev;
  2068. SCSIIORequest_t *pReq;
  2069. u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
  2070. /* Get target structure
  2071. */
  2072. pReq = (SCSIIORequest_t *) mf;
  2073. vdev = sc->device->hostdata;
  2074. if (sense_count) {
  2075. u8 *sense_data;
  2076. int req_index;
  2077. /* Copy the sense received into the scsi command block. */
  2078. req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2079. sense_data = ((u8 *)hd->ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
  2080. memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
  2081. /* Log SMART data (asc = 0x5D, non-IM case only) if required.
  2082. */
  2083. if ((hd->ioc->events) && (hd->ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
  2084. if ((sense_data[12] == 0x5D) && (vdev->vtarget->raidVolume == 0)) {
  2085. int idx;
  2086. MPT_ADAPTER *ioc = hd->ioc;
  2087. idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
  2088. ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
  2089. ioc->events[idx].eventContext = ioc->eventContext;
  2090. ioc->events[idx].data[0] = (pReq->LUN[1] << 24) ||
  2091. (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) ||
  2092. (sc->device->channel << 8) || sc->device->id;
  2093. ioc->events[idx].data[1] = (sense_data[13] << 8) || sense_data[12];
  2094. ioc->eventContext++;
  2095. if (hd->ioc->pcidev->vendor ==
  2096. PCI_VENDOR_ID_IBM) {
  2097. mptscsih_issue_sep_command(hd->ioc,
  2098. vdev->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
  2099. vdev->vtarget->tflags |=
  2100. MPT_TARGET_FLAGS_LED_ON;
  2101. }
  2102. }
  2103. }
  2104. } else {
  2105. dprintk((MYIOC_s_INFO_FMT "Hmmm... SenseData len=0! (?)\n",
  2106. hd->ioc->name));
  2107. }
  2108. }
  2109. static int
  2110. SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc)
  2111. {
  2112. MPT_SCSI_HOST *hd;
  2113. int i;
  2114. hd = (MPT_SCSI_HOST *) sc->device->host->hostdata;
  2115. for (i = 0; i < hd->ioc->req_depth; i++) {
  2116. if (hd->ScsiLookup[i] == sc) {
  2117. return i;
  2118. }
  2119. }
  2120. return -1;
  2121. }
  2122. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2123. int
  2124. mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  2125. {
  2126. MPT_SCSI_HOST *hd;
  2127. unsigned long flags;
  2128. int ii;
  2129. dtmprintk((KERN_WARNING MYNAM
  2130. ": IOC %s_reset routed to SCSI host driver!\n",
  2131. reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
  2132. reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
  2133. /* If a FW reload request arrives after base installed but
  2134. * before all scsi hosts have been attached, then an alt_ioc
  2135. * may have a NULL sh pointer.
  2136. */
  2137. if ((ioc->sh == NULL) || (ioc->sh->hostdata == NULL))
  2138. return 0;
  2139. else
  2140. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  2141. if (reset_phase == MPT_IOC_SETUP_RESET) {
  2142. dtmprintk((MYIOC_s_WARN_FMT "Setup-Diag Reset\n", ioc->name));
  2143. /* Clean Up:
  2144. * 1. Set Hard Reset Pending Flag
  2145. * All new commands go to doneQ
  2146. */
  2147. hd->resetPending = 1;
  2148. } else if (reset_phase == MPT_IOC_PRE_RESET) {
  2149. dtmprintk((MYIOC_s_WARN_FMT "Pre-Diag Reset\n", ioc->name));
  2150. /* 2. Flush running commands
  2151. * Clean ScsiLookup (and associated memory)
  2152. * AND clean mytaskQ
  2153. */
  2154. /* 2b. Reply to OS all known outstanding I/O commands.
  2155. */
  2156. mptscsih_flush_running_cmds(hd);
  2157. /* 2c. If there was an internal command that
  2158. * has not completed, configuration or io request,
  2159. * free these resources.
  2160. */
  2161. if (hd->cmdPtr) {
  2162. del_timer(&hd->timer);
  2163. mpt_free_msg_frame(ioc, hd->cmdPtr);
  2164. }
  2165. dtmprintk((MYIOC_s_WARN_FMT "Pre-Reset complete.\n", ioc->name));
  2166. } else {
  2167. dtmprintk((MYIOC_s_WARN_FMT "Post-Diag Reset\n", ioc->name));
  2168. /* Once a FW reload begins, all new OS commands are
  2169. * redirected to the doneQ w/ a reset status.
  2170. * Init all control structures.
  2171. */
  2172. /* ScsiLookup initialization
  2173. */
  2174. for (ii=0; ii < hd->ioc->req_depth; ii++)
  2175. hd->ScsiLookup[ii] = NULL;
  2176. /* 2. Chain Buffer initialization
  2177. */
  2178. /* 4. Renegotiate to all devices, if SPI
  2179. */
  2180. /* 5. Enable new commands to be posted
  2181. */
  2182. spin_lock_irqsave(&ioc->FreeQlock, flags);
  2183. hd->tmPending = 0;
  2184. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  2185. hd->resetPending = 0;
  2186. hd->tmState = TM_STATE_NONE;
  2187. /* 6. If there was an internal command,
  2188. * wake this process up.
  2189. */
  2190. if (hd->cmdPtr) {
  2191. /*
  2192. * Wake up the original calling thread
  2193. */
  2194. hd->pLocal = &hd->localReply;
  2195. hd->pLocal->completion = MPT_SCANDV_DID_RESET;
  2196. hd->scandv_wait_done = 1;
  2197. wake_up(&hd->scandv_waitq);
  2198. hd->cmdPtr = NULL;
  2199. }
  2200. dtmprintk((MYIOC_s_WARN_FMT "Post-Reset complete.\n", ioc->name));
  2201. }
  2202. return 1; /* currently means nothing really */
  2203. }
  2204. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2205. int
  2206. mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  2207. {
  2208. MPT_SCSI_HOST *hd;
  2209. u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
  2210. devtverboseprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
  2211. ioc->name, event));
  2212. if (ioc->sh == NULL ||
  2213. ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL))
  2214. return 1;
  2215. switch (event) {
  2216. case MPI_EVENT_UNIT_ATTENTION: /* 03 */
  2217. /* FIXME! */
  2218. break;
  2219. case MPI_EVENT_IOC_BUS_RESET: /* 04 */
  2220. case MPI_EVENT_EXT_BUS_RESET: /* 05 */
  2221. if (hd && (ioc->bus_type == SPI) && (hd->soft_resets < -1))
  2222. hd->soft_resets++;
  2223. break;
  2224. case MPI_EVENT_LOGOUT: /* 09 */
  2225. /* FIXME! */
  2226. break;
  2227. case MPI_EVENT_RESCAN: /* 06 */
  2228. break;
  2229. /*
  2230. * CHECKME! Don't think we need to do
  2231. * anything for these, but...
  2232. */
  2233. case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
  2234. case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
  2235. /*
  2236. * CHECKME! Falling thru...
  2237. */
  2238. break;
  2239. case MPI_EVENT_INTEGRATED_RAID: /* 0B */
  2240. break;
  2241. case MPI_EVENT_NONE: /* 00 */
  2242. case MPI_EVENT_LOG_DATA: /* 01 */
  2243. case MPI_EVENT_STATE_CHANGE: /* 02 */
  2244. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  2245. default:
  2246. dprintk((KERN_INFO " Ignoring event (=%02Xh)\n", event));
  2247. break;
  2248. }
  2249. return 1; /* currently means nothing really */
  2250. }
  2251. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2252. /*
  2253. * Bus Scan and Domain Validation functionality ...
  2254. */
  2255. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2256. /*
  2257. * mptscsih_scandv_complete - Scan and DV callback routine registered
  2258. * to Fustion MPT (base) driver.
  2259. *
  2260. * @ioc: Pointer to MPT_ADAPTER structure
  2261. * @mf: Pointer to original MPT request frame
  2262. * @mr: Pointer to MPT reply frame (NULL if TurboReply)
  2263. *
  2264. * This routine is called from mpt.c::mpt_interrupt() at the completion
  2265. * of any SCSI IO request.
  2266. * This routine is registered with the Fusion MPT (base) driver at driver
  2267. * load/init time via the mpt_register() API call.
  2268. *
  2269. * Returns 1 indicating alloc'd request frame ptr should be freed.
  2270. *
  2271. * Remark: Sets a completion code and (possibly) saves sense data
  2272. * in the IOC member localReply structure.
  2273. * Used ONLY for DV and other internal commands.
  2274. */
  2275. int
  2276. mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  2277. {
  2278. MPT_SCSI_HOST *hd;
  2279. SCSIIORequest_t *pReq;
  2280. int completionCode;
  2281. u16 req_idx;
  2282. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  2283. if ((mf == NULL) ||
  2284. (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
  2285. printk(MYIOC_s_ERR_FMT
  2286. "ScanDvComplete, %s req frame ptr! (=%p)\n",
  2287. ioc->name, mf?"BAD":"NULL", (void *) mf);
  2288. goto wakeup;
  2289. }
  2290. del_timer(&hd->timer);
  2291. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2292. hd->ScsiLookup[req_idx] = NULL;
  2293. pReq = (SCSIIORequest_t *) mf;
  2294. if (mf != hd->cmdPtr) {
  2295. printk(MYIOC_s_WARN_FMT "ScanDvComplete (mf=%p, cmdPtr=%p, idx=%d)\n",
  2296. hd->ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx);
  2297. }
  2298. hd->cmdPtr = NULL;
  2299. ddvprintk((MYIOC_s_INFO_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n",
  2300. hd->ioc->name, mf, mr, req_idx));
  2301. hd->pLocal = &hd->localReply;
  2302. hd->pLocal->scsiStatus = 0;
  2303. /* If target struct exists, clear sense valid flag.
  2304. */
  2305. if (mr == NULL) {
  2306. completionCode = MPT_SCANDV_GOOD;
  2307. } else {
  2308. SCSIIOReply_t *pReply;
  2309. u16 status;
  2310. u8 scsi_status;
  2311. pReply = (SCSIIOReply_t *) mr;
  2312. status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  2313. scsi_status = pReply->SCSIStatus;
  2314. ddvtprintk((KERN_NOTICE " IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh, IOCLogInfo=%08xh\n",
  2315. status, pReply->SCSIState, scsi_status,
  2316. le32_to_cpu(pReply->IOCLogInfo)));
  2317. switch(status) {
  2318. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  2319. completionCode = MPT_SCANDV_SELECTION_TIMEOUT;
  2320. break;
  2321. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  2322. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  2323. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  2324. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  2325. completionCode = MPT_SCANDV_DID_RESET;
  2326. break;
  2327. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  2328. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  2329. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  2330. if (pReply->Function == MPI_FUNCTION_CONFIG) {
  2331. ConfigReply_t *pr = (ConfigReply_t *)mr;
  2332. completionCode = MPT_SCANDV_GOOD;
  2333. hd->pLocal->header.PageVersion = pr->Header.PageVersion;
  2334. hd->pLocal->header.PageLength = pr->Header.PageLength;
  2335. hd->pLocal->header.PageNumber = pr->Header.PageNumber;
  2336. hd->pLocal->header.PageType = pr->Header.PageType;
  2337. } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
  2338. /* If the RAID Volume request is successful,
  2339. * return GOOD, else indicate that
  2340. * some type of error occurred.
  2341. */
  2342. MpiRaidActionReply_t *pr = (MpiRaidActionReply_t *)mr;
  2343. if (le16_to_cpu(pr->ActionStatus) == MPI_RAID_ACTION_ASTATUS_SUCCESS)
  2344. completionCode = MPT_SCANDV_GOOD;
  2345. else
  2346. completionCode = MPT_SCANDV_SOME_ERROR;
  2347. memcpy(hd->pLocal->sense, pr, sizeof(hd->pLocal->sense));
  2348. } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  2349. u8 *sense_data;
  2350. int sz;
  2351. /* save sense data in global structure
  2352. */
  2353. completionCode = MPT_SCANDV_SENSE;
  2354. hd->pLocal->scsiStatus = scsi_status;
  2355. sense_data = ((u8 *)hd->ioc->sense_buf_pool +
  2356. (req_idx * MPT_SENSE_BUFFER_ALLOC));
  2357. sz = min_t(int, pReq->SenseBufferLength,
  2358. SCSI_STD_SENSE_BYTES);
  2359. memcpy(hd->pLocal->sense, sense_data, sz);
  2360. ddvprintk((KERN_NOTICE " Check Condition, sense ptr %p\n",
  2361. sense_data));
  2362. } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
  2363. if (pReq->CDB[0] == INQUIRY)
  2364. completionCode = MPT_SCANDV_ISSUE_SENSE;
  2365. else
  2366. completionCode = MPT_SCANDV_DID_RESET;
  2367. }
  2368. else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
  2369. completionCode = MPT_SCANDV_DID_RESET;
  2370. else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  2371. completionCode = MPT_SCANDV_DID_RESET;
  2372. else {
  2373. completionCode = MPT_SCANDV_GOOD;
  2374. hd->pLocal->scsiStatus = scsi_status;
  2375. }
  2376. break;
  2377. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  2378. if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  2379. completionCode = MPT_SCANDV_DID_RESET;
  2380. else
  2381. completionCode = MPT_SCANDV_SOME_ERROR;
  2382. break;
  2383. default:
  2384. completionCode = MPT_SCANDV_SOME_ERROR;
  2385. break;
  2386. } /* switch(status) */
  2387. ddvtprintk((KERN_NOTICE " completionCode set to %08xh\n",
  2388. completionCode));
  2389. } /* end of address reply case */
  2390. hd->pLocal->completion = completionCode;
  2391. /* MF and RF are freed in mpt_interrupt
  2392. */
  2393. wakeup:
  2394. /* Free Chain buffers (will never chain) in scan or dv */
  2395. //mptscsih_freeChainBuffers(ioc, req_idx);
  2396. /*
  2397. * Wake up the original calling thread
  2398. */
  2399. hd->scandv_wait_done = 1;
  2400. wake_up(&hd->scandv_waitq);
  2401. return 1;
  2402. }
  2403. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2404. /* mptscsih_timer_expired - Call back for timer process.
  2405. * Used only for dv functionality.
  2406. * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
  2407. *
  2408. */
  2409. void
  2410. mptscsih_timer_expired(unsigned long data)
  2411. {
  2412. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data;
  2413. ddvprintk((MYIOC_s_WARN_FMT "Timer Expired! Cmd %p\n", hd->ioc->name, hd->cmdPtr));
  2414. if (hd->cmdPtr) {
  2415. MPIHeader_t *cmd = (MPIHeader_t *)hd->cmdPtr;
  2416. if (cmd->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
  2417. /* Desire to issue a task management request here.
  2418. * TM requests MUST be single threaded.
  2419. * If old eh code and no TM current, issue request.
  2420. * If new eh code, do nothing. Wait for OS cmd timeout
  2421. * for bus reset.
  2422. */
  2423. ddvtprintk((MYIOC_s_NOTE_FMT "DV Cmd Timeout: NoOp\n", hd->ioc->name));
  2424. } else {
  2425. /* Perform a FW reload */
  2426. if (mpt_HardResetHandler(hd->ioc, NO_SLEEP) < 0) {
  2427. printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", hd->ioc->name);
  2428. }
  2429. }
  2430. } else {
  2431. /* This should NEVER happen */
  2432. printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", hd->ioc->name);
  2433. }
  2434. /* No more processing.
  2435. * TM call will generate an interrupt for SCSI TM Management.
  2436. * The FW will reply to all outstanding commands, callback will finish cleanup.
  2437. * Hard reset clean-up will free all resources.
  2438. */
  2439. ddvprintk((MYIOC_s_WARN_FMT "Timer Expired Complete!\n", hd->ioc->name));
  2440. return;
  2441. }
  2442. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2443. /**
  2444. * mptscsih_do_cmd - Do internal command.
  2445. * @hd: MPT_SCSI_HOST pointer
  2446. * @io: INTERNAL_CMD pointer.
  2447. *
  2448. * Issue the specified internally generated command and do command
  2449. * specific cleanup. For bus scan / DV only.
  2450. * NOTES: If command is Inquiry and status is good,
  2451. * initialize a target structure, save the data
  2452. *
  2453. * Remark: Single threaded access only.
  2454. *
  2455. * Return:
  2456. * < 0 if an illegal command or no resources
  2457. *
  2458. * 0 if good
  2459. *
  2460. * > 0 if command complete but some type of completion error.
  2461. */
  2462. static int
  2463. mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
  2464. {
  2465. MPT_FRAME_HDR *mf;
  2466. SCSIIORequest_t *pScsiReq;
  2467. SCSIIORequest_t ReqCopy;
  2468. int my_idx, ii, dir;
  2469. int rc, cmdTimeout;
  2470. int in_isr;
  2471. char cmdLen;
  2472. char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  2473. char cmd = io->cmd;
  2474. in_isr = in_interrupt();
  2475. if (in_isr) {
  2476. dprintk((MYIOC_s_WARN_FMT "Internal SCSI IO request not allowed in ISR context!\n",
  2477. hd->ioc->name));
  2478. return -EPERM;
  2479. }
  2480. /* Set command specific information
  2481. */
  2482. switch (cmd) {
  2483. case INQUIRY:
  2484. cmdLen = 6;
  2485. dir = MPI_SCSIIO_CONTROL_READ;
  2486. CDB[0] = cmd;
  2487. CDB[4] = io->size;
  2488. cmdTimeout = 10;
  2489. break;
  2490. case TEST_UNIT_READY:
  2491. cmdLen = 6;
  2492. dir = MPI_SCSIIO_CONTROL_READ;
  2493. cmdTimeout = 10;
  2494. break;
  2495. case START_STOP:
  2496. cmdLen = 6;
  2497. dir = MPI_SCSIIO_CONTROL_READ;
  2498. CDB[0] = cmd;
  2499. CDB[4] = 1; /*Spin up the disk */
  2500. cmdTimeout = 15;
  2501. break;
  2502. case REQUEST_SENSE:
  2503. cmdLen = 6;
  2504. CDB[0] = cmd;
  2505. CDB[4] = io->size;
  2506. dir = MPI_SCSIIO_CONTROL_READ;
  2507. cmdTimeout = 10;
  2508. break;
  2509. case READ_BUFFER:
  2510. cmdLen = 10;
  2511. dir = MPI_SCSIIO_CONTROL_READ;
  2512. CDB[0] = cmd;
  2513. if (io->flags & MPT_ICFLAG_ECHO) {
  2514. CDB[1] = 0x0A;
  2515. } else {
  2516. CDB[1] = 0x02;
  2517. }
  2518. if (io->flags & MPT_ICFLAG_BUF_CAP) {
  2519. CDB[1] |= 0x01;
  2520. }
  2521. CDB[6] = (io->size >> 16) & 0xFF;
  2522. CDB[7] = (io->size >> 8) & 0xFF;
  2523. CDB[8] = io->size & 0xFF;
  2524. cmdTimeout = 10;
  2525. break;
  2526. case WRITE_BUFFER:
  2527. cmdLen = 10;
  2528. dir = MPI_SCSIIO_CONTROL_WRITE;
  2529. CDB[0] = cmd;
  2530. if (io->flags & MPT_ICFLAG_ECHO) {
  2531. CDB[1] = 0x0A;
  2532. } else {
  2533. CDB[1] = 0x02;
  2534. }
  2535. CDB[6] = (io->size >> 16) & 0xFF;
  2536. CDB[7] = (io->size >> 8) & 0xFF;
  2537. CDB[8] = io->size & 0xFF;
  2538. cmdTimeout = 10;
  2539. break;
  2540. case RESERVE:
  2541. cmdLen = 6;
  2542. dir = MPI_SCSIIO_CONTROL_READ;
  2543. CDB[0] = cmd;
  2544. cmdTimeout = 10;
  2545. break;
  2546. case RELEASE:
  2547. cmdLen = 6;
  2548. dir = MPI_SCSIIO_CONTROL_READ;
  2549. CDB[0] = cmd;
  2550. cmdTimeout = 10;
  2551. break;
  2552. case SYNCHRONIZE_CACHE:
  2553. cmdLen = 10;
  2554. dir = MPI_SCSIIO_CONTROL_READ;
  2555. CDB[0] = cmd;
  2556. // CDB[1] = 0x02; /* set immediate bit */
  2557. cmdTimeout = 10;
  2558. break;
  2559. default:
  2560. /* Error Case */
  2561. return -EFAULT;
  2562. }
  2563. /* Get and Populate a free Frame
  2564. */
  2565. if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
  2566. ddvprintk((MYIOC_s_WARN_FMT "No msg frames!\n",
  2567. hd->ioc->name));
  2568. return -EBUSY;
  2569. }
  2570. pScsiReq = (SCSIIORequest_t *) mf;
  2571. /* Get the request index */
  2572. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2573. ADD_INDEX_LOG(my_idx); /* for debug */
  2574. if (io->flags & MPT_ICFLAG_PHYS_DISK) {
  2575. pScsiReq->TargetID = io->physDiskNum;
  2576. pScsiReq->Bus = 0;
  2577. pScsiReq->ChainOffset = 0;
  2578. pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  2579. } else {
  2580. pScsiReq->TargetID = io->id;
  2581. pScsiReq->Bus = io->channel;
  2582. pScsiReq->ChainOffset = 0;
  2583. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  2584. }
  2585. pScsiReq->CDBLength = cmdLen;
  2586. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  2587. pScsiReq->Reserved = 0;
  2588. pScsiReq->MsgFlags = mpt_msg_flags();
  2589. /* MsgContext set in mpt_get_msg_fram call */
  2590. int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);
  2591. if (io->flags & MPT_ICFLAG_TAGGED_CMD)
  2592. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
  2593. else
  2594. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  2595. if (cmd == REQUEST_SENSE) {
  2596. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  2597. ddvprintk((MYIOC_s_INFO_FMT "Untagged! 0x%2x\n",
  2598. hd->ioc->name, cmd));
  2599. }
  2600. for (ii=0; ii < 16; ii++)
  2601. pScsiReq->CDB[ii] = CDB[ii];
  2602. pScsiReq->DataLength = cpu_to_le32(io->size);
  2603. pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
  2604. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  2605. ddvprintk((MYIOC_s_INFO_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
  2606. hd->ioc->name, cmd, io->channel, io->id, io->lun));
  2607. if (dir == MPI_SCSIIO_CONTROL_READ) {
  2608. mpt_add_sge((char *) &pScsiReq->SGL,
  2609. MPT_SGE_FLAGS_SSIMPLE_READ | io->size,
  2610. io->data_dma);
  2611. } else {
  2612. mpt_add_sge((char *) &pScsiReq->SGL,
  2613. MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size,
  2614. io->data_dma);
  2615. }
  2616. /* The ISR will free the request frame, but we need
  2617. * the information to initialize the target. Duplicate.
  2618. */
  2619. memcpy(&ReqCopy, pScsiReq, sizeof(SCSIIORequest_t));
  2620. /* Issue this command after:
  2621. * finish init
  2622. * add timer
  2623. * Wait until the reply has been received
  2624. * ScsiScanDvCtx callback function will
  2625. * set hd->pLocal;
  2626. * set scandv_wait_done and call wake_up
  2627. */
  2628. hd->pLocal = NULL;
  2629. hd->timer.expires = jiffies + HZ*cmdTimeout;
  2630. hd->scandv_wait_done = 0;
  2631. /* Save cmd pointer, for resource free if timeout or
  2632. * FW reload occurs
  2633. */
  2634. hd->cmdPtr = mf;
  2635. add_timer(&hd->timer);
  2636. mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
  2637. wait_event(hd->scandv_waitq, hd->scandv_wait_done);
  2638. if (hd->pLocal) {
  2639. rc = hd->pLocal->completion;
  2640. hd->pLocal->skip = 0;
  2641. /* Always set fatal error codes in some cases.
  2642. */
  2643. if (rc == MPT_SCANDV_SELECTION_TIMEOUT)
  2644. rc = -ENXIO;
  2645. else if (rc == MPT_SCANDV_SOME_ERROR)
  2646. rc = -rc;
  2647. } else {
  2648. rc = -EFAULT;
  2649. /* This should never happen. */
  2650. ddvprintk((MYIOC_s_INFO_FMT "_do_cmd: Null pLocal!!!\n",
  2651. hd->ioc->name));
  2652. }
  2653. return rc;
  2654. }
  2655. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2656. /**
  2657. * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
  2658. * @hd: Pointer to a SCSI HOST structure
  2659. * @vdevice: virtual target device
  2660. *
  2661. * Uses the ISR, but with special processing.
  2662. * MUST be single-threaded.
  2663. *
  2664. */
  2665. static void
  2666. mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
  2667. {
  2668. INTERNAL_CMD iocmd;
  2669. /* Following parameters will not change
  2670. * in this routine.
  2671. */
  2672. iocmd.cmd = SYNCHRONIZE_CACHE;
  2673. iocmd.flags = 0;
  2674. iocmd.physDiskNum = -1;
  2675. iocmd.data = NULL;
  2676. iocmd.data_dma = -1;
  2677. iocmd.size = 0;
  2678. iocmd.rsvd = iocmd.rsvd2 = 0;
  2679. iocmd.channel = vdevice->vtarget->channel;
  2680. iocmd.id = vdevice->vtarget->id;
  2681. iocmd.lun = vdevice->lun;
  2682. if ((vdevice->vtarget->type == TYPE_DISK) &&
  2683. (vdevice->configured_lun))
  2684. mptscsih_do_cmd(hd, &iocmd);
  2685. }
  2686. EXPORT_SYMBOL(mptscsih_remove);
  2687. EXPORT_SYMBOL(mptscsih_shutdown);
  2688. #ifdef CONFIG_PM
  2689. EXPORT_SYMBOL(mptscsih_suspend);
  2690. EXPORT_SYMBOL(mptscsih_resume);
  2691. #endif
  2692. EXPORT_SYMBOL(mptscsih_proc_info);
  2693. EXPORT_SYMBOL(mptscsih_info);
  2694. EXPORT_SYMBOL(mptscsih_qcmd);
  2695. EXPORT_SYMBOL(mptscsih_slave_destroy);
  2696. EXPORT_SYMBOL(mptscsih_slave_configure);
  2697. EXPORT_SYMBOL(mptscsih_abort);
  2698. EXPORT_SYMBOL(mptscsih_dev_reset);
  2699. EXPORT_SYMBOL(mptscsih_bus_reset);
  2700. EXPORT_SYMBOL(mptscsih_host_reset);
  2701. EXPORT_SYMBOL(mptscsih_bios_param);
  2702. EXPORT_SYMBOL(mptscsih_io_done);
  2703. EXPORT_SYMBOL(mptscsih_taskmgmt_complete);
  2704. EXPORT_SYMBOL(mptscsih_scandv_complete);
  2705. EXPORT_SYMBOL(mptscsih_event_process);
  2706. EXPORT_SYMBOL(mptscsih_ioc_reset);
  2707. EXPORT_SYMBOL(mptscsih_change_queue_depth);
  2708. EXPORT_SYMBOL(mptscsih_timer_expired);
  2709. EXPORT_SYMBOL(mptscsih_TMHandler);
  2710. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/