mptscsih.c 88 KB

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