mptbase.c 231 KB

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