qla_init.c 119 KB

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