qla_mbx.c 60 KB

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