mptbase.c 216 KB

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