qla_mbx.c 60 KB

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