qla_mbx.c 67 KB

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