qla_init.c 167 KB

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