qla_init.c 102 KB

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