qla_mbx.c 81 KB

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