qla_init.c 95 KB

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