qla_init.c 74 KB

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