qla_init.c 141 KB

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