qla_init.c 146 KB

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