qla_mbx.c 75 KB

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