mptbase.c 205 KB

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