qla_init.c 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094
  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->thermal_support = THERMAL_SUPPORT_I2C|THERMAL_SUPPORT_ISP;
  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_ring)
  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 *base_vha = pci_get_drvdata(ha->pdev);
  2883. rval = QLA_SUCCESS;
  2884. /* Try GID_PT to get device list, else GAN. */
  2885. if (!ha->swl)
  2886. ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
  2887. GFP_KERNEL);
  2888. swl = ha->swl;
  2889. if (!swl) {
  2890. /*EMPTY*/
  2891. ql_dbg(ql_dbg_disc, vha, 0x2054,
  2892. "GID_PT allocations failed, fallback on GA_NXT.\n");
  2893. } else {
  2894. memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
  2895. if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
  2896. swl = NULL;
  2897. } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
  2898. swl = NULL;
  2899. } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
  2900. swl = NULL;
  2901. } else if (ql2xiidmaenable &&
  2902. qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
  2903. qla2x00_gpsc(vha, swl);
  2904. }
  2905. /* If other queries succeeded probe for FC-4 type */
  2906. if (swl)
  2907. qla2x00_gff_id(vha, swl);
  2908. }
  2909. swl_idx = 0;
  2910. /* Allocate temporary fcport for any new fcports discovered. */
  2911. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2912. if (new_fcport == NULL) {
  2913. ql_log(ql_log_warn, vha, 0x205e,
  2914. "Failed to allocate memory for fcport.\n");
  2915. return (QLA_MEMORY_ALLOC_FAILED);
  2916. }
  2917. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  2918. /* Set start port ID scan at adapter ID. */
  2919. first_dev = 1;
  2920. last_dev = 0;
  2921. /* Starting free loop ID. */
  2922. loop_id = ha->min_external_loopid;
  2923. for (; loop_id <= ha->max_loop_id; loop_id++) {
  2924. if (qla2x00_is_reserved_id(vha, loop_id))
  2925. continue;
  2926. if (ha->current_topology == ISP_CFG_FL &&
  2927. (atomic_read(&vha->loop_down_timer) ||
  2928. LOOP_TRANSITION(vha))) {
  2929. atomic_set(&vha->loop_down_timer, 0);
  2930. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2931. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2932. break;
  2933. }
  2934. if (swl != NULL) {
  2935. if (last_dev) {
  2936. wrap.b24 = new_fcport->d_id.b24;
  2937. } else {
  2938. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  2939. memcpy(new_fcport->node_name,
  2940. swl[swl_idx].node_name, WWN_SIZE);
  2941. memcpy(new_fcport->port_name,
  2942. swl[swl_idx].port_name, WWN_SIZE);
  2943. memcpy(new_fcport->fabric_port_name,
  2944. swl[swl_idx].fabric_port_name, WWN_SIZE);
  2945. new_fcport->fp_speed = swl[swl_idx].fp_speed;
  2946. new_fcport->fc4_type = swl[swl_idx].fc4_type;
  2947. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  2948. last_dev = 1;
  2949. }
  2950. swl_idx++;
  2951. }
  2952. } else {
  2953. /* Send GA_NXT to the switch */
  2954. rval = qla2x00_ga_nxt(vha, new_fcport);
  2955. if (rval != QLA_SUCCESS) {
  2956. ql_log(ql_log_warn, vha, 0x2064,
  2957. "SNS scan failed -- assuming "
  2958. "zero-entry result.\n");
  2959. list_for_each_entry_safe(fcport, fcptemp,
  2960. new_fcports, list) {
  2961. list_del(&fcport->list);
  2962. kfree(fcport);
  2963. }
  2964. rval = QLA_SUCCESS;
  2965. break;
  2966. }
  2967. }
  2968. /* If wrap on switch device list, exit. */
  2969. if (first_dev) {
  2970. wrap.b24 = new_fcport->d_id.b24;
  2971. first_dev = 0;
  2972. } else if (new_fcport->d_id.b24 == wrap.b24) {
  2973. ql_dbg(ql_dbg_disc, vha, 0x2065,
  2974. "Device wrap (%02x%02x%02x).\n",
  2975. new_fcport->d_id.b.domain,
  2976. new_fcport->d_id.b.area,
  2977. new_fcport->d_id.b.al_pa);
  2978. break;
  2979. }
  2980. /* Bypass if same physical adapter. */
  2981. if (new_fcport->d_id.b24 == base_vha->d_id.b24)
  2982. continue;
  2983. /* Bypass virtual ports of the same host. */
  2984. if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
  2985. continue;
  2986. /* Bypass if same domain and area of adapter. */
  2987. if (((new_fcport->d_id.b24 & 0xffff00) ==
  2988. (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
  2989. ISP_CFG_FL)
  2990. continue;
  2991. /* Bypass reserved domain fields. */
  2992. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  2993. continue;
  2994. /* Bypass ports whose FCP-4 type is not FCP_SCSI */
  2995. if (ql2xgffidenable &&
  2996. (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
  2997. new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
  2998. continue;
  2999. /* Locate matching device in database. */
  3000. found = 0;
  3001. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3002. if (memcmp(new_fcport->port_name, fcport->port_name,
  3003. WWN_SIZE))
  3004. continue;
  3005. fcport->scan_state = QLA_FCPORT_FOUND;
  3006. found++;
  3007. /* Update port state. */
  3008. memcpy(fcport->fabric_port_name,
  3009. new_fcport->fabric_port_name, WWN_SIZE);
  3010. fcport->fp_speed = new_fcport->fp_speed;
  3011. /*
  3012. * If address the same and state FCS_ONLINE, nothing
  3013. * changed.
  3014. */
  3015. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  3016. atomic_read(&fcport->state) == FCS_ONLINE) {
  3017. break;
  3018. }
  3019. /*
  3020. * If device was not a fabric device before.
  3021. */
  3022. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  3023. fcport->d_id.b24 = new_fcport->d_id.b24;
  3024. qla2x00_clear_loop_id(fcport);
  3025. fcport->flags |= (FCF_FABRIC_DEVICE |
  3026. FCF_LOGIN_NEEDED);
  3027. break;
  3028. }
  3029. /*
  3030. * Port ID changed or device was marked to be updated;
  3031. * Log it out if still logged in and mark it for
  3032. * relogin later.
  3033. */
  3034. fcport->d_id.b24 = new_fcport->d_id.b24;
  3035. fcport->flags |= FCF_LOGIN_NEEDED;
  3036. if (fcport->loop_id != FC_NO_LOOP_ID &&
  3037. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  3038. (fcport->flags & FCF_ASYNC_SENT) == 0 &&
  3039. fcport->port_type != FCT_INITIATOR &&
  3040. fcport->port_type != FCT_BROADCAST) {
  3041. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3042. fcport->d_id.b.domain, fcport->d_id.b.area,
  3043. fcport->d_id.b.al_pa);
  3044. qla2x00_clear_loop_id(fcport);
  3045. }
  3046. break;
  3047. }
  3048. if (found)
  3049. continue;
  3050. /* If device was not in our fcports list, then add it. */
  3051. list_add_tail(&new_fcport->list, new_fcports);
  3052. /* Allocate a new replacement fcport. */
  3053. nxt_d_id.b24 = new_fcport->d_id.b24;
  3054. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  3055. if (new_fcport == NULL) {
  3056. ql_log(ql_log_warn, vha, 0x2066,
  3057. "Memory allocation failed for fcport.\n");
  3058. return (QLA_MEMORY_ALLOC_FAILED);
  3059. }
  3060. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  3061. new_fcport->d_id.b24 = nxt_d_id.b24;
  3062. }
  3063. kfree(new_fcport);
  3064. return (rval);
  3065. }
  3066. /*
  3067. * qla2x00_find_new_loop_id
  3068. * Scan through our port list and find a new usable loop ID.
  3069. *
  3070. * Input:
  3071. * ha: adapter state pointer.
  3072. * dev: port structure pointer.
  3073. *
  3074. * Returns:
  3075. * qla2x00 local function return status code.
  3076. *
  3077. * Context:
  3078. * Kernel context.
  3079. */
  3080. int
  3081. qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
  3082. {
  3083. int rval;
  3084. struct qla_hw_data *ha = vha->hw;
  3085. unsigned long flags = 0;
  3086. rval = QLA_SUCCESS;
  3087. spin_lock_irqsave(&ha->vport_slock, flags);
  3088. dev->loop_id = find_first_zero_bit(ha->loop_id_map,
  3089. LOOPID_MAP_SIZE);
  3090. if (dev->loop_id >= LOOPID_MAP_SIZE ||
  3091. qla2x00_is_reserved_id(vha, dev->loop_id)) {
  3092. dev->loop_id = FC_NO_LOOP_ID;
  3093. rval = QLA_FUNCTION_FAILED;
  3094. } else
  3095. set_bit(dev->loop_id, ha->loop_id_map);
  3096. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3097. if (rval == QLA_SUCCESS)
  3098. ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
  3099. "Assigning new loopid=%x, portid=%x.\n",
  3100. dev->loop_id, dev->d_id.b24);
  3101. else
  3102. ql_log(ql_log_warn, dev->vha, 0x2087,
  3103. "No loop_id's available, portid=%x.\n",
  3104. dev->d_id.b24);
  3105. return (rval);
  3106. }
  3107. /*
  3108. * qla2x00_fabric_dev_login
  3109. * Login fabric target device and update FC port database.
  3110. *
  3111. * Input:
  3112. * ha: adapter state pointer.
  3113. * fcport: port structure list pointer.
  3114. * next_loopid: contains value of a new loop ID that can be used
  3115. * by the next login attempt.
  3116. *
  3117. * Returns:
  3118. * qla2x00 local function return status code.
  3119. *
  3120. * Context:
  3121. * Kernel context.
  3122. */
  3123. static int
  3124. qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3125. uint16_t *next_loopid)
  3126. {
  3127. int rval;
  3128. int retry;
  3129. uint8_t opts;
  3130. struct qla_hw_data *ha = vha->hw;
  3131. rval = QLA_SUCCESS;
  3132. retry = 0;
  3133. if (IS_ALOGIO_CAPABLE(ha)) {
  3134. if (fcport->flags & FCF_ASYNC_SENT)
  3135. return rval;
  3136. fcport->flags |= FCF_ASYNC_SENT;
  3137. rval = qla2x00_post_async_login_work(vha, fcport, NULL);
  3138. if (!rval)
  3139. return rval;
  3140. }
  3141. fcport->flags &= ~FCF_ASYNC_SENT;
  3142. rval = qla2x00_fabric_login(vha, fcport, next_loopid);
  3143. if (rval == QLA_SUCCESS) {
  3144. /* Send an ADISC to FCP2 devices.*/
  3145. opts = 0;
  3146. if (fcport->flags & FCF_FCP2_DEVICE)
  3147. opts |= BIT_1;
  3148. rval = qla2x00_get_port_database(vha, fcport, opts);
  3149. if (rval != QLA_SUCCESS) {
  3150. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3151. fcport->d_id.b.domain, fcport->d_id.b.area,
  3152. fcport->d_id.b.al_pa);
  3153. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3154. } else {
  3155. qla2x00_update_fcport(vha, fcport);
  3156. }
  3157. } else {
  3158. /* Retry Login. */
  3159. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3160. }
  3161. return (rval);
  3162. }
  3163. /*
  3164. * qla2x00_fabric_login
  3165. * Issue fabric login command.
  3166. *
  3167. * Input:
  3168. * ha = adapter block pointer.
  3169. * device = pointer to FC device type structure.
  3170. *
  3171. * Returns:
  3172. * 0 - Login successfully
  3173. * 1 - Login failed
  3174. * 2 - Initiator device
  3175. * 3 - Fatal error
  3176. */
  3177. int
  3178. qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3179. uint16_t *next_loopid)
  3180. {
  3181. int rval;
  3182. int retry;
  3183. uint16_t tmp_loopid;
  3184. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3185. struct qla_hw_data *ha = vha->hw;
  3186. retry = 0;
  3187. tmp_loopid = 0;
  3188. for (;;) {
  3189. ql_dbg(ql_dbg_disc, vha, 0x2000,
  3190. "Trying Fabric Login w/loop id 0x%04x for port "
  3191. "%02x%02x%02x.\n",
  3192. fcport->loop_id, fcport->d_id.b.domain,
  3193. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3194. /* Login fcport on switch. */
  3195. rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
  3196. fcport->d_id.b.domain, fcport->d_id.b.area,
  3197. fcport->d_id.b.al_pa, mb, BIT_0);
  3198. if (rval != QLA_SUCCESS) {
  3199. return rval;
  3200. }
  3201. if (mb[0] == MBS_PORT_ID_USED) {
  3202. /*
  3203. * Device has another loop ID. The firmware team
  3204. * recommends the driver perform an implicit login with
  3205. * the specified ID again. The ID we just used is save
  3206. * here so we return with an ID that can be tried by
  3207. * the next login.
  3208. */
  3209. retry++;
  3210. tmp_loopid = fcport->loop_id;
  3211. fcport->loop_id = mb[1];
  3212. ql_dbg(ql_dbg_disc, vha, 0x2001,
  3213. "Fabric Login: port in use - next loop "
  3214. "id=0x%04x, port id= %02x%02x%02x.\n",
  3215. fcport->loop_id, fcport->d_id.b.domain,
  3216. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3217. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  3218. /*
  3219. * Login succeeded.
  3220. */
  3221. if (retry) {
  3222. /* A retry occurred before. */
  3223. *next_loopid = tmp_loopid;
  3224. } else {
  3225. /*
  3226. * No retry occurred before. Just increment the
  3227. * ID value for next login.
  3228. */
  3229. *next_loopid = (fcport->loop_id + 1);
  3230. }
  3231. if (mb[1] & BIT_0) {
  3232. fcport->port_type = FCT_INITIATOR;
  3233. } else {
  3234. fcport->port_type = FCT_TARGET;
  3235. if (mb[1] & BIT_1) {
  3236. fcport->flags |= FCF_FCP2_DEVICE;
  3237. }
  3238. }
  3239. if (mb[10] & BIT_0)
  3240. fcport->supported_classes |= FC_COS_CLASS2;
  3241. if (mb[10] & BIT_1)
  3242. fcport->supported_classes |= FC_COS_CLASS3;
  3243. if (IS_FWI2_CAPABLE(ha)) {
  3244. if (mb[10] & BIT_7)
  3245. fcport->flags |=
  3246. FCF_CONF_COMP_SUPPORTED;
  3247. }
  3248. rval = QLA_SUCCESS;
  3249. break;
  3250. } else if (mb[0] == MBS_LOOP_ID_USED) {
  3251. /*
  3252. * Loop ID already used, try next loop ID.
  3253. */
  3254. fcport->loop_id++;
  3255. rval = qla2x00_find_new_loop_id(vha, fcport);
  3256. if (rval != QLA_SUCCESS) {
  3257. /* Ran out of loop IDs to use */
  3258. break;
  3259. }
  3260. } else if (mb[0] == MBS_COMMAND_ERROR) {
  3261. /*
  3262. * Firmware possibly timed out during login. If NO
  3263. * retries are left to do then the device is declared
  3264. * dead.
  3265. */
  3266. *next_loopid = fcport->loop_id;
  3267. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3268. fcport->d_id.b.domain, fcport->d_id.b.area,
  3269. fcport->d_id.b.al_pa);
  3270. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3271. rval = 1;
  3272. break;
  3273. } else {
  3274. /*
  3275. * unrecoverable / not handled error
  3276. */
  3277. ql_dbg(ql_dbg_disc, vha, 0x2002,
  3278. "Failed=%x port_id=%02x%02x%02x loop_id=%x "
  3279. "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
  3280. fcport->d_id.b.area, fcport->d_id.b.al_pa,
  3281. fcport->loop_id, jiffies);
  3282. *next_loopid = fcport->loop_id;
  3283. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3284. fcport->d_id.b.domain, fcport->d_id.b.area,
  3285. fcport->d_id.b.al_pa);
  3286. qla2x00_clear_loop_id(fcport);
  3287. fcport->login_retry = 0;
  3288. rval = 3;
  3289. break;
  3290. }
  3291. }
  3292. return (rval);
  3293. }
  3294. /*
  3295. * qla2x00_local_device_login
  3296. * Issue local device login command.
  3297. *
  3298. * Input:
  3299. * ha = adapter block pointer.
  3300. * loop_id = loop id of device to login to.
  3301. *
  3302. * Returns (Where's the #define!!!!):
  3303. * 0 - Login successfully
  3304. * 1 - Login failed
  3305. * 3 - Fatal error
  3306. */
  3307. int
  3308. qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
  3309. {
  3310. int rval;
  3311. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3312. memset(mb, 0, sizeof(mb));
  3313. rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
  3314. if (rval == QLA_SUCCESS) {
  3315. /* Interrogate mailbox registers for any errors */
  3316. if (mb[0] == MBS_COMMAND_ERROR)
  3317. rval = 1;
  3318. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  3319. /* device not in PCB table */
  3320. rval = 3;
  3321. }
  3322. return (rval);
  3323. }
  3324. /*
  3325. * qla2x00_loop_resync
  3326. * Resync with fibre channel devices.
  3327. *
  3328. * Input:
  3329. * ha = adapter block pointer.
  3330. *
  3331. * Returns:
  3332. * 0 = success
  3333. */
  3334. int
  3335. qla2x00_loop_resync(scsi_qla_host_t *vha)
  3336. {
  3337. int rval = QLA_SUCCESS;
  3338. uint32_t wait_time;
  3339. struct req_que *req;
  3340. struct rsp_que *rsp;
  3341. if (vha->hw->flags.cpu_affinity_enabled)
  3342. req = vha->hw->req_q_map[0];
  3343. else
  3344. req = vha->req;
  3345. rsp = req->rsp;
  3346. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3347. if (vha->flags.online) {
  3348. if (!(rval = qla2x00_fw_ready(vha))) {
  3349. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3350. wait_time = 256;
  3351. do {
  3352. /* Issue a marker after FW becomes ready. */
  3353. qla2x00_marker(vha, req, rsp, 0, 0,
  3354. MK_SYNC_ALL);
  3355. vha->marker_needed = 0;
  3356. /* Remap devices on Loop. */
  3357. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3358. qla2x00_configure_loop(vha);
  3359. wait_time--;
  3360. } while (!atomic_read(&vha->loop_down_timer) &&
  3361. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3362. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3363. &vha->dpc_flags)));
  3364. }
  3365. }
  3366. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3367. return (QLA_FUNCTION_FAILED);
  3368. if (rval)
  3369. ql_dbg(ql_dbg_disc, vha, 0x206c,
  3370. "%s *** FAILED ***.\n", __func__);
  3371. return (rval);
  3372. }
  3373. /*
  3374. * qla2x00_perform_loop_resync
  3375. * Description: This function will set the appropriate flags and call
  3376. * qla2x00_loop_resync. If successful loop will be resynced
  3377. * Arguments : scsi_qla_host_t pointer
  3378. * returm : Success or Failure
  3379. */
  3380. int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
  3381. {
  3382. int32_t rval = 0;
  3383. if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
  3384. /*Configure the flags so that resync happens properly*/
  3385. atomic_set(&ha->loop_down_timer, 0);
  3386. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  3387. atomic_set(&ha->loop_state, LOOP_UP);
  3388. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  3389. set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
  3390. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  3391. rval = qla2x00_loop_resync(ha);
  3392. } else
  3393. atomic_set(&ha->loop_state, LOOP_DEAD);
  3394. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  3395. }
  3396. return rval;
  3397. }
  3398. void
  3399. qla2x00_update_fcports(scsi_qla_host_t *base_vha)
  3400. {
  3401. fc_port_t *fcport;
  3402. struct scsi_qla_host *vha;
  3403. struct qla_hw_data *ha = base_vha->hw;
  3404. unsigned long flags;
  3405. spin_lock_irqsave(&ha->vport_slock, flags);
  3406. /* Go with deferred removal of rport references. */
  3407. list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
  3408. atomic_inc(&vha->vref_count);
  3409. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3410. if (fcport->drport &&
  3411. atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
  3412. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3413. qla2x00_rport_del(fcport);
  3414. spin_lock_irqsave(&ha->vport_slock, flags);
  3415. }
  3416. }
  3417. atomic_dec(&vha->vref_count);
  3418. }
  3419. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3420. }
  3421. /* Assumes idc_lock always held on entry */
  3422. void
  3423. qla83xx_reset_ownership(scsi_qla_host_t *vha)
  3424. {
  3425. struct qla_hw_data *ha = vha->hw;
  3426. uint32_t drv_presence, drv_presence_mask;
  3427. uint32_t dev_part_info1, dev_part_info2, class_type;
  3428. uint32_t class_type_mask = 0x3;
  3429. uint16_t fcoe_other_function = 0xffff, i;
  3430. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3431. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
  3432. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
  3433. for (i = 0; i < 8; i++) {
  3434. class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
  3435. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3436. (i != ha->portnum)) {
  3437. fcoe_other_function = i;
  3438. break;
  3439. }
  3440. }
  3441. if (fcoe_other_function == 0xffff) {
  3442. for (i = 0; i < 8; i++) {
  3443. class_type = ((dev_part_info2 >> (i * 4)) &
  3444. class_type_mask);
  3445. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3446. ((i + 8) != ha->portnum)) {
  3447. fcoe_other_function = i + 8;
  3448. break;
  3449. }
  3450. }
  3451. }
  3452. /*
  3453. * Prepare drv-presence mask based on fcoe functions present.
  3454. * However consider only valid physical fcoe function numbers (0-15).
  3455. */
  3456. drv_presence_mask = ~((1 << (ha->portnum)) |
  3457. ((fcoe_other_function == 0xffff) ?
  3458. 0 : (1 << (fcoe_other_function))));
  3459. /* We are the reset owner iff:
  3460. * - No other protocol drivers present.
  3461. * - This is the lowest among fcoe functions. */
  3462. if (!(drv_presence & drv_presence_mask) &&
  3463. (ha->portnum < fcoe_other_function)) {
  3464. ql_dbg(ql_dbg_p3p, vha, 0xb07f,
  3465. "This host is Reset owner.\n");
  3466. ha->flags.nic_core_reset_owner = 1;
  3467. }
  3468. }
  3469. static int
  3470. __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
  3471. {
  3472. int rval = QLA_SUCCESS;
  3473. struct qla_hw_data *ha = vha->hw;
  3474. uint32_t drv_ack;
  3475. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3476. if (rval == QLA_SUCCESS) {
  3477. drv_ack |= (1 << ha->portnum);
  3478. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3479. }
  3480. return rval;
  3481. }
  3482. static int
  3483. __qla83xx_clear_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 const char *
  3496. qla83xx_dev_state_to_string(uint32_t dev_state)
  3497. {
  3498. switch (dev_state) {
  3499. case QLA8XXX_DEV_COLD:
  3500. return "COLD/RE-INIT";
  3501. case QLA8XXX_DEV_INITIALIZING:
  3502. return "INITIALIZING";
  3503. case QLA8XXX_DEV_READY:
  3504. return "READY";
  3505. case QLA8XXX_DEV_NEED_RESET:
  3506. return "NEED RESET";
  3507. case QLA8XXX_DEV_NEED_QUIESCENT:
  3508. return "NEED QUIESCENT";
  3509. case QLA8XXX_DEV_FAILED:
  3510. return "FAILED";
  3511. case QLA8XXX_DEV_QUIESCENT:
  3512. return "QUIESCENT";
  3513. default:
  3514. return "Unknown";
  3515. }
  3516. }
  3517. /* Assumes idc-lock always held on entry */
  3518. void
  3519. qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
  3520. {
  3521. struct qla_hw_data *ha = vha->hw;
  3522. uint32_t idc_audit_reg = 0, duration_secs = 0;
  3523. switch (audit_type) {
  3524. case IDC_AUDIT_TIMESTAMP:
  3525. ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
  3526. idc_audit_reg = (ha->portnum) |
  3527. (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
  3528. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3529. break;
  3530. case IDC_AUDIT_COMPLETION:
  3531. duration_secs = ((jiffies_to_msecs(jiffies) -
  3532. jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
  3533. idc_audit_reg = (ha->portnum) |
  3534. (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
  3535. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3536. break;
  3537. default:
  3538. ql_log(ql_log_warn, vha, 0xb078,
  3539. "Invalid audit type specified.\n");
  3540. break;
  3541. }
  3542. }
  3543. /* Assumes idc_lock always held on entry */
  3544. static int
  3545. qla83xx_initiating_reset(scsi_qla_host_t *vha)
  3546. {
  3547. struct qla_hw_data *ha = vha->hw;
  3548. uint32_t idc_control, dev_state;
  3549. __qla83xx_get_idc_control(vha, &idc_control);
  3550. if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
  3551. ql_log(ql_log_info, vha, 0xb080,
  3552. "NIC Core reset has been disabled. idc-control=0x%x\n",
  3553. idc_control);
  3554. return QLA_FUNCTION_FAILED;
  3555. }
  3556. /* Set NEED-RESET iff in READY state and we are the reset-owner */
  3557. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3558. if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
  3559. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  3560. QLA8XXX_DEV_NEED_RESET);
  3561. ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
  3562. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  3563. } else {
  3564. const char *state = qla83xx_dev_state_to_string(dev_state);
  3565. ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
  3566. /* SV: XXX: Is timeout required here? */
  3567. /* Wait for IDC state change READY -> NEED_RESET */
  3568. while (dev_state == QLA8XXX_DEV_READY) {
  3569. qla83xx_idc_unlock(vha, 0);
  3570. msleep(200);
  3571. qla83xx_idc_lock(vha, 0);
  3572. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3573. }
  3574. }
  3575. /* Send IDC ack by writing to drv-ack register */
  3576. __qla83xx_set_drv_ack(vha);
  3577. return QLA_SUCCESS;
  3578. }
  3579. int
  3580. __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
  3581. {
  3582. return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3583. }
  3584. int
  3585. __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
  3586. {
  3587. return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3588. }
  3589. static int
  3590. qla83xx_check_driver_presence(scsi_qla_host_t *vha)
  3591. {
  3592. uint32_t drv_presence = 0;
  3593. struct qla_hw_data *ha = vha->hw;
  3594. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3595. if (drv_presence & (1 << ha->portnum))
  3596. return QLA_SUCCESS;
  3597. else
  3598. return QLA_TEST_FAILED;
  3599. }
  3600. int
  3601. qla83xx_nic_core_reset(scsi_qla_host_t *vha)
  3602. {
  3603. int rval = QLA_SUCCESS;
  3604. struct qla_hw_data *ha = vha->hw;
  3605. ql_dbg(ql_dbg_p3p, vha, 0xb058,
  3606. "Entered %s().\n", __func__);
  3607. if (vha->device_flags & DFLG_DEV_FAILED) {
  3608. ql_log(ql_log_warn, vha, 0xb059,
  3609. "Device in unrecoverable FAILED state.\n");
  3610. return QLA_FUNCTION_FAILED;
  3611. }
  3612. qla83xx_idc_lock(vha, 0);
  3613. if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
  3614. ql_log(ql_log_warn, vha, 0xb05a,
  3615. "Function=0x%x has been removed from IDC participation.\n",
  3616. ha->portnum);
  3617. rval = QLA_FUNCTION_FAILED;
  3618. goto exit;
  3619. }
  3620. qla83xx_reset_ownership(vha);
  3621. rval = qla83xx_initiating_reset(vha);
  3622. /*
  3623. * Perform reset if we are the reset-owner,
  3624. * else wait till IDC state changes to READY/FAILED.
  3625. */
  3626. if (rval == QLA_SUCCESS) {
  3627. rval = qla83xx_idc_state_handler(vha);
  3628. if (rval == QLA_SUCCESS)
  3629. ha->flags.nic_core_hung = 0;
  3630. __qla83xx_clear_drv_ack(vha);
  3631. }
  3632. exit:
  3633. qla83xx_idc_unlock(vha, 0);
  3634. ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
  3635. return rval;
  3636. }
  3637. int
  3638. qla2xxx_mctp_dump(scsi_qla_host_t *vha)
  3639. {
  3640. struct qla_hw_data *ha = vha->hw;
  3641. int rval = QLA_FUNCTION_FAILED;
  3642. if (!IS_MCTP_CAPABLE(ha)) {
  3643. /* This message can be removed from the final version */
  3644. ql_log(ql_log_info, vha, 0x506d,
  3645. "This board is not MCTP capable\n");
  3646. return rval;
  3647. }
  3648. if (!ha->mctp_dump) {
  3649. ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
  3650. MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
  3651. if (!ha->mctp_dump) {
  3652. ql_log(ql_log_warn, vha, 0x506e,
  3653. "Failed to allocate memory for mctp dump\n");
  3654. return rval;
  3655. }
  3656. }
  3657. #define MCTP_DUMP_STR_ADDR 0x00000000
  3658. rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
  3659. MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
  3660. if (rval != QLA_SUCCESS) {
  3661. ql_log(ql_log_warn, vha, 0x506f,
  3662. "Failed to capture mctp dump\n");
  3663. } else {
  3664. ql_log(ql_log_info, vha, 0x5070,
  3665. "Mctp dump capture for host (%ld/%p).\n",
  3666. vha->host_no, ha->mctp_dump);
  3667. ha->mctp_dumped = 1;
  3668. }
  3669. if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
  3670. ha->flags.nic_core_reset_hdlr_active = 1;
  3671. rval = qla83xx_restart_nic_firmware(vha);
  3672. if (rval)
  3673. /* NIC Core reset failed. */
  3674. ql_log(ql_log_warn, vha, 0x5071,
  3675. "Failed to restart nic firmware\n");
  3676. else
  3677. ql_dbg(ql_dbg_p3p, vha, 0xb084,
  3678. "Restarted NIC firmware successfully.\n");
  3679. ha->flags.nic_core_reset_hdlr_active = 0;
  3680. }
  3681. return rval;
  3682. }
  3683. /*
  3684. * qla2x00_quiesce_io
  3685. * Description: This function will block the new I/Os
  3686. * Its not aborting any I/Os as context
  3687. * is not destroyed during quiescence
  3688. * Arguments: scsi_qla_host_t
  3689. * return : void
  3690. */
  3691. void
  3692. qla2x00_quiesce_io(scsi_qla_host_t *vha)
  3693. {
  3694. struct qla_hw_data *ha = vha->hw;
  3695. struct scsi_qla_host *vp;
  3696. ql_dbg(ql_dbg_dpc, vha, 0x401d,
  3697. "Quiescing I/O - ha=%p.\n", ha);
  3698. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  3699. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3700. atomic_set(&vha->loop_state, LOOP_DOWN);
  3701. qla2x00_mark_all_devices_lost(vha, 0);
  3702. list_for_each_entry(vp, &ha->vp_list, list)
  3703. qla2x00_mark_all_devices_lost(vp, 0);
  3704. } else {
  3705. if (!atomic_read(&vha->loop_down_timer))
  3706. atomic_set(&vha->loop_down_timer,
  3707. LOOP_DOWN_TIME);
  3708. }
  3709. /* Wait for pending cmds to complete */
  3710. qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
  3711. }
  3712. void
  3713. qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
  3714. {
  3715. struct qla_hw_data *ha = vha->hw;
  3716. struct scsi_qla_host *vp;
  3717. unsigned long flags;
  3718. fc_port_t *fcport;
  3719. /* For ISP82XX, driver waits for completion of the commands.
  3720. * online flag should be set.
  3721. */
  3722. if (!IS_QLA82XX(ha))
  3723. vha->flags.online = 0;
  3724. ha->flags.chip_reset_done = 0;
  3725. clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  3726. vha->qla_stats.total_isp_aborts++;
  3727. ql_log(ql_log_info, vha, 0x00af,
  3728. "Performing ISP error recovery - ha=%p.\n", ha);
  3729. /* For ISP82XX, reset_chip is just disabling interrupts.
  3730. * Driver waits for the completion of the commands.
  3731. * the interrupts need to be enabled.
  3732. */
  3733. if (!IS_QLA82XX(ha))
  3734. ha->isp_ops->reset_chip(vha);
  3735. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  3736. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3737. atomic_set(&vha->loop_state, LOOP_DOWN);
  3738. qla2x00_mark_all_devices_lost(vha, 0);
  3739. spin_lock_irqsave(&ha->vport_slock, flags);
  3740. list_for_each_entry(vp, &ha->vp_list, list) {
  3741. atomic_inc(&vp->vref_count);
  3742. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3743. qla2x00_mark_all_devices_lost(vp, 0);
  3744. spin_lock_irqsave(&ha->vport_slock, flags);
  3745. atomic_dec(&vp->vref_count);
  3746. }
  3747. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3748. } else {
  3749. if (!atomic_read(&vha->loop_down_timer))
  3750. atomic_set(&vha->loop_down_timer,
  3751. LOOP_DOWN_TIME);
  3752. }
  3753. /* Clear all async request states across all VPs. */
  3754. list_for_each_entry(fcport, &vha->vp_fcports, list)
  3755. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  3756. spin_lock_irqsave(&ha->vport_slock, flags);
  3757. list_for_each_entry(vp, &ha->vp_list, list) {
  3758. atomic_inc(&vp->vref_count);
  3759. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3760. list_for_each_entry(fcport, &vp->vp_fcports, list)
  3761. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  3762. spin_lock_irqsave(&ha->vport_slock, flags);
  3763. atomic_dec(&vp->vref_count);
  3764. }
  3765. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3766. if (!ha->flags.eeh_busy) {
  3767. /* Make sure for ISP 82XX IO DMA is complete */
  3768. if (IS_QLA82XX(ha)) {
  3769. qla82xx_chip_reset_cleanup(vha);
  3770. ql_log(ql_log_info, vha, 0x00b4,
  3771. "Done chip reset cleanup.\n");
  3772. /* Done waiting for pending commands.
  3773. * Reset the online flag.
  3774. */
  3775. vha->flags.online = 0;
  3776. }
  3777. /* Requeue all commands in outstanding command list. */
  3778. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  3779. }
  3780. }
  3781. /*
  3782. * qla2x00_abort_isp
  3783. * Resets ISP and aborts all outstanding commands.
  3784. *
  3785. * Input:
  3786. * ha = adapter block pointer.
  3787. *
  3788. * Returns:
  3789. * 0 = success
  3790. */
  3791. int
  3792. qla2x00_abort_isp(scsi_qla_host_t *vha)
  3793. {
  3794. int rval;
  3795. uint8_t status = 0;
  3796. struct qla_hw_data *ha = vha->hw;
  3797. struct scsi_qla_host *vp;
  3798. struct req_que *req = ha->req_q_map[0];
  3799. unsigned long flags;
  3800. if (vha->flags.online) {
  3801. qla2x00_abort_isp_cleanup(vha);
  3802. if (IS_QLA8031(ha)) {
  3803. ql_dbg(ql_dbg_p3p, vha, 0xb05c,
  3804. "Clearing fcoe driver presence.\n");
  3805. if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
  3806. ql_dbg(ql_dbg_p3p, vha, 0xb073,
  3807. "Error while clearing DRV-Presence.\n");
  3808. }
  3809. if (unlikely(pci_channel_offline(ha->pdev) &&
  3810. ha->flags.pci_channel_io_perm_failure)) {
  3811. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3812. status = 0;
  3813. return status;
  3814. }
  3815. ha->isp_ops->get_flash_version(vha, req->ring);
  3816. ha->isp_ops->nvram_config(vha);
  3817. if (!qla2x00_restart_isp(vha)) {
  3818. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3819. if (!atomic_read(&vha->loop_down_timer)) {
  3820. /*
  3821. * Issue marker command only when we are going
  3822. * to start the I/O .
  3823. */
  3824. vha->marker_needed = 1;
  3825. }
  3826. vha->flags.online = 1;
  3827. ha->isp_ops->enable_intrs(ha);
  3828. ha->isp_abort_cnt = 0;
  3829. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3830. if (IS_QLA81XX(ha) || IS_QLA8031(ha))
  3831. qla2x00_get_fw_version(vha);
  3832. if (ha->fce) {
  3833. ha->flags.fce_enabled = 1;
  3834. memset(ha->fce, 0,
  3835. fce_calc_size(ha->fce_bufs));
  3836. rval = qla2x00_enable_fce_trace(vha,
  3837. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  3838. &ha->fce_bufs);
  3839. if (rval) {
  3840. ql_log(ql_log_warn, vha, 0x8033,
  3841. "Unable to reinitialize FCE "
  3842. "(%d).\n", rval);
  3843. ha->flags.fce_enabled = 0;
  3844. }
  3845. }
  3846. if (ha->eft) {
  3847. memset(ha->eft, 0, EFT_SIZE);
  3848. rval = qla2x00_enable_eft_trace(vha,
  3849. ha->eft_dma, EFT_NUM_BUFFERS);
  3850. if (rval) {
  3851. ql_log(ql_log_warn, vha, 0x8034,
  3852. "Unable to reinitialize EFT "
  3853. "(%d).\n", rval);
  3854. }
  3855. }
  3856. } else { /* failed the ISP abort */
  3857. vha->flags.online = 1;
  3858. if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  3859. if (ha->isp_abort_cnt == 0) {
  3860. ql_log(ql_log_fatal, vha, 0x8035,
  3861. "ISP error recover failed - "
  3862. "board disabled.\n");
  3863. /*
  3864. * The next call disables the board
  3865. * completely.
  3866. */
  3867. ha->isp_ops->reset_adapter(vha);
  3868. vha->flags.online = 0;
  3869. clear_bit(ISP_ABORT_RETRY,
  3870. &vha->dpc_flags);
  3871. status = 0;
  3872. } else { /* schedule another ISP abort */
  3873. ha->isp_abort_cnt--;
  3874. ql_dbg(ql_dbg_taskm, vha, 0x8020,
  3875. "ISP abort - retry remaining %d.\n",
  3876. ha->isp_abort_cnt);
  3877. status = 1;
  3878. }
  3879. } else {
  3880. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  3881. ql_dbg(ql_dbg_taskm, vha, 0x8021,
  3882. "ISP error recovery - retrying (%d) "
  3883. "more times.\n", ha->isp_abort_cnt);
  3884. set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3885. status = 1;
  3886. }
  3887. }
  3888. }
  3889. if (!status) {
  3890. ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
  3891. spin_lock_irqsave(&ha->vport_slock, flags);
  3892. list_for_each_entry(vp, &ha->vp_list, list) {
  3893. if (vp->vp_idx) {
  3894. atomic_inc(&vp->vref_count);
  3895. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3896. qla2x00_vp_abort_isp(vp);
  3897. spin_lock_irqsave(&ha->vport_slock, flags);
  3898. atomic_dec(&vp->vref_count);
  3899. }
  3900. }
  3901. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3902. if (IS_QLA8031(ha)) {
  3903. ql_dbg(ql_dbg_p3p, vha, 0xb05d,
  3904. "Setting back fcoe driver presence.\n");
  3905. if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
  3906. ql_dbg(ql_dbg_p3p, vha, 0xb074,
  3907. "Error while setting DRV-Presence.\n");
  3908. }
  3909. } else {
  3910. ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
  3911. __func__);
  3912. }
  3913. return(status);
  3914. }
  3915. /*
  3916. * qla2x00_restart_isp
  3917. * restarts the ISP after a reset
  3918. *
  3919. * Input:
  3920. * ha = adapter block pointer.
  3921. *
  3922. * Returns:
  3923. * 0 = success
  3924. */
  3925. static int
  3926. qla2x00_restart_isp(scsi_qla_host_t *vha)
  3927. {
  3928. int status = 0;
  3929. uint32_t wait_time;
  3930. struct qla_hw_data *ha = vha->hw;
  3931. struct req_que *req = ha->req_q_map[0];
  3932. struct rsp_que *rsp = ha->rsp_q_map[0];
  3933. unsigned long flags;
  3934. /* If firmware needs to be loaded */
  3935. if (qla2x00_isp_firmware(vha)) {
  3936. vha->flags.online = 0;
  3937. status = ha->isp_ops->chip_diag(vha);
  3938. if (!status)
  3939. status = qla2x00_setup_chip(vha);
  3940. }
  3941. if (!status && !(status = qla2x00_init_rings(vha))) {
  3942. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3943. ha->flags.chip_reset_done = 1;
  3944. /* Initialize the queues in use */
  3945. qla25xx_init_queues(ha);
  3946. status = qla2x00_fw_ready(vha);
  3947. if (!status) {
  3948. ql_dbg(ql_dbg_taskm, vha, 0x8031,
  3949. "Start configure loop status = %d.\n", status);
  3950. /* Issue a marker after FW becomes ready. */
  3951. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  3952. vha->flags.online = 1;
  3953. /*
  3954. * Process any ATIO queue entries that came in
  3955. * while we weren't online.
  3956. */
  3957. spin_lock_irqsave(&ha->hardware_lock, flags);
  3958. if (qla_tgt_mode_enabled(vha))
  3959. qlt_24xx_process_atio_queue(vha);
  3960. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3961. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3962. wait_time = 256;
  3963. do {
  3964. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3965. qla2x00_configure_loop(vha);
  3966. wait_time--;
  3967. } while (!atomic_read(&vha->loop_down_timer) &&
  3968. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3969. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3970. &vha->dpc_flags)));
  3971. }
  3972. /* if no cable then assume it's good */
  3973. if ((vha->device_flags & DFLG_NO_CABLE))
  3974. status = 0;
  3975. ql_dbg(ql_dbg_taskm, vha, 0x8032,
  3976. "Configure loop done, status = 0x%x.\n", status);
  3977. }
  3978. return (status);
  3979. }
  3980. static int
  3981. qla25xx_init_queues(struct qla_hw_data *ha)
  3982. {
  3983. struct rsp_que *rsp = NULL;
  3984. struct req_que *req = NULL;
  3985. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  3986. int ret = -1;
  3987. int i;
  3988. for (i = 1; i < ha->max_rsp_queues; i++) {
  3989. rsp = ha->rsp_q_map[i];
  3990. if (rsp) {
  3991. rsp->options &= ~BIT_0;
  3992. ret = qla25xx_init_rsp_que(base_vha, rsp);
  3993. if (ret != QLA_SUCCESS)
  3994. ql_dbg(ql_dbg_init, base_vha, 0x00ff,
  3995. "%s Rsp que: %d init failed.\n",
  3996. __func__, rsp->id);
  3997. else
  3998. ql_dbg(ql_dbg_init, base_vha, 0x0100,
  3999. "%s Rsp que: %d inited.\n",
  4000. __func__, rsp->id);
  4001. }
  4002. }
  4003. for (i = 1; i < ha->max_req_queues; i++) {
  4004. req = ha->req_q_map[i];
  4005. if (req) {
  4006. /* Clear outstanding commands array. */
  4007. req->options &= ~BIT_0;
  4008. ret = qla25xx_init_req_que(base_vha, req);
  4009. if (ret != QLA_SUCCESS)
  4010. ql_dbg(ql_dbg_init, base_vha, 0x0101,
  4011. "%s Req que: %d init failed.\n",
  4012. __func__, req->id);
  4013. else
  4014. ql_dbg(ql_dbg_init, base_vha, 0x0102,
  4015. "%s Req que: %d inited.\n",
  4016. __func__, req->id);
  4017. }
  4018. }
  4019. return ret;
  4020. }
  4021. /*
  4022. * qla2x00_reset_adapter
  4023. * Reset adapter.
  4024. *
  4025. * Input:
  4026. * ha = adapter block pointer.
  4027. */
  4028. void
  4029. qla2x00_reset_adapter(scsi_qla_host_t *vha)
  4030. {
  4031. unsigned long flags = 0;
  4032. struct qla_hw_data *ha = vha->hw;
  4033. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4034. vha->flags.online = 0;
  4035. ha->isp_ops->disable_intrs(ha);
  4036. spin_lock_irqsave(&ha->hardware_lock, flags);
  4037. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  4038. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4039. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  4040. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4041. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4042. }
  4043. void
  4044. qla24xx_reset_adapter(scsi_qla_host_t *vha)
  4045. {
  4046. unsigned long flags = 0;
  4047. struct qla_hw_data *ha = vha->hw;
  4048. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  4049. if (IS_QLA82XX(ha))
  4050. return;
  4051. vha->flags.online = 0;
  4052. ha->isp_ops->disable_intrs(ha);
  4053. spin_lock_irqsave(&ha->hardware_lock, flags);
  4054. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  4055. RD_REG_DWORD(&reg->hccr);
  4056. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  4057. RD_REG_DWORD(&reg->hccr);
  4058. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4059. if (IS_NOPOLLING_TYPE(ha))
  4060. ha->isp_ops->enable_intrs(ha);
  4061. }
  4062. /* On sparc systems, obtain port and node WWN from firmware
  4063. * properties.
  4064. */
  4065. static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
  4066. struct nvram_24xx *nv)
  4067. {
  4068. #ifdef CONFIG_SPARC
  4069. struct qla_hw_data *ha = vha->hw;
  4070. struct pci_dev *pdev = ha->pdev;
  4071. struct device_node *dp = pci_device_to_OF_node(pdev);
  4072. const u8 *val;
  4073. int len;
  4074. val = of_get_property(dp, "port-wwn", &len);
  4075. if (val && len >= WWN_SIZE)
  4076. memcpy(nv->port_name, val, WWN_SIZE);
  4077. val = of_get_property(dp, "node-wwn", &len);
  4078. if (val && len >= WWN_SIZE)
  4079. memcpy(nv->node_name, val, WWN_SIZE);
  4080. #endif
  4081. }
  4082. int
  4083. qla24xx_nvram_config(scsi_qla_host_t *vha)
  4084. {
  4085. int rval;
  4086. struct init_cb_24xx *icb;
  4087. struct nvram_24xx *nv;
  4088. uint32_t *dptr;
  4089. uint8_t *dptr1, *dptr2;
  4090. uint32_t chksum;
  4091. uint16_t cnt;
  4092. struct qla_hw_data *ha = vha->hw;
  4093. rval = QLA_SUCCESS;
  4094. icb = (struct init_cb_24xx *)ha->init_cb;
  4095. nv = ha->nvram;
  4096. /* Determine NVRAM starting address. */
  4097. if (ha->flags.port0) {
  4098. ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
  4099. ha->vpd_base = FA_NVRAM_VPD0_ADDR;
  4100. } else {
  4101. ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
  4102. ha->vpd_base = FA_NVRAM_VPD1_ADDR;
  4103. }
  4104. ha->nvram_size = sizeof(struct nvram_24xx);
  4105. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4106. if (IS_QLA82XX(ha))
  4107. ha->vpd_size = FA_VPD_SIZE_82XX;
  4108. /* Get VPD data into cache */
  4109. ha->vpd = ha->nvram + VPD_OFFSET;
  4110. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
  4111. ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
  4112. /* Get NVRAM data into cache and calculate checksum. */
  4113. dptr = (uint32_t *)nv;
  4114. ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
  4115. ha->nvram_size);
  4116. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  4117. chksum += le32_to_cpu(*dptr++);
  4118. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
  4119. "Contents of NVRAM\n");
  4120. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
  4121. (uint8_t *)nv, ha->nvram_size);
  4122. /* Bad NVRAM data, set defaults parameters. */
  4123. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4124. || nv->id[3] != ' ' ||
  4125. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  4126. /* Reset NVRAM data. */
  4127. ql_log(ql_log_warn, vha, 0x006b,
  4128. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  4129. "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
  4130. ql_log(ql_log_warn, vha, 0x006c,
  4131. "Falling back to functioning (yet invalid -- WWPN) "
  4132. "defaults.\n");
  4133. /*
  4134. * Set default initialization control block.
  4135. */
  4136. memset(nv, 0, ha->nvram_size);
  4137. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  4138. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  4139. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  4140. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4141. nv->exchange_count = __constant_cpu_to_le16(0);
  4142. nv->hard_address = __constant_cpu_to_le16(124);
  4143. nv->port_name[0] = 0x21;
  4144. nv->port_name[1] = 0x00 + ha->port_no;
  4145. nv->port_name[2] = 0x00;
  4146. nv->port_name[3] = 0xe0;
  4147. nv->port_name[4] = 0x8b;
  4148. nv->port_name[5] = 0x1c;
  4149. nv->port_name[6] = 0x55;
  4150. nv->port_name[7] = 0x86;
  4151. nv->node_name[0] = 0x20;
  4152. nv->node_name[1] = 0x00;
  4153. nv->node_name[2] = 0x00;
  4154. nv->node_name[3] = 0xe0;
  4155. nv->node_name[4] = 0x8b;
  4156. nv->node_name[5] = 0x1c;
  4157. nv->node_name[6] = 0x55;
  4158. nv->node_name[7] = 0x86;
  4159. qla24xx_nvram_wwn_from_ofw(vha, nv);
  4160. nv->login_retry_count = __constant_cpu_to_le16(8);
  4161. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  4162. nv->login_timeout = __constant_cpu_to_le16(0);
  4163. nv->firmware_options_1 =
  4164. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4165. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  4166. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  4167. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  4168. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  4169. nv->efi_parameters = __constant_cpu_to_le32(0);
  4170. nv->reset_delay = 5;
  4171. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  4172. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  4173. nv->link_down_timeout = __constant_cpu_to_le16(30);
  4174. rval = 1;
  4175. }
  4176. if (!qla_ini_mode_enabled(vha)) {
  4177. /* Don't enable full login after initial LIP */
  4178. nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
  4179. /* Don't enable LIP full login for initiator */
  4180. nv->host_p &= __constant_cpu_to_le32(~BIT_10);
  4181. }
  4182. qlt_24xx_config_nvram_stage1(vha, nv);
  4183. /* Reset Initialization control block */
  4184. memset(icb, 0, ha->init_cb_size);
  4185. /* Copy 1st segment. */
  4186. dptr1 = (uint8_t *)icb;
  4187. dptr2 = (uint8_t *)&nv->version;
  4188. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4189. while (cnt--)
  4190. *dptr1++ = *dptr2++;
  4191. icb->login_retry_count = nv->login_retry_count;
  4192. icb->link_down_on_nos = nv->link_down_on_nos;
  4193. /* Copy 2nd segment. */
  4194. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4195. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4196. cnt = (uint8_t *)&icb->reserved_3 -
  4197. (uint8_t *)&icb->interrupt_delay_timer;
  4198. while (cnt--)
  4199. *dptr1++ = *dptr2++;
  4200. /*
  4201. * Setup driver NVRAM options.
  4202. */
  4203. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4204. "QLA2462");
  4205. qlt_24xx_config_nvram_stage2(vha, icb);
  4206. if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
  4207. /* Use alternate WWN? */
  4208. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4209. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4210. }
  4211. /* Prepare nodename */
  4212. if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
  4213. /*
  4214. * Firmware will apply the following mask if the nodename was
  4215. * not provided.
  4216. */
  4217. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4218. icb->node_name[0] &= 0xF0;
  4219. }
  4220. /* Set host adapter parameters. */
  4221. ha->flags.disable_risc_code_load = 0;
  4222. ha->flags.enable_lip_reset = 0;
  4223. ha->flags.enable_lip_full_login =
  4224. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4225. ha->flags.enable_target_reset =
  4226. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4227. ha->flags.enable_led_scheme = 0;
  4228. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4229. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4230. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4231. memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
  4232. sizeof(ha->fw_seriallink_options24));
  4233. /* save HBA serial number */
  4234. ha->serial0 = icb->port_name[5];
  4235. ha->serial1 = icb->port_name[6];
  4236. ha->serial2 = icb->port_name[7];
  4237. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4238. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4239. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4240. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4241. /* Set minimum login_timeout to 4 seconds. */
  4242. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4243. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4244. if (le16_to_cpu(nv->login_timeout) < 4)
  4245. nv->login_timeout = __constant_cpu_to_le16(4);
  4246. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4247. icb->login_timeout = nv->login_timeout;
  4248. /* Set minimum RATOV to 100 tenths of a second. */
  4249. ha->r_a_tov = 100;
  4250. ha->loop_reset_delay = nv->reset_delay;
  4251. /* Link Down Timeout = 0:
  4252. *
  4253. * When Port Down timer expires we will start returning
  4254. * I/O's to OS with "DID_NO_CONNECT".
  4255. *
  4256. * Link Down Timeout != 0:
  4257. *
  4258. * The driver waits for the link to come up after link down
  4259. * before returning I/Os to OS with "DID_NO_CONNECT".
  4260. */
  4261. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4262. ha->loop_down_abort_time =
  4263. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4264. } else {
  4265. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4266. ha->loop_down_abort_time =
  4267. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4268. }
  4269. /* Need enough time to try and get the port back. */
  4270. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4271. if (qlport_down_retry)
  4272. ha->port_down_retry_count = qlport_down_retry;
  4273. /* Set login_retry_count */
  4274. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4275. if (ha->port_down_retry_count ==
  4276. le16_to_cpu(nv->port_down_retry_count) &&
  4277. ha->port_down_retry_count > 3)
  4278. ha->login_retry_count = ha->port_down_retry_count;
  4279. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4280. ha->login_retry_count = ha->port_down_retry_count;
  4281. if (ql2xloginretrycount)
  4282. ha->login_retry_count = ql2xloginretrycount;
  4283. /* Enable ZIO. */
  4284. if (!vha->flags.init_done) {
  4285. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4286. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4287. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4288. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4289. }
  4290. icb->firmware_options_2 &= __constant_cpu_to_le32(
  4291. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4292. vha->flags.process_response_queue = 0;
  4293. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4294. ha->zio_mode = QLA_ZIO_MODE_6;
  4295. ql_log(ql_log_info, vha, 0x006f,
  4296. "ZIO mode %d enabled; timer delay (%d us).\n",
  4297. ha->zio_mode, ha->zio_timer * 100);
  4298. icb->firmware_options_2 |= cpu_to_le32(
  4299. (uint32_t)ha->zio_mode);
  4300. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4301. vha->flags.process_response_queue = 1;
  4302. }
  4303. if (rval) {
  4304. ql_log(ql_log_warn, vha, 0x0070,
  4305. "NVRAM configuration failed.\n");
  4306. }
  4307. return (rval);
  4308. }
  4309. static int
  4310. qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
  4311. uint32_t faddr)
  4312. {
  4313. int rval = QLA_SUCCESS;
  4314. int segments, fragment;
  4315. uint32_t *dcode, dlen;
  4316. uint32_t risc_addr;
  4317. uint32_t risc_size;
  4318. uint32_t i;
  4319. struct qla_hw_data *ha = vha->hw;
  4320. struct req_que *req = ha->req_q_map[0];
  4321. ql_dbg(ql_dbg_init, vha, 0x008b,
  4322. "FW: Loading firmware from flash (%x).\n", faddr);
  4323. rval = QLA_SUCCESS;
  4324. segments = FA_RISC_CODE_SEGMENTS;
  4325. dcode = (uint32_t *)req->ring;
  4326. *srisc_addr = 0;
  4327. /* Validate firmware image by checking version. */
  4328. qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
  4329. for (i = 0; i < 4; i++)
  4330. dcode[i] = be32_to_cpu(dcode[i]);
  4331. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4332. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4333. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4334. dcode[3] == 0)) {
  4335. ql_log(ql_log_fatal, vha, 0x008c,
  4336. "Unable to verify the integrity of flash firmware "
  4337. "image.\n");
  4338. ql_log(ql_log_fatal, vha, 0x008d,
  4339. "Firmware data: %08x %08x %08x %08x.\n",
  4340. dcode[0], dcode[1], dcode[2], dcode[3]);
  4341. return QLA_FUNCTION_FAILED;
  4342. }
  4343. while (segments && rval == QLA_SUCCESS) {
  4344. /* Read segment's load information. */
  4345. qla24xx_read_flash_data(vha, dcode, faddr, 4);
  4346. risc_addr = be32_to_cpu(dcode[2]);
  4347. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4348. risc_size = be32_to_cpu(dcode[3]);
  4349. fragment = 0;
  4350. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4351. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4352. if (dlen > risc_size)
  4353. dlen = risc_size;
  4354. ql_dbg(ql_dbg_init, vha, 0x008e,
  4355. "Loading risc segment@ risc addr %x "
  4356. "number of dwords 0x%x offset 0x%x.\n",
  4357. risc_addr, dlen, faddr);
  4358. qla24xx_read_flash_data(vha, dcode, faddr, dlen);
  4359. for (i = 0; i < dlen; i++)
  4360. dcode[i] = swab32(dcode[i]);
  4361. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4362. dlen);
  4363. if (rval) {
  4364. ql_log(ql_log_fatal, vha, 0x008f,
  4365. "Failed to load segment %d of firmware.\n",
  4366. fragment);
  4367. break;
  4368. }
  4369. faddr += dlen;
  4370. risc_addr += dlen;
  4371. risc_size -= dlen;
  4372. fragment++;
  4373. }
  4374. /* Next segment. */
  4375. segments--;
  4376. }
  4377. return rval;
  4378. }
  4379. #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
  4380. int
  4381. qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4382. {
  4383. int rval;
  4384. int i, fragment;
  4385. uint16_t *wcode, *fwcode;
  4386. uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
  4387. struct fw_blob *blob;
  4388. struct qla_hw_data *ha = vha->hw;
  4389. struct req_que *req = ha->req_q_map[0];
  4390. /* Load firmware blob. */
  4391. blob = qla2x00_request_firmware(vha);
  4392. if (!blob) {
  4393. ql_log(ql_log_info, vha, 0x0083,
  4394. "Fimware image unavailable.\n");
  4395. ql_log(ql_log_info, vha, 0x0084,
  4396. "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
  4397. return QLA_FUNCTION_FAILED;
  4398. }
  4399. rval = QLA_SUCCESS;
  4400. wcode = (uint16_t *)req->ring;
  4401. *srisc_addr = 0;
  4402. fwcode = (uint16_t *)blob->fw->data;
  4403. fwclen = 0;
  4404. /* Validate firmware image by checking version. */
  4405. if (blob->fw->size < 8 * sizeof(uint16_t)) {
  4406. ql_log(ql_log_fatal, vha, 0x0085,
  4407. "Unable to verify integrity of firmware image (%Zd).\n",
  4408. blob->fw->size);
  4409. goto fail_fw_integrity;
  4410. }
  4411. for (i = 0; i < 4; i++)
  4412. wcode[i] = be16_to_cpu(fwcode[i + 4]);
  4413. if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
  4414. wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
  4415. wcode[2] == 0 && wcode[3] == 0)) {
  4416. ql_log(ql_log_fatal, vha, 0x0086,
  4417. "Unable to verify integrity of firmware image.\n");
  4418. ql_log(ql_log_fatal, vha, 0x0087,
  4419. "Firmware data: %04x %04x %04x %04x.\n",
  4420. wcode[0], wcode[1], wcode[2], wcode[3]);
  4421. goto fail_fw_integrity;
  4422. }
  4423. seg = blob->segs;
  4424. while (*seg && rval == QLA_SUCCESS) {
  4425. risc_addr = *seg;
  4426. *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
  4427. risc_size = be16_to_cpu(fwcode[3]);
  4428. /* Validate firmware image size. */
  4429. fwclen += risc_size * sizeof(uint16_t);
  4430. if (blob->fw->size < fwclen) {
  4431. ql_log(ql_log_fatal, vha, 0x0088,
  4432. "Unable to verify integrity of firmware image "
  4433. "(%Zd).\n", blob->fw->size);
  4434. goto fail_fw_integrity;
  4435. }
  4436. fragment = 0;
  4437. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4438. wlen = (uint16_t)(ha->fw_transfer_size >> 1);
  4439. if (wlen > risc_size)
  4440. wlen = risc_size;
  4441. ql_dbg(ql_dbg_init, vha, 0x0089,
  4442. "Loading risc segment@ risc addr %x number of "
  4443. "words 0x%x.\n", risc_addr, wlen);
  4444. for (i = 0; i < wlen; i++)
  4445. wcode[i] = swab16(fwcode[i]);
  4446. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4447. wlen);
  4448. if (rval) {
  4449. ql_log(ql_log_fatal, vha, 0x008a,
  4450. "Failed to load segment %d of firmware.\n",
  4451. fragment);
  4452. break;
  4453. }
  4454. fwcode += wlen;
  4455. risc_addr += wlen;
  4456. risc_size -= wlen;
  4457. fragment++;
  4458. }
  4459. /* Next segment. */
  4460. seg++;
  4461. }
  4462. return rval;
  4463. fail_fw_integrity:
  4464. return QLA_FUNCTION_FAILED;
  4465. }
  4466. static int
  4467. qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4468. {
  4469. int rval;
  4470. int segments, fragment;
  4471. uint32_t *dcode, dlen;
  4472. uint32_t risc_addr;
  4473. uint32_t risc_size;
  4474. uint32_t i;
  4475. struct fw_blob *blob;
  4476. uint32_t *fwcode, fwclen;
  4477. struct qla_hw_data *ha = vha->hw;
  4478. struct req_que *req = ha->req_q_map[0];
  4479. /* Load firmware blob. */
  4480. blob = qla2x00_request_firmware(vha);
  4481. if (!blob) {
  4482. ql_log(ql_log_warn, vha, 0x0090,
  4483. "Fimware image unavailable.\n");
  4484. ql_log(ql_log_warn, vha, 0x0091,
  4485. "Firmware images can be retrieved from: "
  4486. QLA_FW_URL ".\n");
  4487. return QLA_FUNCTION_FAILED;
  4488. }
  4489. ql_dbg(ql_dbg_init, vha, 0x0092,
  4490. "FW: Loading via request-firmware.\n");
  4491. rval = QLA_SUCCESS;
  4492. segments = FA_RISC_CODE_SEGMENTS;
  4493. dcode = (uint32_t *)req->ring;
  4494. *srisc_addr = 0;
  4495. fwcode = (uint32_t *)blob->fw->data;
  4496. fwclen = 0;
  4497. /* Validate firmware image by checking version. */
  4498. if (blob->fw->size < 8 * sizeof(uint32_t)) {
  4499. ql_log(ql_log_fatal, vha, 0x0093,
  4500. "Unable to verify integrity of firmware image (%Zd).\n",
  4501. blob->fw->size);
  4502. goto fail_fw_integrity;
  4503. }
  4504. for (i = 0; i < 4; i++)
  4505. dcode[i] = be32_to_cpu(fwcode[i + 4]);
  4506. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4507. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4508. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4509. dcode[3] == 0)) {
  4510. ql_log(ql_log_fatal, vha, 0x0094,
  4511. "Unable to verify integrity of firmware image (%Zd).\n",
  4512. blob->fw->size);
  4513. ql_log(ql_log_fatal, vha, 0x0095,
  4514. "Firmware data: %08x %08x %08x %08x.\n",
  4515. dcode[0], dcode[1], dcode[2], dcode[3]);
  4516. goto fail_fw_integrity;
  4517. }
  4518. while (segments && rval == QLA_SUCCESS) {
  4519. risc_addr = be32_to_cpu(fwcode[2]);
  4520. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4521. risc_size = be32_to_cpu(fwcode[3]);
  4522. /* Validate firmware image size. */
  4523. fwclen += risc_size * sizeof(uint32_t);
  4524. if (blob->fw->size < fwclen) {
  4525. ql_log(ql_log_fatal, vha, 0x0096,
  4526. "Unable to verify integrity of firmware image "
  4527. "(%Zd).\n", blob->fw->size);
  4528. goto fail_fw_integrity;
  4529. }
  4530. fragment = 0;
  4531. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4532. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4533. if (dlen > risc_size)
  4534. dlen = risc_size;
  4535. ql_dbg(ql_dbg_init, vha, 0x0097,
  4536. "Loading risc segment@ risc addr %x "
  4537. "number of dwords 0x%x.\n", risc_addr, dlen);
  4538. for (i = 0; i < dlen; i++)
  4539. dcode[i] = swab32(fwcode[i]);
  4540. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4541. dlen);
  4542. if (rval) {
  4543. ql_log(ql_log_fatal, vha, 0x0098,
  4544. "Failed to load segment %d of firmware.\n",
  4545. fragment);
  4546. break;
  4547. }
  4548. fwcode += dlen;
  4549. risc_addr += dlen;
  4550. risc_size -= dlen;
  4551. fragment++;
  4552. }
  4553. /* Next segment. */
  4554. segments--;
  4555. }
  4556. return rval;
  4557. fail_fw_integrity:
  4558. return QLA_FUNCTION_FAILED;
  4559. }
  4560. int
  4561. qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4562. {
  4563. int rval;
  4564. if (ql2xfwloadbin == 1)
  4565. return qla81xx_load_risc(vha, srisc_addr);
  4566. /*
  4567. * FW Load priority:
  4568. * 1) Firmware via request-firmware interface (.bin file).
  4569. * 2) Firmware residing in flash.
  4570. */
  4571. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  4572. if (rval == QLA_SUCCESS)
  4573. return rval;
  4574. return qla24xx_load_risc_flash(vha, srisc_addr,
  4575. vha->hw->flt_region_fw);
  4576. }
  4577. int
  4578. qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4579. {
  4580. int rval;
  4581. struct qla_hw_data *ha = vha->hw;
  4582. if (ql2xfwloadbin == 2)
  4583. goto try_blob_fw;
  4584. /*
  4585. * FW Load priority:
  4586. * 1) Firmware residing in flash.
  4587. * 2) Firmware via request-firmware interface (.bin file).
  4588. * 3) Golden-Firmware residing in flash -- limited operation.
  4589. */
  4590. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
  4591. if (rval == QLA_SUCCESS)
  4592. return rval;
  4593. try_blob_fw:
  4594. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  4595. if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
  4596. return rval;
  4597. ql_log(ql_log_info, vha, 0x0099,
  4598. "Attempting to fallback to golden firmware.\n");
  4599. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
  4600. if (rval != QLA_SUCCESS)
  4601. return rval;
  4602. ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
  4603. ha->flags.running_gold_fw = 1;
  4604. return rval;
  4605. }
  4606. void
  4607. qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
  4608. {
  4609. int ret, retries;
  4610. struct qla_hw_data *ha = vha->hw;
  4611. if (ha->flags.pci_channel_io_perm_failure)
  4612. return;
  4613. if (!IS_FWI2_CAPABLE(ha))
  4614. return;
  4615. if (!ha->fw_major_version)
  4616. return;
  4617. ret = qla2x00_stop_firmware(vha);
  4618. for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
  4619. ret != QLA_INVALID_COMMAND && retries ; retries--) {
  4620. ha->isp_ops->reset_chip(vha);
  4621. if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
  4622. continue;
  4623. if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
  4624. continue;
  4625. ql_log(ql_log_info, vha, 0x8015,
  4626. "Attempting retry of stop-firmware command.\n");
  4627. ret = qla2x00_stop_firmware(vha);
  4628. }
  4629. }
  4630. int
  4631. qla24xx_configure_vhba(scsi_qla_host_t *vha)
  4632. {
  4633. int rval = QLA_SUCCESS;
  4634. int rval2;
  4635. uint16_t mb[MAILBOX_REGISTER_COUNT];
  4636. struct qla_hw_data *ha = vha->hw;
  4637. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  4638. struct req_que *req;
  4639. struct rsp_que *rsp;
  4640. if (!vha->vp_idx)
  4641. return -EINVAL;
  4642. rval = qla2x00_fw_ready(base_vha);
  4643. if (ha->flags.cpu_affinity_enabled)
  4644. req = ha->req_q_map[0];
  4645. else
  4646. req = vha->req;
  4647. rsp = req->rsp;
  4648. if (rval == QLA_SUCCESS) {
  4649. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4650. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4651. }
  4652. vha->flags.management_server_logged_in = 0;
  4653. /* Login to SNS first */
  4654. rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
  4655. BIT_1);
  4656. if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  4657. if (rval2 == QLA_MEMORY_ALLOC_FAILED)
  4658. ql_dbg(ql_dbg_init, vha, 0x0120,
  4659. "Failed SNS login: loop_id=%x, rval2=%d\n",
  4660. NPH_SNS, rval2);
  4661. else
  4662. ql_dbg(ql_dbg_init, vha, 0x0103,
  4663. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  4664. "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
  4665. NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
  4666. return (QLA_FUNCTION_FAILED);
  4667. }
  4668. atomic_set(&vha->loop_down_timer, 0);
  4669. atomic_set(&vha->loop_state, LOOP_UP);
  4670. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4671. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  4672. rval = qla2x00_loop_resync(base_vha);
  4673. return rval;
  4674. }
  4675. /* 84XX Support **************************************************************/
  4676. static LIST_HEAD(qla_cs84xx_list);
  4677. static DEFINE_MUTEX(qla_cs84xx_mutex);
  4678. static struct qla_chip_state_84xx *
  4679. qla84xx_get_chip(struct scsi_qla_host *vha)
  4680. {
  4681. struct qla_chip_state_84xx *cs84xx;
  4682. struct qla_hw_data *ha = vha->hw;
  4683. mutex_lock(&qla_cs84xx_mutex);
  4684. /* Find any shared 84xx chip. */
  4685. list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
  4686. if (cs84xx->bus == ha->pdev->bus) {
  4687. kref_get(&cs84xx->kref);
  4688. goto done;
  4689. }
  4690. }
  4691. cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
  4692. if (!cs84xx)
  4693. goto done;
  4694. kref_init(&cs84xx->kref);
  4695. spin_lock_init(&cs84xx->access_lock);
  4696. mutex_init(&cs84xx->fw_update_mutex);
  4697. cs84xx->bus = ha->pdev->bus;
  4698. list_add_tail(&cs84xx->list, &qla_cs84xx_list);
  4699. done:
  4700. mutex_unlock(&qla_cs84xx_mutex);
  4701. return cs84xx;
  4702. }
  4703. static void
  4704. __qla84xx_chip_release(struct kref *kref)
  4705. {
  4706. struct qla_chip_state_84xx *cs84xx =
  4707. container_of(kref, struct qla_chip_state_84xx, kref);
  4708. mutex_lock(&qla_cs84xx_mutex);
  4709. list_del(&cs84xx->list);
  4710. mutex_unlock(&qla_cs84xx_mutex);
  4711. kfree(cs84xx);
  4712. }
  4713. void
  4714. qla84xx_put_chip(struct scsi_qla_host *vha)
  4715. {
  4716. struct qla_hw_data *ha = vha->hw;
  4717. if (ha->cs84xx)
  4718. kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
  4719. }
  4720. static int
  4721. qla84xx_init_chip(scsi_qla_host_t *vha)
  4722. {
  4723. int rval;
  4724. uint16_t status[2];
  4725. struct qla_hw_data *ha = vha->hw;
  4726. mutex_lock(&ha->cs84xx->fw_update_mutex);
  4727. rval = qla84xx_verify_chip(vha, status);
  4728. mutex_unlock(&ha->cs84xx->fw_update_mutex);
  4729. return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
  4730. QLA_SUCCESS;
  4731. }
  4732. /* 81XX Support **************************************************************/
  4733. int
  4734. qla81xx_nvram_config(scsi_qla_host_t *vha)
  4735. {
  4736. int rval;
  4737. struct init_cb_81xx *icb;
  4738. struct nvram_81xx *nv;
  4739. uint32_t *dptr;
  4740. uint8_t *dptr1, *dptr2;
  4741. uint32_t chksum;
  4742. uint16_t cnt;
  4743. struct qla_hw_data *ha = vha->hw;
  4744. rval = QLA_SUCCESS;
  4745. icb = (struct init_cb_81xx *)ha->init_cb;
  4746. nv = ha->nvram;
  4747. /* Determine NVRAM starting address. */
  4748. ha->nvram_size = sizeof(struct nvram_81xx);
  4749. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4750. /* Get VPD data into cache */
  4751. ha->vpd = ha->nvram + VPD_OFFSET;
  4752. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  4753. ha->vpd_size);
  4754. /* Get NVRAM data into cache and calculate checksum. */
  4755. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  4756. ha->nvram_size);
  4757. dptr = (uint32_t *)nv;
  4758. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  4759. chksum += le32_to_cpu(*dptr++);
  4760. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
  4761. "Contents of NVRAM:\n");
  4762. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
  4763. (uint8_t *)nv, ha->nvram_size);
  4764. /* Bad NVRAM data, set defaults parameters. */
  4765. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4766. || nv->id[3] != ' ' ||
  4767. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  4768. /* Reset NVRAM data. */
  4769. ql_log(ql_log_info, vha, 0x0073,
  4770. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  4771. "version=0x%x.\n", chksum, nv->id[0],
  4772. le16_to_cpu(nv->nvram_version));
  4773. ql_log(ql_log_info, vha, 0x0074,
  4774. "Falling back to functioning (yet invalid -- WWPN) "
  4775. "defaults.\n");
  4776. /*
  4777. * Set default initialization control block.
  4778. */
  4779. memset(nv, 0, ha->nvram_size);
  4780. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  4781. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  4782. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  4783. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4784. nv->exchange_count = __constant_cpu_to_le16(0);
  4785. nv->port_name[0] = 0x21;
  4786. nv->port_name[1] = 0x00 + ha->port_no;
  4787. nv->port_name[2] = 0x00;
  4788. nv->port_name[3] = 0xe0;
  4789. nv->port_name[4] = 0x8b;
  4790. nv->port_name[5] = 0x1c;
  4791. nv->port_name[6] = 0x55;
  4792. nv->port_name[7] = 0x86;
  4793. nv->node_name[0] = 0x20;
  4794. nv->node_name[1] = 0x00;
  4795. nv->node_name[2] = 0x00;
  4796. nv->node_name[3] = 0xe0;
  4797. nv->node_name[4] = 0x8b;
  4798. nv->node_name[5] = 0x1c;
  4799. nv->node_name[6] = 0x55;
  4800. nv->node_name[7] = 0x86;
  4801. nv->login_retry_count = __constant_cpu_to_le16(8);
  4802. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  4803. nv->login_timeout = __constant_cpu_to_le16(0);
  4804. nv->firmware_options_1 =
  4805. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4806. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  4807. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  4808. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  4809. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  4810. nv->efi_parameters = __constant_cpu_to_le32(0);
  4811. nv->reset_delay = 5;
  4812. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  4813. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  4814. nv->link_down_timeout = __constant_cpu_to_le16(180);
  4815. nv->enode_mac[0] = 0x00;
  4816. nv->enode_mac[1] = 0xC0;
  4817. nv->enode_mac[2] = 0xDD;
  4818. nv->enode_mac[3] = 0x04;
  4819. nv->enode_mac[4] = 0x05;
  4820. nv->enode_mac[5] = 0x06 + ha->port_no;
  4821. rval = 1;
  4822. }
  4823. if (IS_T10_PI_CAPABLE(ha))
  4824. nv->frame_payload_size &= ~7;
  4825. qlt_81xx_config_nvram_stage1(vha, nv);
  4826. /* Reset Initialization control block */
  4827. memset(icb, 0, ha->init_cb_size);
  4828. /* Copy 1st segment. */
  4829. dptr1 = (uint8_t *)icb;
  4830. dptr2 = (uint8_t *)&nv->version;
  4831. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4832. while (cnt--)
  4833. *dptr1++ = *dptr2++;
  4834. icb->login_retry_count = nv->login_retry_count;
  4835. /* Copy 2nd segment. */
  4836. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4837. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4838. cnt = (uint8_t *)&icb->reserved_5 -
  4839. (uint8_t *)&icb->interrupt_delay_timer;
  4840. while (cnt--)
  4841. *dptr1++ = *dptr2++;
  4842. memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
  4843. /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
  4844. if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
  4845. icb->enode_mac[0] = 0x00;
  4846. icb->enode_mac[1] = 0xC0;
  4847. icb->enode_mac[2] = 0xDD;
  4848. icb->enode_mac[3] = 0x04;
  4849. icb->enode_mac[4] = 0x05;
  4850. icb->enode_mac[5] = 0x06 + ha->port_no;
  4851. }
  4852. /* Use extended-initialization control block. */
  4853. memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
  4854. /*
  4855. * Setup driver NVRAM options.
  4856. */
  4857. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4858. "QLE8XXX");
  4859. qlt_81xx_config_nvram_stage2(vha, icb);
  4860. /* Use alternate WWN? */
  4861. if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
  4862. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4863. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4864. }
  4865. /* Prepare nodename */
  4866. if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
  4867. /*
  4868. * Firmware will apply the following mask if the nodename was
  4869. * not provided.
  4870. */
  4871. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4872. icb->node_name[0] &= 0xF0;
  4873. }
  4874. /* Set host adapter parameters. */
  4875. ha->flags.disable_risc_code_load = 0;
  4876. ha->flags.enable_lip_reset = 0;
  4877. ha->flags.enable_lip_full_login =
  4878. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4879. ha->flags.enable_target_reset =
  4880. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4881. ha->flags.enable_led_scheme = 0;
  4882. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4883. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4884. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4885. /* save HBA serial number */
  4886. ha->serial0 = icb->port_name[5];
  4887. ha->serial1 = icb->port_name[6];
  4888. ha->serial2 = icb->port_name[7];
  4889. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4890. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4891. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4892. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4893. /* Set minimum login_timeout to 4 seconds. */
  4894. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4895. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4896. if (le16_to_cpu(nv->login_timeout) < 4)
  4897. nv->login_timeout = __constant_cpu_to_le16(4);
  4898. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4899. icb->login_timeout = nv->login_timeout;
  4900. /* Set minimum RATOV to 100 tenths of a second. */
  4901. ha->r_a_tov = 100;
  4902. ha->loop_reset_delay = nv->reset_delay;
  4903. /* Link Down Timeout = 0:
  4904. *
  4905. * When Port Down timer expires we will start returning
  4906. * I/O's to OS with "DID_NO_CONNECT".
  4907. *
  4908. * Link Down Timeout != 0:
  4909. *
  4910. * The driver waits for the link to come up after link down
  4911. * before returning I/Os to OS with "DID_NO_CONNECT".
  4912. */
  4913. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4914. ha->loop_down_abort_time =
  4915. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4916. } else {
  4917. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4918. ha->loop_down_abort_time =
  4919. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4920. }
  4921. /* Need enough time to try and get the port back. */
  4922. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4923. if (qlport_down_retry)
  4924. ha->port_down_retry_count = qlport_down_retry;
  4925. /* Set login_retry_count */
  4926. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4927. if (ha->port_down_retry_count ==
  4928. le16_to_cpu(nv->port_down_retry_count) &&
  4929. ha->port_down_retry_count > 3)
  4930. ha->login_retry_count = ha->port_down_retry_count;
  4931. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4932. ha->login_retry_count = ha->port_down_retry_count;
  4933. if (ql2xloginretrycount)
  4934. ha->login_retry_count = ql2xloginretrycount;
  4935. /* if not running MSI-X we need handshaking on interrupts */
  4936. if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
  4937. icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
  4938. /* Enable ZIO. */
  4939. if (!vha->flags.init_done) {
  4940. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4941. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4942. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4943. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4944. }
  4945. icb->firmware_options_2 &= __constant_cpu_to_le32(
  4946. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4947. vha->flags.process_response_queue = 0;
  4948. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4949. ha->zio_mode = QLA_ZIO_MODE_6;
  4950. ql_log(ql_log_info, vha, 0x0075,
  4951. "ZIO mode %d enabled; timer delay (%d us).\n",
  4952. ha->zio_mode,
  4953. ha->zio_timer * 100);
  4954. icb->firmware_options_2 |= cpu_to_le32(
  4955. (uint32_t)ha->zio_mode);
  4956. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4957. vha->flags.process_response_queue = 1;
  4958. }
  4959. if (rval) {
  4960. ql_log(ql_log_warn, vha, 0x0076,
  4961. "NVRAM configuration failed.\n");
  4962. }
  4963. return (rval);
  4964. }
  4965. int
  4966. qla82xx_restart_isp(scsi_qla_host_t *vha)
  4967. {
  4968. int status, rval;
  4969. uint32_t wait_time;
  4970. struct qla_hw_data *ha = vha->hw;
  4971. struct req_que *req = ha->req_q_map[0];
  4972. struct rsp_que *rsp = ha->rsp_q_map[0];
  4973. struct scsi_qla_host *vp;
  4974. unsigned long flags;
  4975. status = qla2x00_init_rings(vha);
  4976. if (!status) {
  4977. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4978. ha->flags.chip_reset_done = 1;
  4979. status = qla2x00_fw_ready(vha);
  4980. if (!status) {
  4981. ql_log(ql_log_info, vha, 0x803c,
  4982. "Start configure loop, status =%d.\n", status);
  4983. /* Issue a marker after FW becomes ready. */
  4984. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4985. vha->flags.online = 1;
  4986. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  4987. wait_time = 256;
  4988. do {
  4989. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4990. qla2x00_configure_loop(vha);
  4991. wait_time--;
  4992. } while (!atomic_read(&vha->loop_down_timer) &&
  4993. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
  4994. wait_time &&
  4995. (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
  4996. }
  4997. /* if no cable then assume it's good */
  4998. if ((vha->device_flags & DFLG_NO_CABLE))
  4999. status = 0;
  5000. ql_log(ql_log_info, vha, 0x8000,
  5001. "Configure loop done, status = 0x%x.\n", status);
  5002. }
  5003. if (!status) {
  5004. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5005. if (!atomic_read(&vha->loop_down_timer)) {
  5006. /*
  5007. * Issue marker command only when we are going
  5008. * to start the I/O .
  5009. */
  5010. vha->marker_needed = 1;
  5011. }
  5012. vha->flags.online = 1;
  5013. ha->isp_ops->enable_intrs(ha);
  5014. ha->isp_abort_cnt = 0;
  5015. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  5016. /* Update the firmware version */
  5017. status = qla82xx_check_md_needed(vha);
  5018. if (ha->fce) {
  5019. ha->flags.fce_enabled = 1;
  5020. memset(ha->fce, 0,
  5021. fce_calc_size(ha->fce_bufs));
  5022. rval = qla2x00_enable_fce_trace(vha,
  5023. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  5024. &ha->fce_bufs);
  5025. if (rval) {
  5026. ql_log(ql_log_warn, vha, 0x8001,
  5027. "Unable to reinitialize FCE (%d).\n",
  5028. rval);
  5029. ha->flags.fce_enabled = 0;
  5030. }
  5031. }
  5032. if (ha->eft) {
  5033. memset(ha->eft, 0, EFT_SIZE);
  5034. rval = qla2x00_enable_eft_trace(vha,
  5035. ha->eft_dma, EFT_NUM_BUFFERS);
  5036. if (rval) {
  5037. ql_log(ql_log_warn, vha, 0x8010,
  5038. "Unable to reinitialize EFT (%d).\n",
  5039. rval);
  5040. }
  5041. }
  5042. }
  5043. if (!status) {
  5044. ql_dbg(ql_dbg_taskm, vha, 0x8011,
  5045. "qla82xx_restart_isp succeeded.\n");
  5046. spin_lock_irqsave(&ha->vport_slock, flags);
  5047. list_for_each_entry(vp, &ha->vp_list, list) {
  5048. if (vp->vp_idx) {
  5049. atomic_inc(&vp->vref_count);
  5050. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5051. qla2x00_vp_abort_isp(vp);
  5052. spin_lock_irqsave(&ha->vport_slock, flags);
  5053. atomic_dec(&vp->vref_count);
  5054. }
  5055. }
  5056. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5057. } else {
  5058. ql_log(ql_log_warn, vha, 0x8016,
  5059. "qla82xx_restart_isp **** FAILED ****.\n");
  5060. }
  5061. return status;
  5062. }
  5063. void
  5064. qla81xx_update_fw_options(scsi_qla_host_t *vha)
  5065. {
  5066. struct qla_hw_data *ha = vha->hw;
  5067. if (!ql2xetsenable)
  5068. return;
  5069. /* Enable ETS Burst. */
  5070. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  5071. ha->fw_options[2] |= BIT_9;
  5072. qla2x00_set_fw_options(vha, ha->fw_options);
  5073. }
  5074. /*
  5075. * qla24xx_get_fcp_prio
  5076. * Gets the fcp cmd priority value for the logged in port.
  5077. * Looks for a match of the port descriptors within
  5078. * each of the fcp prio config entries. If a match is found,
  5079. * the tag (priority) value is returned.
  5080. *
  5081. * Input:
  5082. * vha = scsi host structure pointer.
  5083. * fcport = port structure pointer.
  5084. *
  5085. * Return:
  5086. * non-zero (if found)
  5087. * -1 (if not found)
  5088. *
  5089. * Context:
  5090. * Kernel context
  5091. */
  5092. static int
  5093. qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5094. {
  5095. int i, entries;
  5096. uint8_t pid_match, wwn_match;
  5097. int priority;
  5098. uint32_t pid1, pid2;
  5099. uint64_t wwn1, wwn2;
  5100. struct qla_fcp_prio_entry *pri_entry;
  5101. struct qla_hw_data *ha = vha->hw;
  5102. if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
  5103. return -1;
  5104. priority = -1;
  5105. entries = ha->fcp_prio_cfg->num_entries;
  5106. pri_entry = &ha->fcp_prio_cfg->entry[0];
  5107. for (i = 0; i < entries; i++) {
  5108. pid_match = wwn_match = 0;
  5109. if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
  5110. pri_entry++;
  5111. continue;
  5112. }
  5113. /* check source pid for a match */
  5114. if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
  5115. pid1 = pri_entry->src_pid & INVALID_PORT_ID;
  5116. pid2 = vha->d_id.b24 & INVALID_PORT_ID;
  5117. if (pid1 == INVALID_PORT_ID)
  5118. pid_match++;
  5119. else if (pid1 == pid2)
  5120. pid_match++;
  5121. }
  5122. /* check destination pid for a match */
  5123. if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
  5124. pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
  5125. pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
  5126. if (pid1 == INVALID_PORT_ID)
  5127. pid_match++;
  5128. else if (pid1 == pid2)
  5129. pid_match++;
  5130. }
  5131. /* check source WWN for a match */
  5132. if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
  5133. wwn1 = wwn_to_u64(vha->port_name);
  5134. wwn2 = wwn_to_u64(pri_entry->src_wwpn);
  5135. if (wwn2 == (uint64_t)-1)
  5136. wwn_match++;
  5137. else if (wwn1 == wwn2)
  5138. wwn_match++;
  5139. }
  5140. /* check destination WWN for a match */
  5141. if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
  5142. wwn1 = wwn_to_u64(fcport->port_name);
  5143. wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
  5144. if (wwn2 == (uint64_t)-1)
  5145. wwn_match++;
  5146. else if (wwn1 == wwn2)
  5147. wwn_match++;
  5148. }
  5149. if (pid_match == 2 || wwn_match == 2) {
  5150. /* Found a matching entry */
  5151. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  5152. priority = pri_entry->tag;
  5153. break;
  5154. }
  5155. pri_entry++;
  5156. }
  5157. return priority;
  5158. }
  5159. /*
  5160. * qla24xx_update_fcport_fcp_prio
  5161. * Activates fcp priority for the logged in fc port
  5162. *
  5163. * Input:
  5164. * vha = scsi host structure pointer.
  5165. * fcp = port structure pointer.
  5166. *
  5167. * Return:
  5168. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5169. *
  5170. * Context:
  5171. * Kernel context.
  5172. */
  5173. int
  5174. qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5175. {
  5176. int ret;
  5177. int priority;
  5178. uint16_t mb[5];
  5179. if (fcport->port_type != FCT_TARGET ||
  5180. fcport->loop_id == FC_NO_LOOP_ID)
  5181. return QLA_FUNCTION_FAILED;
  5182. priority = qla24xx_get_fcp_prio(vha, fcport);
  5183. if (priority < 0)
  5184. return QLA_FUNCTION_FAILED;
  5185. if (IS_QLA82XX(vha->hw)) {
  5186. fcport->fcp_prio = priority & 0xf;
  5187. return QLA_SUCCESS;
  5188. }
  5189. ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
  5190. if (ret == QLA_SUCCESS) {
  5191. if (fcport->fcp_prio != priority)
  5192. ql_dbg(ql_dbg_user, vha, 0x709e,
  5193. "Updated FCP_CMND priority - value=%d loop_id=%d "
  5194. "port_id=%02x%02x%02x.\n", priority,
  5195. fcport->loop_id, fcport->d_id.b.domain,
  5196. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  5197. fcport->fcp_prio = priority & 0xf;
  5198. } else
  5199. ql_dbg(ql_dbg_user, vha, 0x704f,
  5200. "Unable to update FCP_CMND priority - ret=0x%x for "
  5201. "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
  5202. fcport->d_id.b.domain, fcport->d_id.b.area,
  5203. fcport->d_id.b.al_pa);
  5204. return ret;
  5205. }
  5206. /*
  5207. * qla24xx_update_all_fcp_prio
  5208. * Activates fcp priority for all the logged in ports
  5209. *
  5210. * Input:
  5211. * ha = adapter block pointer.
  5212. *
  5213. * Return:
  5214. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5215. *
  5216. * Context:
  5217. * Kernel context.
  5218. */
  5219. int
  5220. qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
  5221. {
  5222. int ret;
  5223. fc_port_t *fcport;
  5224. ret = QLA_FUNCTION_FAILED;
  5225. /* We need to set priority for all logged in ports */
  5226. list_for_each_entry(fcport, &vha->vp_fcports, list)
  5227. ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
  5228. return ret;
  5229. }