qla_mbx.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440
  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. msleep(10);
  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. spin_lock_irqsave(&ha->hardware_lock, flags);
  759. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  760. if (ha->outstanding_cmds[handle] == sp)
  761. break;
  762. }
  763. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  764. if (handle == MAX_OUTSTANDING_COMMANDS) {
  765. /* command not found */
  766. return QLA_FUNCTION_FAILED;
  767. }
  768. mcp->mb[0] = MBC_ABORT_COMMAND;
  769. if (HAS_EXTENDED_IDS(ha))
  770. mcp->mb[1] = fcport->loop_id;
  771. else
  772. mcp->mb[1] = fcport->loop_id << 8;
  773. mcp->mb[2] = (uint16_t)handle;
  774. mcp->mb[3] = (uint16_t)(handle >> 16);
  775. mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
  776. mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  777. mcp->in_mb = MBX_0;
  778. mcp->tov = 30;
  779. mcp->flags = 0;
  780. rval = qla2x00_mailbox_command(ha, mcp);
  781. if (rval != QLA_SUCCESS) {
  782. DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
  783. ha->host_no, rval);)
  784. } else {
  785. sp->flags |= SRB_ABORT_PENDING;
  786. DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
  787. ha->host_no);)
  788. }
  789. return rval;
  790. }
  791. #if USE_ABORT_TGT
  792. /*
  793. * qla2x00_abort_target
  794. * Issue abort target mailbox command.
  795. *
  796. * Input:
  797. * ha = adapter block pointer.
  798. *
  799. * Returns:
  800. * qla2x00 local function return status code.
  801. *
  802. * Context:
  803. * Kernel context.
  804. */
  805. int
  806. qla2x00_abort_target(fc_port_t *fcport)
  807. {
  808. int rval;
  809. mbx_cmd_t mc;
  810. mbx_cmd_t *mcp = &mc;
  811. scsi_qla_host_t *ha;
  812. if (fcport == NULL)
  813. return 0;
  814. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
  815. ha = fcport->ha;
  816. mcp->mb[0] = MBC_ABORT_TARGET;
  817. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  818. if (HAS_EXTENDED_IDS(ha)) {
  819. mcp->mb[1] = fcport->loop_id;
  820. mcp->mb[10] = 0;
  821. mcp->out_mb |= MBX_10;
  822. } else {
  823. mcp->mb[1] = fcport->loop_id << 8;
  824. }
  825. mcp->mb[2] = ha->loop_reset_delay;
  826. mcp->in_mb = MBX_0;
  827. mcp->tov = 30;
  828. mcp->flags = 0;
  829. rval = qla2x00_mailbox_command(ha, mcp);
  830. /* Issue marker command. */
  831. ha->marker_needed = 1;
  832. if (rval != QLA_SUCCESS) {
  833. DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
  834. ha->host_no, rval);)
  835. } else {
  836. /*EMPTY*/
  837. DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
  838. ha->host_no);)
  839. }
  840. return rval;
  841. }
  842. #endif
  843. /*
  844. * qla2x00_get_adapter_id
  845. * Get adapter ID and topology.
  846. *
  847. * Input:
  848. * ha = adapter block pointer.
  849. * id = pointer for loop ID.
  850. * al_pa = pointer for AL_PA.
  851. * area = pointer for area.
  852. * domain = pointer for domain.
  853. * top = pointer for topology.
  854. * TARGET_QUEUE_LOCK must be released.
  855. * ADAPTER_STATE_LOCK must be released.
  856. *
  857. * Returns:
  858. * qla2x00 local function return status code.
  859. *
  860. * Context:
  861. * Kernel context.
  862. */
  863. int
  864. qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
  865. uint8_t *area, uint8_t *domain, uint16_t *top)
  866. {
  867. int rval;
  868. mbx_cmd_t mc;
  869. mbx_cmd_t *mcp = &mc;
  870. DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
  871. ha->host_no);)
  872. mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
  873. mcp->out_mb = MBX_0;
  874. mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  875. mcp->tov = 30;
  876. mcp->flags = 0;
  877. rval = qla2x00_mailbox_command(ha, mcp);
  878. if (mcp->mb[0] == MBS_COMMAND_ERROR)
  879. rval = QLA_COMMAND_ERROR;
  880. /* Return data. */
  881. *id = mcp->mb[1];
  882. *al_pa = LSB(mcp->mb[2]);
  883. *area = MSB(mcp->mb[2]);
  884. *domain = LSB(mcp->mb[3]);
  885. *top = mcp->mb[6];
  886. if (rval != QLA_SUCCESS) {
  887. /*EMPTY*/
  888. DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
  889. ha->host_no, rval);)
  890. } else {
  891. /*EMPTY*/
  892. DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
  893. ha->host_no);)
  894. }
  895. return rval;
  896. }
  897. /*
  898. * qla2x00_get_retry_cnt
  899. * Get current firmware login retry count and delay.
  900. *
  901. * Input:
  902. * ha = adapter block pointer.
  903. * retry_cnt = pointer to login retry count.
  904. * tov = pointer to login timeout value.
  905. *
  906. * Returns:
  907. * qla2x00 local function return status code.
  908. *
  909. * Context:
  910. * Kernel context.
  911. */
  912. int
  913. qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
  914. uint16_t *r_a_tov)
  915. {
  916. int rval;
  917. uint16_t ratov;
  918. mbx_cmd_t mc;
  919. mbx_cmd_t *mcp = &mc;
  920. DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
  921. ha->host_no);)
  922. mcp->mb[0] = MBC_GET_RETRY_COUNT;
  923. mcp->out_mb = MBX_0;
  924. mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  925. mcp->tov = 30;
  926. mcp->flags = 0;
  927. rval = qla2x00_mailbox_command(ha, mcp);
  928. if (rval != QLA_SUCCESS) {
  929. /*EMPTY*/
  930. DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
  931. ha->host_no, mcp->mb[0]);)
  932. } else {
  933. /* Convert returned data and check our values. */
  934. *r_a_tov = mcp->mb[3] / 2;
  935. ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
  936. if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
  937. /* Update to the larger values */
  938. *retry_cnt = (uint8_t)mcp->mb[1];
  939. *tov = ratov;
  940. }
  941. DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
  942. "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
  943. }
  944. return rval;
  945. }
  946. /*
  947. * qla2x00_init_firmware
  948. * Initialize adapter firmware.
  949. *
  950. * Input:
  951. * ha = adapter block pointer.
  952. * dptr = Initialization control block pointer.
  953. * size = size of initialization control block.
  954. * TARGET_QUEUE_LOCK must be released.
  955. * ADAPTER_STATE_LOCK must be released.
  956. *
  957. * Returns:
  958. * qla2x00 local function return status code.
  959. *
  960. * Context:
  961. * Kernel context.
  962. */
  963. int
  964. qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
  965. {
  966. int rval;
  967. mbx_cmd_t mc;
  968. mbx_cmd_t *mcp = &mc;
  969. DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
  970. ha->host_no);)
  971. mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
  972. mcp->mb[2] = MSW(ha->init_cb_dma);
  973. mcp->mb[3] = LSW(ha->init_cb_dma);
  974. mcp->mb[4] = 0;
  975. mcp->mb[5] = 0;
  976. mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
  977. mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
  978. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  979. mcp->in_mb = MBX_5|MBX_4|MBX_0;
  980. mcp->buf_size = size;
  981. mcp->flags = MBX_DMA_OUT;
  982. mcp->tov = 30;
  983. rval = qla2x00_mailbox_command(ha, mcp);
  984. if (rval != QLA_SUCCESS) {
  985. /*EMPTY*/
  986. DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
  987. "mb0=%x.\n",
  988. ha->host_no, rval, mcp->mb[0]);)
  989. } else {
  990. /*EMPTY*/
  991. DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
  992. ha->host_no);)
  993. }
  994. return rval;
  995. }
  996. /*
  997. * qla2x00_get_port_database
  998. * Issue normal/enhanced get port database mailbox command
  999. * and copy device name as necessary.
  1000. *
  1001. * Input:
  1002. * ha = adapter state pointer.
  1003. * dev = structure pointer.
  1004. * opt = enhanced cmd option byte.
  1005. *
  1006. * Returns:
  1007. * qla2x00 local function return status code.
  1008. *
  1009. * Context:
  1010. * Kernel context.
  1011. */
  1012. int
  1013. qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
  1014. {
  1015. int rval;
  1016. mbx_cmd_t mc;
  1017. mbx_cmd_t *mcp = &mc;
  1018. port_database_t *pd;
  1019. struct port_database_24xx *pd24;
  1020. dma_addr_t pd_dma;
  1021. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1022. pd24 = NULL;
  1023. pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
  1024. if (pd == NULL) {
  1025. DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
  1026. "structure.\n", __func__, ha->host_no));
  1027. return QLA_MEMORY_ALLOC_FAILED;
  1028. }
  1029. memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
  1030. mcp->mb[0] = MBC_GET_PORT_DATABASE;
  1031. if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA25XX(ha))
  1032. mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
  1033. mcp->mb[2] = MSW(pd_dma);
  1034. mcp->mb[3] = LSW(pd_dma);
  1035. mcp->mb[6] = MSW(MSD(pd_dma));
  1036. mcp->mb[7] = LSW(MSD(pd_dma));
  1037. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1038. mcp->in_mb = MBX_0;
  1039. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1040. mcp->mb[1] = fcport->loop_id;
  1041. mcp->mb[10] = opt;
  1042. mcp->out_mb |= MBX_10|MBX_1;
  1043. mcp->in_mb |= MBX_1;
  1044. } else if (HAS_EXTENDED_IDS(ha)) {
  1045. mcp->mb[1] = fcport->loop_id;
  1046. mcp->mb[10] = opt;
  1047. mcp->out_mb |= MBX_10|MBX_1;
  1048. } else {
  1049. mcp->mb[1] = fcport->loop_id << 8 | opt;
  1050. mcp->out_mb |= MBX_1;
  1051. }
  1052. mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
  1053. PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
  1054. mcp->flags = MBX_DMA_IN;
  1055. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1056. rval = qla2x00_mailbox_command(ha, mcp);
  1057. if (rval != QLA_SUCCESS)
  1058. goto gpd_error_out;
  1059. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1060. pd24 = (struct port_database_24xx *) pd;
  1061. /* Check for logged in state. */
  1062. if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
  1063. pd24->last_login_state != PDS_PRLI_COMPLETE) {
  1064. DEBUG2(printk("%s(%ld): Unable to verify "
  1065. "login-state (%x/%x) for loop_id %x\n",
  1066. __func__, ha->host_no,
  1067. pd24->current_login_state,
  1068. pd24->last_login_state, fcport->loop_id));
  1069. rval = QLA_FUNCTION_FAILED;
  1070. goto gpd_error_out;
  1071. }
  1072. /* Names are little-endian. */
  1073. memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
  1074. memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
  1075. /* Get port_id of device. */
  1076. fcport->d_id.b.domain = pd24->port_id[0];
  1077. fcport->d_id.b.area = pd24->port_id[1];
  1078. fcport->d_id.b.al_pa = pd24->port_id[2];
  1079. fcport->d_id.b.rsvd_1 = 0;
  1080. /* If not target must be initiator or unknown type. */
  1081. if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
  1082. fcport->port_type = FCT_INITIATOR;
  1083. else
  1084. fcport->port_type = FCT_TARGET;
  1085. } else {
  1086. /* Check for logged in state. */
  1087. if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
  1088. pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
  1089. rval = QLA_FUNCTION_FAILED;
  1090. goto gpd_error_out;
  1091. }
  1092. /* Names are little-endian. */
  1093. memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
  1094. memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
  1095. /* Get port_id of device. */
  1096. fcport->d_id.b.domain = pd->port_id[0];
  1097. fcport->d_id.b.area = pd->port_id[3];
  1098. fcport->d_id.b.al_pa = pd->port_id[2];
  1099. fcport->d_id.b.rsvd_1 = 0;
  1100. /* Check for device require authentication. */
  1101. pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
  1102. (fcport->flags &= ~FCF_AUTH_REQ);
  1103. /* If not target must be initiator or unknown type. */
  1104. if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
  1105. fcport->port_type = FCT_INITIATOR;
  1106. else
  1107. fcport->port_type = FCT_TARGET;
  1108. /* Passback COS information. */
  1109. fcport->supported_classes = (pd->options & BIT_4) ?
  1110. FC_COS_CLASS2: FC_COS_CLASS3;
  1111. }
  1112. gpd_error_out:
  1113. dma_pool_free(ha->s_dma_pool, pd, pd_dma);
  1114. if (rval != QLA_SUCCESS) {
  1115. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  1116. __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1117. } else {
  1118. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1119. }
  1120. return rval;
  1121. }
  1122. /*
  1123. * qla2x00_get_firmware_state
  1124. * Get adapter firmware state.
  1125. *
  1126. * Input:
  1127. * ha = adapter block pointer.
  1128. * dptr = pointer for firmware state.
  1129. * TARGET_QUEUE_LOCK must be released.
  1130. * ADAPTER_STATE_LOCK must be released.
  1131. *
  1132. * Returns:
  1133. * qla2x00 local function return status code.
  1134. *
  1135. * Context:
  1136. * Kernel context.
  1137. */
  1138. int
  1139. qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
  1140. {
  1141. int rval;
  1142. mbx_cmd_t mc;
  1143. mbx_cmd_t *mcp = &mc;
  1144. DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
  1145. ha->host_no);)
  1146. mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
  1147. mcp->out_mb = MBX_0;
  1148. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  1149. mcp->tov = 30;
  1150. mcp->flags = 0;
  1151. rval = qla2x00_mailbox_command(ha, mcp);
  1152. /* Return firmware state. */
  1153. *dptr = mcp->mb[1];
  1154. if (rval != QLA_SUCCESS) {
  1155. /*EMPTY*/
  1156. DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
  1157. "failed=%x.\n", ha->host_no, rval);)
  1158. } else {
  1159. /*EMPTY*/
  1160. DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
  1161. ha->host_no);)
  1162. }
  1163. return rval;
  1164. }
  1165. /*
  1166. * qla2x00_get_port_name
  1167. * Issue get port name mailbox command.
  1168. * Returned name is in big endian format.
  1169. *
  1170. * Input:
  1171. * ha = adapter block pointer.
  1172. * loop_id = loop ID of device.
  1173. * name = pointer for name.
  1174. * TARGET_QUEUE_LOCK must be released.
  1175. * ADAPTER_STATE_LOCK must be released.
  1176. *
  1177. * Returns:
  1178. * qla2x00 local function return status code.
  1179. *
  1180. * Context:
  1181. * Kernel context.
  1182. */
  1183. int
  1184. qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
  1185. uint8_t opt)
  1186. {
  1187. int rval;
  1188. mbx_cmd_t mc;
  1189. mbx_cmd_t *mcp = &mc;
  1190. DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
  1191. ha->host_no);)
  1192. mcp->mb[0] = MBC_GET_PORT_NAME;
  1193. mcp->out_mb = MBX_1|MBX_0;
  1194. if (HAS_EXTENDED_IDS(ha)) {
  1195. mcp->mb[1] = loop_id;
  1196. mcp->mb[10] = opt;
  1197. mcp->out_mb |= MBX_10;
  1198. } else {
  1199. mcp->mb[1] = loop_id << 8 | opt;
  1200. }
  1201. mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1202. mcp->tov = 30;
  1203. mcp->flags = 0;
  1204. rval = qla2x00_mailbox_command(ha, mcp);
  1205. if (rval != QLA_SUCCESS) {
  1206. /*EMPTY*/
  1207. DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
  1208. ha->host_no, rval);)
  1209. } else {
  1210. if (name != NULL) {
  1211. /* This function returns name in big endian. */
  1212. name[0] = LSB(mcp->mb[2]);
  1213. name[1] = MSB(mcp->mb[2]);
  1214. name[2] = LSB(mcp->mb[3]);
  1215. name[3] = MSB(mcp->mb[3]);
  1216. name[4] = LSB(mcp->mb[6]);
  1217. name[5] = MSB(mcp->mb[6]);
  1218. name[6] = LSB(mcp->mb[7]);
  1219. name[7] = MSB(mcp->mb[7]);
  1220. }
  1221. DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
  1222. ha->host_no);)
  1223. }
  1224. return rval;
  1225. }
  1226. /*
  1227. * qla2x00_lip_reset
  1228. * Issue LIP reset mailbox command.
  1229. *
  1230. * Input:
  1231. * ha = adapter block pointer.
  1232. * TARGET_QUEUE_LOCK must be released.
  1233. * ADAPTER_STATE_LOCK must be released.
  1234. *
  1235. * Returns:
  1236. * qla2x00 local function return status code.
  1237. *
  1238. * Context:
  1239. * Kernel context.
  1240. */
  1241. int
  1242. qla2x00_lip_reset(scsi_qla_host_t *ha)
  1243. {
  1244. int rval;
  1245. mbx_cmd_t mc;
  1246. mbx_cmd_t *mcp = &mc;
  1247. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1248. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1249. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1250. mcp->mb[1] = BIT_0;
  1251. mcp->mb[2] = 0xff;
  1252. mcp->mb[3] = 0;
  1253. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1254. } else {
  1255. mcp->mb[0] = MBC_LIP_RESET;
  1256. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1257. if (HAS_EXTENDED_IDS(ha)) {
  1258. mcp->mb[1] = 0x00ff;
  1259. mcp->mb[10] = 0;
  1260. mcp->out_mb |= MBX_10;
  1261. } else {
  1262. mcp->mb[1] = 0xff00;
  1263. }
  1264. mcp->mb[2] = ha->loop_reset_delay;
  1265. mcp->mb[3] = 0;
  1266. }
  1267. mcp->in_mb = MBX_0;
  1268. mcp->tov = 30;
  1269. mcp->flags = 0;
  1270. rval = qla2x00_mailbox_command(ha, mcp);
  1271. if (rval != QLA_SUCCESS) {
  1272. /*EMPTY*/
  1273. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
  1274. __func__, ha->host_no, rval);)
  1275. } else {
  1276. /*EMPTY*/
  1277. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1278. }
  1279. return rval;
  1280. }
  1281. /*
  1282. * qla2x00_send_sns
  1283. * Send SNS command.
  1284. *
  1285. * Input:
  1286. * ha = adapter block pointer.
  1287. * sns = pointer for command.
  1288. * cmd_size = command size.
  1289. * buf_size = response/command size.
  1290. * TARGET_QUEUE_LOCK must be released.
  1291. * ADAPTER_STATE_LOCK must be released.
  1292. *
  1293. * Returns:
  1294. * qla2x00 local function return status code.
  1295. *
  1296. * Context:
  1297. * Kernel context.
  1298. */
  1299. int
  1300. qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
  1301. uint16_t cmd_size, size_t buf_size)
  1302. {
  1303. int rval;
  1304. mbx_cmd_t mc;
  1305. mbx_cmd_t *mcp = &mc;
  1306. DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
  1307. ha->host_no);)
  1308. DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
  1309. "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
  1310. mcp->mb[0] = MBC_SEND_SNS_COMMAND;
  1311. mcp->mb[1] = cmd_size;
  1312. mcp->mb[2] = MSW(sns_phys_address);
  1313. mcp->mb[3] = LSW(sns_phys_address);
  1314. mcp->mb[6] = MSW(MSD(sns_phys_address));
  1315. mcp->mb[7] = LSW(MSD(sns_phys_address));
  1316. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1317. mcp->in_mb = MBX_0|MBX_1;
  1318. mcp->buf_size = buf_size;
  1319. mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
  1320. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1321. rval = qla2x00_mailbox_command(ha, mcp);
  1322. if (rval != QLA_SUCCESS) {
  1323. /*EMPTY*/
  1324. DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1325. "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
  1326. DEBUG2_3_11(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. } else {
  1329. /*EMPTY*/
  1330. DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
  1331. }
  1332. return rval;
  1333. }
  1334. int
  1335. qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1336. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1337. {
  1338. int rval;
  1339. struct logio_entry_24xx *lg;
  1340. dma_addr_t lg_dma;
  1341. uint32_t iop[2];
  1342. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1343. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1344. if (lg == NULL) {
  1345. DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
  1346. __func__, ha->host_no));
  1347. return QLA_MEMORY_ALLOC_FAILED;
  1348. }
  1349. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1350. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1351. lg->entry_count = 1;
  1352. lg->nport_handle = cpu_to_le16(loop_id);
  1353. lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
  1354. if (opt & BIT_0)
  1355. lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
  1356. lg->port_id[0] = al_pa;
  1357. lg->port_id[1] = area;
  1358. lg->port_id[2] = domain;
  1359. rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
  1360. if (rval != QLA_SUCCESS) {
  1361. DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
  1362. "(%x).\n", __func__, ha->host_no, rval);)
  1363. } else if (lg->entry_status != 0) {
  1364. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1365. "-- error status (%x).\n", __func__, ha->host_no,
  1366. lg->entry_status));
  1367. rval = QLA_FUNCTION_FAILED;
  1368. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1369. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1370. iop[1] = le32_to_cpu(lg->io_parameter[1]);
  1371. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1372. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1373. ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
  1374. iop[1]));
  1375. switch (iop[0]) {
  1376. case LSC_SCODE_PORTID_USED:
  1377. mb[0] = MBS_PORT_ID_USED;
  1378. mb[1] = LSW(iop[1]);
  1379. break;
  1380. case LSC_SCODE_NPORT_USED:
  1381. mb[0] = MBS_LOOP_ID_USED;
  1382. break;
  1383. case LSC_SCODE_NOLINK:
  1384. case LSC_SCODE_NOIOCB:
  1385. case LSC_SCODE_NOXCB:
  1386. case LSC_SCODE_CMD_FAILED:
  1387. case LSC_SCODE_NOFABRIC:
  1388. case LSC_SCODE_FW_NOT_READY:
  1389. case LSC_SCODE_NOT_LOGGED_IN:
  1390. case LSC_SCODE_NOPCB:
  1391. case LSC_SCODE_ELS_REJECT:
  1392. case LSC_SCODE_CMD_PARAM_ERR:
  1393. case LSC_SCODE_NONPORT:
  1394. case LSC_SCODE_LOGGED_IN:
  1395. case LSC_SCODE_NOFLOGI_ACC:
  1396. default:
  1397. mb[0] = MBS_COMMAND_ERROR;
  1398. break;
  1399. }
  1400. } else {
  1401. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1402. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1403. mb[0] = MBS_COMMAND_COMPLETE;
  1404. mb[1] = 0;
  1405. if (iop[0] & BIT_4) {
  1406. if (iop[0] & BIT_8)
  1407. mb[1] |= BIT_1;
  1408. } else
  1409. mb[1] = BIT_0;
  1410. /* Passback COS information. */
  1411. mb[10] = 0;
  1412. if (lg->io_parameter[7] || lg->io_parameter[8])
  1413. mb[10] |= BIT_0; /* Class 2. */
  1414. if (lg->io_parameter[9] || lg->io_parameter[10])
  1415. mb[10] |= BIT_1; /* Class 3. */
  1416. }
  1417. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1418. return rval;
  1419. }
  1420. /*
  1421. * qla2x00_login_fabric
  1422. * Issue login fabric port mailbox command.
  1423. *
  1424. * Input:
  1425. * ha = adapter block pointer.
  1426. * loop_id = device loop ID.
  1427. * domain = device domain.
  1428. * area = device area.
  1429. * al_pa = device AL_PA.
  1430. * status = pointer for return status.
  1431. * opt = command options.
  1432. * TARGET_QUEUE_LOCK must be released.
  1433. * ADAPTER_STATE_LOCK must be released.
  1434. *
  1435. * Returns:
  1436. * qla2x00 local function return status code.
  1437. *
  1438. * Context:
  1439. * Kernel context.
  1440. */
  1441. int
  1442. qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1443. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1444. {
  1445. int rval;
  1446. mbx_cmd_t mc;
  1447. mbx_cmd_t *mcp = &mc;
  1448. DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);)
  1449. mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
  1450. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1451. if (HAS_EXTENDED_IDS(ha)) {
  1452. mcp->mb[1] = loop_id;
  1453. mcp->mb[10] = opt;
  1454. mcp->out_mb |= MBX_10;
  1455. } else {
  1456. mcp->mb[1] = (loop_id << 8) | opt;
  1457. }
  1458. mcp->mb[2] = domain;
  1459. mcp->mb[3] = area << 8 | al_pa;
  1460. mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
  1461. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1462. mcp->flags = 0;
  1463. rval = qla2x00_mailbox_command(ha, mcp);
  1464. /* Return mailbox statuses. */
  1465. if (mb != NULL) {
  1466. mb[0] = mcp->mb[0];
  1467. mb[1] = mcp->mb[1];
  1468. mb[2] = mcp->mb[2];
  1469. mb[6] = mcp->mb[6];
  1470. mb[7] = mcp->mb[7];
  1471. /* COS retrieved from Get-Port-Database mailbox command. */
  1472. mb[10] = 0;
  1473. }
  1474. if (rval != QLA_SUCCESS) {
  1475. /* RLU tmp code: need to change main mailbox_command function to
  1476. * return ok even when the mailbox completion value is not
  1477. * SUCCESS. The caller needs to be responsible to interpret
  1478. * the return values of this mailbox command if we're not
  1479. * to change too much of the existing code.
  1480. */
  1481. if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
  1482. mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
  1483. mcp->mb[0] == 0x4006)
  1484. rval = QLA_SUCCESS;
  1485. /*EMPTY*/
  1486. DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
  1487. "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
  1488. mcp->mb[0], mcp->mb[1], mcp->mb[2]);)
  1489. } else {
  1490. /*EMPTY*/
  1491. DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
  1492. ha->host_no);)
  1493. }
  1494. return rval;
  1495. }
  1496. /*
  1497. * qla2x00_login_local_device
  1498. * Issue login loop port mailbox command.
  1499. *
  1500. * Input:
  1501. * ha = adapter block pointer.
  1502. * loop_id = device loop ID.
  1503. * opt = command options.
  1504. *
  1505. * Returns:
  1506. * Return status code.
  1507. *
  1508. * Context:
  1509. * Kernel context.
  1510. *
  1511. */
  1512. int
  1513. qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
  1514. uint16_t *mb_ret, uint8_t opt)
  1515. {
  1516. int rval;
  1517. mbx_cmd_t mc;
  1518. mbx_cmd_t *mcp = &mc;
  1519. DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1520. mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
  1521. if (HAS_EXTENDED_IDS(ha))
  1522. mcp->mb[1] = loop_id;
  1523. else
  1524. mcp->mb[1] = loop_id << 8;
  1525. mcp->mb[2] = opt;
  1526. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  1527. mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
  1528. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1529. mcp->flags = 0;
  1530. rval = qla2x00_mailbox_command(ha, mcp);
  1531. /* Return mailbox statuses. */
  1532. if (mb_ret != NULL) {
  1533. mb_ret[0] = mcp->mb[0];
  1534. mb_ret[1] = mcp->mb[1];
  1535. mb_ret[6] = mcp->mb[6];
  1536. mb_ret[7] = mcp->mb[7];
  1537. }
  1538. if (rval != QLA_SUCCESS) {
  1539. /* AV tmp code: need to change main mailbox_command function to
  1540. * return ok even when the mailbox completion value is not
  1541. * SUCCESS. The caller needs to be responsible to interpret
  1542. * the return values of this mailbox command if we're not
  1543. * to change too much of the existing code.
  1544. */
  1545. if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
  1546. rval = QLA_SUCCESS;
  1547. DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1548. "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
  1549. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
  1550. DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1551. "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
  1552. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
  1553. } else {
  1554. /*EMPTY*/
  1555. DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1556. }
  1557. return (rval);
  1558. }
  1559. int
  1560. qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1561. uint8_t area, uint8_t al_pa)
  1562. {
  1563. int rval;
  1564. struct logio_entry_24xx *lg;
  1565. dma_addr_t lg_dma;
  1566. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1567. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1568. if (lg == NULL) {
  1569. DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
  1570. __func__, ha->host_no));
  1571. return QLA_MEMORY_ALLOC_FAILED;
  1572. }
  1573. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1574. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1575. lg->entry_count = 1;
  1576. lg->nport_handle = cpu_to_le16(loop_id);
  1577. lg->control_flags =
  1578. __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_EXPL_LOGO);
  1579. lg->port_id[0] = al_pa;
  1580. lg->port_id[1] = area;
  1581. lg->port_id[2] = domain;
  1582. rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
  1583. if (rval != QLA_SUCCESS) {
  1584. DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
  1585. "(%x).\n", __func__, ha->host_no, rval);)
  1586. } else if (lg->entry_status != 0) {
  1587. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1588. "-- error status (%x).\n", __func__, ha->host_no,
  1589. lg->entry_status));
  1590. rval = QLA_FUNCTION_FAILED;
  1591. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1592. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1593. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1594. ha->host_no, le16_to_cpu(lg->comp_status),
  1595. le32_to_cpu(lg->io_parameter[0]),
  1596. le32_to_cpu(lg->io_parameter[1]));)
  1597. } else {
  1598. /*EMPTY*/
  1599. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1600. }
  1601. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1602. return rval;
  1603. }
  1604. /*
  1605. * qla2x00_fabric_logout
  1606. * Issue logout fabric port mailbox command.
  1607. *
  1608. * Input:
  1609. * ha = adapter block pointer.
  1610. * loop_id = device loop ID.
  1611. * TARGET_QUEUE_LOCK must be released.
  1612. * ADAPTER_STATE_LOCK must be released.
  1613. *
  1614. * Returns:
  1615. * qla2x00 local function return status code.
  1616. *
  1617. * Context:
  1618. * Kernel context.
  1619. */
  1620. int
  1621. qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1622. uint8_t area, uint8_t al_pa)
  1623. {
  1624. int rval;
  1625. mbx_cmd_t mc;
  1626. mbx_cmd_t *mcp = &mc;
  1627. DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
  1628. ha->host_no);)
  1629. mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
  1630. mcp->out_mb = MBX_1|MBX_0;
  1631. if (HAS_EXTENDED_IDS(ha)) {
  1632. mcp->mb[1] = loop_id;
  1633. mcp->mb[10] = 0;
  1634. mcp->out_mb |= MBX_10;
  1635. } else {
  1636. mcp->mb[1] = loop_id << 8;
  1637. }
  1638. mcp->in_mb = MBX_1|MBX_0;
  1639. mcp->tov = 30;
  1640. mcp->flags = 0;
  1641. rval = qla2x00_mailbox_command(ha, mcp);
  1642. if (rval != QLA_SUCCESS) {
  1643. /*EMPTY*/
  1644. DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
  1645. "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
  1646. } else {
  1647. /*EMPTY*/
  1648. DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
  1649. ha->host_no);)
  1650. }
  1651. return rval;
  1652. }
  1653. /*
  1654. * qla2x00_full_login_lip
  1655. * Issue full login LIP mailbox command.
  1656. *
  1657. * Input:
  1658. * ha = adapter block pointer.
  1659. * TARGET_QUEUE_LOCK must be released.
  1660. * ADAPTER_STATE_LOCK must be released.
  1661. *
  1662. * Returns:
  1663. * qla2x00 local function return status code.
  1664. *
  1665. * Context:
  1666. * Kernel context.
  1667. */
  1668. int
  1669. qla2x00_full_login_lip(scsi_qla_host_t *ha)
  1670. {
  1671. int rval;
  1672. mbx_cmd_t mc;
  1673. mbx_cmd_t *mcp = &mc;
  1674. DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
  1675. ha->host_no);)
  1676. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1677. mcp->mb[1] = 0;
  1678. mcp->mb[2] = 0xff;
  1679. mcp->mb[3] = 0;
  1680. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1681. mcp->in_mb = MBX_0;
  1682. mcp->tov = 30;
  1683. mcp->flags = 0;
  1684. rval = qla2x00_mailbox_command(ha, mcp);
  1685. if (rval != QLA_SUCCESS) {
  1686. /*EMPTY*/
  1687. DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
  1688. ha->host_no, rval);)
  1689. } else {
  1690. /*EMPTY*/
  1691. DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
  1692. ha->host_no);)
  1693. }
  1694. return rval;
  1695. }
  1696. /*
  1697. * qla2x00_get_id_list
  1698. *
  1699. * Input:
  1700. * ha = adapter block pointer.
  1701. *
  1702. * Returns:
  1703. * qla2x00 local function return status code.
  1704. *
  1705. * Context:
  1706. * Kernel context.
  1707. */
  1708. int
  1709. qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
  1710. uint16_t *entries)
  1711. {
  1712. int rval;
  1713. mbx_cmd_t mc;
  1714. mbx_cmd_t *mcp = &mc;
  1715. DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
  1716. ha->host_no);)
  1717. if (id_list == NULL)
  1718. return QLA_FUNCTION_FAILED;
  1719. mcp->mb[0] = MBC_GET_ID_LIST;
  1720. mcp->out_mb = MBX_0;
  1721. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  1722. mcp->mb[2] = MSW(id_list_dma);
  1723. mcp->mb[3] = LSW(id_list_dma);
  1724. mcp->mb[6] = MSW(MSD(id_list_dma));
  1725. mcp->mb[7] = LSW(MSD(id_list_dma));
  1726. mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2;
  1727. } else {
  1728. mcp->mb[1] = MSW(id_list_dma);
  1729. mcp->mb[2] = LSW(id_list_dma);
  1730. mcp->mb[3] = MSW(MSD(id_list_dma));
  1731. mcp->mb[6] = LSW(MSD(id_list_dma));
  1732. mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
  1733. }
  1734. mcp->in_mb = MBX_1|MBX_0;
  1735. mcp->tov = 30;
  1736. mcp->flags = 0;
  1737. rval = qla2x00_mailbox_command(ha, mcp);
  1738. if (rval != QLA_SUCCESS) {
  1739. /*EMPTY*/
  1740. DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
  1741. ha->host_no, rval);)
  1742. } else {
  1743. *entries = mcp->mb[1];
  1744. DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
  1745. ha->host_no);)
  1746. }
  1747. return rval;
  1748. }
  1749. /*
  1750. * qla2x00_get_resource_cnts
  1751. * Get current firmware resource counts.
  1752. *
  1753. * Input:
  1754. * ha = adapter block pointer.
  1755. *
  1756. * Returns:
  1757. * qla2x00 local function return status code.
  1758. *
  1759. * Context:
  1760. * Kernel context.
  1761. */
  1762. int
  1763. qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
  1764. uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
  1765. {
  1766. int rval;
  1767. mbx_cmd_t mc;
  1768. mbx_cmd_t *mcp = &mc;
  1769. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1770. mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
  1771. mcp->out_mb = MBX_0;
  1772. mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1773. mcp->tov = 30;
  1774. mcp->flags = 0;
  1775. rval = qla2x00_mailbox_command(ha, mcp);
  1776. if (rval != QLA_SUCCESS) {
  1777. /*EMPTY*/
  1778. DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
  1779. ha->host_no, mcp->mb[0]);)
  1780. } else {
  1781. DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
  1782. "mb7=%x mb10=%x.\n", __func__, ha->host_no,
  1783. mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
  1784. mcp->mb[10]));
  1785. if (cur_xchg_cnt)
  1786. *cur_xchg_cnt = mcp->mb[3];
  1787. if (orig_xchg_cnt)
  1788. *orig_xchg_cnt = mcp->mb[6];
  1789. if (cur_iocb_cnt)
  1790. *cur_iocb_cnt = mcp->mb[7];
  1791. if (orig_iocb_cnt)
  1792. *orig_iocb_cnt = mcp->mb[10];
  1793. }
  1794. return (rval);
  1795. }
  1796. #if defined(QL_DEBUG_LEVEL_3)
  1797. /*
  1798. * qla2x00_get_fcal_position_map
  1799. * Get FCAL (LILP) position map using mailbox command
  1800. *
  1801. * Input:
  1802. * ha = adapter state pointer.
  1803. * pos_map = buffer pointer (can be NULL).
  1804. *
  1805. * Returns:
  1806. * qla2x00 local function return status code.
  1807. *
  1808. * Context:
  1809. * Kernel context.
  1810. */
  1811. int
  1812. qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
  1813. {
  1814. int rval;
  1815. mbx_cmd_t mc;
  1816. mbx_cmd_t *mcp = &mc;
  1817. char *pmap;
  1818. dma_addr_t pmap_dma;
  1819. pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
  1820. if (pmap == NULL) {
  1821. DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
  1822. __func__, ha->host_no));
  1823. return QLA_MEMORY_ALLOC_FAILED;
  1824. }
  1825. memset(pmap, 0, FCAL_MAP_SIZE);
  1826. mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
  1827. mcp->mb[2] = MSW(pmap_dma);
  1828. mcp->mb[3] = LSW(pmap_dma);
  1829. mcp->mb[6] = MSW(MSD(pmap_dma));
  1830. mcp->mb[7] = LSW(MSD(pmap_dma));
  1831. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1832. mcp->in_mb = MBX_1|MBX_0;
  1833. mcp->buf_size = FCAL_MAP_SIZE;
  1834. mcp->flags = MBX_DMA_IN;
  1835. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1836. rval = qla2x00_mailbox_command(ha, mcp);
  1837. if (rval == QLA_SUCCESS) {
  1838. DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
  1839. "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
  1840. mcp->mb[1], (unsigned)pmap[0]));
  1841. DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
  1842. if (pos_map)
  1843. memcpy(pos_map, pmap, FCAL_MAP_SIZE);
  1844. }
  1845. dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
  1846. if (rval != QLA_SUCCESS) {
  1847. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1848. ha->host_no, rval));
  1849. } else {
  1850. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1851. }
  1852. return rval;
  1853. }
  1854. uint8_t
  1855. qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
  1856. uint16_t *status)
  1857. {
  1858. int rval;
  1859. mbx_cmd_t mc;
  1860. mbx_cmd_t *mcp = &mc;
  1861. uint32_t *sbuf, *siter;
  1862. dma_addr_t sbuf_dma;
  1863. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1864. if (dwords > (DMA_POOL_SIZE / 4)) {
  1865. DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
  1866. "(max %d).\n", __func__, ha->host_no, dwords,
  1867. DMA_POOL_SIZE / 4));
  1868. return BIT_0;
  1869. }
  1870. sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
  1871. if (sbuf == NULL) {
  1872. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1873. __func__, ha->host_no));
  1874. return BIT_0;
  1875. }
  1876. memset(sbuf, 0, DMA_POOL_SIZE);
  1877. mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
  1878. mcp->mb[2] = MSW(sbuf_dma);
  1879. mcp->mb[3] = LSW(sbuf_dma);
  1880. mcp->mb[6] = MSW(MSD(sbuf_dma));
  1881. mcp->mb[7] = LSW(MSD(sbuf_dma));
  1882. mcp->mb[8] = dwords;
  1883. mcp->mb[10] = 0;
  1884. mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1885. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  1886. mcp->tov = 30;
  1887. mcp->flags = IOCTL_CMD;
  1888. rval = qla2x00_mailbox_command(ha, mcp);
  1889. if (rval == QLA_SUCCESS) {
  1890. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  1891. DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
  1892. __func__, ha->host_no, mcp->mb[0]));
  1893. status[0] = mcp->mb[0];
  1894. rval = BIT_1;
  1895. } else {
  1896. /* Copy over data -- firmware data is LE. */
  1897. siter = sbuf;
  1898. while (dwords--)
  1899. *dwbuf++ = le32_to_cpu(*siter++);
  1900. }
  1901. } else {
  1902. /* Failed. */
  1903. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1904. ha->host_no, rval));
  1905. rval = BIT_1;
  1906. }
  1907. dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
  1908. return rval;
  1909. }
  1910. #endif
  1911. int
  1912. qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
  1913. {
  1914. int rval;
  1915. fc_port_t *fcport;
  1916. unsigned long flags = 0;
  1917. struct abort_entry_24xx *abt;
  1918. dma_addr_t abt_dma;
  1919. uint32_t handle;
  1920. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
  1921. fcport = sp->fcport;
  1922. spin_lock_irqsave(&ha->hardware_lock, flags);
  1923. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  1924. if (ha->outstanding_cmds[handle] == sp)
  1925. break;
  1926. }
  1927. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1928. if (handle == MAX_OUTSTANDING_COMMANDS) {
  1929. /* Command not found. */
  1930. return QLA_FUNCTION_FAILED;
  1931. }
  1932. abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
  1933. if (abt == NULL) {
  1934. DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
  1935. __func__, ha->host_no));
  1936. return QLA_MEMORY_ALLOC_FAILED;
  1937. }
  1938. memset(abt, 0, sizeof(struct abort_entry_24xx));
  1939. abt->entry_type = ABORT_IOCB_TYPE;
  1940. abt->entry_count = 1;
  1941. abt->nport_handle = cpu_to_le16(fcport->loop_id);
  1942. abt->handle_to_abort = handle;
  1943. abt->port_id[0] = fcport->d_id.b.al_pa;
  1944. abt->port_id[1] = fcport->d_id.b.area;
  1945. abt->port_id[2] = fcport->d_id.b.domain;
  1946. rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
  1947. if (rval != QLA_SUCCESS) {
  1948. DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
  1949. __func__, ha->host_no, rval);)
  1950. } else if (abt->entry_status != 0) {
  1951. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1952. "-- error status (%x).\n", __func__, ha->host_no,
  1953. abt->entry_status));
  1954. rval = QLA_FUNCTION_FAILED;
  1955. } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
  1956. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1957. "-- completion status (%x).\n", __func__, ha->host_no,
  1958. le16_to_cpu(abt->nport_handle));)
  1959. rval = QLA_FUNCTION_FAILED;
  1960. } else {
  1961. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  1962. sp->flags |= SRB_ABORT_PENDING;
  1963. }
  1964. dma_pool_free(ha->s_dma_pool, abt, abt_dma);
  1965. return rval;
  1966. }
  1967. struct tsk_mgmt_cmd {
  1968. union {
  1969. struct tsk_mgmt_entry tsk;
  1970. struct sts_entry_24xx sts;
  1971. } p;
  1972. };
  1973. int
  1974. qla24xx_abort_target(fc_port_t *fcport)
  1975. {
  1976. int rval;
  1977. struct tsk_mgmt_cmd *tsk;
  1978. dma_addr_t tsk_dma;
  1979. scsi_qla_host_t *ha;
  1980. if (fcport == NULL)
  1981. return 0;
  1982. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
  1983. ha = fcport->ha;
  1984. tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
  1985. if (tsk == NULL) {
  1986. DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
  1987. "IOCB.\n", __func__, ha->host_no));
  1988. return QLA_MEMORY_ALLOC_FAILED;
  1989. }
  1990. memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
  1991. tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
  1992. tsk->p.tsk.entry_count = 1;
  1993. tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
  1994. tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
  1995. tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
  1996. tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
  1997. tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
  1998. tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
  1999. rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
  2000. if (rval != QLA_SUCCESS) {
  2001. DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
  2002. "(%x).\n", __func__, ha->host_no, rval);)
  2003. goto atarget_done;
  2004. } else if (tsk->p.sts.entry_status != 0) {
  2005. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2006. "-- error status (%x).\n", __func__, ha->host_no,
  2007. tsk->p.sts.entry_status));
  2008. rval = QLA_FUNCTION_FAILED;
  2009. goto atarget_done;
  2010. } else if (tsk->p.sts.comp_status !=
  2011. __constant_cpu_to_le16(CS_COMPLETE)) {
  2012. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2013. "-- completion status (%x).\n", __func__,
  2014. ha->host_no, le16_to_cpu(tsk->p.sts.comp_status));)
  2015. rval = QLA_FUNCTION_FAILED;
  2016. goto atarget_done;
  2017. }
  2018. /* Issue marker IOCB. */
  2019. rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
  2020. if (rval != QLA_SUCCESS) {
  2021. DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
  2022. "(%x).\n", __func__, ha->host_no, rval);)
  2023. } else {
  2024. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
  2025. }
  2026. atarget_done:
  2027. dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
  2028. return rval;
  2029. }
  2030. int
  2031. qla2x00_system_error(scsi_qla_host_t *ha)
  2032. {
  2033. int rval;
  2034. mbx_cmd_t mc;
  2035. mbx_cmd_t *mcp = &mc;
  2036. if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
  2037. return QLA_FUNCTION_FAILED;
  2038. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2039. mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
  2040. mcp->out_mb = MBX_0;
  2041. mcp->in_mb = MBX_0;
  2042. mcp->tov = 5;
  2043. mcp->flags = 0;
  2044. rval = qla2x00_mailbox_command(ha, mcp);
  2045. if (rval != QLA_SUCCESS) {
  2046. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2047. ha->host_no, rval));
  2048. } else {
  2049. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2050. }
  2051. return rval;
  2052. }
  2053. /**
  2054. * qla2x00_get_serdes_params() -
  2055. * @ha: HA context
  2056. *
  2057. * Returns
  2058. */
  2059. int
  2060. qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
  2061. uint16_t *sw_em_2g, uint16_t *sw_em_4g)
  2062. {
  2063. int rval;
  2064. mbx_cmd_t mc;
  2065. mbx_cmd_t *mcp = &mc;
  2066. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2067. mcp->mb[0] = MBC_SERDES_PARAMS;
  2068. mcp->mb[1] = 0;
  2069. mcp->out_mb = MBX_1|MBX_0;
  2070. mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
  2071. mcp->tov = 30;
  2072. mcp->flags = 0;
  2073. rval = qla2x00_mailbox_command(ha, mcp);
  2074. if (rval != QLA_SUCCESS) {
  2075. /*EMPTY*/
  2076. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2077. ha->host_no, rval, mcp->mb[0]));
  2078. } else {
  2079. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2080. if (sw_em_1g)
  2081. *sw_em_1g = mcp->mb[2];
  2082. if (sw_em_2g)
  2083. *sw_em_2g = mcp->mb[3];
  2084. if (sw_em_4g)
  2085. *sw_em_4g = mcp->mb[4];
  2086. }
  2087. return rval;
  2088. }
  2089. /**
  2090. * qla2x00_set_serdes_params() -
  2091. * @ha: HA context
  2092. *
  2093. * Returns
  2094. */
  2095. int
  2096. qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
  2097. uint16_t sw_em_2g, uint16_t sw_em_4g)
  2098. {
  2099. int rval;
  2100. mbx_cmd_t mc;
  2101. mbx_cmd_t *mcp = &mc;
  2102. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2103. mcp->mb[0] = MBC_SERDES_PARAMS;
  2104. mcp->mb[1] = BIT_0;
  2105. mcp->mb[2] = sw_em_1g;
  2106. mcp->mb[3] = sw_em_2g;
  2107. mcp->mb[4] = sw_em_4g;
  2108. mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2109. mcp->in_mb = MBX_0;
  2110. mcp->tov = 30;
  2111. mcp->flags = 0;
  2112. rval = qla2x00_mailbox_command(ha, mcp);
  2113. if (rval != QLA_SUCCESS) {
  2114. /*EMPTY*/
  2115. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2116. ha->host_no, rval, mcp->mb[0]));
  2117. } else {
  2118. /*EMPTY*/
  2119. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2120. }
  2121. return rval;
  2122. }
  2123. int
  2124. qla2x00_stop_firmware(scsi_qla_host_t *ha)
  2125. {
  2126. int rval;
  2127. mbx_cmd_t mc;
  2128. mbx_cmd_t *mcp = &mc;
  2129. if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
  2130. return QLA_FUNCTION_FAILED;
  2131. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2132. mcp->mb[0] = MBC_STOP_FIRMWARE;
  2133. mcp->out_mb = MBX_0;
  2134. mcp->in_mb = MBX_0;
  2135. mcp->tov = 5;
  2136. mcp->flags = 0;
  2137. rval = qla2x00_mailbox_command(ha, mcp);
  2138. if (rval != QLA_SUCCESS) {
  2139. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2140. ha->host_no, rval));
  2141. } else {
  2142. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2143. }
  2144. return rval;
  2145. }