qla_mbx.c 57 KB

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