qla_mbx.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467
  1. /*
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic ISP2x00 device driver for Linux 2.6.x
  5. * Copyright (C) 2003-2004 QLogic Corporation
  6. * (www.qlogic.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. */
  19. #include "qla_def.h"
  20. #include <linux/delay.h>
  21. static void
  22. qla2x00_mbx_sem_timeout(unsigned long data)
  23. {
  24. struct semaphore *sem_ptr = (struct semaphore *)data;
  25. DEBUG11(printk("qla2x00_sem_timeout: entered.\n");)
  26. if (sem_ptr != NULL) {
  27. up(sem_ptr);
  28. }
  29. DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");)
  30. }
  31. /*
  32. * qla2x00_mailbox_command
  33. * Issue mailbox command and waits for completion.
  34. *
  35. * Input:
  36. * ha = adapter block pointer.
  37. * mcp = driver internal mbx struct pointer.
  38. *
  39. * Output:
  40. * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
  41. *
  42. * Returns:
  43. * 0 : QLA_SUCCESS = cmd performed success
  44. * 1 : QLA_FUNCTION_FAILED (error encountered)
  45. * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
  46. *
  47. * Context:
  48. * Kernel context.
  49. */
  50. static int
  51. qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
  52. {
  53. int rval;
  54. unsigned long flags = 0;
  55. device_reg_t __iomem *reg = ha->iobase;
  56. struct timer_list tmp_intr_timer;
  57. uint8_t abort_active;
  58. uint8_t io_lock_on = ha->flags.init_done;
  59. uint16_t command;
  60. uint16_t *iptr;
  61. uint16_t __iomem *optr;
  62. uint32_t cnt;
  63. uint32_t mboxes;
  64. unsigned long mbx_flags = 0;
  65. unsigned long wait_time;
  66. rval = QLA_SUCCESS;
  67. abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  68. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  69. /*
  70. * Wait for active mailbox commands to finish by waiting at most tov
  71. * seconds. This is to serialize actual issuing of mailbox cmds during
  72. * non ISP abort time.
  73. */
  74. if (!abort_active) {
  75. if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
  76. /* Timeout occurred. Return error. */
  77. DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
  78. "Exiting.\n", __func__, ha->host_no);)
  79. return QLA_FUNCTION_TIMEOUT;
  80. }
  81. }
  82. ha->flags.mbox_busy = 1;
  83. /* Save mailbox command for debug */
  84. ha->mcp = mcp;
  85. /* Try to get mailbox register access */
  86. if (!abort_active)
  87. spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
  88. DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
  89. ha->host_no, mcp->mb[0]);)
  90. spin_lock_irqsave(&ha->hardware_lock, flags);
  91. /* Load mailbox registers. */
  92. if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
  93. optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
  94. else
  95. optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
  96. iptr = mcp->mb;
  97. command = mcp->mb[0];
  98. mboxes = mcp->out_mb;
  99. for (cnt = 0; cnt < ha->mbx_count; cnt++) {
  100. if (IS_QLA2200(ha) && cnt == 8)
  101. optr =
  102. (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
  103. if (mboxes & BIT_0)
  104. WRT_REG_WORD(optr, *iptr);
  105. mboxes >>= 1;
  106. optr++;
  107. iptr++;
  108. }
  109. #if defined(QL_DEBUG_LEVEL_1)
  110. printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
  111. __func__, ha->host_no);
  112. qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
  113. printk("\n");
  114. qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
  115. printk("\n");
  116. qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
  117. printk("\n");
  118. printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
  119. qla2x00_dump_regs(ha);
  120. #endif
  121. /* Issue set host interrupt command to send cmd out. */
  122. ha->flags.mbox_int = 0;
  123. clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  124. /* Unlock mbx registers and wait for interrupt */
  125. DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
  126. "jiffies=%lx.\n", __func__, ha->host_no, jiffies);)
  127. /* Wait for mbx cmd completion until timeout */
  128. if (!abort_active && io_lock_on) {
  129. /* sleep on completion semaphore */
  130. DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
  131. __func__, ha->host_no);)
  132. init_timer(&tmp_intr_timer);
  133. tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
  134. tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
  135. tmp_intr_timer.function =
  136. (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
  137. DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
  138. ha->host_no);)
  139. add_timer(&tmp_intr_timer);
  140. DEBUG11(printk("%s(%ld): going to unlock & sleep. "
  141. "time=0x%lx.\n", __func__, ha->host_no, jiffies);)
  142. set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
  143. if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
  144. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
  145. else
  146. WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
  147. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  148. if (!abort_active)
  149. spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
  150. /* Wait for either the timer to expire
  151. * or the mbox completion interrupt
  152. */
  153. down(&ha->mbx_intr_sem);
  154. DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
  155. ha->host_no, jiffies);)
  156. clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
  157. /* delete the timer */
  158. del_timer(&tmp_intr_timer);
  159. } else {
  160. DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
  161. ha->host_no, command);)
  162. if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
  163. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
  164. else
  165. WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
  166. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  167. if (!abort_active)
  168. spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
  169. wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
  170. while (!ha->flags.mbox_int) {
  171. if (time_after(jiffies, wait_time))
  172. break;
  173. /* Check for pending interrupts. */
  174. qla2x00_poll(ha);
  175. udelay(10); /* v4.27 */
  176. } /* while */
  177. }
  178. if (!abort_active)
  179. spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
  180. /* Check whether we timed out */
  181. if (ha->flags.mbox_int) {
  182. uint16_t *iptr2;
  183. DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
  184. ha->host_no, command);)
  185. /* Got interrupt. Clear the flag. */
  186. ha->flags.mbox_int = 0;
  187. clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  188. if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
  189. rval = QLA_FUNCTION_FAILED;
  190. /* Load return mailbox registers. */
  191. iptr2 = mcp->mb;
  192. iptr = (uint16_t *)&ha->mailbox_out[0];
  193. mboxes = mcp->in_mb;
  194. for (cnt = 0; cnt < ha->mbx_count; cnt++) {
  195. if (mboxes & BIT_0)
  196. *iptr2 = *iptr;
  197. mboxes >>= 1;
  198. iptr2++;
  199. iptr++;
  200. }
  201. } else {
  202. #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
  203. defined(QL_DEBUG_LEVEL_11)
  204. uint16_t mb0;
  205. uint32_t ictrl;
  206. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  207. mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
  208. ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
  209. } else {
  210. mb0 = RD_MAILBOX_REG(ha, reg->isp, 0);
  211. ictrl = RD_REG_WORD(&reg->isp.ictrl);
  212. }
  213. printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
  214. __func__, ha->host_no, command);
  215. printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
  216. ha->host_no, ictrl, jiffies);
  217. printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
  218. ha->host_no, mb0);
  219. qla2x00_dump_regs(ha);
  220. #endif
  221. rval = QLA_FUNCTION_TIMEOUT;
  222. }
  223. if (!abort_active)
  224. spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
  225. ha->flags.mbox_busy = 0;
  226. /* Clean up */
  227. ha->mcp = NULL;
  228. if (!abort_active) {
  229. DEBUG11(printk("%s(%ld): checking for additional resp "
  230. "interrupt.\n", __func__, ha->host_no);)
  231. /* polling mode for non isp_abort commands. */
  232. qla2x00_poll(ha);
  233. }
  234. if (rval == QLA_FUNCTION_TIMEOUT &&
  235. mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
  236. if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
  237. /* not in dpc. schedule it for dpc to take over. */
  238. DEBUG(printk("%s(%ld): timeout schedule "
  239. "isp_abort_needed.\n", __func__, ha->host_no);)
  240. DEBUG2_3_11(printk("%s(%ld): timeout schedule "
  241. "isp_abort_needed.\n", __func__, ha->host_no);)
  242. qla_printk(KERN_WARNING, ha,
  243. "Mailbox command timeout occured. Scheduling ISP "
  244. "abort.\n");
  245. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  246. if (ha->dpc_wait && !ha->dpc_active)
  247. up(ha->dpc_wait);
  248. } else if (!abort_active) {
  249. /* call abort directly since we are in the DPC thread */
  250. DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
  251. __func__, ha->host_no);)
  252. DEBUG2_3_11(printk("%s(%ld): timeout calling "
  253. "abort_isp\n", __func__, ha->host_no);)
  254. qla_printk(KERN_WARNING, ha,
  255. "Mailbox command timeout occured. Issuing ISP "
  256. "abort.\n");
  257. set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  258. clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  259. if (qla2x00_abort_isp(ha)) {
  260. /* Failed. retry later. */
  261. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  262. }
  263. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  264. DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
  265. ha->host_no);)
  266. DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
  267. __func__, ha->host_no);)
  268. }
  269. }
  270. /* Allow next mbx cmd to come in. */
  271. if (!abort_active)
  272. up(&ha->mbx_cmd_sem);
  273. if (rval) {
  274. DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
  275. "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
  276. mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)
  277. } else {
  278. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  279. }
  280. return rval;
  281. }
  282. /*
  283. * qla2x00_load_ram
  284. * Load adapter RAM using DMA.
  285. *
  286. * Input:
  287. * ha = adapter block pointer.
  288. *
  289. * Returns:
  290. * qla2x00 local function return status code.
  291. *
  292. * Context:
  293. * Kernel context.
  294. */
  295. int
  296. qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr,
  297. uint16_t risc_code_size)
  298. {
  299. int rval;
  300. mbx_cmd_t mc;
  301. mbx_cmd_t *mcp = &mc;
  302. uint32_t req_len;
  303. dma_addr_t nml_dma;
  304. uint32_t nml_len;
  305. uint32_t normalized;
  306. DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n",
  307. ha->host_no);)
  308. req_len = risc_code_size;
  309. nml_dma = 0;
  310. nml_len = 0;
  311. normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
  312. &nml_len);
  313. /* Load first segment */
  314. mcp->mb[0] = MBC_LOAD_RISC_RAM;
  315. mcp->mb[1] = risc_addr;
  316. mcp->mb[2] = MSW(req_dma);
  317. mcp->mb[3] = LSW(req_dma);
  318. mcp->mb[4] = (uint16_t)req_len;
  319. mcp->mb[6] = MSW(MSD(req_dma));
  320. mcp->mb[7] = LSW(MSD(req_dma));
  321. mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  322. mcp->in_mb = MBX_0;
  323. mcp->tov = 30;
  324. mcp->flags = 0;
  325. rval = qla2x00_mailbox_command(ha, mcp);
  326. /* Load second segment - if necessary */
  327. if (normalized && (rval == QLA_SUCCESS)) {
  328. mcp->mb[0] = MBC_LOAD_RISC_RAM;
  329. mcp->mb[1] = risc_addr + (uint16_t)req_len;
  330. mcp->mb[2] = MSW(nml_dma);
  331. mcp->mb[3] = LSW(nml_dma);
  332. mcp->mb[4] = (uint16_t)nml_len;
  333. mcp->mb[6] = MSW(MSD(nml_dma));
  334. mcp->mb[7] = LSW(MSD(nml_dma));
  335. mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  336. mcp->in_mb = MBX_0;
  337. mcp->tov = 30;
  338. mcp->flags = 0;
  339. rval = qla2x00_mailbox_command(ha, mcp);
  340. }
  341. if (rval == QLA_SUCCESS) {
  342. /* Empty */
  343. DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);)
  344. } else {
  345. /* Empty */
  346. DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x "
  347. "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);)
  348. }
  349. return rval;
  350. }
  351. /*
  352. * qla2x00_load_ram_ext
  353. * Load adapter extended RAM using DMA.
  354. *
  355. * Input:
  356. * ha = adapter block pointer.
  357. *
  358. * Returns:
  359. * qla2x00 local function return status code.
  360. *
  361. * Context:
  362. * Kernel context.
  363. */
  364. int
  365. qla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma,
  366. uint32_t risc_addr, uint32_t risc_code_size)
  367. {
  368. int rval;
  369. mbx_cmd_t mc;
  370. mbx_cmd_t *mcp = &mc;
  371. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  372. mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
  373. mcp->mb[1] = LSW(risc_addr);
  374. mcp->mb[2] = MSW(req_dma);
  375. mcp->mb[3] = LSW(req_dma);
  376. mcp->mb[6] = MSW(MSD(req_dma));
  377. mcp->mb[7] = LSW(MSD(req_dma));
  378. mcp->mb[8] = MSW(risc_addr);
  379. mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  380. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  381. mcp->mb[4] = MSW(risc_code_size);
  382. mcp->mb[5] = LSW(risc_code_size);
  383. mcp->out_mb |= MBX_5|MBX_4;
  384. } else {
  385. mcp->mb[4] = LSW(risc_code_size);
  386. mcp->out_mb |= MBX_4;
  387. }
  388. mcp->in_mb = MBX_0;
  389. mcp->tov = 30;
  390. mcp->flags = 0;
  391. rval = qla2x00_mailbox_command(ha, mcp);
  392. if (rval != QLA_SUCCESS) {
  393. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  394. ha->host_no, rval, mcp->mb[0]));
  395. } else {
  396. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  397. }
  398. return rval;
  399. }
  400. /*
  401. * qla2x00_execute_fw
  402. * Start adapter firmware.
  403. *
  404. * Input:
  405. * ha = adapter block pointer.
  406. * TARGET_QUEUE_LOCK must be released.
  407. * ADAPTER_STATE_LOCK must be released.
  408. *
  409. * Returns:
  410. * qla2x00 local function return status code.
  411. *
  412. * Context:
  413. * Kernel context.
  414. */
  415. int
  416. qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
  417. {
  418. int rval;
  419. mbx_cmd_t mc;
  420. mbx_cmd_t *mcp = &mc;
  421. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  422. mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
  423. mcp->out_mb = MBX_0;
  424. mcp->in_mb = MBX_0;
  425. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  426. mcp->mb[1] = MSW(risc_addr);
  427. mcp->mb[2] = LSW(risc_addr);
  428. mcp->mb[3] = 0;
  429. mcp->out_mb |= MBX_3|MBX_2|MBX_1;
  430. mcp->in_mb |= MBX_1;
  431. } else {
  432. mcp->mb[1] = LSW(risc_addr);
  433. mcp->out_mb |= MBX_1;
  434. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  435. mcp->mb[2] = 0;
  436. mcp->out_mb |= MBX_2;
  437. }
  438. }
  439. mcp->tov = 30;
  440. mcp->flags = 0;
  441. rval = qla2x00_mailbox_command(ha, mcp);
  442. if (rval != QLA_SUCCESS) {
  443. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  444. ha->host_no, rval, mcp->mb[0]));
  445. } else {
  446. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  447. DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
  448. __func__, ha->host_no, mcp->mb[1]);)
  449. } else {
  450. DEBUG11(printk("%s(%ld): done.\n", __func__,
  451. ha->host_no);)
  452. }
  453. }
  454. return rval;
  455. }
  456. /*
  457. * qla2x00_get_fw_version
  458. * Get firmware version.
  459. *
  460. * Input:
  461. * ha: adapter state pointer.
  462. * major: pointer for major number.
  463. * minor: pointer for minor number.
  464. * subminor: pointer for subminor number.
  465. *
  466. * Returns:
  467. * qla2x00 local function return status code.
  468. *
  469. * Context:
  470. * Kernel context.
  471. */
  472. void
  473. qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
  474. uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
  475. {
  476. int rval;
  477. mbx_cmd_t mc;
  478. mbx_cmd_t *mcp = &mc;
  479. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  480. mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
  481. mcp->out_mb = MBX_0;
  482. mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  483. mcp->flags = 0;
  484. mcp->tov = 30;
  485. rval = qla2x00_mailbox_command(ha, mcp);
  486. /* Return mailbox data. */
  487. *major = mcp->mb[1];
  488. *minor = mcp->mb[2];
  489. *subminor = mcp->mb[3];
  490. *attributes = mcp->mb[6];
  491. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  492. *memory = 0x1FFFF; /* Defaults to 128KB. */
  493. else
  494. *memory = (mcp->mb[5] << 16) | mcp->mb[4];
  495. if (rval != QLA_SUCCESS) {
  496. /*EMPTY*/
  497. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  498. ha->host_no, rval));
  499. } else {
  500. /*EMPTY*/
  501. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  502. }
  503. }
  504. /*
  505. * qla2x00_get_fw_options
  506. * Set firmware options.
  507. *
  508. * Input:
  509. * ha = adapter block pointer.
  510. * fwopt = pointer for firmware options.
  511. *
  512. * Returns:
  513. * qla2x00 local function return status code.
  514. *
  515. * Context:
  516. * Kernel context.
  517. */
  518. int
  519. qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
  520. {
  521. int rval;
  522. mbx_cmd_t mc;
  523. mbx_cmd_t *mcp = &mc;
  524. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  525. mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
  526. mcp->out_mb = MBX_0;
  527. mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  528. mcp->tov = 30;
  529. mcp->flags = 0;
  530. rval = qla2x00_mailbox_command(ha, mcp);
  531. if (rval != QLA_SUCCESS) {
  532. /*EMPTY*/
  533. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  534. ha->host_no, rval));
  535. } else {
  536. fwopts[0] = mcp->mb[0];
  537. fwopts[1] = mcp->mb[1];
  538. fwopts[2] = mcp->mb[2];
  539. fwopts[3] = mcp->mb[3];
  540. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  541. }
  542. return rval;
  543. }
  544. /*
  545. * qla2x00_set_fw_options
  546. * Set firmware options.
  547. *
  548. * Input:
  549. * ha = adapter block pointer.
  550. * fwopt = pointer for firmware options.
  551. *
  552. * Returns:
  553. * qla2x00 local function return status code.
  554. *
  555. * Context:
  556. * Kernel context.
  557. */
  558. int
  559. qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
  560. {
  561. int rval;
  562. mbx_cmd_t mc;
  563. mbx_cmd_t *mcp = &mc;
  564. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  565. mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
  566. mcp->mb[1] = fwopts[1];
  567. mcp->mb[2] = fwopts[2];
  568. mcp->mb[3] = fwopts[3];
  569. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  570. mcp->in_mb = MBX_0;
  571. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  572. mcp->in_mb |= MBX_1;
  573. } else {
  574. mcp->mb[10] = fwopts[10];
  575. mcp->mb[11] = fwopts[11];
  576. mcp->mb[12] = 0; /* Undocumented, but used */
  577. mcp->out_mb |= MBX_12|MBX_11|MBX_10;
  578. }
  579. mcp->tov = 30;
  580. mcp->flags = 0;
  581. rval = qla2x00_mailbox_command(ha, mcp);
  582. fwopts[0] = mcp->mb[0];
  583. if (rval != QLA_SUCCESS) {
  584. /*EMPTY*/
  585. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
  586. ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  587. } else {
  588. /*EMPTY*/
  589. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  590. }
  591. return rval;
  592. }
  593. /*
  594. * qla2x00_mbx_reg_test
  595. * Mailbox register wrap test.
  596. *
  597. * Input:
  598. * ha = adapter block pointer.
  599. * TARGET_QUEUE_LOCK must be released.
  600. * ADAPTER_STATE_LOCK must be released.
  601. *
  602. * Returns:
  603. * qla2x00 local function return status code.
  604. *
  605. * Context:
  606. * Kernel context.
  607. */
  608. int
  609. qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
  610. {
  611. int rval;
  612. mbx_cmd_t mc;
  613. mbx_cmd_t *mcp = &mc;
  614. DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);)
  615. mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
  616. mcp->mb[1] = 0xAAAA;
  617. mcp->mb[2] = 0x5555;
  618. mcp->mb[3] = 0xAA55;
  619. mcp->mb[4] = 0x55AA;
  620. mcp->mb[5] = 0xA5A5;
  621. mcp->mb[6] = 0x5A5A;
  622. mcp->mb[7] = 0x2525;
  623. mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  624. mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  625. mcp->tov = 30;
  626. mcp->flags = 0;
  627. rval = qla2x00_mailbox_command(ha, mcp);
  628. if (rval == QLA_SUCCESS) {
  629. if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
  630. mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
  631. rval = QLA_FUNCTION_FAILED;
  632. if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
  633. mcp->mb[7] != 0x2525)
  634. rval = QLA_FUNCTION_FAILED;
  635. }
  636. if (rval != QLA_SUCCESS) {
  637. /*EMPTY*/
  638. DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
  639. ha->host_no, rval);)
  640. } else {
  641. /*EMPTY*/
  642. DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
  643. ha->host_no);)
  644. }
  645. return rval;
  646. }
  647. /*
  648. * qla2x00_verify_checksum
  649. * Verify firmware checksum.
  650. *
  651. * Input:
  652. * ha = adapter block pointer.
  653. * TARGET_QUEUE_LOCK must be released.
  654. * ADAPTER_STATE_LOCK must be released.
  655. *
  656. * Returns:
  657. * qla2x00 local function return status code.
  658. *
  659. * Context:
  660. * Kernel context.
  661. */
  662. int
  663. qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
  664. {
  665. int rval;
  666. mbx_cmd_t mc;
  667. mbx_cmd_t *mcp = &mc;
  668. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  669. mcp->mb[0] = MBC_VERIFY_CHECKSUM;
  670. mcp->out_mb = MBX_0;
  671. mcp->in_mb = MBX_0;
  672. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  673. mcp->mb[1] = MSW(risc_addr);
  674. mcp->mb[2] = LSW(risc_addr);
  675. mcp->out_mb |= MBX_2|MBX_1;
  676. mcp->in_mb |= MBX_2|MBX_1;
  677. } else {
  678. mcp->mb[1] = LSW(risc_addr);
  679. mcp->out_mb |= MBX_1;
  680. mcp->in_mb |= MBX_1;
  681. }
  682. mcp->tov = 30;
  683. mcp->flags = 0;
  684. rval = qla2x00_mailbox_command(ha, mcp);
  685. if (rval != QLA_SUCCESS) {
  686. DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
  687. ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
  688. (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));)
  689. } else {
  690. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  691. }
  692. return rval;
  693. }
  694. /*
  695. * qla2x00_issue_iocb
  696. * Issue IOCB using mailbox command
  697. *
  698. * Input:
  699. * ha = adapter state pointer.
  700. * buffer = buffer pointer.
  701. * phys_addr = physical address of buffer.
  702. * size = size of buffer.
  703. * TARGET_QUEUE_LOCK must be released.
  704. * ADAPTER_STATE_LOCK must be released.
  705. *
  706. * Returns:
  707. * qla2x00 local function return status code.
  708. *
  709. * Context:
  710. * Kernel context.
  711. */
  712. int
  713. qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
  714. size_t size)
  715. {
  716. int rval;
  717. mbx_cmd_t mc;
  718. mbx_cmd_t *mcp = &mc;
  719. mcp->mb[0] = MBC_IOCB_COMMAND_A64;
  720. mcp->mb[1] = 0;
  721. mcp->mb[2] = MSW(phys_addr);
  722. mcp->mb[3] = LSW(phys_addr);
  723. mcp->mb[6] = MSW(MSD(phys_addr));
  724. mcp->mb[7] = LSW(MSD(phys_addr));
  725. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  726. mcp->in_mb = MBX_2|MBX_0;
  727. mcp->tov = 30;
  728. mcp->flags = 0;
  729. rval = qla2x00_mailbox_command(ha, mcp);
  730. if (rval != QLA_SUCCESS) {
  731. /*EMPTY*/
  732. DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
  733. ha->host_no, rval);)
  734. DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
  735. ha->host_no, rval);)
  736. } else {
  737. sts_entry_t *sts_entry = (sts_entry_t *) buffer;
  738. /* Mask reserved bits. */
  739. sts_entry->entry_status &=
  740. IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RF_MASK_24XX :RF_MASK;
  741. }
  742. return rval;
  743. }
  744. /*
  745. * qla2x00_abort_command
  746. * Abort command aborts a specified IOCB.
  747. *
  748. * Input:
  749. * ha = adapter block pointer.
  750. * sp = SB structure pointer.
  751. *
  752. * Returns:
  753. * qla2x00 local function return status code.
  754. *
  755. * Context:
  756. * Kernel context.
  757. */
  758. int
  759. qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
  760. {
  761. unsigned long flags = 0;
  762. fc_port_t *fcport;
  763. int rval;
  764. uint32_t handle;
  765. mbx_cmd_t mc;
  766. mbx_cmd_t *mcp = &mc;
  767. DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
  768. fcport = sp->fcport;
  769. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  770. atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  771. return 1;
  772. }
  773. spin_lock_irqsave(&ha->hardware_lock, flags);
  774. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  775. if (ha->outstanding_cmds[handle] == sp)
  776. break;
  777. }
  778. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  779. if (handle == MAX_OUTSTANDING_COMMANDS) {
  780. /* command not found */
  781. return QLA_FUNCTION_FAILED;
  782. }
  783. mcp->mb[0] = MBC_ABORT_COMMAND;
  784. if (HAS_EXTENDED_IDS(ha))
  785. mcp->mb[1] = fcport->loop_id;
  786. else
  787. mcp->mb[1] = fcport->loop_id << 8;
  788. mcp->mb[2] = (uint16_t)handle;
  789. mcp->mb[3] = (uint16_t)(handle >> 16);
  790. mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
  791. mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  792. mcp->in_mb = MBX_0;
  793. mcp->tov = 30;
  794. mcp->flags = 0;
  795. rval = qla2x00_mailbox_command(ha, mcp);
  796. if (rval != QLA_SUCCESS) {
  797. DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
  798. ha->host_no, rval);)
  799. } else {
  800. sp->flags |= SRB_ABORT_PENDING;
  801. DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
  802. ha->host_no);)
  803. }
  804. return rval;
  805. }
  806. #if USE_ABORT_TGT
  807. /*
  808. * qla2x00_abort_target
  809. * Issue abort target mailbox command.
  810. *
  811. * Input:
  812. * ha = adapter block pointer.
  813. *
  814. * Returns:
  815. * qla2x00 local function return status code.
  816. *
  817. * Context:
  818. * Kernel context.
  819. */
  820. int
  821. qla2x00_abort_target(fc_port_t *fcport)
  822. {
  823. int rval;
  824. mbx_cmd_t mc;
  825. mbx_cmd_t *mcp = &mc;
  826. scsi_qla_host_t *ha;
  827. if (fcport == NULL)
  828. return 0;
  829. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
  830. ha = fcport->ha;
  831. mcp->mb[0] = MBC_ABORT_TARGET;
  832. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  833. if (HAS_EXTENDED_IDS(ha)) {
  834. mcp->mb[1] = fcport->loop_id;
  835. mcp->mb[10] = 0;
  836. mcp->out_mb |= MBX_10;
  837. } else {
  838. mcp->mb[1] = fcport->loop_id << 8;
  839. }
  840. mcp->mb[2] = ha->loop_reset_delay;
  841. mcp->in_mb = MBX_0;
  842. mcp->tov = 30;
  843. mcp->flags = 0;
  844. rval = qla2x00_mailbox_command(ha, mcp);
  845. /* Issue marker command. */
  846. ha->marker_needed = 1;
  847. if (rval != QLA_SUCCESS) {
  848. DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
  849. ha->host_no, rval);)
  850. } else {
  851. /*EMPTY*/
  852. DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
  853. ha->host_no);)
  854. }
  855. return rval;
  856. }
  857. #endif
  858. /*
  859. * qla2x00_target_reset
  860. * Issue target reset mailbox command.
  861. *
  862. * Input:
  863. * ha = adapter block pointer.
  864. * TARGET_QUEUE_LOCK must be released.
  865. * ADAPTER_STATE_LOCK must be released.
  866. *
  867. * Returns:
  868. * qla2x00 local function return status code.
  869. *
  870. * Context:
  871. * Kernel context.
  872. */
  873. int
  874. qla2x00_target_reset(scsi_qla_host_t *ha, struct fc_port *fcport)
  875. {
  876. int rval;
  877. mbx_cmd_t mc;
  878. mbx_cmd_t *mcp = &mc;
  879. DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha->host_no);)
  880. if (atomic_read(&fcport->state) != FCS_ONLINE)
  881. return 0;
  882. mcp->mb[0] = MBC_TARGET_RESET;
  883. if (HAS_EXTENDED_IDS(ha))
  884. mcp->mb[1] = fcport->loop_id;
  885. else
  886. mcp->mb[1] = fcport->loop_id << 8;
  887. mcp->mb[2] = ha->loop_reset_delay;
  888. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  889. mcp->in_mb = MBX_0;
  890. mcp->tov = 30;
  891. mcp->flags = 0;
  892. rval = qla2x00_mailbox_command(ha, mcp);
  893. if (rval != QLA_SUCCESS) {
  894. /*EMPTY*/
  895. DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n",
  896. ha->host_no, rval);)
  897. } else {
  898. /*EMPTY*/
  899. DEBUG11(printk("qla2x00_target_reset(%ld): done.\n",
  900. ha->host_no);)
  901. }
  902. return rval;
  903. }
  904. /*
  905. * qla2x00_get_adapter_id
  906. * Get adapter ID and topology.
  907. *
  908. * Input:
  909. * ha = adapter block pointer.
  910. * id = pointer for loop ID.
  911. * al_pa = pointer for AL_PA.
  912. * area = pointer for area.
  913. * domain = pointer for domain.
  914. * top = pointer for topology.
  915. * TARGET_QUEUE_LOCK must be released.
  916. * ADAPTER_STATE_LOCK must be released.
  917. *
  918. * Returns:
  919. * qla2x00 local function return status code.
  920. *
  921. * Context:
  922. * Kernel context.
  923. */
  924. int
  925. qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
  926. uint8_t *area, uint8_t *domain, uint16_t *top)
  927. {
  928. int rval;
  929. mbx_cmd_t mc;
  930. mbx_cmd_t *mcp = &mc;
  931. DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
  932. ha->host_no);)
  933. mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
  934. mcp->out_mb = MBX_0;
  935. mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  936. mcp->tov = 30;
  937. mcp->flags = 0;
  938. rval = qla2x00_mailbox_command(ha, mcp);
  939. /* Return data. */
  940. *id = mcp->mb[1];
  941. *al_pa = LSB(mcp->mb[2]);
  942. *area = MSB(mcp->mb[2]);
  943. *domain = LSB(mcp->mb[3]);
  944. *top = mcp->mb[6];
  945. if (rval != QLA_SUCCESS) {
  946. /*EMPTY*/
  947. DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
  948. ha->host_no, rval);)
  949. } else {
  950. /*EMPTY*/
  951. DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
  952. ha->host_no);)
  953. }
  954. return rval;
  955. }
  956. /*
  957. * qla2x00_get_retry_cnt
  958. * Get current firmware login retry count and delay.
  959. *
  960. * Input:
  961. * ha = adapter block pointer.
  962. * retry_cnt = pointer to login retry count.
  963. * tov = pointer to login timeout value.
  964. *
  965. * Returns:
  966. * qla2x00 local function return status code.
  967. *
  968. * Context:
  969. * Kernel context.
  970. */
  971. int
  972. qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
  973. uint16_t *r_a_tov)
  974. {
  975. int rval;
  976. uint16_t ratov;
  977. mbx_cmd_t mc;
  978. mbx_cmd_t *mcp = &mc;
  979. DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
  980. ha->host_no);)
  981. mcp->mb[0] = MBC_GET_RETRY_COUNT;
  982. mcp->out_mb = MBX_0;
  983. mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  984. mcp->tov = 30;
  985. mcp->flags = 0;
  986. rval = qla2x00_mailbox_command(ha, mcp);
  987. if (rval != QLA_SUCCESS) {
  988. /*EMPTY*/
  989. DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
  990. ha->host_no, mcp->mb[0]);)
  991. } else {
  992. /* Convert returned data and check our values. */
  993. *r_a_tov = mcp->mb[3] / 2;
  994. ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
  995. if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
  996. /* Update to the larger values */
  997. *retry_cnt = (uint8_t)mcp->mb[1];
  998. *tov = ratov;
  999. }
  1000. DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
  1001. "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
  1002. }
  1003. return rval;
  1004. }
  1005. /*
  1006. * qla2x00_init_firmware
  1007. * Initialize adapter firmware.
  1008. *
  1009. * Input:
  1010. * ha = adapter block pointer.
  1011. * dptr = Initialization control block pointer.
  1012. * size = size of initialization control block.
  1013. * TARGET_QUEUE_LOCK must be released.
  1014. * ADAPTER_STATE_LOCK must be released.
  1015. *
  1016. * Returns:
  1017. * qla2x00 local function return status code.
  1018. *
  1019. * Context:
  1020. * Kernel context.
  1021. */
  1022. int
  1023. qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
  1024. {
  1025. int rval;
  1026. mbx_cmd_t mc;
  1027. mbx_cmd_t *mcp = &mc;
  1028. DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
  1029. ha->host_no);)
  1030. mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
  1031. mcp->mb[2] = MSW(ha->init_cb_dma);
  1032. mcp->mb[3] = LSW(ha->init_cb_dma);
  1033. mcp->mb[4] = 0;
  1034. mcp->mb[5] = 0;
  1035. mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
  1036. mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
  1037. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1038. mcp->in_mb = MBX_5|MBX_4|MBX_0;
  1039. mcp->buf_size = size;
  1040. mcp->flags = MBX_DMA_OUT;
  1041. mcp->tov = 30;
  1042. rval = qla2x00_mailbox_command(ha, mcp);
  1043. if (rval != QLA_SUCCESS) {
  1044. /*EMPTY*/
  1045. DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
  1046. "mb0=%x.\n",
  1047. ha->host_no, rval, mcp->mb[0]);)
  1048. } else {
  1049. /*EMPTY*/
  1050. DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
  1051. ha->host_no);)
  1052. }
  1053. return rval;
  1054. }
  1055. /*
  1056. * qla2x00_get_port_database
  1057. * Issue normal/enhanced get port database mailbox command
  1058. * and copy device name as necessary.
  1059. *
  1060. * Input:
  1061. * ha = adapter state pointer.
  1062. * dev = structure pointer.
  1063. * opt = enhanced cmd option byte.
  1064. *
  1065. * Returns:
  1066. * qla2x00 local function return status code.
  1067. *
  1068. * Context:
  1069. * Kernel context.
  1070. */
  1071. int
  1072. qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
  1073. {
  1074. int rval;
  1075. mbx_cmd_t mc;
  1076. mbx_cmd_t *mcp = &mc;
  1077. port_database_t *pd;
  1078. struct port_database_24xx *pd24;
  1079. dma_addr_t pd_dma;
  1080. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1081. pd24 = NULL;
  1082. pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
  1083. if (pd == NULL) {
  1084. DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
  1085. "structure.\n", __func__, ha->host_no));
  1086. return QLA_MEMORY_ALLOC_FAILED;
  1087. }
  1088. memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
  1089. mcp->mb[0] = MBC_GET_PORT_DATABASE;
  1090. if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA25XX(ha))
  1091. mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
  1092. mcp->mb[2] = MSW(pd_dma);
  1093. mcp->mb[3] = LSW(pd_dma);
  1094. mcp->mb[6] = MSW(MSD(pd_dma));
  1095. mcp->mb[7] = LSW(MSD(pd_dma));
  1096. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1097. mcp->in_mb = MBX_0;
  1098. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1099. mcp->mb[1] = fcport->loop_id;
  1100. mcp->mb[10] = opt;
  1101. mcp->out_mb |= MBX_10|MBX_1;
  1102. mcp->in_mb |= MBX_1;
  1103. } else if (HAS_EXTENDED_IDS(ha)) {
  1104. mcp->mb[1] = fcport->loop_id;
  1105. mcp->mb[10] = opt;
  1106. mcp->out_mb |= MBX_10|MBX_1;
  1107. } else {
  1108. mcp->mb[1] = fcport->loop_id << 8 | opt;
  1109. mcp->out_mb |= MBX_1;
  1110. }
  1111. mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
  1112. PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
  1113. mcp->flags = MBX_DMA_IN;
  1114. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1115. rval = qla2x00_mailbox_command(ha, mcp);
  1116. if (rval != QLA_SUCCESS)
  1117. goto gpd_error_out;
  1118. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1119. pd24 = (struct port_database_24xx *) pd;
  1120. /* Check for logged in state. */
  1121. if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
  1122. pd24->last_login_state != PDS_PRLI_COMPLETE) {
  1123. DEBUG2(printk("%s(%ld): Unable to verify "
  1124. "login-state (%x/%x) for loop_id %x\n",
  1125. __func__, ha->host_no,
  1126. pd24->current_login_state,
  1127. pd24->last_login_state, fcport->loop_id));
  1128. rval = QLA_FUNCTION_FAILED;
  1129. goto gpd_error_out;
  1130. }
  1131. /* Names are little-endian. */
  1132. memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
  1133. memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
  1134. /* Get port_id of device. */
  1135. fcport->d_id.b.domain = pd24->port_id[0];
  1136. fcport->d_id.b.area = pd24->port_id[1];
  1137. fcport->d_id.b.al_pa = pd24->port_id[2];
  1138. fcport->d_id.b.rsvd_1 = 0;
  1139. /* If not target must be initiator or unknown type. */
  1140. if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
  1141. fcport->port_type = FCT_INITIATOR;
  1142. else
  1143. fcport->port_type = FCT_TARGET;
  1144. } else {
  1145. /* Check for logged in state. */
  1146. if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
  1147. pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
  1148. rval = QLA_FUNCTION_FAILED;
  1149. goto gpd_error_out;
  1150. }
  1151. /* Names are little-endian. */
  1152. memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
  1153. memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
  1154. /* Get port_id of device. */
  1155. fcport->d_id.b.domain = pd->port_id[0];
  1156. fcport->d_id.b.area = pd->port_id[3];
  1157. fcport->d_id.b.al_pa = pd->port_id[2];
  1158. fcport->d_id.b.rsvd_1 = 0;
  1159. /* Check for device require authentication. */
  1160. pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
  1161. (fcport->flags &= ~FCF_AUTH_REQ);
  1162. /* If not target must be initiator or unknown type. */
  1163. if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
  1164. fcport->port_type = FCT_INITIATOR;
  1165. else
  1166. fcport->port_type = FCT_TARGET;
  1167. }
  1168. gpd_error_out:
  1169. dma_pool_free(ha->s_dma_pool, pd, pd_dma);
  1170. if (rval != QLA_SUCCESS) {
  1171. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  1172. __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1173. } else {
  1174. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1175. }
  1176. return rval;
  1177. }
  1178. /*
  1179. * qla2x00_get_firmware_state
  1180. * Get adapter firmware state.
  1181. *
  1182. * Input:
  1183. * ha = adapter block pointer.
  1184. * dptr = pointer for firmware state.
  1185. * TARGET_QUEUE_LOCK must be released.
  1186. * ADAPTER_STATE_LOCK must be released.
  1187. *
  1188. * Returns:
  1189. * qla2x00 local function return status code.
  1190. *
  1191. * Context:
  1192. * Kernel context.
  1193. */
  1194. int
  1195. qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
  1196. {
  1197. int rval;
  1198. mbx_cmd_t mc;
  1199. mbx_cmd_t *mcp = &mc;
  1200. DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
  1201. ha->host_no);)
  1202. mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
  1203. mcp->out_mb = MBX_0;
  1204. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  1205. mcp->tov = 30;
  1206. mcp->flags = 0;
  1207. rval = qla2x00_mailbox_command(ha, mcp);
  1208. /* Return firmware state. */
  1209. *dptr = mcp->mb[1];
  1210. if (rval != QLA_SUCCESS) {
  1211. /*EMPTY*/
  1212. DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
  1213. "failed=%x.\n", ha->host_no, rval);)
  1214. } else {
  1215. /*EMPTY*/
  1216. DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
  1217. ha->host_no);)
  1218. }
  1219. return rval;
  1220. }
  1221. /*
  1222. * qla2x00_get_port_name
  1223. * Issue get port name mailbox command.
  1224. * Returned name is in big endian format.
  1225. *
  1226. * Input:
  1227. * ha = adapter block pointer.
  1228. * loop_id = loop ID of device.
  1229. * name = pointer for name.
  1230. * TARGET_QUEUE_LOCK must be released.
  1231. * ADAPTER_STATE_LOCK must be released.
  1232. *
  1233. * Returns:
  1234. * qla2x00 local function return status code.
  1235. *
  1236. * Context:
  1237. * Kernel context.
  1238. */
  1239. int
  1240. qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
  1241. uint8_t opt)
  1242. {
  1243. int rval;
  1244. mbx_cmd_t mc;
  1245. mbx_cmd_t *mcp = &mc;
  1246. DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
  1247. ha->host_no);)
  1248. mcp->mb[0] = MBC_GET_PORT_NAME;
  1249. mcp->out_mb = MBX_1|MBX_0;
  1250. if (HAS_EXTENDED_IDS(ha)) {
  1251. mcp->mb[1] = loop_id;
  1252. mcp->mb[10] = opt;
  1253. mcp->out_mb |= MBX_10;
  1254. } else {
  1255. mcp->mb[1] = loop_id << 8 | opt;
  1256. }
  1257. mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1258. mcp->tov = 30;
  1259. mcp->flags = 0;
  1260. rval = qla2x00_mailbox_command(ha, mcp);
  1261. if (rval != QLA_SUCCESS) {
  1262. /*EMPTY*/
  1263. DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
  1264. ha->host_no, rval);)
  1265. } else {
  1266. if (name != NULL) {
  1267. /* This function returns name in big endian. */
  1268. name[0] = LSB(mcp->mb[2]);
  1269. name[1] = MSB(mcp->mb[2]);
  1270. name[2] = LSB(mcp->mb[3]);
  1271. name[3] = MSB(mcp->mb[3]);
  1272. name[4] = LSB(mcp->mb[6]);
  1273. name[5] = MSB(mcp->mb[6]);
  1274. name[6] = LSB(mcp->mb[7]);
  1275. name[7] = MSB(mcp->mb[7]);
  1276. }
  1277. DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
  1278. ha->host_no);)
  1279. }
  1280. return rval;
  1281. }
  1282. /*
  1283. * qla2x00_lip_reset
  1284. * Issue LIP reset mailbox command.
  1285. *
  1286. * Input:
  1287. * ha = adapter block pointer.
  1288. * TARGET_QUEUE_LOCK must be released.
  1289. * ADAPTER_STATE_LOCK must be released.
  1290. *
  1291. * Returns:
  1292. * qla2x00 local function return status code.
  1293. *
  1294. * Context:
  1295. * Kernel context.
  1296. */
  1297. int
  1298. qla2x00_lip_reset(scsi_qla_host_t *ha)
  1299. {
  1300. int rval;
  1301. mbx_cmd_t mc;
  1302. mbx_cmd_t *mcp = &mc;
  1303. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1304. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1305. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1306. mcp->mb[1] = BIT_0;
  1307. mcp->mb[2] = 0xff;
  1308. mcp->mb[3] = 0;
  1309. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1310. } else {
  1311. mcp->mb[0] = MBC_LIP_RESET;
  1312. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1313. if (HAS_EXTENDED_IDS(ha)) {
  1314. mcp->mb[1] = 0x00ff;
  1315. mcp->mb[10] = 0;
  1316. mcp->out_mb |= MBX_10;
  1317. } else {
  1318. mcp->mb[1] = 0xff00;
  1319. }
  1320. mcp->mb[2] = ha->loop_reset_delay;
  1321. mcp->mb[3] = 0;
  1322. }
  1323. mcp->in_mb = MBX_0;
  1324. mcp->tov = 30;
  1325. mcp->flags = 0;
  1326. rval = qla2x00_mailbox_command(ha, mcp);
  1327. if (rval != QLA_SUCCESS) {
  1328. /*EMPTY*/
  1329. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
  1330. __func__, ha->host_no, rval);)
  1331. } else {
  1332. /*EMPTY*/
  1333. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1334. }
  1335. return rval;
  1336. }
  1337. /*
  1338. * qla2x00_send_sns
  1339. * Send SNS command.
  1340. *
  1341. * Input:
  1342. * ha = adapter block pointer.
  1343. * sns = pointer for command.
  1344. * cmd_size = command size.
  1345. * buf_size = response/command size.
  1346. * TARGET_QUEUE_LOCK must be released.
  1347. * ADAPTER_STATE_LOCK must be released.
  1348. *
  1349. * Returns:
  1350. * qla2x00 local function return status code.
  1351. *
  1352. * Context:
  1353. * Kernel context.
  1354. */
  1355. int
  1356. qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
  1357. uint16_t cmd_size, size_t buf_size)
  1358. {
  1359. int rval;
  1360. mbx_cmd_t mc;
  1361. mbx_cmd_t *mcp = &mc;
  1362. DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
  1363. ha->host_no);)
  1364. DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
  1365. "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
  1366. mcp->mb[0] = MBC_SEND_SNS_COMMAND;
  1367. mcp->mb[1] = cmd_size;
  1368. mcp->mb[2] = MSW(sns_phys_address);
  1369. mcp->mb[3] = LSW(sns_phys_address);
  1370. mcp->mb[6] = MSW(MSD(sns_phys_address));
  1371. mcp->mb[7] = LSW(MSD(sns_phys_address));
  1372. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1373. mcp->in_mb = MBX_0|MBX_1;
  1374. mcp->buf_size = buf_size;
  1375. mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
  1376. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1377. rval = qla2x00_mailbox_command(ha, mcp);
  1378. if (rval != QLA_SUCCESS) {
  1379. /*EMPTY*/
  1380. DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1381. "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
  1382. DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1383. "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
  1384. } else {
  1385. /*EMPTY*/
  1386. DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
  1387. }
  1388. return rval;
  1389. }
  1390. int
  1391. qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1392. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1393. {
  1394. int rval;
  1395. struct logio_entry_24xx *lg;
  1396. dma_addr_t lg_dma;
  1397. uint32_t iop[2];
  1398. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1399. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1400. if (lg == NULL) {
  1401. DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
  1402. __func__, ha->host_no));
  1403. return QLA_MEMORY_ALLOC_FAILED;
  1404. }
  1405. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1406. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1407. lg->entry_count = 1;
  1408. lg->nport_handle = cpu_to_le16(loop_id);
  1409. lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
  1410. if (opt & BIT_0)
  1411. lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
  1412. lg->port_id[0] = al_pa;
  1413. lg->port_id[1] = area;
  1414. lg->port_id[2] = domain;
  1415. rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
  1416. if (rval != QLA_SUCCESS) {
  1417. DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
  1418. "(%x).\n", __func__, ha->host_no, rval);)
  1419. } else if (lg->entry_status != 0) {
  1420. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1421. "-- error status (%x).\n", __func__, ha->host_no,
  1422. lg->entry_status));
  1423. rval = QLA_FUNCTION_FAILED;
  1424. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1425. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1426. iop[1] = le32_to_cpu(lg->io_parameter[1]);
  1427. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1428. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1429. ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
  1430. iop[1]));
  1431. switch (iop[0]) {
  1432. case LSC_SCODE_PORTID_USED:
  1433. mb[0] = MBS_PORT_ID_USED;
  1434. mb[1] = LSW(iop[1]);
  1435. break;
  1436. case LSC_SCODE_NPORT_USED:
  1437. mb[0] = MBS_LOOP_ID_USED;
  1438. break;
  1439. case LSC_SCODE_NOLINK:
  1440. case LSC_SCODE_NOIOCB:
  1441. case LSC_SCODE_NOXCB:
  1442. case LSC_SCODE_CMD_FAILED:
  1443. case LSC_SCODE_NOFABRIC:
  1444. case LSC_SCODE_FW_NOT_READY:
  1445. case LSC_SCODE_NOT_LOGGED_IN:
  1446. case LSC_SCODE_NOPCB:
  1447. case LSC_SCODE_ELS_REJECT:
  1448. case LSC_SCODE_CMD_PARAM_ERR:
  1449. case LSC_SCODE_NONPORT:
  1450. case LSC_SCODE_LOGGED_IN:
  1451. case LSC_SCODE_NOFLOGI_ACC:
  1452. default:
  1453. mb[0] = MBS_COMMAND_ERROR;
  1454. break;
  1455. }
  1456. } else {
  1457. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1458. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1459. mb[0] = MBS_COMMAND_COMPLETE;
  1460. mb[1] = 0;
  1461. if (iop[0] & BIT_4) {
  1462. if (iop[0] & BIT_8)
  1463. mb[1] |= BIT_1;
  1464. } else
  1465. mb[1] = BIT_0;
  1466. }
  1467. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1468. return rval;
  1469. }
  1470. /*
  1471. * qla2x00_login_fabric
  1472. * Issue login fabric port mailbox command.
  1473. *
  1474. * Input:
  1475. * ha = adapter block pointer.
  1476. * loop_id = device loop ID.
  1477. * domain = device domain.
  1478. * area = device area.
  1479. * al_pa = device AL_PA.
  1480. * status = pointer for return status.
  1481. * opt = command options.
  1482. * TARGET_QUEUE_LOCK must be released.
  1483. * ADAPTER_STATE_LOCK must be released.
  1484. *
  1485. * Returns:
  1486. * qla2x00 local function return status code.
  1487. *
  1488. * Context:
  1489. * Kernel context.
  1490. */
  1491. int
  1492. qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1493. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1494. {
  1495. int rval;
  1496. mbx_cmd_t mc;
  1497. mbx_cmd_t *mcp = &mc;
  1498. DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);)
  1499. mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
  1500. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1501. if (HAS_EXTENDED_IDS(ha)) {
  1502. mcp->mb[1] = loop_id;
  1503. mcp->mb[10] = opt;
  1504. mcp->out_mb |= MBX_10;
  1505. } else {
  1506. mcp->mb[1] = (loop_id << 8) | opt;
  1507. }
  1508. mcp->mb[2] = domain;
  1509. mcp->mb[3] = area << 8 | al_pa;
  1510. mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
  1511. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1512. mcp->flags = 0;
  1513. rval = qla2x00_mailbox_command(ha, mcp);
  1514. /* Return mailbox statuses. */
  1515. if (mb != NULL) {
  1516. mb[0] = mcp->mb[0];
  1517. mb[1] = mcp->mb[1];
  1518. mb[2] = mcp->mb[2];
  1519. mb[6] = mcp->mb[6];
  1520. mb[7] = mcp->mb[7];
  1521. }
  1522. if (rval != QLA_SUCCESS) {
  1523. /* RLU tmp code: need to change main mailbox_command function to
  1524. * return ok even when the mailbox completion value is not
  1525. * SUCCESS. The caller needs to be responsible to interpret
  1526. * the return values of this mailbox command if we're not
  1527. * to change too much of the existing code.
  1528. */
  1529. if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
  1530. mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
  1531. mcp->mb[0] == 0x4006)
  1532. rval = QLA_SUCCESS;
  1533. /*EMPTY*/
  1534. DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
  1535. "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
  1536. mcp->mb[0], mcp->mb[1], mcp->mb[2]);)
  1537. } else {
  1538. /*EMPTY*/
  1539. DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
  1540. ha->host_no);)
  1541. }
  1542. return rval;
  1543. }
  1544. /*
  1545. * qla2x00_login_local_device
  1546. * Issue login loop port mailbox command.
  1547. *
  1548. * Input:
  1549. * ha = adapter block pointer.
  1550. * loop_id = device loop ID.
  1551. * opt = command options.
  1552. *
  1553. * Returns:
  1554. * Return status code.
  1555. *
  1556. * Context:
  1557. * Kernel context.
  1558. *
  1559. */
  1560. int
  1561. qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
  1562. uint16_t *mb_ret, uint8_t opt)
  1563. {
  1564. int rval;
  1565. mbx_cmd_t mc;
  1566. mbx_cmd_t *mcp = &mc;
  1567. DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1568. mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
  1569. if (HAS_EXTENDED_IDS(ha))
  1570. mcp->mb[1] = loop_id;
  1571. else
  1572. mcp->mb[1] = loop_id << 8;
  1573. mcp->mb[2] = opt;
  1574. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  1575. mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
  1576. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1577. mcp->flags = 0;
  1578. rval = qla2x00_mailbox_command(ha, mcp);
  1579. /* Return mailbox statuses. */
  1580. if (mb_ret != NULL) {
  1581. mb_ret[0] = mcp->mb[0];
  1582. mb_ret[1] = mcp->mb[1];
  1583. mb_ret[6] = mcp->mb[6];
  1584. mb_ret[7] = mcp->mb[7];
  1585. }
  1586. if (rval != QLA_SUCCESS) {
  1587. /* AV tmp code: need to change main mailbox_command function to
  1588. * return ok even when the mailbox completion value is not
  1589. * SUCCESS. The caller needs to be responsible to interpret
  1590. * the return values of this mailbox command if we're not
  1591. * to change too much of the existing code.
  1592. */
  1593. if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
  1594. rval = QLA_SUCCESS;
  1595. DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1596. "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
  1597. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
  1598. DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1599. "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
  1600. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
  1601. } else {
  1602. /*EMPTY*/
  1603. DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1604. }
  1605. return (rval);
  1606. }
  1607. int
  1608. qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1609. uint8_t area, uint8_t al_pa)
  1610. {
  1611. int rval;
  1612. struct logio_entry_24xx *lg;
  1613. dma_addr_t lg_dma;
  1614. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1615. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1616. if (lg == NULL) {
  1617. DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
  1618. __func__, ha->host_no));
  1619. return QLA_MEMORY_ALLOC_FAILED;
  1620. }
  1621. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1622. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1623. lg->entry_count = 1;
  1624. lg->nport_handle = cpu_to_le16(loop_id);
  1625. lg->control_flags =
  1626. __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_EXPL_LOGO);
  1627. lg->port_id[0] = al_pa;
  1628. lg->port_id[1] = area;
  1629. lg->port_id[2] = domain;
  1630. rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
  1631. if (rval != QLA_SUCCESS) {
  1632. DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
  1633. "(%x).\n", __func__, ha->host_no, rval);)
  1634. } else if (lg->entry_status != 0) {
  1635. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1636. "-- error status (%x).\n", __func__, ha->host_no,
  1637. lg->entry_status));
  1638. rval = QLA_FUNCTION_FAILED;
  1639. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1640. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1641. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1642. ha->host_no, le16_to_cpu(lg->comp_status),
  1643. le32_to_cpu(lg->io_parameter[0]),
  1644. le32_to_cpu(lg->io_parameter[1]));)
  1645. } else {
  1646. /*EMPTY*/
  1647. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1648. }
  1649. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1650. return rval;
  1651. }
  1652. /*
  1653. * qla2x00_fabric_logout
  1654. * Issue logout fabric port mailbox command.
  1655. *
  1656. * Input:
  1657. * ha = adapter block pointer.
  1658. * loop_id = device loop ID.
  1659. * TARGET_QUEUE_LOCK must be released.
  1660. * ADAPTER_STATE_LOCK must be released.
  1661. *
  1662. * Returns:
  1663. * qla2x00 local function return status code.
  1664. *
  1665. * Context:
  1666. * Kernel context.
  1667. */
  1668. int
  1669. qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1670. uint8_t area, uint8_t al_pa)
  1671. {
  1672. int rval;
  1673. mbx_cmd_t mc;
  1674. mbx_cmd_t *mcp = &mc;
  1675. DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
  1676. ha->host_no);)
  1677. mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
  1678. mcp->out_mb = MBX_1|MBX_0;
  1679. if (HAS_EXTENDED_IDS(ha)) {
  1680. mcp->mb[1] = loop_id;
  1681. mcp->mb[10] = 0;
  1682. mcp->out_mb |= MBX_10;
  1683. } else {
  1684. mcp->mb[1] = loop_id << 8;
  1685. }
  1686. mcp->in_mb = MBX_1|MBX_0;
  1687. mcp->tov = 30;
  1688. mcp->flags = 0;
  1689. rval = qla2x00_mailbox_command(ha, mcp);
  1690. if (rval != QLA_SUCCESS) {
  1691. /*EMPTY*/
  1692. DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
  1693. "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
  1694. } else {
  1695. /*EMPTY*/
  1696. DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
  1697. ha->host_no);)
  1698. }
  1699. return rval;
  1700. }
  1701. /*
  1702. * qla2x00_full_login_lip
  1703. * Issue full login LIP mailbox command.
  1704. *
  1705. * Input:
  1706. * ha = adapter block pointer.
  1707. * TARGET_QUEUE_LOCK must be released.
  1708. * ADAPTER_STATE_LOCK must be released.
  1709. *
  1710. * Returns:
  1711. * qla2x00 local function return status code.
  1712. *
  1713. * Context:
  1714. * Kernel context.
  1715. */
  1716. int
  1717. qla2x00_full_login_lip(scsi_qla_host_t *ha)
  1718. {
  1719. int rval;
  1720. mbx_cmd_t mc;
  1721. mbx_cmd_t *mcp = &mc;
  1722. DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
  1723. ha->host_no);)
  1724. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1725. mcp->mb[1] = 0;
  1726. mcp->mb[2] = 0xff;
  1727. mcp->mb[3] = 0;
  1728. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1729. mcp->in_mb = MBX_0;
  1730. mcp->tov = 30;
  1731. mcp->flags = 0;
  1732. rval = qla2x00_mailbox_command(ha, mcp);
  1733. if (rval != QLA_SUCCESS) {
  1734. /*EMPTY*/
  1735. DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
  1736. ha->host_no, rval);)
  1737. } else {
  1738. /*EMPTY*/
  1739. DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
  1740. ha->host_no);)
  1741. }
  1742. return rval;
  1743. }
  1744. /*
  1745. * qla2x00_get_id_list
  1746. *
  1747. * Input:
  1748. * ha = adapter block pointer.
  1749. *
  1750. * Returns:
  1751. * qla2x00 local function return status code.
  1752. *
  1753. * Context:
  1754. * Kernel context.
  1755. */
  1756. int
  1757. qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
  1758. uint16_t *entries)
  1759. {
  1760. int rval;
  1761. mbx_cmd_t mc;
  1762. mbx_cmd_t *mcp = &mc;
  1763. DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
  1764. ha->host_no);)
  1765. if (id_list == NULL)
  1766. return QLA_FUNCTION_FAILED;
  1767. mcp->mb[0] = MBC_GET_ID_LIST;
  1768. mcp->out_mb = MBX_0;
  1769. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1770. mcp->mb[2] = MSW(id_list_dma);
  1771. mcp->mb[3] = LSW(id_list_dma);
  1772. mcp->mb[6] = MSW(MSD(id_list_dma));
  1773. mcp->mb[7] = LSW(MSD(id_list_dma));
  1774. mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2;
  1775. } else {
  1776. mcp->mb[1] = MSW(id_list_dma);
  1777. mcp->mb[2] = LSW(id_list_dma);
  1778. mcp->mb[3] = MSW(MSD(id_list_dma));
  1779. mcp->mb[6] = LSW(MSD(id_list_dma));
  1780. mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
  1781. }
  1782. mcp->in_mb = MBX_1|MBX_0;
  1783. mcp->tov = 30;
  1784. mcp->flags = 0;
  1785. rval = qla2x00_mailbox_command(ha, mcp);
  1786. if (rval != QLA_SUCCESS) {
  1787. /*EMPTY*/
  1788. DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
  1789. ha->host_no, rval);)
  1790. } else {
  1791. *entries = mcp->mb[1];
  1792. DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
  1793. ha->host_no);)
  1794. }
  1795. return rval;
  1796. }
  1797. /*
  1798. * qla2x00_get_resource_cnts
  1799. * Get current firmware resource counts.
  1800. *
  1801. * Input:
  1802. * ha = adapter block pointer.
  1803. *
  1804. * Returns:
  1805. * qla2x00 local function return status code.
  1806. *
  1807. * Context:
  1808. * Kernel context.
  1809. */
  1810. int
  1811. qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
  1812. uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
  1813. {
  1814. int rval;
  1815. mbx_cmd_t mc;
  1816. mbx_cmd_t *mcp = &mc;
  1817. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1818. mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
  1819. mcp->out_mb = MBX_0;
  1820. mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1821. mcp->tov = 30;
  1822. mcp->flags = 0;
  1823. rval = qla2x00_mailbox_command(ha, mcp);
  1824. if (rval != QLA_SUCCESS) {
  1825. /*EMPTY*/
  1826. DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
  1827. ha->host_no, mcp->mb[0]);)
  1828. } else {
  1829. DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
  1830. "mb7=%x mb10=%x.\n", __func__, ha->host_no,
  1831. mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
  1832. mcp->mb[10]));
  1833. if (cur_xchg_cnt)
  1834. *cur_xchg_cnt = mcp->mb[3];
  1835. if (orig_xchg_cnt)
  1836. *orig_xchg_cnt = mcp->mb[6];
  1837. if (cur_iocb_cnt)
  1838. *cur_iocb_cnt = mcp->mb[7];
  1839. if (orig_iocb_cnt)
  1840. *orig_iocb_cnt = mcp->mb[10];
  1841. }
  1842. return (rval);
  1843. }
  1844. #if defined(QL_DEBUG_LEVEL_3)
  1845. /*
  1846. * qla2x00_get_fcal_position_map
  1847. * Get FCAL (LILP) position map using mailbox command
  1848. *
  1849. * Input:
  1850. * ha = adapter state pointer.
  1851. * pos_map = buffer pointer (can be NULL).
  1852. *
  1853. * Returns:
  1854. * qla2x00 local function return status code.
  1855. *
  1856. * Context:
  1857. * Kernel context.
  1858. */
  1859. int
  1860. qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
  1861. {
  1862. int rval;
  1863. mbx_cmd_t mc;
  1864. mbx_cmd_t *mcp = &mc;
  1865. char *pmap;
  1866. dma_addr_t pmap_dma;
  1867. pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
  1868. if (pmap == NULL) {
  1869. DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
  1870. __func__, ha->host_no));
  1871. return QLA_MEMORY_ALLOC_FAILED;
  1872. }
  1873. memset(pmap, 0, FCAL_MAP_SIZE);
  1874. mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
  1875. mcp->mb[2] = MSW(pmap_dma);
  1876. mcp->mb[3] = LSW(pmap_dma);
  1877. mcp->mb[6] = MSW(MSD(pmap_dma));
  1878. mcp->mb[7] = LSW(MSD(pmap_dma));
  1879. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1880. mcp->in_mb = MBX_1|MBX_0;
  1881. mcp->buf_size = FCAL_MAP_SIZE;
  1882. mcp->flags = MBX_DMA_IN;
  1883. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1884. rval = qla2x00_mailbox_command(ha, mcp);
  1885. if (rval == QLA_SUCCESS) {
  1886. DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
  1887. "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
  1888. mcp->mb[1], (unsigned)pmap[0]));
  1889. DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
  1890. if (pos_map)
  1891. memcpy(pos_map, pmap, FCAL_MAP_SIZE);
  1892. }
  1893. dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
  1894. if (rval != QLA_SUCCESS) {
  1895. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1896. ha->host_no, rval));
  1897. } else {
  1898. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1899. }
  1900. return rval;
  1901. }
  1902. uint8_t
  1903. qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
  1904. uint16_t *status)
  1905. {
  1906. int rval;
  1907. mbx_cmd_t mc;
  1908. mbx_cmd_t *mcp = &mc;
  1909. uint32_t *sbuf, *siter;
  1910. dma_addr_t sbuf_dma;
  1911. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1912. if (dwords > (DMA_POOL_SIZE / 4)) {
  1913. DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
  1914. "(max %d).\n", __func__, ha->host_no, dwords,
  1915. DMA_POOL_SIZE / 4));
  1916. return BIT_0;
  1917. }
  1918. sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
  1919. if (sbuf == NULL) {
  1920. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1921. __func__, ha->host_no));
  1922. return BIT_0;
  1923. }
  1924. memset(sbuf, 0, DMA_POOL_SIZE);
  1925. mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
  1926. mcp->mb[2] = MSW(sbuf_dma);
  1927. mcp->mb[3] = LSW(sbuf_dma);
  1928. mcp->mb[6] = MSW(MSD(sbuf_dma));
  1929. mcp->mb[7] = LSW(MSD(sbuf_dma));
  1930. mcp->mb[8] = dwords;
  1931. mcp->mb[10] = 0;
  1932. mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1933. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  1934. mcp->tov = 30;
  1935. mcp->flags = IOCTL_CMD;
  1936. rval = qla2x00_mailbox_command(ha, mcp);
  1937. if (rval == QLA_SUCCESS) {
  1938. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  1939. DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
  1940. __func__, ha->host_no, mcp->mb[0]));
  1941. status[0] = mcp->mb[0];
  1942. rval = BIT_1;
  1943. } else {
  1944. /* Copy over data -- firmware data is LE. */
  1945. siter = sbuf;
  1946. while (dwords--)
  1947. *dwbuf++ = le32_to_cpu(*siter++);
  1948. }
  1949. } else {
  1950. /* Failed. */
  1951. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1952. ha->host_no, rval));
  1953. rval = BIT_1;
  1954. }
  1955. dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
  1956. return rval;
  1957. }
  1958. #endif
  1959. int
  1960. qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
  1961. {
  1962. int rval;
  1963. fc_port_t *fcport;
  1964. unsigned long flags = 0;
  1965. struct abort_entry_24xx *abt;
  1966. dma_addr_t abt_dma;
  1967. uint32_t handle;
  1968. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1969. fcport = sp->fcport;
  1970. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  1971. atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  1972. return QLA_FUNCTION_FAILED;
  1973. }
  1974. spin_lock_irqsave(&ha->hardware_lock, flags);
  1975. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  1976. if (ha->outstanding_cmds[handle] == sp)
  1977. break;
  1978. }
  1979. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1980. if (handle == MAX_OUTSTANDING_COMMANDS) {
  1981. /* Command not found. */
  1982. return QLA_FUNCTION_FAILED;
  1983. }
  1984. abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
  1985. if (abt == NULL) {
  1986. DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
  1987. __func__, ha->host_no));
  1988. return QLA_MEMORY_ALLOC_FAILED;
  1989. }
  1990. memset(abt, 0, sizeof(struct abort_entry_24xx));
  1991. abt->entry_type = ABORT_IOCB_TYPE;
  1992. abt->entry_count = 1;
  1993. abt->nport_handle = cpu_to_le16(fcport->loop_id);
  1994. abt->handle_to_abort = handle;
  1995. abt->port_id[0] = fcport->d_id.b.al_pa;
  1996. abt->port_id[1] = fcport->d_id.b.area;
  1997. abt->port_id[2] = fcport->d_id.b.domain;
  1998. rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
  1999. if (rval != QLA_SUCCESS) {
  2000. DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
  2001. __func__, ha->host_no, rval);)
  2002. } else if (abt->entry_status != 0) {
  2003. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2004. "-- error status (%x).\n", __func__, ha->host_no,
  2005. abt->entry_status));
  2006. rval = QLA_FUNCTION_FAILED;
  2007. } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
  2008. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2009. "-- completion status (%x).\n", __func__, ha->host_no,
  2010. le16_to_cpu(abt->nport_handle));)
  2011. rval = QLA_FUNCTION_FAILED;
  2012. } else {
  2013. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  2014. sp->flags |= SRB_ABORT_PENDING;
  2015. }
  2016. dma_pool_free(ha->s_dma_pool, abt, abt_dma);
  2017. return rval;
  2018. }
  2019. struct tsk_mgmt_cmd {
  2020. union {
  2021. struct tsk_mgmt_entry tsk;
  2022. struct sts_entry_24xx sts;
  2023. } p;
  2024. };
  2025. int
  2026. qla24xx_abort_target(fc_port_t *fcport)
  2027. {
  2028. int rval;
  2029. struct tsk_mgmt_cmd *tsk;
  2030. dma_addr_t tsk_dma;
  2031. scsi_qla_host_t *ha;
  2032. if (fcport == NULL)
  2033. return 0;
  2034. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
  2035. ha = fcport->ha;
  2036. tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
  2037. if (tsk == NULL) {
  2038. DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
  2039. "IOCB.\n", __func__, ha->host_no));
  2040. return QLA_MEMORY_ALLOC_FAILED;
  2041. }
  2042. memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
  2043. tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
  2044. tsk->p.tsk.entry_count = 1;
  2045. tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
  2046. tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
  2047. tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
  2048. tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
  2049. tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
  2050. tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
  2051. rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
  2052. if (rval != QLA_SUCCESS) {
  2053. DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
  2054. "(%x).\n", __func__, ha->host_no, rval);)
  2055. goto atarget_done;
  2056. } else if (tsk->p.sts.entry_status != 0) {
  2057. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2058. "-- error status (%x).\n", __func__, ha->host_no,
  2059. tsk->p.sts.entry_status));
  2060. rval = QLA_FUNCTION_FAILED;
  2061. goto atarget_done;
  2062. } else if (tsk->p.sts.comp_status !=
  2063. __constant_cpu_to_le16(CS_COMPLETE)) {
  2064. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2065. "-- completion status (%x).\n", __func__,
  2066. ha->host_no, le16_to_cpu(tsk->p.sts.comp_status));)
  2067. rval = QLA_FUNCTION_FAILED;
  2068. goto atarget_done;
  2069. }
  2070. /* Issue marker IOCB. */
  2071. rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
  2072. if (rval != QLA_SUCCESS) {
  2073. DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
  2074. "(%x).\n", __func__, ha->host_no, rval);)
  2075. } else {
  2076. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  2077. }
  2078. atarget_done:
  2079. dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
  2080. return rval;
  2081. }
  2082. int
  2083. qla2x00_system_error(scsi_qla_host_t *ha)
  2084. {
  2085. int rval;
  2086. mbx_cmd_t mc;
  2087. mbx_cmd_t *mcp = &mc;
  2088. if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
  2089. return QLA_FUNCTION_FAILED;
  2090. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2091. mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
  2092. mcp->out_mb = MBX_0;
  2093. mcp->in_mb = MBX_0;
  2094. mcp->tov = 5;
  2095. mcp->flags = 0;
  2096. rval = qla2x00_mailbox_command(ha, mcp);
  2097. if (rval != QLA_SUCCESS) {
  2098. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2099. ha->host_no, rval));
  2100. } else {
  2101. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2102. }
  2103. return rval;
  2104. }
  2105. /**
  2106. * qla2x00_get_serdes_params() -
  2107. * @ha: HA context
  2108. *
  2109. * Returns
  2110. */
  2111. int
  2112. qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
  2113. uint16_t *sw_em_2g, uint16_t *sw_em_4g)
  2114. {
  2115. int rval;
  2116. mbx_cmd_t mc;
  2117. mbx_cmd_t *mcp = &mc;
  2118. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2119. mcp->mb[0] = MBC_SERDES_PARAMS;
  2120. mcp->mb[1] = 0;
  2121. mcp->out_mb = MBX_1|MBX_0;
  2122. mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
  2123. mcp->tov = 30;
  2124. mcp->flags = 0;
  2125. rval = qla2x00_mailbox_command(ha, mcp);
  2126. if (rval != QLA_SUCCESS) {
  2127. /*EMPTY*/
  2128. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2129. ha->host_no, rval, mcp->mb[0]));
  2130. } else {
  2131. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2132. if (sw_em_1g)
  2133. *sw_em_1g = mcp->mb[2];
  2134. if (sw_em_2g)
  2135. *sw_em_2g = mcp->mb[3];
  2136. if (sw_em_4g)
  2137. *sw_em_4g = mcp->mb[4];
  2138. }
  2139. return rval;
  2140. }
  2141. /**
  2142. * qla2x00_set_serdes_params() -
  2143. * @ha: HA context
  2144. *
  2145. * Returns
  2146. */
  2147. int
  2148. qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
  2149. uint16_t sw_em_2g, uint16_t sw_em_4g)
  2150. {
  2151. int rval;
  2152. mbx_cmd_t mc;
  2153. mbx_cmd_t *mcp = &mc;
  2154. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2155. mcp->mb[0] = MBC_SERDES_PARAMS;
  2156. mcp->mb[1] = BIT_0;
  2157. mcp->mb[2] = sw_em_1g;
  2158. mcp->mb[3] = sw_em_2g;
  2159. mcp->mb[4] = sw_em_4g;
  2160. mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2161. mcp->in_mb = MBX_0;
  2162. mcp->tov = 30;
  2163. mcp->flags = 0;
  2164. rval = qla2x00_mailbox_command(ha, mcp);
  2165. if (rval != QLA_SUCCESS) {
  2166. /*EMPTY*/
  2167. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2168. ha->host_no, rval, mcp->mb[0]));
  2169. } else {
  2170. /*EMPTY*/
  2171. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2172. }
  2173. return rval;
  2174. }