qla_mbx.c 89 KB

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