mptbase.c 209 KB

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