qla_init.c 100 KB

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