mptbase.c 237 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569
  1. /*
  2. * linux/drivers/message/fusion/mptbase.c
  3. * This is the Fusion MPT base driver which supports multiple
  4. * (SCSI + LAN) specialized protocol drivers.
  5. * For use with LSI PCI chip/adapter(s)
  6. * running LSI Fusion MPT (Message Passing Technology) firmware.
  7. *
  8. * Copyright (c) 1999-2008 LSI Corporation
  9. * (mailto:DL-MPTFusionLinux@lsi.com)
  10. *
  11. */
  12. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  13. /*
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; version 2 of the License.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. NO WARRANTY
  22. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  23. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  24. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  25. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  26. solely responsible for determining the appropriateness of using and
  27. distributing the Program and assumes all risks associated with its
  28. exercise of rights under this Agreement, including but not limited to
  29. the risks and costs of program errors, damage to or loss of data,
  30. programs or equipment, and unavailability or interruption of operations.
  31. DISCLAIMER OF LIABILITY
  32. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  33. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  35. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  36. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  37. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  38. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  39. You should have received a copy of the GNU General Public License
  40. along with this program; if not, write to the Free Software
  41. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  42. */
  43. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  44. #include <linux/kernel.h>
  45. #include <linux/module.h>
  46. #include <linux/errno.h>
  47. #include <linux/init.h>
  48. #include <linux/seq_file.h>
  49. #include <linux/slab.h>
  50. #include <linux/types.h>
  51. #include <linux/pci.h>
  52. #include <linux/kdev_t.h>
  53. #include <linux/blkdev.h>
  54. #include <linux/delay.h>
  55. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  56. #include <linux/dma-mapping.h>
  57. #include <asm/io.h>
  58. #ifdef CONFIG_MTRR
  59. #include <asm/mtrr.h>
  60. #endif
  61. #include <linux/kthread.h>
  62. #include <scsi/scsi_host.h>
  63. #include "mptbase.h"
  64. #include "lsi/mpi_log_fc.h"
  65. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  66. #define my_NAME "Fusion MPT base driver"
  67. #define my_VERSION MPT_LINUX_VERSION_COMMON
  68. #define MYNAM "mptbase"
  69. MODULE_AUTHOR(MODULEAUTHOR);
  70. MODULE_DESCRIPTION(my_NAME);
  71. MODULE_LICENSE("GPL");
  72. MODULE_VERSION(my_VERSION);
  73. /*
  74. * cmd line parameters
  75. */
  76. static int mpt_msi_enable_spi;
  77. module_param(mpt_msi_enable_spi, int, 0);
  78. MODULE_PARM_DESC(mpt_msi_enable_spi,
  79. " Enable MSI Support for SPI controllers (default=0)");
  80. static int mpt_msi_enable_fc;
  81. module_param(mpt_msi_enable_fc, int, 0);
  82. MODULE_PARM_DESC(mpt_msi_enable_fc,
  83. " Enable MSI Support for FC controllers (default=0)");
  84. static int mpt_msi_enable_sas;
  85. module_param(mpt_msi_enable_sas, int, 0);
  86. MODULE_PARM_DESC(mpt_msi_enable_sas,
  87. " Enable MSI Support for SAS controllers (default=0)");
  88. static int mpt_channel_mapping;
  89. module_param(mpt_channel_mapping, int, 0);
  90. MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
  91. static int mpt_debug_level;
  92. static int mpt_set_debug_level(const char *val, struct kernel_param *kp);
  93. module_param_call(mpt_debug_level, mpt_set_debug_level, param_get_int,
  94. &mpt_debug_level, 0600);
  95. MODULE_PARM_DESC(mpt_debug_level,
  96. " debug level - refer to mptdebug.h - (default=0)");
  97. int mpt_fwfault_debug;
  98. EXPORT_SYMBOL(mpt_fwfault_debug);
  99. module_param(mpt_fwfault_debug, int, 0600);
  100. MODULE_PARM_DESC(mpt_fwfault_debug,
  101. "Enable detection of Firmware fault and halt Firmware on fault - (default=0)");
  102. static char MptCallbacksName[MPT_MAX_PROTOCOL_DRIVERS]
  103. [MPT_MAX_CALLBACKNAME_LEN+1];
  104. #ifdef MFCNT
  105. static int mfcounter = 0;
  106. #define PRINT_MF_COUNT 20000
  107. #endif
  108. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  109. /*
  110. * Public data...
  111. */
  112. #define WHOINIT_UNKNOWN 0xAA
  113. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  114. /*
  115. * Private data...
  116. */
  117. /* Adapter link list */
  118. LIST_HEAD(ioc_list);
  119. /* Callback lookup table */
  120. static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
  121. /* Protocol driver class lookup table */
  122. static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
  123. /* Event handler lookup table */
  124. static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  125. /* Reset handler lookup table */
  126. static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  127. static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  128. #ifdef CONFIG_PROC_FS
  129. static struct proc_dir_entry *mpt_proc_root_dir;
  130. #endif
  131. /*
  132. * Driver Callback Index's
  133. */
  134. static u8 mpt_base_index = MPT_MAX_PROTOCOL_DRIVERS;
  135. static u8 last_drv_idx;
  136. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  137. /*
  138. * Forward protos...
  139. */
  140. static irqreturn_t mpt_interrupt(int irq, void *bus_id);
  141. static int mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
  142. MPT_FRAME_HDR *reply);
  143. static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
  144. u32 *req, int replyBytes, u16 *u16reply, int maxwait,
  145. int sleepFlag);
  146. static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
  147. static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
  148. static void mpt_adapter_disable(MPT_ADAPTER *ioc);
  149. static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
  150. static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
  151. static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
  152. static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
  153. static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  154. static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
  155. static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  156. static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
  157. static int mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag);
  158. static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  159. static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  160. static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
  161. static int PrimeIocFifos(MPT_ADAPTER *ioc);
  162. static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  163. static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  164. static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  165. static int GetLanConfigPages(MPT_ADAPTER *ioc);
  166. static int GetIoUnitPage2(MPT_ADAPTER *ioc);
  167. int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
  168. static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
  169. static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
  170. static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
  171. static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
  172. static void mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc);
  173. static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch,
  174. int sleepFlag);
  175. static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
  176. static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
  177. static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
  178. #ifdef CONFIG_PROC_FS
  179. static const struct file_operations mpt_summary_proc_fops;
  180. static const struct file_operations mpt_version_proc_fops;
  181. static const struct file_operations mpt_iocinfo_proc_fops;
  182. #endif
  183. static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
  184. static int ProcessEventNotification(MPT_ADAPTER *ioc,
  185. EventNotificationReply_t *evReply, int *evHandlers);
  186. static void mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
  187. static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
  188. static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
  189. static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info , u8 cb_idx);
  190. static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
  191. static void mpt_inactive_raid_list_free(MPT_ADAPTER *ioc);
  192. /* module entry point */
  193. static int __init fusion_init (void);
  194. static void __exit fusion_exit (void);
  195. #define CHIPREG_READ32(addr) readl_relaxed(addr)
  196. #define CHIPREG_READ32_dmasync(addr) readl(addr)
  197. #define CHIPREG_WRITE32(addr,val) writel(val, addr)
  198. #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
  199. #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
  200. static void
  201. pci_disable_io_access(struct pci_dev *pdev)
  202. {
  203. u16 command_reg;
  204. pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
  205. command_reg &= ~1;
  206. pci_write_config_word(pdev, PCI_COMMAND, command_reg);
  207. }
  208. static void
  209. pci_enable_io_access(struct pci_dev *pdev)
  210. {
  211. u16 command_reg;
  212. pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
  213. command_reg |= 1;
  214. pci_write_config_word(pdev, PCI_COMMAND, command_reg);
  215. }
  216. static int mpt_set_debug_level(const char *val, struct kernel_param *kp)
  217. {
  218. int ret = param_set_int(val, kp);
  219. MPT_ADAPTER *ioc;
  220. if (ret)
  221. return ret;
  222. list_for_each_entry(ioc, &ioc_list, list)
  223. ioc->debug_level = mpt_debug_level;
  224. return 0;
  225. }
  226. /**
  227. * mpt_get_cb_idx - obtain cb_idx for registered driver
  228. * @dclass: class driver enum
  229. *
  230. * Returns cb_idx, or zero means it wasn't found
  231. **/
  232. static u8
  233. mpt_get_cb_idx(MPT_DRIVER_CLASS dclass)
  234. {
  235. u8 cb_idx;
  236. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--)
  237. if (MptDriverClass[cb_idx] == dclass)
  238. return cb_idx;
  239. return 0;
  240. }
  241. /**
  242. * mpt_is_discovery_complete - determine if discovery has completed
  243. * @ioc: per adatper instance
  244. *
  245. * Returns 1 when discovery completed, else zero.
  246. */
  247. static int
  248. mpt_is_discovery_complete(MPT_ADAPTER *ioc)
  249. {
  250. ConfigExtendedPageHeader_t hdr;
  251. CONFIGPARMS cfg;
  252. SasIOUnitPage0_t *buffer;
  253. dma_addr_t dma_handle;
  254. int rc = 0;
  255. memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
  256. memset(&cfg, 0, sizeof(CONFIGPARMS));
  257. hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
  258. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  259. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  260. cfg.cfghdr.ehdr = &hdr;
  261. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  262. if ((mpt_config(ioc, &cfg)))
  263. goto out;
  264. if (!hdr.ExtPageLength)
  265. goto out;
  266. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  267. &dma_handle);
  268. if (!buffer)
  269. goto out;
  270. cfg.physAddr = dma_handle;
  271. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  272. if ((mpt_config(ioc, &cfg)))
  273. goto out_free_consistent;
  274. if (!(buffer->PhyData[0].PortFlags &
  275. MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS))
  276. rc = 1;
  277. out_free_consistent:
  278. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  279. buffer, dma_handle);
  280. out:
  281. return rc;
  282. }
  283. /**
  284. * mpt_remove_dead_ioc_func - kthread context to remove dead ioc
  285. * @arg: input argument, used to derive ioc
  286. *
  287. * Return 0 if controller is removed from pci subsystem.
  288. * Return -1 for other case.
  289. */
  290. static int mpt_remove_dead_ioc_func(void *arg)
  291. {
  292. MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
  293. struct pci_dev *pdev;
  294. if ((ioc == NULL))
  295. return -1;
  296. pdev = ioc->pcidev;
  297. if ((pdev == NULL))
  298. return -1;
  299. pci_stop_and_remove_bus_device(pdev);
  300. return 0;
  301. }
  302. /**
  303. * mpt_fault_reset_work - work performed on workq after ioc fault
  304. * @work: input argument, used to derive ioc
  305. *
  306. **/
  307. static void
  308. mpt_fault_reset_work(struct work_struct *work)
  309. {
  310. MPT_ADAPTER *ioc =
  311. container_of(work, MPT_ADAPTER, fault_reset_work.work);
  312. u32 ioc_raw_state;
  313. int rc;
  314. unsigned long flags;
  315. MPT_SCSI_HOST *hd;
  316. struct task_struct *p;
  317. if (ioc->ioc_reset_in_progress || !ioc->active)
  318. goto out;
  319. ioc_raw_state = mpt_GetIocState(ioc, 0);
  320. if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_MASK) {
  321. printk(MYIOC_s_INFO_FMT "%s: IOC is non-operational !!!!\n",
  322. ioc->name, __func__);
  323. /*
  324. * Call mptscsih_flush_pending_cmds callback so that we
  325. * flush all pending commands back to OS.
  326. * This call is required to aovid deadlock at block layer.
  327. * Dead IOC will fail to do diag reset,and this call is safe
  328. * since dead ioc will never return any command back from HW.
  329. */
  330. hd = shost_priv(ioc->sh);
  331. ioc->schedule_dead_ioc_flush_running_cmds(hd);
  332. /*Remove the Dead Host */
  333. p = kthread_run(mpt_remove_dead_ioc_func, ioc,
  334. "mpt_dead_ioc_%d", ioc->id);
  335. if (IS_ERR(p)) {
  336. printk(MYIOC_s_ERR_FMT
  337. "%s: Running mpt_dead_ioc thread failed !\n",
  338. ioc->name, __func__);
  339. } else {
  340. printk(MYIOC_s_WARN_FMT
  341. "%s: Running mpt_dead_ioc thread success !\n",
  342. ioc->name, __func__);
  343. }
  344. return; /* don't rearm timer */
  345. }
  346. if ((ioc_raw_state & MPI_IOC_STATE_MASK)
  347. == MPI_IOC_STATE_FAULT) {
  348. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state (%04xh)!!!\n",
  349. ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
  350. printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
  351. ioc->name, __func__);
  352. rc = mpt_HardResetHandler(ioc, CAN_SLEEP);
  353. printk(MYIOC_s_WARN_FMT "%s: HardReset: %s\n", ioc->name,
  354. __func__, (rc == 0) ? "success" : "failed");
  355. ioc_raw_state = mpt_GetIocState(ioc, 0);
  356. if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT)
  357. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state after "
  358. "reset (%04xh)\n", ioc->name, ioc_raw_state &
  359. MPI_DOORBELL_DATA_MASK);
  360. } else if (ioc->bus_type == SAS && ioc->sas_discovery_quiesce_io) {
  361. if ((mpt_is_discovery_complete(ioc))) {
  362. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "clearing "
  363. "discovery_quiesce_io flag\n", ioc->name));
  364. ioc->sas_discovery_quiesce_io = 0;
  365. }
  366. }
  367. out:
  368. /*
  369. * Take turns polling alternate controller
  370. */
  371. if (ioc->alt_ioc)
  372. ioc = ioc->alt_ioc;
  373. /* rearm the timer */
  374. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  375. if (ioc->reset_work_q)
  376. queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
  377. msecs_to_jiffies(MPT_POLLING_INTERVAL));
  378. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  379. }
  380. /*
  381. * Process turbo (context) reply...
  382. */
  383. static void
  384. mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
  385. {
  386. MPT_FRAME_HDR *mf = NULL;
  387. MPT_FRAME_HDR *mr = NULL;
  388. u16 req_idx = 0;
  389. u8 cb_idx;
  390. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got TURBO reply req_idx=%08x\n",
  391. ioc->name, pa));
  392. switch (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT) {
  393. case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
  394. req_idx = pa & 0x0000FFFF;
  395. cb_idx = (pa & 0x00FF0000) >> 16;
  396. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  397. break;
  398. case MPI_CONTEXT_REPLY_TYPE_LAN:
  399. cb_idx = mpt_get_cb_idx(MPTLAN_DRIVER);
  400. /*
  401. * Blind set of mf to NULL here was fatal
  402. * after lan_reply says "freeme"
  403. * Fix sort of combined with an optimization here;
  404. * added explicit check for case where lan_reply
  405. * was just returning 1 and doing nothing else.
  406. * For this case skip the callback, but set up
  407. * proper mf value first here:-)
  408. */
  409. if ((pa & 0x58000000) == 0x58000000) {
  410. req_idx = pa & 0x0000FFFF;
  411. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  412. mpt_free_msg_frame(ioc, mf);
  413. mb();
  414. return;
  415. break;
  416. }
  417. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  418. break;
  419. case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
  420. cb_idx = mpt_get_cb_idx(MPTSTM_DRIVER);
  421. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  422. break;
  423. default:
  424. cb_idx = 0;
  425. BUG();
  426. }
  427. /* Check for (valid) IO callback! */
  428. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
  429. MptCallbacks[cb_idx] == NULL) {
  430. printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
  431. __func__, ioc->name, cb_idx);
  432. goto out;
  433. }
  434. if (MptCallbacks[cb_idx](ioc, mf, mr))
  435. mpt_free_msg_frame(ioc, mf);
  436. out:
  437. mb();
  438. }
  439. static void
  440. mpt_reply(MPT_ADAPTER *ioc, u32 pa)
  441. {
  442. MPT_FRAME_HDR *mf;
  443. MPT_FRAME_HDR *mr;
  444. u16 req_idx;
  445. u8 cb_idx;
  446. int freeme;
  447. u32 reply_dma_low;
  448. u16 ioc_stat;
  449. /* non-TURBO reply! Hmmm, something may be up...
  450. * Newest turbo reply mechanism; get address
  451. * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
  452. */
  453. /* Map DMA address of reply header to cpu address.
  454. * pa is 32 bits - but the dma address may be 32 or 64 bits
  455. * get offset based only only the low addresses
  456. */
  457. reply_dma_low = (pa <<= 1);
  458. mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
  459. (reply_dma_low - ioc->reply_frames_low_dma));
  460. req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
  461. cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
  462. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  463. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
  464. ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
  465. DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mr);
  466. /* Check/log IOC log info
  467. */
  468. ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
  469. if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
  470. u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
  471. if (ioc->bus_type == FC)
  472. mpt_fc_log_info(ioc, log_info);
  473. else if (ioc->bus_type == SPI)
  474. mpt_spi_log_info(ioc, log_info);
  475. else if (ioc->bus_type == SAS)
  476. mpt_sas_log_info(ioc, log_info, cb_idx);
  477. }
  478. if (ioc_stat & MPI_IOCSTATUS_MASK)
  479. mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
  480. /* Check for (valid) IO callback! */
  481. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
  482. MptCallbacks[cb_idx] == NULL) {
  483. printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
  484. __func__, ioc->name, cb_idx);
  485. freeme = 0;
  486. goto out;
  487. }
  488. freeme = MptCallbacks[cb_idx](ioc, mf, mr);
  489. out:
  490. /* Flush (non-TURBO) reply with a WRITE! */
  491. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
  492. if (freeme)
  493. mpt_free_msg_frame(ioc, mf);
  494. mb();
  495. }
  496. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  497. /**
  498. * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
  499. * @irq: irq number (not used)
  500. * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
  501. *
  502. * This routine is registered via the request_irq() kernel API call,
  503. * and handles all interrupts generated from a specific MPT adapter
  504. * (also referred to as a IO Controller or IOC).
  505. * This routine must clear the interrupt from the adapter and does
  506. * so by reading the reply FIFO. Multiple replies may be processed
  507. * per single call to this routine.
  508. *
  509. * This routine handles register-level access of the adapter but
  510. * dispatches (calls) a protocol-specific callback routine to handle
  511. * the protocol-specific details of the MPT request completion.
  512. */
  513. static irqreturn_t
  514. mpt_interrupt(int irq, void *bus_id)
  515. {
  516. MPT_ADAPTER *ioc = bus_id;
  517. u32 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
  518. if (pa == 0xFFFFFFFF)
  519. return IRQ_NONE;
  520. /*
  521. * Drain the reply FIFO!
  522. */
  523. do {
  524. if (pa & MPI_ADDRESS_REPLY_A_BIT)
  525. mpt_reply(ioc, pa);
  526. else
  527. mpt_turbo_reply(ioc, pa);
  528. pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
  529. } while (pa != 0xFFFFFFFF);
  530. return IRQ_HANDLED;
  531. }
  532. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  533. /**
  534. * mptbase_reply - MPT base driver's callback routine
  535. * @ioc: Pointer to MPT_ADAPTER structure
  536. * @req: Pointer to original MPT request frame
  537. * @reply: Pointer to MPT reply frame (NULL if TurboReply)
  538. *
  539. * MPT base driver's callback routine; all base driver
  540. * "internal" request/reply processing is routed here.
  541. * Currently used for EventNotification and EventAck handling.
  542. *
  543. * Returns 1 indicating original alloc'd request frame ptr
  544. * should be freed, or 0 if it shouldn't.
  545. */
  546. static int
  547. mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
  548. {
  549. EventNotificationReply_t *pEventReply;
  550. u8 event;
  551. int evHandlers;
  552. int freereq = 1;
  553. switch (reply->u.hdr.Function) {
  554. case MPI_FUNCTION_EVENT_NOTIFICATION:
  555. pEventReply = (EventNotificationReply_t *)reply;
  556. evHandlers = 0;
  557. ProcessEventNotification(ioc, pEventReply, &evHandlers);
  558. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  559. if (pEventReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
  560. freereq = 0;
  561. if (event != MPI_EVENT_EVENT_CHANGE)
  562. break;
  563. case MPI_FUNCTION_CONFIG:
  564. case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
  565. ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  566. if (reply) {
  567. ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  568. memcpy(ioc->mptbase_cmds.reply, reply,
  569. min(MPT_DEFAULT_FRAME_SIZE,
  570. 4 * reply->u.reply.MsgLength));
  571. }
  572. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
  573. ioc->mptbase_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  574. complete(&ioc->mptbase_cmds.done);
  575. } else
  576. freereq = 0;
  577. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_FREE_MF)
  578. freereq = 1;
  579. break;
  580. case MPI_FUNCTION_EVENT_ACK:
  581. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  582. "EventAck reply received\n", ioc->name));
  583. break;
  584. default:
  585. printk(MYIOC_s_ERR_FMT
  586. "Unexpected msg function (=%02Xh) reply received!\n",
  587. ioc->name, reply->u.hdr.Function);
  588. break;
  589. }
  590. /*
  591. * Conditionally tell caller to free the original
  592. * EventNotification/EventAck/unexpected request frame!
  593. */
  594. return freereq;
  595. }
  596. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  597. /**
  598. * mpt_register - Register protocol-specific main callback handler.
  599. * @cbfunc: callback function pointer
  600. * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
  601. * @func_name: call function's name
  602. *
  603. * This routine is called by a protocol-specific driver (SCSI host,
  604. * LAN, SCSI target) to register its reply callback routine. Each
  605. * protocol-specific driver must do this before it will be able to
  606. * use any IOC resources, such as obtaining request frames.
  607. *
  608. * NOTES: The SCSI protocol driver currently calls this routine thrice
  609. * in order to register separate callbacks; one for "normal" SCSI IO;
  610. * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
  611. *
  612. * Returns u8 valued "handle" in the range (and S.O.D. order)
  613. * {N,...,7,6,5,...,1} if successful.
  614. * A return value of MPT_MAX_PROTOCOL_DRIVERS (including zero!) should be
  615. * considered an error by the caller.
  616. */
  617. u8
  618. mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass, char *func_name)
  619. {
  620. u8 cb_idx;
  621. last_drv_idx = MPT_MAX_PROTOCOL_DRIVERS;
  622. /*
  623. * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
  624. * (slot/handle 0 is reserved!)
  625. */
  626. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  627. if (MptCallbacks[cb_idx] == NULL) {
  628. MptCallbacks[cb_idx] = cbfunc;
  629. MptDriverClass[cb_idx] = dclass;
  630. MptEvHandlers[cb_idx] = NULL;
  631. last_drv_idx = cb_idx;
  632. strlcpy(MptCallbacksName[cb_idx], func_name,
  633. MPT_MAX_CALLBACKNAME_LEN+1);
  634. break;
  635. }
  636. }
  637. return last_drv_idx;
  638. }
  639. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  640. /**
  641. * mpt_deregister - Deregister a protocol drivers resources.
  642. * @cb_idx: previously registered callback handle
  643. *
  644. * Each protocol-specific driver should call this routine when its
  645. * module is unloaded.
  646. */
  647. void
  648. mpt_deregister(u8 cb_idx)
  649. {
  650. if (cb_idx && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
  651. MptCallbacks[cb_idx] = NULL;
  652. MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
  653. MptEvHandlers[cb_idx] = NULL;
  654. last_drv_idx++;
  655. }
  656. }
  657. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  658. /**
  659. * mpt_event_register - Register protocol-specific event callback handler.
  660. * @cb_idx: previously registered (via mpt_register) callback handle
  661. * @ev_cbfunc: callback function
  662. *
  663. * This routine can be called by one or more protocol-specific drivers
  664. * if/when they choose to be notified of MPT events.
  665. *
  666. * Returns 0 for success.
  667. */
  668. int
  669. mpt_event_register(u8 cb_idx, MPT_EVHANDLER ev_cbfunc)
  670. {
  671. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  672. return -1;
  673. MptEvHandlers[cb_idx] = ev_cbfunc;
  674. return 0;
  675. }
  676. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  677. /**
  678. * mpt_event_deregister - Deregister protocol-specific event callback handler
  679. * @cb_idx: previously registered callback handle
  680. *
  681. * Each protocol-specific driver should call this routine
  682. * when it does not (or can no longer) handle events,
  683. * or when its module is unloaded.
  684. */
  685. void
  686. mpt_event_deregister(u8 cb_idx)
  687. {
  688. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  689. return;
  690. MptEvHandlers[cb_idx] = NULL;
  691. }
  692. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  693. /**
  694. * mpt_reset_register - Register protocol-specific IOC reset handler.
  695. * @cb_idx: previously registered (via mpt_register) callback handle
  696. * @reset_func: reset function
  697. *
  698. * This routine can be called by one or more protocol-specific drivers
  699. * if/when they choose to be notified of IOC resets.
  700. *
  701. * Returns 0 for success.
  702. */
  703. int
  704. mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func)
  705. {
  706. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  707. return -1;
  708. MptResetHandlers[cb_idx] = reset_func;
  709. return 0;
  710. }
  711. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  712. /**
  713. * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
  714. * @cb_idx: previously registered callback handle
  715. *
  716. * Each protocol-specific driver should call this routine
  717. * when it does not (or can no longer) handle IOC reset handling,
  718. * or when its module is unloaded.
  719. */
  720. void
  721. mpt_reset_deregister(u8 cb_idx)
  722. {
  723. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  724. return;
  725. MptResetHandlers[cb_idx] = NULL;
  726. }
  727. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  728. /**
  729. * mpt_device_driver_register - Register device driver hooks
  730. * @dd_cbfunc: driver callbacks struct
  731. * @cb_idx: MPT protocol driver index
  732. */
  733. int
  734. mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
  735. {
  736. MPT_ADAPTER *ioc;
  737. const struct pci_device_id *id;
  738. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  739. return -EINVAL;
  740. MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
  741. /* call per pci device probe entry point */
  742. list_for_each_entry(ioc, &ioc_list, list) {
  743. id = ioc->pcidev->driver ?
  744. ioc->pcidev->driver->id_table : NULL;
  745. if (dd_cbfunc->probe)
  746. dd_cbfunc->probe(ioc->pcidev, id);
  747. }
  748. return 0;
  749. }
  750. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  751. /**
  752. * mpt_device_driver_deregister - DeRegister device driver hooks
  753. * @cb_idx: MPT protocol driver index
  754. */
  755. void
  756. mpt_device_driver_deregister(u8 cb_idx)
  757. {
  758. struct mpt_pci_driver *dd_cbfunc;
  759. MPT_ADAPTER *ioc;
  760. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  761. return;
  762. dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
  763. list_for_each_entry(ioc, &ioc_list, list) {
  764. if (dd_cbfunc->remove)
  765. dd_cbfunc->remove(ioc->pcidev);
  766. }
  767. MptDeviceDriverHandlers[cb_idx] = NULL;
  768. }
  769. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  770. /**
  771. * mpt_get_msg_frame - Obtain an MPT request frame from the pool
  772. * @cb_idx: Handle of registered MPT protocol driver
  773. * @ioc: Pointer to MPT adapter structure
  774. *
  775. * Obtain an MPT request frame from the pool (of 1024) that are
  776. * allocated per MPT adapter.
  777. *
  778. * Returns pointer to a MPT request frame or %NULL if none are available
  779. * or IOC is not active.
  780. */
  781. MPT_FRAME_HDR*
  782. mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc)
  783. {
  784. MPT_FRAME_HDR *mf;
  785. unsigned long flags;
  786. u16 req_idx; /* Request index */
  787. /* validate handle and ioc identifier */
  788. #ifdef MFCNT
  789. if (!ioc->active)
  790. printk(MYIOC_s_WARN_FMT "IOC Not Active! mpt_get_msg_frame "
  791. "returning NULL!\n", ioc->name);
  792. #endif
  793. /* If interrupts are not attached, do not return a request frame */
  794. if (!ioc->active)
  795. return NULL;
  796. spin_lock_irqsave(&ioc->FreeQlock, flags);
  797. if (!list_empty(&ioc->FreeQ)) {
  798. int req_offset;
  799. mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
  800. u.frame.linkage.list);
  801. list_del(&mf->u.frame.linkage.list);
  802. mf->u.frame.linkage.arg1 = 0;
  803. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx; /* byte */
  804. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  805. /* u16! */
  806. req_idx = req_offset / ioc->req_sz;
  807. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  808. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  809. /* Default, will be changed if necessary in SG generation */
  810. ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame;
  811. #ifdef MFCNT
  812. ioc->mfcnt++;
  813. #endif
  814. }
  815. else
  816. mf = NULL;
  817. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  818. #ifdef MFCNT
  819. if (mf == NULL)
  820. printk(MYIOC_s_WARN_FMT "IOC Active. No free Msg Frames! "
  821. "Count 0x%x Max 0x%x\n", ioc->name, ioc->mfcnt,
  822. ioc->req_depth);
  823. mfcounter++;
  824. if (mfcounter == PRINT_MF_COUNT)
  825. printk(MYIOC_s_INFO_FMT "MF Count 0x%x Max 0x%x \n", ioc->name,
  826. ioc->mfcnt, ioc->req_depth);
  827. #endif
  828. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_get_msg_frame(%d,%d), got mf=%p\n",
  829. ioc->name, cb_idx, ioc->id, mf));
  830. return mf;
  831. }
  832. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  833. /**
  834. * mpt_put_msg_frame - Send a protocol-specific MPT request frame to an IOC
  835. * @cb_idx: Handle of registered MPT protocol driver
  836. * @ioc: Pointer to MPT adapter structure
  837. * @mf: Pointer to MPT request frame
  838. *
  839. * This routine posts an MPT request frame to the request post FIFO of a
  840. * specific MPT adapter.
  841. */
  842. void
  843. mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  844. {
  845. u32 mf_dma_addr;
  846. int req_offset;
  847. u16 req_idx; /* Request index */
  848. /* ensure values are reset properly! */
  849. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx; /* byte */
  850. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  851. /* u16! */
  852. req_idx = req_offset / ioc->req_sz;
  853. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  854. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  855. DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
  856. mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
  857. dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d "
  858. "RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx,
  859. ioc->RequestNB[req_idx]));
  860. CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
  861. }
  862. /**
  863. * mpt_put_msg_frame_hi_pri - Send a hi-pri protocol-specific MPT request frame
  864. * @cb_idx: Handle of registered MPT protocol driver
  865. * @ioc: Pointer to MPT adapter structure
  866. * @mf: Pointer to MPT request frame
  867. *
  868. * Send a protocol-specific MPT request frame to an IOC using
  869. * hi-priority request queue.
  870. *
  871. * This routine posts an MPT request frame to the request post FIFO of a
  872. * specific MPT adapter.
  873. **/
  874. void
  875. mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  876. {
  877. u32 mf_dma_addr;
  878. int req_offset;
  879. u16 req_idx; /* Request index */
  880. /* ensure values are reset properly! */
  881. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
  882. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  883. req_idx = req_offset / ioc->req_sz;
  884. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  885. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  886. DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
  887. mf_dma_addr = (ioc->req_frames_low_dma + req_offset);
  888. dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d\n",
  889. ioc->name, mf_dma_addr, req_idx));
  890. CHIPREG_WRITE32(&ioc->chip->RequestHiPriFifo, mf_dma_addr);
  891. }
  892. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  893. /**
  894. * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
  895. * @ioc: Pointer to MPT adapter structure
  896. * @mf: Pointer to MPT request frame
  897. *
  898. * This routine places a MPT request frame back on the MPT adapter's
  899. * FreeQ.
  900. */
  901. void
  902. mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  903. {
  904. unsigned long flags;
  905. /* Put Request back on FreeQ! */
  906. spin_lock_irqsave(&ioc->FreeQlock, flags);
  907. if (cpu_to_le32(mf->u.frame.linkage.arg1) == 0xdeadbeaf)
  908. goto out;
  909. /* signature to know if this mf is freed */
  910. mf->u.frame.linkage.arg1 = cpu_to_le32(0xdeadbeaf);
  911. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  912. #ifdef MFCNT
  913. ioc->mfcnt--;
  914. #endif
  915. out:
  916. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  917. }
  918. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  919. /**
  920. * mpt_add_sge - Place a simple 32 bit SGE at address pAddr.
  921. * @pAddr: virtual address for SGE
  922. * @flagslength: SGE flags and data transfer length
  923. * @dma_addr: Physical address
  924. *
  925. * This routine places a MPT request frame back on the MPT adapter's
  926. * FreeQ.
  927. */
  928. static void
  929. mpt_add_sge(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
  930. {
  931. SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
  932. pSge->FlagsLength = cpu_to_le32(flagslength);
  933. pSge->Address = cpu_to_le32(dma_addr);
  934. }
  935. /**
  936. * mpt_add_sge_64bit - Place a simple 64 bit SGE at address pAddr.
  937. * @pAddr: virtual address for SGE
  938. * @flagslength: SGE flags and data transfer length
  939. * @dma_addr: Physical address
  940. *
  941. * This routine places a MPT request frame back on the MPT adapter's
  942. * FreeQ.
  943. **/
  944. static void
  945. mpt_add_sge_64bit(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
  946. {
  947. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  948. pSge->Address.Low = cpu_to_le32
  949. (lower_32_bits(dma_addr));
  950. pSge->Address.High = cpu_to_le32
  951. (upper_32_bits(dma_addr));
  952. pSge->FlagsLength = cpu_to_le32
  953. ((flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
  954. }
  955. /**
  956. * mpt_add_sge_64bit_1078 - Place a simple 64 bit SGE at address pAddr (1078 workaround).
  957. * @pAddr: virtual address for SGE
  958. * @flagslength: SGE flags and data transfer length
  959. * @dma_addr: Physical address
  960. *
  961. * This routine places a MPT request frame back on the MPT adapter's
  962. * FreeQ.
  963. **/
  964. static void
  965. mpt_add_sge_64bit_1078(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
  966. {
  967. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  968. u32 tmp;
  969. pSge->Address.Low = cpu_to_le32
  970. (lower_32_bits(dma_addr));
  971. tmp = (u32)(upper_32_bits(dma_addr));
  972. /*
  973. * 1078 errata workaround for the 36GB limitation
  974. */
  975. if ((((u64)dma_addr + MPI_SGE_LENGTH(flagslength)) >> 32) == 9) {
  976. flagslength |=
  977. MPI_SGE_SET_FLAGS(MPI_SGE_FLAGS_LOCAL_ADDRESS);
  978. tmp |= (1<<31);
  979. if (mpt_debug_level & MPT_DEBUG_36GB_MEM)
  980. printk(KERN_DEBUG "1078 P0M2 addressing for "
  981. "addr = 0x%llx len = %d\n",
  982. (unsigned long long)dma_addr,
  983. MPI_SGE_LENGTH(flagslength));
  984. }
  985. pSge->Address.High = cpu_to_le32(tmp);
  986. pSge->FlagsLength = cpu_to_le32(
  987. (flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
  988. }
  989. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  990. /**
  991. * mpt_add_chain - Place a 32 bit chain SGE at address pAddr.
  992. * @pAddr: virtual address for SGE
  993. * @next: nextChainOffset value (u32's)
  994. * @length: length of next SGL segment
  995. * @dma_addr: Physical address
  996. *
  997. */
  998. static void
  999. mpt_add_chain(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
  1000. {
  1001. SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
  1002. pChain->Length = cpu_to_le16(length);
  1003. pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT;
  1004. pChain->NextChainOffset = next;
  1005. pChain->Address = cpu_to_le32(dma_addr);
  1006. }
  1007. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1008. /**
  1009. * mpt_add_chain_64bit - Place a 64 bit chain SGE at address pAddr.
  1010. * @pAddr: virtual address for SGE
  1011. * @next: nextChainOffset value (u32's)
  1012. * @length: length of next SGL segment
  1013. * @dma_addr: Physical address
  1014. *
  1015. */
  1016. static void
  1017. mpt_add_chain_64bit(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
  1018. {
  1019. SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
  1020. u32 tmp = dma_addr & 0xFFFFFFFF;
  1021. pChain->Length = cpu_to_le16(length);
  1022. pChain->Flags = (MPI_SGE_FLAGS_CHAIN_ELEMENT |
  1023. MPI_SGE_FLAGS_64_BIT_ADDRESSING);
  1024. pChain->NextChainOffset = next;
  1025. pChain->Address.Low = cpu_to_le32(tmp);
  1026. tmp = (u32)(upper_32_bits(dma_addr));
  1027. pChain->Address.High = cpu_to_le32(tmp);
  1028. }
  1029. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1030. /**
  1031. * mpt_send_handshake_request - Send MPT request via doorbell handshake method.
  1032. * @cb_idx: Handle of registered MPT protocol driver
  1033. * @ioc: Pointer to MPT adapter structure
  1034. * @reqBytes: Size of the request in bytes
  1035. * @req: Pointer to MPT request frame
  1036. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  1037. *
  1038. * This routine is used exclusively to send MptScsiTaskMgmt
  1039. * requests since they are required to be sent via doorbell handshake.
  1040. *
  1041. * NOTE: It is the callers responsibility to byte-swap fields in the
  1042. * request which are greater than 1 byte in size.
  1043. *
  1044. * Returns 0 for success, non-zero for failure.
  1045. */
  1046. int
  1047. mpt_send_handshake_request(u8 cb_idx, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
  1048. {
  1049. int r = 0;
  1050. u8 *req_as_bytes;
  1051. int ii;
  1052. /* State is known to be good upon entering
  1053. * this function so issue the bus reset
  1054. * request.
  1055. */
  1056. /*
  1057. * Emulate what mpt_put_msg_frame() does /wrt to sanity
  1058. * setting cb_idx/req_idx. But ONLY if this request
  1059. * is in proper (pre-alloc'd) request buffer range...
  1060. */
  1061. ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
  1062. if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
  1063. MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
  1064. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
  1065. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
  1066. }
  1067. /* Make sure there are no doorbells */
  1068. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1069. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  1070. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  1071. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  1072. /* Wait for IOC doorbell int */
  1073. if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
  1074. return ii;
  1075. }
  1076. /* Read doorbell and check for active bit */
  1077. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  1078. return -5;
  1079. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_send_handshake_request start, WaitCnt=%d\n",
  1080. ioc->name, ii));
  1081. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1082. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  1083. return -2;
  1084. }
  1085. /* Send request via doorbell handshake */
  1086. req_as_bytes = (u8 *) req;
  1087. for (ii = 0; ii < reqBytes/4; ii++) {
  1088. u32 word;
  1089. word = ((req_as_bytes[(ii*4) + 0] << 0) |
  1090. (req_as_bytes[(ii*4) + 1] << 8) |
  1091. (req_as_bytes[(ii*4) + 2] << 16) |
  1092. (req_as_bytes[(ii*4) + 3] << 24));
  1093. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  1094. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  1095. r = -3;
  1096. break;
  1097. }
  1098. }
  1099. if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
  1100. r = 0;
  1101. else
  1102. r = -4;
  1103. /* Make sure there are no doorbells */
  1104. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1105. return r;
  1106. }
  1107. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1108. /**
  1109. * mpt_host_page_access_control - control the IOC's Host Page Buffer access
  1110. * @ioc: Pointer to MPT adapter structure
  1111. * @access_control_value: define bits below
  1112. * @sleepFlag: Specifies whether the process can sleep
  1113. *
  1114. * Provides mechanism for the host driver to control the IOC's
  1115. * Host Page Buffer access.
  1116. *
  1117. * Access Control Value - bits[15:12]
  1118. * 0h Reserved
  1119. * 1h Enable Access { MPI_DB_HPBAC_ENABLE_ACCESS }
  1120. * 2h Disable Access { MPI_DB_HPBAC_DISABLE_ACCESS }
  1121. * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
  1122. *
  1123. * Returns 0 for success, non-zero for failure.
  1124. */
  1125. static int
  1126. mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
  1127. {
  1128. int r = 0;
  1129. /* return if in use */
  1130. if (CHIPREG_READ32(&ioc->chip->Doorbell)
  1131. & MPI_DOORBELL_ACTIVE)
  1132. return -1;
  1133. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1134. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  1135. ((MPI_FUNCTION_HOST_PAGEBUF_ACCESS_CONTROL
  1136. <<MPI_DOORBELL_FUNCTION_SHIFT) |
  1137. (access_control_value<<12)));
  1138. /* Wait for IOC to clear Doorbell Status bit */
  1139. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  1140. return -2;
  1141. }else
  1142. return 0;
  1143. }
  1144. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1145. /**
  1146. * mpt_host_page_alloc - allocate system memory for the fw
  1147. * @ioc: Pointer to pointer to IOC adapter
  1148. * @ioc_init: Pointer to ioc init config page
  1149. *
  1150. * If we already allocated memory in past, then resend the same pointer.
  1151. * Returns 0 for success, non-zero for failure.
  1152. */
  1153. static int
  1154. mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
  1155. {
  1156. char *psge;
  1157. int flags_length;
  1158. u32 host_page_buffer_sz=0;
  1159. if(!ioc->HostPageBuffer) {
  1160. host_page_buffer_sz =
  1161. le32_to_cpu(ioc->facts.HostPageBufferSGE.FlagsLength) & 0xFFFFFF;
  1162. if(!host_page_buffer_sz)
  1163. return 0; /* fw doesn't need any host buffers */
  1164. /* spin till we get enough memory */
  1165. while(host_page_buffer_sz > 0) {
  1166. if((ioc->HostPageBuffer = pci_alloc_consistent(
  1167. ioc->pcidev,
  1168. host_page_buffer_sz,
  1169. &ioc->HostPageBuffer_dma)) != NULL) {
  1170. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1171. "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
  1172. ioc->name, ioc->HostPageBuffer,
  1173. (u32)ioc->HostPageBuffer_dma,
  1174. host_page_buffer_sz));
  1175. ioc->alloc_total += host_page_buffer_sz;
  1176. ioc->HostPageBuffer_sz = host_page_buffer_sz;
  1177. break;
  1178. }
  1179. host_page_buffer_sz -= (4*1024);
  1180. }
  1181. }
  1182. if(!ioc->HostPageBuffer) {
  1183. printk(MYIOC_s_ERR_FMT
  1184. "Failed to alloc memory for host_page_buffer!\n",
  1185. ioc->name);
  1186. return -999;
  1187. }
  1188. psge = (char *)&ioc_init->HostPageBufferSGE;
  1189. flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
  1190. MPI_SGE_FLAGS_SYSTEM_ADDRESS |
  1191. MPI_SGE_FLAGS_HOST_TO_IOC |
  1192. MPI_SGE_FLAGS_END_OF_BUFFER;
  1193. flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
  1194. flags_length |= ioc->HostPageBuffer_sz;
  1195. ioc->add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
  1196. ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
  1197. return 0;
  1198. }
  1199. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1200. /**
  1201. * mpt_verify_adapter - Given IOC identifier, set pointer to its adapter structure.
  1202. * @iocid: IOC unique identifier (integer)
  1203. * @iocpp: Pointer to pointer to IOC adapter
  1204. *
  1205. * Given a unique IOC identifier, set pointer to the associated MPT
  1206. * adapter structure.
  1207. *
  1208. * Returns iocid and sets iocpp if iocid is found.
  1209. * Returns -1 if iocid is not found.
  1210. */
  1211. int
  1212. mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
  1213. {
  1214. MPT_ADAPTER *ioc;
  1215. list_for_each_entry(ioc,&ioc_list,list) {
  1216. if (ioc->id == iocid) {
  1217. *iocpp =ioc;
  1218. return iocid;
  1219. }
  1220. }
  1221. *iocpp = NULL;
  1222. return -1;
  1223. }
  1224. /**
  1225. * mpt_get_product_name - returns product string
  1226. * @vendor: pci vendor id
  1227. * @device: pci device id
  1228. * @revision: pci revision id
  1229. * @prod_name: string returned
  1230. *
  1231. * Returns product string displayed when driver loads,
  1232. * in /proc/mpt/summary and /sysfs/class/scsi_host/host<X>/version_product
  1233. *
  1234. **/
  1235. static void
  1236. mpt_get_product_name(u16 vendor, u16 device, u8 revision, char *prod_name)
  1237. {
  1238. char *product_str = NULL;
  1239. if (vendor == PCI_VENDOR_ID_BROCADE) {
  1240. switch (device)
  1241. {
  1242. case MPI_MANUFACTPAGE_DEVICEID_FC949E:
  1243. switch (revision)
  1244. {
  1245. case 0x00:
  1246. product_str = "BRE040 A0";
  1247. break;
  1248. case 0x01:
  1249. product_str = "BRE040 A1";
  1250. break;
  1251. default:
  1252. product_str = "BRE040";
  1253. break;
  1254. }
  1255. break;
  1256. }
  1257. goto out;
  1258. }
  1259. switch (device)
  1260. {
  1261. case MPI_MANUFACTPAGE_DEVICEID_FC909:
  1262. product_str = "LSIFC909 B1";
  1263. break;
  1264. case MPI_MANUFACTPAGE_DEVICEID_FC919:
  1265. product_str = "LSIFC919 B0";
  1266. break;
  1267. case MPI_MANUFACTPAGE_DEVICEID_FC929:
  1268. product_str = "LSIFC929 B0";
  1269. break;
  1270. case MPI_MANUFACTPAGE_DEVICEID_FC919X:
  1271. if (revision < 0x80)
  1272. product_str = "LSIFC919X A0";
  1273. else
  1274. product_str = "LSIFC919XL A1";
  1275. break;
  1276. case MPI_MANUFACTPAGE_DEVICEID_FC929X:
  1277. if (revision < 0x80)
  1278. product_str = "LSIFC929X A0";
  1279. else
  1280. product_str = "LSIFC929XL A1";
  1281. break;
  1282. case MPI_MANUFACTPAGE_DEVICEID_FC939X:
  1283. product_str = "LSIFC939X A1";
  1284. break;
  1285. case MPI_MANUFACTPAGE_DEVICEID_FC949X:
  1286. product_str = "LSIFC949X A1";
  1287. break;
  1288. case MPI_MANUFACTPAGE_DEVICEID_FC949E:
  1289. switch (revision)
  1290. {
  1291. case 0x00:
  1292. product_str = "LSIFC949E A0";
  1293. break;
  1294. case 0x01:
  1295. product_str = "LSIFC949E A1";
  1296. break;
  1297. default:
  1298. product_str = "LSIFC949E";
  1299. break;
  1300. }
  1301. break;
  1302. case MPI_MANUFACTPAGE_DEVID_53C1030:
  1303. switch (revision)
  1304. {
  1305. case 0x00:
  1306. product_str = "LSI53C1030 A0";
  1307. break;
  1308. case 0x01:
  1309. product_str = "LSI53C1030 B0";
  1310. break;
  1311. case 0x03:
  1312. product_str = "LSI53C1030 B1";
  1313. break;
  1314. case 0x07:
  1315. product_str = "LSI53C1030 B2";
  1316. break;
  1317. case 0x08:
  1318. product_str = "LSI53C1030 C0";
  1319. break;
  1320. case 0x80:
  1321. product_str = "LSI53C1030T A0";
  1322. break;
  1323. case 0x83:
  1324. product_str = "LSI53C1030T A2";
  1325. break;
  1326. case 0x87:
  1327. product_str = "LSI53C1030T A3";
  1328. break;
  1329. case 0xc1:
  1330. product_str = "LSI53C1020A A1";
  1331. break;
  1332. default:
  1333. product_str = "LSI53C1030";
  1334. break;
  1335. }
  1336. break;
  1337. case MPI_MANUFACTPAGE_DEVID_1030_53C1035:
  1338. switch (revision)
  1339. {
  1340. case 0x03:
  1341. product_str = "LSI53C1035 A2";
  1342. break;
  1343. case 0x04:
  1344. product_str = "LSI53C1035 B0";
  1345. break;
  1346. default:
  1347. product_str = "LSI53C1035";
  1348. break;
  1349. }
  1350. break;
  1351. case MPI_MANUFACTPAGE_DEVID_SAS1064:
  1352. switch (revision)
  1353. {
  1354. case 0x00:
  1355. product_str = "LSISAS1064 A1";
  1356. break;
  1357. case 0x01:
  1358. product_str = "LSISAS1064 A2";
  1359. break;
  1360. case 0x02:
  1361. product_str = "LSISAS1064 A3";
  1362. break;
  1363. case 0x03:
  1364. product_str = "LSISAS1064 A4";
  1365. break;
  1366. default:
  1367. product_str = "LSISAS1064";
  1368. break;
  1369. }
  1370. break;
  1371. case MPI_MANUFACTPAGE_DEVID_SAS1064E:
  1372. switch (revision)
  1373. {
  1374. case 0x00:
  1375. product_str = "LSISAS1064E A0";
  1376. break;
  1377. case 0x01:
  1378. product_str = "LSISAS1064E B0";
  1379. break;
  1380. case 0x02:
  1381. product_str = "LSISAS1064E B1";
  1382. break;
  1383. case 0x04:
  1384. product_str = "LSISAS1064E B2";
  1385. break;
  1386. case 0x08:
  1387. product_str = "LSISAS1064E B3";
  1388. break;
  1389. default:
  1390. product_str = "LSISAS1064E";
  1391. break;
  1392. }
  1393. break;
  1394. case MPI_MANUFACTPAGE_DEVID_SAS1068:
  1395. switch (revision)
  1396. {
  1397. case 0x00:
  1398. product_str = "LSISAS1068 A0";
  1399. break;
  1400. case 0x01:
  1401. product_str = "LSISAS1068 B0";
  1402. break;
  1403. case 0x02:
  1404. product_str = "LSISAS1068 B1";
  1405. break;
  1406. default:
  1407. product_str = "LSISAS1068";
  1408. break;
  1409. }
  1410. break;
  1411. case MPI_MANUFACTPAGE_DEVID_SAS1068E:
  1412. switch (revision)
  1413. {
  1414. case 0x00:
  1415. product_str = "LSISAS1068E A0";
  1416. break;
  1417. case 0x01:
  1418. product_str = "LSISAS1068E B0";
  1419. break;
  1420. case 0x02:
  1421. product_str = "LSISAS1068E B1";
  1422. break;
  1423. case 0x04:
  1424. product_str = "LSISAS1068E B2";
  1425. break;
  1426. case 0x08:
  1427. product_str = "LSISAS1068E B3";
  1428. break;
  1429. default:
  1430. product_str = "LSISAS1068E";
  1431. break;
  1432. }
  1433. break;
  1434. case MPI_MANUFACTPAGE_DEVID_SAS1078:
  1435. switch (revision)
  1436. {
  1437. case 0x00:
  1438. product_str = "LSISAS1078 A0";
  1439. break;
  1440. case 0x01:
  1441. product_str = "LSISAS1078 B0";
  1442. break;
  1443. case 0x02:
  1444. product_str = "LSISAS1078 C0";
  1445. break;
  1446. case 0x03:
  1447. product_str = "LSISAS1078 C1";
  1448. break;
  1449. case 0x04:
  1450. product_str = "LSISAS1078 C2";
  1451. break;
  1452. default:
  1453. product_str = "LSISAS1078";
  1454. break;
  1455. }
  1456. break;
  1457. }
  1458. out:
  1459. if (product_str)
  1460. sprintf(prod_name, "%s", product_str);
  1461. }
  1462. /**
  1463. * mpt_mapresources - map in memory mapped io
  1464. * @ioc: Pointer to pointer to IOC adapter
  1465. *
  1466. **/
  1467. static int
  1468. mpt_mapresources(MPT_ADAPTER *ioc)
  1469. {
  1470. u8 __iomem *mem;
  1471. int ii;
  1472. resource_size_t mem_phys;
  1473. unsigned long port;
  1474. u32 msize;
  1475. u32 psize;
  1476. u8 revision;
  1477. int r = -ENODEV;
  1478. struct pci_dev *pdev;
  1479. pdev = ioc->pcidev;
  1480. ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1481. if (pci_enable_device_mem(pdev)) {
  1482. printk(MYIOC_s_ERR_FMT "pci_enable_device_mem() "
  1483. "failed\n", ioc->name);
  1484. return r;
  1485. }
  1486. if (pci_request_selected_regions(pdev, ioc->bars, "mpt")) {
  1487. printk(MYIOC_s_ERR_FMT "pci_request_selected_regions() with "
  1488. "MEM failed\n", ioc->name);
  1489. return r;
  1490. }
  1491. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1492. if (sizeof(dma_addr_t) > 4) {
  1493. const uint64_t required_mask = dma_get_required_mask
  1494. (&pdev->dev);
  1495. if (required_mask > DMA_BIT_MASK(32)
  1496. && !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
  1497. && !pci_set_consistent_dma_mask(pdev,
  1498. DMA_BIT_MASK(64))) {
  1499. ioc->dma_mask = DMA_BIT_MASK(64);
  1500. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  1501. ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
  1502. ioc->name));
  1503. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
  1504. && !pci_set_consistent_dma_mask(pdev,
  1505. DMA_BIT_MASK(32))) {
  1506. ioc->dma_mask = DMA_BIT_MASK(32);
  1507. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  1508. ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
  1509. ioc->name));
  1510. } else {
  1511. printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
  1512. ioc->name, pci_name(pdev));
  1513. pci_release_selected_regions(pdev, ioc->bars);
  1514. return r;
  1515. }
  1516. } else {
  1517. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
  1518. && !pci_set_consistent_dma_mask(pdev,
  1519. DMA_BIT_MASK(32))) {
  1520. ioc->dma_mask = DMA_BIT_MASK(32);
  1521. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  1522. ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
  1523. ioc->name));
  1524. } else {
  1525. printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
  1526. ioc->name, pci_name(pdev));
  1527. pci_release_selected_regions(pdev, ioc->bars);
  1528. return r;
  1529. }
  1530. }
  1531. mem_phys = msize = 0;
  1532. port = psize = 0;
  1533. for (ii = 0; ii < DEVICE_COUNT_RESOURCE; ii++) {
  1534. if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
  1535. if (psize)
  1536. continue;
  1537. /* Get I/O space! */
  1538. port = pci_resource_start(pdev, ii);
  1539. psize = pci_resource_len(pdev, ii);
  1540. } else {
  1541. if (msize)
  1542. continue;
  1543. /* Get memmap */
  1544. mem_phys = pci_resource_start(pdev, ii);
  1545. msize = pci_resource_len(pdev, ii);
  1546. }
  1547. }
  1548. ioc->mem_size = msize;
  1549. mem = NULL;
  1550. /* Get logical ptr for PciMem0 space */
  1551. /*mem = ioremap(mem_phys, msize);*/
  1552. mem = ioremap(mem_phys, msize);
  1553. if (mem == NULL) {
  1554. printk(MYIOC_s_ERR_FMT ": ERROR - Unable to map adapter"
  1555. " memory!\n", ioc->name);
  1556. pci_release_selected_regions(pdev, ioc->bars);
  1557. return -EINVAL;
  1558. }
  1559. ioc->memmap = mem;
  1560. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "mem = %p, mem_phys = %llx\n",
  1561. ioc->name, mem, (unsigned long long)mem_phys));
  1562. ioc->mem_phys = mem_phys;
  1563. ioc->chip = (SYSIF_REGS __iomem *)mem;
  1564. /* Save Port IO values in case we need to do downloadboot */
  1565. ioc->pio_mem_phys = port;
  1566. ioc->pio_chip = (SYSIF_REGS __iomem *)port;
  1567. return 0;
  1568. }
  1569. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1570. /**
  1571. * mpt_attach - Install a PCI intelligent MPT adapter.
  1572. * @pdev: Pointer to pci_dev structure
  1573. * @id: PCI device ID information
  1574. *
  1575. * This routine performs all the steps necessary to bring the IOC of
  1576. * a MPT adapter to a OPERATIONAL state. This includes registering
  1577. * memory regions, registering the interrupt, and allocating request
  1578. * and reply memory pools.
  1579. *
  1580. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  1581. * MPT adapter.
  1582. *
  1583. * Returns 0 for success, non-zero for failure.
  1584. *
  1585. * TODO: Add support for polled controllers
  1586. */
  1587. int
  1588. mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
  1589. {
  1590. MPT_ADAPTER *ioc;
  1591. u8 cb_idx;
  1592. int r = -ENODEV;
  1593. u8 revision;
  1594. u8 pcixcmd;
  1595. static int mpt_ids = 0;
  1596. #ifdef CONFIG_PROC_FS
  1597. struct proc_dir_entry *dent;
  1598. #endif
  1599. ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
  1600. if (ioc == NULL) {
  1601. printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
  1602. return -ENOMEM;
  1603. }
  1604. ioc->id = mpt_ids++;
  1605. sprintf(ioc->name, "ioc%d", ioc->id);
  1606. dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n"));
  1607. /*
  1608. * set initial debug level
  1609. * (refer to mptdebug.h)
  1610. *
  1611. */
  1612. ioc->debug_level = mpt_debug_level;
  1613. if (mpt_debug_level)
  1614. printk(KERN_INFO "mpt_debug_level=%xh\n", mpt_debug_level);
  1615. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": mpt_adapter_install\n", ioc->name));
  1616. ioc->pcidev = pdev;
  1617. if (mpt_mapresources(ioc)) {
  1618. kfree(ioc);
  1619. return r;
  1620. }
  1621. /*
  1622. * Setting up proper handlers for scatter gather handling
  1623. */
  1624. if (ioc->dma_mask == DMA_BIT_MASK(64)) {
  1625. if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
  1626. ioc->add_sge = &mpt_add_sge_64bit_1078;
  1627. else
  1628. ioc->add_sge = &mpt_add_sge_64bit;
  1629. ioc->add_chain = &mpt_add_chain_64bit;
  1630. ioc->sg_addr_size = 8;
  1631. } else {
  1632. ioc->add_sge = &mpt_add_sge;
  1633. ioc->add_chain = &mpt_add_chain;
  1634. ioc->sg_addr_size = 4;
  1635. }
  1636. ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
  1637. ioc->alloc_total = sizeof(MPT_ADAPTER);
  1638. ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
  1639. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  1640. spin_lock_init(&ioc->taskmgmt_lock);
  1641. mutex_init(&ioc->internal_cmds.mutex);
  1642. init_completion(&ioc->internal_cmds.done);
  1643. mutex_init(&ioc->mptbase_cmds.mutex);
  1644. init_completion(&ioc->mptbase_cmds.done);
  1645. mutex_init(&ioc->taskmgmt_cmds.mutex);
  1646. init_completion(&ioc->taskmgmt_cmds.done);
  1647. /* Initialize the event logging.
  1648. */
  1649. ioc->eventTypes = 0; /* None */
  1650. ioc->eventContext = 0;
  1651. ioc->eventLogSize = 0;
  1652. ioc->events = NULL;
  1653. #ifdef MFCNT
  1654. ioc->mfcnt = 0;
  1655. #endif
  1656. ioc->sh = NULL;
  1657. ioc->cached_fw = NULL;
  1658. /* Initialize SCSI Config Data structure
  1659. */
  1660. memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
  1661. /* Initialize the fc rport list head.
  1662. */
  1663. INIT_LIST_HEAD(&ioc->fc_rports);
  1664. /* Find lookup slot. */
  1665. INIT_LIST_HEAD(&ioc->list);
  1666. /* Initialize workqueue */
  1667. INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work);
  1668. snprintf(ioc->reset_work_q_name, MPT_KOBJ_NAME_LEN,
  1669. "mpt_poll_%d", ioc->id);
  1670. ioc->reset_work_q =
  1671. create_singlethread_workqueue(ioc->reset_work_q_name);
  1672. if (!ioc->reset_work_q) {
  1673. printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n",
  1674. ioc->name);
  1675. pci_release_selected_regions(pdev, ioc->bars);
  1676. kfree(ioc);
  1677. return -ENOMEM;
  1678. }
  1679. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "facts @ %p, pfacts[0] @ %p\n",
  1680. ioc->name, &ioc->facts, &ioc->pfacts[0]));
  1681. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1682. mpt_get_product_name(pdev->vendor, pdev->device, revision, ioc->prod_name);
  1683. switch (pdev->device)
  1684. {
  1685. case MPI_MANUFACTPAGE_DEVICEID_FC939X:
  1686. case MPI_MANUFACTPAGE_DEVICEID_FC949X:
  1687. ioc->errata_flag_1064 = 1;
  1688. case MPI_MANUFACTPAGE_DEVICEID_FC909:
  1689. case MPI_MANUFACTPAGE_DEVICEID_FC929:
  1690. case MPI_MANUFACTPAGE_DEVICEID_FC919:
  1691. case MPI_MANUFACTPAGE_DEVICEID_FC949E:
  1692. ioc->bus_type = FC;
  1693. break;
  1694. case MPI_MANUFACTPAGE_DEVICEID_FC929X:
  1695. if (revision < XL_929) {
  1696. /* 929X Chip Fix. Set Split transactions level
  1697. * for PCIX. Set MOST bits to zero.
  1698. */
  1699. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1700. pcixcmd &= 0x8F;
  1701. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1702. } else {
  1703. /* 929XL Chip Fix. Set MMRBC to 0x08.
  1704. */
  1705. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1706. pcixcmd |= 0x08;
  1707. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1708. }
  1709. ioc->bus_type = FC;
  1710. break;
  1711. case MPI_MANUFACTPAGE_DEVICEID_FC919X:
  1712. /* 919X Chip Fix. Set Split transactions level
  1713. * for PCIX. Set MOST bits to zero.
  1714. */
  1715. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1716. pcixcmd &= 0x8F;
  1717. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1718. ioc->bus_type = FC;
  1719. break;
  1720. case MPI_MANUFACTPAGE_DEVID_53C1030:
  1721. /* 1030 Chip Fix. Disable Split transactions
  1722. * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
  1723. */
  1724. if (revision < C0_1030) {
  1725. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1726. pcixcmd &= 0x8F;
  1727. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1728. }
  1729. case MPI_MANUFACTPAGE_DEVID_1030_53C1035:
  1730. ioc->bus_type = SPI;
  1731. break;
  1732. case MPI_MANUFACTPAGE_DEVID_SAS1064:
  1733. case MPI_MANUFACTPAGE_DEVID_SAS1068:
  1734. ioc->errata_flag_1064 = 1;
  1735. ioc->bus_type = SAS;
  1736. break;
  1737. case MPI_MANUFACTPAGE_DEVID_SAS1064E:
  1738. case MPI_MANUFACTPAGE_DEVID_SAS1068E:
  1739. case MPI_MANUFACTPAGE_DEVID_SAS1078:
  1740. ioc->bus_type = SAS;
  1741. break;
  1742. }
  1743. switch (ioc->bus_type) {
  1744. case SAS:
  1745. ioc->msi_enable = mpt_msi_enable_sas;
  1746. break;
  1747. case SPI:
  1748. ioc->msi_enable = mpt_msi_enable_spi;
  1749. break;
  1750. case FC:
  1751. ioc->msi_enable = mpt_msi_enable_fc;
  1752. break;
  1753. default:
  1754. ioc->msi_enable = 0;
  1755. break;
  1756. }
  1757. ioc->fw_events_off = 1;
  1758. if (ioc->errata_flag_1064)
  1759. pci_disable_io_access(pdev);
  1760. spin_lock_init(&ioc->FreeQlock);
  1761. /* Disable all! */
  1762. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1763. ioc->active = 0;
  1764. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1765. /* Set IOC ptr in the pcidev's driver data. */
  1766. pci_set_drvdata(ioc->pcidev, ioc);
  1767. /* Set lookup ptr. */
  1768. list_add_tail(&ioc->list, &ioc_list);
  1769. /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
  1770. */
  1771. mpt_detect_bound_ports(ioc, pdev);
  1772. INIT_LIST_HEAD(&ioc->fw_event_list);
  1773. spin_lock_init(&ioc->fw_event_lock);
  1774. snprintf(ioc->fw_event_q_name, MPT_KOBJ_NAME_LEN, "mpt/%d", ioc->id);
  1775. ioc->fw_event_q = create_singlethread_workqueue(ioc->fw_event_q_name);
  1776. if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
  1777. CAN_SLEEP)) != 0){
  1778. printk(MYIOC_s_ERR_FMT "didn't initialize properly! (%d)\n",
  1779. ioc->name, r);
  1780. list_del(&ioc->list);
  1781. if (ioc->alt_ioc)
  1782. ioc->alt_ioc->alt_ioc = NULL;
  1783. iounmap(ioc->memmap);
  1784. if (r != -5)
  1785. pci_release_selected_regions(pdev, ioc->bars);
  1786. destroy_workqueue(ioc->reset_work_q);
  1787. ioc->reset_work_q = NULL;
  1788. kfree(ioc);
  1789. pci_set_drvdata(pdev, NULL);
  1790. return r;
  1791. }
  1792. /* call per device driver probe entry point */
  1793. for(cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
  1794. if(MptDeviceDriverHandlers[cb_idx] &&
  1795. MptDeviceDriverHandlers[cb_idx]->probe) {
  1796. MptDeviceDriverHandlers[cb_idx]->probe(pdev,id);
  1797. }
  1798. }
  1799. #ifdef CONFIG_PROC_FS
  1800. /*
  1801. * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
  1802. */
  1803. dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
  1804. if (dent) {
  1805. proc_create_data("info", S_IRUGO, dent, &mpt_iocinfo_proc_fops, ioc);
  1806. proc_create_data("summary", S_IRUGO, dent, &mpt_summary_proc_fops, ioc);
  1807. }
  1808. #endif
  1809. if (!ioc->alt_ioc)
  1810. queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
  1811. msecs_to_jiffies(MPT_POLLING_INTERVAL));
  1812. return 0;
  1813. }
  1814. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1815. /**
  1816. * mpt_detach - Remove a PCI intelligent MPT adapter.
  1817. * @pdev: Pointer to pci_dev structure
  1818. */
  1819. void
  1820. mpt_detach(struct pci_dev *pdev)
  1821. {
  1822. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1823. char pname[32];
  1824. u8 cb_idx;
  1825. unsigned long flags;
  1826. struct workqueue_struct *wq;
  1827. /*
  1828. * Stop polling ioc for fault condition
  1829. */
  1830. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  1831. wq = ioc->reset_work_q;
  1832. ioc->reset_work_q = NULL;
  1833. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  1834. cancel_delayed_work(&ioc->fault_reset_work);
  1835. destroy_workqueue(wq);
  1836. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  1837. wq = ioc->fw_event_q;
  1838. ioc->fw_event_q = NULL;
  1839. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  1840. destroy_workqueue(wq);
  1841. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
  1842. remove_proc_entry(pname, NULL);
  1843. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
  1844. remove_proc_entry(pname, NULL);
  1845. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
  1846. remove_proc_entry(pname, NULL);
  1847. /* call per device driver remove entry point */
  1848. for(cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
  1849. if(MptDeviceDriverHandlers[cb_idx] &&
  1850. MptDeviceDriverHandlers[cb_idx]->remove) {
  1851. MptDeviceDriverHandlers[cb_idx]->remove(pdev);
  1852. }
  1853. }
  1854. /* Disable interrupts! */
  1855. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1856. ioc->active = 0;
  1857. synchronize_irq(pdev->irq);
  1858. /* Clear any lingering interrupt */
  1859. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1860. CHIPREG_READ32(&ioc->chip->IntStatus);
  1861. mpt_adapter_dispose(ioc);
  1862. }
  1863. /**************************************************************************
  1864. * Power Management
  1865. */
  1866. #ifdef CONFIG_PM
  1867. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1868. /**
  1869. * mpt_suspend - Fusion MPT base driver suspend routine.
  1870. * @pdev: Pointer to pci_dev structure
  1871. * @state: new state to enter
  1872. */
  1873. int
  1874. mpt_suspend(struct pci_dev *pdev, pm_message_t state)
  1875. {
  1876. u32 device_state;
  1877. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1878. device_state = pci_choose_state(pdev, state);
  1879. printk(MYIOC_s_INFO_FMT "pci-suspend: pdev=0x%p, slot=%s, Entering "
  1880. "operating state [D%d]\n", ioc->name, pdev, pci_name(pdev),
  1881. device_state);
  1882. /* put ioc into READY_STATE */
  1883. if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
  1884. printk(MYIOC_s_ERR_FMT
  1885. "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
  1886. }
  1887. /* disable interrupts */
  1888. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1889. ioc->active = 0;
  1890. /* Clear any lingering interrupt */
  1891. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1892. free_irq(ioc->pci_irq, ioc);
  1893. if (ioc->msi_enable)
  1894. pci_disable_msi(ioc->pcidev);
  1895. ioc->pci_irq = -1;
  1896. pci_save_state(pdev);
  1897. pci_disable_device(pdev);
  1898. pci_release_selected_regions(pdev, ioc->bars);
  1899. pci_set_power_state(pdev, device_state);
  1900. return 0;
  1901. }
  1902. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1903. /**
  1904. * mpt_resume - Fusion MPT base driver resume routine.
  1905. * @pdev: Pointer to pci_dev structure
  1906. */
  1907. int
  1908. mpt_resume(struct pci_dev *pdev)
  1909. {
  1910. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1911. u32 device_state = pdev->current_state;
  1912. int recovery_state;
  1913. int err;
  1914. printk(MYIOC_s_INFO_FMT "pci-resume: pdev=0x%p, slot=%s, Previous "
  1915. "operating state [D%d]\n", ioc->name, pdev, pci_name(pdev),
  1916. device_state);
  1917. pci_set_power_state(pdev, PCI_D0);
  1918. pci_enable_wake(pdev, PCI_D0, 0);
  1919. pci_restore_state(pdev);
  1920. ioc->pcidev = pdev;
  1921. err = mpt_mapresources(ioc);
  1922. if (err)
  1923. return err;
  1924. if (ioc->dma_mask == DMA_BIT_MASK(64)) {
  1925. if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
  1926. ioc->add_sge = &mpt_add_sge_64bit_1078;
  1927. else
  1928. ioc->add_sge = &mpt_add_sge_64bit;
  1929. ioc->add_chain = &mpt_add_chain_64bit;
  1930. ioc->sg_addr_size = 8;
  1931. } else {
  1932. ioc->add_sge = &mpt_add_sge;
  1933. ioc->add_chain = &mpt_add_chain;
  1934. ioc->sg_addr_size = 4;
  1935. }
  1936. ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
  1937. printk(MYIOC_s_INFO_FMT "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
  1938. ioc->name, (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
  1939. CHIPREG_READ32(&ioc->chip->Doorbell));
  1940. /*
  1941. * Errata workaround for SAS pci express:
  1942. * Upon returning to the D0 state, the contents of the doorbell will be
  1943. * stale data, and this will incorrectly signal to the host driver that
  1944. * the firmware is ready to process mpt commands. The workaround is
  1945. * to issue a diagnostic reset.
  1946. */
  1947. if (ioc->bus_type == SAS && (pdev->device ==
  1948. MPI_MANUFACTPAGE_DEVID_SAS1068E || pdev->device ==
  1949. MPI_MANUFACTPAGE_DEVID_SAS1064E)) {
  1950. if (KickStart(ioc, 1, CAN_SLEEP) < 0) {
  1951. printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover\n",
  1952. ioc->name);
  1953. goto out;
  1954. }
  1955. }
  1956. /* bring ioc to operational state */
  1957. printk(MYIOC_s_INFO_FMT "Sending mpt_do_ioc_recovery\n", ioc->name);
  1958. recovery_state = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
  1959. CAN_SLEEP);
  1960. if (recovery_state != 0)
  1961. printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover, "
  1962. "error:[%x]\n", ioc->name, recovery_state);
  1963. else
  1964. printk(MYIOC_s_INFO_FMT
  1965. "pci-resume: success\n", ioc->name);
  1966. out:
  1967. return 0;
  1968. }
  1969. #endif
  1970. static int
  1971. mpt_signal_reset(u8 index, MPT_ADAPTER *ioc, int reset_phase)
  1972. {
  1973. if ((MptDriverClass[index] == MPTSPI_DRIVER &&
  1974. ioc->bus_type != SPI) ||
  1975. (MptDriverClass[index] == MPTFC_DRIVER &&
  1976. ioc->bus_type != FC) ||
  1977. (MptDriverClass[index] == MPTSAS_DRIVER &&
  1978. ioc->bus_type != SAS))
  1979. /* make sure we only call the relevant reset handler
  1980. * for the bus */
  1981. return 0;
  1982. return (MptResetHandlers[index])(ioc, reset_phase);
  1983. }
  1984. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1985. /**
  1986. * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
  1987. * @ioc: Pointer to MPT adapter structure
  1988. * @reason: Event word / reason
  1989. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  1990. *
  1991. * This routine performs all the steps necessary to bring the IOC
  1992. * to a OPERATIONAL state.
  1993. *
  1994. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  1995. * MPT adapter.
  1996. *
  1997. * Returns:
  1998. * 0 for success
  1999. * -1 if failed to get board READY
  2000. * -2 if READY but IOCFacts Failed
  2001. * -3 if READY but PrimeIOCFifos Failed
  2002. * -4 if READY but IOCInit Failed
  2003. * -5 if failed to enable_device and/or request_selected_regions
  2004. * -6 if failed to upload firmware
  2005. */
  2006. static int
  2007. mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
  2008. {
  2009. int hard_reset_done = 0;
  2010. int alt_ioc_ready = 0;
  2011. int hard;
  2012. int rc=0;
  2013. int ii;
  2014. int ret = 0;
  2015. int reset_alt_ioc_active = 0;
  2016. int irq_allocated = 0;
  2017. u8 *a;
  2018. printk(MYIOC_s_INFO_FMT "Initiating %s\n", ioc->name,
  2019. reason == MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
  2020. /* Disable reply interrupts (also blocks FreeQ) */
  2021. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  2022. ioc->active = 0;
  2023. if (ioc->alt_ioc) {
  2024. if (ioc->alt_ioc->active ||
  2025. reason == MPT_HOSTEVENT_IOC_RECOVER) {
  2026. reset_alt_ioc_active = 1;
  2027. /* Disable alt-IOC's reply interrupts
  2028. * (and FreeQ) for a bit
  2029. **/
  2030. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
  2031. 0xFFFFFFFF);
  2032. ioc->alt_ioc->active = 0;
  2033. }
  2034. }
  2035. hard = 1;
  2036. if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
  2037. hard = 0;
  2038. if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
  2039. if (hard_reset_done == -4) {
  2040. printk(MYIOC_s_WARN_FMT "Owned by PEER..skipping!\n",
  2041. ioc->name);
  2042. if (reset_alt_ioc_active && ioc->alt_ioc) {
  2043. /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
  2044. dprintk(ioc, printk(MYIOC_s_INFO_FMT
  2045. "alt_ioc reply irq re-enabled\n", ioc->alt_ioc->name));
  2046. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
  2047. ioc->alt_ioc->active = 1;
  2048. }
  2049. } else {
  2050. printk(MYIOC_s_WARN_FMT
  2051. "NOT READY WARNING!\n", ioc->name);
  2052. }
  2053. ret = -1;
  2054. goto out;
  2055. }
  2056. /* hard_reset_done = 0 if a soft reset was performed
  2057. * and 1 if a hard reset was performed.
  2058. */
  2059. if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
  2060. if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
  2061. alt_ioc_ready = 1;
  2062. else
  2063. printk(MYIOC_s_WARN_FMT
  2064. ": alt-ioc Not ready WARNING!\n",
  2065. ioc->alt_ioc->name);
  2066. }
  2067. for (ii=0; ii<5; ii++) {
  2068. /* Get IOC facts! Allow 5 retries */
  2069. if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
  2070. break;
  2071. }
  2072. if (ii == 5) {
  2073. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2074. "Retry IocFacts failed rc=%x\n", ioc->name, rc));
  2075. ret = -2;
  2076. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2077. MptDisplayIocCapabilities(ioc);
  2078. }
  2079. if (alt_ioc_ready) {
  2080. if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
  2081. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2082. "Initial Alt IocFacts failed rc=%x\n",
  2083. ioc->name, rc));
  2084. /* Retry - alt IOC was initialized once
  2085. */
  2086. rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
  2087. }
  2088. if (rc) {
  2089. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2090. "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
  2091. alt_ioc_ready = 0;
  2092. reset_alt_ioc_active = 0;
  2093. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2094. MptDisplayIocCapabilities(ioc->alt_ioc);
  2095. }
  2096. }
  2097. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP) &&
  2098. (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)) {
  2099. pci_release_selected_regions(ioc->pcidev, ioc->bars);
  2100. ioc->bars = pci_select_bars(ioc->pcidev, IORESOURCE_MEM |
  2101. IORESOURCE_IO);
  2102. if (pci_enable_device(ioc->pcidev))
  2103. return -5;
  2104. if (pci_request_selected_regions(ioc->pcidev, ioc->bars,
  2105. "mpt"))
  2106. return -5;
  2107. }
  2108. /*
  2109. * Device is reset now. It must have de-asserted the interrupt line
  2110. * (if it was asserted) and it should be safe to register for the
  2111. * interrupt now.
  2112. */
  2113. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
  2114. ioc->pci_irq = -1;
  2115. if (ioc->pcidev->irq) {
  2116. if (ioc->msi_enable && !pci_enable_msi(ioc->pcidev))
  2117. printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
  2118. ioc->name);
  2119. else
  2120. ioc->msi_enable = 0;
  2121. rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
  2122. IRQF_SHARED, ioc->name, ioc);
  2123. if (rc < 0) {
  2124. printk(MYIOC_s_ERR_FMT "Unable to allocate "
  2125. "interrupt %d!\n",
  2126. ioc->name, ioc->pcidev->irq);
  2127. if (ioc->msi_enable)
  2128. pci_disable_msi(ioc->pcidev);
  2129. ret = -EBUSY;
  2130. goto out;
  2131. }
  2132. irq_allocated = 1;
  2133. ioc->pci_irq = ioc->pcidev->irq;
  2134. pci_set_master(ioc->pcidev); /* ?? */
  2135. pci_set_drvdata(ioc->pcidev, ioc);
  2136. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  2137. "installed at interrupt %d\n", ioc->name,
  2138. ioc->pcidev->irq));
  2139. }
  2140. }
  2141. /* Prime reply & request queues!
  2142. * (mucho alloc's) Must be done prior to
  2143. * init as upper addresses are needed for init.
  2144. * If fails, continue with alt-ioc processing
  2145. */
  2146. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "PrimeIocFifos\n",
  2147. ioc->name));
  2148. if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
  2149. ret = -3;
  2150. /* May need to check/upload firmware & data here!
  2151. * If fails, continue with alt-ioc processing
  2152. */
  2153. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "SendIocInit\n",
  2154. ioc->name));
  2155. if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
  2156. ret = -4;
  2157. // NEW!
  2158. if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
  2159. printk(MYIOC_s_WARN_FMT
  2160. ": alt-ioc (%d) FIFO mgmt alloc WARNING!\n",
  2161. ioc->alt_ioc->name, rc);
  2162. alt_ioc_ready = 0;
  2163. reset_alt_ioc_active = 0;
  2164. }
  2165. if (alt_ioc_ready) {
  2166. if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
  2167. alt_ioc_ready = 0;
  2168. reset_alt_ioc_active = 0;
  2169. printk(MYIOC_s_WARN_FMT
  2170. ": alt-ioc: (%d) init failure WARNING!\n",
  2171. ioc->alt_ioc->name, rc);
  2172. }
  2173. }
  2174. if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
  2175. if (ioc->upload_fw) {
  2176. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2177. "firmware upload required!\n", ioc->name));
  2178. /* Controller is not operational, cannot do upload
  2179. */
  2180. if (ret == 0) {
  2181. rc = mpt_do_upload(ioc, sleepFlag);
  2182. if (rc == 0) {
  2183. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  2184. /*
  2185. * Maintain only one pointer to FW memory
  2186. * so there will not be two attempt to
  2187. * downloadboot onboard dual function
  2188. * chips (mpt_adapter_disable,
  2189. * mpt_diag_reset)
  2190. */
  2191. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2192. "mpt_upload: alt_%s has cached_fw=%p \n",
  2193. ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
  2194. ioc->cached_fw = NULL;
  2195. }
  2196. } else {
  2197. printk(MYIOC_s_WARN_FMT
  2198. "firmware upload failure!\n", ioc->name);
  2199. ret = -6;
  2200. }
  2201. }
  2202. }
  2203. }
  2204. /* Enable MPT base driver management of EventNotification
  2205. * and EventAck handling.
  2206. */
  2207. if ((ret == 0) && (!ioc->facts.EventState)) {
  2208. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  2209. "SendEventNotification\n",
  2210. ioc->name));
  2211. ret = SendEventNotification(ioc, 1, sleepFlag); /* 1=Enable */
  2212. }
  2213. if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
  2214. rc = SendEventNotification(ioc->alt_ioc, 1, sleepFlag);
  2215. if (ret == 0) {
  2216. /* Enable! (reply interrupt) */
  2217. CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
  2218. ioc->active = 1;
  2219. }
  2220. if (rc == 0) { /* alt ioc */
  2221. if (reset_alt_ioc_active && ioc->alt_ioc) {
  2222. /* (re)Enable alt-IOC! (reply interrupt) */
  2223. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "alt-ioc"
  2224. "reply irq re-enabled\n",
  2225. ioc->alt_ioc->name));
  2226. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
  2227. MPI_HIM_DIM);
  2228. ioc->alt_ioc->active = 1;
  2229. }
  2230. }
  2231. /* Add additional "reason" check before call to GetLanConfigPages
  2232. * (combined with GetIoUnitPage2 call). This prevents a somewhat
  2233. * recursive scenario; GetLanConfigPages times out, timer expired
  2234. * routine calls HardResetHandler, which calls into here again,
  2235. * and we try GetLanConfigPages again...
  2236. */
  2237. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
  2238. /*
  2239. * Initialize link list for inactive raid volumes.
  2240. */
  2241. mutex_init(&ioc->raid_data.inactive_list_mutex);
  2242. INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
  2243. switch (ioc->bus_type) {
  2244. case SAS:
  2245. /* clear persistency table */
  2246. if(ioc->facts.IOCExceptions &
  2247. MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
  2248. ret = mptbase_sas_persist_operation(ioc,
  2249. MPI_SAS_OP_CLEAR_NOT_PRESENT);
  2250. if(ret != 0)
  2251. goto out;
  2252. }
  2253. /* Find IM volumes
  2254. */
  2255. mpt_findImVolumes(ioc);
  2256. /* Check, and possibly reset, the coalescing value
  2257. */
  2258. mpt_read_ioc_pg_1(ioc);
  2259. break;
  2260. case FC:
  2261. if ((ioc->pfacts[0].ProtocolFlags &
  2262. MPI_PORTFACTS_PROTOCOL_LAN) &&
  2263. (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
  2264. /*
  2265. * Pre-fetch the ports LAN MAC address!
  2266. * (LANPage1_t stuff)
  2267. */
  2268. (void) GetLanConfigPages(ioc);
  2269. a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  2270. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2271. "LanAddr = %02X:%02X:%02X"
  2272. ":%02X:%02X:%02X\n",
  2273. ioc->name, a[5], a[4],
  2274. a[3], a[2], a[1], a[0]));
  2275. }
  2276. break;
  2277. case SPI:
  2278. /* Get NVRAM and adapter maximums from SPP 0 and 2
  2279. */
  2280. mpt_GetScsiPortSettings(ioc, 0);
  2281. /* Get version and length of SDP 1
  2282. */
  2283. mpt_readScsiDevicePageHeaders(ioc, 0);
  2284. /* Find IM volumes
  2285. */
  2286. if (ioc->facts.MsgVersion >= MPI_VERSION_01_02)
  2287. mpt_findImVolumes(ioc);
  2288. /* Check, and possibly reset, the coalescing value
  2289. */
  2290. mpt_read_ioc_pg_1(ioc);
  2291. mpt_read_ioc_pg_4(ioc);
  2292. break;
  2293. }
  2294. GetIoUnitPage2(ioc);
  2295. mpt_get_manufacturing_pg_0(ioc);
  2296. }
  2297. out:
  2298. if ((ret != 0) && irq_allocated) {
  2299. free_irq(ioc->pci_irq, ioc);
  2300. if (ioc->msi_enable)
  2301. pci_disable_msi(ioc->pcidev);
  2302. }
  2303. return ret;
  2304. }
  2305. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2306. /**
  2307. * mpt_detect_bound_ports - Search for matching PCI bus/dev_function
  2308. * @ioc: Pointer to MPT adapter structure
  2309. * @pdev: Pointer to (struct pci_dev) structure
  2310. *
  2311. * Search for PCI bus/dev_function which matches
  2312. * PCI bus/dev_function (+/-1) for newly discovered 929,
  2313. * 929X, 1030 or 1035.
  2314. *
  2315. * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
  2316. * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
  2317. */
  2318. static void
  2319. mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
  2320. {
  2321. struct pci_dev *peer=NULL;
  2322. unsigned int slot = PCI_SLOT(pdev->devfn);
  2323. unsigned int func = PCI_FUNC(pdev->devfn);
  2324. MPT_ADAPTER *ioc_srch;
  2325. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PCI device %s devfn=%x/%x,"
  2326. " searching for devfn match on %x or %x\n",
  2327. ioc->name, pci_name(pdev), pdev->bus->number,
  2328. pdev->devfn, func-1, func+1));
  2329. peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
  2330. if (!peer) {
  2331. peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
  2332. if (!peer)
  2333. return;
  2334. }
  2335. list_for_each_entry(ioc_srch, &ioc_list, list) {
  2336. struct pci_dev *_pcidev = ioc_srch->pcidev;
  2337. if (_pcidev == peer) {
  2338. /* Paranoia checks */
  2339. if (ioc->alt_ioc != NULL) {
  2340. printk(MYIOC_s_WARN_FMT
  2341. "Oops, already bound (%s <==> %s)!\n",
  2342. ioc->name, ioc->name, ioc->alt_ioc->name);
  2343. break;
  2344. } else if (ioc_srch->alt_ioc != NULL) {
  2345. printk(MYIOC_s_WARN_FMT
  2346. "Oops, already bound (%s <==> %s)!\n",
  2347. ioc_srch->name, ioc_srch->name,
  2348. ioc_srch->alt_ioc->name);
  2349. break;
  2350. }
  2351. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2352. "FOUND! binding %s <==> %s\n",
  2353. ioc->name, ioc->name, ioc_srch->name));
  2354. ioc_srch->alt_ioc = ioc;
  2355. ioc->alt_ioc = ioc_srch;
  2356. }
  2357. }
  2358. pci_dev_put(peer);
  2359. }
  2360. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2361. /**
  2362. * mpt_adapter_disable - Disable misbehaving MPT adapter.
  2363. * @ioc: Pointer to MPT adapter structure
  2364. */
  2365. static void
  2366. mpt_adapter_disable(MPT_ADAPTER *ioc)
  2367. {
  2368. int sz;
  2369. int ret;
  2370. if (ioc->cached_fw != NULL) {
  2371. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2372. "%s: Pushing FW onto adapter\n", __func__, ioc->name));
  2373. if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)
  2374. ioc->cached_fw, CAN_SLEEP)) < 0) {
  2375. printk(MYIOC_s_WARN_FMT
  2376. ": firmware downloadboot failure (%d)!\n",
  2377. ioc->name, ret);
  2378. }
  2379. }
  2380. /*
  2381. * Put the controller into ready state (if its not already)
  2382. */
  2383. if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY) {
  2384. if (!SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET,
  2385. CAN_SLEEP)) {
  2386. if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY)
  2387. printk(MYIOC_s_ERR_FMT "%s: IOC msg unit "
  2388. "reset failed to put ioc in ready state!\n",
  2389. ioc->name, __func__);
  2390. } else
  2391. printk(MYIOC_s_ERR_FMT "%s: IOC msg unit reset "
  2392. "failed!\n", ioc->name, __func__);
  2393. }
  2394. /* Disable adapter interrupts! */
  2395. synchronize_irq(ioc->pcidev->irq);
  2396. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  2397. ioc->active = 0;
  2398. /* Clear any lingering interrupt */
  2399. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  2400. CHIPREG_READ32(&ioc->chip->IntStatus);
  2401. if (ioc->alloc != NULL) {
  2402. sz = ioc->alloc_sz;
  2403. dexitprintk(ioc, printk(MYIOC_s_INFO_FMT "free @ %p, sz=%d bytes\n",
  2404. ioc->name, ioc->alloc, ioc->alloc_sz));
  2405. pci_free_consistent(ioc->pcidev, sz,
  2406. ioc->alloc, ioc->alloc_dma);
  2407. ioc->reply_frames = NULL;
  2408. ioc->req_frames = NULL;
  2409. ioc->alloc = NULL;
  2410. ioc->alloc_total -= sz;
  2411. }
  2412. if (ioc->sense_buf_pool != NULL) {
  2413. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  2414. pci_free_consistent(ioc->pcidev, sz,
  2415. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  2416. ioc->sense_buf_pool = NULL;
  2417. ioc->alloc_total -= sz;
  2418. }
  2419. if (ioc->events != NULL){
  2420. sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
  2421. kfree(ioc->events);
  2422. ioc->events = NULL;
  2423. ioc->alloc_total -= sz;
  2424. }
  2425. mpt_free_fw_memory(ioc);
  2426. kfree(ioc->spi_data.nvram);
  2427. mpt_inactive_raid_list_free(ioc);
  2428. kfree(ioc->raid_data.pIocPg2);
  2429. kfree(ioc->raid_data.pIocPg3);
  2430. ioc->spi_data.nvram = NULL;
  2431. ioc->raid_data.pIocPg3 = NULL;
  2432. if (ioc->spi_data.pIocPg4 != NULL) {
  2433. sz = ioc->spi_data.IocPg4Sz;
  2434. pci_free_consistent(ioc->pcidev, sz,
  2435. ioc->spi_data.pIocPg4,
  2436. ioc->spi_data.IocPg4_dma);
  2437. ioc->spi_data.pIocPg4 = NULL;
  2438. ioc->alloc_total -= sz;
  2439. }
  2440. if (ioc->ReqToChain != NULL) {
  2441. kfree(ioc->ReqToChain);
  2442. kfree(ioc->RequestNB);
  2443. ioc->ReqToChain = NULL;
  2444. }
  2445. kfree(ioc->ChainToChain);
  2446. ioc->ChainToChain = NULL;
  2447. if (ioc->HostPageBuffer != NULL) {
  2448. if((ret = mpt_host_page_access_control(ioc,
  2449. MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
  2450. printk(MYIOC_s_ERR_FMT
  2451. ": %s: host page buffers free failed (%d)!\n",
  2452. ioc->name, __func__, ret);
  2453. }
  2454. dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2455. "HostPageBuffer free @ %p, sz=%d bytes\n",
  2456. ioc->name, ioc->HostPageBuffer,
  2457. ioc->HostPageBuffer_sz));
  2458. pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
  2459. ioc->HostPageBuffer, ioc->HostPageBuffer_dma);
  2460. ioc->HostPageBuffer = NULL;
  2461. ioc->HostPageBuffer_sz = 0;
  2462. ioc->alloc_total -= ioc->HostPageBuffer_sz;
  2463. }
  2464. pci_set_drvdata(ioc->pcidev, NULL);
  2465. }
  2466. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2467. /**
  2468. * mpt_adapter_dispose - Free all resources associated with an MPT adapter
  2469. * @ioc: Pointer to MPT adapter structure
  2470. *
  2471. * This routine unregisters h/w resources and frees all alloc'd memory
  2472. * associated with a MPT adapter structure.
  2473. */
  2474. static void
  2475. mpt_adapter_dispose(MPT_ADAPTER *ioc)
  2476. {
  2477. int sz_first, sz_last;
  2478. if (ioc == NULL)
  2479. return;
  2480. sz_first = ioc->alloc_total;
  2481. mpt_adapter_disable(ioc);
  2482. if (ioc->pci_irq != -1) {
  2483. free_irq(ioc->pci_irq, ioc);
  2484. if (ioc->msi_enable)
  2485. pci_disable_msi(ioc->pcidev);
  2486. ioc->pci_irq = -1;
  2487. }
  2488. if (ioc->memmap != NULL) {
  2489. iounmap(ioc->memmap);
  2490. ioc->memmap = NULL;
  2491. }
  2492. pci_disable_device(ioc->pcidev);
  2493. pci_release_selected_regions(ioc->pcidev, ioc->bars);
  2494. #if defined(CONFIG_MTRR) && 0
  2495. if (ioc->mtrr_reg > 0) {
  2496. mtrr_del(ioc->mtrr_reg, 0, 0);
  2497. dprintk(ioc, printk(MYIOC_s_INFO_FMT "MTRR region de-registered\n", ioc->name));
  2498. }
  2499. #endif
  2500. /* Zap the adapter lookup ptr! */
  2501. list_del(&ioc->list);
  2502. sz_last = ioc->alloc_total;
  2503. dprintk(ioc, printk(MYIOC_s_INFO_FMT "free'd %d of %d bytes\n",
  2504. ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
  2505. if (ioc->alt_ioc)
  2506. ioc->alt_ioc->alt_ioc = NULL;
  2507. kfree(ioc);
  2508. }
  2509. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2510. /**
  2511. * MptDisplayIocCapabilities - Disply IOC's capabilities.
  2512. * @ioc: Pointer to MPT adapter structure
  2513. */
  2514. static void
  2515. MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
  2516. {
  2517. int i = 0;
  2518. printk(KERN_INFO "%s: ", ioc->name);
  2519. if (ioc->prod_name)
  2520. printk("%s: ", ioc->prod_name);
  2521. printk("Capabilities={");
  2522. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
  2523. printk("Initiator");
  2524. i++;
  2525. }
  2526. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  2527. printk("%sTarget", i ? "," : "");
  2528. i++;
  2529. }
  2530. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  2531. printk("%sLAN", i ? "," : "");
  2532. i++;
  2533. }
  2534. #if 0
  2535. /*
  2536. * This would probably evoke more questions than it's worth
  2537. */
  2538. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  2539. printk("%sLogBusAddr", i ? "," : "");
  2540. i++;
  2541. }
  2542. #endif
  2543. printk("}\n");
  2544. }
  2545. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2546. /**
  2547. * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
  2548. * @ioc: Pointer to MPT_ADAPTER structure
  2549. * @force: Force hard KickStart of IOC
  2550. * @sleepFlag: Specifies whether the process can sleep
  2551. *
  2552. * Returns:
  2553. * 1 - DIAG reset and READY
  2554. * 0 - READY initially OR soft reset and READY
  2555. * -1 - Any failure on KickStart
  2556. * -2 - Msg Unit Reset Failed
  2557. * -3 - IO Unit Reset Failed
  2558. * -4 - IOC owned by a PEER
  2559. */
  2560. static int
  2561. MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
  2562. {
  2563. u32 ioc_state;
  2564. int statefault = 0;
  2565. int cntdn;
  2566. int hard_reset_done = 0;
  2567. int r;
  2568. int ii;
  2569. int whoinit;
  2570. /* Get current [raw] IOC state */
  2571. ioc_state = mpt_GetIocState(ioc, 0);
  2572. dhsprintk(ioc, printk(MYIOC_s_INFO_FMT "MakeIocReady [raw] state=%08x\n", ioc->name, ioc_state));
  2573. /*
  2574. * Check to see if IOC got left/stuck in doorbell handshake
  2575. * grip of death. If so, hard reset the IOC.
  2576. */
  2577. if (ioc_state & MPI_DOORBELL_ACTIVE) {
  2578. statefault = 1;
  2579. printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
  2580. ioc->name);
  2581. }
  2582. /* Is it already READY? */
  2583. if (!statefault &&
  2584. ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)) {
  2585. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  2586. "IOC is in READY state\n", ioc->name));
  2587. return 0;
  2588. }
  2589. /*
  2590. * Check to see if IOC is in FAULT state.
  2591. */
  2592. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
  2593. statefault = 2;
  2594. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
  2595. ioc->name);
  2596. printk(MYIOC_s_WARN_FMT " FAULT code = %04xh\n",
  2597. ioc->name, ioc_state & MPI_DOORBELL_DATA_MASK);
  2598. }
  2599. /*
  2600. * Hmmm... Did it get left operational?
  2601. */
  2602. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
  2603. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOC operational unexpected\n",
  2604. ioc->name));
  2605. /* Check WhoInit.
  2606. * If PCI Peer, exit.
  2607. * Else, if no fault conditions are present, issue a MessageUnitReset
  2608. * Else, fall through to KickStart case
  2609. */
  2610. whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
  2611. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  2612. "whoinit 0x%x statefault %d force %d\n",
  2613. ioc->name, whoinit, statefault, force));
  2614. if (whoinit == MPI_WHOINIT_PCI_PEER)
  2615. return -4;
  2616. else {
  2617. if ((statefault == 0 ) && (force == 0)) {
  2618. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
  2619. return 0;
  2620. }
  2621. statefault = 3;
  2622. }
  2623. }
  2624. hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
  2625. if (hard_reset_done < 0)
  2626. return -1;
  2627. /*
  2628. * Loop here waiting for IOC to come READY.
  2629. */
  2630. ii = 0;
  2631. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 5; /* 5 seconds */
  2632. while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  2633. if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
  2634. /*
  2635. * BIOS or previous driver load left IOC in OP state.
  2636. * Reset messaging FIFOs.
  2637. */
  2638. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
  2639. printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
  2640. return -2;
  2641. }
  2642. } else if (ioc_state == MPI_IOC_STATE_RESET) {
  2643. /*
  2644. * Something is wrong. Try to get IOC back
  2645. * to a known state.
  2646. */
  2647. if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
  2648. printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
  2649. return -3;
  2650. }
  2651. }
  2652. ii++; cntdn--;
  2653. if (!cntdn) {
  2654. printk(MYIOC_s_ERR_FMT
  2655. "Wait IOC_READY state (0x%x) timeout(%d)!\n",
  2656. ioc->name, ioc_state, (int)((ii+5)/HZ));
  2657. return -ETIME;
  2658. }
  2659. if (sleepFlag == CAN_SLEEP) {
  2660. msleep(1);
  2661. } else {
  2662. mdelay (1); /* 1 msec delay */
  2663. }
  2664. }
  2665. if (statefault < 3) {
  2666. printk(MYIOC_s_INFO_FMT "Recovered from %s\n", ioc->name,
  2667. statefault == 1 ? "stuck handshake" : "IOC FAULT");
  2668. }
  2669. return hard_reset_done;
  2670. }
  2671. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2672. /**
  2673. * mpt_GetIocState - Get the current state of a MPT adapter.
  2674. * @ioc: Pointer to MPT_ADAPTER structure
  2675. * @cooked: Request raw or cooked IOC state
  2676. *
  2677. * Returns all IOC Doorbell register bits if cooked==0, else just the
  2678. * Doorbell bits in MPI_IOC_STATE_MASK.
  2679. */
  2680. u32
  2681. mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
  2682. {
  2683. u32 s, sc;
  2684. /* Get! */
  2685. s = CHIPREG_READ32(&ioc->chip->Doorbell);
  2686. sc = s & MPI_IOC_STATE_MASK;
  2687. /* Save! */
  2688. ioc->last_state = sc;
  2689. return cooked ? sc : s;
  2690. }
  2691. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2692. /**
  2693. * GetIocFacts - Send IOCFacts request to MPT adapter.
  2694. * @ioc: Pointer to MPT_ADAPTER structure
  2695. * @sleepFlag: Specifies whether the process can sleep
  2696. * @reason: If recovery, only update facts.
  2697. *
  2698. * Returns 0 for success, non-zero for failure.
  2699. */
  2700. static int
  2701. GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
  2702. {
  2703. IOCFacts_t get_facts;
  2704. IOCFactsReply_t *facts;
  2705. int r;
  2706. int req_sz;
  2707. int reply_sz;
  2708. int sz;
  2709. u32 status, vv;
  2710. u8 shiftFactor=1;
  2711. /* IOC *must* NOT be in RESET state! */
  2712. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2713. printk(KERN_ERR MYNAM
  2714. ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
  2715. ioc->name, ioc->last_state);
  2716. return -44;
  2717. }
  2718. facts = &ioc->facts;
  2719. /* Destination (reply area)... */
  2720. reply_sz = sizeof(*facts);
  2721. memset(facts, 0, reply_sz);
  2722. /* Request area (get_facts on the stack right now!) */
  2723. req_sz = sizeof(get_facts);
  2724. memset(&get_facts, 0, req_sz);
  2725. get_facts.Function = MPI_FUNCTION_IOC_FACTS;
  2726. /* Assert: All other get_facts fields are zero! */
  2727. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2728. "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
  2729. ioc->name, req_sz, reply_sz));
  2730. /* No non-zero fields in the get_facts request are greater than
  2731. * 1 byte in size, so we can just fire it off as is.
  2732. */
  2733. r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
  2734. reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
  2735. if (r != 0)
  2736. return r;
  2737. /*
  2738. * Now byte swap (GRRR) the necessary fields before any further
  2739. * inspection of reply contents.
  2740. *
  2741. * But need to do some sanity checks on MsgLength (byte) field
  2742. * to make sure we don't zero IOC's req_sz!
  2743. */
  2744. /* Did we get a valid reply? */
  2745. if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
  2746. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2747. /*
  2748. * If not been here, done that, save off first WhoInit value
  2749. */
  2750. if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
  2751. ioc->FirstWhoInit = facts->WhoInit;
  2752. }
  2753. facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
  2754. facts->MsgContext = le32_to_cpu(facts->MsgContext);
  2755. facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
  2756. facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
  2757. facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
  2758. status = le16_to_cpu(facts->IOCStatus) & MPI_IOCSTATUS_MASK;
  2759. /* CHECKME! IOCStatus, IOCLogInfo */
  2760. facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
  2761. facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
  2762. /*
  2763. * FC f/w version changed between 1.1 and 1.2
  2764. * Old: u16{Major(4),Minor(4),SubMinor(8)}
  2765. * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
  2766. */
  2767. if (facts->MsgVersion < MPI_VERSION_01_02) {
  2768. /*
  2769. * Handle old FC f/w style, convert to new...
  2770. */
  2771. u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
  2772. facts->FWVersion.Word =
  2773. ((oldv<<12) & 0xFF000000) |
  2774. ((oldv<<8) & 0x000FFF00);
  2775. } else
  2776. facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
  2777. facts->ProductID = le16_to_cpu(facts->ProductID);
  2778. if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
  2779. > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
  2780. ioc->ir_firmware = 1;
  2781. facts->CurrentHostMfaHighAddr =
  2782. le32_to_cpu(facts->CurrentHostMfaHighAddr);
  2783. facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
  2784. facts->CurrentSenseBufferHighAddr =
  2785. le32_to_cpu(facts->CurrentSenseBufferHighAddr);
  2786. facts->CurReplyFrameSize =
  2787. le16_to_cpu(facts->CurReplyFrameSize);
  2788. facts->IOCCapabilities = le32_to_cpu(facts->IOCCapabilities);
  2789. /*
  2790. * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
  2791. * Older MPI-1.00.xx struct had 13 dwords, and enlarged
  2792. * to 14 in MPI-1.01.0x.
  2793. */
  2794. if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
  2795. facts->MsgVersion > MPI_VERSION_01_00) {
  2796. facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
  2797. }
  2798. sz = facts->FWImageSize;
  2799. if ( sz & 0x01 )
  2800. sz += 1;
  2801. if ( sz & 0x02 )
  2802. sz += 2;
  2803. facts->FWImageSize = sz;
  2804. if (!facts->RequestFrameSize) {
  2805. /* Something is wrong! */
  2806. printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
  2807. ioc->name);
  2808. return -55;
  2809. }
  2810. r = sz = facts->BlockSize;
  2811. vv = ((63 / (sz * 4)) + 1) & 0x03;
  2812. ioc->NB_for_64_byte_frame = vv;
  2813. while ( sz )
  2814. {
  2815. shiftFactor++;
  2816. sz = sz >> 1;
  2817. }
  2818. ioc->NBShiftFactor = shiftFactor;
  2819. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2820. "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
  2821. ioc->name, vv, shiftFactor, r));
  2822. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2823. /*
  2824. * Set values for this IOC's request & reply frame sizes,
  2825. * and request & reply queue depths...
  2826. */
  2827. ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
  2828. ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
  2829. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  2830. ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
  2831. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "reply_sz=%3d, reply_depth=%4d\n",
  2832. ioc->name, ioc->reply_sz, ioc->reply_depth));
  2833. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "req_sz =%3d, req_depth =%4d\n",
  2834. ioc->name, ioc->req_sz, ioc->req_depth));
  2835. /* Get port facts! */
  2836. if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
  2837. return r;
  2838. }
  2839. } else {
  2840. printk(MYIOC_s_ERR_FMT
  2841. "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
  2842. ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
  2843. RequestFrameSize)/sizeof(u32)));
  2844. return -66;
  2845. }
  2846. return 0;
  2847. }
  2848. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2849. /**
  2850. * GetPortFacts - Send PortFacts request to MPT adapter.
  2851. * @ioc: Pointer to MPT_ADAPTER structure
  2852. * @portnum: Port number
  2853. * @sleepFlag: Specifies whether the process can sleep
  2854. *
  2855. * Returns 0 for success, non-zero for failure.
  2856. */
  2857. static int
  2858. GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2859. {
  2860. PortFacts_t get_pfacts;
  2861. PortFactsReply_t *pfacts;
  2862. int ii;
  2863. int req_sz;
  2864. int reply_sz;
  2865. int max_id;
  2866. /* IOC *must* NOT be in RESET state! */
  2867. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2868. printk(MYIOC_s_ERR_FMT "Can't get PortFacts NOT READY! (%08x)\n",
  2869. ioc->name, ioc->last_state );
  2870. return -4;
  2871. }
  2872. pfacts = &ioc->pfacts[portnum];
  2873. /* Destination (reply area)... */
  2874. reply_sz = sizeof(*pfacts);
  2875. memset(pfacts, 0, reply_sz);
  2876. /* Request area (get_pfacts on the stack right now!) */
  2877. req_sz = sizeof(get_pfacts);
  2878. memset(&get_pfacts, 0, req_sz);
  2879. get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
  2880. get_pfacts.PortNumber = portnum;
  2881. /* Assert: All other get_pfacts fields are zero! */
  2882. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending get PortFacts(%d) request\n",
  2883. ioc->name, portnum));
  2884. /* No non-zero fields in the get_pfacts request are greater than
  2885. * 1 byte in size, so we can just fire it off as is.
  2886. */
  2887. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
  2888. reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
  2889. if (ii != 0)
  2890. return ii;
  2891. /* Did we get a valid reply? */
  2892. /* Now byte swap the necessary fields in the response. */
  2893. pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
  2894. pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
  2895. pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
  2896. pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
  2897. pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
  2898. pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
  2899. pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
  2900. pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
  2901. pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
  2902. max_id = (ioc->bus_type == SAS) ? pfacts->PortSCSIID :
  2903. pfacts->MaxDevices;
  2904. ioc->devices_per_bus = (max_id > 255) ? 256 : max_id;
  2905. ioc->number_of_buses = (ioc->devices_per_bus < 256) ? 1 : max_id/256;
  2906. /*
  2907. * Place all the devices on channels
  2908. *
  2909. * (for debuging)
  2910. */
  2911. if (mpt_channel_mapping) {
  2912. ioc->devices_per_bus = 1;
  2913. ioc->number_of_buses = (max_id > 255) ? 255 : max_id;
  2914. }
  2915. return 0;
  2916. }
  2917. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2918. /**
  2919. * SendIocInit - Send IOCInit request to MPT adapter.
  2920. * @ioc: Pointer to MPT_ADAPTER structure
  2921. * @sleepFlag: Specifies whether the process can sleep
  2922. *
  2923. * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
  2924. *
  2925. * Returns 0 for success, non-zero for failure.
  2926. */
  2927. static int
  2928. SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
  2929. {
  2930. IOCInit_t ioc_init;
  2931. MPIDefaultReply_t init_reply;
  2932. u32 state;
  2933. int r;
  2934. int count;
  2935. int cntdn;
  2936. memset(&ioc_init, 0, sizeof(ioc_init));
  2937. memset(&init_reply, 0, sizeof(init_reply));
  2938. ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
  2939. ioc_init.Function = MPI_FUNCTION_IOC_INIT;
  2940. /* If we are in a recovery mode and we uploaded the FW image,
  2941. * then this pointer is not NULL. Skip the upload a second time.
  2942. * Set this flag if cached_fw set for either IOC.
  2943. */
  2944. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  2945. ioc->upload_fw = 1;
  2946. else
  2947. ioc->upload_fw = 0;
  2948. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "upload_fw %d facts.Flags=%x\n",
  2949. ioc->name, ioc->upload_fw, ioc->facts.Flags));
  2950. ioc_init.MaxDevices = (U8)ioc->devices_per_bus;
  2951. ioc_init.MaxBuses = (U8)ioc->number_of_buses;
  2952. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts.MsgVersion=%x\n",
  2953. ioc->name, ioc->facts.MsgVersion));
  2954. if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
  2955. // set MsgVersion and HeaderVersion host driver was built with
  2956. ioc_init.MsgVersion = cpu_to_le16(MPI_VERSION);
  2957. ioc_init.HeaderVersion = cpu_to_le16(MPI_HEADER_VERSION);
  2958. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_HOST_PAGE_BUFFER_PERSISTENT) {
  2959. ioc_init.HostPageBufferSGE = ioc->facts.HostPageBufferSGE;
  2960. } else if(mpt_host_page_alloc(ioc, &ioc_init))
  2961. return -99;
  2962. }
  2963. ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
  2964. if (ioc->sg_addr_size == sizeof(u64)) {
  2965. /* Save the upper 32-bits of the request
  2966. * (reply) and sense buffers.
  2967. */
  2968. ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
  2969. ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
  2970. } else {
  2971. /* Force 32-bit addressing */
  2972. ioc_init.HostMfaHighAddr = cpu_to_le32(0);
  2973. ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
  2974. }
  2975. ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
  2976. ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
  2977. ioc->facts.MaxDevices = ioc_init.MaxDevices;
  2978. ioc->facts.MaxBuses = ioc_init.MaxBuses;
  2979. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending IOCInit (req @ %p)\n",
  2980. ioc->name, &ioc_init));
  2981. r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
  2982. sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
  2983. if (r != 0) {
  2984. printk(MYIOC_s_ERR_FMT "Sending IOCInit failed(%d)!\n",ioc->name, r);
  2985. return r;
  2986. }
  2987. /* No need to byte swap the multibyte fields in the reply
  2988. * since we don't even look at its contents.
  2989. */
  2990. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending PortEnable (req @ %p)\n",
  2991. ioc->name, &ioc_init));
  2992. if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) {
  2993. printk(MYIOC_s_ERR_FMT "Sending PortEnable failed(%d)!\n",ioc->name, r);
  2994. return r;
  2995. }
  2996. /* YIKES! SUPER IMPORTANT!!!
  2997. * Poll IocState until _OPERATIONAL while IOC is doing
  2998. * LoopInit and TargetDiscovery!
  2999. */
  3000. count = 0;
  3001. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
  3002. state = mpt_GetIocState(ioc, 1);
  3003. while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
  3004. if (sleepFlag == CAN_SLEEP) {
  3005. msleep(1);
  3006. } else {
  3007. mdelay(1);
  3008. }
  3009. if (!cntdn) {
  3010. printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
  3011. ioc->name, (int)((count+5)/HZ));
  3012. return -9;
  3013. }
  3014. state = mpt_GetIocState(ioc, 1);
  3015. count++;
  3016. }
  3017. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wait IOC_OPERATIONAL state (cnt=%d)\n",
  3018. ioc->name, count));
  3019. ioc->aen_event_read_flag=0;
  3020. return r;
  3021. }
  3022. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3023. /**
  3024. * SendPortEnable - Send PortEnable request to MPT adapter port.
  3025. * @ioc: Pointer to MPT_ADAPTER structure
  3026. * @portnum: Port number to enable
  3027. * @sleepFlag: Specifies whether the process can sleep
  3028. *
  3029. * Send PortEnable to bring IOC to OPERATIONAL state.
  3030. *
  3031. * Returns 0 for success, non-zero for failure.
  3032. */
  3033. static int
  3034. SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  3035. {
  3036. PortEnable_t port_enable;
  3037. MPIDefaultReply_t reply_buf;
  3038. int rc;
  3039. int req_sz;
  3040. int reply_sz;
  3041. /* Destination... */
  3042. reply_sz = sizeof(MPIDefaultReply_t);
  3043. memset(&reply_buf, 0, reply_sz);
  3044. req_sz = sizeof(PortEnable_t);
  3045. memset(&port_enable, 0, req_sz);
  3046. port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
  3047. port_enable.PortNumber = portnum;
  3048. /* port_enable.ChainOffset = 0; */
  3049. /* port_enable.MsgFlags = 0; */
  3050. /* port_enable.MsgContext = 0; */
  3051. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Port(%d)Enable (req @ %p)\n",
  3052. ioc->name, portnum, &port_enable));
  3053. /* RAID FW may take a long time to enable
  3054. */
  3055. if (ioc->ir_firmware || ioc->bus_type == SAS) {
  3056. rc = mpt_handshake_req_reply_wait(ioc, req_sz,
  3057. (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
  3058. 300 /*seconds*/, sleepFlag);
  3059. } else {
  3060. rc = mpt_handshake_req_reply_wait(ioc, req_sz,
  3061. (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
  3062. 30 /*seconds*/, sleepFlag);
  3063. }
  3064. return rc;
  3065. }
  3066. /**
  3067. * mpt_alloc_fw_memory - allocate firmware memory
  3068. * @ioc: Pointer to MPT_ADAPTER structure
  3069. * @size: total FW bytes
  3070. *
  3071. * If memory has already been allocated, the same (cached) value
  3072. * is returned.
  3073. *
  3074. * Return 0 if successful, or non-zero for failure
  3075. **/
  3076. int
  3077. mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
  3078. {
  3079. int rc;
  3080. if (ioc->cached_fw) {
  3081. rc = 0; /* use already allocated memory */
  3082. goto out;
  3083. }
  3084. else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  3085. ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
  3086. ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
  3087. rc = 0;
  3088. goto out;
  3089. }
  3090. ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma);
  3091. if (!ioc->cached_fw) {
  3092. printk(MYIOC_s_ERR_FMT "Unable to allocate memory for the cached firmware image!\n",
  3093. ioc->name);
  3094. rc = -1;
  3095. } else {
  3096. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Image @ %p[%p], sz=%d[%x] bytes\n",
  3097. ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, size, size));
  3098. ioc->alloc_total += size;
  3099. rc = 0;
  3100. }
  3101. out:
  3102. return rc;
  3103. }
  3104. /**
  3105. * mpt_free_fw_memory - free firmware memory
  3106. * @ioc: Pointer to MPT_ADAPTER structure
  3107. *
  3108. * If alt_img is NULL, delete from ioc structure.
  3109. * Else, delete a secondary image in same format.
  3110. **/
  3111. void
  3112. mpt_free_fw_memory(MPT_ADAPTER *ioc)
  3113. {
  3114. int sz;
  3115. if (!ioc->cached_fw)
  3116. return;
  3117. sz = ioc->facts.FWImageSize;
  3118. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
  3119. ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  3120. pci_free_consistent(ioc->pcidev, sz, ioc->cached_fw, ioc->cached_fw_dma);
  3121. ioc->alloc_total -= sz;
  3122. ioc->cached_fw = NULL;
  3123. }
  3124. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3125. /**
  3126. * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
  3127. * @ioc: Pointer to MPT_ADAPTER structure
  3128. * @sleepFlag: Specifies whether the process can sleep
  3129. *
  3130. * Returns 0 for success, >0 for handshake failure
  3131. * <0 for fw upload failure.
  3132. *
  3133. * Remark: If bound IOC and a successful FWUpload was performed
  3134. * on the bound IOC, the second image is discarded
  3135. * and memory is free'd. Both channels must upload to prevent
  3136. * IOC from running in degraded mode.
  3137. */
  3138. static int
  3139. mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
  3140. {
  3141. u8 reply[sizeof(FWUploadReply_t)];
  3142. FWUpload_t *prequest;
  3143. FWUploadReply_t *preply;
  3144. FWUploadTCSGE_t *ptcsge;
  3145. u32 flagsLength;
  3146. int ii, sz, reply_sz;
  3147. int cmdStatus;
  3148. int request_size;
  3149. /* If the image size is 0, we are done.
  3150. */
  3151. if ((sz = ioc->facts.FWImageSize) == 0)
  3152. return 0;
  3153. if (mpt_alloc_fw_memory(ioc, ioc->facts.FWImageSize) != 0)
  3154. return -ENOMEM;
  3155. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
  3156. ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  3157. prequest = (sleepFlag == NO_SLEEP) ? kzalloc(ioc->req_sz, GFP_ATOMIC) :
  3158. kzalloc(ioc->req_sz, GFP_KERNEL);
  3159. if (!prequest) {
  3160. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed "
  3161. "while allocating memory \n", ioc->name));
  3162. mpt_free_fw_memory(ioc);
  3163. return -ENOMEM;
  3164. }
  3165. preply = (FWUploadReply_t *)&reply;
  3166. reply_sz = sizeof(reply);
  3167. memset(preply, 0, reply_sz);
  3168. prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
  3169. prequest->Function = MPI_FUNCTION_FW_UPLOAD;
  3170. ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
  3171. ptcsge->DetailsLength = 12;
  3172. ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
  3173. ptcsge->ImageSize = cpu_to_le32(sz);
  3174. ptcsge++;
  3175. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
  3176. ioc->add_sge((char *)ptcsge, flagsLength, ioc->cached_fw_dma);
  3177. request_size = offsetof(FWUpload_t, SGL) + sizeof(FWUploadTCSGE_t) +
  3178. ioc->SGE_size;
  3179. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending FW Upload "
  3180. " (req @ %p) fw_size=%d mf_request_size=%d\n", ioc->name, prequest,
  3181. ioc->facts.FWImageSize, request_size));
  3182. DBG_DUMP_FW_REQUEST_FRAME(ioc, (u32 *)prequest);
  3183. ii = mpt_handshake_req_reply_wait(ioc, request_size, (u32 *)prequest,
  3184. reply_sz, (u16 *)preply, 65 /*seconds*/, sleepFlag);
  3185. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Upload completed "
  3186. "rc=%x \n", ioc->name, ii));
  3187. cmdStatus = -EFAULT;
  3188. if (ii == 0) {
  3189. /* Handshake transfer was complete and successful.
  3190. * Check the Reply Frame.
  3191. */
  3192. int status;
  3193. status = le16_to_cpu(preply->IOCStatus) &
  3194. MPI_IOCSTATUS_MASK;
  3195. if (status == MPI_IOCSTATUS_SUCCESS &&
  3196. ioc->facts.FWImageSize ==
  3197. le32_to_cpu(preply->ActualImageSize))
  3198. cmdStatus = 0;
  3199. }
  3200. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": do_upload cmdStatus=%d \n",
  3201. ioc->name, cmdStatus));
  3202. if (cmdStatus) {
  3203. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed, "
  3204. "freeing image \n", ioc->name));
  3205. mpt_free_fw_memory(ioc);
  3206. }
  3207. kfree(prequest);
  3208. return cmdStatus;
  3209. }
  3210. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3211. /**
  3212. * mpt_downloadboot - DownloadBoot code
  3213. * @ioc: Pointer to MPT_ADAPTER structure
  3214. * @pFwHeader: Pointer to firmware header info
  3215. * @sleepFlag: Specifies whether the process can sleep
  3216. *
  3217. * FwDownloadBoot requires Programmed IO access.
  3218. *
  3219. * Returns 0 for success
  3220. * -1 FW Image size is 0
  3221. * -2 No valid cached_fw Pointer
  3222. * <0 for fw upload failure.
  3223. */
  3224. static int
  3225. mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
  3226. {
  3227. MpiExtImageHeader_t *pExtImage;
  3228. u32 fwSize;
  3229. u32 diag0val;
  3230. int count;
  3231. u32 *ptrFw;
  3232. u32 diagRwData;
  3233. u32 nextImage;
  3234. u32 load_addr;
  3235. u32 ioc_state=0;
  3236. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot: fw size 0x%x (%d), FW Ptr %p\n",
  3237. ioc->name, pFwHeader->ImageSize, pFwHeader->ImageSize, pFwHeader));
  3238. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3239. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  3240. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  3241. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  3242. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  3243. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  3244. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
  3245. /* wait 1 msec */
  3246. if (sleepFlag == CAN_SLEEP) {
  3247. msleep(1);
  3248. } else {
  3249. mdelay (1);
  3250. }
  3251. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3252. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  3253. for (count = 0; count < 30; count ++) {
  3254. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3255. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  3256. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RESET_ADAPTER cleared, count=%d\n",
  3257. ioc->name, count));
  3258. break;
  3259. }
  3260. /* wait .1 sec */
  3261. if (sleepFlag == CAN_SLEEP) {
  3262. msleep (100);
  3263. } else {
  3264. mdelay (100);
  3265. }
  3266. }
  3267. if ( count == 30 ) {
  3268. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot failed! "
  3269. "Unable to get MPI_DIAG_DRWE mode, diag0val=%x\n",
  3270. ioc->name, diag0val));
  3271. return -3;
  3272. }
  3273. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3274. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  3275. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  3276. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  3277. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  3278. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  3279. /* Set the DiagRwEn and Disable ARM bits */
  3280. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
  3281. fwSize = (pFwHeader->ImageSize + 3)/4;
  3282. ptrFw = (u32 *) pFwHeader;
  3283. /* Write the LoadStartAddress to the DiagRw Address Register
  3284. * using Programmed IO
  3285. */
  3286. if (ioc->errata_flag_1064)
  3287. pci_enable_io_access(ioc->pcidev);
  3288. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
  3289. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "LoadStart addr written 0x%x \n",
  3290. ioc->name, pFwHeader->LoadStartAddress));
  3291. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write FW Image: 0x%x bytes @ %p\n",
  3292. ioc->name, fwSize*4, ptrFw));
  3293. while (fwSize--) {
  3294. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  3295. }
  3296. nextImage = pFwHeader->NextImageHeaderOffset;
  3297. while (nextImage) {
  3298. pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
  3299. load_addr = pExtImage->LoadStartAddress;
  3300. fwSize = (pExtImage->ImageSize + 3) >> 2;
  3301. ptrFw = (u32 *)pExtImage;
  3302. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
  3303. ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
  3304. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
  3305. while (fwSize--) {
  3306. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  3307. }
  3308. nextImage = pExtImage->NextImageHeaderOffset;
  3309. }
  3310. /* Write the IopResetVectorRegAddr */
  3311. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
  3312. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
  3313. /* Write the IopResetVectorValue */
  3314. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
  3315. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
  3316. /* Clear the internal flash bad bit - autoincrementing register,
  3317. * so must do two writes.
  3318. */
  3319. if (ioc->bus_type == SPI) {
  3320. /*
  3321. * 1030 and 1035 H/W errata, workaround to access
  3322. * the ClearFlashBadSignatureBit
  3323. */
  3324. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  3325. diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
  3326. diagRwData |= 0x40000000;
  3327. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  3328. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
  3329. } else /* if((ioc->bus_type == SAS) || (ioc->bus_type == FC)) */ {
  3330. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3331. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val |
  3332. MPI_DIAG_CLEAR_FLASH_BAD_SIG);
  3333. /* wait 1 msec */
  3334. if (sleepFlag == CAN_SLEEP) {
  3335. msleep (1);
  3336. } else {
  3337. mdelay (1);
  3338. }
  3339. }
  3340. if (ioc->errata_flag_1064)
  3341. pci_disable_io_access(ioc->pcidev);
  3342. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3343. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot diag0val=%x, "
  3344. "turning off PREVENT_IOC_BOOT, DISABLE_ARM, RW_ENABLE\n",
  3345. ioc->name, diag0val));
  3346. diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM | MPI_DIAG_RW_ENABLE);
  3347. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot now diag0val=%x\n",
  3348. ioc->name, diag0val));
  3349. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  3350. /* Write 0xFF to reset the sequencer */
  3351. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3352. if (ioc->bus_type == SAS) {
  3353. ioc_state = mpt_GetIocState(ioc, 0);
  3354. if ( (GetIocFacts(ioc, sleepFlag,
  3355. MPT_HOSTEVENT_IOC_BRINGUP)) != 0 ) {
  3356. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "GetIocFacts failed: IocState=%x\n",
  3357. ioc->name, ioc_state));
  3358. return -EFAULT;
  3359. }
  3360. }
  3361. for (count=0; count<HZ*20; count++) {
  3362. if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
  3363. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3364. "downloadboot successful! (count=%d) IocState=%x\n",
  3365. ioc->name, count, ioc_state));
  3366. if (ioc->bus_type == SAS) {
  3367. return 0;
  3368. }
  3369. if ((SendIocInit(ioc, sleepFlag)) != 0) {
  3370. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3371. "downloadboot: SendIocInit failed\n",
  3372. ioc->name));
  3373. return -EFAULT;
  3374. }
  3375. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3376. "downloadboot: SendIocInit successful\n",
  3377. ioc->name));
  3378. return 0;
  3379. }
  3380. if (sleepFlag == CAN_SLEEP) {
  3381. msleep (10);
  3382. } else {
  3383. mdelay (10);
  3384. }
  3385. }
  3386. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3387. "downloadboot failed! IocState=%x\n",ioc->name, ioc_state));
  3388. return -EFAULT;
  3389. }
  3390. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3391. /**
  3392. * KickStart - Perform hard reset of MPT adapter.
  3393. * @ioc: Pointer to MPT_ADAPTER structure
  3394. * @force: Force hard reset
  3395. * @sleepFlag: Specifies whether the process can sleep
  3396. *
  3397. * This routine places MPT adapter in diagnostic mode via the
  3398. * WriteSequence register, and then performs a hard reset of adapter
  3399. * via the Diagnostic register.
  3400. *
  3401. * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
  3402. * or NO_SLEEP (interrupt thread, use mdelay)
  3403. * force - 1 if doorbell active, board fault state
  3404. * board operational, IOC_RECOVERY or
  3405. * IOC_BRINGUP and there is an alt_ioc.
  3406. * 0 else
  3407. *
  3408. * Returns:
  3409. * 1 - hard reset, READY
  3410. * 0 - no reset due to History bit, READY
  3411. * -1 - no reset due to History bit but not READY
  3412. * OR reset but failed to come READY
  3413. * -2 - no reset, could not enter DIAG mode
  3414. * -3 - reset but bad FW bit
  3415. */
  3416. static int
  3417. KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
  3418. {
  3419. int hard_reset_done = 0;
  3420. u32 ioc_state=0;
  3421. int cnt,cntdn;
  3422. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStarting!\n", ioc->name));
  3423. if (ioc->bus_type == SPI) {
  3424. /* Always issue a Msg Unit Reset first. This will clear some
  3425. * SCSI bus hang conditions.
  3426. */
  3427. SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
  3428. if (sleepFlag == CAN_SLEEP) {
  3429. msleep (1000);
  3430. } else {
  3431. mdelay (1000);
  3432. }
  3433. }
  3434. hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
  3435. if (hard_reset_done < 0)
  3436. return hard_reset_done;
  3437. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset successful!\n",
  3438. ioc->name));
  3439. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
  3440. for (cnt=0; cnt<cntdn; cnt++) {
  3441. ioc_state = mpt_GetIocState(ioc, 1);
  3442. if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
  3443. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStart successful! (cnt=%d)\n",
  3444. ioc->name, cnt));
  3445. return hard_reset_done;
  3446. }
  3447. if (sleepFlag == CAN_SLEEP) {
  3448. msleep (10);
  3449. } else {
  3450. mdelay (10);
  3451. }
  3452. }
  3453. dinitprintk(ioc, printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
  3454. ioc->name, mpt_GetIocState(ioc, 0)));
  3455. return -1;
  3456. }
  3457. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3458. /**
  3459. * mpt_diag_reset - Perform hard reset of the adapter.
  3460. * @ioc: Pointer to MPT_ADAPTER structure
  3461. * @ignore: Set if to honor and clear to ignore
  3462. * the reset history bit
  3463. * @sleepFlag: CAN_SLEEP if called in a non-interrupt thread,
  3464. * else set to NO_SLEEP (use mdelay instead)
  3465. *
  3466. * This routine places the adapter in diagnostic mode via the
  3467. * WriteSequence register and then performs a hard reset of adapter
  3468. * via the Diagnostic register. Adapter should be in ready state
  3469. * upon successful completion.
  3470. *
  3471. * Returns: 1 hard reset successful
  3472. * 0 no reset performed because reset history bit set
  3473. * -2 enabling diagnostic mode failed
  3474. * -3 diagnostic reset failed
  3475. */
  3476. static int
  3477. mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
  3478. {
  3479. u32 diag0val;
  3480. u32 doorbell;
  3481. int hard_reset_done = 0;
  3482. int count = 0;
  3483. u32 diag1val = 0;
  3484. MpiFwHeader_t *cached_fw; /* Pointer to FW */
  3485. u8 cb_idx;
  3486. /* Clear any existing interrupts */
  3487. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3488. if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
  3489. if (!ignore)
  3490. return 0;
  3491. drsprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
  3492. "address=%p\n", ioc->name, __func__,
  3493. &ioc->chip->Doorbell, &ioc->chip->Reset_1078));
  3494. CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
  3495. if (sleepFlag == CAN_SLEEP)
  3496. msleep(1);
  3497. else
  3498. mdelay(1);
  3499. /*
  3500. * Call each currently registered protocol IOC reset handler
  3501. * with pre-reset indication.
  3502. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  3503. * MptResetHandlers[] registered yet.
  3504. */
  3505. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  3506. if (MptResetHandlers[cb_idx])
  3507. (*(MptResetHandlers[cb_idx]))(ioc,
  3508. MPT_IOC_PRE_RESET);
  3509. }
  3510. for (count = 0; count < 60; count ++) {
  3511. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  3512. doorbell &= MPI_IOC_STATE_MASK;
  3513. drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3514. "looking for READY STATE: doorbell=%x"
  3515. " count=%d\n",
  3516. ioc->name, doorbell, count));
  3517. if (doorbell == MPI_IOC_STATE_READY) {
  3518. return 1;
  3519. }
  3520. /* wait 1 sec */
  3521. if (sleepFlag == CAN_SLEEP)
  3522. msleep(1000);
  3523. else
  3524. mdelay(1000);
  3525. }
  3526. return -1;
  3527. }
  3528. /* Use "Diagnostic reset" method! (only thing available!) */
  3529. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3530. if (ioc->debug_level & MPT_DEBUG) {
  3531. if (ioc->alt_ioc)
  3532. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  3533. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG1: diag0=%08x, diag1=%08x\n",
  3534. ioc->name, diag0val, diag1val));
  3535. }
  3536. /* Do the reset if we are told to ignore the reset history
  3537. * or if the reset history is 0
  3538. */
  3539. if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
  3540. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  3541. /* Write magic sequence to WriteSequence register
  3542. * Loop until in diagnostic mode
  3543. */
  3544. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3545. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  3546. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  3547. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  3548. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  3549. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  3550. /* wait 100 msec */
  3551. if (sleepFlag == CAN_SLEEP) {
  3552. msleep (100);
  3553. } else {
  3554. mdelay (100);
  3555. }
  3556. count++;
  3557. if (count > 20) {
  3558. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  3559. ioc->name, diag0val);
  3560. return -2;
  3561. }
  3562. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3563. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
  3564. ioc->name, diag0val));
  3565. }
  3566. if (ioc->debug_level & MPT_DEBUG) {
  3567. if (ioc->alt_ioc)
  3568. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  3569. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG2: diag0=%08x, diag1=%08x\n",
  3570. ioc->name, diag0val, diag1val));
  3571. }
  3572. /*
  3573. * Disable the ARM (Bug fix)
  3574. *
  3575. */
  3576. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
  3577. mdelay(1);
  3578. /*
  3579. * Now hit the reset bit in the Diagnostic register
  3580. * (THE BIG HAMMER!) (Clears DRWE bit).
  3581. */
  3582. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  3583. hard_reset_done = 1;
  3584. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset performed\n",
  3585. ioc->name));
  3586. /*
  3587. * Call each currently registered protocol IOC reset handler
  3588. * with pre-reset indication.
  3589. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  3590. * MptResetHandlers[] registered yet.
  3591. */
  3592. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  3593. if (MptResetHandlers[cb_idx]) {
  3594. mpt_signal_reset(cb_idx,
  3595. ioc, MPT_IOC_PRE_RESET);
  3596. if (ioc->alt_ioc) {
  3597. mpt_signal_reset(cb_idx,
  3598. ioc->alt_ioc, MPT_IOC_PRE_RESET);
  3599. }
  3600. }
  3601. }
  3602. if (ioc->cached_fw)
  3603. cached_fw = (MpiFwHeader_t *)ioc->cached_fw;
  3604. else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
  3605. cached_fw = (MpiFwHeader_t *)ioc->alt_ioc->cached_fw;
  3606. else
  3607. cached_fw = NULL;
  3608. if (cached_fw) {
  3609. /* If the DownloadBoot operation fails, the
  3610. * IOC will be left unusable. This is a fatal error
  3611. * case. _diag_reset will return < 0
  3612. */
  3613. for (count = 0; count < 30; count ++) {
  3614. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3615. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  3616. break;
  3617. }
  3618. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "cached_fw: diag0val=%x count=%d\n",
  3619. ioc->name, diag0val, count));
  3620. /* wait 1 sec */
  3621. if (sleepFlag == CAN_SLEEP) {
  3622. msleep (1000);
  3623. } else {
  3624. mdelay (1000);
  3625. }
  3626. }
  3627. if ((count = mpt_downloadboot(ioc, cached_fw, sleepFlag)) < 0) {
  3628. printk(MYIOC_s_WARN_FMT
  3629. "firmware downloadboot failure (%d)!\n", ioc->name, count);
  3630. }
  3631. } else {
  3632. /* Wait for FW to reload and for board
  3633. * to go to the READY state.
  3634. * Maximum wait is 60 seconds.
  3635. * If fail, no error will check again
  3636. * with calling program.
  3637. */
  3638. for (count = 0; count < 60; count ++) {
  3639. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  3640. doorbell &= MPI_IOC_STATE_MASK;
  3641. drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3642. "looking for READY STATE: doorbell=%x"
  3643. " count=%d\n", ioc->name, doorbell, count));
  3644. if (doorbell == MPI_IOC_STATE_READY) {
  3645. break;
  3646. }
  3647. /* wait 1 sec */
  3648. if (sleepFlag == CAN_SLEEP) {
  3649. msleep (1000);
  3650. } else {
  3651. mdelay (1000);
  3652. }
  3653. }
  3654. if (doorbell != MPI_IOC_STATE_READY)
  3655. printk(MYIOC_s_ERR_FMT "Failed to come READY "
  3656. "after reset! IocState=%x", ioc->name,
  3657. doorbell);
  3658. }
  3659. }
  3660. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3661. if (ioc->debug_level & MPT_DEBUG) {
  3662. if (ioc->alt_ioc)
  3663. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  3664. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG3: diag0=%08x, diag1=%08x\n",
  3665. ioc->name, diag0val, diag1val));
  3666. }
  3667. /* Clear RESET_HISTORY bit! Place board in the
  3668. * diagnostic mode to update the diag register.
  3669. */
  3670. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3671. count = 0;
  3672. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  3673. /* Write magic sequence to WriteSequence register
  3674. * Loop until in diagnostic mode
  3675. */
  3676. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3677. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  3678. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  3679. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  3680. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  3681. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  3682. /* wait 100 msec */
  3683. if (sleepFlag == CAN_SLEEP) {
  3684. msleep (100);
  3685. } else {
  3686. mdelay (100);
  3687. }
  3688. count++;
  3689. if (count > 20) {
  3690. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  3691. ioc->name, diag0val);
  3692. break;
  3693. }
  3694. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3695. }
  3696. diag0val &= ~MPI_DIAG_RESET_HISTORY;
  3697. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  3698. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3699. if (diag0val & MPI_DIAG_RESET_HISTORY) {
  3700. printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
  3701. ioc->name);
  3702. }
  3703. /* Disable Diagnostic Mode
  3704. */
  3705. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
  3706. /* Check FW reload status flags.
  3707. */
  3708. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3709. if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
  3710. printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
  3711. ioc->name, diag0val);
  3712. return -3;
  3713. }
  3714. if (ioc->debug_level & MPT_DEBUG) {
  3715. if (ioc->alt_ioc)
  3716. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  3717. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG4: diag0=%08x, diag1=%08x\n",
  3718. ioc->name, diag0val, diag1val));
  3719. }
  3720. /*
  3721. * Reset flag that says we've enabled event notification
  3722. */
  3723. ioc->facts.EventState = 0;
  3724. if (ioc->alt_ioc)
  3725. ioc->alt_ioc->facts.EventState = 0;
  3726. return hard_reset_done;
  3727. }
  3728. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3729. /**
  3730. * SendIocReset - Send IOCReset request to MPT adapter.
  3731. * @ioc: Pointer to MPT_ADAPTER structure
  3732. * @reset_type: reset type, expected values are
  3733. * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
  3734. * @sleepFlag: Specifies whether the process can sleep
  3735. *
  3736. * Send IOCReset request to the MPT adapter.
  3737. *
  3738. * Returns 0 for success, non-zero for failure.
  3739. */
  3740. static int
  3741. SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
  3742. {
  3743. int r;
  3744. u32 state;
  3745. int cntdn, count;
  3746. drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending IOC reset(0x%02x)!\n",
  3747. ioc->name, reset_type));
  3748. CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
  3749. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3750. return r;
  3751. /* FW ACK'd request, wait for READY state
  3752. */
  3753. count = 0;
  3754. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  3755. while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  3756. cntdn--;
  3757. count++;
  3758. if (!cntdn) {
  3759. if (sleepFlag != CAN_SLEEP)
  3760. count *= 10;
  3761. printk(MYIOC_s_ERR_FMT
  3762. "Wait IOC_READY state (0x%x) timeout(%d)!\n",
  3763. ioc->name, state, (int)((count+5)/HZ));
  3764. return -ETIME;
  3765. }
  3766. if (sleepFlag == CAN_SLEEP) {
  3767. msleep(1);
  3768. } else {
  3769. mdelay (1); /* 1 msec delay */
  3770. }
  3771. }
  3772. /* TODO!
  3773. * Cleanup all event stuff for this IOC; re-issue EventNotification
  3774. * request if needed.
  3775. */
  3776. if (ioc->facts.Function)
  3777. ioc->facts.EventState = 0;
  3778. return 0;
  3779. }
  3780. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3781. /**
  3782. * initChainBuffers - Allocate memory for and initialize chain buffers
  3783. * @ioc: Pointer to MPT_ADAPTER structure
  3784. *
  3785. * Allocates memory for and initializes chain buffers,
  3786. * chain buffer control arrays and spinlock.
  3787. */
  3788. static int
  3789. initChainBuffers(MPT_ADAPTER *ioc)
  3790. {
  3791. u8 *mem;
  3792. int sz, ii, num_chain;
  3793. int scale, num_sge, numSGE;
  3794. /* ReqToChain size must equal the req_depth
  3795. * index = req_idx
  3796. */
  3797. if (ioc->ReqToChain == NULL) {
  3798. sz = ioc->req_depth * sizeof(int);
  3799. mem = kmalloc(sz, GFP_ATOMIC);
  3800. if (mem == NULL)
  3801. return -1;
  3802. ioc->ReqToChain = (int *) mem;
  3803. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReqToChain alloc @ %p, sz=%d bytes\n",
  3804. ioc->name, mem, sz));
  3805. mem = kmalloc(sz, GFP_ATOMIC);
  3806. if (mem == NULL)
  3807. return -1;
  3808. ioc->RequestNB = (int *) mem;
  3809. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestNB alloc @ %p, sz=%d bytes\n",
  3810. ioc->name, mem, sz));
  3811. }
  3812. for (ii = 0; ii < ioc->req_depth; ii++) {
  3813. ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
  3814. }
  3815. /* ChainToChain size must equal the total number
  3816. * of chain buffers to be allocated.
  3817. * index = chain_idx
  3818. *
  3819. * Calculate the number of chain buffers needed(plus 1) per I/O
  3820. * then multiply the maximum number of simultaneous cmds
  3821. *
  3822. * num_sge = num sge in request frame + last chain buffer
  3823. * scale = num sge per chain buffer if no chain element
  3824. */
  3825. scale = ioc->req_sz / ioc->SGE_size;
  3826. if (ioc->sg_addr_size == sizeof(u64))
  3827. num_sge = scale + (ioc->req_sz - 60) / ioc->SGE_size;
  3828. else
  3829. num_sge = 1 + scale + (ioc->req_sz - 64) / ioc->SGE_size;
  3830. if (ioc->sg_addr_size == sizeof(u64)) {
  3831. numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  3832. (ioc->req_sz - 60) / ioc->SGE_size;
  3833. } else {
  3834. numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) +
  3835. scale + (ioc->req_sz - 64) / ioc->SGE_size;
  3836. }
  3837. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "num_sge=%d numSGE=%d\n",
  3838. ioc->name, num_sge, numSGE));
  3839. if (ioc->bus_type == FC) {
  3840. if (numSGE > MPT_SCSI_FC_SG_DEPTH)
  3841. numSGE = MPT_SCSI_FC_SG_DEPTH;
  3842. } else {
  3843. if (numSGE > MPT_SCSI_SG_DEPTH)
  3844. numSGE = MPT_SCSI_SG_DEPTH;
  3845. }
  3846. num_chain = 1;
  3847. while (numSGE - num_sge > 0) {
  3848. num_chain++;
  3849. num_sge += (scale - 1);
  3850. }
  3851. num_chain++;
  3852. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Now numSGE=%d num_sge=%d num_chain=%d\n",
  3853. ioc->name, numSGE, num_sge, num_chain));
  3854. if (ioc->bus_type == SPI)
  3855. num_chain *= MPT_SCSI_CAN_QUEUE;
  3856. else if (ioc->bus_type == SAS)
  3857. num_chain *= MPT_SAS_CAN_QUEUE;
  3858. else
  3859. num_chain *= MPT_FC_CAN_QUEUE;
  3860. ioc->num_chain = num_chain;
  3861. sz = num_chain * sizeof(int);
  3862. if (ioc->ChainToChain == NULL) {
  3863. mem = kmalloc(sz, GFP_ATOMIC);
  3864. if (mem == NULL)
  3865. return -1;
  3866. ioc->ChainToChain = (int *) mem;
  3867. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainToChain alloc @ %p, sz=%d bytes\n",
  3868. ioc->name, mem, sz));
  3869. } else {
  3870. mem = (u8 *) ioc->ChainToChain;
  3871. }
  3872. memset(mem, 0xFF, sz);
  3873. return num_chain;
  3874. }
  3875. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3876. /**
  3877. * PrimeIocFifos - Initialize IOC request and reply FIFOs.
  3878. * @ioc: Pointer to MPT_ADAPTER structure
  3879. *
  3880. * This routine allocates memory for the MPT reply and request frame
  3881. * pools (if necessary), and primes the IOC reply FIFO with
  3882. * reply frames.
  3883. *
  3884. * Returns 0 for success, non-zero for failure.
  3885. */
  3886. static int
  3887. PrimeIocFifos(MPT_ADAPTER *ioc)
  3888. {
  3889. MPT_FRAME_HDR *mf;
  3890. unsigned long flags;
  3891. dma_addr_t alloc_dma;
  3892. u8 *mem;
  3893. int i, reply_sz, sz, total_size, num_chain;
  3894. u64 dma_mask;
  3895. dma_mask = 0;
  3896. /* Prime reply FIFO... */
  3897. if (ioc->reply_frames == NULL) {
  3898. if ( (num_chain = initChainBuffers(ioc)) < 0)
  3899. return -1;
  3900. /*
  3901. * 1078 errata workaround for the 36GB limitation
  3902. */
  3903. if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078 &&
  3904. ioc->dma_mask > DMA_BIT_MASK(35)) {
  3905. if (!pci_set_dma_mask(ioc->pcidev, DMA_BIT_MASK(32))
  3906. && !pci_set_consistent_dma_mask(ioc->pcidev,
  3907. DMA_BIT_MASK(32))) {
  3908. dma_mask = DMA_BIT_MASK(35);
  3909. d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3910. "setting 35 bit addressing for "
  3911. "Request/Reply/Chain and Sense Buffers\n",
  3912. ioc->name));
  3913. } else {
  3914. /*Reseting DMA mask to 64 bit*/
  3915. pci_set_dma_mask(ioc->pcidev,
  3916. DMA_BIT_MASK(64));
  3917. pci_set_consistent_dma_mask(ioc->pcidev,
  3918. DMA_BIT_MASK(64));
  3919. printk(MYIOC_s_ERR_FMT
  3920. "failed setting 35 bit addressing for "
  3921. "Request/Reply/Chain and Sense Buffers\n",
  3922. ioc->name);
  3923. return -1;
  3924. }
  3925. }
  3926. total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
  3927. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
  3928. ioc->name, ioc->reply_sz, ioc->reply_depth));
  3929. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffer sz=%d[%x] bytes\n",
  3930. ioc->name, reply_sz, reply_sz));
  3931. sz = (ioc->req_sz * ioc->req_depth);
  3932. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffer sz=%d bytes, RequestDepth=%d\n",
  3933. ioc->name, ioc->req_sz, ioc->req_depth));
  3934. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffer sz=%d[%x] bytes\n",
  3935. ioc->name, sz, sz));
  3936. total_size += sz;
  3937. sz = num_chain * ioc->req_sz; /* chain buffer pool size */
  3938. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffer sz=%d bytes, ChainDepth=%d\n",
  3939. ioc->name, ioc->req_sz, num_chain));
  3940. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
  3941. ioc->name, sz, sz, num_chain));
  3942. total_size += sz;
  3943. mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
  3944. if (mem == NULL) {
  3945. printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
  3946. ioc->name);
  3947. goto out_fail;
  3948. }
  3949. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Total alloc @ %p[%p], sz=%d[%x] bytes\n",
  3950. ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
  3951. memset(mem, 0, total_size);
  3952. ioc->alloc_total += total_size;
  3953. ioc->alloc = mem;
  3954. ioc->alloc_dma = alloc_dma;
  3955. ioc->alloc_sz = total_size;
  3956. ioc->reply_frames = (MPT_FRAME_HDR *) mem;
  3957. ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  3958. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffers @ %p[%p]\n",
  3959. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  3960. alloc_dma += reply_sz;
  3961. mem += reply_sz;
  3962. /* Request FIFO - WE manage this! */
  3963. ioc->req_frames = (MPT_FRAME_HDR *) mem;
  3964. ioc->req_frames_dma = alloc_dma;
  3965. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffers @ %p[%p]\n",
  3966. ioc->name, mem, (void *)(ulong)alloc_dma));
  3967. ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  3968. #if defined(CONFIG_MTRR) && 0
  3969. /*
  3970. * Enable Write Combining MTRR for IOC's memory region.
  3971. * (at least as much as we can; "size and base must be
  3972. * multiples of 4 kiB"
  3973. */
  3974. ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
  3975. sz,
  3976. MTRR_TYPE_WRCOMB, 1);
  3977. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MTRR region registered (base:size=%08x:%x)\n",
  3978. ioc->name, ioc->req_frames_dma, sz));
  3979. #endif
  3980. for (i = 0; i < ioc->req_depth; i++) {
  3981. alloc_dma += ioc->req_sz;
  3982. mem += ioc->req_sz;
  3983. }
  3984. ioc->ChainBuffer = mem;
  3985. ioc->ChainBufferDMA = alloc_dma;
  3986. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffers @ %p(%p)\n",
  3987. ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
  3988. /* Initialize the free chain Q.
  3989. */
  3990. INIT_LIST_HEAD(&ioc->FreeChainQ);
  3991. /* Post the chain buffers to the FreeChainQ.
  3992. */
  3993. mem = (u8 *)ioc->ChainBuffer;
  3994. for (i=0; i < num_chain; i++) {
  3995. mf = (MPT_FRAME_HDR *) mem;
  3996. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
  3997. mem += ioc->req_sz;
  3998. }
  3999. /* Initialize Request frames linked list
  4000. */
  4001. alloc_dma = ioc->req_frames_dma;
  4002. mem = (u8 *) ioc->req_frames;
  4003. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4004. INIT_LIST_HEAD(&ioc->FreeQ);
  4005. for (i = 0; i < ioc->req_depth; i++) {
  4006. mf = (MPT_FRAME_HDR *) mem;
  4007. /* Queue REQUESTs *internally*! */
  4008. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  4009. mem += ioc->req_sz;
  4010. }
  4011. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4012. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  4013. ioc->sense_buf_pool =
  4014. pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
  4015. if (ioc->sense_buf_pool == NULL) {
  4016. printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
  4017. ioc->name);
  4018. goto out_fail;
  4019. }
  4020. ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
  4021. ioc->alloc_total += sz;
  4022. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SenseBuffers @ %p[%p]\n",
  4023. ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
  4024. }
  4025. /* Post Reply frames to FIFO
  4026. */
  4027. alloc_dma = ioc->alloc_dma;
  4028. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffers @ %p[%p]\n",
  4029. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  4030. for (i = 0; i < ioc->reply_depth; i++) {
  4031. /* Write each address to the IOC! */
  4032. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
  4033. alloc_dma += ioc->reply_sz;
  4034. }
  4035. if (dma_mask == DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc->pcidev,
  4036. ioc->dma_mask) && !pci_set_consistent_dma_mask(ioc->pcidev,
  4037. ioc->dma_mask))
  4038. d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4039. "restoring 64 bit addressing\n", ioc->name));
  4040. return 0;
  4041. out_fail:
  4042. if (ioc->alloc != NULL) {
  4043. sz = ioc->alloc_sz;
  4044. pci_free_consistent(ioc->pcidev,
  4045. sz,
  4046. ioc->alloc, ioc->alloc_dma);
  4047. ioc->reply_frames = NULL;
  4048. ioc->req_frames = NULL;
  4049. ioc->alloc_total -= sz;
  4050. }
  4051. if (ioc->sense_buf_pool != NULL) {
  4052. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  4053. pci_free_consistent(ioc->pcidev,
  4054. sz,
  4055. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  4056. ioc->sense_buf_pool = NULL;
  4057. }
  4058. if (dma_mask == DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc->pcidev,
  4059. DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(ioc->pcidev,
  4060. DMA_BIT_MASK(64)))
  4061. d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4062. "restoring 64 bit addressing\n", ioc->name));
  4063. return -1;
  4064. }
  4065. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4066. /**
  4067. * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
  4068. * from IOC via doorbell handshake method.
  4069. * @ioc: Pointer to MPT_ADAPTER structure
  4070. * @reqBytes: Size of the request in bytes
  4071. * @req: Pointer to MPT request frame
  4072. * @replyBytes: Expected size of the reply in bytes
  4073. * @u16reply: Pointer to area where reply should be written
  4074. * @maxwait: Max wait time for a reply (in seconds)
  4075. * @sleepFlag: Specifies whether the process can sleep
  4076. *
  4077. * NOTES: It is the callers responsibility to byte-swap fields in the
  4078. * request which are greater than 1 byte in size. It is also the
  4079. * callers responsibility to byte-swap response fields which are
  4080. * greater than 1 byte in size.
  4081. *
  4082. * Returns 0 for success, non-zero for failure.
  4083. */
  4084. static int
  4085. mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
  4086. int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
  4087. {
  4088. MPIDefaultReply_t *mptReply;
  4089. int failcnt = 0;
  4090. int t;
  4091. /*
  4092. * Get ready to cache a handshake reply
  4093. */
  4094. ioc->hs_reply_idx = 0;
  4095. mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  4096. mptReply->MsgLength = 0;
  4097. /*
  4098. * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
  4099. * then tell IOC that we want to handshake a request of N words.
  4100. * (WRITE u32val to Doorbell reg).
  4101. */
  4102. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4103. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  4104. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  4105. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  4106. /*
  4107. * Wait for IOC's doorbell handshake int
  4108. */
  4109. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  4110. failcnt++;
  4111. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
  4112. ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  4113. /* Read doorbell and check for active bit */
  4114. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  4115. return -1;
  4116. /*
  4117. * Clear doorbell int (WRITE 0 to IntStatus reg),
  4118. * then wait for IOC to ACKnowledge that it's ready for
  4119. * our handshake request.
  4120. */
  4121. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4122. if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  4123. failcnt++;
  4124. if (!failcnt) {
  4125. int ii;
  4126. u8 *req_as_bytes = (u8 *) req;
  4127. /*
  4128. * Stuff request words via doorbell handshake,
  4129. * with ACK from IOC for each.
  4130. */
  4131. for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
  4132. u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
  4133. (req_as_bytes[(ii*4) + 1] << 8) |
  4134. (req_as_bytes[(ii*4) + 2] << 16) |
  4135. (req_as_bytes[(ii*4) + 3] << 24));
  4136. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  4137. if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  4138. failcnt++;
  4139. }
  4140. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handshake request frame (@%p) header\n", ioc->name, req));
  4141. DBG_DUMP_REQUEST_FRAME_HDR(ioc, (u32 *)req);
  4142. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake request post done, WaitCnt=%d%s\n",
  4143. ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
  4144. /*
  4145. * Wait for completion of doorbell handshake reply from the IOC
  4146. */
  4147. if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
  4148. failcnt++;
  4149. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake reply count=%d%s\n",
  4150. ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
  4151. /*
  4152. * Copy out the cached reply...
  4153. */
  4154. for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
  4155. u16reply[ii] = ioc->hs_reply[ii];
  4156. } else {
  4157. return -99;
  4158. }
  4159. return -failcnt;
  4160. }
  4161. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4162. /**
  4163. * WaitForDoorbellAck - Wait for IOC doorbell handshake acknowledge
  4164. * @ioc: Pointer to MPT_ADAPTER structure
  4165. * @howlong: How long to wait (in seconds)
  4166. * @sleepFlag: Specifies whether the process can sleep
  4167. *
  4168. * This routine waits (up to ~2 seconds max) for IOC doorbell
  4169. * handshake ACKnowledge, indicated by the IOP_DOORBELL_STATUS
  4170. * bit in its IntStatus register being clear.
  4171. *
  4172. * Returns a negative value on failure, else wait loop count.
  4173. */
  4174. static int
  4175. WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  4176. {
  4177. int cntdn;
  4178. int count = 0;
  4179. u32 intstat=0;
  4180. cntdn = 1000 * howlong;
  4181. if (sleepFlag == CAN_SLEEP) {
  4182. while (--cntdn) {
  4183. msleep (1);
  4184. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  4185. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  4186. break;
  4187. count++;
  4188. }
  4189. } else {
  4190. while (--cntdn) {
  4191. udelay (1000);
  4192. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  4193. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  4194. break;
  4195. count++;
  4196. }
  4197. }
  4198. if (cntdn) {
  4199. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell ACK (count=%d)\n",
  4200. ioc->name, count));
  4201. return count;
  4202. }
  4203. printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
  4204. ioc->name, count, intstat);
  4205. return -1;
  4206. }
  4207. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4208. /**
  4209. * WaitForDoorbellInt - Wait for IOC to set its doorbell interrupt bit
  4210. * @ioc: Pointer to MPT_ADAPTER structure
  4211. * @howlong: How long to wait (in seconds)
  4212. * @sleepFlag: Specifies whether the process can sleep
  4213. *
  4214. * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt
  4215. * (MPI_HIS_DOORBELL_INTERRUPT) to be set in the IntStatus register.
  4216. *
  4217. * Returns a negative value on failure, else wait loop count.
  4218. */
  4219. static int
  4220. WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  4221. {
  4222. int cntdn;
  4223. int count = 0;
  4224. u32 intstat=0;
  4225. cntdn = 1000 * howlong;
  4226. if (sleepFlag == CAN_SLEEP) {
  4227. while (--cntdn) {
  4228. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  4229. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  4230. break;
  4231. msleep(1);
  4232. count++;
  4233. }
  4234. } else {
  4235. while (--cntdn) {
  4236. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  4237. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  4238. break;
  4239. udelay (1000);
  4240. count++;
  4241. }
  4242. }
  4243. if (cntdn) {
  4244. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
  4245. ioc->name, count, howlong));
  4246. return count;
  4247. }
  4248. printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
  4249. ioc->name, count, intstat);
  4250. return -1;
  4251. }
  4252. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4253. /**
  4254. * WaitForDoorbellReply - Wait for and capture an IOC handshake reply.
  4255. * @ioc: Pointer to MPT_ADAPTER structure
  4256. * @howlong: How long to wait (in seconds)
  4257. * @sleepFlag: Specifies whether the process can sleep
  4258. *
  4259. * This routine polls the IOC for a handshake reply, 16 bits at a time.
  4260. * Reply is cached to IOC private area large enough to hold a maximum
  4261. * of 128 bytes of reply data.
  4262. *
  4263. * Returns a negative value on failure, else size of reply in WORDS.
  4264. */
  4265. static int
  4266. WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  4267. {
  4268. int u16cnt = 0;
  4269. int failcnt = 0;
  4270. int t;
  4271. u16 *hs_reply = ioc->hs_reply;
  4272. volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  4273. u16 hword;
  4274. hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
  4275. /*
  4276. * Get first two u16's so we can look at IOC's intended reply MsgLength
  4277. */
  4278. u16cnt=0;
  4279. if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
  4280. failcnt++;
  4281. } else {
  4282. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  4283. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4284. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  4285. failcnt++;
  4286. else {
  4287. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  4288. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4289. }
  4290. }
  4291. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
  4292. ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
  4293. failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  4294. /*
  4295. * If no error (and IOC said MsgLength is > 0), piece together
  4296. * reply 16 bits at a time.
  4297. */
  4298. for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
  4299. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  4300. failcnt++;
  4301. hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  4302. /* don't overflow our IOC hs_reply[] buffer! */
  4303. if (u16cnt < ARRAY_SIZE(ioc->hs_reply))
  4304. hs_reply[u16cnt] = hword;
  4305. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4306. }
  4307. if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  4308. failcnt++;
  4309. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4310. if (failcnt) {
  4311. printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
  4312. ioc->name);
  4313. return -failcnt;
  4314. }
  4315. #if 0
  4316. else if (u16cnt != (2 * mptReply->MsgLength)) {
  4317. return -101;
  4318. }
  4319. else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
  4320. return -102;
  4321. }
  4322. #endif
  4323. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got Handshake reply:\n", ioc->name));
  4324. DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mptReply);
  4325. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
  4326. ioc->name, t, u16cnt/2));
  4327. return u16cnt/2;
  4328. }
  4329. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4330. /**
  4331. * GetLanConfigPages - Fetch LANConfig pages.
  4332. * @ioc: Pointer to MPT_ADAPTER structure
  4333. *
  4334. * Return: 0 for success
  4335. * -ENOMEM if no memory available
  4336. * -EPERM if not allowed due to ISR context
  4337. * -EAGAIN if no msg frames currently available
  4338. * -EFAULT for non-successful reply or no reply (timeout)
  4339. */
  4340. static int
  4341. GetLanConfigPages(MPT_ADAPTER *ioc)
  4342. {
  4343. ConfigPageHeader_t hdr;
  4344. CONFIGPARMS cfg;
  4345. LANPage0_t *ppage0_alloc;
  4346. dma_addr_t page0_dma;
  4347. LANPage1_t *ppage1_alloc;
  4348. dma_addr_t page1_dma;
  4349. int rc = 0;
  4350. int data_sz;
  4351. int copy_sz;
  4352. /* Get LAN Page 0 header */
  4353. hdr.PageVersion = 0;
  4354. hdr.PageLength = 0;
  4355. hdr.PageNumber = 0;
  4356. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  4357. cfg.cfghdr.hdr = &hdr;
  4358. cfg.physAddr = -1;
  4359. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4360. cfg.dir = 0;
  4361. cfg.pageAddr = 0;
  4362. cfg.timeout = 0;
  4363. if ((rc = mpt_config(ioc, &cfg)) != 0)
  4364. return rc;
  4365. if (hdr.PageLength > 0) {
  4366. data_sz = hdr.PageLength * 4;
  4367. ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  4368. rc = -ENOMEM;
  4369. if (ppage0_alloc) {
  4370. memset((u8 *)ppage0_alloc, 0, data_sz);
  4371. cfg.physAddr = page0_dma;
  4372. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4373. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  4374. /* save the data */
  4375. copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
  4376. memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
  4377. }
  4378. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  4379. /* FIXME!
  4380. * Normalize endianness of structure data,
  4381. * by byte-swapping all > 1 byte fields!
  4382. */
  4383. }
  4384. if (rc)
  4385. return rc;
  4386. }
  4387. /* Get LAN Page 1 header */
  4388. hdr.PageVersion = 0;
  4389. hdr.PageLength = 0;
  4390. hdr.PageNumber = 1;
  4391. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  4392. cfg.cfghdr.hdr = &hdr;
  4393. cfg.physAddr = -1;
  4394. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4395. cfg.dir = 0;
  4396. cfg.pageAddr = 0;
  4397. if ((rc = mpt_config(ioc, &cfg)) != 0)
  4398. return rc;
  4399. if (hdr.PageLength == 0)
  4400. return 0;
  4401. data_sz = hdr.PageLength * 4;
  4402. rc = -ENOMEM;
  4403. ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
  4404. if (ppage1_alloc) {
  4405. memset((u8 *)ppage1_alloc, 0, data_sz);
  4406. cfg.physAddr = page1_dma;
  4407. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4408. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  4409. /* save the data */
  4410. copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
  4411. memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
  4412. }
  4413. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
  4414. /* FIXME!
  4415. * Normalize endianness of structure data,
  4416. * by byte-swapping all > 1 byte fields!
  4417. */
  4418. }
  4419. return rc;
  4420. }
  4421. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4422. /**
  4423. * mptbase_sas_persist_operation - Perform operation on SAS Persistent Table
  4424. * @ioc: Pointer to MPT_ADAPTER structure
  4425. * @persist_opcode: see below
  4426. *
  4427. * MPI_SAS_OP_CLEAR_NOT_PRESENT - Free all persist TargetID mappings for
  4428. * devices not currently present.
  4429. * MPI_SAS_OP_CLEAR_ALL_PERSISTENT - Clear al persist TargetID mappings
  4430. *
  4431. * NOTE: Don't use not this function during interrupt time.
  4432. *
  4433. * Returns 0 for success, non-zero error
  4434. */
  4435. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4436. int
  4437. mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
  4438. {
  4439. SasIoUnitControlRequest_t *sasIoUnitCntrReq;
  4440. SasIoUnitControlReply_t *sasIoUnitCntrReply;
  4441. MPT_FRAME_HDR *mf = NULL;
  4442. MPIHeader_t *mpi_hdr;
  4443. int ret = 0;
  4444. unsigned long timeleft;
  4445. mutex_lock(&ioc->mptbase_cmds.mutex);
  4446. /* init the internal cmd struct */
  4447. memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
  4448. INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
  4449. /* insure garbage is not sent to fw */
  4450. switch(persist_opcode) {
  4451. case MPI_SAS_OP_CLEAR_NOT_PRESENT:
  4452. case MPI_SAS_OP_CLEAR_ALL_PERSISTENT:
  4453. break;
  4454. default:
  4455. ret = -1;
  4456. goto out;
  4457. }
  4458. printk(KERN_DEBUG "%s: persist_opcode=%x\n",
  4459. __func__, persist_opcode);
  4460. /* Get a MF for this command.
  4461. */
  4462. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4463. printk(KERN_DEBUG "%s: no msg frames!\n", __func__);
  4464. ret = -1;
  4465. goto out;
  4466. }
  4467. mpi_hdr = (MPIHeader_t *) mf;
  4468. sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
  4469. memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
  4470. sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
  4471. sasIoUnitCntrReq->MsgContext = mpi_hdr->MsgContext;
  4472. sasIoUnitCntrReq->Operation = persist_opcode;
  4473. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4474. timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done, 10*HZ);
  4475. if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  4476. ret = -ETIME;
  4477. printk(KERN_DEBUG "%s: failed\n", __func__);
  4478. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
  4479. goto out;
  4480. if (!timeleft) {
  4481. printk(MYIOC_s_WARN_FMT
  4482. "Issuing Reset from %s!!, doorbell=0x%08x\n",
  4483. ioc->name, __func__, mpt_GetIocState(ioc, 0));
  4484. mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  4485. mpt_free_msg_frame(ioc, mf);
  4486. }
  4487. goto out;
  4488. }
  4489. if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
  4490. ret = -1;
  4491. goto out;
  4492. }
  4493. sasIoUnitCntrReply =
  4494. (SasIoUnitControlReply_t *)ioc->mptbase_cmds.reply;
  4495. if (le16_to_cpu(sasIoUnitCntrReply->IOCStatus) != MPI_IOCSTATUS_SUCCESS) {
  4496. printk(KERN_DEBUG "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
  4497. __func__, sasIoUnitCntrReply->IOCStatus,
  4498. sasIoUnitCntrReply->IOCLogInfo);
  4499. printk(KERN_DEBUG "%s: failed\n", __func__);
  4500. ret = -1;
  4501. } else
  4502. printk(KERN_DEBUG "%s: success\n", __func__);
  4503. out:
  4504. CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
  4505. mutex_unlock(&ioc->mptbase_cmds.mutex);
  4506. return ret;
  4507. }
  4508. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4509. static void
  4510. mptbase_raid_process_event_data(MPT_ADAPTER *ioc,
  4511. MpiEventDataRaid_t * pRaidEventData)
  4512. {
  4513. int volume;
  4514. int reason;
  4515. int disk;
  4516. int status;
  4517. int flags;
  4518. int state;
  4519. volume = pRaidEventData->VolumeID;
  4520. reason = pRaidEventData->ReasonCode;
  4521. disk = pRaidEventData->PhysDiskNum;
  4522. status = le32_to_cpu(pRaidEventData->SettingsStatus);
  4523. flags = (status >> 0) & 0xff;
  4524. state = (status >> 8) & 0xff;
  4525. if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
  4526. return;
  4527. }
  4528. if ((reason >= MPI_EVENT_RAID_RC_PHYSDISK_CREATED &&
  4529. reason <= MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED) ||
  4530. (reason == MPI_EVENT_RAID_RC_SMART_DATA)) {
  4531. printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for PhysDisk %d id=%d\n",
  4532. ioc->name, disk, volume);
  4533. } else {
  4534. printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for VolumeID %d\n",
  4535. ioc->name, volume);
  4536. }
  4537. switch(reason) {
  4538. case MPI_EVENT_RAID_RC_VOLUME_CREATED:
  4539. printk(MYIOC_s_INFO_FMT " volume has been created\n",
  4540. ioc->name);
  4541. break;
  4542. case MPI_EVENT_RAID_RC_VOLUME_DELETED:
  4543. printk(MYIOC_s_INFO_FMT " volume has been deleted\n",
  4544. ioc->name);
  4545. break;
  4546. case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED:
  4547. printk(MYIOC_s_INFO_FMT " volume settings have been changed\n",
  4548. ioc->name);
  4549. break;
  4550. case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
  4551. printk(MYIOC_s_INFO_FMT " volume is now %s%s%s%s\n",
  4552. ioc->name,
  4553. state == MPI_RAIDVOL0_STATUS_STATE_OPTIMAL
  4554. ? "optimal"
  4555. : state == MPI_RAIDVOL0_STATUS_STATE_DEGRADED
  4556. ? "degraded"
  4557. : state == MPI_RAIDVOL0_STATUS_STATE_FAILED
  4558. ? "failed"
  4559. : "state unknown",
  4560. flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED
  4561. ? ", enabled" : "",
  4562. flags & MPI_RAIDVOL0_STATUS_FLAG_QUIESCED
  4563. ? ", quiesced" : "",
  4564. flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
  4565. ? ", resync in progress" : "" );
  4566. break;
  4567. case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED:
  4568. printk(MYIOC_s_INFO_FMT " volume membership of PhysDisk %d has changed\n",
  4569. ioc->name, disk);
  4570. break;
  4571. case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
  4572. printk(MYIOC_s_INFO_FMT " PhysDisk has been created\n",
  4573. ioc->name);
  4574. break;
  4575. case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
  4576. printk(MYIOC_s_INFO_FMT " PhysDisk has been deleted\n",
  4577. ioc->name);
  4578. break;
  4579. case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED:
  4580. printk(MYIOC_s_INFO_FMT " PhysDisk settings have been changed\n",
  4581. ioc->name);
  4582. break;
  4583. case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
  4584. printk(MYIOC_s_INFO_FMT " PhysDisk is now %s%s%s\n",
  4585. ioc->name,
  4586. state == MPI_PHYSDISK0_STATUS_ONLINE
  4587. ? "online"
  4588. : state == MPI_PHYSDISK0_STATUS_MISSING
  4589. ? "missing"
  4590. : state == MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE
  4591. ? "not compatible"
  4592. : state == MPI_PHYSDISK0_STATUS_FAILED
  4593. ? "failed"
  4594. : state == MPI_PHYSDISK0_STATUS_INITIALIZING
  4595. ? "initializing"
  4596. : state == MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED
  4597. ? "offline requested"
  4598. : state == MPI_PHYSDISK0_STATUS_FAILED_REQUESTED
  4599. ? "failed requested"
  4600. : state == MPI_PHYSDISK0_STATUS_OTHER_OFFLINE
  4601. ? "offline"
  4602. : "state unknown",
  4603. flags & MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC
  4604. ? ", out of sync" : "",
  4605. flags & MPI_PHYSDISK0_STATUS_FLAG_QUIESCED
  4606. ? ", quiesced" : "" );
  4607. break;
  4608. case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED:
  4609. printk(MYIOC_s_INFO_FMT " Domain Validation needed for PhysDisk %d\n",
  4610. ioc->name, disk);
  4611. break;
  4612. case MPI_EVENT_RAID_RC_SMART_DATA:
  4613. printk(MYIOC_s_INFO_FMT " SMART data received, ASC/ASCQ = %02xh/%02xh\n",
  4614. ioc->name, pRaidEventData->ASC, pRaidEventData->ASCQ);
  4615. break;
  4616. case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED:
  4617. printk(MYIOC_s_INFO_FMT " replacement of PhysDisk %d has started\n",
  4618. ioc->name, disk);
  4619. break;
  4620. }
  4621. }
  4622. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4623. /**
  4624. * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
  4625. * @ioc: Pointer to MPT_ADAPTER structure
  4626. *
  4627. * Returns: 0 for success
  4628. * -ENOMEM if no memory available
  4629. * -EPERM if not allowed due to ISR context
  4630. * -EAGAIN if no msg frames currently available
  4631. * -EFAULT for non-successful reply or no reply (timeout)
  4632. */
  4633. static int
  4634. GetIoUnitPage2(MPT_ADAPTER *ioc)
  4635. {
  4636. ConfigPageHeader_t hdr;
  4637. CONFIGPARMS cfg;
  4638. IOUnitPage2_t *ppage_alloc;
  4639. dma_addr_t page_dma;
  4640. int data_sz;
  4641. int rc;
  4642. /* Get the page header */
  4643. hdr.PageVersion = 0;
  4644. hdr.PageLength = 0;
  4645. hdr.PageNumber = 2;
  4646. hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
  4647. cfg.cfghdr.hdr = &hdr;
  4648. cfg.physAddr = -1;
  4649. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4650. cfg.dir = 0;
  4651. cfg.pageAddr = 0;
  4652. cfg.timeout = 0;
  4653. if ((rc = mpt_config(ioc, &cfg)) != 0)
  4654. return rc;
  4655. if (hdr.PageLength == 0)
  4656. return 0;
  4657. /* Read the config page */
  4658. data_sz = hdr.PageLength * 4;
  4659. rc = -ENOMEM;
  4660. ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
  4661. if (ppage_alloc) {
  4662. memset((u8 *)ppage_alloc, 0, data_sz);
  4663. cfg.physAddr = page_dma;
  4664. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4665. /* If Good, save data */
  4666. if ((rc = mpt_config(ioc, &cfg)) == 0)
  4667. ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
  4668. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
  4669. }
  4670. return rc;
  4671. }
  4672. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4673. /**
  4674. * mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
  4675. * @ioc: Pointer to a Adapter Strucutre
  4676. * @portnum: IOC port number
  4677. *
  4678. * Return: -EFAULT if read of config page header fails
  4679. * or if no nvram
  4680. * If read of SCSI Port Page 0 fails,
  4681. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  4682. * Adapter settings: async, narrow
  4683. * Return 1
  4684. * If read of SCSI Port Page 2 fails,
  4685. * Adapter settings valid
  4686. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  4687. * Return 1
  4688. * Else
  4689. * Both valid
  4690. * Return 0
  4691. * CHECK - what type of locking mechanisms should be used????
  4692. */
  4693. static int
  4694. mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
  4695. {
  4696. u8 *pbuf;
  4697. dma_addr_t buf_dma;
  4698. CONFIGPARMS cfg;
  4699. ConfigPageHeader_t header;
  4700. int ii;
  4701. int data, rc = 0;
  4702. /* Allocate memory
  4703. */
  4704. if (!ioc->spi_data.nvram) {
  4705. int sz;
  4706. u8 *mem;
  4707. sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
  4708. mem = kmalloc(sz, GFP_ATOMIC);
  4709. if (mem == NULL)
  4710. return -EFAULT;
  4711. ioc->spi_data.nvram = (int *) mem;
  4712. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
  4713. ioc->name, ioc->spi_data.nvram, sz));
  4714. }
  4715. /* Invalidate NVRAM information
  4716. */
  4717. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  4718. ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
  4719. }
  4720. /* Read SPP0 header, allocate memory, then read page.
  4721. */
  4722. header.PageVersion = 0;
  4723. header.PageLength = 0;
  4724. header.PageNumber = 0;
  4725. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  4726. cfg.cfghdr.hdr = &header;
  4727. cfg.physAddr = -1;
  4728. cfg.pageAddr = portnum;
  4729. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4730. cfg.dir = 0;
  4731. cfg.timeout = 0; /* use default */
  4732. if (mpt_config(ioc, &cfg) != 0)
  4733. return -EFAULT;
  4734. if (header.PageLength > 0) {
  4735. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  4736. if (pbuf) {
  4737. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4738. cfg.physAddr = buf_dma;
  4739. if (mpt_config(ioc, &cfg) != 0) {
  4740. ioc->spi_data.maxBusWidth = MPT_NARROW;
  4741. ioc->spi_data.maxSyncOffset = 0;
  4742. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  4743. ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
  4744. rc = 1;
  4745. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4746. "Unable to read PortPage0 minSyncFactor=%x\n",
  4747. ioc->name, ioc->spi_data.minSyncFactor));
  4748. } else {
  4749. /* Save the Port Page 0 data
  4750. */
  4751. SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
  4752. pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
  4753. pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
  4754. if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
  4755. ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
  4756. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4757. "noQas due to Capabilities=%x\n",
  4758. ioc->name, pPP0->Capabilities));
  4759. }
  4760. ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
  4761. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
  4762. if (data) {
  4763. ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
  4764. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
  4765. ioc->spi_data.minSyncFactor = (u8) (data >> 8);
  4766. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4767. "PortPage0 minSyncFactor=%x\n",
  4768. ioc->name, ioc->spi_data.minSyncFactor));
  4769. } else {
  4770. ioc->spi_data.maxSyncOffset = 0;
  4771. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  4772. }
  4773. ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
  4774. /* Update the minSyncFactor based on bus type.
  4775. */
  4776. if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
  4777. (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
  4778. if (ioc->spi_data.minSyncFactor < MPT_ULTRA) {
  4779. ioc->spi_data.minSyncFactor = MPT_ULTRA;
  4780. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4781. "HVD or SE detected, minSyncFactor=%x\n",
  4782. ioc->name, ioc->spi_data.minSyncFactor));
  4783. }
  4784. }
  4785. }
  4786. if (pbuf) {
  4787. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  4788. }
  4789. }
  4790. }
  4791. /* SCSI Port Page 2 - Read the header then the page.
  4792. */
  4793. header.PageVersion = 0;
  4794. header.PageLength = 0;
  4795. header.PageNumber = 2;
  4796. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  4797. cfg.cfghdr.hdr = &header;
  4798. cfg.physAddr = -1;
  4799. cfg.pageAddr = portnum;
  4800. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4801. cfg.dir = 0;
  4802. if (mpt_config(ioc, &cfg) != 0)
  4803. return -EFAULT;
  4804. if (header.PageLength > 0) {
  4805. /* Allocate memory and read SCSI Port Page 2
  4806. */
  4807. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  4808. if (pbuf) {
  4809. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
  4810. cfg.physAddr = buf_dma;
  4811. if (mpt_config(ioc, &cfg) != 0) {
  4812. /* Nvram data is left with INVALID mark
  4813. */
  4814. rc = 1;
  4815. } else if (ioc->pcidev->vendor == PCI_VENDOR_ID_ATTO) {
  4816. /* This is an ATTO adapter, read Page2 accordingly
  4817. */
  4818. ATTO_SCSIPortPage2_t *pPP2 = (ATTO_SCSIPortPage2_t *) pbuf;
  4819. ATTODeviceInfo_t *pdevice = NULL;
  4820. u16 ATTOFlags;
  4821. /* Save the Port Page 2 data
  4822. * (reformat into a 32bit quantity)
  4823. */
  4824. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  4825. pdevice = &pPP2->DeviceSettings[ii];
  4826. ATTOFlags = le16_to_cpu(pdevice->ATTOFlags);
  4827. data = 0;
  4828. /* Translate ATTO device flags to LSI format
  4829. */
  4830. if (ATTOFlags & ATTOFLAG_DISC)
  4831. data |= (MPI_SCSIPORTPAGE2_DEVICE_DISCONNECT_ENABLE);
  4832. if (ATTOFlags & ATTOFLAG_ID_ENB)
  4833. data |= (MPI_SCSIPORTPAGE2_DEVICE_ID_SCAN_ENABLE);
  4834. if (ATTOFlags & ATTOFLAG_LUN_ENB)
  4835. data |= (MPI_SCSIPORTPAGE2_DEVICE_LUN_SCAN_ENABLE);
  4836. if (ATTOFlags & ATTOFLAG_TAGGED)
  4837. data |= (MPI_SCSIPORTPAGE2_DEVICE_TAG_QUEUE_ENABLE);
  4838. if (!(ATTOFlags & ATTOFLAG_WIDE_ENB))
  4839. data |= (MPI_SCSIPORTPAGE2_DEVICE_WIDE_DISABLE);
  4840. data = (data << 16) | (pdevice->Period << 8) | 10;
  4841. ioc->spi_data.nvram[ii] = data;
  4842. }
  4843. } else {
  4844. SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
  4845. MpiDeviceInfo_t *pdevice = NULL;
  4846. /*
  4847. * Save "Set to Avoid SCSI Bus Resets" flag
  4848. */
  4849. ioc->spi_data.bus_reset =
  4850. (le32_to_cpu(pPP2->PortFlags) &
  4851. MPI_SCSIPORTPAGE2_PORT_FLAGS_AVOID_SCSI_RESET) ?
  4852. 0 : 1 ;
  4853. /* Save the Port Page 2 data
  4854. * (reformat into a 32bit quantity)
  4855. */
  4856. data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
  4857. ioc->spi_data.PortFlags = data;
  4858. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  4859. pdevice = &pPP2->DeviceSettings[ii];
  4860. data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
  4861. (pdevice->SyncFactor << 8) | pdevice->Timeout;
  4862. ioc->spi_data.nvram[ii] = data;
  4863. }
  4864. }
  4865. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  4866. }
  4867. }
  4868. /* Update Adapter limits with those from NVRAM
  4869. * Comment: Don't need to do this. Target performance
  4870. * parameters will never exceed the adapters limits.
  4871. */
  4872. return rc;
  4873. }
  4874. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4875. /**
  4876. * mpt_readScsiDevicePageHeaders - save version and length of SDP1
  4877. * @ioc: Pointer to a Adapter Strucutre
  4878. * @portnum: IOC port number
  4879. *
  4880. * Return: -EFAULT if read of config page header fails
  4881. * or 0 if success.
  4882. */
  4883. static int
  4884. mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
  4885. {
  4886. CONFIGPARMS cfg;
  4887. ConfigPageHeader_t header;
  4888. /* Read the SCSI Device Page 1 header
  4889. */
  4890. header.PageVersion = 0;
  4891. header.PageLength = 0;
  4892. header.PageNumber = 1;
  4893. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  4894. cfg.cfghdr.hdr = &header;
  4895. cfg.physAddr = -1;
  4896. cfg.pageAddr = portnum;
  4897. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4898. cfg.dir = 0;
  4899. cfg.timeout = 0;
  4900. if (mpt_config(ioc, &cfg) != 0)
  4901. return -EFAULT;
  4902. ioc->spi_data.sdp1version = cfg.cfghdr.hdr->PageVersion;
  4903. ioc->spi_data.sdp1length = cfg.cfghdr.hdr->PageLength;
  4904. header.PageVersion = 0;
  4905. header.PageLength = 0;
  4906. header.PageNumber = 0;
  4907. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  4908. if (mpt_config(ioc, &cfg) != 0)
  4909. return -EFAULT;
  4910. ioc->spi_data.sdp0version = cfg.cfghdr.hdr->PageVersion;
  4911. ioc->spi_data.sdp0length = cfg.cfghdr.hdr->PageLength;
  4912. dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Headers: 0: version %d length %d\n",
  4913. ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
  4914. dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Headers: 1: version %d length %d\n",
  4915. ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
  4916. return 0;
  4917. }
  4918. /**
  4919. * mpt_inactive_raid_list_free - This clears this link list.
  4920. * @ioc : pointer to per adapter structure
  4921. **/
  4922. static void
  4923. mpt_inactive_raid_list_free(MPT_ADAPTER *ioc)
  4924. {
  4925. struct inactive_raid_component_info *component_info, *pNext;
  4926. if (list_empty(&ioc->raid_data.inactive_list))
  4927. return;
  4928. mutex_lock(&ioc->raid_data.inactive_list_mutex);
  4929. list_for_each_entry_safe(component_info, pNext,
  4930. &ioc->raid_data.inactive_list, list) {
  4931. list_del(&component_info->list);
  4932. kfree(component_info);
  4933. }
  4934. mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  4935. }
  4936. /**
  4937. * mpt_inactive_raid_volumes - sets up link list of phy_disk_nums for devices belonging in an inactive volume
  4938. *
  4939. * @ioc : pointer to per adapter structure
  4940. * @channel : volume channel
  4941. * @id : volume target id
  4942. **/
  4943. static void
  4944. mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
  4945. {
  4946. CONFIGPARMS cfg;
  4947. ConfigPageHeader_t hdr;
  4948. dma_addr_t dma_handle;
  4949. pRaidVolumePage0_t buffer = NULL;
  4950. int i;
  4951. RaidPhysDiskPage0_t phys_disk;
  4952. struct inactive_raid_component_info *component_info;
  4953. int handle_inactive_volumes;
  4954. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  4955. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  4956. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
  4957. cfg.pageAddr = (channel << 8) + id;
  4958. cfg.cfghdr.hdr = &hdr;
  4959. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4960. if (mpt_config(ioc, &cfg) != 0)
  4961. goto out;
  4962. if (!hdr.PageLength)
  4963. goto out;
  4964. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  4965. &dma_handle);
  4966. if (!buffer)
  4967. goto out;
  4968. cfg.physAddr = dma_handle;
  4969. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4970. if (mpt_config(ioc, &cfg) != 0)
  4971. goto out;
  4972. if (!buffer->NumPhysDisks)
  4973. goto out;
  4974. handle_inactive_volumes =
  4975. (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE ||
  4976. (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED) == 0 ||
  4977. buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_FAILED ||
  4978. buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_MISSING) ? 1 : 0;
  4979. if (!handle_inactive_volumes)
  4980. goto out;
  4981. mutex_lock(&ioc->raid_data.inactive_list_mutex);
  4982. for (i = 0; i < buffer->NumPhysDisks; i++) {
  4983. if(mpt_raid_phys_disk_pg0(ioc,
  4984. buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
  4985. continue;
  4986. if ((component_info = kmalloc(sizeof (*component_info),
  4987. GFP_KERNEL)) == NULL)
  4988. continue;
  4989. component_info->volumeID = id;
  4990. component_info->volumeBus = channel;
  4991. component_info->d.PhysDiskNum = phys_disk.PhysDiskNum;
  4992. component_info->d.PhysDiskBus = phys_disk.PhysDiskBus;
  4993. component_info->d.PhysDiskID = phys_disk.PhysDiskID;
  4994. component_info->d.PhysDiskIOC = phys_disk.PhysDiskIOC;
  4995. list_add_tail(&component_info->list,
  4996. &ioc->raid_data.inactive_list);
  4997. }
  4998. mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  4999. out:
  5000. if (buffer)
  5001. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  5002. dma_handle);
  5003. }
  5004. /**
  5005. * mpt_raid_phys_disk_pg0 - returns phys disk page zero
  5006. * @ioc: Pointer to a Adapter Structure
  5007. * @phys_disk_num: io unit unique phys disk num generated by the ioc
  5008. * @phys_disk: requested payload data returned
  5009. *
  5010. * Return:
  5011. * 0 on success
  5012. * -EFAULT if read of config page header fails or data pointer not NULL
  5013. * -ENOMEM if pci_alloc failed
  5014. **/
  5015. int
  5016. mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num,
  5017. RaidPhysDiskPage0_t *phys_disk)
  5018. {
  5019. CONFIGPARMS cfg;
  5020. ConfigPageHeader_t hdr;
  5021. dma_addr_t dma_handle;
  5022. pRaidPhysDiskPage0_t buffer = NULL;
  5023. int rc;
  5024. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  5025. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  5026. memset(phys_disk, 0, sizeof(RaidPhysDiskPage0_t));
  5027. hdr.PageVersion = MPI_RAIDPHYSDISKPAGE0_PAGEVERSION;
  5028. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
  5029. cfg.cfghdr.hdr = &hdr;
  5030. cfg.physAddr = -1;
  5031. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5032. if (mpt_config(ioc, &cfg) != 0) {
  5033. rc = -EFAULT;
  5034. goto out;
  5035. }
  5036. if (!hdr.PageLength) {
  5037. rc = -EFAULT;
  5038. goto out;
  5039. }
  5040. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  5041. &dma_handle);
  5042. if (!buffer) {
  5043. rc = -ENOMEM;
  5044. goto out;
  5045. }
  5046. cfg.physAddr = dma_handle;
  5047. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5048. cfg.pageAddr = phys_disk_num;
  5049. if (mpt_config(ioc, &cfg) != 0) {
  5050. rc = -EFAULT;
  5051. goto out;
  5052. }
  5053. rc = 0;
  5054. memcpy(phys_disk, buffer, sizeof(*buffer));
  5055. phys_disk->MaxLBA = le32_to_cpu(buffer->MaxLBA);
  5056. out:
  5057. if (buffer)
  5058. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  5059. dma_handle);
  5060. return rc;
  5061. }
  5062. /**
  5063. * mpt_raid_phys_disk_get_num_paths - returns number paths associated to this phys_num
  5064. * @ioc: Pointer to a Adapter Structure
  5065. * @phys_disk_num: io unit unique phys disk num generated by the ioc
  5066. *
  5067. * Return:
  5068. * returns number paths
  5069. **/
  5070. int
  5071. mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER *ioc, u8 phys_disk_num)
  5072. {
  5073. CONFIGPARMS cfg;
  5074. ConfigPageHeader_t hdr;
  5075. dma_addr_t dma_handle;
  5076. pRaidPhysDiskPage1_t buffer = NULL;
  5077. int rc;
  5078. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  5079. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  5080. hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
  5081. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
  5082. hdr.PageNumber = 1;
  5083. cfg.cfghdr.hdr = &hdr;
  5084. cfg.physAddr = -1;
  5085. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5086. if (mpt_config(ioc, &cfg) != 0) {
  5087. rc = 0;
  5088. goto out;
  5089. }
  5090. if (!hdr.PageLength) {
  5091. rc = 0;
  5092. goto out;
  5093. }
  5094. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  5095. &dma_handle);
  5096. if (!buffer) {
  5097. rc = 0;
  5098. goto out;
  5099. }
  5100. cfg.physAddr = dma_handle;
  5101. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5102. cfg.pageAddr = phys_disk_num;
  5103. if (mpt_config(ioc, &cfg) != 0) {
  5104. rc = 0;
  5105. goto out;
  5106. }
  5107. rc = buffer->NumPhysDiskPaths;
  5108. out:
  5109. if (buffer)
  5110. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  5111. dma_handle);
  5112. return rc;
  5113. }
  5114. EXPORT_SYMBOL(mpt_raid_phys_disk_get_num_paths);
  5115. /**
  5116. * mpt_raid_phys_disk_pg1 - returns phys disk page 1
  5117. * @ioc: Pointer to a Adapter Structure
  5118. * @phys_disk_num: io unit unique phys disk num generated by the ioc
  5119. * @phys_disk: requested payload data returned
  5120. *
  5121. * Return:
  5122. * 0 on success
  5123. * -EFAULT if read of config page header fails or data pointer not NULL
  5124. * -ENOMEM if pci_alloc failed
  5125. **/
  5126. int
  5127. mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num,
  5128. RaidPhysDiskPage1_t *phys_disk)
  5129. {
  5130. CONFIGPARMS cfg;
  5131. ConfigPageHeader_t hdr;
  5132. dma_addr_t dma_handle;
  5133. pRaidPhysDiskPage1_t buffer = NULL;
  5134. int rc;
  5135. int i;
  5136. __le64 sas_address;
  5137. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  5138. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  5139. rc = 0;
  5140. hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
  5141. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
  5142. hdr.PageNumber = 1;
  5143. cfg.cfghdr.hdr = &hdr;
  5144. cfg.physAddr = -1;
  5145. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5146. if (mpt_config(ioc, &cfg) != 0) {
  5147. rc = -EFAULT;
  5148. goto out;
  5149. }
  5150. if (!hdr.PageLength) {
  5151. rc = -EFAULT;
  5152. goto out;
  5153. }
  5154. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  5155. &dma_handle);
  5156. if (!buffer) {
  5157. rc = -ENOMEM;
  5158. goto out;
  5159. }
  5160. cfg.physAddr = dma_handle;
  5161. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5162. cfg.pageAddr = phys_disk_num;
  5163. if (mpt_config(ioc, &cfg) != 0) {
  5164. rc = -EFAULT;
  5165. goto out;
  5166. }
  5167. phys_disk->NumPhysDiskPaths = buffer->NumPhysDiskPaths;
  5168. phys_disk->PhysDiskNum = phys_disk_num;
  5169. for (i = 0; i < phys_disk->NumPhysDiskPaths; i++) {
  5170. phys_disk->Path[i].PhysDiskID = buffer->Path[i].PhysDiskID;
  5171. phys_disk->Path[i].PhysDiskBus = buffer->Path[i].PhysDiskBus;
  5172. phys_disk->Path[i].OwnerIdentifier =
  5173. buffer->Path[i].OwnerIdentifier;
  5174. phys_disk->Path[i].Flags = le16_to_cpu(buffer->Path[i].Flags);
  5175. memcpy(&sas_address, &buffer->Path[i].WWID, sizeof(__le64));
  5176. sas_address = le64_to_cpu(sas_address);
  5177. memcpy(&phys_disk->Path[i].WWID, &sas_address, sizeof(__le64));
  5178. memcpy(&sas_address,
  5179. &buffer->Path[i].OwnerWWID, sizeof(__le64));
  5180. sas_address = le64_to_cpu(sas_address);
  5181. memcpy(&phys_disk->Path[i].OwnerWWID,
  5182. &sas_address, sizeof(__le64));
  5183. }
  5184. out:
  5185. if (buffer)
  5186. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  5187. dma_handle);
  5188. return rc;
  5189. }
  5190. EXPORT_SYMBOL(mpt_raid_phys_disk_pg1);
  5191. /**
  5192. * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
  5193. * @ioc: Pointer to a Adapter Strucutre
  5194. *
  5195. * Return:
  5196. * 0 on success
  5197. * -EFAULT if read of config page header fails or data pointer not NULL
  5198. * -ENOMEM if pci_alloc failed
  5199. **/
  5200. int
  5201. mpt_findImVolumes(MPT_ADAPTER *ioc)
  5202. {
  5203. IOCPage2_t *pIoc2;
  5204. u8 *mem;
  5205. dma_addr_t ioc2_dma;
  5206. CONFIGPARMS cfg;
  5207. ConfigPageHeader_t header;
  5208. int rc = 0;
  5209. int iocpage2sz;
  5210. int i;
  5211. if (!ioc->ir_firmware)
  5212. return 0;
  5213. /* Free the old page
  5214. */
  5215. kfree(ioc->raid_data.pIocPg2);
  5216. ioc->raid_data.pIocPg2 = NULL;
  5217. mpt_inactive_raid_list_free(ioc);
  5218. /* Read IOCP2 header then the page.
  5219. */
  5220. header.PageVersion = 0;
  5221. header.PageLength = 0;
  5222. header.PageNumber = 2;
  5223. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  5224. cfg.cfghdr.hdr = &header;
  5225. cfg.physAddr = -1;
  5226. cfg.pageAddr = 0;
  5227. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5228. cfg.dir = 0;
  5229. cfg.timeout = 0;
  5230. if (mpt_config(ioc, &cfg) != 0)
  5231. return -EFAULT;
  5232. if (header.PageLength == 0)
  5233. return -EFAULT;
  5234. iocpage2sz = header.PageLength * 4;
  5235. pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
  5236. if (!pIoc2)
  5237. return -ENOMEM;
  5238. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5239. cfg.physAddr = ioc2_dma;
  5240. if (mpt_config(ioc, &cfg) != 0)
  5241. goto out;
  5242. mem = kmalloc(iocpage2sz, GFP_KERNEL);
  5243. if (!mem) {
  5244. rc = -ENOMEM;
  5245. goto out;
  5246. }
  5247. memcpy(mem, (u8 *)pIoc2, iocpage2sz);
  5248. ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
  5249. mpt_read_ioc_pg_3(ioc);
  5250. for (i = 0; i < pIoc2->NumActiveVolumes ; i++)
  5251. mpt_inactive_raid_volumes(ioc,
  5252. pIoc2->RaidVolume[i].VolumeBus,
  5253. pIoc2->RaidVolume[i].VolumeID);
  5254. out:
  5255. pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
  5256. return rc;
  5257. }
  5258. static int
  5259. mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
  5260. {
  5261. IOCPage3_t *pIoc3;
  5262. u8 *mem;
  5263. CONFIGPARMS cfg;
  5264. ConfigPageHeader_t header;
  5265. dma_addr_t ioc3_dma;
  5266. int iocpage3sz = 0;
  5267. /* Free the old page
  5268. */
  5269. kfree(ioc->raid_data.pIocPg3);
  5270. ioc->raid_data.pIocPg3 = NULL;
  5271. /* There is at least one physical disk.
  5272. * Read and save IOC Page 3
  5273. */
  5274. header.PageVersion = 0;
  5275. header.PageLength = 0;
  5276. header.PageNumber = 3;
  5277. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  5278. cfg.cfghdr.hdr = &header;
  5279. cfg.physAddr = -1;
  5280. cfg.pageAddr = 0;
  5281. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5282. cfg.dir = 0;
  5283. cfg.timeout = 0;
  5284. if (mpt_config(ioc, &cfg) != 0)
  5285. return 0;
  5286. if (header.PageLength == 0)
  5287. return 0;
  5288. /* Read Header good, alloc memory
  5289. */
  5290. iocpage3sz = header.PageLength * 4;
  5291. pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
  5292. if (!pIoc3)
  5293. return 0;
  5294. /* Read the Page and save the data
  5295. * into malloc'd memory.
  5296. */
  5297. cfg.physAddr = ioc3_dma;
  5298. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5299. if (mpt_config(ioc, &cfg) == 0) {
  5300. mem = kmalloc(iocpage3sz, GFP_KERNEL);
  5301. if (mem) {
  5302. memcpy(mem, (u8 *)pIoc3, iocpage3sz);
  5303. ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;
  5304. }
  5305. }
  5306. pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
  5307. return 0;
  5308. }
  5309. static void
  5310. mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
  5311. {
  5312. IOCPage4_t *pIoc4;
  5313. CONFIGPARMS cfg;
  5314. ConfigPageHeader_t header;
  5315. dma_addr_t ioc4_dma;
  5316. int iocpage4sz;
  5317. /* Read and save IOC Page 4
  5318. */
  5319. header.PageVersion = 0;
  5320. header.PageLength = 0;
  5321. header.PageNumber = 4;
  5322. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  5323. cfg.cfghdr.hdr = &header;
  5324. cfg.physAddr = -1;
  5325. cfg.pageAddr = 0;
  5326. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5327. cfg.dir = 0;
  5328. cfg.timeout = 0;
  5329. if (mpt_config(ioc, &cfg) != 0)
  5330. return;
  5331. if (header.PageLength == 0)
  5332. return;
  5333. if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
  5334. iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
  5335. pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
  5336. if (!pIoc4)
  5337. return;
  5338. ioc->alloc_total += iocpage4sz;
  5339. } else {
  5340. ioc4_dma = ioc->spi_data.IocPg4_dma;
  5341. iocpage4sz = ioc->spi_data.IocPg4Sz;
  5342. }
  5343. /* Read the Page into dma memory.
  5344. */
  5345. cfg.physAddr = ioc4_dma;
  5346. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5347. if (mpt_config(ioc, &cfg) == 0) {
  5348. ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
  5349. ioc->spi_data.IocPg4_dma = ioc4_dma;
  5350. ioc->spi_data.IocPg4Sz = iocpage4sz;
  5351. } else {
  5352. pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
  5353. ioc->spi_data.pIocPg4 = NULL;
  5354. ioc->alloc_total -= iocpage4sz;
  5355. }
  5356. }
  5357. static void
  5358. mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
  5359. {
  5360. IOCPage1_t *pIoc1;
  5361. CONFIGPARMS cfg;
  5362. ConfigPageHeader_t header;
  5363. dma_addr_t ioc1_dma;
  5364. int iocpage1sz = 0;
  5365. u32 tmp;
  5366. /* Check the Coalescing Timeout in IOC Page 1
  5367. */
  5368. header.PageVersion = 0;
  5369. header.PageLength = 0;
  5370. header.PageNumber = 1;
  5371. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  5372. cfg.cfghdr.hdr = &header;
  5373. cfg.physAddr = -1;
  5374. cfg.pageAddr = 0;
  5375. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5376. cfg.dir = 0;
  5377. cfg.timeout = 0;
  5378. if (mpt_config(ioc, &cfg) != 0)
  5379. return;
  5380. if (header.PageLength == 0)
  5381. return;
  5382. /* Read Header good, alloc memory
  5383. */
  5384. iocpage1sz = header.PageLength * 4;
  5385. pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
  5386. if (!pIoc1)
  5387. return;
  5388. /* Read the Page and check coalescing timeout
  5389. */
  5390. cfg.physAddr = ioc1_dma;
  5391. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5392. if (mpt_config(ioc, &cfg) == 0) {
  5393. tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
  5394. if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
  5395. tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
  5396. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Coalescing Enabled Timeout = %d\n",
  5397. ioc->name, tmp));
  5398. if (tmp > MPT_COALESCING_TIMEOUT) {
  5399. pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
  5400. /* Write NVRAM and current
  5401. */
  5402. cfg.dir = 1;
  5403. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  5404. if (mpt_config(ioc, &cfg) == 0) {
  5405. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Reset Current Coalescing Timeout to = %d\n",
  5406. ioc->name, MPT_COALESCING_TIMEOUT));
  5407. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
  5408. if (mpt_config(ioc, &cfg) == 0) {
  5409. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5410. "Reset NVRAM Coalescing Timeout to = %d\n",
  5411. ioc->name, MPT_COALESCING_TIMEOUT));
  5412. } else {
  5413. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5414. "Reset NVRAM Coalescing Timeout Failed\n",
  5415. ioc->name));
  5416. }
  5417. } else {
  5418. dprintk(ioc, printk(MYIOC_s_WARN_FMT
  5419. "Reset of Current Coalescing Timeout Failed!\n",
  5420. ioc->name));
  5421. }
  5422. }
  5423. } else {
  5424. dprintk(ioc, printk(MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
  5425. }
  5426. }
  5427. pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
  5428. return;
  5429. }
  5430. static void
  5431. mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc)
  5432. {
  5433. CONFIGPARMS cfg;
  5434. ConfigPageHeader_t hdr;
  5435. dma_addr_t buf_dma;
  5436. ManufacturingPage0_t *pbuf = NULL;
  5437. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  5438. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  5439. hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
  5440. cfg.cfghdr.hdr = &hdr;
  5441. cfg.physAddr = -1;
  5442. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5443. cfg.timeout = 10;
  5444. if (mpt_config(ioc, &cfg) != 0)
  5445. goto out;
  5446. if (!cfg.cfghdr.hdr->PageLength)
  5447. goto out;
  5448. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5449. pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
  5450. if (!pbuf)
  5451. goto out;
  5452. cfg.physAddr = buf_dma;
  5453. if (mpt_config(ioc, &cfg) != 0)
  5454. goto out;
  5455. memcpy(ioc->board_name, pbuf->BoardName, sizeof(ioc->board_name));
  5456. memcpy(ioc->board_assembly, pbuf->BoardAssembly, sizeof(ioc->board_assembly));
  5457. memcpy(ioc->board_tracer, pbuf->BoardTracerNumber, sizeof(ioc->board_tracer));
  5458. out:
  5459. if (pbuf)
  5460. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
  5461. }
  5462. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5463. /**
  5464. * SendEventNotification - Send EventNotification (on or off) request to adapter
  5465. * @ioc: Pointer to MPT_ADAPTER structure
  5466. * @EvSwitch: Event switch flags
  5467. * @sleepFlag: Specifies whether the process can sleep
  5468. */
  5469. static int
  5470. SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch, int sleepFlag)
  5471. {
  5472. EventNotification_t evn;
  5473. MPIDefaultReply_t reply_buf;
  5474. memset(&evn, 0, sizeof(EventNotification_t));
  5475. memset(&reply_buf, 0, sizeof(MPIDefaultReply_t));
  5476. evn.Function = MPI_FUNCTION_EVENT_NOTIFICATION;
  5477. evn.Switch = EvSwitch;
  5478. evn.MsgContext = cpu_to_le32(mpt_base_index << 16);
  5479. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5480. "Sending EventNotification (%d) request %p\n",
  5481. ioc->name, EvSwitch, &evn));
  5482. return mpt_handshake_req_reply_wait(ioc, sizeof(EventNotification_t),
  5483. (u32 *)&evn, sizeof(MPIDefaultReply_t), (u16 *)&reply_buf, 30,
  5484. sleepFlag);
  5485. }
  5486. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5487. /**
  5488. * SendEventAck - Send EventAck request to MPT adapter.
  5489. * @ioc: Pointer to MPT_ADAPTER structure
  5490. * @evnp: Pointer to original EventNotification request
  5491. */
  5492. static int
  5493. SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
  5494. {
  5495. EventAck_t *pAck;
  5496. if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  5497. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
  5498. ioc->name, __func__));
  5499. return -1;
  5500. }
  5501. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending EventAck\n", ioc->name));
  5502. pAck->Function = MPI_FUNCTION_EVENT_ACK;
  5503. pAck->ChainOffset = 0;
  5504. pAck->Reserved[0] = pAck->Reserved[1] = 0;
  5505. pAck->MsgFlags = 0;
  5506. pAck->Reserved1[0] = pAck->Reserved1[1] = pAck->Reserved1[2] = 0;
  5507. pAck->Event = evnp->Event;
  5508. pAck->EventContext = evnp->EventContext;
  5509. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
  5510. return 0;
  5511. }
  5512. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5513. /**
  5514. * mpt_config - Generic function to issue config message
  5515. * @ioc: Pointer to an adapter structure
  5516. * @pCfg: Pointer to a configuration structure. Struct contains
  5517. * action, page address, direction, physical address
  5518. * and pointer to a configuration page header
  5519. * Page header is updated.
  5520. *
  5521. * Returns 0 for success
  5522. * -EPERM if not allowed due to ISR context
  5523. * -EAGAIN if no msg frames currently available
  5524. * -EFAULT for non-successful reply or no reply (timeout)
  5525. */
  5526. int
  5527. mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  5528. {
  5529. Config_t *pReq;
  5530. ConfigReply_t *pReply;
  5531. ConfigExtendedPageHeader_t *pExtHdr = NULL;
  5532. MPT_FRAME_HDR *mf;
  5533. int ii;
  5534. int flagsLength;
  5535. long timeout;
  5536. int ret;
  5537. u8 page_type = 0, extend_page;
  5538. unsigned long timeleft;
  5539. unsigned long flags;
  5540. int in_isr;
  5541. u8 issue_hard_reset = 0;
  5542. u8 retry_count = 0;
  5543. /* Prevent calling wait_event() (below), if caller happens
  5544. * to be in ISR context, because that is fatal!
  5545. */
  5546. in_isr = in_interrupt();
  5547. if (in_isr) {
  5548. dcprintk(ioc, printk(MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
  5549. ioc->name));
  5550. return -EPERM;
  5551. }
  5552. /* don't send a config page during diag reset */
  5553. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  5554. if (ioc->ioc_reset_in_progress) {
  5555. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5556. "%s: busy with host reset\n", ioc->name, __func__));
  5557. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  5558. return -EBUSY;
  5559. }
  5560. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  5561. /* don't send if no chance of success */
  5562. if (!ioc->active ||
  5563. mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_OPERATIONAL) {
  5564. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5565. "%s: ioc not operational, %d, %xh\n",
  5566. ioc->name, __func__, ioc->active,
  5567. mpt_GetIocState(ioc, 0)));
  5568. return -EFAULT;
  5569. }
  5570. retry_config:
  5571. mutex_lock(&ioc->mptbase_cmds.mutex);
  5572. /* init the internal cmd struct */
  5573. memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
  5574. INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
  5575. /* Get and Populate a free Frame
  5576. */
  5577. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  5578. dcprintk(ioc, printk(MYIOC_s_WARN_FMT
  5579. "mpt_config: no msg frames!\n", ioc->name));
  5580. ret = -EAGAIN;
  5581. goto out;
  5582. }
  5583. pReq = (Config_t *)mf;
  5584. pReq->Action = pCfg->action;
  5585. pReq->Reserved = 0;
  5586. pReq->ChainOffset = 0;
  5587. pReq->Function = MPI_FUNCTION_CONFIG;
  5588. /* Assume page type is not extended and clear "reserved" fields. */
  5589. pReq->ExtPageLength = 0;
  5590. pReq->ExtPageType = 0;
  5591. pReq->MsgFlags = 0;
  5592. for (ii=0; ii < 8; ii++)
  5593. pReq->Reserved2[ii] = 0;
  5594. pReq->Header.PageVersion = pCfg->cfghdr.hdr->PageVersion;
  5595. pReq->Header.PageLength = pCfg->cfghdr.hdr->PageLength;
  5596. pReq->Header.PageNumber = pCfg->cfghdr.hdr->PageNumber;
  5597. pReq->Header.PageType = (pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
  5598. if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
  5599. pExtHdr = (ConfigExtendedPageHeader_t *)pCfg->cfghdr.ehdr;
  5600. pReq->ExtPageLength = cpu_to_le16(pExtHdr->ExtPageLength);
  5601. pReq->ExtPageType = pExtHdr->ExtPageType;
  5602. pReq->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  5603. /* Page Length must be treated as a reserved field for the
  5604. * extended header.
  5605. */
  5606. pReq->Header.PageLength = 0;
  5607. }
  5608. pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
  5609. /* Add a SGE to the config request.
  5610. */
  5611. if (pCfg->dir)
  5612. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
  5613. else
  5614. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  5615. if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) ==
  5616. MPI_CONFIG_PAGETYPE_EXTENDED) {
  5617. flagsLength |= pExtHdr->ExtPageLength * 4;
  5618. page_type = pReq->ExtPageType;
  5619. extend_page = 1;
  5620. } else {
  5621. flagsLength |= pCfg->cfghdr.hdr->PageLength * 4;
  5622. page_type = pReq->Header.PageType;
  5623. extend_page = 0;
  5624. }
  5625. dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5626. "Sending Config request type 0x%x, page 0x%x and action %d\n",
  5627. ioc->name, page_type, pReq->Header.PageNumber, pReq->Action));
  5628. ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
  5629. timeout = (pCfg->timeout < 15) ? HZ*15 : HZ*pCfg->timeout;
  5630. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  5631. timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done,
  5632. timeout);
  5633. if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  5634. ret = -ETIME;
  5635. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5636. "Failed Sending Config request type 0x%x, page 0x%x,"
  5637. " action %d, status %xh, time left %ld\n\n",
  5638. ioc->name, page_type, pReq->Header.PageNumber,
  5639. pReq->Action, ioc->mptbase_cmds.status, timeleft));
  5640. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
  5641. goto out;
  5642. if (!timeleft) {
  5643. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  5644. if (ioc->ioc_reset_in_progress) {
  5645. spin_unlock_irqrestore(&ioc->taskmgmt_lock,
  5646. flags);
  5647. printk(MYIOC_s_INFO_FMT "%s: host reset in"
  5648. " progress mpt_config timed out.!!\n",
  5649. __func__, ioc->name);
  5650. return -EFAULT;
  5651. }
  5652. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  5653. issue_hard_reset = 1;
  5654. }
  5655. goto out;
  5656. }
  5657. if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
  5658. ret = -1;
  5659. goto out;
  5660. }
  5661. pReply = (ConfigReply_t *)ioc->mptbase_cmds.reply;
  5662. ret = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  5663. if (ret == MPI_IOCSTATUS_SUCCESS) {
  5664. if (extend_page) {
  5665. pCfg->cfghdr.ehdr->ExtPageLength =
  5666. le16_to_cpu(pReply->ExtPageLength);
  5667. pCfg->cfghdr.ehdr->ExtPageType =
  5668. pReply->ExtPageType;
  5669. }
  5670. pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
  5671. pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
  5672. pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
  5673. pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
  5674. }
  5675. if (retry_count)
  5676. printk(MYIOC_s_INFO_FMT "Retry completed "
  5677. "ret=0x%x timeleft=%ld\n",
  5678. ioc->name, ret, timeleft);
  5679. dcprintk(ioc, printk(KERN_DEBUG "IOCStatus=%04xh, IOCLogInfo=%08xh\n",
  5680. ret, le32_to_cpu(pReply->IOCLogInfo)));
  5681. out:
  5682. CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
  5683. mutex_unlock(&ioc->mptbase_cmds.mutex);
  5684. if (issue_hard_reset) {
  5685. issue_hard_reset = 0;
  5686. printk(MYIOC_s_WARN_FMT
  5687. "Issuing Reset from %s!!, doorbell=0x%08x\n",
  5688. ioc->name, __func__, mpt_GetIocState(ioc, 0));
  5689. if (retry_count == 0) {
  5690. if (mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP) != 0)
  5691. retry_count++;
  5692. } else
  5693. mpt_HardResetHandler(ioc, CAN_SLEEP);
  5694. mpt_free_msg_frame(ioc, mf);
  5695. /* attempt one retry for a timed out command */
  5696. if (retry_count < 2) {
  5697. printk(MYIOC_s_INFO_FMT
  5698. "Attempting Retry Config request"
  5699. " type 0x%x, page 0x%x,"
  5700. " action %d\n", ioc->name, page_type,
  5701. pCfg->cfghdr.hdr->PageNumber, pCfg->action);
  5702. retry_count++;
  5703. goto retry_config;
  5704. }
  5705. }
  5706. return ret;
  5707. }
  5708. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5709. /**
  5710. * mpt_ioc_reset - Base cleanup for hard reset
  5711. * @ioc: Pointer to the adapter structure
  5712. * @reset_phase: Indicates pre- or post-reset functionality
  5713. *
  5714. * Remark: Frees resources with internally generated commands.
  5715. */
  5716. static int
  5717. mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  5718. {
  5719. switch (reset_phase) {
  5720. case MPT_IOC_SETUP_RESET:
  5721. ioc->taskmgmt_quiesce_io = 1;
  5722. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5723. "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
  5724. break;
  5725. case MPT_IOC_PRE_RESET:
  5726. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5727. "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
  5728. break;
  5729. case MPT_IOC_POST_RESET:
  5730. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5731. "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
  5732. /* wake up mptbase_cmds */
  5733. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
  5734. ioc->mptbase_cmds.status |=
  5735. MPT_MGMT_STATUS_DID_IOCRESET;
  5736. complete(&ioc->mptbase_cmds.done);
  5737. }
  5738. /* wake up taskmgmt_cmds */
  5739. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
  5740. ioc->taskmgmt_cmds.status |=
  5741. MPT_MGMT_STATUS_DID_IOCRESET;
  5742. complete(&ioc->taskmgmt_cmds.done);
  5743. }
  5744. break;
  5745. default:
  5746. break;
  5747. }
  5748. return 1; /* currently means nothing really */
  5749. }
  5750. #ifdef CONFIG_PROC_FS /* { */
  5751. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5752. /*
  5753. * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
  5754. */
  5755. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5756. /**
  5757. * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
  5758. *
  5759. * Returns 0 for success, non-zero for failure.
  5760. */
  5761. static int
  5762. procmpt_create(void)
  5763. {
  5764. mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
  5765. if (mpt_proc_root_dir == NULL)
  5766. return -ENOTDIR;
  5767. proc_create("summary", S_IRUGO, mpt_proc_root_dir, &mpt_summary_proc_fops);
  5768. proc_create("version", S_IRUGO, mpt_proc_root_dir, &mpt_version_proc_fops);
  5769. return 0;
  5770. }
  5771. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5772. /**
  5773. * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
  5774. *
  5775. * Returns 0 for success, non-zero for failure.
  5776. */
  5777. static void
  5778. procmpt_destroy(void)
  5779. {
  5780. remove_proc_entry("version", mpt_proc_root_dir);
  5781. remove_proc_entry("summary", mpt_proc_root_dir);
  5782. remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
  5783. }
  5784. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5785. /*
  5786. * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
  5787. */
  5788. static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan);
  5789. static int mpt_summary_proc_show(struct seq_file *m, void *v)
  5790. {
  5791. MPT_ADAPTER *ioc = m->private;
  5792. if (ioc) {
  5793. seq_mpt_print_ioc_summary(ioc, m, 1);
  5794. } else {
  5795. list_for_each_entry(ioc, &ioc_list, list) {
  5796. seq_mpt_print_ioc_summary(ioc, m, 1);
  5797. }
  5798. }
  5799. return 0;
  5800. }
  5801. static int mpt_summary_proc_open(struct inode *inode, struct file *file)
  5802. {
  5803. return single_open(file, mpt_summary_proc_show, PDE(inode)->data);
  5804. }
  5805. static const struct file_operations mpt_summary_proc_fops = {
  5806. .owner = THIS_MODULE,
  5807. .open = mpt_summary_proc_open,
  5808. .read = seq_read,
  5809. .llseek = seq_lseek,
  5810. .release = single_release,
  5811. };
  5812. static int mpt_version_proc_show(struct seq_file *m, void *v)
  5813. {
  5814. u8 cb_idx;
  5815. int scsi, fc, sas, lan, ctl, targ, dmp;
  5816. char *drvname;
  5817. seq_printf(m, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
  5818. seq_printf(m, " Fusion MPT base driver\n");
  5819. scsi = fc = sas = lan = ctl = targ = dmp = 0;
  5820. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  5821. drvname = NULL;
  5822. if (MptCallbacks[cb_idx]) {
  5823. switch (MptDriverClass[cb_idx]) {
  5824. case MPTSPI_DRIVER:
  5825. if (!scsi++) drvname = "SPI host";
  5826. break;
  5827. case MPTFC_DRIVER:
  5828. if (!fc++) drvname = "FC host";
  5829. break;
  5830. case MPTSAS_DRIVER:
  5831. if (!sas++) drvname = "SAS host";
  5832. break;
  5833. case MPTLAN_DRIVER:
  5834. if (!lan++) drvname = "LAN";
  5835. break;
  5836. case MPTSTM_DRIVER:
  5837. if (!targ++) drvname = "SCSI target";
  5838. break;
  5839. case MPTCTL_DRIVER:
  5840. if (!ctl++) drvname = "ioctl";
  5841. break;
  5842. }
  5843. if (drvname)
  5844. seq_printf(m, " Fusion MPT %s driver\n", drvname);
  5845. }
  5846. }
  5847. return 0;
  5848. }
  5849. static int mpt_version_proc_open(struct inode *inode, struct file *file)
  5850. {
  5851. return single_open(file, mpt_version_proc_show, NULL);
  5852. }
  5853. static const struct file_operations mpt_version_proc_fops = {
  5854. .owner = THIS_MODULE,
  5855. .open = mpt_version_proc_open,
  5856. .read = seq_read,
  5857. .llseek = seq_lseek,
  5858. .release = single_release,
  5859. };
  5860. static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
  5861. {
  5862. MPT_ADAPTER *ioc = m->private;
  5863. char expVer[32];
  5864. int sz;
  5865. int p;
  5866. mpt_get_fw_exp_ver(expVer, ioc);
  5867. seq_printf(m, "%s:", ioc->name);
  5868. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  5869. seq_printf(m, " (f/w download boot flag set)");
  5870. // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
  5871. // seq_printf(m, " CONFIG_CHECKSUM_FAIL!");
  5872. seq_printf(m, "\n ProductID = 0x%04x (%s)\n",
  5873. ioc->facts.ProductID,
  5874. ioc->prod_name);
  5875. seq_printf(m, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
  5876. if (ioc->facts.FWImageSize)
  5877. seq_printf(m, " (fw_size=%d)", ioc->facts.FWImageSize);
  5878. seq_printf(m, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
  5879. seq_printf(m, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
  5880. seq_printf(m, " EventState = 0x%02x\n", ioc->facts.EventState);
  5881. seq_printf(m, " CurrentHostMfaHighAddr = 0x%08x\n",
  5882. ioc->facts.CurrentHostMfaHighAddr);
  5883. seq_printf(m, " CurrentSenseBufferHighAddr = 0x%08x\n",
  5884. ioc->facts.CurrentSenseBufferHighAddr);
  5885. seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
  5886. seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
  5887. seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
  5888. (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
  5889. /*
  5890. * Rounding UP to nearest 4-kB boundary here...
  5891. */
  5892. sz = (ioc->req_sz * ioc->req_depth) + 128;
  5893. sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
  5894. seq_printf(m, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
  5895. ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
  5896. seq_printf(m, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
  5897. 4*ioc->facts.RequestFrameSize,
  5898. ioc->facts.GlobalCredits);
  5899. seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
  5900. (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
  5901. sz = (ioc->reply_sz * ioc->reply_depth) + 128;
  5902. seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
  5903. ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
  5904. seq_printf(m, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
  5905. ioc->facts.CurReplyFrameSize,
  5906. ioc->facts.ReplyQueueDepth);
  5907. seq_printf(m, " MaxDevices = %d\n",
  5908. (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
  5909. seq_printf(m, " MaxBuses = %d\n", ioc->facts.MaxBuses);
  5910. /* per-port info */
  5911. for (p=0; p < ioc->facts.NumberOfPorts; p++) {
  5912. seq_printf(m, " PortNumber = %d (of %d)\n",
  5913. p+1,
  5914. ioc->facts.NumberOfPorts);
  5915. if (ioc->bus_type == FC) {
  5916. if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  5917. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  5918. seq_printf(m, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
  5919. a[5], a[4], a[3], a[2], a[1], a[0]);
  5920. }
  5921. seq_printf(m, " WWN = %08X%08X:%08X%08X\n",
  5922. ioc->fc_port_page0[p].WWNN.High,
  5923. ioc->fc_port_page0[p].WWNN.Low,
  5924. ioc->fc_port_page0[p].WWPN.High,
  5925. ioc->fc_port_page0[p].WWPN.Low);
  5926. }
  5927. }
  5928. return 0;
  5929. }
  5930. static int mpt_iocinfo_proc_open(struct inode *inode, struct file *file)
  5931. {
  5932. return single_open(file, mpt_iocinfo_proc_show, PDE(inode)->data);
  5933. }
  5934. static const struct file_operations mpt_iocinfo_proc_fops = {
  5935. .owner = THIS_MODULE,
  5936. .open = mpt_iocinfo_proc_open,
  5937. .read = seq_read,
  5938. .llseek = seq_lseek,
  5939. .release = single_release,
  5940. };
  5941. #endif /* CONFIG_PROC_FS } */
  5942. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5943. static void
  5944. mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
  5945. {
  5946. buf[0] ='\0';
  5947. if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
  5948. sprintf(buf, " (Exp %02d%02d)",
  5949. (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
  5950. (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
  5951. /* insider hack! */
  5952. if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
  5953. strcat(buf, " [MDBG]");
  5954. }
  5955. }
  5956. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5957. /**
  5958. * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
  5959. * @ioc: Pointer to MPT_ADAPTER structure
  5960. * @buffer: Pointer to buffer where IOC summary info should be written
  5961. * @size: Pointer to number of bytes we wrote (set by this routine)
  5962. * @len: Offset at which to start writing in buffer
  5963. * @showlan: Display LAN stuff?
  5964. *
  5965. * This routine writes (english readable) ASCII text, which represents
  5966. * a summary of IOC information, to a buffer.
  5967. */
  5968. void
  5969. mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
  5970. {
  5971. char expVer[32];
  5972. int y;
  5973. mpt_get_fw_exp_ver(expVer, ioc);
  5974. /*
  5975. * Shorter summary of attached ioc's...
  5976. */
  5977. y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
  5978. ioc->name,
  5979. ioc->prod_name,
  5980. MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
  5981. ioc->facts.FWVersion.Word,
  5982. expVer,
  5983. ioc->facts.NumberOfPorts,
  5984. ioc->req_depth);
  5985. if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
  5986. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  5987. y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
  5988. a[5], a[4], a[3], a[2], a[1], a[0]);
  5989. }
  5990. y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
  5991. if (!ioc->active)
  5992. y += sprintf(buffer+len+y, " (disabled)");
  5993. y += sprintf(buffer+len+y, "\n");
  5994. *size = y;
  5995. }
  5996. static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan)
  5997. {
  5998. char expVer[32];
  5999. mpt_get_fw_exp_ver(expVer, ioc);
  6000. /*
  6001. * Shorter summary of attached ioc's...
  6002. */
  6003. seq_printf(m, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
  6004. ioc->name,
  6005. ioc->prod_name,
  6006. MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
  6007. ioc->facts.FWVersion.Word,
  6008. expVer,
  6009. ioc->facts.NumberOfPorts,
  6010. ioc->req_depth);
  6011. if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
  6012. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  6013. seq_printf(m, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
  6014. a[5], a[4], a[3], a[2], a[1], a[0]);
  6015. }
  6016. seq_printf(m, ", IRQ=%d", ioc->pci_irq);
  6017. if (!ioc->active)
  6018. seq_printf(m, " (disabled)");
  6019. seq_putc(m, '\n');
  6020. }
  6021. /**
  6022. * mpt_set_taskmgmt_in_progress_flag - set flags associated with task management
  6023. * @ioc: Pointer to MPT_ADAPTER structure
  6024. *
  6025. * Returns 0 for SUCCESS or -1 if FAILED.
  6026. *
  6027. * If -1 is return, then it was not possible to set the flags
  6028. **/
  6029. int
  6030. mpt_set_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
  6031. {
  6032. unsigned long flags;
  6033. int retval;
  6034. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6035. if (ioc->ioc_reset_in_progress || ioc->taskmgmt_in_progress ||
  6036. (ioc->alt_ioc && ioc->alt_ioc->taskmgmt_in_progress)) {
  6037. retval = -1;
  6038. goto out;
  6039. }
  6040. retval = 0;
  6041. ioc->taskmgmt_in_progress = 1;
  6042. ioc->taskmgmt_quiesce_io = 1;
  6043. if (ioc->alt_ioc) {
  6044. ioc->alt_ioc->taskmgmt_in_progress = 1;
  6045. ioc->alt_ioc->taskmgmt_quiesce_io = 1;
  6046. }
  6047. out:
  6048. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6049. return retval;
  6050. }
  6051. EXPORT_SYMBOL(mpt_set_taskmgmt_in_progress_flag);
  6052. /**
  6053. * mpt_clear_taskmgmt_in_progress_flag - clear flags associated with task management
  6054. * @ioc: Pointer to MPT_ADAPTER structure
  6055. *
  6056. **/
  6057. void
  6058. mpt_clear_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
  6059. {
  6060. unsigned long flags;
  6061. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6062. ioc->taskmgmt_in_progress = 0;
  6063. ioc->taskmgmt_quiesce_io = 0;
  6064. if (ioc->alt_ioc) {
  6065. ioc->alt_ioc->taskmgmt_in_progress = 0;
  6066. ioc->alt_ioc->taskmgmt_quiesce_io = 0;
  6067. }
  6068. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6069. }
  6070. EXPORT_SYMBOL(mpt_clear_taskmgmt_in_progress_flag);
  6071. /**
  6072. * mpt_halt_firmware - Halts the firmware if it is operational and panic
  6073. * the kernel
  6074. * @ioc: Pointer to MPT_ADAPTER structure
  6075. *
  6076. **/
  6077. void
  6078. mpt_halt_firmware(MPT_ADAPTER *ioc)
  6079. {
  6080. u32 ioc_raw_state;
  6081. ioc_raw_state = mpt_GetIocState(ioc, 0);
  6082. if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
  6083. printk(MYIOC_s_ERR_FMT "IOC is in FAULT state (%04xh)!!!\n",
  6084. ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
  6085. panic("%s: IOC Fault (%04xh)!!!\n", ioc->name,
  6086. ioc_raw_state & MPI_DOORBELL_DATA_MASK);
  6087. } else {
  6088. CHIPREG_WRITE32(&ioc->chip->Doorbell, 0xC0FFEE00);
  6089. panic("%s: Firmware is halted due to command timeout\n",
  6090. ioc->name);
  6091. }
  6092. }
  6093. EXPORT_SYMBOL(mpt_halt_firmware);
  6094. /**
  6095. * mpt_SoftResetHandler - Issues a less expensive reset
  6096. * @ioc: Pointer to MPT_ADAPTER structure
  6097. * @sleepFlag: Indicates if sleep or schedule must be called.
  6098. *
  6099. * Returns 0 for SUCCESS or -1 if FAILED.
  6100. *
  6101. * Message Unit Reset - instructs the IOC to reset the Reply Post and
  6102. * Free FIFO's. All the Message Frames on Reply Free FIFO are discarded.
  6103. * All posted buffers are freed, and event notification is turned off.
  6104. * IOC doesn't reply to any outstanding request. This will transfer IOC
  6105. * to READY state.
  6106. **/
  6107. int
  6108. mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  6109. {
  6110. int rc;
  6111. int ii;
  6112. u8 cb_idx;
  6113. unsigned long flags;
  6114. u32 ioc_state;
  6115. unsigned long time_count;
  6116. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SoftResetHandler Entered!\n",
  6117. ioc->name));
  6118. ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
  6119. if (mpt_fwfault_debug)
  6120. mpt_halt_firmware(ioc);
  6121. if (ioc_state == MPI_IOC_STATE_FAULT ||
  6122. ioc_state == MPI_IOC_STATE_RESET) {
  6123. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6124. "skipping, either in FAULT or RESET state!\n", ioc->name));
  6125. return -1;
  6126. }
  6127. if (ioc->bus_type == FC) {
  6128. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6129. "skipping, because the bus type is FC!\n", ioc->name));
  6130. return -1;
  6131. }
  6132. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6133. if (ioc->ioc_reset_in_progress) {
  6134. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6135. return -1;
  6136. }
  6137. ioc->ioc_reset_in_progress = 1;
  6138. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6139. rc = -1;
  6140. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6141. if (MptResetHandlers[cb_idx])
  6142. mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
  6143. }
  6144. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6145. if (ioc->taskmgmt_in_progress) {
  6146. ioc->ioc_reset_in_progress = 0;
  6147. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6148. return -1;
  6149. }
  6150. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6151. /* Disable reply interrupts (also blocks FreeQ) */
  6152. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  6153. ioc->active = 0;
  6154. time_count = jiffies;
  6155. rc = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
  6156. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6157. if (MptResetHandlers[cb_idx])
  6158. mpt_signal_reset(cb_idx, ioc, MPT_IOC_PRE_RESET);
  6159. }
  6160. if (rc)
  6161. goto out;
  6162. ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
  6163. if (ioc_state != MPI_IOC_STATE_READY)
  6164. goto out;
  6165. for (ii = 0; ii < 5; ii++) {
  6166. /* Get IOC facts! Allow 5 retries */
  6167. rc = GetIocFacts(ioc, sleepFlag,
  6168. MPT_HOSTEVENT_IOC_RECOVER);
  6169. if (rc == 0)
  6170. break;
  6171. if (sleepFlag == CAN_SLEEP)
  6172. msleep(100);
  6173. else
  6174. mdelay(100);
  6175. }
  6176. if (ii == 5)
  6177. goto out;
  6178. rc = PrimeIocFifos(ioc);
  6179. if (rc != 0)
  6180. goto out;
  6181. rc = SendIocInit(ioc, sleepFlag);
  6182. if (rc != 0)
  6183. goto out;
  6184. rc = SendEventNotification(ioc, 1, sleepFlag);
  6185. if (rc != 0)
  6186. goto out;
  6187. if (ioc->hard_resets < -1)
  6188. ioc->hard_resets++;
  6189. /*
  6190. * At this point, we know soft reset succeeded.
  6191. */
  6192. ioc->active = 1;
  6193. CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
  6194. out:
  6195. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6196. ioc->ioc_reset_in_progress = 0;
  6197. ioc->taskmgmt_quiesce_io = 0;
  6198. ioc->taskmgmt_in_progress = 0;
  6199. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6200. if (ioc->active) { /* otherwise, hard reset coming */
  6201. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6202. if (MptResetHandlers[cb_idx])
  6203. mpt_signal_reset(cb_idx, ioc,
  6204. MPT_IOC_POST_RESET);
  6205. }
  6206. }
  6207. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6208. "SoftResetHandler: completed (%d seconds): %s\n",
  6209. ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
  6210. ((rc == 0) ? "SUCCESS" : "FAILED")));
  6211. return rc;
  6212. }
  6213. /**
  6214. * mpt_Soft_Hard_ResetHandler - Try less expensive reset
  6215. * @ioc: Pointer to MPT_ADAPTER structure
  6216. * @sleepFlag: Indicates if sleep or schedule must be called.
  6217. *
  6218. * Returns 0 for SUCCESS or -1 if FAILED.
  6219. * Try for softreset first, only if it fails go for expensive
  6220. * HardReset.
  6221. **/
  6222. int
  6223. mpt_Soft_Hard_ResetHandler(MPT_ADAPTER *ioc, int sleepFlag) {
  6224. int ret = -1;
  6225. ret = mpt_SoftResetHandler(ioc, sleepFlag);
  6226. if (ret == 0)
  6227. return ret;
  6228. ret = mpt_HardResetHandler(ioc, sleepFlag);
  6229. return ret;
  6230. }
  6231. EXPORT_SYMBOL(mpt_Soft_Hard_ResetHandler);
  6232. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6233. /*
  6234. * Reset Handling
  6235. */
  6236. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6237. /**
  6238. * mpt_HardResetHandler - Generic reset handler
  6239. * @ioc: Pointer to MPT_ADAPTER structure
  6240. * @sleepFlag: Indicates if sleep or schedule must be called.
  6241. *
  6242. * Issues SCSI Task Management call based on input arg values.
  6243. * If TaskMgmt fails, returns associated SCSI request.
  6244. *
  6245. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  6246. * or a non-interrupt thread. In the former, must not call schedule().
  6247. *
  6248. * Note: A return of -1 is a FATAL error case, as it means a
  6249. * FW reload/initialization failed.
  6250. *
  6251. * Returns 0 for SUCCESS or -1 if FAILED.
  6252. */
  6253. int
  6254. mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  6255. {
  6256. int rc;
  6257. u8 cb_idx;
  6258. unsigned long flags;
  6259. unsigned long time_count;
  6260. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler Entered!\n", ioc->name));
  6261. #ifdef MFCNT
  6262. printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
  6263. printk("MF count 0x%x !\n", ioc->mfcnt);
  6264. #endif
  6265. if (mpt_fwfault_debug)
  6266. mpt_halt_firmware(ioc);
  6267. /* Reset the adapter. Prevent more than 1 call to
  6268. * mpt_do_ioc_recovery at any instant in time.
  6269. */
  6270. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6271. if (ioc->ioc_reset_in_progress) {
  6272. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6273. ioc->wait_on_reset_completion = 1;
  6274. do {
  6275. ssleep(1);
  6276. } while (ioc->ioc_reset_in_progress == 1);
  6277. ioc->wait_on_reset_completion = 0;
  6278. return ioc->reset_status;
  6279. }
  6280. if (ioc->wait_on_reset_completion) {
  6281. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6282. rc = 0;
  6283. time_count = jiffies;
  6284. goto exit;
  6285. }
  6286. ioc->ioc_reset_in_progress = 1;
  6287. if (ioc->alt_ioc)
  6288. ioc->alt_ioc->ioc_reset_in_progress = 1;
  6289. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6290. /* The SCSI driver needs to adjust timeouts on all current
  6291. * commands prior to the diagnostic reset being issued.
  6292. * Prevents timeouts occurring during a diagnostic reset...very bad.
  6293. * For all other protocol drivers, this is a no-op.
  6294. */
  6295. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6296. if (MptResetHandlers[cb_idx]) {
  6297. mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
  6298. if (ioc->alt_ioc)
  6299. mpt_signal_reset(cb_idx, ioc->alt_ioc,
  6300. MPT_IOC_SETUP_RESET);
  6301. }
  6302. }
  6303. time_count = jiffies;
  6304. rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag);
  6305. if (rc != 0) {
  6306. printk(KERN_WARNING MYNAM
  6307. ": WARNING - (%d) Cannot recover %s, doorbell=0x%08x\n",
  6308. rc, ioc->name, mpt_GetIocState(ioc, 0));
  6309. } else {
  6310. if (ioc->hard_resets < -1)
  6311. ioc->hard_resets++;
  6312. }
  6313. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6314. ioc->ioc_reset_in_progress = 0;
  6315. ioc->taskmgmt_quiesce_io = 0;
  6316. ioc->taskmgmt_in_progress = 0;
  6317. ioc->reset_status = rc;
  6318. if (ioc->alt_ioc) {
  6319. ioc->alt_ioc->ioc_reset_in_progress = 0;
  6320. ioc->alt_ioc->taskmgmt_quiesce_io = 0;
  6321. ioc->alt_ioc->taskmgmt_in_progress = 0;
  6322. }
  6323. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6324. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6325. if (MptResetHandlers[cb_idx]) {
  6326. mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
  6327. if (ioc->alt_ioc)
  6328. mpt_signal_reset(cb_idx,
  6329. ioc->alt_ioc, MPT_IOC_POST_RESET);
  6330. }
  6331. }
  6332. exit:
  6333. dtmprintk(ioc,
  6334. printk(MYIOC_s_DEBUG_FMT
  6335. "HardResetHandler: completed (%d seconds): %s\n", ioc->name,
  6336. jiffies_to_msecs(jiffies - time_count)/1000, ((rc == 0) ?
  6337. "SUCCESS" : "FAILED")));
  6338. return rc;
  6339. }
  6340. #ifdef CONFIG_FUSION_LOGGING
  6341. static void
  6342. mpt_display_event_info(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply)
  6343. {
  6344. char *ds = NULL;
  6345. u32 evData0;
  6346. int ii;
  6347. u8 event;
  6348. char *evStr = ioc->evStr;
  6349. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  6350. evData0 = le32_to_cpu(pEventReply->Data[0]);
  6351. switch(event) {
  6352. case MPI_EVENT_NONE:
  6353. ds = "None";
  6354. break;
  6355. case MPI_EVENT_LOG_DATA:
  6356. ds = "Log Data";
  6357. break;
  6358. case MPI_EVENT_STATE_CHANGE:
  6359. ds = "State Change";
  6360. break;
  6361. case MPI_EVENT_UNIT_ATTENTION:
  6362. ds = "Unit Attention";
  6363. break;
  6364. case MPI_EVENT_IOC_BUS_RESET:
  6365. ds = "IOC Bus Reset";
  6366. break;
  6367. case MPI_EVENT_EXT_BUS_RESET:
  6368. ds = "External Bus Reset";
  6369. break;
  6370. case MPI_EVENT_RESCAN:
  6371. ds = "Bus Rescan Event";
  6372. break;
  6373. case MPI_EVENT_LINK_STATUS_CHANGE:
  6374. if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
  6375. ds = "Link Status(FAILURE) Change";
  6376. else
  6377. ds = "Link Status(ACTIVE) Change";
  6378. break;
  6379. case MPI_EVENT_LOOP_STATE_CHANGE:
  6380. if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
  6381. ds = "Loop State(LIP) Change";
  6382. else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
  6383. ds = "Loop State(LPE) Change";
  6384. else
  6385. ds = "Loop State(LPB) Change";
  6386. break;
  6387. case MPI_EVENT_LOGOUT:
  6388. ds = "Logout";
  6389. break;
  6390. case MPI_EVENT_EVENT_CHANGE:
  6391. if (evData0)
  6392. ds = "Events ON";
  6393. else
  6394. ds = "Events OFF";
  6395. break;
  6396. case MPI_EVENT_INTEGRATED_RAID:
  6397. {
  6398. u8 ReasonCode = (u8)(evData0 >> 16);
  6399. switch (ReasonCode) {
  6400. case MPI_EVENT_RAID_RC_VOLUME_CREATED :
  6401. ds = "Integrated Raid: Volume Created";
  6402. break;
  6403. case MPI_EVENT_RAID_RC_VOLUME_DELETED :
  6404. ds = "Integrated Raid: Volume Deleted";
  6405. break;
  6406. case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED :
  6407. ds = "Integrated Raid: Volume Settings Changed";
  6408. break;
  6409. case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED :
  6410. ds = "Integrated Raid: Volume Status Changed";
  6411. break;
  6412. case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED :
  6413. ds = "Integrated Raid: Volume Physdisk Changed";
  6414. break;
  6415. case MPI_EVENT_RAID_RC_PHYSDISK_CREATED :
  6416. ds = "Integrated Raid: Physdisk Created";
  6417. break;
  6418. case MPI_EVENT_RAID_RC_PHYSDISK_DELETED :
  6419. ds = "Integrated Raid: Physdisk Deleted";
  6420. break;
  6421. case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED :
  6422. ds = "Integrated Raid: Physdisk Settings Changed";
  6423. break;
  6424. case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED :
  6425. ds = "Integrated Raid: Physdisk Status Changed";
  6426. break;
  6427. case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED :
  6428. ds = "Integrated Raid: Domain Validation Needed";
  6429. break;
  6430. case MPI_EVENT_RAID_RC_SMART_DATA :
  6431. ds = "Integrated Raid; Smart Data";
  6432. break;
  6433. case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED :
  6434. ds = "Integrated Raid: Replace Action Started";
  6435. break;
  6436. default:
  6437. ds = "Integrated Raid";
  6438. break;
  6439. }
  6440. break;
  6441. }
  6442. case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE:
  6443. ds = "SCSI Device Status Change";
  6444. break;
  6445. case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
  6446. {
  6447. u8 id = (u8)(evData0);
  6448. u8 channel = (u8)(evData0 >> 8);
  6449. u8 ReasonCode = (u8)(evData0 >> 16);
  6450. switch (ReasonCode) {
  6451. case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
  6452. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6453. "SAS Device Status Change: Added: "
  6454. "id=%d channel=%d", id, channel);
  6455. break;
  6456. case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
  6457. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6458. "SAS Device Status Change: Deleted: "
  6459. "id=%d channel=%d", id, channel);
  6460. break;
  6461. case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  6462. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6463. "SAS Device Status Change: SMART Data: "
  6464. "id=%d channel=%d", id, channel);
  6465. break;
  6466. case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
  6467. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6468. "SAS Device Status Change: No Persistancy: "
  6469. "id=%d channel=%d", id, channel);
  6470. break;
  6471. case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
  6472. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6473. "SAS Device Status Change: Unsupported Device "
  6474. "Discovered : id=%d channel=%d", id, channel);
  6475. break;
  6476. case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  6477. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6478. "SAS Device Status Change: Internal Device "
  6479. "Reset : id=%d channel=%d", id, channel);
  6480. break;
  6481. case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  6482. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6483. "SAS Device Status Change: Internal Task "
  6484. "Abort : id=%d channel=%d", id, channel);
  6485. break;
  6486. case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  6487. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6488. "SAS Device Status Change: Internal Abort "
  6489. "Task Set : id=%d channel=%d", id, channel);
  6490. break;
  6491. case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  6492. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6493. "SAS Device Status Change: Internal Clear "
  6494. "Task Set : id=%d channel=%d", id, channel);
  6495. break;
  6496. case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  6497. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6498. "SAS Device Status Change: Internal Query "
  6499. "Task : id=%d channel=%d", id, channel);
  6500. break;
  6501. default:
  6502. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6503. "SAS Device Status Change: Unknown: "
  6504. "id=%d channel=%d", id, channel);
  6505. break;
  6506. }
  6507. break;
  6508. }
  6509. case MPI_EVENT_ON_BUS_TIMER_EXPIRED:
  6510. ds = "Bus Timer Expired";
  6511. break;
  6512. case MPI_EVENT_QUEUE_FULL:
  6513. {
  6514. u16 curr_depth = (u16)(evData0 >> 16);
  6515. u8 channel = (u8)(evData0 >> 8);
  6516. u8 id = (u8)(evData0);
  6517. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6518. "Queue Full: channel=%d id=%d depth=%d",
  6519. channel, id, curr_depth);
  6520. break;
  6521. }
  6522. case MPI_EVENT_SAS_SES:
  6523. ds = "SAS SES Event";
  6524. break;
  6525. case MPI_EVENT_PERSISTENT_TABLE_FULL:
  6526. ds = "Persistent Table Full";
  6527. break;
  6528. case MPI_EVENT_SAS_PHY_LINK_STATUS:
  6529. {
  6530. u8 LinkRates = (u8)(evData0 >> 8);
  6531. u8 PhyNumber = (u8)(evData0);
  6532. LinkRates = (LinkRates & MPI_EVENT_SAS_PLS_LR_CURRENT_MASK) >>
  6533. MPI_EVENT_SAS_PLS_LR_CURRENT_SHIFT;
  6534. switch (LinkRates) {
  6535. case MPI_EVENT_SAS_PLS_LR_RATE_UNKNOWN:
  6536. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6537. "SAS PHY Link Status: Phy=%d:"
  6538. " Rate Unknown",PhyNumber);
  6539. break;
  6540. case MPI_EVENT_SAS_PLS_LR_RATE_PHY_DISABLED:
  6541. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6542. "SAS PHY Link Status: Phy=%d:"
  6543. " Phy Disabled",PhyNumber);
  6544. break;
  6545. case MPI_EVENT_SAS_PLS_LR_RATE_FAILED_SPEED_NEGOTIATION:
  6546. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6547. "SAS PHY Link Status: Phy=%d:"
  6548. " Failed Speed Nego",PhyNumber);
  6549. break;
  6550. case MPI_EVENT_SAS_PLS_LR_RATE_SATA_OOB_COMPLETE:
  6551. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6552. "SAS PHY Link Status: Phy=%d:"
  6553. " Sata OOB Completed",PhyNumber);
  6554. break;
  6555. case MPI_EVENT_SAS_PLS_LR_RATE_1_5:
  6556. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6557. "SAS PHY Link Status: Phy=%d:"
  6558. " Rate 1.5 Gbps",PhyNumber);
  6559. break;
  6560. case MPI_EVENT_SAS_PLS_LR_RATE_3_0:
  6561. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6562. "SAS PHY Link Status: Phy=%d:"
  6563. " Rate 3.0 Gbps", PhyNumber);
  6564. break;
  6565. case MPI_EVENT_SAS_PLS_LR_RATE_6_0:
  6566. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6567. "SAS PHY Link Status: Phy=%d:"
  6568. " Rate 6.0 Gbps", PhyNumber);
  6569. break;
  6570. default:
  6571. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6572. "SAS PHY Link Status: Phy=%d", PhyNumber);
  6573. break;
  6574. }
  6575. break;
  6576. }
  6577. case MPI_EVENT_SAS_DISCOVERY_ERROR:
  6578. ds = "SAS Discovery Error";
  6579. break;
  6580. case MPI_EVENT_IR_RESYNC_UPDATE:
  6581. {
  6582. u8 resync_complete = (u8)(evData0 >> 16);
  6583. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6584. "IR Resync Update: Complete = %d:",resync_complete);
  6585. break;
  6586. }
  6587. case MPI_EVENT_IR2:
  6588. {
  6589. u8 id = (u8)(evData0);
  6590. u8 channel = (u8)(evData0 >> 8);
  6591. u8 phys_num = (u8)(evData0 >> 24);
  6592. u8 ReasonCode = (u8)(evData0 >> 16);
  6593. switch (ReasonCode) {
  6594. case MPI_EVENT_IR2_RC_LD_STATE_CHANGED:
  6595. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6596. "IR2: LD State Changed: "
  6597. "id=%d channel=%d phys_num=%d",
  6598. id, channel, phys_num);
  6599. break;
  6600. case MPI_EVENT_IR2_RC_PD_STATE_CHANGED:
  6601. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6602. "IR2: PD State Changed "
  6603. "id=%d channel=%d phys_num=%d",
  6604. id, channel, phys_num);
  6605. break;
  6606. case MPI_EVENT_IR2_RC_BAD_BLOCK_TABLE_FULL:
  6607. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6608. "IR2: Bad Block Table Full: "
  6609. "id=%d channel=%d phys_num=%d",
  6610. id, channel, phys_num);
  6611. break;
  6612. case MPI_EVENT_IR2_RC_PD_INSERTED:
  6613. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6614. "IR2: PD Inserted: "
  6615. "id=%d channel=%d phys_num=%d",
  6616. id, channel, phys_num);
  6617. break;
  6618. case MPI_EVENT_IR2_RC_PD_REMOVED:
  6619. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6620. "IR2: PD Removed: "
  6621. "id=%d channel=%d phys_num=%d",
  6622. id, channel, phys_num);
  6623. break;
  6624. case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
  6625. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6626. "IR2: Foreign CFG Detected: "
  6627. "id=%d channel=%d phys_num=%d",
  6628. id, channel, phys_num);
  6629. break;
  6630. case MPI_EVENT_IR2_RC_REBUILD_MEDIUM_ERROR:
  6631. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6632. "IR2: Rebuild Medium Error: "
  6633. "id=%d channel=%d phys_num=%d",
  6634. id, channel, phys_num);
  6635. break;
  6636. case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
  6637. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6638. "IR2: Dual Port Added: "
  6639. "id=%d channel=%d phys_num=%d",
  6640. id, channel, phys_num);
  6641. break;
  6642. case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
  6643. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6644. "IR2: Dual Port Removed: "
  6645. "id=%d channel=%d phys_num=%d",
  6646. id, channel, phys_num);
  6647. break;
  6648. default:
  6649. ds = "IR2";
  6650. break;
  6651. }
  6652. break;
  6653. }
  6654. case MPI_EVENT_SAS_DISCOVERY:
  6655. {
  6656. if (evData0)
  6657. ds = "SAS Discovery: Start";
  6658. else
  6659. ds = "SAS Discovery: Stop";
  6660. break;
  6661. }
  6662. case MPI_EVENT_LOG_ENTRY_ADDED:
  6663. ds = "SAS Log Entry Added";
  6664. break;
  6665. case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
  6666. {
  6667. u8 phy_num = (u8)(evData0);
  6668. u8 port_num = (u8)(evData0 >> 8);
  6669. u8 port_width = (u8)(evData0 >> 16);
  6670. u8 primative = (u8)(evData0 >> 24);
  6671. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6672. "SAS Broadcase Primative: phy=%d port=%d "
  6673. "width=%d primative=0x%02x",
  6674. phy_num, port_num, port_width, primative);
  6675. break;
  6676. }
  6677. case MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
  6678. {
  6679. u8 reason = (u8)(evData0);
  6680. switch (reason) {
  6681. case MPI_EVENT_SAS_INIT_RC_ADDED:
  6682. ds = "SAS Initiator Status Change: Added";
  6683. break;
  6684. case MPI_EVENT_SAS_INIT_RC_REMOVED:
  6685. ds = "SAS Initiator Status Change: Deleted";
  6686. break;
  6687. default:
  6688. ds = "SAS Initiator Status Change";
  6689. break;
  6690. }
  6691. break;
  6692. }
  6693. case MPI_EVENT_SAS_INIT_TABLE_OVERFLOW:
  6694. {
  6695. u8 max_init = (u8)(evData0);
  6696. u8 current_init = (u8)(evData0 >> 8);
  6697. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6698. "SAS Initiator Device Table Overflow: max initiators=%02d "
  6699. "current initators=%02d",
  6700. max_init, current_init);
  6701. break;
  6702. }
  6703. case MPI_EVENT_SAS_SMP_ERROR:
  6704. {
  6705. u8 status = (u8)(evData0);
  6706. u8 port_num = (u8)(evData0 >> 8);
  6707. u8 result = (u8)(evData0 >> 16);
  6708. if (status == MPI_EVENT_SAS_SMP_FUNCTION_RESULT_VALID)
  6709. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6710. "SAS SMP Error: port=%d result=0x%02x",
  6711. port_num, result);
  6712. else if (status == MPI_EVENT_SAS_SMP_CRC_ERROR)
  6713. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6714. "SAS SMP Error: port=%d : CRC Error",
  6715. port_num);
  6716. else if (status == MPI_EVENT_SAS_SMP_TIMEOUT)
  6717. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6718. "SAS SMP Error: port=%d : Timeout",
  6719. port_num);
  6720. else if (status == MPI_EVENT_SAS_SMP_NO_DESTINATION)
  6721. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6722. "SAS SMP Error: port=%d : No Destination",
  6723. port_num);
  6724. else if (status == MPI_EVENT_SAS_SMP_BAD_DESTINATION)
  6725. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6726. "SAS SMP Error: port=%d : Bad Destination",
  6727. port_num);
  6728. else
  6729. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6730. "SAS SMP Error: port=%d : status=0x%02x",
  6731. port_num, status);
  6732. break;
  6733. }
  6734. case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
  6735. {
  6736. u8 reason = (u8)(evData0);
  6737. switch (reason) {
  6738. case MPI_EVENT_SAS_EXP_RC_ADDED:
  6739. ds = "Expander Status Change: Added";
  6740. break;
  6741. case MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING:
  6742. ds = "Expander Status Change: Deleted";
  6743. break;
  6744. default:
  6745. ds = "Expander Status Change";
  6746. break;
  6747. }
  6748. break;
  6749. }
  6750. /*
  6751. * MPT base "custom" events may be added here...
  6752. */
  6753. default:
  6754. ds = "Unknown";
  6755. break;
  6756. }
  6757. if (ds)
  6758. strncpy(evStr, ds, EVENT_DESCR_STR_SZ);
  6759. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6760. "MPT event:(%02Xh) : %s\n",
  6761. ioc->name, event, evStr));
  6762. devtverboseprintk(ioc, printk(KERN_DEBUG MYNAM
  6763. ": Event data:\n"));
  6764. for (ii = 0; ii < le16_to_cpu(pEventReply->EventDataLength); ii++)
  6765. devtverboseprintk(ioc, printk(" %08x",
  6766. le32_to_cpu(pEventReply->Data[ii])));
  6767. devtverboseprintk(ioc, printk(KERN_DEBUG "\n"));
  6768. }
  6769. #endif
  6770. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6771. /**
  6772. * ProcessEventNotification - Route EventNotificationReply to all event handlers
  6773. * @ioc: Pointer to MPT_ADAPTER structure
  6774. * @pEventReply: Pointer to EventNotification reply frame
  6775. * @evHandlers: Pointer to integer, number of event handlers
  6776. *
  6777. * Routes a received EventNotificationReply to all currently registered
  6778. * event handlers.
  6779. * Returns sum of event handlers return values.
  6780. */
  6781. static int
  6782. ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
  6783. {
  6784. u16 evDataLen;
  6785. u32 evData0 = 0;
  6786. int ii;
  6787. u8 cb_idx;
  6788. int r = 0;
  6789. int handlers = 0;
  6790. u8 event;
  6791. /*
  6792. * Do platform normalization of values
  6793. */
  6794. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  6795. evDataLen = le16_to_cpu(pEventReply->EventDataLength);
  6796. if (evDataLen) {
  6797. evData0 = le32_to_cpu(pEventReply->Data[0]);
  6798. }
  6799. #ifdef CONFIG_FUSION_LOGGING
  6800. if (evDataLen)
  6801. mpt_display_event_info(ioc, pEventReply);
  6802. #endif
  6803. /*
  6804. * Do general / base driver event processing
  6805. */
  6806. switch(event) {
  6807. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  6808. if (evDataLen) {
  6809. u8 evState = evData0 & 0xFF;
  6810. /* CHECKME! What if evState unexpectedly says OFF (0)? */
  6811. /* Update EventState field in cached IocFacts */
  6812. if (ioc->facts.Function) {
  6813. ioc->facts.EventState = evState;
  6814. }
  6815. }
  6816. break;
  6817. case MPI_EVENT_INTEGRATED_RAID:
  6818. mptbase_raid_process_event_data(ioc,
  6819. (MpiEventDataRaid_t *)pEventReply->Data);
  6820. break;
  6821. default:
  6822. break;
  6823. }
  6824. /*
  6825. * Should this event be logged? Events are written sequentially.
  6826. * When buffer is full, start again at the top.
  6827. */
  6828. if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
  6829. int idx;
  6830. idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
  6831. ioc->events[idx].event = event;
  6832. ioc->events[idx].eventContext = ioc->eventContext;
  6833. for (ii = 0; ii < 2; ii++) {
  6834. if (ii < evDataLen)
  6835. ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
  6836. else
  6837. ioc->events[idx].data[ii] = 0;
  6838. }
  6839. ioc->eventContext++;
  6840. }
  6841. /*
  6842. * Call each currently registered protocol event handler.
  6843. */
  6844. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6845. if (MptEvHandlers[cb_idx]) {
  6846. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6847. "Routing Event to event handler #%d\n",
  6848. ioc->name, cb_idx));
  6849. r += (*(MptEvHandlers[cb_idx]))(ioc, pEventReply);
  6850. handlers++;
  6851. }
  6852. }
  6853. /* FIXME? Examine results here? */
  6854. /*
  6855. * If needed, send (a single) EventAck.
  6856. */
  6857. if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
  6858. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6859. "EventAck required\n",ioc->name));
  6860. if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
  6861. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SendEventAck returned %d\n",
  6862. ioc->name, ii));
  6863. }
  6864. }
  6865. *evHandlers = handlers;
  6866. return r;
  6867. }
  6868. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6869. /**
  6870. * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
  6871. * @ioc: Pointer to MPT_ADAPTER structure
  6872. * @log_info: U32 LogInfo reply word from the IOC
  6873. *
  6874. * Refer to lsi/mpi_log_fc.h.
  6875. */
  6876. static void
  6877. mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
  6878. {
  6879. char *desc = "unknown";
  6880. switch (log_info & 0xFF000000) {
  6881. case MPI_IOCLOGINFO_FC_INIT_BASE:
  6882. desc = "FCP Initiator";
  6883. break;
  6884. case MPI_IOCLOGINFO_FC_TARGET_BASE:
  6885. desc = "FCP Target";
  6886. break;
  6887. case MPI_IOCLOGINFO_FC_LAN_BASE:
  6888. desc = "LAN";
  6889. break;
  6890. case MPI_IOCLOGINFO_FC_MSG_BASE:
  6891. desc = "MPI Message Layer";
  6892. break;
  6893. case MPI_IOCLOGINFO_FC_LINK_BASE:
  6894. desc = "FC Link";
  6895. break;
  6896. case MPI_IOCLOGINFO_FC_CTX_BASE:
  6897. desc = "Context Manager";
  6898. break;
  6899. case MPI_IOCLOGINFO_FC_INVALID_FIELD_BYTE_OFFSET:
  6900. desc = "Invalid Field Offset";
  6901. break;
  6902. case MPI_IOCLOGINFO_FC_STATE_CHANGE:
  6903. desc = "State Change Info";
  6904. break;
  6905. }
  6906. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubClass={%s}, Value=(0x%06x)\n",
  6907. ioc->name, log_info, desc, (log_info & 0xFFFFFF));
  6908. }
  6909. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6910. /**
  6911. * mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
  6912. * @ioc: Pointer to MPT_ADAPTER structure
  6913. * @log_info: U32 LogInfo word from the IOC
  6914. *
  6915. * Refer to lsi/sp_log.h.
  6916. */
  6917. static void
  6918. mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
  6919. {
  6920. u32 info = log_info & 0x00FF0000;
  6921. char *desc = "unknown";
  6922. switch (info) {
  6923. case 0x00010000:
  6924. desc = "bug! MID not found";
  6925. break;
  6926. case 0x00020000:
  6927. desc = "Parity Error";
  6928. break;
  6929. case 0x00030000:
  6930. desc = "ASYNC Outbound Overrun";
  6931. break;
  6932. case 0x00040000:
  6933. desc = "SYNC Offset Error";
  6934. break;
  6935. case 0x00050000:
  6936. desc = "BM Change";
  6937. break;
  6938. case 0x00060000:
  6939. desc = "Msg In Overflow";
  6940. break;
  6941. case 0x00070000:
  6942. desc = "DMA Error";
  6943. break;
  6944. case 0x00080000:
  6945. desc = "Outbound DMA Overrun";
  6946. break;
  6947. case 0x00090000:
  6948. desc = "Task Management";
  6949. break;
  6950. case 0x000A0000:
  6951. desc = "Device Problem";
  6952. break;
  6953. case 0x000B0000:
  6954. desc = "Invalid Phase Change";
  6955. break;
  6956. case 0x000C0000:
  6957. desc = "Untagged Table Size";
  6958. break;
  6959. }
  6960. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
  6961. }
  6962. /* strings for sas loginfo */
  6963. static char *originator_str[] = {
  6964. "IOP", /* 00h */
  6965. "PL", /* 01h */
  6966. "IR" /* 02h */
  6967. };
  6968. static char *iop_code_str[] = {
  6969. NULL, /* 00h */
  6970. "Invalid SAS Address", /* 01h */
  6971. NULL, /* 02h */
  6972. "Invalid Page", /* 03h */
  6973. "Diag Message Error", /* 04h */
  6974. "Task Terminated", /* 05h */
  6975. "Enclosure Management", /* 06h */
  6976. "Target Mode" /* 07h */
  6977. };
  6978. static char *pl_code_str[] = {
  6979. NULL, /* 00h */
  6980. "Open Failure", /* 01h */
  6981. "Invalid Scatter Gather List", /* 02h */
  6982. "Wrong Relative Offset or Frame Length", /* 03h */
  6983. "Frame Transfer Error", /* 04h */
  6984. "Transmit Frame Connected Low", /* 05h */
  6985. "SATA Non-NCQ RW Error Bit Set", /* 06h */
  6986. "SATA Read Log Receive Data Error", /* 07h */
  6987. "SATA NCQ Fail All Commands After Error", /* 08h */
  6988. "SATA Error in Receive Set Device Bit FIS", /* 09h */
  6989. "Receive Frame Invalid Message", /* 0Ah */
  6990. "Receive Context Message Valid Error", /* 0Bh */
  6991. "Receive Frame Current Frame Error", /* 0Ch */
  6992. "SATA Link Down", /* 0Dh */
  6993. "Discovery SATA Init W IOS", /* 0Eh */
  6994. "Config Invalid Page", /* 0Fh */
  6995. "Discovery SATA Init Timeout", /* 10h */
  6996. "Reset", /* 11h */
  6997. "Abort", /* 12h */
  6998. "IO Not Yet Executed", /* 13h */
  6999. "IO Executed", /* 14h */
  7000. "Persistent Reservation Out Not Affiliation "
  7001. "Owner", /* 15h */
  7002. "Open Transmit DMA Abort", /* 16h */
  7003. "IO Device Missing Delay Retry", /* 17h */
  7004. "IO Cancelled Due to Receive Error", /* 18h */
  7005. NULL, /* 19h */
  7006. NULL, /* 1Ah */
  7007. NULL, /* 1Bh */
  7008. NULL, /* 1Ch */
  7009. NULL, /* 1Dh */
  7010. NULL, /* 1Eh */
  7011. NULL, /* 1Fh */
  7012. "Enclosure Management" /* 20h */
  7013. };
  7014. static char *ir_code_str[] = {
  7015. "Raid Action Error", /* 00h */
  7016. NULL, /* 00h */
  7017. NULL, /* 01h */
  7018. NULL, /* 02h */
  7019. NULL, /* 03h */
  7020. NULL, /* 04h */
  7021. NULL, /* 05h */
  7022. NULL, /* 06h */
  7023. NULL /* 07h */
  7024. };
  7025. static char *raid_sub_code_str[] = {
  7026. NULL, /* 00h */
  7027. "Volume Creation Failed: Data Passed too "
  7028. "Large", /* 01h */
  7029. "Volume Creation Failed: Duplicate Volumes "
  7030. "Attempted", /* 02h */
  7031. "Volume Creation Failed: Max Number "
  7032. "Supported Volumes Exceeded", /* 03h */
  7033. "Volume Creation Failed: DMA Error", /* 04h */
  7034. "Volume Creation Failed: Invalid Volume Type", /* 05h */
  7035. "Volume Creation Failed: Error Reading "
  7036. "MFG Page 4", /* 06h */
  7037. "Volume Creation Failed: Creating Internal "
  7038. "Structures", /* 07h */
  7039. NULL, /* 08h */
  7040. NULL, /* 09h */
  7041. NULL, /* 0Ah */
  7042. NULL, /* 0Bh */
  7043. NULL, /* 0Ch */
  7044. NULL, /* 0Dh */
  7045. NULL, /* 0Eh */
  7046. NULL, /* 0Fh */
  7047. "Activation failed: Already Active Volume", /* 10h */
  7048. "Activation failed: Unsupported Volume Type", /* 11h */
  7049. "Activation failed: Too Many Active Volumes", /* 12h */
  7050. "Activation failed: Volume ID in Use", /* 13h */
  7051. "Activation failed: Reported Failure", /* 14h */
  7052. "Activation failed: Importing a Volume", /* 15h */
  7053. NULL, /* 16h */
  7054. NULL, /* 17h */
  7055. NULL, /* 18h */
  7056. NULL, /* 19h */
  7057. NULL, /* 1Ah */
  7058. NULL, /* 1Bh */
  7059. NULL, /* 1Ch */
  7060. NULL, /* 1Dh */
  7061. NULL, /* 1Eh */
  7062. NULL, /* 1Fh */
  7063. "Phys Disk failed: Too Many Phys Disks", /* 20h */
  7064. "Phys Disk failed: Data Passed too Large", /* 21h */
  7065. "Phys Disk failed: DMA Error", /* 22h */
  7066. "Phys Disk failed: Invalid <channel:id>", /* 23h */
  7067. "Phys Disk failed: Creating Phys Disk Config "
  7068. "Page", /* 24h */
  7069. NULL, /* 25h */
  7070. NULL, /* 26h */
  7071. NULL, /* 27h */
  7072. NULL, /* 28h */
  7073. NULL, /* 29h */
  7074. NULL, /* 2Ah */
  7075. NULL, /* 2Bh */
  7076. NULL, /* 2Ch */
  7077. NULL, /* 2Dh */
  7078. NULL, /* 2Eh */
  7079. NULL, /* 2Fh */
  7080. "Compatibility Error: IR Disabled", /* 30h */
  7081. "Compatibility Error: Inquiry Command Failed", /* 31h */
  7082. "Compatibility Error: Device not Direct Access "
  7083. "Device ", /* 32h */
  7084. "Compatibility Error: Removable Device Found", /* 33h */
  7085. "Compatibility Error: Device SCSI Version not "
  7086. "2 or Higher", /* 34h */
  7087. "Compatibility Error: SATA Device, 48 BIT LBA "
  7088. "not Supported", /* 35h */
  7089. "Compatibility Error: Device doesn't have "
  7090. "512 Byte Block Sizes", /* 36h */
  7091. "Compatibility Error: Volume Type Check Failed", /* 37h */
  7092. "Compatibility Error: Volume Type is "
  7093. "Unsupported by FW", /* 38h */
  7094. "Compatibility Error: Disk Drive too Small for "
  7095. "use in Volume", /* 39h */
  7096. "Compatibility Error: Phys Disk for Create "
  7097. "Volume not Found", /* 3Ah */
  7098. "Compatibility Error: Too Many or too Few "
  7099. "Disks for Volume Type", /* 3Bh */
  7100. "Compatibility Error: Disk stripe Sizes "
  7101. "Must be 64KB", /* 3Ch */
  7102. "Compatibility Error: IME Size Limited to < 2TB", /* 3Dh */
  7103. };
  7104. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7105. /**
  7106. * mpt_sas_log_info - Log information returned from SAS IOC.
  7107. * @ioc: Pointer to MPT_ADAPTER structure
  7108. * @log_info: U32 LogInfo reply word from the IOC
  7109. * @cb_idx: callback function's handle
  7110. *
  7111. * Refer to lsi/mpi_log_sas.h.
  7112. **/
  7113. static void
  7114. mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info, u8 cb_idx)
  7115. {
  7116. union loginfo_type {
  7117. u32 loginfo;
  7118. struct {
  7119. u32 subcode:16;
  7120. u32 code:8;
  7121. u32 originator:4;
  7122. u32 bus_type:4;
  7123. }dw;
  7124. };
  7125. union loginfo_type sas_loginfo;
  7126. char *originator_desc = NULL;
  7127. char *code_desc = NULL;
  7128. char *sub_code_desc = NULL;
  7129. sas_loginfo.loginfo = log_info;
  7130. if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) &&
  7131. (sas_loginfo.dw.originator < ARRAY_SIZE(originator_str)))
  7132. return;
  7133. originator_desc = originator_str[sas_loginfo.dw.originator];
  7134. switch (sas_loginfo.dw.originator) {
  7135. case 0: /* IOP */
  7136. if (sas_loginfo.dw.code <
  7137. ARRAY_SIZE(iop_code_str))
  7138. code_desc = iop_code_str[sas_loginfo.dw.code];
  7139. break;
  7140. case 1: /* PL */
  7141. if (sas_loginfo.dw.code <
  7142. ARRAY_SIZE(pl_code_str))
  7143. code_desc = pl_code_str[sas_loginfo.dw.code];
  7144. break;
  7145. case 2: /* IR */
  7146. if (sas_loginfo.dw.code >=
  7147. ARRAY_SIZE(ir_code_str))
  7148. break;
  7149. code_desc = ir_code_str[sas_loginfo.dw.code];
  7150. if (sas_loginfo.dw.subcode >=
  7151. ARRAY_SIZE(raid_sub_code_str))
  7152. break;
  7153. if (sas_loginfo.dw.code == 0)
  7154. sub_code_desc =
  7155. raid_sub_code_str[sas_loginfo.dw.subcode];
  7156. break;
  7157. default:
  7158. return;
  7159. }
  7160. if (sub_code_desc != NULL)
  7161. printk(MYIOC_s_INFO_FMT
  7162. "LogInfo(0x%08x): Originator={%s}, Code={%s},"
  7163. " SubCode={%s} cb_idx %s\n",
  7164. ioc->name, log_info, originator_desc, code_desc,
  7165. sub_code_desc, MptCallbacksName[cb_idx]);
  7166. else if (code_desc != NULL)
  7167. printk(MYIOC_s_INFO_FMT
  7168. "LogInfo(0x%08x): Originator={%s}, Code={%s},"
  7169. " SubCode(0x%04x) cb_idx %s\n",
  7170. ioc->name, log_info, originator_desc, code_desc,
  7171. sas_loginfo.dw.subcode, MptCallbacksName[cb_idx]);
  7172. else
  7173. printk(MYIOC_s_INFO_FMT
  7174. "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x),"
  7175. " SubCode(0x%04x) cb_idx %s\n",
  7176. ioc->name, log_info, originator_desc,
  7177. sas_loginfo.dw.code, sas_loginfo.dw.subcode,
  7178. MptCallbacksName[cb_idx]);
  7179. }
  7180. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7181. /**
  7182. * mpt_iocstatus_info_config - IOCSTATUS information for config pages
  7183. * @ioc: Pointer to MPT_ADAPTER structure
  7184. * @ioc_status: U32 IOCStatus word from IOC
  7185. * @mf: Pointer to MPT request frame
  7186. *
  7187. * Refer to lsi/mpi.h.
  7188. **/
  7189. static void
  7190. mpt_iocstatus_info_config(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
  7191. {
  7192. Config_t *pReq = (Config_t *)mf;
  7193. char extend_desc[EVENT_DESCR_STR_SZ];
  7194. char *desc = NULL;
  7195. u32 form;
  7196. u8 page_type;
  7197. if (pReq->Header.PageType == MPI_CONFIG_PAGETYPE_EXTENDED)
  7198. page_type = pReq->ExtPageType;
  7199. else
  7200. page_type = pReq->Header.PageType;
  7201. /*
  7202. * ignore invalid page messages for GET_NEXT_HANDLE
  7203. */
  7204. form = le32_to_cpu(pReq->PageAddress);
  7205. if (ioc_status == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
  7206. if (page_type == MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE ||
  7207. page_type == MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER ||
  7208. page_type == MPI_CONFIG_EXTPAGETYPE_ENCLOSURE) {
  7209. if ((form >> MPI_SAS_DEVICE_PGAD_FORM_SHIFT) ==
  7210. MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE)
  7211. return;
  7212. }
  7213. if (page_type == MPI_CONFIG_PAGETYPE_FC_DEVICE)
  7214. if ((form & MPI_FC_DEVICE_PGAD_FORM_MASK) ==
  7215. MPI_FC_DEVICE_PGAD_FORM_NEXT_DID)
  7216. return;
  7217. }
  7218. snprintf(extend_desc, EVENT_DESCR_STR_SZ,
  7219. "type=%02Xh, page=%02Xh, action=%02Xh, form=%08Xh",
  7220. page_type, pReq->Header.PageNumber, pReq->Action, form);
  7221. switch (ioc_status) {
  7222. case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
  7223. desc = "Config Page Invalid Action";
  7224. break;
  7225. case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
  7226. desc = "Config Page Invalid Type";
  7227. break;
  7228. case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
  7229. desc = "Config Page Invalid Page";
  7230. break;
  7231. case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
  7232. desc = "Config Page Invalid Data";
  7233. break;
  7234. case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
  7235. desc = "Config Page No Defaults";
  7236. break;
  7237. case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
  7238. desc = "Config Page Can't Commit";
  7239. break;
  7240. }
  7241. if (!desc)
  7242. return;
  7243. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s: %s\n",
  7244. ioc->name, ioc_status, desc, extend_desc));
  7245. }
  7246. /**
  7247. * mpt_iocstatus_info - IOCSTATUS information returned from IOC.
  7248. * @ioc: Pointer to MPT_ADAPTER structure
  7249. * @ioc_status: U32 IOCStatus word from IOC
  7250. * @mf: Pointer to MPT request frame
  7251. *
  7252. * Refer to lsi/mpi.h.
  7253. **/
  7254. static void
  7255. mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
  7256. {
  7257. u32 status = ioc_status & MPI_IOCSTATUS_MASK;
  7258. char *desc = NULL;
  7259. switch (status) {
  7260. /****************************************************************************/
  7261. /* Common IOCStatus values for all replies */
  7262. /****************************************************************************/
  7263. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  7264. desc = "Invalid Function";
  7265. break;
  7266. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  7267. desc = "Busy";
  7268. break;
  7269. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  7270. desc = "Invalid SGL";
  7271. break;
  7272. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  7273. desc = "Internal Error";
  7274. break;
  7275. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  7276. desc = "Reserved";
  7277. break;
  7278. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  7279. desc = "Insufficient Resources";
  7280. break;
  7281. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  7282. desc = "Invalid Field";
  7283. break;
  7284. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  7285. desc = "Invalid State";
  7286. break;
  7287. /****************************************************************************/
  7288. /* Config IOCStatus values */
  7289. /****************************************************************************/
  7290. case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
  7291. case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
  7292. case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
  7293. case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
  7294. case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
  7295. case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
  7296. mpt_iocstatus_info_config(ioc, status, mf);
  7297. break;
  7298. /****************************************************************************/
  7299. /* SCSIIO Reply (SPI, FCP, SAS) initiator values */
  7300. /* */
  7301. /* Look at mptscsih_iocstatus_info_scsiio in mptscsih.c */
  7302. /* */
  7303. /****************************************************************************/
  7304. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  7305. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  7306. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  7307. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  7308. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  7309. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  7310. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  7311. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  7312. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  7313. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  7314. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  7315. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  7316. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  7317. break;
  7318. /****************************************************************************/
  7319. /* SCSI Target values */
  7320. /****************************************************************************/
  7321. case MPI_IOCSTATUS_TARGET_PRIORITY_IO: /* 0x0060 */
  7322. desc = "Target: Priority IO";
  7323. break;
  7324. case MPI_IOCSTATUS_TARGET_INVALID_PORT: /* 0x0061 */
  7325. desc = "Target: Invalid Port";
  7326. break;
  7327. case MPI_IOCSTATUS_TARGET_INVALID_IO_INDEX: /* 0x0062 */
  7328. desc = "Target Invalid IO Index:";
  7329. break;
  7330. case MPI_IOCSTATUS_TARGET_ABORTED: /* 0x0063 */
  7331. desc = "Target: Aborted";
  7332. break;
  7333. case MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: /* 0x0064 */
  7334. desc = "Target: No Conn Retryable";
  7335. break;
  7336. case MPI_IOCSTATUS_TARGET_NO_CONNECTION: /* 0x0065 */
  7337. desc = "Target: No Connection";
  7338. break;
  7339. case MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: /* 0x006A */
  7340. desc = "Target: Transfer Count Mismatch";
  7341. break;
  7342. case MPI_IOCSTATUS_TARGET_STS_DATA_NOT_SENT: /* 0x006B */
  7343. desc = "Target: STS Data not Sent";
  7344. break;
  7345. case MPI_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: /* 0x006D */
  7346. desc = "Target: Data Offset Error";
  7347. break;
  7348. case MPI_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: /* 0x006E */
  7349. desc = "Target: Too Much Write Data";
  7350. break;
  7351. case MPI_IOCSTATUS_TARGET_IU_TOO_SHORT: /* 0x006F */
  7352. desc = "Target: IU Too Short";
  7353. break;
  7354. case MPI_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: /* 0x0070 */
  7355. desc = "Target: ACK NAK Timeout";
  7356. break;
  7357. case MPI_IOCSTATUS_TARGET_NAK_RECEIVED: /* 0x0071 */
  7358. desc = "Target: Nak Received";
  7359. break;
  7360. /****************************************************************************/
  7361. /* Fibre Channel Direct Access values */
  7362. /****************************************************************************/
  7363. case MPI_IOCSTATUS_FC_ABORTED: /* 0x0066 */
  7364. desc = "FC: Aborted";
  7365. break;
  7366. case MPI_IOCSTATUS_FC_RX_ID_INVALID: /* 0x0067 */
  7367. desc = "FC: RX ID Invalid";
  7368. break;
  7369. case MPI_IOCSTATUS_FC_DID_INVALID: /* 0x0068 */
  7370. desc = "FC: DID Invalid";
  7371. break;
  7372. case MPI_IOCSTATUS_FC_NODE_LOGGED_OUT: /* 0x0069 */
  7373. desc = "FC: Node Logged Out";
  7374. break;
  7375. case MPI_IOCSTATUS_FC_EXCHANGE_CANCELED: /* 0x006C */
  7376. desc = "FC: Exchange Canceled";
  7377. break;
  7378. /****************************************************************************/
  7379. /* LAN values */
  7380. /****************************************************************************/
  7381. case MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND: /* 0x0080 */
  7382. desc = "LAN: Device not Found";
  7383. break;
  7384. case MPI_IOCSTATUS_LAN_DEVICE_FAILURE: /* 0x0081 */
  7385. desc = "LAN: Device Failure";
  7386. break;
  7387. case MPI_IOCSTATUS_LAN_TRANSMIT_ERROR: /* 0x0082 */
  7388. desc = "LAN: Transmit Error";
  7389. break;
  7390. case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED: /* 0x0083 */
  7391. desc = "LAN: Transmit Aborted";
  7392. break;
  7393. case MPI_IOCSTATUS_LAN_RECEIVE_ERROR: /* 0x0084 */
  7394. desc = "LAN: Receive Error";
  7395. break;
  7396. case MPI_IOCSTATUS_LAN_RECEIVE_ABORTED: /* 0x0085 */
  7397. desc = "LAN: Receive Aborted";
  7398. break;
  7399. case MPI_IOCSTATUS_LAN_PARTIAL_PACKET: /* 0x0086 */
  7400. desc = "LAN: Partial Packet";
  7401. break;
  7402. case MPI_IOCSTATUS_LAN_CANCELED: /* 0x0087 */
  7403. desc = "LAN: Canceled";
  7404. break;
  7405. /****************************************************************************/
  7406. /* Serial Attached SCSI values */
  7407. /****************************************************************************/
  7408. case MPI_IOCSTATUS_SAS_SMP_REQUEST_FAILED: /* 0x0090 */
  7409. desc = "SAS: SMP Request Failed";
  7410. break;
  7411. case MPI_IOCSTATUS_SAS_SMP_DATA_OVERRUN: /* 0x0090 */
  7412. desc = "SAS: SMP Data Overrun";
  7413. break;
  7414. default:
  7415. desc = "Others";
  7416. break;
  7417. }
  7418. if (!desc)
  7419. return;
  7420. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s\n",
  7421. ioc->name, status, desc));
  7422. }
  7423. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7424. EXPORT_SYMBOL(mpt_attach);
  7425. EXPORT_SYMBOL(mpt_detach);
  7426. #ifdef CONFIG_PM
  7427. EXPORT_SYMBOL(mpt_resume);
  7428. EXPORT_SYMBOL(mpt_suspend);
  7429. #endif
  7430. EXPORT_SYMBOL(ioc_list);
  7431. EXPORT_SYMBOL(mpt_register);
  7432. EXPORT_SYMBOL(mpt_deregister);
  7433. EXPORT_SYMBOL(mpt_event_register);
  7434. EXPORT_SYMBOL(mpt_event_deregister);
  7435. EXPORT_SYMBOL(mpt_reset_register);
  7436. EXPORT_SYMBOL(mpt_reset_deregister);
  7437. EXPORT_SYMBOL(mpt_device_driver_register);
  7438. EXPORT_SYMBOL(mpt_device_driver_deregister);
  7439. EXPORT_SYMBOL(mpt_get_msg_frame);
  7440. EXPORT_SYMBOL(mpt_put_msg_frame);
  7441. EXPORT_SYMBOL(mpt_put_msg_frame_hi_pri);
  7442. EXPORT_SYMBOL(mpt_free_msg_frame);
  7443. EXPORT_SYMBOL(mpt_send_handshake_request);
  7444. EXPORT_SYMBOL(mpt_verify_adapter);
  7445. EXPORT_SYMBOL(mpt_GetIocState);
  7446. EXPORT_SYMBOL(mpt_print_ioc_summary);
  7447. EXPORT_SYMBOL(mpt_HardResetHandler);
  7448. EXPORT_SYMBOL(mpt_config);
  7449. EXPORT_SYMBOL(mpt_findImVolumes);
  7450. EXPORT_SYMBOL(mpt_alloc_fw_memory);
  7451. EXPORT_SYMBOL(mpt_free_fw_memory);
  7452. EXPORT_SYMBOL(mptbase_sas_persist_operation);
  7453. EXPORT_SYMBOL(mpt_raid_phys_disk_pg0);
  7454. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7455. /**
  7456. * fusion_init - Fusion MPT base driver initialization routine.
  7457. *
  7458. * Returns 0 for success, non-zero for failure.
  7459. */
  7460. static int __init
  7461. fusion_init(void)
  7462. {
  7463. u8 cb_idx;
  7464. show_mptmod_ver(my_NAME, my_VERSION);
  7465. printk(KERN_INFO COPYRIGHT "\n");
  7466. for (cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
  7467. MptCallbacks[cb_idx] = NULL;
  7468. MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
  7469. MptEvHandlers[cb_idx] = NULL;
  7470. MptResetHandlers[cb_idx] = NULL;
  7471. }
  7472. /* Register ourselves (mptbase) in order to facilitate
  7473. * EventNotification handling.
  7474. */
  7475. mpt_base_index = mpt_register(mptbase_reply, MPTBASE_DRIVER,
  7476. "mptbase_reply");
  7477. /* Register for hard reset handling callbacks.
  7478. */
  7479. mpt_reset_register(mpt_base_index, mpt_ioc_reset);
  7480. #ifdef CONFIG_PROC_FS
  7481. (void) procmpt_create();
  7482. #endif
  7483. return 0;
  7484. }
  7485. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7486. /**
  7487. * fusion_exit - Perform driver unload cleanup.
  7488. *
  7489. * This routine frees all resources associated with each MPT adapter
  7490. * and removes all %MPT_PROCFS_MPTBASEDIR entries.
  7491. */
  7492. static void __exit
  7493. fusion_exit(void)
  7494. {
  7495. mpt_reset_deregister(mpt_base_index);
  7496. #ifdef CONFIG_PROC_FS
  7497. procmpt_destroy();
  7498. #endif
  7499. }
  7500. module_init(fusion_init);
  7501. module_exit(fusion_exit);