qla_init.c 95 KB

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