qla_mbx.c 74 KB

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