qla_init.c 121 KB

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