qla_init.c 105 KB

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