mptscsih.c 151 KB

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