qla_init.c 157 KB

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