qla_init.c 75 KB

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