qla_mbx.c 63 KB

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