mptscsih.c 88 KB

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