mptbase.c 180 KB

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