qla_mbx.c 75 KB

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