mptscsih.c 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369
  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. break;
  704. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  705. if (ioc->bus_type == FC)
  706. sc->result = DID_ERROR << 16;
  707. else
  708. sc->result = DID_RESET << 16;
  709. break;
  710. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  711. scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
  712. if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
  713. sc->result=DID_SOFT_ERROR << 16;
  714. else /* Sufficient data transfer occurred */
  715. sc->result = (DID_OK << 16) | scsi_status;
  716. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  717. "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
  718. ioc->name, sc->result, sc->device->channel, sc->device->id));
  719. break;
  720. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  721. /*
  722. * Do upfront check for valid SenseData and give it
  723. * precedence!
  724. */
  725. sc->result = (DID_OK << 16) | scsi_status;
  726. if (!(scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
  727. /*
  728. * For an Errata on LSI53C1030
  729. * When the length of request data
  730. * and transfer data are different
  731. * with result of command (READ or VERIFY),
  732. * DID_SOFT_ERROR is set.
  733. */
  734. if (ioc->bus_type == SPI) {
  735. if ((pScsiReq->CDB[0] == READ_6 && ((pScsiReq->CDB[1] & 0x02) == 0)) ||
  736. pScsiReq->CDB[0] == READ_10 ||
  737. pScsiReq->CDB[0] == READ_12 ||
  738. (pScsiReq->CDB[0] == READ_16 &&
  739. ((pScsiReq->CDB[1] & 0x02) == 0)) ||
  740. pScsiReq->CDB[0] == VERIFY ||
  741. pScsiReq->CDB[0] == VERIFY_16) {
  742. if (scsi_bufflen(sc) !=
  743. xfer_cnt) {
  744. sc->result =
  745. DID_SOFT_ERROR << 16;
  746. printk(KERN_WARNING "Errata"
  747. "on LSI53C1030 occurred."
  748. "sc->req_bufflen=0x%02x,"
  749. "xfer_cnt=0x%02x\n",
  750. scsi_bufflen(sc),
  751. xfer_cnt);
  752. }
  753. }
  754. }
  755. if (xfer_cnt < sc->underflow) {
  756. if (scsi_status == SAM_STAT_BUSY)
  757. sc->result = SAM_STAT_BUSY;
  758. else
  759. sc->result = DID_SOFT_ERROR << 16;
  760. }
  761. if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
  762. /* What to do?
  763. */
  764. sc->result = DID_SOFT_ERROR << 16;
  765. }
  766. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  767. /* Not real sure here either... */
  768. sc->result = DID_RESET << 16;
  769. }
  770. }
  771. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  772. " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
  773. ioc->name, sc->underflow));
  774. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  775. " ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));
  776. /* Report Queue Full
  777. */
  778. if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
  779. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  780. break;
  781. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  782. scsi_set_resid(sc, 0);
  783. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  784. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  785. sc->result = (DID_OK << 16) | scsi_status;
  786. if (scsi_state == 0) {
  787. ;
  788. } else if (scsi_state &
  789. MPI_SCSI_STATE_AUTOSENSE_VALID) {
  790. /*
  791. * For potential trouble on LSI53C1030.
  792. * (date:2007.xx.)
  793. * It is checked whether the length of
  794. * request data is equal to
  795. * the length of transfer and residual.
  796. * MEDIUM_ERROR is set by incorrect data.
  797. */
  798. if ((ioc->bus_type == SPI) &&
  799. (sc->sense_buffer[2] & 0x20)) {
  800. u32 difftransfer;
  801. difftransfer =
  802. sc->sense_buffer[3] << 24 |
  803. sc->sense_buffer[4] << 16 |
  804. sc->sense_buffer[5] << 8 |
  805. sc->sense_buffer[6];
  806. if (((sc->sense_buffer[3] & 0x80) ==
  807. 0x80) && (scsi_bufflen(sc)
  808. != xfer_cnt)) {
  809. sc->sense_buffer[2] =
  810. MEDIUM_ERROR;
  811. sc->sense_buffer[12] = 0xff;
  812. sc->sense_buffer[13] = 0xff;
  813. printk(KERN_WARNING"Errata"
  814. "on LSI53C1030 occurred."
  815. "sc->req_bufflen=0x%02x,"
  816. "xfer_cnt=0x%02x\n" ,
  817. scsi_bufflen(sc),
  818. xfer_cnt);
  819. }
  820. if (((sc->sense_buffer[3] & 0x80)
  821. != 0x80) &&
  822. (scsi_bufflen(sc) !=
  823. xfer_cnt + difftransfer)) {
  824. sc->sense_buffer[2] =
  825. MEDIUM_ERROR;
  826. sc->sense_buffer[12] = 0xff;
  827. sc->sense_buffer[13] = 0xff;
  828. printk(KERN_WARNING
  829. "Errata on LSI53C1030 occurred"
  830. "sc->req_bufflen=0x%02x,"
  831. " xfer_cnt=0x%02x,"
  832. "difftransfer=0x%02x\n",
  833. scsi_bufflen(sc),
  834. xfer_cnt,
  835. difftransfer);
  836. }
  837. }
  838. /*
  839. * If running against circa 200003dd 909 MPT f/w,
  840. * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
  841. * (QUEUE_FULL) returned from device! --> get 0x0000?128
  842. * and with SenseBytes set to 0.
  843. */
  844. if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
  845. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  846. }
  847. else if (scsi_state &
  848. (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
  849. ) {
  850. /*
  851. * What to do?
  852. */
  853. sc->result = DID_SOFT_ERROR << 16;
  854. }
  855. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  856. /* Not real sure here either... */
  857. sc->result = DID_RESET << 16;
  858. }
  859. else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
  860. /* Device Inq. data indicates that it supports
  861. * QTags, but rejects QTag messages.
  862. * This command completed OK.
  863. *
  864. * Not real sure here either so do nothing... */
  865. }
  866. if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
  867. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  868. /* Add handling of:
  869. * Reservation Conflict, Busy,
  870. * Command Terminated, CHECK
  871. */
  872. break;
  873. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  874. sc->result = DID_SOFT_ERROR << 16;
  875. break;
  876. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  877. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  878. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  879. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  880. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  881. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  882. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  883. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  884. default:
  885. /*
  886. * What to do?
  887. */
  888. sc->result = DID_SOFT_ERROR << 16;
  889. break;
  890. } /* switch(status) */
  891. #ifdef CONFIG_FUSION_LOGGING
  892. if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY))
  893. mptscsih_info_scsiio(ioc, sc, pScsiReply);
  894. #endif
  895. } /* end of address reply case */
  896. out:
  897. /* Unmap the DMA buffers, if any. */
  898. scsi_dma_unmap(sc);
  899. sc->scsi_done(sc); /* Issue the command callback */
  900. /* Free Chain buffers */
  901. mptscsih_freeChainBuffers(ioc, req_idx);
  902. return 1;
  903. }
  904. /*
  905. * mptscsih_flush_running_cmds - For each command found, search
  906. * Scsi_Host instance taskQ and reply to OS.
  907. * Called only if recovering from a FW reload.
  908. * @hd: Pointer to a SCSI HOST structure
  909. *
  910. * Returns: None.
  911. *
  912. * Must be called while new I/Os are being queued.
  913. */
  914. void
  915. mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
  916. {
  917. MPT_ADAPTER *ioc = hd->ioc;
  918. struct scsi_cmnd *sc;
  919. SCSIIORequest_t *mf = NULL;
  920. int ii;
  921. int channel, id;
  922. for (ii= 0; ii < ioc->req_depth; ii++) {
  923. sc = mptscsih_getclear_scsi_lookup(ioc, ii);
  924. if (!sc)
  925. continue;
  926. mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
  927. if (!mf)
  928. continue;
  929. channel = mf->Bus;
  930. id = mf->TargetID;
  931. mptscsih_freeChainBuffers(ioc, ii);
  932. mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
  933. if ((unsigned char *)mf != sc->host_scribble)
  934. continue;
  935. scsi_dma_unmap(sc);
  936. sc->result = DID_RESET << 16;
  937. sc->host_scribble = NULL;
  938. dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT
  939. "completing cmds: fw_channel %d, fw_id %d, sc=%p, mf = %p, "
  940. "idx=%x\n", ioc->name, channel, id, sc, mf, ii));
  941. sc->scsi_done(sc);
  942. }
  943. }
  944. EXPORT_SYMBOL(mptscsih_flush_running_cmds);
  945. /*
  946. * mptscsih_search_running_cmds - Delete any commands associated
  947. * with the specified target and lun. Function called only
  948. * when a lun is disable by mid-layer.
  949. * Do NOT access the referenced scsi_cmnd structure or
  950. * members. Will cause either a paging or NULL ptr error.
  951. * (BUT, BUT, BUT, the code does reference it! - mdr)
  952. * @hd: Pointer to a SCSI HOST structure
  953. * @vdevice: per device private data
  954. *
  955. * Returns: None.
  956. *
  957. * Called from slave_destroy.
  958. */
  959. static void
  960. mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
  961. {
  962. SCSIIORequest_t *mf = NULL;
  963. int ii;
  964. struct scsi_cmnd *sc;
  965. struct scsi_lun lun;
  966. MPT_ADAPTER *ioc = hd->ioc;
  967. unsigned long flags;
  968. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  969. for (ii = 0; ii < ioc->req_depth; ii++) {
  970. if ((sc = ioc->ScsiLookup[ii]) != NULL) {
  971. mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
  972. if (mf == NULL)
  973. continue;
  974. /* If the device is a hidden raid component, then its
  975. * expected that the mf->function will be RAID_SCSI_IO
  976. */
  977. if (vdevice->vtarget->tflags &
  978. MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function !=
  979. MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
  980. continue;
  981. int_to_scsilun(vdevice->lun, &lun);
  982. if ((mf->Bus != vdevice->vtarget->channel) ||
  983. (mf->TargetID != vdevice->vtarget->id) ||
  984. memcmp(lun.scsi_lun, mf->LUN, 8))
  985. continue;
  986. if ((unsigned char *)mf != sc->host_scribble)
  987. continue;
  988. ioc->ScsiLookup[ii] = NULL;
  989. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  990. mptscsih_freeChainBuffers(ioc, ii);
  991. mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
  992. scsi_dma_unmap(sc);
  993. sc->host_scribble = NULL;
  994. sc->result = DID_NO_CONNECT << 16;
  995. dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device,
  996. MYIOC_s_FMT "completing cmds: fw_channel %d, "
  997. "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name,
  998. vdevice->vtarget->channel, vdevice->vtarget->id,
  999. sc, mf, ii));
  1000. sc->scsi_done(sc);
  1001. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1002. }
  1003. }
  1004. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1005. return;
  1006. }
  1007. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1008. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1009. /*
  1010. * mptscsih_report_queue_full - Report QUEUE_FULL status returned
  1011. * from a SCSI target device.
  1012. * @sc: Pointer to scsi_cmnd structure
  1013. * @pScsiReply: Pointer to SCSIIOReply_t
  1014. * @pScsiReq: Pointer to original SCSI request
  1015. *
  1016. * This routine periodically reports QUEUE_FULL status returned from a
  1017. * SCSI target device. It reports this to the console via kernel
  1018. * printk() API call, not more than once every 10 seconds.
  1019. */
  1020. static void
  1021. mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
  1022. {
  1023. long time = jiffies;
  1024. MPT_SCSI_HOST *hd;
  1025. MPT_ADAPTER *ioc;
  1026. if (sc->device == NULL)
  1027. return;
  1028. if (sc->device->host == NULL)
  1029. return;
  1030. if ((hd = shost_priv(sc->device->host)) == NULL)
  1031. return;
  1032. ioc = hd->ioc;
  1033. if (time - hd->last_queue_full > 10 * HZ) {
  1034. dprintk(ioc, printk(MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
  1035. ioc->name, 0, sc->device->id, sc->device->lun));
  1036. hd->last_queue_full = time;
  1037. }
  1038. }
  1039. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1040. /*
  1041. * mptscsih_remove - Removed scsi devices
  1042. * @pdev: Pointer to pci_dev structure
  1043. *
  1044. *
  1045. */
  1046. void
  1047. mptscsih_remove(struct pci_dev *pdev)
  1048. {
  1049. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1050. struct Scsi_Host *host = ioc->sh;
  1051. MPT_SCSI_HOST *hd;
  1052. int sz1;
  1053. scsi_remove_host(host);
  1054. if((hd = shost_priv(host)) == NULL)
  1055. return;
  1056. mptscsih_shutdown(pdev);
  1057. sz1=0;
  1058. if (ioc->ScsiLookup != NULL) {
  1059. sz1 = ioc->req_depth * sizeof(void *);
  1060. kfree(ioc->ScsiLookup);
  1061. ioc->ScsiLookup = NULL;
  1062. }
  1063. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1064. "Free'd ScsiLookup (%d) memory\n",
  1065. ioc->name, sz1));
  1066. kfree(hd->info_kbuf);
  1067. /* NULL the Scsi_Host pointer
  1068. */
  1069. ioc->sh = NULL;
  1070. scsi_host_put(host);
  1071. mpt_detach(pdev);
  1072. }
  1073. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1074. /*
  1075. * mptscsih_shutdown - reboot notifier
  1076. *
  1077. */
  1078. void
  1079. mptscsih_shutdown(struct pci_dev *pdev)
  1080. {
  1081. }
  1082. #ifdef CONFIG_PM
  1083. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1084. /*
  1085. * mptscsih_suspend - Fusion MPT scsi driver suspend routine.
  1086. *
  1087. *
  1088. */
  1089. int
  1090. mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
  1091. {
  1092. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1093. scsi_block_requests(ioc->sh);
  1094. flush_scheduled_work();
  1095. mptscsih_shutdown(pdev);
  1096. return mpt_suspend(pdev,state);
  1097. }
  1098. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1099. /*
  1100. * mptscsih_resume - Fusion MPT scsi driver resume routine.
  1101. *
  1102. *
  1103. */
  1104. int
  1105. mptscsih_resume(struct pci_dev *pdev)
  1106. {
  1107. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1108. int rc;
  1109. rc = mpt_resume(pdev);
  1110. scsi_unblock_requests(ioc->sh);
  1111. return rc;
  1112. }
  1113. #endif
  1114. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1115. /**
  1116. * mptscsih_info - Return information about MPT adapter
  1117. * @SChost: Pointer to Scsi_Host structure
  1118. *
  1119. * (linux scsi_host_template.info routine)
  1120. *
  1121. * Returns pointer to buffer where information was written.
  1122. */
  1123. const char *
  1124. mptscsih_info(struct Scsi_Host *SChost)
  1125. {
  1126. MPT_SCSI_HOST *h;
  1127. int size = 0;
  1128. h = shost_priv(SChost);
  1129. if (h) {
  1130. if (h->info_kbuf == NULL)
  1131. if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
  1132. return h->info_kbuf;
  1133. h->info_kbuf[0] = '\0';
  1134. mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
  1135. h->info_kbuf[size-1] = '\0';
  1136. }
  1137. return h->info_kbuf;
  1138. }
  1139. struct info_str {
  1140. char *buffer;
  1141. int length;
  1142. int offset;
  1143. int pos;
  1144. };
  1145. static void
  1146. mptscsih_copy_mem_info(struct info_str *info, char *data, int len)
  1147. {
  1148. if (info->pos + len > info->length)
  1149. len = info->length - info->pos;
  1150. if (info->pos + len < info->offset) {
  1151. info->pos += len;
  1152. return;
  1153. }
  1154. if (info->pos < info->offset) {
  1155. data += (info->offset - info->pos);
  1156. len -= (info->offset - info->pos);
  1157. }
  1158. if (len > 0) {
  1159. memcpy(info->buffer + info->pos, data, len);
  1160. info->pos += len;
  1161. }
  1162. }
  1163. static int
  1164. mptscsih_copy_info(struct info_str *info, char *fmt, ...)
  1165. {
  1166. va_list args;
  1167. char buf[81];
  1168. int len;
  1169. va_start(args, fmt);
  1170. len = vsprintf(buf, fmt, args);
  1171. va_end(args);
  1172. mptscsih_copy_mem_info(info, buf, len);
  1173. return len;
  1174. }
  1175. static int
  1176. mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)
  1177. {
  1178. struct info_str info;
  1179. info.buffer = pbuf;
  1180. info.length = len;
  1181. info.offset = offset;
  1182. info.pos = 0;
  1183. mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);
  1184. mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
  1185. mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);
  1186. mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth);
  1187. return ((info.pos > info.offset) ? info.pos - info.offset : 0);
  1188. }
  1189. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1190. /**
  1191. * mptscsih_proc_info - Return information about MPT adapter
  1192. * @host: scsi host struct
  1193. * @buffer: if write, user data; if read, buffer for user
  1194. * @start: returns the buffer address
  1195. * @offset: if write, 0; if read, the current offset into the buffer from
  1196. * the previous read.
  1197. * @length: if write, return length;
  1198. * @func: write = 1; read = 0
  1199. *
  1200. * (linux scsi_host_template.info routine)
  1201. */
  1202. int
  1203. mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
  1204. int length, int func)
  1205. {
  1206. MPT_SCSI_HOST *hd = shost_priv(host);
  1207. MPT_ADAPTER *ioc = hd->ioc;
  1208. int size = 0;
  1209. if (func) {
  1210. /*
  1211. * write is not supported
  1212. */
  1213. } else {
  1214. if (start)
  1215. *start = buffer;
  1216. size = mptscsih_host_info(ioc, buffer, offset, length);
  1217. }
  1218. return size;
  1219. }
  1220. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1221. #define ADD_INDEX_LOG(req_ent) do { } while(0)
  1222. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1223. /**
  1224. * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
  1225. * @SCpnt: Pointer to scsi_cmnd structure
  1226. * @done: Pointer SCSI mid-layer IO completion function
  1227. *
  1228. * (linux scsi_host_template.queuecommand routine)
  1229. * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
  1230. * from a linux scsi_cmnd request and send it to the IOC.
  1231. *
  1232. * Returns 0. (rtn value discarded by linux scsi mid-layer)
  1233. */
  1234. int
  1235. mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
  1236. {
  1237. MPT_SCSI_HOST *hd;
  1238. MPT_FRAME_HDR *mf;
  1239. SCSIIORequest_t *pScsiReq;
  1240. VirtDevice *vdevice = SCpnt->device->hostdata;
  1241. u32 datalen;
  1242. u32 scsictl;
  1243. u32 scsidir;
  1244. u32 cmd_len;
  1245. int my_idx;
  1246. int ii;
  1247. MPT_ADAPTER *ioc;
  1248. hd = shost_priv(SCpnt->device->host);
  1249. ioc = hd->ioc;
  1250. SCpnt->scsi_done = done;
  1251. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p, done()=%p\n",
  1252. ioc->name, SCpnt, done));
  1253. if (ioc->taskmgmt_quiesce_io)
  1254. return SCSI_MLQUEUE_HOST_BUSY;
  1255. /*
  1256. * Put together a MPT SCSI request...
  1257. */
  1258. if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
  1259. dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
  1260. ioc->name));
  1261. return SCSI_MLQUEUE_HOST_BUSY;
  1262. }
  1263. pScsiReq = (SCSIIORequest_t *) mf;
  1264. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  1265. ADD_INDEX_LOG(my_idx);
  1266. /* TUR's being issued with scsictl=0x02000000 (DATA_IN)!
  1267. * Seems we may receive a buffer (datalen>0) even when there
  1268. * will be no data transfer! GRRRRR...
  1269. */
  1270. if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
  1271. datalen = scsi_bufflen(SCpnt);
  1272. scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
  1273. } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
  1274. datalen = scsi_bufflen(SCpnt);
  1275. scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
  1276. } else {
  1277. datalen = 0;
  1278. scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
  1279. }
  1280. /* Default to untagged. Once a target structure has been allocated,
  1281. * use the Inquiry data to determine if device supports tagged.
  1282. */
  1283. if (vdevice
  1284. && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
  1285. && (SCpnt->device->tagged_supported)) {
  1286. scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
  1287. if (SCpnt->request && SCpnt->request->ioprio) {
  1288. if (((SCpnt->request->ioprio & 0x7) == 1) ||
  1289. !(SCpnt->request->ioprio & 0x7))
  1290. scsictl |= MPI_SCSIIO_CONTROL_HEADOFQ;
  1291. }
  1292. } else
  1293. scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
  1294. /* Use the above information to set up the message frame
  1295. */
  1296. pScsiReq->TargetID = (u8) vdevice->vtarget->id;
  1297. pScsiReq->Bus = vdevice->vtarget->channel;
  1298. pScsiReq->ChainOffset = 0;
  1299. if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
  1300. pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  1301. else
  1302. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  1303. pScsiReq->CDBLength = SCpnt->cmd_len;
  1304. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1305. pScsiReq->Reserved = 0;
  1306. pScsiReq->MsgFlags = mpt_msg_flags(ioc);
  1307. int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);
  1308. pScsiReq->Control = cpu_to_le32(scsictl);
  1309. /*
  1310. * Write SCSI CDB into the message
  1311. */
  1312. cmd_len = SCpnt->cmd_len;
  1313. for (ii=0; ii < cmd_len; ii++)
  1314. pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
  1315. for (ii=cmd_len; ii < 16; ii++)
  1316. pScsiReq->CDB[ii] = 0;
  1317. /* DataLength */
  1318. pScsiReq->DataLength = cpu_to_le32(datalen);
  1319. /* SenseBuffer low address */
  1320. pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
  1321. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  1322. /* Now add the SG list
  1323. * Always have a SGE even if null length.
  1324. */
  1325. if (datalen == 0) {
  1326. /* Add a NULL SGE */
  1327. ioc->add_sge((char *)&pScsiReq->SGL,
  1328. MPT_SGE_FLAGS_SSIMPLE_READ | 0,
  1329. (dma_addr_t) -1);
  1330. } else {
  1331. /* Add a 32 or 64 bit SGE */
  1332. if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
  1333. goto fail;
  1334. }
  1335. SCpnt->host_scribble = (unsigned char *)mf;
  1336. mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt);
  1337. mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  1338. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
  1339. ioc->name, SCpnt, mf, my_idx));
  1340. DBG_DUMP_REQUEST_FRAME(ioc, (u32 *)mf);
  1341. return 0;
  1342. fail:
  1343. mptscsih_freeChainBuffers(ioc, my_idx);
  1344. mpt_free_msg_frame(ioc, mf);
  1345. return SCSI_MLQUEUE_HOST_BUSY;
  1346. }
  1347. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1348. /*
  1349. * mptscsih_freeChainBuffers - Function to free chain buffers associated
  1350. * with a SCSI IO request
  1351. * @hd: Pointer to the MPT_SCSI_HOST instance
  1352. * @req_idx: Index of the SCSI IO request frame.
  1353. *
  1354. * Called if SG chain buffer allocation fails and mptscsih callbacks.
  1355. * No return.
  1356. */
  1357. static void
  1358. mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
  1359. {
  1360. MPT_FRAME_HDR *chain;
  1361. unsigned long flags;
  1362. int chain_idx;
  1363. int next;
  1364. /* Get the first chain index and reset
  1365. * tracker state.
  1366. */
  1367. chain_idx = ioc->ReqToChain[req_idx];
  1368. ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
  1369. while (chain_idx != MPT_HOST_NO_CHAIN) {
  1370. /* Save the next chain buffer index */
  1371. next = ioc->ChainToChain[chain_idx];
  1372. /* Free this chain buffer and reset
  1373. * tracker
  1374. */
  1375. ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
  1376. chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
  1377. + (chain_idx * ioc->req_sz));
  1378. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1379. list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
  1380. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1381. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FreeChainBuffers (index %d)\n",
  1382. ioc->name, chain_idx));
  1383. /* handle next */
  1384. chain_idx = next;
  1385. }
  1386. return;
  1387. }
  1388. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1389. /*
  1390. * Reset Handling
  1391. */
  1392. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1393. /**
  1394. * mptscsih_IssueTaskMgmt - Generic send Task Management function.
  1395. * @hd: Pointer to MPT_SCSI_HOST structure
  1396. * @type: Task Management type
  1397. * @channel: channel number for task management
  1398. * @id: Logical Target ID for reset (if appropriate)
  1399. * @lun: Logical Unit for reset (if appropriate)
  1400. * @ctx2abort: Context for the task to be aborted (if appropriate)
  1401. * @timeout: timeout for task management control
  1402. *
  1403. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  1404. * or a non-interrupt thread. In the former, must not call schedule().
  1405. *
  1406. * Not all fields are meaningfull for all task types.
  1407. *
  1408. * Returns 0 for SUCCESS, or FAILED.
  1409. *
  1410. **/
  1411. int
  1412. mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun,
  1413. int ctx2abort, ulong timeout)
  1414. {
  1415. MPT_FRAME_HDR *mf;
  1416. SCSITaskMgmt_t *pScsiTm;
  1417. int ii;
  1418. int retval;
  1419. MPT_ADAPTER *ioc = hd->ioc;
  1420. unsigned long timeleft;
  1421. u8 issue_hard_reset;
  1422. u32 ioc_raw_state;
  1423. unsigned long time_count;
  1424. issue_hard_reset = 0;
  1425. ioc_raw_state = mpt_GetIocState(ioc, 0);
  1426. if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
  1427. printk(MYIOC_s_WARN_FMT
  1428. "TaskMgmt type=%x: IOC Not operational (0x%x)!\n",
  1429. ioc->name, type, ioc_raw_state);
  1430. printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
  1431. ioc->name, __func__);
  1432. if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
  1433. printk(MYIOC_s_WARN_FMT "TaskMgmt HardReset "
  1434. "FAILED!!\n", ioc->name);
  1435. return 0;
  1436. }
  1437. /* DOORBELL ACTIVE check is not required if
  1438. * MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q is supported.
  1439. */
  1440. if (!((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q)
  1441. && (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) &&
  1442. (ioc_raw_state & MPI_DOORBELL_ACTIVE)) {
  1443. printk(MYIOC_s_WARN_FMT
  1444. "TaskMgmt type=%x: ioc_state: "
  1445. "DOORBELL_ACTIVE (0x%x)!\n",
  1446. ioc->name, type, ioc_raw_state);
  1447. return FAILED;
  1448. }
  1449. mutex_lock(&ioc->taskmgmt_cmds.mutex);
  1450. if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
  1451. mf = NULL;
  1452. retval = FAILED;
  1453. goto out;
  1454. }
  1455. /* Return Fail to calling function if no message frames available.
  1456. */
  1457. if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
  1458. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1459. "TaskMgmt no msg frames!!\n", ioc->name));
  1460. retval = FAILED;
  1461. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1462. goto out;
  1463. }
  1464. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
  1465. ioc->name, mf));
  1466. /* Format the Request
  1467. */
  1468. pScsiTm = (SCSITaskMgmt_t *) mf;
  1469. pScsiTm->TargetID = id;
  1470. pScsiTm->Bus = channel;
  1471. pScsiTm->ChainOffset = 0;
  1472. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  1473. pScsiTm->Reserved = 0;
  1474. pScsiTm->TaskType = type;
  1475. pScsiTm->Reserved1 = 0;
  1476. pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
  1477. ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
  1478. int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
  1479. for (ii=0; ii < 7; ii++)
  1480. pScsiTm->Reserved2[ii] = 0;
  1481. pScsiTm->TaskMsgContext = ctx2abort;
  1482. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt: ctx2abort (0x%08x) "
  1483. "task_type = 0x%02X, timeout = %ld\n", ioc->name, ctx2abort,
  1484. type, timeout));
  1485. DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);
  1486. INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
  1487. time_count = jiffies;
  1488. if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
  1489. (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
  1490. mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
  1491. else {
  1492. retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
  1493. sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
  1494. if (retval) {
  1495. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1496. "TaskMgmt handshake FAILED!(mf=%p, rc=%d) \n",
  1497. ioc->name, mf, retval));
  1498. mpt_free_msg_frame(ioc, mf);
  1499. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1500. goto out;
  1501. }
  1502. }
  1503. timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
  1504. timeout*HZ);
  1505. if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  1506. retval = FAILED;
  1507. dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
  1508. "TaskMgmt TIMED OUT!(mf=%p)\n", ioc->name, mf));
  1509. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1510. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
  1511. goto out;
  1512. issue_hard_reset = 1;
  1513. goto out;
  1514. }
  1515. retval = mptscsih_taskmgmt_reply(ioc, type,
  1516. (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply);
  1517. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1518. "TaskMgmt completed (%d seconds)\n",
  1519. ioc->name, jiffies_to_msecs(jiffies - time_count)/1000));
  1520. out:
  1521. CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
  1522. if (issue_hard_reset) {
  1523. printk(MYIOC_s_WARN_FMT
  1524. "Issuing Reset from %s!! doorbell=0x%08x\n",
  1525. ioc->name, __func__, mpt_GetIocState(ioc, 0));
  1526. retval = (ioc->bus_type == SAS) ?
  1527. mpt_HardResetHandler(ioc, CAN_SLEEP) :
  1528. mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  1529. mpt_free_msg_frame(ioc, mf);
  1530. }
  1531. retval = (retval == 0) ? 0 : FAILED;
  1532. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  1533. return retval;
  1534. }
  1535. EXPORT_SYMBOL(mptscsih_IssueTaskMgmt);
  1536. static int
  1537. mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
  1538. {
  1539. switch (ioc->bus_type) {
  1540. case FC:
  1541. return 40;
  1542. case SAS:
  1543. return 30;
  1544. case SPI:
  1545. default:
  1546. return 10;
  1547. }
  1548. }
  1549. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1550. /**
  1551. * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
  1552. * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
  1553. *
  1554. * (linux scsi_host_template.eh_abort_handler routine)
  1555. *
  1556. * Returns SUCCESS or FAILED.
  1557. **/
  1558. int
  1559. mptscsih_abort(struct scsi_cmnd * SCpnt)
  1560. {
  1561. MPT_SCSI_HOST *hd;
  1562. MPT_FRAME_HDR *mf;
  1563. u32 ctx2abort;
  1564. int scpnt_idx;
  1565. int retval;
  1566. VirtDevice *vdevice;
  1567. MPT_ADAPTER *ioc;
  1568. /* If we can't locate our host adapter structure, return FAILED status.
  1569. */
  1570. if ((hd = shost_priv(SCpnt->device->host)) == NULL) {
  1571. SCpnt->result = DID_RESET << 16;
  1572. SCpnt->scsi_done(SCpnt);
  1573. printk(KERN_ERR MYNAM ": task abort: "
  1574. "can't locate host! (sc=%p)\n", SCpnt);
  1575. return FAILED;
  1576. }
  1577. ioc = hd->ioc;
  1578. printk(MYIOC_s_INFO_FMT "attempting task abort! (sc=%p)\n",
  1579. ioc->name, SCpnt);
  1580. scsi_print_command(SCpnt);
  1581. vdevice = SCpnt->device->hostdata;
  1582. if (!vdevice || !vdevice->vtarget) {
  1583. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1584. "task abort: device has been deleted (sc=%p)\n",
  1585. ioc->name, SCpnt));
  1586. SCpnt->result = DID_NO_CONNECT << 16;
  1587. SCpnt->scsi_done(SCpnt);
  1588. retval = SUCCESS;
  1589. goto out;
  1590. }
  1591. /* Task aborts are not supported for hidden raid components.
  1592. */
  1593. if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1594. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1595. "task abort: hidden raid component (sc=%p)\n",
  1596. ioc->name, SCpnt));
  1597. SCpnt->result = DID_RESET << 16;
  1598. retval = FAILED;
  1599. goto out;
  1600. }
  1601. /* Task aborts are not supported for volumes.
  1602. */
  1603. if (vdevice->vtarget->raidVolume) {
  1604. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1605. "task abort: raid volume (sc=%p)\n",
  1606. ioc->name, SCpnt));
  1607. SCpnt->result = DID_RESET << 16;
  1608. retval = FAILED;
  1609. goto out;
  1610. }
  1611. /* Find this command
  1612. */
  1613. if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
  1614. /* Cmd not found in ScsiLookup.
  1615. * Do OS callback.
  1616. */
  1617. SCpnt->result = DID_RESET << 16;
  1618. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: "
  1619. "Command not in the active list! (sc=%p)\n", ioc->name,
  1620. SCpnt));
  1621. retval = SUCCESS;
  1622. goto out;
  1623. }
  1624. if (ioc->timeouts < -1)
  1625. ioc->timeouts++;
  1626. if (mpt_fwfault_debug)
  1627. mpt_halt_firmware(ioc);
  1628. /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
  1629. * (the IO to be ABORT'd)
  1630. *
  1631. * NOTE: Since we do not byteswap MsgContext, we do not
  1632. * swap it here either. It is an opaque cookie to
  1633. * the controller, so it does not matter. -DaveM
  1634. */
  1635. mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);
  1636. ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
  1637. retval = mptscsih_IssueTaskMgmt(hd,
  1638. MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
  1639. vdevice->vtarget->channel,
  1640. vdevice->vtarget->id, vdevice->lun,
  1641. ctx2abort, mptscsih_get_tm_timeout(ioc));
  1642. if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx) {
  1643. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1644. "task abort: command still in active list! (sc=%p)\n",
  1645. ioc->name, SCpnt));
  1646. retval = FAILED;
  1647. } else {
  1648. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1649. "task abort: command cleared from active list! (sc=%p)\n",
  1650. ioc->name, SCpnt));
  1651. retval = SUCCESS;
  1652. }
  1653. out:
  1654. printk(MYIOC_s_INFO_FMT "task abort: %s (rv=%04x) (sc=%p)\n",
  1655. ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), retval,
  1656. SCpnt);
  1657. return retval;
  1658. }
  1659. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1660. /**
  1661. * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
  1662. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1663. *
  1664. * (linux scsi_host_template.eh_dev_reset_handler routine)
  1665. *
  1666. * Returns SUCCESS or FAILED.
  1667. **/
  1668. int
  1669. mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
  1670. {
  1671. MPT_SCSI_HOST *hd;
  1672. int retval;
  1673. VirtDevice *vdevice;
  1674. MPT_ADAPTER *ioc;
  1675. /* If we can't locate our host adapter structure, return FAILED status.
  1676. */
  1677. if ((hd = shost_priv(SCpnt->device->host)) == NULL){
  1678. printk(KERN_ERR MYNAM ": target reset: "
  1679. "Can't locate host! (sc=%p)\n", SCpnt);
  1680. return FAILED;
  1681. }
  1682. ioc = hd->ioc;
  1683. printk(MYIOC_s_INFO_FMT "attempting target reset! (sc=%p)\n",
  1684. ioc->name, SCpnt);
  1685. scsi_print_command(SCpnt);
  1686. vdevice = SCpnt->device->hostdata;
  1687. if (!vdevice || !vdevice->vtarget) {
  1688. retval = 0;
  1689. goto out;
  1690. }
  1691. /* Target reset to hidden raid component is not supported
  1692. */
  1693. if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1694. retval = FAILED;
  1695. goto out;
  1696. }
  1697. retval = mptscsih_IssueTaskMgmt(hd,
  1698. MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
  1699. vdevice->vtarget->channel,
  1700. vdevice->vtarget->id, 0, 0,
  1701. mptscsih_get_tm_timeout(ioc));
  1702. out:
  1703. printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",
  1704. ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1705. if (retval == 0)
  1706. return SUCCESS;
  1707. else
  1708. return FAILED;
  1709. }
  1710. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1711. /**
  1712. * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
  1713. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1714. *
  1715. * (linux scsi_host_template.eh_bus_reset_handler routine)
  1716. *
  1717. * Returns SUCCESS or FAILED.
  1718. **/
  1719. int
  1720. mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
  1721. {
  1722. MPT_SCSI_HOST *hd;
  1723. int retval;
  1724. VirtDevice *vdevice;
  1725. MPT_ADAPTER *ioc;
  1726. /* If we can't locate our host adapter structure, return FAILED status.
  1727. */
  1728. if ((hd = shost_priv(SCpnt->device->host)) == NULL){
  1729. printk(KERN_ERR MYNAM ": bus reset: "
  1730. "Can't locate host! (sc=%p)\n", SCpnt);
  1731. return FAILED;
  1732. }
  1733. ioc = hd->ioc;
  1734. printk(MYIOC_s_INFO_FMT "attempting bus reset! (sc=%p)\n",
  1735. ioc->name, SCpnt);
  1736. scsi_print_command(SCpnt);
  1737. if (ioc->timeouts < -1)
  1738. ioc->timeouts++;
  1739. vdevice = SCpnt->device->hostdata;
  1740. if (!vdevice || !vdevice->vtarget)
  1741. return SUCCESS;
  1742. retval = mptscsih_IssueTaskMgmt(hd,
  1743. MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  1744. vdevice->vtarget->channel, 0, 0, 0,
  1745. mptscsih_get_tm_timeout(ioc));
  1746. printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n",
  1747. ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1748. if (retval == 0)
  1749. return SUCCESS;
  1750. else
  1751. return FAILED;
  1752. }
  1753. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1754. /**
  1755. * mptscsih_host_reset - Perform a SCSI host adapter RESET (new_eh variant)
  1756. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1757. *
  1758. * (linux scsi_host_template.eh_host_reset_handler routine)
  1759. *
  1760. * Returns SUCCESS or FAILED.
  1761. */
  1762. int
  1763. mptscsih_host_reset(struct scsi_cmnd *SCpnt)
  1764. {
  1765. MPT_SCSI_HOST * hd;
  1766. int status = SUCCESS;
  1767. MPT_ADAPTER *ioc;
  1768. int retval;
  1769. /* If we can't locate the host to reset, then we failed. */
  1770. if ((hd = shost_priv(SCpnt->device->host)) == NULL){
  1771. printk(KERN_ERR MYNAM ": host reset: "
  1772. "Can't locate host! (sc=%p)\n", SCpnt);
  1773. return FAILED;
  1774. }
  1775. /* make sure we have no outstanding commands at this stage */
  1776. mptscsih_flush_running_cmds(hd);
  1777. ioc = hd->ioc;
  1778. printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n",
  1779. ioc->name, SCpnt);
  1780. /* If our attempts to reset the host failed, then return a failed
  1781. * status. The host will be taken off line by the SCSI mid-layer.
  1782. */
  1783. retval = mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  1784. if (retval < 0)
  1785. status = FAILED;
  1786. else
  1787. status = SUCCESS;
  1788. printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n",
  1789. ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1790. return status;
  1791. }
  1792. static int
  1793. mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,
  1794. SCSITaskMgmtReply_t *pScsiTmReply)
  1795. {
  1796. u16 iocstatus;
  1797. u32 termination_count;
  1798. int retval;
  1799. if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
  1800. retval = FAILED;
  1801. goto out;
  1802. }
  1803. DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);
  1804. iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  1805. termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
  1806. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1807. "TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n"
  1808. "\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n"
  1809. "\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->Bus,
  1810. pScsiTmReply->TargetID, type, le16_to_cpu(pScsiTmReply->IOCStatus),
  1811. le32_to_cpu(pScsiTmReply->IOCLogInfo), pScsiTmReply->ResponseCode,
  1812. termination_count));
  1813. if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
  1814. pScsiTmReply->ResponseCode)
  1815. mptscsih_taskmgmt_response_code(ioc,
  1816. pScsiTmReply->ResponseCode);
  1817. if (iocstatus == MPI_IOCSTATUS_SUCCESS) {
  1818. retval = 0;
  1819. goto out;
  1820. }
  1821. retval = FAILED;
  1822. if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
  1823. if (termination_count == 1)
  1824. retval = 0;
  1825. goto out;
  1826. }
  1827. if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
  1828. iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
  1829. retval = 0;
  1830. out:
  1831. return retval;
  1832. }
  1833. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1834. void
  1835. mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
  1836. {
  1837. char *desc;
  1838. switch (response_code) {
  1839. case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:
  1840. desc = "The task completed.";
  1841. break;
  1842. case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:
  1843. desc = "The IOC received an invalid frame status.";
  1844. break;
  1845. case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
  1846. desc = "The task type is not supported.";
  1847. break;
  1848. case MPI_SCSITASKMGMT_RSP_TM_FAILED:
  1849. desc = "The requested task failed.";
  1850. break;
  1851. case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:
  1852. desc = "The task completed successfully.";
  1853. break;
  1854. case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:
  1855. desc = "The LUN request is invalid.";
  1856. break;
  1857. case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
  1858. desc = "The task is in the IOC queue and has not been sent to target.";
  1859. break;
  1860. default:
  1861. desc = "unknown";
  1862. break;
  1863. }
  1864. printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n",
  1865. ioc->name, response_code, desc);
  1866. }
  1867. EXPORT_SYMBOL(mptscsih_taskmgmt_response_code);
  1868. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1869. /**
  1870. * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
  1871. * @ioc: Pointer to MPT_ADAPTER structure
  1872. * @mf: Pointer to SCSI task mgmt request frame
  1873. * @mr: Pointer to SCSI task mgmt reply frame
  1874. *
  1875. * This routine is called from mptbase.c::mpt_interrupt() at the completion
  1876. * of any SCSI task management request.
  1877. * This routine is registered with the MPT (base) driver at driver
  1878. * load/init time via the mpt_register() API call.
  1879. *
  1880. * Returns 1 indicating alloc'd request frame ptr should be freed.
  1881. **/
  1882. int
  1883. mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
  1884. MPT_FRAME_HDR *mr)
  1885. {
  1886. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1887. "TaskMgmt completed (mf=%p, mr=%p)\n", ioc->name, mf, mr));
  1888. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  1889. if (!mr)
  1890. goto out;
  1891. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  1892. memcpy(ioc->taskmgmt_cmds.reply, mr,
  1893. min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
  1894. out:
  1895. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
  1896. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1897. ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  1898. complete(&ioc->taskmgmt_cmds.done);
  1899. if (ioc->bus_type == SAS)
  1900. ioc->schedule_target_reset(ioc);
  1901. return 1;
  1902. }
  1903. return 0;
  1904. }
  1905. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1906. /*
  1907. * This is anyones guess quite frankly.
  1908. */
  1909. int
  1910. mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
  1911. sector_t capacity, int geom[])
  1912. {
  1913. int heads;
  1914. int sectors;
  1915. sector_t cylinders;
  1916. ulong dummy;
  1917. heads = 64;
  1918. sectors = 32;
  1919. dummy = heads * sectors;
  1920. cylinders = capacity;
  1921. sector_div(cylinders,dummy);
  1922. /*
  1923. * Handle extended translation size for logical drives
  1924. * > 1Gb
  1925. */
  1926. if ((ulong)capacity >= 0x200000) {
  1927. heads = 255;
  1928. sectors = 63;
  1929. dummy = heads * sectors;
  1930. cylinders = capacity;
  1931. sector_div(cylinders,dummy);
  1932. }
  1933. /* return result */
  1934. geom[0] = heads;
  1935. geom[1] = sectors;
  1936. geom[2] = cylinders;
  1937. return 0;
  1938. }
  1939. /* Search IOC page 3 to determine if this is hidden physical disk
  1940. *
  1941. */
  1942. int
  1943. mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
  1944. {
  1945. struct inactive_raid_component_info *component_info;
  1946. int i, j;
  1947. RaidPhysDiskPage1_t *phys_disk;
  1948. int rc = 0;
  1949. int num_paths;
  1950. if (!ioc->raid_data.pIocPg3)
  1951. goto out;
  1952. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  1953. if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
  1954. (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
  1955. rc = 1;
  1956. goto out;
  1957. }
  1958. }
  1959. if (ioc->bus_type != SAS)
  1960. goto out;
  1961. /*
  1962. * Check if dual path
  1963. */
  1964. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  1965. num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
  1966. ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
  1967. if (num_paths < 2)
  1968. continue;
  1969. phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
  1970. (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
  1971. if (!phys_disk)
  1972. continue;
  1973. if ((mpt_raid_phys_disk_pg1(ioc,
  1974. ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
  1975. phys_disk))) {
  1976. kfree(phys_disk);
  1977. continue;
  1978. }
  1979. for (j = 0; j < num_paths; j++) {
  1980. if ((phys_disk->Path[j].Flags &
  1981. MPI_RAID_PHYSDISK1_FLAG_INVALID))
  1982. continue;
  1983. if ((phys_disk->Path[j].Flags &
  1984. MPI_RAID_PHYSDISK1_FLAG_BROKEN))
  1985. continue;
  1986. if ((id == phys_disk->Path[j].PhysDiskID) &&
  1987. (channel == phys_disk->Path[j].PhysDiskBus)) {
  1988. rc = 1;
  1989. kfree(phys_disk);
  1990. goto out;
  1991. }
  1992. }
  1993. kfree(phys_disk);
  1994. }
  1995. /*
  1996. * Check inactive list for matching phys disks
  1997. */
  1998. if (list_empty(&ioc->raid_data.inactive_list))
  1999. goto out;
  2000. mutex_lock(&ioc->raid_data.inactive_list_mutex);
  2001. list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
  2002. list) {
  2003. if ((component_info->d.PhysDiskID == id) &&
  2004. (component_info->d.PhysDiskBus == channel))
  2005. rc = 1;
  2006. }
  2007. mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  2008. out:
  2009. return rc;
  2010. }
  2011. EXPORT_SYMBOL(mptscsih_is_phys_disk);
  2012. u8
  2013. mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
  2014. {
  2015. struct inactive_raid_component_info *component_info;
  2016. int i, j;
  2017. RaidPhysDiskPage1_t *phys_disk;
  2018. int rc = -ENXIO;
  2019. int num_paths;
  2020. if (!ioc->raid_data.pIocPg3)
  2021. goto out;
  2022. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  2023. if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
  2024. (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
  2025. rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
  2026. goto out;
  2027. }
  2028. }
  2029. if (ioc->bus_type != SAS)
  2030. goto out;
  2031. /*
  2032. * Check if dual path
  2033. */
  2034. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  2035. num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
  2036. ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
  2037. if (num_paths < 2)
  2038. continue;
  2039. phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
  2040. (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
  2041. if (!phys_disk)
  2042. continue;
  2043. if ((mpt_raid_phys_disk_pg1(ioc,
  2044. ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
  2045. phys_disk))) {
  2046. kfree(phys_disk);
  2047. continue;
  2048. }
  2049. for (j = 0; j < num_paths; j++) {
  2050. if ((phys_disk->Path[j].Flags &
  2051. MPI_RAID_PHYSDISK1_FLAG_INVALID))
  2052. continue;
  2053. if ((phys_disk->Path[j].Flags &
  2054. MPI_RAID_PHYSDISK1_FLAG_BROKEN))
  2055. continue;
  2056. if ((id == phys_disk->Path[j].PhysDiskID) &&
  2057. (channel == phys_disk->Path[j].PhysDiskBus)) {
  2058. rc = phys_disk->PhysDiskNum;
  2059. kfree(phys_disk);
  2060. goto out;
  2061. }
  2062. }
  2063. kfree(phys_disk);
  2064. }
  2065. /*
  2066. * Check inactive list for matching phys disks
  2067. */
  2068. if (list_empty(&ioc->raid_data.inactive_list))
  2069. goto out;
  2070. mutex_lock(&ioc->raid_data.inactive_list_mutex);
  2071. list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
  2072. list) {
  2073. if ((component_info->d.PhysDiskID == id) &&
  2074. (component_info->d.PhysDiskBus == channel))
  2075. rc = component_info->d.PhysDiskNum;
  2076. }
  2077. mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  2078. out:
  2079. return rc;
  2080. }
  2081. EXPORT_SYMBOL(mptscsih_raid_id_to_num);
  2082. /*
  2083. * OS entry point to allow for host driver to free allocated memory
  2084. * Called if no device present or device being unloaded
  2085. */
  2086. void
  2087. mptscsih_slave_destroy(struct scsi_device *sdev)
  2088. {
  2089. struct Scsi_Host *host = sdev->host;
  2090. MPT_SCSI_HOST *hd = shost_priv(host);
  2091. VirtTarget *vtarget;
  2092. VirtDevice *vdevice;
  2093. struct scsi_target *starget;
  2094. starget = scsi_target(sdev);
  2095. vtarget = starget->hostdata;
  2096. vdevice = sdev->hostdata;
  2097. if (!vdevice)
  2098. return;
  2099. mptscsih_search_running_cmds(hd, vdevice);
  2100. vtarget->num_luns--;
  2101. mptscsih_synchronize_cache(hd, vdevice);
  2102. kfree(vdevice);
  2103. sdev->hostdata = NULL;
  2104. }
  2105. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2106. /*
  2107. * mptscsih_change_queue_depth - This function will set a devices queue depth
  2108. * @sdev: per scsi_device pointer
  2109. * @qdepth: requested queue depth
  2110. * @reason: calling context
  2111. *
  2112. * Adding support for new 'change_queue_depth' api.
  2113. */
  2114. int
  2115. mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  2116. {
  2117. MPT_SCSI_HOST *hd = shost_priv(sdev->host);
  2118. VirtTarget *vtarget;
  2119. struct scsi_target *starget;
  2120. int max_depth;
  2121. int tagged;
  2122. MPT_ADAPTER *ioc = hd->ioc;
  2123. starget = scsi_target(sdev);
  2124. vtarget = starget->hostdata;
  2125. if (reason != SCSI_QDEPTH_DEFAULT)
  2126. return -EOPNOTSUPP;
  2127. if (ioc->bus_type == SPI) {
  2128. if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
  2129. max_depth = 1;
  2130. else if (sdev->type == TYPE_DISK &&
  2131. vtarget->minSyncFactor <= MPT_ULTRA160)
  2132. max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
  2133. else
  2134. max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
  2135. } else
  2136. max_depth = ioc->sh->can_queue;
  2137. if (!sdev->tagged_supported)
  2138. max_depth = 1;
  2139. if (qdepth > max_depth)
  2140. qdepth = max_depth;
  2141. if (qdepth == 1)
  2142. tagged = 0;
  2143. else
  2144. tagged = MSG_SIMPLE_TAG;
  2145. scsi_adjust_queue_depth(sdev, tagged, qdepth);
  2146. return sdev->queue_depth;
  2147. }
  2148. /*
  2149. * OS entry point to adjust the queue_depths on a per-device basis.
  2150. * Called once per device the bus scan. Use it to force the queue_depth
  2151. * member to 1 if a device does not support Q tags.
  2152. * Return non-zero if fails.
  2153. */
  2154. int
  2155. mptscsih_slave_configure(struct scsi_device *sdev)
  2156. {
  2157. struct Scsi_Host *sh = sdev->host;
  2158. VirtTarget *vtarget;
  2159. VirtDevice *vdevice;
  2160. struct scsi_target *starget;
  2161. MPT_SCSI_HOST *hd = shost_priv(sh);
  2162. MPT_ADAPTER *ioc = hd->ioc;
  2163. starget = scsi_target(sdev);
  2164. vtarget = starget->hostdata;
  2165. vdevice = sdev->hostdata;
  2166. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2167. "device @ %p, channel=%d, id=%d, lun=%d\n",
  2168. ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
  2169. if (ioc->bus_type == SPI)
  2170. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2171. "sdtr %d wdtr %d ppr %d inq length=%d\n",
  2172. ioc->name, sdev->sdtr, sdev->wdtr,
  2173. sdev->ppr, sdev->inquiry_len));
  2174. vdevice->configured_lun = 1;
  2175. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2176. "Queue depth=%d, tflags=%x\n",
  2177. ioc->name, sdev->queue_depth, vtarget->tflags));
  2178. if (ioc->bus_type == SPI)
  2179. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2180. "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
  2181. ioc->name, vtarget->negoFlags, vtarget->maxOffset,
  2182. vtarget->minSyncFactor));
  2183. mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH,
  2184. SCSI_QDEPTH_DEFAULT);
  2185. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2186. "tagged %d, simple %d, ordered %d\n",
  2187. ioc->name,sdev->tagged_supported, sdev->simple_tags,
  2188. sdev->ordered_tags));
  2189. blk_queue_dma_alignment (sdev->request_queue, 512 - 1);
  2190. return 0;
  2191. }
  2192. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2193. /*
  2194. * Private routines...
  2195. */
  2196. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2197. /* Utility function to copy sense data from the scsi_cmnd buffer
  2198. * to the FC and SCSI target structures.
  2199. *
  2200. */
  2201. static void
  2202. mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
  2203. {
  2204. VirtDevice *vdevice;
  2205. SCSIIORequest_t *pReq;
  2206. u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
  2207. MPT_ADAPTER *ioc = hd->ioc;
  2208. /* Get target structure
  2209. */
  2210. pReq = (SCSIIORequest_t *) mf;
  2211. vdevice = sc->device->hostdata;
  2212. if (sense_count) {
  2213. u8 *sense_data;
  2214. int req_index;
  2215. /* Copy the sense received into the scsi command block. */
  2216. req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2217. sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
  2218. memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
  2219. /* Log SMART data (asc = 0x5D, non-IM case only) if required.
  2220. */
  2221. if ((ioc->events) && (ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
  2222. if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) {
  2223. int idx;
  2224. idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
  2225. ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
  2226. ioc->events[idx].eventContext = ioc->eventContext;
  2227. ioc->events[idx].data[0] = (pReq->LUN[1] << 24) |
  2228. (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) |
  2229. (sc->device->channel << 8) | sc->device->id;
  2230. ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];
  2231. ioc->eventContext++;
  2232. if (ioc->pcidev->vendor ==
  2233. PCI_VENDOR_ID_IBM) {
  2234. mptscsih_issue_sep_command(ioc,
  2235. vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
  2236. vdevice->vtarget->tflags |=
  2237. MPT_TARGET_FLAGS_LED_ON;
  2238. }
  2239. }
  2240. }
  2241. } else {
  2242. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n",
  2243. ioc->name));
  2244. }
  2245. }
  2246. /**
  2247. * mptscsih_get_scsi_lookup - retrieves scmd entry
  2248. * @ioc: Pointer to MPT_ADAPTER structure
  2249. * @i: index into the array
  2250. *
  2251. * Returns the scsi_cmd pointer
  2252. */
  2253. struct scsi_cmnd *
  2254. mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i)
  2255. {
  2256. unsigned long flags;
  2257. struct scsi_cmnd *scmd;
  2258. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  2259. scmd = ioc->ScsiLookup[i];
  2260. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  2261. return scmd;
  2262. }
  2263. EXPORT_SYMBOL(mptscsih_get_scsi_lookup);
  2264. /**
  2265. * mptscsih_getclear_scsi_lookup - retrieves and clears scmd entry from ScsiLookup[] array list
  2266. * @ioc: Pointer to MPT_ADAPTER structure
  2267. * @i: index into the array
  2268. *
  2269. * Returns the scsi_cmd pointer
  2270. *
  2271. **/
  2272. static struct scsi_cmnd *
  2273. mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i)
  2274. {
  2275. unsigned long flags;
  2276. struct scsi_cmnd *scmd;
  2277. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  2278. scmd = ioc->ScsiLookup[i];
  2279. ioc->ScsiLookup[i] = NULL;
  2280. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  2281. return scmd;
  2282. }
  2283. /**
  2284. * mptscsih_set_scsi_lookup - write a scmd entry into the ScsiLookup[] array list
  2285. *
  2286. * @ioc: Pointer to MPT_ADAPTER structure
  2287. * @i: index into the array
  2288. * @scmd: scsi_cmnd pointer
  2289. *
  2290. **/
  2291. static void
  2292. mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd)
  2293. {
  2294. unsigned long flags;
  2295. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  2296. ioc->ScsiLookup[i] = scmd;
  2297. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  2298. }
  2299. /**
  2300. * SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list
  2301. * @ioc: Pointer to MPT_ADAPTER structure
  2302. * @sc: scsi_cmnd pointer
  2303. */
  2304. static int
  2305. SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc)
  2306. {
  2307. unsigned long flags;
  2308. int i, index=-1;
  2309. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  2310. for (i = 0; i < ioc->req_depth; i++) {
  2311. if (ioc->ScsiLookup[i] == sc) {
  2312. index = i;
  2313. goto out;
  2314. }
  2315. }
  2316. out:
  2317. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  2318. return index;
  2319. }
  2320. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2321. int
  2322. mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  2323. {
  2324. MPT_SCSI_HOST *hd;
  2325. if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
  2326. return 0;
  2327. hd = shost_priv(ioc->sh);
  2328. switch (reset_phase) {
  2329. case MPT_IOC_SETUP_RESET:
  2330. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2331. "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
  2332. break;
  2333. case MPT_IOC_PRE_RESET:
  2334. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2335. "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
  2336. mptscsih_flush_running_cmds(hd);
  2337. break;
  2338. case MPT_IOC_POST_RESET:
  2339. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2340. "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
  2341. if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) {
  2342. ioc->internal_cmds.status |=
  2343. MPT_MGMT_STATUS_DID_IOCRESET;
  2344. complete(&ioc->internal_cmds.done);
  2345. }
  2346. break;
  2347. default:
  2348. break;
  2349. }
  2350. return 1; /* currently means nothing really */
  2351. }
  2352. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2353. int
  2354. mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  2355. {
  2356. u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
  2357. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2358. "MPT event (=%02Xh) routed to SCSI host driver!\n",
  2359. ioc->name, event));
  2360. if ((event == MPI_EVENT_IOC_BUS_RESET ||
  2361. event == MPI_EVENT_EXT_BUS_RESET) &&
  2362. (ioc->bus_type == SPI) && (ioc->soft_resets < -1))
  2363. ioc->soft_resets++;
  2364. return 1; /* currently means nothing really */
  2365. }
  2366. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2367. /*
  2368. * Bus Scan and Domain Validation functionality ...
  2369. */
  2370. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2371. /*
  2372. * mptscsih_scandv_complete - Scan and DV callback routine registered
  2373. * to Fustion MPT (base) driver.
  2374. *
  2375. * @ioc: Pointer to MPT_ADAPTER structure
  2376. * @mf: Pointer to original MPT request frame
  2377. * @mr: Pointer to MPT reply frame (NULL if TurboReply)
  2378. *
  2379. * This routine is called from mpt.c::mpt_interrupt() at the completion
  2380. * of any SCSI IO request.
  2381. * This routine is registered with the Fusion MPT (base) driver at driver
  2382. * load/init time via the mpt_register() API call.
  2383. *
  2384. * Returns 1 indicating alloc'd request frame ptr should be freed.
  2385. *
  2386. * Remark: Sets a completion code and (possibly) saves sense data
  2387. * in the IOC member localReply structure.
  2388. * Used ONLY for DV and other internal commands.
  2389. */
  2390. int
  2391. mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
  2392. MPT_FRAME_HDR *reply)
  2393. {
  2394. SCSIIORequest_t *pReq;
  2395. SCSIIOReply_t *pReply;
  2396. u8 cmd;
  2397. u16 req_idx;
  2398. u8 *sense_data;
  2399. int sz;
  2400. ioc->internal_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  2401. ioc->internal_cmds.completion_code = MPT_SCANDV_GOOD;
  2402. if (!reply)
  2403. goto out;
  2404. pReply = (SCSIIOReply_t *) reply;
  2405. pReq = (SCSIIORequest_t *) req;
  2406. ioc->internal_cmds.completion_code =
  2407. mptscsih_get_completion_code(ioc, req, reply);
  2408. ioc->internal_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  2409. memcpy(ioc->internal_cmds.reply, reply,
  2410. min(MPT_DEFAULT_FRAME_SIZE, 4 * reply->u.reply.MsgLength));
  2411. cmd = reply->u.hdr.Function;
  2412. if (((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
  2413. (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) &&
  2414. (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
  2415. req_idx = le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
  2416. sense_data = ((u8 *)ioc->sense_buf_pool +
  2417. (req_idx * MPT_SENSE_BUFFER_ALLOC));
  2418. sz = min_t(int, pReq->SenseBufferLength,
  2419. MPT_SENSE_BUFFER_ALLOC);
  2420. memcpy(ioc->internal_cmds.sense, sense_data, sz);
  2421. }
  2422. out:
  2423. if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING))
  2424. return 0;
  2425. ioc->internal_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  2426. complete(&ioc->internal_cmds.done);
  2427. return 1;
  2428. }
  2429. /**
  2430. * mptscsih_get_completion_code - get completion code from MPT request
  2431. * @ioc: Pointer to MPT_ADAPTER structure
  2432. * @req: Pointer to original MPT request frame
  2433. * @reply: Pointer to MPT reply frame (NULL if TurboReply)
  2434. *
  2435. **/
  2436. static int
  2437. mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
  2438. MPT_FRAME_HDR *reply)
  2439. {
  2440. SCSIIOReply_t *pReply;
  2441. MpiRaidActionReply_t *pr;
  2442. u8 scsi_status;
  2443. u16 status;
  2444. int completion_code;
  2445. pReply = (SCSIIOReply_t *)reply;
  2446. status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  2447. scsi_status = pReply->SCSIStatus;
  2448. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2449. "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh,"
  2450. "IOCLogInfo=%08xh\n", ioc->name, status, pReply->SCSIState,
  2451. scsi_status, le32_to_cpu(pReply->IOCLogInfo)));
  2452. switch (status) {
  2453. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  2454. completion_code = MPT_SCANDV_SELECTION_TIMEOUT;
  2455. break;
  2456. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  2457. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  2458. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  2459. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  2460. completion_code = MPT_SCANDV_DID_RESET;
  2461. break;
  2462. case MPI_IOCSTATUS_BUSY:
  2463. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:
  2464. completion_code = MPT_SCANDV_BUSY;
  2465. break;
  2466. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  2467. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  2468. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  2469. if (pReply->Function == MPI_FUNCTION_CONFIG) {
  2470. completion_code = MPT_SCANDV_GOOD;
  2471. } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
  2472. pr = (MpiRaidActionReply_t *)reply;
  2473. if (le16_to_cpu(pr->ActionStatus) ==
  2474. MPI_RAID_ACTION_ASTATUS_SUCCESS)
  2475. completion_code = MPT_SCANDV_GOOD;
  2476. else
  2477. completion_code = MPT_SCANDV_SOME_ERROR;
  2478. } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)
  2479. completion_code = MPT_SCANDV_SENSE;
  2480. else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
  2481. if (req->u.scsireq.CDB[0] == INQUIRY)
  2482. completion_code = MPT_SCANDV_ISSUE_SENSE;
  2483. else
  2484. completion_code = MPT_SCANDV_DID_RESET;
  2485. } else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
  2486. completion_code = MPT_SCANDV_DID_RESET;
  2487. else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  2488. completion_code = MPT_SCANDV_DID_RESET;
  2489. else if (scsi_status == MPI_SCSI_STATUS_BUSY)
  2490. completion_code = MPT_SCANDV_BUSY;
  2491. else
  2492. completion_code = MPT_SCANDV_GOOD;
  2493. break;
  2494. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  2495. if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  2496. completion_code = MPT_SCANDV_DID_RESET;
  2497. else
  2498. completion_code = MPT_SCANDV_SOME_ERROR;
  2499. break;
  2500. default:
  2501. completion_code = MPT_SCANDV_SOME_ERROR;
  2502. break;
  2503. } /* switch(status) */
  2504. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2505. " completionCode set to %08xh\n", ioc->name, completion_code));
  2506. return completion_code;
  2507. }
  2508. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2509. /**
  2510. * mptscsih_do_cmd - Do internal command.
  2511. * @hd: MPT_SCSI_HOST pointer
  2512. * @io: INTERNAL_CMD pointer.
  2513. *
  2514. * Issue the specified internally generated command and do command
  2515. * specific cleanup. For bus scan / DV only.
  2516. * NOTES: If command is Inquiry and status is good,
  2517. * initialize a target structure, save the data
  2518. *
  2519. * Remark: Single threaded access only.
  2520. *
  2521. * Return:
  2522. * < 0 if an illegal command or no resources
  2523. *
  2524. * 0 if good
  2525. *
  2526. * > 0 if command complete but some type of completion error.
  2527. */
  2528. static int
  2529. mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
  2530. {
  2531. MPT_FRAME_HDR *mf;
  2532. SCSIIORequest_t *pScsiReq;
  2533. int my_idx, ii, dir;
  2534. int timeout;
  2535. char cmdLen;
  2536. char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  2537. u8 cmd = io->cmd;
  2538. MPT_ADAPTER *ioc = hd->ioc;
  2539. int ret = 0;
  2540. unsigned long timeleft;
  2541. unsigned long flags;
  2542. /* don't send internal command during diag reset */
  2543. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  2544. if (ioc->ioc_reset_in_progress) {
  2545. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  2546. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2547. "%s: busy with host reset\n", ioc->name, __func__));
  2548. return MPT_SCANDV_BUSY;
  2549. }
  2550. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  2551. mutex_lock(&ioc->internal_cmds.mutex);
  2552. /* Set command specific information
  2553. */
  2554. switch (cmd) {
  2555. case INQUIRY:
  2556. cmdLen = 6;
  2557. dir = MPI_SCSIIO_CONTROL_READ;
  2558. CDB[0] = cmd;
  2559. CDB[4] = io->size;
  2560. timeout = 10;
  2561. break;
  2562. case TEST_UNIT_READY:
  2563. cmdLen = 6;
  2564. dir = MPI_SCSIIO_CONTROL_READ;
  2565. timeout = 10;
  2566. break;
  2567. case START_STOP:
  2568. cmdLen = 6;
  2569. dir = MPI_SCSIIO_CONTROL_READ;
  2570. CDB[0] = cmd;
  2571. CDB[4] = 1; /*Spin up the disk */
  2572. timeout = 15;
  2573. break;
  2574. case REQUEST_SENSE:
  2575. cmdLen = 6;
  2576. CDB[0] = cmd;
  2577. CDB[4] = io->size;
  2578. dir = MPI_SCSIIO_CONTROL_READ;
  2579. timeout = 10;
  2580. break;
  2581. case READ_BUFFER:
  2582. cmdLen = 10;
  2583. dir = MPI_SCSIIO_CONTROL_READ;
  2584. CDB[0] = cmd;
  2585. if (io->flags & MPT_ICFLAG_ECHO) {
  2586. CDB[1] = 0x0A;
  2587. } else {
  2588. CDB[1] = 0x02;
  2589. }
  2590. if (io->flags & MPT_ICFLAG_BUF_CAP) {
  2591. CDB[1] |= 0x01;
  2592. }
  2593. CDB[6] = (io->size >> 16) & 0xFF;
  2594. CDB[7] = (io->size >> 8) & 0xFF;
  2595. CDB[8] = io->size & 0xFF;
  2596. timeout = 10;
  2597. break;
  2598. case WRITE_BUFFER:
  2599. cmdLen = 10;
  2600. dir = MPI_SCSIIO_CONTROL_WRITE;
  2601. CDB[0] = cmd;
  2602. if (io->flags & MPT_ICFLAG_ECHO) {
  2603. CDB[1] = 0x0A;
  2604. } else {
  2605. CDB[1] = 0x02;
  2606. }
  2607. CDB[6] = (io->size >> 16) & 0xFF;
  2608. CDB[7] = (io->size >> 8) & 0xFF;
  2609. CDB[8] = io->size & 0xFF;
  2610. timeout = 10;
  2611. break;
  2612. case RESERVE:
  2613. cmdLen = 6;
  2614. dir = MPI_SCSIIO_CONTROL_READ;
  2615. CDB[0] = cmd;
  2616. timeout = 10;
  2617. break;
  2618. case RELEASE:
  2619. cmdLen = 6;
  2620. dir = MPI_SCSIIO_CONTROL_READ;
  2621. CDB[0] = cmd;
  2622. timeout = 10;
  2623. break;
  2624. case SYNCHRONIZE_CACHE:
  2625. cmdLen = 10;
  2626. dir = MPI_SCSIIO_CONTROL_READ;
  2627. CDB[0] = cmd;
  2628. // CDB[1] = 0x02; /* set immediate bit */
  2629. timeout = 10;
  2630. break;
  2631. default:
  2632. /* Error Case */
  2633. ret = -EFAULT;
  2634. goto out;
  2635. }
  2636. /* Get and Populate a free Frame
  2637. * MsgContext set in mpt_get_msg_frame call
  2638. */
  2639. if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
  2640. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: No msg frames!\n",
  2641. ioc->name, __func__));
  2642. ret = MPT_SCANDV_BUSY;
  2643. goto out;
  2644. }
  2645. pScsiReq = (SCSIIORequest_t *) mf;
  2646. /* Get the request index */
  2647. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2648. ADD_INDEX_LOG(my_idx); /* for debug */
  2649. if (io->flags & MPT_ICFLAG_PHYS_DISK) {
  2650. pScsiReq->TargetID = io->physDiskNum;
  2651. pScsiReq->Bus = 0;
  2652. pScsiReq->ChainOffset = 0;
  2653. pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  2654. } else {
  2655. pScsiReq->TargetID = io->id;
  2656. pScsiReq->Bus = io->channel;
  2657. pScsiReq->ChainOffset = 0;
  2658. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  2659. }
  2660. pScsiReq->CDBLength = cmdLen;
  2661. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  2662. pScsiReq->Reserved = 0;
  2663. pScsiReq->MsgFlags = mpt_msg_flags(ioc);
  2664. /* MsgContext set in mpt_get_msg_fram call */
  2665. int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);
  2666. if (io->flags & MPT_ICFLAG_TAGGED_CMD)
  2667. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
  2668. else
  2669. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  2670. if (cmd == REQUEST_SENSE) {
  2671. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  2672. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2673. "%s: Untagged! 0x%02x\n", ioc->name, __func__, cmd));
  2674. }
  2675. for (ii = 0; ii < 16; ii++)
  2676. pScsiReq->CDB[ii] = CDB[ii];
  2677. pScsiReq->DataLength = cpu_to_le32(io->size);
  2678. pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
  2679. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  2680. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2681. "%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%d\n",
  2682. ioc->name, __func__, cmd, io->channel, io->id, io->lun));
  2683. if (dir == MPI_SCSIIO_CONTROL_READ)
  2684. ioc->add_sge((char *) &pScsiReq->SGL,
  2685. MPT_SGE_FLAGS_SSIMPLE_READ | io->size, io->data_dma);
  2686. else
  2687. ioc->add_sge((char *) &pScsiReq->SGL,
  2688. MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size, io->data_dma);
  2689. INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
  2690. mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
  2691. timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done,
  2692. timeout*HZ);
  2693. if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  2694. ret = MPT_SCANDV_DID_RESET;
  2695. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2696. "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __func__,
  2697. cmd));
  2698. if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
  2699. mpt_free_msg_frame(ioc, mf);
  2700. goto out;
  2701. }
  2702. if (!timeleft) {
  2703. printk(MYIOC_s_WARN_FMT
  2704. "Issuing Reset from %s!! doorbell=0x%08xh"
  2705. " cmd=0x%02x\n",
  2706. ioc->name, __func__, mpt_GetIocState(ioc, 0),
  2707. cmd);
  2708. mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  2709. mpt_free_msg_frame(ioc, mf);
  2710. }
  2711. goto out;
  2712. }
  2713. ret = ioc->internal_cmds.completion_code;
  2714. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: success, rc=0x%02x\n",
  2715. ioc->name, __func__, ret));
  2716. out:
  2717. CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
  2718. mutex_unlock(&ioc->internal_cmds.mutex);
  2719. return ret;
  2720. }
  2721. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2722. /**
  2723. * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
  2724. * @hd: Pointer to a SCSI HOST structure
  2725. * @vdevice: virtual target device
  2726. *
  2727. * Uses the ISR, but with special processing.
  2728. * MUST be single-threaded.
  2729. *
  2730. */
  2731. static void
  2732. mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
  2733. {
  2734. INTERNAL_CMD iocmd;
  2735. /* Ignore hidden raid components, this is handled when the command
  2736. * is sent to the volume
  2737. */
  2738. if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
  2739. return;
  2740. if (vdevice->vtarget->type != TYPE_DISK || vdevice->vtarget->deleted ||
  2741. !vdevice->configured_lun)
  2742. return;
  2743. /* Following parameters will not change
  2744. * in this routine.
  2745. */
  2746. iocmd.cmd = SYNCHRONIZE_CACHE;
  2747. iocmd.flags = 0;
  2748. iocmd.physDiskNum = -1;
  2749. iocmd.data = NULL;
  2750. iocmd.data_dma = -1;
  2751. iocmd.size = 0;
  2752. iocmd.rsvd = iocmd.rsvd2 = 0;
  2753. iocmd.channel = vdevice->vtarget->channel;
  2754. iocmd.id = vdevice->vtarget->id;
  2755. iocmd.lun = vdevice->lun;
  2756. mptscsih_do_cmd(hd, &iocmd);
  2757. }
  2758. static ssize_t
  2759. mptscsih_version_fw_show(struct device *dev, struct device_attribute *attr,
  2760. char *buf)
  2761. {
  2762. struct Scsi_Host *host = class_to_shost(dev);
  2763. MPT_SCSI_HOST *hd = shost_priv(host);
  2764. MPT_ADAPTER *ioc = hd->ioc;
  2765. return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
  2766. (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
  2767. (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
  2768. (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
  2769. ioc->facts.FWVersion.Word & 0x000000FF);
  2770. }
  2771. static DEVICE_ATTR(version_fw, S_IRUGO, mptscsih_version_fw_show, NULL);
  2772. static ssize_t
  2773. mptscsih_version_bios_show(struct device *dev, struct device_attribute *attr,
  2774. char *buf)
  2775. {
  2776. struct Scsi_Host *host = class_to_shost(dev);
  2777. MPT_SCSI_HOST *hd = shost_priv(host);
  2778. MPT_ADAPTER *ioc = hd->ioc;
  2779. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
  2780. (ioc->biosVersion & 0xFF000000) >> 24,
  2781. (ioc->biosVersion & 0x00FF0000) >> 16,
  2782. (ioc->biosVersion & 0x0000FF00) >> 8,
  2783. ioc->biosVersion & 0x000000FF);
  2784. }
  2785. static DEVICE_ATTR(version_bios, S_IRUGO, mptscsih_version_bios_show, NULL);
  2786. static ssize_t
  2787. mptscsih_version_mpi_show(struct device *dev, struct device_attribute *attr,
  2788. char *buf)
  2789. {
  2790. struct Scsi_Host *host = class_to_shost(dev);
  2791. MPT_SCSI_HOST *hd = shost_priv(host);
  2792. MPT_ADAPTER *ioc = hd->ioc;
  2793. return snprintf(buf, PAGE_SIZE, "%03x\n", ioc->facts.MsgVersion);
  2794. }
  2795. static DEVICE_ATTR(version_mpi, S_IRUGO, mptscsih_version_mpi_show, NULL);
  2796. static ssize_t
  2797. mptscsih_version_product_show(struct device *dev,
  2798. struct device_attribute *attr,
  2799. char *buf)
  2800. {
  2801. struct Scsi_Host *host = class_to_shost(dev);
  2802. MPT_SCSI_HOST *hd = shost_priv(host);
  2803. MPT_ADAPTER *ioc = hd->ioc;
  2804. return snprintf(buf, PAGE_SIZE, "%s\n", ioc->prod_name);
  2805. }
  2806. static DEVICE_ATTR(version_product, S_IRUGO,
  2807. mptscsih_version_product_show, NULL);
  2808. static ssize_t
  2809. mptscsih_version_nvdata_persistent_show(struct device *dev,
  2810. struct device_attribute *attr,
  2811. char *buf)
  2812. {
  2813. struct Scsi_Host *host = class_to_shost(dev);
  2814. MPT_SCSI_HOST *hd = shost_priv(host);
  2815. MPT_ADAPTER *ioc = hd->ioc;
  2816. return snprintf(buf, PAGE_SIZE, "%02xh\n",
  2817. ioc->nvdata_version_persistent);
  2818. }
  2819. static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
  2820. mptscsih_version_nvdata_persistent_show, NULL);
  2821. static ssize_t
  2822. mptscsih_version_nvdata_default_show(struct device *dev,
  2823. struct device_attribute *attr, char *buf)
  2824. {
  2825. struct Scsi_Host *host = class_to_shost(dev);
  2826. MPT_SCSI_HOST *hd = shost_priv(host);
  2827. MPT_ADAPTER *ioc = hd->ioc;
  2828. return snprintf(buf, PAGE_SIZE, "%02xh\n",ioc->nvdata_version_default);
  2829. }
  2830. static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
  2831. mptscsih_version_nvdata_default_show, NULL);
  2832. static ssize_t
  2833. mptscsih_board_name_show(struct device *dev, struct device_attribute *attr,
  2834. 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_name);
  2840. }
  2841. static DEVICE_ATTR(board_name, S_IRUGO, mptscsih_board_name_show, NULL);
  2842. static ssize_t
  2843. mptscsih_board_assembly_show(struct device *dev,
  2844. struct device_attribute *attr, char *buf)
  2845. {
  2846. struct Scsi_Host *host = class_to_shost(dev);
  2847. MPT_SCSI_HOST *hd = shost_priv(host);
  2848. MPT_ADAPTER *ioc = hd->ioc;
  2849. return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_assembly);
  2850. }
  2851. static DEVICE_ATTR(board_assembly, S_IRUGO,
  2852. mptscsih_board_assembly_show, NULL);
  2853. static ssize_t
  2854. mptscsih_board_tracer_show(struct device *dev, struct device_attribute *attr,
  2855. char *buf)
  2856. {
  2857. struct Scsi_Host *host = class_to_shost(dev);
  2858. MPT_SCSI_HOST *hd = shost_priv(host);
  2859. MPT_ADAPTER *ioc = hd->ioc;
  2860. return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_tracer);
  2861. }
  2862. static DEVICE_ATTR(board_tracer, S_IRUGO,
  2863. mptscsih_board_tracer_show, NULL);
  2864. static ssize_t
  2865. mptscsih_io_delay_show(struct device *dev, struct device_attribute *attr,
  2866. char *buf)
  2867. {
  2868. struct Scsi_Host *host = class_to_shost(dev);
  2869. MPT_SCSI_HOST *hd = shost_priv(host);
  2870. MPT_ADAPTER *ioc = hd->ioc;
  2871. return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
  2872. }
  2873. static DEVICE_ATTR(io_delay, S_IRUGO,
  2874. mptscsih_io_delay_show, NULL);
  2875. static ssize_t
  2876. mptscsih_device_delay_show(struct device *dev, struct device_attribute *attr,
  2877. char *buf)
  2878. {
  2879. struct Scsi_Host *host = class_to_shost(dev);
  2880. MPT_SCSI_HOST *hd = shost_priv(host);
  2881. MPT_ADAPTER *ioc = hd->ioc;
  2882. return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
  2883. }
  2884. static DEVICE_ATTR(device_delay, S_IRUGO,
  2885. mptscsih_device_delay_show, NULL);
  2886. static ssize_t
  2887. mptscsih_debug_level_show(struct device *dev, struct device_attribute *attr,
  2888. char *buf)
  2889. {
  2890. struct Scsi_Host *host = class_to_shost(dev);
  2891. MPT_SCSI_HOST *hd = shost_priv(host);
  2892. MPT_ADAPTER *ioc = hd->ioc;
  2893. return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->debug_level);
  2894. }
  2895. static ssize_t
  2896. mptscsih_debug_level_store(struct device *dev, struct device_attribute *attr,
  2897. const char *buf, size_t count)
  2898. {
  2899. struct Scsi_Host *host = class_to_shost(dev);
  2900. MPT_SCSI_HOST *hd = shost_priv(host);
  2901. MPT_ADAPTER *ioc = hd->ioc;
  2902. int val = 0;
  2903. if (sscanf(buf, "%x", &val) != 1)
  2904. return -EINVAL;
  2905. ioc->debug_level = val;
  2906. printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n",
  2907. ioc->name, ioc->debug_level);
  2908. return strlen(buf);
  2909. }
  2910. static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,
  2911. mptscsih_debug_level_show, mptscsih_debug_level_store);
  2912. struct device_attribute *mptscsih_host_attrs[] = {
  2913. &dev_attr_version_fw,
  2914. &dev_attr_version_bios,
  2915. &dev_attr_version_mpi,
  2916. &dev_attr_version_product,
  2917. &dev_attr_version_nvdata_persistent,
  2918. &dev_attr_version_nvdata_default,
  2919. &dev_attr_board_name,
  2920. &dev_attr_board_assembly,
  2921. &dev_attr_board_tracer,
  2922. &dev_attr_io_delay,
  2923. &dev_attr_device_delay,
  2924. &dev_attr_debug_level,
  2925. NULL,
  2926. };
  2927. EXPORT_SYMBOL(mptscsih_host_attrs);
  2928. EXPORT_SYMBOL(mptscsih_remove);
  2929. EXPORT_SYMBOL(mptscsih_shutdown);
  2930. #ifdef CONFIG_PM
  2931. EXPORT_SYMBOL(mptscsih_suspend);
  2932. EXPORT_SYMBOL(mptscsih_resume);
  2933. #endif
  2934. EXPORT_SYMBOL(mptscsih_proc_info);
  2935. EXPORT_SYMBOL(mptscsih_info);
  2936. EXPORT_SYMBOL(mptscsih_qcmd);
  2937. EXPORT_SYMBOL(mptscsih_slave_destroy);
  2938. EXPORT_SYMBOL(mptscsih_slave_configure);
  2939. EXPORT_SYMBOL(mptscsih_abort);
  2940. EXPORT_SYMBOL(mptscsih_dev_reset);
  2941. EXPORT_SYMBOL(mptscsih_bus_reset);
  2942. EXPORT_SYMBOL(mptscsih_host_reset);
  2943. EXPORT_SYMBOL(mptscsih_bios_param);
  2944. EXPORT_SYMBOL(mptscsih_io_done);
  2945. EXPORT_SYMBOL(mptscsih_taskmgmt_complete);
  2946. EXPORT_SYMBOL(mptscsih_scandv_complete);
  2947. EXPORT_SYMBOL(mptscsih_event_process);
  2948. EXPORT_SYMBOL(mptscsih_ioc_reset);
  2949. EXPORT_SYMBOL(mptscsih_change_queue_depth);
  2950. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/