qla_init.c 95 KB

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