qla_mbx.c 86 KB

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