qla_init.c 154 KB

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