qla_init.c 210 KB

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