qla_init.c 145 KB

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