mptscsih.c 91 KB

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