qla_mbx.c 80 KB

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