mptbase.c 209 KB

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