qla_mbx.c 77 KB

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