mptscsih.c 87 KB

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