qla_init.c 104 KB

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