qla_init.c 102 KB

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