mptscsih.c 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262
  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/slab.h>
  45. #include <linux/init.h>
  46. #include <linux/errno.h>
  47. #include <linux/kdev_t.h>
  48. #include <linux/blkdev.h>
  49. #include <linux/delay.h> /* for mdelay */
  50. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  51. #include <linux/reboot.h> /* notifier code */
  52. #include <linux/workqueue.h>
  53. #include <scsi/scsi.h>
  54. #include <scsi/scsi_cmnd.h>
  55. #include <scsi/scsi_device.h>
  56. #include <scsi/scsi_host.h>
  57. #include <scsi/scsi_tcq.h>
  58. #include <scsi/scsi_dbg.h>
  59. #include "mptbase.h"
  60. #include "mptscsih.h"
  61. #include "lsi/mpi_log_sas.h"
  62. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  63. #define my_NAME "Fusion MPT SCSI Host driver"
  64. #define my_VERSION MPT_LINUX_VERSION_COMMON
  65. #define MYNAM "mptscsih"
  66. MODULE_AUTHOR(MODULEAUTHOR);
  67. MODULE_DESCRIPTION(my_NAME);
  68. MODULE_LICENSE("GPL");
  69. MODULE_VERSION(my_VERSION);
  70. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  71. /*
  72. * Other private/forward protos...
  73. */
  74. struct scsi_cmnd *mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
  75. static struct scsi_cmnd * mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i);
  76. static void mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd);
  77. static int SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *scmd);
  78. int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  79. static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);
  80. int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  81. static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
  82. SCSIIORequest_t *pReq, int req_idx);
  83. static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
  84. static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
  85. int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id,
  86. u64 lun, int ctx2abort, ulong timeout);
  87. int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
  88. int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
  89. void
  90. mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code);
  91. static int mptscsih_get_completion_code(MPT_ADAPTER *ioc,
  92. MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
  93. int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  94. static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
  95. static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);
  96. static int
  97. mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,
  98. SCSITaskMgmtReply_t *pScsiTmReply);
  99. void mptscsih_remove(struct pci_dev *);
  100. void mptscsih_shutdown(struct pci_dev *);
  101. #ifdef CONFIG_PM
  102. int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
  103. int mptscsih_resume(struct pci_dev *pdev);
  104. #endif
  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 = %llu\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:%llu] "
  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 =
  654. le16_to_cpu(pScsiReply->IOCStatus);
  655. if ((ioc_status &
  656. MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  657. &&
  658. ((log_info & SAS_LOGINFO_MASK) ==
  659. SAS_LOGINFO_NEXUS_LOSS)) {
  660. VirtDevice *vdevice =
  661. sc->device->hostdata;
  662. /* flag the device as being in
  663. * device removal delay so we can
  664. * notify the midlayer to hold off
  665. * on timeout eh */
  666. if (vdevice && vdevice->
  667. vtarget &&
  668. vdevice->vtarget->
  669. raidVolume)
  670. printk(KERN_INFO
  671. "Skipping Raid Volume"
  672. "for inDMD\n");
  673. else if (vdevice &&
  674. vdevice->vtarget)
  675. vdevice->vtarget->
  676. inDMD = 1;
  677. sc->result =
  678. (DID_TRANSPORT_DISRUPTED
  679. << 16);
  680. break;
  681. }
  682. } else if (ioc->bus_type == FC) {
  683. /*
  684. * The FC IOC may kill a request for variety of
  685. * reasons, some of which may be recovered by a
  686. * retry, some which are unlikely to be
  687. * recovered. Return DID_ERROR instead of
  688. * DID_RESET to permit retry of the command,
  689. * just not an infinite number of them
  690. */
  691. sc->result = DID_ERROR << 16;
  692. break;
  693. }
  694. /*
  695. * Allow non-SAS & non-NEXUS_LOSS to drop into below code
  696. */
  697. fallthrough;
  698. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  699. /* Linux handles an unsolicited DID_RESET better
  700. * than an unsolicited DID_ABORT.
  701. */
  702. sc->result = DID_RESET << 16;
  703. break;
  704. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  705. if (ioc->bus_type == FC)
  706. sc->result = DID_ERROR << 16;
  707. else
  708. sc->result = DID_RESET << 16;
  709. break;
  710. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  711. scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
  712. if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
  713. sc->result=DID_SOFT_ERROR << 16;
  714. else /* Sufficient data transfer occurred */
  715. sc->result = (DID_OK << 16) | scsi_status;
  716. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  717. "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
  718. ioc->name, sc->result, sc->device->channel, sc->device->id));
  719. break;
  720. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  721. /*
  722. * Do upfront check for valid SenseData and give it
  723. * precedence!
  724. */
  725. sc->result = (DID_OK << 16) | scsi_status;
  726. if (!(scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
  727. /*
  728. * For an Errata on LSI53C1030
  729. * When the length of request data
  730. * and transfer data are different
  731. * with result of command (READ or VERIFY),
  732. * DID_SOFT_ERROR is set.
  733. */
  734. if (ioc->bus_type == SPI) {
  735. if ((pScsiReq->CDB[0] == READ_6 && ((pScsiReq->CDB[1] & 0x02) == 0)) ||
  736. pScsiReq->CDB[0] == READ_10 ||
  737. pScsiReq->CDB[0] == READ_12 ||
  738. (pScsiReq->CDB[0] == READ_16 &&
  739. ((pScsiReq->CDB[1] & 0x02) == 0)) ||
  740. pScsiReq->CDB[0] == VERIFY ||
  741. pScsiReq->CDB[0] == VERIFY_16) {
  742. if (scsi_bufflen(sc) !=
  743. xfer_cnt) {
  744. sc->result =
  745. DID_SOFT_ERROR << 16;
  746. printk(KERN_WARNING "Errata"
  747. "on LSI53C1030 occurred."
  748. "sc->req_bufflen=0x%02x,"
  749. "xfer_cnt=0x%02x\n",
  750. scsi_bufflen(sc),
  751. xfer_cnt);
  752. }
  753. }
  754. }
  755. if (xfer_cnt < sc->underflow) {
  756. if (scsi_status == SAM_STAT_BUSY)
  757. sc->result = SAM_STAT_BUSY;
  758. else
  759. sc->result = DID_SOFT_ERROR << 16;
  760. }
  761. if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
  762. /* What to do?
  763. */
  764. sc->result = DID_SOFT_ERROR << 16;
  765. }
  766. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  767. /* Not real sure here either... */
  768. sc->result = DID_RESET << 16;
  769. }
  770. }
  771. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  772. " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
  773. ioc->name, sc->underflow));
  774. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  775. " ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));
  776. /* Report Queue Full
  777. */
  778. if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
  779. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  780. break;
  781. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  782. scsi_set_resid(sc, 0);
  783. fallthrough;
  784. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  785. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  786. sc->result = (DID_OK << 16) | scsi_status;
  787. if (scsi_state == 0) {
  788. ;
  789. } else if (scsi_state &
  790. MPI_SCSI_STATE_AUTOSENSE_VALID) {
  791. /*
  792. * For potential trouble on LSI53C1030.
  793. * (date:2007.xx.)
  794. * It is checked whether the length of
  795. * request data is equal to
  796. * the length of transfer and residual.
  797. * MEDIUM_ERROR is set by incorrect data.
  798. */
  799. if ((ioc->bus_type == SPI) &&
  800. (sc->sense_buffer[2] & 0x20)) {
  801. u32 difftransfer;
  802. difftransfer =
  803. sc->sense_buffer[3] << 24 |
  804. sc->sense_buffer[4] << 16 |
  805. sc->sense_buffer[5] << 8 |
  806. sc->sense_buffer[6];
  807. if (((sc->sense_buffer[3] & 0x80) ==
  808. 0x80) && (scsi_bufflen(sc)
  809. != xfer_cnt)) {
  810. sc->sense_buffer[2] =
  811. MEDIUM_ERROR;
  812. sc->sense_buffer[12] = 0xff;
  813. sc->sense_buffer[13] = 0xff;
  814. printk(KERN_WARNING"Errata"
  815. "on LSI53C1030 occurred."
  816. "sc->req_bufflen=0x%02x,"
  817. "xfer_cnt=0x%02x\n" ,
  818. scsi_bufflen(sc),
  819. xfer_cnt);
  820. }
  821. if (((sc->sense_buffer[3] & 0x80)
  822. != 0x80) &&
  823. (scsi_bufflen(sc) !=
  824. xfer_cnt + difftransfer)) {
  825. sc->sense_buffer[2] =
  826. MEDIUM_ERROR;
  827. sc->sense_buffer[12] = 0xff;
  828. sc->sense_buffer[13] = 0xff;
  829. printk(KERN_WARNING
  830. "Errata on LSI53C1030 occurred"
  831. "sc->req_bufflen=0x%02x,"
  832. " xfer_cnt=0x%02x,"
  833. "difftransfer=0x%02x\n",
  834. scsi_bufflen(sc),
  835. xfer_cnt,
  836. difftransfer);
  837. }
  838. }
  839. /*
  840. * If running against circa 200003dd 909 MPT f/w,
  841. * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
  842. * (QUEUE_FULL) returned from device! --> get 0x0000?128
  843. * and with SenseBytes set to 0.
  844. */
  845. if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
  846. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  847. }
  848. else if (scsi_state &
  849. (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
  850. ) {
  851. /*
  852. * What to do?
  853. */
  854. sc->result = DID_SOFT_ERROR << 16;
  855. }
  856. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  857. /* Not real sure here either... */
  858. sc->result = DID_RESET << 16;
  859. }
  860. else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
  861. /* Device Inq. data indicates that it supports
  862. * QTags, but rejects QTag messages.
  863. * This command completed OK.
  864. *
  865. * Not real sure here either so do nothing... */
  866. }
  867. if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
  868. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  869. /* Add handling of:
  870. * Reservation Conflict, Busy,
  871. * Command Terminated, CHECK
  872. */
  873. break;
  874. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  875. sc->result = DID_SOFT_ERROR << 16;
  876. break;
  877. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  878. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  879. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  880. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  881. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  882. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  883. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  884. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  885. default:
  886. /*
  887. * What to do?
  888. */
  889. sc->result = DID_SOFT_ERROR << 16;
  890. break;
  891. } /* switch(status) */
  892. #ifdef CONFIG_FUSION_LOGGING
  893. if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY))
  894. mptscsih_info_scsiio(ioc, sc, pScsiReply);
  895. #endif
  896. } /* end of address reply case */
  897. out:
  898. /* Unmap the DMA buffers, if any. */
  899. scsi_dma_unmap(sc);
  900. sc->scsi_done(sc); /* Issue the command callback */
  901. /* Free Chain buffers */
  902. mptscsih_freeChainBuffers(ioc, req_idx);
  903. return 1;
  904. }
  905. /*
  906. * mptscsih_flush_running_cmds - For each command found, search
  907. * Scsi_Host instance taskQ and reply to OS.
  908. * Called only if recovering from a FW reload.
  909. * @hd: Pointer to a SCSI HOST structure
  910. *
  911. * Returns: None.
  912. *
  913. * Must be called while new I/Os are being queued.
  914. */
  915. void
  916. mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
  917. {
  918. MPT_ADAPTER *ioc = hd->ioc;
  919. struct scsi_cmnd *sc;
  920. SCSIIORequest_t *mf = NULL;
  921. int ii;
  922. int channel, id;
  923. for (ii= 0; ii < ioc->req_depth; ii++) {
  924. sc = mptscsih_getclear_scsi_lookup(ioc, ii);
  925. if (!sc)
  926. continue;
  927. mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
  928. if (!mf)
  929. continue;
  930. channel = mf->Bus;
  931. id = mf->TargetID;
  932. mptscsih_freeChainBuffers(ioc, ii);
  933. mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
  934. if ((unsigned char *)mf != sc->host_scribble)
  935. continue;
  936. scsi_dma_unmap(sc);
  937. sc->result = DID_RESET << 16;
  938. sc->host_scribble = NULL;
  939. dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT
  940. "completing cmds: fw_channel %d, fw_id %d, sc=%p, mf = %p, "
  941. "idx=%x\n", ioc->name, channel, id, sc, mf, ii));
  942. sc->scsi_done(sc);
  943. }
  944. }
  945. EXPORT_SYMBOL(mptscsih_flush_running_cmds);
  946. /*
  947. * mptscsih_search_running_cmds - Delete any commands associated
  948. * with the specified target and lun. Function called only
  949. * when a lun is disable by mid-layer.
  950. * Do NOT access the referenced scsi_cmnd structure or
  951. * members. Will cause either a paging or NULL ptr error.
  952. * (BUT, BUT, BUT, the code does reference it! - mdr)
  953. * @hd: Pointer to a SCSI HOST structure
  954. * @vdevice: per device private data
  955. *
  956. * Returns: None.
  957. *
  958. * Called from slave_destroy.
  959. */
  960. static void
  961. mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
  962. {
  963. SCSIIORequest_t *mf = NULL;
  964. int ii;
  965. struct scsi_cmnd *sc;
  966. struct scsi_lun lun;
  967. MPT_ADAPTER *ioc = hd->ioc;
  968. unsigned long flags;
  969. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  970. for (ii = 0; ii < ioc->req_depth; ii++) {
  971. if ((sc = ioc->ScsiLookup[ii]) != NULL) {
  972. mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
  973. if (mf == NULL)
  974. continue;
  975. /* If the device is a hidden raid component, then its
  976. * expected that the mf->function will be RAID_SCSI_IO
  977. */
  978. if (vdevice->vtarget->tflags &
  979. MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function !=
  980. MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
  981. continue;
  982. int_to_scsilun(vdevice->lun, &lun);
  983. if ((mf->Bus != vdevice->vtarget->channel) ||
  984. (mf->TargetID != vdevice->vtarget->id) ||
  985. memcmp(lun.scsi_lun, mf->LUN, 8))
  986. continue;
  987. if ((unsigned char *)mf != sc->host_scribble)
  988. continue;
  989. ioc->ScsiLookup[ii] = NULL;
  990. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  991. mptscsih_freeChainBuffers(ioc, ii);
  992. mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
  993. scsi_dma_unmap(sc);
  994. sc->host_scribble = NULL;
  995. sc->result = DID_NO_CONNECT << 16;
  996. dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device,
  997. MYIOC_s_FMT "completing cmds: fw_channel %d, "
  998. "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name,
  999. vdevice->vtarget->channel, vdevice->vtarget->id,
  1000. sc, mf, ii));
  1001. sc->scsi_done(sc);
  1002. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  1003. }
  1004. }
  1005. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  1006. return;
  1007. }
  1008. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1009. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1010. /*
  1011. * mptscsih_report_queue_full - Report QUEUE_FULL status returned
  1012. * from a SCSI target device.
  1013. * @sc: Pointer to scsi_cmnd structure
  1014. * @pScsiReply: Pointer to SCSIIOReply_t
  1015. * @pScsiReq: Pointer to original SCSI request
  1016. *
  1017. * This routine periodically reports QUEUE_FULL status returned from a
  1018. * SCSI target device. It reports this to the console via kernel
  1019. * printk() API call, not more than once every 10 seconds.
  1020. */
  1021. static void
  1022. mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
  1023. {
  1024. long time = jiffies;
  1025. MPT_SCSI_HOST *hd;
  1026. MPT_ADAPTER *ioc;
  1027. if (sc->device == NULL)
  1028. return;
  1029. if (sc->device->host == NULL)
  1030. return;
  1031. if ((hd = shost_priv(sc->device->host)) == NULL)
  1032. return;
  1033. ioc = hd->ioc;
  1034. if (time - hd->last_queue_full > 10 * HZ) {
  1035. dprintk(ioc, printk(MYIOC_s_WARN_FMT "Device (%d:%d:%llu) reported QUEUE_FULL!\n",
  1036. ioc->name, 0, sc->device->id, sc->device->lun));
  1037. hd->last_queue_full = time;
  1038. }
  1039. }
  1040. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1041. /*
  1042. * mptscsih_remove - Removed scsi devices
  1043. * @pdev: Pointer to pci_dev structure
  1044. *
  1045. *
  1046. */
  1047. void
  1048. mptscsih_remove(struct pci_dev *pdev)
  1049. {
  1050. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1051. struct Scsi_Host *host = ioc->sh;
  1052. MPT_SCSI_HOST *hd;
  1053. int sz1;
  1054. if (host == NULL)
  1055. hd = NULL;
  1056. else
  1057. hd = shost_priv(host);
  1058. mptscsih_shutdown(pdev);
  1059. sz1=0;
  1060. if (ioc->ScsiLookup != NULL) {
  1061. sz1 = ioc->req_depth * sizeof(void *);
  1062. kfree(ioc->ScsiLookup);
  1063. ioc->ScsiLookup = NULL;
  1064. }
  1065. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1066. "Free'd ScsiLookup (%d) memory\n",
  1067. ioc->name, sz1));
  1068. if (hd)
  1069. kfree(hd->info_kbuf);
  1070. /* NULL the Scsi_Host pointer
  1071. */
  1072. ioc->sh = NULL;
  1073. if (host)
  1074. scsi_host_put(host);
  1075. mpt_detach(pdev);
  1076. }
  1077. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1078. /*
  1079. * mptscsih_shutdown - reboot notifier
  1080. *
  1081. */
  1082. void
  1083. mptscsih_shutdown(struct pci_dev *pdev)
  1084. {
  1085. }
  1086. #ifdef CONFIG_PM
  1087. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1088. /*
  1089. * mptscsih_suspend - Fusion MPT scsi driver suspend routine.
  1090. *
  1091. *
  1092. */
  1093. int
  1094. mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
  1095. {
  1096. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1097. scsi_block_requests(ioc->sh);
  1098. flush_scheduled_work();
  1099. mptscsih_shutdown(pdev);
  1100. return mpt_suspend(pdev,state);
  1101. }
  1102. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1103. /*
  1104. * mptscsih_resume - Fusion MPT scsi driver resume routine.
  1105. *
  1106. *
  1107. */
  1108. int
  1109. mptscsih_resume(struct pci_dev *pdev)
  1110. {
  1111. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1112. int rc;
  1113. rc = mpt_resume(pdev);
  1114. scsi_unblock_requests(ioc->sh);
  1115. return rc;
  1116. }
  1117. #endif
  1118. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1119. /**
  1120. * mptscsih_info - Return information about MPT adapter
  1121. * @SChost: Pointer to Scsi_Host structure
  1122. *
  1123. * (linux scsi_host_template.info routine)
  1124. *
  1125. * Returns pointer to buffer where information was written.
  1126. */
  1127. const char *
  1128. mptscsih_info(struct Scsi_Host *SChost)
  1129. {
  1130. MPT_SCSI_HOST *h;
  1131. int size = 0;
  1132. h = shost_priv(SChost);
  1133. if (h->info_kbuf == NULL)
  1134. if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
  1135. return h->info_kbuf;
  1136. h->info_kbuf[0] = '\0';
  1137. mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
  1138. h->info_kbuf[size-1] = '\0';
  1139. return h->info_kbuf;
  1140. }
  1141. int mptscsih_show_info(struct seq_file *m, struct Scsi_Host *host)
  1142. {
  1143. MPT_SCSI_HOST *hd = shost_priv(host);
  1144. MPT_ADAPTER *ioc = hd->ioc;
  1145. seq_printf(m, "%s: %s, ", ioc->name, ioc->prod_name);
  1146. seq_printf(m, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
  1147. seq_printf(m, "Ports=%d, ", ioc->facts.NumberOfPorts);
  1148. seq_printf(m, "MaxQ=%d\n", ioc->req_depth);
  1149. return 0;
  1150. }
  1151. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1152. #define ADD_INDEX_LOG(req_ent) do { } while(0)
  1153. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1154. /**
  1155. * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
  1156. * @SCpnt: Pointer to scsi_cmnd structure
  1157. *
  1158. * (linux scsi_host_template.queuecommand routine)
  1159. * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
  1160. * from a linux scsi_cmnd request and send it to the IOC.
  1161. *
  1162. * Returns 0. (rtn value discarded by linux scsi mid-layer)
  1163. */
  1164. int
  1165. mptscsih_qcmd(struct scsi_cmnd *SCpnt)
  1166. {
  1167. MPT_SCSI_HOST *hd;
  1168. MPT_FRAME_HDR *mf;
  1169. SCSIIORequest_t *pScsiReq;
  1170. VirtDevice *vdevice = SCpnt->device->hostdata;
  1171. u32 datalen;
  1172. u32 scsictl;
  1173. u32 scsidir;
  1174. u32 cmd_len;
  1175. int my_idx;
  1176. int ii;
  1177. MPT_ADAPTER *ioc;
  1178. hd = shost_priv(SCpnt->device->host);
  1179. ioc = hd->ioc;
  1180. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p\n",
  1181. ioc->name, SCpnt));
  1182. if (ioc->taskmgmt_quiesce_io)
  1183. return SCSI_MLQUEUE_HOST_BUSY;
  1184. /*
  1185. * Put together a MPT SCSI request...
  1186. */
  1187. if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
  1188. dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
  1189. ioc->name));
  1190. return SCSI_MLQUEUE_HOST_BUSY;
  1191. }
  1192. pScsiReq = (SCSIIORequest_t *) mf;
  1193. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  1194. ADD_INDEX_LOG(my_idx);
  1195. /* TUR's being issued with scsictl=0x02000000 (DATA_IN)!
  1196. * Seems we may receive a buffer (datalen>0) even when there
  1197. * will be no data transfer! GRRRRR...
  1198. */
  1199. if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
  1200. datalen = scsi_bufflen(SCpnt);
  1201. scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
  1202. } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
  1203. datalen = scsi_bufflen(SCpnt);
  1204. scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
  1205. } else {
  1206. datalen = 0;
  1207. scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
  1208. }
  1209. /* Default to untagged. Once a target structure has been allocated,
  1210. * use the Inquiry data to determine if device supports tagged.
  1211. */
  1212. if ((vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES) &&
  1213. SCpnt->device->tagged_supported)
  1214. scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
  1215. else
  1216. scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
  1217. /* Use the above information to set up the message frame
  1218. */
  1219. pScsiReq->TargetID = (u8) vdevice->vtarget->id;
  1220. pScsiReq->Bus = vdevice->vtarget->channel;
  1221. pScsiReq->ChainOffset = 0;
  1222. if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
  1223. pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  1224. else
  1225. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  1226. pScsiReq->CDBLength = SCpnt->cmd_len;
  1227. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1228. pScsiReq->Reserved = 0;
  1229. pScsiReq->MsgFlags = mpt_msg_flags(ioc);
  1230. int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);
  1231. pScsiReq->Control = cpu_to_le32(scsictl);
  1232. /*
  1233. * Write SCSI CDB into the message
  1234. */
  1235. cmd_len = SCpnt->cmd_len;
  1236. for (ii=0; ii < cmd_len; ii++)
  1237. pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
  1238. for (ii=cmd_len; ii < 16; ii++)
  1239. pScsiReq->CDB[ii] = 0;
  1240. /* DataLength */
  1241. pScsiReq->DataLength = cpu_to_le32(datalen);
  1242. /* SenseBuffer low address */
  1243. pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
  1244. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  1245. /* Now add the SG list
  1246. * Always have a SGE even if null length.
  1247. */
  1248. if (datalen == 0) {
  1249. /* Add a NULL SGE */
  1250. ioc->add_sge((char *)&pScsiReq->SGL,
  1251. MPT_SGE_FLAGS_SSIMPLE_READ | 0,
  1252. (dma_addr_t) -1);
  1253. } else {
  1254. /* Add a 32 or 64 bit SGE */
  1255. if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
  1256. goto fail;
  1257. }
  1258. SCpnt->host_scribble = (unsigned char *)mf;
  1259. mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt);
  1260. mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  1261. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
  1262. ioc->name, SCpnt, mf, my_idx));
  1263. DBG_DUMP_REQUEST_FRAME(ioc, (u32 *)mf);
  1264. return 0;
  1265. fail:
  1266. mptscsih_freeChainBuffers(ioc, my_idx);
  1267. mpt_free_msg_frame(ioc, mf);
  1268. return SCSI_MLQUEUE_HOST_BUSY;
  1269. }
  1270. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1271. /*
  1272. * mptscsih_freeChainBuffers - Function to free chain buffers associated
  1273. * with a SCSI IO request
  1274. * @hd: Pointer to the MPT_SCSI_HOST instance
  1275. * @req_idx: Index of the SCSI IO request frame.
  1276. *
  1277. * Called if SG chain buffer allocation fails and mptscsih callbacks.
  1278. * No return.
  1279. */
  1280. static void
  1281. mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
  1282. {
  1283. MPT_FRAME_HDR *chain;
  1284. unsigned long flags;
  1285. int chain_idx;
  1286. int next;
  1287. /* Get the first chain index and reset
  1288. * tracker state.
  1289. */
  1290. chain_idx = ioc->ReqToChain[req_idx];
  1291. ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
  1292. while (chain_idx != MPT_HOST_NO_CHAIN) {
  1293. /* Save the next chain buffer index */
  1294. next = ioc->ChainToChain[chain_idx];
  1295. /* Free this chain buffer and reset
  1296. * tracker
  1297. */
  1298. ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
  1299. chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
  1300. + (chain_idx * ioc->req_sz));
  1301. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1302. list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
  1303. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1304. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FreeChainBuffers (index %d)\n",
  1305. ioc->name, chain_idx));
  1306. /* handle next */
  1307. chain_idx = next;
  1308. }
  1309. return;
  1310. }
  1311. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1312. /*
  1313. * Reset Handling
  1314. */
  1315. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1316. /**
  1317. * mptscsih_IssueTaskMgmt - Generic send Task Management function.
  1318. * @hd: Pointer to MPT_SCSI_HOST structure
  1319. * @type: Task Management type
  1320. * @channel: channel number for task management
  1321. * @id: Logical Target ID for reset (if appropriate)
  1322. * @lun: Logical Unit for reset (if appropriate)
  1323. * @ctx2abort: Context for the task to be aborted (if appropriate)
  1324. * @timeout: timeout for task management control
  1325. *
  1326. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  1327. * or a non-interrupt thread. In the former, must not call schedule().
  1328. *
  1329. * Not all fields are meaningfull for all task types.
  1330. *
  1331. * Returns 0 for SUCCESS, or FAILED.
  1332. *
  1333. **/
  1334. int
  1335. mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, u64 lun,
  1336. int ctx2abort, ulong timeout)
  1337. {
  1338. MPT_FRAME_HDR *mf;
  1339. SCSITaskMgmt_t *pScsiTm;
  1340. int ii;
  1341. int retval;
  1342. MPT_ADAPTER *ioc = hd->ioc;
  1343. u8 issue_hard_reset;
  1344. u32 ioc_raw_state;
  1345. unsigned long time_count;
  1346. issue_hard_reset = 0;
  1347. ioc_raw_state = mpt_GetIocState(ioc, 0);
  1348. if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
  1349. printk(MYIOC_s_WARN_FMT
  1350. "TaskMgmt type=%x: IOC Not operational (0x%x)!\n",
  1351. ioc->name, type, ioc_raw_state);
  1352. printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
  1353. ioc->name, __func__);
  1354. if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
  1355. printk(MYIOC_s_WARN_FMT "TaskMgmt HardReset "
  1356. "FAILED!!\n", ioc->name);
  1357. return 0;
  1358. }
  1359. /* DOORBELL ACTIVE check is not required if
  1360. * MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q is supported.
  1361. */
  1362. if (!((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q)
  1363. && (ioc->facts.MsgVersion >= MPI_VERSION_01_05)) &&
  1364. (ioc_raw_state & MPI_DOORBELL_ACTIVE)) {
  1365. printk(MYIOC_s_WARN_FMT
  1366. "TaskMgmt type=%x: ioc_state: "
  1367. "DOORBELL_ACTIVE (0x%x)!\n",
  1368. ioc->name, type, ioc_raw_state);
  1369. return FAILED;
  1370. }
  1371. mutex_lock(&ioc->taskmgmt_cmds.mutex);
  1372. if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
  1373. mf = NULL;
  1374. retval = FAILED;
  1375. goto out;
  1376. }
  1377. /* Return Fail to calling function if no message frames available.
  1378. */
  1379. if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
  1380. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1381. "TaskMgmt no msg frames!!\n", ioc->name));
  1382. retval = FAILED;
  1383. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1384. goto out;
  1385. }
  1386. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
  1387. ioc->name, mf));
  1388. /* Format the Request
  1389. */
  1390. pScsiTm = (SCSITaskMgmt_t *) mf;
  1391. pScsiTm->TargetID = id;
  1392. pScsiTm->Bus = channel;
  1393. pScsiTm->ChainOffset = 0;
  1394. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  1395. pScsiTm->Reserved = 0;
  1396. pScsiTm->TaskType = type;
  1397. pScsiTm->Reserved1 = 0;
  1398. pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
  1399. ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
  1400. int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
  1401. for (ii=0; ii < 7; ii++)
  1402. pScsiTm->Reserved2[ii] = 0;
  1403. pScsiTm->TaskMsgContext = ctx2abort;
  1404. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt: ctx2abort (0x%08x) "
  1405. "task_type = 0x%02X, timeout = %ld\n", ioc->name, ctx2abort,
  1406. type, timeout));
  1407. DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);
  1408. INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
  1409. time_count = jiffies;
  1410. if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
  1411. (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
  1412. mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
  1413. else {
  1414. retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
  1415. sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
  1416. if (retval) {
  1417. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1418. "TaskMgmt handshake FAILED!(mf=%p, rc=%d) \n",
  1419. ioc->name, mf, retval));
  1420. mpt_free_msg_frame(ioc, mf);
  1421. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1422. goto out;
  1423. }
  1424. }
  1425. wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
  1426. timeout*HZ);
  1427. if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  1428. retval = FAILED;
  1429. dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
  1430. "TaskMgmt TIMED OUT!(mf=%p)\n", ioc->name, mf));
  1431. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1432. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
  1433. goto out;
  1434. issue_hard_reset = 1;
  1435. goto out;
  1436. }
  1437. retval = mptscsih_taskmgmt_reply(ioc, type,
  1438. (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply);
  1439. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1440. "TaskMgmt completed (%d seconds)\n",
  1441. ioc->name, jiffies_to_msecs(jiffies - time_count)/1000));
  1442. out:
  1443. CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
  1444. if (issue_hard_reset) {
  1445. printk(MYIOC_s_WARN_FMT
  1446. "Issuing Reset from %s!! doorbell=0x%08x\n",
  1447. ioc->name, __func__, mpt_GetIocState(ioc, 0));
  1448. retval = (ioc->bus_type == SAS) ?
  1449. mpt_HardResetHandler(ioc, CAN_SLEEP) :
  1450. mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  1451. mpt_free_msg_frame(ioc, mf);
  1452. }
  1453. retval = (retval == 0) ? 0 : FAILED;
  1454. mutex_unlock(&ioc->taskmgmt_cmds.mutex);
  1455. return retval;
  1456. }
  1457. EXPORT_SYMBOL(mptscsih_IssueTaskMgmt);
  1458. static int
  1459. mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
  1460. {
  1461. switch (ioc->bus_type) {
  1462. case FC:
  1463. return 40;
  1464. case SAS:
  1465. return 30;
  1466. case SPI:
  1467. default:
  1468. return 10;
  1469. }
  1470. }
  1471. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1472. /**
  1473. * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
  1474. * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
  1475. *
  1476. * (linux scsi_host_template.eh_abort_handler routine)
  1477. *
  1478. * Returns SUCCESS or FAILED.
  1479. **/
  1480. int
  1481. mptscsih_abort(struct scsi_cmnd * SCpnt)
  1482. {
  1483. MPT_SCSI_HOST *hd;
  1484. MPT_FRAME_HDR *mf;
  1485. u32 ctx2abort;
  1486. int scpnt_idx;
  1487. int retval;
  1488. VirtDevice *vdevice;
  1489. MPT_ADAPTER *ioc;
  1490. /* If we can't locate our host adapter structure, return FAILED status.
  1491. */
  1492. if ((hd = shost_priv(SCpnt->device->host)) == NULL) {
  1493. SCpnt->result = DID_RESET << 16;
  1494. SCpnt->scsi_done(SCpnt);
  1495. printk(KERN_ERR MYNAM ": task abort: "
  1496. "can't locate host! (sc=%p)\n", SCpnt);
  1497. return FAILED;
  1498. }
  1499. ioc = hd->ioc;
  1500. printk(MYIOC_s_INFO_FMT "attempting task abort! (sc=%p)\n",
  1501. ioc->name, SCpnt);
  1502. scsi_print_command(SCpnt);
  1503. vdevice = SCpnt->device->hostdata;
  1504. if (!vdevice || !vdevice->vtarget) {
  1505. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1506. "task abort: device has been deleted (sc=%p)\n",
  1507. ioc->name, SCpnt));
  1508. SCpnt->result = DID_NO_CONNECT << 16;
  1509. SCpnt->scsi_done(SCpnt);
  1510. retval = SUCCESS;
  1511. goto out;
  1512. }
  1513. /* Task aborts are not supported for hidden raid components.
  1514. */
  1515. if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1516. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1517. "task abort: hidden raid component (sc=%p)\n",
  1518. ioc->name, SCpnt));
  1519. SCpnt->result = DID_RESET << 16;
  1520. retval = FAILED;
  1521. goto out;
  1522. }
  1523. /* Task aborts are not supported for volumes.
  1524. */
  1525. if (vdevice->vtarget->raidVolume) {
  1526. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1527. "task abort: raid volume (sc=%p)\n",
  1528. ioc->name, SCpnt));
  1529. SCpnt->result = DID_RESET << 16;
  1530. retval = FAILED;
  1531. goto out;
  1532. }
  1533. /* Find this command
  1534. */
  1535. if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
  1536. /* Cmd not found in ScsiLookup.
  1537. * Do OS callback.
  1538. */
  1539. SCpnt->result = DID_RESET << 16;
  1540. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: "
  1541. "Command not in the active list! (sc=%p)\n", ioc->name,
  1542. SCpnt));
  1543. retval = SUCCESS;
  1544. goto out;
  1545. }
  1546. if (ioc->timeouts < -1)
  1547. ioc->timeouts++;
  1548. if (mpt_fwfault_debug)
  1549. mpt_halt_firmware(ioc);
  1550. /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
  1551. * (the IO to be ABORT'd)
  1552. *
  1553. * NOTE: Since we do not byteswap MsgContext, we do not
  1554. * swap it here either. It is an opaque cookie to
  1555. * the controller, so it does not matter. -DaveM
  1556. */
  1557. mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);
  1558. ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
  1559. retval = mptscsih_IssueTaskMgmt(hd,
  1560. MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
  1561. vdevice->vtarget->channel,
  1562. vdevice->vtarget->id, vdevice->lun,
  1563. ctx2abort, mptscsih_get_tm_timeout(ioc));
  1564. if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx) {
  1565. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1566. "task abort: command still in active list! (sc=%p)\n",
  1567. ioc->name, SCpnt));
  1568. retval = FAILED;
  1569. } else {
  1570. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1571. "task abort: command cleared from active list! (sc=%p)\n",
  1572. ioc->name, SCpnt));
  1573. retval = SUCCESS;
  1574. }
  1575. out:
  1576. printk(MYIOC_s_INFO_FMT "task abort: %s (rv=%04x) (sc=%p)\n",
  1577. ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), retval,
  1578. SCpnt);
  1579. return retval;
  1580. }
  1581. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1582. /**
  1583. * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
  1584. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1585. *
  1586. * (linux scsi_host_template.eh_dev_reset_handler routine)
  1587. *
  1588. * Returns SUCCESS or FAILED.
  1589. **/
  1590. int
  1591. mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
  1592. {
  1593. MPT_SCSI_HOST *hd;
  1594. int retval;
  1595. VirtDevice *vdevice;
  1596. MPT_ADAPTER *ioc;
  1597. /* If we can't locate our host adapter structure, return FAILED status.
  1598. */
  1599. if ((hd = shost_priv(SCpnt->device->host)) == NULL){
  1600. printk(KERN_ERR MYNAM ": target reset: "
  1601. "Can't locate host! (sc=%p)\n", SCpnt);
  1602. return FAILED;
  1603. }
  1604. ioc = hd->ioc;
  1605. printk(MYIOC_s_INFO_FMT "attempting target reset! (sc=%p)\n",
  1606. ioc->name, SCpnt);
  1607. scsi_print_command(SCpnt);
  1608. vdevice = SCpnt->device->hostdata;
  1609. if (!vdevice || !vdevice->vtarget) {
  1610. retval = 0;
  1611. goto out;
  1612. }
  1613. /* Target reset to hidden raid component is not supported
  1614. */
  1615. if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1616. retval = FAILED;
  1617. goto out;
  1618. }
  1619. retval = mptscsih_IssueTaskMgmt(hd,
  1620. MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
  1621. vdevice->vtarget->channel,
  1622. vdevice->vtarget->id, 0, 0,
  1623. mptscsih_get_tm_timeout(ioc));
  1624. out:
  1625. printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",
  1626. ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1627. if (retval == 0)
  1628. return SUCCESS;
  1629. else
  1630. return FAILED;
  1631. }
  1632. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1633. /**
  1634. * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
  1635. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1636. *
  1637. * (linux scsi_host_template.eh_bus_reset_handler routine)
  1638. *
  1639. * Returns SUCCESS or FAILED.
  1640. **/
  1641. int
  1642. mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
  1643. {
  1644. MPT_SCSI_HOST *hd;
  1645. int retval;
  1646. VirtDevice *vdevice;
  1647. MPT_ADAPTER *ioc;
  1648. /* If we can't locate our host adapter structure, return FAILED status.
  1649. */
  1650. if ((hd = shost_priv(SCpnt->device->host)) == NULL){
  1651. printk(KERN_ERR MYNAM ": bus reset: "
  1652. "Can't locate host! (sc=%p)\n", SCpnt);
  1653. return FAILED;
  1654. }
  1655. ioc = hd->ioc;
  1656. printk(MYIOC_s_INFO_FMT "attempting bus reset! (sc=%p)\n",
  1657. ioc->name, SCpnt);
  1658. scsi_print_command(SCpnt);
  1659. if (ioc->timeouts < -1)
  1660. ioc->timeouts++;
  1661. vdevice = SCpnt->device->hostdata;
  1662. if (!vdevice || !vdevice->vtarget)
  1663. return SUCCESS;
  1664. retval = mptscsih_IssueTaskMgmt(hd,
  1665. MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  1666. vdevice->vtarget->channel, 0, 0, 0,
  1667. mptscsih_get_tm_timeout(ioc));
  1668. printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n",
  1669. ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1670. if (retval == 0)
  1671. return SUCCESS;
  1672. else
  1673. return FAILED;
  1674. }
  1675. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1676. /**
  1677. * mptscsih_host_reset - Perform a SCSI host adapter RESET (new_eh variant)
  1678. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1679. *
  1680. * (linux scsi_host_template.eh_host_reset_handler routine)
  1681. *
  1682. * Returns SUCCESS or FAILED.
  1683. */
  1684. int
  1685. mptscsih_host_reset(struct scsi_cmnd *SCpnt)
  1686. {
  1687. MPT_SCSI_HOST * hd;
  1688. int status = SUCCESS;
  1689. MPT_ADAPTER *ioc;
  1690. int retval;
  1691. /* If we can't locate the host to reset, then we failed. */
  1692. if ((hd = shost_priv(SCpnt->device->host)) == NULL){
  1693. printk(KERN_ERR MYNAM ": host reset: "
  1694. "Can't locate host! (sc=%p)\n", SCpnt);
  1695. return FAILED;
  1696. }
  1697. /* make sure we have no outstanding commands at this stage */
  1698. mptscsih_flush_running_cmds(hd);
  1699. ioc = hd->ioc;
  1700. printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n",
  1701. ioc->name, SCpnt);
  1702. /* If our attempts to reset the host failed, then return a failed
  1703. * status. The host will be taken off line by the SCSI mid-layer.
  1704. */
  1705. retval = mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  1706. if (retval < 0)
  1707. status = FAILED;
  1708. else
  1709. status = SUCCESS;
  1710. printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n",
  1711. ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1712. return status;
  1713. }
  1714. static int
  1715. mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,
  1716. SCSITaskMgmtReply_t *pScsiTmReply)
  1717. {
  1718. u16 iocstatus;
  1719. u32 termination_count;
  1720. int retval;
  1721. if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
  1722. retval = FAILED;
  1723. goto out;
  1724. }
  1725. DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);
  1726. iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  1727. termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
  1728. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1729. "TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n"
  1730. "\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n"
  1731. "\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->Bus,
  1732. pScsiTmReply->TargetID, type, le16_to_cpu(pScsiTmReply->IOCStatus),
  1733. le32_to_cpu(pScsiTmReply->IOCLogInfo), pScsiTmReply->ResponseCode,
  1734. termination_count));
  1735. if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
  1736. pScsiTmReply->ResponseCode)
  1737. mptscsih_taskmgmt_response_code(ioc,
  1738. pScsiTmReply->ResponseCode);
  1739. if (iocstatus == MPI_IOCSTATUS_SUCCESS) {
  1740. retval = 0;
  1741. goto out;
  1742. }
  1743. retval = FAILED;
  1744. if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
  1745. if (termination_count == 1)
  1746. retval = 0;
  1747. goto out;
  1748. }
  1749. if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
  1750. iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
  1751. retval = 0;
  1752. out:
  1753. return retval;
  1754. }
  1755. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1756. void
  1757. mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
  1758. {
  1759. char *desc;
  1760. switch (response_code) {
  1761. case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:
  1762. desc = "The task completed.";
  1763. break;
  1764. case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:
  1765. desc = "The IOC received an invalid frame status.";
  1766. break;
  1767. case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
  1768. desc = "The task type is not supported.";
  1769. break;
  1770. case MPI_SCSITASKMGMT_RSP_TM_FAILED:
  1771. desc = "The requested task failed.";
  1772. break;
  1773. case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:
  1774. desc = "The task completed successfully.";
  1775. break;
  1776. case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:
  1777. desc = "The LUN request is invalid.";
  1778. break;
  1779. case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
  1780. desc = "The task is in the IOC queue and has not been sent to target.";
  1781. break;
  1782. default:
  1783. desc = "unknown";
  1784. break;
  1785. }
  1786. printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n",
  1787. ioc->name, response_code, desc);
  1788. }
  1789. EXPORT_SYMBOL(mptscsih_taskmgmt_response_code);
  1790. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1791. /**
  1792. * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
  1793. * @ioc: Pointer to MPT_ADAPTER structure
  1794. * @mf: Pointer to SCSI task mgmt request frame
  1795. * @mr: Pointer to SCSI task mgmt reply frame
  1796. *
  1797. * This routine is called from mptbase.c::mpt_interrupt() at the completion
  1798. * of any SCSI task management request.
  1799. * This routine is registered with the MPT (base) driver at driver
  1800. * load/init time via the mpt_register() API call.
  1801. *
  1802. * Returns 1 indicating alloc'd request frame ptr should be freed.
  1803. **/
  1804. int
  1805. mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
  1806. MPT_FRAME_HDR *mr)
  1807. {
  1808. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1809. "TaskMgmt completed (mf=%p, mr=%p)\n", ioc->name, mf, mr));
  1810. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  1811. if (!mr)
  1812. goto out;
  1813. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  1814. memcpy(ioc->taskmgmt_cmds.reply, mr,
  1815. min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
  1816. out:
  1817. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
  1818. mpt_clear_taskmgmt_in_progress_flag(ioc);
  1819. ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  1820. complete(&ioc->taskmgmt_cmds.done);
  1821. if (ioc->bus_type == SAS)
  1822. ioc->schedule_target_reset(ioc);
  1823. return 1;
  1824. }
  1825. return 0;
  1826. }
  1827. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1828. /*
  1829. * This is anyones guess quite frankly.
  1830. */
  1831. int
  1832. mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
  1833. sector_t capacity, int geom[])
  1834. {
  1835. int heads;
  1836. int sectors;
  1837. sector_t cylinders;
  1838. ulong dummy;
  1839. heads = 64;
  1840. sectors = 32;
  1841. dummy = heads * sectors;
  1842. cylinders = capacity;
  1843. sector_div(cylinders,dummy);
  1844. /*
  1845. * Handle extended translation size for logical drives
  1846. * > 1Gb
  1847. */
  1848. if ((ulong)capacity >= 0x200000) {
  1849. heads = 255;
  1850. sectors = 63;
  1851. dummy = heads * sectors;
  1852. cylinders = capacity;
  1853. sector_div(cylinders,dummy);
  1854. }
  1855. /* return result */
  1856. geom[0] = heads;
  1857. geom[1] = sectors;
  1858. geom[2] = cylinders;
  1859. return 0;
  1860. }
  1861. /* Search IOC page 3 to determine if this is hidden physical disk
  1862. *
  1863. */
  1864. int
  1865. mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
  1866. {
  1867. struct inactive_raid_component_info *component_info;
  1868. int i, j;
  1869. RaidPhysDiskPage1_t *phys_disk;
  1870. int rc = 0;
  1871. int num_paths;
  1872. if (!ioc->raid_data.pIocPg3)
  1873. goto out;
  1874. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  1875. if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
  1876. (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
  1877. rc = 1;
  1878. goto out;
  1879. }
  1880. }
  1881. if (ioc->bus_type != SAS)
  1882. goto out;
  1883. /*
  1884. * Check if dual path
  1885. */
  1886. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  1887. num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
  1888. ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
  1889. if (num_paths < 2)
  1890. continue;
  1891. phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
  1892. (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
  1893. if (!phys_disk)
  1894. continue;
  1895. if ((mpt_raid_phys_disk_pg1(ioc,
  1896. ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
  1897. phys_disk))) {
  1898. kfree(phys_disk);
  1899. continue;
  1900. }
  1901. for (j = 0; j < num_paths; j++) {
  1902. if ((phys_disk->Path[j].Flags &
  1903. MPI_RAID_PHYSDISK1_FLAG_INVALID))
  1904. continue;
  1905. if ((phys_disk->Path[j].Flags &
  1906. MPI_RAID_PHYSDISK1_FLAG_BROKEN))
  1907. continue;
  1908. if ((id == phys_disk->Path[j].PhysDiskID) &&
  1909. (channel == phys_disk->Path[j].PhysDiskBus)) {
  1910. rc = 1;
  1911. kfree(phys_disk);
  1912. goto out;
  1913. }
  1914. }
  1915. kfree(phys_disk);
  1916. }
  1917. /*
  1918. * Check inactive list for matching phys disks
  1919. */
  1920. if (list_empty(&ioc->raid_data.inactive_list))
  1921. goto out;
  1922. mutex_lock(&ioc->raid_data.inactive_list_mutex);
  1923. list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
  1924. list) {
  1925. if ((component_info->d.PhysDiskID == id) &&
  1926. (component_info->d.PhysDiskBus == channel))
  1927. rc = 1;
  1928. }
  1929. mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  1930. out:
  1931. return rc;
  1932. }
  1933. EXPORT_SYMBOL(mptscsih_is_phys_disk);
  1934. u8
  1935. mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
  1936. {
  1937. struct inactive_raid_component_info *component_info;
  1938. int i, j;
  1939. RaidPhysDiskPage1_t *phys_disk;
  1940. int rc = -ENXIO;
  1941. int num_paths;
  1942. if (!ioc->raid_data.pIocPg3)
  1943. goto out;
  1944. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  1945. if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
  1946. (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
  1947. rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
  1948. goto out;
  1949. }
  1950. }
  1951. if (ioc->bus_type != SAS)
  1952. goto out;
  1953. /*
  1954. * Check if dual path
  1955. */
  1956. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  1957. num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
  1958. ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
  1959. if (num_paths < 2)
  1960. continue;
  1961. phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
  1962. (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
  1963. if (!phys_disk)
  1964. continue;
  1965. if ((mpt_raid_phys_disk_pg1(ioc,
  1966. ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
  1967. phys_disk))) {
  1968. kfree(phys_disk);
  1969. continue;
  1970. }
  1971. for (j = 0; j < num_paths; j++) {
  1972. if ((phys_disk->Path[j].Flags &
  1973. MPI_RAID_PHYSDISK1_FLAG_INVALID))
  1974. continue;
  1975. if ((phys_disk->Path[j].Flags &
  1976. MPI_RAID_PHYSDISK1_FLAG_BROKEN))
  1977. continue;
  1978. if ((id == phys_disk->Path[j].PhysDiskID) &&
  1979. (channel == phys_disk->Path[j].PhysDiskBus)) {
  1980. rc = phys_disk->PhysDiskNum;
  1981. kfree(phys_disk);
  1982. goto out;
  1983. }
  1984. }
  1985. kfree(phys_disk);
  1986. }
  1987. /*
  1988. * Check inactive list for matching phys disks
  1989. */
  1990. if (list_empty(&ioc->raid_data.inactive_list))
  1991. goto out;
  1992. mutex_lock(&ioc->raid_data.inactive_list_mutex);
  1993. list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
  1994. list) {
  1995. if ((component_info->d.PhysDiskID == id) &&
  1996. (component_info->d.PhysDiskBus == channel))
  1997. rc = component_info->d.PhysDiskNum;
  1998. }
  1999. mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  2000. out:
  2001. return rc;
  2002. }
  2003. EXPORT_SYMBOL(mptscsih_raid_id_to_num);
  2004. /*
  2005. * OS entry point to allow for host driver to free allocated memory
  2006. * Called if no device present or device being unloaded
  2007. */
  2008. void
  2009. mptscsih_slave_destroy(struct scsi_device *sdev)
  2010. {
  2011. struct Scsi_Host *host = sdev->host;
  2012. MPT_SCSI_HOST *hd = shost_priv(host);
  2013. VirtTarget *vtarget;
  2014. VirtDevice *vdevice;
  2015. struct scsi_target *starget;
  2016. starget = scsi_target(sdev);
  2017. vtarget = starget->hostdata;
  2018. vdevice = sdev->hostdata;
  2019. if (!vdevice)
  2020. return;
  2021. mptscsih_search_running_cmds(hd, vdevice);
  2022. vtarget->num_luns--;
  2023. mptscsih_synchronize_cache(hd, vdevice);
  2024. kfree(vdevice);
  2025. sdev->hostdata = NULL;
  2026. }
  2027. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2028. /*
  2029. * mptscsih_change_queue_depth - This function will set a devices queue depth
  2030. * @sdev: per scsi_device pointer
  2031. * @qdepth: requested queue depth
  2032. *
  2033. * Adding support for new 'change_queue_depth' api.
  2034. */
  2035. int
  2036. mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
  2037. {
  2038. MPT_SCSI_HOST *hd = shost_priv(sdev->host);
  2039. VirtTarget *vtarget;
  2040. struct scsi_target *starget;
  2041. int max_depth;
  2042. MPT_ADAPTER *ioc = hd->ioc;
  2043. starget = scsi_target(sdev);
  2044. vtarget = starget->hostdata;
  2045. if (ioc->bus_type == SPI) {
  2046. if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
  2047. max_depth = 1;
  2048. else if (sdev->type == TYPE_DISK &&
  2049. vtarget->minSyncFactor <= MPT_ULTRA160)
  2050. max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
  2051. else
  2052. max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
  2053. } else
  2054. max_depth = ioc->sh->can_queue;
  2055. if (!sdev->tagged_supported)
  2056. max_depth = 1;
  2057. if (qdepth > max_depth)
  2058. qdepth = max_depth;
  2059. return scsi_change_queue_depth(sdev, qdepth);
  2060. }
  2061. /*
  2062. * OS entry point to adjust the queue_depths on a per-device basis.
  2063. * Called once per device the bus scan. Use it to force the queue_depth
  2064. * member to 1 if a device does not support Q tags.
  2065. * Return non-zero if fails.
  2066. */
  2067. int
  2068. mptscsih_slave_configure(struct scsi_device *sdev)
  2069. {
  2070. struct Scsi_Host *sh = sdev->host;
  2071. VirtTarget *vtarget;
  2072. VirtDevice *vdevice;
  2073. struct scsi_target *starget;
  2074. MPT_SCSI_HOST *hd = shost_priv(sh);
  2075. MPT_ADAPTER *ioc = hd->ioc;
  2076. starget = scsi_target(sdev);
  2077. vtarget = starget->hostdata;
  2078. vdevice = sdev->hostdata;
  2079. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2080. "device @ %p, channel=%d, id=%d, lun=%llu\n",
  2081. ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
  2082. if (ioc->bus_type == SPI)
  2083. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2084. "sdtr %d wdtr %d ppr %d inq length=%d\n",
  2085. ioc->name, sdev->sdtr, sdev->wdtr,
  2086. sdev->ppr, sdev->inquiry_len));
  2087. vdevice->configured_lun = 1;
  2088. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2089. "Queue depth=%d, tflags=%x\n",
  2090. ioc->name, sdev->queue_depth, vtarget->tflags));
  2091. if (ioc->bus_type == SPI)
  2092. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2093. "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
  2094. ioc->name, vtarget->negoFlags, vtarget->maxOffset,
  2095. vtarget->minSyncFactor));
  2096. mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH);
  2097. dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2098. "tagged %d, simple %d\n",
  2099. ioc->name,sdev->tagged_supported, sdev->simple_tags));
  2100. blk_queue_dma_alignment (sdev->request_queue, 512 - 1);
  2101. return 0;
  2102. }
  2103. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2104. /*
  2105. * Private routines...
  2106. */
  2107. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2108. /* Utility function to copy sense data from the scsi_cmnd buffer
  2109. * to the FC and SCSI target structures.
  2110. *
  2111. */
  2112. static void
  2113. mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
  2114. {
  2115. VirtDevice *vdevice;
  2116. SCSIIORequest_t *pReq;
  2117. u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
  2118. MPT_ADAPTER *ioc = hd->ioc;
  2119. /* Get target structure
  2120. */
  2121. pReq = (SCSIIORequest_t *) mf;
  2122. vdevice = sc->device->hostdata;
  2123. if (sense_count) {
  2124. u8 *sense_data;
  2125. int req_index;
  2126. /* Copy the sense received into the scsi command block. */
  2127. req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2128. sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
  2129. memcpy(sc->sense_buffer, sense_data, MPT_SENSE_BUFFER_ALLOC);
  2130. /* Log SMART data (asc = 0x5D, non-IM case only) if required.
  2131. */
  2132. if ((ioc->events) && (ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
  2133. if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) {
  2134. int idx;
  2135. idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
  2136. ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
  2137. ioc->events[idx].eventContext = ioc->eventContext;
  2138. ioc->events[idx].data[0] = (pReq->LUN[1] << 24) |
  2139. (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) |
  2140. (sc->device->channel << 8) | sc->device->id;
  2141. ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];
  2142. ioc->eventContext++;
  2143. if (ioc->pcidev->vendor ==
  2144. PCI_VENDOR_ID_IBM) {
  2145. mptscsih_issue_sep_command(ioc,
  2146. vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
  2147. vdevice->vtarget->tflags |=
  2148. MPT_TARGET_FLAGS_LED_ON;
  2149. }
  2150. }
  2151. }
  2152. } else {
  2153. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n",
  2154. ioc->name));
  2155. }
  2156. }
  2157. /**
  2158. * mptscsih_get_scsi_lookup - retrieves scmd entry
  2159. * @ioc: Pointer to MPT_ADAPTER structure
  2160. * @i: index into the array
  2161. *
  2162. * Returns the scsi_cmd pointer
  2163. */
  2164. struct scsi_cmnd *
  2165. mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i)
  2166. {
  2167. unsigned long flags;
  2168. struct scsi_cmnd *scmd;
  2169. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  2170. scmd = ioc->ScsiLookup[i];
  2171. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  2172. return scmd;
  2173. }
  2174. EXPORT_SYMBOL(mptscsih_get_scsi_lookup);
  2175. /**
  2176. * mptscsih_getclear_scsi_lookup - retrieves and clears scmd entry from ScsiLookup[] array list
  2177. * @ioc: Pointer to MPT_ADAPTER structure
  2178. * @i: index into the array
  2179. *
  2180. * Returns the scsi_cmd pointer
  2181. *
  2182. **/
  2183. static struct scsi_cmnd *
  2184. mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i)
  2185. {
  2186. unsigned long flags;
  2187. struct scsi_cmnd *scmd;
  2188. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  2189. scmd = ioc->ScsiLookup[i];
  2190. ioc->ScsiLookup[i] = NULL;
  2191. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  2192. return scmd;
  2193. }
  2194. /**
  2195. * mptscsih_set_scsi_lookup - write a scmd entry into the ScsiLookup[] array list
  2196. *
  2197. * @ioc: Pointer to MPT_ADAPTER structure
  2198. * @i: index into the array
  2199. * @scmd: scsi_cmnd pointer
  2200. *
  2201. **/
  2202. static void
  2203. mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd)
  2204. {
  2205. unsigned long flags;
  2206. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  2207. ioc->ScsiLookup[i] = scmd;
  2208. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  2209. }
  2210. /**
  2211. * SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list
  2212. * @ioc: Pointer to MPT_ADAPTER structure
  2213. * @sc: scsi_cmnd pointer
  2214. */
  2215. static int
  2216. SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc)
  2217. {
  2218. unsigned long flags;
  2219. int i, index=-1;
  2220. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  2221. for (i = 0; i < ioc->req_depth; i++) {
  2222. if (ioc->ScsiLookup[i] == sc) {
  2223. index = i;
  2224. goto out;
  2225. }
  2226. }
  2227. out:
  2228. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  2229. return index;
  2230. }
  2231. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2232. int
  2233. mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  2234. {
  2235. MPT_SCSI_HOST *hd;
  2236. if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
  2237. return 0;
  2238. hd = shost_priv(ioc->sh);
  2239. switch (reset_phase) {
  2240. case MPT_IOC_SETUP_RESET:
  2241. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2242. "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
  2243. break;
  2244. case MPT_IOC_PRE_RESET:
  2245. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2246. "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
  2247. mptscsih_flush_running_cmds(hd);
  2248. break;
  2249. case MPT_IOC_POST_RESET:
  2250. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2251. "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
  2252. if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) {
  2253. ioc->internal_cmds.status |=
  2254. MPT_MGMT_STATUS_DID_IOCRESET;
  2255. complete(&ioc->internal_cmds.done);
  2256. }
  2257. break;
  2258. default:
  2259. break;
  2260. }
  2261. return 1; /* currently means nothing really */
  2262. }
  2263. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2264. int
  2265. mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  2266. {
  2267. u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
  2268. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2269. "MPT event (=%02Xh) routed to SCSI host driver!\n",
  2270. ioc->name, event));
  2271. if ((event == MPI_EVENT_IOC_BUS_RESET ||
  2272. event == MPI_EVENT_EXT_BUS_RESET) &&
  2273. (ioc->bus_type == SPI) && (ioc->soft_resets < -1))
  2274. ioc->soft_resets++;
  2275. return 1; /* currently means nothing really */
  2276. }
  2277. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2278. /*
  2279. * Bus Scan and Domain Validation functionality ...
  2280. */
  2281. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2282. /*
  2283. * mptscsih_scandv_complete - Scan and DV callback routine registered
  2284. * to Fustion MPT (base) driver.
  2285. *
  2286. * @ioc: Pointer to MPT_ADAPTER structure
  2287. * @mf: Pointer to original MPT request frame
  2288. * @mr: Pointer to MPT reply frame (NULL if TurboReply)
  2289. *
  2290. * This routine is called from mpt.c::mpt_interrupt() at the completion
  2291. * of any SCSI IO request.
  2292. * This routine is registered with the Fusion MPT (base) driver at driver
  2293. * load/init time via the mpt_register() API call.
  2294. *
  2295. * Returns 1 indicating alloc'd request frame ptr should be freed.
  2296. *
  2297. * Remark: Sets a completion code and (possibly) saves sense data
  2298. * in the IOC member localReply structure.
  2299. * Used ONLY for DV and other internal commands.
  2300. */
  2301. int
  2302. mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
  2303. MPT_FRAME_HDR *reply)
  2304. {
  2305. SCSIIORequest_t *pReq;
  2306. SCSIIOReply_t *pReply;
  2307. u8 cmd;
  2308. u16 req_idx;
  2309. u8 *sense_data;
  2310. int sz;
  2311. ioc->internal_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  2312. ioc->internal_cmds.completion_code = MPT_SCANDV_GOOD;
  2313. if (!reply)
  2314. goto out;
  2315. pReply = (SCSIIOReply_t *) reply;
  2316. pReq = (SCSIIORequest_t *) req;
  2317. ioc->internal_cmds.completion_code =
  2318. mptscsih_get_completion_code(ioc, req, reply);
  2319. ioc->internal_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  2320. memcpy(ioc->internal_cmds.reply, reply,
  2321. min(MPT_DEFAULT_FRAME_SIZE, 4 * reply->u.reply.MsgLength));
  2322. cmd = reply->u.hdr.Function;
  2323. if (((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
  2324. (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) &&
  2325. (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
  2326. req_idx = le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
  2327. sense_data = ((u8 *)ioc->sense_buf_pool +
  2328. (req_idx * MPT_SENSE_BUFFER_ALLOC));
  2329. sz = min_t(int, pReq->SenseBufferLength,
  2330. MPT_SENSE_BUFFER_ALLOC);
  2331. memcpy(ioc->internal_cmds.sense, sense_data, sz);
  2332. }
  2333. out:
  2334. if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING))
  2335. return 0;
  2336. ioc->internal_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  2337. complete(&ioc->internal_cmds.done);
  2338. return 1;
  2339. }
  2340. /**
  2341. * mptscsih_get_completion_code - get completion code from MPT request
  2342. * @ioc: Pointer to MPT_ADAPTER structure
  2343. * @req: Pointer to original MPT request frame
  2344. * @reply: Pointer to MPT reply frame (NULL if TurboReply)
  2345. *
  2346. **/
  2347. static int
  2348. mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
  2349. MPT_FRAME_HDR *reply)
  2350. {
  2351. SCSIIOReply_t *pReply;
  2352. MpiRaidActionReply_t *pr;
  2353. u8 scsi_status;
  2354. u16 status;
  2355. int completion_code;
  2356. pReply = (SCSIIOReply_t *)reply;
  2357. status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  2358. scsi_status = pReply->SCSIStatus;
  2359. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2360. "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh,"
  2361. "IOCLogInfo=%08xh\n", ioc->name, status, pReply->SCSIState,
  2362. scsi_status, le32_to_cpu(pReply->IOCLogInfo)));
  2363. switch (status) {
  2364. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  2365. completion_code = MPT_SCANDV_SELECTION_TIMEOUT;
  2366. break;
  2367. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  2368. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  2369. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  2370. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  2371. completion_code = MPT_SCANDV_DID_RESET;
  2372. break;
  2373. case MPI_IOCSTATUS_BUSY:
  2374. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:
  2375. completion_code = MPT_SCANDV_BUSY;
  2376. break;
  2377. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  2378. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  2379. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  2380. if (pReply->Function == MPI_FUNCTION_CONFIG) {
  2381. completion_code = MPT_SCANDV_GOOD;
  2382. } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
  2383. pr = (MpiRaidActionReply_t *)reply;
  2384. if (le16_to_cpu(pr->ActionStatus) ==
  2385. MPI_RAID_ACTION_ASTATUS_SUCCESS)
  2386. completion_code = MPT_SCANDV_GOOD;
  2387. else
  2388. completion_code = MPT_SCANDV_SOME_ERROR;
  2389. } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)
  2390. completion_code = MPT_SCANDV_SENSE;
  2391. else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
  2392. if (req->u.scsireq.CDB[0] == INQUIRY)
  2393. completion_code = MPT_SCANDV_ISSUE_SENSE;
  2394. else
  2395. completion_code = MPT_SCANDV_DID_RESET;
  2396. } else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
  2397. completion_code = MPT_SCANDV_DID_RESET;
  2398. else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  2399. completion_code = MPT_SCANDV_DID_RESET;
  2400. else if (scsi_status == MPI_SCSI_STATUS_BUSY)
  2401. completion_code = MPT_SCANDV_BUSY;
  2402. else
  2403. completion_code = MPT_SCANDV_GOOD;
  2404. break;
  2405. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  2406. if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  2407. completion_code = MPT_SCANDV_DID_RESET;
  2408. else
  2409. completion_code = MPT_SCANDV_SOME_ERROR;
  2410. break;
  2411. default:
  2412. completion_code = MPT_SCANDV_SOME_ERROR;
  2413. break;
  2414. } /* switch(status) */
  2415. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2416. " completionCode set to %08xh\n", ioc->name, completion_code));
  2417. return completion_code;
  2418. }
  2419. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2420. /**
  2421. * mptscsih_do_cmd - Do internal command.
  2422. * @hd: MPT_SCSI_HOST pointer
  2423. * @io: INTERNAL_CMD pointer.
  2424. *
  2425. * Issue the specified internally generated command and do command
  2426. * specific cleanup. For bus scan / DV only.
  2427. * NOTES: If command is Inquiry and status is good,
  2428. * initialize a target structure, save the data
  2429. *
  2430. * Remark: Single threaded access only.
  2431. *
  2432. * Return:
  2433. * < 0 if an illegal command or no resources
  2434. *
  2435. * 0 if good
  2436. *
  2437. * > 0 if command complete but some type of completion error.
  2438. */
  2439. static int
  2440. mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
  2441. {
  2442. MPT_FRAME_HDR *mf;
  2443. SCSIIORequest_t *pScsiReq;
  2444. int my_idx, ii, dir;
  2445. int timeout;
  2446. char cmdLen;
  2447. char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  2448. u8 cmd = io->cmd;
  2449. MPT_ADAPTER *ioc = hd->ioc;
  2450. int ret = 0;
  2451. unsigned long timeleft;
  2452. unsigned long flags;
  2453. /* don't send internal command during diag reset */
  2454. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  2455. if (ioc->ioc_reset_in_progress) {
  2456. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  2457. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2458. "%s: busy with host reset\n", ioc->name, __func__));
  2459. return MPT_SCANDV_BUSY;
  2460. }
  2461. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  2462. mutex_lock(&ioc->internal_cmds.mutex);
  2463. /* Set command specific information
  2464. */
  2465. switch (cmd) {
  2466. case INQUIRY:
  2467. cmdLen = 6;
  2468. dir = MPI_SCSIIO_CONTROL_READ;
  2469. CDB[0] = cmd;
  2470. CDB[4] = io->size;
  2471. timeout = 10;
  2472. break;
  2473. case TEST_UNIT_READY:
  2474. cmdLen = 6;
  2475. dir = MPI_SCSIIO_CONTROL_READ;
  2476. timeout = 10;
  2477. break;
  2478. case START_STOP:
  2479. cmdLen = 6;
  2480. dir = MPI_SCSIIO_CONTROL_READ;
  2481. CDB[0] = cmd;
  2482. CDB[4] = 1; /*Spin up the disk */
  2483. timeout = 15;
  2484. break;
  2485. case REQUEST_SENSE:
  2486. cmdLen = 6;
  2487. CDB[0] = cmd;
  2488. CDB[4] = io->size;
  2489. dir = MPI_SCSIIO_CONTROL_READ;
  2490. timeout = 10;
  2491. break;
  2492. case READ_BUFFER:
  2493. cmdLen = 10;
  2494. dir = MPI_SCSIIO_CONTROL_READ;
  2495. CDB[0] = cmd;
  2496. if (io->flags & MPT_ICFLAG_ECHO) {
  2497. CDB[1] = 0x0A;
  2498. } else {
  2499. CDB[1] = 0x02;
  2500. }
  2501. if (io->flags & MPT_ICFLAG_BUF_CAP) {
  2502. CDB[1] |= 0x01;
  2503. }
  2504. CDB[6] = (io->size >> 16) & 0xFF;
  2505. CDB[7] = (io->size >> 8) & 0xFF;
  2506. CDB[8] = io->size & 0xFF;
  2507. timeout = 10;
  2508. break;
  2509. case WRITE_BUFFER:
  2510. cmdLen = 10;
  2511. dir = MPI_SCSIIO_CONTROL_WRITE;
  2512. CDB[0] = cmd;
  2513. if (io->flags & MPT_ICFLAG_ECHO) {
  2514. CDB[1] = 0x0A;
  2515. } else {
  2516. CDB[1] = 0x02;
  2517. }
  2518. CDB[6] = (io->size >> 16) & 0xFF;
  2519. CDB[7] = (io->size >> 8) & 0xFF;
  2520. CDB[8] = io->size & 0xFF;
  2521. timeout = 10;
  2522. break;
  2523. case RESERVE:
  2524. cmdLen = 6;
  2525. dir = MPI_SCSIIO_CONTROL_READ;
  2526. CDB[0] = cmd;
  2527. timeout = 10;
  2528. break;
  2529. case RELEASE:
  2530. cmdLen = 6;
  2531. dir = MPI_SCSIIO_CONTROL_READ;
  2532. CDB[0] = cmd;
  2533. timeout = 10;
  2534. break;
  2535. case SYNCHRONIZE_CACHE:
  2536. cmdLen = 10;
  2537. dir = MPI_SCSIIO_CONTROL_READ;
  2538. CDB[0] = cmd;
  2539. // CDB[1] = 0x02; /* set immediate bit */
  2540. timeout = 10;
  2541. break;
  2542. default:
  2543. /* Error Case */
  2544. ret = -EFAULT;
  2545. goto out;
  2546. }
  2547. /* Get and Populate a free Frame
  2548. * MsgContext set in mpt_get_msg_frame call
  2549. */
  2550. if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
  2551. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: No msg frames!\n",
  2552. ioc->name, __func__));
  2553. ret = MPT_SCANDV_BUSY;
  2554. goto out;
  2555. }
  2556. pScsiReq = (SCSIIORequest_t *) mf;
  2557. /* Get the request index */
  2558. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2559. ADD_INDEX_LOG(my_idx); /* for debug */
  2560. if (io->flags & MPT_ICFLAG_PHYS_DISK) {
  2561. pScsiReq->TargetID = io->physDiskNum;
  2562. pScsiReq->Bus = 0;
  2563. pScsiReq->ChainOffset = 0;
  2564. pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  2565. } else {
  2566. pScsiReq->TargetID = io->id;
  2567. pScsiReq->Bus = io->channel;
  2568. pScsiReq->ChainOffset = 0;
  2569. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  2570. }
  2571. pScsiReq->CDBLength = cmdLen;
  2572. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  2573. pScsiReq->Reserved = 0;
  2574. pScsiReq->MsgFlags = mpt_msg_flags(ioc);
  2575. /* MsgContext set in mpt_get_msg_fram call */
  2576. int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);
  2577. if (io->flags & MPT_ICFLAG_TAGGED_CMD)
  2578. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
  2579. else
  2580. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  2581. if (cmd == REQUEST_SENSE) {
  2582. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  2583. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2584. "%s: Untagged! 0x%02x\n", ioc->name, __func__, cmd));
  2585. }
  2586. for (ii = 0; ii < 16; ii++)
  2587. pScsiReq->CDB[ii] = CDB[ii];
  2588. pScsiReq->DataLength = cpu_to_le32(io->size);
  2589. pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
  2590. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  2591. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2592. "%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%llu\n",
  2593. ioc->name, __func__, cmd, io->channel, io->id, io->lun));
  2594. if (dir == MPI_SCSIIO_CONTROL_READ)
  2595. ioc->add_sge((char *) &pScsiReq->SGL,
  2596. MPT_SGE_FLAGS_SSIMPLE_READ | io->size, io->data_dma);
  2597. else
  2598. ioc->add_sge((char *) &pScsiReq->SGL,
  2599. MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size, io->data_dma);
  2600. INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
  2601. mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
  2602. timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done,
  2603. timeout*HZ);
  2604. if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  2605. ret = MPT_SCANDV_DID_RESET;
  2606. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2607. "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __func__,
  2608. cmd));
  2609. if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
  2610. mpt_free_msg_frame(ioc, mf);
  2611. goto out;
  2612. }
  2613. if (!timeleft) {
  2614. printk(MYIOC_s_WARN_FMT
  2615. "Issuing Reset from %s!! doorbell=0x%08xh"
  2616. " cmd=0x%02x\n",
  2617. ioc->name, __func__, mpt_GetIocState(ioc, 0),
  2618. cmd);
  2619. mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  2620. mpt_free_msg_frame(ioc, mf);
  2621. }
  2622. goto out;
  2623. }
  2624. ret = ioc->internal_cmds.completion_code;
  2625. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: success, rc=0x%02x\n",
  2626. ioc->name, __func__, ret));
  2627. out:
  2628. CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
  2629. mutex_unlock(&ioc->internal_cmds.mutex);
  2630. return ret;
  2631. }
  2632. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2633. /**
  2634. * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
  2635. * @hd: Pointer to a SCSI HOST structure
  2636. * @vdevice: virtual target device
  2637. *
  2638. * Uses the ISR, but with special processing.
  2639. * MUST be single-threaded.
  2640. *
  2641. */
  2642. static void
  2643. mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
  2644. {
  2645. INTERNAL_CMD iocmd;
  2646. /* Ignore hidden raid components, this is handled when the command
  2647. * is sent to the volume
  2648. */
  2649. if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
  2650. return;
  2651. if (vdevice->vtarget->type != TYPE_DISK || vdevice->vtarget->deleted ||
  2652. !vdevice->configured_lun)
  2653. return;
  2654. /* Following parameters will not change
  2655. * in this routine.
  2656. */
  2657. iocmd.cmd = SYNCHRONIZE_CACHE;
  2658. iocmd.flags = 0;
  2659. iocmd.physDiskNum = -1;
  2660. iocmd.data = NULL;
  2661. iocmd.data_dma = -1;
  2662. iocmd.size = 0;
  2663. iocmd.rsvd = iocmd.rsvd2 = 0;
  2664. iocmd.channel = vdevice->vtarget->channel;
  2665. iocmd.id = vdevice->vtarget->id;
  2666. iocmd.lun = vdevice->lun;
  2667. mptscsih_do_cmd(hd, &iocmd);
  2668. }
  2669. static ssize_t
  2670. mptscsih_version_fw_show(struct device *dev, struct device_attribute *attr,
  2671. char *buf)
  2672. {
  2673. struct Scsi_Host *host = class_to_shost(dev);
  2674. MPT_SCSI_HOST *hd = shost_priv(host);
  2675. MPT_ADAPTER *ioc = hd->ioc;
  2676. return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
  2677. (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
  2678. (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
  2679. (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
  2680. ioc->facts.FWVersion.Word & 0x000000FF);
  2681. }
  2682. static DEVICE_ATTR(version_fw, S_IRUGO, mptscsih_version_fw_show, NULL);
  2683. static ssize_t
  2684. mptscsih_version_bios_show(struct device *dev, struct device_attribute *attr,
  2685. char *buf)
  2686. {
  2687. struct Scsi_Host *host = class_to_shost(dev);
  2688. MPT_SCSI_HOST *hd = shost_priv(host);
  2689. MPT_ADAPTER *ioc = hd->ioc;
  2690. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
  2691. (ioc->biosVersion & 0xFF000000) >> 24,
  2692. (ioc->biosVersion & 0x00FF0000) >> 16,
  2693. (ioc->biosVersion & 0x0000FF00) >> 8,
  2694. ioc->biosVersion & 0x000000FF);
  2695. }
  2696. static DEVICE_ATTR(version_bios, S_IRUGO, mptscsih_version_bios_show, NULL);
  2697. static ssize_t
  2698. mptscsih_version_mpi_show(struct device *dev, struct device_attribute *attr,
  2699. char *buf)
  2700. {
  2701. struct Scsi_Host *host = class_to_shost(dev);
  2702. MPT_SCSI_HOST *hd = shost_priv(host);
  2703. MPT_ADAPTER *ioc = hd->ioc;
  2704. return snprintf(buf, PAGE_SIZE, "%03x\n", ioc->facts.MsgVersion);
  2705. }
  2706. static DEVICE_ATTR(version_mpi, S_IRUGO, mptscsih_version_mpi_show, NULL);
  2707. static ssize_t
  2708. mptscsih_version_product_show(struct device *dev,
  2709. struct device_attribute *attr,
  2710. char *buf)
  2711. {
  2712. struct Scsi_Host *host = class_to_shost(dev);
  2713. MPT_SCSI_HOST *hd = shost_priv(host);
  2714. MPT_ADAPTER *ioc = hd->ioc;
  2715. return snprintf(buf, PAGE_SIZE, "%s\n", ioc->prod_name);
  2716. }
  2717. static DEVICE_ATTR(version_product, S_IRUGO,
  2718. mptscsih_version_product_show, NULL);
  2719. static ssize_t
  2720. mptscsih_version_nvdata_persistent_show(struct device *dev,
  2721. struct device_attribute *attr,
  2722. char *buf)
  2723. {
  2724. struct Scsi_Host *host = class_to_shost(dev);
  2725. MPT_SCSI_HOST *hd = shost_priv(host);
  2726. MPT_ADAPTER *ioc = hd->ioc;
  2727. return snprintf(buf, PAGE_SIZE, "%02xh\n",
  2728. ioc->nvdata_version_persistent);
  2729. }
  2730. static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
  2731. mptscsih_version_nvdata_persistent_show, NULL);
  2732. static ssize_t
  2733. mptscsih_version_nvdata_default_show(struct device *dev,
  2734. struct device_attribute *attr, char *buf)
  2735. {
  2736. struct Scsi_Host *host = class_to_shost(dev);
  2737. MPT_SCSI_HOST *hd = shost_priv(host);
  2738. MPT_ADAPTER *ioc = hd->ioc;
  2739. return snprintf(buf, PAGE_SIZE, "%02xh\n",ioc->nvdata_version_default);
  2740. }
  2741. static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
  2742. mptscsih_version_nvdata_default_show, NULL);
  2743. static ssize_t
  2744. mptscsih_board_name_show(struct device *dev, struct device_attribute *attr,
  2745. char *buf)
  2746. {
  2747. struct Scsi_Host *host = class_to_shost(dev);
  2748. MPT_SCSI_HOST *hd = shost_priv(host);
  2749. MPT_ADAPTER *ioc = hd->ioc;
  2750. return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_name);
  2751. }
  2752. static DEVICE_ATTR(board_name, S_IRUGO, mptscsih_board_name_show, NULL);
  2753. static ssize_t
  2754. mptscsih_board_assembly_show(struct device *dev,
  2755. struct device_attribute *attr, char *buf)
  2756. {
  2757. struct Scsi_Host *host = class_to_shost(dev);
  2758. MPT_SCSI_HOST *hd = shost_priv(host);
  2759. MPT_ADAPTER *ioc = hd->ioc;
  2760. return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_assembly);
  2761. }
  2762. static DEVICE_ATTR(board_assembly, S_IRUGO,
  2763. mptscsih_board_assembly_show, NULL);
  2764. static ssize_t
  2765. mptscsih_board_tracer_show(struct device *dev, struct device_attribute *attr,
  2766. char *buf)
  2767. {
  2768. struct Scsi_Host *host = class_to_shost(dev);
  2769. MPT_SCSI_HOST *hd = shost_priv(host);
  2770. MPT_ADAPTER *ioc = hd->ioc;
  2771. return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_tracer);
  2772. }
  2773. static DEVICE_ATTR(board_tracer, S_IRUGO,
  2774. mptscsih_board_tracer_show, NULL);
  2775. static ssize_t
  2776. mptscsih_io_delay_show(struct device *dev, struct device_attribute *attr,
  2777. 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, "%02d\n", ioc->io_missing_delay);
  2783. }
  2784. static DEVICE_ATTR(io_delay, S_IRUGO,
  2785. mptscsih_io_delay_show, NULL);
  2786. static ssize_t
  2787. mptscsih_device_delay_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, "%02d\n", ioc->device_missing_delay);
  2794. }
  2795. static DEVICE_ATTR(device_delay, S_IRUGO,
  2796. mptscsih_device_delay_show, NULL);
  2797. static ssize_t
  2798. mptscsih_debug_level_show(struct device *dev, struct device_attribute *attr,
  2799. char *buf)
  2800. {
  2801. struct Scsi_Host *host = class_to_shost(dev);
  2802. MPT_SCSI_HOST *hd = shost_priv(host);
  2803. MPT_ADAPTER *ioc = hd->ioc;
  2804. return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->debug_level);
  2805. }
  2806. static ssize_t
  2807. mptscsih_debug_level_store(struct device *dev, struct device_attribute *attr,
  2808. const char *buf, size_t count)
  2809. {
  2810. struct Scsi_Host *host = class_to_shost(dev);
  2811. MPT_SCSI_HOST *hd = shost_priv(host);
  2812. MPT_ADAPTER *ioc = hd->ioc;
  2813. int val = 0;
  2814. if (sscanf(buf, "%x", &val) != 1)
  2815. return -EINVAL;
  2816. ioc->debug_level = val;
  2817. printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n",
  2818. ioc->name, ioc->debug_level);
  2819. return strlen(buf);
  2820. }
  2821. static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,
  2822. mptscsih_debug_level_show, mptscsih_debug_level_store);
  2823. struct device_attribute *mptscsih_host_attrs[] = {
  2824. &dev_attr_version_fw,
  2825. &dev_attr_version_bios,
  2826. &dev_attr_version_mpi,
  2827. &dev_attr_version_product,
  2828. &dev_attr_version_nvdata_persistent,
  2829. &dev_attr_version_nvdata_default,
  2830. &dev_attr_board_name,
  2831. &dev_attr_board_assembly,
  2832. &dev_attr_board_tracer,
  2833. &dev_attr_io_delay,
  2834. &dev_attr_device_delay,
  2835. &dev_attr_debug_level,
  2836. NULL,
  2837. };
  2838. EXPORT_SYMBOL(mptscsih_host_attrs);
  2839. EXPORT_SYMBOL(mptscsih_remove);
  2840. EXPORT_SYMBOL(mptscsih_shutdown);
  2841. #ifdef CONFIG_PM
  2842. EXPORT_SYMBOL(mptscsih_suspend);
  2843. EXPORT_SYMBOL(mptscsih_resume);
  2844. #endif
  2845. EXPORT_SYMBOL(mptscsih_show_info);
  2846. EXPORT_SYMBOL(mptscsih_info);
  2847. EXPORT_SYMBOL(mptscsih_qcmd);
  2848. EXPORT_SYMBOL(mptscsih_slave_destroy);
  2849. EXPORT_SYMBOL(mptscsih_slave_configure);
  2850. EXPORT_SYMBOL(mptscsih_abort);
  2851. EXPORT_SYMBOL(mptscsih_dev_reset);
  2852. EXPORT_SYMBOL(mptscsih_bus_reset);
  2853. EXPORT_SYMBOL(mptscsih_host_reset);
  2854. EXPORT_SYMBOL(mptscsih_bios_param);
  2855. EXPORT_SYMBOL(mptscsih_io_done);
  2856. EXPORT_SYMBOL(mptscsih_taskmgmt_complete);
  2857. EXPORT_SYMBOL(mptscsih_scandv_complete);
  2858. EXPORT_SYMBOL(mptscsih_event_process);
  2859. EXPORT_SYMBOL(mptscsih_ioc_reset);
  2860. EXPORT_SYMBOL(mptscsih_change_queue_depth);
  2861. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/