qla_init.c 100 KB

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