qla_init.c 105 KB

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