qla_mbx.c 79 KB

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