qla_init.c 155 KB

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