mptscsih.c 90 KB

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