qla_mbx.c 60 KB

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