qla_init.c 159 KB

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