qla_init.c 104 KB

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