qla_mbx.c 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193
  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[2] = MSW(ha->init_cb_dma);
  918. mcp->mb[3] = LSW(ha->init_cb_dma);
  919. mcp->mb[4] = 0;
  920. mcp->mb[5] = 0;
  921. mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
  922. mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
  923. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  924. mcp->in_mb = MBX_5|MBX_4|MBX_0;
  925. mcp->buf_size = size;
  926. mcp->flags = MBX_DMA_OUT;
  927. mcp->tov = MBX_TOV_SECONDS;
  928. rval = qla2x00_mailbox_command(vha, mcp);
  929. if (rval != QLA_SUCCESS) {
  930. /*EMPTY*/
  931. DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
  932. "mb0=%x.\n",
  933. vha->host_no, rval, mcp->mb[0]));
  934. } else {
  935. /*EMPTY*/
  936. DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
  937. vha->host_no));
  938. }
  939. return rval;
  940. }
  941. /*
  942. * qla2x00_get_port_database
  943. * Issue normal/enhanced get port database mailbox command
  944. * and copy device name as necessary.
  945. *
  946. * Input:
  947. * ha = adapter state pointer.
  948. * dev = structure pointer.
  949. * opt = enhanced cmd option byte.
  950. *
  951. * Returns:
  952. * qla2x00 local function return status code.
  953. *
  954. * Context:
  955. * Kernel context.
  956. */
  957. int
  958. qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
  959. {
  960. int rval;
  961. mbx_cmd_t mc;
  962. mbx_cmd_t *mcp = &mc;
  963. port_database_t *pd;
  964. struct port_database_24xx *pd24;
  965. dma_addr_t pd_dma;
  966. struct qla_hw_data *ha = vha->hw;
  967. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  968. pd24 = NULL;
  969. pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
  970. if (pd == NULL) {
  971. DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
  972. "structure.\n", __func__, vha->host_no));
  973. return QLA_MEMORY_ALLOC_FAILED;
  974. }
  975. memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
  976. mcp->mb[0] = MBC_GET_PORT_DATABASE;
  977. if (opt != 0 && !IS_FWI2_CAPABLE(ha))
  978. mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
  979. mcp->mb[2] = MSW(pd_dma);
  980. mcp->mb[3] = LSW(pd_dma);
  981. mcp->mb[6] = MSW(MSD(pd_dma));
  982. mcp->mb[7] = LSW(MSD(pd_dma));
  983. mcp->mb[9] = vha->vp_idx;
  984. mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  985. mcp->in_mb = MBX_0;
  986. if (IS_FWI2_CAPABLE(ha)) {
  987. mcp->mb[1] = fcport->loop_id;
  988. mcp->mb[10] = opt;
  989. mcp->out_mb |= MBX_10|MBX_1;
  990. mcp->in_mb |= MBX_1;
  991. } else if (HAS_EXTENDED_IDS(ha)) {
  992. mcp->mb[1] = fcport->loop_id;
  993. mcp->mb[10] = opt;
  994. mcp->out_mb |= MBX_10|MBX_1;
  995. } else {
  996. mcp->mb[1] = fcport->loop_id << 8 | opt;
  997. mcp->out_mb |= MBX_1;
  998. }
  999. mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
  1000. PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
  1001. mcp->flags = MBX_DMA_IN;
  1002. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1003. rval = qla2x00_mailbox_command(vha, mcp);
  1004. if (rval != QLA_SUCCESS)
  1005. goto gpd_error_out;
  1006. if (IS_FWI2_CAPABLE(ha)) {
  1007. pd24 = (struct port_database_24xx *) pd;
  1008. /* Check for logged in state. */
  1009. if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
  1010. pd24->last_login_state != PDS_PRLI_COMPLETE) {
  1011. DEBUG2(printk("%s(%ld): Unable to verify "
  1012. "login-state (%x/%x) for loop_id %x\n",
  1013. __func__, vha->host_no,
  1014. pd24->current_login_state,
  1015. pd24->last_login_state, fcport->loop_id));
  1016. rval = QLA_FUNCTION_FAILED;
  1017. goto gpd_error_out;
  1018. }
  1019. /* Names are little-endian. */
  1020. memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
  1021. memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
  1022. /* Get port_id of device. */
  1023. fcport->d_id.b.domain = pd24->port_id[0];
  1024. fcport->d_id.b.area = pd24->port_id[1];
  1025. fcport->d_id.b.al_pa = pd24->port_id[2];
  1026. fcport->d_id.b.rsvd_1 = 0;
  1027. /* If not target must be initiator or unknown type. */
  1028. if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
  1029. fcport->port_type = FCT_INITIATOR;
  1030. else
  1031. fcport->port_type = FCT_TARGET;
  1032. } else {
  1033. /* Check for logged in state. */
  1034. if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
  1035. pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
  1036. rval = QLA_FUNCTION_FAILED;
  1037. goto gpd_error_out;
  1038. }
  1039. /* Names are little-endian. */
  1040. memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
  1041. memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
  1042. /* Get port_id of device. */
  1043. fcport->d_id.b.domain = pd->port_id[0];
  1044. fcport->d_id.b.area = pd->port_id[3];
  1045. fcport->d_id.b.al_pa = pd->port_id[2];
  1046. fcport->d_id.b.rsvd_1 = 0;
  1047. /* Check for device require authentication. */
  1048. pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
  1049. (fcport->flags &= ~FCF_AUTH_REQ);
  1050. /* If not target must be initiator or unknown type. */
  1051. if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
  1052. fcport->port_type = FCT_INITIATOR;
  1053. else
  1054. fcport->port_type = FCT_TARGET;
  1055. /* Passback COS information. */
  1056. fcport->supported_classes = (pd->options & BIT_4) ?
  1057. FC_COS_CLASS2: FC_COS_CLASS3;
  1058. }
  1059. gpd_error_out:
  1060. dma_pool_free(ha->s_dma_pool, pd, pd_dma);
  1061. if (rval != QLA_SUCCESS) {
  1062. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  1063. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1064. } else {
  1065. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1066. }
  1067. return rval;
  1068. }
  1069. /*
  1070. * qla2x00_get_firmware_state
  1071. * Get adapter firmware state.
  1072. *
  1073. * Input:
  1074. * ha = adapter block pointer.
  1075. * dptr = pointer for firmware state.
  1076. * TARGET_QUEUE_LOCK must be released.
  1077. * ADAPTER_STATE_LOCK must be released.
  1078. *
  1079. * Returns:
  1080. * qla2x00 local function return status code.
  1081. *
  1082. * Context:
  1083. * Kernel context.
  1084. */
  1085. int
  1086. qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
  1087. {
  1088. int rval;
  1089. mbx_cmd_t mc;
  1090. mbx_cmd_t *mcp = &mc;
  1091. DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
  1092. vha->host_no));
  1093. mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
  1094. mcp->out_mb = MBX_0;
  1095. mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1096. mcp->tov = MBX_TOV_SECONDS;
  1097. mcp->flags = 0;
  1098. rval = qla2x00_mailbox_command(vha, mcp);
  1099. /* Return firmware states. */
  1100. states[0] = mcp->mb[1];
  1101. states[1] = mcp->mb[2];
  1102. states[2] = mcp->mb[3];
  1103. if (rval != QLA_SUCCESS) {
  1104. /*EMPTY*/
  1105. DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
  1106. "failed=%x.\n", vha->host_no, rval));
  1107. } else {
  1108. /*EMPTY*/
  1109. DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
  1110. vha->host_no));
  1111. }
  1112. return rval;
  1113. }
  1114. /*
  1115. * qla2x00_get_port_name
  1116. * Issue get port name mailbox command.
  1117. * Returned name is in big endian format.
  1118. *
  1119. * Input:
  1120. * ha = adapter block pointer.
  1121. * loop_id = loop ID of device.
  1122. * name = pointer for name.
  1123. * TARGET_QUEUE_LOCK must be released.
  1124. * ADAPTER_STATE_LOCK must be released.
  1125. *
  1126. * Returns:
  1127. * qla2x00 local function return status code.
  1128. *
  1129. * Context:
  1130. * Kernel context.
  1131. */
  1132. int
  1133. qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
  1134. uint8_t opt)
  1135. {
  1136. int rval;
  1137. mbx_cmd_t mc;
  1138. mbx_cmd_t *mcp = &mc;
  1139. DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
  1140. vha->host_no));
  1141. mcp->mb[0] = MBC_GET_PORT_NAME;
  1142. mcp->mb[9] = vha->vp_idx;
  1143. mcp->out_mb = MBX_9|MBX_1|MBX_0;
  1144. if (HAS_EXTENDED_IDS(vha->hw)) {
  1145. mcp->mb[1] = loop_id;
  1146. mcp->mb[10] = opt;
  1147. mcp->out_mb |= MBX_10;
  1148. } else {
  1149. mcp->mb[1] = loop_id << 8 | opt;
  1150. }
  1151. mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1152. mcp->tov = MBX_TOV_SECONDS;
  1153. mcp->flags = 0;
  1154. rval = qla2x00_mailbox_command(vha, mcp);
  1155. if (rval != QLA_SUCCESS) {
  1156. /*EMPTY*/
  1157. DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
  1158. vha->host_no, rval));
  1159. } else {
  1160. if (name != NULL) {
  1161. /* This function returns name in big endian. */
  1162. name[0] = MSB(mcp->mb[2]);
  1163. name[1] = LSB(mcp->mb[2]);
  1164. name[2] = MSB(mcp->mb[3]);
  1165. name[3] = LSB(mcp->mb[3]);
  1166. name[4] = MSB(mcp->mb[6]);
  1167. name[5] = LSB(mcp->mb[6]);
  1168. name[6] = MSB(mcp->mb[7]);
  1169. name[7] = LSB(mcp->mb[7]);
  1170. }
  1171. DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
  1172. vha->host_no));
  1173. }
  1174. return rval;
  1175. }
  1176. /*
  1177. * qla2x00_lip_reset
  1178. * Issue LIP reset mailbox command.
  1179. *
  1180. * Input:
  1181. * ha = adapter block pointer.
  1182. * TARGET_QUEUE_LOCK must be released.
  1183. * ADAPTER_STATE_LOCK must be released.
  1184. *
  1185. * Returns:
  1186. * qla2x00 local function return status code.
  1187. *
  1188. * Context:
  1189. * Kernel context.
  1190. */
  1191. int
  1192. qla2x00_lip_reset(scsi_qla_host_t *vha)
  1193. {
  1194. int rval;
  1195. mbx_cmd_t mc;
  1196. mbx_cmd_t *mcp = &mc;
  1197. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1198. if (IS_QLA81XX(vha->hw)) {
  1199. /* Logout across all FCFs. */
  1200. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1201. mcp->mb[1] = BIT_1;
  1202. mcp->mb[2] = 0;
  1203. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  1204. } else if (IS_FWI2_CAPABLE(vha->hw)) {
  1205. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1206. mcp->mb[1] = BIT_6;
  1207. mcp->mb[2] = 0;
  1208. mcp->mb[3] = vha->hw->loop_reset_delay;
  1209. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1210. } else {
  1211. mcp->mb[0] = MBC_LIP_RESET;
  1212. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1213. if (HAS_EXTENDED_IDS(vha->hw)) {
  1214. mcp->mb[1] = 0x00ff;
  1215. mcp->mb[10] = 0;
  1216. mcp->out_mb |= MBX_10;
  1217. } else {
  1218. mcp->mb[1] = 0xff00;
  1219. }
  1220. mcp->mb[2] = vha->hw->loop_reset_delay;
  1221. mcp->mb[3] = 0;
  1222. }
  1223. mcp->in_mb = MBX_0;
  1224. mcp->tov = MBX_TOV_SECONDS;
  1225. mcp->flags = 0;
  1226. rval = qla2x00_mailbox_command(vha, mcp);
  1227. if (rval != QLA_SUCCESS) {
  1228. /*EMPTY*/
  1229. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
  1230. __func__, vha->host_no, rval));
  1231. } else {
  1232. /*EMPTY*/
  1233. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1234. }
  1235. return rval;
  1236. }
  1237. /*
  1238. * qla2x00_send_sns
  1239. * Send SNS command.
  1240. *
  1241. * Input:
  1242. * ha = adapter block pointer.
  1243. * sns = pointer for command.
  1244. * cmd_size = command size.
  1245. * buf_size = response/command size.
  1246. * TARGET_QUEUE_LOCK must be released.
  1247. * ADAPTER_STATE_LOCK must be released.
  1248. *
  1249. * Returns:
  1250. * qla2x00 local function return status code.
  1251. *
  1252. * Context:
  1253. * Kernel context.
  1254. */
  1255. int
  1256. qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
  1257. uint16_t cmd_size, size_t buf_size)
  1258. {
  1259. int rval;
  1260. mbx_cmd_t mc;
  1261. mbx_cmd_t *mcp = &mc;
  1262. DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
  1263. vha->host_no));
  1264. DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
  1265. "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
  1266. mcp->tov));
  1267. mcp->mb[0] = MBC_SEND_SNS_COMMAND;
  1268. mcp->mb[1] = cmd_size;
  1269. mcp->mb[2] = MSW(sns_phys_address);
  1270. mcp->mb[3] = LSW(sns_phys_address);
  1271. mcp->mb[6] = MSW(MSD(sns_phys_address));
  1272. mcp->mb[7] = LSW(MSD(sns_phys_address));
  1273. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1274. mcp->in_mb = MBX_0|MBX_1;
  1275. mcp->buf_size = buf_size;
  1276. mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
  1277. mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
  1278. rval = qla2x00_mailbox_command(vha, mcp);
  1279. if (rval != QLA_SUCCESS) {
  1280. /*EMPTY*/
  1281. DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1282. "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1283. DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1284. "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1285. } else {
  1286. /*EMPTY*/
  1287. DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
  1288. }
  1289. return rval;
  1290. }
  1291. int
  1292. qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
  1293. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1294. {
  1295. int rval;
  1296. struct logio_entry_24xx *lg;
  1297. dma_addr_t lg_dma;
  1298. uint32_t iop[2];
  1299. struct qla_hw_data *ha = vha->hw;
  1300. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1301. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1302. if (lg == NULL) {
  1303. DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
  1304. __func__, vha->host_no));
  1305. return QLA_MEMORY_ALLOC_FAILED;
  1306. }
  1307. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1308. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1309. lg->entry_count = 1;
  1310. lg->nport_handle = cpu_to_le16(loop_id);
  1311. lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
  1312. if (opt & BIT_0)
  1313. lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
  1314. if (opt & BIT_1)
  1315. lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
  1316. lg->port_id[0] = al_pa;
  1317. lg->port_id[1] = area;
  1318. lg->port_id[2] = domain;
  1319. lg->vp_index = vha->vp_idx;
  1320. rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
  1321. if (rval != QLA_SUCCESS) {
  1322. DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
  1323. "(%x).\n", __func__, vha->host_no, rval));
  1324. } else if (lg->entry_status != 0) {
  1325. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1326. "-- error status (%x).\n", __func__, vha->host_no,
  1327. lg->entry_status));
  1328. rval = QLA_FUNCTION_FAILED;
  1329. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1330. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1331. iop[1] = le32_to_cpu(lg->io_parameter[1]);
  1332. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1333. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1334. vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
  1335. iop[1]));
  1336. switch (iop[0]) {
  1337. case LSC_SCODE_PORTID_USED:
  1338. mb[0] = MBS_PORT_ID_USED;
  1339. mb[1] = LSW(iop[1]);
  1340. break;
  1341. case LSC_SCODE_NPORT_USED:
  1342. mb[0] = MBS_LOOP_ID_USED;
  1343. break;
  1344. case LSC_SCODE_NOLINK:
  1345. case LSC_SCODE_NOIOCB:
  1346. case LSC_SCODE_NOXCB:
  1347. case LSC_SCODE_CMD_FAILED:
  1348. case LSC_SCODE_NOFABRIC:
  1349. case LSC_SCODE_FW_NOT_READY:
  1350. case LSC_SCODE_NOT_LOGGED_IN:
  1351. case LSC_SCODE_NOPCB:
  1352. case LSC_SCODE_ELS_REJECT:
  1353. case LSC_SCODE_CMD_PARAM_ERR:
  1354. case LSC_SCODE_NONPORT:
  1355. case LSC_SCODE_LOGGED_IN:
  1356. case LSC_SCODE_NOFLOGI_ACC:
  1357. default:
  1358. mb[0] = MBS_COMMAND_ERROR;
  1359. break;
  1360. }
  1361. } else {
  1362. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1363. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1364. mb[0] = MBS_COMMAND_COMPLETE;
  1365. mb[1] = 0;
  1366. if (iop[0] & BIT_4) {
  1367. if (iop[0] & BIT_8)
  1368. mb[1] |= BIT_1;
  1369. } else
  1370. mb[1] = BIT_0;
  1371. /* Passback COS information. */
  1372. mb[10] = 0;
  1373. if (lg->io_parameter[7] || lg->io_parameter[8])
  1374. mb[10] |= BIT_0; /* Class 2. */
  1375. if (lg->io_parameter[9] || lg->io_parameter[10])
  1376. mb[10] |= BIT_1; /* Class 3. */
  1377. }
  1378. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1379. return rval;
  1380. }
  1381. /*
  1382. * qla2x00_login_fabric
  1383. * Issue login fabric port mailbox command.
  1384. *
  1385. * Input:
  1386. * ha = adapter block pointer.
  1387. * loop_id = device loop ID.
  1388. * domain = device domain.
  1389. * area = device area.
  1390. * al_pa = device AL_PA.
  1391. * status = pointer for return status.
  1392. * opt = command options.
  1393. * TARGET_QUEUE_LOCK must be released.
  1394. * ADAPTER_STATE_LOCK must be released.
  1395. *
  1396. * Returns:
  1397. * qla2x00 local function return status code.
  1398. *
  1399. * Context:
  1400. * Kernel context.
  1401. */
  1402. int
  1403. qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
  1404. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1405. {
  1406. int rval;
  1407. mbx_cmd_t mc;
  1408. mbx_cmd_t *mcp = &mc;
  1409. struct qla_hw_data *ha = vha->hw;
  1410. DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
  1411. mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
  1412. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1413. if (HAS_EXTENDED_IDS(ha)) {
  1414. mcp->mb[1] = loop_id;
  1415. mcp->mb[10] = opt;
  1416. mcp->out_mb |= MBX_10;
  1417. } else {
  1418. mcp->mb[1] = (loop_id << 8) | opt;
  1419. }
  1420. mcp->mb[2] = domain;
  1421. mcp->mb[3] = area << 8 | al_pa;
  1422. mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
  1423. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1424. mcp->flags = 0;
  1425. rval = qla2x00_mailbox_command(vha, mcp);
  1426. /* Return mailbox statuses. */
  1427. if (mb != NULL) {
  1428. mb[0] = mcp->mb[0];
  1429. mb[1] = mcp->mb[1];
  1430. mb[2] = mcp->mb[2];
  1431. mb[6] = mcp->mb[6];
  1432. mb[7] = mcp->mb[7];
  1433. /* COS retrieved from Get-Port-Database mailbox command. */
  1434. mb[10] = 0;
  1435. }
  1436. if (rval != QLA_SUCCESS) {
  1437. /* RLU tmp code: need to change main mailbox_command function to
  1438. * return ok even when the mailbox completion value is not
  1439. * SUCCESS. The caller needs to be responsible to interpret
  1440. * the return values of this mailbox command if we're not
  1441. * to change too much of the existing code.
  1442. */
  1443. if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
  1444. mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
  1445. mcp->mb[0] == 0x4006)
  1446. rval = QLA_SUCCESS;
  1447. /*EMPTY*/
  1448. DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
  1449. "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
  1450. mcp->mb[0], mcp->mb[1], mcp->mb[2]));
  1451. } else {
  1452. /*EMPTY*/
  1453. DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
  1454. vha->host_no));
  1455. }
  1456. return rval;
  1457. }
  1458. /*
  1459. * qla2x00_login_local_device
  1460. * Issue login loop port mailbox command.
  1461. *
  1462. * Input:
  1463. * ha = adapter block pointer.
  1464. * loop_id = device loop ID.
  1465. * opt = command options.
  1466. *
  1467. * Returns:
  1468. * Return status code.
  1469. *
  1470. * Context:
  1471. * Kernel context.
  1472. *
  1473. */
  1474. int
  1475. qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
  1476. uint16_t *mb_ret, uint8_t opt)
  1477. {
  1478. int rval;
  1479. mbx_cmd_t mc;
  1480. mbx_cmd_t *mcp = &mc;
  1481. struct qla_hw_data *ha = vha->hw;
  1482. if (IS_FWI2_CAPABLE(ha))
  1483. return qla24xx_login_fabric(vha, fcport->loop_id,
  1484. fcport->d_id.b.domain, fcport->d_id.b.area,
  1485. fcport->d_id.b.al_pa, mb_ret, opt);
  1486. DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1487. mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
  1488. if (HAS_EXTENDED_IDS(ha))
  1489. mcp->mb[1] = fcport->loop_id;
  1490. else
  1491. mcp->mb[1] = fcport->loop_id << 8;
  1492. mcp->mb[2] = opt;
  1493. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  1494. mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
  1495. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1496. mcp->flags = 0;
  1497. rval = qla2x00_mailbox_command(vha, mcp);
  1498. /* Return mailbox statuses. */
  1499. if (mb_ret != NULL) {
  1500. mb_ret[0] = mcp->mb[0];
  1501. mb_ret[1] = mcp->mb[1];
  1502. mb_ret[6] = mcp->mb[6];
  1503. mb_ret[7] = mcp->mb[7];
  1504. }
  1505. if (rval != QLA_SUCCESS) {
  1506. /* AV tmp code: need to change main mailbox_command function to
  1507. * return ok even when the mailbox completion value is not
  1508. * SUCCESS. The caller needs to be responsible to interpret
  1509. * the return values of this mailbox command if we're not
  1510. * to change too much of the existing code.
  1511. */
  1512. if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
  1513. rval = QLA_SUCCESS;
  1514. DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1515. "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
  1516. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
  1517. DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1518. "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
  1519. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
  1520. } else {
  1521. /*EMPTY*/
  1522. DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1523. }
  1524. return (rval);
  1525. }
  1526. int
  1527. qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
  1528. uint8_t area, uint8_t al_pa)
  1529. {
  1530. int rval;
  1531. struct logio_entry_24xx *lg;
  1532. dma_addr_t lg_dma;
  1533. struct qla_hw_data *ha = vha->hw;
  1534. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1535. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1536. if (lg == NULL) {
  1537. DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
  1538. __func__, vha->host_no));
  1539. return QLA_MEMORY_ALLOC_FAILED;
  1540. }
  1541. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1542. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1543. lg->entry_count = 1;
  1544. lg->nport_handle = cpu_to_le16(loop_id);
  1545. lg->control_flags =
  1546. __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
  1547. lg->port_id[0] = al_pa;
  1548. lg->port_id[1] = area;
  1549. lg->port_id[2] = domain;
  1550. lg->vp_index = vha->vp_idx;
  1551. rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
  1552. if (rval != QLA_SUCCESS) {
  1553. DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
  1554. "(%x).\n", __func__, vha->host_no, rval));
  1555. } else if (lg->entry_status != 0) {
  1556. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1557. "-- error status (%x).\n", __func__, vha->host_no,
  1558. lg->entry_status));
  1559. rval = QLA_FUNCTION_FAILED;
  1560. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1561. DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
  1562. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1563. vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
  1564. le32_to_cpu(lg->io_parameter[0]),
  1565. le32_to_cpu(lg->io_parameter[1])));
  1566. } else {
  1567. /*EMPTY*/
  1568. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1569. }
  1570. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1571. return rval;
  1572. }
  1573. /*
  1574. * qla2x00_fabric_logout
  1575. * Issue logout fabric port mailbox command.
  1576. *
  1577. * Input:
  1578. * ha = adapter block pointer.
  1579. * loop_id = device loop ID.
  1580. * TARGET_QUEUE_LOCK must be released.
  1581. * ADAPTER_STATE_LOCK must be released.
  1582. *
  1583. * Returns:
  1584. * qla2x00 local function return status code.
  1585. *
  1586. * Context:
  1587. * Kernel context.
  1588. */
  1589. int
  1590. qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
  1591. uint8_t area, uint8_t al_pa)
  1592. {
  1593. int rval;
  1594. mbx_cmd_t mc;
  1595. mbx_cmd_t *mcp = &mc;
  1596. DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
  1597. vha->host_no));
  1598. mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
  1599. mcp->out_mb = MBX_1|MBX_0;
  1600. if (HAS_EXTENDED_IDS(vha->hw)) {
  1601. mcp->mb[1] = loop_id;
  1602. mcp->mb[10] = 0;
  1603. mcp->out_mb |= MBX_10;
  1604. } else {
  1605. mcp->mb[1] = loop_id << 8;
  1606. }
  1607. mcp->in_mb = MBX_1|MBX_0;
  1608. mcp->tov = MBX_TOV_SECONDS;
  1609. mcp->flags = 0;
  1610. rval = qla2x00_mailbox_command(vha, mcp);
  1611. if (rval != QLA_SUCCESS) {
  1612. /*EMPTY*/
  1613. DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
  1614. "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
  1615. } else {
  1616. /*EMPTY*/
  1617. DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
  1618. vha->host_no));
  1619. }
  1620. return rval;
  1621. }
  1622. /*
  1623. * qla2x00_full_login_lip
  1624. * Issue full login LIP mailbox command.
  1625. *
  1626. * Input:
  1627. * ha = adapter block pointer.
  1628. * TARGET_QUEUE_LOCK must be released.
  1629. * ADAPTER_STATE_LOCK must be released.
  1630. *
  1631. * Returns:
  1632. * qla2x00 local function return status code.
  1633. *
  1634. * Context:
  1635. * Kernel context.
  1636. */
  1637. int
  1638. qla2x00_full_login_lip(scsi_qla_host_t *vha)
  1639. {
  1640. int rval;
  1641. mbx_cmd_t mc;
  1642. mbx_cmd_t *mcp = &mc;
  1643. if (IS_QLA81XX(vha->hw))
  1644. return QLA_SUCCESS;
  1645. DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
  1646. vha->host_no));
  1647. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1648. mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
  1649. mcp->mb[2] = 0;
  1650. mcp->mb[3] = 0;
  1651. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1652. mcp->in_mb = MBX_0;
  1653. mcp->tov = MBX_TOV_SECONDS;
  1654. mcp->flags = 0;
  1655. rval = qla2x00_mailbox_command(vha, mcp);
  1656. if (rval != QLA_SUCCESS) {
  1657. /*EMPTY*/
  1658. DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
  1659. vha->host_no, rval));
  1660. } else {
  1661. /*EMPTY*/
  1662. DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
  1663. vha->host_no));
  1664. }
  1665. return rval;
  1666. }
  1667. /*
  1668. * qla2x00_get_id_list
  1669. *
  1670. * Input:
  1671. * ha = adapter block pointer.
  1672. *
  1673. * Returns:
  1674. * qla2x00 local function return status code.
  1675. *
  1676. * Context:
  1677. * Kernel context.
  1678. */
  1679. int
  1680. qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
  1681. uint16_t *entries)
  1682. {
  1683. int rval;
  1684. mbx_cmd_t mc;
  1685. mbx_cmd_t *mcp = &mc;
  1686. DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
  1687. vha->host_no));
  1688. if (id_list == NULL)
  1689. return QLA_FUNCTION_FAILED;
  1690. mcp->mb[0] = MBC_GET_ID_LIST;
  1691. mcp->out_mb = MBX_0;
  1692. if (IS_FWI2_CAPABLE(vha->hw)) {
  1693. mcp->mb[2] = MSW(id_list_dma);
  1694. mcp->mb[3] = LSW(id_list_dma);
  1695. mcp->mb[6] = MSW(MSD(id_list_dma));
  1696. mcp->mb[7] = LSW(MSD(id_list_dma));
  1697. mcp->mb[8] = 0;
  1698. mcp->mb[9] = vha->vp_idx;
  1699. mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
  1700. } else {
  1701. mcp->mb[1] = MSW(id_list_dma);
  1702. mcp->mb[2] = LSW(id_list_dma);
  1703. mcp->mb[3] = MSW(MSD(id_list_dma));
  1704. mcp->mb[6] = LSW(MSD(id_list_dma));
  1705. mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
  1706. }
  1707. mcp->in_mb = MBX_1|MBX_0;
  1708. mcp->tov = MBX_TOV_SECONDS;
  1709. mcp->flags = 0;
  1710. rval = qla2x00_mailbox_command(vha, mcp);
  1711. if (rval != QLA_SUCCESS) {
  1712. /*EMPTY*/
  1713. DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
  1714. vha->host_no, rval));
  1715. } else {
  1716. *entries = mcp->mb[1];
  1717. DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
  1718. vha->host_no));
  1719. }
  1720. return rval;
  1721. }
  1722. /*
  1723. * qla2x00_get_resource_cnts
  1724. * Get current firmware resource counts.
  1725. *
  1726. * Input:
  1727. * ha = adapter block pointer.
  1728. *
  1729. * Returns:
  1730. * qla2x00 local function return status code.
  1731. *
  1732. * Context:
  1733. * Kernel context.
  1734. */
  1735. int
  1736. qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
  1737. uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
  1738. uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
  1739. {
  1740. int rval;
  1741. mbx_cmd_t mc;
  1742. mbx_cmd_t *mcp = &mc;
  1743. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1744. mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
  1745. mcp->out_mb = MBX_0;
  1746. mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1747. mcp->tov = MBX_TOV_SECONDS;
  1748. mcp->flags = 0;
  1749. rval = qla2x00_mailbox_command(vha, mcp);
  1750. if (rval != QLA_SUCCESS) {
  1751. /*EMPTY*/
  1752. DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
  1753. vha->host_no, mcp->mb[0]));
  1754. } else {
  1755. DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
  1756. "mb7=%x mb10=%x mb11=%x.\n", __func__, vha->host_no,
  1757. mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
  1758. mcp->mb[10], mcp->mb[11]));
  1759. if (cur_xchg_cnt)
  1760. *cur_xchg_cnt = mcp->mb[3];
  1761. if (orig_xchg_cnt)
  1762. *orig_xchg_cnt = mcp->mb[6];
  1763. if (cur_iocb_cnt)
  1764. *cur_iocb_cnt = mcp->mb[7];
  1765. if (orig_iocb_cnt)
  1766. *orig_iocb_cnt = mcp->mb[10];
  1767. if (vha->hw->flags.npiv_supported && max_npiv_vports)
  1768. *max_npiv_vports = mcp->mb[11];
  1769. }
  1770. return (rval);
  1771. }
  1772. #if defined(QL_DEBUG_LEVEL_3)
  1773. /*
  1774. * qla2x00_get_fcal_position_map
  1775. * Get FCAL (LILP) position map using mailbox command
  1776. *
  1777. * Input:
  1778. * ha = adapter state pointer.
  1779. * pos_map = buffer pointer (can be NULL).
  1780. *
  1781. * Returns:
  1782. * qla2x00 local function return status code.
  1783. *
  1784. * Context:
  1785. * Kernel context.
  1786. */
  1787. int
  1788. qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
  1789. {
  1790. int rval;
  1791. mbx_cmd_t mc;
  1792. mbx_cmd_t *mcp = &mc;
  1793. char *pmap;
  1794. dma_addr_t pmap_dma;
  1795. struct qla_hw_data *ha = vha->hw;
  1796. pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
  1797. if (pmap == NULL) {
  1798. DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
  1799. __func__, vha->host_no));
  1800. return QLA_MEMORY_ALLOC_FAILED;
  1801. }
  1802. memset(pmap, 0, FCAL_MAP_SIZE);
  1803. mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
  1804. mcp->mb[2] = MSW(pmap_dma);
  1805. mcp->mb[3] = LSW(pmap_dma);
  1806. mcp->mb[6] = MSW(MSD(pmap_dma));
  1807. mcp->mb[7] = LSW(MSD(pmap_dma));
  1808. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1809. mcp->in_mb = MBX_1|MBX_0;
  1810. mcp->buf_size = FCAL_MAP_SIZE;
  1811. mcp->flags = MBX_DMA_IN;
  1812. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1813. rval = qla2x00_mailbox_command(vha, mcp);
  1814. if (rval == QLA_SUCCESS) {
  1815. DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
  1816. "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
  1817. mcp->mb[1], (unsigned)pmap[0]));
  1818. DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
  1819. if (pos_map)
  1820. memcpy(pos_map, pmap, FCAL_MAP_SIZE);
  1821. }
  1822. dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
  1823. if (rval != QLA_SUCCESS) {
  1824. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1825. vha->host_no, rval));
  1826. } else {
  1827. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1828. }
  1829. return rval;
  1830. }
  1831. #endif
  1832. /*
  1833. * qla2x00_get_link_status
  1834. *
  1835. * Input:
  1836. * ha = adapter block pointer.
  1837. * loop_id = device loop ID.
  1838. * ret_buf = pointer to link status return buffer.
  1839. *
  1840. * Returns:
  1841. * 0 = success.
  1842. * BIT_0 = mem alloc error.
  1843. * BIT_1 = mailbox error.
  1844. */
  1845. int
  1846. qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
  1847. struct link_statistics *stats, dma_addr_t stats_dma)
  1848. {
  1849. int rval;
  1850. mbx_cmd_t mc;
  1851. mbx_cmd_t *mcp = &mc;
  1852. uint32_t *siter, *diter, dwords;
  1853. struct qla_hw_data *ha = vha->hw;
  1854. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1855. mcp->mb[0] = MBC_GET_LINK_STATUS;
  1856. mcp->mb[2] = MSW(stats_dma);
  1857. mcp->mb[3] = LSW(stats_dma);
  1858. mcp->mb[6] = MSW(MSD(stats_dma));
  1859. mcp->mb[7] = LSW(MSD(stats_dma));
  1860. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1861. mcp->in_mb = MBX_0;
  1862. if (IS_FWI2_CAPABLE(ha)) {
  1863. mcp->mb[1] = loop_id;
  1864. mcp->mb[4] = 0;
  1865. mcp->mb[10] = 0;
  1866. mcp->out_mb |= MBX_10|MBX_4|MBX_1;
  1867. mcp->in_mb |= MBX_1;
  1868. } else if (HAS_EXTENDED_IDS(ha)) {
  1869. mcp->mb[1] = loop_id;
  1870. mcp->mb[10] = 0;
  1871. mcp->out_mb |= MBX_10|MBX_1;
  1872. } else {
  1873. mcp->mb[1] = loop_id << 8;
  1874. mcp->out_mb |= MBX_1;
  1875. }
  1876. mcp->tov = MBX_TOV_SECONDS;
  1877. mcp->flags = IOCTL_CMD;
  1878. rval = qla2x00_mailbox_command(vha, mcp);
  1879. if (rval == QLA_SUCCESS) {
  1880. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  1881. DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
  1882. __func__, vha->host_no, mcp->mb[0]));
  1883. rval = QLA_FUNCTION_FAILED;
  1884. } else {
  1885. /* Copy over data -- firmware data is LE. */
  1886. dwords = offsetof(struct link_statistics, unused1) / 4;
  1887. siter = diter = &stats->link_fail_cnt;
  1888. while (dwords--)
  1889. *diter++ = le32_to_cpu(*siter++);
  1890. }
  1891. } else {
  1892. /* Failed. */
  1893. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1894. vha->host_no, rval));
  1895. }
  1896. return rval;
  1897. }
  1898. int
  1899. qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
  1900. dma_addr_t stats_dma)
  1901. {
  1902. int rval;
  1903. mbx_cmd_t mc;
  1904. mbx_cmd_t *mcp = &mc;
  1905. uint32_t *siter, *diter, dwords;
  1906. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1907. mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
  1908. mcp->mb[2] = MSW(stats_dma);
  1909. mcp->mb[3] = LSW(stats_dma);
  1910. mcp->mb[6] = MSW(MSD(stats_dma));
  1911. mcp->mb[7] = LSW(MSD(stats_dma));
  1912. mcp->mb[8] = sizeof(struct link_statistics) / 4;
  1913. mcp->mb[9] = vha->vp_idx;
  1914. mcp->mb[10] = 0;
  1915. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1916. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  1917. mcp->tov = MBX_TOV_SECONDS;
  1918. mcp->flags = IOCTL_CMD;
  1919. rval = qla2x00_mailbox_command(vha, mcp);
  1920. if (rval == QLA_SUCCESS) {
  1921. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  1922. DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
  1923. __func__, vha->host_no, mcp->mb[0]));
  1924. rval = QLA_FUNCTION_FAILED;
  1925. } else {
  1926. /* Copy over data -- firmware data is LE. */
  1927. dwords = sizeof(struct link_statistics) / 4;
  1928. siter = diter = &stats->link_fail_cnt;
  1929. while (dwords--)
  1930. *diter++ = le32_to_cpu(*siter++);
  1931. }
  1932. } else {
  1933. /* Failed. */
  1934. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1935. vha->host_no, rval));
  1936. }
  1937. return rval;
  1938. }
  1939. int
  1940. qla24xx_abort_command(scsi_qla_host_t *vha, srb_t *sp, struct req_que *req)
  1941. {
  1942. int rval;
  1943. fc_port_t *fcport;
  1944. unsigned long flags = 0;
  1945. struct abort_entry_24xx *abt;
  1946. dma_addr_t abt_dma;
  1947. uint32_t handle;
  1948. struct qla_hw_data *ha = vha->hw;
  1949. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  1950. fcport = sp->fcport;
  1951. spin_lock_irqsave(&ha->hardware_lock, flags);
  1952. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  1953. if (req->outstanding_cmds[handle] == sp)
  1954. break;
  1955. }
  1956. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1957. if (handle == MAX_OUTSTANDING_COMMANDS) {
  1958. /* Command not found. */
  1959. return QLA_FUNCTION_FAILED;
  1960. }
  1961. abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
  1962. if (abt == NULL) {
  1963. DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
  1964. __func__, vha->host_no));
  1965. return QLA_MEMORY_ALLOC_FAILED;
  1966. }
  1967. memset(abt, 0, sizeof(struct abort_entry_24xx));
  1968. abt->entry_type = ABORT_IOCB_TYPE;
  1969. abt->entry_count = 1;
  1970. abt->nport_handle = cpu_to_le16(fcport->loop_id);
  1971. abt->handle_to_abort = handle;
  1972. abt->port_id[0] = fcport->d_id.b.al_pa;
  1973. abt->port_id[1] = fcport->d_id.b.area;
  1974. abt->port_id[2] = fcport->d_id.b.domain;
  1975. abt->vp_index = fcport->vp_idx;
  1976. abt->req_que_no = cpu_to_le16(req->id);
  1977. rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
  1978. if (rval != QLA_SUCCESS) {
  1979. DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
  1980. __func__, vha->host_no, rval));
  1981. } else if (abt->entry_status != 0) {
  1982. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1983. "-- error status (%x).\n", __func__, vha->host_no,
  1984. abt->entry_status));
  1985. rval = QLA_FUNCTION_FAILED;
  1986. } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
  1987. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1988. "-- completion status (%x).\n", __func__, vha->host_no,
  1989. le16_to_cpu(abt->nport_handle)));
  1990. rval = QLA_FUNCTION_FAILED;
  1991. } else {
  1992. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  1993. }
  1994. dma_pool_free(ha->s_dma_pool, abt, abt_dma);
  1995. return rval;
  1996. }
  1997. struct tsk_mgmt_cmd {
  1998. union {
  1999. struct tsk_mgmt_entry tsk;
  2000. struct sts_entry_24xx sts;
  2001. } p;
  2002. };
  2003. static int
  2004. __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
  2005. unsigned int l)
  2006. {
  2007. int rval, rval2;
  2008. struct tsk_mgmt_cmd *tsk;
  2009. dma_addr_t tsk_dma;
  2010. scsi_qla_host_t *vha;
  2011. struct qla_hw_data *ha;
  2012. struct req_que *req;
  2013. struct rsp_que *rsp;
  2014. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
  2015. vha = fcport->vha;
  2016. ha = vha->hw;
  2017. req = ha->req_q_map[0];
  2018. rsp = ha->rsp_q_map[0];
  2019. tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
  2020. if (tsk == NULL) {
  2021. DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
  2022. "IOCB.\n", __func__, vha->host_no));
  2023. return QLA_MEMORY_ALLOC_FAILED;
  2024. }
  2025. memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
  2026. tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
  2027. tsk->p.tsk.entry_count = 1;
  2028. tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
  2029. tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  2030. tsk->p.tsk.control_flags = cpu_to_le32(type);
  2031. tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
  2032. tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
  2033. tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
  2034. tsk->p.tsk.vp_index = fcport->vp_idx;
  2035. if (type == TCF_LUN_RESET) {
  2036. int_to_scsilun(l, &tsk->p.tsk.lun);
  2037. host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
  2038. sizeof(tsk->p.tsk.lun));
  2039. }
  2040. rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
  2041. if (rval != QLA_SUCCESS) {
  2042. DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
  2043. "(%x).\n", __func__, vha->host_no, name, rval));
  2044. } else if (tsk->p.sts.entry_status != 0) {
  2045. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2046. "-- error status (%x).\n", __func__, vha->host_no,
  2047. tsk->p.sts.entry_status));
  2048. rval = QLA_FUNCTION_FAILED;
  2049. } else if (tsk->p.sts.comp_status !=
  2050. __constant_cpu_to_le16(CS_COMPLETE)) {
  2051. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2052. "-- completion status (%x).\n", __func__,
  2053. vha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
  2054. rval = QLA_FUNCTION_FAILED;
  2055. }
  2056. /* Issue marker IOCB. */
  2057. rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
  2058. type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
  2059. if (rval2 != QLA_SUCCESS) {
  2060. DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
  2061. "(%x).\n", __func__, vha->host_no, rval2));
  2062. } else {
  2063. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2064. }
  2065. dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
  2066. return rval;
  2067. }
  2068. int
  2069. qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
  2070. {
  2071. return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
  2072. }
  2073. int
  2074. qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
  2075. {
  2076. return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
  2077. }
  2078. int
  2079. qla2x00_system_error(scsi_qla_host_t *vha)
  2080. {
  2081. int rval;
  2082. mbx_cmd_t mc;
  2083. mbx_cmd_t *mcp = &mc;
  2084. struct qla_hw_data *ha = vha->hw;
  2085. if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
  2086. return QLA_FUNCTION_FAILED;
  2087. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2088. mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
  2089. mcp->out_mb = MBX_0;
  2090. mcp->in_mb = MBX_0;
  2091. mcp->tov = 5;
  2092. mcp->flags = 0;
  2093. rval = qla2x00_mailbox_command(vha, mcp);
  2094. if (rval != QLA_SUCCESS) {
  2095. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2096. vha->host_no, rval));
  2097. } else {
  2098. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2099. }
  2100. return rval;
  2101. }
  2102. /**
  2103. * qla2x00_set_serdes_params() -
  2104. * @ha: HA context
  2105. *
  2106. * Returns
  2107. */
  2108. int
  2109. qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
  2110. uint16_t sw_em_2g, uint16_t sw_em_4g)
  2111. {
  2112. int rval;
  2113. mbx_cmd_t mc;
  2114. mbx_cmd_t *mcp = &mc;
  2115. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2116. mcp->mb[0] = MBC_SERDES_PARAMS;
  2117. mcp->mb[1] = BIT_0;
  2118. mcp->mb[2] = sw_em_1g | BIT_15;
  2119. mcp->mb[3] = sw_em_2g | BIT_15;
  2120. mcp->mb[4] = sw_em_4g | BIT_15;
  2121. mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2122. mcp->in_mb = MBX_0;
  2123. mcp->tov = MBX_TOV_SECONDS;
  2124. mcp->flags = 0;
  2125. rval = qla2x00_mailbox_command(vha, mcp);
  2126. if (rval != QLA_SUCCESS) {
  2127. /*EMPTY*/
  2128. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2129. vha->host_no, rval, mcp->mb[0]));
  2130. } else {
  2131. /*EMPTY*/
  2132. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2133. }
  2134. return rval;
  2135. }
  2136. int
  2137. qla2x00_stop_firmware(scsi_qla_host_t *vha)
  2138. {
  2139. int rval;
  2140. mbx_cmd_t mc;
  2141. mbx_cmd_t *mcp = &mc;
  2142. if (!IS_FWI2_CAPABLE(vha->hw))
  2143. return QLA_FUNCTION_FAILED;
  2144. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2145. mcp->mb[0] = MBC_STOP_FIRMWARE;
  2146. mcp->out_mb = MBX_0;
  2147. mcp->in_mb = MBX_0;
  2148. mcp->tov = 5;
  2149. mcp->flags = 0;
  2150. rval = qla2x00_mailbox_command(vha, mcp);
  2151. if (rval != QLA_SUCCESS) {
  2152. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2153. vha->host_no, rval));
  2154. } else {
  2155. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2156. }
  2157. return rval;
  2158. }
  2159. int
  2160. qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
  2161. uint16_t buffers)
  2162. {
  2163. int rval;
  2164. mbx_cmd_t mc;
  2165. mbx_cmd_t *mcp = &mc;
  2166. if (!IS_FWI2_CAPABLE(vha->hw))
  2167. return QLA_FUNCTION_FAILED;
  2168. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2169. mcp->mb[0] = MBC_TRACE_CONTROL;
  2170. mcp->mb[1] = TC_EFT_ENABLE;
  2171. mcp->mb[2] = LSW(eft_dma);
  2172. mcp->mb[3] = MSW(eft_dma);
  2173. mcp->mb[4] = LSW(MSD(eft_dma));
  2174. mcp->mb[5] = MSW(MSD(eft_dma));
  2175. mcp->mb[6] = buffers;
  2176. mcp->mb[7] = TC_AEN_DISABLE;
  2177. mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2178. mcp->in_mb = MBX_1|MBX_0;
  2179. mcp->tov = MBX_TOV_SECONDS;
  2180. mcp->flags = 0;
  2181. rval = qla2x00_mailbox_command(vha, mcp);
  2182. if (rval != QLA_SUCCESS) {
  2183. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2184. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2185. } else {
  2186. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2187. }
  2188. return rval;
  2189. }
  2190. int
  2191. qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
  2192. {
  2193. int rval;
  2194. mbx_cmd_t mc;
  2195. mbx_cmd_t *mcp = &mc;
  2196. if (!IS_FWI2_CAPABLE(vha->hw))
  2197. return QLA_FUNCTION_FAILED;
  2198. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2199. mcp->mb[0] = MBC_TRACE_CONTROL;
  2200. mcp->mb[1] = TC_EFT_DISABLE;
  2201. mcp->out_mb = MBX_1|MBX_0;
  2202. mcp->in_mb = MBX_1|MBX_0;
  2203. mcp->tov = MBX_TOV_SECONDS;
  2204. mcp->flags = 0;
  2205. rval = qla2x00_mailbox_command(vha, mcp);
  2206. if (rval != QLA_SUCCESS) {
  2207. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2208. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2209. } else {
  2210. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2211. }
  2212. return rval;
  2213. }
  2214. int
  2215. qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
  2216. uint16_t buffers, uint16_t *mb, uint32_t *dwords)
  2217. {
  2218. int rval;
  2219. mbx_cmd_t mc;
  2220. mbx_cmd_t *mcp = &mc;
  2221. if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
  2222. return QLA_FUNCTION_FAILED;
  2223. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2224. mcp->mb[0] = MBC_TRACE_CONTROL;
  2225. mcp->mb[1] = TC_FCE_ENABLE;
  2226. mcp->mb[2] = LSW(fce_dma);
  2227. mcp->mb[3] = MSW(fce_dma);
  2228. mcp->mb[4] = LSW(MSD(fce_dma));
  2229. mcp->mb[5] = MSW(MSD(fce_dma));
  2230. mcp->mb[6] = buffers;
  2231. mcp->mb[7] = TC_AEN_DISABLE;
  2232. mcp->mb[8] = 0;
  2233. mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
  2234. mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
  2235. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
  2236. MBX_1|MBX_0;
  2237. mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2238. mcp->tov = MBX_TOV_SECONDS;
  2239. mcp->flags = 0;
  2240. rval = qla2x00_mailbox_command(vha, mcp);
  2241. if (rval != QLA_SUCCESS) {
  2242. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2243. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2244. } else {
  2245. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2246. if (mb)
  2247. memcpy(mb, mcp->mb, 8 * sizeof(*mb));
  2248. if (dwords)
  2249. *dwords = buffers;
  2250. }
  2251. return rval;
  2252. }
  2253. int
  2254. qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
  2255. {
  2256. int rval;
  2257. mbx_cmd_t mc;
  2258. mbx_cmd_t *mcp = &mc;
  2259. if (!IS_FWI2_CAPABLE(vha->hw))
  2260. return QLA_FUNCTION_FAILED;
  2261. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2262. mcp->mb[0] = MBC_TRACE_CONTROL;
  2263. mcp->mb[1] = TC_FCE_DISABLE;
  2264. mcp->mb[2] = TC_FCE_DISABLE_TRACE;
  2265. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  2266. mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
  2267. MBX_1|MBX_0;
  2268. mcp->tov = MBX_TOV_SECONDS;
  2269. mcp->flags = 0;
  2270. rval = qla2x00_mailbox_command(vha, mcp);
  2271. if (rval != QLA_SUCCESS) {
  2272. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2273. __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2274. } else {
  2275. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2276. if (wr)
  2277. *wr = (uint64_t) mcp->mb[5] << 48 |
  2278. (uint64_t) mcp->mb[4] << 32 |
  2279. (uint64_t) mcp->mb[3] << 16 |
  2280. (uint64_t) mcp->mb[2];
  2281. if (rd)
  2282. *rd = (uint64_t) mcp->mb[9] << 48 |
  2283. (uint64_t) mcp->mb[8] << 32 |
  2284. (uint64_t) mcp->mb[7] << 16 |
  2285. (uint64_t) mcp->mb[6];
  2286. }
  2287. return rval;
  2288. }
  2289. int
  2290. qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
  2291. uint16_t off, uint16_t count)
  2292. {
  2293. int rval;
  2294. mbx_cmd_t mc;
  2295. mbx_cmd_t *mcp = &mc;
  2296. if (!IS_FWI2_CAPABLE(vha->hw))
  2297. return QLA_FUNCTION_FAILED;
  2298. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2299. mcp->mb[0] = MBC_READ_SFP;
  2300. mcp->mb[1] = addr;
  2301. mcp->mb[2] = MSW(sfp_dma);
  2302. mcp->mb[3] = LSW(sfp_dma);
  2303. mcp->mb[6] = MSW(MSD(sfp_dma));
  2304. mcp->mb[7] = LSW(MSD(sfp_dma));
  2305. mcp->mb[8] = count;
  2306. mcp->mb[9] = off;
  2307. mcp->mb[10] = 0;
  2308. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  2309. mcp->in_mb = MBX_0;
  2310. mcp->tov = MBX_TOV_SECONDS;
  2311. mcp->flags = 0;
  2312. rval = qla2x00_mailbox_command(vha, mcp);
  2313. if (rval != QLA_SUCCESS) {
  2314. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2315. vha->host_no, rval, mcp->mb[0]));
  2316. } else {
  2317. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2318. }
  2319. return rval;
  2320. }
  2321. int
  2322. qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
  2323. uint16_t port_speed, uint16_t *mb)
  2324. {
  2325. int rval;
  2326. mbx_cmd_t mc;
  2327. mbx_cmd_t *mcp = &mc;
  2328. if (!IS_IIDMA_CAPABLE(vha->hw))
  2329. return QLA_FUNCTION_FAILED;
  2330. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2331. mcp->mb[0] = MBC_PORT_PARAMS;
  2332. mcp->mb[1] = loop_id;
  2333. mcp->mb[2] = BIT_0;
  2334. mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
  2335. mcp->mb[4] = mcp->mb[5] = 0;
  2336. mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2337. mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
  2338. mcp->tov = MBX_TOV_SECONDS;
  2339. mcp->flags = 0;
  2340. rval = qla2x00_mailbox_command(vha, mcp);
  2341. /* Return mailbox statuses. */
  2342. if (mb != NULL) {
  2343. mb[0] = mcp->mb[0];
  2344. mb[1] = mcp->mb[1];
  2345. mb[3] = mcp->mb[3];
  2346. mb[4] = mcp->mb[4];
  2347. mb[5] = mcp->mb[5];
  2348. }
  2349. if (rval != QLA_SUCCESS) {
  2350. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2351. vha->host_no, rval));
  2352. } else {
  2353. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2354. }
  2355. return rval;
  2356. }
  2357. void
  2358. qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
  2359. struct vp_rpt_id_entry_24xx *rptid_entry)
  2360. {
  2361. uint8_t vp_idx;
  2362. uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
  2363. struct qla_hw_data *ha = vha->hw;
  2364. scsi_qla_host_t *vp;
  2365. if (rptid_entry->entry_status != 0)
  2366. return;
  2367. if (rptid_entry->format == 0) {
  2368. DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
  2369. " number of VPs acquired %d\n", __func__, vha->host_no,
  2370. MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
  2371. DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
  2372. rptid_entry->port_id[2], rptid_entry->port_id[1],
  2373. rptid_entry->port_id[0]));
  2374. } else if (rptid_entry->format == 1) {
  2375. vp_idx = LSB(stat);
  2376. DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
  2377. "- status %d - "
  2378. "with port id %02x%02x%02x\n", __func__, vha->host_no,
  2379. vp_idx, MSB(stat),
  2380. rptid_entry->port_id[2], rptid_entry->port_id[1],
  2381. rptid_entry->port_id[0]));
  2382. if (vp_idx == 0)
  2383. return;
  2384. if (MSB(stat) == 1)
  2385. return;
  2386. list_for_each_entry(vp, &ha->vp_list, list)
  2387. if (vp_idx == vp->vp_idx)
  2388. break;
  2389. if (!vp)
  2390. return;
  2391. vp->d_id.b.domain = rptid_entry->port_id[2];
  2392. vp->d_id.b.area = rptid_entry->port_id[1];
  2393. vp->d_id.b.al_pa = rptid_entry->port_id[0];
  2394. /*
  2395. * Cannot configure here as we are still sitting on the
  2396. * response queue. Handle it in dpc context.
  2397. */
  2398. set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
  2399. set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
  2400. qla2xxx_wake_dpc(vha);
  2401. }
  2402. }
  2403. /*
  2404. * qla24xx_modify_vp_config
  2405. * Change VP configuration for vha
  2406. *
  2407. * Input:
  2408. * vha = adapter block pointer.
  2409. *
  2410. * Returns:
  2411. * qla2xxx local function return status code.
  2412. *
  2413. * Context:
  2414. * Kernel context.
  2415. */
  2416. int
  2417. qla24xx_modify_vp_config(scsi_qla_host_t *vha)
  2418. {
  2419. int rval;
  2420. struct vp_config_entry_24xx *vpmod;
  2421. dma_addr_t vpmod_dma;
  2422. struct qla_hw_data *ha = vha->hw;
  2423. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2424. /* This can be called by the parent */
  2425. vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
  2426. if (!vpmod) {
  2427. DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
  2428. "IOCB.\n", __func__, vha->host_no));
  2429. return QLA_MEMORY_ALLOC_FAILED;
  2430. }
  2431. memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
  2432. vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
  2433. vpmod->entry_count = 1;
  2434. vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
  2435. vpmod->vp_count = 1;
  2436. vpmod->vp_index1 = vha->vp_idx;
  2437. vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
  2438. memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
  2439. memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
  2440. vpmod->entry_count = 1;
  2441. rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
  2442. if (rval != QLA_SUCCESS) {
  2443. DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
  2444. "(%x).\n", __func__, base_vha->host_no, rval));
  2445. } else if (vpmod->comp_status != 0) {
  2446. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2447. "-- error status (%x).\n", __func__, base_vha->host_no,
  2448. vpmod->comp_status));
  2449. rval = QLA_FUNCTION_FAILED;
  2450. } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  2451. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2452. "-- completion status (%x).\n", __func__, base_vha->host_no,
  2453. le16_to_cpu(vpmod->comp_status)));
  2454. rval = QLA_FUNCTION_FAILED;
  2455. } else {
  2456. /* EMPTY */
  2457. DEBUG11(printk("%s(%ld): done.\n", __func__,
  2458. base_vha->host_no));
  2459. fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
  2460. }
  2461. dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
  2462. return rval;
  2463. }
  2464. /*
  2465. * qla24xx_control_vp
  2466. * Enable a virtual port for given host
  2467. *
  2468. * Input:
  2469. * ha = adapter block pointer.
  2470. * vhba = virtual adapter (unused)
  2471. * index = index number for enabled VP
  2472. *
  2473. * Returns:
  2474. * qla2xxx local function return status code.
  2475. *
  2476. * Context:
  2477. * Kernel context.
  2478. */
  2479. int
  2480. qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
  2481. {
  2482. int rval;
  2483. int map, pos;
  2484. struct vp_ctrl_entry_24xx *vce;
  2485. dma_addr_t vce_dma;
  2486. struct qla_hw_data *ha = vha->hw;
  2487. int vp_index = vha->vp_idx;
  2488. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2489. DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
  2490. vha->host_no, vp_index));
  2491. if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
  2492. return QLA_PARAMETER_ERROR;
  2493. vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
  2494. if (!vce) {
  2495. DEBUG2_3(printk("%s(%ld): "
  2496. "failed to allocate VP Control IOCB.\n", __func__,
  2497. base_vha->host_no));
  2498. return QLA_MEMORY_ALLOC_FAILED;
  2499. }
  2500. memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
  2501. vce->entry_type = VP_CTRL_IOCB_TYPE;
  2502. vce->entry_count = 1;
  2503. vce->command = cpu_to_le16(cmd);
  2504. vce->vp_count = __constant_cpu_to_le16(1);
  2505. /* index map in firmware starts with 1; decrement index
  2506. * this is ok as we never use index 0
  2507. */
  2508. map = (vp_index - 1) / 8;
  2509. pos = (vp_index - 1) & 7;
  2510. mutex_lock(&ha->vport_lock);
  2511. vce->vp_idx_map[map] |= 1 << pos;
  2512. mutex_unlock(&ha->vport_lock);
  2513. rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
  2514. if (rval != QLA_SUCCESS) {
  2515. DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
  2516. "(%x).\n", __func__, base_vha->host_no, rval));
  2517. printk("%s(%ld): failed to issue VP control IOCB"
  2518. "(%x).\n", __func__, base_vha->host_no, rval);
  2519. } else if (vce->entry_status != 0) {
  2520. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2521. "-- error status (%x).\n", __func__, base_vha->host_no,
  2522. vce->entry_status));
  2523. printk("%s(%ld): failed to complete IOCB "
  2524. "-- error status (%x).\n", __func__, base_vha->host_no,
  2525. vce->entry_status);
  2526. rval = QLA_FUNCTION_FAILED;
  2527. } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  2528. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2529. "-- completion status (%x).\n", __func__, base_vha->host_no,
  2530. le16_to_cpu(vce->comp_status)));
  2531. printk("%s(%ld): failed to complete IOCB "
  2532. "-- completion status (%x).\n", __func__, base_vha->host_no,
  2533. le16_to_cpu(vce->comp_status));
  2534. rval = QLA_FUNCTION_FAILED;
  2535. } else {
  2536. DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
  2537. }
  2538. dma_pool_free(ha->s_dma_pool, vce, vce_dma);
  2539. return rval;
  2540. }
  2541. /*
  2542. * qla2x00_send_change_request
  2543. * Receive or disable RSCN request from fabric controller
  2544. *
  2545. * Input:
  2546. * ha = adapter block pointer
  2547. * format = registration format:
  2548. * 0 - Reserved
  2549. * 1 - Fabric detected registration
  2550. * 2 - N_port detected registration
  2551. * 3 - Full registration
  2552. * FF - clear registration
  2553. * vp_idx = Virtual port index
  2554. *
  2555. * Returns:
  2556. * qla2x00 local function return status code.
  2557. *
  2558. * Context:
  2559. * Kernel Context
  2560. */
  2561. int
  2562. qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
  2563. uint16_t vp_idx)
  2564. {
  2565. int rval;
  2566. mbx_cmd_t mc;
  2567. mbx_cmd_t *mcp = &mc;
  2568. /*
  2569. * This command is implicitly executed by firmware during login for the
  2570. * physical hosts
  2571. */
  2572. if (vp_idx == 0)
  2573. return QLA_FUNCTION_FAILED;
  2574. mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
  2575. mcp->mb[1] = format;
  2576. mcp->mb[9] = vp_idx;
  2577. mcp->out_mb = MBX_9|MBX_1|MBX_0;
  2578. mcp->in_mb = MBX_0|MBX_1;
  2579. mcp->tov = MBX_TOV_SECONDS;
  2580. mcp->flags = 0;
  2581. rval = qla2x00_mailbox_command(vha, mcp);
  2582. if (rval == QLA_SUCCESS) {
  2583. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  2584. rval = BIT_1;
  2585. }
  2586. } else
  2587. rval = BIT_1;
  2588. return rval;
  2589. }
  2590. int
  2591. qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
  2592. uint32_t size)
  2593. {
  2594. int rval;
  2595. mbx_cmd_t mc;
  2596. mbx_cmd_t *mcp = &mc;
  2597. DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2598. if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
  2599. mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
  2600. mcp->mb[8] = MSW(addr);
  2601. mcp->out_mb = MBX_8|MBX_0;
  2602. } else {
  2603. mcp->mb[0] = MBC_DUMP_RISC_RAM;
  2604. mcp->out_mb = MBX_0;
  2605. }
  2606. mcp->mb[1] = LSW(addr);
  2607. mcp->mb[2] = MSW(req_dma);
  2608. mcp->mb[3] = LSW(req_dma);
  2609. mcp->mb[6] = MSW(MSD(req_dma));
  2610. mcp->mb[7] = LSW(MSD(req_dma));
  2611. mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
  2612. if (IS_FWI2_CAPABLE(vha->hw)) {
  2613. mcp->mb[4] = MSW(size);
  2614. mcp->mb[5] = LSW(size);
  2615. mcp->out_mb |= MBX_5|MBX_4;
  2616. } else {
  2617. mcp->mb[4] = LSW(size);
  2618. mcp->out_mb |= MBX_4;
  2619. }
  2620. mcp->in_mb = MBX_0;
  2621. mcp->tov = MBX_TOV_SECONDS;
  2622. mcp->flags = 0;
  2623. rval = qla2x00_mailbox_command(vha, mcp);
  2624. if (rval != QLA_SUCCESS) {
  2625. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  2626. vha->host_no, rval, mcp->mb[0]));
  2627. } else {
  2628. DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2629. }
  2630. return rval;
  2631. }
  2632. /* 84XX Support **************************************************************/
  2633. struct cs84xx_mgmt_cmd {
  2634. union {
  2635. struct verify_chip_entry_84xx req;
  2636. struct verify_chip_rsp_84xx rsp;
  2637. } p;
  2638. };
  2639. int
  2640. qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
  2641. {
  2642. int rval, retry;
  2643. struct cs84xx_mgmt_cmd *mn;
  2644. dma_addr_t mn_dma;
  2645. uint16_t options;
  2646. unsigned long flags;
  2647. struct qla_hw_data *ha = vha->hw;
  2648. DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
  2649. mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
  2650. if (mn == NULL) {
  2651. DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
  2652. "IOCB.\n", __func__, vha->host_no));
  2653. return QLA_MEMORY_ALLOC_FAILED;
  2654. }
  2655. /* Force Update? */
  2656. options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
  2657. /* Diagnostic firmware? */
  2658. /* options |= MENLO_DIAG_FW; */
  2659. /* We update the firmware with only one data sequence. */
  2660. options |= VCO_END_OF_DATA;
  2661. do {
  2662. retry = 0;
  2663. memset(mn, 0, sizeof(*mn));
  2664. mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
  2665. mn->p.req.entry_count = 1;
  2666. mn->p.req.options = cpu_to_le16(options);
  2667. DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
  2668. vha->host_no));
  2669. DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
  2670. sizeof(*mn)));
  2671. rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
  2672. if (rval != QLA_SUCCESS) {
  2673. DEBUG2_16(printk("%s(%ld): failed to issue Verify "
  2674. "IOCB (%x).\n", __func__, vha->host_no, rval));
  2675. goto verify_done;
  2676. }
  2677. DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
  2678. vha->host_no));
  2679. DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
  2680. sizeof(*mn)));
  2681. status[0] = le16_to_cpu(mn->p.rsp.comp_status);
  2682. status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
  2683. le16_to_cpu(mn->p.rsp.failure_code) : 0;
  2684. DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
  2685. vha->host_no, status[0], status[1]));
  2686. if (status[0] != CS_COMPLETE) {
  2687. rval = QLA_FUNCTION_FAILED;
  2688. if (!(options & VCO_DONT_UPDATE_FW)) {
  2689. DEBUG2_16(printk("%s(%ld): Firmware update "
  2690. "failed. Retrying without update "
  2691. "firmware.\n", __func__, vha->host_no));
  2692. options |= VCO_DONT_UPDATE_FW;
  2693. options &= ~VCO_FORCE_UPDATE;
  2694. retry = 1;
  2695. }
  2696. } else {
  2697. DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
  2698. __func__, vha->host_no,
  2699. le32_to_cpu(mn->p.rsp.fw_ver)));
  2700. /* NOTE: we only update OP firmware. */
  2701. spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
  2702. ha->cs84xx->op_fw_version =
  2703. le32_to_cpu(mn->p.rsp.fw_ver);
  2704. spin_unlock_irqrestore(&ha->cs84xx->access_lock,
  2705. flags);
  2706. }
  2707. } while (retry);
  2708. verify_done:
  2709. dma_pool_free(ha->s_dma_pool, mn, mn_dma);
  2710. if (rval != QLA_SUCCESS) {
  2711. DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
  2712. vha->host_no, rval));
  2713. } else {
  2714. DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
  2715. }
  2716. return rval;
  2717. }
  2718. int
  2719. qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
  2720. {
  2721. int rval;
  2722. unsigned long flags;
  2723. mbx_cmd_t mc;
  2724. mbx_cmd_t *mcp = &mc;
  2725. struct device_reg_25xxmq __iomem *reg;
  2726. struct qla_hw_data *ha = vha->hw;
  2727. mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
  2728. mcp->mb[1] = req->options;
  2729. mcp->mb[2] = MSW(LSD(req->dma));
  2730. mcp->mb[3] = LSW(LSD(req->dma));
  2731. mcp->mb[6] = MSW(MSD(req->dma));
  2732. mcp->mb[7] = LSW(MSD(req->dma));
  2733. mcp->mb[5] = req->length;
  2734. if (req->rsp)
  2735. mcp->mb[10] = req->rsp->id;
  2736. mcp->mb[12] = req->qos;
  2737. mcp->mb[11] = req->vp_idx;
  2738. mcp->mb[13] = req->rid;
  2739. reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
  2740. QLA_QUE_PAGE * req->id);
  2741. mcp->mb[4] = req->id;
  2742. /* que in ptr index */
  2743. mcp->mb[8] = 0;
  2744. /* que out ptr index */
  2745. mcp->mb[9] = 0;
  2746. mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
  2747. MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2748. mcp->in_mb = MBX_0;
  2749. mcp->flags = MBX_DMA_OUT;
  2750. mcp->tov = 60;
  2751. spin_lock_irqsave(&ha->hardware_lock, flags);
  2752. if (!(req->options & BIT_0)) {
  2753. WRT_REG_DWORD(&reg->req_q_in, 0);
  2754. WRT_REG_DWORD(&reg->req_q_out, 0);
  2755. }
  2756. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2757. rval = qla2x00_mailbox_command(vha, mcp);
  2758. if (rval != QLA_SUCCESS)
  2759. DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
  2760. __func__, vha->host_no, rval, mcp->mb[0]));
  2761. return rval;
  2762. }
  2763. int
  2764. qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
  2765. {
  2766. int rval;
  2767. unsigned long flags;
  2768. mbx_cmd_t mc;
  2769. mbx_cmd_t *mcp = &mc;
  2770. struct device_reg_25xxmq __iomem *reg;
  2771. struct qla_hw_data *ha = vha->hw;
  2772. mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
  2773. mcp->mb[1] = rsp->options;
  2774. mcp->mb[2] = MSW(LSD(rsp->dma));
  2775. mcp->mb[3] = LSW(LSD(rsp->dma));
  2776. mcp->mb[6] = MSW(MSD(rsp->dma));
  2777. mcp->mb[7] = LSW(MSD(rsp->dma));
  2778. mcp->mb[5] = rsp->length;
  2779. mcp->mb[11] = rsp->vp_idx;
  2780. mcp->mb[14] = rsp->msix->entry;
  2781. mcp->mb[13] = rsp->rid;
  2782. reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
  2783. QLA_QUE_PAGE * rsp->id);
  2784. mcp->mb[4] = rsp->id;
  2785. /* que in ptr index */
  2786. mcp->mb[8] = 0;
  2787. /* que out ptr index */
  2788. mcp->mb[9] = 0;
  2789. mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7
  2790. |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2791. mcp->in_mb = MBX_0;
  2792. mcp->flags = MBX_DMA_OUT;
  2793. mcp->tov = 60;
  2794. spin_lock_irqsave(&ha->hardware_lock, flags);
  2795. if (!(rsp->options & BIT_0)) {
  2796. WRT_REG_DWORD(&reg->rsp_q_out, 0);
  2797. WRT_REG_DWORD(&reg->rsp_q_in, 0);
  2798. }
  2799. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2800. rval = qla2x00_mailbox_command(vha, mcp);
  2801. if (rval != QLA_SUCCESS)
  2802. DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
  2803. "mb0=%x.\n", __func__,
  2804. vha->host_no, rval, mcp->mb[0]));
  2805. return rval;
  2806. }