qla_mbx.c 80 KB

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