mptscsih.c 90 KB

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