qla_mbx.c 59 KB

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