qla_mbx.c 87 KB

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