qla_mbx.c 75 KB

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