qla_init.c 99 KB

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