mptscsih.c 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608
  1. /*
  2. * linux/drivers/message/fusion/mptscsih.c
  3. * For use with LSI Logic PCI chip/adapter(s)
  4. * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
  5. *
  6. * Copyright (c) 1999-2005 LSI Logic Corporation
  7. * (mailto:mpt_linux_developer@lsil.com)
  8. *
  9. */
  10. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  11. /*
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; version 2 of the License.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. NO WARRANTY
  20. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. solely responsible for determining the appropriateness of using and
  25. distributing the Program and assumes all risks associated with its
  26. exercise of rights under this Agreement, including but not limited to
  27. the risks and costs of program errors, damage to or loss of data,
  28. programs or equipment, and unavailability or interruption of operations.
  29. DISCLAIMER OF LIABILITY
  30. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. You should have received a copy of the GNU General Public License
  38. along with this program; if not, write to the Free Software
  39. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  40. */
  41. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  42. #include "linux_compat.h" /* linux-2.6 tweaks */
  43. #include <linux/module.h>
  44. #include <linux/kernel.h>
  45. #include <linux/init.h>
  46. #include <linux/errno.h>
  47. #include <linux/kdev_t.h>
  48. #include <linux/blkdev.h>
  49. #include <linux/delay.h> /* for mdelay */
  50. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  51. #include <linux/reboot.h> /* notifier code */
  52. #include <linux/sched.h>
  53. #include <linux/workqueue.h>
  54. #include <scsi/scsi.h>
  55. #include <scsi/scsi_cmnd.h>
  56. #include <scsi/scsi_device.h>
  57. #include <scsi/scsi_host.h>
  58. #include <scsi/scsi_tcq.h>
  59. #include <scsi/scsi_dbg.h>
  60. #include "mptbase.h"
  61. #include "mptscsih.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. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  70. typedef struct _BIG_SENSE_BUF {
  71. u8 data[MPT_SENSE_BUFFER_ALLOC];
  72. } BIG_SENSE_BUF;
  73. #define MPT_SCANDV_GOOD (0x00000000) /* must be 0 */
  74. #define MPT_SCANDV_DID_RESET (0x00000001)
  75. #define MPT_SCANDV_SENSE (0x00000002)
  76. #define MPT_SCANDV_SOME_ERROR (0x00000004)
  77. #define MPT_SCANDV_SELECTION_TIMEOUT (0x00000008)
  78. #define MPT_SCANDV_ISSUE_SENSE (0x00000010)
  79. #define MPT_SCANDV_FALLBACK (0x00000020)
  80. #define MPT_SCANDV_MAX_RETRIES (10)
  81. #define MPT_ICFLAG_BUF_CAP 0x01 /* ReadBuffer Read Capacity format */
  82. #define MPT_ICFLAG_ECHO 0x02 /* ReadBuffer Echo buffer format */
  83. #define MPT_ICFLAG_EBOS 0x04 /* ReadBuffer Echo buffer has EBOS */
  84. #define MPT_ICFLAG_PHYS_DISK 0x08 /* Any SCSI IO but do Phys Disk Format */
  85. #define MPT_ICFLAG_TAGGED_CMD 0x10 /* Do tagged IO */
  86. #define MPT_ICFLAG_DID_RESET 0x20 /* Bus Reset occurred with this command */
  87. #define MPT_ICFLAG_RESERVED 0x40 /* Reserved has been issued */
  88. typedef struct _internal_cmd {
  89. char *data; /* data pointer */
  90. dma_addr_t data_dma; /* data dma address */
  91. int size; /* transfer size */
  92. u8 cmd; /* SCSI Op Code */
  93. u8 bus; /* bus number */
  94. u8 id; /* SCSI ID (virtual) */
  95. u8 lun;
  96. u8 flags; /* Bit Field - See above */
  97. u8 physDiskNum; /* Phys disk number, -1 else */
  98. u8 rsvd2;
  99. u8 rsvd;
  100. } INTERNAL_CMD;
  101. typedef struct _negoparms {
  102. u8 width;
  103. u8 offset;
  104. u8 factor;
  105. u8 flags;
  106. } NEGOPARMS;
  107. typedef struct _dv_parameters {
  108. NEGOPARMS max;
  109. NEGOPARMS now;
  110. u8 cmd;
  111. u8 id;
  112. u16 pad1;
  113. } DVPARAMETERS;
  114. /*
  115. * Other private/forward protos...
  116. */
  117. int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  118. static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);
  119. int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  120. static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
  121. SCSIIORequest_t *pReq, int req_idx);
  122. static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
  123. static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
  124. static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
  125. static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout );
  126. static u32 SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc);
  127. static int mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout);
  128. static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout);
  129. int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
  130. int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
  131. static void mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *data, int dlen);
  132. static void mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtDevice *target, char byte56);
  133. static void mptscsih_set_dvflags(MPT_SCSI_HOST *hd, SCSIIORequest_t *pReq);
  134. static void mptscsih_setDevicePage1Flags (u8 width, u8 factor, u8 offset, int *requestedPtr, int *configurationPtr, u8 flags);
  135. static void mptscsih_no_negotiate(MPT_SCSI_HOST *hd, int target_id);
  136. static int mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target, int flags);
  137. static int mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus);
  138. int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  139. static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
  140. static int mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum);
  141. static struct work_struct mptscsih_persistTask;
  142. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  143. static int mptscsih_do_raid(MPT_SCSI_HOST *hd, u8 action, INTERNAL_CMD *io);
  144. static void mptscsih_domainValidation(void *hd);
  145. static int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id);
  146. static void mptscsih_qas_check(MPT_SCSI_HOST *hd, int id);
  147. static int mptscsih_doDv(MPT_SCSI_HOST *hd, int channel, int target);
  148. static void mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage);
  149. static void mptscsih_fillbuf(char *buffer, int size, int index, int width);
  150. static void mptscsih_set_dvflags_raid(MPT_SCSI_HOST *hd, int id);
  151. #endif
  152. void mptscsih_remove(struct pci_dev *);
  153. void mptscsih_shutdown(struct pci_dev *);
  154. #ifdef CONFIG_PM
  155. int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
  156. int mptscsih_resume(struct pci_dev *pdev);
  157. #endif
  158. #define SNS_LEN(scp) sizeof((scp)->sense_buffer)
  159. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  160. /*
  161. * Domain Validation task structure
  162. */
  163. static DEFINE_SPINLOCK(dvtaskQ_lock);
  164. static int dvtaskQ_active = 0;
  165. static int dvtaskQ_release = 0;
  166. static struct work_struct dvTaskQ_task;
  167. #endif
  168. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  169. /**
  170. * mptscsih_add_sge - Place a simple SGE at address pAddr.
  171. * @pAddr: virtual address for SGE
  172. * @flagslength: SGE flags and data transfer length
  173. * @dma_addr: Physical address
  174. *
  175. * This routine places a MPT request frame back on the MPT adapter's
  176. * FreeQ.
  177. */
  178. static inline void
  179. mptscsih_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
  180. {
  181. if (sizeof(dma_addr_t) == sizeof(u64)) {
  182. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  183. u32 tmp = dma_addr & 0xFFFFFFFF;
  184. pSge->FlagsLength = cpu_to_le32(flagslength);
  185. pSge->Address.Low = cpu_to_le32(tmp);
  186. tmp = (u32) ((u64)dma_addr >> 32);
  187. pSge->Address.High = cpu_to_le32(tmp);
  188. } else {
  189. SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
  190. pSge->FlagsLength = cpu_to_le32(flagslength);
  191. pSge->Address = cpu_to_le32(dma_addr);
  192. }
  193. } /* mptscsih_add_sge() */
  194. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  195. /**
  196. * mptscsih_add_chain - Place a chain SGE at address pAddr.
  197. * @pAddr: virtual address for SGE
  198. * @next: nextChainOffset value (u32's)
  199. * @length: length of next SGL segment
  200. * @dma_addr: Physical address
  201. *
  202. * This routine places a MPT request frame back on the MPT adapter's
  203. * FreeQ.
  204. */
  205. static inline void
  206. mptscsih_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
  207. {
  208. if (sizeof(dma_addr_t) == sizeof(u64)) {
  209. SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
  210. u32 tmp = dma_addr & 0xFFFFFFFF;
  211. pChain->Length = cpu_to_le16(length);
  212. pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
  213. pChain->NextChainOffset = next;
  214. pChain->Address.Low = cpu_to_le32(tmp);
  215. tmp = (u32) ((u64)dma_addr >> 32);
  216. pChain->Address.High = cpu_to_le32(tmp);
  217. } else {
  218. SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
  219. pChain->Length = cpu_to_le16(length);
  220. pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
  221. pChain->NextChainOffset = next;
  222. pChain->Address = cpu_to_le32(dma_addr);
  223. }
  224. } /* mptscsih_add_chain() */
  225. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  226. /*
  227. * mptscsih_getFreeChainBuffer - Function to get a free chain
  228. * from the MPT_SCSI_HOST FreeChainQ.
  229. * @ioc: Pointer to MPT_ADAPTER structure
  230. * @req_idx: Index of the SCSI IO request frame. (output)
  231. *
  232. * return SUCCESS or FAILED
  233. */
  234. static inline int
  235. mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
  236. {
  237. MPT_FRAME_HDR *chainBuf;
  238. unsigned long flags;
  239. int rc;
  240. int chain_idx;
  241. dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer called\n",
  242. ioc->name));
  243. spin_lock_irqsave(&ioc->FreeQlock, flags);
  244. if (!list_empty(&ioc->FreeChainQ)) {
  245. int offset;
  246. chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,
  247. u.frame.linkage.list);
  248. list_del(&chainBuf->u.frame.linkage.list);
  249. offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
  250. chain_idx = offset / ioc->req_sz;
  251. rc = SUCCESS;
  252. dsgprintk((MYIOC_s_ERR_FMT "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
  253. ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
  254. } else {
  255. rc = FAILED;
  256. chain_idx = MPT_HOST_NO_CHAIN;
  257. dfailprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer failed\n",
  258. ioc->name));
  259. }
  260. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  261. *retIndex = chain_idx;
  262. return rc;
  263. } /* mptscsih_getFreeChainBuffer() */
  264. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  265. /*
  266. * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the
  267. * SCSIIORequest_t Message Frame.
  268. * @ioc: Pointer to MPT_ADAPTER structure
  269. * @SCpnt: Pointer to scsi_cmnd structure
  270. * @pReq: Pointer to SCSIIORequest_t structure
  271. *
  272. * Returns ...
  273. */
  274. static int
  275. mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
  276. SCSIIORequest_t *pReq, int req_idx)
  277. {
  278. char *psge;
  279. char *chainSge;
  280. struct scatterlist *sg;
  281. int frm_sz;
  282. int sges_left, sg_done;
  283. int chain_idx = MPT_HOST_NO_CHAIN;
  284. int sgeOffset;
  285. int numSgeSlots, numSgeThisFrame;
  286. u32 sgflags, sgdir, thisxfer = 0;
  287. int chain_dma_off = 0;
  288. int newIndex;
  289. int ii;
  290. dma_addr_t v2;
  291. u32 RequestNB;
  292. sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;
  293. if (sgdir == MPI_SCSIIO_CONTROL_WRITE) {
  294. sgdir = MPT_TRANSFER_HOST_TO_IOC;
  295. } else {
  296. sgdir = MPT_TRANSFER_IOC_TO_HOST;
  297. }
  298. psge = (char *) &pReq->SGL;
  299. frm_sz = ioc->req_sz;
  300. /* Map the data portion, if any.
  301. * sges_left = 0 if no data transfer.
  302. */
  303. if ( (sges_left = SCpnt->use_sg) ) {
  304. sges_left = pci_map_sg(ioc->pcidev,
  305. (struct scatterlist *) SCpnt->request_buffer,
  306. SCpnt->use_sg,
  307. SCpnt->sc_data_direction);
  308. if (sges_left == 0)
  309. return FAILED;
  310. } else if (SCpnt->request_bufflen) {
  311. SCpnt->SCp.dma_handle = pci_map_single(ioc->pcidev,
  312. SCpnt->request_buffer,
  313. SCpnt->request_bufflen,
  314. SCpnt->sc_data_direction);
  315. dsgprintk((MYIOC_s_INFO_FMT "SG: non-SG for %p, len=%d\n",
  316. ioc->name, SCpnt, SCpnt->request_bufflen));
  317. mptscsih_add_sge((char *) &pReq->SGL,
  318. 0xD1000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|SCpnt->request_bufflen,
  319. SCpnt->SCp.dma_handle);
  320. return SUCCESS;
  321. }
  322. /* Handle the SG case.
  323. */
  324. sg = (struct scatterlist *) SCpnt->request_buffer;
  325. sg_done = 0;
  326. sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);
  327. chainSge = NULL;
  328. /* Prior to entering this loop - the following must be set
  329. * current MF: sgeOffset (bytes)
  330. * chainSge (Null if original MF is not a chain buffer)
  331. * sg_done (num SGE done for this MF)
  332. */
  333. nextSGEset:
  334. numSgeSlots = ((frm_sz - sgeOffset) / (sizeof(u32) + sizeof(dma_addr_t)) );
  335. numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
  336. sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | MPT_SGE_FLAGS_ADDRESSING | sgdir;
  337. /* Get first (num - 1) SG elements
  338. * Skip any SG entries with a length of 0
  339. * NOTE: at finish, sg and psge pointed to NEXT data/location positions
  340. */
  341. for (ii=0; ii < (numSgeThisFrame-1); ii++) {
  342. thisxfer = sg_dma_len(sg);
  343. if (thisxfer == 0) {
  344. sg ++; /* Get next SG element from the OS */
  345. sg_done++;
  346. continue;
  347. }
  348. v2 = sg_dma_address(sg);
  349. mptscsih_add_sge(psge, sgflags | thisxfer, v2);
  350. sg++; /* Get next SG element from the OS */
  351. psge += (sizeof(u32) + sizeof(dma_addr_t));
  352. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  353. sg_done++;
  354. }
  355. if (numSgeThisFrame == sges_left) {
  356. /* Add last element, end of buffer and end of list flags.
  357. */
  358. sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT |
  359. MPT_SGE_FLAGS_END_OF_BUFFER |
  360. MPT_SGE_FLAGS_END_OF_LIST;
  361. /* Add last SGE and set termination flags.
  362. * Note: Last SGE may have a length of 0 - which should be ok.
  363. */
  364. thisxfer = sg_dma_len(sg);
  365. v2 = sg_dma_address(sg);
  366. mptscsih_add_sge(psge, sgflags | thisxfer, v2);
  367. /*
  368. sg++;
  369. psge += (sizeof(u32) + sizeof(dma_addr_t));
  370. */
  371. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  372. sg_done++;
  373. if (chainSge) {
  374. /* The current buffer is a chain buffer,
  375. * but there is not another one.
  376. * Update the chain element
  377. * Offset and Length fields.
  378. */
  379. mptscsih_add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
  380. } else {
  381. /* The current buffer is the original MF
  382. * and there is no Chain buffer.
  383. */
  384. pReq->ChainOffset = 0;
  385. RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
  386. dsgprintk((MYIOC_s_INFO_FMT
  387. "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
  388. ioc->RequestNB[req_idx] = RequestNB;
  389. }
  390. } else {
  391. /* At least one chain buffer is needed.
  392. * Complete the first MF
  393. * - last SGE element, set the LastElement bit
  394. * - set ChainOffset (words) for orig MF
  395. * (OR finish previous MF chain buffer)
  396. * - update MFStructPtr ChainIndex
  397. * - Populate chain element
  398. * Also
  399. * Loop until done.
  400. */
  401. dsgprintk((MYIOC_s_INFO_FMT "SG: Chain Required! sg done %d\n",
  402. ioc->name, sg_done));
  403. /* Set LAST_ELEMENT flag for last non-chain element
  404. * in the buffer. Since psge points at the NEXT
  405. * SGE element, go back one SGE element, update the flags
  406. * and reset the pointer. (Note: sgflags & thisxfer are already
  407. * set properly).
  408. */
  409. if (sg_done) {
  410. u32 *ptmp = (u32 *) (psge - (sizeof(u32) + sizeof(dma_addr_t)));
  411. sgflags = le32_to_cpu(*ptmp);
  412. sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;
  413. *ptmp = cpu_to_le32(sgflags);
  414. }
  415. if (chainSge) {
  416. /* The current buffer is a chain buffer.
  417. * chainSge points to the previous Chain Element.
  418. * Update its chain element Offset and Length (must
  419. * include chain element size) fields.
  420. * Old chain element is now complete.
  421. */
  422. u8 nextChain = (u8) (sgeOffset >> 2);
  423. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  424. mptscsih_add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
  425. } else {
  426. /* The original MF buffer requires a chain buffer -
  427. * set the offset.
  428. * Last element in this MF is a chain element.
  429. */
  430. pReq->ChainOffset = (u8) (sgeOffset >> 2);
  431. RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
  432. dsgprintk((MYIOC_s_ERR_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
  433. ioc->RequestNB[req_idx] = RequestNB;
  434. }
  435. sges_left -= sg_done;
  436. /* NOTE: psge points to the beginning of the chain element
  437. * in current buffer. Get a chain buffer.
  438. */
  439. if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) {
  440. dfailprintk((MYIOC_s_INFO_FMT
  441. "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",
  442. ioc->name, pReq->CDB[0], SCpnt));
  443. return FAILED;
  444. }
  445. /* Update the tracking arrays.
  446. * If chainSge == NULL, update ReqToChain, else ChainToChain
  447. */
  448. if (chainSge) {
  449. ioc->ChainToChain[chain_idx] = newIndex;
  450. } else {
  451. ioc->ReqToChain[req_idx] = newIndex;
  452. }
  453. chain_idx = newIndex;
  454. chain_dma_off = ioc->req_sz * chain_idx;
  455. /* Populate the chainSGE for the current buffer.
  456. * - Set chain buffer pointer to psge and fill
  457. * out the Address and Flags fields.
  458. */
  459. chainSge = (char *) psge;
  460. dsgprintk((KERN_INFO " Current buff @ %p (index 0x%x)",
  461. psge, req_idx));
  462. /* Start the SGE for the next buffer
  463. */
  464. psge = (char *) (ioc->ChainBuffer + chain_dma_off);
  465. sgeOffset = 0;
  466. sg_done = 0;
  467. dsgprintk((KERN_INFO " Chain buff @ %p (index 0x%x)\n",
  468. psge, chain_idx));
  469. /* Start the SGE for the next buffer
  470. */
  471. goto nextSGEset;
  472. }
  473. return SUCCESS;
  474. } /* mptscsih_AddSGE() */
  475. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  476. /*
  477. * mptscsih_io_done - Main SCSI IO callback routine registered to
  478. * Fusion MPT (base) driver
  479. * @ioc: Pointer to MPT_ADAPTER structure
  480. * @mf: Pointer to original MPT request frame
  481. * @r: Pointer to MPT reply frame (NULL if TurboReply)
  482. *
  483. * This routine is called from mpt.c::mpt_interrupt() at the completion
  484. * of any SCSI IO request.
  485. * This routine is registered with the Fusion MPT (base) driver at driver
  486. * load/init time via the mpt_register() API call.
  487. *
  488. * Returns 1 indicating alloc'd request frame ptr should be freed.
  489. */
  490. int
  491. mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  492. {
  493. struct scsi_cmnd *sc;
  494. MPT_SCSI_HOST *hd;
  495. SCSIIORequest_t *pScsiReq;
  496. SCSIIOReply_t *pScsiReply;
  497. u16 req_idx;
  498. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  499. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  500. sc = hd->ScsiLookup[req_idx];
  501. if (sc == NULL) {
  502. MPIHeader_t *hdr = (MPIHeader_t *)mf;
  503. /* Remark: writeSDP1 will use the ScsiDoneCtx
  504. * If a SCSI I/O cmd, device disabled by OS and
  505. * completion done. Cannot touch sc struct. Just free mem.
  506. */
  507. if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)
  508. printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",
  509. ioc->name);
  510. mptscsih_freeChainBuffers(ioc, req_idx);
  511. return 1;
  512. }
  513. sc->result = DID_OK << 16; /* Set default reply as OK */
  514. pScsiReq = (SCSIIORequest_t *) mf;
  515. pScsiReply = (SCSIIOReply_t *) mr;
  516. if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){
  517. dmfprintk((MYIOC_s_INFO_FMT
  518. "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
  519. ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));
  520. }else{
  521. dmfprintk((MYIOC_s_INFO_FMT
  522. "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
  523. ioc->name, mf, mr, sc, req_idx));
  524. }
  525. if (pScsiReply == NULL) {
  526. /* special context reply handling */
  527. ;
  528. } else {
  529. u32 xfer_cnt;
  530. u16 status;
  531. u8 scsi_state, scsi_status;
  532. status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  533. scsi_state = pScsiReply->SCSIState;
  534. scsi_status = pScsiReply->SCSIStatus;
  535. xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
  536. sc->resid = sc->request_bufflen - xfer_cnt;
  537. /*
  538. * if we get a data underrun indication, yet no data was
  539. * transferred and the SCSI status indicates that the
  540. * command was never started, change the data underrun
  541. * to success
  542. */
  543. if (status == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
  544. (scsi_status == MPI_SCSI_STATUS_BUSY ||
  545. scsi_status == MPI_SCSI_STATUS_RESERVATION_CONFLICT ||
  546. scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)) {
  547. status = MPI_IOCSTATUS_SUCCESS;
  548. }
  549. dreplyprintk((KERN_NOTICE "Reply ha=%d id=%d lun=%d:\n"
  550. "IOCStatus=%04xh SCSIState=%02xh SCSIStatus=%02xh\n"
  551. "resid=%d bufflen=%d xfer_cnt=%d\n",
  552. ioc->id, pScsiReq->TargetID, pScsiReq->LUN[1],
  553. status, scsi_state, scsi_status, sc->resid,
  554. sc->request_bufflen, xfer_cnt));
  555. if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
  556. mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
  557. /*
  558. * Look for + dump FCP ResponseInfo[]!
  559. */
  560. if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
  561. pScsiReply->ResponseInfo) {
  562. printk(KERN_NOTICE "ha=%d id=%d lun=%d: "
  563. "FCP_ResponseInfo=%08xh\n",
  564. ioc->id, pScsiReq->TargetID, pScsiReq->LUN[1],
  565. le32_to_cpu(pScsiReply->ResponseInfo));
  566. }
  567. switch(status) {
  568. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  569. /* CHECKME!
  570. * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
  571. * But not: DID_BUS_BUSY lest one risk
  572. * killing interrupt handler:-(
  573. */
  574. sc->result = SAM_STAT_BUSY;
  575. break;
  576. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  577. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  578. sc->result = DID_BAD_TARGET << 16;
  579. break;
  580. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  581. /* Spoof to SCSI Selection Timeout! */
  582. sc->result = DID_NO_CONNECT << 16;
  583. if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
  584. hd->sel_timeout[pScsiReq->TargetID]++;
  585. break;
  586. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  587. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  588. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  589. /* Linux handles an unsolicited DID_RESET better
  590. * than an unsolicited DID_ABORT.
  591. */
  592. sc->result = DID_RESET << 16;
  593. /* GEM Workaround. */
  594. if (ioc->bus_type == SCSI)
  595. mptscsih_no_negotiate(hd, sc->device->id);
  596. break;
  597. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  598. sc->resid = sc->request_bufflen - xfer_cnt;
  599. if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
  600. sc->result=DID_SOFT_ERROR << 16;
  601. else /* Sufficient data transfer occurred */
  602. sc->result = (DID_OK << 16) | scsi_status;
  603. dreplyprintk((KERN_NOTICE
  604. "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->device->id));
  605. break;
  606. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  607. /*
  608. * Do upfront check for valid SenseData and give it
  609. * precedence!
  610. */
  611. sc->result = (DID_OK << 16) | scsi_status;
  612. if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  613. /* Have already saved the status and sense data
  614. */
  615. ;
  616. } else {
  617. if (xfer_cnt < sc->underflow) {
  618. if (scsi_status == SAM_STAT_BUSY)
  619. sc->result = SAM_STAT_BUSY;
  620. else
  621. sc->result = DID_SOFT_ERROR << 16;
  622. }
  623. if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
  624. /* What to do?
  625. */
  626. sc->result = DID_SOFT_ERROR << 16;
  627. }
  628. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  629. /* Not real sure here either... */
  630. sc->result = DID_RESET << 16;
  631. }
  632. }
  633. dreplyprintk((KERN_NOTICE " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
  634. sc->underflow));
  635. dreplyprintk((KERN_NOTICE " ActBytesXferd=%02xh\n", xfer_cnt));
  636. /* Report Queue Full
  637. */
  638. if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
  639. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  640. break;
  641. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  642. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  643. if (scsi_status == MPI_SCSI_STATUS_BUSY)
  644. sc->result = (DID_BUS_BUSY << 16) | scsi_status;
  645. else
  646. sc->result = (DID_OK << 16) | scsi_status;
  647. if (scsi_state == 0) {
  648. ;
  649. } else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  650. /*
  651. * If running against circa 200003dd 909 MPT f/w,
  652. * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
  653. * (QUEUE_FULL) returned from device! --> get 0x0000?128
  654. * and with SenseBytes set to 0.
  655. */
  656. if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
  657. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  658. }
  659. else if (scsi_state &
  660. (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
  661. ) {
  662. /*
  663. * What to do?
  664. */
  665. sc->result = DID_SOFT_ERROR << 16;
  666. }
  667. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  668. /* Not real sure here either... */
  669. sc->result = DID_RESET << 16;
  670. }
  671. else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
  672. /* Device Inq. data indicates that it supports
  673. * QTags, but rejects QTag messages.
  674. * This command completed OK.
  675. *
  676. * Not real sure here either so do nothing... */
  677. }
  678. if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
  679. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  680. /* Add handling of:
  681. * Reservation Conflict, Busy,
  682. * Command Terminated, CHECK
  683. */
  684. break;
  685. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  686. sc->result = DID_SOFT_ERROR << 16;
  687. break;
  688. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  689. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  690. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  691. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  692. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  693. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  694. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  695. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  696. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  697. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  698. default:
  699. /*
  700. * What to do?
  701. */
  702. sc->result = DID_SOFT_ERROR << 16;
  703. break;
  704. } /* switch(status) */
  705. dreplyprintk((KERN_NOTICE " sc->result is %08xh\n", sc->result));
  706. } /* end of address reply case */
  707. /* Unmap the DMA buffers, if any. */
  708. if (sc->use_sg) {
  709. pci_unmap_sg(ioc->pcidev, (struct scatterlist *) sc->request_buffer,
  710. sc->use_sg, sc->sc_data_direction);
  711. } else if (sc->request_bufflen) {
  712. pci_unmap_single(ioc->pcidev, sc->SCp.dma_handle,
  713. sc->request_bufflen, sc->sc_data_direction);
  714. }
  715. hd->ScsiLookup[req_idx] = NULL;
  716. sc->scsi_done(sc); /* Issue the command callback */
  717. /* Free Chain buffers */
  718. mptscsih_freeChainBuffers(ioc, req_idx);
  719. return 1;
  720. }
  721. /*
  722. * mptscsih_flush_running_cmds - For each command found, search
  723. * Scsi_Host instance taskQ and reply to OS.
  724. * Called only if recovering from a FW reload.
  725. * @hd: Pointer to a SCSI HOST structure
  726. *
  727. * Returns: None.
  728. *
  729. * Must be called while new I/Os are being queued.
  730. */
  731. static void
  732. mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
  733. {
  734. MPT_ADAPTER *ioc = hd->ioc;
  735. struct scsi_cmnd *SCpnt;
  736. MPT_FRAME_HDR *mf;
  737. int ii;
  738. int max = ioc->req_depth;
  739. dprintk((KERN_INFO MYNAM ": flush_ScsiLookup called\n"));
  740. for (ii= 0; ii < max; ii++) {
  741. if ((SCpnt = hd->ScsiLookup[ii]) != NULL) {
  742. /* Command found.
  743. */
  744. /* Null ScsiLookup index
  745. */
  746. hd->ScsiLookup[ii] = NULL;
  747. mf = MPT_INDEX_2_MFPTR(ioc, ii);
  748. dmfprintk(( "flush: ScsiDone (mf=%p,sc=%p)\n",
  749. mf, SCpnt));
  750. /* Set status, free OS resources (SG DMA buffers)
  751. * Do OS callback
  752. * Free driver resources (chain, msg buffers)
  753. */
  754. if (SCpnt->use_sg) {
  755. pci_unmap_sg(ioc->pcidev,
  756. (struct scatterlist *) SCpnt->request_buffer,
  757. SCpnt->use_sg,
  758. SCpnt->sc_data_direction);
  759. } else if (SCpnt->request_bufflen) {
  760. pci_unmap_single(ioc->pcidev,
  761. SCpnt->SCp.dma_handle,
  762. SCpnt->request_bufflen,
  763. SCpnt->sc_data_direction);
  764. }
  765. SCpnt->result = DID_RESET << 16;
  766. SCpnt->host_scribble = NULL;
  767. /* Free Chain buffers */
  768. mptscsih_freeChainBuffers(ioc, ii);
  769. /* Free Message frames */
  770. mpt_free_msg_frame(ioc, mf);
  771. SCpnt->scsi_done(SCpnt); /* Issue the command callback */
  772. }
  773. }
  774. return;
  775. }
  776. /*
  777. * mptscsih_search_running_cmds - Delete any commands associated
  778. * with the specified target and lun. Function called only
  779. * when a lun is disable by mid-layer.
  780. * Do NOT access the referenced scsi_cmnd structure or
  781. * members. Will cause either a paging or NULL ptr error.
  782. * @hd: Pointer to a SCSI HOST structure
  783. * @target: target id
  784. * @lun: lun
  785. *
  786. * Returns: None.
  787. *
  788. * Called from slave_destroy.
  789. */
  790. static void
  791. mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, uint target, uint lun)
  792. {
  793. SCSIIORequest_t *mf = NULL;
  794. int ii;
  795. int max = hd->ioc->req_depth;
  796. struct scsi_cmnd *sc;
  797. dsprintk((KERN_INFO MYNAM ": search_running target %d lun %d max %d\n",
  798. target, lun, max));
  799. for (ii=0; ii < max; ii++) {
  800. if ((sc = hd->ScsiLookup[ii]) != NULL) {
  801. mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii);
  802. dsprintk(( "search_running: found (sc=%p, mf = %p) target %d, lun %d \n",
  803. hd->ScsiLookup[ii], mf, mf->TargetID, mf->LUN[1]));
  804. if ((mf->TargetID != ((u8)target)) || (mf->LUN[1] != ((u8) lun)))
  805. continue;
  806. /* Cleanup
  807. */
  808. hd->ScsiLookup[ii] = NULL;
  809. mptscsih_freeChainBuffers(hd->ioc, ii);
  810. mpt_free_msg_frame(hd->ioc, (MPT_FRAME_HDR *)mf);
  811. if (sc->use_sg) {
  812. pci_unmap_sg(hd->ioc->pcidev,
  813. (struct scatterlist *) sc->request_buffer,
  814. sc->use_sg,
  815. sc->sc_data_direction);
  816. } else if (sc->request_bufflen) {
  817. pci_unmap_single(hd->ioc->pcidev,
  818. sc->SCp.dma_handle,
  819. sc->request_bufflen,
  820. sc->sc_data_direction);
  821. }
  822. sc->host_scribble = NULL;
  823. sc->result = DID_NO_CONNECT << 16;
  824. sc->scsi_done(sc);
  825. }
  826. }
  827. return;
  828. }
  829. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  830. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  831. /*
  832. * mptscsih_report_queue_full - Report QUEUE_FULL status returned
  833. * from a SCSI target device.
  834. * @sc: Pointer to scsi_cmnd structure
  835. * @pScsiReply: Pointer to SCSIIOReply_t
  836. * @pScsiReq: Pointer to original SCSI request
  837. *
  838. * This routine periodically reports QUEUE_FULL status returned from a
  839. * SCSI target device. It reports this to the console via kernel
  840. * printk() API call, not more than once every 10 seconds.
  841. */
  842. static void
  843. mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
  844. {
  845. long time = jiffies;
  846. MPT_SCSI_HOST *hd;
  847. if (sc->device == NULL)
  848. return;
  849. if (sc->device->host == NULL)
  850. return;
  851. if ((hd = (MPT_SCSI_HOST *)sc->device->host->hostdata) == NULL)
  852. return;
  853. if (time - hd->last_queue_full > 10 * HZ) {
  854. dprintk((MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
  855. hd->ioc->name, 0, sc->device->id, sc->device->lun));
  856. hd->last_queue_full = time;
  857. }
  858. }
  859. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  860. /*
  861. * mptscsih_remove - Removed scsi devices
  862. * @pdev: Pointer to pci_dev structure
  863. *
  864. *
  865. */
  866. void
  867. mptscsih_remove(struct pci_dev *pdev)
  868. {
  869. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  870. struct Scsi_Host *host = ioc->sh;
  871. MPT_SCSI_HOST *hd;
  872. int count;
  873. unsigned long flags;
  874. int sz1;
  875. if(!host) {
  876. mpt_detach(pdev);
  877. return;
  878. }
  879. scsi_remove_host(host);
  880. if((hd = (MPT_SCSI_HOST *)host->hostdata) == NULL)
  881. return;
  882. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  883. /* Check DV thread active */
  884. count = 10 * HZ;
  885. spin_lock_irqsave(&dvtaskQ_lock, flags);
  886. if (dvtaskQ_active) {
  887. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  888. while(dvtaskQ_active && --count)
  889. schedule_timeout_interruptible(1);
  890. } else {
  891. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  892. }
  893. if (!count)
  894. printk(KERN_ERR MYNAM ": ERROR - DV thread still active!\n");
  895. #if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY)
  896. else
  897. printk(KERN_ERR MYNAM ": DV thread orig %d, count %d\n", 10 * HZ, count);
  898. #endif
  899. #endif
  900. mptscsih_shutdown(pdev);
  901. sz1=0;
  902. if (hd->ScsiLookup != NULL) {
  903. sz1 = hd->ioc->req_depth * sizeof(void *);
  904. kfree(hd->ScsiLookup);
  905. hd->ScsiLookup = NULL;
  906. }
  907. /*
  908. * Free pointer array.
  909. */
  910. kfree(hd->Targets);
  911. hd->Targets = NULL;
  912. dprintk((MYIOC_s_INFO_FMT
  913. "Free'd ScsiLookup (%d) memory\n",
  914. hd->ioc->name, sz1));
  915. kfree(hd->info_kbuf);
  916. /* NULL the Scsi_Host pointer
  917. */
  918. hd->ioc->sh = NULL;
  919. scsi_host_put(host);
  920. mpt_detach(pdev);
  921. }
  922. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  923. /*
  924. * mptscsih_shutdown - reboot notifier
  925. *
  926. */
  927. void
  928. mptscsih_shutdown(struct pci_dev *pdev)
  929. {
  930. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  931. struct Scsi_Host *host = ioc->sh;
  932. MPT_SCSI_HOST *hd;
  933. if(!host)
  934. return;
  935. hd = (MPT_SCSI_HOST *)host->hostdata;
  936. /* Flush the cache of this adapter
  937. */
  938. if(hd != NULL)
  939. mptscsih_synchronize_cache(hd, 0);
  940. }
  941. #ifdef CONFIG_PM
  942. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  943. /*
  944. * mptscsih_suspend - Fusion MPT scsi driver suspend routine.
  945. *
  946. *
  947. */
  948. int
  949. mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
  950. {
  951. mptscsih_shutdown(pdev);
  952. return mpt_suspend(pdev,state);
  953. }
  954. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  955. /*
  956. * mptscsih_resume - Fusion MPT scsi driver resume routine.
  957. *
  958. *
  959. */
  960. int
  961. mptscsih_resume(struct pci_dev *pdev)
  962. {
  963. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  964. struct Scsi_Host *host = ioc->sh;
  965. MPT_SCSI_HOST *hd;
  966. mpt_resume(pdev);
  967. if(!host)
  968. return 0;
  969. hd = (MPT_SCSI_HOST *)host->hostdata;
  970. if(!hd)
  971. return 0;
  972. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  973. {
  974. unsigned long lflags;
  975. spin_lock_irqsave(&dvtaskQ_lock, lflags);
  976. if (!dvtaskQ_active) {
  977. dvtaskQ_active = 1;
  978. spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
  979. INIT_WORK(&dvTaskQ_task,
  980. mptscsih_domainValidation, (void *) hd);
  981. schedule_work(&dvTaskQ_task);
  982. } else {
  983. spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
  984. }
  985. }
  986. #endif
  987. return 0;
  988. }
  989. #endif
  990. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  991. /**
  992. * mptscsih_info - Return information about MPT adapter
  993. * @SChost: Pointer to Scsi_Host structure
  994. *
  995. * (linux scsi_host_template.info routine)
  996. *
  997. * Returns pointer to buffer where information was written.
  998. */
  999. const char *
  1000. mptscsih_info(struct Scsi_Host *SChost)
  1001. {
  1002. MPT_SCSI_HOST *h;
  1003. int size = 0;
  1004. h = (MPT_SCSI_HOST *)SChost->hostdata;
  1005. if (h) {
  1006. if (h->info_kbuf == NULL)
  1007. if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
  1008. return h->info_kbuf;
  1009. h->info_kbuf[0] = '\0';
  1010. mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
  1011. h->info_kbuf[size-1] = '\0';
  1012. }
  1013. return h->info_kbuf;
  1014. }
  1015. struct info_str {
  1016. char *buffer;
  1017. int length;
  1018. int offset;
  1019. int pos;
  1020. };
  1021. static void
  1022. mptscsih_copy_mem_info(struct info_str *info, char *data, int len)
  1023. {
  1024. if (info->pos + len > info->length)
  1025. len = info->length - info->pos;
  1026. if (info->pos + len < info->offset) {
  1027. info->pos += len;
  1028. return;
  1029. }
  1030. if (info->pos < info->offset) {
  1031. data += (info->offset - info->pos);
  1032. len -= (info->offset - info->pos);
  1033. }
  1034. if (len > 0) {
  1035. memcpy(info->buffer + info->pos, data, len);
  1036. info->pos += len;
  1037. }
  1038. }
  1039. static int
  1040. mptscsih_copy_info(struct info_str *info, char *fmt, ...)
  1041. {
  1042. va_list args;
  1043. char buf[81];
  1044. int len;
  1045. va_start(args, fmt);
  1046. len = vsprintf(buf, fmt, args);
  1047. va_end(args);
  1048. mptscsih_copy_mem_info(info, buf, len);
  1049. return len;
  1050. }
  1051. static int
  1052. mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)
  1053. {
  1054. struct info_str info;
  1055. info.buffer = pbuf;
  1056. info.length = len;
  1057. info.offset = offset;
  1058. info.pos = 0;
  1059. mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);
  1060. mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
  1061. mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);
  1062. mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth);
  1063. return ((info.pos > info.offset) ? info.pos - info.offset : 0);
  1064. }
  1065. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1066. /**
  1067. * mptscsih_proc_info - Return information about MPT adapter
  1068. *
  1069. * (linux scsi_host_template.info routine)
  1070. *
  1071. * buffer: if write, user data; if read, buffer for user
  1072. * length: if write, return length;
  1073. * offset: if write, 0; if read, the current offset into the buffer from
  1074. * the previous read.
  1075. * hostno: scsi host number
  1076. * func: if write = 1; if read = 0
  1077. */
  1078. int
  1079. mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
  1080. int length, int func)
  1081. {
  1082. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  1083. MPT_ADAPTER *ioc = hd->ioc;
  1084. int size = 0;
  1085. if (func) {
  1086. /*
  1087. * write is not supported
  1088. */
  1089. } else {
  1090. if (start)
  1091. *start = buffer;
  1092. size = mptscsih_host_info(ioc, buffer, offset, length);
  1093. }
  1094. return size;
  1095. }
  1096. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1097. #define ADD_INDEX_LOG(req_ent) do { } while(0)
  1098. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1099. /**
  1100. * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
  1101. * @SCpnt: Pointer to scsi_cmnd structure
  1102. * @done: Pointer SCSI mid-layer IO completion function
  1103. *
  1104. * (linux scsi_host_template.queuecommand routine)
  1105. * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
  1106. * from a linux scsi_cmnd request and send it to the IOC.
  1107. *
  1108. * Returns 0. (rtn value discarded by linux scsi mid-layer)
  1109. */
  1110. int
  1111. mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
  1112. {
  1113. MPT_SCSI_HOST *hd;
  1114. MPT_FRAME_HDR *mf;
  1115. SCSIIORequest_t *pScsiReq;
  1116. VirtDevice *pTarget = SCpnt->device->hostdata;
  1117. int lun;
  1118. u32 datalen;
  1119. u32 scsictl;
  1120. u32 scsidir;
  1121. u32 cmd_len;
  1122. int my_idx;
  1123. int ii;
  1124. hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata;
  1125. lun = SCpnt->device->lun;
  1126. SCpnt->scsi_done = done;
  1127. dmfprintk((MYIOC_s_INFO_FMT "qcmd: SCpnt=%p, done()=%p\n",
  1128. (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt, done));
  1129. if (hd->resetPending) {
  1130. dtmprintk((MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
  1131. (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt));
  1132. return SCSI_MLQUEUE_HOST_BUSY;
  1133. }
  1134. /*
  1135. * Put together a MPT SCSI request...
  1136. */
  1137. if ((mf = mpt_get_msg_frame(hd->ioc->DoneCtx, hd->ioc)) == NULL) {
  1138. dprintk((MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
  1139. hd->ioc->name));
  1140. return SCSI_MLQUEUE_HOST_BUSY;
  1141. }
  1142. pScsiReq = (SCSIIORequest_t *) mf;
  1143. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  1144. ADD_INDEX_LOG(my_idx);
  1145. /* TUR's being issued with scsictl=0x02000000 (DATA_IN)!
  1146. * Seems we may receive a buffer (datalen>0) even when there
  1147. * will be no data transfer! GRRRRR...
  1148. */
  1149. if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
  1150. datalen = SCpnt->request_bufflen;
  1151. scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
  1152. } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
  1153. datalen = SCpnt->request_bufflen;
  1154. scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
  1155. } else {
  1156. datalen = 0;
  1157. scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
  1158. }
  1159. /* Default to untagged. Once a target structure has been allocated,
  1160. * use the Inquiry data to determine if device supports tagged.
  1161. */
  1162. if (pTarget
  1163. && (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)
  1164. && (SCpnt->device->tagged_supported)) {
  1165. scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
  1166. } else {
  1167. scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
  1168. }
  1169. /* Use the above information to set up the message frame
  1170. */
  1171. pScsiReq->TargetID = (u8) pTarget->target_id;
  1172. pScsiReq->Bus = pTarget->bus_id;
  1173. pScsiReq->ChainOffset = 0;
  1174. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  1175. pScsiReq->CDBLength = SCpnt->cmd_len;
  1176. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1177. pScsiReq->Reserved = 0;
  1178. pScsiReq->MsgFlags = mpt_msg_flags();
  1179. pScsiReq->LUN[0] = 0;
  1180. pScsiReq->LUN[1] = lun;
  1181. pScsiReq->LUN[2] = 0;
  1182. pScsiReq->LUN[3] = 0;
  1183. pScsiReq->LUN[4] = 0;
  1184. pScsiReq->LUN[5] = 0;
  1185. pScsiReq->LUN[6] = 0;
  1186. pScsiReq->LUN[7] = 0;
  1187. pScsiReq->Control = cpu_to_le32(scsictl);
  1188. /*
  1189. * Write SCSI CDB into the message
  1190. */
  1191. cmd_len = SCpnt->cmd_len;
  1192. for (ii=0; ii < cmd_len; ii++)
  1193. pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
  1194. for (ii=cmd_len; ii < 16; ii++)
  1195. pScsiReq->CDB[ii] = 0;
  1196. /* DataLength */
  1197. pScsiReq->DataLength = cpu_to_le32(datalen);
  1198. /* SenseBuffer low address */
  1199. pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
  1200. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  1201. /* Now add the SG list
  1202. * Always have a SGE even if null length.
  1203. */
  1204. if (datalen == 0) {
  1205. /* Add a NULL SGE */
  1206. mptscsih_add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0,
  1207. (dma_addr_t) -1);
  1208. } else {
  1209. /* Add a 32 or 64 bit SGE */
  1210. if (mptscsih_AddSGE(hd->ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
  1211. goto fail;
  1212. }
  1213. hd->ScsiLookup[my_idx] = SCpnt;
  1214. SCpnt->host_scribble = NULL;
  1215. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  1216. if (hd->ioc->bus_type == SCSI) {
  1217. int dvStatus = hd->ioc->spi_data.dvStatus[pTarget->target_id];
  1218. int issueCmd = 1;
  1219. if (dvStatus || hd->ioc->spi_data.forceDv) {
  1220. if ((dvStatus & MPT_SCSICFG_NEED_DV) ||
  1221. (hd->ioc->spi_data.forceDv & MPT_SCSICFG_NEED_DV)) {
  1222. unsigned long lflags;
  1223. /* Schedule DV if necessary */
  1224. spin_lock_irqsave(&dvtaskQ_lock, lflags);
  1225. if (!dvtaskQ_active) {
  1226. dvtaskQ_active = 1;
  1227. spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
  1228. INIT_WORK(&dvTaskQ_task, mptscsih_domainValidation, (void *) hd);
  1229. schedule_work(&dvTaskQ_task);
  1230. } else {
  1231. spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
  1232. }
  1233. hd->ioc->spi_data.forceDv &= ~MPT_SCSICFG_NEED_DV;
  1234. }
  1235. /* Trying to do DV to this target, extend timeout.
  1236. * Wait to issue until flag is clear
  1237. */
  1238. if (dvStatus & MPT_SCSICFG_DV_PENDING) {
  1239. mod_timer(&SCpnt->eh_timeout, jiffies + 40 * HZ);
  1240. issueCmd = 0;
  1241. }
  1242. /* Set the DV flags.
  1243. */
  1244. if (dvStatus & MPT_SCSICFG_DV_NOT_DONE)
  1245. mptscsih_set_dvflags(hd, pScsiReq);
  1246. if (!issueCmd)
  1247. goto fail;
  1248. }
  1249. }
  1250. #endif
  1251. mpt_put_msg_frame(hd->ioc->DoneCtx, hd->ioc, mf);
  1252. dmfprintk((MYIOC_s_INFO_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
  1253. hd->ioc->name, SCpnt, mf, my_idx));
  1254. DBG_DUMP_REQUEST_FRAME(mf)
  1255. return 0;
  1256. fail:
  1257. hd->ScsiLookup[my_idx] = NULL;
  1258. mptscsih_freeChainBuffers(hd->ioc, my_idx);
  1259. mpt_free_msg_frame(hd->ioc, mf);
  1260. return SCSI_MLQUEUE_HOST_BUSY;
  1261. }
  1262. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1263. /*
  1264. * mptscsih_freeChainBuffers - Function to free chain buffers associated
  1265. * with a SCSI IO request
  1266. * @hd: Pointer to the MPT_SCSI_HOST instance
  1267. * @req_idx: Index of the SCSI IO request frame.
  1268. *
  1269. * Called if SG chain buffer allocation fails and mptscsih callbacks.
  1270. * No return.
  1271. */
  1272. static void
  1273. mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
  1274. {
  1275. MPT_FRAME_HDR *chain;
  1276. unsigned long flags;
  1277. int chain_idx;
  1278. int next;
  1279. /* Get the first chain index and reset
  1280. * tracker state.
  1281. */
  1282. chain_idx = ioc->ReqToChain[req_idx];
  1283. ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
  1284. while (chain_idx != MPT_HOST_NO_CHAIN) {
  1285. /* Save the next chain buffer index */
  1286. next = ioc->ChainToChain[chain_idx];
  1287. /* Free this chain buffer and reset
  1288. * tracker
  1289. */
  1290. ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
  1291. chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
  1292. + (chain_idx * ioc->req_sz));
  1293. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1294. list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
  1295. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1296. dmfprintk((MYIOC_s_INFO_FMT "FreeChainBuffers (index %d)\n",
  1297. ioc->name, chain_idx));
  1298. /* handle next */
  1299. chain_idx = next;
  1300. }
  1301. return;
  1302. }
  1303. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1304. /*
  1305. * Reset Handling
  1306. */
  1307. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1308. /*
  1309. * mptscsih_TMHandler - Generic handler for SCSI Task Management.
  1310. * Fall through to mpt_HardResetHandler if: not operational, too many
  1311. * failed TM requests or handshake failure.
  1312. *
  1313. * @ioc: Pointer to MPT_ADAPTER structure
  1314. * @type: Task Management type
  1315. * @target: Logical Target ID for reset (if appropriate)
  1316. * @lun: Logical Unit for reset (if appropriate)
  1317. * @ctx2abort: Context for the task to be aborted (if appropriate)
  1318. *
  1319. * Remark: Currently invoked from a non-interrupt thread (_bh).
  1320. *
  1321. * Remark: With old EH code, at most 1 SCSI TaskMgmt function per IOC
  1322. * will be active.
  1323. *
  1324. * Returns 0 for SUCCESS or -1 if FAILED.
  1325. */
  1326. static int
  1327. mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout)
  1328. {
  1329. MPT_ADAPTER *ioc;
  1330. int rc = -1;
  1331. int doTask = 1;
  1332. u32 ioc_raw_state;
  1333. unsigned long flags;
  1334. /* If FW is being reloaded currently, return success to
  1335. * the calling function.
  1336. */
  1337. if (hd == NULL)
  1338. return 0;
  1339. ioc = hd->ioc;
  1340. if (ioc == NULL) {
  1341. printk(KERN_ERR MYNAM " TMHandler" " NULL ioc!\n");
  1342. return FAILED;
  1343. }
  1344. dtmprintk((MYIOC_s_INFO_FMT "TMHandler Entered!\n", ioc->name));
  1345. // SJR - CHECKME - Can we avoid this here?
  1346. // (mpt_HardResetHandler has this check...)
  1347. spin_lock_irqsave(&ioc->diagLock, flags);
  1348. if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)) {
  1349. spin_unlock_irqrestore(&ioc->diagLock, flags);
  1350. return FAILED;
  1351. }
  1352. spin_unlock_irqrestore(&ioc->diagLock, flags);
  1353. /* Wait a fixed amount of time for the TM pending flag to be cleared.
  1354. * If we time out and not bus reset, then we return a FAILED status to the caller.
  1355. * The call to mptscsih_tm_pending_wait() will set the pending flag if we are
  1356. * successful. Otherwise, reload the FW.
  1357. */
  1358. if (mptscsih_tm_pending_wait(hd) == FAILED) {
  1359. if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
  1360. dtmprintk((KERN_INFO MYNAM ": %s: TMHandler abort: "
  1361. "Timed out waiting for last TM (%d) to complete! \n",
  1362. hd->ioc->name, hd->tmPending));
  1363. return FAILED;
  1364. } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
  1365. dtmprintk((KERN_INFO MYNAM ": %s: TMHandler target reset: "
  1366. "Timed out waiting for last TM (%d) to complete! \n",
  1367. hd->ioc->name, hd->tmPending));
  1368. return FAILED;
  1369. } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
  1370. dtmprintk((KERN_INFO MYNAM ": %s: TMHandler bus reset: "
  1371. "Timed out waiting for last TM (%d) to complete! \n",
  1372. hd->ioc->name, hd->tmPending));
  1373. if (hd->tmPending & (1 << MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS))
  1374. return FAILED;
  1375. doTask = 0;
  1376. }
  1377. } else {
  1378. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1379. hd->tmPending |= (1 << type);
  1380. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1381. }
  1382. /* Is operational?
  1383. */
  1384. ioc_raw_state = mpt_GetIocState(hd->ioc, 0);
  1385. #ifdef MPT_DEBUG_RESET
  1386. if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
  1387. printk(MYIOC_s_WARN_FMT
  1388. "TM Handler: IOC Not operational(0x%x)!\n",
  1389. hd->ioc->name, ioc_raw_state);
  1390. }
  1391. #endif
  1392. if (doTask && ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL)
  1393. && !(ioc_raw_state & MPI_DOORBELL_ACTIVE)) {
  1394. /* Isse the Task Mgmt request.
  1395. */
  1396. if (hd->hard_resets < -1)
  1397. hd->hard_resets++;
  1398. rc = mptscsih_IssueTaskMgmt(hd, type, channel, target, lun, ctx2abort, timeout);
  1399. if (rc) {
  1400. printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n", hd->ioc->name);
  1401. } else {
  1402. dtmprintk((MYIOC_s_INFO_FMT "Issue of TaskMgmt Successful!\n", hd->ioc->name));
  1403. }
  1404. }
  1405. /* Only fall through to the HRH if this is a bus reset
  1406. */
  1407. if ((type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) && (rc ||
  1408. ioc->reload_fw || (ioc->alt_ioc && ioc->alt_ioc->reload_fw))) {
  1409. dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
  1410. hd->ioc->name));
  1411. rc = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
  1412. }
  1413. dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc));
  1414. return rc;
  1415. }
  1416. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1417. /*
  1418. * mptscsih_IssueTaskMgmt - Generic send Task Management function.
  1419. * @hd: Pointer to MPT_SCSI_HOST structure
  1420. * @type: Task Management type
  1421. * @target: Logical Target ID for reset (if appropriate)
  1422. * @lun: Logical Unit for reset (if appropriate)
  1423. * @ctx2abort: Context for the task to be aborted (if appropriate)
  1424. *
  1425. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  1426. * or a non-interrupt thread. In the former, must not call schedule().
  1427. *
  1428. * Not all fields are meaningfull for all task types.
  1429. *
  1430. * Returns 0 for SUCCESS, -999 for "no msg frames",
  1431. * else other non-zero value returned.
  1432. */
  1433. static int
  1434. mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout)
  1435. {
  1436. MPT_FRAME_HDR *mf;
  1437. SCSITaskMgmt_t *pScsiTm;
  1438. int ii;
  1439. int retval;
  1440. /* Return Fail to calling function if no message frames available.
  1441. */
  1442. if ((mf = mpt_get_msg_frame(hd->ioc->TaskCtx, hd->ioc)) == NULL) {
  1443. dfailprintk((MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
  1444. hd->ioc->name));
  1445. return FAILED;
  1446. }
  1447. dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
  1448. hd->ioc->name, mf));
  1449. /* Format the Request
  1450. */
  1451. pScsiTm = (SCSITaskMgmt_t *) mf;
  1452. pScsiTm->TargetID = target;
  1453. pScsiTm->Bus = channel;
  1454. pScsiTm->ChainOffset = 0;
  1455. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  1456. pScsiTm->Reserved = 0;
  1457. pScsiTm->TaskType = type;
  1458. pScsiTm->Reserved1 = 0;
  1459. pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
  1460. ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
  1461. for (ii= 0; ii < 8; ii++) {
  1462. pScsiTm->LUN[ii] = 0;
  1463. }
  1464. pScsiTm->LUN[1] = lun;
  1465. for (ii=0; ii < 7; ii++)
  1466. pScsiTm->Reserved2[ii] = 0;
  1467. pScsiTm->TaskMsgContext = ctx2abort;
  1468. dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt: ctx2abort (0x%08x) type=%d\n",
  1469. hd->ioc->name, ctx2abort, type));
  1470. DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm);
  1471. if ((retval = mpt_send_handshake_request(hd->ioc->TaskCtx, hd->ioc,
  1472. sizeof(SCSITaskMgmt_t), (u32*)pScsiTm,
  1473. CAN_SLEEP)) != 0) {
  1474. dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!"
  1475. " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
  1476. hd->ioc, mf));
  1477. mpt_free_msg_frame(hd->ioc, mf);
  1478. return retval;
  1479. }
  1480. if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) {
  1481. dfailprintk((MYIOC_s_ERR_FMT "_wait_for_completion FAILED!"
  1482. " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
  1483. hd->ioc, mf));
  1484. mpt_free_msg_frame(hd->ioc, mf);
  1485. dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
  1486. hd->ioc->name));
  1487. retval = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
  1488. }
  1489. return retval;
  1490. }
  1491. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1492. /**
  1493. * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
  1494. * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
  1495. *
  1496. * (linux scsi_host_template.eh_abort_handler routine)
  1497. *
  1498. * Returns SUCCESS or FAILED.
  1499. */
  1500. int
  1501. mptscsih_abort(struct scsi_cmnd * SCpnt)
  1502. {
  1503. MPT_SCSI_HOST *hd;
  1504. MPT_ADAPTER *ioc;
  1505. MPT_FRAME_HDR *mf;
  1506. u32 ctx2abort;
  1507. int scpnt_idx;
  1508. int retval;
  1509. /* If we can't locate our host adapter structure, return FAILED status.
  1510. */
  1511. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL) {
  1512. SCpnt->result = DID_RESET << 16;
  1513. SCpnt->scsi_done(SCpnt);
  1514. dfailprintk((KERN_INFO MYNAM ": mptscsih_abort: "
  1515. "Can't locate host! (sc=%p)\n",
  1516. SCpnt));
  1517. return FAILED;
  1518. }
  1519. ioc = hd->ioc;
  1520. if (hd->resetPending) {
  1521. return FAILED;
  1522. }
  1523. if (hd->timeouts < -1)
  1524. hd->timeouts++;
  1525. /* Find this command
  1526. */
  1527. if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(SCpnt)) < 0) {
  1528. /* Cmd not found in ScsiLookup.
  1529. * Do OS callback.
  1530. */
  1531. SCpnt->result = DID_RESET << 16;
  1532. dtmprintk((KERN_INFO MYNAM ": %s: mptscsih_abort: "
  1533. "Command not in the active list! (sc=%p)\n",
  1534. hd->ioc->name, SCpnt));
  1535. return SUCCESS;
  1536. }
  1537. printk(KERN_WARNING MYNAM ": %s: attempting task abort! (sc=%p)\n",
  1538. hd->ioc->name, SCpnt);
  1539. scsi_print_command(SCpnt);
  1540. /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
  1541. * (the IO to be ABORT'd)
  1542. *
  1543. * NOTE: Since we do not byteswap MsgContext, we do not
  1544. * swap it here either. It is an opaque cookie to
  1545. * the controller, so it does not matter. -DaveM
  1546. */
  1547. mf = MPT_INDEX_2_MFPTR(hd->ioc, scpnt_idx);
  1548. ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
  1549. hd->abortSCpnt = SCpnt;
  1550. retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
  1551. SCpnt->device->channel, SCpnt->device->id, SCpnt->device->lun,
  1552. ctx2abort, 2 /* 2 second timeout */);
  1553. printk (KERN_WARNING MYNAM ": %s: task abort: %s (sc=%p)\n",
  1554. hd->ioc->name,
  1555. ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1556. if (retval == 0)
  1557. return SUCCESS;
  1558. if(retval != FAILED ) {
  1559. hd->tmPending = 0;
  1560. hd->tmState = TM_STATE_NONE;
  1561. }
  1562. return FAILED;
  1563. }
  1564. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1565. /**
  1566. * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
  1567. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1568. *
  1569. * (linux scsi_host_template.eh_dev_reset_handler routine)
  1570. *
  1571. * Returns SUCCESS or FAILED.
  1572. */
  1573. int
  1574. mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
  1575. {
  1576. MPT_SCSI_HOST *hd;
  1577. int retval;
  1578. /* If we can't locate our host adapter structure, return FAILED status.
  1579. */
  1580. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1581. dtmprintk((KERN_INFO MYNAM ": mptscsih_dev_reset: "
  1582. "Can't locate host! (sc=%p)\n",
  1583. SCpnt));
  1584. return FAILED;
  1585. }
  1586. if (hd->resetPending)
  1587. return FAILED;
  1588. printk(KERN_WARNING MYNAM ": %s: attempting target reset! (sc=%p)\n",
  1589. hd->ioc->name, SCpnt);
  1590. scsi_print_command(SCpnt);
  1591. retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
  1592. SCpnt->device->channel, SCpnt->device->id,
  1593. 0, 0, 5 /* 5 second timeout */);
  1594. printk (KERN_WARNING MYNAM ": %s: target reset: %s (sc=%p)\n",
  1595. hd->ioc->name,
  1596. ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1597. if (retval == 0)
  1598. return SUCCESS;
  1599. if(retval != FAILED ) {
  1600. hd->tmPending = 0;
  1601. hd->tmState = TM_STATE_NONE;
  1602. }
  1603. return FAILED;
  1604. }
  1605. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1606. /**
  1607. * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
  1608. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1609. *
  1610. * (linux scsi_host_template.eh_bus_reset_handler routine)
  1611. *
  1612. * Returns SUCCESS or FAILED.
  1613. */
  1614. int
  1615. mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
  1616. {
  1617. MPT_SCSI_HOST *hd;
  1618. int retval;
  1619. /* If we can't locate our host adapter structure, return FAILED status.
  1620. */
  1621. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1622. dtmprintk((KERN_INFO MYNAM ": mptscsih_bus_reset: "
  1623. "Can't locate host! (sc=%p)\n",
  1624. SCpnt ) );
  1625. return FAILED;
  1626. }
  1627. printk(KERN_WARNING MYNAM ": %s: attempting bus reset! (sc=%p)\n",
  1628. hd->ioc->name, SCpnt);
  1629. scsi_print_command(SCpnt);
  1630. if (hd->timeouts < -1)
  1631. hd->timeouts++;
  1632. retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  1633. SCpnt->device->channel, 0, 0, 0, 5 /* 5 second timeout */);
  1634. printk (KERN_WARNING MYNAM ": %s: bus reset: %s (sc=%p)\n",
  1635. hd->ioc->name,
  1636. ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
  1637. if (retval == 0)
  1638. return SUCCESS;
  1639. if(retval != FAILED ) {
  1640. hd->tmPending = 0;
  1641. hd->tmState = TM_STATE_NONE;
  1642. }
  1643. return FAILED;
  1644. }
  1645. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1646. /**
  1647. * mptscsih_host_reset - Perform a SCSI host adapter RESET!
  1648. * new_eh variant
  1649. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1650. *
  1651. * (linux scsi_host_template.eh_host_reset_handler routine)
  1652. *
  1653. * Returns SUCCESS or FAILED.
  1654. */
  1655. int
  1656. mptscsih_host_reset(struct scsi_cmnd *SCpnt)
  1657. {
  1658. MPT_SCSI_HOST * hd;
  1659. int status = SUCCESS;
  1660. /* If we can't locate the host to reset, then we failed. */
  1661. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1662. dtmprintk( ( KERN_INFO MYNAM ": mptscsih_host_reset: "
  1663. "Can't locate host! (sc=%p)\n",
  1664. SCpnt ) );
  1665. return FAILED;
  1666. }
  1667. printk(KERN_WARNING MYNAM ": %s: Attempting host reset! (sc=%p)\n",
  1668. hd->ioc->name, SCpnt);
  1669. /* If our attempts to reset the host failed, then return a failed
  1670. * status. The host will be taken off line by the SCSI mid-layer.
  1671. */
  1672. if (mpt_HardResetHandler(hd->ioc, CAN_SLEEP) < 0){
  1673. status = FAILED;
  1674. } else {
  1675. /* Make sure TM pending is cleared and TM state is set to
  1676. * NONE.
  1677. */
  1678. hd->tmPending = 0;
  1679. hd->tmState = TM_STATE_NONE;
  1680. }
  1681. dtmprintk( ( KERN_INFO MYNAM ": mptscsih_host_reset: "
  1682. "Status = %s\n",
  1683. (status == SUCCESS) ? "SUCCESS" : "FAILED" ) );
  1684. return status;
  1685. }
  1686. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1687. /**
  1688. * mptscsih_tm_pending_wait - wait for pending task management request to
  1689. * complete.
  1690. * @hd: Pointer to MPT host structure.
  1691. *
  1692. * Returns {SUCCESS,FAILED}.
  1693. */
  1694. static int
  1695. mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
  1696. {
  1697. unsigned long flags;
  1698. int loop_count = 4 * 10; /* Wait 10 seconds */
  1699. int status = FAILED;
  1700. do {
  1701. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1702. if (hd->tmState == TM_STATE_NONE) {
  1703. hd->tmState = TM_STATE_IN_PROGRESS;
  1704. hd->tmPending = 1;
  1705. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1706. status = SUCCESS;
  1707. break;
  1708. }
  1709. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1710. msleep(250);
  1711. } while (--loop_count);
  1712. return status;
  1713. }
  1714. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1715. /**
  1716. * mptscsih_tm_wait_for_completion - wait for completion of TM task
  1717. * @hd: Pointer to MPT host structure.
  1718. *
  1719. * Returns {SUCCESS,FAILED}.
  1720. */
  1721. static int
  1722. mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout )
  1723. {
  1724. unsigned long flags;
  1725. int loop_count = 4 * timeout;
  1726. int status = FAILED;
  1727. do {
  1728. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1729. if(hd->tmPending == 0) {
  1730. status = SUCCESS;
  1731. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1732. break;
  1733. }
  1734. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1735. msleep_interruptible(250);
  1736. } while (--loop_count);
  1737. return status;
  1738. }
  1739. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1740. /**
  1741. * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
  1742. * @ioc: Pointer to MPT_ADAPTER structure
  1743. * @mf: Pointer to SCSI task mgmt request frame
  1744. * @mr: Pointer to SCSI task mgmt reply frame
  1745. *
  1746. * This routine is called from mptbase.c::mpt_interrupt() at the completion
  1747. * of any SCSI task management request.
  1748. * This routine is registered with the MPT (base) driver at driver
  1749. * load/init time via the mpt_register() API call.
  1750. *
  1751. * Returns 1 indicating alloc'd request frame ptr should be freed.
  1752. */
  1753. int
  1754. mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  1755. {
  1756. SCSITaskMgmtReply_t *pScsiTmReply;
  1757. SCSITaskMgmt_t *pScsiTmReq;
  1758. MPT_SCSI_HOST *hd;
  1759. unsigned long flags;
  1760. u16 iocstatus;
  1761. u8 tmType;
  1762. dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
  1763. ioc->name, mf, mr));
  1764. if (ioc->sh) {
  1765. /* Depending on the thread, a timer is activated for
  1766. * the TM request. Delete this timer on completion of TM.
  1767. * Decrement count of outstanding TM requests.
  1768. */
  1769. hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
  1770. } else {
  1771. dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt Complete: NULL Scsi Host Ptr\n",
  1772. ioc->name));
  1773. return 1;
  1774. }
  1775. if (mr == NULL) {
  1776. dtmprintk((MYIOC_s_WARN_FMT "ERROR! TaskMgmt Reply: NULL Request %p\n",
  1777. ioc->name, mf));
  1778. return 1;
  1779. } else {
  1780. pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
  1781. pScsiTmReq = (SCSITaskMgmt_t*)mf;
  1782. /* Figure out if this was ABORT_TASK, TARGET_RESET, or BUS_RESET! */
  1783. tmType = pScsiTmReq->TaskType;
  1784. dtmprintk((MYIOC_s_WARN_FMT " TaskType = %d, TerminationCount=%d\n",
  1785. ioc->name, tmType, le32_to_cpu(pScsiTmReply->TerminationCount)));
  1786. DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply);
  1787. iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  1788. dtmprintk((MYIOC_s_WARN_FMT " SCSI TaskMgmt (%d) IOCStatus=%04x IOCLogInfo=%08x\n",
  1789. ioc->name, tmType, iocstatus, le32_to_cpu(pScsiTmReply->IOCLogInfo)));
  1790. /* Error? (anything non-zero?) */
  1791. if (iocstatus) {
  1792. /* clear flags and continue.
  1793. */
  1794. if (tmType == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
  1795. hd->abortSCpnt = NULL;
  1796. /* If an internal command is present
  1797. * or the TM failed - reload the FW.
  1798. * FC FW may respond FAILED to an ABORT
  1799. */
  1800. if (tmType == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
  1801. if ((hd->cmdPtr) ||
  1802. (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED)) {
  1803. if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0) {
  1804. printk((KERN_WARNING
  1805. " Firmware Reload FAILED!!\n"));
  1806. }
  1807. }
  1808. }
  1809. } else {
  1810. dtmprintk((MYIOC_s_WARN_FMT " TaskMgmt SUCCESS\n", ioc->name));
  1811. hd->abortSCpnt = NULL;
  1812. }
  1813. }
  1814. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1815. hd->tmPending = 0;
  1816. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1817. hd->tmState = TM_STATE_NONE;
  1818. return 1;
  1819. }
  1820. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1821. /*
  1822. * This is anyones guess quite frankly.
  1823. */
  1824. int
  1825. mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
  1826. sector_t capacity, int geom[])
  1827. {
  1828. int heads;
  1829. int sectors;
  1830. sector_t cylinders;
  1831. ulong dummy;
  1832. heads = 64;
  1833. sectors = 32;
  1834. dummy = heads * sectors;
  1835. cylinders = capacity;
  1836. sector_div(cylinders,dummy);
  1837. /*
  1838. * Handle extended translation size for logical drives
  1839. * > 1Gb
  1840. */
  1841. if ((ulong)capacity >= 0x200000) {
  1842. heads = 255;
  1843. sectors = 63;
  1844. dummy = heads * sectors;
  1845. cylinders = capacity;
  1846. sector_div(cylinders,dummy);
  1847. }
  1848. /* return result */
  1849. geom[0] = heads;
  1850. geom[1] = sectors;
  1851. geom[2] = cylinders;
  1852. dprintk((KERN_NOTICE
  1853. ": bios_param: Id=%i Lun=%i Channel=%i CHS=%i/%i/%i\n",
  1854. sdev->id, sdev->lun,sdev->channel,(int)cylinders,heads,sectors));
  1855. return 0;
  1856. }
  1857. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1858. /*
  1859. * OS entry point to allow host driver to alloc memory
  1860. * for each scsi device. Called once per device the bus scan.
  1861. * Return non-zero if allocation fails.
  1862. * Init memory once per id (not LUN).
  1863. */
  1864. int
  1865. mptscsih_slave_alloc(struct scsi_device *device)
  1866. {
  1867. struct Scsi_Host *host = device->host;
  1868. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  1869. VirtDevice *vdev;
  1870. uint target = device->id;
  1871. if (hd == NULL)
  1872. return -ENODEV;
  1873. if ((vdev = hd->Targets[target]) != NULL)
  1874. goto out;
  1875. vdev = kmalloc(sizeof(VirtDevice), GFP_KERNEL);
  1876. if (!vdev) {
  1877. printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
  1878. hd->ioc->name, sizeof(VirtDevice));
  1879. return -ENOMEM;
  1880. }
  1881. memset(vdev, 0, sizeof(VirtDevice));
  1882. vdev->tflags = MPT_TARGET_FLAGS_Q_YES;
  1883. vdev->ioc_id = hd->ioc->id;
  1884. vdev->target_id = device->id;
  1885. vdev->bus_id = device->channel;
  1886. vdev->raidVolume = 0;
  1887. hd->Targets[device->id] = vdev;
  1888. if (hd->ioc->bus_type == SCSI) {
  1889. if (hd->ioc->raid_data.isRaid & (1 << device->id)) {
  1890. vdev->raidVolume = 1;
  1891. ddvtprintk((KERN_INFO
  1892. "RAID Volume @ id %d\n", device->id));
  1893. }
  1894. } else {
  1895. vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
  1896. }
  1897. out:
  1898. vdev->num_luns++;
  1899. device->hostdata = vdev;
  1900. return 0;
  1901. }
  1902. /*
  1903. * OS entry point to allow for host driver to free allocated memory
  1904. * Called if no device present or device being unloaded
  1905. */
  1906. void
  1907. mptscsih_slave_destroy(struct scsi_device *device)
  1908. {
  1909. struct Scsi_Host *host = device->host;
  1910. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  1911. VirtDevice *vdev;
  1912. uint target = device->id;
  1913. uint lun = device->lun;
  1914. if (hd == NULL)
  1915. return;
  1916. mptscsih_search_running_cmds(hd, target, lun);
  1917. vdev = hd->Targets[target];
  1918. vdev->luns[0] &= ~(1 << lun);
  1919. if (--vdev->num_luns)
  1920. return;
  1921. kfree(hd->Targets[target]);
  1922. hd->Targets[target] = NULL;
  1923. if (hd->ioc->bus_type == SCSI) {
  1924. if (mptscsih_is_phys_disk(hd->ioc, target)) {
  1925. hd->ioc->spi_data.forceDv |= MPT_SCSICFG_RELOAD_IOC_PG3;
  1926. } else {
  1927. hd->ioc->spi_data.dvStatus[target] =
  1928. MPT_SCSICFG_NEGOTIATE;
  1929. if (!hd->negoNvram) {
  1930. hd->ioc->spi_data.dvStatus[target] |=
  1931. MPT_SCSICFG_DV_NOT_DONE;
  1932. }
  1933. }
  1934. }
  1935. }
  1936. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1937. /*
  1938. * mptscsih_change_queue_depth - This function will set a devices queue depth
  1939. * @sdev: per scsi_device pointer
  1940. * @qdepth: requested queue depth
  1941. *
  1942. * Adding support for new 'change_queue_depth' api.
  1943. */
  1944. int
  1945. mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
  1946. {
  1947. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
  1948. VirtDevice *pTarget;
  1949. int max_depth;
  1950. int tagged;
  1951. if (hd == NULL)
  1952. return 0;
  1953. if (!(pTarget = hd->Targets[sdev->id]))
  1954. return 0;
  1955. if (hd->ioc->bus_type == SCSI) {
  1956. if (pTarget->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY) {
  1957. if (!(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES))
  1958. max_depth = 1;
  1959. else if (((pTarget->inq_data[0] & 0x1f) == 0x00) &&
  1960. (pTarget->minSyncFactor <= MPT_ULTRA160 ))
  1961. max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
  1962. else
  1963. max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
  1964. } else {
  1965. /* error case - No Inq. Data */
  1966. max_depth = 1;
  1967. }
  1968. } else
  1969. max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
  1970. if (qdepth > max_depth)
  1971. qdepth = max_depth;
  1972. if (qdepth == 1)
  1973. tagged = 0;
  1974. else
  1975. tagged = MSG_SIMPLE_TAG;
  1976. scsi_adjust_queue_depth(sdev, tagged, qdepth);
  1977. return sdev->queue_depth;
  1978. }
  1979. /*
  1980. * OS entry point to adjust the queue_depths on a per-device basis.
  1981. * Called once per device the bus scan. Use it to force the queue_depth
  1982. * member to 1 if a device does not support Q tags.
  1983. * Return non-zero if fails.
  1984. */
  1985. int
  1986. mptscsih_slave_configure(struct scsi_device *device)
  1987. {
  1988. struct Scsi_Host *sh = device->host;
  1989. VirtDevice *pTarget;
  1990. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sh->hostdata;
  1991. if ((hd == NULL) || (hd->Targets == NULL)) {
  1992. return 0;
  1993. }
  1994. dsprintk((MYIOC_s_INFO_FMT
  1995. "device @ %p, id=%d, LUN=%d, channel=%d\n",
  1996. hd->ioc->name, device, device->id, device->lun, device->channel));
  1997. dsprintk((MYIOC_s_INFO_FMT
  1998. "sdtr %d wdtr %d ppr %d inq length=%d\n",
  1999. hd->ioc->name, device->sdtr, device->wdtr,
  2000. device->ppr, device->inquiry_len));
  2001. if (device->id > sh->max_id) {
  2002. /* error case, should never happen */
  2003. scsi_adjust_queue_depth(device, 0, 1);
  2004. goto slave_configure_exit;
  2005. }
  2006. pTarget = hd->Targets[device->id];
  2007. if (pTarget == NULL) {
  2008. /* Driver doesn't know about this device.
  2009. * Kernel may generate a "Dummy Lun 0" which
  2010. * may become a real Lun if a
  2011. * "scsi add-single-device" command is executed
  2012. * while the driver is active (hot-plug a
  2013. * device). LSI Raid controllers need
  2014. * queue_depth set to DEV_HIGH for this reason.
  2015. */
  2016. scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG,
  2017. MPT_SCSI_CMD_PER_DEV_HIGH);
  2018. goto slave_configure_exit;
  2019. }
  2020. mptscsih_initTarget(hd, device->channel, device->id, device->lun,
  2021. device->inquiry, device->inquiry_len );
  2022. mptscsih_change_queue_depth(device, MPT_SCSI_CMD_PER_DEV_HIGH);
  2023. dsprintk((MYIOC_s_INFO_FMT
  2024. "Queue depth=%d, tflags=%x\n",
  2025. hd->ioc->name, device->queue_depth, pTarget->tflags));
  2026. dsprintk((MYIOC_s_INFO_FMT
  2027. "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
  2028. hd->ioc->name, pTarget->negoFlags, pTarget->maxOffset, pTarget->minSyncFactor));
  2029. slave_configure_exit:
  2030. dsprintk((MYIOC_s_INFO_FMT
  2031. "tagged %d, simple %d, ordered %d\n",
  2032. hd->ioc->name,device->tagged_supported, device->simple_tags,
  2033. device->ordered_tags));
  2034. return 0;
  2035. }
  2036. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2037. /*
  2038. * Private routines...
  2039. */
  2040. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2041. /* Utility function to copy sense data from the scsi_cmnd buffer
  2042. * to the FC and SCSI target structures.
  2043. *
  2044. */
  2045. static void
  2046. mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
  2047. {
  2048. VirtDevice *target;
  2049. SCSIIORequest_t *pReq;
  2050. u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
  2051. int index;
  2052. /* Get target structure
  2053. */
  2054. pReq = (SCSIIORequest_t *) mf;
  2055. index = (int) pReq->TargetID;
  2056. target = hd->Targets[index];
  2057. if (sense_count) {
  2058. u8 *sense_data;
  2059. int req_index;
  2060. /* Copy the sense received into the scsi command block. */
  2061. req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2062. sense_data = ((u8 *)hd->ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
  2063. memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
  2064. /* Log SMART data (asc = 0x5D, non-IM case only) if required.
  2065. */
  2066. if ((hd->ioc->events) && (hd->ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
  2067. if ((sense_data[12] == 0x5D) && (target->raidVolume == 0)) {
  2068. int idx;
  2069. MPT_ADAPTER *ioc = hd->ioc;
  2070. idx = ioc->eventContext % ioc->eventLogSize;
  2071. ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
  2072. ioc->events[idx].eventContext = ioc->eventContext;
  2073. ioc->events[idx].data[0] = (pReq->LUN[1] << 24) ||
  2074. (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) ||
  2075. (pReq->Bus << 8) || pReq->TargetID;
  2076. ioc->events[idx].data[1] = (sense_data[13] << 8) || sense_data[12];
  2077. ioc->eventContext++;
  2078. }
  2079. }
  2080. } else {
  2081. dprintk((MYIOC_s_INFO_FMT "Hmmm... SenseData len=0! (?)\n",
  2082. hd->ioc->name));
  2083. }
  2084. }
  2085. static u32
  2086. SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc)
  2087. {
  2088. MPT_SCSI_HOST *hd;
  2089. int i;
  2090. hd = (MPT_SCSI_HOST *) sc->device->host->hostdata;
  2091. for (i = 0; i < hd->ioc->req_depth; i++) {
  2092. if (hd->ScsiLookup[i] == sc) {
  2093. return i;
  2094. }
  2095. }
  2096. return -1;
  2097. }
  2098. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2099. int
  2100. mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  2101. {
  2102. MPT_SCSI_HOST *hd;
  2103. unsigned long flags;
  2104. int ii;
  2105. dtmprintk((KERN_WARNING MYNAM
  2106. ": IOC %s_reset routed to SCSI host driver!\n",
  2107. reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
  2108. reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
  2109. /* If a FW reload request arrives after base installed but
  2110. * before all scsi hosts have been attached, then an alt_ioc
  2111. * may have a NULL sh pointer.
  2112. */
  2113. if ((ioc->sh == NULL) || (ioc->sh->hostdata == NULL))
  2114. return 0;
  2115. else
  2116. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  2117. if (reset_phase == MPT_IOC_SETUP_RESET) {
  2118. dtmprintk((MYIOC_s_WARN_FMT "Setup-Diag Reset\n", ioc->name));
  2119. /* Clean Up:
  2120. * 1. Set Hard Reset Pending Flag
  2121. * All new commands go to doneQ
  2122. */
  2123. hd->resetPending = 1;
  2124. } else if (reset_phase == MPT_IOC_PRE_RESET) {
  2125. dtmprintk((MYIOC_s_WARN_FMT "Pre-Diag Reset\n", ioc->name));
  2126. /* 2. Flush running commands
  2127. * Clean ScsiLookup (and associated memory)
  2128. * AND clean mytaskQ
  2129. */
  2130. /* 2b. Reply to OS all known outstanding I/O commands.
  2131. */
  2132. mptscsih_flush_running_cmds(hd);
  2133. /* 2c. If there was an internal command that
  2134. * has not completed, configuration or io request,
  2135. * free these resources.
  2136. */
  2137. if (hd->cmdPtr) {
  2138. del_timer(&hd->timer);
  2139. mpt_free_msg_frame(ioc, hd->cmdPtr);
  2140. }
  2141. dtmprintk((MYIOC_s_WARN_FMT "Pre-Reset complete.\n", ioc->name));
  2142. } else {
  2143. dtmprintk((MYIOC_s_WARN_FMT "Post-Diag Reset\n", ioc->name));
  2144. /* Once a FW reload begins, all new OS commands are
  2145. * redirected to the doneQ w/ a reset status.
  2146. * Init all control structures.
  2147. */
  2148. /* ScsiLookup initialization
  2149. */
  2150. for (ii=0; ii < hd->ioc->req_depth; ii++)
  2151. hd->ScsiLookup[ii] = NULL;
  2152. /* 2. Chain Buffer initialization
  2153. */
  2154. /* 4. Renegotiate to all devices, if SCSI
  2155. */
  2156. if (ioc->bus_type == SCSI) {
  2157. dnegoprintk(("writeSDP1: ALL_IDS USE_NVRAM\n"));
  2158. mptscsih_writeSDP1(hd, 0, 0, MPT_SCSICFG_ALL_IDS | MPT_SCSICFG_USE_NVRAM);
  2159. }
  2160. /* 5. Enable new commands to be posted
  2161. */
  2162. spin_lock_irqsave(&ioc->FreeQlock, flags);
  2163. hd->tmPending = 0;
  2164. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  2165. hd->resetPending = 0;
  2166. hd->tmState = TM_STATE_NONE;
  2167. /* 6. If there was an internal command,
  2168. * wake this process up.
  2169. */
  2170. if (hd->cmdPtr) {
  2171. /*
  2172. * Wake up the original calling thread
  2173. */
  2174. hd->pLocal = &hd->localReply;
  2175. hd->pLocal->completion = MPT_SCANDV_DID_RESET;
  2176. hd->scandv_wait_done = 1;
  2177. wake_up(&hd->scandv_waitq);
  2178. hd->cmdPtr = NULL;
  2179. }
  2180. /* 7. Set flag to force DV and re-read IOC Page 3
  2181. */
  2182. if (ioc->bus_type == SCSI) {
  2183. ioc->spi_data.forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3;
  2184. ddvtprintk(("Set reload IOC Pg3 Flag\n"));
  2185. }
  2186. dtmprintk((MYIOC_s_WARN_FMT "Post-Reset complete.\n", ioc->name));
  2187. }
  2188. return 1; /* currently means nothing really */
  2189. }
  2190. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2191. /* work queue thread to clear the persitency table */
  2192. static void
  2193. mptscsih_sas_persist_clear_table(void * arg)
  2194. {
  2195. MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
  2196. mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
  2197. }
  2198. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2199. int
  2200. mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  2201. {
  2202. MPT_SCSI_HOST *hd;
  2203. u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
  2204. devtprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
  2205. ioc->name, event));
  2206. if (ioc->sh == NULL ||
  2207. ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL))
  2208. return 1;
  2209. switch (event) {
  2210. case MPI_EVENT_UNIT_ATTENTION: /* 03 */
  2211. /* FIXME! */
  2212. break;
  2213. case MPI_EVENT_IOC_BUS_RESET: /* 04 */
  2214. case MPI_EVENT_EXT_BUS_RESET: /* 05 */
  2215. if (hd && (ioc->bus_type == SCSI) && (hd->soft_resets < -1))
  2216. hd->soft_resets++;
  2217. break;
  2218. case MPI_EVENT_LOGOUT: /* 09 */
  2219. /* FIXME! */
  2220. break;
  2221. /*
  2222. * CHECKME! Don't think we need to do
  2223. * anything for these, but...
  2224. */
  2225. case MPI_EVENT_RESCAN: /* 06 */
  2226. case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
  2227. case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
  2228. /*
  2229. * CHECKME! Falling thru...
  2230. */
  2231. break;
  2232. case MPI_EVENT_INTEGRATED_RAID: /* 0B */
  2233. {
  2234. pMpiEventDataRaid_t pRaidEventData =
  2235. (pMpiEventDataRaid_t) pEvReply->Data;
  2236. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  2237. /* Domain Validation Needed */
  2238. if (ioc->bus_type == SCSI &&
  2239. pRaidEventData->ReasonCode ==
  2240. MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED)
  2241. mptscsih_set_dvflags_raid(hd, pRaidEventData->PhysDiskNum);
  2242. #endif
  2243. break;
  2244. }
  2245. /* Persistent table is full. */
  2246. case MPI_EVENT_PERSISTENT_TABLE_FULL:
  2247. INIT_WORK(&mptscsih_persistTask,
  2248. mptscsih_sas_persist_clear_table,(void *)ioc);
  2249. schedule_work(&mptscsih_persistTask);
  2250. break;
  2251. case MPI_EVENT_NONE: /* 00 */
  2252. case MPI_EVENT_LOG_DATA: /* 01 */
  2253. case MPI_EVENT_STATE_CHANGE: /* 02 */
  2254. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  2255. default:
  2256. dprintk((KERN_INFO " Ignoring event (=%02Xh)\n", event));
  2257. break;
  2258. }
  2259. return 1; /* currently means nothing really */
  2260. }
  2261. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2262. /*
  2263. * mptscsih_initTarget - Target, LUN alloc/free functionality.
  2264. * @hd: Pointer to MPT_SCSI_HOST structure
  2265. * @bus_id: Bus number (?)
  2266. * @target_id: SCSI target id
  2267. * @lun: SCSI LUN id
  2268. * @data: Pointer to data
  2269. * @dlen: Number of INQUIRY bytes
  2270. *
  2271. * NOTE: It's only SAFE to call this routine if data points to
  2272. * sane & valid STANDARD INQUIRY data!
  2273. *
  2274. * Allocate and initialize memory for this target.
  2275. * Save inquiry data.
  2276. *
  2277. */
  2278. static void
  2279. mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *data, int dlen)
  2280. {
  2281. int indexed_lun, lun_index;
  2282. VirtDevice *vdev;
  2283. SpiCfgData *pSpi;
  2284. char data_56;
  2285. dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n",
  2286. hd->ioc->name, bus_id, target_id, lun, hd));
  2287. /*
  2288. * If the peripheral qualifier filter is enabled then if the target reports a 0x1
  2289. * (i.e. The targer is capable of supporting the specified peripheral device type
  2290. * on this logical unit; however, the physical device is not currently connected
  2291. * to this logical unit) it will be converted to a 0x3 (i.e. The target is not
  2292. * capable of supporting a physical device on this logical unit). This is to work
  2293. * around a bug in th emid-layer in some distributions in which the mid-layer will
  2294. * continue to try to communicate to the LUN and evntually create a dummy LUN.
  2295. */
  2296. if (hd->mpt_pq_filter && dlen && (data[0] & 0xE0))
  2297. data[0] |= 0x40;
  2298. /* Is LUN supported? If so, upper 2 bits will be 0
  2299. * in first byte of inquiry data.
  2300. */
  2301. if (data[0] & 0xe0)
  2302. return;
  2303. if ((vdev = hd->Targets[target_id]) == NULL) {
  2304. return;
  2305. }
  2306. lun_index = (lun >> 5); /* 32 luns per lun_index */
  2307. indexed_lun = (lun % 32);
  2308. vdev->luns[lun_index] |= (1 << indexed_lun);
  2309. if (hd->ioc->bus_type == SCSI) {
  2310. if ((data[0] == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) {
  2311. /* Treat all Processors as SAF-TE if
  2312. * command line option is set */
  2313. vdev->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
  2314. mptscsih_writeIOCPage4(hd, target_id, bus_id);
  2315. }else if ((data[0] == TYPE_PROCESSOR) &&
  2316. !(vdev->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) {
  2317. if ( dlen > 49 ) {
  2318. vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
  2319. if ( data[44] == 'S' &&
  2320. data[45] == 'A' &&
  2321. data[46] == 'F' &&
  2322. data[47] == '-' &&
  2323. data[48] == 'T' &&
  2324. data[49] == 'E' ) {
  2325. vdev->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
  2326. mptscsih_writeIOCPage4(hd, target_id, bus_id);
  2327. }
  2328. }
  2329. }
  2330. if (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY)) {
  2331. if ( dlen > 8 ) {
  2332. memcpy (vdev->inq_data, data, 8);
  2333. } else {
  2334. memcpy (vdev->inq_data, data, dlen);
  2335. }
  2336. /* If have not done DV, set the DV flag.
  2337. */
  2338. pSpi = &hd->ioc->spi_data;
  2339. if ((data[0] == TYPE_TAPE) || (data[0] == TYPE_PROCESSOR)) {
  2340. if (pSpi->dvStatus[target_id] & MPT_SCSICFG_DV_NOT_DONE)
  2341. pSpi->dvStatus[target_id] |= MPT_SCSICFG_NEED_DV;
  2342. }
  2343. vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
  2344. data_56 = 0x0F; /* Default to full capabilities if Inq data length is < 57 */
  2345. if (dlen > 56) {
  2346. if ( (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_56))) {
  2347. /* Update the target capabilities
  2348. */
  2349. data_56 = data[56];
  2350. vdev->tflags |= MPT_TARGET_FLAGS_VALID_56;
  2351. }
  2352. }
  2353. mptscsih_setTargetNegoParms(hd, vdev, data_56);
  2354. } else {
  2355. /* Initial Inquiry may not request enough data bytes to
  2356. * obtain byte 57. DV will; if target doesn't return
  2357. * at least 57 bytes, data[56] will be zero. */
  2358. if (dlen > 56) {
  2359. if ( (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_56))) {
  2360. /* Update the target capabilities
  2361. */
  2362. data_56 = data[56];
  2363. vdev->tflags |= MPT_TARGET_FLAGS_VALID_56;
  2364. mptscsih_setTargetNegoParms(hd, vdev, data_56);
  2365. }
  2366. }
  2367. }
  2368. }
  2369. }
  2370. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2371. /*
  2372. * Update the target negotiation parameters based on the
  2373. * the Inquiry data, adapter capabilities, and NVRAM settings.
  2374. *
  2375. */
  2376. static void
  2377. mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtDevice *target, char byte56)
  2378. {
  2379. SpiCfgData *pspi_data = &hd->ioc->spi_data;
  2380. int id = (int) target->target_id;
  2381. int nvram;
  2382. VirtDevice *vdev;
  2383. int ii;
  2384. u8 width = MPT_NARROW;
  2385. u8 factor = MPT_ASYNC;
  2386. u8 offset = 0;
  2387. u8 version, nfactor;
  2388. u8 noQas = 1;
  2389. target->negoFlags = pspi_data->noQas;
  2390. /* noQas == 0 => device supports QAS. Need byte 56 of Inq to determine
  2391. * support. If available, default QAS to off and allow enabling.
  2392. * If not available, default QAS to on, turn off for non-disks.
  2393. */
  2394. /* Set flags based on Inquiry data
  2395. */
  2396. version = target->inq_data[2] & 0x07;
  2397. if (version < 2) {
  2398. width = 0;
  2399. factor = MPT_ULTRA2;
  2400. offset = pspi_data->maxSyncOffset;
  2401. target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
  2402. } else {
  2403. if (target->inq_data[7] & 0x20) {
  2404. width = 1;
  2405. }
  2406. if (target->inq_data[7] & 0x10) {
  2407. factor = pspi_data->minSyncFactor;
  2408. if (target->tflags & MPT_TARGET_FLAGS_VALID_56) {
  2409. /* bits 2 & 3 show Clocking support */
  2410. if ((byte56 & 0x0C) == 0)
  2411. factor = MPT_ULTRA2;
  2412. else {
  2413. if ((byte56 & 0x03) == 0)
  2414. factor = MPT_ULTRA160;
  2415. else {
  2416. factor = MPT_ULTRA320;
  2417. if (byte56 & 0x02)
  2418. {
  2419. ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", byte56, id));
  2420. noQas = 0;
  2421. }
  2422. if (target->inq_data[0] == TYPE_TAPE) {
  2423. if (byte56 & 0x01)
  2424. target->negoFlags |= MPT_TAPE_NEGO_IDP;
  2425. }
  2426. }
  2427. }
  2428. } else {
  2429. ddvtprintk((KERN_INFO "Enabling QAS on id=%d due to ~TARGET_FLAGS_VALID_56!\n", id));
  2430. noQas = 0;
  2431. }
  2432. offset = pspi_data->maxSyncOffset;
  2433. /* If RAID, never disable QAS
  2434. * else if non RAID, do not disable
  2435. * QAS if bit 1 is set
  2436. * bit 1 QAS support, non-raid only
  2437. * bit 0 IU support
  2438. */
  2439. if (target->raidVolume == 1) {
  2440. noQas = 0;
  2441. }
  2442. } else {
  2443. factor = MPT_ASYNC;
  2444. offset = 0;
  2445. }
  2446. }
  2447. if ( (target->inq_data[7] & 0x02) == 0) {
  2448. target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
  2449. }
  2450. /* Update tflags based on NVRAM settings. (SCSI only)
  2451. */
  2452. if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  2453. nvram = pspi_data->nvram[id];
  2454. nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
  2455. if (width)
  2456. width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  2457. if (offset > 0) {
  2458. /* Ensure factor is set to the
  2459. * maximum of: adapter, nvram, inquiry
  2460. */
  2461. if (nfactor) {
  2462. if (nfactor < pspi_data->minSyncFactor )
  2463. nfactor = pspi_data->minSyncFactor;
  2464. factor = max(factor, nfactor);
  2465. if (factor == MPT_ASYNC)
  2466. offset = 0;
  2467. } else {
  2468. offset = 0;
  2469. factor = MPT_ASYNC;
  2470. }
  2471. } else {
  2472. factor = MPT_ASYNC;
  2473. }
  2474. }
  2475. /* Make sure data is consistent
  2476. */
  2477. if ((!width) && (factor < MPT_ULTRA2)) {
  2478. factor = MPT_ULTRA2;
  2479. }
  2480. /* Save the data to the target structure.
  2481. */
  2482. target->minSyncFactor = factor;
  2483. target->maxOffset = offset;
  2484. target->maxWidth = width;
  2485. target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO;
  2486. /* Disable unused features.
  2487. */
  2488. if (!width)
  2489. target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
  2490. if (!offset)
  2491. target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
  2492. if ( factor > MPT_ULTRA320 )
  2493. noQas = 0;
  2494. /* GEM, processor WORKAROUND
  2495. */
  2496. if ((target->inq_data[0] == TYPE_PROCESSOR) || (target->inq_data[0] > 0x08)) {
  2497. target->negoFlags |= (MPT_TARGET_NO_NEGO_WIDE | MPT_TARGET_NO_NEGO_SYNC);
  2498. pspi_data->dvStatus[id] |= MPT_SCSICFG_BLK_NEGO;
  2499. } else {
  2500. if (noQas && (pspi_data->noQas == 0)) {
  2501. pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS;
  2502. target->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
  2503. /* Disable QAS in a mixed configuration case
  2504. */
  2505. ddvtprintk((KERN_INFO "Disabling QAS due to noQas=%02x on id=%d!\n", noQas, id));
  2506. for (ii = 0; ii < id; ii++) {
  2507. if ( (vdev = hd->Targets[ii]) ) {
  2508. vdev->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
  2509. mptscsih_writeSDP1(hd, 0, ii, vdev->negoFlags);
  2510. }
  2511. }
  2512. }
  2513. }
  2514. /* Write SDP1 on this I/O to this target */
  2515. if (pspi_data->dvStatus[id] & MPT_SCSICFG_NEGOTIATE) {
  2516. ddvtprintk((KERN_INFO "MPT_SCSICFG_NEGOTIATE on id=%d!\n", id));
  2517. mptscsih_writeSDP1(hd, 0, id, hd->negoNvram);
  2518. pspi_data->dvStatus[id] &= ~MPT_SCSICFG_NEGOTIATE;
  2519. } else if (pspi_data->dvStatus[id] & MPT_SCSICFG_BLK_NEGO) {
  2520. ddvtprintk((KERN_INFO "MPT_SCSICFG_BLK_NEGO on id=%d!\n", id));
  2521. mptscsih_writeSDP1(hd, 0, id, MPT_SCSICFG_BLK_NEGO);
  2522. pspi_data->dvStatus[id] &= ~MPT_SCSICFG_BLK_NEGO;
  2523. }
  2524. }
  2525. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2526. /* If DV disabled (negoNvram set to USE_NVARM) or if not LUN 0, return.
  2527. * Else set the NEED_DV flag after Read Capacity Issued (disks)
  2528. * or Mode Sense (cdroms).
  2529. *
  2530. * Tapes, initTarget will set this flag on completion of Inquiry command.
  2531. * Called only if DV_NOT_DONE flag is set
  2532. */
  2533. static void
  2534. mptscsih_set_dvflags(MPT_SCSI_HOST *hd, SCSIIORequest_t *pReq)
  2535. {
  2536. MPT_ADAPTER *ioc = hd->ioc;
  2537. u8 cmd;
  2538. SpiCfgData *pSpi;
  2539. ddvtprintk((MYIOC_s_NOTE_FMT
  2540. " set_dvflags: id=%d lun=%d negoNvram=%x cmd=%x\n",
  2541. hd->ioc->name, pReq->TargetID, pReq->LUN[1], hd->negoNvram, pReq->CDB[0]));
  2542. if ((pReq->LUN[1] != 0) || (hd->negoNvram != 0))
  2543. return;
  2544. cmd = pReq->CDB[0];
  2545. if ((cmd == READ_CAPACITY) || (cmd == MODE_SENSE)) {
  2546. pSpi = &ioc->spi_data;
  2547. if ((ioc->raid_data.isRaid & (1 << pReq->TargetID)) && ioc->raid_data.pIocPg3) {
  2548. /* Set NEED_DV for all hidden disks
  2549. */
  2550. Ioc3PhysDisk_t *pPDisk = ioc->raid_data.pIocPg3->PhysDisk;
  2551. int numPDisk = ioc->raid_data.pIocPg3->NumPhysDisks;
  2552. while (numPDisk) {
  2553. pSpi->dvStatus[pPDisk->PhysDiskID] |= MPT_SCSICFG_NEED_DV;
  2554. ddvtprintk(("NEED_DV set for phys disk id %d\n", pPDisk->PhysDiskID));
  2555. pPDisk++;
  2556. numPDisk--;
  2557. }
  2558. }
  2559. pSpi->dvStatus[pReq->TargetID] |= MPT_SCSICFG_NEED_DV;
  2560. ddvtprintk(("NEED_DV set for visible disk id %d\n", pReq->TargetID));
  2561. }
  2562. }
  2563. /* mptscsih_raid_set_dv_flags()
  2564. *
  2565. * New or replaced disk. Set DV flag and schedule DV.
  2566. */
  2567. static void
  2568. mptscsih_set_dvflags_raid(MPT_SCSI_HOST *hd, int id)
  2569. {
  2570. MPT_ADAPTER *ioc = hd->ioc;
  2571. SpiCfgData *pSpi = &ioc->spi_data;
  2572. Ioc3PhysDisk_t *pPDisk;
  2573. int numPDisk;
  2574. if (hd->negoNvram != 0)
  2575. return;
  2576. ddvtprintk(("DV requested for phys disk id %d\n", id));
  2577. if (ioc->raid_data.pIocPg3) {
  2578. pPDisk = ioc->raid_data.pIocPg3->PhysDisk;
  2579. numPDisk = ioc->raid_data.pIocPg3->NumPhysDisks;
  2580. while (numPDisk) {
  2581. if (id == pPDisk->PhysDiskNum) {
  2582. pSpi->dvStatus[pPDisk->PhysDiskID] =
  2583. (MPT_SCSICFG_NEED_DV | MPT_SCSICFG_DV_NOT_DONE);
  2584. pSpi->forceDv = MPT_SCSICFG_NEED_DV;
  2585. ddvtprintk(("NEED_DV set for phys disk id %d\n",
  2586. pPDisk->PhysDiskID));
  2587. break;
  2588. }
  2589. pPDisk++;
  2590. numPDisk--;
  2591. }
  2592. if (numPDisk == 0) {
  2593. /* The physical disk that needs DV was not found
  2594. * in the stored IOC Page 3. The driver must reload
  2595. * this page. DV routine will set the NEED_DV flag for
  2596. * all phys disks that have DV_NOT_DONE set.
  2597. */
  2598. pSpi->forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3;
  2599. ddvtprintk(("phys disk %d not found. Setting reload IOC Pg3 Flag\n",id));
  2600. }
  2601. }
  2602. }
  2603. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2604. /*
  2605. * If no Target, bus reset on 1st I/O. Set the flag to
  2606. * prevent any future negotiations to this device.
  2607. */
  2608. static void
  2609. mptscsih_no_negotiate(MPT_SCSI_HOST *hd, int target_id)
  2610. {
  2611. if ((hd->Targets) && (hd->Targets[target_id] == NULL))
  2612. hd->ioc->spi_data.dvStatus[target_id] |= MPT_SCSICFG_BLK_NEGO;
  2613. return;
  2614. }
  2615. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2616. /*
  2617. * SCSI Config Page functionality ...
  2618. */
  2619. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2620. /* mptscsih_setDevicePage1Flags - add Requested and Configuration fields flags
  2621. * based on width, factor and offset parameters.
  2622. * @width: bus width
  2623. * @factor: sync factor
  2624. * @offset: sync offset
  2625. * @requestedPtr: pointer to requested values (updated)
  2626. * @configurationPtr: pointer to configuration values (updated)
  2627. * @flags: flags to block WDTR or SDTR negotiation
  2628. *
  2629. * Return: None.
  2630. *
  2631. * Remark: Called by writeSDP1 and _dv_params
  2632. */
  2633. static void
  2634. mptscsih_setDevicePage1Flags (u8 width, u8 factor, u8 offset, int *requestedPtr, int *configurationPtr, u8 flags)
  2635. {
  2636. u8 nowide = flags & MPT_TARGET_NO_NEGO_WIDE;
  2637. u8 nosync = flags & MPT_TARGET_NO_NEGO_SYNC;
  2638. *configurationPtr = 0;
  2639. *requestedPtr = width ? MPI_SCSIDEVPAGE1_RP_WIDE : 0;
  2640. *requestedPtr |= (offset << 16) | (factor << 8);
  2641. if (width && offset && !nowide && !nosync) {
  2642. if (factor < MPT_ULTRA160) {
  2643. *requestedPtr |= (MPI_SCSIDEVPAGE1_RP_IU + MPI_SCSIDEVPAGE1_RP_DT);
  2644. if ((flags & MPT_TARGET_NO_NEGO_QAS) == 0)
  2645. *requestedPtr |= MPI_SCSIDEVPAGE1_RP_QAS;
  2646. if (flags & MPT_TAPE_NEGO_IDP)
  2647. *requestedPtr |= 0x08000000;
  2648. } else if (factor < MPT_ULTRA2) {
  2649. *requestedPtr |= MPI_SCSIDEVPAGE1_RP_DT;
  2650. }
  2651. }
  2652. if (nowide)
  2653. *configurationPtr |= MPI_SCSIDEVPAGE1_CONF_WDTR_DISALLOWED;
  2654. if (nosync)
  2655. *configurationPtr |= MPI_SCSIDEVPAGE1_CONF_SDTR_DISALLOWED;
  2656. return;
  2657. }
  2658. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2659. /* mptscsih_writeSDP1 - write SCSI Device Page 1
  2660. * @hd: Pointer to a SCSI Host Strucutre
  2661. * @portnum: IOC port number
  2662. * @target_id: writeSDP1 for single ID
  2663. * @flags: MPT_SCSICFG_ALL_IDS, MPT_SCSICFG_USE_NVRAM, MPT_SCSICFG_BLK_NEGO
  2664. *
  2665. * Return: -EFAULT if read of config page header fails
  2666. * or 0 if success.
  2667. *
  2668. * Remark: If a target has been found, the settings from the
  2669. * target structure are used, else the device is set
  2670. * to async/narrow.
  2671. *
  2672. * Remark: Called during init and after a FW reload.
  2673. * Remark: We do not wait for a return, write pages sequentially.
  2674. */
  2675. static int
  2676. mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target_id, int flags)
  2677. {
  2678. MPT_ADAPTER *ioc = hd->ioc;
  2679. Config_t *pReq;
  2680. SCSIDevicePage1_t *pData;
  2681. VirtDevice *pTarget=NULL;
  2682. MPT_FRAME_HDR *mf;
  2683. dma_addr_t dataDma;
  2684. u16 req_idx;
  2685. u32 frameOffset;
  2686. u32 requested, configuration, flagsLength;
  2687. int ii, nvram;
  2688. int id = 0, maxid = 0;
  2689. u8 width;
  2690. u8 factor;
  2691. u8 offset;
  2692. u8 bus = 0;
  2693. u8 negoFlags;
  2694. u8 maxwidth, maxoffset, maxfactor;
  2695. if (ioc->spi_data.sdp1length == 0)
  2696. return 0;
  2697. if (flags & MPT_SCSICFG_ALL_IDS) {
  2698. id = 0;
  2699. maxid = ioc->sh->max_id - 1;
  2700. } else if (ioc->sh) {
  2701. id = target_id;
  2702. maxid = min_t(int, id, ioc->sh->max_id - 1);
  2703. }
  2704. for (; id <= maxid; id++) {
  2705. if (id == ioc->pfacts[portnum].PortSCSIID)
  2706. continue;
  2707. /* Use NVRAM to get adapter and target maximums
  2708. * Data over-riden by target structure information, if present
  2709. */
  2710. maxwidth = ioc->spi_data.maxBusWidth;
  2711. maxoffset = ioc->spi_data.maxSyncOffset;
  2712. maxfactor = ioc->spi_data.minSyncFactor;
  2713. if (ioc->spi_data.nvram && (ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  2714. nvram = ioc->spi_data.nvram[id];
  2715. if (maxwidth)
  2716. maxwidth = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  2717. if (maxoffset > 0) {
  2718. maxfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
  2719. if (maxfactor == 0) {
  2720. /* Key for async */
  2721. maxfactor = MPT_ASYNC;
  2722. maxoffset = 0;
  2723. } else if (maxfactor < ioc->spi_data.minSyncFactor) {
  2724. maxfactor = ioc->spi_data.minSyncFactor;
  2725. }
  2726. } else
  2727. maxfactor = MPT_ASYNC;
  2728. }
  2729. /* Set the negotiation flags.
  2730. */
  2731. negoFlags = ioc->spi_data.noQas;
  2732. if (!maxwidth)
  2733. negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
  2734. if (!maxoffset)
  2735. negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
  2736. if (flags & MPT_SCSICFG_USE_NVRAM) {
  2737. width = maxwidth;
  2738. factor = maxfactor;
  2739. offset = maxoffset;
  2740. } else {
  2741. width = 0;
  2742. factor = MPT_ASYNC;
  2743. offset = 0;
  2744. //negoFlags = 0;
  2745. //negoFlags = MPT_TARGET_NO_NEGO_SYNC;
  2746. }
  2747. /* If id is not a raid volume, get the updated
  2748. * transmission settings from the target structure.
  2749. */
  2750. if (hd->Targets && (pTarget = hd->Targets[id]) && !pTarget->raidVolume) {
  2751. width = pTarget->maxWidth;
  2752. factor = pTarget->minSyncFactor;
  2753. offset = pTarget->maxOffset;
  2754. negoFlags = pTarget->negoFlags;
  2755. }
  2756. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  2757. /* Force to async and narrow if DV has not been executed
  2758. * for this ID
  2759. */
  2760. if ((hd->ioc->spi_data.dvStatus[id] & MPT_SCSICFG_DV_NOT_DONE) != 0) {
  2761. width = 0;
  2762. factor = MPT_ASYNC;
  2763. offset = 0;
  2764. }
  2765. #endif
  2766. if (flags & MPT_SCSICFG_BLK_NEGO)
  2767. negoFlags |= MPT_TARGET_NO_NEGO_WIDE | MPT_TARGET_NO_NEGO_SYNC;
  2768. mptscsih_setDevicePage1Flags(width, factor, offset,
  2769. &requested, &configuration, negoFlags);
  2770. dnegoprintk(("writeSDP1: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
  2771. target_id, width, factor, offset, negoFlags, requested, configuration));
  2772. /* Get a MF for this command.
  2773. */
  2774. if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
  2775. dfailprintk((MYIOC_s_WARN_FMT "write SDP1: no msg frames!\n",
  2776. ioc->name));
  2777. return -EAGAIN;
  2778. }
  2779. ddvprintk((MYIOC_s_INFO_FMT "WriteSDP1 (mf=%p, id=%d, req=0x%x, cfg=0x%x)\n",
  2780. hd->ioc->name, mf, id, requested, configuration));
  2781. /* Set the request and the data pointers.
  2782. * Request takes: 36 bytes (32 bit SGE)
  2783. * SCSI Device Page 1 requires 16 bytes
  2784. * 40 + 16 <= size of SCSI IO Request = 56 bytes
  2785. * and MF size >= 64 bytes.
  2786. * Place data at end of MF.
  2787. */
  2788. pReq = (Config_t *)mf;
  2789. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2790. frameOffset = ioc->req_sz - sizeof(SCSIDevicePage1_t);
  2791. pData = (SCSIDevicePage1_t *)((u8 *) mf + frameOffset);
  2792. dataDma = ioc->req_frames_dma + (req_idx * ioc->req_sz) + frameOffset;
  2793. /* Complete the request frame (same for all requests).
  2794. */
  2795. pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  2796. pReq->Reserved = 0;
  2797. pReq->ChainOffset = 0;
  2798. pReq->Function = MPI_FUNCTION_CONFIG;
  2799. pReq->ExtPageLength = 0;
  2800. pReq->ExtPageType = 0;
  2801. pReq->MsgFlags = 0;
  2802. for (ii=0; ii < 8; ii++) {
  2803. pReq->Reserved2[ii] = 0;
  2804. }
  2805. pReq->Header.PageVersion = ioc->spi_data.sdp1version;
  2806. pReq->Header.PageLength = ioc->spi_data.sdp1length;
  2807. pReq->Header.PageNumber = 1;
  2808. pReq->Header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  2809. pReq->PageAddress = cpu_to_le32(id | (bus << 8 ));
  2810. /* Add a SGE to the config request.
  2811. */
  2812. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE | ioc->spi_data.sdp1length * 4;
  2813. mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
  2814. /* Set up the common data portion
  2815. */
  2816. pData->Header.PageVersion = pReq->Header.PageVersion;
  2817. pData->Header.PageLength = pReq->Header.PageLength;
  2818. pData->Header.PageNumber = pReq->Header.PageNumber;
  2819. pData->Header.PageType = pReq->Header.PageType;
  2820. pData->RequestedParameters = cpu_to_le32(requested);
  2821. pData->Reserved = 0;
  2822. pData->Configuration = cpu_to_le32(configuration);
  2823. dprintk((MYIOC_s_INFO_FMT
  2824. "write SDP1: id %d pgaddr 0x%x req 0x%x config 0x%x\n",
  2825. ioc->name, id, (id | (bus<<8)),
  2826. requested, configuration));
  2827. mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  2828. }
  2829. return 0;
  2830. }
  2831. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2832. /* mptscsih_writeIOCPage4 - write IOC Page 4
  2833. * @hd: Pointer to a SCSI Host Structure
  2834. * @target_id: write IOC Page4 for this ID & Bus
  2835. *
  2836. * Return: -EAGAIN if unable to obtain a Message Frame
  2837. * or 0 if success.
  2838. *
  2839. * Remark: We do not wait for a return, write pages sequentially.
  2840. */
  2841. static int
  2842. mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus)
  2843. {
  2844. MPT_ADAPTER *ioc = hd->ioc;
  2845. Config_t *pReq;
  2846. IOCPage4_t *IOCPage4Ptr;
  2847. MPT_FRAME_HDR *mf;
  2848. dma_addr_t dataDma;
  2849. u16 req_idx;
  2850. u32 frameOffset;
  2851. u32 flagsLength;
  2852. int ii;
  2853. /* Get a MF for this command.
  2854. */
  2855. if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
  2856. dfailprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n",
  2857. ioc->name));
  2858. return -EAGAIN;
  2859. }
  2860. /* Set the request and the data pointers.
  2861. * Place data at end of MF.
  2862. */
  2863. pReq = (Config_t *)mf;
  2864. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2865. frameOffset = ioc->req_sz - sizeof(IOCPage4_t);
  2866. /* Complete the request frame (same for all requests).
  2867. */
  2868. pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  2869. pReq->Reserved = 0;
  2870. pReq->ChainOffset = 0;
  2871. pReq->Function = MPI_FUNCTION_CONFIG;
  2872. pReq->ExtPageLength = 0;
  2873. pReq->ExtPageType = 0;
  2874. pReq->MsgFlags = 0;
  2875. for (ii=0; ii < 8; ii++) {
  2876. pReq->Reserved2[ii] = 0;
  2877. }
  2878. IOCPage4Ptr = ioc->spi_data.pIocPg4;
  2879. dataDma = ioc->spi_data.IocPg4_dma;
  2880. ii = IOCPage4Ptr->ActiveSEP++;
  2881. IOCPage4Ptr->SEP[ii].SEPTargetID = target_id;
  2882. IOCPage4Ptr->SEP[ii].SEPBus = bus;
  2883. pReq->Header = IOCPage4Ptr->Header;
  2884. pReq->PageAddress = cpu_to_le32(target_id | (bus << 8 ));
  2885. /* Add a SGE to the config request.
  2886. */
  2887. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE |
  2888. (IOCPage4Ptr->Header.PageLength + ii) * 4;
  2889. mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
  2890. dinitprintk((MYIOC_s_INFO_FMT
  2891. "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
  2892. ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, target_id, bus));
  2893. mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  2894. return 0;
  2895. }
  2896. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2897. /*
  2898. * Bus Scan and Domain Validation functionality ...
  2899. */
  2900. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2901. /*
  2902. * mptscsih_scandv_complete - Scan and DV callback routine registered
  2903. * to Fustion MPT (base) driver.
  2904. *
  2905. * @ioc: Pointer to MPT_ADAPTER structure
  2906. * @mf: Pointer to original MPT request frame
  2907. * @mr: Pointer to MPT reply frame (NULL if TurboReply)
  2908. *
  2909. * This routine is called from mpt.c::mpt_interrupt() at the completion
  2910. * of any SCSI IO request.
  2911. * This routine is registered with the Fusion MPT (base) driver at driver
  2912. * load/init time via the mpt_register() API call.
  2913. *
  2914. * Returns 1 indicating alloc'd request frame ptr should be freed.
  2915. *
  2916. * Remark: Sets a completion code and (possibly) saves sense data
  2917. * in the IOC member localReply structure.
  2918. * Used ONLY for DV and other internal commands.
  2919. */
  2920. int
  2921. mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  2922. {
  2923. MPT_SCSI_HOST *hd;
  2924. SCSIIORequest_t *pReq;
  2925. int completionCode;
  2926. u16 req_idx;
  2927. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  2928. if ((mf == NULL) ||
  2929. (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
  2930. printk(MYIOC_s_ERR_FMT
  2931. "ScanDvComplete, %s req frame ptr! (=%p)\n",
  2932. ioc->name, mf?"BAD":"NULL", (void *) mf);
  2933. goto wakeup;
  2934. }
  2935. del_timer(&hd->timer);
  2936. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2937. hd->ScsiLookup[req_idx] = NULL;
  2938. pReq = (SCSIIORequest_t *) mf;
  2939. if (mf != hd->cmdPtr) {
  2940. printk(MYIOC_s_WARN_FMT "ScanDvComplete (mf=%p, cmdPtr=%p, idx=%d)\n",
  2941. hd->ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx);
  2942. }
  2943. hd->cmdPtr = NULL;
  2944. ddvprintk((MYIOC_s_INFO_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n",
  2945. hd->ioc->name, mf, mr, req_idx));
  2946. hd->pLocal = &hd->localReply;
  2947. hd->pLocal->scsiStatus = 0;
  2948. /* If target struct exists, clear sense valid flag.
  2949. */
  2950. if (mr == NULL) {
  2951. completionCode = MPT_SCANDV_GOOD;
  2952. } else {
  2953. SCSIIOReply_t *pReply;
  2954. u16 status;
  2955. u8 scsi_status;
  2956. pReply = (SCSIIOReply_t *) mr;
  2957. status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  2958. scsi_status = pReply->SCSIStatus;
  2959. ddvtprintk((KERN_NOTICE " IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh, IOCLogInfo=%08xh\n",
  2960. status, pReply->SCSIState, scsi_status,
  2961. le32_to_cpu(pReply->IOCLogInfo)));
  2962. switch(status) {
  2963. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  2964. completionCode = MPT_SCANDV_SELECTION_TIMEOUT;
  2965. break;
  2966. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  2967. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  2968. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  2969. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  2970. completionCode = MPT_SCANDV_DID_RESET;
  2971. break;
  2972. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  2973. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  2974. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  2975. if (pReply->Function == MPI_FUNCTION_CONFIG) {
  2976. ConfigReply_t *pr = (ConfigReply_t *)mr;
  2977. completionCode = MPT_SCANDV_GOOD;
  2978. hd->pLocal->header.PageVersion = pr->Header.PageVersion;
  2979. hd->pLocal->header.PageLength = pr->Header.PageLength;
  2980. hd->pLocal->header.PageNumber = pr->Header.PageNumber;
  2981. hd->pLocal->header.PageType = pr->Header.PageType;
  2982. } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
  2983. /* If the RAID Volume request is successful,
  2984. * return GOOD, else indicate that
  2985. * some type of error occurred.
  2986. */
  2987. MpiRaidActionReply_t *pr = (MpiRaidActionReply_t *)mr;
  2988. if (le16_to_cpu(pr->ActionStatus) == MPI_RAID_ACTION_ASTATUS_SUCCESS)
  2989. completionCode = MPT_SCANDV_GOOD;
  2990. else
  2991. completionCode = MPT_SCANDV_SOME_ERROR;
  2992. } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  2993. u8 *sense_data;
  2994. int sz;
  2995. /* save sense data in global structure
  2996. */
  2997. completionCode = MPT_SCANDV_SENSE;
  2998. hd->pLocal->scsiStatus = scsi_status;
  2999. sense_data = ((u8 *)hd->ioc->sense_buf_pool +
  3000. (req_idx * MPT_SENSE_BUFFER_ALLOC));
  3001. sz = min_t(int, pReq->SenseBufferLength,
  3002. SCSI_STD_SENSE_BYTES);
  3003. memcpy(hd->pLocal->sense, sense_data, sz);
  3004. ddvprintk((KERN_NOTICE " Check Condition, sense ptr %p\n",
  3005. sense_data));
  3006. } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
  3007. if (pReq->CDB[0] == INQUIRY)
  3008. completionCode = MPT_SCANDV_ISSUE_SENSE;
  3009. else
  3010. completionCode = MPT_SCANDV_DID_RESET;
  3011. }
  3012. else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
  3013. completionCode = MPT_SCANDV_DID_RESET;
  3014. else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  3015. completionCode = MPT_SCANDV_DID_RESET;
  3016. else {
  3017. completionCode = MPT_SCANDV_GOOD;
  3018. hd->pLocal->scsiStatus = scsi_status;
  3019. }
  3020. break;
  3021. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  3022. if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  3023. completionCode = MPT_SCANDV_DID_RESET;
  3024. else
  3025. completionCode = MPT_SCANDV_SOME_ERROR;
  3026. break;
  3027. default:
  3028. completionCode = MPT_SCANDV_SOME_ERROR;
  3029. break;
  3030. } /* switch(status) */
  3031. ddvtprintk((KERN_NOTICE " completionCode set to %08xh\n",
  3032. completionCode));
  3033. } /* end of address reply case */
  3034. hd->pLocal->completion = completionCode;
  3035. /* MF and RF are freed in mpt_interrupt
  3036. */
  3037. wakeup:
  3038. /* Free Chain buffers (will never chain) in scan or dv */
  3039. //mptscsih_freeChainBuffers(ioc, req_idx);
  3040. /*
  3041. * Wake up the original calling thread
  3042. */
  3043. hd->scandv_wait_done = 1;
  3044. wake_up(&hd->scandv_waitq);
  3045. return 1;
  3046. }
  3047. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3048. /* mptscsih_timer_expired - Call back for timer process.
  3049. * Used only for dv functionality.
  3050. * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
  3051. *
  3052. */
  3053. void
  3054. mptscsih_timer_expired(unsigned long data)
  3055. {
  3056. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data;
  3057. ddvprintk((MYIOC_s_WARN_FMT "Timer Expired! Cmd %p\n", hd->ioc->name, hd->cmdPtr));
  3058. if (hd->cmdPtr) {
  3059. MPIHeader_t *cmd = (MPIHeader_t *)hd->cmdPtr;
  3060. if (cmd->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
  3061. /* Desire to issue a task management request here.
  3062. * TM requests MUST be single threaded.
  3063. * If old eh code and no TM current, issue request.
  3064. * If new eh code, do nothing. Wait for OS cmd timeout
  3065. * for bus reset.
  3066. */
  3067. ddvtprintk((MYIOC_s_NOTE_FMT "DV Cmd Timeout: NoOp\n", hd->ioc->name));
  3068. } else {
  3069. /* Perform a FW reload */
  3070. if (mpt_HardResetHandler(hd->ioc, NO_SLEEP) < 0) {
  3071. printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", hd->ioc->name);
  3072. }
  3073. }
  3074. } else {
  3075. /* This should NEVER happen */
  3076. printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", hd->ioc->name);
  3077. }
  3078. /* No more processing.
  3079. * TM call will generate an interrupt for SCSI TM Management.
  3080. * The FW will reply to all outstanding commands, callback will finish cleanup.
  3081. * Hard reset clean-up will free all resources.
  3082. */
  3083. ddvprintk((MYIOC_s_WARN_FMT "Timer Expired Complete!\n", hd->ioc->name));
  3084. return;
  3085. }
  3086. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  3087. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3088. /* mptscsih_do_raid - Format and Issue a RAID volume request message.
  3089. * @hd: Pointer to scsi host structure
  3090. * @action: What do be done.
  3091. * @id: Logical target id.
  3092. * @bus: Target locations bus.
  3093. *
  3094. * Returns: < 0 on a fatal error
  3095. * 0 on success
  3096. *
  3097. * Remark: Wait to return until reply processed by the ISR.
  3098. */
  3099. static int
  3100. mptscsih_do_raid(MPT_SCSI_HOST *hd, u8 action, INTERNAL_CMD *io)
  3101. {
  3102. MpiRaidActionRequest_t *pReq;
  3103. MPT_FRAME_HDR *mf;
  3104. int in_isr;
  3105. in_isr = in_interrupt();
  3106. if (in_isr) {
  3107. dprintk((MYIOC_s_WARN_FMT "Internal raid request not allowed in ISR context!\n",
  3108. hd->ioc->name));
  3109. return -EPERM;
  3110. }
  3111. /* Get and Populate a free Frame
  3112. */
  3113. if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
  3114. ddvprintk((MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",
  3115. hd->ioc->name));
  3116. return -EAGAIN;
  3117. }
  3118. pReq = (MpiRaidActionRequest_t *)mf;
  3119. pReq->Action = action;
  3120. pReq->Reserved1 = 0;
  3121. pReq->ChainOffset = 0;
  3122. pReq->Function = MPI_FUNCTION_RAID_ACTION;
  3123. pReq->VolumeID = io->id;
  3124. pReq->VolumeBus = io->bus;
  3125. pReq->PhysDiskNum = io->physDiskNum;
  3126. pReq->MsgFlags = 0;
  3127. pReq->Reserved2 = 0;
  3128. pReq->ActionDataWord = 0; /* Reserved for this action */
  3129. //pReq->ActionDataSGE = 0;
  3130. mpt_add_sge((char *)&pReq->ActionDataSGE,
  3131. MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
  3132. ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action %x id %d\n",
  3133. hd->ioc->name, action, io->id));
  3134. hd->pLocal = NULL;
  3135. hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */
  3136. hd->scandv_wait_done = 0;
  3137. /* Save cmd pointer, for resource free if timeout or
  3138. * FW reload occurs
  3139. */
  3140. hd->cmdPtr = mf;
  3141. add_timer(&hd->timer);
  3142. mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
  3143. wait_event(hd->scandv_waitq, hd->scandv_wait_done);
  3144. if ((hd->pLocal == NULL) || (hd->pLocal->completion != MPT_SCANDV_GOOD))
  3145. return -1;
  3146. return 0;
  3147. }
  3148. #endif /* ~MPTSCSIH_ENABLE_DOMAIN_VALIDATION */
  3149. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3150. /**
  3151. * mptscsih_do_cmd - Do internal command.
  3152. * @hd: MPT_SCSI_HOST pointer
  3153. * @io: INTERNAL_CMD pointer.
  3154. *
  3155. * Issue the specified internally generated command and do command
  3156. * specific cleanup. For bus scan / DV only.
  3157. * NOTES: If command is Inquiry and status is good,
  3158. * initialize a target structure, save the data
  3159. *
  3160. * Remark: Single threaded access only.
  3161. *
  3162. * Return:
  3163. * < 0 if an illegal command or no resources
  3164. *
  3165. * 0 if good
  3166. *
  3167. * > 0 if command complete but some type of completion error.
  3168. */
  3169. static int
  3170. mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
  3171. {
  3172. MPT_FRAME_HDR *mf;
  3173. SCSIIORequest_t *pScsiReq;
  3174. SCSIIORequest_t ReqCopy;
  3175. int my_idx, ii, dir;
  3176. int rc, cmdTimeout;
  3177. int in_isr;
  3178. char cmdLen;
  3179. char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  3180. char cmd = io->cmd;
  3181. in_isr = in_interrupt();
  3182. if (in_isr) {
  3183. dprintk((MYIOC_s_WARN_FMT "Internal SCSI IO request not allowed in ISR context!\n",
  3184. hd->ioc->name));
  3185. return -EPERM;
  3186. }
  3187. /* Set command specific information
  3188. */
  3189. switch (cmd) {
  3190. case INQUIRY:
  3191. cmdLen = 6;
  3192. dir = MPI_SCSIIO_CONTROL_READ;
  3193. CDB[0] = cmd;
  3194. CDB[4] = io->size;
  3195. cmdTimeout = 10;
  3196. break;
  3197. case TEST_UNIT_READY:
  3198. cmdLen = 6;
  3199. dir = MPI_SCSIIO_CONTROL_READ;
  3200. cmdTimeout = 10;
  3201. break;
  3202. case START_STOP:
  3203. cmdLen = 6;
  3204. dir = MPI_SCSIIO_CONTROL_READ;
  3205. CDB[0] = cmd;
  3206. CDB[4] = 1; /*Spin up the disk */
  3207. cmdTimeout = 15;
  3208. break;
  3209. case REQUEST_SENSE:
  3210. cmdLen = 6;
  3211. CDB[0] = cmd;
  3212. CDB[4] = io->size;
  3213. dir = MPI_SCSIIO_CONTROL_READ;
  3214. cmdTimeout = 10;
  3215. break;
  3216. case READ_BUFFER:
  3217. cmdLen = 10;
  3218. dir = MPI_SCSIIO_CONTROL_READ;
  3219. CDB[0] = cmd;
  3220. if (io->flags & MPT_ICFLAG_ECHO) {
  3221. CDB[1] = 0x0A;
  3222. } else {
  3223. CDB[1] = 0x02;
  3224. }
  3225. if (io->flags & MPT_ICFLAG_BUF_CAP) {
  3226. CDB[1] |= 0x01;
  3227. }
  3228. CDB[6] = (io->size >> 16) & 0xFF;
  3229. CDB[7] = (io->size >> 8) & 0xFF;
  3230. CDB[8] = io->size & 0xFF;
  3231. cmdTimeout = 10;
  3232. break;
  3233. case WRITE_BUFFER:
  3234. cmdLen = 10;
  3235. dir = MPI_SCSIIO_CONTROL_WRITE;
  3236. CDB[0] = cmd;
  3237. if (io->flags & MPT_ICFLAG_ECHO) {
  3238. CDB[1] = 0x0A;
  3239. } else {
  3240. CDB[1] = 0x02;
  3241. }
  3242. CDB[6] = (io->size >> 16) & 0xFF;
  3243. CDB[7] = (io->size >> 8) & 0xFF;
  3244. CDB[8] = io->size & 0xFF;
  3245. cmdTimeout = 10;
  3246. break;
  3247. case RESERVE:
  3248. cmdLen = 6;
  3249. dir = MPI_SCSIIO_CONTROL_READ;
  3250. CDB[0] = cmd;
  3251. cmdTimeout = 10;
  3252. break;
  3253. case RELEASE:
  3254. cmdLen = 6;
  3255. dir = MPI_SCSIIO_CONTROL_READ;
  3256. CDB[0] = cmd;
  3257. cmdTimeout = 10;
  3258. break;
  3259. case SYNCHRONIZE_CACHE:
  3260. cmdLen = 10;
  3261. dir = MPI_SCSIIO_CONTROL_READ;
  3262. CDB[0] = cmd;
  3263. // CDB[1] = 0x02; /* set immediate bit */
  3264. cmdTimeout = 10;
  3265. break;
  3266. default:
  3267. /* Error Case */
  3268. return -EFAULT;
  3269. }
  3270. /* Get and Populate a free Frame
  3271. */
  3272. if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
  3273. ddvprintk((MYIOC_s_WARN_FMT "No msg frames!\n",
  3274. hd->ioc->name));
  3275. return -EBUSY;
  3276. }
  3277. pScsiReq = (SCSIIORequest_t *) mf;
  3278. /* Get the request index */
  3279. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  3280. ADD_INDEX_LOG(my_idx); /* for debug */
  3281. if (io->flags & MPT_ICFLAG_PHYS_DISK) {
  3282. pScsiReq->TargetID = io->physDiskNum;
  3283. pScsiReq->Bus = 0;
  3284. pScsiReq->ChainOffset = 0;
  3285. pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  3286. } else {
  3287. pScsiReq->TargetID = io->id;
  3288. pScsiReq->Bus = io->bus;
  3289. pScsiReq->ChainOffset = 0;
  3290. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  3291. }
  3292. pScsiReq->CDBLength = cmdLen;
  3293. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  3294. pScsiReq->Reserved = 0;
  3295. pScsiReq->MsgFlags = mpt_msg_flags();
  3296. /* MsgContext set in mpt_get_msg_fram call */
  3297. for (ii=0; ii < 8; ii++)
  3298. pScsiReq->LUN[ii] = 0;
  3299. pScsiReq->LUN[1] = io->lun;
  3300. if (io->flags & MPT_ICFLAG_TAGGED_CMD)
  3301. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
  3302. else
  3303. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  3304. if (cmd == REQUEST_SENSE) {
  3305. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  3306. ddvprintk((MYIOC_s_INFO_FMT "Untagged! 0x%2x\n",
  3307. hd->ioc->name, cmd));
  3308. }
  3309. for (ii=0; ii < 16; ii++)
  3310. pScsiReq->CDB[ii] = CDB[ii];
  3311. pScsiReq->DataLength = cpu_to_le32(io->size);
  3312. pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
  3313. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  3314. ddvprintk((MYIOC_s_INFO_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
  3315. hd->ioc->name, cmd, io->bus, io->id, io->lun));
  3316. if (dir == MPI_SCSIIO_CONTROL_READ) {
  3317. mpt_add_sge((char *) &pScsiReq->SGL,
  3318. MPT_SGE_FLAGS_SSIMPLE_READ | io->size,
  3319. io->data_dma);
  3320. } else {
  3321. mpt_add_sge((char *) &pScsiReq->SGL,
  3322. MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size,
  3323. io->data_dma);
  3324. }
  3325. /* The ISR will free the request frame, but we need
  3326. * the information to initialize the target. Duplicate.
  3327. */
  3328. memcpy(&ReqCopy, pScsiReq, sizeof(SCSIIORequest_t));
  3329. /* Issue this command after:
  3330. * finish init
  3331. * add timer
  3332. * Wait until the reply has been received
  3333. * ScsiScanDvCtx callback function will
  3334. * set hd->pLocal;
  3335. * set scandv_wait_done and call wake_up
  3336. */
  3337. hd->pLocal = NULL;
  3338. hd->timer.expires = jiffies + HZ*cmdTimeout;
  3339. hd->scandv_wait_done = 0;
  3340. /* Save cmd pointer, for resource free if timeout or
  3341. * FW reload occurs
  3342. */
  3343. hd->cmdPtr = mf;
  3344. add_timer(&hd->timer);
  3345. mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
  3346. wait_event(hd->scandv_waitq, hd->scandv_wait_done);
  3347. if (hd->pLocal) {
  3348. rc = hd->pLocal->completion;
  3349. hd->pLocal->skip = 0;
  3350. /* Always set fatal error codes in some cases.
  3351. */
  3352. if (rc == MPT_SCANDV_SELECTION_TIMEOUT)
  3353. rc = -ENXIO;
  3354. else if (rc == MPT_SCANDV_SOME_ERROR)
  3355. rc = -rc;
  3356. } else {
  3357. rc = -EFAULT;
  3358. /* This should never happen. */
  3359. ddvprintk((MYIOC_s_INFO_FMT "_do_cmd: Null pLocal!!!\n",
  3360. hd->ioc->name));
  3361. }
  3362. return rc;
  3363. }
  3364. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3365. /**
  3366. * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
  3367. * @hd: Pointer to MPT_SCSI_HOST structure
  3368. * @portnum: IOC port number
  3369. *
  3370. * Uses the ISR, but with special processing.
  3371. * MUST be single-threaded.
  3372. *
  3373. * Return: 0 on completion
  3374. */
  3375. static int
  3376. mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum)
  3377. {
  3378. MPT_ADAPTER *ioc= hd->ioc;
  3379. VirtDevice *pTarget;
  3380. SCSIDevicePage1_t *pcfg1Data = NULL;
  3381. INTERNAL_CMD iocmd;
  3382. CONFIGPARMS cfg;
  3383. dma_addr_t cfg1_dma_addr = -1;
  3384. ConfigPageHeader_t header1;
  3385. int bus = 0;
  3386. int id = 0;
  3387. int lun;
  3388. int indexed_lun, lun_index;
  3389. int hostId = ioc->pfacts[portnum].PortSCSIID;
  3390. int max_id;
  3391. int requested, configuration, data;
  3392. int doConfig = 0;
  3393. u8 flags, factor;
  3394. max_id = ioc->sh->max_id - 1;
  3395. /* Following parameters will not change
  3396. * in this routine.
  3397. */
  3398. iocmd.cmd = SYNCHRONIZE_CACHE;
  3399. iocmd.flags = 0;
  3400. iocmd.physDiskNum = -1;
  3401. iocmd.data = NULL;
  3402. iocmd.data_dma = -1;
  3403. iocmd.size = 0;
  3404. iocmd.rsvd = iocmd.rsvd2 = 0;
  3405. /* No SCSI hosts
  3406. */
  3407. if (hd->Targets == NULL)
  3408. return 0;
  3409. /* Skip the host
  3410. */
  3411. if (id == hostId)
  3412. id++;
  3413. /* Write SDP1 for all SCSI devices
  3414. * Alloc memory and set up config buffer
  3415. */
  3416. if (ioc->bus_type == SCSI) {
  3417. if (ioc->spi_data.sdp1length > 0) {
  3418. pcfg1Data = (SCSIDevicePage1_t *)pci_alloc_consistent(ioc->pcidev,
  3419. ioc->spi_data.sdp1length * 4, &cfg1_dma_addr);
  3420. if (pcfg1Data != NULL) {
  3421. doConfig = 1;
  3422. header1.PageVersion = ioc->spi_data.sdp1version;
  3423. header1.PageLength = ioc->spi_data.sdp1length;
  3424. header1.PageNumber = 1;
  3425. header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3426. cfg.cfghdr.hdr = &header1;
  3427. cfg.physAddr = cfg1_dma_addr;
  3428. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  3429. cfg.dir = 1;
  3430. cfg.timeout = 0;
  3431. }
  3432. }
  3433. }
  3434. /* loop through all devices on this port
  3435. */
  3436. while (bus < MPT_MAX_BUS) {
  3437. iocmd.bus = bus;
  3438. iocmd.id = id;
  3439. pTarget = hd->Targets[(int)id];
  3440. if (doConfig) {
  3441. /* Set the negotiation flags */
  3442. if (pTarget && (pTarget = hd->Targets[id]) && !pTarget->raidVolume) {
  3443. flags = pTarget->negoFlags;
  3444. } else {
  3445. flags = hd->ioc->spi_data.noQas;
  3446. if (hd->ioc->spi_data.nvram && (hd->ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  3447. data = hd->ioc->spi_data.nvram[id];
  3448. if (data & MPT_NVRAM_WIDE_DISABLE)
  3449. flags |= MPT_TARGET_NO_NEGO_WIDE;
  3450. factor = (data & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
  3451. if ((factor == 0) || (factor == MPT_ASYNC))
  3452. flags |= MPT_TARGET_NO_NEGO_SYNC;
  3453. }
  3454. }
  3455. /* Force to async, narrow */
  3456. mptscsih_setDevicePage1Flags(0, MPT_ASYNC, 0, &requested,
  3457. &configuration, flags);
  3458. dnegoprintk(("syncronize cache: id=%d width=0 factor=MPT_ASYNC "
  3459. "offset=0 negoFlags=%x request=%x config=%x\n",
  3460. id, flags, requested, configuration));
  3461. pcfg1Data->RequestedParameters = cpu_to_le32(requested);
  3462. pcfg1Data->Reserved = 0;
  3463. pcfg1Data->Configuration = cpu_to_le32(configuration);
  3464. cfg.pageAddr = (bus<<8) | id;
  3465. mpt_config(hd->ioc, &cfg);
  3466. }
  3467. /* If target Ptr NULL or if this target is NOT a disk, skip.
  3468. */
  3469. if ((pTarget) && (pTarget->inq_data[0] == TYPE_DISK)){
  3470. for (lun=0; lun <= MPT_LAST_LUN; lun++) {
  3471. /* If LUN present, issue the command
  3472. */
  3473. lun_index = (lun >> 5); /* 32 luns per lun_index */
  3474. indexed_lun = (lun % 32);
  3475. if (pTarget->luns[lun_index] & (1<<indexed_lun)) {
  3476. iocmd.lun = lun;
  3477. (void) mptscsih_do_cmd(hd, &iocmd);
  3478. }
  3479. }
  3480. }
  3481. /* get next relevant device */
  3482. id++;
  3483. if (id == hostId)
  3484. id++;
  3485. if (id > max_id) {
  3486. id = 0;
  3487. bus++;
  3488. }
  3489. }
  3490. if (pcfg1Data) {
  3491. pci_free_consistent(ioc->pcidev, header1.PageLength * 4, pcfg1Data, cfg1_dma_addr);
  3492. }
  3493. return 0;
  3494. }
  3495. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  3496. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3497. /**
  3498. * mptscsih_domainValidation - Top level handler for domain validation.
  3499. * @hd: Pointer to MPT_SCSI_HOST structure.
  3500. *
  3501. * Uses the ISR, but with special processing.
  3502. * Called from schedule, should not be in interrupt mode.
  3503. * While thread alive, do dv for all devices needing dv
  3504. *
  3505. * Return: None.
  3506. */
  3507. static void
  3508. mptscsih_domainValidation(void *arg)
  3509. {
  3510. MPT_SCSI_HOST *hd;
  3511. MPT_ADAPTER *ioc;
  3512. unsigned long flags;
  3513. int id, maxid, dvStatus, did;
  3514. int ii, isPhysDisk;
  3515. spin_lock_irqsave(&dvtaskQ_lock, flags);
  3516. dvtaskQ_active = 1;
  3517. if (dvtaskQ_release) {
  3518. dvtaskQ_active = 0;
  3519. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3520. return;
  3521. }
  3522. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3523. /* For this ioc, loop through all devices and do dv to each device.
  3524. * When complete with this ioc, search through the ioc list, and
  3525. * for each scsi ioc found, do dv for all devices. Exit when no
  3526. * device needs dv.
  3527. */
  3528. did = 1;
  3529. while (did) {
  3530. did = 0;
  3531. list_for_each_entry(ioc, &ioc_list, list) {
  3532. spin_lock_irqsave(&dvtaskQ_lock, flags);
  3533. if (dvtaskQ_release) {
  3534. dvtaskQ_active = 0;
  3535. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3536. return;
  3537. }
  3538. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3539. msleep(250);
  3540. /* DV only to SCSI adapters */
  3541. if (ioc->bus_type != SCSI)
  3542. continue;
  3543. /* Make sure everything looks ok */
  3544. if (ioc->sh == NULL)
  3545. continue;
  3546. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  3547. if (hd == NULL)
  3548. continue;
  3549. if ((ioc->spi_data.forceDv & MPT_SCSICFG_RELOAD_IOC_PG3) != 0) {
  3550. mpt_read_ioc_pg_3(ioc);
  3551. if (ioc->raid_data.pIocPg3) {
  3552. Ioc3PhysDisk_t *pPDisk = ioc->raid_data.pIocPg3->PhysDisk;
  3553. int numPDisk = ioc->raid_data.pIocPg3->NumPhysDisks;
  3554. while (numPDisk) {
  3555. if (ioc->spi_data.dvStatus[pPDisk->PhysDiskID] & MPT_SCSICFG_DV_NOT_DONE)
  3556. ioc->spi_data.dvStatus[pPDisk->PhysDiskID] |= MPT_SCSICFG_NEED_DV;
  3557. pPDisk++;
  3558. numPDisk--;
  3559. }
  3560. }
  3561. ioc->spi_data.forceDv &= ~MPT_SCSICFG_RELOAD_IOC_PG3;
  3562. }
  3563. maxid = min_t(int, ioc->sh->max_id, MPT_MAX_SCSI_DEVICES);
  3564. for (id = 0; id < maxid; id++) {
  3565. spin_lock_irqsave(&dvtaskQ_lock, flags);
  3566. if (dvtaskQ_release) {
  3567. dvtaskQ_active = 0;
  3568. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3569. return;
  3570. }
  3571. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3572. dvStatus = hd->ioc->spi_data.dvStatus[id];
  3573. if (dvStatus & MPT_SCSICFG_NEED_DV) {
  3574. did++;
  3575. hd->ioc->spi_data.dvStatus[id] |= MPT_SCSICFG_DV_PENDING;
  3576. hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_NEED_DV;
  3577. msleep(250);
  3578. /* If hidden phys disk, block IO's to all
  3579. * raid volumes
  3580. * else, process normally
  3581. */
  3582. isPhysDisk = mptscsih_is_phys_disk(ioc, id);
  3583. if (isPhysDisk) {
  3584. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3585. if (hd->ioc->raid_data.isRaid & (1 << ii)) {
  3586. hd->ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_DV_PENDING;
  3587. }
  3588. }
  3589. }
  3590. if (mptscsih_doDv(hd, 0, id) == 1) {
  3591. /* Untagged device was busy, try again
  3592. */
  3593. hd->ioc->spi_data.dvStatus[id] |= MPT_SCSICFG_NEED_DV;
  3594. hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_PENDING;
  3595. } else {
  3596. /* DV is complete. Clear flags.
  3597. */
  3598. hd->ioc->spi_data.dvStatus[id] &= ~(MPT_SCSICFG_DV_NOT_DONE | MPT_SCSICFG_DV_PENDING);
  3599. }
  3600. if (isPhysDisk) {
  3601. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3602. if (hd->ioc->raid_data.isRaid & (1 << ii)) {
  3603. hd->ioc->spi_data.dvStatus[ii] &= ~MPT_SCSICFG_DV_PENDING;
  3604. }
  3605. }
  3606. }
  3607. if (hd->ioc->spi_data.noQas)
  3608. mptscsih_qas_check(hd, id);
  3609. }
  3610. }
  3611. }
  3612. }
  3613. spin_lock_irqsave(&dvtaskQ_lock, flags);
  3614. dvtaskQ_active = 0;
  3615. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3616. return;
  3617. }
  3618. /* Search IOC page 3 to determine if this is hidden physical disk
  3619. */
  3620. /* Search IOC page 3 to determine if this is hidden physical disk
  3621. */
  3622. static int
  3623. mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id)
  3624. {
  3625. int i;
  3626. if (!ioc->raid_data.isRaid || !ioc->raid_data.pIocPg3)
  3627. return 0;
  3628. for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
  3629. if (id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID)
  3630. return 1;
  3631. }
  3632. return 0;
  3633. }
  3634. /* Write SDP1 if no QAS has been enabled
  3635. */
  3636. static void
  3637. mptscsih_qas_check(MPT_SCSI_HOST *hd, int id)
  3638. {
  3639. VirtDevice *pTarget;
  3640. int ii;
  3641. if (hd->Targets == NULL)
  3642. return;
  3643. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3644. if (ii == id)
  3645. continue;
  3646. if ((hd->ioc->spi_data.dvStatus[ii] & MPT_SCSICFG_DV_NOT_DONE) != 0)
  3647. continue;
  3648. pTarget = hd->Targets[ii];
  3649. if ((pTarget != NULL) && (!pTarget->raidVolume)) {
  3650. if ((pTarget->negoFlags & hd->ioc->spi_data.noQas) == 0) {
  3651. pTarget->negoFlags |= hd->ioc->spi_data.noQas;
  3652. dnegoprintk(("writeSDP1: id=%d flags=0\n", id));
  3653. mptscsih_writeSDP1(hd, 0, ii, 0);
  3654. }
  3655. } else {
  3656. if (mptscsih_is_phys_disk(hd->ioc, ii) == 1) {
  3657. dnegoprintk(("writeSDP1: id=%d SCSICFG_USE_NVRAM\n", id));
  3658. mptscsih_writeSDP1(hd, 0, ii, MPT_SCSICFG_USE_NVRAM);
  3659. }
  3660. }
  3661. }
  3662. return;
  3663. }
  3664. #define MPT_GET_NVRAM_VALS 0x01
  3665. #define MPT_UPDATE_MAX 0x02
  3666. #define MPT_SET_MAX 0x04
  3667. #define MPT_SET_MIN 0x08
  3668. #define MPT_FALLBACK 0x10
  3669. #define MPT_SAVE 0x20
  3670. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3671. /**
  3672. * mptscsih_doDv - Perform domain validation to a target.
  3673. * @hd: Pointer to MPT_SCSI_HOST structure.
  3674. * @portnum: IOC port number.
  3675. * @target: Physical ID of this target
  3676. *
  3677. * Uses the ISR, but with special processing.
  3678. * MUST be single-threaded.
  3679. * Test will exit if target is at async & narrow.
  3680. *
  3681. * Return: None.
  3682. */
  3683. static int
  3684. mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
  3685. {
  3686. MPT_ADAPTER *ioc = hd->ioc;
  3687. VirtDevice *pTarget;
  3688. SCSIDevicePage1_t *pcfg1Data;
  3689. SCSIDevicePage0_t *pcfg0Data;
  3690. u8 *pbuf1;
  3691. u8 *pbuf2;
  3692. u8 *pDvBuf;
  3693. dma_addr_t dvbuf_dma = -1;
  3694. dma_addr_t buf1_dma = -1;
  3695. dma_addr_t buf2_dma = -1;
  3696. dma_addr_t cfg1_dma_addr = -1;
  3697. dma_addr_t cfg0_dma_addr = -1;
  3698. ConfigPageHeader_t header1;
  3699. ConfigPageHeader_t header0;
  3700. DVPARAMETERS dv;
  3701. INTERNAL_CMD iocmd;
  3702. CONFIGPARMS cfg;
  3703. int dv_alloc = 0;
  3704. int rc, sz = 0;
  3705. int bufsize = 0;
  3706. int dataBufSize = 0;
  3707. int echoBufSize = 0;
  3708. int notDone;
  3709. int patt;
  3710. int repeat;
  3711. int retcode = 0;
  3712. int nfactor = MPT_ULTRA320;
  3713. char firstPass = 1;
  3714. char doFallback = 0;
  3715. char readPage0;
  3716. char bus, lun;
  3717. char inq0 = 0;
  3718. if (ioc->spi_data.sdp1length == 0)
  3719. return 0;
  3720. if (ioc->spi_data.sdp0length == 0)
  3721. return 0;
  3722. /* If multiple buses are used, require that the initiator
  3723. * id be the same on all buses.
  3724. */
  3725. if (id == ioc->pfacts[0].PortSCSIID)
  3726. return 0;
  3727. lun = 0;
  3728. bus = (u8) bus_number;
  3729. ddvtprintk((MYIOC_s_NOTE_FMT
  3730. "DV started: bus=%d, id=%d dv @ %p\n",
  3731. ioc->name, bus, id, &dv));
  3732. /* Prep DV structure
  3733. */
  3734. memset (&dv, 0, sizeof(DVPARAMETERS));
  3735. dv.id = id;
  3736. /* Populate tmax with the current maximum
  3737. * transfer parameters for this target.
  3738. * Exit if narrow and async.
  3739. */
  3740. dv.cmd = MPT_GET_NVRAM_VALS;
  3741. mptscsih_dv_parms(hd, &dv, NULL);
  3742. /* Prep SCSI IO structure
  3743. */
  3744. iocmd.id = id;
  3745. iocmd.bus = bus;
  3746. iocmd.lun = lun;
  3747. iocmd.flags = 0;
  3748. iocmd.physDiskNum = -1;
  3749. iocmd.rsvd = iocmd.rsvd2 = 0;
  3750. pTarget = hd->Targets[id];
  3751. /* Use tagged commands if possible.
  3752. */
  3753. if (pTarget) {
  3754. if (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)
  3755. iocmd.flags |= MPT_ICFLAG_TAGGED_CMD;
  3756. else {
  3757. if (hd->ioc->facts.FWVersion.Word < 0x01000600)
  3758. return 0;
  3759. if ((hd->ioc->facts.FWVersion.Word >= 0x01010000) &&
  3760. (hd->ioc->facts.FWVersion.Word < 0x01010B00))
  3761. return 0;
  3762. }
  3763. }
  3764. /* Prep cfg structure
  3765. */
  3766. cfg.pageAddr = (bus<<8) | id;
  3767. cfg.cfghdr.hdr = NULL;
  3768. /* Prep SDP0 header
  3769. */
  3770. header0.PageVersion = ioc->spi_data.sdp0version;
  3771. header0.PageLength = ioc->spi_data.sdp0length;
  3772. header0.PageNumber = 0;
  3773. header0.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3774. /* Prep SDP1 header
  3775. */
  3776. header1.PageVersion = ioc->spi_data.sdp1version;
  3777. header1.PageLength = ioc->spi_data.sdp1length;
  3778. header1.PageNumber = 1;
  3779. header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3780. if (header0.PageLength & 1)
  3781. dv_alloc = (header0.PageLength * 4) + 4;
  3782. dv_alloc += (2048 + (header1.PageLength * 4));
  3783. pDvBuf = pci_alloc_consistent(ioc->pcidev, dv_alloc, &dvbuf_dma);
  3784. if (pDvBuf == NULL)
  3785. return 0;
  3786. sz = 0;
  3787. pbuf1 = (u8 *)pDvBuf;
  3788. buf1_dma = dvbuf_dma;
  3789. sz +=1024;
  3790. pbuf2 = (u8 *) (pDvBuf + sz);
  3791. buf2_dma = dvbuf_dma + sz;
  3792. sz +=1024;
  3793. pcfg0Data = (SCSIDevicePage0_t *) (pDvBuf + sz);
  3794. cfg0_dma_addr = dvbuf_dma + sz;
  3795. sz += header0.PageLength * 4;
  3796. /* 8-byte alignment
  3797. */
  3798. if (header0.PageLength & 1)
  3799. sz += 4;
  3800. pcfg1Data = (SCSIDevicePage1_t *) (pDvBuf + sz);
  3801. cfg1_dma_addr = dvbuf_dma + sz;
  3802. /* Skip this ID? Set cfg.cfghdr.hdr to force config page write
  3803. */
  3804. {
  3805. SpiCfgData *pspi_data = &hd->ioc->spi_data;
  3806. if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  3807. /* Set the factor from nvram */
  3808. nfactor = (pspi_data->nvram[id] & MPT_NVRAM_SYNC_MASK) >> 8;
  3809. if (nfactor < pspi_data->minSyncFactor )
  3810. nfactor = pspi_data->minSyncFactor;
  3811. if (!(pspi_data->nvram[id] & MPT_NVRAM_ID_SCAN_ENABLE) ||
  3812. (pspi_data->PortFlags == MPI_SCSIPORTPAGE2_PORT_FLAGS_OFF_DV) ) {
  3813. ddvprintk((MYIOC_s_NOTE_FMT "DV Skipped: bus, id, lun (%d, %d, %d)\n",
  3814. ioc->name, bus, id, lun));
  3815. dv.cmd = MPT_SET_MAX;
  3816. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  3817. cfg.cfghdr.hdr = &header1;
  3818. /* Save the final negotiated settings to
  3819. * SCSI device page 1.
  3820. */
  3821. cfg.physAddr = cfg1_dma_addr;
  3822. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  3823. cfg.dir = 1;
  3824. mpt_config(hd->ioc, &cfg);
  3825. goto target_done;
  3826. }
  3827. }
  3828. }
  3829. /* Finish iocmd inititialization - hidden or visible disk? */
  3830. if (ioc->raid_data.pIocPg3) {
  3831. /* Search IOC page 3 for matching id
  3832. */
  3833. Ioc3PhysDisk_t *pPDisk = ioc->raid_data.pIocPg3->PhysDisk;
  3834. int numPDisk = ioc->raid_data.pIocPg3->NumPhysDisks;
  3835. while (numPDisk) {
  3836. if (pPDisk->PhysDiskID == id) {
  3837. /* match */
  3838. iocmd.flags |= MPT_ICFLAG_PHYS_DISK;
  3839. iocmd.physDiskNum = pPDisk->PhysDiskNum;
  3840. /* Quiesce the IM
  3841. */
  3842. if (mptscsih_do_raid(hd, MPI_RAID_ACTION_QUIESCE_PHYS_IO, &iocmd) < 0) {
  3843. ddvprintk((MYIOC_s_ERR_FMT "RAID Queisce FAILED!\n", ioc->name));
  3844. goto target_done;
  3845. }
  3846. break;
  3847. }
  3848. pPDisk++;
  3849. numPDisk--;
  3850. }
  3851. }
  3852. /* RAID Volume ID's may double for a physical device. If RAID but
  3853. * not a physical ID as well, skip DV.
  3854. */
  3855. if ((hd->ioc->raid_data.isRaid & (1 << id)) && !(iocmd.flags & MPT_ICFLAG_PHYS_DISK))
  3856. goto target_done;
  3857. /* Basic Test.
  3858. * Async & Narrow - Inquiry
  3859. * Async & Narrow - Inquiry
  3860. * Maximum transfer rate - Inquiry
  3861. * Compare buffers:
  3862. * If compare, test complete.
  3863. * If miscompare and first pass, repeat
  3864. * If miscompare and not first pass, fall back and repeat
  3865. */
  3866. hd->pLocal = NULL;
  3867. readPage0 = 0;
  3868. sz = SCSI_MAX_INQUIRY_BYTES;
  3869. rc = MPT_SCANDV_GOOD;
  3870. while (1) {
  3871. ddvprintk((MYIOC_s_NOTE_FMT "DV: Start Basic test on id=%d\n", ioc->name, id));
  3872. retcode = 0;
  3873. dv.cmd = MPT_SET_MIN;
  3874. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  3875. cfg.cfghdr.hdr = &header1;
  3876. cfg.physAddr = cfg1_dma_addr;
  3877. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  3878. cfg.dir = 1;
  3879. if (mpt_config(hd->ioc, &cfg) != 0)
  3880. goto target_done;
  3881. /* Wide - narrow - wide workaround case
  3882. */
  3883. if ((rc == MPT_SCANDV_ISSUE_SENSE) && dv.max.width) {
  3884. /* Send an untagged command to reset disk Qs corrupted
  3885. * when a parity error occurs on a Request Sense.
  3886. */
  3887. if ((hd->ioc->facts.FWVersion.Word >= 0x01000600) ||
  3888. ((hd->ioc->facts.FWVersion.Word >= 0x01010000) &&
  3889. (hd->ioc->facts.FWVersion.Word < 0x01010B00)) ) {
  3890. iocmd.cmd = REQUEST_SENSE;
  3891. iocmd.data_dma = buf1_dma;
  3892. iocmd.data = pbuf1;
  3893. iocmd.size = 0x12;
  3894. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  3895. goto target_done;
  3896. else {
  3897. if (hd->pLocal == NULL)
  3898. goto target_done;
  3899. rc = hd->pLocal->completion;
  3900. if ((rc == MPT_SCANDV_GOOD) || (rc == MPT_SCANDV_SENSE)) {
  3901. dv.max.width = 0;
  3902. doFallback = 0;
  3903. } else
  3904. goto target_done;
  3905. }
  3906. } else
  3907. goto target_done;
  3908. }
  3909. iocmd.cmd = INQUIRY;
  3910. iocmd.data_dma = buf1_dma;
  3911. iocmd.data = pbuf1;
  3912. iocmd.size = sz;
  3913. memset(pbuf1, 0x00, sz);
  3914. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  3915. goto target_done;
  3916. else {
  3917. if (hd->pLocal == NULL)
  3918. goto target_done;
  3919. rc = hd->pLocal->completion;
  3920. if (rc == MPT_SCANDV_GOOD) {
  3921. if (hd->pLocal->scsiStatus == SAM_STAT_BUSY) {
  3922. if ((iocmd.flags & MPT_ICFLAG_TAGGED_CMD) == 0)
  3923. retcode = 1;
  3924. else
  3925. retcode = 0;
  3926. goto target_done;
  3927. }
  3928. } else if (rc == MPT_SCANDV_SENSE) {
  3929. ;
  3930. } else {
  3931. /* If first command doesn't complete
  3932. * with a good status or with a check condition,
  3933. * exit.
  3934. */
  3935. goto target_done;
  3936. }
  3937. }
  3938. /* Reset the size for disks
  3939. */
  3940. inq0 = (*pbuf1) & 0x1F;
  3941. if ((inq0 == 0) && pTarget && !pTarget->raidVolume) {
  3942. sz = 0x40;
  3943. iocmd.size = sz;
  3944. }
  3945. /* Another GEM workaround. Check peripheral device type,
  3946. * if PROCESSOR, quit DV.
  3947. */
  3948. if (inq0 == TYPE_PROCESSOR) {
  3949. mptscsih_initTarget(hd,
  3950. bus,
  3951. id,
  3952. lun,
  3953. pbuf1,
  3954. sz);
  3955. goto target_done;
  3956. }
  3957. if (inq0 > 0x08)
  3958. goto target_done;
  3959. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  3960. goto target_done;
  3961. if (sz == 0x40) {
  3962. if ((pTarget->maxWidth == 1) && (pTarget->maxOffset) && (nfactor < 0x0A)
  3963. && (pTarget->minSyncFactor > 0x09)) {
  3964. if ((pbuf1[56] & 0x04) == 0)
  3965. ;
  3966. else if ((pbuf1[56] & 0x01) == 1) {
  3967. pTarget->minSyncFactor =
  3968. nfactor > MPT_ULTRA320 ? nfactor : MPT_ULTRA320;
  3969. } else {
  3970. pTarget->minSyncFactor =
  3971. nfactor > MPT_ULTRA160 ? nfactor : MPT_ULTRA160;
  3972. }
  3973. dv.max.factor = pTarget->minSyncFactor;
  3974. if ((pbuf1[56] & 0x02) == 0) {
  3975. pTarget->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
  3976. hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS;
  3977. ddvprintk((MYIOC_s_NOTE_FMT
  3978. "DV: Start Basic noQas on id=%d due to pbuf1[56]=%x\n",
  3979. ioc->name, id, pbuf1[56]));
  3980. }
  3981. }
  3982. }
  3983. if (doFallback)
  3984. dv.cmd = MPT_FALLBACK;
  3985. else
  3986. dv.cmd = MPT_SET_MAX;
  3987. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  3988. if (mpt_config(hd->ioc, &cfg) != 0)
  3989. goto target_done;
  3990. if ((!dv.now.width) && (!dv.now.offset))
  3991. goto target_done;
  3992. iocmd.cmd = INQUIRY;
  3993. iocmd.data_dma = buf2_dma;
  3994. iocmd.data = pbuf2;
  3995. iocmd.size = sz;
  3996. memset(pbuf2, 0x00, sz);
  3997. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  3998. goto target_done;
  3999. else if (hd->pLocal == NULL)
  4000. goto target_done;
  4001. else {
  4002. /* Save the return code.
  4003. * If this is the first pass,
  4004. * read SCSI Device Page 0
  4005. * and update the target max parameters.
  4006. */
  4007. rc = hd->pLocal->completion;
  4008. doFallback = 0;
  4009. if (rc == MPT_SCANDV_GOOD) {
  4010. if (!readPage0) {
  4011. u32 sdp0_info;
  4012. u32 sdp0_nego;
  4013. cfg.cfghdr.hdr = &header0;
  4014. cfg.physAddr = cfg0_dma_addr;
  4015. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4016. cfg.dir = 0;
  4017. if (mpt_config(hd->ioc, &cfg) != 0)
  4018. goto target_done;
  4019. sdp0_info = le32_to_cpu(pcfg0Data->Information) & 0x0E;
  4020. sdp0_nego = (le32_to_cpu(pcfg0Data->NegotiatedParameters) & 0xFF00 ) >> 8;
  4021. /* Quantum and Fujitsu workarounds.
  4022. * Quantum: PPR U320 -> PPR reply with Ultra2 and wide
  4023. * Fujitsu: PPR U320 -> Msg Reject and Ultra2 and wide
  4024. * Resetart with a request for U160.
  4025. */
  4026. if ((dv.now.factor == MPT_ULTRA320) && (sdp0_nego == MPT_ULTRA2)) {
  4027. doFallback = 1;
  4028. } else {
  4029. dv.cmd = MPT_UPDATE_MAX;
  4030. mptscsih_dv_parms(hd, &dv, (void *)pcfg0Data);
  4031. /* Update the SCSI device page 1 area
  4032. */
  4033. pcfg1Data->RequestedParameters = pcfg0Data->NegotiatedParameters;
  4034. readPage0 = 1;
  4035. }
  4036. }
  4037. /* Quantum workaround. Restart this test will the fallback
  4038. * flag set.
  4039. */
  4040. if (doFallback == 0) {
  4041. if (memcmp(pbuf1, pbuf2, sz) != 0) {
  4042. if (!firstPass)
  4043. doFallback = 1;
  4044. } else {
  4045. ddvprintk((MYIOC_s_NOTE_FMT
  4046. "DV:Inquiry compared id=%d, calling initTarget\n", ioc->name, id));
  4047. hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_NOT_DONE;
  4048. mptscsih_initTarget(hd,
  4049. bus,
  4050. id,
  4051. lun,
  4052. pbuf1,
  4053. sz);
  4054. break; /* test complete */
  4055. }
  4056. }
  4057. } else if (rc == MPT_SCANDV_ISSUE_SENSE)
  4058. doFallback = 1; /* set fallback flag */
  4059. else if ((rc == MPT_SCANDV_DID_RESET) ||
  4060. (rc == MPT_SCANDV_SENSE) ||
  4061. (rc == MPT_SCANDV_FALLBACK))
  4062. doFallback = 1; /* set fallback flag */
  4063. else
  4064. goto target_done;
  4065. firstPass = 0;
  4066. }
  4067. }
  4068. ddvprintk((MYIOC_s_NOTE_FMT "DV: Basic test on id=%d completed OK.\n", ioc->name, id));
  4069. if (ioc->spi_data.mpt_dv == 0)
  4070. goto target_done;
  4071. inq0 = (*pbuf1) & 0x1F;
  4072. /* Continue only for disks
  4073. */
  4074. if (inq0 != 0)
  4075. goto target_done;
  4076. if ( ioc->spi_data.PortFlags == MPI_SCSIPORTPAGE2_PORT_FLAGS_BASIC_DV_ONLY )
  4077. goto target_done;
  4078. /* Start the Enhanced Test.
  4079. * 0) issue TUR to clear out check conditions
  4080. * 1) read capacity of echo (regular) buffer
  4081. * 2) reserve device
  4082. * 3) do write-read-compare data pattern test
  4083. * 4) release
  4084. * 5) update nego parms to target struct
  4085. */
  4086. cfg.cfghdr.hdr = &header1;
  4087. cfg.physAddr = cfg1_dma_addr;
  4088. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  4089. cfg.dir = 1;
  4090. iocmd.cmd = TEST_UNIT_READY;
  4091. iocmd.data_dma = -1;
  4092. iocmd.data = NULL;
  4093. iocmd.size = 0;
  4094. notDone = 1;
  4095. while (notDone) {
  4096. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4097. goto target_done;
  4098. if (hd->pLocal == NULL)
  4099. goto target_done;
  4100. rc = hd->pLocal->completion;
  4101. if (rc == MPT_SCANDV_GOOD)
  4102. notDone = 0;
  4103. else if (rc == MPT_SCANDV_SENSE) {
  4104. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4105. u8 asc = hd->pLocal->sense[12];
  4106. u8 ascq = hd->pLocal->sense[13];
  4107. ddvprintk((MYIOC_s_INFO_FMT
  4108. "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
  4109. ioc->name, skey, asc, ascq));
  4110. if (skey == UNIT_ATTENTION)
  4111. notDone++; /* repeat */
  4112. else if ((skey == NOT_READY) &&
  4113. (asc == 0x04)&&(ascq == 0x01)) {
  4114. /* wait then repeat */
  4115. mdelay (2000);
  4116. notDone++;
  4117. } else if ((skey == NOT_READY) && (asc == 0x3A)) {
  4118. /* no medium, try read test anyway */
  4119. notDone = 0;
  4120. } else {
  4121. /* All other errors are fatal.
  4122. */
  4123. ddvprintk((MYIOC_s_INFO_FMT "DV: fatal error.",
  4124. ioc->name));
  4125. goto target_done;
  4126. }
  4127. } else
  4128. goto target_done;
  4129. }
  4130. iocmd.cmd = READ_BUFFER;
  4131. iocmd.data_dma = buf1_dma;
  4132. iocmd.data = pbuf1;
  4133. iocmd.size = 4;
  4134. iocmd.flags |= MPT_ICFLAG_BUF_CAP;
  4135. dataBufSize = 0;
  4136. echoBufSize = 0;
  4137. for (patt = 0; patt < 2; patt++) {
  4138. if (patt == 0)
  4139. iocmd.flags |= MPT_ICFLAG_ECHO;
  4140. else
  4141. iocmd.flags &= ~MPT_ICFLAG_ECHO;
  4142. notDone = 1;
  4143. while (notDone) {
  4144. bufsize = 0;
  4145. /* If not ready after 8 trials,
  4146. * give up on this device.
  4147. */
  4148. if (notDone > 8)
  4149. goto target_done;
  4150. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4151. goto target_done;
  4152. else if (hd->pLocal == NULL)
  4153. goto target_done;
  4154. else {
  4155. rc = hd->pLocal->completion;
  4156. ddvprintk(("ReadBuffer Comp Code %d", rc));
  4157. ddvprintk((" buff: %0x %0x %0x %0x\n",
  4158. pbuf1[0], pbuf1[1], pbuf1[2], pbuf1[3]));
  4159. if (rc == MPT_SCANDV_GOOD) {
  4160. notDone = 0;
  4161. if (iocmd.flags & MPT_ICFLAG_ECHO) {
  4162. bufsize = ((pbuf1[2] & 0x1F) <<8) | pbuf1[3];
  4163. if (pbuf1[0] & 0x01)
  4164. iocmd.flags |= MPT_ICFLAG_EBOS;
  4165. } else {
  4166. bufsize = pbuf1[1]<<16 | pbuf1[2]<<8 | pbuf1[3];
  4167. }
  4168. } else if (rc == MPT_SCANDV_SENSE) {
  4169. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4170. u8 asc = hd->pLocal->sense[12];
  4171. u8 ascq = hd->pLocal->sense[13];
  4172. ddvprintk((MYIOC_s_INFO_FMT
  4173. "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
  4174. ioc->name, skey, asc, ascq));
  4175. if (skey == ILLEGAL_REQUEST) {
  4176. notDone = 0;
  4177. } else if (skey == UNIT_ATTENTION) {
  4178. notDone++; /* repeat */
  4179. } else if ((skey == NOT_READY) &&
  4180. (asc == 0x04)&&(ascq == 0x01)) {
  4181. /* wait then repeat */
  4182. mdelay (2000);
  4183. notDone++;
  4184. } else {
  4185. /* All other errors are fatal.
  4186. */
  4187. ddvprintk((MYIOC_s_INFO_FMT "DV: fatal error.",
  4188. ioc->name));
  4189. goto target_done;
  4190. }
  4191. } else {
  4192. /* All other errors are fatal
  4193. */
  4194. goto target_done;
  4195. }
  4196. }
  4197. }
  4198. if (iocmd.flags & MPT_ICFLAG_ECHO)
  4199. echoBufSize = bufsize;
  4200. else
  4201. dataBufSize = bufsize;
  4202. }
  4203. sz = 0;
  4204. iocmd.flags &= ~MPT_ICFLAG_BUF_CAP;
  4205. /* Use echo buffers if possible,
  4206. * Exit if both buffers are 0.
  4207. */
  4208. if (echoBufSize > 0) {
  4209. iocmd.flags |= MPT_ICFLAG_ECHO;
  4210. if (dataBufSize > 0)
  4211. bufsize = min(echoBufSize, dataBufSize);
  4212. else
  4213. bufsize = echoBufSize;
  4214. } else if (dataBufSize == 0)
  4215. goto target_done;
  4216. ddvprintk((MYIOC_s_INFO_FMT "%s Buffer Capacity %d\n", ioc->name,
  4217. (iocmd.flags & MPT_ICFLAG_ECHO) ? "Echo" : " ", bufsize));
  4218. /* Data buffers for write-read-compare test max 1K.
  4219. */
  4220. sz = min(bufsize, 1024);
  4221. /* --- loop ----
  4222. * On first pass, always issue a reserve.
  4223. * On additional loops, only if a reset has occurred.
  4224. * iocmd.flags indicates if echo or regular buffer
  4225. */
  4226. for (patt = 0; patt < 4; patt++) {
  4227. ddvprintk(("Pattern %d\n", patt));
  4228. if ((iocmd.flags & MPT_ICFLAG_RESERVED) && (iocmd.flags & MPT_ICFLAG_DID_RESET)) {
  4229. iocmd.cmd = TEST_UNIT_READY;
  4230. iocmd.data_dma = -1;
  4231. iocmd.data = NULL;
  4232. iocmd.size = 0;
  4233. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4234. goto target_done;
  4235. iocmd.cmd = RELEASE;
  4236. iocmd.data_dma = -1;
  4237. iocmd.data = NULL;
  4238. iocmd.size = 0;
  4239. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4240. goto target_done;
  4241. else if (hd->pLocal == NULL)
  4242. goto target_done;
  4243. else {
  4244. rc = hd->pLocal->completion;
  4245. ddvprintk(("Release rc %d\n", rc));
  4246. if (rc == MPT_SCANDV_GOOD)
  4247. iocmd.flags &= ~MPT_ICFLAG_RESERVED;
  4248. else
  4249. goto target_done;
  4250. }
  4251. iocmd.flags &= ~MPT_ICFLAG_RESERVED;
  4252. }
  4253. iocmd.flags &= ~MPT_ICFLAG_DID_RESET;
  4254. if (iocmd.flags & MPT_ICFLAG_EBOS)
  4255. goto skip_Reserve;
  4256. repeat = 5;
  4257. while (repeat && (!(iocmd.flags & MPT_ICFLAG_RESERVED))) {
  4258. iocmd.cmd = RESERVE;
  4259. iocmd.data_dma = -1;
  4260. iocmd.data = NULL;
  4261. iocmd.size = 0;
  4262. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4263. goto target_done;
  4264. else if (hd->pLocal == NULL)
  4265. goto target_done;
  4266. else {
  4267. rc = hd->pLocal->completion;
  4268. if (rc == MPT_SCANDV_GOOD) {
  4269. iocmd.flags |= MPT_ICFLAG_RESERVED;
  4270. } else if (rc == MPT_SCANDV_SENSE) {
  4271. /* Wait if coming ready
  4272. */
  4273. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4274. u8 asc = hd->pLocal->sense[12];
  4275. u8 ascq = hd->pLocal->sense[13];
  4276. ddvprintk((MYIOC_s_INFO_FMT
  4277. "DV: Reserve Failed: ", ioc->name));
  4278. ddvprintk(("SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
  4279. skey, asc, ascq));
  4280. if ((skey == NOT_READY) && (asc == 0x04)&&
  4281. (ascq == 0x01)) {
  4282. /* wait then repeat */
  4283. mdelay (2000);
  4284. notDone++;
  4285. } else {
  4286. ddvprintk((MYIOC_s_INFO_FMT
  4287. "DV: Reserved Failed.", ioc->name));
  4288. goto target_done;
  4289. }
  4290. } else {
  4291. ddvprintk((MYIOC_s_INFO_FMT "DV: Reserved Failed.",
  4292. ioc->name));
  4293. goto target_done;
  4294. }
  4295. }
  4296. }
  4297. skip_Reserve:
  4298. mptscsih_fillbuf(pbuf1, sz, patt, 1);
  4299. iocmd.cmd = WRITE_BUFFER;
  4300. iocmd.data_dma = buf1_dma;
  4301. iocmd.data = pbuf1;
  4302. iocmd.size = sz;
  4303. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4304. goto target_done;
  4305. else if (hd->pLocal == NULL)
  4306. goto target_done;
  4307. else {
  4308. rc = hd->pLocal->completion;
  4309. if (rc == MPT_SCANDV_GOOD)
  4310. ; /* Issue read buffer */
  4311. else if (rc == MPT_SCANDV_DID_RESET) {
  4312. /* If using echo buffers, reset to data buffers.
  4313. * Else do Fallback and restart
  4314. * this test (re-issue reserve
  4315. * because of bus reset).
  4316. */
  4317. if ((iocmd.flags & MPT_ICFLAG_ECHO) && (dataBufSize >= bufsize)) {
  4318. iocmd.flags &= ~MPT_ICFLAG_ECHO;
  4319. } else {
  4320. dv.cmd = MPT_FALLBACK;
  4321. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  4322. if (mpt_config(hd->ioc, &cfg) != 0)
  4323. goto target_done;
  4324. if ((!dv.now.width) && (!dv.now.offset))
  4325. goto target_done;
  4326. }
  4327. iocmd.flags |= MPT_ICFLAG_DID_RESET;
  4328. patt = -1;
  4329. continue;
  4330. } else if (rc == MPT_SCANDV_SENSE) {
  4331. /* Restart data test if UA, else quit.
  4332. */
  4333. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4334. ddvprintk((MYIOC_s_INFO_FMT
  4335. "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", ioc->name, skey,
  4336. hd->pLocal->sense[12], hd->pLocal->sense[13]));
  4337. if (skey == UNIT_ATTENTION) {
  4338. patt = -1;
  4339. continue;
  4340. } else if (skey == ILLEGAL_REQUEST) {
  4341. if (iocmd.flags & MPT_ICFLAG_ECHO) {
  4342. if (dataBufSize >= bufsize) {
  4343. iocmd.flags &= ~MPT_ICFLAG_ECHO;
  4344. patt = -1;
  4345. continue;
  4346. }
  4347. }
  4348. goto target_done;
  4349. }
  4350. else
  4351. goto target_done;
  4352. } else {
  4353. /* fatal error */
  4354. goto target_done;
  4355. }
  4356. }
  4357. iocmd.cmd = READ_BUFFER;
  4358. iocmd.data_dma = buf2_dma;
  4359. iocmd.data = pbuf2;
  4360. iocmd.size = sz;
  4361. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4362. goto target_done;
  4363. else if (hd->pLocal == NULL)
  4364. goto target_done;
  4365. else {
  4366. rc = hd->pLocal->completion;
  4367. if (rc == MPT_SCANDV_GOOD) {
  4368. /* If buffers compare,
  4369. * go to next pattern,
  4370. * else, do a fallback and restart
  4371. * data transfer test.
  4372. */
  4373. if (memcmp (pbuf1, pbuf2, sz) == 0) {
  4374. ; /* goto next pattern */
  4375. } else {
  4376. /* Miscompare with Echo buffer, go to data buffer,
  4377. * if that buffer exists.
  4378. * Miscompare with Data buffer, check first 4 bytes,
  4379. * some devices return capacity. Exit in this case.
  4380. */
  4381. if (iocmd.flags & MPT_ICFLAG_ECHO) {
  4382. if (dataBufSize >= bufsize)
  4383. iocmd.flags &= ~MPT_ICFLAG_ECHO;
  4384. else
  4385. goto target_done;
  4386. } else {
  4387. if (dataBufSize == (pbuf2[1]<<16 | pbuf2[2]<<8 | pbuf2[3])) {
  4388. /* Argh. Device returning wrong data.
  4389. * Quit DV for this device.
  4390. */
  4391. goto target_done;
  4392. }
  4393. /* Had an actual miscompare. Slow down.*/
  4394. dv.cmd = MPT_FALLBACK;
  4395. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  4396. if (mpt_config(hd->ioc, &cfg) != 0)
  4397. goto target_done;
  4398. if ((!dv.now.width) && (!dv.now.offset))
  4399. goto target_done;
  4400. }
  4401. patt = -1;
  4402. continue;
  4403. }
  4404. } else if (rc == MPT_SCANDV_DID_RESET) {
  4405. /* Do Fallback and restart
  4406. * this test (re-issue reserve
  4407. * because of bus reset).
  4408. */
  4409. dv.cmd = MPT_FALLBACK;
  4410. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  4411. if (mpt_config(hd->ioc, &cfg) != 0)
  4412. goto target_done;
  4413. if ((!dv.now.width) && (!dv.now.offset))
  4414. goto target_done;
  4415. iocmd.flags |= MPT_ICFLAG_DID_RESET;
  4416. patt = -1;
  4417. continue;
  4418. } else if (rc == MPT_SCANDV_SENSE) {
  4419. /* Restart data test if UA, else quit.
  4420. */
  4421. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4422. ddvprintk((MYIOC_s_INFO_FMT
  4423. "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", ioc->name, skey,
  4424. hd->pLocal->sense[12], hd->pLocal->sense[13]));
  4425. if (skey == UNIT_ATTENTION) {
  4426. patt = -1;
  4427. continue;
  4428. }
  4429. else
  4430. goto target_done;
  4431. } else {
  4432. /* fatal error */
  4433. goto target_done;
  4434. }
  4435. }
  4436. } /* --- end of patt loop ---- */
  4437. target_done:
  4438. if (iocmd.flags & MPT_ICFLAG_RESERVED) {
  4439. iocmd.cmd = RELEASE;
  4440. iocmd.data_dma = -1;
  4441. iocmd.data = NULL;
  4442. iocmd.size = 0;
  4443. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4444. printk(MYIOC_s_INFO_FMT "DV: Release failed. id %d",
  4445. ioc->name, id);
  4446. else if (hd->pLocal) {
  4447. if (hd->pLocal->completion == MPT_SCANDV_GOOD)
  4448. iocmd.flags &= ~MPT_ICFLAG_RESERVED;
  4449. } else {
  4450. printk(MYIOC_s_INFO_FMT "DV: Release failed. id %d",
  4451. ioc->name, id);
  4452. }
  4453. }
  4454. /* Set if cfg1_dma_addr contents is valid
  4455. */
  4456. if ((cfg.cfghdr.hdr != NULL) && (retcode == 0)){
  4457. /* If disk, not U320, disable QAS
  4458. */
  4459. if ((inq0 == 0) && (dv.now.factor > MPT_ULTRA320)) {
  4460. hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS;
  4461. ddvprintk((MYIOC_s_NOTE_FMT
  4462. "noQas set due to id=%d has factor=%x\n", ioc->name, id, dv.now.factor));
  4463. }
  4464. dv.cmd = MPT_SAVE;
  4465. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  4466. /* Double writes to SDP1 can cause problems,
  4467. * skip save of the final negotiated settings to
  4468. * SCSI device page 1.
  4469. *
  4470. cfg.cfghdr.hdr = &header1;
  4471. cfg.physAddr = cfg1_dma_addr;
  4472. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  4473. cfg.dir = 1;
  4474. mpt_config(hd->ioc, &cfg);
  4475. */
  4476. }
  4477. /* If this is a RAID Passthrough, enable internal IOs
  4478. */
  4479. if (iocmd.flags & MPT_ICFLAG_PHYS_DISK) {
  4480. if (mptscsih_do_raid(hd, MPI_RAID_ACTION_ENABLE_PHYS_IO, &iocmd) < 0)
  4481. ddvprintk((MYIOC_s_ERR_FMT "RAID Enable FAILED!\n", ioc->name));
  4482. }
  4483. /* Done with the DV scan of the current target
  4484. */
  4485. if (pDvBuf)
  4486. pci_free_consistent(ioc->pcidev, dv_alloc, pDvBuf, dvbuf_dma);
  4487. ddvtprintk((MYIOC_s_INFO_FMT "DV Done id=%d\n",
  4488. ioc->name, id));
  4489. return retcode;
  4490. }
  4491. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4492. /* mptscsih_dv_parms - perform a variety of operations on the
  4493. * parameters used for negotiation.
  4494. * @hd: Pointer to a SCSI host.
  4495. * @dv: Pointer to a structure that contains the maximum and current
  4496. * negotiated parameters.
  4497. */
  4498. static void
  4499. mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage)
  4500. {
  4501. VirtDevice *pTarget;
  4502. SCSIDevicePage0_t *pPage0;
  4503. SCSIDevicePage1_t *pPage1;
  4504. int val = 0, data, configuration;
  4505. u8 width = 0;
  4506. u8 offset = 0;
  4507. u8 factor = 0;
  4508. u8 negoFlags = 0;
  4509. u8 cmd = dv->cmd;
  4510. u8 id = dv->id;
  4511. switch (cmd) {
  4512. case MPT_GET_NVRAM_VALS:
  4513. ddvprintk((MYIOC_s_NOTE_FMT "Getting NVRAM: ",
  4514. hd->ioc->name));
  4515. /* Get the NVRAM values and save in tmax
  4516. * If not an LVD bus, the adapter minSyncFactor has been
  4517. * already throttled back.
  4518. */
  4519. negoFlags = hd->ioc->spi_data.noQas;
  4520. if ((hd->Targets)&&((pTarget = hd->Targets[(int)id]) != NULL) && !pTarget->raidVolume) {
  4521. width = pTarget->maxWidth;
  4522. offset = pTarget->maxOffset;
  4523. factor = pTarget->minSyncFactor;
  4524. negoFlags |= pTarget->negoFlags;
  4525. } else {
  4526. if (hd->ioc->spi_data.nvram && (hd->ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  4527. data = hd->ioc->spi_data.nvram[id];
  4528. width = data & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  4529. if ((offset = hd->ioc->spi_data.maxSyncOffset) == 0)
  4530. factor = MPT_ASYNC;
  4531. else {
  4532. factor = (data & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
  4533. if ((factor == 0) || (factor == MPT_ASYNC)){
  4534. factor = MPT_ASYNC;
  4535. offset = 0;
  4536. }
  4537. }
  4538. } else {
  4539. width = MPT_NARROW;
  4540. offset = 0;
  4541. factor = MPT_ASYNC;
  4542. }
  4543. /* Set the negotiation flags */
  4544. if (!width)
  4545. negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
  4546. if (!offset)
  4547. negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
  4548. }
  4549. /* limit by adapter capabilities */
  4550. width = min(width, hd->ioc->spi_data.maxBusWidth);
  4551. offset = min(offset, hd->ioc->spi_data.maxSyncOffset);
  4552. factor = max(factor, hd->ioc->spi_data.minSyncFactor);
  4553. /* Check Consistency */
  4554. if (offset && (factor < MPT_ULTRA2) && !width)
  4555. factor = MPT_ULTRA2;
  4556. dv->max.width = width;
  4557. dv->max.offset = offset;
  4558. dv->max.factor = factor;
  4559. dv->max.flags = negoFlags;
  4560. ddvprintk((" id=%d width=%d factor=%x offset=%x flags=%x\n",
  4561. id, width, factor, offset, negoFlags));
  4562. break;
  4563. case MPT_UPDATE_MAX:
  4564. ddvprintk((MYIOC_s_NOTE_FMT
  4565. "Updating with SDP0 Data: ", hd->ioc->name));
  4566. /* Update tmax values with those from Device Page 0.*/
  4567. pPage0 = (SCSIDevicePage0_t *) pPage;
  4568. if (pPage0) {
  4569. val = le32_to_cpu(pPage0->NegotiatedParameters);
  4570. dv->max.width = val & MPI_SCSIDEVPAGE0_NP_WIDE ? 1 : 0;
  4571. dv->max.offset = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> 16;
  4572. dv->max.factor = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
  4573. }
  4574. dv->now.width = dv->max.width;
  4575. dv->now.offset = dv->max.offset;
  4576. dv->now.factor = dv->max.factor;
  4577. ddvprintk(("id=%d width=%d factor=%x offset=%x flags=%x\n",
  4578. id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags));
  4579. break;
  4580. case MPT_SET_MAX:
  4581. ddvprintk((MYIOC_s_NOTE_FMT "Setting Max: ",
  4582. hd->ioc->name));
  4583. /* Set current to the max values. Update the config page.*/
  4584. dv->now.width = dv->max.width;
  4585. dv->now.offset = dv->max.offset;
  4586. dv->now.factor = dv->max.factor;
  4587. dv->now.flags = dv->max.flags;
  4588. pPage1 = (SCSIDevicePage1_t *)pPage;
  4589. if (pPage1) {
  4590. mptscsih_setDevicePage1Flags (dv->now.width, dv->now.factor,
  4591. dv->now.offset, &val, &configuration, dv->now.flags);
  4592. dnegoprintk(("Setting Max: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
  4593. id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration));
  4594. pPage1->RequestedParameters = cpu_to_le32(val);
  4595. pPage1->Reserved = 0;
  4596. pPage1->Configuration = cpu_to_le32(configuration);
  4597. }
  4598. ddvprintk(("id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x configuration=%x\n",
  4599. id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration));
  4600. break;
  4601. case MPT_SET_MIN:
  4602. ddvprintk((MYIOC_s_NOTE_FMT "Setting Min: ",
  4603. hd->ioc->name));
  4604. /* Set page to asynchronous and narrow
  4605. * Do not update now, breaks fallback routine. */
  4606. width = MPT_NARROW;
  4607. offset = 0;
  4608. factor = MPT_ASYNC;
  4609. negoFlags = dv->max.flags;
  4610. pPage1 = (SCSIDevicePage1_t *)pPage;
  4611. if (pPage1) {
  4612. mptscsih_setDevicePage1Flags (width, factor,
  4613. offset, &val, &configuration, negoFlags);
  4614. dnegoprintk(("Setting Min: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
  4615. id, width, factor, offset, negoFlags, val, configuration));
  4616. pPage1->RequestedParameters = cpu_to_le32(val);
  4617. pPage1->Reserved = 0;
  4618. pPage1->Configuration = cpu_to_le32(configuration);
  4619. }
  4620. ddvprintk(("id=%d width=%d factor=%x offset=%x request=%x config=%x negoFlags=%x\n",
  4621. id, width, factor, offset, val, configuration, negoFlags));
  4622. break;
  4623. case MPT_FALLBACK:
  4624. ddvprintk((MYIOC_s_NOTE_FMT
  4625. "Fallback: Start: offset %d, factor %x, width %d \n",
  4626. hd->ioc->name, dv->now.offset,
  4627. dv->now.factor, dv->now.width));
  4628. width = dv->now.width;
  4629. offset = dv->now.offset;
  4630. factor = dv->now.factor;
  4631. if ((offset) && (dv->max.width)) {
  4632. if (factor < MPT_ULTRA160)
  4633. factor = MPT_ULTRA160;
  4634. else if (factor < MPT_ULTRA2) {
  4635. factor = MPT_ULTRA2;
  4636. width = MPT_WIDE;
  4637. } else if ((factor == MPT_ULTRA2) && width) {
  4638. factor = MPT_ULTRA2;
  4639. width = MPT_NARROW;
  4640. } else if (factor < MPT_ULTRA) {
  4641. factor = MPT_ULTRA;
  4642. width = MPT_WIDE;
  4643. } else if ((factor == MPT_ULTRA) && width) {
  4644. width = MPT_NARROW;
  4645. } else if (factor < MPT_FAST) {
  4646. factor = MPT_FAST;
  4647. width = MPT_WIDE;
  4648. } else if ((factor == MPT_FAST) && width) {
  4649. factor = MPT_FAST;
  4650. width = MPT_NARROW;
  4651. } else if (factor < MPT_SCSI) {
  4652. factor = MPT_SCSI;
  4653. width = MPT_WIDE;
  4654. } else if ((factor == MPT_SCSI) && width) {
  4655. factor = MPT_SCSI;
  4656. width = MPT_NARROW;
  4657. } else {
  4658. factor = MPT_ASYNC;
  4659. offset = 0;
  4660. }
  4661. } else if (offset) {
  4662. width = MPT_NARROW;
  4663. if (factor < MPT_ULTRA)
  4664. factor = MPT_ULTRA;
  4665. else if (factor < MPT_FAST)
  4666. factor = MPT_FAST;
  4667. else if (factor < MPT_SCSI)
  4668. factor = MPT_SCSI;
  4669. else {
  4670. factor = MPT_ASYNC;
  4671. offset = 0;
  4672. }
  4673. } else {
  4674. width = MPT_NARROW;
  4675. factor = MPT_ASYNC;
  4676. }
  4677. dv->max.flags |= MPT_TARGET_NO_NEGO_QAS;
  4678. dv->max.flags &= ~MPT_TAPE_NEGO_IDP;
  4679. dv->now.width = width;
  4680. dv->now.offset = offset;
  4681. dv->now.factor = factor;
  4682. dv->now.flags = dv->max.flags;
  4683. pPage1 = (SCSIDevicePage1_t *)pPage;
  4684. if (pPage1) {
  4685. mptscsih_setDevicePage1Flags (width, factor, offset, &val,
  4686. &configuration, dv->now.flags);
  4687. dnegoprintk(("Finish: id=%d width=%d offset=%d factor=%x negoFlags=%x request=%x config=%x\n",
  4688. id, width, offset, factor, dv->now.flags, val, configuration));
  4689. pPage1->RequestedParameters = cpu_to_le32(val);
  4690. pPage1->Reserved = 0;
  4691. pPage1->Configuration = cpu_to_le32(configuration);
  4692. }
  4693. ddvprintk(("Finish: id=%d offset=%d factor=%x width=%d request=%x config=%x\n",
  4694. id, dv->now.offset, dv->now.factor, dv->now.width, val, configuration));
  4695. break;
  4696. case MPT_SAVE:
  4697. ddvprintk((MYIOC_s_NOTE_FMT
  4698. "Saving to Target structure: ", hd->ioc->name));
  4699. ddvprintk(("id=%d width=%x factor=%x offset=%d flags=%x\n",
  4700. id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags));
  4701. /* Save these values to target structures
  4702. * or overwrite nvram (phys disks only).
  4703. */
  4704. if ((hd->Targets)&&((pTarget = hd->Targets[(int)id]) != NULL) && !pTarget->raidVolume ) {
  4705. pTarget->maxWidth = dv->now.width;
  4706. pTarget->maxOffset = dv->now.offset;
  4707. pTarget->minSyncFactor = dv->now.factor;
  4708. pTarget->negoFlags = dv->now.flags;
  4709. } else {
  4710. /* Preserv all flags, use
  4711. * read-modify-write algorithm
  4712. */
  4713. if (hd->ioc->spi_data.nvram) {
  4714. data = hd->ioc->spi_data.nvram[id];
  4715. if (dv->now.width)
  4716. data &= ~MPT_NVRAM_WIDE_DISABLE;
  4717. else
  4718. data |= MPT_NVRAM_WIDE_DISABLE;
  4719. if (!dv->now.offset)
  4720. factor = MPT_ASYNC;
  4721. data &= ~MPT_NVRAM_SYNC_MASK;
  4722. data |= (dv->now.factor << MPT_NVRAM_SYNC_SHIFT) & MPT_NVRAM_SYNC_MASK;
  4723. hd->ioc->spi_data.nvram[id] = data;
  4724. }
  4725. }
  4726. break;
  4727. }
  4728. }
  4729. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4730. /* mptscsih_fillbuf - fill a buffer with a special data pattern
  4731. * cleanup. For bus scan only.
  4732. *
  4733. * @buffer: Pointer to data buffer to be filled.
  4734. * @size: Number of bytes to fill
  4735. * @index: Pattern index
  4736. * @width: bus width, 0 (8 bits) or 1 (16 bits)
  4737. */
  4738. static void
  4739. mptscsih_fillbuf(char *buffer, int size, int index, int width)
  4740. {
  4741. char *ptr = buffer;
  4742. int ii;
  4743. char byte;
  4744. short val;
  4745. switch (index) {
  4746. case 0:
  4747. if (width) {
  4748. /* Pattern: 0000 FFFF 0000 FFFF
  4749. */
  4750. for (ii=0; ii < size; ii++, ptr++) {
  4751. if (ii & 0x02)
  4752. *ptr = 0xFF;
  4753. else
  4754. *ptr = 0x00;
  4755. }
  4756. } else {
  4757. /* Pattern: 00 FF 00 FF
  4758. */
  4759. for (ii=0; ii < size; ii++, ptr++) {
  4760. if (ii & 0x01)
  4761. *ptr = 0xFF;
  4762. else
  4763. *ptr = 0x00;
  4764. }
  4765. }
  4766. break;
  4767. case 1:
  4768. if (width) {
  4769. /* Pattern: 5555 AAAA 5555 AAAA 5555
  4770. */
  4771. for (ii=0; ii < size; ii++, ptr++) {
  4772. if (ii & 0x02)
  4773. *ptr = 0xAA;
  4774. else
  4775. *ptr = 0x55;
  4776. }
  4777. } else {
  4778. /* Pattern: 55 AA 55 AA 55
  4779. */
  4780. for (ii=0; ii < size; ii++, ptr++) {
  4781. if (ii & 0x01)
  4782. *ptr = 0xAA;
  4783. else
  4784. *ptr = 0x55;
  4785. }
  4786. }
  4787. break;
  4788. case 2:
  4789. /* Pattern: 00 01 02 03 04 05
  4790. * ... FE FF 00 01..
  4791. */
  4792. for (ii=0; ii < size; ii++, ptr++)
  4793. *ptr = (char) ii;
  4794. break;
  4795. case 3:
  4796. if (width) {
  4797. /* Wide Pattern: FFFE 0001 FFFD 0002
  4798. * ... 4000 DFFF 8000 EFFF
  4799. */
  4800. byte = 0;
  4801. for (ii=0; ii < size/2; ii++) {
  4802. /* Create the base pattern
  4803. */
  4804. val = (1 << byte);
  4805. /* every 64 (0x40) bytes flip the pattern
  4806. * since we fill 2 bytes / iteration,
  4807. * test for ii = 0x20
  4808. */
  4809. if (ii & 0x20)
  4810. val = ~(val);
  4811. if (ii & 0x01) {
  4812. *ptr = (char)( (val & 0xFF00) >> 8);
  4813. ptr++;
  4814. *ptr = (char)(val & 0xFF);
  4815. byte++;
  4816. byte &= 0x0F;
  4817. } else {
  4818. val = ~val;
  4819. *ptr = (char)( (val & 0xFF00) >> 8);
  4820. ptr++;
  4821. *ptr = (char)(val & 0xFF);
  4822. }
  4823. ptr++;
  4824. }
  4825. } else {
  4826. /* Narrow Pattern: FE 01 FD 02 FB 04
  4827. * .. 7F 80 01 FE 02 FD ... 80 7F
  4828. */
  4829. byte = 0;
  4830. for (ii=0; ii < size; ii++, ptr++) {
  4831. /* Base pattern - first 32 bytes
  4832. */
  4833. if (ii & 0x01) {
  4834. *ptr = (1 << byte);
  4835. byte++;
  4836. byte &= 0x07;
  4837. } else {
  4838. *ptr = (char) (~(1 << byte));
  4839. }
  4840. /* Flip the pattern every 32 bytes
  4841. */
  4842. if (ii & 0x20)
  4843. *ptr = ~(*ptr);
  4844. }
  4845. }
  4846. break;
  4847. }
  4848. }
  4849. #endif /* ~MPTSCSIH_ENABLE_DOMAIN_VALIDATION */
  4850. EXPORT_SYMBOL(mptscsih_remove);
  4851. EXPORT_SYMBOL(mptscsih_shutdown);
  4852. #ifdef CONFIG_PM
  4853. EXPORT_SYMBOL(mptscsih_suspend);
  4854. EXPORT_SYMBOL(mptscsih_resume);
  4855. #endif
  4856. EXPORT_SYMBOL(mptscsih_proc_info);
  4857. EXPORT_SYMBOL(mptscsih_info);
  4858. EXPORT_SYMBOL(mptscsih_qcmd);
  4859. EXPORT_SYMBOL(mptscsih_slave_alloc);
  4860. EXPORT_SYMBOL(mptscsih_slave_destroy);
  4861. EXPORT_SYMBOL(mptscsih_slave_configure);
  4862. EXPORT_SYMBOL(mptscsih_abort);
  4863. EXPORT_SYMBOL(mptscsih_dev_reset);
  4864. EXPORT_SYMBOL(mptscsih_bus_reset);
  4865. EXPORT_SYMBOL(mptscsih_host_reset);
  4866. EXPORT_SYMBOL(mptscsih_bios_param);
  4867. EXPORT_SYMBOL(mptscsih_io_done);
  4868. EXPORT_SYMBOL(mptscsih_taskmgmt_complete);
  4869. EXPORT_SYMBOL(mptscsih_scandv_complete);
  4870. EXPORT_SYMBOL(mptscsih_event_process);
  4871. EXPORT_SYMBOL(mptscsih_ioc_reset);
  4872. EXPORT_SYMBOL(mptscsih_change_queue_depth);
  4873. EXPORT_SYMBOL(mptscsih_timer_expired);
  4874. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/