qla_mbx.c 90 KB

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