mptbase.c 206 KB

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