qla_mbx.c 81 KB

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