qla_init.c 158 KB

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