qla_init.c 100 KB

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