qla_mbx.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/delay.h>
  9. /*
  10. * qla2x00_mailbox_command
  11. * Issue mailbox command and waits for completion.
  12. *
  13. * Input:
  14. * ha = adapter block pointer.
  15. * mcp = driver internal mbx struct pointer.
  16. *
  17. * Output:
  18. * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
  19. *
  20. * Returns:
  21. * 0 : QLA_SUCCESS = cmd performed success
  22. * 1 : QLA_FUNCTION_FAILED (error encountered)
  23. * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
  24. *
  25. * Context:
  26. * Kernel context.
  27. */
  28. static int
  29. qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
  30. {
  31. int rval;
  32. unsigned long flags = 0;
  33. device_reg_t __iomem *reg;
  34. uint8_t abort_active;
  35. uint8_t io_lock_on;
  36. uint16_t command;
  37. uint16_t *iptr;
  38. uint16_t __iomem *optr;
  39. uint32_t cnt;
  40. uint32_t mboxes;
  41. unsigned long wait_time;
  42. struct qla_hw_data *ha = vha->hw;
  43. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  44. if (ha->pdev->error_state > pci_channel_io_frozen)
  45. return QLA_FUNCTION_TIMEOUT;
  46. reg = ha->iobase;
  47. io_lock_on = base_vha->flags.init_done;
  48. rval = QLA_SUCCESS;
  49. abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  50. DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
  51. /*
  52. * Wait for active mailbox commands to finish by waiting at most tov
  53. * seconds. This is to serialize actual issuing of mailbox cmds during
  54. * non ISP abort time.
  55. */
  56. if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
  57. /* Timeout occurred. Return error. */
  58. DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
  59. "Exiting.\n", __func__, base_vha->host_no));
  60. return QLA_FUNCTION_TIMEOUT;
  61. }
  62. ha->flags.mbox_busy = 1;
  63. /* Save mailbox command for debug */
  64. ha->mcp = mcp;
  65. DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
  66. base_vha->host_no, mcp->mb[0]));
  67. spin_lock_irqsave(&ha->hardware_lock, flags);
  68. /* Load mailbox registers. */
  69. if (IS_FWI2_CAPABLE(ha))
  70. optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
  71. else
  72. optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
  73. iptr = mcp->mb;
  74. command = mcp->mb[0];
  75. mboxes = mcp->out_mb;
  76. for (cnt = 0; cnt < ha->mbx_count; cnt++) {
  77. if (IS_QLA2200(ha) && cnt == 8)
  78. optr =
  79. (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
  80. if (mboxes & BIT_0)
  81. WRT_REG_WORD(optr, *iptr);
  82. mboxes >>= 1;
  83. optr++;
  84. iptr++;
  85. }
  86. #if defined(QL_DEBUG_LEVEL_1)
  87. printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
  88. __func__, base_vha->host_no);
  89. qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
  90. printk("\n");
  91. qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
  92. printk("\n");
  93. qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
  94. printk("\n");
  95. printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
  96. optr);
  97. qla2x00_dump_regs(base_vha);
  98. #endif
  99. /* Issue set host interrupt command to send cmd out. */
  100. ha->flags.mbox_int = 0;
  101. clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  102. /* Unlock mbx registers and wait for interrupt */
  103. DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
  104. "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies));
  105. /* Wait for mbx cmd completion until timeout */
  106. if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
  107. set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
  108. if (IS_FWI2_CAPABLE(ha))
  109. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
  110. else
  111. WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
  112. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  113. wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
  114. clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
  115. } else {
  116. DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
  117. base_vha->host_no, command));
  118. if (IS_FWI2_CAPABLE(ha))
  119. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
  120. else
  121. WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
  122. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  123. wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
  124. while (!ha->flags.mbox_int) {
  125. if (time_after(jiffies, wait_time))
  126. break;
  127. /* Check for pending interrupts. */
  128. qla2x00_poll(ha->rsp_q_map[0]);
  129. if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
  130. !ha->flags.mbox_int)
  131. msleep(10);
  132. } /* while */
  133. }
  134. /* Check whether we timed out */
  135. if (ha->flags.mbox_int) {
  136. uint16_t *iptr2;
  137. DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
  138. base_vha->host_no, command));
  139. /* Got interrupt. Clear the flag. */
  140. ha->flags.mbox_int = 0;
  141. clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  142. if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
  143. rval = QLA_FUNCTION_FAILED;
  144. /* Load return mailbox registers. */
  145. iptr2 = mcp->mb;
  146. iptr = (uint16_t *)&ha->mailbox_out[0];
  147. mboxes = mcp->in_mb;
  148. for (cnt = 0; cnt < ha->mbx_count; cnt++) {
  149. if (mboxes & BIT_0)
  150. *iptr2 = *iptr;
  151. mboxes >>= 1;
  152. iptr2++;
  153. iptr++;
  154. }
  155. } else {
  156. #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
  157. defined(QL_DEBUG_LEVEL_11)
  158. uint16_t mb0;
  159. uint32_t ictrl;
  160. if (IS_FWI2_CAPABLE(ha)) {
  161. mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
  162. ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
  163. } else {
  164. mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
  165. ictrl = RD_REG_WORD(&reg->isp.ictrl);
  166. }
  167. printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
  168. __func__, base_vha->host_no, command);
  169. printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
  170. base_vha->host_no, ictrl, jiffies);
  171. printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
  172. base_vha->host_no, mb0);
  173. qla2x00_dump_regs(base_vha);
  174. #endif
  175. rval = QLA_FUNCTION_TIMEOUT;
  176. }
  177. ha->flags.mbox_busy = 0;
  178. /* Clean up */
  179. ha->mcp = NULL;
  180. if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
  181. DEBUG11(printk("%s(%ld): checking for additional resp "
  182. "interrupt.\n", __func__, base_vha->host_no));
  183. /* polling mode for non isp_abort commands. */
  184. qla2x00_poll(ha->rsp_q_map[0]);
  185. }
  186. if (rval == QLA_FUNCTION_TIMEOUT &&
  187. mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
  188. if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
  189. /* not in dpc. schedule it for dpc to take over. */
  190. DEBUG(printk("%s(%ld): timeout schedule "
  191. "isp_abort_needed.\n", __func__,
  192. base_vha->host_no));
  193. DEBUG2_3_11(printk("%s(%ld): timeout schedule "
  194. "isp_abort_needed.\n", __func__,
  195. base_vha->host_no));
  196. qla_printk(KERN_WARNING, ha,
  197. "Mailbox command timeout occurred. Scheduling ISP "
  198. "abort.\n");
  199. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  200. qla2xxx_wake_dpc(vha);
  201. } else if (!abort_active) {
  202. /* call abort directly since we are in the DPC thread */
  203. DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
  204. __func__, base_vha->host_no));
  205. DEBUG2_3_11(printk("%s(%ld): timeout calling "
  206. "abort_isp\n", __func__, base_vha->host_no));
  207. qla_printk(KERN_WARNING, ha,
  208. "Mailbox command timeout occurred. Issuing ISP "
  209. "abort.\n");
  210. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  211. clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  212. if (qla2x00_abort_isp(base_vha)) {
  213. /* Failed. retry later. */
  214. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  215. }
  216. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  217. DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
  218. base_vha->host_no));
  219. DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
  220. __func__, base_vha->host_no));
  221. }
  222. }
  223. /* Allow next mbx cmd to come in. */
  224. complete(&ha->mbx_cmd_comp);
  225. if (rval) {
  226. DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
  227. "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
  228. mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
  229. } else {
  230. DEBUG11(printk("%s(%ld): done.\n", __func__,
  231. base_vha->host_no));
  232. }
  233. return rval;
  234. }
  235. int
  236. qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
  237. uint32_t risc_code_size)
  238. {
  239. int rval;
  240. struct qla_hw_data *ha = vha->hw;
  241. mbx_cmd_t mc;
  242. mbx_cmd_t *mcp = &mc;
  243. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  244. if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
  245. mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
  246. mcp->mb[8] = MSW(risc_addr);
  247. mcp->out_mb = MBX_8|MBX_0;
  248. } else {
  249. mcp->mb[0] = MBC_LOAD_RISC_RAM;
  250. mcp->out_mb = MBX_0;
  251. }
  252. mcp->mb[1] = LSW(risc_addr);
  253. mcp->mb[2] = MSW(req_dma);
  254. mcp->mb[3] = LSW(req_dma);
  255. mcp->mb[6] = MSW(MSD(req_dma));
  256. mcp->mb[7] = LSW(MSD(req_dma));
  257. mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
  258. if (IS_FWI2_CAPABLE(ha)) {
  259. mcp->mb[4] = MSW(risc_code_size);
  260. mcp->mb[5] = LSW(risc_code_size);
  261. mcp->out_mb |= MBX_5|MBX_4;
  262. } else {
  263. mcp->mb[4] = LSW(risc_code_size);
  264. mcp->out_mb |= MBX_4;
  265. }
  266. mcp->in_mb = MBX_0;
  267. mcp->tov = MBX_TOV_SECONDS;
  268. mcp->flags = 0;
  269. rval = qla2x00_mailbox_command(vha, mcp);
  270. if (rval != QLA_SUCCESS) {
  271. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  272. vha->host_no, rval, mcp->mb[0]));
  273. } else {
  274. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  275. }
  276. return rval;
  277. }
  278. /*
  279. * qla2x00_execute_fw
  280. * Start adapter firmware.
  281. *
  282. * Input:
  283. * ha = adapter block pointer.
  284. * TARGET_QUEUE_LOCK must be released.
  285. * ADAPTER_STATE_LOCK must be released.
  286. *
  287. * Returns:
  288. * qla2x00 local function return status code.
  289. *
  290. * Context:
  291. * Kernel context.
  292. */
  293. int
  294. qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
  295. {
  296. int rval;
  297. struct qla_hw_data *ha = vha->hw;
  298. mbx_cmd_t mc;
  299. mbx_cmd_t *mcp = &mc;
  300. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  301. mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
  302. mcp->out_mb = MBX_0;
  303. mcp->in_mb = MBX_0;
  304. if (IS_FWI2_CAPABLE(ha)) {
  305. mcp->mb[1] = MSW(risc_addr);
  306. mcp->mb[2] = LSW(risc_addr);
  307. mcp->mb[3] = 0;
  308. mcp->mb[4] = 0;
  309. mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
  310. mcp->in_mb |= MBX_1;
  311. } else {
  312. mcp->mb[1] = LSW(risc_addr);
  313. mcp->out_mb |= MBX_1;
  314. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  315. mcp->mb[2] = 0;
  316. mcp->out_mb |= MBX_2;
  317. }
  318. }
  319. mcp->tov = MBX_TOV_SECONDS;
  320. mcp->flags = 0;
  321. rval = qla2x00_mailbox_command(vha, mcp);
  322. if (rval != QLA_SUCCESS) {
  323. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  324. vha->host_no, rval, mcp->mb[0]));
  325. } else {
  326. if (IS_FWI2_CAPABLE(ha)) {
  327. DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
  328. __func__, vha->host_no, mcp->mb[1]));
  329. } else {
  330. DEBUG11(printk("%s(%ld): done.\n", __func__,
  331. vha->host_no));
  332. }
  333. }
  334. return rval;
  335. }
  336. /*
  337. * qla2x00_get_fw_version
  338. * Get firmware version.
  339. *
  340. * Input:
  341. * ha: adapter state pointer.
  342. * major: pointer for major number.
  343. * minor: pointer for minor number.
  344. * subminor: pointer for subminor number.
  345. *
  346. * Returns:
  347. * qla2x00 local function return status code.
  348. *
  349. * Context:
  350. * Kernel context.
  351. */
  352. int
  353. qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
  354. uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
  355. uint32_t *mpi_caps, uint8_t *phy)
  356. {
  357. int rval;
  358. mbx_cmd_t mc;
  359. mbx_cmd_t *mcp = &mc;
  360. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  361. mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
  362. mcp->out_mb = MBX_0;
  363. mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  364. if (IS_QLA81XX(vha->hw))
  365. mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
  366. mcp->flags = 0;
  367. mcp->tov = MBX_TOV_SECONDS;
  368. rval = qla2x00_mailbox_command(vha, mcp);
  369. if (rval != QLA_SUCCESS)
  370. goto failed;
  371. /* Return mailbox data. */
  372. *major = mcp->mb[1];
  373. *minor = mcp->mb[2];
  374. *subminor = mcp->mb[3];
  375. *attributes = mcp->mb[6];
  376. if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
  377. *memory = 0x1FFFF; /* Defaults to 128KB. */
  378. else
  379. *memory = (mcp->mb[5] << 16) | mcp->mb[4];
  380. if (IS_QLA81XX(vha->hw)) {
  381. mpi[0] = mcp->mb[10] & 0xff;
  382. mpi[1] = mcp->mb[11] >> 8;
  383. mpi[2] = mcp->mb[11] & 0xff;
  384. *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
  385. phy[0] = mcp->mb[8] & 0xff;
  386. phy[1] = mcp->mb[9] >> 8;
  387. phy[2] = mcp->mb[9] & 0xff;
  388. }
  389. failed:
  390. if (rval != QLA_SUCCESS) {
  391. /*EMPTY*/
  392. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  393. vha->host_no, rval));
  394. } else {
  395. /*EMPTY*/
  396. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  397. }
  398. return rval;
  399. }
  400. /*
  401. * qla2x00_get_fw_options
  402. * Set firmware options.
  403. *
  404. * Input:
  405. * ha = adapter block pointer.
  406. * fwopt = pointer for firmware options.
  407. *
  408. * Returns:
  409. * qla2x00 local function return status code.
  410. *
  411. * Context:
  412. * Kernel context.
  413. */
  414. int
  415. qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
  416. {
  417. int rval;
  418. mbx_cmd_t mc;
  419. mbx_cmd_t *mcp = &mc;
  420. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  421. mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
  422. mcp->out_mb = MBX_0;
  423. mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  424. mcp->tov = MBX_TOV_SECONDS;
  425. mcp->flags = 0;
  426. rval = qla2x00_mailbox_command(vha, mcp);
  427. if (rval != QLA_SUCCESS) {
  428. /*EMPTY*/
  429. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  430. vha->host_no, rval));
  431. } else {
  432. fwopts[0] = mcp->mb[0];
  433. fwopts[1] = mcp->mb[1];
  434. fwopts[2] = mcp->mb[2];
  435. fwopts[3] = mcp->mb[3];
  436. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  437. }
  438. return rval;
  439. }
  440. /*
  441. * qla2x00_set_fw_options
  442. * Set firmware options.
  443. *
  444. * Input:
  445. * ha = adapter block pointer.
  446. * fwopt = pointer for firmware options.
  447. *
  448. * Returns:
  449. * qla2x00 local function return status code.
  450. *
  451. * Context:
  452. * Kernel context.
  453. */
  454. int
  455. qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
  456. {
  457. int rval;
  458. mbx_cmd_t mc;
  459. mbx_cmd_t *mcp = &mc;
  460. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  461. mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
  462. mcp->mb[1] = fwopts[1];
  463. mcp->mb[2] = fwopts[2];
  464. mcp->mb[3] = fwopts[3];
  465. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  466. mcp->in_mb = MBX_0;
  467. if (IS_FWI2_CAPABLE(vha->hw)) {
  468. mcp->in_mb |= MBX_1;
  469. } else {
  470. mcp->mb[10] = fwopts[10];
  471. mcp->mb[11] = fwopts[11];
  472. mcp->mb[12] = 0; /* Undocumented, but used */
  473. mcp->out_mb |= MBX_12|MBX_11|MBX_10;
  474. }
  475. mcp->tov = MBX_TOV_SECONDS;
  476. mcp->flags = 0;
  477. rval = qla2x00_mailbox_command(vha, mcp);
  478. fwopts[0] = mcp->mb[0];
  479. if (rval != QLA_SUCCESS) {
  480. /*EMPTY*/
  481. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
  482. vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  483. } else {
  484. /*EMPTY*/
  485. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  486. }
  487. return rval;
  488. }
  489. /*
  490. * qla2x00_mbx_reg_test
  491. * Mailbox register wrap test.
  492. *
  493. * Input:
  494. * ha = adapter block pointer.
  495. * TARGET_QUEUE_LOCK must be released.
  496. * ADAPTER_STATE_LOCK must be released.
  497. *
  498. * Returns:
  499. * qla2x00 local function return status code.
  500. *
  501. * Context:
  502. * Kernel context.
  503. */
  504. int
  505. qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
  506. {
  507. int rval;
  508. mbx_cmd_t mc;
  509. mbx_cmd_t *mcp = &mc;
  510. DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
  511. mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
  512. mcp->mb[1] = 0xAAAA;
  513. mcp->mb[2] = 0x5555;
  514. mcp->mb[3] = 0xAA55;
  515. mcp->mb[4] = 0x55AA;
  516. mcp->mb[5] = 0xA5A5;
  517. mcp->mb[6] = 0x5A5A;
  518. mcp->mb[7] = 0x2525;
  519. mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  520. mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  521. mcp->tov = MBX_TOV_SECONDS;
  522. mcp->flags = 0;
  523. rval = qla2x00_mailbox_command(vha, mcp);
  524. if (rval == QLA_SUCCESS) {
  525. if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
  526. mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
  527. rval = QLA_FUNCTION_FAILED;
  528. if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
  529. mcp->mb[7] != 0x2525)
  530. rval = QLA_FUNCTION_FAILED;
  531. }
  532. if (rval != QLA_SUCCESS) {
  533. /*EMPTY*/
  534. DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
  535. vha->host_no, rval));
  536. } else {
  537. /*EMPTY*/
  538. DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
  539. vha->host_no));
  540. }
  541. return rval;
  542. }
  543. /*
  544. * qla2x00_verify_checksum
  545. * Verify firmware checksum.
  546. *
  547. * Input:
  548. * ha = adapter block pointer.
  549. * TARGET_QUEUE_LOCK must be released.
  550. * ADAPTER_STATE_LOCK must be released.
  551. *
  552. * Returns:
  553. * qla2x00 local function return status code.
  554. *
  555. * Context:
  556. * Kernel context.
  557. */
  558. int
  559. qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
  560. {
  561. int rval;
  562. mbx_cmd_t mc;
  563. mbx_cmd_t *mcp = &mc;
  564. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  565. mcp->mb[0] = MBC_VERIFY_CHECKSUM;
  566. mcp->out_mb = MBX_0;
  567. mcp->in_mb = MBX_0;
  568. if (IS_FWI2_CAPABLE(vha->hw)) {
  569. mcp->mb[1] = MSW(risc_addr);
  570. mcp->mb[2] = LSW(risc_addr);
  571. mcp->out_mb |= MBX_2|MBX_1;
  572. mcp->in_mb |= MBX_2|MBX_1;
  573. } else {
  574. mcp->mb[1] = LSW(risc_addr);
  575. mcp->out_mb |= MBX_1;
  576. mcp->in_mb |= MBX_1;
  577. }
  578. mcp->tov = MBX_TOV_SECONDS;
  579. mcp->flags = 0;
  580. rval = qla2x00_mailbox_command(vha, mcp);
  581. if (rval != QLA_SUCCESS) {
  582. DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
  583. vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
  584. (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
  585. } else {
  586. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  587. }
  588. return rval;
  589. }
  590. /*
  591. * qla2x00_issue_iocb
  592. * Issue IOCB using mailbox command
  593. *
  594. * Input:
  595. * ha = adapter state pointer.
  596. * buffer = buffer pointer.
  597. * phys_addr = physical address of buffer.
  598. * size = size of buffer.
  599. * TARGET_QUEUE_LOCK must be released.
  600. * ADAPTER_STATE_LOCK must be released.
  601. *
  602. * Returns:
  603. * qla2x00 local function return status code.
  604. *
  605. * Context:
  606. * Kernel context.
  607. */
  608. static int
  609. qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
  610. dma_addr_t phys_addr, size_t size, uint32_t tov)
  611. {
  612. int rval;
  613. mbx_cmd_t mc;
  614. mbx_cmd_t *mcp = &mc;
  615. mcp->mb[0] = MBC_IOCB_COMMAND_A64;
  616. mcp->mb[1] = 0;
  617. mcp->mb[2] = MSW(phys_addr);
  618. mcp->mb[3] = LSW(phys_addr);
  619. mcp->mb[6] = MSW(MSD(phys_addr));
  620. mcp->mb[7] = LSW(MSD(phys_addr));
  621. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  622. mcp->in_mb = MBX_2|MBX_0;
  623. mcp->tov = tov;
  624. mcp->flags = 0;
  625. rval = qla2x00_mailbox_command(vha, mcp);
  626. if (rval != QLA_SUCCESS) {
  627. /*EMPTY*/
  628. DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
  629. vha->host_no, rval));
  630. } else {
  631. sts_entry_t *sts_entry = (sts_entry_t *) buffer;
  632. /* Mask reserved bits. */
  633. sts_entry->entry_status &=
  634. IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
  635. }
  636. return rval;
  637. }
  638. int
  639. qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
  640. size_t size)
  641. {
  642. return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
  643. MBX_TOV_SECONDS);
  644. }
  645. /*
  646. * qla2x00_abort_command
  647. * Abort command aborts a specified IOCB.
  648. *
  649. * Input:
  650. * ha = adapter block pointer.
  651. * sp = SB structure pointer.
  652. *
  653. * Returns:
  654. * qla2x00 local function return status code.
  655. *
  656. * Context:
  657. * Kernel context.
  658. */
  659. int
  660. qla2x00_abort_command(srb_t *sp)
  661. {
  662. unsigned long flags = 0;
  663. int rval;
  664. uint32_t handle = 0;
  665. mbx_cmd_t mc;
  666. mbx_cmd_t *mcp = &mc;
  667. fc_port_t *fcport = sp->fcport;
  668. scsi_qla_host_t *vha = fcport->vha;
  669. struct qla_hw_data *ha = vha->hw;
  670. struct req_que *req = vha->req;
  671. DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
  672. spin_lock_irqsave(&ha->hardware_lock, flags);
  673. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  674. if (req->outstanding_cmds[handle] == sp)
  675. break;
  676. }
  677. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  678. if (handle == MAX_OUTSTANDING_COMMANDS) {
  679. /* command not found */
  680. return QLA_FUNCTION_FAILED;
  681. }
  682. mcp->mb[0] = MBC_ABORT_COMMAND;
  683. if (HAS_EXTENDED_IDS(ha))
  684. mcp->mb[1] = fcport->loop_id;
  685. else
  686. mcp->mb[1] = fcport->loop_id << 8;
  687. mcp->mb[2] = (uint16_t)handle;
  688. mcp->mb[3] = (uint16_t)(handle >> 16);
  689. mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
  690. mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  691. mcp->in_mb = MBX_0;
  692. mcp->tov = MBX_TOV_SECONDS;
  693. mcp->flags = 0;
  694. rval = qla2x00_mailbox_command(vha, mcp);
  695. if (rval != QLA_SUCCESS) {
  696. DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
  697. vha->host_no, rval));
  698. } else {
  699. DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
  700. vha->host_no));
  701. }
  702. return rval;
  703. }
  704. int
  705. qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
  706. {
  707. int rval, rval2;
  708. mbx_cmd_t mc;
  709. mbx_cmd_t *mcp = &mc;
  710. scsi_qla_host_t *vha;
  711. struct req_que *req;
  712. struct rsp_que *rsp;
  713. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
  714. l = l;
  715. vha = fcport->vha;
  716. req = vha->hw->req_q_map[tag];
  717. rsp = vha->hw->rsp_q_map[tag];
  718. mcp->mb[0] = MBC_ABORT_TARGET;
  719. mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
  720. if (HAS_EXTENDED_IDS(vha->hw)) {
  721. mcp->mb[1] = fcport->loop_id;
  722. mcp->mb[10] = 0;
  723. mcp->out_mb |= MBX_10;
  724. } else {
  725. mcp->mb[1] = fcport->loop_id << 8;
  726. }
  727. mcp->mb[2] = vha->hw->loop_reset_delay;
  728. mcp->mb[9] = vha->vp_idx;
  729. mcp->in_mb = MBX_0;
  730. mcp->tov = MBX_TOV_SECONDS;
  731. mcp->flags = 0;
  732. rval = qla2x00_mailbox_command(vha, mcp);
  733. if (rval != QLA_SUCCESS) {
  734. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  735. vha->host_no, rval));
  736. }
  737. /* Issue marker IOCB. */
  738. rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
  739. MK_SYNC_ID);
  740. if (rval2 != QLA_SUCCESS) {
  741. DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
  742. "(%x).\n", __func__, vha->host_no, rval2));
  743. } else {
  744. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  745. }
  746. return rval;
  747. }
  748. int
  749. qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
  750. {
  751. int rval, rval2;
  752. mbx_cmd_t mc;
  753. mbx_cmd_t *mcp = &mc;
  754. scsi_qla_host_t *vha;
  755. struct req_que *req;
  756. struct rsp_que *rsp;
  757. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
  758. vha = fcport->vha;
  759. req = vha->hw->req_q_map[tag];
  760. rsp = vha->hw->rsp_q_map[tag];
  761. mcp->mb[0] = MBC_LUN_RESET;
  762. mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
  763. if (HAS_EXTENDED_IDS(vha->hw))
  764. mcp->mb[1] = fcport->loop_id;
  765. else
  766. mcp->mb[1] = fcport->loop_id << 8;
  767. mcp->mb[2] = l;
  768. mcp->mb[3] = 0;
  769. mcp->mb[9] = vha->vp_idx;
  770. mcp->in_mb = MBX_0;
  771. mcp->tov = MBX_TOV_SECONDS;
  772. mcp->flags = 0;
  773. rval = qla2x00_mailbox_command(vha, mcp);
  774. if (rval != QLA_SUCCESS) {
  775. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  776. vha->host_no, rval));
  777. }
  778. /* Issue marker IOCB. */
  779. rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
  780. MK_SYNC_ID_LUN);
  781. if (rval2 != QLA_SUCCESS) {
  782. DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
  783. "(%x).\n", __func__, vha->host_no, rval2));
  784. } else {
  785. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  786. }
  787. return rval;
  788. }
  789. /*
  790. * qla2x00_get_adapter_id
  791. * Get adapter ID and topology.
  792. *
  793. * Input:
  794. * ha = adapter block pointer.
  795. * id = pointer for loop ID.
  796. * al_pa = pointer for AL_PA.
  797. * area = pointer for area.
  798. * domain = pointer for domain.
  799. * top = pointer for topology.
  800. * TARGET_QUEUE_LOCK must be released.
  801. * ADAPTER_STATE_LOCK must be released.
  802. *
  803. * Returns:
  804. * qla2x00 local function return status code.
  805. *
  806. * Context:
  807. * Kernel context.
  808. */
  809. int
  810. qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
  811. uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
  812. {
  813. int rval;
  814. mbx_cmd_t mc;
  815. mbx_cmd_t *mcp = &mc;
  816. DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
  817. vha->host_no));
  818. mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
  819. mcp->mb[9] = vha->vp_idx;
  820. mcp->out_mb = MBX_9|MBX_0;
  821. mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  822. if (IS_QLA81XX(vha->hw))
  823. mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
  824. mcp->tov = MBX_TOV_SECONDS;
  825. mcp->flags = 0;
  826. rval = qla2x00_mailbox_command(vha, mcp);
  827. if (mcp->mb[0] == MBS_COMMAND_ERROR)
  828. rval = QLA_COMMAND_ERROR;
  829. else if (mcp->mb[0] == MBS_INVALID_COMMAND)
  830. rval = QLA_INVALID_COMMAND;
  831. /* Return data. */
  832. *id = mcp->mb[1];
  833. *al_pa = LSB(mcp->mb[2]);
  834. *area = MSB(mcp->mb[2]);
  835. *domain = LSB(mcp->mb[3]);
  836. *top = mcp->mb[6];
  837. *sw_cap = mcp->mb[7];
  838. if (rval != QLA_SUCCESS) {
  839. /*EMPTY*/
  840. DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
  841. vha->host_no, rval));
  842. } else {
  843. DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
  844. vha->host_no));
  845. if (IS_QLA81XX(vha->hw)) {
  846. vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
  847. vha->fcoe_fcf_idx = mcp->mb[10];
  848. vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
  849. vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
  850. vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
  851. vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
  852. vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
  853. vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
  854. }
  855. }
  856. return rval;
  857. }
  858. /*
  859. * qla2x00_get_retry_cnt
  860. * Get current firmware login retry count and delay.
  861. *
  862. * Input:
  863. * ha = adapter block pointer.
  864. * retry_cnt = pointer to login retry count.
  865. * tov = pointer to login timeout value.
  866. *
  867. * Returns:
  868. * qla2x00 local function return status code.
  869. *
  870. * Context:
  871. * Kernel context.
  872. */
  873. int
  874. qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
  875. uint16_t *r_a_tov)
  876. {
  877. int rval;
  878. uint16_t ratov;
  879. mbx_cmd_t mc;
  880. mbx_cmd_t *mcp = &mc;
  881. DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
  882. vha->host_no));
  883. mcp->mb[0] = MBC_GET_RETRY_COUNT;
  884. mcp->out_mb = MBX_0;
  885. mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  886. mcp->tov = MBX_TOV_SECONDS;
  887. mcp->flags = 0;
  888. rval = qla2x00_mailbox_command(vha, mcp);
  889. if (rval != QLA_SUCCESS) {
  890. /*EMPTY*/
  891. DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
  892. vha->host_no, mcp->mb[0]));
  893. } else {
  894. /* Convert returned data and check our values. */
  895. *r_a_tov = mcp->mb[3] / 2;
  896. ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
  897. if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
  898. /* Update to the larger values */
  899. *retry_cnt = (uint8_t)mcp->mb[1];
  900. *tov = ratov;
  901. }
  902. DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
  903. "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
  904. }
  905. return rval;
  906. }
  907. /*
  908. * qla2x00_init_firmware
  909. * Initialize adapter firmware.
  910. *
  911. * Input:
  912. * ha = adapter block pointer.
  913. * dptr = Initialization control block pointer.
  914. * size = size of initialization control block.
  915. * TARGET_QUEUE_LOCK must be released.
  916. * ADAPTER_STATE_LOCK must be released.
  917. *
  918. * Returns:
  919. * qla2x00 local function return status code.
  920. *
  921. * Context:
  922. * Kernel context.
  923. */
  924. int
  925. qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
  926. {
  927. int rval;
  928. mbx_cmd_t mc;
  929. mbx_cmd_t *mcp = &mc;
  930. struct qla_hw_data *ha = vha->hw;
  931. DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
  932. vha->host_no));
  933. if (ha->flags.npiv_supported)
  934. mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
  935. else
  936. mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
  937. mcp->mb[1] = 0;
  938. mcp->mb[2] = MSW(ha->init_cb_dma);
  939. mcp->mb[3] = LSW(ha->init_cb_dma);
  940. mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
  941. mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
  942. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  943. if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
  944. mcp->mb[1] = BIT_0;
  945. mcp->mb[10] = MSW(ha->ex_init_cb_dma);
  946. mcp->mb[11] = LSW(ha->ex_init_cb_dma);
  947. mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
  948. mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
  949. mcp->mb[14] = sizeof(*ha->ex_init_cb);
  950. mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
  951. }
  952. mcp->in_mb = MBX_0;
  953. mcp->buf_size = size;
  954. mcp->flags = MBX_DMA_OUT;
  955. mcp->tov = MBX_TOV_SECONDS;
  956. rval = qla2x00_mailbox_command(vha, mcp);
  957. if (rval != QLA_SUCCESS) {
  958. /*EMPTY*/
  959. DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
  960. "mb0=%x.\n",
  961. vha->host_no, rval, mcp->mb[0]));
  962. } else {
  963. /*EMPTY*/
  964. DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
  965. vha->host_no));
  966. }
  967. return rval;
  968. }
  969. /*
  970. * qla2x00_get_port_database
  971. * Issue normal/enhanced get port database mailbox command
  972. * and copy device name as necessary.
  973. *
  974. * Input:
  975. * ha = adapter state pointer.
  976. * dev = structure pointer.
  977. * opt = enhanced cmd option byte.
  978. *
  979. * Returns:
  980. * qla2x00 local function return status code.
  981. *
  982. * Context:
  983. * Kernel context.
  984. */
  985. int
  986. qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
  987. {
  988. int rval;
  989. mbx_cmd_t mc;
  990. mbx_cmd_t *mcp = &mc;
  991. port_database_t *pd;
  992. struct port_database_24xx *pd24;
  993. dma_addr_t pd_dma;
  994. struct qla_hw_data *ha = vha->hw;
  995. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  996. pd24 = NULL;
  997. pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
  998. if (pd == NULL) {
  999. DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
  1000. "structure.\n", __func__, vha->host_no));
  1001. return QLA_MEMORY_ALLOC_FAILED;
  1002. }
  1003. memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
  1004. mcp->mb[0] = MBC_GET_PORT_DATABASE;
  1005. if (opt != 0 && !IS_FWI2_CAPABLE(ha))
  1006. mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
  1007. mcp->mb[2] = MSW(pd_dma);
  1008. mcp->mb[3] = LSW(pd_dma);
  1009. mcp->mb[6] = MSW(MSD(pd_dma));
  1010. mcp->mb[7] = LSW(MSD(pd_dma));
  1011. mcp->mb[9] = vha->vp_idx;
  1012. mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1013. mcp->in_mb = MBX_0;
  1014. if (IS_FWI2_CAPABLE(ha)) {
  1015. mcp->mb[1] = fcport->loop_id;
  1016. mcp->mb[10] = opt;
  1017. mcp->out_mb |= MBX_10|MBX_1;
  1018. mcp->in_mb |= MBX_1;
  1019. } else if (HAS_EXTENDED_IDS(ha)) {
  1020. mcp->mb[1] = fcport->loop_id;
  1021. mcp->mb[10] = opt;
  1022. mcp->out_mb |= MBX_10|MBX_1;
  1023. } else {
  1024. mcp->mb[1] = fcport->loop_id << 8 | opt;
  1025. mcp->out_mb |= MBX_1;
  1026. }
  1027. mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
  1028. PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
  1029. mcp->flags = MBX_DMA_IN;
  1030. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1031. rval = qla2x00_mailbox_command(vha, mcp);
  1032. if (rval != QLA_SUCCESS)
  1033. goto gpd_error_out;
  1034. if (IS_FWI2_CAPABLE(ha)) {
  1035. pd24 = (struct port_database_24xx *) pd;
  1036. /* Check for logged in state. */
  1037. if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
  1038. pd24->last_login_state != PDS_PRLI_COMPLETE) {
  1039. DEBUG2(printk("%s(%ld): Unable to verify "
  1040. "login-state (%x/%x) for loop_id %x\n",
  1041. __func__, vha->host_no,
  1042. pd24->current_login_state,
  1043. pd24->last_login_state, fcport->loop_id));
  1044. rval = QLA_FUNCTION_FAILED;
  1045. goto gpd_error_out;
  1046. }
  1047. /* Names are little-endian. */
  1048. memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
  1049. memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
  1050. /* Get port_id of device. */
  1051. fcport->d_id.b.domain = pd24->port_id[0];
  1052. fcport->d_id.b.area = pd24->port_id[1];
  1053. fcport->d_id.b.al_pa = pd24->port_id[2];
  1054. fcport->d_id.b.rsvd_1 = 0;
  1055. /* If not target must be initiator or unknown type. */
  1056. if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
  1057. fcport->port_type = FCT_INITIATOR;
  1058. else
  1059. fcport->port_type = FCT_TARGET;
  1060. } else {
  1061. /* Check for logged in state. */
  1062. if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
  1063. pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
  1064. rval = QLA_FUNCTION_FAILED;
  1065. goto gpd_error_out;
  1066. }
  1067. /* Names are little-endian. */
  1068. memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
  1069. memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
  1070. /* Get port_id of device. */
  1071. fcport->d_id.b.domain = pd->port_id[0];
  1072. fcport->d_id.b.area = pd->port_id[3];
  1073. fcport->d_id.b.al_pa = pd->port_id[2];
  1074. fcport->d_id.b.rsvd_1 = 0;
  1075. /* If not target must be initiator or unknown type. */
  1076. if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
  1077. fcport->port_type = FCT_INITIATOR;
  1078. else
  1079. fcport->port_type = FCT_TARGET;
  1080. /* Passback COS information. */
  1081. fcport->supported_classes = (pd->options & BIT_4) ?
  1082. FC_COS_CLASS2: FC_COS_CLASS3;
  1083. }
  1084. gpd_error_out:
  1085. dma_pool_free(ha->s_dma_pool, pd, pd_dma);
  1086. if (rval != QLA_SUCCESS) {
  1087. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  1088. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1089. } else {
  1090. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1091. }
  1092. return rval;
  1093. }
  1094. /*
  1095. * qla2x00_get_firmware_state
  1096. * Get adapter firmware state.
  1097. *
  1098. * Input:
  1099. * ha = adapter block pointer.
  1100. * dptr = pointer for firmware state.
  1101. * TARGET_QUEUE_LOCK must be released.
  1102. * ADAPTER_STATE_LOCK must be released.
  1103. *
  1104. * Returns:
  1105. * qla2x00 local function return status code.
  1106. *
  1107. * Context:
  1108. * Kernel context.
  1109. */
  1110. int
  1111. qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
  1112. {
  1113. int rval;
  1114. mbx_cmd_t mc;
  1115. mbx_cmd_t *mcp = &mc;
  1116. DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
  1117. vha->host_no));
  1118. mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
  1119. mcp->out_mb = MBX_0;
  1120. if (IS_FWI2_CAPABLE(vha->hw))
  1121. mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  1122. else
  1123. mcp->in_mb = MBX_1|MBX_0;
  1124. mcp->tov = MBX_TOV_SECONDS;
  1125. mcp->flags = 0;
  1126. rval = qla2x00_mailbox_command(vha, mcp);
  1127. /* Return firmware states. */
  1128. states[0] = mcp->mb[1];
  1129. if (IS_FWI2_CAPABLE(vha->hw)) {
  1130. states[1] = mcp->mb[2];
  1131. states[2] = mcp->mb[3];
  1132. states[3] = mcp->mb[4];
  1133. states[4] = mcp->mb[5];
  1134. }
  1135. if (rval != QLA_SUCCESS) {
  1136. /*EMPTY*/
  1137. DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
  1138. "failed=%x.\n", vha->host_no, rval));
  1139. } else {
  1140. /*EMPTY*/
  1141. DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
  1142. vha->host_no));
  1143. }
  1144. return rval;
  1145. }
  1146. /*
  1147. * qla2x00_get_port_name
  1148. * Issue get port name mailbox command.
  1149. * Returned name is in big endian format.
  1150. *
  1151. * Input:
  1152. * ha = adapter block pointer.
  1153. * loop_id = loop ID of device.
  1154. * name = pointer for name.
  1155. * TARGET_QUEUE_LOCK must be released.
  1156. * ADAPTER_STATE_LOCK must be released.
  1157. *
  1158. * Returns:
  1159. * qla2x00 local function return status code.
  1160. *
  1161. * Context:
  1162. * Kernel context.
  1163. */
  1164. int
  1165. qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
  1166. uint8_t opt)
  1167. {
  1168. int rval;
  1169. mbx_cmd_t mc;
  1170. mbx_cmd_t *mcp = &mc;
  1171. DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
  1172. vha->host_no));
  1173. mcp->mb[0] = MBC_GET_PORT_NAME;
  1174. mcp->mb[9] = vha->vp_idx;
  1175. mcp->out_mb = MBX_9|MBX_1|MBX_0;
  1176. if (HAS_EXTENDED_IDS(vha->hw)) {
  1177. mcp->mb[1] = loop_id;
  1178. mcp->mb[10] = opt;
  1179. mcp->out_mb |= MBX_10;
  1180. } else {
  1181. mcp->mb[1] = loop_id << 8 | opt;
  1182. }
  1183. mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1184. mcp->tov = MBX_TOV_SECONDS;
  1185. mcp->flags = 0;
  1186. rval = qla2x00_mailbox_command(vha, mcp);
  1187. if (rval != QLA_SUCCESS) {
  1188. /*EMPTY*/
  1189. DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
  1190. vha->host_no, rval));
  1191. } else {
  1192. if (name != NULL) {
  1193. /* This function returns name in big endian. */
  1194. name[0] = MSB(mcp->mb[2]);
  1195. name[1] = LSB(mcp->mb[2]);
  1196. name[2] = MSB(mcp->mb[3]);
  1197. name[3] = LSB(mcp->mb[3]);
  1198. name[4] = MSB(mcp->mb[6]);
  1199. name[5] = LSB(mcp->mb[6]);
  1200. name[6] = MSB(mcp->mb[7]);
  1201. name[7] = LSB(mcp->mb[7]);
  1202. }
  1203. DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
  1204. vha->host_no));
  1205. }
  1206. return rval;
  1207. }
  1208. /*
  1209. * qla2x00_lip_reset
  1210. * Issue LIP reset mailbox command.
  1211. *
  1212. * Input:
  1213. * ha = adapter block pointer.
  1214. * TARGET_QUEUE_LOCK must be released.
  1215. * ADAPTER_STATE_LOCK must be released.
  1216. *
  1217. * Returns:
  1218. * qla2x00 local function return status code.
  1219. *
  1220. * Context:
  1221. * Kernel context.
  1222. */
  1223. int
  1224. qla2x00_lip_reset(scsi_qla_host_t *vha)
  1225. {
  1226. int rval;
  1227. mbx_cmd_t mc;
  1228. mbx_cmd_t *mcp = &mc;
  1229. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1230. if (IS_QLA81XX(vha->hw)) {
  1231. /* Logout across all FCFs. */
  1232. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1233. mcp->mb[1] = BIT_1;
  1234. mcp->mb[2] = 0;
  1235. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  1236. } else if (IS_FWI2_CAPABLE(vha->hw)) {
  1237. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1238. mcp->mb[1] = BIT_6;
  1239. mcp->mb[2] = 0;
  1240. mcp->mb[3] = vha->hw->loop_reset_delay;
  1241. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1242. } else {
  1243. mcp->mb[0] = MBC_LIP_RESET;
  1244. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1245. if (HAS_EXTENDED_IDS(vha->hw)) {
  1246. mcp->mb[1] = 0x00ff;
  1247. mcp->mb[10] = 0;
  1248. mcp->out_mb |= MBX_10;
  1249. } else {
  1250. mcp->mb[1] = 0xff00;
  1251. }
  1252. mcp->mb[2] = vha->hw->loop_reset_delay;
  1253. mcp->mb[3] = 0;
  1254. }
  1255. mcp->in_mb = MBX_0;
  1256. mcp->tov = MBX_TOV_SECONDS;
  1257. mcp->flags = 0;
  1258. rval = qla2x00_mailbox_command(vha, mcp);
  1259. if (rval != QLA_SUCCESS) {
  1260. /*EMPTY*/
  1261. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
  1262. __func__, vha->host_no, rval));
  1263. } else {
  1264. /*EMPTY*/
  1265. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1266. }
  1267. return rval;
  1268. }
  1269. /*
  1270. * qla2x00_send_sns
  1271. * Send SNS command.
  1272. *
  1273. * Input:
  1274. * ha = adapter block pointer.
  1275. * sns = pointer for command.
  1276. * cmd_size = command size.
  1277. * buf_size = response/command size.
  1278. * TARGET_QUEUE_LOCK must be released.
  1279. * ADAPTER_STATE_LOCK must be released.
  1280. *
  1281. * Returns:
  1282. * qla2x00 local function return status code.
  1283. *
  1284. * Context:
  1285. * Kernel context.
  1286. */
  1287. int
  1288. qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
  1289. uint16_t cmd_size, size_t buf_size)
  1290. {
  1291. int rval;
  1292. mbx_cmd_t mc;
  1293. mbx_cmd_t *mcp = &mc;
  1294. DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
  1295. vha->host_no));
  1296. DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
  1297. "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
  1298. mcp->tov));
  1299. mcp->mb[0] = MBC_SEND_SNS_COMMAND;
  1300. mcp->mb[1] = cmd_size;
  1301. mcp->mb[2] = MSW(sns_phys_address);
  1302. mcp->mb[3] = LSW(sns_phys_address);
  1303. mcp->mb[6] = MSW(MSD(sns_phys_address));
  1304. mcp->mb[7] = LSW(MSD(sns_phys_address));
  1305. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1306. mcp->in_mb = MBX_0|MBX_1;
  1307. mcp->buf_size = buf_size;
  1308. mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
  1309. mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
  1310. rval = qla2x00_mailbox_command(vha, mcp);
  1311. if (rval != QLA_SUCCESS) {
  1312. /*EMPTY*/
  1313. DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1314. "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1315. DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1316. "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1317. } else {
  1318. /*EMPTY*/
  1319. DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
  1320. }
  1321. return rval;
  1322. }
  1323. int
  1324. qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
  1325. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1326. {
  1327. int rval;
  1328. struct logio_entry_24xx *lg;
  1329. dma_addr_t lg_dma;
  1330. uint32_t iop[2];
  1331. struct qla_hw_data *ha = vha->hw;
  1332. struct req_que *req;
  1333. struct rsp_que *rsp;
  1334. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1335. if (ha->flags.cpu_affinity_enabled)
  1336. req = ha->req_q_map[0];
  1337. else
  1338. req = vha->req;
  1339. rsp = req->rsp;
  1340. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1341. if (lg == NULL) {
  1342. DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
  1343. __func__, vha->host_no));
  1344. return QLA_MEMORY_ALLOC_FAILED;
  1345. }
  1346. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1347. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1348. lg->entry_count = 1;
  1349. lg->handle = MAKE_HANDLE(req->id, lg->handle);
  1350. lg->nport_handle = cpu_to_le16(loop_id);
  1351. lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
  1352. if (opt & BIT_0)
  1353. lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
  1354. if (opt & BIT_1)
  1355. lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
  1356. lg->port_id[0] = al_pa;
  1357. lg->port_id[1] = area;
  1358. lg->port_id[2] = domain;
  1359. lg->vp_index = vha->vp_idx;
  1360. rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
  1361. if (rval != QLA_SUCCESS) {
  1362. DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
  1363. "(%x).\n", __func__, vha->host_no, rval));
  1364. } else if (lg->entry_status != 0) {
  1365. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1366. "-- error status (%x).\n", __func__, vha->host_no,
  1367. lg->entry_status));
  1368. rval = QLA_FUNCTION_FAILED;
  1369. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1370. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1371. iop[1] = le32_to_cpu(lg->io_parameter[1]);
  1372. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1373. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1374. vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
  1375. iop[1]));
  1376. switch (iop[0]) {
  1377. case LSC_SCODE_PORTID_USED:
  1378. mb[0] = MBS_PORT_ID_USED;
  1379. mb[1] = LSW(iop[1]);
  1380. break;
  1381. case LSC_SCODE_NPORT_USED:
  1382. mb[0] = MBS_LOOP_ID_USED;
  1383. break;
  1384. case LSC_SCODE_NOLINK:
  1385. case LSC_SCODE_NOIOCB:
  1386. case LSC_SCODE_NOXCB:
  1387. case LSC_SCODE_CMD_FAILED:
  1388. case LSC_SCODE_NOFABRIC:
  1389. case LSC_SCODE_FW_NOT_READY:
  1390. case LSC_SCODE_NOT_LOGGED_IN:
  1391. case LSC_SCODE_NOPCB:
  1392. case LSC_SCODE_ELS_REJECT:
  1393. case LSC_SCODE_CMD_PARAM_ERR:
  1394. case LSC_SCODE_NONPORT:
  1395. case LSC_SCODE_LOGGED_IN:
  1396. case LSC_SCODE_NOFLOGI_ACC:
  1397. default:
  1398. mb[0] = MBS_COMMAND_ERROR;
  1399. break;
  1400. }
  1401. } else {
  1402. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1403. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1404. mb[0] = MBS_COMMAND_COMPLETE;
  1405. mb[1] = 0;
  1406. if (iop[0] & BIT_4) {
  1407. if (iop[0] & BIT_8)
  1408. mb[1] |= BIT_1;
  1409. } else
  1410. mb[1] = BIT_0;
  1411. /* Passback COS information. */
  1412. mb[10] = 0;
  1413. if (lg->io_parameter[7] || lg->io_parameter[8])
  1414. mb[10] |= BIT_0; /* Class 2. */
  1415. if (lg->io_parameter[9] || lg->io_parameter[10])
  1416. mb[10] |= BIT_1; /* Class 3. */
  1417. }
  1418. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1419. return rval;
  1420. }
  1421. /*
  1422. * qla2x00_login_fabric
  1423. * Issue login fabric port mailbox command.
  1424. *
  1425. * Input:
  1426. * ha = adapter block pointer.
  1427. * loop_id = device loop ID.
  1428. * domain = device domain.
  1429. * area = device area.
  1430. * al_pa = device AL_PA.
  1431. * status = pointer for return status.
  1432. * opt = command options.
  1433. * TARGET_QUEUE_LOCK must be released.
  1434. * ADAPTER_STATE_LOCK must be released.
  1435. *
  1436. * Returns:
  1437. * qla2x00 local function return status code.
  1438. *
  1439. * Context:
  1440. * Kernel context.
  1441. */
  1442. int
  1443. qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
  1444. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1445. {
  1446. int rval;
  1447. mbx_cmd_t mc;
  1448. mbx_cmd_t *mcp = &mc;
  1449. struct qla_hw_data *ha = vha->hw;
  1450. DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
  1451. mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
  1452. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1453. if (HAS_EXTENDED_IDS(ha)) {
  1454. mcp->mb[1] = loop_id;
  1455. mcp->mb[10] = opt;
  1456. mcp->out_mb |= MBX_10;
  1457. } else {
  1458. mcp->mb[1] = (loop_id << 8) | opt;
  1459. }
  1460. mcp->mb[2] = domain;
  1461. mcp->mb[3] = area << 8 | al_pa;
  1462. mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
  1463. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1464. mcp->flags = 0;
  1465. rval = qla2x00_mailbox_command(vha, mcp);
  1466. /* Return mailbox statuses. */
  1467. if (mb != NULL) {
  1468. mb[0] = mcp->mb[0];
  1469. mb[1] = mcp->mb[1];
  1470. mb[2] = mcp->mb[2];
  1471. mb[6] = mcp->mb[6];
  1472. mb[7] = mcp->mb[7];
  1473. /* COS retrieved from Get-Port-Database mailbox command. */
  1474. mb[10] = 0;
  1475. }
  1476. if (rval != QLA_SUCCESS) {
  1477. /* RLU tmp code: need to change main mailbox_command function to
  1478. * return ok even when the mailbox completion value is not
  1479. * SUCCESS. The caller needs to be responsible to interpret
  1480. * the return values of this mailbox command if we're not
  1481. * to change too much of the existing code.
  1482. */
  1483. if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
  1484. mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
  1485. mcp->mb[0] == 0x4006)
  1486. rval = QLA_SUCCESS;
  1487. /*EMPTY*/
  1488. DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
  1489. "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
  1490. mcp->mb[0], mcp->mb[1], mcp->mb[2]));
  1491. } else {
  1492. /*EMPTY*/
  1493. DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
  1494. vha->host_no));
  1495. }
  1496. return rval;
  1497. }
  1498. /*
  1499. * qla2x00_login_local_device
  1500. * Issue login loop port mailbox command.
  1501. *
  1502. * Input:
  1503. * ha = adapter block pointer.
  1504. * loop_id = device loop ID.
  1505. * opt = command options.
  1506. *
  1507. * Returns:
  1508. * Return status code.
  1509. *
  1510. * Context:
  1511. * Kernel context.
  1512. *
  1513. */
  1514. int
  1515. qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
  1516. uint16_t *mb_ret, uint8_t opt)
  1517. {
  1518. int rval;
  1519. mbx_cmd_t mc;
  1520. mbx_cmd_t *mcp = &mc;
  1521. struct qla_hw_data *ha = vha->hw;
  1522. if (IS_FWI2_CAPABLE(ha))
  1523. return qla24xx_login_fabric(vha, fcport->loop_id,
  1524. fcport->d_id.b.domain, fcport->d_id.b.area,
  1525. fcport->d_id.b.al_pa, mb_ret, opt);
  1526. DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1527. mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
  1528. if (HAS_EXTENDED_IDS(ha))
  1529. mcp->mb[1] = fcport->loop_id;
  1530. else
  1531. mcp->mb[1] = fcport->loop_id << 8;
  1532. mcp->mb[2] = opt;
  1533. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  1534. mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
  1535. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1536. mcp->flags = 0;
  1537. rval = qla2x00_mailbox_command(vha, mcp);
  1538. /* Return mailbox statuses. */
  1539. if (mb_ret != NULL) {
  1540. mb_ret[0] = mcp->mb[0];
  1541. mb_ret[1] = mcp->mb[1];
  1542. mb_ret[6] = mcp->mb[6];
  1543. mb_ret[7] = mcp->mb[7];
  1544. }
  1545. if (rval != QLA_SUCCESS) {
  1546. /* AV tmp code: need to change main mailbox_command function to
  1547. * return ok even when the mailbox completion value is not
  1548. * SUCCESS. The caller needs to be responsible to interpret
  1549. * the return values of this mailbox command if we're not
  1550. * to change too much of the existing code.
  1551. */
  1552. if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
  1553. rval = QLA_SUCCESS;
  1554. DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1555. "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
  1556. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
  1557. DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1558. "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
  1559. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
  1560. } else {
  1561. /*EMPTY*/
  1562. DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1563. }
  1564. return (rval);
  1565. }
  1566. int
  1567. qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
  1568. uint8_t area, uint8_t al_pa)
  1569. {
  1570. int rval;
  1571. struct logio_entry_24xx *lg;
  1572. dma_addr_t lg_dma;
  1573. struct qla_hw_data *ha = vha->hw;
  1574. struct req_que *req;
  1575. struct rsp_que *rsp;
  1576. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1577. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1578. if (lg == NULL) {
  1579. DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
  1580. __func__, vha->host_no));
  1581. return QLA_MEMORY_ALLOC_FAILED;
  1582. }
  1583. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1584. if (ql2xmaxqueues > 1)
  1585. req = ha->req_q_map[0];
  1586. else
  1587. req = vha->req;
  1588. rsp = req->rsp;
  1589. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1590. lg->entry_count = 1;
  1591. lg->handle = MAKE_HANDLE(req->id, lg->handle);
  1592. lg->nport_handle = cpu_to_le16(loop_id);
  1593. lg->control_flags =
  1594. __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
  1595. lg->port_id[0] = al_pa;
  1596. lg->port_id[1] = area;
  1597. lg->port_id[2] = domain;
  1598. lg->vp_index = vha->vp_idx;
  1599. rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
  1600. if (rval != QLA_SUCCESS) {
  1601. DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
  1602. "(%x).\n", __func__, vha->host_no, rval));
  1603. } else if (lg->entry_status != 0) {
  1604. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1605. "-- error status (%x).\n", __func__, vha->host_no,
  1606. lg->entry_status));
  1607. rval = QLA_FUNCTION_FAILED;
  1608. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1609. DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
  1610. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1611. vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
  1612. le32_to_cpu(lg->io_parameter[0]),
  1613. le32_to_cpu(lg->io_parameter[1])));
  1614. } else {
  1615. /*EMPTY*/
  1616. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1617. }
  1618. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1619. return rval;
  1620. }
  1621. /*
  1622. * qla2x00_fabric_logout
  1623. * Issue logout fabric port mailbox command.
  1624. *
  1625. * Input:
  1626. * ha = adapter block pointer.
  1627. * loop_id = device loop ID.
  1628. * TARGET_QUEUE_LOCK must be released.
  1629. * ADAPTER_STATE_LOCK must be released.
  1630. *
  1631. * Returns:
  1632. * qla2x00 local function return status code.
  1633. *
  1634. * Context:
  1635. * Kernel context.
  1636. */
  1637. int
  1638. qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
  1639. uint8_t area, uint8_t al_pa)
  1640. {
  1641. int rval;
  1642. mbx_cmd_t mc;
  1643. mbx_cmd_t *mcp = &mc;
  1644. DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
  1645. vha->host_no));
  1646. mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
  1647. mcp->out_mb = MBX_1|MBX_0;
  1648. if (HAS_EXTENDED_IDS(vha->hw)) {
  1649. mcp->mb[1] = loop_id;
  1650. mcp->mb[10] = 0;
  1651. mcp->out_mb |= MBX_10;
  1652. } else {
  1653. mcp->mb[1] = loop_id << 8;
  1654. }
  1655. mcp->in_mb = MBX_1|MBX_0;
  1656. mcp->tov = MBX_TOV_SECONDS;
  1657. mcp->flags = 0;
  1658. rval = qla2x00_mailbox_command(vha, mcp);
  1659. if (rval != QLA_SUCCESS) {
  1660. /*EMPTY*/
  1661. DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
  1662. "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
  1663. } else {
  1664. /*EMPTY*/
  1665. DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
  1666. vha->host_no));
  1667. }
  1668. return rval;
  1669. }
  1670. /*
  1671. * qla2x00_full_login_lip
  1672. * Issue full login LIP mailbox command.
  1673. *
  1674. * Input:
  1675. * ha = adapter block pointer.
  1676. * TARGET_QUEUE_LOCK must be released.
  1677. * ADAPTER_STATE_LOCK must be released.
  1678. *
  1679. * Returns:
  1680. * qla2x00 local function return status code.
  1681. *
  1682. * Context:
  1683. * Kernel context.
  1684. */
  1685. int
  1686. qla2x00_full_login_lip(scsi_qla_host_t *vha)
  1687. {
  1688. int rval;
  1689. mbx_cmd_t mc;
  1690. mbx_cmd_t *mcp = &mc;
  1691. DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
  1692. vha->host_no));
  1693. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1694. mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
  1695. mcp->mb[2] = 0;
  1696. mcp->mb[3] = 0;
  1697. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1698. mcp->in_mb = MBX_0;
  1699. mcp->tov = MBX_TOV_SECONDS;
  1700. mcp->flags = 0;
  1701. rval = qla2x00_mailbox_command(vha, mcp);
  1702. if (rval != QLA_SUCCESS) {
  1703. /*EMPTY*/
  1704. DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
  1705. vha->host_no, rval));
  1706. } else {
  1707. /*EMPTY*/
  1708. DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
  1709. vha->host_no));
  1710. }
  1711. return rval;
  1712. }
  1713. /*
  1714. * qla2x00_get_id_list
  1715. *
  1716. * Input:
  1717. * ha = adapter block pointer.
  1718. *
  1719. * Returns:
  1720. * qla2x00 local function return status code.
  1721. *
  1722. * Context:
  1723. * Kernel context.
  1724. */
  1725. int
  1726. qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
  1727. uint16_t *entries)
  1728. {
  1729. int rval;
  1730. mbx_cmd_t mc;
  1731. mbx_cmd_t *mcp = &mc;
  1732. DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
  1733. vha->host_no));
  1734. if (id_list == NULL)
  1735. return QLA_FUNCTION_FAILED;
  1736. mcp->mb[0] = MBC_GET_ID_LIST;
  1737. mcp->out_mb = MBX_0;
  1738. if (IS_FWI2_CAPABLE(vha->hw)) {
  1739. mcp->mb[2] = MSW(id_list_dma);
  1740. mcp->mb[3] = LSW(id_list_dma);
  1741. mcp->mb[6] = MSW(MSD(id_list_dma));
  1742. mcp->mb[7] = LSW(MSD(id_list_dma));
  1743. mcp->mb[8] = 0;
  1744. mcp->mb[9] = vha->vp_idx;
  1745. mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
  1746. } else {
  1747. mcp->mb[1] = MSW(id_list_dma);
  1748. mcp->mb[2] = LSW(id_list_dma);
  1749. mcp->mb[3] = MSW(MSD(id_list_dma));
  1750. mcp->mb[6] = LSW(MSD(id_list_dma));
  1751. mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
  1752. }
  1753. mcp->in_mb = MBX_1|MBX_0;
  1754. mcp->tov = MBX_TOV_SECONDS;
  1755. mcp->flags = 0;
  1756. rval = qla2x00_mailbox_command(vha, mcp);
  1757. if (rval != QLA_SUCCESS) {
  1758. /*EMPTY*/
  1759. DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
  1760. vha->host_no, rval));
  1761. } else {
  1762. *entries = mcp->mb[1];
  1763. DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
  1764. vha->host_no));
  1765. }
  1766. return rval;
  1767. }
  1768. /*
  1769. * qla2x00_get_resource_cnts
  1770. * Get current firmware resource counts.
  1771. *
  1772. * Input:
  1773. * ha = adapter block pointer.
  1774. *
  1775. * Returns:
  1776. * qla2x00 local function return status code.
  1777. *
  1778. * Context:
  1779. * Kernel context.
  1780. */
  1781. int
  1782. qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
  1783. uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
  1784. uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
  1785. {
  1786. int rval;
  1787. mbx_cmd_t mc;
  1788. mbx_cmd_t *mcp = &mc;
  1789. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1790. mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
  1791. mcp->out_mb = MBX_0;
  1792. mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1793. if (IS_QLA81XX(vha->hw))
  1794. mcp->in_mb |= MBX_12;
  1795. mcp->tov = MBX_TOV_SECONDS;
  1796. mcp->flags = 0;
  1797. rval = qla2x00_mailbox_command(vha, mcp);
  1798. if (rval != QLA_SUCCESS) {
  1799. /*EMPTY*/
  1800. DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
  1801. vha->host_no, mcp->mb[0]));
  1802. } else {
  1803. DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
  1804. "mb7=%x mb10=%x mb11=%x mb12=%x.\n", __func__,
  1805. vha->host_no, mcp->mb[1], mcp->mb[2], mcp->mb[3],
  1806. mcp->mb[6], mcp->mb[7], mcp->mb[10], mcp->mb[11],
  1807. mcp->mb[12]));
  1808. if (cur_xchg_cnt)
  1809. *cur_xchg_cnt = mcp->mb[3];
  1810. if (orig_xchg_cnt)
  1811. *orig_xchg_cnt = mcp->mb[6];
  1812. if (cur_iocb_cnt)
  1813. *cur_iocb_cnt = mcp->mb[7];
  1814. if (orig_iocb_cnt)
  1815. *orig_iocb_cnt = mcp->mb[10];
  1816. if (vha->hw->flags.npiv_supported && max_npiv_vports)
  1817. *max_npiv_vports = mcp->mb[11];
  1818. if (IS_QLA81XX(vha->hw) && max_fcfs)
  1819. *max_fcfs = mcp->mb[12];
  1820. }
  1821. return (rval);
  1822. }
  1823. #if defined(QL_DEBUG_LEVEL_3)
  1824. /*
  1825. * qla2x00_get_fcal_position_map
  1826. * Get FCAL (LILP) position map using mailbox command
  1827. *
  1828. * Input:
  1829. * ha = adapter state pointer.
  1830. * pos_map = buffer pointer (can be NULL).
  1831. *
  1832. * Returns:
  1833. * qla2x00 local function return status code.
  1834. *
  1835. * Context:
  1836. * Kernel context.
  1837. */
  1838. int
  1839. qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
  1840. {
  1841. int rval;
  1842. mbx_cmd_t mc;
  1843. mbx_cmd_t *mcp = &mc;
  1844. char *pmap;
  1845. dma_addr_t pmap_dma;
  1846. struct qla_hw_data *ha = vha->hw;
  1847. pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
  1848. if (pmap == NULL) {
  1849. DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
  1850. __func__, vha->host_no));
  1851. return QLA_MEMORY_ALLOC_FAILED;
  1852. }
  1853. memset(pmap, 0, FCAL_MAP_SIZE);
  1854. mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
  1855. mcp->mb[2] = MSW(pmap_dma);
  1856. mcp->mb[3] = LSW(pmap_dma);
  1857. mcp->mb[6] = MSW(MSD(pmap_dma));
  1858. mcp->mb[7] = LSW(MSD(pmap_dma));
  1859. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1860. mcp->in_mb = MBX_1|MBX_0;
  1861. mcp->buf_size = FCAL_MAP_SIZE;
  1862. mcp->flags = MBX_DMA_IN;
  1863. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1864. rval = qla2x00_mailbox_command(vha, mcp);
  1865. if (rval == QLA_SUCCESS) {
  1866. DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
  1867. "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
  1868. mcp->mb[1], (unsigned)pmap[0]));
  1869. DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
  1870. if (pos_map)
  1871. memcpy(pos_map, pmap, FCAL_MAP_SIZE);
  1872. }
  1873. dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
  1874. if (rval != QLA_SUCCESS) {
  1875. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1876. vha->host_no, rval));
  1877. } else {
  1878. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1879. }
  1880. return rval;
  1881. }
  1882. #endif
  1883. /*
  1884. * qla2x00_get_link_status
  1885. *
  1886. * Input:
  1887. * ha = adapter block pointer.
  1888. * loop_id = device loop ID.
  1889. * ret_buf = pointer to link status return buffer.
  1890. *
  1891. * Returns:
  1892. * 0 = success.
  1893. * BIT_0 = mem alloc error.
  1894. * BIT_1 = mailbox error.
  1895. */
  1896. int
  1897. qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
  1898. struct link_statistics *stats, dma_addr_t stats_dma)
  1899. {
  1900. int rval;
  1901. mbx_cmd_t mc;
  1902. mbx_cmd_t *mcp = &mc;
  1903. uint32_t *siter, *diter, dwords;
  1904. struct qla_hw_data *ha = vha->hw;
  1905. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1906. mcp->mb[0] = MBC_GET_LINK_STATUS;
  1907. mcp->mb[2] = MSW(stats_dma);
  1908. mcp->mb[3] = LSW(stats_dma);
  1909. mcp->mb[6] = MSW(MSD(stats_dma));
  1910. mcp->mb[7] = LSW(MSD(stats_dma));
  1911. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1912. mcp->in_mb = MBX_0;
  1913. if (IS_FWI2_CAPABLE(ha)) {
  1914. mcp->mb[1] = loop_id;
  1915. mcp->mb[4] = 0;
  1916. mcp->mb[10] = 0;
  1917. mcp->out_mb |= MBX_10|MBX_4|MBX_1;
  1918. mcp->in_mb |= MBX_1;
  1919. } else if (HAS_EXTENDED_IDS(ha)) {
  1920. mcp->mb[1] = loop_id;
  1921. mcp->mb[10] = 0;
  1922. mcp->out_mb |= MBX_10|MBX_1;
  1923. } else {
  1924. mcp->mb[1] = loop_id << 8;
  1925. mcp->out_mb |= MBX_1;
  1926. }
  1927. mcp->tov = MBX_TOV_SECONDS;
  1928. mcp->flags = IOCTL_CMD;
  1929. rval = qla2x00_mailbox_command(vha, mcp);
  1930. if (rval == QLA_SUCCESS) {
  1931. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  1932. DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
  1933. __func__, vha->host_no, mcp->mb[0]));
  1934. rval = QLA_FUNCTION_FAILED;
  1935. } else {
  1936. /* Copy over data -- firmware data is LE. */
  1937. dwords = offsetof(struct link_statistics, unused1) / 4;
  1938. siter = diter = &stats->link_fail_cnt;
  1939. while (dwords--)
  1940. *diter++ = le32_to_cpu(*siter++);
  1941. }
  1942. } else {
  1943. /* Failed. */
  1944. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1945. vha->host_no, rval));
  1946. }
  1947. return rval;
  1948. }
  1949. int
  1950. qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
  1951. dma_addr_t stats_dma)
  1952. {
  1953. int rval;
  1954. mbx_cmd_t mc;
  1955. mbx_cmd_t *mcp = &mc;
  1956. uint32_t *siter, *diter, dwords;
  1957. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1958. mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
  1959. mcp->mb[2] = MSW(stats_dma);
  1960. mcp->mb[3] = LSW(stats_dma);
  1961. mcp->mb[6] = MSW(MSD(stats_dma));
  1962. mcp->mb[7] = LSW(MSD(stats_dma));
  1963. mcp->mb[8] = sizeof(struct link_statistics) / 4;
  1964. mcp->mb[9] = vha->vp_idx;
  1965. mcp->mb[10] = 0;
  1966. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1967. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  1968. mcp->tov = MBX_TOV_SECONDS;
  1969. mcp->flags = IOCTL_CMD;
  1970. rval = qla2x00_mailbox_command(vha, mcp);
  1971. if (rval == QLA_SUCCESS) {
  1972. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  1973. DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
  1974. __func__, vha->host_no, mcp->mb[0]));
  1975. rval = QLA_FUNCTION_FAILED;
  1976. } else {
  1977. /* Copy over data -- firmware data is LE. */
  1978. dwords = sizeof(struct link_statistics) / 4;
  1979. siter = diter = &stats->link_fail_cnt;
  1980. while (dwords--)
  1981. *diter++ = le32_to_cpu(*siter++);
  1982. }
  1983. } else {
  1984. /* Failed. */
  1985. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1986. vha->host_no, rval));
  1987. }
  1988. return rval;
  1989. }
  1990. int
  1991. qla24xx_abort_command(srb_t *sp)
  1992. {
  1993. int rval;
  1994. unsigned long flags = 0;
  1995. struct abort_entry_24xx *abt;
  1996. dma_addr_t abt_dma;
  1997. uint32_t handle;
  1998. fc_port_t *fcport = sp->fcport;
  1999. struct scsi_qla_host *vha = fcport->vha;
  2000. struct qla_hw_data *ha = vha->hw;
  2001. struct req_que *req = vha->req;
  2002. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2003. spin_lock_irqsave(&ha->hardware_lock, flags);
  2004. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  2005. if (req->outstanding_cmds[handle] == sp)
  2006. break;
  2007. }
  2008. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2009. if (handle == MAX_OUTSTANDING_COMMANDS) {
  2010. /* Command not found. */
  2011. return QLA_FUNCTION_FAILED;
  2012. }
  2013. abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
  2014. if (abt == NULL) {
  2015. DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
  2016. __func__, vha->host_no));
  2017. return QLA_MEMORY_ALLOC_FAILED;
  2018. }
  2019. memset(abt, 0, sizeof(struct abort_entry_24xx));
  2020. abt->entry_type = ABORT_IOCB_TYPE;
  2021. abt->entry_count = 1;
  2022. abt->handle = MAKE_HANDLE(req->id, abt->handle);
  2023. abt->nport_handle = cpu_to_le16(fcport->loop_id);
  2024. abt->handle_to_abort = handle;
  2025. abt->port_id[0] = fcport->d_id.b.al_pa;
  2026. abt->port_id[1] = fcport->d_id.b.area;
  2027. abt->port_id[2] = fcport->d_id.b.domain;
  2028. abt->vp_index = fcport->vp_idx;
  2029. abt->req_que_no = cpu_to_le16(req->id);
  2030. rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
  2031. if (rval != QLA_SUCCESS) {
  2032. DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
  2033. __func__, vha->host_no, rval));
  2034. } else if (abt->entry_status != 0) {
  2035. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2036. "-- error status (%x).\n", __func__, vha->host_no,
  2037. abt->entry_status));
  2038. rval = QLA_FUNCTION_FAILED;
  2039. } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
  2040. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2041. "-- completion status (%x).\n", __func__, vha->host_no,
  2042. le16_to_cpu(abt->nport_handle)));
  2043. rval = QLA_FUNCTION_FAILED;
  2044. } else {
  2045. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2046. }
  2047. dma_pool_free(ha->s_dma_pool, abt, abt_dma);
  2048. return rval;
  2049. }
  2050. struct tsk_mgmt_cmd {
  2051. union {
  2052. struct tsk_mgmt_entry tsk;
  2053. struct sts_entry_24xx sts;
  2054. } p;
  2055. };
  2056. static int
  2057. __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
  2058. unsigned int l, int tag)
  2059. {
  2060. int rval, rval2;
  2061. struct tsk_mgmt_cmd *tsk;
  2062. struct sts_entry_24xx *sts;
  2063. dma_addr_t tsk_dma;
  2064. scsi_qla_host_t *vha;
  2065. struct qla_hw_data *ha;
  2066. struct req_que *req;
  2067. struct rsp_que *rsp;
  2068. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
  2069. vha = fcport->vha;
  2070. ha = vha->hw;
  2071. req = vha->req;
  2072. if (ha->flags.cpu_affinity_enabled)
  2073. rsp = ha->rsp_q_map[tag + 1];
  2074. else
  2075. rsp = req->rsp;
  2076. tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
  2077. if (tsk == NULL) {
  2078. DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
  2079. "IOCB.\n", __func__, vha->host_no));
  2080. return QLA_MEMORY_ALLOC_FAILED;
  2081. }
  2082. memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
  2083. tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
  2084. tsk->p.tsk.entry_count = 1;
  2085. tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
  2086. tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
  2087. tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  2088. tsk->p.tsk.control_flags = cpu_to_le32(type);
  2089. tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
  2090. tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
  2091. tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
  2092. tsk->p.tsk.vp_index = fcport->vp_idx;
  2093. if (type == TCF_LUN_RESET) {
  2094. int_to_scsilun(l, &tsk->p.tsk.lun);
  2095. host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
  2096. sizeof(tsk->p.tsk.lun));
  2097. }
  2098. sts = &tsk->p.sts;
  2099. rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
  2100. if (rval != QLA_SUCCESS) {
  2101. DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
  2102. "(%x).\n", __func__, vha->host_no, name, rval));
  2103. } else if (sts->entry_status != 0) {
  2104. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2105. "-- error status (%x).\n", __func__, vha->host_no,
  2106. sts->entry_status));
  2107. rval = QLA_FUNCTION_FAILED;
  2108. } else if (sts->comp_status !=
  2109. __constant_cpu_to_le16(CS_COMPLETE)) {
  2110. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2111. "-- completion status (%x).\n", __func__,
  2112. vha->host_no, le16_to_cpu(sts->comp_status)));
  2113. rval = QLA_FUNCTION_FAILED;
  2114. } else if (!(le16_to_cpu(sts->scsi_status) &
  2115. SS_RESPONSE_INFO_LEN_VALID)) {
  2116. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2117. "-- no response info (%x).\n", __func__, vha->host_no,
  2118. le16_to_cpu(sts->scsi_status)));
  2119. rval = QLA_FUNCTION_FAILED;
  2120. } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
  2121. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2122. "-- not enough response info (%d).\n", __func__,
  2123. vha->host_no, le32_to_cpu(sts->rsp_data_len)));
  2124. rval = QLA_FUNCTION_FAILED;
  2125. } else if (sts->data[3]) {
  2126. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2127. "-- response (%x).\n", __func__,
  2128. vha->host_no, sts->data[3]));
  2129. rval = QLA_FUNCTION_FAILED;
  2130. }
  2131. /* Issue marker IOCB. */
  2132. rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
  2133. type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
  2134. if (rval2 != QLA_SUCCESS) {
  2135. DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
  2136. "(%x).\n", __func__, vha->host_no, rval2));
  2137. } else {
  2138. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2139. }
  2140. dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
  2141. return rval;
  2142. }
  2143. int
  2144. qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
  2145. {
  2146. return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
  2147. }
  2148. int
  2149. qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
  2150. {
  2151. return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
  2152. }
  2153. int
  2154. qla2x00_system_error(scsi_qla_host_t *vha)
  2155. {
  2156. int rval;
  2157. mbx_cmd_t mc;
  2158. mbx_cmd_t *mcp = &mc;
  2159. struct qla_hw_data *ha = vha->hw;
  2160. if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
  2161. return QLA_FUNCTION_FAILED;
  2162. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2163. mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
  2164. mcp->out_mb = MBX_0;
  2165. mcp->in_mb = MBX_0;
  2166. mcp->tov = 5;
  2167. mcp->flags = 0;
  2168. rval = qla2x00_mailbox_command(vha, mcp);
  2169. if (rval != QLA_SUCCESS) {
  2170. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2171. vha->host_no, rval));
  2172. } else {
  2173. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2174. }
  2175. return rval;
  2176. }
  2177. /**
  2178. * qla2x00_set_serdes_params() -
  2179. * @ha: HA context
  2180. *
  2181. * Returns
  2182. */
  2183. int
  2184. qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
  2185. uint16_t sw_em_2g, uint16_t sw_em_4g)
  2186. {
  2187. int rval;
  2188. mbx_cmd_t mc;
  2189. mbx_cmd_t *mcp = &mc;
  2190. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2191. mcp->mb[0] = MBC_SERDES_PARAMS;
  2192. mcp->mb[1] = BIT_0;
  2193. mcp->mb[2] = sw_em_1g | BIT_15;
  2194. mcp->mb[3] = sw_em_2g | BIT_15;
  2195. mcp->mb[4] = sw_em_4g | BIT_15;
  2196. mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2197. mcp->in_mb = MBX_0;
  2198. mcp->tov = MBX_TOV_SECONDS;
  2199. mcp->flags = 0;
  2200. rval = qla2x00_mailbox_command(vha, mcp);
  2201. if (rval != QLA_SUCCESS) {
  2202. /*EMPTY*/
  2203. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2204. vha->host_no, rval, mcp->mb[0]));
  2205. } else {
  2206. /*EMPTY*/
  2207. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2208. }
  2209. return rval;
  2210. }
  2211. int
  2212. qla2x00_stop_firmware(scsi_qla_host_t *vha)
  2213. {
  2214. int rval;
  2215. mbx_cmd_t mc;
  2216. mbx_cmd_t *mcp = &mc;
  2217. if (!IS_FWI2_CAPABLE(vha->hw))
  2218. return QLA_FUNCTION_FAILED;
  2219. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2220. mcp->mb[0] = MBC_STOP_FIRMWARE;
  2221. mcp->out_mb = MBX_0;
  2222. mcp->in_mb = MBX_0;
  2223. mcp->tov = 5;
  2224. mcp->flags = 0;
  2225. rval = qla2x00_mailbox_command(vha, mcp);
  2226. if (rval != QLA_SUCCESS) {
  2227. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2228. vha->host_no, rval));
  2229. if (mcp->mb[0] == MBS_INVALID_COMMAND)
  2230. rval = QLA_INVALID_COMMAND;
  2231. } else {
  2232. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2233. }
  2234. return rval;
  2235. }
  2236. int
  2237. qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
  2238. uint16_t buffers)
  2239. {
  2240. int rval;
  2241. mbx_cmd_t mc;
  2242. mbx_cmd_t *mcp = &mc;
  2243. if (!IS_FWI2_CAPABLE(vha->hw))
  2244. return QLA_FUNCTION_FAILED;
  2245. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2246. mcp->mb[0] = MBC_TRACE_CONTROL;
  2247. mcp->mb[1] = TC_EFT_ENABLE;
  2248. mcp->mb[2] = LSW(eft_dma);
  2249. mcp->mb[3] = MSW(eft_dma);
  2250. mcp->mb[4] = LSW(MSD(eft_dma));
  2251. mcp->mb[5] = MSW(MSD(eft_dma));
  2252. mcp->mb[6] = buffers;
  2253. mcp->mb[7] = TC_AEN_DISABLE;
  2254. mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2255. mcp->in_mb = MBX_1|MBX_0;
  2256. mcp->tov = MBX_TOV_SECONDS;
  2257. mcp->flags = 0;
  2258. rval = qla2x00_mailbox_command(vha, mcp);
  2259. if (rval != QLA_SUCCESS) {
  2260. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2261. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2262. } else {
  2263. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2264. }
  2265. return rval;
  2266. }
  2267. int
  2268. qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
  2269. {
  2270. int rval;
  2271. mbx_cmd_t mc;
  2272. mbx_cmd_t *mcp = &mc;
  2273. if (!IS_FWI2_CAPABLE(vha->hw))
  2274. return QLA_FUNCTION_FAILED;
  2275. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2276. mcp->mb[0] = MBC_TRACE_CONTROL;
  2277. mcp->mb[1] = TC_EFT_DISABLE;
  2278. mcp->out_mb = MBX_1|MBX_0;
  2279. mcp->in_mb = MBX_1|MBX_0;
  2280. mcp->tov = MBX_TOV_SECONDS;
  2281. mcp->flags = 0;
  2282. rval = qla2x00_mailbox_command(vha, mcp);
  2283. if (rval != QLA_SUCCESS) {
  2284. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2285. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2286. } else {
  2287. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2288. }
  2289. return rval;
  2290. }
  2291. int
  2292. qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
  2293. uint16_t buffers, uint16_t *mb, uint32_t *dwords)
  2294. {
  2295. int rval;
  2296. mbx_cmd_t mc;
  2297. mbx_cmd_t *mcp = &mc;
  2298. if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
  2299. return QLA_FUNCTION_FAILED;
  2300. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2301. mcp->mb[0] = MBC_TRACE_CONTROL;
  2302. mcp->mb[1] = TC_FCE_ENABLE;
  2303. mcp->mb[2] = LSW(fce_dma);
  2304. mcp->mb[3] = MSW(fce_dma);
  2305. mcp->mb[4] = LSW(MSD(fce_dma));
  2306. mcp->mb[5] = MSW(MSD(fce_dma));
  2307. mcp->mb[6] = buffers;
  2308. mcp->mb[7] = TC_AEN_DISABLE;
  2309. mcp->mb[8] = 0;
  2310. mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
  2311. mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
  2312. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
  2313. MBX_1|MBX_0;
  2314. mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2315. mcp->tov = MBX_TOV_SECONDS;
  2316. mcp->flags = 0;
  2317. rval = qla2x00_mailbox_command(vha, mcp);
  2318. if (rval != QLA_SUCCESS) {
  2319. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2320. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2321. } else {
  2322. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2323. if (mb)
  2324. memcpy(mb, mcp->mb, 8 * sizeof(*mb));
  2325. if (dwords)
  2326. *dwords = buffers;
  2327. }
  2328. return rval;
  2329. }
  2330. int
  2331. qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
  2332. {
  2333. int rval;
  2334. mbx_cmd_t mc;
  2335. mbx_cmd_t *mcp = &mc;
  2336. if (!IS_FWI2_CAPABLE(vha->hw))
  2337. return QLA_FUNCTION_FAILED;
  2338. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2339. mcp->mb[0] = MBC_TRACE_CONTROL;
  2340. mcp->mb[1] = TC_FCE_DISABLE;
  2341. mcp->mb[2] = TC_FCE_DISABLE_TRACE;
  2342. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  2343. mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
  2344. MBX_1|MBX_0;
  2345. mcp->tov = MBX_TOV_SECONDS;
  2346. mcp->flags = 0;
  2347. rval = qla2x00_mailbox_command(vha, mcp);
  2348. if (rval != QLA_SUCCESS) {
  2349. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2350. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2351. } else {
  2352. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2353. if (wr)
  2354. *wr = (uint64_t) mcp->mb[5] << 48 |
  2355. (uint64_t) mcp->mb[4] << 32 |
  2356. (uint64_t) mcp->mb[3] << 16 |
  2357. (uint64_t) mcp->mb[2];
  2358. if (rd)
  2359. *rd = (uint64_t) mcp->mb[9] << 48 |
  2360. (uint64_t) mcp->mb[8] << 32 |
  2361. (uint64_t) mcp->mb[7] << 16 |
  2362. (uint64_t) mcp->mb[6];
  2363. }
  2364. return rval;
  2365. }
  2366. int
  2367. qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
  2368. uint16_t off, uint16_t count)
  2369. {
  2370. int rval;
  2371. mbx_cmd_t mc;
  2372. mbx_cmd_t *mcp = &mc;
  2373. if (!IS_FWI2_CAPABLE(vha->hw))
  2374. return QLA_FUNCTION_FAILED;
  2375. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2376. mcp->mb[0] = MBC_READ_SFP;
  2377. mcp->mb[1] = addr;
  2378. mcp->mb[2] = MSW(sfp_dma);
  2379. mcp->mb[3] = LSW(sfp_dma);
  2380. mcp->mb[6] = MSW(MSD(sfp_dma));
  2381. mcp->mb[7] = LSW(MSD(sfp_dma));
  2382. mcp->mb[8] = count;
  2383. mcp->mb[9] = off;
  2384. mcp->mb[10] = 0;
  2385. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  2386. mcp->in_mb = MBX_0;
  2387. mcp->tov = MBX_TOV_SECONDS;
  2388. mcp->flags = 0;
  2389. rval = qla2x00_mailbox_command(vha, mcp);
  2390. if (rval != QLA_SUCCESS) {
  2391. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2392. vha->host_no, rval, mcp->mb[0]));
  2393. } else {
  2394. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2395. }
  2396. return rval;
  2397. }
  2398. int
  2399. qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
  2400. uint16_t port_speed, uint16_t *mb)
  2401. {
  2402. int rval;
  2403. mbx_cmd_t mc;
  2404. mbx_cmd_t *mcp = &mc;
  2405. if (!IS_IIDMA_CAPABLE(vha->hw))
  2406. return QLA_FUNCTION_FAILED;
  2407. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2408. mcp->mb[0] = MBC_PORT_PARAMS;
  2409. mcp->mb[1] = loop_id;
  2410. mcp->mb[2] = BIT_0;
  2411. if (IS_QLA81XX(vha->hw))
  2412. mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
  2413. else
  2414. mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
  2415. mcp->mb[9] = vha->vp_idx;
  2416. mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
  2417. mcp->in_mb = MBX_3|MBX_1|MBX_0;
  2418. mcp->tov = MBX_TOV_SECONDS;
  2419. mcp->flags = 0;
  2420. rval = qla2x00_mailbox_command(vha, mcp);
  2421. /* Return mailbox statuses. */
  2422. if (mb != NULL) {
  2423. mb[0] = mcp->mb[0];
  2424. mb[1] = mcp->mb[1];
  2425. mb[3] = mcp->mb[3];
  2426. }
  2427. if (rval != QLA_SUCCESS) {
  2428. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2429. vha->host_no, rval));
  2430. } else {
  2431. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2432. }
  2433. return rval;
  2434. }
  2435. void
  2436. qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
  2437. struct vp_rpt_id_entry_24xx *rptid_entry)
  2438. {
  2439. uint8_t vp_idx;
  2440. uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
  2441. struct qla_hw_data *ha = vha->hw;
  2442. scsi_qla_host_t *vp;
  2443. scsi_qla_host_t *tvp;
  2444. if (rptid_entry->entry_status != 0)
  2445. return;
  2446. if (rptid_entry->format == 0) {
  2447. DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
  2448. " number of VPs acquired %d\n", __func__, vha->host_no,
  2449. MSB(le16_to_cpu(rptid_entry->vp_count)),
  2450. LSB(le16_to_cpu(rptid_entry->vp_count))));
  2451. DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
  2452. rptid_entry->port_id[2], rptid_entry->port_id[1],
  2453. rptid_entry->port_id[0]));
  2454. } else if (rptid_entry->format == 1) {
  2455. vp_idx = LSB(stat);
  2456. DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
  2457. "- status %d - "
  2458. "with port id %02x%02x%02x\n", __func__, vha->host_no,
  2459. vp_idx, MSB(stat),
  2460. rptid_entry->port_id[2], rptid_entry->port_id[1],
  2461. rptid_entry->port_id[0]));
  2462. vp = vha;
  2463. if (vp_idx == 0 && (MSB(stat) != 1))
  2464. goto reg_needed;
  2465. if (MSB(stat) == 1) {
  2466. DEBUG2(printk("scsi(%ld): Could not acquire ID for "
  2467. "VP[%d].\n", vha->host_no, vp_idx));
  2468. return;
  2469. }
  2470. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
  2471. if (vp_idx == vp->vp_idx)
  2472. break;
  2473. if (!vp)
  2474. return;
  2475. vp->d_id.b.domain = rptid_entry->port_id[2];
  2476. vp->d_id.b.area = rptid_entry->port_id[1];
  2477. vp->d_id.b.al_pa = rptid_entry->port_id[0];
  2478. /*
  2479. * Cannot configure here as we are still sitting on the
  2480. * response queue. Handle it in dpc context.
  2481. */
  2482. set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
  2483. reg_needed:
  2484. set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
  2485. set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
  2486. set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
  2487. qla2xxx_wake_dpc(vha);
  2488. }
  2489. }
  2490. /*
  2491. * qla24xx_modify_vp_config
  2492. * Change VP configuration for vha
  2493. *
  2494. * Input:
  2495. * vha = adapter block pointer.
  2496. *
  2497. * Returns:
  2498. * qla2xxx local function return status code.
  2499. *
  2500. * Context:
  2501. * Kernel context.
  2502. */
  2503. int
  2504. qla24xx_modify_vp_config(scsi_qla_host_t *vha)
  2505. {
  2506. int rval;
  2507. struct vp_config_entry_24xx *vpmod;
  2508. dma_addr_t vpmod_dma;
  2509. struct qla_hw_data *ha = vha->hw;
  2510. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2511. /* This can be called by the parent */
  2512. vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
  2513. if (!vpmod) {
  2514. DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
  2515. "IOCB.\n", __func__, vha->host_no));
  2516. return QLA_MEMORY_ALLOC_FAILED;
  2517. }
  2518. memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
  2519. vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
  2520. vpmod->entry_count = 1;
  2521. vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
  2522. vpmod->vp_count = 1;
  2523. vpmod->vp_index1 = vha->vp_idx;
  2524. vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
  2525. memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
  2526. memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
  2527. vpmod->entry_count = 1;
  2528. rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
  2529. if (rval != QLA_SUCCESS) {
  2530. DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
  2531. "(%x).\n", __func__, base_vha->host_no, rval));
  2532. } else if (vpmod->comp_status != 0) {
  2533. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2534. "-- error status (%x).\n", __func__, base_vha->host_no,
  2535. vpmod->comp_status));
  2536. rval = QLA_FUNCTION_FAILED;
  2537. } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  2538. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2539. "-- completion status (%x).\n", __func__, base_vha->host_no,
  2540. le16_to_cpu(vpmod->comp_status)));
  2541. rval = QLA_FUNCTION_FAILED;
  2542. } else {
  2543. /* EMPTY */
  2544. DEBUG11(printk("%s(%ld): done.\n", __func__,
  2545. base_vha->host_no));
  2546. fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
  2547. }
  2548. dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
  2549. return rval;
  2550. }
  2551. /*
  2552. * qla24xx_control_vp
  2553. * Enable a virtual port for given host
  2554. *
  2555. * Input:
  2556. * ha = adapter block pointer.
  2557. * vhba = virtual adapter (unused)
  2558. * index = index number for enabled VP
  2559. *
  2560. * Returns:
  2561. * qla2xxx local function return status code.
  2562. *
  2563. * Context:
  2564. * Kernel context.
  2565. */
  2566. int
  2567. qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
  2568. {
  2569. int rval;
  2570. int map, pos;
  2571. struct vp_ctrl_entry_24xx *vce;
  2572. dma_addr_t vce_dma;
  2573. struct qla_hw_data *ha = vha->hw;
  2574. int vp_index = vha->vp_idx;
  2575. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2576. DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
  2577. vha->host_no, vp_index));
  2578. if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
  2579. return QLA_PARAMETER_ERROR;
  2580. vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
  2581. if (!vce) {
  2582. DEBUG2_3(printk("%s(%ld): "
  2583. "failed to allocate VP Control IOCB.\n", __func__,
  2584. base_vha->host_no));
  2585. return QLA_MEMORY_ALLOC_FAILED;
  2586. }
  2587. memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
  2588. vce->entry_type = VP_CTRL_IOCB_TYPE;
  2589. vce->entry_count = 1;
  2590. vce->command = cpu_to_le16(cmd);
  2591. vce->vp_count = __constant_cpu_to_le16(1);
  2592. /* index map in firmware starts with 1; decrement index
  2593. * this is ok as we never use index 0
  2594. */
  2595. map = (vp_index - 1) / 8;
  2596. pos = (vp_index - 1) & 7;
  2597. mutex_lock(&ha->vport_lock);
  2598. vce->vp_idx_map[map] |= 1 << pos;
  2599. mutex_unlock(&ha->vport_lock);
  2600. rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
  2601. if (rval != QLA_SUCCESS) {
  2602. DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
  2603. "(%x).\n", __func__, base_vha->host_no, rval));
  2604. printk("%s(%ld): failed to issue VP control IOCB"
  2605. "(%x).\n", __func__, base_vha->host_no, rval);
  2606. } else if (vce->entry_status != 0) {
  2607. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2608. "-- error status (%x).\n", __func__, base_vha->host_no,
  2609. vce->entry_status));
  2610. printk("%s(%ld): failed to complete IOCB "
  2611. "-- error status (%x).\n", __func__, base_vha->host_no,
  2612. vce->entry_status);
  2613. rval = QLA_FUNCTION_FAILED;
  2614. } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  2615. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2616. "-- completion status (%x).\n", __func__, base_vha->host_no,
  2617. le16_to_cpu(vce->comp_status)));
  2618. printk("%s(%ld): failed to complete IOCB "
  2619. "-- completion status (%x).\n", __func__, base_vha->host_no,
  2620. le16_to_cpu(vce->comp_status));
  2621. rval = QLA_FUNCTION_FAILED;
  2622. } else {
  2623. DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
  2624. }
  2625. dma_pool_free(ha->s_dma_pool, vce, vce_dma);
  2626. return rval;
  2627. }
  2628. /*
  2629. * qla2x00_send_change_request
  2630. * Receive or disable RSCN request from fabric controller
  2631. *
  2632. * Input:
  2633. * ha = adapter block pointer
  2634. * format = registration format:
  2635. * 0 - Reserved
  2636. * 1 - Fabric detected registration
  2637. * 2 - N_port detected registration
  2638. * 3 - Full registration
  2639. * FF - clear registration
  2640. * vp_idx = Virtual port index
  2641. *
  2642. * Returns:
  2643. * qla2x00 local function return status code.
  2644. *
  2645. * Context:
  2646. * Kernel Context
  2647. */
  2648. int
  2649. qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
  2650. uint16_t vp_idx)
  2651. {
  2652. int rval;
  2653. mbx_cmd_t mc;
  2654. mbx_cmd_t *mcp = &mc;
  2655. /*
  2656. * This command is implicitly executed by firmware during login for the
  2657. * physical hosts
  2658. */
  2659. if (vp_idx == 0)
  2660. return QLA_FUNCTION_FAILED;
  2661. mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
  2662. mcp->mb[1] = format;
  2663. mcp->mb[9] = vp_idx;
  2664. mcp->out_mb = MBX_9|MBX_1|MBX_0;
  2665. mcp->in_mb = MBX_0|MBX_1;
  2666. mcp->tov = MBX_TOV_SECONDS;
  2667. mcp->flags = 0;
  2668. rval = qla2x00_mailbox_command(vha, mcp);
  2669. if (rval == QLA_SUCCESS) {
  2670. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  2671. rval = BIT_1;
  2672. }
  2673. } else
  2674. rval = BIT_1;
  2675. return rval;
  2676. }
  2677. int
  2678. qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
  2679. uint32_t size)
  2680. {
  2681. int rval;
  2682. mbx_cmd_t mc;
  2683. mbx_cmd_t *mcp = &mc;
  2684. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2685. if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
  2686. mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
  2687. mcp->mb[8] = MSW(addr);
  2688. mcp->out_mb = MBX_8|MBX_0;
  2689. } else {
  2690. mcp->mb[0] = MBC_DUMP_RISC_RAM;
  2691. mcp->out_mb = MBX_0;
  2692. }
  2693. mcp->mb[1] = LSW(addr);
  2694. mcp->mb[2] = MSW(req_dma);
  2695. mcp->mb[3] = LSW(req_dma);
  2696. mcp->mb[6] = MSW(MSD(req_dma));
  2697. mcp->mb[7] = LSW(MSD(req_dma));
  2698. mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
  2699. if (IS_FWI2_CAPABLE(vha->hw)) {
  2700. mcp->mb[4] = MSW(size);
  2701. mcp->mb[5] = LSW(size);
  2702. mcp->out_mb |= MBX_5|MBX_4;
  2703. } else {
  2704. mcp->mb[4] = LSW(size);
  2705. mcp->out_mb |= MBX_4;
  2706. }
  2707. mcp->in_mb = MBX_0;
  2708. mcp->tov = MBX_TOV_SECONDS;
  2709. mcp->flags = 0;
  2710. rval = qla2x00_mailbox_command(vha, mcp);
  2711. if (rval != QLA_SUCCESS) {
  2712. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  2713. vha->host_no, rval, mcp->mb[0]));
  2714. } else {
  2715. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2716. }
  2717. return rval;
  2718. }
  2719. /* 84XX Support **************************************************************/
  2720. struct cs84xx_mgmt_cmd {
  2721. union {
  2722. struct verify_chip_entry_84xx req;
  2723. struct verify_chip_rsp_84xx rsp;
  2724. } p;
  2725. };
  2726. int
  2727. qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
  2728. {
  2729. int rval, retry;
  2730. struct cs84xx_mgmt_cmd *mn;
  2731. dma_addr_t mn_dma;
  2732. uint16_t options;
  2733. unsigned long flags;
  2734. struct qla_hw_data *ha = vha->hw;
  2735. DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2736. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  2737. if (mn == NULL) {
  2738. DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
  2739. "IOCB.\n", __func__, vha->host_no));
  2740. return QLA_MEMORY_ALLOC_FAILED;
  2741. }
  2742. /* Force Update? */
  2743. options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
  2744. /* Diagnostic firmware? */
  2745. /* options |= MENLO_DIAG_FW; */
  2746. /* We update the firmware with only one data sequence. */
  2747. options |= VCO_END_OF_DATA;
  2748. do {
  2749. retry = 0;
  2750. memset(mn, 0, sizeof(*mn));
  2751. mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
  2752. mn->p.req.entry_count = 1;
  2753. mn->p.req.options = cpu_to_le16(options);
  2754. DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
  2755. vha->host_no));
  2756. DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
  2757. sizeof(*mn)));
  2758. rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
  2759. if (rval != QLA_SUCCESS) {
  2760. DEBUG2_16(printk("%s(%ld): failed to issue Verify "
  2761. "IOCB (%x).\n", __func__, vha->host_no, rval));
  2762. goto verify_done;
  2763. }
  2764. DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
  2765. vha->host_no));
  2766. DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
  2767. sizeof(*mn)));
  2768. status[0] = le16_to_cpu(mn->p.rsp.comp_status);
  2769. status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
  2770. le16_to_cpu(mn->p.rsp.failure_code) : 0;
  2771. DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
  2772. vha->host_no, status[0], status[1]));
  2773. if (status[0] != CS_COMPLETE) {
  2774. rval = QLA_FUNCTION_FAILED;
  2775. if (!(options & VCO_DONT_UPDATE_FW)) {
  2776. DEBUG2_16(printk("%s(%ld): Firmware update "
  2777. "failed. Retrying without update "
  2778. "firmware.\n", __func__, vha->host_no));
  2779. options |= VCO_DONT_UPDATE_FW;
  2780. options &= ~VCO_FORCE_UPDATE;
  2781. retry = 1;
  2782. }
  2783. } else {
  2784. DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
  2785. __func__, vha->host_no,
  2786. le32_to_cpu(mn->p.rsp.fw_ver)));
  2787. /* NOTE: we only update OP firmware. */
  2788. spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
  2789. ha->cs84xx->op_fw_version =
  2790. le32_to_cpu(mn->p.rsp.fw_ver);
  2791. spin_unlock_irqrestore(&ha->cs84xx->access_lock,
  2792. flags);
  2793. }
  2794. } while (retry);
  2795. verify_done:
  2796. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  2797. if (rval != QLA_SUCCESS) {
  2798. DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
  2799. vha->host_no, rval));
  2800. } else {
  2801. DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2802. }
  2803. return rval;
  2804. }
  2805. int
  2806. qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
  2807. {
  2808. int rval;
  2809. unsigned long flags;
  2810. mbx_cmd_t mc;
  2811. mbx_cmd_t *mcp = &mc;
  2812. struct device_reg_25xxmq __iomem *reg;
  2813. struct qla_hw_data *ha = vha->hw;
  2814. mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
  2815. mcp->mb[1] = req->options;
  2816. mcp->mb[2] = MSW(LSD(req->dma));
  2817. mcp->mb[3] = LSW(LSD(req->dma));
  2818. mcp->mb[6] = MSW(MSD(req->dma));
  2819. mcp->mb[7] = LSW(MSD(req->dma));
  2820. mcp->mb[5] = req->length;
  2821. if (req->rsp)
  2822. mcp->mb[10] = req->rsp->id;
  2823. mcp->mb[12] = req->qos;
  2824. mcp->mb[11] = req->vp_idx;
  2825. mcp->mb[13] = req->rid;
  2826. reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
  2827. QLA_QUE_PAGE * req->id);
  2828. mcp->mb[4] = req->id;
  2829. /* que in ptr index */
  2830. mcp->mb[8] = 0;
  2831. /* que out ptr index */
  2832. mcp->mb[9] = 0;
  2833. mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
  2834. MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2835. mcp->in_mb = MBX_0;
  2836. mcp->flags = MBX_DMA_OUT;
  2837. mcp->tov = 60;
  2838. spin_lock_irqsave(&ha->hardware_lock, flags);
  2839. if (!(req->options & BIT_0)) {
  2840. WRT_REG_DWORD(&reg->req_q_in, 0);
  2841. WRT_REG_DWORD(&reg->req_q_out, 0);
  2842. }
  2843. req->req_q_in = &reg->req_q_in;
  2844. req->req_q_out = &reg->req_q_out;
  2845. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2846. rval = qla2x00_mailbox_command(vha, mcp);
  2847. if (rval != QLA_SUCCESS)
  2848. DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
  2849. __func__, vha->host_no, rval, mcp->mb[0]));
  2850. return rval;
  2851. }
  2852. int
  2853. qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
  2854. {
  2855. int rval;
  2856. unsigned long flags;
  2857. mbx_cmd_t mc;
  2858. mbx_cmd_t *mcp = &mc;
  2859. struct device_reg_25xxmq __iomem *reg;
  2860. struct qla_hw_data *ha = vha->hw;
  2861. mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
  2862. mcp->mb[1] = rsp->options;
  2863. mcp->mb[2] = MSW(LSD(rsp->dma));
  2864. mcp->mb[3] = LSW(LSD(rsp->dma));
  2865. mcp->mb[6] = MSW(MSD(rsp->dma));
  2866. mcp->mb[7] = LSW(MSD(rsp->dma));
  2867. mcp->mb[5] = rsp->length;
  2868. mcp->mb[14] = rsp->msix->entry;
  2869. mcp->mb[13] = rsp->rid;
  2870. reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
  2871. QLA_QUE_PAGE * rsp->id);
  2872. mcp->mb[4] = rsp->id;
  2873. /* que in ptr index */
  2874. mcp->mb[8] = 0;
  2875. /* que out ptr index */
  2876. mcp->mb[9] = 0;
  2877. mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
  2878. |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2879. mcp->in_mb = MBX_0;
  2880. mcp->flags = MBX_DMA_OUT;
  2881. mcp->tov = 60;
  2882. spin_lock_irqsave(&ha->hardware_lock, flags);
  2883. if (!(rsp->options & BIT_0)) {
  2884. WRT_REG_DWORD(&reg->rsp_q_out, 0);
  2885. WRT_REG_DWORD(&reg->rsp_q_in, 0);
  2886. }
  2887. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2888. rval = qla2x00_mailbox_command(vha, mcp);
  2889. if (rval != QLA_SUCCESS)
  2890. DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
  2891. "mb0=%x.\n", __func__,
  2892. vha->host_no, rval, mcp->mb[0]));
  2893. return rval;
  2894. }
  2895. int
  2896. qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
  2897. {
  2898. int rval;
  2899. mbx_cmd_t mc;
  2900. mbx_cmd_t *mcp = &mc;
  2901. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2902. mcp->mb[0] = MBC_IDC_ACK;
  2903. memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  2904. mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2905. mcp->in_mb = MBX_0;
  2906. mcp->tov = MBX_TOV_SECONDS;
  2907. mcp->flags = 0;
  2908. rval = qla2x00_mailbox_command(vha, mcp);
  2909. if (rval != QLA_SUCCESS) {
  2910. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2911. vha->host_no, rval, mcp->mb[0]));
  2912. } else {
  2913. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2914. }
  2915. return rval;
  2916. }
  2917. int
  2918. qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
  2919. {
  2920. int rval;
  2921. mbx_cmd_t mc;
  2922. mbx_cmd_t *mcp = &mc;
  2923. if (!IS_QLA81XX(vha->hw))
  2924. return QLA_FUNCTION_FAILED;
  2925. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2926. mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
  2927. mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
  2928. mcp->out_mb = MBX_1|MBX_0;
  2929. mcp->in_mb = MBX_1|MBX_0;
  2930. mcp->tov = MBX_TOV_SECONDS;
  2931. mcp->flags = 0;
  2932. rval = qla2x00_mailbox_command(vha, mcp);
  2933. if (rval != QLA_SUCCESS) {
  2934. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2935. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2936. } else {
  2937. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2938. *sector_size = mcp->mb[1];
  2939. }
  2940. return rval;
  2941. }
  2942. int
  2943. qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
  2944. {
  2945. int rval;
  2946. mbx_cmd_t mc;
  2947. mbx_cmd_t *mcp = &mc;
  2948. if (!IS_QLA81XX(vha->hw))
  2949. return QLA_FUNCTION_FAILED;
  2950. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2951. mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
  2952. mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
  2953. FAC_OPT_CMD_WRITE_PROTECT;
  2954. mcp->out_mb = MBX_1|MBX_0;
  2955. mcp->in_mb = MBX_1|MBX_0;
  2956. mcp->tov = MBX_TOV_SECONDS;
  2957. mcp->flags = 0;
  2958. rval = qla2x00_mailbox_command(vha, mcp);
  2959. if (rval != QLA_SUCCESS) {
  2960. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2961. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2962. } else {
  2963. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2964. }
  2965. return rval;
  2966. }
  2967. int
  2968. qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
  2969. {
  2970. int rval;
  2971. mbx_cmd_t mc;
  2972. mbx_cmd_t *mcp = &mc;
  2973. if (!IS_QLA81XX(vha->hw))
  2974. return QLA_FUNCTION_FAILED;
  2975. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2976. mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
  2977. mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
  2978. mcp->mb[2] = LSW(start);
  2979. mcp->mb[3] = MSW(start);
  2980. mcp->mb[4] = LSW(finish);
  2981. mcp->mb[5] = MSW(finish);
  2982. mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2983. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  2984. mcp->tov = MBX_TOV_SECONDS;
  2985. mcp->flags = 0;
  2986. rval = qla2x00_mailbox_command(vha, mcp);
  2987. if (rval != QLA_SUCCESS) {
  2988. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  2989. "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
  2990. mcp->mb[1], mcp->mb[2]));
  2991. } else {
  2992. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2993. }
  2994. return rval;
  2995. }
  2996. int
  2997. qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
  2998. {
  2999. int rval = 0;
  3000. mbx_cmd_t mc;
  3001. mbx_cmd_t *mcp = &mc;
  3002. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  3003. mcp->mb[0] = MBC_RESTART_MPI_FW;
  3004. mcp->out_mb = MBX_0;
  3005. mcp->in_mb = MBX_0|MBX_1;
  3006. mcp->tov = MBX_TOV_SECONDS;
  3007. mcp->flags = 0;
  3008. rval = qla2x00_mailbox_command(vha, mcp);
  3009. if (rval != QLA_SUCCESS) {
  3010. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
  3011. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  3012. } else {
  3013. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  3014. }
  3015. return rval;
  3016. }
  3017. int
  3018. qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
  3019. dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
  3020. {
  3021. int rval;
  3022. mbx_cmd_t mc;
  3023. mbx_cmd_t *mcp = &mc;
  3024. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  3025. mcp->mb[0] = MBC_READ_SFP;
  3026. mcp->mb[1] = dev;
  3027. mcp->mb[2] = MSW(sfp_dma);
  3028. mcp->mb[3] = LSW(sfp_dma);
  3029. mcp->mb[6] = MSW(MSD(sfp_dma));
  3030. mcp->mb[7] = LSW(MSD(sfp_dma));
  3031. mcp->mb[8] = len;
  3032. mcp->mb[9] = adr;
  3033. mcp->mb[10] = opt;
  3034. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  3035. mcp->in_mb = MBX_0;
  3036. mcp->tov = MBX_TOV_SECONDS;
  3037. mcp->flags = 0;
  3038. rval = qla2x00_mailbox_command(vha, mcp);
  3039. if (opt & BIT_0)
  3040. if (sfp)
  3041. *sfp = mcp->mb[8];
  3042. if (rval != QLA_SUCCESS) {
  3043. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  3044. vha->host_no, rval, mcp->mb[0]));
  3045. } else {
  3046. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  3047. }
  3048. return rval;
  3049. }
  3050. int
  3051. qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
  3052. dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
  3053. {
  3054. int rval;
  3055. mbx_cmd_t mc;
  3056. mbx_cmd_t *mcp = &mc;
  3057. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  3058. if (opt & BIT_0)
  3059. if (sfp)
  3060. len = *sfp;
  3061. mcp->mb[0] = MBC_WRITE_SFP;
  3062. mcp->mb[1] = dev;
  3063. mcp->mb[2] = MSW(sfp_dma);
  3064. mcp->mb[3] = LSW(sfp_dma);
  3065. mcp->mb[6] = MSW(MSD(sfp_dma));
  3066. mcp->mb[7] = LSW(MSD(sfp_dma));
  3067. mcp->mb[8] = len;
  3068. mcp->mb[9] = adr;
  3069. mcp->mb[10] = opt;
  3070. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  3071. mcp->in_mb = MBX_0;
  3072. mcp->tov = MBX_TOV_SECONDS;
  3073. mcp->flags = 0;
  3074. rval = qla2x00_mailbox_command(vha, mcp);
  3075. if (rval != QLA_SUCCESS) {
  3076. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  3077. vha->host_no, rval, mcp->mb[0]));
  3078. } else {
  3079. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  3080. }
  3081. return rval;
  3082. }
  3083. int
  3084. qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
  3085. uint16_t size_in_bytes, uint16_t *actual_size)
  3086. {
  3087. int rval;
  3088. mbx_cmd_t mc;
  3089. mbx_cmd_t *mcp = &mc;
  3090. if (!IS_QLA81XX(vha->hw))
  3091. return QLA_FUNCTION_FAILED;
  3092. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  3093. mcp->mb[0] = MBC_GET_XGMAC_STATS;
  3094. mcp->mb[2] = MSW(stats_dma);
  3095. mcp->mb[3] = LSW(stats_dma);
  3096. mcp->mb[6] = MSW(MSD(stats_dma));
  3097. mcp->mb[7] = LSW(MSD(stats_dma));
  3098. mcp->mb[8] = size_in_bytes >> 2;
  3099. mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  3100. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  3101. mcp->tov = MBX_TOV_SECONDS;
  3102. mcp->flags = 0;
  3103. rval = qla2x00_mailbox_command(vha, mcp);
  3104. if (rval != QLA_SUCCESS) {
  3105. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
  3106. "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
  3107. mcp->mb[0], mcp->mb[1], mcp->mb[2]));
  3108. } else {
  3109. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  3110. *actual_size = mcp->mb[2] << 2;
  3111. }
  3112. return rval;
  3113. }
  3114. int
  3115. qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
  3116. uint16_t size)
  3117. {
  3118. int rval;
  3119. mbx_cmd_t mc;
  3120. mbx_cmd_t *mcp = &mc;
  3121. if (!IS_QLA81XX(vha->hw))
  3122. return QLA_FUNCTION_FAILED;
  3123. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  3124. mcp->mb[0] = MBC_GET_DCBX_PARAMS;
  3125. mcp->mb[1] = 0;
  3126. mcp->mb[2] = MSW(tlv_dma);
  3127. mcp->mb[3] = LSW(tlv_dma);
  3128. mcp->mb[6] = MSW(MSD(tlv_dma));
  3129. mcp->mb[7] = LSW(MSD(tlv_dma));
  3130. mcp->mb[8] = size;
  3131. mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  3132. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  3133. mcp->tov = MBX_TOV_SECONDS;
  3134. mcp->flags = 0;
  3135. rval = qla2x00_mailbox_command(vha, mcp);
  3136. if (rval != QLA_SUCCESS) {
  3137. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
  3138. "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
  3139. mcp->mb[0], mcp->mb[1], mcp->mb[2]));
  3140. } else {
  3141. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  3142. }
  3143. return rval;
  3144. }
  3145. int
  3146. qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
  3147. {
  3148. int rval;
  3149. mbx_cmd_t mc;
  3150. mbx_cmd_t *mcp = &mc;
  3151. if (!IS_FWI2_CAPABLE(vha->hw))
  3152. return QLA_FUNCTION_FAILED;
  3153. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  3154. mcp->mb[0] = MBC_READ_RAM_EXTENDED;
  3155. mcp->mb[1] = LSW(risc_addr);
  3156. mcp->mb[8] = MSW(risc_addr);
  3157. mcp->out_mb = MBX_8|MBX_1|MBX_0;
  3158. mcp->in_mb = MBX_3|MBX_2|MBX_0;
  3159. mcp->tov = 30;
  3160. mcp->flags = 0;
  3161. rval = qla2x00_mailbox_command(vha, mcp);
  3162. if (rval != QLA_SUCCESS) {
  3163. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  3164. vha->host_no, rval, mcp->mb[0]));
  3165. } else {
  3166. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  3167. *data = mcp->mb[3] << 16 | mcp->mb[2];
  3168. }
  3169. return rval;
  3170. }
  3171. int
  3172. qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
  3173. {
  3174. int rval;
  3175. mbx_cmd_t mc;
  3176. mbx_cmd_t *mcp = &mc;
  3177. if (!IS_FWI2_CAPABLE(vha->hw))
  3178. return QLA_FUNCTION_FAILED;
  3179. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  3180. mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
  3181. mcp->mb[1] = LSW(risc_addr);
  3182. mcp->mb[2] = LSW(data);
  3183. mcp->mb[3] = MSW(data);
  3184. mcp->mb[8] = MSW(risc_addr);
  3185. mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
  3186. mcp->in_mb = MBX_0;
  3187. mcp->tov = 30;
  3188. mcp->flags = 0;
  3189. rval = qla2x00_mailbox_command(vha, mcp);
  3190. if (rval != QLA_SUCCESS) {
  3191. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  3192. vha->host_no, rval, mcp->mb[0]));
  3193. } else {
  3194. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  3195. }
  3196. return rval;
  3197. }