qla_init.c 171 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_gbl.h"
  9. #include <linux/delay.h>
  10. #include <linux/slab.h>
  11. #include <linux/vmalloc.h>
  12. #include "qla_devtbl.h"
  13. #ifdef CONFIG_SPARC
  14. #include <asm/prom.h>
  15. #endif
  16. #include <target/target_core_base.h>
  17. #include "qla_target.h"
  18. /*
  19. * QLogic ISP2x00 Hardware Support Function Prototypes.
  20. */
  21. static int qla2x00_isp_firmware(scsi_qla_host_t *);
  22. static int qla2x00_setup_chip(scsi_qla_host_t *);
  23. static int qla2x00_fw_ready(scsi_qla_host_t *);
  24. static int qla2x00_configure_hba(scsi_qla_host_t *);
  25. static int qla2x00_configure_loop(scsi_qla_host_t *);
  26. static int qla2x00_configure_local_loop(scsi_qla_host_t *);
  27. static int qla2x00_configure_fabric(scsi_qla_host_t *);
  28. static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
  29. static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
  30. uint16_t *);
  31. static int qla2x00_restart_isp(scsi_qla_host_t *);
  32. static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
  33. static int qla84xx_init_chip(scsi_qla_host_t *);
  34. static int qla25xx_init_queues(struct qla_hw_data *);
  35. /* SRB Extensions ---------------------------------------------------------- */
  36. void
  37. qla2x00_sp_timeout(unsigned long __data)
  38. {
  39. srb_t *sp = (srb_t *)__data;
  40. struct srb_iocb *iocb;
  41. fc_port_t *fcport = sp->fcport;
  42. struct qla_hw_data *ha = fcport->vha->hw;
  43. struct req_que *req;
  44. unsigned long flags;
  45. spin_lock_irqsave(&ha->hardware_lock, flags);
  46. req = ha->req_q_map[0];
  47. req->outstanding_cmds[sp->handle] = NULL;
  48. iocb = &sp->u.iocb_cmd;
  49. iocb->timeout(sp);
  50. sp->free(fcport->vha, sp);
  51. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  52. }
  53. void
  54. qla2x00_sp_free(void *data, void *ptr)
  55. {
  56. srb_t *sp = (srb_t *)ptr;
  57. struct srb_iocb *iocb = &sp->u.iocb_cmd;
  58. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  59. del_timer(&iocb->timer);
  60. qla2x00_rel_sp(vha, sp);
  61. }
  62. /* Asynchronous Login/Logout Routines -------------------------------------- */
  63. unsigned long
  64. qla2x00_get_async_timeout(struct scsi_qla_host *vha)
  65. {
  66. unsigned long tmo;
  67. struct qla_hw_data *ha = vha->hw;
  68. /* Firmware should use switch negotiated r_a_tov for timeout. */
  69. tmo = ha->r_a_tov / 10 * 2;
  70. if (IS_QLAFX00(ha)) {
  71. tmo = FX00_DEF_RATOV * 2;
  72. } else if (!IS_FWI2_CAPABLE(ha)) {
  73. /*
  74. * Except for earlier ISPs where the timeout is seeded from the
  75. * initialization control block.
  76. */
  77. tmo = ha->login_timeout;
  78. }
  79. return tmo;
  80. }
  81. static void
  82. qla2x00_async_iocb_timeout(void *data)
  83. {
  84. srb_t *sp = (srb_t *)data;
  85. fc_port_t *fcport = sp->fcport;
  86. ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
  87. "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
  88. sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
  89. fcport->d_id.b.al_pa);
  90. fcport->flags &= ~FCF_ASYNC_SENT;
  91. if (sp->type == SRB_LOGIN_CMD) {
  92. struct srb_iocb *lio = &sp->u.iocb_cmd;
  93. qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
  94. /* Retry as needed. */
  95. lio->u.logio.data[0] = MBS_COMMAND_ERROR;
  96. lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
  97. QLA_LOGIO_LOGIN_RETRIED : 0;
  98. qla2x00_post_async_login_done_work(fcport->vha, fcport,
  99. lio->u.logio.data);
  100. } else if (sp->type == SRB_LOGOUT_CMD) {
  101. qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
  102. }
  103. }
  104. static void
  105. qla2x00_async_login_sp_done(void *data, void *ptr, int res)
  106. {
  107. srb_t *sp = (srb_t *)ptr;
  108. struct srb_iocb *lio = &sp->u.iocb_cmd;
  109. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  110. if (!test_bit(UNLOADING, &vha->dpc_flags))
  111. qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
  112. lio->u.logio.data);
  113. sp->free(sp->fcport->vha, sp);
  114. }
  115. int
  116. qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
  117. uint16_t *data)
  118. {
  119. srb_t *sp;
  120. struct srb_iocb *lio;
  121. int rval;
  122. rval = QLA_FUNCTION_FAILED;
  123. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  124. if (!sp)
  125. goto done;
  126. sp->type = SRB_LOGIN_CMD;
  127. sp->name = "login";
  128. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  129. lio = &sp->u.iocb_cmd;
  130. lio->timeout = qla2x00_async_iocb_timeout;
  131. sp->done = qla2x00_async_login_sp_done;
  132. lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
  133. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  134. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  135. rval = qla2x00_start_sp(sp);
  136. if (rval != QLA_SUCCESS)
  137. goto done_free_sp;
  138. ql_dbg(ql_dbg_disc, vha, 0x2072,
  139. "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
  140. "retries=%d.\n", sp->handle, fcport->loop_id,
  141. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
  142. fcport->login_retry);
  143. return rval;
  144. done_free_sp:
  145. sp->free(fcport->vha, sp);
  146. done:
  147. return rval;
  148. }
  149. static void
  150. qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
  151. {
  152. srb_t *sp = (srb_t *)ptr;
  153. struct srb_iocb *lio = &sp->u.iocb_cmd;
  154. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  155. if (!test_bit(UNLOADING, &vha->dpc_flags))
  156. qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
  157. lio->u.logio.data);
  158. sp->free(sp->fcport->vha, sp);
  159. }
  160. int
  161. qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
  162. {
  163. srb_t *sp;
  164. struct srb_iocb *lio;
  165. int rval;
  166. rval = QLA_FUNCTION_FAILED;
  167. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  168. if (!sp)
  169. goto done;
  170. sp->type = SRB_LOGOUT_CMD;
  171. sp->name = "logout";
  172. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  173. lio = &sp->u.iocb_cmd;
  174. lio->timeout = qla2x00_async_iocb_timeout;
  175. sp->done = qla2x00_async_logout_sp_done;
  176. rval = qla2x00_start_sp(sp);
  177. if (rval != QLA_SUCCESS)
  178. goto done_free_sp;
  179. ql_dbg(ql_dbg_disc, vha, 0x2070,
  180. "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  181. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  182. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  183. return rval;
  184. done_free_sp:
  185. sp->free(fcport->vha, sp);
  186. done:
  187. return rval;
  188. }
  189. static void
  190. qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
  191. {
  192. srb_t *sp = (srb_t *)ptr;
  193. struct srb_iocb *lio = &sp->u.iocb_cmd;
  194. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  195. if (!test_bit(UNLOADING, &vha->dpc_flags))
  196. qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
  197. lio->u.logio.data);
  198. sp->free(sp->fcport->vha, sp);
  199. }
  200. int
  201. qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
  202. uint16_t *data)
  203. {
  204. srb_t *sp;
  205. struct srb_iocb *lio;
  206. int rval;
  207. rval = QLA_FUNCTION_FAILED;
  208. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  209. if (!sp)
  210. goto done;
  211. sp->type = SRB_ADISC_CMD;
  212. sp->name = "adisc";
  213. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  214. lio = &sp->u.iocb_cmd;
  215. lio->timeout = qla2x00_async_iocb_timeout;
  216. sp->done = qla2x00_async_adisc_sp_done;
  217. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  218. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  219. rval = qla2x00_start_sp(sp);
  220. if (rval != QLA_SUCCESS)
  221. goto done_free_sp;
  222. ql_dbg(ql_dbg_disc, vha, 0x206f,
  223. "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
  224. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  225. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  226. return rval;
  227. done_free_sp:
  228. sp->free(fcport->vha, sp);
  229. done:
  230. return rval;
  231. }
  232. static void
  233. qla2x00_tmf_iocb_timeout(void *data)
  234. {
  235. srb_t *sp = (srb_t *)data;
  236. struct srb_iocb *tmf = &sp->u.iocb_cmd;
  237. tmf->u.tmf.comp_status = CS_TIMEOUT;
  238. complete(&tmf->u.tmf.comp);
  239. }
  240. static void
  241. qla2x00_tmf_sp_done(void *data, void *ptr, int res)
  242. {
  243. srb_t *sp = (srb_t *)ptr;
  244. struct srb_iocb *tmf = &sp->u.iocb_cmd;
  245. complete(&tmf->u.tmf.comp);
  246. }
  247. int
  248. qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
  249. uint32_t tag)
  250. {
  251. struct scsi_qla_host *vha = fcport->vha;
  252. struct srb_iocb *tm_iocb;
  253. srb_t *sp;
  254. int rval = QLA_FUNCTION_FAILED;
  255. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  256. if (!sp)
  257. goto done;
  258. tm_iocb = &sp->u.iocb_cmd;
  259. sp->type = SRB_TM_CMD;
  260. sp->name = "tmf";
  261. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
  262. tm_iocb->u.tmf.flags = flags;
  263. tm_iocb->u.tmf.lun = lun;
  264. tm_iocb->u.tmf.data = tag;
  265. sp->done = qla2x00_tmf_sp_done;
  266. tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
  267. init_completion(&tm_iocb->u.tmf.comp);
  268. rval = qla2x00_start_sp(sp);
  269. if (rval != QLA_SUCCESS)
  270. goto done_free_sp;
  271. ql_dbg(ql_dbg_taskm, vha, 0x802f,
  272. "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  273. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  274. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  275. wait_for_completion(&tm_iocb->u.tmf.comp);
  276. rval = tm_iocb->u.tmf.data;
  277. if (rval != QLA_SUCCESS) {
  278. ql_log(ql_log_warn, vha, 0x8030,
  279. "TM IOCB failed (%x).\n", rval);
  280. }
  281. if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
  282. flags = tm_iocb->u.tmf.flags;
  283. lun = (uint16_t)tm_iocb->u.tmf.lun;
  284. /* Issue Marker IOCB */
  285. qla2x00_marker(vha, vha->hw->req_q_map[0],
  286. vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
  287. flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
  288. }
  289. done_free_sp:
  290. sp->free(vha, sp);
  291. done:
  292. return rval;
  293. }
  294. static void
  295. qla24xx_abort_iocb_timeout(void *data)
  296. {
  297. srb_t *sp = (srb_t *)data;
  298. struct srb_iocb *abt = &sp->u.iocb_cmd;
  299. abt->u.abt.comp_status = CS_TIMEOUT;
  300. complete(&abt->u.abt.comp);
  301. }
  302. static void
  303. qla24xx_abort_sp_done(void *data, void *ptr, int res)
  304. {
  305. srb_t *sp = (srb_t *)ptr;
  306. struct srb_iocb *abt = &sp->u.iocb_cmd;
  307. del_timer(&sp->u.iocb_cmd.timer);
  308. complete(&abt->u.abt.comp);
  309. }
  310. static int
  311. qla24xx_async_abort_cmd(srb_t *cmd_sp)
  312. {
  313. scsi_qla_host_t *vha = cmd_sp->fcport->vha;
  314. fc_port_t *fcport = cmd_sp->fcport;
  315. struct srb_iocb *abt_iocb;
  316. srb_t *sp;
  317. int rval = QLA_FUNCTION_FAILED;
  318. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  319. if (!sp)
  320. goto done;
  321. abt_iocb = &sp->u.iocb_cmd;
  322. sp->type = SRB_ABT_CMD;
  323. sp->name = "abort";
  324. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
  325. abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
  326. sp->done = qla24xx_abort_sp_done;
  327. abt_iocb->timeout = qla24xx_abort_iocb_timeout;
  328. init_completion(&abt_iocb->u.abt.comp);
  329. rval = qla2x00_start_sp(sp);
  330. if (rval != QLA_SUCCESS)
  331. goto done_free_sp;
  332. ql_dbg(ql_dbg_async, vha, 0x507c,
  333. "Abort command issued - hdl=%x, target_id=%x\n",
  334. cmd_sp->handle, fcport->tgt_id);
  335. wait_for_completion(&abt_iocb->u.abt.comp);
  336. rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
  337. QLA_SUCCESS : QLA_FUNCTION_FAILED;
  338. done_free_sp:
  339. sp->free(vha, sp);
  340. done:
  341. return rval;
  342. }
  343. int
  344. qla24xx_async_abort_command(srb_t *sp)
  345. {
  346. unsigned long flags = 0;
  347. uint32_t handle;
  348. fc_port_t *fcport = sp->fcport;
  349. struct scsi_qla_host *vha = fcport->vha;
  350. struct qla_hw_data *ha = vha->hw;
  351. struct req_que *req = vha->req;
  352. spin_lock_irqsave(&ha->hardware_lock, flags);
  353. for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
  354. if (req->outstanding_cmds[handle] == sp)
  355. break;
  356. }
  357. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  358. if (handle == req->num_outstanding_cmds) {
  359. /* Command not found. */
  360. return QLA_FUNCTION_FAILED;
  361. }
  362. if (sp->type == SRB_FXIOCB_DCMD)
  363. return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
  364. FXDISC_ABORT_IOCTL);
  365. return qla24xx_async_abort_cmd(sp);
  366. }
  367. void
  368. qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  369. uint16_t *data)
  370. {
  371. int rval;
  372. switch (data[0]) {
  373. case MBS_COMMAND_COMPLETE:
  374. /*
  375. * Driver must validate login state - If PRLI not complete,
  376. * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
  377. * requests.
  378. */
  379. rval = qla2x00_get_port_database(vha, fcport, 0);
  380. if (rval == QLA_NOT_LOGGED_IN) {
  381. fcport->flags &= ~FCF_ASYNC_SENT;
  382. fcport->flags |= FCF_LOGIN_NEEDED;
  383. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  384. break;
  385. }
  386. if (rval != QLA_SUCCESS) {
  387. qla2x00_post_async_logout_work(vha, fcport, NULL);
  388. qla2x00_post_async_login_work(vha, fcport, NULL);
  389. break;
  390. }
  391. if (fcport->flags & FCF_FCP2_DEVICE) {
  392. qla2x00_post_async_adisc_work(vha, fcport, data);
  393. break;
  394. }
  395. qla2x00_update_fcport(vha, fcport);
  396. break;
  397. case MBS_COMMAND_ERROR:
  398. fcport->flags &= ~FCF_ASYNC_SENT;
  399. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  400. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  401. else
  402. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  403. break;
  404. case MBS_PORT_ID_USED:
  405. fcport->loop_id = data[1];
  406. qla2x00_post_async_logout_work(vha, fcport, NULL);
  407. qla2x00_post_async_login_work(vha, fcport, NULL);
  408. break;
  409. case MBS_LOOP_ID_USED:
  410. fcport->loop_id++;
  411. rval = qla2x00_find_new_loop_id(vha, fcport);
  412. if (rval != QLA_SUCCESS) {
  413. fcport->flags &= ~FCF_ASYNC_SENT;
  414. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  415. break;
  416. }
  417. qla2x00_post_async_login_work(vha, fcport, NULL);
  418. break;
  419. }
  420. return;
  421. }
  422. void
  423. qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  424. uint16_t *data)
  425. {
  426. /* Don't re-login in target mode */
  427. if (!fcport->tgt_session)
  428. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  429. qlt_logo_completion_handler(fcport, data[0]);
  430. return;
  431. }
  432. void
  433. qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  434. uint16_t *data)
  435. {
  436. if (data[0] == MBS_COMMAND_COMPLETE) {
  437. qla2x00_update_fcport(vha, fcport);
  438. return;
  439. }
  440. /* Retry login. */
  441. fcport->flags &= ~FCF_ASYNC_SENT;
  442. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  443. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  444. else
  445. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  446. return;
  447. }
  448. /****************************************************************************/
  449. /* QLogic ISP2x00 Hardware Support Functions. */
  450. /****************************************************************************/
  451. static int
  452. qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
  453. {
  454. int rval = QLA_SUCCESS;
  455. struct qla_hw_data *ha = vha->hw;
  456. uint32_t idc_major_ver, idc_minor_ver;
  457. uint16_t config[4];
  458. qla83xx_idc_lock(vha, 0);
  459. /* SV: TODO: Assign initialization timeout from
  460. * flash-info / other param
  461. */
  462. ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
  463. ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
  464. /* Set our fcoe function presence */
  465. if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
  466. ql_dbg(ql_dbg_p3p, vha, 0xb077,
  467. "Error while setting DRV-Presence.\n");
  468. rval = QLA_FUNCTION_FAILED;
  469. goto exit;
  470. }
  471. /* Decide the reset ownership */
  472. qla83xx_reset_ownership(vha);
  473. /*
  474. * On first protocol driver load:
  475. * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
  476. * register.
  477. * Others: Check compatibility with current IDC Major version.
  478. */
  479. qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
  480. if (ha->flags.nic_core_reset_owner) {
  481. /* Set IDC Major version */
  482. idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
  483. qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
  484. /* Clearing IDC-Lock-Recovery register */
  485. qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
  486. } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
  487. /*
  488. * Clear further IDC participation if we are not compatible with
  489. * the current IDC Major Version.
  490. */
  491. ql_log(ql_log_warn, vha, 0xb07d,
  492. "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
  493. idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
  494. __qla83xx_clear_drv_presence(vha);
  495. rval = QLA_FUNCTION_FAILED;
  496. goto exit;
  497. }
  498. /* Each function sets its supported Minor version. */
  499. qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
  500. idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
  501. qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
  502. if (ha->flags.nic_core_reset_owner) {
  503. memset(config, 0, sizeof(config));
  504. if (!qla81xx_get_port_config(vha, config))
  505. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  506. QLA8XXX_DEV_READY);
  507. }
  508. rval = qla83xx_idc_state_handler(vha);
  509. exit:
  510. qla83xx_idc_unlock(vha, 0);
  511. return rval;
  512. }
  513. /*
  514. * qla2x00_initialize_adapter
  515. * Initialize board.
  516. *
  517. * Input:
  518. * ha = adapter block pointer.
  519. *
  520. * Returns:
  521. * 0 = success
  522. */
  523. int
  524. qla2x00_initialize_adapter(scsi_qla_host_t *vha)
  525. {
  526. int rval;
  527. struct qla_hw_data *ha = vha->hw;
  528. struct req_que *req = ha->req_q_map[0];
  529. /* Clear adapter flags. */
  530. vha->flags.online = 0;
  531. ha->flags.chip_reset_done = 0;
  532. vha->flags.reset_active = 0;
  533. ha->flags.pci_channel_io_perm_failure = 0;
  534. ha->flags.eeh_busy = 0;
  535. vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
  536. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  537. atomic_set(&vha->loop_state, LOOP_DOWN);
  538. vha->device_flags = DFLG_NO_CABLE;
  539. vha->dpc_flags = 0;
  540. vha->flags.management_server_logged_in = 0;
  541. vha->marker_needed = 0;
  542. ha->isp_abort_cnt = 0;
  543. ha->beacon_blink_led = 0;
  544. set_bit(0, ha->req_qid_map);
  545. set_bit(0, ha->rsp_qid_map);
  546. ql_dbg(ql_dbg_init, vha, 0x0040,
  547. "Configuring PCI space...\n");
  548. rval = ha->isp_ops->pci_config(vha);
  549. if (rval) {
  550. ql_log(ql_log_warn, vha, 0x0044,
  551. "Unable to configure PCI space.\n");
  552. return (rval);
  553. }
  554. ha->isp_ops->reset_chip(vha);
  555. rval = qla2xxx_get_flash_info(vha);
  556. if (rval) {
  557. ql_log(ql_log_fatal, vha, 0x004f,
  558. "Unable to validate FLASH data.\n");
  559. return rval;
  560. }
  561. if (IS_QLA8044(ha)) {
  562. qla8044_read_reset_template(vha);
  563. /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  564. * If DONRESET_BIT0 is set, drivers should not set dev_state
  565. * to NEED_RESET. But if NEED_RESET is set, drivers should
  566. * should honor the reset. */
  567. if (ql2xdontresethba == 1)
  568. qla8044_set_idc_dontreset(vha);
  569. }
  570. ha->isp_ops->get_flash_version(vha, req->ring);
  571. ql_dbg(ql_dbg_init, vha, 0x0061,
  572. "Configure NVRAM parameters...\n");
  573. ha->isp_ops->nvram_config(vha);
  574. if (ha->flags.disable_serdes) {
  575. /* Mask HBA via NVRAM settings? */
  576. ql_log(ql_log_info, vha, 0x0077,
  577. "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
  578. return QLA_FUNCTION_FAILED;
  579. }
  580. ql_dbg(ql_dbg_init, vha, 0x0078,
  581. "Verifying loaded RISC code...\n");
  582. if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
  583. rval = ha->isp_ops->chip_diag(vha);
  584. if (rval)
  585. return (rval);
  586. rval = qla2x00_setup_chip(vha);
  587. if (rval)
  588. return (rval);
  589. }
  590. if (IS_QLA84XX(ha)) {
  591. ha->cs84xx = qla84xx_get_chip(vha);
  592. if (!ha->cs84xx) {
  593. ql_log(ql_log_warn, vha, 0x00d0,
  594. "Unable to configure ISP84XX.\n");
  595. return QLA_FUNCTION_FAILED;
  596. }
  597. }
  598. if (qla_ini_mode_enabled(vha))
  599. rval = qla2x00_init_rings(vha);
  600. ha->flags.chip_reset_done = 1;
  601. if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
  602. /* Issue verify 84xx FW IOCB to complete 84xx initialization */
  603. rval = qla84xx_init_chip(vha);
  604. if (rval != QLA_SUCCESS) {
  605. ql_log(ql_log_warn, vha, 0x00d4,
  606. "Unable to initialize ISP84XX.\n");
  607. qla84xx_put_chip(vha);
  608. }
  609. }
  610. /* Load the NIC Core f/w if we are the first protocol driver. */
  611. if (IS_QLA8031(ha)) {
  612. rval = qla83xx_nic_core_fw_load(vha);
  613. if (rval)
  614. ql_log(ql_log_warn, vha, 0x0124,
  615. "Error in initializing NIC Core f/w.\n");
  616. }
  617. if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
  618. qla24xx_read_fcp_prio_cfg(vha);
  619. if (IS_P3P_TYPE(ha))
  620. qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
  621. else
  622. qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
  623. return (rval);
  624. }
  625. /**
  626. * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
  627. * @ha: HA context
  628. *
  629. * Returns 0 on success.
  630. */
  631. int
  632. qla2100_pci_config(scsi_qla_host_t *vha)
  633. {
  634. uint16_t w;
  635. unsigned long flags;
  636. struct qla_hw_data *ha = vha->hw;
  637. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  638. pci_set_master(ha->pdev);
  639. pci_try_set_mwi(ha->pdev);
  640. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  641. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  642. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  643. pci_disable_rom(ha->pdev);
  644. /* Get PCI bus information. */
  645. spin_lock_irqsave(&ha->hardware_lock, flags);
  646. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  647. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  648. return QLA_SUCCESS;
  649. }
  650. /**
  651. * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
  652. * @ha: HA context
  653. *
  654. * Returns 0 on success.
  655. */
  656. int
  657. qla2300_pci_config(scsi_qla_host_t *vha)
  658. {
  659. uint16_t w;
  660. unsigned long flags = 0;
  661. uint32_t cnt;
  662. struct qla_hw_data *ha = vha->hw;
  663. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  664. pci_set_master(ha->pdev);
  665. pci_try_set_mwi(ha->pdev);
  666. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  667. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  668. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  669. w &= ~PCI_COMMAND_INTX_DISABLE;
  670. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  671. /*
  672. * If this is a 2300 card and not 2312, reset the
  673. * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
  674. * the 2310 also reports itself as a 2300 so we need to get the
  675. * fb revision level -- a 6 indicates it really is a 2300 and
  676. * not a 2310.
  677. */
  678. if (IS_QLA2300(ha)) {
  679. spin_lock_irqsave(&ha->hardware_lock, flags);
  680. /* Pause RISC. */
  681. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  682. for (cnt = 0; cnt < 30000; cnt++) {
  683. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  684. break;
  685. udelay(10);
  686. }
  687. /* Select FPM registers. */
  688. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  689. RD_REG_WORD(&reg->ctrl_status);
  690. /* Get the fb rev level */
  691. ha->fb_rev = RD_FB_CMD_REG(ha, reg);
  692. if (ha->fb_rev == FPM_2300)
  693. pci_clear_mwi(ha->pdev);
  694. /* Deselect FPM registers. */
  695. WRT_REG_WORD(&reg->ctrl_status, 0x0);
  696. RD_REG_WORD(&reg->ctrl_status);
  697. /* Release RISC module. */
  698. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  699. for (cnt = 0; cnt < 30000; cnt++) {
  700. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
  701. break;
  702. udelay(10);
  703. }
  704. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  705. }
  706. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  707. pci_disable_rom(ha->pdev);
  708. /* Get PCI bus information. */
  709. spin_lock_irqsave(&ha->hardware_lock, flags);
  710. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  711. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  712. return QLA_SUCCESS;
  713. }
  714. /**
  715. * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
  716. * @ha: HA context
  717. *
  718. * Returns 0 on success.
  719. */
  720. int
  721. qla24xx_pci_config(scsi_qla_host_t *vha)
  722. {
  723. uint16_t w;
  724. unsigned long flags = 0;
  725. struct qla_hw_data *ha = vha->hw;
  726. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  727. pci_set_master(ha->pdev);
  728. pci_try_set_mwi(ha->pdev);
  729. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  730. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  731. w &= ~PCI_COMMAND_INTX_DISABLE;
  732. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  733. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  734. /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
  735. if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
  736. pcix_set_mmrbc(ha->pdev, 2048);
  737. /* PCIe -- adjust Maximum Read Request Size (2048). */
  738. if (pci_is_pcie(ha->pdev))
  739. pcie_set_readrq(ha->pdev, 4096);
  740. pci_disable_rom(ha->pdev);
  741. ha->chip_revision = ha->pdev->revision;
  742. /* Get PCI bus information. */
  743. spin_lock_irqsave(&ha->hardware_lock, flags);
  744. ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
  745. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  746. return QLA_SUCCESS;
  747. }
  748. /**
  749. * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
  750. * @ha: HA context
  751. *
  752. * Returns 0 on success.
  753. */
  754. int
  755. qla25xx_pci_config(scsi_qla_host_t *vha)
  756. {
  757. uint16_t w;
  758. struct qla_hw_data *ha = vha->hw;
  759. pci_set_master(ha->pdev);
  760. pci_try_set_mwi(ha->pdev);
  761. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  762. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  763. w &= ~PCI_COMMAND_INTX_DISABLE;
  764. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  765. /* PCIe -- adjust Maximum Read Request Size (2048). */
  766. if (pci_is_pcie(ha->pdev))
  767. pcie_set_readrq(ha->pdev, 4096);
  768. pci_disable_rom(ha->pdev);
  769. ha->chip_revision = ha->pdev->revision;
  770. return QLA_SUCCESS;
  771. }
  772. /**
  773. * qla2x00_isp_firmware() - Choose firmware image.
  774. * @ha: HA context
  775. *
  776. * Returns 0 on success.
  777. */
  778. static int
  779. qla2x00_isp_firmware(scsi_qla_host_t *vha)
  780. {
  781. int rval;
  782. uint16_t loop_id, topo, sw_cap;
  783. uint8_t domain, area, al_pa;
  784. struct qla_hw_data *ha = vha->hw;
  785. /* Assume loading risc code */
  786. rval = QLA_FUNCTION_FAILED;
  787. if (ha->flags.disable_risc_code_load) {
  788. ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
  789. /* Verify checksum of loaded RISC code. */
  790. rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
  791. if (rval == QLA_SUCCESS) {
  792. /* And, verify we are not in ROM code. */
  793. rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
  794. &area, &domain, &topo, &sw_cap);
  795. }
  796. }
  797. if (rval)
  798. ql_dbg(ql_dbg_init, vha, 0x007a,
  799. "**** Load RISC code ****.\n");
  800. return (rval);
  801. }
  802. /**
  803. * qla2x00_reset_chip() - Reset ISP chip.
  804. * @ha: HA context
  805. *
  806. * Returns 0 on success.
  807. */
  808. void
  809. qla2x00_reset_chip(scsi_qla_host_t *vha)
  810. {
  811. unsigned long flags = 0;
  812. struct qla_hw_data *ha = vha->hw;
  813. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  814. uint32_t cnt;
  815. uint16_t cmd;
  816. if (unlikely(pci_channel_offline(ha->pdev)))
  817. return;
  818. ha->isp_ops->disable_intrs(ha);
  819. spin_lock_irqsave(&ha->hardware_lock, flags);
  820. /* Turn off master enable */
  821. cmd = 0;
  822. pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
  823. cmd &= ~PCI_COMMAND_MASTER;
  824. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  825. if (!IS_QLA2100(ha)) {
  826. /* Pause RISC. */
  827. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  828. if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
  829. for (cnt = 0; cnt < 30000; cnt++) {
  830. if ((RD_REG_WORD(&reg->hccr) &
  831. HCCR_RISC_PAUSE) != 0)
  832. break;
  833. udelay(100);
  834. }
  835. } else {
  836. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  837. udelay(10);
  838. }
  839. /* Select FPM registers. */
  840. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  841. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  842. /* FPM Soft Reset. */
  843. WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
  844. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  845. /* Toggle Fpm Reset. */
  846. if (!IS_QLA2200(ha)) {
  847. WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
  848. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  849. }
  850. /* Select frame buffer registers. */
  851. WRT_REG_WORD(&reg->ctrl_status, 0x10);
  852. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  853. /* Reset frame buffer FIFOs. */
  854. if (IS_QLA2200(ha)) {
  855. WRT_FB_CMD_REG(ha, reg, 0xa000);
  856. RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
  857. } else {
  858. WRT_FB_CMD_REG(ha, reg, 0x00fc);
  859. /* Read back fb_cmd until zero or 3 seconds max */
  860. for (cnt = 0; cnt < 3000; cnt++) {
  861. if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
  862. break;
  863. udelay(100);
  864. }
  865. }
  866. /* Select RISC module registers. */
  867. WRT_REG_WORD(&reg->ctrl_status, 0);
  868. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  869. /* Reset RISC processor. */
  870. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  871. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  872. /* Release RISC processor. */
  873. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  874. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  875. }
  876. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  877. WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
  878. /* Reset ISP chip. */
  879. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  880. /* Wait for RISC to recover from reset. */
  881. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  882. /*
  883. * It is necessary to for a delay here since the card doesn't
  884. * respond to PCI reads during a reset. On some architectures
  885. * this will result in an MCA.
  886. */
  887. udelay(20);
  888. for (cnt = 30000; cnt; cnt--) {
  889. if ((RD_REG_WORD(&reg->ctrl_status) &
  890. CSR_ISP_SOFT_RESET) == 0)
  891. break;
  892. udelay(100);
  893. }
  894. } else
  895. udelay(10);
  896. /* Reset RISC processor. */
  897. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  898. WRT_REG_WORD(&reg->semaphore, 0);
  899. /* Release RISC processor. */
  900. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  901. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  902. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  903. for (cnt = 0; cnt < 30000; cnt++) {
  904. if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
  905. break;
  906. udelay(100);
  907. }
  908. } else
  909. udelay(100);
  910. /* Turn on master enable */
  911. cmd |= PCI_COMMAND_MASTER;
  912. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  913. /* Disable RISC pause on FPM parity error. */
  914. if (!IS_QLA2100(ha)) {
  915. WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
  916. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  917. }
  918. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  919. }
  920. /**
  921. * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
  922. *
  923. * Returns 0 on success.
  924. */
  925. static int
  926. qla81xx_reset_mpi(scsi_qla_host_t *vha)
  927. {
  928. uint16_t mb[4] = {0x1010, 0, 1, 0};
  929. if (!IS_QLA81XX(vha->hw))
  930. return QLA_SUCCESS;
  931. return qla81xx_write_mpi_register(vha, mb);
  932. }
  933. /**
  934. * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
  935. * @ha: HA context
  936. *
  937. * Returns 0 on success.
  938. */
  939. static inline int
  940. qla24xx_reset_risc(scsi_qla_host_t *vha)
  941. {
  942. unsigned long flags = 0;
  943. struct qla_hw_data *ha = vha->hw;
  944. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  945. uint32_t cnt;
  946. uint16_t wd;
  947. static int abts_cnt; /* ISP abort retry counts */
  948. int rval = QLA_SUCCESS;
  949. spin_lock_irqsave(&ha->hardware_lock, flags);
  950. /* Reset RISC. */
  951. WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  952. for (cnt = 0; cnt < 30000; cnt++) {
  953. if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
  954. break;
  955. udelay(10);
  956. }
  957. if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
  958. set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
  959. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
  960. "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
  961. RD_REG_DWORD(&reg->hccr),
  962. RD_REG_DWORD(&reg->ctrl_status),
  963. (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
  964. WRT_REG_DWORD(&reg->ctrl_status,
  965. CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  966. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  967. udelay(100);
  968. /* Wait for firmware to complete NVRAM accesses. */
  969. RD_REG_WORD(&reg->mailbox0);
  970. for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
  971. rval == QLA_SUCCESS; cnt--) {
  972. barrier();
  973. if (cnt)
  974. udelay(5);
  975. else
  976. rval = QLA_FUNCTION_TIMEOUT;
  977. }
  978. if (rval == QLA_SUCCESS)
  979. set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
  980. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
  981. "HCCR: 0x%x, MailBox0 Status 0x%x\n",
  982. RD_REG_DWORD(&reg->hccr),
  983. RD_REG_DWORD(&reg->mailbox0));
  984. /* Wait for soft-reset to complete. */
  985. RD_REG_DWORD(&reg->ctrl_status);
  986. for (cnt = 0; cnt < 6000000; cnt++) {
  987. barrier();
  988. if ((RD_REG_DWORD(&reg->ctrl_status) &
  989. CSRX_ISP_SOFT_RESET) == 0)
  990. break;
  991. udelay(5);
  992. }
  993. if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
  994. set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
  995. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
  996. "HCCR: 0x%x, Soft Reset status: 0x%x\n",
  997. RD_REG_DWORD(&reg->hccr),
  998. RD_REG_DWORD(&reg->ctrl_status));
  999. /* If required, do an MPI FW reset now */
  1000. if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
  1001. if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
  1002. if (++abts_cnt < 5) {
  1003. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1004. set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
  1005. } else {
  1006. /*
  1007. * We exhausted the ISP abort retries. We have to
  1008. * set the board offline.
  1009. */
  1010. abts_cnt = 0;
  1011. vha->flags.online = 0;
  1012. }
  1013. }
  1014. }
  1015. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  1016. RD_REG_DWORD(&reg->hccr);
  1017. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  1018. RD_REG_DWORD(&reg->hccr);
  1019. WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
  1020. RD_REG_DWORD(&reg->hccr);
  1021. RD_REG_WORD(&reg->mailbox0);
  1022. for (cnt = 6000000; RD_REG_WORD(&reg->mailbox0) != 0 &&
  1023. rval == QLA_SUCCESS; cnt--) {
  1024. barrier();
  1025. if (cnt)
  1026. udelay(5);
  1027. else
  1028. rval = QLA_FUNCTION_TIMEOUT;
  1029. }
  1030. if (rval == QLA_SUCCESS)
  1031. set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
  1032. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
  1033. "Host Risc 0x%x, mailbox0 0x%x\n",
  1034. RD_REG_DWORD(&reg->hccr),
  1035. RD_REG_WORD(&reg->mailbox0));
  1036. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1037. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
  1038. "Driver in %s mode\n",
  1039. IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
  1040. if (IS_NOPOLLING_TYPE(ha))
  1041. ha->isp_ops->enable_intrs(ha);
  1042. return rval;
  1043. }
  1044. static void
  1045. qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
  1046. {
  1047. struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
  1048. WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
  1049. *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
  1050. }
  1051. static void
  1052. qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
  1053. {
  1054. struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
  1055. WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
  1056. WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
  1057. }
  1058. static void
  1059. qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
  1060. {
  1061. uint32_t wd32 = 0;
  1062. uint delta_msec = 100;
  1063. uint elapsed_msec = 0;
  1064. uint timeout_msec;
  1065. ulong n;
  1066. if (vha->hw->pdev->subsystem_device != 0x0175 &&
  1067. vha->hw->pdev->subsystem_device != 0x0240)
  1068. return;
  1069. WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
  1070. udelay(100);
  1071. attempt:
  1072. timeout_msec = TIMEOUT_SEMAPHORE;
  1073. n = timeout_msec / delta_msec;
  1074. while (n--) {
  1075. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
  1076. qla25xx_read_risc_sema_reg(vha, &wd32);
  1077. if (wd32 & RISC_SEMAPHORE)
  1078. break;
  1079. msleep(delta_msec);
  1080. elapsed_msec += delta_msec;
  1081. if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
  1082. goto force;
  1083. }
  1084. if (!(wd32 & RISC_SEMAPHORE))
  1085. goto force;
  1086. if (!(wd32 & RISC_SEMAPHORE_FORCE))
  1087. goto acquired;
  1088. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
  1089. timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
  1090. n = timeout_msec / delta_msec;
  1091. while (n--) {
  1092. qla25xx_read_risc_sema_reg(vha, &wd32);
  1093. if (!(wd32 & RISC_SEMAPHORE_FORCE))
  1094. break;
  1095. msleep(delta_msec);
  1096. elapsed_msec += delta_msec;
  1097. if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
  1098. goto force;
  1099. }
  1100. if (wd32 & RISC_SEMAPHORE_FORCE)
  1101. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
  1102. goto attempt;
  1103. force:
  1104. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
  1105. acquired:
  1106. return;
  1107. }
  1108. /**
  1109. * qla24xx_reset_chip() - Reset ISP24xx chip.
  1110. * @ha: HA context
  1111. *
  1112. * Returns 0 on success.
  1113. */
  1114. void
  1115. qla24xx_reset_chip(scsi_qla_host_t *vha)
  1116. {
  1117. struct qla_hw_data *ha = vha->hw;
  1118. if (pci_channel_offline(ha->pdev) &&
  1119. ha->flags.pci_channel_io_perm_failure) {
  1120. return;
  1121. }
  1122. ha->isp_ops->disable_intrs(ha);
  1123. qla25xx_manipulate_risc_semaphore(vha);
  1124. /* Perform RISC reset. */
  1125. qla24xx_reset_risc(vha);
  1126. }
  1127. /**
  1128. * qla2x00_chip_diag() - Test chip for proper operation.
  1129. * @ha: HA context
  1130. *
  1131. * Returns 0 on success.
  1132. */
  1133. int
  1134. qla2x00_chip_diag(scsi_qla_host_t *vha)
  1135. {
  1136. int rval;
  1137. struct qla_hw_data *ha = vha->hw;
  1138. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1139. unsigned long flags = 0;
  1140. uint16_t data;
  1141. uint32_t cnt;
  1142. uint16_t mb[5];
  1143. struct req_que *req = ha->req_q_map[0];
  1144. /* Assume a failed state */
  1145. rval = QLA_FUNCTION_FAILED;
  1146. ql_dbg(ql_dbg_init, vha, 0x007b,
  1147. "Testing device at %lx.\n", (u_long)&reg->flash_address);
  1148. spin_lock_irqsave(&ha->hardware_lock, flags);
  1149. /* Reset ISP chip. */
  1150. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  1151. /*
  1152. * We need to have a delay here since the card will not respond while
  1153. * in reset causing an MCA on some architectures.
  1154. */
  1155. udelay(20);
  1156. data = qla2x00_debounce_register(&reg->ctrl_status);
  1157. for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
  1158. udelay(5);
  1159. data = RD_REG_WORD(&reg->ctrl_status);
  1160. barrier();
  1161. }
  1162. if (!cnt)
  1163. goto chip_diag_failed;
  1164. ql_dbg(ql_dbg_init, vha, 0x007c,
  1165. "Reset register cleared by chip reset.\n");
  1166. /* Reset RISC processor. */
  1167. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  1168. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  1169. /* Workaround for QLA2312 PCI parity error */
  1170. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  1171. data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
  1172. for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
  1173. udelay(5);
  1174. data = RD_MAILBOX_REG(ha, reg, 0);
  1175. barrier();
  1176. }
  1177. } else
  1178. udelay(10);
  1179. if (!cnt)
  1180. goto chip_diag_failed;
  1181. /* Check product ID of chip */
  1182. ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
  1183. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  1184. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  1185. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  1186. mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
  1187. if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
  1188. mb[3] != PROD_ID_3) {
  1189. ql_log(ql_log_warn, vha, 0x0062,
  1190. "Wrong product ID = 0x%x,0x%x,0x%x.\n",
  1191. mb[1], mb[2], mb[3]);
  1192. goto chip_diag_failed;
  1193. }
  1194. ha->product_id[0] = mb[1];
  1195. ha->product_id[1] = mb[2];
  1196. ha->product_id[2] = mb[3];
  1197. ha->product_id[3] = mb[4];
  1198. /* Adjust fw RISC transfer size */
  1199. if (req->length > 1024)
  1200. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
  1201. else
  1202. ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
  1203. req->length;
  1204. if (IS_QLA2200(ha) &&
  1205. RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
  1206. /* Limit firmware transfer size with a 2200A */
  1207. ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
  1208. ha->device_type |= DT_ISP2200A;
  1209. ha->fw_transfer_size = 128;
  1210. }
  1211. /* Wrap Incoming Mailboxes Test. */
  1212. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1213. ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
  1214. rval = qla2x00_mbx_reg_test(vha);
  1215. if (rval)
  1216. ql_log(ql_log_warn, vha, 0x0080,
  1217. "Failed mailbox send register test.\n");
  1218. else
  1219. /* Flag a successful rval */
  1220. rval = QLA_SUCCESS;
  1221. spin_lock_irqsave(&ha->hardware_lock, flags);
  1222. chip_diag_failed:
  1223. if (rval)
  1224. ql_log(ql_log_info, vha, 0x0081,
  1225. "Chip diagnostics **** FAILED ****.\n");
  1226. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1227. return (rval);
  1228. }
  1229. /**
  1230. * qla24xx_chip_diag() - Test ISP24xx for proper operation.
  1231. * @ha: HA context
  1232. *
  1233. * Returns 0 on success.
  1234. */
  1235. int
  1236. qla24xx_chip_diag(scsi_qla_host_t *vha)
  1237. {
  1238. int rval;
  1239. struct qla_hw_data *ha = vha->hw;
  1240. struct req_que *req = ha->req_q_map[0];
  1241. if (IS_P3P_TYPE(ha))
  1242. return QLA_SUCCESS;
  1243. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
  1244. rval = qla2x00_mbx_reg_test(vha);
  1245. if (rval) {
  1246. ql_log(ql_log_warn, vha, 0x0082,
  1247. "Failed mailbox send register test.\n");
  1248. } else {
  1249. /* Flag a successful rval */
  1250. rval = QLA_SUCCESS;
  1251. }
  1252. return rval;
  1253. }
  1254. void
  1255. qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
  1256. {
  1257. int rval;
  1258. uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
  1259. eft_size, fce_size, mq_size;
  1260. dma_addr_t tc_dma;
  1261. void *tc;
  1262. struct qla_hw_data *ha = vha->hw;
  1263. struct req_que *req = ha->req_q_map[0];
  1264. struct rsp_que *rsp = ha->rsp_q_map[0];
  1265. if (ha->fw_dump) {
  1266. ql_dbg(ql_dbg_init, vha, 0x00bd,
  1267. "Firmware dump already allocated.\n");
  1268. return;
  1269. }
  1270. ha->fw_dumped = 0;
  1271. ha->fw_dump_cap_flags = 0;
  1272. dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
  1273. req_q_size = rsp_q_size = 0;
  1274. if (IS_QLA27XX(ha))
  1275. goto try_fce;
  1276. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1277. fixed_size = sizeof(struct qla2100_fw_dump);
  1278. } else if (IS_QLA23XX(ha)) {
  1279. fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
  1280. mem_size = (ha->fw_memory_size - 0x11000 + 1) *
  1281. sizeof(uint16_t);
  1282. } else if (IS_FWI2_CAPABLE(ha)) {
  1283. if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
  1284. fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
  1285. else if (IS_QLA81XX(ha))
  1286. fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
  1287. else if (IS_QLA25XX(ha))
  1288. fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
  1289. else
  1290. fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
  1291. mem_size = (ha->fw_memory_size - 0x100000 + 1) *
  1292. sizeof(uint32_t);
  1293. if (ha->mqenable) {
  1294. if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
  1295. mq_size = sizeof(struct qla2xxx_mq_chain);
  1296. /*
  1297. * Allocate maximum buffer size for all queues.
  1298. * Resizing must be done at end-of-dump processing.
  1299. */
  1300. mq_size += ha->max_req_queues *
  1301. (req->length * sizeof(request_t));
  1302. mq_size += ha->max_rsp_queues *
  1303. (rsp->length * sizeof(response_t));
  1304. }
  1305. if (ha->tgt.atio_ring)
  1306. mq_size += ha->tgt.atio_q_length * sizeof(request_t);
  1307. /* Allocate memory for Fibre Channel Event Buffer. */
  1308. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
  1309. !IS_QLA27XX(ha))
  1310. goto try_eft;
  1311. try_fce:
  1312. if (ha->fce)
  1313. dma_free_coherent(&ha->pdev->dev,
  1314. FCE_SIZE, ha->fce, ha->fce_dma);
  1315. /* Allocate memory for Fibre Channel Event Buffer. */
  1316. tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
  1317. GFP_KERNEL);
  1318. if (!tc) {
  1319. ql_log(ql_log_warn, vha, 0x00be,
  1320. "Unable to allocate (%d KB) for FCE.\n",
  1321. FCE_SIZE / 1024);
  1322. goto try_eft;
  1323. }
  1324. rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
  1325. ha->fce_mb, &ha->fce_bufs);
  1326. if (rval) {
  1327. ql_log(ql_log_warn, vha, 0x00bf,
  1328. "Unable to initialize FCE (%d).\n", rval);
  1329. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
  1330. tc_dma);
  1331. ha->flags.fce_enabled = 0;
  1332. goto try_eft;
  1333. }
  1334. ql_dbg(ql_dbg_init, vha, 0x00c0,
  1335. "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
  1336. fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
  1337. ha->flags.fce_enabled = 1;
  1338. ha->fce_dma = tc_dma;
  1339. ha->fce = tc;
  1340. try_eft:
  1341. if (ha->eft)
  1342. dma_free_coherent(&ha->pdev->dev,
  1343. EFT_SIZE, ha->eft, ha->eft_dma);
  1344. /* Allocate memory for Extended Trace Buffer. */
  1345. tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
  1346. GFP_KERNEL);
  1347. if (!tc) {
  1348. ql_log(ql_log_warn, vha, 0x00c1,
  1349. "Unable to allocate (%d KB) for EFT.\n",
  1350. EFT_SIZE / 1024);
  1351. goto cont_alloc;
  1352. }
  1353. rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
  1354. if (rval) {
  1355. ql_log(ql_log_warn, vha, 0x00c2,
  1356. "Unable to initialize EFT (%d).\n", rval);
  1357. dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
  1358. tc_dma);
  1359. goto cont_alloc;
  1360. }
  1361. ql_dbg(ql_dbg_init, vha, 0x00c3,
  1362. "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
  1363. eft_size = EFT_SIZE;
  1364. ha->eft_dma = tc_dma;
  1365. ha->eft = tc;
  1366. }
  1367. cont_alloc:
  1368. if (IS_QLA27XX(ha)) {
  1369. if (!ha->fw_dump_template) {
  1370. ql_log(ql_log_warn, vha, 0x00ba,
  1371. "Failed missing fwdump template\n");
  1372. return;
  1373. }
  1374. dump_size = qla27xx_fwdt_calculate_dump_size(vha);
  1375. ql_dbg(ql_dbg_init, vha, 0x00fa,
  1376. "-> allocating fwdump (%x bytes)...\n", dump_size);
  1377. goto allocate;
  1378. }
  1379. req_q_size = req->length * sizeof(request_t);
  1380. rsp_q_size = rsp->length * sizeof(response_t);
  1381. dump_size = offsetof(struct qla2xxx_fw_dump, isp);
  1382. dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
  1383. ha->chain_offset = dump_size;
  1384. dump_size += mq_size + fce_size;
  1385. allocate:
  1386. ha->fw_dump = vmalloc(dump_size);
  1387. if (!ha->fw_dump) {
  1388. ql_log(ql_log_warn, vha, 0x00c4,
  1389. "Unable to allocate (%d KB) for firmware dump.\n",
  1390. dump_size / 1024);
  1391. if (ha->fce) {
  1392. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  1393. ha->fce_dma);
  1394. ha->fce = NULL;
  1395. ha->fce_dma = 0;
  1396. }
  1397. if (ha->eft) {
  1398. dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
  1399. ha->eft_dma);
  1400. ha->eft = NULL;
  1401. ha->eft_dma = 0;
  1402. }
  1403. return;
  1404. }
  1405. ha->fw_dump_len = dump_size;
  1406. ql_dbg(ql_dbg_init, vha, 0x00c5,
  1407. "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
  1408. if (IS_QLA27XX(ha))
  1409. return;
  1410. ha->fw_dump->signature[0] = 'Q';
  1411. ha->fw_dump->signature[1] = 'L';
  1412. ha->fw_dump->signature[2] = 'G';
  1413. ha->fw_dump->signature[3] = 'C';
  1414. ha->fw_dump->version = htonl(1);
  1415. ha->fw_dump->fixed_size = htonl(fixed_size);
  1416. ha->fw_dump->mem_size = htonl(mem_size);
  1417. ha->fw_dump->req_q_size = htonl(req_q_size);
  1418. ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
  1419. ha->fw_dump->eft_size = htonl(eft_size);
  1420. ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
  1421. ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
  1422. ha->fw_dump->header_size =
  1423. htonl(offsetof(struct qla2xxx_fw_dump, isp));
  1424. }
  1425. static int
  1426. qla81xx_mpi_sync(scsi_qla_host_t *vha)
  1427. {
  1428. #define MPS_MASK 0xe0
  1429. int rval;
  1430. uint16_t dc;
  1431. uint32_t dw;
  1432. if (!IS_QLA81XX(vha->hw))
  1433. return QLA_SUCCESS;
  1434. rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
  1435. if (rval != QLA_SUCCESS) {
  1436. ql_log(ql_log_warn, vha, 0x0105,
  1437. "Unable to acquire semaphore.\n");
  1438. goto done;
  1439. }
  1440. pci_read_config_word(vha->hw->pdev, 0x54, &dc);
  1441. rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
  1442. if (rval != QLA_SUCCESS) {
  1443. ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
  1444. goto done_release;
  1445. }
  1446. dc &= MPS_MASK;
  1447. if (dc == (dw & MPS_MASK))
  1448. goto done_release;
  1449. dw &= ~MPS_MASK;
  1450. dw |= dc;
  1451. rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
  1452. if (rval != QLA_SUCCESS) {
  1453. ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
  1454. }
  1455. done_release:
  1456. rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
  1457. if (rval != QLA_SUCCESS) {
  1458. ql_log(ql_log_warn, vha, 0x006d,
  1459. "Unable to release semaphore.\n");
  1460. }
  1461. done:
  1462. return rval;
  1463. }
  1464. int
  1465. qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
  1466. {
  1467. /* Don't try to reallocate the array */
  1468. if (req->outstanding_cmds)
  1469. return QLA_SUCCESS;
  1470. if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
  1471. (ql2xmultique_tag || ql2xmaxqueues > 1)))
  1472. req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
  1473. else {
  1474. if (ha->fw_xcb_count <= ha->fw_iocb_count)
  1475. req->num_outstanding_cmds = ha->fw_xcb_count;
  1476. else
  1477. req->num_outstanding_cmds = ha->fw_iocb_count;
  1478. }
  1479. req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
  1480. req->num_outstanding_cmds, GFP_KERNEL);
  1481. if (!req->outstanding_cmds) {
  1482. /*
  1483. * Try to allocate a minimal size just so we can get through
  1484. * initialization.
  1485. */
  1486. req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
  1487. req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
  1488. req->num_outstanding_cmds, GFP_KERNEL);
  1489. if (!req->outstanding_cmds) {
  1490. ql_log(ql_log_fatal, NULL, 0x0126,
  1491. "Failed to allocate memory for "
  1492. "outstanding_cmds for req_que %p.\n", req);
  1493. req->num_outstanding_cmds = 0;
  1494. return QLA_FUNCTION_FAILED;
  1495. }
  1496. }
  1497. return QLA_SUCCESS;
  1498. }
  1499. /**
  1500. * qla2x00_setup_chip() - Load and start RISC firmware.
  1501. * @ha: HA context
  1502. *
  1503. * Returns 0 on success.
  1504. */
  1505. static int
  1506. qla2x00_setup_chip(scsi_qla_host_t *vha)
  1507. {
  1508. int rval;
  1509. uint32_t srisc_address = 0;
  1510. struct qla_hw_data *ha = vha->hw;
  1511. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1512. unsigned long flags;
  1513. uint16_t fw_major_version;
  1514. if (IS_P3P_TYPE(ha)) {
  1515. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  1516. if (rval == QLA_SUCCESS) {
  1517. qla2x00_stop_firmware(vha);
  1518. goto enable_82xx_npiv;
  1519. } else
  1520. goto failed;
  1521. }
  1522. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1523. /* Disable SRAM, Instruction RAM and GP RAM parity. */
  1524. spin_lock_irqsave(&ha->hardware_lock, flags);
  1525. WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
  1526. RD_REG_WORD(&reg->hccr);
  1527. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1528. }
  1529. qla81xx_mpi_sync(vha);
  1530. /* Load firmware sequences */
  1531. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  1532. if (rval == QLA_SUCCESS) {
  1533. ql_dbg(ql_dbg_init, vha, 0x00c9,
  1534. "Verifying Checksum of loaded RISC code.\n");
  1535. rval = qla2x00_verify_checksum(vha, srisc_address);
  1536. if (rval == QLA_SUCCESS) {
  1537. /* Start firmware execution. */
  1538. ql_dbg(ql_dbg_init, vha, 0x00ca,
  1539. "Starting firmware.\n");
  1540. rval = qla2x00_execute_fw(vha, srisc_address);
  1541. /* Retrieve firmware information. */
  1542. if (rval == QLA_SUCCESS) {
  1543. enable_82xx_npiv:
  1544. fw_major_version = ha->fw_major_version;
  1545. if (IS_P3P_TYPE(ha))
  1546. qla82xx_check_md_needed(vha);
  1547. else
  1548. rval = qla2x00_get_fw_version(vha);
  1549. if (rval != QLA_SUCCESS)
  1550. goto failed;
  1551. ha->flags.npiv_supported = 0;
  1552. if (IS_QLA2XXX_MIDTYPE(ha) &&
  1553. (ha->fw_attributes & BIT_2)) {
  1554. ha->flags.npiv_supported = 1;
  1555. if ((!ha->max_npiv_vports) ||
  1556. ((ha->max_npiv_vports + 1) %
  1557. MIN_MULTI_ID_FABRIC))
  1558. ha->max_npiv_vports =
  1559. MIN_MULTI_ID_FABRIC - 1;
  1560. }
  1561. qla2x00_get_resource_cnts(vha, NULL,
  1562. &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
  1563. &ha->max_npiv_vports, NULL);
  1564. /*
  1565. * Allocate the array of outstanding commands
  1566. * now that we know the firmware resources.
  1567. */
  1568. rval = qla2x00_alloc_outstanding_cmds(ha,
  1569. vha->req);
  1570. if (rval != QLA_SUCCESS)
  1571. goto failed;
  1572. if (!fw_major_version && ql2xallocfwdump
  1573. && !(IS_P3P_TYPE(ha)))
  1574. qla2x00_alloc_fw_dump(vha);
  1575. } else {
  1576. goto failed;
  1577. }
  1578. } else {
  1579. ql_log(ql_log_fatal, vha, 0x00cd,
  1580. "ISP Firmware failed checksum.\n");
  1581. goto failed;
  1582. }
  1583. } else
  1584. goto failed;
  1585. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1586. /* Enable proper parity. */
  1587. spin_lock_irqsave(&ha->hardware_lock, flags);
  1588. if (IS_QLA2300(ha))
  1589. /* SRAM parity */
  1590. WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
  1591. else
  1592. /* SRAM, Instruction RAM and GP RAM parity */
  1593. WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
  1594. RD_REG_WORD(&reg->hccr);
  1595. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1596. }
  1597. if (IS_QLA27XX(ha))
  1598. ha->flags.fac_supported = 1;
  1599. else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
  1600. uint32_t size;
  1601. rval = qla81xx_fac_get_sector_size(vha, &size);
  1602. if (rval == QLA_SUCCESS) {
  1603. ha->flags.fac_supported = 1;
  1604. ha->fdt_block_size = size << 2;
  1605. } else {
  1606. ql_log(ql_log_warn, vha, 0x00ce,
  1607. "Unsupported FAC firmware (%d.%02d.%02d).\n",
  1608. ha->fw_major_version, ha->fw_minor_version,
  1609. ha->fw_subminor_version);
  1610. if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  1611. ha->flags.fac_supported = 0;
  1612. rval = QLA_SUCCESS;
  1613. }
  1614. }
  1615. }
  1616. failed:
  1617. if (rval) {
  1618. ql_log(ql_log_fatal, vha, 0x00cf,
  1619. "Setup chip ****FAILED****.\n");
  1620. }
  1621. return (rval);
  1622. }
  1623. /**
  1624. * qla2x00_init_response_q_entries() - Initializes response queue entries.
  1625. * @ha: HA context
  1626. *
  1627. * Beginning of request ring has initialization control block already built
  1628. * by nvram config routine.
  1629. *
  1630. * Returns 0 on success.
  1631. */
  1632. void
  1633. qla2x00_init_response_q_entries(struct rsp_que *rsp)
  1634. {
  1635. uint16_t cnt;
  1636. response_t *pkt;
  1637. rsp->ring_ptr = rsp->ring;
  1638. rsp->ring_index = 0;
  1639. rsp->status_srb = NULL;
  1640. pkt = rsp->ring_ptr;
  1641. for (cnt = 0; cnt < rsp->length; cnt++) {
  1642. pkt->signature = RESPONSE_PROCESSED;
  1643. pkt++;
  1644. }
  1645. }
  1646. /**
  1647. * qla2x00_update_fw_options() - Read and process firmware options.
  1648. * @ha: HA context
  1649. *
  1650. * Returns 0 on success.
  1651. */
  1652. void
  1653. qla2x00_update_fw_options(scsi_qla_host_t *vha)
  1654. {
  1655. uint16_t swing, emphasis, tx_sens, rx_sens;
  1656. struct qla_hw_data *ha = vha->hw;
  1657. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  1658. qla2x00_get_fw_options(vha, ha->fw_options);
  1659. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1660. return;
  1661. /* Serial Link options. */
  1662. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
  1663. "Serial link options.\n");
  1664. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
  1665. (uint8_t *)&ha->fw_seriallink_options,
  1666. sizeof(ha->fw_seriallink_options));
  1667. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1668. if (ha->fw_seriallink_options[3] & BIT_2) {
  1669. ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
  1670. /* 1G settings */
  1671. swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
  1672. emphasis = (ha->fw_seriallink_options[2] &
  1673. (BIT_4 | BIT_3)) >> 3;
  1674. tx_sens = ha->fw_seriallink_options[0] &
  1675. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1676. rx_sens = (ha->fw_seriallink_options[0] &
  1677. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  1678. ha->fw_options[10] = (emphasis << 14) | (swing << 8);
  1679. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  1680. if (rx_sens == 0x0)
  1681. rx_sens = 0x3;
  1682. ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
  1683. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1684. ha->fw_options[10] |= BIT_5 |
  1685. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  1686. (tx_sens & (BIT_1 | BIT_0));
  1687. /* 2G settings */
  1688. swing = (ha->fw_seriallink_options[2] &
  1689. (BIT_7 | BIT_6 | BIT_5)) >> 5;
  1690. emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
  1691. tx_sens = ha->fw_seriallink_options[1] &
  1692. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1693. rx_sens = (ha->fw_seriallink_options[1] &
  1694. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  1695. ha->fw_options[11] = (emphasis << 14) | (swing << 8);
  1696. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  1697. if (rx_sens == 0x0)
  1698. rx_sens = 0x3;
  1699. ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
  1700. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1701. ha->fw_options[11] |= BIT_5 |
  1702. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  1703. (tx_sens & (BIT_1 | BIT_0));
  1704. }
  1705. /* FCP2 options. */
  1706. /* Return command IOCBs without waiting for an ABTS to complete. */
  1707. ha->fw_options[3] |= BIT_13;
  1708. /* LED scheme. */
  1709. if (ha->flags.enable_led_scheme)
  1710. ha->fw_options[2] |= BIT_12;
  1711. /* Detect ISP6312. */
  1712. if (IS_QLA6312(ha))
  1713. ha->fw_options[2] |= BIT_13;
  1714. /* Update firmware options. */
  1715. qla2x00_set_fw_options(vha, ha->fw_options);
  1716. }
  1717. void
  1718. qla24xx_update_fw_options(scsi_qla_host_t *vha)
  1719. {
  1720. int rval;
  1721. struct qla_hw_data *ha = vha->hw;
  1722. if (IS_P3P_TYPE(ha))
  1723. return;
  1724. /* Update Serial Link options. */
  1725. if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
  1726. return;
  1727. rval = qla2x00_set_serdes_params(vha,
  1728. le16_to_cpu(ha->fw_seriallink_options24[1]),
  1729. le16_to_cpu(ha->fw_seriallink_options24[2]),
  1730. le16_to_cpu(ha->fw_seriallink_options24[3]));
  1731. if (rval != QLA_SUCCESS) {
  1732. ql_log(ql_log_warn, vha, 0x0104,
  1733. "Unable to update Serial Link options (%x).\n", rval);
  1734. }
  1735. }
  1736. void
  1737. qla2x00_config_rings(struct scsi_qla_host *vha)
  1738. {
  1739. struct qla_hw_data *ha = vha->hw;
  1740. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1741. struct req_que *req = ha->req_q_map[0];
  1742. struct rsp_que *rsp = ha->rsp_q_map[0];
  1743. /* Setup ring parameters in initialization control block. */
  1744. ha->init_cb->request_q_outpointer = cpu_to_le16(0);
  1745. ha->init_cb->response_q_inpointer = cpu_to_le16(0);
  1746. ha->init_cb->request_q_length = cpu_to_le16(req->length);
  1747. ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
  1748. ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
  1749. ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
  1750. ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
  1751. ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
  1752. WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
  1753. WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
  1754. WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
  1755. WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
  1756. RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
  1757. }
  1758. void
  1759. qla24xx_config_rings(struct scsi_qla_host *vha)
  1760. {
  1761. struct qla_hw_data *ha = vha->hw;
  1762. device_reg_t *reg = ISP_QUE_REG(ha, 0);
  1763. struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
  1764. struct qla_msix_entry *msix;
  1765. struct init_cb_24xx *icb;
  1766. uint16_t rid = 0;
  1767. struct req_que *req = ha->req_q_map[0];
  1768. struct rsp_que *rsp = ha->rsp_q_map[0];
  1769. /* Setup ring parameters in initialization control block. */
  1770. icb = (struct init_cb_24xx *)ha->init_cb;
  1771. icb->request_q_outpointer = cpu_to_le16(0);
  1772. icb->response_q_inpointer = cpu_to_le16(0);
  1773. icb->request_q_length = cpu_to_le16(req->length);
  1774. icb->response_q_length = cpu_to_le16(rsp->length);
  1775. icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
  1776. icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
  1777. icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
  1778. icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
  1779. /* Setup ATIO queue dma pointers for target mode */
  1780. icb->atio_q_inpointer = cpu_to_le16(0);
  1781. icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
  1782. icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
  1783. icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
  1784. if (IS_SHADOW_REG_CAPABLE(ha))
  1785. icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
  1786. if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  1787. icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
  1788. icb->rid = cpu_to_le16(rid);
  1789. if (ha->flags.msix_enabled) {
  1790. msix = &ha->msix_entries[1];
  1791. ql_dbg(ql_dbg_init, vha, 0x00fd,
  1792. "Registering vector 0x%x for base que.\n",
  1793. msix->entry);
  1794. icb->msix = cpu_to_le16(msix->entry);
  1795. }
  1796. /* Use alternate PCI bus number */
  1797. if (MSB(rid))
  1798. icb->firmware_options_2 |= cpu_to_le32(BIT_19);
  1799. /* Use alternate PCI devfn */
  1800. if (LSB(rid))
  1801. icb->firmware_options_2 |= cpu_to_le32(BIT_18);
  1802. /* Use Disable MSIX Handshake mode for capable adapters */
  1803. if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
  1804. (ha->flags.msix_enabled)) {
  1805. icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
  1806. ha->flags.disable_msix_handshake = 1;
  1807. ql_dbg(ql_dbg_init, vha, 0x00fe,
  1808. "MSIX Handshake Disable Mode turned on.\n");
  1809. } else {
  1810. icb->firmware_options_2 |= cpu_to_le32(BIT_22);
  1811. }
  1812. icb->firmware_options_2 |= cpu_to_le32(BIT_23);
  1813. WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
  1814. WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
  1815. WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
  1816. WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
  1817. } else {
  1818. WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
  1819. WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
  1820. WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
  1821. WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
  1822. }
  1823. qlt_24xx_config_rings(vha);
  1824. /* PCI posting */
  1825. RD_REG_DWORD(&ioreg->hccr);
  1826. }
  1827. /**
  1828. * qla2x00_init_rings() - Initializes firmware.
  1829. * @ha: HA context
  1830. *
  1831. * Beginning of request ring has initialization control block already built
  1832. * by nvram config routine.
  1833. *
  1834. * Returns 0 on success.
  1835. */
  1836. int
  1837. qla2x00_init_rings(scsi_qla_host_t *vha)
  1838. {
  1839. int rval;
  1840. unsigned long flags = 0;
  1841. int cnt, que;
  1842. struct qla_hw_data *ha = vha->hw;
  1843. struct req_que *req;
  1844. struct rsp_que *rsp;
  1845. struct mid_init_cb_24xx *mid_init_cb =
  1846. (struct mid_init_cb_24xx *) ha->init_cb;
  1847. spin_lock_irqsave(&ha->hardware_lock, flags);
  1848. /* Clear outstanding commands array. */
  1849. for (que = 0; que < ha->max_req_queues; que++) {
  1850. req = ha->req_q_map[que];
  1851. if (!req || !test_bit(que, ha->req_qid_map))
  1852. continue;
  1853. req->out_ptr = (void *)(req->ring + req->length);
  1854. *req->out_ptr = 0;
  1855. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
  1856. req->outstanding_cmds[cnt] = NULL;
  1857. req->current_outstanding_cmd = 1;
  1858. /* Initialize firmware. */
  1859. req->ring_ptr = req->ring;
  1860. req->ring_index = 0;
  1861. req->cnt = req->length;
  1862. }
  1863. for (que = 0; que < ha->max_rsp_queues; que++) {
  1864. rsp = ha->rsp_q_map[que];
  1865. if (!rsp || !test_bit(que, ha->rsp_qid_map))
  1866. continue;
  1867. rsp->in_ptr = (void *)(rsp->ring + rsp->length);
  1868. *rsp->in_ptr = 0;
  1869. /* Initialize response queue entries */
  1870. if (IS_QLAFX00(ha))
  1871. qlafx00_init_response_q_entries(rsp);
  1872. else
  1873. qla2x00_init_response_q_entries(rsp);
  1874. }
  1875. ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
  1876. ha->tgt.atio_ring_index = 0;
  1877. /* Initialize ATIO queue entries */
  1878. qlt_init_atio_q_entries(vha);
  1879. ha->isp_ops->config_rings(vha);
  1880. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1881. ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
  1882. if (IS_QLAFX00(ha)) {
  1883. rval = qlafx00_init_firmware(vha, ha->init_cb_size);
  1884. goto next_check;
  1885. }
  1886. /* Update any ISP specific firmware options before initialization. */
  1887. ha->isp_ops->update_fw_options(vha);
  1888. if (ha->flags.npiv_supported) {
  1889. if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
  1890. ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
  1891. mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
  1892. }
  1893. if (IS_FWI2_CAPABLE(ha)) {
  1894. mid_init_cb->options = cpu_to_le16(BIT_1);
  1895. mid_init_cb->init_cb.execution_throttle =
  1896. cpu_to_le16(ha->fw_xcb_count);
  1897. /* D-Port Status */
  1898. if (IS_DPORT_CAPABLE(ha))
  1899. mid_init_cb->init_cb.firmware_options_1 |=
  1900. cpu_to_le16(BIT_7);
  1901. /* Enable FA-WWPN */
  1902. ha->flags.fawwpn_enabled =
  1903. (mid_init_cb->init_cb.firmware_options_1 & BIT_6) ? 1 : 0;
  1904. ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
  1905. (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
  1906. }
  1907. rval = qla2x00_init_firmware(vha, ha->init_cb_size);
  1908. next_check:
  1909. if (rval) {
  1910. ql_log(ql_log_fatal, vha, 0x00d2,
  1911. "Init Firmware **** FAILED ****.\n");
  1912. } else {
  1913. ql_dbg(ql_dbg_init, vha, 0x00d3,
  1914. "Init Firmware -- success.\n");
  1915. }
  1916. return (rval);
  1917. }
  1918. /**
  1919. * qla2x00_fw_ready() - Waits for firmware ready.
  1920. * @ha: HA context
  1921. *
  1922. * Returns 0 on success.
  1923. */
  1924. static int
  1925. qla2x00_fw_ready(scsi_qla_host_t *vha)
  1926. {
  1927. int rval;
  1928. unsigned long wtime, mtime, cs84xx_time;
  1929. uint16_t min_wait; /* Minimum wait time if loop is down */
  1930. uint16_t wait_time; /* Wait time if loop is coming ready */
  1931. uint16_t state[6];
  1932. struct qla_hw_data *ha = vha->hw;
  1933. if (IS_QLAFX00(vha->hw))
  1934. return qlafx00_fw_ready(vha);
  1935. rval = QLA_SUCCESS;
  1936. /* Time to wait for loop down */
  1937. if (IS_P3P_TYPE(ha))
  1938. min_wait = 30;
  1939. else
  1940. min_wait = 20;
  1941. /*
  1942. * Firmware should take at most one RATOV to login, plus 5 seconds for
  1943. * our own processing.
  1944. */
  1945. if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
  1946. wait_time = min_wait;
  1947. }
  1948. /* Min wait time if loop down */
  1949. mtime = jiffies + (min_wait * HZ);
  1950. /* wait time before firmware ready */
  1951. wtime = jiffies + (wait_time * HZ);
  1952. /* Wait for ISP to finish LIP */
  1953. if (!vha->flags.init_done)
  1954. ql_log(ql_log_info, vha, 0x801e,
  1955. "Waiting for LIP to complete.\n");
  1956. do {
  1957. memset(state, -1, sizeof(state));
  1958. rval = qla2x00_get_firmware_state(vha, state);
  1959. if (rval == QLA_SUCCESS) {
  1960. if (state[0] < FSTATE_LOSS_OF_SYNC) {
  1961. vha->device_flags &= ~DFLG_NO_CABLE;
  1962. }
  1963. if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
  1964. ql_dbg(ql_dbg_taskm, vha, 0x801f,
  1965. "fw_state=%x 84xx=%x.\n", state[0],
  1966. state[2]);
  1967. if ((state[2] & FSTATE_LOGGED_IN) &&
  1968. (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
  1969. ql_dbg(ql_dbg_taskm, vha, 0x8028,
  1970. "Sending verify iocb.\n");
  1971. cs84xx_time = jiffies;
  1972. rval = qla84xx_init_chip(vha);
  1973. if (rval != QLA_SUCCESS) {
  1974. ql_log(ql_log_warn,
  1975. vha, 0x8007,
  1976. "Init chip failed.\n");
  1977. break;
  1978. }
  1979. /* Add time taken to initialize. */
  1980. cs84xx_time = jiffies - cs84xx_time;
  1981. wtime += cs84xx_time;
  1982. mtime += cs84xx_time;
  1983. ql_dbg(ql_dbg_taskm, vha, 0x8008,
  1984. "Increasing wait time by %ld. "
  1985. "New time %ld.\n", cs84xx_time,
  1986. wtime);
  1987. }
  1988. } else if (state[0] == FSTATE_READY) {
  1989. ql_dbg(ql_dbg_taskm, vha, 0x8037,
  1990. "F/W Ready - OK.\n");
  1991. qla2x00_get_retry_cnt(vha, &ha->retry_count,
  1992. &ha->login_timeout, &ha->r_a_tov);
  1993. rval = QLA_SUCCESS;
  1994. break;
  1995. }
  1996. rval = QLA_FUNCTION_FAILED;
  1997. if (atomic_read(&vha->loop_down_timer) &&
  1998. state[0] != FSTATE_READY) {
  1999. /* Loop down. Timeout on min_wait for states
  2000. * other than Wait for Login.
  2001. */
  2002. if (time_after_eq(jiffies, mtime)) {
  2003. ql_log(ql_log_info, vha, 0x8038,
  2004. "Cable is unplugged...\n");
  2005. vha->device_flags |= DFLG_NO_CABLE;
  2006. break;
  2007. }
  2008. }
  2009. } else {
  2010. /* Mailbox cmd failed. Timeout on min_wait. */
  2011. if (time_after_eq(jiffies, mtime) ||
  2012. ha->flags.isp82xx_fw_hung)
  2013. break;
  2014. }
  2015. if (time_after_eq(jiffies, wtime))
  2016. break;
  2017. /* Delay for a while */
  2018. msleep(500);
  2019. } while (1);
  2020. ql_dbg(ql_dbg_taskm, vha, 0x803a,
  2021. "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
  2022. state[1], state[2], state[3], state[4], state[5], jiffies);
  2023. if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
  2024. ql_log(ql_log_warn, vha, 0x803b,
  2025. "Firmware ready **** FAILED ****.\n");
  2026. }
  2027. return (rval);
  2028. }
  2029. /*
  2030. * qla2x00_configure_hba
  2031. * Setup adapter context.
  2032. *
  2033. * Input:
  2034. * ha = adapter state pointer.
  2035. *
  2036. * Returns:
  2037. * 0 = success
  2038. *
  2039. * Context:
  2040. * Kernel context.
  2041. */
  2042. static int
  2043. qla2x00_configure_hba(scsi_qla_host_t *vha)
  2044. {
  2045. int rval;
  2046. uint16_t loop_id;
  2047. uint16_t topo;
  2048. uint16_t sw_cap;
  2049. uint8_t al_pa;
  2050. uint8_t area;
  2051. uint8_t domain;
  2052. char connect_type[22];
  2053. struct qla_hw_data *ha = vha->hw;
  2054. unsigned long flags;
  2055. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  2056. /* Get host addresses. */
  2057. rval = qla2x00_get_adapter_id(vha,
  2058. &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
  2059. if (rval != QLA_SUCCESS) {
  2060. if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
  2061. IS_CNA_CAPABLE(ha) ||
  2062. (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
  2063. ql_dbg(ql_dbg_disc, vha, 0x2008,
  2064. "Loop is in a transition state.\n");
  2065. } else {
  2066. ql_log(ql_log_warn, vha, 0x2009,
  2067. "Unable to get host loop ID.\n");
  2068. if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
  2069. (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
  2070. ql_log(ql_log_warn, vha, 0x1151,
  2071. "Doing link init.\n");
  2072. if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
  2073. return rval;
  2074. }
  2075. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  2076. }
  2077. return (rval);
  2078. }
  2079. if (topo == 4) {
  2080. ql_log(ql_log_info, vha, 0x200a,
  2081. "Cannot get topology - retrying.\n");
  2082. return (QLA_FUNCTION_FAILED);
  2083. }
  2084. vha->loop_id = loop_id;
  2085. /* initialize */
  2086. ha->min_external_loopid = SNS_FIRST_LOOP_ID;
  2087. ha->operating_mode = LOOP;
  2088. ha->switch_cap = 0;
  2089. switch (topo) {
  2090. case 0:
  2091. ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
  2092. ha->current_topology = ISP_CFG_NL;
  2093. strcpy(connect_type, "(Loop)");
  2094. break;
  2095. case 1:
  2096. ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
  2097. ha->switch_cap = sw_cap;
  2098. ha->current_topology = ISP_CFG_FL;
  2099. strcpy(connect_type, "(FL_Port)");
  2100. break;
  2101. case 2:
  2102. ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
  2103. ha->operating_mode = P2P;
  2104. ha->current_topology = ISP_CFG_N;
  2105. strcpy(connect_type, "(N_Port-to-N_Port)");
  2106. break;
  2107. case 3:
  2108. ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
  2109. ha->switch_cap = sw_cap;
  2110. ha->operating_mode = P2P;
  2111. ha->current_topology = ISP_CFG_F;
  2112. strcpy(connect_type, "(F_Port)");
  2113. break;
  2114. default:
  2115. ql_dbg(ql_dbg_disc, vha, 0x200f,
  2116. "HBA in unknown topology %x, using NL.\n", topo);
  2117. ha->current_topology = ISP_CFG_NL;
  2118. strcpy(connect_type, "(Loop)");
  2119. break;
  2120. }
  2121. /* Save Host port and loop ID. */
  2122. /* byte order - Big Endian */
  2123. vha->d_id.b.domain = domain;
  2124. vha->d_id.b.area = area;
  2125. vha->d_id.b.al_pa = al_pa;
  2126. spin_lock_irqsave(&ha->vport_slock, flags);
  2127. qlt_update_vp_map(vha, SET_AL_PA);
  2128. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2129. if (!vha->flags.init_done)
  2130. ql_log(ql_log_info, vha, 0x2010,
  2131. "Topology - %s, Host Loop address 0x%x.\n",
  2132. connect_type, vha->loop_id);
  2133. return(rval);
  2134. }
  2135. inline void
  2136. qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
  2137. char *def)
  2138. {
  2139. char *st, *en;
  2140. uint16_t index;
  2141. struct qla_hw_data *ha = vha->hw;
  2142. int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
  2143. !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
  2144. if (memcmp(model, BINZERO, len) != 0) {
  2145. strncpy(ha->model_number, model, len);
  2146. st = en = ha->model_number;
  2147. en += len - 1;
  2148. while (en > st) {
  2149. if (*en != 0x20 && *en != 0x00)
  2150. break;
  2151. *en-- = '\0';
  2152. }
  2153. index = (ha->pdev->subsystem_device & 0xff);
  2154. if (use_tbl &&
  2155. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  2156. index < QLA_MODEL_NAMES)
  2157. strncpy(ha->model_desc,
  2158. qla2x00_model_name[index * 2 + 1],
  2159. sizeof(ha->model_desc) - 1);
  2160. } else {
  2161. index = (ha->pdev->subsystem_device & 0xff);
  2162. if (use_tbl &&
  2163. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  2164. index < QLA_MODEL_NAMES) {
  2165. strcpy(ha->model_number,
  2166. qla2x00_model_name[index * 2]);
  2167. strncpy(ha->model_desc,
  2168. qla2x00_model_name[index * 2 + 1],
  2169. sizeof(ha->model_desc) - 1);
  2170. } else {
  2171. strcpy(ha->model_number, def);
  2172. }
  2173. }
  2174. if (IS_FWI2_CAPABLE(ha))
  2175. qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
  2176. sizeof(ha->model_desc));
  2177. }
  2178. /* On sparc systems, obtain port and node WWN from firmware
  2179. * properties.
  2180. */
  2181. static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
  2182. {
  2183. #ifdef CONFIG_SPARC
  2184. struct qla_hw_data *ha = vha->hw;
  2185. struct pci_dev *pdev = ha->pdev;
  2186. struct device_node *dp = pci_device_to_OF_node(pdev);
  2187. const u8 *val;
  2188. int len;
  2189. val = of_get_property(dp, "port-wwn", &len);
  2190. if (val && len >= WWN_SIZE)
  2191. memcpy(nv->port_name, val, WWN_SIZE);
  2192. val = of_get_property(dp, "node-wwn", &len);
  2193. if (val && len >= WWN_SIZE)
  2194. memcpy(nv->node_name, val, WWN_SIZE);
  2195. #endif
  2196. }
  2197. /*
  2198. * NVRAM configuration for ISP 2xxx
  2199. *
  2200. * Input:
  2201. * ha = adapter block pointer.
  2202. *
  2203. * Output:
  2204. * initialization control block in response_ring
  2205. * host adapters parameters in host adapter block
  2206. *
  2207. * Returns:
  2208. * 0 = success.
  2209. */
  2210. int
  2211. qla2x00_nvram_config(scsi_qla_host_t *vha)
  2212. {
  2213. int rval;
  2214. uint8_t chksum = 0;
  2215. uint16_t cnt;
  2216. uint8_t *dptr1, *dptr2;
  2217. struct qla_hw_data *ha = vha->hw;
  2218. init_cb_t *icb = ha->init_cb;
  2219. nvram_t *nv = ha->nvram;
  2220. uint8_t *ptr = ha->nvram;
  2221. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2222. rval = QLA_SUCCESS;
  2223. /* Determine NVRAM starting address. */
  2224. ha->nvram_size = sizeof(nvram_t);
  2225. ha->nvram_base = 0;
  2226. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
  2227. if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
  2228. ha->nvram_base = 0x80;
  2229. /* Get NVRAM data and calculate checksum. */
  2230. ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
  2231. for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
  2232. chksum += *ptr++;
  2233. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
  2234. "Contents of NVRAM.\n");
  2235. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
  2236. (uint8_t *)nv, ha->nvram_size);
  2237. /* Bad NVRAM data, set defaults parameters. */
  2238. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
  2239. nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
  2240. /* Reset NVRAM data. */
  2241. ql_log(ql_log_warn, vha, 0x0064,
  2242. "Inconsistent NVRAM "
  2243. "detected: checksum=0x%x id=%c version=0x%x.\n",
  2244. chksum, nv->id[0], nv->nvram_version);
  2245. ql_log(ql_log_warn, vha, 0x0065,
  2246. "Falling back to "
  2247. "functioning (yet invalid -- WWPN) defaults.\n");
  2248. /*
  2249. * Set default initialization control block.
  2250. */
  2251. memset(nv, 0, ha->nvram_size);
  2252. nv->parameter_block_version = ICB_VERSION;
  2253. if (IS_QLA23XX(ha)) {
  2254. nv->firmware_options[0] = BIT_2 | BIT_1;
  2255. nv->firmware_options[1] = BIT_7 | BIT_5;
  2256. nv->add_firmware_options[0] = BIT_5;
  2257. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  2258. nv->frame_payload_size = 2048;
  2259. nv->special_options[1] = BIT_7;
  2260. } else if (IS_QLA2200(ha)) {
  2261. nv->firmware_options[0] = BIT_2 | BIT_1;
  2262. nv->firmware_options[1] = BIT_7 | BIT_5;
  2263. nv->add_firmware_options[0] = BIT_5;
  2264. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  2265. nv->frame_payload_size = 1024;
  2266. } else if (IS_QLA2100(ha)) {
  2267. nv->firmware_options[0] = BIT_3 | BIT_1;
  2268. nv->firmware_options[1] = BIT_5;
  2269. nv->frame_payload_size = 1024;
  2270. }
  2271. nv->max_iocb_allocation = cpu_to_le16(256);
  2272. nv->execution_throttle = cpu_to_le16(16);
  2273. nv->retry_count = 8;
  2274. nv->retry_delay = 1;
  2275. nv->port_name[0] = 33;
  2276. nv->port_name[3] = 224;
  2277. nv->port_name[4] = 139;
  2278. qla2xxx_nvram_wwn_from_ofw(vha, nv);
  2279. nv->login_timeout = 4;
  2280. /*
  2281. * Set default host adapter parameters
  2282. */
  2283. nv->host_p[1] = BIT_2;
  2284. nv->reset_delay = 5;
  2285. nv->port_down_retry_count = 8;
  2286. nv->max_luns_per_target = cpu_to_le16(8);
  2287. nv->link_down_timeout = 60;
  2288. rval = 1;
  2289. }
  2290. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2291. /*
  2292. * The SN2 does not provide BIOS emulation which means you can't change
  2293. * potentially bogus BIOS settings. Force the use of default settings
  2294. * for link rate and frame size. Hope that the rest of the settings
  2295. * are valid.
  2296. */
  2297. if (ia64_platform_is("sn2")) {
  2298. nv->frame_payload_size = 2048;
  2299. if (IS_QLA23XX(ha))
  2300. nv->special_options[1] = BIT_7;
  2301. }
  2302. #endif
  2303. /* Reset Initialization control block */
  2304. memset(icb, 0, ha->init_cb_size);
  2305. /*
  2306. * Setup driver NVRAM options.
  2307. */
  2308. nv->firmware_options[0] |= (BIT_6 | BIT_1);
  2309. nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
  2310. nv->firmware_options[1] |= (BIT_5 | BIT_0);
  2311. nv->firmware_options[1] &= ~BIT_4;
  2312. if (IS_QLA23XX(ha)) {
  2313. nv->firmware_options[0] |= BIT_2;
  2314. nv->firmware_options[0] &= ~BIT_3;
  2315. nv->special_options[0] &= ~BIT_6;
  2316. nv->add_firmware_options[1] |= BIT_5 | BIT_4;
  2317. if (IS_QLA2300(ha)) {
  2318. if (ha->fb_rev == FPM_2310) {
  2319. strcpy(ha->model_number, "QLA2310");
  2320. } else {
  2321. strcpy(ha->model_number, "QLA2300");
  2322. }
  2323. } else {
  2324. qla2x00_set_model_info(vha, nv->model_number,
  2325. sizeof(nv->model_number), "QLA23xx");
  2326. }
  2327. } else if (IS_QLA2200(ha)) {
  2328. nv->firmware_options[0] |= BIT_2;
  2329. /*
  2330. * 'Point-to-point preferred, else loop' is not a safe
  2331. * connection mode setting.
  2332. */
  2333. if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
  2334. (BIT_5 | BIT_4)) {
  2335. /* Force 'loop preferred, else point-to-point'. */
  2336. nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
  2337. nv->add_firmware_options[0] |= BIT_5;
  2338. }
  2339. strcpy(ha->model_number, "QLA22xx");
  2340. } else /*if (IS_QLA2100(ha))*/ {
  2341. strcpy(ha->model_number, "QLA2100");
  2342. }
  2343. /*
  2344. * Copy over NVRAM RISC parameter block to initialization control block.
  2345. */
  2346. dptr1 = (uint8_t *)icb;
  2347. dptr2 = (uint8_t *)&nv->parameter_block_version;
  2348. cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
  2349. while (cnt--)
  2350. *dptr1++ = *dptr2++;
  2351. /* Copy 2nd half. */
  2352. dptr1 = (uint8_t *)icb->add_firmware_options;
  2353. cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
  2354. while (cnt--)
  2355. *dptr1++ = *dptr2++;
  2356. /* Use alternate WWN? */
  2357. if (nv->host_p[1] & BIT_7) {
  2358. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  2359. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  2360. }
  2361. /* Prepare nodename */
  2362. if ((icb->firmware_options[1] & BIT_6) == 0) {
  2363. /*
  2364. * Firmware will apply the following mask if the nodename was
  2365. * not provided.
  2366. */
  2367. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  2368. icb->node_name[0] &= 0xF0;
  2369. }
  2370. /*
  2371. * Set host adapter parameters.
  2372. */
  2373. /*
  2374. * BIT_7 in the host-parameters section allows for modification to
  2375. * internal driver logging.
  2376. */
  2377. if (nv->host_p[0] & BIT_7)
  2378. ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
  2379. ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
  2380. /* Always load RISC code on non ISP2[12]00 chips. */
  2381. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  2382. ha->flags.disable_risc_code_load = 0;
  2383. ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
  2384. ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
  2385. ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
  2386. ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
  2387. ha->flags.disable_serdes = 0;
  2388. ha->operating_mode =
  2389. (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  2390. memcpy(ha->fw_seriallink_options, nv->seriallink_options,
  2391. sizeof(ha->fw_seriallink_options));
  2392. /* save HBA serial number */
  2393. ha->serial0 = icb->port_name[5];
  2394. ha->serial1 = icb->port_name[6];
  2395. ha->serial2 = icb->port_name[7];
  2396. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  2397. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  2398. icb->execution_throttle = cpu_to_le16(0xFFFF);
  2399. ha->retry_count = nv->retry_count;
  2400. /* Set minimum login_timeout to 4 seconds. */
  2401. if (nv->login_timeout != ql2xlogintimeout)
  2402. nv->login_timeout = ql2xlogintimeout;
  2403. if (nv->login_timeout < 4)
  2404. nv->login_timeout = 4;
  2405. ha->login_timeout = nv->login_timeout;
  2406. icb->login_timeout = nv->login_timeout;
  2407. /* Set minimum RATOV to 100 tenths of a second. */
  2408. ha->r_a_tov = 100;
  2409. ha->loop_reset_delay = nv->reset_delay;
  2410. /* Link Down Timeout = 0:
  2411. *
  2412. * When Port Down timer expires we will start returning
  2413. * I/O's to OS with "DID_NO_CONNECT".
  2414. *
  2415. * Link Down Timeout != 0:
  2416. *
  2417. * The driver waits for the link to come up after link down
  2418. * before returning I/Os to OS with "DID_NO_CONNECT".
  2419. */
  2420. if (nv->link_down_timeout == 0) {
  2421. ha->loop_down_abort_time =
  2422. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  2423. } else {
  2424. ha->link_down_timeout = nv->link_down_timeout;
  2425. ha->loop_down_abort_time =
  2426. (LOOP_DOWN_TIME - ha->link_down_timeout);
  2427. }
  2428. /*
  2429. * Need enough time to try and get the port back.
  2430. */
  2431. ha->port_down_retry_count = nv->port_down_retry_count;
  2432. if (qlport_down_retry)
  2433. ha->port_down_retry_count = qlport_down_retry;
  2434. /* Set login_retry_count */
  2435. ha->login_retry_count = nv->retry_count;
  2436. if (ha->port_down_retry_count == nv->port_down_retry_count &&
  2437. ha->port_down_retry_count > 3)
  2438. ha->login_retry_count = ha->port_down_retry_count;
  2439. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  2440. ha->login_retry_count = ha->port_down_retry_count;
  2441. if (ql2xloginretrycount)
  2442. ha->login_retry_count = ql2xloginretrycount;
  2443. icb->lun_enables = cpu_to_le16(0);
  2444. icb->command_resource_count = 0;
  2445. icb->immediate_notify_resource_count = 0;
  2446. icb->timeout = cpu_to_le16(0);
  2447. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2448. /* Enable RIO */
  2449. icb->firmware_options[0] &= ~BIT_3;
  2450. icb->add_firmware_options[0] &=
  2451. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2452. icb->add_firmware_options[0] |= BIT_2;
  2453. icb->response_accumulation_timer = 3;
  2454. icb->interrupt_delay_timer = 5;
  2455. vha->flags.process_response_queue = 1;
  2456. } else {
  2457. /* Enable ZIO. */
  2458. if (!vha->flags.init_done) {
  2459. ha->zio_mode = icb->add_firmware_options[0] &
  2460. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2461. ha->zio_timer = icb->interrupt_delay_timer ?
  2462. icb->interrupt_delay_timer: 2;
  2463. }
  2464. icb->add_firmware_options[0] &=
  2465. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2466. vha->flags.process_response_queue = 0;
  2467. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  2468. ha->zio_mode = QLA_ZIO_MODE_6;
  2469. ql_log(ql_log_info, vha, 0x0068,
  2470. "ZIO mode %d enabled; timer delay (%d us).\n",
  2471. ha->zio_mode, ha->zio_timer * 100);
  2472. icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
  2473. icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
  2474. vha->flags.process_response_queue = 1;
  2475. }
  2476. }
  2477. if (rval) {
  2478. ql_log(ql_log_warn, vha, 0x0069,
  2479. "NVRAM configuration failed.\n");
  2480. }
  2481. return (rval);
  2482. }
  2483. static void
  2484. qla2x00_rport_del(void *data)
  2485. {
  2486. fc_port_t *fcport = data;
  2487. struct fc_rport *rport;
  2488. unsigned long flags;
  2489. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2490. rport = fcport->drport ? fcport->drport: fcport->rport;
  2491. fcport->drport = NULL;
  2492. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2493. if (rport)
  2494. fc_remote_port_delete(rport);
  2495. }
  2496. /**
  2497. * qla2x00_alloc_fcport() - Allocate a generic fcport.
  2498. * @ha: HA context
  2499. * @flags: allocation flags
  2500. *
  2501. * Returns a pointer to the allocated fcport, or NULL, if none available.
  2502. */
  2503. fc_port_t *
  2504. qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
  2505. {
  2506. fc_port_t *fcport;
  2507. fcport = kzalloc(sizeof(fc_port_t), flags);
  2508. if (!fcport)
  2509. return NULL;
  2510. /* Setup fcport template structure. */
  2511. fcport->vha = vha;
  2512. fcport->port_type = FCT_UNKNOWN;
  2513. fcport->loop_id = FC_NO_LOOP_ID;
  2514. qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
  2515. fcport->supported_classes = FC_COS_UNSPECIFIED;
  2516. return fcport;
  2517. }
  2518. /*
  2519. * qla2x00_configure_loop
  2520. * Updates Fibre Channel Device Database with what is actually on loop.
  2521. *
  2522. * Input:
  2523. * ha = adapter block pointer.
  2524. *
  2525. * Returns:
  2526. * 0 = success.
  2527. * 1 = error.
  2528. * 2 = database was full and device was not configured.
  2529. */
  2530. static int
  2531. qla2x00_configure_loop(scsi_qla_host_t *vha)
  2532. {
  2533. int rval;
  2534. unsigned long flags, save_flags;
  2535. struct qla_hw_data *ha = vha->hw;
  2536. rval = QLA_SUCCESS;
  2537. /* Get Initiator ID */
  2538. if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
  2539. rval = qla2x00_configure_hba(vha);
  2540. if (rval != QLA_SUCCESS) {
  2541. ql_dbg(ql_dbg_disc, vha, 0x2013,
  2542. "Unable to configure HBA.\n");
  2543. return (rval);
  2544. }
  2545. }
  2546. save_flags = flags = vha->dpc_flags;
  2547. ql_dbg(ql_dbg_disc, vha, 0x2014,
  2548. "Configure loop -- dpc flags = 0x%lx.\n", flags);
  2549. /*
  2550. * If we have both an RSCN and PORT UPDATE pending then handle them
  2551. * both at the same time.
  2552. */
  2553. clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2554. clear_bit(RSCN_UPDATE, &vha->dpc_flags);
  2555. qla2x00_get_data_rate(vha);
  2556. /* Determine what we need to do */
  2557. if (ha->current_topology == ISP_CFG_FL &&
  2558. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2559. set_bit(RSCN_UPDATE, &flags);
  2560. } else if (ha->current_topology == ISP_CFG_F &&
  2561. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2562. set_bit(RSCN_UPDATE, &flags);
  2563. clear_bit(LOCAL_LOOP_UPDATE, &flags);
  2564. } else if (ha->current_topology == ISP_CFG_N) {
  2565. clear_bit(RSCN_UPDATE, &flags);
  2566. } else if (!vha->flags.online ||
  2567. (test_bit(ABORT_ISP_ACTIVE, &flags))) {
  2568. set_bit(RSCN_UPDATE, &flags);
  2569. set_bit(LOCAL_LOOP_UPDATE, &flags);
  2570. }
  2571. if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
  2572. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2573. ql_dbg(ql_dbg_disc, vha, 0x2015,
  2574. "Loop resync needed, failing.\n");
  2575. rval = QLA_FUNCTION_FAILED;
  2576. } else
  2577. rval = qla2x00_configure_local_loop(vha);
  2578. }
  2579. if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
  2580. if (LOOP_TRANSITION(vha)) {
  2581. ql_dbg(ql_dbg_disc, vha, 0x201e,
  2582. "Needs RSCN update and loop transition.\n");
  2583. rval = QLA_FUNCTION_FAILED;
  2584. }
  2585. else
  2586. rval = qla2x00_configure_fabric(vha);
  2587. }
  2588. if (rval == QLA_SUCCESS) {
  2589. if (atomic_read(&vha->loop_down_timer) ||
  2590. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2591. rval = QLA_FUNCTION_FAILED;
  2592. } else {
  2593. atomic_set(&vha->loop_state, LOOP_READY);
  2594. ql_dbg(ql_dbg_disc, vha, 0x2069,
  2595. "LOOP READY.\n");
  2596. }
  2597. }
  2598. if (rval) {
  2599. ql_dbg(ql_dbg_disc, vha, 0x206a,
  2600. "%s *** FAILED ***.\n", __func__);
  2601. } else {
  2602. ql_dbg(ql_dbg_disc, vha, 0x206b,
  2603. "%s: exiting normally.\n", __func__);
  2604. }
  2605. /* Restore state if a resync event occurred during processing */
  2606. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2607. if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
  2608. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2609. if (test_bit(RSCN_UPDATE, &save_flags)) {
  2610. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2611. }
  2612. }
  2613. return (rval);
  2614. }
  2615. /*
  2616. * qla2x00_configure_local_loop
  2617. * Updates Fibre Channel Device Database with local loop devices.
  2618. *
  2619. * Input:
  2620. * ha = adapter block pointer.
  2621. *
  2622. * Returns:
  2623. * 0 = success.
  2624. */
  2625. static int
  2626. qla2x00_configure_local_loop(scsi_qla_host_t *vha)
  2627. {
  2628. int rval, rval2;
  2629. int found_devs;
  2630. int found;
  2631. fc_port_t *fcport, *new_fcport;
  2632. uint16_t index;
  2633. uint16_t entries;
  2634. char *id_iter;
  2635. uint16_t loop_id;
  2636. uint8_t domain, area, al_pa;
  2637. struct qla_hw_data *ha = vha->hw;
  2638. found_devs = 0;
  2639. new_fcport = NULL;
  2640. entries = MAX_FIBRE_DEVICES_LOOP;
  2641. /* Get list of logged in devices. */
  2642. memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
  2643. rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
  2644. &entries);
  2645. if (rval != QLA_SUCCESS)
  2646. goto cleanup_allocation;
  2647. ql_dbg(ql_dbg_disc, vha, 0x2017,
  2648. "Entries in ID list (%d).\n", entries);
  2649. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
  2650. (uint8_t *)ha->gid_list,
  2651. entries * sizeof(struct gid_list_info));
  2652. /* Allocate temporary fcport for any new fcports discovered. */
  2653. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2654. if (new_fcport == NULL) {
  2655. ql_log(ql_log_warn, vha, 0x2018,
  2656. "Memory allocation failed for fcport.\n");
  2657. rval = QLA_MEMORY_ALLOC_FAILED;
  2658. goto cleanup_allocation;
  2659. }
  2660. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2661. /*
  2662. * Mark local devices that were present with FCF_DEVICE_LOST for now.
  2663. */
  2664. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2665. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2666. fcport->port_type != FCT_BROADCAST &&
  2667. (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  2668. ql_dbg(ql_dbg_disc, vha, 0x2019,
  2669. "Marking port lost loop_id=0x%04x.\n",
  2670. fcport->loop_id);
  2671. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2672. }
  2673. }
  2674. /* Add devices to port list. */
  2675. id_iter = (char *)ha->gid_list;
  2676. for (index = 0; index < entries; index++) {
  2677. domain = ((struct gid_list_info *)id_iter)->domain;
  2678. area = ((struct gid_list_info *)id_iter)->area;
  2679. al_pa = ((struct gid_list_info *)id_iter)->al_pa;
  2680. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  2681. loop_id = (uint16_t)
  2682. ((struct gid_list_info *)id_iter)->loop_id_2100;
  2683. else
  2684. loop_id = le16_to_cpu(
  2685. ((struct gid_list_info *)id_iter)->loop_id);
  2686. id_iter += ha->gid_list_info_size;
  2687. /* Bypass reserved domain fields. */
  2688. if ((domain & 0xf0) == 0xf0)
  2689. continue;
  2690. /* Bypass if not same domain and area of adapter. */
  2691. if (area && domain &&
  2692. (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
  2693. continue;
  2694. /* Bypass invalid local loop ID. */
  2695. if (loop_id > LAST_LOCAL_LOOP_ID)
  2696. continue;
  2697. memset(new_fcport, 0, sizeof(fc_port_t));
  2698. /* Fill in member data. */
  2699. new_fcport->d_id.b.domain = domain;
  2700. new_fcport->d_id.b.area = area;
  2701. new_fcport->d_id.b.al_pa = al_pa;
  2702. new_fcport->loop_id = loop_id;
  2703. rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
  2704. if (rval2 != QLA_SUCCESS) {
  2705. ql_dbg(ql_dbg_disc, vha, 0x201a,
  2706. "Failed to retrieve fcport information "
  2707. "-- get_port_database=%x, loop_id=0x%04x.\n",
  2708. rval2, new_fcport->loop_id);
  2709. ql_dbg(ql_dbg_disc, vha, 0x201b,
  2710. "Scheduling resync.\n");
  2711. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2712. continue;
  2713. }
  2714. /* Check for matching device in port list. */
  2715. found = 0;
  2716. fcport = NULL;
  2717. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2718. if (memcmp(new_fcport->port_name, fcport->port_name,
  2719. WWN_SIZE))
  2720. continue;
  2721. fcport->flags &= ~FCF_FABRIC_DEVICE;
  2722. fcport->loop_id = new_fcport->loop_id;
  2723. fcport->port_type = new_fcport->port_type;
  2724. fcport->d_id.b24 = new_fcport->d_id.b24;
  2725. memcpy(fcport->node_name, new_fcport->node_name,
  2726. WWN_SIZE);
  2727. found++;
  2728. break;
  2729. }
  2730. if (!found) {
  2731. /* New device, add to fcports list. */
  2732. list_add_tail(&new_fcport->list, &vha->vp_fcports);
  2733. /* Allocate a new replacement fcport. */
  2734. fcport = new_fcport;
  2735. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2736. if (new_fcport == NULL) {
  2737. ql_log(ql_log_warn, vha, 0x201c,
  2738. "Failed to allocate memory for fcport.\n");
  2739. rval = QLA_MEMORY_ALLOC_FAILED;
  2740. goto cleanup_allocation;
  2741. }
  2742. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2743. }
  2744. /* Base iIDMA settings on HBA port speed. */
  2745. fcport->fp_speed = ha->link_data_rate;
  2746. qla2x00_update_fcport(vha, fcport);
  2747. found_devs++;
  2748. }
  2749. cleanup_allocation:
  2750. kfree(new_fcport);
  2751. if (rval != QLA_SUCCESS) {
  2752. ql_dbg(ql_dbg_disc, vha, 0x201d,
  2753. "Configure local loop error exit: rval=%x.\n", rval);
  2754. }
  2755. return (rval);
  2756. }
  2757. static void
  2758. qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2759. {
  2760. int rval;
  2761. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2762. struct qla_hw_data *ha = vha->hw;
  2763. if (!IS_IIDMA_CAPABLE(ha))
  2764. return;
  2765. if (atomic_read(&fcport->state) != FCS_ONLINE)
  2766. return;
  2767. if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
  2768. fcport->fp_speed > ha->link_data_rate ||
  2769. !ha->flags.gpsc_supported)
  2770. return;
  2771. rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
  2772. mb);
  2773. if (rval != QLA_SUCCESS) {
  2774. ql_dbg(ql_dbg_disc, vha, 0x2004,
  2775. "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
  2776. fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
  2777. } else {
  2778. ql_dbg(ql_dbg_disc, vha, 0x2005,
  2779. "iIDMA adjusted to %s GB/s on %8phN.\n",
  2780. qla2x00_get_link_speed_str(ha, fcport->fp_speed),
  2781. fcport->port_name);
  2782. }
  2783. }
  2784. static void
  2785. qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
  2786. {
  2787. struct fc_rport_identifiers rport_ids;
  2788. struct fc_rport *rport;
  2789. unsigned long flags;
  2790. rport_ids.node_name = wwn_to_u64(fcport->node_name);
  2791. rport_ids.port_name = wwn_to_u64(fcport->port_name);
  2792. rport_ids.port_id = fcport->d_id.b.domain << 16 |
  2793. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  2794. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2795. fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
  2796. if (!rport) {
  2797. ql_log(ql_log_warn, vha, 0x2006,
  2798. "Unable to allocate fc remote port.\n");
  2799. return;
  2800. }
  2801. /*
  2802. * Create target mode FC NEXUS in qla_target.c if target mode is
  2803. * enabled..
  2804. */
  2805. qlt_fc_port_added(vha, fcport);
  2806. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2807. *((fc_port_t **)rport->dd_data) = fcport;
  2808. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2809. rport->supported_classes = fcport->supported_classes;
  2810. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2811. if (fcport->port_type == FCT_INITIATOR)
  2812. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2813. if (fcport->port_type == FCT_TARGET)
  2814. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2815. fc_remote_port_rolechg(rport, rport_ids.roles);
  2816. }
  2817. /*
  2818. * qla2x00_update_fcport
  2819. * Updates device on list.
  2820. *
  2821. * Input:
  2822. * ha = adapter block pointer.
  2823. * fcport = port structure pointer.
  2824. *
  2825. * Return:
  2826. * 0 - Success
  2827. * BIT_0 - error
  2828. *
  2829. * Context:
  2830. * Kernel context.
  2831. */
  2832. void
  2833. qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2834. {
  2835. fcport->vha = vha;
  2836. if (IS_QLAFX00(vha->hw)) {
  2837. qla2x00_set_fcport_state(fcport, FCS_ONLINE);
  2838. goto reg_port;
  2839. }
  2840. fcport->login_retry = 0;
  2841. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  2842. qla2x00_set_fcport_state(fcport, FCS_ONLINE);
  2843. qla2x00_iidma_fcport(vha, fcport);
  2844. qla24xx_update_fcport_fcp_prio(vha, fcport);
  2845. reg_port:
  2846. if (qla_ini_mode_enabled(vha))
  2847. qla2x00_reg_remote_port(vha, fcport);
  2848. else {
  2849. /*
  2850. * Create target mode FC NEXUS in qla_target.c
  2851. */
  2852. qlt_fc_port_added(vha, fcport);
  2853. }
  2854. }
  2855. /*
  2856. * qla2x00_configure_fabric
  2857. * Setup SNS devices with loop ID's.
  2858. *
  2859. * Input:
  2860. * ha = adapter block pointer.
  2861. *
  2862. * Returns:
  2863. * 0 = success.
  2864. * BIT_0 = error
  2865. */
  2866. static int
  2867. qla2x00_configure_fabric(scsi_qla_host_t *vha)
  2868. {
  2869. int rval;
  2870. fc_port_t *fcport, *fcptemp;
  2871. uint16_t next_loopid;
  2872. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2873. uint16_t loop_id;
  2874. LIST_HEAD(new_fcports);
  2875. struct qla_hw_data *ha = vha->hw;
  2876. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2877. int discovery_gen;
  2878. /* If FL port exists, then SNS is present */
  2879. if (IS_FWI2_CAPABLE(ha))
  2880. loop_id = NPH_F_PORT;
  2881. else
  2882. loop_id = SNS_FL_PORT;
  2883. rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
  2884. if (rval != QLA_SUCCESS) {
  2885. ql_dbg(ql_dbg_disc, vha, 0x201f,
  2886. "MBX_GET_PORT_NAME failed, No FL Port.\n");
  2887. vha->device_flags &= ~SWITCH_FOUND;
  2888. return (QLA_SUCCESS);
  2889. }
  2890. vha->device_flags |= SWITCH_FOUND;
  2891. do {
  2892. /* FDMI support. */
  2893. if (ql2xfdmienable &&
  2894. test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
  2895. qla2x00_fdmi_register(vha);
  2896. /* Ensure we are logged into the SNS. */
  2897. if (IS_FWI2_CAPABLE(ha))
  2898. loop_id = NPH_SNS;
  2899. else
  2900. loop_id = SIMPLE_NAME_SERVER;
  2901. rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
  2902. 0xfc, mb, BIT_1|BIT_0);
  2903. if (rval != QLA_SUCCESS) {
  2904. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2905. return rval;
  2906. }
  2907. if (mb[0] != MBS_COMMAND_COMPLETE) {
  2908. ql_dbg(ql_dbg_disc, vha, 0x2042,
  2909. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
  2910. "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
  2911. mb[2], mb[6], mb[7]);
  2912. return (QLA_SUCCESS);
  2913. }
  2914. if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
  2915. if (qla2x00_rft_id(vha)) {
  2916. /* EMPTY */
  2917. ql_dbg(ql_dbg_disc, vha, 0x2045,
  2918. "Register FC-4 TYPE failed.\n");
  2919. }
  2920. if (qla2x00_rff_id(vha)) {
  2921. /* EMPTY */
  2922. ql_dbg(ql_dbg_disc, vha, 0x2049,
  2923. "Register FC-4 Features failed.\n");
  2924. }
  2925. if (qla2x00_rnn_id(vha)) {
  2926. /* EMPTY */
  2927. ql_dbg(ql_dbg_disc, vha, 0x204f,
  2928. "Register Node Name failed.\n");
  2929. } else if (qla2x00_rsnn_nn(vha)) {
  2930. /* EMPTY */
  2931. ql_dbg(ql_dbg_disc, vha, 0x2053,
  2932. "Register Symobilic Node Name failed.\n");
  2933. }
  2934. }
  2935. #define QLA_FCPORT_SCAN 1
  2936. #define QLA_FCPORT_FOUND 2
  2937. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2938. fcport->scan_state = QLA_FCPORT_SCAN;
  2939. }
  2940. /* Mark the time right before querying FW for connected ports.
  2941. * This process is long, asynchronous and by the time it's done,
  2942. * collected information might not be accurate anymore. E.g.
  2943. * disconnected port might have re-connected and a brand new
  2944. * session has been created. In this case session's generation
  2945. * will be newer than discovery_gen. */
  2946. qlt_do_generation_tick(vha, &discovery_gen);
  2947. rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
  2948. if (rval != QLA_SUCCESS)
  2949. break;
  2950. /*
  2951. * Logout all previous fabric devices marked lost, except
  2952. * FCP2 devices.
  2953. */
  2954. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2955. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2956. break;
  2957. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
  2958. continue;
  2959. if (fcport->scan_state == QLA_FCPORT_SCAN) {
  2960. if (qla_ini_mode_enabled(base_vha) &&
  2961. atomic_read(&fcport->state) == FCS_ONLINE) {
  2962. qla2x00_mark_device_lost(vha, fcport,
  2963. ql2xplogiabsentdevice, 0);
  2964. if (fcport->loop_id != FC_NO_LOOP_ID &&
  2965. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  2966. fcport->port_type != FCT_INITIATOR &&
  2967. fcport->port_type != FCT_BROADCAST) {
  2968. ha->isp_ops->fabric_logout(vha,
  2969. fcport->loop_id,
  2970. fcport->d_id.b.domain,
  2971. fcport->d_id.b.area,
  2972. fcport->d_id.b.al_pa);
  2973. qla2x00_clear_loop_id(fcport);
  2974. }
  2975. } else if (!qla_ini_mode_enabled(base_vha)) {
  2976. /*
  2977. * In target mode, explicitly kill
  2978. * sessions and log out of devices
  2979. * that are gone, so that we don't
  2980. * end up with an initiator using the
  2981. * wrong ACL (if the fabric recycles
  2982. * an FC address and we have a stale
  2983. * session around) and so that we don't
  2984. * report initiators that are no longer
  2985. * on the fabric.
  2986. */
  2987. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf077,
  2988. "port gone, logging out/killing session: "
  2989. "%8phC state 0x%x flags 0x%x fc4_type 0x%x "
  2990. "scan_state %d\n",
  2991. fcport->port_name,
  2992. atomic_read(&fcport->state),
  2993. fcport->flags, fcport->fc4_type,
  2994. fcport->scan_state);
  2995. qlt_fc_port_deleted(vha, fcport,
  2996. discovery_gen);
  2997. }
  2998. }
  2999. }
  3000. /* Starting free loop ID. */
  3001. next_loopid = ha->min_external_loopid;
  3002. /*
  3003. * Scan through our port list and login entries that need to be
  3004. * logged in.
  3005. */
  3006. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3007. if (atomic_read(&vha->loop_down_timer) ||
  3008. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3009. break;
  3010. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  3011. (fcport->flags & FCF_LOGIN_NEEDED) == 0)
  3012. continue;
  3013. /*
  3014. * If we're not an initiator, skip looking for devices
  3015. * and logging in. There's no reason for us to do it,
  3016. * and it seems to actively cause problems in target
  3017. * mode if we race with the initiator logging into us
  3018. * (we might get the "port ID used" status back from
  3019. * our login command and log out the initiator, which
  3020. * seems to cause havoc).
  3021. */
  3022. if (!qla_ini_mode_enabled(base_vha)) {
  3023. if (fcport->scan_state == QLA_FCPORT_FOUND) {
  3024. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf078,
  3025. "port %8phC state 0x%x flags 0x%x fc4_type 0x%x "
  3026. "scan_state %d (initiator mode disabled; skipping "
  3027. "login)\n", fcport->port_name,
  3028. atomic_read(&fcport->state),
  3029. fcport->flags, fcport->fc4_type,
  3030. fcport->scan_state);
  3031. }
  3032. continue;
  3033. }
  3034. if (fcport->loop_id == FC_NO_LOOP_ID) {
  3035. fcport->loop_id = next_loopid;
  3036. rval = qla2x00_find_new_loop_id(
  3037. base_vha, fcport);
  3038. if (rval != QLA_SUCCESS) {
  3039. /* Ran out of IDs to use */
  3040. break;
  3041. }
  3042. }
  3043. /* Login and update database */
  3044. qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
  3045. }
  3046. /* Exit if out of loop IDs. */
  3047. if (rval != QLA_SUCCESS) {
  3048. break;
  3049. }
  3050. /*
  3051. * Login and add the new devices to our port list.
  3052. */
  3053. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  3054. if (atomic_read(&vha->loop_down_timer) ||
  3055. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3056. break;
  3057. /*
  3058. * If we're not an initiator, skip looking for devices
  3059. * and logging in. There's no reason for us to do it,
  3060. * and it seems to actively cause problems in target
  3061. * mode if we race with the initiator logging into us
  3062. * (we might get the "port ID used" status back from
  3063. * our login command and log out the initiator, which
  3064. * seems to cause havoc).
  3065. */
  3066. if (qla_ini_mode_enabled(base_vha)) {
  3067. /* Find a new loop ID to use. */
  3068. fcport->loop_id = next_loopid;
  3069. rval = qla2x00_find_new_loop_id(base_vha,
  3070. fcport);
  3071. if (rval != QLA_SUCCESS) {
  3072. /* Ran out of IDs to use */
  3073. break;
  3074. }
  3075. /* Login and update database */
  3076. qla2x00_fabric_dev_login(vha, fcport,
  3077. &next_loopid);
  3078. } else {
  3079. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf079,
  3080. "new port %8phC state 0x%x flags 0x%x fc4_type "
  3081. "0x%x scan_state %d (initiator mode disabled; "
  3082. "skipping login)\n",
  3083. fcport->port_name,
  3084. atomic_read(&fcport->state),
  3085. fcport->flags, fcport->fc4_type,
  3086. fcport->scan_state);
  3087. }
  3088. list_move_tail(&fcport->list, &vha->vp_fcports);
  3089. }
  3090. } while (0);
  3091. /* Free all new device structures not processed. */
  3092. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  3093. list_del(&fcport->list);
  3094. kfree(fcport);
  3095. }
  3096. if (rval) {
  3097. ql_dbg(ql_dbg_disc, vha, 0x2068,
  3098. "Configure fabric error exit rval=%d.\n", rval);
  3099. }
  3100. return (rval);
  3101. }
  3102. /*
  3103. * qla2x00_find_all_fabric_devs
  3104. *
  3105. * Input:
  3106. * ha = adapter block pointer.
  3107. * dev = database device entry pointer.
  3108. *
  3109. * Returns:
  3110. * 0 = success.
  3111. *
  3112. * Context:
  3113. * Kernel context.
  3114. */
  3115. static int
  3116. qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
  3117. struct list_head *new_fcports)
  3118. {
  3119. int rval;
  3120. uint16_t loop_id;
  3121. fc_port_t *fcport, *new_fcport, *fcptemp;
  3122. int found;
  3123. sw_info_t *swl;
  3124. int swl_idx;
  3125. int first_dev, last_dev;
  3126. port_id_t wrap = {}, nxt_d_id;
  3127. struct qla_hw_data *ha = vha->hw;
  3128. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  3129. rval = QLA_SUCCESS;
  3130. /* Try GID_PT to get device list, else GAN. */
  3131. if (!ha->swl)
  3132. ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
  3133. GFP_KERNEL);
  3134. swl = ha->swl;
  3135. if (!swl) {
  3136. /*EMPTY*/
  3137. ql_dbg(ql_dbg_disc, vha, 0x2054,
  3138. "GID_PT allocations failed, fallback on GA_NXT.\n");
  3139. } else {
  3140. memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
  3141. if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
  3142. swl = NULL;
  3143. } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
  3144. swl = NULL;
  3145. } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
  3146. swl = NULL;
  3147. } else if (ql2xiidmaenable &&
  3148. qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
  3149. qla2x00_gpsc(vha, swl);
  3150. }
  3151. /* If other queries succeeded probe for FC-4 type */
  3152. if (swl)
  3153. qla2x00_gff_id(vha, swl);
  3154. }
  3155. swl_idx = 0;
  3156. /* Allocate temporary fcport for any new fcports discovered. */
  3157. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  3158. if (new_fcport == NULL) {
  3159. ql_log(ql_log_warn, vha, 0x205e,
  3160. "Failed to allocate memory for fcport.\n");
  3161. return (QLA_MEMORY_ALLOC_FAILED);
  3162. }
  3163. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  3164. /* Set start port ID scan at adapter ID. */
  3165. first_dev = 1;
  3166. last_dev = 0;
  3167. /* Starting free loop ID. */
  3168. loop_id = ha->min_external_loopid;
  3169. for (; loop_id <= ha->max_loop_id; loop_id++) {
  3170. if (qla2x00_is_reserved_id(vha, loop_id))
  3171. continue;
  3172. if (ha->current_topology == ISP_CFG_FL &&
  3173. (atomic_read(&vha->loop_down_timer) ||
  3174. LOOP_TRANSITION(vha))) {
  3175. atomic_set(&vha->loop_down_timer, 0);
  3176. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3177. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  3178. break;
  3179. }
  3180. if (swl != NULL) {
  3181. if (last_dev) {
  3182. wrap.b24 = new_fcport->d_id.b24;
  3183. } else {
  3184. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  3185. memcpy(new_fcport->node_name,
  3186. swl[swl_idx].node_name, WWN_SIZE);
  3187. memcpy(new_fcport->port_name,
  3188. swl[swl_idx].port_name, WWN_SIZE);
  3189. memcpy(new_fcport->fabric_port_name,
  3190. swl[swl_idx].fabric_port_name, WWN_SIZE);
  3191. new_fcport->fp_speed = swl[swl_idx].fp_speed;
  3192. new_fcport->fc4_type = swl[swl_idx].fc4_type;
  3193. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  3194. last_dev = 1;
  3195. }
  3196. swl_idx++;
  3197. }
  3198. } else {
  3199. /* Send GA_NXT to the switch */
  3200. rval = qla2x00_ga_nxt(vha, new_fcport);
  3201. if (rval != QLA_SUCCESS) {
  3202. ql_log(ql_log_warn, vha, 0x2064,
  3203. "SNS scan failed -- assuming "
  3204. "zero-entry result.\n");
  3205. list_for_each_entry_safe(fcport, fcptemp,
  3206. new_fcports, list) {
  3207. list_del(&fcport->list);
  3208. kfree(fcport);
  3209. }
  3210. rval = QLA_SUCCESS;
  3211. break;
  3212. }
  3213. }
  3214. /* If wrap on switch device list, exit. */
  3215. if (first_dev) {
  3216. wrap.b24 = new_fcport->d_id.b24;
  3217. first_dev = 0;
  3218. } else if (new_fcport->d_id.b24 == wrap.b24) {
  3219. ql_dbg(ql_dbg_disc, vha, 0x2065,
  3220. "Device wrap (%02x%02x%02x).\n",
  3221. new_fcport->d_id.b.domain,
  3222. new_fcport->d_id.b.area,
  3223. new_fcport->d_id.b.al_pa);
  3224. break;
  3225. }
  3226. /* Bypass if same physical adapter. */
  3227. if (new_fcport->d_id.b24 == base_vha->d_id.b24)
  3228. continue;
  3229. /* Bypass virtual ports of the same host. */
  3230. if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
  3231. continue;
  3232. /* Bypass if same domain and area of adapter. */
  3233. if (((new_fcport->d_id.b24 & 0xffff00) ==
  3234. (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
  3235. ISP_CFG_FL)
  3236. continue;
  3237. /* Bypass reserved domain fields. */
  3238. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  3239. continue;
  3240. /* Bypass ports whose FCP-4 type is not FCP_SCSI */
  3241. if (ql2xgffidenable &&
  3242. (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
  3243. new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
  3244. continue;
  3245. /* Locate matching device in database. */
  3246. found = 0;
  3247. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3248. if (memcmp(new_fcport->port_name, fcport->port_name,
  3249. WWN_SIZE))
  3250. continue;
  3251. fcport->scan_state = QLA_FCPORT_FOUND;
  3252. found++;
  3253. /* Update port state. */
  3254. memcpy(fcport->fabric_port_name,
  3255. new_fcport->fabric_port_name, WWN_SIZE);
  3256. fcport->fp_speed = new_fcport->fp_speed;
  3257. /*
  3258. * If address the same and state FCS_ONLINE
  3259. * (or in target mode), nothing changed.
  3260. */
  3261. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  3262. (atomic_read(&fcport->state) == FCS_ONLINE ||
  3263. !qla_ini_mode_enabled(base_vha))) {
  3264. break;
  3265. }
  3266. /*
  3267. * If device was not a fabric device before.
  3268. */
  3269. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  3270. fcport->d_id.b24 = new_fcport->d_id.b24;
  3271. qla2x00_clear_loop_id(fcport);
  3272. fcport->flags |= (FCF_FABRIC_DEVICE |
  3273. FCF_LOGIN_NEEDED);
  3274. break;
  3275. }
  3276. /*
  3277. * Port ID changed or device was marked to be updated;
  3278. * Log it out if still logged in and mark it for
  3279. * relogin later.
  3280. */
  3281. if (!qla_ini_mode_enabled(base_vha)) {
  3282. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
  3283. "port changed FC ID, %8phC"
  3284. " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
  3285. fcport->port_name,
  3286. fcport->d_id.b.domain,
  3287. fcport->d_id.b.area,
  3288. fcport->d_id.b.al_pa,
  3289. fcport->loop_id,
  3290. new_fcport->d_id.b.domain,
  3291. new_fcport->d_id.b.area,
  3292. new_fcport->d_id.b.al_pa);
  3293. fcport->d_id.b24 = new_fcport->d_id.b24;
  3294. break;
  3295. }
  3296. fcport->d_id.b24 = new_fcport->d_id.b24;
  3297. fcport->flags |= FCF_LOGIN_NEEDED;
  3298. if (fcport->loop_id != FC_NO_LOOP_ID &&
  3299. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  3300. (fcport->flags & FCF_ASYNC_SENT) == 0 &&
  3301. fcport->port_type != FCT_INITIATOR &&
  3302. fcport->port_type != FCT_BROADCAST) {
  3303. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3304. fcport->d_id.b.domain, fcport->d_id.b.area,
  3305. fcport->d_id.b.al_pa);
  3306. qla2x00_clear_loop_id(fcport);
  3307. }
  3308. break;
  3309. }
  3310. if (found)
  3311. continue;
  3312. /* If device was not in our fcports list, then add it. */
  3313. new_fcport->scan_state = QLA_FCPORT_FOUND;
  3314. list_add_tail(&new_fcport->list, new_fcports);
  3315. /* Allocate a new replacement fcport. */
  3316. nxt_d_id.b24 = new_fcport->d_id.b24;
  3317. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  3318. if (new_fcport == NULL) {
  3319. ql_log(ql_log_warn, vha, 0x2066,
  3320. "Memory allocation failed for fcport.\n");
  3321. return (QLA_MEMORY_ALLOC_FAILED);
  3322. }
  3323. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  3324. new_fcport->d_id.b24 = nxt_d_id.b24;
  3325. }
  3326. kfree(new_fcport);
  3327. return (rval);
  3328. }
  3329. /*
  3330. * qla2x00_find_new_loop_id
  3331. * Scan through our port list and find a new usable loop ID.
  3332. *
  3333. * Input:
  3334. * ha: adapter state pointer.
  3335. * dev: port structure pointer.
  3336. *
  3337. * Returns:
  3338. * qla2x00 local function return status code.
  3339. *
  3340. * Context:
  3341. * Kernel context.
  3342. */
  3343. int
  3344. qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
  3345. {
  3346. int rval;
  3347. struct qla_hw_data *ha = vha->hw;
  3348. unsigned long flags = 0;
  3349. rval = QLA_SUCCESS;
  3350. spin_lock_irqsave(&ha->vport_slock, flags);
  3351. dev->loop_id = find_first_zero_bit(ha->loop_id_map,
  3352. LOOPID_MAP_SIZE);
  3353. if (dev->loop_id >= LOOPID_MAP_SIZE ||
  3354. qla2x00_is_reserved_id(vha, dev->loop_id)) {
  3355. dev->loop_id = FC_NO_LOOP_ID;
  3356. rval = QLA_FUNCTION_FAILED;
  3357. } else
  3358. set_bit(dev->loop_id, ha->loop_id_map);
  3359. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3360. if (rval == QLA_SUCCESS)
  3361. ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
  3362. "Assigning new loopid=%x, portid=%x.\n",
  3363. dev->loop_id, dev->d_id.b24);
  3364. else
  3365. ql_log(ql_log_warn, dev->vha, 0x2087,
  3366. "No loop_id's available, portid=%x.\n",
  3367. dev->d_id.b24);
  3368. return (rval);
  3369. }
  3370. /*
  3371. * qla2x00_fabric_dev_login
  3372. * Login fabric target device and update FC port database.
  3373. *
  3374. * Input:
  3375. * ha: adapter state pointer.
  3376. * fcport: port structure list pointer.
  3377. * next_loopid: contains value of a new loop ID that can be used
  3378. * by the next login attempt.
  3379. *
  3380. * Returns:
  3381. * qla2x00 local function return status code.
  3382. *
  3383. * Context:
  3384. * Kernel context.
  3385. */
  3386. static int
  3387. qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3388. uint16_t *next_loopid)
  3389. {
  3390. int rval;
  3391. uint8_t opts;
  3392. struct qla_hw_data *ha = vha->hw;
  3393. rval = QLA_SUCCESS;
  3394. if (IS_ALOGIO_CAPABLE(ha)) {
  3395. if (fcport->flags & FCF_ASYNC_SENT)
  3396. return rval;
  3397. fcport->flags |= FCF_ASYNC_SENT;
  3398. rval = qla2x00_post_async_login_work(vha, fcport, NULL);
  3399. if (!rval)
  3400. return rval;
  3401. }
  3402. fcport->flags &= ~FCF_ASYNC_SENT;
  3403. rval = qla2x00_fabric_login(vha, fcport, next_loopid);
  3404. if (rval == QLA_SUCCESS) {
  3405. /* Send an ADISC to FCP2 devices.*/
  3406. opts = 0;
  3407. if (fcport->flags & FCF_FCP2_DEVICE)
  3408. opts |= BIT_1;
  3409. rval = qla2x00_get_port_database(vha, fcport, opts);
  3410. if (rval != QLA_SUCCESS) {
  3411. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3412. fcport->d_id.b.domain, fcport->d_id.b.area,
  3413. fcport->d_id.b.al_pa);
  3414. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3415. } else {
  3416. qla2x00_update_fcport(vha, fcport);
  3417. }
  3418. } else {
  3419. /* Retry Login. */
  3420. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3421. }
  3422. return (rval);
  3423. }
  3424. /*
  3425. * qla2x00_fabric_login
  3426. * Issue fabric login command.
  3427. *
  3428. * Input:
  3429. * ha = adapter block pointer.
  3430. * device = pointer to FC device type structure.
  3431. *
  3432. * Returns:
  3433. * 0 - Login successfully
  3434. * 1 - Login failed
  3435. * 2 - Initiator device
  3436. * 3 - Fatal error
  3437. */
  3438. int
  3439. qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3440. uint16_t *next_loopid)
  3441. {
  3442. int rval;
  3443. int retry;
  3444. uint16_t tmp_loopid;
  3445. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3446. struct qla_hw_data *ha = vha->hw;
  3447. retry = 0;
  3448. tmp_loopid = 0;
  3449. for (;;) {
  3450. ql_dbg(ql_dbg_disc, vha, 0x2000,
  3451. "Trying Fabric Login w/loop id 0x%04x for port "
  3452. "%02x%02x%02x.\n",
  3453. fcport->loop_id, fcport->d_id.b.domain,
  3454. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3455. /* Login fcport on switch. */
  3456. rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
  3457. fcport->d_id.b.domain, fcport->d_id.b.area,
  3458. fcport->d_id.b.al_pa, mb, BIT_0);
  3459. if (rval != QLA_SUCCESS) {
  3460. return rval;
  3461. }
  3462. if (mb[0] == MBS_PORT_ID_USED) {
  3463. /*
  3464. * Device has another loop ID. The firmware team
  3465. * recommends the driver perform an implicit login with
  3466. * the specified ID again. The ID we just used is save
  3467. * here so we return with an ID that can be tried by
  3468. * the next login.
  3469. */
  3470. retry++;
  3471. tmp_loopid = fcport->loop_id;
  3472. fcport->loop_id = mb[1];
  3473. ql_dbg(ql_dbg_disc, vha, 0x2001,
  3474. "Fabric Login: port in use - next loop "
  3475. "id=0x%04x, port id= %02x%02x%02x.\n",
  3476. fcport->loop_id, fcport->d_id.b.domain,
  3477. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3478. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  3479. /*
  3480. * Login succeeded.
  3481. */
  3482. if (retry) {
  3483. /* A retry occurred before. */
  3484. *next_loopid = tmp_loopid;
  3485. } else {
  3486. /*
  3487. * No retry occurred before. Just increment the
  3488. * ID value for next login.
  3489. */
  3490. *next_loopid = (fcport->loop_id + 1);
  3491. }
  3492. if (mb[1] & BIT_0) {
  3493. fcport->port_type = FCT_INITIATOR;
  3494. } else {
  3495. fcport->port_type = FCT_TARGET;
  3496. if (mb[1] & BIT_1) {
  3497. fcport->flags |= FCF_FCP2_DEVICE;
  3498. }
  3499. }
  3500. if (mb[10] & BIT_0)
  3501. fcport->supported_classes |= FC_COS_CLASS2;
  3502. if (mb[10] & BIT_1)
  3503. fcport->supported_classes |= FC_COS_CLASS3;
  3504. if (IS_FWI2_CAPABLE(ha)) {
  3505. if (mb[10] & BIT_7)
  3506. fcport->flags |=
  3507. FCF_CONF_COMP_SUPPORTED;
  3508. }
  3509. rval = QLA_SUCCESS;
  3510. break;
  3511. } else if (mb[0] == MBS_LOOP_ID_USED) {
  3512. /*
  3513. * Loop ID already used, try next loop ID.
  3514. */
  3515. fcport->loop_id++;
  3516. rval = qla2x00_find_new_loop_id(vha, fcport);
  3517. if (rval != QLA_SUCCESS) {
  3518. /* Ran out of loop IDs to use */
  3519. break;
  3520. }
  3521. } else if (mb[0] == MBS_COMMAND_ERROR) {
  3522. /*
  3523. * Firmware possibly timed out during login. If NO
  3524. * retries are left to do then the device is declared
  3525. * dead.
  3526. */
  3527. *next_loopid = fcport->loop_id;
  3528. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3529. fcport->d_id.b.domain, fcport->d_id.b.area,
  3530. fcport->d_id.b.al_pa);
  3531. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3532. rval = 1;
  3533. break;
  3534. } else {
  3535. /*
  3536. * unrecoverable / not handled error
  3537. */
  3538. ql_dbg(ql_dbg_disc, vha, 0x2002,
  3539. "Failed=%x port_id=%02x%02x%02x loop_id=%x "
  3540. "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
  3541. fcport->d_id.b.area, fcport->d_id.b.al_pa,
  3542. fcport->loop_id, jiffies);
  3543. *next_loopid = fcport->loop_id;
  3544. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3545. fcport->d_id.b.domain, fcport->d_id.b.area,
  3546. fcport->d_id.b.al_pa);
  3547. qla2x00_clear_loop_id(fcport);
  3548. fcport->login_retry = 0;
  3549. rval = 3;
  3550. break;
  3551. }
  3552. }
  3553. return (rval);
  3554. }
  3555. /*
  3556. * qla2x00_local_device_login
  3557. * Issue local device login command.
  3558. *
  3559. * Input:
  3560. * ha = adapter block pointer.
  3561. * loop_id = loop id of device to login to.
  3562. *
  3563. * Returns (Where's the #define!!!!):
  3564. * 0 - Login successfully
  3565. * 1 - Login failed
  3566. * 3 - Fatal error
  3567. */
  3568. int
  3569. qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
  3570. {
  3571. int rval;
  3572. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3573. memset(mb, 0, sizeof(mb));
  3574. rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
  3575. if (rval == QLA_SUCCESS) {
  3576. /* Interrogate mailbox registers for any errors */
  3577. if (mb[0] == MBS_COMMAND_ERROR)
  3578. rval = 1;
  3579. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  3580. /* device not in PCB table */
  3581. rval = 3;
  3582. }
  3583. return (rval);
  3584. }
  3585. /*
  3586. * qla2x00_loop_resync
  3587. * Resync with fibre channel devices.
  3588. *
  3589. * Input:
  3590. * ha = adapter block pointer.
  3591. *
  3592. * Returns:
  3593. * 0 = success
  3594. */
  3595. int
  3596. qla2x00_loop_resync(scsi_qla_host_t *vha)
  3597. {
  3598. int rval = QLA_SUCCESS;
  3599. uint32_t wait_time;
  3600. struct req_que *req;
  3601. struct rsp_que *rsp;
  3602. if (vha->hw->flags.cpu_affinity_enabled)
  3603. req = vha->hw->req_q_map[0];
  3604. else
  3605. req = vha->req;
  3606. rsp = req->rsp;
  3607. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3608. if (vha->flags.online) {
  3609. if (!(rval = qla2x00_fw_ready(vha))) {
  3610. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3611. wait_time = 256;
  3612. do {
  3613. if (!IS_QLAFX00(vha->hw)) {
  3614. /*
  3615. * Issue a marker after FW becomes
  3616. * ready.
  3617. */
  3618. qla2x00_marker(vha, req, rsp, 0, 0,
  3619. MK_SYNC_ALL);
  3620. vha->marker_needed = 0;
  3621. }
  3622. /* Remap devices on Loop. */
  3623. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3624. if (IS_QLAFX00(vha->hw))
  3625. qlafx00_configure_devices(vha);
  3626. else
  3627. qla2x00_configure_loop(vha);
  3628. wait_time--;
  3629. } while (!atomic_read(&vha->loop_down_timer) &&
  3630. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3631. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3632. &vha->dpc_flags)));
  3633. }
  3634. }
  3635. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3636. return (QLA_FUNCTION_FAILED);
  3637. if (rval)
  3638. ql_dbg(ql_dbg_disc, vha, 0x206c,
  3639. "%s *** FAILED ***.\n", __func__);
  3640. return (rval);
  3641. }
  3642. /*
  3643. * qla2x00_perform_loop_resync
  3644. * Description: This function will set the appropriate flags and call
  3645. * qla2x00_loop_resync. If successful loop will be resynced
  3646. * Arguments : scsi_qla_host_t pointer
  3647. * returm : Success or Failure
  3648. */
  3649. int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
  3650. {
  3651. int32_t rval = 0;
  3652. if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
  3653. /*Configure the flags so that resync happens properly*/
  3654. atomic_set(&ha->loop_down_timer, 0);
  3655. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  3656. atomic_set(&ha->loop_state, LOOP_UP);
  3657. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  3658. set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
  3659. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  3660. rval = qla2x00_loop_resync(ha);
  3661. } else
  3662. atomic_set(&ha->loop_state, LOOP_DEAD);
  3663. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  3664. }
  3665. return rval;
  3666. }
  3667. void
  3668. qla2x00_update_fcports(scsi_qla_host_t *base_vha)
  3669. {
  3670. fc_port_t *fcport;
  3671. struct scsi_qla_host *vha;
  3672. struct qla_hw_data *ha = base_vha->hw;
  3673. unsigned long flags;
  3674. spin_lock_irqsave(&ha->vport_slock, flags);
  3675. /* Go with deferred removal of rport references. */
  3676. list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
  3677. atomic_inc(&vha->vref_count);
  3678. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3679. if (fcport->drport &&
  3680. atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
  3681. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3682. qla2x00_rport_del(fcport);
  3683. /*
  3684. * Release the target mode FC NEXUS in
  3685. * qla_target.c, if target mod is enabled.
  3686. */
  3687. qlt_fc_port_deleted(vha, fcport,
  3688. base_vha->total_fcport_update_gen);
  3689. spin_lock_irqsave(&ha->vport_slock, flags);
  3690. }
  3691. }
  3692. atomic_dec(&vha->vref_count);
  3693. }
  3694. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3695. }
  3696. /* Assumes idc_lock always held on entry */
  3697. void
  3698. qla83xx_reset_ownership(scsi_qla_host_t *vha)
  3699. {
  3700. struct qla_hw_data *ha = vha->hw;
  3701. uint32_t drv_presence, drv_presence_mask;
  3702. uint32_t dev_part_info1, dev_part_info2, class_type;
  3703. uint32_t class_type_mask = 0x3;
  3704. uint16_t fcoe_other_function = 0xffff, i;
  3705. if (IS_QLA8044(ha)) {
  3706. drv_presence = qla8044_rd_direct(vha,
  3707. QLA8044_CRB_DRV_ACTIVE_INDEX);
  3708. dev_part_info1 = qla8044_rd_direct(vha,
  3709. QLA8044_CRB_DEV_PART_INFO_INDEX);
  3710. dev_part_info2 = qla8044_rd_direct(vha,
  3711. QLA8044_CRB_DEV_PART_INFO2);
  3712. } else {
  3713. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3714. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
  3715. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
  3716. }
  3717. for (i = 0; i < 8; i++) {
  3718. class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
  3719. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3720. (i != ha->portnum)) {
  3721. fcoe_other_function = i;
  3722. break;
  3723. }
  3724. }
  3725. if (fcoe_other_function == 0xffff) {
  3726. for (i = 0; i < 8; i++) {
  3727. class_type = ((dev_part_info2 >> (i * 4)) &
  3728. class_type_mask);
  3729. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3730. ((i + 8) != ha->portnum)) {
  3731. fcoe_other_function = i + 8;
  3732. break;
  3733. }
  3734. }
  3735. }
  3736. /*
  3737. * Prepare drv-presence mask based on fcoe functions present.
  3738. * However consider only valid physical fcoe function numbers (0-15).
  3739. */
  3740. drv_presence_mask = ~((1 << (ha->portnum)) |
  3741. ((fcoe_other_function == 0xffff) ?
  3742. 0 : (1 << (fcoe_other_function))));
  3743. /* We are the reset owner iff:
  3744. * - No other protocol drivers present.
  3745. * - This is the lowest among fcoe functions. */
  3746. if (!(drv_presence & drv_presence_mask) &&
  3747. (ha->portnum < fcoe_other_function)) {
  3748. ql_dbg(ql_dbg_p3p, vha, 0xb07f,
  3749. "This host is Reset owner.\n");
  3750. ha->flags.nic_core_reset_owner = 1;
  3751. }
  3752. }
  3753. static int
  3754. __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
  3755. {
  3756. int rval = QLA_SUCCESS;
  3757. struct qla_hw_data *ha = vha->hw;
  3758. uint32_t drv_ack;
  3759. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3760. if (rval == QLA_SUCCESS) {
  3761. drv_ack |= (1 << ha->portnum);
  3762. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3763. }
  3764. return rval;
  3765. }
  3766. static int
  3767. __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
  3768. {
  3769. int rval = QLA_SUCCESS;
  3770. struct qla_hw_data *ha = vha->hw;
  3771. uint32_t drv_ack;
  3772. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3773. if (rval == QLA_SUCCESS) {
  3774. drv_ack &= ~(1 << ha->portnum);
  3775. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3776. }
  3777. return rval;
  3778. }
  3779. static const char *
  3780. qla83xx_dev_state_to_string(uint32_t dev_state)
  3781. {
  3782. switch (dev_state) {
  3783. case QLA8XXX_DEV_COLD:
  3784. return "COLD/RE-INIT";
  3785. case QLA8XXX_DEV_INITIALIZING:
  3786. return "INITIALIZING";
  3787. case QLA8XXX_DEV_READY:
  3788. return "READY";
  3789. case QLA8XXX_DEV_NEED_RESET:
  3790. return "NEED RESET";
  3791. case QLA8XXX_DEV_NEED_QUIESCENT:
  3792. return "NEED QUIESCENT";
  3793. case QLA8XXX_DEV_FAILED:
  3794. return "FAILED";
  3795. case QLA8XXX_DEV_QUIESCENT:
  3796. return "QUIESCENT";
  3797. default:
  3798. return "Unknown";
  3799. }
  3800. }
  3801. /* Assumes idc-lock always held on entry */
  3802. void
  3803. qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
  3804. {
  3805. struct qla_hw_data *ha = vha->hw;
  3806. uint32_t idc_audit_reg = 0, duration_secs = 0;
  3807. switch (audit_type) {
  3808. case IDC_AUDIT_TIMESTAMP:
  3809. ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
  3810. idc_audit_reg = (ha->portnum) |
  3811. (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
  3812. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3813. break;
  3814. case IDC_AUDIT_COMPLETION:
  3815. duration_secs = ((jiffies_to_msecs(jiffies) -
  3816. jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
  3817. idc_audit_reg = (ha->portnum) |
  3818. (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
  3819. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3820. break;
  3821. default:
  3822. ql_log(ql_log_warn, vha, 0xb078,
  3823. "Invalid audit type specified.\n");
  3824. break;
  3825. }
  3826. }
  3827. /* Assumes idc_lock always held on entry */
  3828. static int
  3829. qla83xx_initiating_reset(scsi_qla_host_t *vha)
  3830. {
  3831. struct qla_hw_data *ha = vha->hw;
  3832. uint32_t idc_control, dev_state;
  3833. __qla83xx_get_idc_control(vha, &idc_control);
  3834. if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
  3835. ql_log(ql_log_info, vha, 0xb080,
  3836. "NIC Core reset has been disabled. idc-control=0x%x\n",
  3837. idc_control);
  3838. return QLA_FUNCTION_FAILED;
  3839. }
  3840. /* Set NEED-RESET iff in READY state and we are the reset-owner */
  3841. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3842. if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
  3843. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  3844. QLA8XXX_DEV_NEED_RESET);
  3845. ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
  3846. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  3847. } else {
  3848. const char *state = qla83xx_dev_state_to_string(dev_state);
  3849. ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
  3850. /* SV: XXX: Is timeout required here? */
  3851. /* Wait for IDC state change READY -> NEED_RESET */
  3852. while (dev_state == QLA8XXX_DEV_READY) {
  3853. qla83xx_idc_unlock(vha, 0);
  3854. msleep(200);
  3855. qla83xx_idc_lock(vha, 0);
  3856. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3857. }
  3858. }
  3859. /* Send IDC ack by writing to drv-ack register */
  3860. __qla83xx_set_drv_ack(vha);
  3861. return QLA_SUCCESS;
  3862. }
  3863. int
  3864. __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
  3865. {
  3866. return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3867. }
  3868. int
  3869. __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
  3870. {
  3871. return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3872. }
  3873. static int
  3874. qla83xx_check_driver_presence(scsi_qla_host_t *vha)
  3875. {
  3876. uint32_t drv_presence = 0;
  3877. struct qla_hw_data *ha = vha->hw;
  3878. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3879. if (drv_presence & (1 << ha->portnum))
  3880. return QLA_SUCCESS;
  3881. else
  3882. return QLA_TEST_FAILED;
  3883. }
  3884. int
  3885. qla83xx_nic_core_reset(scsi_qla_host_t *vha)
  3886. {
  3887. int rval = QLA_SUCCESS;
  3888. struct qla_hw_data *ha = vha->hw;
  3889. ql_dbg(ql_dbg_p3p, vha, 0xb058,
  3890. "Entered %s().\n", __func__);
  3891. if (vha->device_flags & DFLG_DEV_FAILED) {
  3892. ql_log(ql_log_warn, vha, 0xb059,
  3893. "Device in unrecoverable FAILED state.\n");
  3894. return QLA_FUNCTION_FAILED;
  3895. }
  3896. qla83xx_idc_lock(vha, 0);
  3897. if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
  3898. ql_log(ql_log_warn, vha, 0xb05a,
  3899. "Function=0x%x has been removed from IDC participation.\n",
  3900. ha->portnum);
  3901. rval = QLA_FUNCTION_FAILED;
  3902. goto exit;
  3903. }
  3904. qla83xx_reset_ownership(vha);
  3905. rval = qla83xx_initiating_reset(vha);
  3906. /*
  3907. * Perform reset if we are the reset-owner,
  3908. * else wait till IDC state changes to READY/FAILED.
  3909. */
  3910. if (rval == QLA_SUCCESS) {
  3911. rval = qla83xx_idc_state_handler(vha);
  3912. if (rval == QLA_SUCCESS)
  3913. ha->flags.nic_core_hung = 0;
  3914. __qla83xx_clear_drv_ack(vha);
  3915. }
  3916. exit:
  3917. qla83xx_idc_unlock(vha, 0);
  3918. ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
  3919. return rval;
  3920. }
  3921. int
  3922. qla2xxx_mctp_dump(scsi_qla_host_t *vha)
  3923. {
  3924. struct qla_hw_data *ha = vha->hw;
  3925. int rval = QLA_FUNCTION_FAILED;
  3926. if (!IS_MCTP_CAPABLE(ha)) {
  3927. /* This message can be removed from the final version */
  3928. ql_log(ql_log_info, vha, 0x506d,
  3929. "This board is not MCTP capable\n");
  3930. return rval;
  3931. }
  3932. if (!ha->mctp_dump) {
  3933. ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
  3934. MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
  3935. if (!ha->mctp_dump) {
  3936. ql_log(ql_log_warn, vha, 0x506e,
  3937. "Failed to allocate memory for mctp dump\n");
  3938. return rval;
  3939. }
  3940. }
  3941. #define MCTP_DUMP_STR_ADDR 0x00000000
  3942. rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
  3943. MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
  3944. if (rval != QLA_SUCCESS) {
  3945. ql_log(ql_log_warn, vha, 0x506f,
  3946. "Failed to capture mctp dump\n");
  3947. } else {
  3948. ql_log(ql_log_info, vha, 0x5070,
  3949. "Mctp dump capture for host (%ld/%p).\n",
  3950. vha->host_no, ha->mctp_dump);
  3951. ha->mctp_dumped = 1;
  3952. }
  3953. if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
  3954. ha->flags.nic_core_reset_hdlr_active = 1;
  3955. rval = qla83xx_restart_nic_firmware(vha);
  3956. if (rval)
  3957. /* NIC Core reset failed. */
  3958. ql_log(ql_log_warn, vha, 0x5071,
  3959. "Failed to restart nic firmware\n");
  3960. else
  3961. ql_dbg(ql_dbg_p3p, vha, 0xb084,
  3962. "Restarted NIC firmware successfully.\n");
  3963. ha->flags.nic_core_reset_hdlr_active = 0;
  3964. }
  3965. return rval;
  3966. }
  3967. /*
  3968. * qla2x00_quiesce_io
  3969. * Description: This function will block the new I/Os
  3970. * Its not aborting any I/Os as context
  3971. * is not destroyed during quiescence
  3972. * Arguments: scsi_qla_host_t
  3973. * return : void
  3974. */
  3975. void
  3976. qla2x00_quiesce_io(scsi_qla_host_t *vha)
  3977. {
  3978. struct qla_hw_data *ha = vha->hw;
  3979. struct scsi_qla_host *vp;
  3980. ql_dbg(ql_dbg_dpc, vha, 0x401d,
  3981. "Quiescing I/O - ha=%p.\n", ha);
  3982. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  3983. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3984. atomic_set(&vha->loop_state, LOOP_DOWN);
  3985. qla2x00_mark_all_devices_lost(vha, 0);
  3986. list_for_each_entry(vp, &ha->vp_list, list)
  3987. qla2x00_mark_all_devices_lost(vp, 0);
  3988. } else {
  3989. if (!atomic_read(&vha->loop_down_timer))
  3990. atomic_set(&vha->loop_down_timer,
  3991. LOOP_DOWN_TIME);
  3992. }
  3993. /* Wait for pending cmds to complete */
  3994. qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
  3995. }
  3996. void
  3997. qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
  3998. {
  3999. struct qla_hw_data *ha = vha->hw;
  4000. struct scsi_qla_host *vp;
  4001. unsigned long flags;
  4002. fc_port_t *fcport;
  4003. /* For ISP82XX, driver waits for completion of the commands.
  4004. * online flag should be set.
  4005. */
  4006. if (!(IS_P3P_TYPE(ha)))
  4007. vha->flags.online = 0;
  4008. ha->flags.chip_reset_done = 0;
  4009. clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  4010. vha->qla_stats.total_isp_aborts++;
  4011. ql_log(ql_log_info, vha, 0x00af,
  4012. "Performing ISP error recovery - ha=%p.\n", ha);
  4013. /* For ISP82XX, reset_chip is just disabling interrupts.
  4014. * Driver waits for the completion of the commands.
  4015. * the interrupts need to be enabled.
  4016. */
  4017. if (!(IS_P3P_TYPE(ha)))
  4018. ha->isp_ops->reset_chip(vha);
  4019. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  4020. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  4021. atomic_set(&vha->loop_state, LOOP_DOWN);
  4022. qla2x00_mark_all_devices_lost(vha, 0);
  4023. spin_lock_irqsave(&ha->vport_slock, flags);
  4024. list_for_each_entry(vp, &ha->vp_list, list) {
  4025. atomic_inc(&vp->vref_count);
  4026. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4027. qla2x00_mark_all_devices_lost(vp, 0);
  4028. spin_lock_irqsave(&ha->vport_slock, flags);
  4029. atomic_dec(&vp->vref_count);
  4030. }
  4031. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4032. } else {
  4033. if (!atomic_read(&vha->loop_down_timer))
  4034. atomic_set(&vha->loop_down_timer,
  4035. LOOP_DOWN_TIME);
  4036. }
  4037. /* Clear all async request states across all VPs. */
  4038. list_for_each_entry(fcport, &vha->vp_fcports, list)
  4039. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  4040. spin_lock_irqsave(&ha->vport_slock, flags);
  4041. list_for_each_entry(vp, &ha->vp_list, list) {
  4042. atomic_inc(&vp->vref_count);
  4043. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4044. list_for_each_entry(fcport, &vp->vp_fcports, list)
  4045. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  4046. spin_lock_irqsave(&ha->vport_slock, flags);
  4047. atomic_dec(&vp->vref_count);
  4048. }
  4049. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4050. if (!ha->flags.eeh_busy) {
  4051. /* Make sure for ISP 82XX IO DMA is complete */
  4052. if (IS_P3P_TYPE(ha)) {
  4053. qla82xx_chip_reset_cleanup(vha);
  4054. ql_log(ql_log_info, vha, 0x00b4,
  4055. "Done chip reset cleanup.\n");
  4056. /* Done waiting for pending commands.
  4057. * Reset the online flag.
  4058. */
  4059. vha->flags.online = 0;
  4060. }
  4061. /* Requeue all commands in outstanding command list. */
  4062. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  4063. }
  4064. ha->chip_reset++;
  4065. /* memory barrier */
  4066. wmb();
  4067. }
  4068. /*
  4069. * qla2x00_abort_isp
  4070. * Resets ISP and aborts all outstanding commands.
  4071. *
  4072. * Input:
  4073. * ha = adapter block pointer.
  4074. *
  4075. * Returns:
  4076. * 0 = success
  4077. */
  4078. int
  4079. qla2x00_abort_isp(scsi_qla_host_t *vha)
  4080. {
  4081. int rval;
  4082. uint8_t status = 0;
  4083. struct qla_hw_data *ha = vha->hw;
  4084. struct scsi_qla_host *vp;
  4085. struct req_que *req = ha->req_q_map[0];
  4086. unsigned long flags;
  4087. if (vha->flags.online) {
  4088. qla2x00_abort_isp_cleanup(vha);
  4089. if (IS_QLA8031(ha)) {
  4090. ql_dbg(ql_dbg_p3p, vha, 0xb05c,
  4091. "Clearing fcoe driver presence.\n");
  4092. if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
  4093. ql_dbg(ql_dbg_p3p, vha, 0xb073,
  4094. "Error while clearing DRV-Presence.\n");
  4095. }
  4096. if (unlikely(pci_channel_offline(ha->pdev) &&
  4097. ha->flags.pci_channel_io_perm_failure)) {
  4098. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  4099. status = 0;
  4100. return status;
  4101. }
  4102. ha->isp_ops->get_flash_version(vha, req->ring);
  4103. ha->isp_ops->nvram_config(vha);
  4104. if (!qla2x00_restart_isp(vha)) {
  4105. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4106. if (!atomic_read(&vha->loop_down_timer)) {
  4107. /*
  4108. * Issue marker command only when we are going
  4109. * to start the I/O .
  4110. */
  4111. vha->marker_needed = 1;
  4112. }
  4113. vha->flags.online = 1;
  4114. ha->isp_ops->enable_intrs(ha);
  4115. ha->isp_abort_cnt = 0;
  4116. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  4117. if (IS_QLA81XX(ha) || IS_QLA8031(ha))
  4118. qla2x00_get_fw_version(vha);
  4119. if (ha->fce) {
  4120. ha->flags.fce_enabled = 1;
  4121. memset(ha->fce, 0,
  4122. fce_calc_size(ha->fce_bufs));
  4123. rval = qla2x00_enable_fce_trace(vha,
  4124. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  4125. &ha->fce_bufs);
  4126. if (rval) {
  4127. ql_log(ql_log_warn, vha, 0x8033,
  4128. "Unable to reinitialize FCE "
  4129. "(%d).\n", rval);
  4130. ha->flags.fce_enabled = 0;
  4131. }
  4132. }
  4133. if (ha->eft) {
  4134. memset(ha->eft, 0, EFT_SIZE);
  4135. rval = qla2x00_enable_eft_trace(vha,
  4136. ha->eft_dma, EFT_NUM_BUFFERS);
  4137. if (rval) {
  4138. ql_log(ql_log_warn, vha, 0x8034,
  4139. "Unable to reinitialize EFT "
  4140. "(%d).\n", rval);
  4141. }
  4142. }
  4143. } else { /* failed the ISP abort */
  4144. vha->flags.online = 1;
  4145. if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  4146. if (ha->isp_abort_cnt == 0) {
  4147. ql_log(ql_log_fatal, vha, 0x8035,
  4148. "ISP error recover failed - "
  4149. "board disabled.\n");
  4150. /*
  4151. * The next call disables the board
  4152. * completely.
  4153. */
  4154. ha->isp_ops->reset_adapter(vha);
  4155. vha->flags.online = 0;
  4156. clear_bit(ISP_ABORT_RETRY,
  4157. &vha->dpc_flags);
  4158. status = 0;
  4159. } else { /* schedule another ISP abort */
  4160. ha->isp_abort_cnt--;
  4161. ql_dbg(ql_dbg_taskm, vha, 0x8020,
  4162. "ISP abort - retry remaining %d.\n",
  4163. ha->isp_abort_cnt);
  4164. status = 1;
  4165. }
  4166. } else {
  4167. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  4168. ql_dbg(ql_dbg_taskm, vha, 0x8021,
  4169. "ISP error recovery - retrying (%d) "
  4170. "more times.\n", ha->isp_abort_cnt);
  4171. set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  4172. status = 1;
  4173. }
  4174. }
  4175. }
  4176. if (!status) {
  4177. ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
  4178. spin_lock_irqsave(&ha->vport_slock, flags);
  4179. list_for_each_entry(vp, &ha->vp_list, list) {
  4180. if (vp->vp_idx) {
  4181. atomic_inc(&vp->vref_count);
  4182. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4183. qla2x00_vp_abort_isp(vp);
  4184. spin_lock_irqsave(&ha->vport_slock, flags);
  4185. atomic_dec(&vp->vref_count);
  4186. }
  4187. }
  4188. spin_unlock_irqrestore(&ha->vport_slock, flags);
  4189. if (IS_QLA8031(ha)) {
  4190. ql_dbg(ql_dbg_p3p, vha, 0xb05d,
  4191. "Setting back fcoe driver presence.\n");
  4192. if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
  4193. ql_dbg(ql_dbg_p3p, vha, 0xb074,
  4194. "Error while setting DRV-Presence.\n");
  4195. }
  4196. } else {
  4197. ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
  4198. __func__);
  4199. }
  4200. return(status);
  4201. }
  4202. /*
  4203. * qla2x00_restart_isp
  4204. * restarts the ISP after a reset
  4205. *
  4206. * Input:
  4207. * ha = adapter block pointer.
  4208. *
  4209. * Returns:
  4210. * 0 = success
  4211. */
  4212. static int
  4213. qla2x00_restart_isp(scsi_qla_host_t *vha)
  4214. {
  4215. int status = 0;
  4216. struct qla_hw_data *ha = vha->hw;
  4217. struct req_que *req = ha->req_q_map[0];
  4218. struct rsp_que *rsp = ha->rsp_q_map[0];
  4219. unsigned long flags;
  4220. /* If firmware needs to be loaded */
  4221. if (qla2x00_isp_firmware(vha)) {
  4222. vha->flags.online = 0;
  4223. status = ha->isp_ops->chip_diag(vha);
  4224. if (!status)
  4225. status = qla2x00_setup_chip(vha);
  4226. }
  4227. if (!status && !(status = qla2x00_init_rings(vha))) {
  4228. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4229. ha->flags.chip_reset_done = 1;
  4230. /* Initialize the queues in use */
  4231. qla25xx_init_queues(ha);
  4232. status = qla2x00_fw_ready(vha);
  4233. if (!status) {
  4234. /* Issue a marker after FW becomes ready. */
  4235. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4236. vha->flags.online = 1;
  4237. /*
  4238. * Process any ATIO queue entries that came in
  4239. * while we weren't online.
  4240. */
  4241. spin_lock_irqsave(&ha->hardware_lock, flags);
  4242. if (qla_tgt_mode_enabled(vha))
  4243. qlt_24xx_process_atio_queue(vha);
  4244. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4245. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4246. }
  4247. /* if no cable then assume it's good */
  4248. if ((vha->device_flags & DFLG_NO_CABLE))
  4249. status = 0;
  4250. }
  4251. return (status);
  4252. }
  4253. static int
  4254. qla25xx_init_queues(struct qla_hw_data *ha)
  4255. {
  4256. struct rsp_que *rsp = NULL;
  4257. struct req_que *req = NULL;
  4258. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  4259. int ret = -1;
  4260. int i;
  4261. for (i = 1; i < ha->max_rsp_queues; i++) {
  4262. rsp = ha->rsp_q_map[i];
  4263. if (rsp && test_bit(i, ha->rsp_qid_map)) {
  4264. rsp->options &= ~BIT_0;
  4265. ret = qla25xx_init_rsp_que(base_vha, rsp);
  4266. if (ret != QLA_SUCCESS)
  4267. ql_dbg(ql_dbg_init, base_vha, 0x00ff,
  4268. "%s Rsp que: %d init failed.\n",
  4269. __func__, rsp->id);
  4270. else
  4271. ql_dbg(ql_dbg_init, base_vha, 0x0100,
  4272. "%s Rsp que: %d inited.\n",
  4273. __func__, rsp->id);
  4274. }
  4275. }
  4276. for (i = 1; i < ha->max_req_queues; i++) {
  4277. req = ha->req_q_map[i];
  4278. if (req && test_bit(i, ha->req_qid_map)) {
  4279. /* Clear outstanding commands array. */
  4280. req->options &= ~BIT_0;
  4281. ret = qla25xx_init_req_que(base_vha, req);
  4282. if (ret != QLA_SUCCESS)
  4283. ql_dbg(ql_dbg_init, base_vha, 0x0101,
  4284. "%s Req que: %d init failed.\n",
  4285. __func__, req->id);
  4286. else
  4287. ql_dbg(ql_dbg_init, base_vha, 0x0102,
  4288. "%s Req que: %d inited.\n",
  4289. __func__, req->id);
  4290. }
  4291. }
  4292. return ret;
  4293. }
  4294. /*
  4295. * qla2x00_reset_adapter
  4296. * Reset adapter.
  4297. *
  4298. * Input:
  4299. * ha = adapter block pointer.
  4300. */
  4301. void
  4302. qla2x00_reset_adapter(scsi_qla_host_t *vha)
  4303. {
  4304. unsigned long flags = 0;
  4305. struct qla_hw_data *ha = vha->hw;
  4306. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4307. vha->flags.online = 0;
  4308. ha->isp_ops->disable_intrs(ha);
  4309. spin_lock_irqsave(&ha->hardware_lock, flags);
  4310. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  4311. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4312. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  4313. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4314. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4315. }
  4316. void
  4317. qla24xx_reset_adapter(scsi_qla_host_t *vha)
  4318. {
  4319. unsigned long flags = 0;
  4320. struct qla_hw_data *ha = vha->hw;
  4321. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  4322. if (IS_P3P_TYPE(ha))
  4323. return;
  4324. vha->flags.online = 0;
  4325. ha->isp_ops->disable_intrs(ha);
  4326. spin_lock_irqsave(&ha->hardware_lock, flags);
  4327. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  4328. RD_REG_DWORD(&reg->hccr);
  4329. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  4330. RD_REG_DWORD(&reg->hccr);
  4331. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4332. if (IS_NOPOLLING_TYPE(ha))
  4333. ha->isp_ops->enable_intrs(ha);
  4334. }
  4335. /* On sparc systems, obtain port and node WWN from firmware
  4336. * properties.
  4337. */
  4338. static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
  4339. struct nvram_24xx *nv)
  4340. {
  4341. #ifdef CONFIG_SPARC
  4342. struct qla_hw_data *ha = vha->hw;
  4343. struct pci_dev *pdev = ha->pdev;
  4344. struct device_node *dp = pci_device_to_OF_node(pdev);
  4345. const u8 *val;
  4346. int len;
  4347. val = of_get_property(dp, "port-wwn", &len);
  4348. if (val && len >= WWN_SIZE)
  4349. memcpy(nv->port_name, val, WWN_SIZE);
  4350. val = of_get_property(dp, "node-wwn", &len);
  4351. if (val && len >= WWN_SIZE)
  4352. memcpy(nv->node_name, val, WWN_SIZE);
  4353. #endif
  4354. }
  4355. int
  4356. qla24xx_nvram_config(scsi_qla_host_t *vha)
  4357. {
  4358. int rval;
  4359. struct init_cb_24xx *icb;
  4360. struct nvram_24xx *nv;
  4361. uint32_t *dptr;
  4362. uint8_t *dptr1, *dptr2;
  4363. uint32_t chksum;
  4364. uint16_t cnt;
  4365. struct qla_hw_data *ha = vha->hw;
  4366. rval = QLA_SUCCESS;
  4367. icb = (struct init_cb_24xx *)ha->init_cb;
  4368. nv = ha->nvram;
  4369. /* Determine NVRAM starting address. */
  4370. if (ha->port_no == 0) {
  4371. ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
  4372. ha->vpd_base = FA_NVRAM_VPD0_ADDR;
  4373. } else {
  4374. ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
  4375. ha->vpd_base = FA_NVRAM_VPD1_ADDR;
  4376. }
  4377. ha->nvram_size = sizeof(struct nvram_24xx);
  4378. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4379. /* Get VPD data into cache */
  4380. ha->vpd = ha->nvram + VPD_OFFSET;
  4381. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
  4382. ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
  4383. /* Get NVRAM data into cache and calculate checksum. */
  4384. dptr = (uint32_t *)nv;
  4385. ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
  4386. ha->nvram_size);
  4387. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  4388. chksum += le32_to_cpu(*dptr++);
  4389. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
  4390. "Contents of NVRAM\n");
  4391. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
  4392. (uint8_t *)nv, ha->nvram_size);
  4393. /* Bad NVRAM data, set defaults parameters. */
  4394. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4395. || nv->id[3] != ' ' ||
  4396. nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
  4397. /* Reset NVRAM data. */
  4398. ql_log(ql_log_warn, vha, 0x006b,
  4399. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  4400. "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
  4401. ql_log(ql_log_warn, vha, 0x006c,
  4402. "Falling back to functioning (yet invalid -- WWPN) "
  4403. "defaults.\n");
  4404. /*
  4405. * Set default initialization control block.
  4406. */
  4407. memset(nv, 0, ha->nvram_size);
  4408. nv->nvram_version = cpu_to_le16(ICB_VERSION);
  4409. nv->version = cpu_to_le16(ICB_VERSION);
  4410. nv->frame_payload_size = 2048;
  4411. nv->execution_throttle = cpu_to_le16(0xFFFF);
  4412. nv->exchange_count = cpu_to_le16(0);
  4413. nv->hard_address = cpu_to_le16(124);
  4414. nv->port_name[0] = 0x21;
  4415. nv->port_name[1] = 0x00 + ha->port_no + 1;
  4416. nv->port_name[2] = 0x00;
  4417. nv->port_name[3] = 0xe0;
  4418. nv->port_name[4] = 0x8b;
  4419. nv->port_name[5] = 0x1c;
  4420. nv->port_name[6] = 0x55;
  4421. nv->port_name[7] = 0x86;
  4422. nv->node_name[0] = 0x20;
  4423. nv->node_name[1] = 0x00;
  4424. nv->node_name[2] = 0x00;
  4425. nv->node_name[3] = 0xe0;
  4426. nv->node_name[4] = 0x8b;
  4427. nv->node_name[5] = 0x1c;
  4428. nv->node_name[6] = 0x55;
  4429. nv->node_name[7] = 0x86;
  4430. qla24xx_nvram_wwn_from_ofw(vha, nv);
  4431. nv->login_retry_count = cpu_to_le16(8);
  4432. nv->interrupt_delay_timer = cpu_to_le16(0);
  4433. nv->login_timeout = cpu_to_le16(0);
  4434. nv->firmware_options_1 =
  4435. cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4436. nv->firmware_options_2 = cpu_to_le32(2 << 4);
  4437. nv->firmware_options_2 |= cpu_to_le32(BIT_12);
  4438. nv->firmware_options_3 = cpu_to_le32(2 << 13);
  4439. nv->host_p = cpu_to_le32(BIT_11|BIT_10);
  4440. nv->efi_parameters = cpu_to_le32(0);
  4441. nv->reset_delay = 5;
  4442. nv->max_luns_per_target = cpu_to_le16(128);
  4443. nv->port_down_retry_count = cpu_to_le16(30);
  4444. nv->link_down_timeout = cpu_to_le16(30);
  4445. rval = 1;
  4446. }
  4447. if (!qla_ini_mode_enabled(vha)) {
  4448. /* Don't enable full login after initial LIP */
  4449. nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
  4450. /* Don't enable LIP full login for initiator */
  4451. nv->host_p &= cpu_to_le32(~BIT_10);
  4452. }
  4453. qlt_24xx_config_nvram_stage1(vha, nv);
  4454. /* Reset Initialization control block */
  4455. memset(icb, 0, ha->init_cb_size);
  4456. /* Copy 1st segment. */
  4457. dptr1 = (uint8_t *)icb;
  4458. dptr2 = (uint8_t *)&nv->version;
  4459. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4460. while (cnt--)
  4461. *dptr1++ = *dptr2++;
  4462. icb->login_retry_count = nv->login_retry_count;
  4463. icb->link_down_on_nos = nv->link_down_on_nos;
  4464. /* Copy 2nd segment. */
  4465. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4466. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4467. cnt = (uint8_t *)&icb->reserved_3 -
  4468. (uint8_t *)&icb->interrupt_delay_timer;
  4469. while (cnt--)
  4470. *dptr1++ = *dptr2++;
  4471. /*
  4472. * Setup driver NVRAM options.
  4473. */
  4474. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4475. "QLA2462");
  4476. qlt_24xx_config_nvram_stage2(vha, icb);
  4477. if (nv->host_p & cpu_to_le32(BIT_15)) {
  4478. /* Use alternate WWN? */
  4479. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4480. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4481. }
  4482. /* Prepare nodename */
  4483. if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
  4484. /*
  4485. * Firmware will apply the following mask if the nodename was
  4486. * not provided.
  4487. */
  4488. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4489. icb->node_name[0] &= 0xF0;
  4490. }
  4491. /* Set host adapter parameters. */
  4492. ha->flags.disable_risc_code_load = 0;
  4493. ha->flags.enable_lip_reset = 0;
  4494. ha->flags.enable_lip_full_login =
  4495. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4496. ha->flags.enable_target_reset =
  4497. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4498. ha->flags.enable_led_scheme = 0;
  4499. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4500. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4501. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4502. memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
  4503. sizeof(ha->fw_seriallink_options24));
  4504. /* save HBA serial number */
  4505. ha->serial0 = icb->port_name[5];
  4506. ha->serial1 = icb->port_name[6];
  4507. ha->serial2 = icb->port_name[7];
  4508. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4509. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4510. icb->execution_throttle = cpu_to_le16(0xFFFF);
  4511. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4512. /* Set minimum login_timeout to 4 seconds. */
  4513. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4514. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4515. if (le16_to_cpu(nv->login_timeout) < 4)
  4516. nv->login_timeout = cpu_to_le16(4);
  4517. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4518. icb->login_timeout = nv->login_timeout;
  4519. /* Set minimum RATOV to 100 tenths of a second. */
  4520. ha->r_a_tov = 100;
  4521. ha->loop_reset_delay = nv->reset_delay;
  4522. /* Link Down Timeout = 0:
  4523. *
  4524. * When Port Down timer expires we will start returning
  4525. * I/O's to OS with "DID_NO_CONNECT".
  4526. *
  4527. * Link Down Timeout != 0:
  4528. *
  4529. * The driver waits for the link to come up after link down
  4530. * before returning I/Os to OS with "DID_NO_CONNECT".
  4531. */
  4532. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4533. ha->loop_down_abort_time =
  4534. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4535. } else {
  4536. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4537. ha->loop_down_abort_time =
  4538. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4539. }
  4540. /* Need enough time to try and get the port back. */
  4541. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4542. if (qlport_down_retry)
  4543. ha->port_down_retry_count = qlport_down_retry;
  4544. /* Set login_retry_count */
  4545. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4546. if (ha->port_down_retry_count ==
  4547. le16_to_cpu(nv->port_down_retry_count) &&
  4548. ha->port_down_retry_count > 3)
  4549. ha->login_retry_count = ha->port_down_retry_count;
  4550. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4551. ha->login_retry_count = ha->port_down_retry_count;
  4552. if (ql2xloginretrycount)
  4553. ha->login_retry_count = ql2xloginretrycount;
  4554. /* Enable ZIO. */
  4555. if (!vha->flags.init_done) {
  4556. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4557. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4558. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4559. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4560. }
  4561. icb->firmware_options_2 &= cpu_to_le32(
  4562. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4563. vha->flags.process_response_queue = 0;
  4564. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4565. ha->zio_mode = QLA_ZIO_MODE_6;
  4566. ql_log(ql_log_info, vha, 0x006f,
  4567. "ZIO mode %d enabled; timer delay (%d us).\n",
  4568. ha->zio_mode, ha->zio_timer * 100);
  4569. icb->firmware_options_2 |= cpu_to_le32(
  4570. (uint32_t)ha->zio_mode);
  4571. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4572. vha->flags.process_response_queue = 1;
  4573. }
  4574. if (rval) {
  4575. ql_log(ql_log_warn, vha, 0x0070,
  4576. "NVRAM configuration failed.\n");
  4577. }
  4578. return (rval);
  4579. }
  4580. static int
  4581. qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
  4582. uint32_t faddr)
  4583. {
  4584. int rval = QLA_SUCCESS;
  4585. int segments, fragment;
  4586. uint32_t *dcode, dlen;
  4587. uint32_t risc_addr;
  4588. uint32_t risc_size;
  4589. uint32_t i;
  4590. struct qla_hw_data *ha = vha->hw;
  4591. struct req_que *req = ha->req_q_map[0];
  4592. ql_dbg(ql_dbg_init, vha, 0x008b,
  4593. "FW: Loading firmware from flash (%x).\n", faddr);
  4594. rval = QLA_SUCCESS;
  4595. segments = FA_RISC_CODE_SEGMENTS;
  4596. dcode = (uint32_t *)req->ring;
  4597. *srisc_addr = 0;
  4598. /* Validate firmware image by checking version. */
  4599. qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
  4600. for (i = 0; i < 4; i++)
  4601. dcode[i] = be32_to_cpu(dcode[i]);
  4602. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4603. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4604. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4605. dcode[3] == 0)) {
  4606. ql_log(ql_log_fatal, vha, 0x008c,
  4607. "Unable to verify the integrity of flash firmware "
  4608. "image.\n");
  4609. ql_log(ql_log_fatal, vha, 0x008d,
  4610. "Firmware data: %08x %08x %08x %08x.\n",
  4611. dcode[0], dcode[1], dcode[2], dcode[3]);
  4612. return QLA_FUNCTION_FAILED;
  4613. }
  4614. while (segments && rval == QLA_SUCCESS) {
  4615. /* Read segment's load information. */
  4616. qla24xx_read_flash_data(vha, dcode, faddr, 4);
  4617. risc_addr = be32_to_cpu(dcode[2]);
  4618. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4619. risc_size = be32_to_cpu(dcode[3]);
  4620. fragment = 0;
  4621. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4622. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4623. if (dlen > risc_size)
  4624. dlen = risc_size;
  4625. ql_dbg(ql_dbg_init, vha, 0x008e,
  4626. "Loading risc segment@ risc addr %x "
  4627. "number of dwords 0x%x offset 0x%x.\n",
  4628. risc_addr, dlen, faddr);
  4629. qla24xx_read_flash_data(vha, dcode, faddr, dlen);
  4630. for (i = 0; i < dlen; i++)
  4631. dcode[i] = swab32(dcode[i]);
  4632. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4633. dlen);
  4634. if (rval) {
  4635. ql_log(ql_log_fatal, vha, 0x008f,
  4636. "Failed to load segment %d of firmware.\n",
  4637. fragment);
  4638. return QLA_FUNCTION_FAILED;
  4639. }
  4640. faddr += dlen;
  4641. risc_addr += dlen;
  4642. risc_size -= dlen;
  4643. fragment++;
  4644. }
  4645. /* Next segment. */
  4646. segments--;
  4647. }
  4648. if (!IS_QLA27XX(ha))
  4649. return rval;
  4650. if (ha->fw_dump_template)
  4651. vfree(ha->fw_dump_template);
  4652. ha->fw_dump_template = NULL;
  4653. ha->fw_dump_template_len = 0;
  4654. ql_dbg(ql_dbg_init, vha, 0x0161,
  4655. "Loading fwdump template from %x\n", faddr);
  4656. qla24xx_read_flash_data(vha, dcode, faddr, 7);
  4657. risc_size = be32_to_cpu(dcode[2]);
  4658. ql_dbg(ql_dbg_init, vha, 0x0162,
  4659. "-> array size %x dwords\n", risc_size);
  4660. if (risc_size == 0 || risc_size == ~0)
  4661. goto default_template;
  4662. dlen = (risc_size - 8) * sizeof(*dcode);
  4663. ql_dbg(ql_dbg_init, vha, 0x0163,
  4664. "-> template allocating %x bytes...\n", dlen);
  4665. ha->fw_dump_template = vmalloc(dlen);
  4666. if (!ha->fw_dump_template) {
  4667. ql_log(ql_log_warn, vha, 0x0164,
  4668. "Failed fwdump template allocate %x bytes.\n", risc_size);
  4669. goto default_template;
  4670. }
  4671. faddr += 7;
  4672. risc_size -= 8;
  4673. dcode = ha->fw_dump_template;
  4674. qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
  4675. for (i = 0; i < risc_size; i++)
  4676. dcode[i] = le32_to_cpu(dcode[i]);
  4677. if (!qla27xx_fwdt_template_valid(dcode)) {
  4678. ql_log(ql_log_warn, vha, 0x0165,
  4679. "Failed fwdump template validate\n");
  4680. goto default_template;
  4681. }
  4682. dlen = qla27xx_fwdt_template_size(dcode);
  4683. ql_dbg(ql_dbg_init, vha, 0x0166,
  4684. "-> template size %x bytes\n", dlen);
  4685. if (dlen > risc_size * sizeof(*dcode)) {
  4686. ql_log(ql_log_warn, vha, 0x0167,
  4687. "Failed fwdump template exceeds array by %x bytes\n",
  4688. (uint32_t)(dlen - risc_size * sizeof(*dcode)));
  4689. goto default_template;
  4690. }
  4691. ha->fw_dump_template_len = dlen;
  4692. return rval;
  4693. default_template:
  4694. ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
  4695. if (ha->fw_dump_template)
  4696. vfree(ha->fw_dump_template);
  4697. ha->fw_dump_template = NULL;
  4698. ha->fw_dump_template_len = 0;
  4699. dlen = qla27xx_fwdt_template_default_size();
  4700. ql_dbg(ql_dbg_init, vha, 0x0169,
  4701. "-> template allocating %x bytes...\n", dlen);
  4702. ha->fw_dump_template = vmalloc(dlen);
  4703. if (!ha->fw_dump_template) {
  4704. ql_log(ql_log_warn, vha, 0x016a,
  4705. "Failed fwdump template allocate %x bytes.\n", risc_size);
  4706. goto failed_template;
  4707. }
  4708. dcode = ha->fw_dump_template;
  4709. risc_size = dlen / sizeof(*dcode);
  4710. memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
  4711. for (i = 0; i < risc_size; i++)
  4712. dcode[i] = be32_to_cpu(dcode[i]);
  4713. if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
  4714. ql_log(ql_log_warn, vha, 0x016b,
  4715. "Failed fwdump template validate\n");
  4716. goto failed_template;
  4717. }
  4718. dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
  4719. ql_dbg(ql_dbg_init, vha, 0x016c,
  4720. "-> template size %x bytes\n", dlen);
  4721. ha->fw_dump_template_len = dlen;
  4722. return rval;
  4723. failed_template:
  4724. ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
  4725. if (ha->fw_dump_template)
  4726. vfree(ha->fw_dump_template);
  4727. ha->fw_dump_template = NULL;
  4728. ha->fw_dump_template_len = 0;
  4729. return rval;
  4730. }
  4731. #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
  4732. int
  4733. qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4734. {
  4735. int rval;
  4736. int i, fragment;
  4737. uint16_t *wcode, *fwcode;
  4738. uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
  4739. struct fw_blob *blob;
  4740. struct qla_hw_data *ha = vha->hw;
  4741. struct req_que *req = ha->req_q_map[0];
  4742. /* Load firmware blob. */
  4743. blob = qla2x00_request_firmware(vha);
  4744. if (!blob) {
  4745. ql_log(ql_log_info, vha, 0x0083,
  4746. "Firmware image unavailable.\n");
  4747. ql_log(ql_log_info, vha, 0x0084,
  4748. "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
  4749. return QLA_FUNCTION_FAILED;
  4750. }
  4751. rval = QLA_SUCCESS;
  4752. wcode = (uint16_t *)req->ring;
  4753. *srisc_addr = 0;
  4754. fwcode = (uint16_t *)blob->fw->data;
  4755. fwclen = 0;
  4756. /* Validate firmware image by checking version. */
  4757. if (blob->fw->size < 8 * sizeof(uint16_t)) {
  4758. ql_log(ql_log_fatal, vha, 0x0085,
  4759. "Unable to verify integrity of firmware image (%Zd).\n",
  4760. blob->fw->size);
  4761. goto fail_fw_integrity;
  4762. }
  4763. for (i = 0; i < 4; i++)
  4764. wcode[i] = be16_to_cpu(fwcode[i + 4]);
  4765. if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
  4766. wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
  4767. wcode[2] == 0 && wcode[3] == 0)) {
  4768. ql_log(ql_log_fatal, vha, 0x0086,
  4769. "Unable to verify integrity of firmware image.\n");
  4770. ql_log(ql_log_fatal, vha, 0x0087,
  4771. "Firmware data: %04x %04x %04x %04x.\n",
  4772. wcode[0], wcode[1], wcode[2], wcode[3]);
  4773. goto fail_fw_integrity;
  4774. }
  4775. seg = blob->segs;
  4776. while (*seg && rval == QLA_SUCCESS) {
  4777. risc_addr = *seg;
  4778. *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
  4779. risc_size = be16_to_cpu(fwcode[3]);
  4780. /* Validate firmware image size. */
  4781. fwclen += risc_size * sizeof(uint16_t);
  4782. if (blob->fw->size < fwclen) {
  4783. ql_log(ql_log_fatal, vha, 0x0088,
  4784. "Unable to verify integrity of firmware image "
  4785. "(%Zd).\n", blob->fw->size);
  4786. goto fail_fw_integrity;
  4787. }
  4788. fragment = 0;
  4789. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4790. wlen = (uint16_t)(ha->fw_transfer_size >> 1);
  4791. if (wlen > risc_size)
  4792. wlen = risc_size;
  4793. ql_dbg(ql_dbg_init, vha, 0x0089,
  4794. "Loading risc segment@ risc addr %x number of "
  4795. "words 0x%x.\n", risc_addr, wlen);
  4796. for (i = 0; i < wlen; i++)
  4797. wcode[i] = swab16(fwcode[i]);
  4798. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4799. wlen);
  4800. if (rval) {
  4801. ql_log(ql_log_fatal, vha, 0x008a,
  4802. "Failed to load segment %d of firmware.\n",
  4803. fragment);
  4804. break;
  4805. }
  4806. fwcode += wlen;
  4807. risc_addr += wlen;
  4808. risc_size -= wlen;
  4809. fragment++;
  4810. }
  4811. /* Next segment. */
  4812. seg++;
  4813. }
  4814. return rval;
  4815. fail_fw_integrity:
  4816. return QLA_FUNCTION_FAILED;
  4817. }
  4818. static int
  4819. qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4820. {
  4821. int rval;
  4822. int segments, fragment;
  4823. uint32_t *dcode, dlen;
  4824. uint32_t risc_addr;
  4825. uint32_t risc_size;
  4826. uint32_t i;
  4827. struct fw_blob *blob;
  4828. const uint32_t *fwcode;
  4829. uint32_t fwclen;
  4830. struct qla_hw_data *ha = vha->hw;
  4831. struct req_que *req = ha->req_q_map[0];
  4832. /* Load firmware blob. */
  4833. blob = qla2x00_request_firmware(vha);
  4834. if (!blob) {
  4835. ql_log(ql_log_warn, vha, 0x0090,
  4836. "Firmware image unavailable.\n");
  4837. ql_log(ql_log_warn, vha, 0x0091,
  4838. "Firmware images can be retrieved from: "
  4839. QLA_FW_URL ".\n");
  4840. return QLA_FUNCTION_FAILED;
  4841. }
  4842. ql_dbg(ql_dbg_init, vha, 0x0092,
  4843. "FW: Loading via request-firmware.\n");
  4844. rval = QLA_SUCCESS;
  4845. segments = FA_RISC_CODE_SEGMENTS;
  4846. dcode = (uint32_t *)req->ring;
  4847. *srisc_addr = 0;
  4848. fwcode = (uint32_t *)blob->fw->data;
  4849. fwclen = 0;
  4850. /* Validate firmware image by checking version. */
  4851. if (blob->fw->size < 8 * sizeof(uint32_t)) {
  4852. ql_log(ql_log_fatal, vha, 0x0093,
  4853. "Unable to verify integrity of firmware image (%Zd).\n",
  4854. blob->fw->size);
  4855. return QLA_FUNCTION_FAILED;
  4856. }
  4857. for (i = 0; i < 4; i++)
  4858. dcode[i] = be32_to_cpu(fwcode[i + 4]);
  4859. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4860. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4861. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4862. dcode[3] == 0)) {
  4863. ql_log(ql_log_fatal, vha, 0x0094,
  4864. "Unable to verify integrity of firmware image (%Zd).\n",
  4865. blob->fw->size);
  4866. ql_log(ql_log_fatal, vha, 0x0095,
  4867. "Firmware data: %08x %08x %08x %08x.\n",
  4868. dcode[0], dcode[1], dcode[2], dcode[3]);
  4869. return QLA_FUNCTION_FAILED;
  4870. }
  4871. while (segments && rval == QLA_SUCCESS) {
  4872. risc_addr = be32_to_cpu(fwcode[2]);
  4873. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4874. risc_size = be32_to_cpu(fwcode[3]);
  4875. /* Validate firmware image size. */
  4876. fwclen += risc_size * sizeof(uint32_t);
  4877. if (blob->fw->size < fwclen) {
  4878. ql_log(ql_log_fatal, vha, 0x0096,
  4879. "Unable to verify integrity of firmware image "
  4880. "(%Zd).\n", blob->fw->size);
  4881. return QLA_FUNCTION_FAILED;
  4882. }
  4883. fragment = 0;
  4884. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4885. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4886. if (dlen > risc_size)
  4887. dlen = risc_size;
  4888. ql_dbg(ql_dbg_init, vha, 0x0097,
  4889. "Loading risc segment@ risc addr %x "
  4890. "number of dwords 0x%x.\n", risc_addr, dlen);
  4891. for (i = 0; i < dlen; i++)
  4892. dcode[i] = swab32(fwcode[i]);
  4893. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4894. dlen);
  4895. if (rval) {
  4896. ql_log(ql_log_fatal, vha, 0x0098,
  4897. "Failed to load segment %d of firmware.\n",
  4898. fragment);
  4899. return QLA_FUNCTION_FAILED;
  4900. }
  4901. fwcode += dlen;
  4902. risc_addr += dlen;
  4903. risc_size -= dlen;
  4904. fragment++;
  4905. }
  4906. /* Next segment. */
  4907. segments--;
  4908. }
  4909. if (!IS_QLA27XX(ha))
  4910. return rval;
  4911. if (ha->fw_dump_template)
  4912. vfree(ha->fw_dump_template);
  4913. ha->fw_dump_template = NULL;
  4914. ha->fw_dump_template_len = 0;
  4915. ql_dbg(ql_dbg_init, vha, 0x171,
  4916. "Loading fwdump template from %x\n",
  4917. (uint32_t)((void *)fwcode - (void *)blob->fw->data));
  4918. risc_size = be32_to_cpu(fwcode[2]);
  4919. ql_dbg(ql_dbg_init, vha, 0x172,
  4920. "-> array size %x dwords\n", risc_size);
  4921. if (risc_size == 0 || risc_size == ~0)
  4922. goto default_template;
  4923. dlen = (risc_size - 8) * sizeof(*fwcode);
  4924. ql_dbg(ql_dbg_init, vha, 0x0173,
  4925. "-> template allocating %x bytes...\n", dlen);
  4926. ha->fw_dump_template = vmalloc(dlen);
  4927. if (!ha->fw_dump_template) {
  4928. ql_log(ql_log_warn, vha, 0x0174,
  4929. "Failed fwdump template allocate %x bytes.\n", risc_size);
  4930. goto default_template;
  4931. }
  4932. fwcode += 7;
  4933. risc_size -= 8;
  4934. dcode = ha->fw_dump_template;
  4935. for (i = 0; i < risc_size; i++)
  4936. dcode[i] = le32_to_cpu(fwcode[i]);
  4937. if (!qla27xx_fwdt_template_valid(dcode)) {
  4938. ql_log(ql_log_warn, vha, 0x0175,
  4939. "Failed fwdump template validate\n");
  4940. goto default_template;
  4941. }
  4942. dlen = qla27xx_fwdt_template_size(dcode);
  4943. ql_dbg(ql_dbg_init, vha, 0x0176,
  4944. "-> template size %x bytes\n", dlen);
  4945. if (dlen > risc_size * sizeof(*fwcode)) {
  4946. ql_log(ql_log_warn, vha, 0x0177,
  4947. "Failed fwdump template exceeds array by %x bytes\n",
  4948. (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
  4949. goto default_template;
  4950. }
  4951. ha->fw_dump_template_len = dlen;
  4952. return rval;
  4953. default_template:
  4954. ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
  4955. if (ha->fw_dump_template)
  4956. vfree(ha->fw_dump_template);
  4957. ha->fw_dump_template = NULL;
  4958. ha->fw_dump_template_len = 0;
  4959. dlen = qla27xx_fwdt_template_default_size();
  4960. ql_dbg(ql_dbg_init, vha, 0x0179,
  4961. "-> template allocating %x bytes...\n", dlen);
  4962. ha->fw_dump_template = vmalloc(dlen);
  4963. if (!ha->fw_dump_template) {
  4964. ql_log(ql_log_warn, vha, 0x017a,
  4965. "Failed fwdump template allocate %x bytes.\n", risc_size);
  4966. goto failed_template;
  4967. }
  4968. dcode = ha->fw_dump_template;
  4969. risc_size = dlen / sizeof(*fwcode);
  4970. fwcode = qla27xx_fwdt_template_default();
  4971. for (i = 0; i < risc_size; i++)
  4972. dcode[i] = be32_to_cpu(fwcode[i]);
  4973. if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
  4974. ql_log(ql_log_warn, vha, 0x017b,
  4975. "Failed fwdump template validate\n");
  4976. goto failed_template;
  4977. }
  4978. dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
  4979. ql_dbg(ql_dbg_init, vha, 0x017c,
  4980. "-> template size %x bytes\n", dlen);
  4981. ha->fw_dump_template_len = dlen;
  4982. return rval;
  4983. failed_template:
  4984. ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
  4985. if (ha->fw_dump_template)
  4986. vfree(ha->fw_dump_template);
  4987. ha->fw_dump_template = NULL;
  4988. ha->fw_dump_template_len = 0;
  4989. return rval;
  4990. }
  4991. int
  4992. qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4993. {
  4994. int rval;
  4995. if (ql2xfwloadbin == 1)
  4996. return qla81xx_load_risc(vha, srisc_addr);
  4997. /*
  4998. * FW Load priority:
  4999. * 1) Firmware via request-firmware interface (.bin file).
  5000. * 2) Firmware residing in flash.
  5001. */
  5002. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  5003. if (rval == QLA_SUCCESS)
  5004. return rval;
  5005. return qla24xx_load_risc_flash(vha, srisc_addr,
  5006. vha->hw->flt_region_fw);
  5007. }
  5008. int
  5009. qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  5010. {
  5011. int rval;
  5012. struct qla_hw_data *ha = vha->hw;
  5013. if (ql2xfwloadbin == 2)
  5014. goto try_blob_fw;
  5015. /*
  5016. * FW Load priority:
  5017. * 1) Firmware residing in flash.
  5018. * 2) Firmware via request-firmware interface (.bin file).
  5019. * 3) Golden-Firmware residing in flash -- limited operation.
  5020. */
  5021. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
  5022. if (rval == QLA_SUCCESS)
  5023. return rval;
  5024. try_blob_fw:
  5025. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  5026. if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
  5027. return rval;
  5028. ql_log(ql_log_info, vha, 0x0099,
  5029. "Attempting to fallback to golden firmware.\n");
  5030. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
  5031. if (rval != QLA_SUCCESS)
  5032. return rval;
  5033. ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
  5034. ha->flags.running_gold_fw = 1;
  5035. return rval;
  5036. }
  5037. void
  5038. qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
  5039. {
  5040. int ret, retries;
  5041. struct qla_hw_data *ha = vha->hw;
  5042. if (ha->flags.pci_channel_io_perm_failure)
  5043. return;
  5044. if (!IS_FWI2_CAPABLE(ha))
  5045. return;
  5046. if (!ha->fw_major_version)
  5047. return;
  5048. ret = qla2x00_stop_firmware(vha);
  5049. for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
  5050. ret != QLA_INVALID_COMMAND && retries ; retries--) {
  5051. ha->isp_ops->reset_chip(vha);
  5052. if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
  5053. continue;
  5054. if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
  5055. continue;
  5056. ql_log(ql_log_info, vha, 0x8015,
  5057. "Attempting retry of stop-firmware command.\n");
  5058. ret = qla2x00_stop_firmware(vha);
  5059. }
  5060. }
  5061. int
  5062. qla24xx_configure_vhba(scsi_qla_host_t *vha)
  5063. {
  5064. int rval = QLA_SUCCESS;
  5065. int rval2;
  5066. uint16_t mb[MAILBOX_REGISTER_COUNT];
  5067. struct qla_hw_data *ha = vha->hw;
  5068. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  5069. struct req_que *req;
  5070. struct rsp_que *rsp;
  5071. if (!vha->vp_idx)
  5072. return -EINVAL;
  5073. rval = qla2x00_fw_ready(base_vha);
  5074. if (ha->flags.cpu_affinity_enabled)
  5075. req = ha->req_q_map[0];
  5076. else
  5077. req = vha->req;
  5078. rsp = req->rsp;
  5079. if (rval == QLA_SUCCESS) {
  5080. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5081. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  5082. }
  5083. vha->flags.management_server_logged_in = 0;
  5084. /* Login to SNS first */
  5085. rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
  5086. BIT_1);
  5087. if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  5088. if (rval2 == QLA_MEMORY_ALLOC_FAILED)
  5089. ql_dbg(ql_dbg_init, vha, 0x0120,
  5090. "Failed SNS login: loop_id=%x, rval2=%d\n",
  5091. NPH_SNS, rval2);
  5092. else
  5093. ql_dbg(ql_dbg_init, vha, 0x0103,
  5094. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  5095. "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
  5096. NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
  5097. return (QLA_FUNCTION_FAILED);
  5098. }
  5099. atomic_set(&vha->loop_down_timer, 0);
  5100. atomic_set(&vha->loop_state, LOOP_UP);
  5101. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5102. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  5103. rval = qla2x00_loop_resync(base_vha);
  5104. return rval;
  5105. }
  5106. /* 84XX Support **************************************************************/
  5107. static LIST_HEAD(qla_cs84xx_list);
  5108. static DEFINE_MUTEX(qla_cs84xx_mutex);
  5109. static struct qla_chip_state_84xx *
  5110. qla84xx_get_chip(struct scsi_qla_host *vha)
  5111. {
  5112. struct qla_chip_state_84xx *cs84xx;
  5113. struct qla_hw_data *ha = vha->hw;
  5114. mutex_lock(&qla_cs84xx_mutex);
  5115. /* Find any shared 84xx chip. */
  5116. list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
  5117. if (cs84xx->bus == ha->pdev->bus) {
  5118. kref_get(&cs84xx->kref);
  5119. goto done;
  5120. }
  5121. }
  5122. cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
  5123. if (!cs84xx)
  5124. goto done;
  5125. kref_init(&cs84xx->kref);
  5126. spin_lock_init(&cs84xx->access_lock);
  5127. mutex_init(&cs84xx->fw_update_mutex);
  5128. cs84xx->bus = ha->pdev->bus;
  5129. list_add_tail(&cs84xx->list, &qla_cs84xx_list);
  5130. done:
  5131. mutex_unlock(&qla_cs84xx_mutex);
  5132. return cs84xx;
  5133. }
  5134. static void
  5135. __qla84xx_chip_release(struct kref *kref)
  5136. {
  5137. struct qla_chip_state_84xx *cs84xx =
  5138. container_of(kref, struct qla_chip_state_84xx, kref);
  5139. mutex_lock(&qla_cs84xx_mutex);
  5140. list_del(&cs84xx->list);
  5141. mutex_unlock(&qla_cs84xx_mutex);
  5142. kfree(cs84xx);
  5143. }
  5144. void
  5145. qla84xx_put_chip(struct scsi_qla_host *vha)
  5146. {
  5147. struct qla_hw_data *ha = vha->hw;
  5148. if (ha->cs84xx)
  5149. kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
  5150. }
  5151. static int
  5152. qla84xx_init_chip(scsi_qla_host_t *vha)
  5153. {
  5154. int rval;
  5155. uint16_t status[2];
  5156. struct qla_hw_data *ha = vha->hw;
  5157. mutex_lock(&ha->cs84xx->fw_update_mutex);
  5158. rval = qla84xx_verify_chip(vha, status);
  5159. mutex_unlock(&ha->cs84xx->fw_update_mutex);
  5160. return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
  5161. QLA_SUCCESS;
  5162. }
  5163. /* 81XX Support **************************************************************/
  5164. int
  5165. qla81xx_nvram_config(scsi_qla_host_t *vha)
  5166. {
  5167. int rval;
  5168. struct init_cb_81xx *icb;
  5169. struct nvram_81xx *nv;
  5170. uint32_t *dptr;
  5171. uint8_t *dptr1, *dptr2;
  5172. uint32_t chksum;
  5173. uint16_t cnt;
  5174. struct qla_hw_data *ha = vha->hw;
  5175. rval = QLA_SUCCESS;
  5176. icb = (struct init_cb_81xx *)ha->init_cb;
  5177. nv = ha->nvram;
  5178. /* Determine NVRAM starting address. */
  5179. ha->nvram_size = sizeof(struct nvram_81xx);
  5180. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  5181. if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
  5182. ha->vpd_size = FA_VPD_SIZE_82XX;
  5183. /* Get VPD data into cache */
  5184. ha->vpd = ha->nvram + VPD_OFFSET;
  5185. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  5186. ha->vpd_size);
  5187. /* Get NVRAM data into cache and calculate checksum. */
  5188. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  5189. ha->nvram_size);
  5190. dptr = (uint32_t *)nv;
  5191. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  5192. chksum += le32_to_cpu(*dptr++);
  5193. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
  5194. "Contents of NVRAM:\n");
  5195. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
  5196. (uint8_t *)nv, ha->nvram_size);
  5197. /* Bad NVRAM data, set defaults parameters. */
  5198. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  5199. || nv->id[3] != ' ' ||
  5200. nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
  5201. /* Reset NVRAM data. */
  5202. ql_log(ql_log_info, vha, 0x0073,
  5203. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  5204. "version=0x%x.\n", chksum, nv->id[0],
  5205. le16_to_cpu(nv->nvram_version));
  5206. ql_log(ql_log_info, vha, 0x0074,
  5207. "Falling back to functioning (yet invalid -- WWPN) "
  5208. "defaults.\n");
  5209. /*
  5210. * Set default initialization control block.
  5211. */
  5212. memset(nv, 0, ha->nvram_size);
  5213. nv->nvram_version = cpu_to_le16(ICB_VERSION);
  5214. nv->version = cpu_to_le16(ICB_VERSION);
  5215. nv->frame_payload_size = 2048;
  5216. nv->execution_throttle = cpu_to_le16(0xFFFF);
  5217. nv->exchange_count = cpu_to_le16(0);
  5218. nv->port_name[0] = 0x21;
  5219. nv->port_name[1] = 0x00 + ha->port_no + 1;
  5220. nv->port_name[2] = 0x00;
  5221. nv->port_name[3] = 0xe0;
  5222. nv->port_name[4] = 0x8b;
  5223. nv->port_name[5] = 0x1c;
  5224. nv->port_name[6] = 0x55;
  5225. nv->port_name[7] = 0x86;
  5226. nv->node_name[0] = 0x20;
  5227. nv->node_name[1] = 0x00;
  5228. nv->node_name[2] = 0x00;
  5229. nv->node_name[3] = 0xe0;
  5230. nv->node_name[4] = 0x8b;
  5231. nv->node_name[5] = 0x1c;
  5232. nv->node_name[6] = 0x55;
  5233. nv->node_name[7] = 0x86;
  5234. nv->login_retry_count = cpu_to_le16(8);
  5235. nv->interrupt_delay_timer = cpu_to_le16(0);
  5236. nv->login_timeout = cpu_to_le16(0);
  5237. nv->firmware_options_1 =
  5238. cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  5239. nv->firmware_options_2 = cpu_to_le32(2 << 4);
  5240. nv->firmware_options_2 |= cpu_to_le32(BIT_12);
  5241. nv->firmware_options_3 = cpu_to_le32(2 << 13);
  5242. nv->host_p = cpu_to_le32(BIT_11|BIT_10);
  5243. nv->efi_parameters = cpu_to_le32(0);
  5244. nv->reset_delay = 5;
  5245. nv->max_luns_per_target = cpu_to_le16(128);
  5246. nv->port_down_retry_count = cpu_to_le16(30);
  5247. nv->link_down_timeout = cpu_to_le16(180);
  5248. nv->enode_mac[0] = 0x00;
  5249. nv->enode_mac[1] = 0xC0;
  5250. nv->enode_mac[2] = 0xDD;
  5251. nv->enode_mac[3] = 0x04;
  5252. nv->enode_mac[4] = 0x05;
  5253. nv->enode_mac[5] = 0x06 + ha->port_no + 1;
  5254. rval = 1;
  5255. }
  5256. if (IS_T10_PI_CAPABLE(ha))
  5257. nv->frame_payload_size &= ~7;
  5258. qlt_81xx_config_nvram_stage1(vha, nv);
  5259. /* Reset Initialization control block */
  5260. memset(icb, 0, ha->init_cb_size);
  5261. /* Copy 1st segment. */
  5262. dptr1 = (uint8_t *)icb;
  5263. dptr2 = (uint8_t *)&nv->version;
  5264. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  5265. while (cnt--)
  5266. *dptr1++ = *dptr2++;
  5267. icb->login_retry_count = nv->login_retry_count;
  5268. /* Copy 2nd segment. */
  5269. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  5270. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  5271. cnt = (uint8_t *)&icb->reserved_5 -
  5272. (uint8_t *)&icb->interrupt_delay_timer;
  5273. while (cnt--)
  5274. *dptr1++ = *dptr2++;
  5275. memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
  5276. /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
  5277. if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
  5278. icb->enode_mac[0] = 0x00;
  5279. icb->enode_mac[1] = 0xC0;
  5280. icb->enode_mac[2] = 0xDD;
  5281. icb->enode_mac[3] = 0x04;
  5282. icb->enode_mac[4] = 0x05;
  5283. icb->enode_mac[5] = 0x06 + ha->port_no + 1;
  5284. }
  5285. /* Use extended-initialization control block. */
  5286. memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
  5287. /*
  5288. * Setup driver NVRAM options.
  5289. */
  5290. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  5291. "QLE8XXX");
  5292. qlt_81xx_config_nvram_stage2(vha, icb);
  5293. /* Use alternate WWN? */
  5294. if (nv->host_p & cpu_to_le32(BIT_15)) {
  5295. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  5296. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  5297. }
  5298. /* Prepare nodename */
  5299. if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
  5300. /*
  5301. * Firmware will apply the following mask if the nodename was
  5302. * not provided.
  5303. */
  5304. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  5305. icb->node_name[0] &= 0xF0;
  5306. }
  5307. /* Set host adapter parameters. */
  5308. ha->flags.disable_risc_code_load = 0;
  5309. ha->flags.enable_lip_reset = 0;
  5310. ha->flags.enable_lip_full_login =
  5311. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  5312. ha->flags.enable_target_reset =
  5313. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  5314. ha->flags.enable_led_scheme = 0;
  5315. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  5316. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  5317. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  5318. /* save HBA serial number */
  5319. ha->serial0 = icb->port_name[5];
  5320. ha->serial1 = icb->port_name[6];
  5321. ha->serial2 = icb->port_name[7];
  5322. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  5323. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  5324. icb->execution_throttle = cpu_to_le16(0xFFFF);
  5325. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  5326. /* Set minimum login_timeout to 4 seconds. */
  5327. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  5328. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  5329. if (le16_to_cpu(nv->login_timeout) < 4)
  5330. nv->login_timeout = cpu_to_le16(4);
  5331. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  5332. icb->login_timeout = nv->login_timeout;
  5333. /* Set minimum RATOV to 100 tenths of a second. */
  5334. ha->r_a_tov = 100;
  5335. ha->loop_reset_delay = nv->reset_delay;
  5336. /* Link Down Timeout = 0:
  5337. *
  5338. * When Port Down timer expires we will start returning
  5339. * I/O's to OS with "DID_NO_CONNECT".
  5340. *
  5341. * Link Down Timeout != 0:
  5342. *
  5343. * The driver waits for the link to come up after link down
  5344. * before returning I/Os to OS with "DID_NO_CONNECT".
  5345. */
  5346. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  5347. ha->loop_down_abort_time =
  5348. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  5349. } else {
  5350. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  5351. ha->loop_down_abort_time =
  5352. (LOOP_DOWN_TIME - ha->link_down_timeout);
  5353. }
  5354. /* Need enough time to try and get the port back. */
  5355. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  5356. if (qlport_down_retry)
  5357. ha->port_down_retry_count = qlport_down_retry;
  5358. /* Set login_retry_count */
  5359. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  5360. if (ha->port_down_retry_count ==
  5361. le16_to_cpu(nv->port_down_retry_count) &&
  5362. ha->port_down_retry_count > 3)
  5363. ha->login_retry_count = ha->port_down_retry_count;
  5364. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  5365. ha->login_retry_count = ha->port_down_retry_count;
  5366. if (ql2xloginretrycount)
  5367. ha->login_retry_count = ql2xloginretrycount;
  5368. /* if not running MSI-X we need handshaking on interrupts */
  5369. if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
  5370. icb->firmware_options_2 |= cpu_to_le32(BIT_22);
  5371. /* Enable ZIO. */
  5372. if (!vha->flags.init_done) {
  5373. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  5374. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  5375. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  5376. le16_to_cpu(icb->interrupt_delay_timer): 2;
  5377. }
  5378. icb->firmware_options_2 &= cpu_to_le32(
  5379. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  5380. vha->flags.process_response_queue = 0;
  5381. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  5382. ha->zio_mode = QLA_ZIO_MODE_6;
  5383. ql_log(ql_log_info, vha, 0x0075,
  5384. "ZIO mode %d enabled; timer delay (%d us).\n",
  5385. ha->zio_mode,
  5386. ha->zio_timer * 100);
  5387. icb->firmware_options_2 |= cpu_to_le32(
  5388. (uint32_t)ha->zio_mode);
  5389. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  5390. vha->flags.process_response_queue = 1;
  5391. }
  5392. if (rval) {
  5393. ql_log(ql_log_warn, vha, 0x0076,
  5394. "NVRAM configuration failed.\n");
  5395. }
  5396. return (rval);
  5397. }
  5398. int
  5399. qla82xx_restart_isp(scsi_qla_host_t *vha)
  5400. {
  5401. int status, rval;
  5402. struct qla_hw_data *ha = vha->hw;
  5403. struct req_que *req = ha->req_q_map[0];
  5404. struct rsp_que *rsp = ha->rsp_q_map[0];
  5405. struct scsi_qla_host *vp;
  5406. unsigned long flags;
  5407. status = qla2x00_init_rings(vha);
  5408. if (!status) {
  5409. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5410. ha->flags.chip_reset_done = 1;
  5411. status = qla2x00_fw_ready(vha);
  5412. if (!status) {
  5413. /* Issue a marker after FW becomes ready. */
  5414. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  5415. vha->flags.online = 1;
  5416. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5417. }
  5418. /* if no cable then assume it's good */
  5419. if ((vha->device_flags & DFLG_NO_CABLE))
  5420. status = 0;
  5421. }
  5422. if (!status) {
  5423. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5424. if (!atomic_read(&vha->loop_down_timer)) {
  5425. /*
  5426. * Issue marker command only when we are going
  5427. * to start the I/O .
  5428. */
  5429. vha->marker_needed = 1;
  5430. }
  5431. ha->isp_ops->enable_intrs(ha);
  5432. ha->isp_abort_cnt = 0;
  5433. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  5434. /* Update the firmware version */
  5435. status = qla82xx_check_md_needed(vha);
  5436. if (ha->fce) {
  5437. ha->flags.fce_enabled = 1;
  5438. memset(ha->fce, 0,
  5439. fce_calc_size(ha->fce_bufs));
  5440. rval = qla2x00_enable_fce_trace(vha,
  5441. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  5442. &ha->fce_bufs);
  5443. if (rval) {
  5444. ql_log(ql_log_warn, vha, 0x8001,
  5445. "Unable to reinitialize FCE (%d).\n",
  5446. rval);
  5447. ha->flags.fce_enabled = 0;
  5448. }
  5449. }
  5450. if (ha->eft) {
  5451. memset(ha->eft, 0, EFT_SIZE);
  5452. rval = qla2x00_enable_eft_trace(vha,
  5453. ha->eft_dma, EFT_NUM_BUFFERS);
  5454. if (rval) {
  5455. ql_log(ql_log_warn, vha, 0x8010,
  5456. "Unable to reinitialize EFT (%d).\n",
  5457. rval);
  5458. }
  5459. }
  5460. }
  5461. if (!status) {
  5462. ql_dbg(ql_dbg_taskm, vha, 0x8011,
  5463. "qla82xx_restart_isp succeeded.\n");
  5464. spin_lock_irqsave(&ha->vport_slock, flags);
  5465. list_for_each_entry(vp, &ha->vp_list, list) {
  5466. if (vp->vp_idx) {
  5467. atomic_inc(&vp->vref_count);
  5468. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5469. qla2x00_vp_abort_isp(vp);
  5470. spin_lock_irqsave(&ha->vport_slock, flags);
  5471. atomic_dec(&vp->vref_count);
  5472. }
  5473. }
  5474. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5475. } else {
  5476. ql_log(ql_log_warn, vha, 0x8016,
  5477. "qla82xx_restart_isp **** FAILED ****.\n");
  5478. }
  5479. return status;
  5480. }
  5481. void
  5482. qla81xx_update_fw_options(scsi_qla_host_t *vha)
  5483. {
  5484. struct qla_hw_data *ha = vha->hw;
  5485. if (!ql2xetsenable)
  5486. return;
  5487. /* Enable ETS Burst. */
  5488. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  5489. ha->fw_options[2] |= BIT_9;
  5490. qla2x00_set_fw_options(vha, ha->fw_options);
  5491. }
  5492. /*
  5493. * qla24xx_get_fcp_prio
  5494. * Gets the fcp cmd priority value for the logged in port.
  5495. * Looks for a match of the port descriptors within
  5496. * each of the fcp prio config entries. If a match is found,
  5497. * the tag (priority) value is returned.
  5498. *
  5499. * Input:
  5500. * vha = scsi host structure pointer.
  5501. * fcport = port structure pointer.
  5502. *
  5503. * Return:
  5504. * non-zero (if found)
  5505. * -1 (if not found)
  5506. *
  5507. * Context:
  5508. * Kernel context
  5509. */
  5510. static int
  5511. qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5512. {
  5513. int i, entries;
  5514. uint8_t pid_match, wwn_match;
  5515. int priority;
  5516. uint32_t pid1, pid2;
  5517. uint64_t wwn1, wwn2;
  5518. struct qla_fcp_prio_entry *pri_entry;
  5519. struct qla_hw_data *ha = vha->hw;
  5520. if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
  5521. return -1;
  5522. priority = -1;
  5523. entries = ha->fcp_prio_cfg->num_entries;
  5524. pri_entry = &ha->fcp_prio_cfg->entry[0];
  5525. for (i = 0; i < entries; i++) {
  5526. pid_match = wwn_match = 0;
  5527. if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
  5528. pri_entry++;
  5529. continue;
  5530. }
  5531. /* check source pid for a match */
  5532. if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
  5533. pid1 = pri_entry->src_pid & INVALID_PORT_ID;
  5534. pid2 = vha->d_id.b24 & INVALID_PORT_ID;
  5535. if (pid1 == INVALID_PORT_ID)
  5536. pid_match++;
  5537. else if (pid1 == pid2)
  5538. pid_match++;
  5539. }
  5540. /* check destination pid for a match */
  5541. if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
  5542. pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
  5543. pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
  5544. if (pid1 == INVALID_PORT_ID)
  5545. pid_match++;
  5546. else if (pid1 == pid2)
  5547. pid_match++;
  5548. }
  5549. /* check source WWN for a match */
  5550. if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
  5551. wwn1 = wwn_to_u64(vha->port_name);
  5552. wwn2 = wwn_to_u64(pri_entry->src_wwpn);
  5553. if (wwn2 == (uint64_t)-1)
  5554. wwn_match++;
  5555. else if (wwn1 == wwn2)
  5556. wwn_match++;
  5557. }
  5558. /* check destination WWN for a match */
  5559. if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
  5560. wwn1 = wwn_to_u64(fcport->port_name);
  5561. wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
  5562. if (wwn2 == (uint64_t)-1)
  5563. wwn_match++;
  5564. else if (wwn1 == wwn2)
  5565. wwn_match++;
  5566. }
  5567. if (pid_match == 2 || wwn_match == 2) {
  5568. /* Found a matching entry */
  5569. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  5570. priority = pri_entry->tag;
  5571. break;
  5572. }
  5573. pri_entry++;
  5574. }
  5575. return priority;
  5576. }
  5577. /*
  5578. * qla24xx_update_fcport_fcp_prio
  5579. * Activates fcp priority for the logged in fc port
  5580. *
  5581. * Input:
  5582. * vha = scsi host structure pointer.
  5583. * fcp = port structure pointer.
  5584. *
  5585. * Return:
  5586. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5587. *
  5588. * Context:
  5589. * Kernel context.
  5590. */
  5591. int
  5592. qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5593. {
  5594. int ret;
  5595. int priority;
  5596. uint16_t mb[5];
  5597. if (fcport->port_type != FCT_TARGET ||
  5598. fcport->loop_id == FC_NO_LOOP_ID)
  5599. return QLA_FUNCTION_FAILED;
  5600. priority = qla24xx_get_fcp_prio(vha, fcport);
  5601. if (priority < 0)
  5602. return QLA_FUNCTION_FAILED;
  5603. if (IS_P3P_TYPE(vha->hw)) {
  5604. fcport->fcp_prio = priority & 0xf;
  5605. return QLA_SUCCESS;
  5606. }
  5607. ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
  5608. if (ret == QLA_SUCCESS) {
  5609. if (fcport->fcp_prio != priority)
  5610. ql_dbg(ql_dbg_user, vha, 0x709e,
  5611. "Updated FCP_CMND priority - value=%d loop_id=%d "
  5612. "port_id=%02x%02x%02x.\n", priority,
  5613. fcport->loop_id, fcport->d_id.b.domain,
  5614. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  5615. fcport->fcp_prio = priority & 0xf;
  5616. } else
  5617. ql_dbg(ql_dbg_user, vha, 0x704f,
  5618. "Unable to update FCP_CMND priority - ret=0x%x for "
  5619. "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
  5620. fcport->d_id.b.domain, fcport->d_id.b.area,
  5621. fcport->d_id.b.al_pa);
  5622. return ret;
  5623. }
  5624. /*
  5625. * qla24xx_update_all_fcp_prio
  5626. * Activates fcp priority for all the logged in ports
  5627. *
  5628. * Input:
  5629. * ha = adapter block pointer.
  5630. *
  5631. * Return:
  5632. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5633. *
  5634. * Context:
  5635. * Kernel context.
  5636. */
  5637. int
  5638. qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
  5639. {
  5640. int ret;
  5641. fc_port_t *fcport;
  5642. ret = QLA_FUNCTION_FAILED;
  5643. /* We need to set priority for all logged in ports */
  5644. list_for_each_entry(fcport, &vha->vp_fcports, list)
  5645. ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
  5646. return ret;
  5647. }