mptbase.c 182 KB

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