mptscsih.c 93 KB

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