qla_mbx.c 72 KB

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