mptscsih.c 88 KB

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