qla_mbx.c 59 KB

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