qla_init.c 159 KB

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