mptbase.c 163 KB

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