qla_init.c 105 KB

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