qla_init.c 143 KB

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