qla_init.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985
  1. /*
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic ISP2x00 device driver for Linux 2.6.x
  5. * Copyright (C) 2003-2004 QLogic Corporation
  6. * (www.qlogic.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. */
  19. #include "qla_def.h"
  20. #include <linux/delay.h>
  21. #include <scsi/scsi_transport_fc.h>
  22. #include "qla_devtbl.h"
  23. /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
  24. #ifndef EXT_IS_LUN_BIT_SET
  25. #define EXT_IS_LUN_BIT_SET(P,L) \
  26. (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
  27. #define EXT_SET_LUN_BIT(P,L) \
  28. ((P)->mask[L/8] |= (0x80 >> (L%8)))
  29. #endif
  30. /*
  31. * QLogic ISP2x00 Hardware Support Function Prototypes.
  32. */
  33. static int qla2x00_isp_firmware(scsi_qla_host_t *);
  34. static void qla2x00_resize_request_q(scsi_qla_host_t *);
  35. static int qla2x00_setup_chip(scsi_qla_host_t *);
  36. static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
  37. static int qla2x00_init_rings(scsi_qla_host_t *);
  38. static int qla2x00_fw_ready(scsi_qla_host_t *);
  39. static int qla2x00_configure_hba(scsi_qla_host_t *);
  40. static int qla2x00_configure_loop(scsi_qla_host_t *);
  41. static int qla2x00_configure_local_loop(scsi_qla_host_t *);
  42. static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
  43. static int qla2x00_configure_fabric(scsi_qla_host_t *);
  44. static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
  45. static int qla2x00_device_resync(scsi_qla_host_t *);
  46. static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
  47. uint16_t *);
  48. static int qla2x00_restart_isp(scsi_qla_host_t *);
  49. /****************************************************************************/
  50. /* QLogic ISP2x00 Hardware Support Functions. */
  51. /****************************************************************************/
  52. /*
  53. * qla2x00_initialize_adapter
  54. * Initialize board.
  55. *
  56. * Input:
  57. * ha = adapter block pointer.
  58. *
  59. * Returns:
  60. * 0 = success
  61. */
  62. int
  63. qla2x00_initialize_adapter(scsi_qla_host_t *ha)
  64. {
  65. int rval;
  66. uint8_t restart_risc = 0;
  67. uint8_t retry;
  68. uint32_t wait_time;
  69. /* Clear adapter flags. */
  70. ha->flags.online = 0;
  71. ha->flags.reset_active = 0;
  72. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  73. atomic_set(&ha->loop_state, LOOP_DOWN);
  74. ha->device_flags = 0;
  75. ha->dpc_flags = 0;
  76. ha->flags.management_server_logged_in = 0;
  77. ha->marker_needed = 0;
  78. ha->mbx_flags = 0;
  79. ha->isp_abort_cnt = 0;
  80. ha->beacon_blink_led = 0;
  81. rval = ha->isp_ops.pci_config(ha);
  82. if (rval) {
  83. DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
  84. ha->host_no));
  85. return (rval);
  86. }
  87. ha->isp_ops.reset_chip(ha);
  88. qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
  89. ha->isp_ops.nvram_config(ha);
  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. /*
  117. * Wait at most MAX_TARGET RSCNs for a stable
  118. * link.
  119. */
  120. wait_time = 256;
  121. do {
  122. clear_bit(LOOP_RESYNC_NEEDED,
  123. &ha->dpc_flags);
  124. rval = qla2x00_configure_loop(ha);
  125. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  126. &ha->dpc_flags)) {
  127. restart_risc = 1;
  128. break;
  129. }
  130. /*
  131. * If loop state change while we were
  132. * discoverying devices then wait for
  133. * LIP to complete
  134. */
  135. if (atomic_read(&ha->loop_state) ==
  136. LOOP_DOWN && retry--) {
  137. goto check_fw_ready_again;
  138. }
  139. wait_time--;
  140. } while (!atomic_read(&ha->loop_down_timer) &&
  141. retry &&
  142. wait_time &&
  143. (test_bit(LOOP_RESYNC_NEEDED,
  144. &ha->dpc_flags)));
  145. if (wait_time == 0)
  146. rval = QLA_FUNCTION_FAILED;
  147. } else if (ha->device_flags & DFLG_NO_CABLE)
  148. /* If no cable, then all is good. */
  149. rval = QLA_SUCCESS;
  150. }
  151. } while (restart_risc && retry--);
  152. if (rval == QLA_SUCCESS) {
  153. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  154. ha->marker_needed = 1;
  155. qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
  156. ha->marker_needed = 0;
  157. ha->flags.online = 1;
  158. } else {
  159. DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
  160. }
  161. return (rval);
  162. }
  163. /**
  164. * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
  165. * @ha: HA context
  166. *
  167. * Returns 0 on success.
  168. */
  169. int
  170. qla2100_pci_config(scsi_qla_host_t *ha)
  171. {
  172. uint16_t w, mwi;
  173. unsigned long flags;
  174. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  175. qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
  176. pci_set_master(ha->pdev);
  177. mwi = 0;
  178. if (pci_set_mwi(ha->pdev))
  179. mwi = PCI_COMMAND_INVALIDATE;
  180. pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
  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_word(ha->pdev, PCI_ROM_ADDRESS, &w);
  186. w &= ~PCI_ROM_ADDRESS_ENABLE;
  187. pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
  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. unsigned long flags = 0;
  205. uint32_t cnt;
  206. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  207. qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
  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_REVISION_ID, &ha->revision);
  213. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  214. w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  215. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  216. w &= ~PCI_COMMAND_INTX_DISABLE;
  217. /*
  218. * If this is a 2300 card and not 2312, reset the
  219. * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
  220. * the 2310 also reports itself as a 2300 so we need to get the
  221. * fb revision level -- a 6 indicates it really is a 2300 and
  222. * not a 2310.
  223. */
  224. if (IS_QLA2300(ha)) {
  225. spin_lock_irqsave(&ha->hardware_lock, flags);
  226. /* Pause RISC. */
  227. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  228. for (cnt = 0; cnt < 30000; cnt++) {
  229. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  230. break;
  231. udelay(10);
  232. }
  233. /* Select FPM registers. */
  234. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  235. RD_REG_WORD(&reg->ctrl_status);
  236. /* Get the fb rev level */
  237. ha->fb_rev = RD_FB_CMD_REG(ha, reg);
  238. if (ha->fb_rev == FPM_2300)
  239. w &= ~PCI_COMMAND_INVALIDATE;
  240. /* Deselect FPM registers. */
  241. WRT_REG_WORD(&reg->ctrl_status, 0x0);
  242. RD_REG_WORD(&reg->ctrl_status);
  243. /* Release RISC module. */
  244. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  245. for (cnt = 0; cnt < 30000; cnt++) {
  246. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
  247. break;
  248. udelay(10);
  249. }
  250. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  251. }
  252. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  253. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  254. /* Reset expansion ROM address decode enable */
  255. pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
  256. w &= ~PCI_ROM_ADDRESS_ENABLE;
  257. pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
  258. /* Get PCI bus information. */
  259. spin_lock_irqsave(&ha->hardware_lock, flags);
  260. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  261. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  262. return QLA_SUCCESS;
  263. }
  264. /**
  265. * qla2x00_isp_firmware() - Choose firmware image.
  266. * @ha: HA context
  267. *
  268. * Returns 0 on success.
  269. */
  270. static int
  271. qla2x00_isp_firmware(scsi_qla_host_t *ha)
  272. {
  273. int rval;
  274. /* Assume loading risc code */
  275. rval = QLA_FUNCTION_FAILED;
  276. if (ha->flags.disable_risc_code_load) {
  277. DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
  278. ha->host_no));
  279. qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
  280. /* Verify checksum of loaded RISC code. */
  281. rval = qla2x00_verify_checksum(ha);
  282. }
  283. if (rval) {
  284. DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
  285. ha->host_no));
  286. }
  287. return (rval);
  288. }
  289. /**
  290. * qla2x00_reset_chip() - Reset ISP chip.
  291. * @ha: HA context
  292. *
  293. * Returns 0 on success.
  294. */
  295. void
  296. qla2x00_reset_chip(scsi_qla_host_t *ha)
  297. {
  298. unsigned long flags = 0;
  299. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  300. uint32_t cnt;
  301. unsigned long mbx_flags = 0;
  302. uint16_t cmd;
  303. ha->isp_ops.disable_intrs(ha);
  304. spin_lock_irqsave(&ha->hardware_lock, flags);
  305. /* Turn off master enable */
  306. cmd = 0;
  307. pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
  308. cmd &= ~PCI_COMMAND_MASTER;
  309. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  310. if (!IS_QLA2100(ha)) {
  311. /* Pause RISC. */
  312. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  313. if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
  314. for (cnt = 0; cnt < 30000; cnt++) {
  315. if ((RD_REG_WORD(&reg->hccr) &
  316. HCCR_RISC_PAUSE) != 0)
  317. break;
  318. udelay(100);
  319. }
  320. } else {
  321. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  322. udelay(10);
  323. }
  324. /* Select FPM registers. */
  325. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  326. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  327. /* FPM Soft Reset. */
  328. WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
  329. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  330. /* Toggle Fpm Reset. */
  331. if (!IS_QLA2200(ha)) {
  332. WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
  333. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  334. }
  335. /* Select frame buffer registers. */
  336. WRT_REG_WORD(&reg->ctrl_status, 0x10);
  337. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  338. /* Reset frame buffer FIFOs. */
  339. if (IS_QLA2200(ha)) {
  340. WRT_FB_CMD_REG(ha, reg, 0xa000);
  341. RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
  342. } else {
  343. WRT_FB_CMD_REG(ha, reg, 0x00fc);
  344. /* Read back fb_cmd until zero or 3 seconds max */
  345. for (cnt = 0; cnt < 3000; cnt++) {
  346. if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
  347. break;
  348. udelay(100);
  349. }
  350. }
  351. /* Select RISC module registers. */
  352. WRT_REG_WORD(&reg->ctrl_status, 0);
  353. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  354. /* Reset RISC processor. */
  355. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  356. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  357. /* Release RISC processor. */
  358. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  359. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  360. }
  361. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  362. WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
  363. /* Reset ISP chip. */
  364. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  365. /* Wait for RISC to recover from reset. */
  366. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  367. /*
  368. * It is necessary to for a delay here since the card doesn't
  369. * respond to PCI reads during a reset. On some architectures
  370. * this will result in an MCA.
  371. */
  372. udelay(20);
  373. for (cnt = 30000; cnt; cnt--) {
  374. if ((RD_REG_WORD(&reg->ctrl_status) &
  375. CSR_ISP_SOFT_RESET) == 0)
  376. break;
  377. udelay(100);
  378. }
  379. } else
  380. udelay(10);
  381. /* Reset RISC processor. */
  382. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  383. WRT_REG_WORD(&reg->semaphore, 0);
  384. /* Release RISC processor. */
  385. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  386. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  387. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  388. for (cnt = 0; cnt < 30000; cnt++) {
  389. if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
  390. spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
  391. if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
  392. if (!(test_bit(ABORT_ISP_ACTIVE,
  393. &ha->dpc_flags)))
  394. spin_unlock_irqrestore(
  395. &ha->mbx_reg_lock, mbx_flags);
  396. break;
  397. }
  398. if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
  399. spin_unlock_irqrestore(&ha->mbx_reg_lock,
  400. mbx_flags);
  401. udelay(100);
  402. }
  403. } else
  404. udelay(100);
  405. /* Turn on master enable */
  406. cmd |= PCI_COMMAND_MASTER;
  407. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  408. /* Disable RISC pause on FPM parity error. */
  409. if (!IS_QLA2100(ha)) {
  410. WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
  411. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  412. }
  413. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  414. }
  415. /**
  416. * qla2x00_chip_diag() - Test chip for proper operation.
  417. * @ha: HA context
  418. *
  419. * Returns 0 on success.
  420. */
  421. int
  422. qla2x00_chip_diag(scsi_qla_host_t *ha)
  423. {
  424. int rval;
  425. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  426. unsigned long flags = 0;
  427. uint16_t data;
  428. uint32_t cnt;
  429. uint16_t mb[5];
  430. /* Assume a failed state */
  431. rval = QLA_FUNCTION_FAILED;
  432. DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
  433. ha->host_no, (u_long)&reg->flash_address));
  434. spin_lock_irqsave(&ha->hardware_lock, flags);
  435. /* Reset ISP chip. */
  436. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  437. /*
  438. * We need to have a delay here since the card will not respond while
  439. * in reset causing an MCA on some architectures.
  440. */
  441. udelay(20);
  442. data = qla2x00_debounce_register(&reg->ctrl_status);
  443. for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
  444. udelay(5);
  445. data = RD_REG_WORD(&reg->ctrl_status);
  446. barrier();
  447. }
  448. if (!cnt)
  449. goto chip_diag_failed;
  450. DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
  451. ha->host_no));
  452. /* Reset RISC processor. */
  453. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  454. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  455. /* Workaround for QLA2312 PCI parity error */
  456. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  457. data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
  458. for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
  459. udelay(5);
  460. data = RD_MAILBOX_REG(ha, reg, 0);
  461. barrier();
  462. }
  463. } else
  464. udelay(10);
  465. if (!cnt)
  466. goto chip_diag_failed;
  467. /* Check product ID of chip */
  468. DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
  469. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  470. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  471. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  472. mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
  473. if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
  474. mb[3] != PROD_ID_3) {
  475. qla_printk(KERN_WARNING, ha,
  476. "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
  477. goto chip_diag_failed;
  478. }
  479. ha->product_id[0] = mb[1];
  480. ha->product_id[1] = mb[2];
  481. ha->product_id[2] = mb[3];
  482. ha->product_id[3] = mb[4];
  483. /* Adjust fw RISC transfer size */
  484. if (ha->request_q_length > 1024)
  485. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
  486. else
  487. ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
  488. ha->request_q_length;
  489. if (IS_QLA2200(ha) &&
  490. RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
  491. /* Limit firmware transfer size with a 2200A */
  492. DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
  493. ha->host_no));
  494. ha->fw_transfer_size = 128;
  495. }
  496. /* Wrap Incoming Mailboxes Test. */
  497. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  498. DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
  499. rval = qla2x00_mbx_reg_test(ha);
  500. if (rval) {
  501. DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
  502. ha->host_no));
  503. qla_printk(KERN_WARNING, ha,
  504. "Failed mailbox send register test\n");
  505. }
  506. else {
  507. /* Flag a successful rval */
  508. rval = QLA_SUCCESS;
  509. }
  510. spin_lock_irqsave(&ha->hardware_lock, flags);
  511. chip_diag_failed:
  512. if (rval)
  513. DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
  514. "****\n", ha->host_no));
  515. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  516. return (rval);
  517. }
  518. /**
  519. * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
  520. * @ha: HA context
  521. *
  522. * Returns 0 on success.
  523. */
  524. static void
  525. qla2x00_resize_request_q(scsi_qla_host_t *ha)
  526. {
  527. int rval;
  528. uint16_t fw_iocb_cnt = 0;
  529. uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
  530. dma_addr_t request_dma;
  531. request_t *request_ring;
  532. /* Valid only on recent ISPs. */
  533. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  534. return;
  535. /* Retrieve IOCB counts available to the firmware. */
  536. rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
  537. if (rval)
  538. return;
  539. /* No point in continuing if current settings are sufficient. */
  540. if (fw_iocb_cnt < 1024)
  541. return;
  542. if (ha->request_q_length >= request_q_length)
  543. return;
  544. /* Attempt to claim larger area for request queue. */
  545. request_ring = dma_alloc_coherent(&ha->pdev->dev,
  546. (request_q_length + 1) * sizeof(request_t), &request_dma,
  547. GFP_KERNEL);
  548. if (request_ring == NULL)
  549. return;
  550. /* Resize successful, report extensions. */
  551. qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
  552. (ha->fw_memory_size + 1) / 1024);
  553. qla_printk(KERN_INFO, ha, "Resizing request queue depth "
  554. "(%d -> %d)...\n", ha->request_q_length, request_q_length);
  555. /* Clear old allocations. */
  556. dma_free_coherent(&ha->pdev->dev,
  557. (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
  558. ha->request_dma);
  559. /* Begin using larger queue. */
  560. ha->request_q_length = request_q_length;
  561. ha->request_ring = request_ring;
  562. ha->request_dma = request_dma;
  563. }
  564. /**
  565. * qla2x00_setup_chip() - Load and start RISC firmware.
  566. * @ha: HA context
  567. *
  568. * Returns 0 on success.
  569. */
  570. static int
  571. qla2x00_setup_chip(scsi_qla_host_t *ha)
  572. {
  573. int rval;
  574. uint16_t cnt;
  575. uint16_t *risc_code;
  576. unsigned long risc_address;
  577. unsigned long risc_code_size;
  578. int num;
  579. int i;
  580. uint16_t *req_ring;
  581. struct qla_fw_info *fw_iter;
  582. rval = QLA_SUCCESS;
  583. /* Load firmware sequences */
  584. fw_iter = ha->brd_info->fw_info;
  585. while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
  586. risc_code = fw_iter->fwcode;
  587. risc_code_size = *fw_iter->fwlen;
  588. if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
  589. risc_address = *fw_iter->fwstart;
  590. } else {
  591. /* Extended address */
  592. risc_address = *fw_iter->lfwstart;
  593. }
  594. num = 0;
  595. rval = 0;
  596. while (risc_code_size > 0 && !rval) {
  597. cnt = (uint16_t)(ha->fw_transfer_size >> 1);
  598. if (cnt > risc_code_size)
  599. cnt = risc_code_size;
  600. DEBUG7(printk("scsi(%ld): Loading risc segment@ "
  601. "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
  602. ha->host_no, risc_code, cnt, risc_address));
  603. req_ring = (uint16_t *)ha->request_ring;
  604. for (i = 0; i < cnt; i++)
  605. req_ring[i] = cpu_to_le16(risc_code[i]);
  606. if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
  607. rval = qla2x00_load_ram(ha,
  608. ha->request_dma, risc_address, cnt);
  609. } else {
  610. rval = qla2x00_load_ram_ext(ha,
  611. ha->request_dma, risc_address, cnt);
  612. }
  613. if (rval) {
  614. DEBUG(printk("scsi(%ld): [ERROR] Failed to "
  615. "load segment %d of firmware\n",
  616. ha->host_no, num));
  617. qla_printk(KERN_WARNING, ha,
  618. "[ERROR] Failed to load "
  619. "segment %d of firmware\n", num);
  620. qla2x00_dump_regs(ha);
  621. break;
  622. }
  623. risc_code += cnt;
  624. risc_address += cnt;
  625. risc_code_size -= cnt;
  626. num++;
  627. }
  628. /* Next firmware sequence */
  629. fw_iter++;
  630. }
  631. /* Verify checksum of loaded RISC code. */
  632. if (!rval) {
  633. DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
  634. "code.\n", ha->host_no));
  635. rval = qla2x00_verify_checksum(ha);
  636. if (rval == QLA_SUCCESS) {
  637. /* Start firmware execution. */
  638. DEBUG(printk("scsi(%ld): Checksum OK, start "
  639. "firmware.\n", ha->host_no));
  640. rval = qla2x00_execute_fw(ha);
  641. /* Retrieve firmware information. */
  642. if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
  643. qla2x00_get_fw_version(ha,
  644. &ha->fw_major_version,
  645. &ha->fw_minor_version,
  646. &ha->fw_subminor_version,
  647. &ha->fw_attributes, &ha->fw_memory_size);
  648. qla2x00_resize_request_q(ha);
  649. }
  650. } else {
  651. DEBUG2(printk(KERN_INFO
  652. "scsi(%ld): ISP Firmware failed checksum.\n",
  653. ha->host_no));
  654. }
  655. }
  656. if (rval) {
  657. DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
  658. ha->host_no));
  659. }
  660. return (rval);
  661. }
  662. /**
  663. * qla2x00_init_response_q_entries() - Initializes response queue entries.
  664. * @ha: HA context
  665. *
  666. * Beginning of request ring has initialization control block already built
  667. * by nvram config routine.
  668. *
  669. * Returns 0 on success.
  670. */
  671. static void
  672. qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
  673. {
  674. uint16_t cnt;
  675. response_t *pkt;
  676. pkt = ha->response_ring_ptr;
  677. for (cnt = 0; cnt < ha->response_q_length; cnt++) {
  678. pkt->signature = RESPONSE_PROCESSED;
  679. pkt++;
  680. }
  681. }
  682. /**
  683. * qla2x00_update_fw_options() - Read and process firmware options.
  684. * @ha: HA context
  685. *
  686. * Returns 0 on success.
  687. */
  688. void
  689. qla2x00_update_fw_options(scsi_qla_host_t *ha)
  690. {
  691. uint16_t swing, emphasis, tx_sens, rx_sens;
  692. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  693. qla2x00_get_fw_options(ha, ha->fw_options);
  694. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  695. return;
  696. /* Serial Link options. */
  697. DEBUG3(printk("scsi(%ld): Serial link options:\n",
  698. ha->host_no));
  699. DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
  700. sizeof(ha->fw_seriallink_options)));
  701. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  702. if (ha->fw_seriallink_options[3] & BIT_2) {
  703. ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
  704. /* 1G settings */
  705. swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
  706. emphasis = (ha->fw_seriallink_options[2] &
  707. (BIT_4 | BIT_3)) >> 3;
  708. tx_sens = ha->fw_seriallink_options[0] &
  709. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  710. rx_sens = (ha->fw_seriallink_options[0] &
  711. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  712. ha->fw_options[10] = (emphasis << 14) | (swing << 8);
  713. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  714. if (rx_sens == 0x0)
  715. rx_sens = 0x3;
  716. ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
  717. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  718. ha->fw_options[10] |= BIT_5 |
  719. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  720. (tx_sens & (BIT_1 | BIT_0));
  721. /* 2G settings */
  722. swing = (ha->fw_seriallink_options[2] &
  723. (BIT_7 | BIT_6 | BIT_5)) >> 5;
  724. emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
  725. tx_sens = ha->fw_seriallink_options[1] &
  726. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  727. rx_sens = (ha->fw_seriallink_options[1] &
  728. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  729. ha->fw_options[11] = (emphasis << 14) | (swing << 8);
  730. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  731. if (rx_sens == 0x0)
  732. rx_sens = 0x3;
  733. ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
  734. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  735. ha->fw_options[11] |= BIT_5 |
  736. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  737. (tx_sens & (BIT_1 | BIT_0));
  738. }
  739. /* FCP2 options. */
  740. /* Return command IOCBs without waiting for an ABTS to complete. */
  741. ha->fw_options[3] |= BIT_13;
  742. /* LED scheme. */
  743. if (ha->flags.enable_led_scheme)
  744. ha->fw_options[2] |= BIT_12;
  745. /* Update firmware options. */
  746. qla2x00_set_fw_options(ha, ha->fw_options);
  747. }
  748. void
  749. qla2x00_config_rings(struct scsi_qla_host *ha)
  750. {
  751. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  752. /* Setup ring parameters in initialization control block. */
  753. ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
  754. ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
  755. ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
  756. ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
  757. ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
  758. ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
  759. ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
  760. ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
  761. WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
  762. WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
  763. WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
  764. WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
  765. RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
  766. }
  767. /**
  768. * qla2x00_init_rings() - Initializes firmware.
  769. * @ha: HA context
  770. *
  771. * Beginning of request ring has initialization control block already built
  772. * by nvram config routine.
  773. *
  774. * Returns 0 on success.
  775. */
  776. static int
  777. qla2x00_init_rings(scsi_qla_host_t *ha)
  778. {
  779. int rval;
  780. unsigned long flags = 0;
  781. int cnt;
  782. spin_lock_irqsave(&ha->hardware_lock, flags);
  783. /* Clear outstanding commands array. */
  784. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
  785. ha->outstanding_cmds[cnt] = NULL;
  786. ha->current_outstanding_cmd = 0;
  787. /* Clear RSCN queue. */
  788. ha->rscn_in_ptr = 0;
  789. ha->rscn_out_ptr = 0;
  790. /* Initialize firmware. */
  791. ha->request_ring_ptr = ha->request_ring;
  792. ha->req_ring_index = 0;
  793. ha->req_q_cnt = ha->request_q_length;
  794. ha->response_ring_ptr = ha->response_ring;
  795. ha->rsp_ring_index = 0;
  796. /* Initialize response queue entries */
  797. qla2x00_init_response_q_entries(ha);
  798. ha->isp_ops.config_rings(ha);
  799. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  800. /* Update any ISP specific firmware options before initialization. */
  801. ha->isp_ops.update_fw_options(ha);
  802. DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
  803. rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
  804. if (rval) {
  805. DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
  806. ha->host_no));
  807. } else {
  808. DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
  809. ha->host_no));
  810. }
  811. return (rval);
  812. }
  813. /**
  814. * qla2x00_fw_ready() - Waits for firmware ready.
  815. * @ha: HA context
  816. *
  817. * Returns 0 on success.
  818. */
  819. static int
  820. qla2x00_fw_ready(scsi_qla_host_t *ha)
  821. {
  822. int rval;
  823. unsigned long wtime, mtime;
  824. uint16_t min_wait; /* Minimum wait time if loop is down */
  825. uint16_t wait_time; /* Wait time if loop is coming ready */
  826. uint16_t fw_state;
  827. rval = QLA_SUCCESS;
  828. /* 20 seconds for loop down. */
  829. min_wait = 20;
  830. /*
  831. * Firmware should take at most one RATOV to login, plus 5 seconds for
  832. * our own processing.
  833. */
  834. if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
  835. wait_time = min_wait;
  836. }
  837. /* Min wait time if loop down */
  838. mtime = jiffies + (min_wait * HZ);
  839. /* wait time before firmware ready */
  840. wtime = jiffies + (wait_time * HZ);
  841. /* Wait for ISP to finish LIP */
  842. if (!ha->flags.init_done)
  843. qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
  844. DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
  845. ha->host_no));
  846. do {
  847. rval = qla2x00_get_firmware_state(ha, &fw_state);
  848. if (rval == QLA_SUCCESS) {
  849. if (fw_state < FSTATE_LOSS_OF_SYNC) {
  850. ha->device_flags &= ~DFLG_NO_CABLE;
  851. }
  852. if (fw_state == FSTATE_READY) {
  853. DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
  854. ha->host_no));
  855. qla2x00_get_retry_cnt(ha, &ha->retry_count,
  856. &ha->login_timeout, &ha->r_a_tov);
  857. rval = QLA_SUCCESS;
  858. break;
  859. }
  860. rval = QLA_FUNCTION_FAILED;
  861. if (atomic_read(&ha->loop_down_timer) &&
  862. (fw_state >= FSTATE_LOSS_OF_SYNC ||
  863. fw_state == FSTATE_WAIT_AL_PA)) {
  864. /* Loop down. Timeout on min_wait for states
  865. * other than Wait for Login.
  866. */
  867. if (time_after_eq(jiffies, mtime)) {
  868. qla_printk(KERN_INFO, ha,
  869. "Cable is unplugged...\n");
  870. ha->device_flags |= DFLG_NO_CABLE;
  871. break;
  872. }
  873. }
  874. } else {
  875. /* Mailbox cmd failed. Timeout on min_wait. */
  876. if (time_after_eq(jiffies, mtime))
  877. break;
  878. }
  879. if (time_after_eq(jiffies, wtime))
  880. break;
  881. /* Delay for a while */
  882. msleep(500);
  883. DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
  884. ha->host_no, fw_state, jiffies));
  885. } while (1);
  886. DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
  887. ha->host_no, fw_state, jiffies));
  888. if (rval) {
  889. DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
  890. ha->host_no));
  891. }
  892. return (rval);
  893. }
  894. /*
  895. * qla2x00_configure_hba
  896. * Setup adapter context.
  897. *
  898. * Input:
  899. * ha = adapter state pointer.
  900. *
  901. * Returns:
  902. * 0 = success
  903. *
  904. * Context:
  905. * Kernel context.
  906. */
  907. static int
  908. qla2x00_configure_hba(scsi_qla_host_t *ha)
  909. {
  910. int rval;
  911. uint16_t loop_id;
  912. uint16_t topo;
  913. uint8_t al_pa;
  914. uint8_t area;
  915. uint8_t domain;
  916. char connect_type[22];
  917. /* Get host addresses. */
  918. rval = qla2x00_get_adapter_id(ha,
  919. &loop_id, &al_pa, &area, &domain, &topo);
  920. if (rval != QLA_SUCCESS) {
  921. qla_printk(KERN_WARNING, ha,
  922. "ERROR -- Unable to get host loop ID.\n");
  923. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  924. return (rval);
  925. }
  926. if (topo == 4) {
  927. qla_printk(KERN_INFO, ha,
  928. "Cannot get topology - retrying.\n");
  929. return (QLA_FUNCTION_FAILED);
  930. }
  931. ha->loop_id = loop_id;
  932. /* initialize */
  933. ha->min_external_loopid = SNS_FIRST_LOOP_ID;
  934. ha->operating_mode = LOOP;
  935. switch (topo) {
  936. case 0:
  937. DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
  938. ha->host_no));
  939. ha->current_topology = ISP_CFG_NL;
  940. strcpy(connect_type, "(Loop)");
  941. break;
  942. case 1:
  943. DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
  944. ha->host_no));
  945. ha->current_topology = ISP_CFG_FL;
  946. strcpy(connect_type, "(FL_Port)");
  947. break;
  948. case 2:
  949. DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
  950. ha->host_no));
  951. ha->operating_mode = P2P;
  952. ha->current_topology = ISP_CFG_N;
  953. strcpy(connect_type, "(N_Port-to-N_Port)");
  954. break;
  955. case 3:
  956. DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
  957. ha->host_no));
  958. ha->operating_mode = P2P;
  959. ha->current_topology = ISP_CFG_F;
  960. strcpy(connect_type, "(F_Port)");
  961. break;
  962. default:
  963. DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
  964. "Using NL.\n",
  965. ha->host_no, topo));
  966. ha->current_topology = ISP_CFG_NL;
  967. strcpy(connect_type, "(Loop)");
  968. break;
  969. }
  970. /* Save Host port and loop ID. */
  971. /* byte order - Big Endian */
  972. ha->d_id.b.domain = domain;
  973. ha->d_id.b.area = area;
  974. ha->d_id.b.al_pa = al_pa;
  975. if (!ha->flags.init_done)
  976. qla_printk(KERN_INFO, ha,
  977. "Topology - %s, Host Loop address 0x%x\n",
  978. connect_type, ha->loop_id);
  979. if (rval) {
  980. DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
  981. } else {
  982. DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
  983. }
  984. return(rval);
  985. }
  986. /*
  987. * NVRAM configuration for ISP 2xxx
  988. *
  989. * Input:
  990. * ha = adapter block pointer.
  991. *
  992. * Output:
  993. * initialization control block in response_ring
  994. * host adapters parameters in host adapter block
  995. *
  996. * Returns:
  997. * 0 = success.
  998. */
  999. int
  1000. qla2x00_nvram_config(scsi_qla_host_t *ha)
  1001. {
  1002. int rval;
  1003. uint8_t chksum = 0;
  1004. uint16_t cnt;
  1005. uint8_t *dptr1, *dptr2;
  1006. init_cb_t *icb = ha->init_cb;
  1007. nvram_t *nv = (nvram_t *)ha->request_ring;
  1008. uint16_t *wptr = (uint16_t *)ha->request_ring;
  1009. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1010. uint8_t timer_mode;
  1011. rval = QLA_SUCCESS;
  1012. /* Determine NVRAM starting address. */
  1013. ha->nvram_base = 0;
  1014. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
  1015. if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
  1016. ha->nvram_base = 0x80;
  1017. /* Get NVRAM data and calculate checksum. */
  1018. qla2x00_lock_nvram_access(ha);
  1019. for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
  1020. *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
  1021. (cnt+ha->nvram_base)));
  1022. chksum += (uint8_t)*wptr;
  1023. chksum += (uint8_t)(*wptr >> 8);
  1024. wptr++;
  1025. }
  1026. qla2x00_unlock_nvram_access(ha);
  1027. DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
  1028. DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
  1029. sizeof(nvram_t)));
  1030. /* Bad NVRAM data, set defaults parameters. */
  1031. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
  1032. nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
  1033. /* Reset NVRAM data. */
  1034. qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
  1035. "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
  1036. nv->nvram_version);
  1037. qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
  1038. "invalid -- WWPN) defaults.\n");
  1039. /*
  1040. * Set default initialization control block.
  1041. */
  1042. memset(nv, 0, sizeof(nvram_t));
  1043. nv->parameter_block_version = ICB_VERSION;
  1044. if (IS_QLA23XX(ha)) {
  1045. nv->firmware_options[0] = BIT_2 | BIT_1;
  1046. nv->firmware_options[1] = BIT_7 | BIT_5;
  1047. nv->add_firmware_options[0] = BIT_5;
  1048. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  1049. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  1050. nv->special_options[1] = BIT_7;
  1051. } else if (IS_QLA2200(ha)) {
  1052. nv->firmware_options[0] = BIT_2 | BIT_1;
  1053. nv->firmware_options[1] = BIT_7 | BIT_5;
  1054. nv->add_firmware_options[0] = BIT_5;
  1055. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  1056. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  1057. } else if (IS_QLA2100(ha)) {
  1058. nv->firmware_options[0] = BIT_3 | BIT_1;
  1059. nv->firmware_options[1] = BIT_5;
  1060. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  1061. }
  1062. nv->max_iocb_allocation = __constant_cpu_to_le16(256);
  1063. nv->execution_throttle = __constant_cpu_to_le16(16);
  1064. nv->retry_count = 8;
  1065. nv->retry_delay = 1;
  1066. nv->port_name[0] = 33;
  1067. nv->port_name[3] = 224;
  1068. nv->port_name[4] = 139;
  1069. nv->login_timeout = 4;
  1070. /*
  1071. * Set default host adapter parameters
  1072. */
  1073. nv->host_p[1] = BIT_2;
  1074. nv->reset_delay = 5;
  1075. nv->port_down_retry_count = 8;
  1076. nv->max_luns_per_target = __constant_cpu_to_le16(8);
  1077. nv->link_down_timeout = 60;
  1078. rval = 1;
  1079. }
  1080. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  1081. /*
  1082. * The SN2 does not provide BIOS emulation which means you can't change
  1083. * potentially bogus BIOS settings. Force the use of default settings
  1084. * for link rate and frame size. Hope that the rest of the settings
  1085. * are valid.
  1086. */
  1087. if (ia64_platform_is("sn2")) {
  1088. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  1089. if (IS_QLA23XX(ha))
  1090. nv->special_options[1] = BIT_7;
  1091. }
  1092. #endif
  1093. /* Reset Initialization control block */
  1094. memset(icb, 0, sizeof(init_cb_t));
  1095. /*
  1096. * Setup driver NVRAM options.
  1097. */
  1098. nv->firmware_options[0] |= (BIT_6 | BIT_1);
  1099. nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
  1100. nv->firmware_options[1] |= (BIT_5 | BIT_0);
  1101. nv->firmware_options[1] &= ~BIT_4;
  1102. if (IS_QLA23XX(ha)) {
  1103. nv->firmware_options[0] |= BIT_2;
  1104. nv->firmware_options[0] &= ~BIT_3;
  1105. if (IS_QLA2300(ha)) {
  1106. if (ha->fb_rev == FPM_2310) {
  1107. strcpy(ha->model_number, "QLA2310");
  1108. } else {
  1109. strcpy(ha->model_number, "QLA2300");
  1110. }
  1111. } else {
  1112. if (rval == 0 &&
  1113. memcmp(nv->model_number, BINZERO,
  1114. sizeof(nv->model_number)) != 0) {
  1115. char *st, *en;
  1116. strncpy(ha->model_number, nv->model_number,
  1117. sizeof(nv->model_number));
  1118. st = en = ha->model_number;
  1119. en += sizeof(nv->model_number) - 1;
  1120. while (en > st) {
  1121. if (*en != 0x20 && *en != 0x00)
  1122. break;
  1123. *en-- = '\0';
  1124. }
  1125. } else {
  1126. uint16_t index;
  1127. index = (ha->pdev->subsystem_device & 0xff);
  1128. if (index < QLA_MODEL_NAMES) {
  1129. strcpy(ha->model_number,
  1130. qla2x00_model_name[index]);
  1131. ha->model_desc =
  1132. qla2x00_model_desc[index];
  1133. } else {
  1134. strcpy(ha->model_number, "QLA23xx");
  1135. }
  1136. }
  1137. }
  1138. } else if (IS_QLA2200(ha)) {
  1139. nv->firmware_options[0] |= BIT_2;
  1140. /*
  1141. * 'Point-to-point preferred, else loop' is not a safe
  1142. * connection mode setting.
  1143. */
  1144. if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
  1145. (BIT_5 | BIT_4)) {
  1146. /* Force 'loop preferred, else point-to-point'. */
  1147. nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
  1148. nv->add_firmware_options[0] |= BIT_5;
  1149. }
  1150. strcpy(ha->model_number, "QLA22xx");
  1151. } else /*if (IS_QLA2100(ha))*/ {
  1152. strcpy(ha->model_number, "QLA2100");
  1153. }
  1154. /*
  1155. * Copy over NVRAM RISC parameter block to initialization control block.
  1156. */
  1157. dptr1 = (uint8_t *)icb;
  1158. dptr2 = (uint8_t *)&nv->parameter_block_version;
  1159. cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
  1160. while (cnt--)
  1161. *dptr1++ = *dptr2++;
  1162. /* Copy 2nd half. */
  1163. dptr1 = (uint8_t *)icb->add_firmware_options;
  1164. cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
  1165. while (cnt--)
  1166. *dptr1++ = *dptr2++;
  1167. /* Prepare nodename */
  1168. if ((icb->firmware_options[1] & BIT_6) == 0) {
  1169. /*
  1170. * Firmware will apply the following mask if the nodename was
  1171. * not provided.
  1172. */
  1173. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  1174. icb->node_name[0] &= 0xF0;
  1175. }
  1176. /*
  1177. * Set host adapter parameters.
  1178. */
  1179. ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
  1180. /* Always load RISC code on non ISP2[12]00 chips. */
  1181. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  1182. ha->flags.disable_risc_code_load = 0;
  1183. ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
  1184. ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
  1185. ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
  1186. ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0);
  1187. ha->operating_mode =
  1188. (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  1189. memcpy(ha->fw_seriallink_options, nv->seriallink_options,
  1190. sizeof(ha->fw_seriallink_options));
  1191. /* save HBA serial number */
  1192. ha->serial0 = icb->port_name[5];
  1193. ha->serial1 = icb->port_name[6];
  1194. ha->serial2 = icb->port_name[7];
  1195. ha->node_name = icb->node_name;
  1196. ha->port_name = icb->port_name;
  1197. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  1198. ha->retry_count = nv->retry_count;
  1199. /* Set minimum login_timeout to 4 seconds. */
  1200. if (nv->login_timeout < ql2xlogintimeout)
  1201. nv->login_timeout = ql2xlogintimeout;
  1202. if (nv->login_timeout < 4)
  1203. nv->login_timeout = 4;
  1204. ha->login_timeout = nv->login_timeout;
  1205. icb->login_timeout = nv->login_timeout;
  1206. /* Set minimum RATOV to 200 tenths of a second. */
  1207. ha->r_a_tov = 200;
  1208. ha->loop_reset_delay = nv->reset_delay;
  1209. /* Link Down Timeout = 0:
  1210. *
  1211. * When Port Down timer expires we will start returning
  1212. * I/O's to OS with "DID_NO_CONNECT".
  1213. *
  1214. * Link Down Timeout != 0:
  1215. *
  1216. * The driver waits for the link to come up after link down
  1217. * before returning I/Os to OS with "DID_NO_CONNECT".
  1218. */
  1219. if (nv->link_down_timeout == 0) {
  1220. ha->loop_down_abort_time =
  1221. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  1222. } else {
  1223. ha->link_down_timeout = nv->link_down_timeout;
  1224. ha->loop_down_abort_time =
  1225. (LOOP_DOWN_TIME - ha->link_down_timeout);
  1226. }
  1227. /*
  1228. * Need enough time to try and get the port back.
  1229. */
  1230. ha->port_down_retry_count = nv->port_down_retry_count;
  1231. if (qlport_down_retry)
  1232. ha->port_down_retry_count = qlport_down_retry;
  1233. /* Set login_retry_count */
  1234. ha->login_retry_count = nv->retry_count;
  1235. if (ha->port_down_retry_count == nv->port_down_retry_count &&
  1236. ha->port_down_retry_count > 3)
  1237. ha->login_retry_count = ha->port_down_retry_count;
  1238. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  1239. ha->login_retry_count = ha->port_down_retry_count;
  1240. if (ql2xloginretrycount)
  1241. ha->login_retry_count = ql2xloginretrycount;
  1242. icb->lun_enables = __constant_cpu_to_le16(0);
  1243. icb->command_resource_count = 0;
  1244. icb->immediate_notify_resource_count = 0;
  1245. icb->timeout = __constant_cpu_to_le16(0);
  1246. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1247. /* Enable RIO */
  1248. icb->firmware_options[0] &= ~BIT_3;
  1249. icb->add_firmware_options[0] &=
  1250. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1251. icb->add_firmware_options[0] |= BIT_2;
  1252. icb->response_accumulation_timer = 3;
  1253. icb->interrupt_delay_timer = 5;
  1254. ha->flags.process_response_queue = 1;
  1255. } else {
  1256. /* Enable ZIO -- Support mode 5 only. */
  1257. timer_mode = icb->add_firmware_options[0] &
  1258. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1259. icb->add_firmware_options[0] &=
  1260. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1261. if (ql2xenablezio)
  1262. timer_mode = BIT_2 | BIT_0;
  1263. if (timer_mode == (BIT_2 | BIT_0)) {
  1264. DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
  1265. "(%d).\n", ha->host_no, ql2xintrdelaytimer));
  1266. qla_printk(KERN_INFO, ha,
  1267. "ZIO enabled; timer delay (%d).\n",
  1268. ql2xintrdelaytimer);
  1269. icb->add_firmware_options[0] |= timer_mode;
  1270. icb->interrupt_delay_timer = ql2xintrdelaytimer;
  1271. ha->flags.process_response_queue = 1;
  1272. }
  1273. }
  1274. if (rval) {
  1275. DEBUG2_3(printk(KERN_WARNING
  1276. "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
  1277. }
  1278. return (rval);
  1279. }
  1280. /**
  1281. * qla2x00_alloc_fcport() - Allocate a generic fcport.
  1282. * @ha: HA context
  1283. * @flags: allocation flags
  1284. *
  1285. * Returns a pointer to the allocated fcport, or NULL, if none available.
  1286. */
  1287. fc_port_t *
  1288. qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
  1289. {
  1290. fc_port_t *fcport;
  1291. fcport = kmalloc(sizeof(fc_port_t), flags);
  1292. if (fcport == NULL)
  1293. return (fcport);
  1294. /* Setup fcport template structure. */
  1295. memset(fcport, 0, sizeof (fc_port_t));
  1296. fcport->ha = ha;
  1297. fcport->port_type = FCT_UNKNOWN;
  1298. fcport->loop_id = FC_NO_LOOP_ID;
  1299. fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
  1300. atomic_set(&fcport->state, FCS_UNCONFIGURED);
  1301. fcport->flags = FCF_RLC_SUPPORT;
  1302. return (fcport);
  1303. }
  1304. /*
  1305. * qla2x00_configure_loop
  1306. * Updates Fibre Channel Device Database with what is actually on loop.
  1307. *
  1308. * Input:
  1309. * ha = adapter block pointer.
  1310. *
  1311. * Returns:
  1312. * 0 = success.
  1313. * 1 = error.
  1314. * 2 = database was full and device was not configured.
  1315. */
  1316. static int
  1317. qla2x00_configure_loop(scsi_qla_host_t *ha)
  1318. {
  1319. int rval;
  1320. unsigned long flags, save_flags;
  1321. rval = QLA_SUCCESS;
  1322. /* Get Initiator ID */
  1323. if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
  1324. rval = qla2x00_configure_hba(ha);
  1325. if (rval != QLA_SUCCESS) {
  1326. DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
  1327. ha->host_no));
  1328. return (rval);
  1329. }
  1330. }
  1331. save_flags = flags = ha->dpc_flags;
  1332. DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
  1333. ha->host_no, flags));
  1334. /*
  1335. * If we have both an RSCN and PORT UPDATE pending then handle them
  1336. * both at the same time.
  1337. */
  1338. clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  1339. clear_bit(RSCN_UPDATE, &ha->dpc_flags);
  1340. /* Determine what we need to do */
  1341. if (ha->current_topology == ISP_CFG_FL &&
  1342. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  1343. ha->flags.rscn_queue_overflow = 1;
  1344. set_bit(RSCN_UPDATE, &flags);
  1345. } else if (ha->current_topology == ISP_CFG_F &&
  1346. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  1347. ha->flags.rscn_queue_overflow = 1;
  1348. set_bit(RSCN_UPDATE, &flags);
  1349. clear_bit(LOCAL_LOOP_UPDATE, &flags);
  1350. } else if (!ha->flags.online ||
  1351. (test_bit(ABORT_ISP_ACTIVE, &flags))) {
  1352. ha->flags.rscn_queue_overflow = 1;
  1353. set_bit(RSCN_UPDATE, &flags);
  1354. set_bit(LOCAL_LOOP_UPDATE, &flags);
  1355. }
  1356. if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
  1357. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1358. rval = QLA_FUNCTION_FAILED;
  1359. } else {
  1360. rval = qla2x00_configure_local_loop(ha);
  1361. }
  1362. }
  1363. if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
  1364. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1365. rval = QLA_FUNCTION_FAILED;
  1366. } else {
  1367. rval = qla2x00_configure_fabric(ha);
  1368. }
  1369. }
  1370. if (rval == QLA_SUCCESS) {
  1371. if (atomic_read(&ha->loop_down_timer) ||
  1372. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1373. rval = QLA_FUNCTION_FAILED;
  1374. } else {
  1375. atomic_set(&ha->loop_state, LOOP_READY);
  1376. DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
  1377. }
  1378. }
  1379. if (rval) {
  1380. DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
  1381. __func__, ha->host_no));
  1382. } else {
  1383. DEBUG3(printk("%s: exiting normally\n", __func__));
  1384. }
  1385. /* Restore state if a resync event occured during processing */
  1386. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
  1387. if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
  1388. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  1389. if (test_bit(RSCN_UPDATE, &save_flags))
  1390. set_bit(RSCN_UPDATE, &ha->dpc_flags);
  1391. }
  1392. return (rval);
  1393. }
  1394. /*
  1395. * qla2x00_configure_local_loop
  1396. * Updates Fibre Channel Device Database with local loop devices.
  1397. *
  1398. * Input:
  1399. * ha = adapter block pointer.
  1400. *
  1401. * Returns:
  1402. * 0 = success.
  1403. */
  1404. static int
  1405. qla2x00_configure_local_loop(scsi_qla_host_t *ha)
  1406. {
  1407. int rval, rval2;
  1408. int found_devs;
  1409. int found;
  1410. fc_port_t *fcport, *new_fcport;
  1411. uint16_t index;
  1412. uint16_t entries;
  1413. char *id_iter;
  1414. uint16_t loop_id;
  1415. uint8_t domain, area, al_pa;
  1416. found_devs = 0;
  1417. new_fcport = NULL;
  1418. entries = MAX_FIBRE_DEVICES;
  1419. DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
  1420. DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
  1421. /* Get list of logged in devices. */
  1422. memset(ha->gid_list, 0, GID_LIST_SIZE);
  1423. rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
  1424. &entries);
  1425. if (rval != QLA_SUCCESS)
  1426. goto cleanup_allocation;
  1427. DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
  1428. ha->host_no, entries));
  1429. DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
  1430. entries * sizeof(struct gid_list_info)));
  1431. /* Allocate temporary fcport for any new fcports discovered. */
  1432. new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
  1433. if (new_fcport == NULL) {
  1434. rval = QLA_MEMORY_ALLOC_FAILED;
  1435. goto cleanup_allocation;
  1436. }
  1437. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  1438. /*
  1439. * Mark local devices that were present with FCF_DEVICE_LOST for now.
  1440. */
  1441. list_for_each_entry(fcport, &ha->fcports, list) {
  1442. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  1443. fcport->port_type != FCT_BROADCAST &&
  1444. (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  1445. DEBUG(printk("scsi(%ld): Marking port lost, "
  1446. "loop_id=0x%04x\n",
  1447. ha->host_no, fcport->loop_id));
  1448. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1449. fcport->flags &= ~FCF_FARP_DONE;
  1450. }
  1451. }
  1452. /* Add devices to port list. */
  1453. id_iter = (char *)ha->gid_list;
  1454. for (index = 0; index < entries; index++) {
  1455. domain = ((struct gid_list_info *)id_iter)->domain;
  1456. area = ((struct gid_list_info *)id_iter)->area;
  1457. al_pa = ((struct gid_list_info *)id_iter)->al_pa;
  1458. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1459. loop_id = (uint16_t)
  1460. ((struct gid_list_info *)id_iter)->loop_id_2100;
  1461. else
  1462. loop_id = le16_to_cpu(
  1463. ((struct gid_list_info *)id_iter)->loop_id);
  1464. id_iter += ha->gid_list_info_size;
  1465. /* Bypass reserved domain fields. */
  1466. if ((domain & 0xf0) == 0xf0)
  1467. continue;
  1468. /* Bypass if not same domain and area of adapter. */
  1469. if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
  1470. continue;
  1471. /* Bypass invalid local loop ID. */
  1472. if (loop_id > LAST_LOCAL_LOOP_ID)
  1473. continue;
  1474. /* Fill in member data. */
  1475. new_fcport->d_id.b.domain = domain;
  1476. new_fcport->d_id.b.area = area;
  1477. new_fcport->d_id.b.al_pa = al_pa;
  1478. new_fcport->loop_id = loop_id;
  1479. rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
  1480. if (rval2 != QLA_SUCCESS) {
  1481. DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
  1482. "information -- get_port_database=%x, "
  1483. "loop_id=0x%04x\n",
  1484. ha->host_no, rval2, new_fcport->loop_id));
  1485. continue;
  1486. }
  1487. /* Check for matching device in port list. */
  1488. found = 0;
  1489. fcport = NULL;
  1490. list_for_each_entry(fcport, &ha->fcports, list) {
  1491. if (memcmp(new_fcport->port_name, fcport->port_name,
  1492. WWN_SIZE))
  1493. continue;
  1494. fcport->flags &= ~(FCF_FABRIC_DEVICE |
  1495. FCF_PERSISTENT_BOUND);
  1496. fcport->loop_id = new_fcport->loop_id;
  1497. fcport->port_type = new_fcport->port_type;
  1498. fcport->d_id.b24 = new_fcport->d_id.b24;
  1499. memcpy(fcport->node_name, new_fcport->node_name,
  1500. WWN_SIZE);
  1501. found++;
  1502. break;
  1503. }
  1504. if (!found) {
  1505. /* New device, add to fcports list. */
  1506. new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
  1507. list_add_tail(&new_fcport->list, &ha->fcports);
  1508. /* Allocate a new replacement fcport. */
  1509. fcport = new_fcport;
  1510. new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
  1511. if (new_fcport == NULL) {
  1512. rval = QLA_MEMORY_ALLOC_FAILED;
  1513. goto cleanup_allocation;
  1514. }
  1515. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  1516. }
  1517. qla2x00_update_fcport(ha, fcport);
  1518. found_devs++;
  1519. }
  1520. cleanup_allocation:
  1521. if (new_fcport)
  1522. kfree(new_fcport);
  1523. if (rval != QLA_SUCCESS) {
  1524. DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
  1525. "rval=%x\n", ha->host_no, rval));
  1526. }
  1527. if (found_devs) {
  1528. ha->device_flags |= DFLG_LOCAL_DEVICES;
  1529. ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
  1530. }
  1531. return (rval);
  1532. }
  1533. static void
  1534. qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
  1535. {
  1536. fc_port_t *fcport;
  1537. qla2x00_mark_all_devices_lost(ha);
  1538. list_for_each_entry(fcport, &ha->fcports, list) {
  1539. if (fcport->port_type != FCT_TARGET)
  1540. continue;
  1541. qla2x00_update_fcport(ha, fcport);
  1542. }
  1543. }
  1544. /*
  1545. * qla2x00_update_fcport
  1546. * Updates device on list.
  1547. *
  1548. * Input:
  1549. * ha = adapter block pointer.
  1550. * fcport = port structure pointer.
  1551. *
  1552. * Return:
  1553. * 0 - Success
  1554. * BIT_0 - error
  1555. *
  1556. * Context:
  1557. * Kernel context.
  1558. */
  1559. static void
  1560. qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
  1561. {
  1562. uint16_t index;
  1563. unsigned long flags;
  1564. srb_t *sp;
  1565. fcport->ha = ha;
  1566. fcport->login_retry = 0;
  1567. fcport->port_login_retry_count = ha->port_down_retry_count *
  1568. PORT_RETRY_TIME;
  1569. atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
  1570. PORT_RETRY_TIME);
  1571. fcport->flags &= ~FCF_LOGIN_NEEDED;
  1572. /*
  1573. * Check for outstanding cmd on tape Bypass LUN discovery if active
  1574. * command on tape.
  1575. */
  1576. if (fcport->flags & FCF_TAPE_PRESENT) {
  1577. spin_lock_irqsave(&ha->hardware_lock, flags);
  1578. for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
  1579. fc_port_t *sfcp;
  1580. if ((sp = ha->outstanding_cmds[index]) != 0) {
  1581. sfcp = sp->fcport;
  1582. if (sfcp == fcport) {
  1583. atomic_set(&fcport->state, FCS_ONLINE);
  1584. spin_unlock_irqrestore(
  1585. &ha->hardware_lock, flags);
  1586. return;
  1587. }
  1588. }
  1589. }
  1590. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1591. }
  1592. if (fcport->port_type == FCT_INITIATOR ||
  1593. fcport->port_type == FCT_BROADCAST)
  1594. fcport->device_type = TYPE_PROCESSOR;
  1595. atomic_set(&fcport->state, FCS_ONLINE);
  1596. if (ha->flags.init_done)
  1597. qla2x00_reg_remote_port(ha, fcport);
  1598. }
  1599. void
  1600. qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
  1601. {
  1602. struct fc_rport_identifiers rport_ids;
  1603. struct fc_rport *rport;
  1604. if (fcport->rport) {
  1605. fc_remote_port_unblock(fcport->rport);
  1606. return;
  1607. }
  1608. rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name);
  1609. rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name);
  1610. rport_ids.port_id = fcport->d_id.b.domain << 16 |
  1611. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1612. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  1613. if (fcport->port_type == FCT_INITIATOR)
  1614. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  1615. if (fcport->port_type == FCT_TARGET)
  1616. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  1617. fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
  1618. if (!rport)
  1619. qla_printk(KERN_WARNING, ha,
  1620. "Unable to allocate fc remote port!\n");
  1621. if (rport->scsi_target_id != -1 && rport->scsi_target_id < MAX_TARGETS)
  1622. fcport->os_target_id = rport->scsi_target_id;
  1623. rport->dd_data = fcport;
  1624. }
  1625. /*
  1626. * qla2x00_configure_fabric
  1627. * Setup SNS devices with loop ID's.
  1628. *
  1629. * Input:
  1630. * ha = adapter block pointer.
  1631. *
  1632. * Returns:
  1633. * 0 = success.
  1634. * BIT_0 = error
  1635. */
  1636. static int
  1637. qla2x00_configure_fabric(scsi_qla_host_t *ha)
  1638. {
  1639. int rval, rval2;
  1640. fc_port_t *fcport, *fcptemp;
  1641. uint16_t next_loopid;
  1642. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1643. LIST_HEAD(new_fcports);
  1644. /* If FL port exists, then SNS is present */
  1645. rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
  1646. if (rval != QLA_SUCCESS) {
  1647. DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
  1648. "Port\n", ha->host_no));
  1649. ha->device_flags &= ~SWITCH_FOUND;
  1650. return (QLA_SUCCESS);
  1651. }
  1652. /* Mark devices that need re-synchronization. */
  1653. rval2 = qla2x00_device_resync(ha);
  1654. if (rval2 == QLA_RSCNS_HANDLED) {
  1655. /* No point doing the scan, just continue. */
  1656. return (QLA_SUCCESS);
  1657. }
  1658. do {
  1659. /* Ensure we are logged into the SNS. */
  1660. ha->isp_ops.fabric_login(ha, SIMPLE_NAME_SERVER, 0xff, 0xff,
  1661. 0xfc, mb, BIT_1 | BIT_0);
  1662. if (mb[0] != MBS_COMMAND_COMPLETE) {
  1663. DEBUG2(qla_printk(KERN_INFO, ha,
  1664. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  1665. "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
  1666. mb[0], mb[1], mb[2], mb[6], mb[7]));
  1667. return (QLA_SUCCESS);
  1668. }
  1669. if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
  1670. if (qla2x00_rft_id(ha)) {
  1671. /* EMPTY */
  1672. DEBUG2(printk("scsi(%ld): Register FC-4 "
  1673. "TYPE failed.\n", ha->host_no));
  1674. }
  1675. if (qla2x00_rff_id(ha)) {
  1676. /* EMPTY */
  1677. DEBUG2(printk("scsi(%ld): Register FC-4 "
  1678. "Features failed.\n", ha->host_no));
  1679. }
  1680. if (qla2x00_rnn_id(ha)) {
  1681. /* EMPTY */
  1682. DEBUG2(printk("scsi(%ld): Register Node Name "
  1683. "failed.\n", ha->host_no));
  1684. } else if (qla2x00_rsnn_nn(ha)) {
  1685. /* EMPTY */
  1686. DEBUG2(printk("scsi(%ld): Register Symbolic "
  1687. "Node Name failed.\n", ha->host_no));
  1688. }
  1689. }
  1690. rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
  1691. if (rval != QLA_SUCCESS)
  1692. break;
  1693. /*
  1694. * Logout all previous fabric devices marked lost, except
  1695. * tape devices.
  1696. */
  1697. list_for_each_entry(fcport, &ha->fcports, list) {
  1698. if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1699. break;
  1700. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
  1701. continue;
  1702. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  1703. qla2x00_mark_device_lost(ha, fcport,
  1704. ql2xplogiabsentdevice);
  1705. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1706. (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
  1707. fcport->port_type != FCT_INITIATOR &&
  1708. fcport->port_type != FCT_BROADCAST) {
  1709. ha->isp_ops.fabric_logout(ha,
  1710. fcport->loop_id);
  1711. fcport->loop_id = FC_NO_LOOP_ID;
  1712. }
  1713. }
  1714. }
  1715. /* Starting free loop ID. */
  1716. next_loopid = ha->min_external_loopid;
  1717. /*
  1718. * Scan through our port list and login entries that need to be
  1719. * logged in.
  1720. */
  1721. list_for_each_entry(fcport, &ha->fcports, list) {
  1722. if (atomic_read(&ha->loop_down_timer) ||
  1723. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1724. break;
  1725. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  1726. (fcport->flags & FCF_LOGIN_NEEDED) == 0)
  1727. continue;
  1728. if (fcport->loop_id == FC_NO_LOOP_ID) {
  1729. fcport->loop_id = next_loopid;
  1730. rval = qla2x00_find_new_loop_id(ha, fcport);
  1731. if (rval != QLA_SUCCESS) {
  1732. /* Ran out of IDs to use */
  1733. break;
  1734. }
  1735. }
  1736. /* Login and update database */
  1737. qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
  1738. }
  1739. /* Exit if out of loop IDs. */
  1740. if (rval != QLA_SUCCESS) {
  1741. break;
  1742. }
  1743. /*
  1744. * Login and add the new devices to our port list.
  1745. */
  1746. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  1747. if (atomic_read(&ha->loop_down_timer) ||
  1748. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1749. break;
  1750. /* Find a new loop ID to use. */
  1751. fcport->loop_id = next_loopid;
  1752. rval = qla2x00_find_new_loop_id(ha, fcport);
  1753. if (rval != QLA_SUCCESS) {
  1754. /* Ran out of IDs to use */
  1755. break;
  1756. }
  1757. /* Remove device from the new list and add it to DB */
  1758. list_del(&fcport->list);
  1759. list_add_tail(&fcport->list, &ha->fcports);
  1760. /* Login and update database */
  1761. qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
  1762. }
  1763. } while (0);
  1764. /* Free all new device structures not processed. */
  1765. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  1766. list_del(&fcport->list);
  1767. kfree(fcport);
  1768. }
  1769. if (rval) {
  1770. DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
  1771. "rval=%d\n", ha->host_no, rval));
  1772. }
  1773. return (rval);
  1774. }
  1775. /*
  1776. * qla2x00_find_all_fabric_devs
  1777. *
  1778. * Input:
  1779. * ha = adapter block pointer.
  1780. * dev = database device entry pointer.
  1781. *
  1782. * Returns:
  1783. * 0 = success.
  1784. *
  1785. * Context:
  1786. * Kernel context.
  1787. */
  1788. static int
  1789. qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
  1790. {
  1791. int rval;
  1792. uint16_t loop_id;
  1793. fc_port_t *fcport, *new_fcport, *fcptemp;
  1794. int found;
  1795. sw_info_t *swl;
  1796. int swl_idx;
  1797. int first_dev, last_dev;
  1798. port_id_t wrap, nxt_d_id;
  1799. rval = QLA_SUCCESS;
  1800. /* Try GID_PT to get device list, else GAN. */
  1801. swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
  1802. if (swl == NULL) {
  1803. /*EMPTY*/
  1804. DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
  1805. "on GA_NXT\n", ha->host_no));
  1806. } else {
  1807. memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
  1808. if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
  1809. kfree(swl);
  1810. swl = NULL;
  1811. } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
  1812. kfree(swl);
  1813. swl = NULL;
  1814. } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
  1815. kfree(swl);
  1816. swl = NULL;
  1817. }
  1818. }
  1819. swl_idx = 0;
  1820. /* Allocate temporary fcport for any new fcports discovered. */
  1821. new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
  1822. if (new_fcport == NULL) {
  1823. if (swl)
  1824. kfree(swl);
  1825. return (QLA_MEMORY_ALLOC_FAILED);
  1826. }
  1827. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  1828. /* Set start port ID scan at adapter ID. */
  1829. first_dev = 1;
  1830. last_dev = 0;
  1831. /* Starting free loop ID. */
  1832. loop_id = ha->min_external_loopid;
  1833. for (; loop_id <= ha->last_loop_id; loop_id++) {
  1834. if (qla2x00_is_reserved_id(ha, loop_id))
  1835. continue;
  1836. if (atomic_read(&ha->loop_down_timer) ||
  1837. test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
  1838. break;
  1839. if (swl != NULL) {
  1840. if (last_dev) {
  1841. wrap.b24 = new_fcport->d_id.b24;
  1842. } else {
  1843. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  1844. memcpy(new_fcport->node_name,
  1845. swl[swl_idx].node_name, WWN_SIZE);
  1846. memcpy(new_fcport->port_name,
  1847. swl[swl_idx].port_name, WWN_SIZE);
  1848. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  1849. last_dev = 1;
  1850. }
  1851. swl_idx++;
  1852. }
  1853. } else {
  1854. /* Send GA_NXT to the switch */
  1855. rval = qla2x00_ga_nxt(ha, new_fcport);
  1856. if (rval != QLA_SUCCESS) {
  1857. qla_printk(KERN_WARNING, ha,
  1858. "SNS scan failed -- assuming zero-entry "
  1859. "result...\n");
  1860. list_for_each_entry_safe(fcport, fcptemp,
  1861. new_fcports, list) {
  1862. list_del(&fcport->list);
  1863. kfree(fcport);
  1864. }
  1865. rval = QLA_SUCCESS;
  1866. break;
  1867. }
  1868. }
  1869. /* If wrap on switch device list, exit. */
  1870. if (first_dev) {
  1871. wrap.b24 = new_fcport->d_id.b24;
  1872. first_dev = 0;
  1873. } else if (new_fcport->d_id.b24 == wrap.b24) {
  1874. DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
  1875. ha->host_no, new_fcport->d_id.b.domain,
  1876. new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
  1877. break;
  1878. }
  1879. /* Bypass if host adapter. */
  1880. if (new_fcport->d_id.b24 == ha->d_id.b24)
  1881. continue;
  1882. /* Bypass reserved domain fields. */
  1883. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  1884. continue;
  1885. /* Locate matching device in database. */
  1886. found = 0;
  1887. list_for_each_entry(fcport, &ha->fcports, list) {
  1888. if (memcmp(new_fcport->port_name, fcport->port_name,
  1889. WWN_SIZE))
  1890. continue;
  1891. found++;
  1892. /*
  1893. * If address the same and state FCS_ONLINE, nothing
  1894. * changed.
  1895. */
  1896. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  1897. atomic_read(&fcport->state) == FCS_ONLINE) {
  1898. break;
  1899. }
  1900. /*
  1901. * If device was not a fabric device before.
  1902. */
  1903. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  1904. fcport->d_id.b24 = new_fcport->d_id.b24;
  1905. fcport->loop_id = FC_NO_LOOP_ID;
  1906. fcport->flags |= (FCF_FABRIC_DEVICE |
  1907. FCF_LOGIN_NEEDED);
  1908. fcport->flags &= ~FCF_PERSISTENT_BOUND;
  1909. break;
  1910. }
  1911. /*
  1912. * Port ID changed or device was marked to be updated;
  1913. * Log it out if still logged in and mark it for
  1914. * relogin later.
  1915. */
  1916. fcport->d_id.b24 = new_fcport->d_id.b24;
  1917. fcport->flags |= FCF_LOGIN_NEEDED;
  1918. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1919. (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
  1920. fcport->port_type != FCT_INITIATOR &&
  1921. fcport->port_type != FCT_BROADCAST) {
  1922. ha->isp_ops.fabric_logout(ha, fcport->loop_id);
  1923. fcport->loop_id = FC_NO_LOOP_ID;
  1924. }
  1925. break;
  1926. }
  1927. if (found)
  1928. continue;
  1929. /* If device was not in our fcports list, then add it. */
  1930. list_add_tail(&new_fcport->list, new_fcports);
  1931. /* Allocate a new replacement fcport. */
  1932. nxt_d_id.b24 = new_fcport->d_id.b24;
  1933. new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
  1934. if (new_fcport == NULL) {
  1935. if (swl)
  1936. kfree(swl);
  1937. return (QLA_MEMORY_ALLOC_FAILED);
  1938. }
  1939. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  1940. new_fcport->d_id.b24 = nxt_d_id.b24;
  1941. }
  1942. if (swl)
  1943. kfree(swl);
  1944. if (new_fcport)
  1945. kfree(new_fcport);
  1946. if (!list_empty(new_fcports))
  1947. ha->device_flags |= DFLG_FABRIC_DEVICES;
  1948. return (rval);
  1949. }
  1950. /*
  1951. * qla2x00_find_new_loop_id
  1952. * Scan through our port list and find a new usable loop ID.
  1953. *
  1954. * Input:
  1955. * ha: adapter state pointer.
  1956. * dev: port structure pointer.
  1957. *
  1958. * Returns:
  1959. * qla2x00 local function return status code.
  1960. *
  1961. * Context:
  1962. * Kernel context.
  1963. */
  1964. int
  1965. qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
  1966. {
  1967. int rval;
  1968. int found;
  1969. fc_port_t *fcport;
  1970. uint16_t first_loop_id;
  1971. rval = QLA_SUCCESS;
  1972. /* Save starting loop ID. */
  1973. first_loop_id = dev->loop_id;
  1974. for (;;) {
  1975. /* Skip loop ID if already used by adapter. */
  1976. if (dev->loop_id == ha->loop_id) {
  1977. dev->loop_id++;
  1978. }
  1979. /* Skip reserved loop IDs. */
  1980. while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
  1981. dev->loop_id++;
  1982. }
  1983. /* Reset loop ID if passed the end. */
  1984. if (dev->loop_id > ha->last_loop_id) {
  1985. /* first loop ID. */
  1986. dev->loop_id = ha->min_external_loopid;
  1987. }
  1988. /* Check for loop ID being already in use. */
  1989. found = 0;
  1990. fcport = NULL;
  1991. list_for_each_entry(fcport, &ha->fcports, list) {
  1992. if (fcport->loop_id == dev->loop_id && fcport != dev) {
  1993. /* ID possibly in use */
  1994. found++;
  1995. break;
  1996. }
  1997. }
  1998. /* If not in use then it is free to use. */
  1999. if (!found) {
  2000. break;
  2001. }
  2002. /* ID in use. Try next value. */
  2003. dev->loop_id++;
  2004. /* If wrap around. No free ID to use. */
  2005. if (dev->loop_id == first_loop_id) {
  2006. dev->loop_id = FC_NO_LOOP_ID;
  2007. rval = QLA_FUNCTION_FAILED;
  2008. break;
  2009. }
  2010. }
  2011. return (rval);
  2012. }
  2013. /*
  2014. * qla2x00_device_resync
  2015. * Marks devices in the database that needs resynchronization.
  2016. *
  2017. * Input:
  2018. * ha = adapter block pointer.
  2019. *
  2020. * Context:
  2021. * Kernel context.
  2022. */
  2023. static int
  2024. qla2x00_device_resync(scsi_qla_host_t *ha)
  2025. {
  2026. int rval;
  2027. int rval2;
  2028. uint32_t mask;
  2029. fc_port_t *fcport;
  2030. uint32_t rscn_entry;
  2031. uint8_t rscn_out_iter;
  2032. uint8_t format;
  2033. port_id_t d_id;
  2034. rval = QLA_RSCNS_HANDLED;
  2035. while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
  2036. ha->flags.rscn_queue_overflow) {
  2037. rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
  2038. format = MSB(MSW(rscn_entry));
  2039. d_id.b.domain = LSB(MSW(rscn_entry));
  2040. d_id.b.area = MSB(LSW(rscn_entry));
  2041. d_id.b.al_pa = LSB(LSW(rscn_entry));
  2042. DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
  2043. "[%02x/%02x%02x%02x].\n",
  2044. ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
  2045. d_id.b.area, d_id.b.al_pa));
  2046. ha->rscn_out_ptr++;
  2047. if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
  2048. ha->rscn_out_ptr = 0;
  2049. /* Skip duplicate entries. */
  2050. for (rscn_out_iter = ha->rscn_out_ptr;
  2051. !ha->flags.rscn_queue_overflow &&
  2052. rscn_out_iter != ha->rscn_in_ptr;
  2053. rscn_out_iter = (rscn_out_iter ==
  2054. (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
  2055. if (rscn_entry != ha->rscn_queue[rscn_out_iter])
  2056. break;
  2057. DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
  2058. "entry found at [%d].\n", ha->host_no,
  2059. rscn_out_iter));
  2060. ha->rscn_out_ptr = rscn_out_iter;
  2061. }
  2062. /* Queue overflow, set switch default case. */
  2063. if (ha->flags.rscn_queue_overflow) {
  2064. DEBUG(printk("scsi(%ld): device_resync: rscn "
  2065. "overflow.\n", ha->host_no));
  2066. format = 3;
  2067. ha->flags.rscn_queue_overflow = 0;
  2068. }
  2069. switch (format) {
  2070. case 0:
  2071. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
  2072. !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
  2073. ha->flags.init_done) {
  2074. /* Handle port RSCN via asyncronous IOCBs */
  2075. rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
  2076. NULL, 0);
  2077. if (rval2 == QLA_SUCCESS)
  2078. continue;
  2079. }
  2080. mask = 0xffffff;
  2081. break;
  2082. case 1:
  2083. mask = 0xffff00;
  2084. break;
  2085. case 2:
  2086. mask = 0xff0000;
  2087. break;
  2088. default:
  2089. mask = 0x0;
  2090. d_id.b24 = 0;
  2091. ha->rscn_out_ptr = ha->rscn_in_ptr;
  2092. break;
  2093. }
  2094. rval = QLA_SUCCESS;
  2095. /* Abort any outstanding IO descriptors. */
  2096. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  2097. qla2x00_cancel_io_descriptors(ha);
  2098. list_for_each_entry(fcport, &ha->fcports, list) {
  2099. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  2100. (fcport->d_id.b24 & mask) != d_id.b24 ||
  2101. fcport->port_type == FCT_BROADCAST)
  2102. continue;
  2103. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2104. if (format != 3 ||
  2105. fcport->port_type != FCT_INITIATOR) {
  2106. qla2x00_mark_device_lost(ha, fcport, 0);
  2107. }
  2108. }
  2109. fcport->flags &= ~FCF_FARP_DONE;
  2110. }
  2111. }
  2112. return (rval);
  2113. }
  2114. /*
  2115. * qla2x00_fabric_dev_login
  2116. * Login fabric target device and update FC port database.
  2117. *
  2118. * Input:
  2119. * ha: adapter state pointer.
  2120. * fcport: port structure list pointer.
  2121. * next_loopid: contains value of a new loop ID that can be used
  2122. * by the next login attempt.
  2123. *
  2124. * Returns:
  2125. * qla2x00 local function return status code.
  2126. *
  2127. * Context:
  2128. * Kernel context.
  2129. */
  2130. static int
  2131. qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
  2132. uint16_t *next_loopid)
  2133. {
  2134. int rval;
  2135. int retry;
  2136. rval = QLA_SUCCESS;
  2137. retry = 0;
  2138. rval = qla2x00_fabric_login(ha, fcport, next_loopid);
  2139. if (rval == QLA_SUCCESS) {
  2140. rval = qla2x00_get_port_database(ha, fcport, 0);
  2141. if (rval != QLA_SUCCESS) {
  2142. ha->isp_ops.fabric_logout(ha, fcport->loop_id);
  2143. } else {
  2144. qla2x00_update_fcport(ha, fcport);
  2145. }
  2146. }
  2147. return (rval);
  2148. }
  2149. /*
  2150. * qla2x00_fabric_login
  2151. * Issue fabric login command.
  2152. *
  2153. * Input:
  2154. * ha = adapter block pointer.
  2155. * device = pointer to FC device type structure.
  2156. *
  2157. * Returns:
  2158. * 0 - Login successfully
  2159. * 1 - Login failed
  2160. * 2 - Initiator device
  2161. * 3 - Fatal error
  2162. */
  2163. int
  2164. qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
  2165. uint16_t *next_loopid)
  2166. {
  2167. int rval;
  2168. int retry;
  2169. uint16_t tmp_loopid;
  2170. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2171. retry = 0;
  2172. tmp_loopid = 0;
  2173. for (;;) {
  2174. DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
  2175. "for port %02x%02x%02x.\n",
  2176. ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
  2177. fcport->d_id.b.area, fcport->d_id.b.al_pa));
  2178. /* Login fcport on switch. */
  2179. ha->isp_ops.fabric_login(ha, fcport->loop_id,
  2180. fcport->d_id.b.domain, fcport->d_id.b.area,
  2181. fcport->d_id.b.al_pa, mb, BIT_0);
  2182. if (mb[0] == MBS_PORT_ID_USED) {
  2183. /*
  2184. * Device has another loop ID. The firmware team
  2185. * recommends us to perform an implicit login with the
  2186. * specified ID again. The ID we just used is save here
  2187. * so we return with an ID that can be tried by the
  2188. * next login.
  2189. */
  2190. retry++;
  2191. tmp_loopid = fcport->loop_id;
  2192. fcport->loop_id = mb[1];
  2193. DEBUG(printk("Fabric Login: port in use - next "
  2194. "loop id=0x%04x, port Id=%02x%02x%02x.\n",
  2195. fcport->loop_id, fcport->d_id.b.domain,
  2196. fcport->d_id.b.area, fcport->d_id.b.al_pa));
  2197. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  2198. /*
  2199. * Login succeeded.
  2200. */
  2201. if (retry) {
  2202. /* A retry occurred before. */
  2203. *next_loopid = tmp_loopid;
  2204. } else {
  2205. /*
  2206. * No retry occurred before. Just increment the
  2207. * ID value for next login.
  2208. */
  2209. *next_loopid = (fcport->loop_id + 1);
  2210. }
  2211. if (mb[1] & BIT_0) {
  2212. fcport->port_type = FCT_INITIATOR;
  2213. } else {
  2214. fcport->port_type = FCT_TARGET;
  2215. if (mb[1] & BIT_1) {
  2216. fcport->flags |= FCF_TAPE_PRESENT;
  2217. }
  2218. }
  2219. rval = QLA_SUCCESS;
  2220. break;
  2221. } else if (mb[0] == MBS_LOOP_ID_USED) {
  2222. /*
  2223. * Loop ID already used, try next loop ID.
  2224. */
  2225. fcport->loop_id++;
  2226. rval = qla2x00_find_new_loop_id(ha, fcport);
  2227. if (rval != QLA_SUCCESS) {
  2228. /* Ran out of loop IDs to use */
  2229. break;
  2230. }
  2231. } else if (mb[0] == MBS_COMMAND_ERROR) {
  2232. /*
  2233. * Firmware possibly timed out during login. If NO
  2234. * retries are left to do then the device is declared
  2235. * dead.
  2236. */
  2237. *next_loopid = fcport->loop_id;
  2238. ha->isp_ops.fabric_logout(ha, fcport->loop_id);
  2239. qla2x00_mark_device_lost(ha, fcport, 1);
  2240. rval = 1;
  2241. break;
  2242. } else {
  2243. /*
  2244. * unrecoverable / not handled error
  2245. */
  2246. DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
  2247. "loop_id=%x jiffies=%lx.\n",
  2248. __func__, ha->host_no, mb[0],
  2249. fcport->d_id.b.domain, fcport->d_id.b.area,
  2250. fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
  2251. *next_loopid = fcport->loop_id;
  2252. ha->isp_ops.fabric_logout(ha, fcport->loop_id);
  2253. fcport->loop_id = FC_NO_LOOP_ID;
  2254. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  2255. rval = 3;
  2256. break;
  2257. }
  2258. }
  2259. return (rval);
  2260. }
  2261. /*
  2262. * qla2x00_local_device_login
  2263. * Issue local device login command.
  2264. *
  2265. * Input:
  2266. * ha = adapter block pointer.
  2267. * loop_id = loop id of device to login to.
  2268. *
  2269. * Returns (Where's the #define!!!!):
  2270. * 0 - Login successfully
  2271. * 1 - Login failed
  2272. * 3 - Fatal error
  2273. */
  2274. int
  2275. qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
  2276. {
  2277. int rval;
  2278. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2279. memset(mb, 0, sizeof(mb));
  2280. rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
  2281. if (rval == QLA_SUCCESS) {
  2282. /* Interrogate mailbox registers for any errors */
  2283. if (mb[0] == MBS_COMMAND_ERROR)
  2284. rval = 1;
  2285. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  2286. /* device not in PCB table */
  2287. rval = 3;
  2288. }
  2289. return (rval);
  2290. }
  2291. /*
  2292. * qla2x00_loop_resync
  2293. * Resync with fibre channel devices.
  2294. *
  2295. * Input:
  2296. * ha = adapter block pointer.
  2297. *
  2298. * Returns:
  2299. * 0 = success
  2300. */
  2301. int
  2302. qla2x00_loop_resync(scsi_qla_host_t *ha)
  2303. {
  2304. int rval;
  2305. uint32_t wait_time;
  2306. rval = QLA_SUCCESS;
  2307. atomic_set(&ha->loop_state, LOOP_UPDATE);
  2308. clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
  2309. if (ha->flags.online) {
  2310. if (!(rval = qla2x00_fw_ready(ha))) {
  2311. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  2312. wait_time = 256;
  2313. do {
  2314. /* v2.19.05b6 */
  2315. atomic_set(&ha->loop_state, LOOP_UPDATE);
  2316. /*
  2317. * Issue marker command only when we are going
  2318. * to start the I/O .
  2319. */
  2320. ha->marker_needed = 1;
  2321. /* Remap devices on Loop. */
  2322. clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  2323. qla2x00_configure_loop(ha);
  2324. wait_time--;
  2325. } while (!atomic_read(&ha->loop_down_timer) &&
  2326. !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
  2327. wait_time &&
  2328. (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
  2329. }
  2330. }
  2331. if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
  2332. return (QLA_FUNCTION_FAILED);
  2333. }
  2334. if (rval) {
  2335. DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
  2336. }
  2337. return (rval);
  2338. }
  2339. void
  2340. qla2x00_rescan_fcports(scsi_qla_host_t *ha)
  2341. {
  2342. int rescan_done;
  2343. fc_port_t *fcport;
  2344. rescan_done = 0;
  2345. list_for_each_entry(fcport, &ha->fcports, list) {
  2346. if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
  2347. continue;
  2348. qla2x00_update_fcport(ha, fcport);
  2349. fcport->flags &= ~FCF_RESCAN_NEEDED;
  2350. rescan_done = 1;
  2351. }
  2352. qla2x00_probe_for_all_luns(ha);
  2353. }
  2354. /*
  2355. * qla2x00_abort_isp
  2356. * Resets ISP and aborts all outstanding commands.
  2357. *
  2358. * Input:
  2359. * ha = adapter block pointer.
  2360. *
  2361. * Returns:
  2362. * 0 = success
  2363. */
  2364. int
  2365. qla2x00_abort_isp(scsi_qla_host_t *ha)
  2366. {
  2367. unsigned long flags = 0;
  2368. uint16_t cnt;
  2369. srb_t *sp;
  2370. uint8_t status = 0;
  2371. if (ha->flags.online) {
  2372. ha->flags.online = 0;
  2373. clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  2374. qla_printk(KERN_INFO, ha,
  2375. "Performing ISP error recovery - ha= %p.\n", ha);
  2376. ha->isp_ops.reset_chip(ha);
  2377. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  2378. if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
  2379. atomic_set(&ha->loop_state, LOOP_DOWN);
  2380. qla2x00_mark_all_devices_lost(ha);
  2381. } else {
  2382. if (!atomic_read(&ha->loop_down_timer))
  2383. atomic_set(&ha->loop_down_timer,
  2384. LOOP_DOWN_TIME);
  2385. }
  2386. spin_lock_irqsave(&ha->hardware_lock, flags);
  2387. /* Requeue all commands in outstanding command list. */
  2388. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  2389. sp = ha->outstanding_cmds[cnt];
  2390. if (sp) {
  2391. ha->outstanding_cmds[cnt] = NULL;
  2392. sp->flags = 0;
  2393. sp->cmd->result = DID_RESET << 16;
  2394. sp->cmd->host_scribble = (unsigned char *)NULL;
  2395. qla2x00_sp_compl(ha, sp);
  2396. }
  2397. }
  2398. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2399. ha->isp_ops.nvram_config(ha);
  2400. if (!qla2x00_restart_isp(ha)) {
  2401. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  2402. if (!atomic_read(&ha->loop_down_timer)) {
  2403. /*
  2404. * Issue marker command only when we are going
  2405. * to start the I/O .
  2406. */
  2407. ha->marker_needed = 1;
  2408. }
  2409. ha->flags.online = 1;
  2410. ha->isp_ops.enable_intrs(ha);
  2411. ha->isp_abort_cnt = 0;
  2412. clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
  2413. } else { /* failed the ISP abort */
  2414. ha->flags.online = 1;
  2415. if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
  2416. if (ha->isp_abort_cnt == 0) {
  2417. qla_printk(KERN_WARNING, ha,
  2418. "ISP error recovery failed - "
  2419. "board disabled\n");
  2420. /*
  2421. * The next call disables the board
  2422. * completely.
  2423. */
  2424. ha->isp_ops.reset_adapter(ha);
  2425. ha->flags.online = 0;
  2426. clear_bit(ISP_ABORT_RETRY,
  2427. &ha->dpc_flags);
  2428. status = 0;
  2429. } else { /* schedule another ISP abort */
  2430. ha->isp_abort_cnt--;
  2431. DEBUG(printk("qla%ld: ISP abort - "
  2432. "retry remainning %d\n",
  2433. ha->host_no, ha->isp_abort_cnt);)
  2434. status = 1;
  2435. }
  2436. } else {
  2437. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  2438. DEBUG(printk("qla2x00(%ld): ISP error recovery "
  2439. "- retrying (%d) more times\n",
  2440. ha->host_no, ha->isp_abort_cnt);)
  2441. set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
  2442. status = 1;
  2443. }
  2444. }
  2445. }
  2446. if (status) {
  2447. qla_printk(KERN_INFO, ha,
  2448. "qla2x00_abort_isp: **** FAILED ****\n");
  2449. } else {
  2450. DEBUG(printk(KERN_INFO
  2451. "qla2x00_abort_isp(%ld): exiting.\n",
  2452. ha->host_no);)
  2453. }
  2454. return(status);
  2455. }
  2456. /*
  2457. * qla2x00_restart_isp
  2458. * restarts the ISP after a reset
  2459. *
  2460. * Input:
  2461. * ha = adapter block pointer.
  2462. *
  2463. * Returns:
  2464. * 0 = success
  2465. */
  2466. static int
  2467. qla2x00_restart_isp(scsi_qla_host_t *ha)
  2468. {
  2469. uint8_t status = 0;
  2470. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2471. unsigned long flags = 0;
  2472. uint32_t wait_time;
  2473. /* If firmware needs to be loaded */
  2474. if (qla2x00_isp_firmware(ha)) {
  2475. ha->flags.online = 0;
  2476. if (!(status = ha->isp_ops.chip_diag(ha))) {
  2477. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2478. status = qla2x00_setup_chip(ha);
  2479. goto done;
  2480. }
  2481. spin_lock_irqsave(&ha->hardware_lock, flags);
  2482. /* Disable SRAM, Instruction RAM and GP RAM parity. */
  2483. WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
  2484. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  2485. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2486. status = qla2x00_setup_chip(ha);
  2487. spin_lock_irqsave(&ha->hardware_lock, flags);
  2488. /* Enable proper parity */
  2489. if (IS_QLA2300(ha))
  2490. /* SRAM parity */
  2491. WRT_REG_WORD(&reg->hccr,
  2492. (HCCR_ENABLE_PARITY + 0x1));
  2493. else
  2494. /* SRAM, Instruction RAM and GP RAM parity */
  2495. WRT_REG_WORD(&reg->hccr,
  2496. (HCCR_ENABLE_PARITY + 0x7));
  2497. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  2498. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2499. }
  2500. }
  2501. done:
  2502. if (!status && !(status = qla2x00_init_rings(ha))) {
  2503. clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
  2504. if (!(status = qla2x00_fw_ready(ha))) {
  2505. DEBUG(printk("%s(): Start configure loop, "
  2506. "status = %d\n",
  2507. __func__,
  2508. status);)
  2509. ha->flags.online = 1;
  2510. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  2511. wait_time = 256;
  2512. do {
  2513. clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  2514. qla2x00_configure_loop(ha);
  2515. wait_time--;
  2516. } while (!atomic_read(&ha->loop_down_timer) &&
  2517. !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
  2518. wait_time &&
  2519. (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
  2520. }
  2521. /* if no cable then assume it's good */
  2522. if ((ha->device_flags & DFLG_NO_CABLE))
  2523. status = 0;
  2524. DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
  2525. __func__,
  2526. status);)
  2527. }
  2528. return (status);
  2529. }
  2530. /*
  2531. * qla2x00_reset_adapter
  2532. * Reset adapter.
  2533. *
  2534. * Input:
  2535. * ha = adapter block pointer.
  2536. */
  2537. void
  2538. qla2x00_reset_adapter(scsi_qla_host_t *ha)
  2539. {
  2540. unsigned long flags = 0;
  2541. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2542. ha->flags.online = 0;
  2543. ha->isp_ops.disable_intrs(ha);
  2544. /* Reset RISC processor. */
  2545. spin_lock_irqsave(&ha->hardware_lock, flags);
  2546. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  2547. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  2548. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  2549. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  2550. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2551. }