qla_init.c 102 KB

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