qla_init.c 146 KB

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