lpfc_sli.c 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_cmnd.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include "lpfc_hw.h"
  31. #include "lpfc_sli.h"
  32. #include "lpfc_disc.h"
  33. #include "lpfc_scsi.h"
  34. #include "lpfc.h"
  35. #include "lpfc_crtn.h"
  36. #include "lpfc_logmsg.h"
  37. #include "lpfc_compat.h"
  38. #include "lpfc_debugfs.h"
  39. /*
  40. * Define macro to log: Mailbox command x%x cannot issue Data
  41. * This allows multiple uses of lpfc_msgBlk0311
  42. * w/o perturbing log msg utility.
  43. */
  44. #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
  45. lpfc_printf_log(phba, \
  46. KERN_INFO, \
  47. LOG_MBOX | LOG_SLI, \
  48. "(%d):0311 Mailbox command x%x cannot " \
  49. "issue Data: x%x x%x x%x\n", \
  50. pmbox->vport ? pmbox->vport->vpi : 0, \
  51. pmbox->mb.mbxCommand, \
  52. phba->pport->port_state, \
  53. psli->sli_flag, \
  54. flag)
  55. /* There are only four IOCB completion types. */
  56. typedef enum _lpfc_iocb_type {
  57. LPFC_UNKNOWN_IOCB,
  58. LPFC_UNSOL_IOCB,
  59. LPFC_SOL_IOCB,
  60. LPFC_ABORT_IOCB
  61. } lpfc_iocb_type;
  62. /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer
  63. * to the start of the ring, and the slot number of the
  64. * desired iocb entry, calc a pointer to that entry.
  65. */
  66. static inline IOCB_t *
  67. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  68. {
  69. return (IOCB_t *) (((char *) pring->cmdringaddr) +
  70. pring->cmdidx * phba->iocb_cmd_size);
  71. }
  72. static inline IOCB_t *
  73. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  74. {
  75. return (IOCB_t *) (((char *) pring->rspringaddr) +
  76. pring->rspidx * phba->iocb_rsp_size);
  77. }
  78. static struct lpfc_iocbq *
  79. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  80. {
  81. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  82. struct lpfc_iocbq * iocbq = NULL;
  83. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  84. return iocbq;
  85. }
  86. struct lpfc_iocbq *
  87. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  88. {
  89. struct lpfc_iocbq * iocbq = NULL;
  90. unsigned long iflags;
  91. spin_lock_irqsave(&phba->hbalock, iflags);
  92. iocbq = __lpfc_sli_get_iocbq(phba);
  93. spin_unlock_irqrestore(&phba->hbalock, iflags);
  94. return iocbq;
  95. }
  96. static void
  97. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  98. {
  99. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  100. /*
  101. * Clean all volatile data fields, preserve iotag and node struct.
  102. */
  103. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  104. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  105. }
  106. void
  107. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  108. {
  109. unsigned long iflags;
  110. /*
  111. * Clean all volatile data fields, preserve iotag and node struct.
  112. */
  113. spin_lock_irqsave(&phba->hbalock, iflags);
  114. __lpfc_sli_release_iocbq(phba, iocbq);
  115. spin_unlock_irqrestore(&phba->hbalock, iflags);
  116. }
  117. /*
  118. * Translate the iocb command to an iocb command type used to decide the final
  119. * disposition of each completed IOCB.
  120. */
  121. static lpfc_iocb_type
  122. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  123. {
  124. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  125. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  126. return 0;
  127. switch (iocb_cmnd) {
  128. case CMD_XMIT_SEQUENCE_CR:
  129. case CMD_XMIT_SEQUENCE_CX:
  130. case CMD_XMIT_BCAST_CN:
  131. case CMD_XMIT_BCAST_CX:
  132. case CMD_ELS_REQUEST_CR:
  133. case CMD_ELS_REQUEST_CX:
  134. case CMD_CREATE_XRI_CR:
  135. case CMD_CREATE_XRI_CX:
  136. case CMD_GET_RPI_CN:
  137. case CMD_XMIT_ELS_RSP_CX:
  138. case CMD_GET_RPI_CR:
  139. case CMD_FCP_IWRITE_CR:
  140. case CMD_FCP_IWRITE_CX:
  141. case CMD_FCP_IREAD_CR:
  142. case CMD_FCP_IREAD_CX:
  143. case CMD_FCP_ICMND_CR:
  144. case CMD_FCP_ICMND_CX:
  145. case CMD_FCP_TSEND_CX:
  146. case CMD_FCP_TRSP_CX:
  147. case CMD_FCP_TRECEIVE_CX:
  148. case CMD_FCP_AUTO_TRSP_CX:
  149. case CMD_ADAPTER_MSG:
  150. case CMD_ADAPTER_DUMP:
  151. case CMD_XMIT_SEQUENCE64_CR:
  152. case CMD_XMIT_SEQUENCE64_CX:
  153. case CMD_XMIT_BCAST64_CN:
  154. case CMD_XMIT_BCAST64_CX:
  155. case CMD_ELS_REQUEST64_CR:
  156. case CMD_ELS_REQUEST64_CX:
  157. case CMD_FCP_IWRITE64_CR:
  158. case CMD_FCP_IWRITE64_CX:
  159. case CMD_FCP_IREAD64_CR:
  160. case CMD_FCP_IREAD64_CX:
  161. case CMD_FCP_ICMND64_CR:
  162. case CMD_FCP_ICMND64_CX:
  163. case CMD_FCP_TSEND64_CX:
  164. case CMD_FCP_TRSP64_CX:
  165. case CMD_FCP_TRECEIVE64_CX:
  166. case CMD_GEN_REQUEST64_CR:
  167. case CMD_GEN_REQUEST64_CX:
  168. case CMD_XMIT_ELS_RSP64_CX:
  169. type = LPFC_SOL_IOCB;
  170. break;
  171. case CMD_ABORT_XRI_CN:
  172. case CMD_ABORT_XRI_CX:
  173. case CMD_CLOSE_XRI_CN:
  174. case CMD_CLOSE_XRI_CX:
  175. case CMD_XRI_ABORTED_CX:
  176. case CMD_ABORT_MXRI64_CN:
  177. type = LPFC_ABORT_IOCB;
  178. break;
  179. case CMD_RCV_SEQUENCE_CX:
  180. case CMD_RCV_ELS_REQ_CX:
  181. case CMD_RCV_SEQUENCE64_CX:
  182. case CMD_RCV_ELS_REQ64_CX:
  183. case CMD_ASYNC_STATUS:
  184. case CMD_IOCB_RCV_SEQ64_CX:
  185. case CMD_IOCB_RCV_ELS64_CX:
  186. case CMD_IOCB_RCV_CONT64_CX:
  187. case CMD_IOCB_RET_XRI64_CX:
  188. type = LPFC_UNSOL_IOCB;
  189. break;
  190. case CMD_IOCB_XMIT_MSEQ64_CR:
  191. case CMD_IOCB_XMIT_MSEQ64_CX:
  192. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  193. case CMD_IOCB_RCV_ELS_LIST64_CX:
  194. case CMD_IOCB_CLOSE_EXTENDED_CN:
  195. case CMD_IOCB_ABORT_EXTENDED_CN:
  196. case CMD_IOCB_RET_HBQE64_CN:
  197. case CMD_IOCB_FCP_IBIDIR64_CR:
  198. case CMD_IOCB_FCP_IBIDIR64_CX:
  199. case CMD_IOCB_FCP_ITASKMGT64_CX:
  200. case CMD_IOCB_LOGENTRY_CN:
  201. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  202. printk("%s - Unhandled SLI-3 Command x%x\n",
  203. __FUNCTION__, iocb_cmnd);
  204. type = LPFC_UNKNOWN_IOCB;
  205. break;
  206. default:
  207. type = LPFC_UNKNOWN_IOCB;
  208. break;
  209. }
  210. return type;
  211. }
  212. static int
  213. lpfc_sli_ring_map(struct lpfc_hba *phba)
  214. {
  215. struct lpfc_sli *psli = &phba->sli;
  216. LPFC_MBOXQ_t *pmb;
  217. MAILBOX_t *pmbox;
  218. int i, rc, ret = 0;
  219. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  220. if (!pmb)
  221. return -ENOMEM;
  222. pmbox = &pmb->mb;
  223. phba->link_state = LPFC_INIT_MBX_CMDS;
  224. for (i = 0; i < psli->num_rings; i++) {
  225. lpfc_config_ring(phba, i, pmb);
  226. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  227. if (rc != MBX_SUCCESS) {
  228. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  229. "0446 Adapter failed to init (%d), "
  230. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  231. "ring %d\n",
  232. rc, pmbox->mbxCommand,
  233. pmbox->mbxStatus, i);
  234. phba->link_state = LPFC_HBA_ERROR;
  235. ret = -ENXIO;
  236. break;
  237. }
  238. }
  239. mempool_free(pmb, phba->mbox_mem_pool);
  240. return ret;
  241. }
  242. static int
  243. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  244. struct lpfc_iocbq *piocb)
  245. {
  246. list_add_tail(&piocb->list, &pring->txcmplq);
  247. pring->txcmplq_cnt++;
  248. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  249. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  250. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  251. if (!piocb->vport)
  252. BUG();
  253. else
  254. mod_timer(&piocb->vport->els_tmofunc,
  255. jiffies + HZ * (phba->fc_ratov << 1));
  256. }
  257. return 0;
  258. }
  259. static struct lpfc_iocbq *
  260. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  261. {
  262. struct lpfc_iocbq *cmd_iocb;
  263. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  264. if (cmd_iocb != NULL)
  265. pring->txq_cnt--;
  266. return cmd_iocb;
  267. }
  268. static IOCB_t *
  269. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  270. {
  271. struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
  272. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  273. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  274. uint32_t max_cmd_idx = pring->numCiocb;
  275. if ((pring->next_cmdidx == pring->cmdidx) &&
  276. (++pring->next_cmdidx >= max_cmd_idx))
  277. pring->next_cmdidx = 0;
  278. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  279. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  280. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  281. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  282. "0315 Ring %d issue: portCmdGet %d "
  283. "is bigger then cmd ring %d\n",
  284. pring->ringno,
  285. pring->local_getidx, max_cmd_idx);
  286. phba->link_state = LPFC_HBA_ERROR;
  287. /*
  288. * All error attention handlers are posted to
  289. * worker thread
  290. */
  291. phba->work_ha |= HA_ERATT;
  292. phba->work_hs = HS_FFER3;
  293. lpfc_worker_wake_up(phba);
  294. return NULL;
  295. }
  296. if (pring->local_getidx == pring->next_cmdidx)
  297. return NULL;
  298. }
  299. return lpfc_cmd_iocb(phba, pring);
  300. }
  301. uint16_t
  302. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  303. {
  304. struct lpfc_iocbq **new_arr;
  305. struct lpfc_iocbq **old_arr;
  306. size_t new_len;
  307. struct lpfc_sli *psli = &phba->sli;
  308. uint16_t iotag;
  309. spin_lock_irq(&phba->hbalock);
  310. iotag = psli->last_iotag;
  311. if(++iotag < psli->iocbq_lookup_len) {
  312. psli->last_iotag = iotag;
  313. psli->iocbq_lookup[iotag] = iocbq;
  314. spin_unlock_irq(&phba->hbalock);
  315. iocbq->iotag = iotag;
  316. return iotag;
  317. } else if (psli->iocbq_lookup_len < (0xffff
  318. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  319. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  320. spin_unlock_irq(&phba->hbalock);
  321. new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
  322. GFP_KERNEL);
  323. if (new_arr) {
  324. spin_lock_irq(&phba->hbalock);
  325. old_arr = psli->iocbq_lookup;
  326. if (new_len <= psli->iocbq_lookup_len) {
  327. /* highly unprobable case */
  328. kfree(new_arr);
  329. iotag = psli->last_iotag;
  330. if(++iotag < psli->iocbq_lookup_len) {
  331. psli->last_iotag = iotag;
  332. psli->iocbq_lookup[iotag] = iocbq;
  333. spin_unlock_irq(&phba->hbalock);
  334. iocbq->iotag = iotag;
  335. return iotag;
  336. }
  337. spin_unlock_irq(&phba->hbalock);
  338. return 0;
  339. }
  340. if (psli->iocbq_lookup)
  341. memcpy(new_arr, old_arr,
  342. ((psli->last_iotag + 1) *
  343. sizeof (struct lpfc_iocbq *)));
  344. psli->iocbq_lookup = new_arr;
  345. psli->iocbq_lookup_len = new_len;
  346. psli->last_iotag = iotag;
  347. psli->iocbq_lookup[iotag] = iocbq;
  348. spin_unlock_irq(&phba->hbalock);
  349. iocbq->iotag = iotag;
  350. kfree(old_arr);
  351. return iotag;
  352. }
  353. } else
  354. spin_unlock_irq(&phba->hbalock);
  355. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  356. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  357. psli->last_iotag);
  358. return 0;
  359. }
  360. static void
  361. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  362. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  363. {
  364. /*
  365. * Set up an iotag
  366. */
  367. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  368. if (pring->ringno == LPFC_ELS_RING) {
  369. lpfc_debugfs_slow_ring_trc(phba,
  370. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  371. *(((uint32_t *) &nextiocb->iocb) + 4),
  372. *(((uint32_t *) &nextiocb->iocb) + 6),
  373. *(((uint32_t *) &nextiocb->iocb) + 7));
  374. }
  375. /*
  376. * Issue iocb command to adapter
  377. */
  378. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  379. wmb();
  380. pring->stats.iocb_cmd++;
  381. /*
  382. * If there is no completion routine to call, we can release the
  383. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  384. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  385. */
  386. if (nextiocb->iocb_cmpl)
  387. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  388. else
  389. __lpfc_sli_release_iocbq(phba, nextiocb);
  390. /*
  391. * Let the HBA know what IOCB slot will be the next one the
  392. * driver will put a command into.
  393. */
  394. pring->cmdidx = pring->next_cmdidx;
  395. writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  396. }
  397. static void
  398. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  399. {
  400. int ringno = pring->ringno;
  401. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  402. wmb();
  403. /*
  404. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  405. * The HBA will tell us when an IOCB entry is available.
  406. */
  407. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  408. readl(phba->CAregaddr); /* flush */
  409. pring->stats.iocb_cmd_full++;
  410. }
  411. static void
  412. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  413. {
  414. int ringno = pring->ringno;
  415. /*
  416. * Tell the HBA that there is work to do in this ring.
  417. */
  418. wmb();
  419. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  420. readl(phba->CAregaddr); /* flush */
  421. }
  422. static void
  423. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  424. {
  425. IOCB_t *iocb;
  426. struct lpfc_iocbq *nextiocb;
  427. /*
  428. * Check to see if:
  429. * (a) there is anything on the txq to send
  430. * (b) link is up
  431. * (c) link attention events can be processed (fcp ring only)
  432. * (d) IOCB processing is not blocked by the outstanding mbox command.
  433. */
  434. if (pring->txq_cnt &&
  435. lpfc_is_link_up(phba) &&
  436. (pring->ringno != phba->sli.fcp_ring ||
  437. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  438. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  439. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  440. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  441. if (iocb)
  442. lpfc_sli_update_ring(phba, pring);
  443. else
  444. lpfc_sli_update_full_ring(phba, pring);
  445. }
  446. return;
  447. }
  448. static struct lpfc_hbq_entry *
  449. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  450. {
  451. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  452. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  453. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  454. hbqp->next_hbqPutIdx = 0;
  455. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  456. uint32_t raw_index = phba->hbq_get[hbqno];
  457. uint32_t getidx = le32_to_cpu(raw_index);
  458. hbqp->local_hbqGetIdx = getidx;
  459. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  460. lpfc_printf_log(phba, KERN_ERR,
  461. LOG_SLI | LOG_VPORT,
  462. "1802 HBQ %d: local_hbqGetIdx "
  463. "%u is > than hbqp->entry_count %u\n",
  464. hbqno, hbqp->local_hbqGetIdx,
  465. hbqp->entry_count);
  466. phba->link_state = LPFC_HBA_ERROR;
  467. return NULL;
  468. }
  469. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  470. return NULL;
  471. }
  472. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  473. hbqp->hbqPutIdx;
  474. }
  475. void
  476. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  477. {
  478. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  479. struct hbq_dmabuf *hbq_buf;
  480. unsigned long flags;
  481. int i, hbq_count;
  482. uint32_t hbqno;
  483. hbq_count = lpfc_sli_hbq_count();
  484. /* Return all memory used by all HBQs */
  485. spin_lock_irqsave(&phba->hbalock, flags);
  486. for (i = 0; i < hbq_count; ++i) {
  487. list_for_each_entry_safe(dmabuf, next_dmabuf,
  488. &phba->hbqs[i].hbq_buffer_list, list) {
  489. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  490. list_del(&hbq_buf->dbuf.list);
  491. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  492. }
  493. phba->hbqs[i].buffer_count = 0;
  494. }
  495. /* Return all HBQ buffer that are in-fly */
  496. list_for_each_entry_safe(dmabuf, next_dmabuf,
  497. &phba->hbqbuf_in_list, list) {
  498. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  499. list_del(&hbq_buf->dbuf.list);
  500. if (hbq_buf->tag == -1) {
  501. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  502. (phba, hbq_buf);
  503. } else {
  504. hbqno = hbq_buf->tag >> 16;
  505. if (hbqno >= LPFC_MAX_HBQS)
  506. (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
  507. (phba, hbq_buf);
  508. else
  509. (phba->hbqs[hbqno].hbq_free_buffer)(phba,
  510. hbq_buf);
  511. }
  512. }
  513. /* Mark the HBQs not in use */
  514. phba->hbq_in_use = 0;
  515. spin_unlock_irqrestore(&phba->hbalock, flags);
  516. }
  517. static struct lpfc_hbq_entry *
  518. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  519. struct hbq_dmabuf *hbq_buf)
  520. {
  521. struct lpfc_hbq_entry *hbqe;
  522. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  523. /* Get next HBQ entry slot to use */
  524. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  525. if (hbqe) {
  526. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  527. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  528. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  529. hbqe->bde.tus.f.bdeSize = hbq_buf->size;
  530. hbqe->bde.tus.f.bdeFlags = 0;
  531. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  532. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  533. /* Sync SLIM */
  534. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  535. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  536. /* flush */
  537. readl(phba->hbq_put + hbqno);
  538. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  539. }
  540. return hbqe;
  541. }
  542. static struct lpfc_hbq_init lpfc_els_hbq = {
  543. .rn = 1,
  544. .entry_count = 200,
  545. .mask_count = 0,
  546. .profile = 0,
  547. .ring_mask = (1 << LPFC_ELS_RING),
  548. .buffer_count = 0,
  549. .init_count = 20,
  550. .add_count = 5,
  551. };
  552. static struct lpfc_hbq_init lpfc_extra_hbq = {
  553. .rn = 1,
  554. .entry_count = 200,
  555. .mask_count = 0,
  556. .profile = 0,
  557. .ring_mask = (1 << LPFC_EXTRA_RING),
  558. .buffer_count = 0,
  559. .init_count = 0,
  560. .add_count = 5,
  561. };
  562. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  563. &lpfc_els_hbq,
  564. &lpfc_extra_hbq,
  565. };
  566. static int
  567. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  568. {
  569. uint32_t i, start, end;
  570. unsigned long flags;
  571. struct hbq_dmabuf *hbq_buffer;
  572. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  573. return 0;
  574. start = phba->hbqs[hbqno].buffer_count;
  575. end = count + start;
  576. if (end > lpfc_hbq_defs[hbqno]->entry_count)
  577. end = lpfc_hbq_defs[hbqno]->entry_count;
  578. /* Check whether HBQ is still in use */
  579. spin_lock_irqsave(&phba->hbalock, flags);
  580. if (!phba->hbq_in_use)
  581. goto out;
  582. /* Populate HBQ entries */
  583. for (i = start; i < end; i++) {
  584. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  585. if (!hbq_buffer)
  586. goto err;
  587. hbq_buffer->tag = (i | (hbqno << 16));
  588. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  589. phba->hbqs[hbqno].buffer_count++;
  590. else
  591. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  592. }
  593. out:
  594. spin_unlock_irqrestore(&phba->hbalock, flags);
  595. return 0;
  596. err:
  597. spin_unlock_irqrestore(&phba->hbalock, flags);
  598. return 1;
  599. }
  600. int
  601. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  602. {
  603. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  604. lpfc_hbq_defs[qno]->add_count));
  605. }
  606. static int
  607. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  608. {
  609. return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  610. lpfc_hbq_defs[qno]->init_count));
  611. }
  612. static struct hbq_dmabuf *
  613. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  614. {
  615. struct lpfc_dmabuf *d_buf;
  616. struct hbq_dmabuf *hbq_buf;
  617. uint32_t hbqno;
  618. hbqno = tag >> 16;
  619. if (hbqno >= LPFC_MAX_HBQS)
  620. return NULL;
  621. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  622. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  623. if (hbq_buf->tag == tag) {
  624. return hbq_buf;
  625. }
  626. }
  627. lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
  628. "1803 Bad hbq tag. Data: x%x x%x\n",
  629. tag, phba->hbqs[tag >> 16].buffer_count);
  630. return NULL;
  631. }
  632. void
  633. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  634. {
  635. uint32_t hbqno;
  636. if (hbq_buffer) {
  637. hbqno = hbq_buffer->tag >> 16;
  638. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  639. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  640. }
  641. }
  642. }
  643. static int
  644. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  645. {
  646. uint8_t ret;
  647. switch (mbxCommand) {
  648. case MBX_LOAD_SM:
  649. case MBX_READ_NV:
  650. case MBX_WRITE_NV:
  651. case MBX_WRITE_VPARMS:
  652. case MBX_RUN_BIU_DIAG:
  653. case MBX_INIT_LINK:
  654. case MBX_DOWN_LINK:
  655. case MBX_CONFIG_LINK:
  656. case MBX_CONFIG_RING:
  657. case MBX_RESET_RING:
  658. case MBX_READ_CONFIG:
  659. case MBX_READ_RCONFIG:
  660. case MBX_READ_SPARM:
  661. case MBX_READ_STATUS:
  662. case MBX_READ_RPI:
  663. case MBX_READ_XRI:
  664. case MBX_READ_REV:
  665. case MBX_READ_LNK_STAT:
  666. case MBX_REG_LOGIN:
  667. case MBX_UNREG_LOGIN:
  668. case MBX_READ_LA:
  669. case MBX_CLEAR_LA:
  670. case MBX_DUMP_MEMORY:
  671. case MBX_DUMP_CONTEXT:
  672. case MBX_RUN_DIAGS:
  673. case MBX_RESTART:
  674. case MBX_UPDATE_CFG:
  675. case MBX_DOWN_LOAD:
  676. case MBX_DEL_LD_ENTRY:
  677. case MBX_RUN_PROGRAM:
  678. case MBX_SET_MASK:
  679. case MBX_SET_VARIABLE:
  680. case MBX_UNREG_D_ID:
  681. case MBX_KILL_BOARD:
  682. case MBX_CONFIG_FARP:
  683. case MBX_BEACON:
  684. case MBX_LOAD_AREA:
  685. case MBX_RUN_BIU_DIAG64:
  686. case MBX_CONFIG_PORT:
  687. case MBX_READ_SPARM64:
  688. case MBX_READ_RPI64:
  689. case MBX_REG_LOGIN64:
  690. case MBX_READ_LA64:
  691. case MBX_WRITE_WWN:
  692. case MBX_SET_DEBUG:
  693. case MBX_LOAD_EXP_ROM:
  694. case MBX_ASYNCEVT_ENABLE:
  695. case MBX_REG_VPI:
  696. case MBX_UNREG_VPI:
  697. case MBX_HEARTBEAT:
  698. ret = mbxCommand;
  699. break;
  700. default:
  701. ret = MBX_SHUTDOWN;
  702. break;
  703. }
  704. return ret;
  705. }
  706. static void
  707. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  708. {
  709. wait_queue_head_t *pdone_q;
  710. unsigned long drvr_flag;
  711. /*
  712. * If pdone_q is empty, the driver thread gave up waiting and
  713. * continued running.
  714. */
  715. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  716. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  717. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  718. if (pdone_q)
  719. wake_up_interruptible(pdone_q);
  720. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  721. return;
  722. }
  723. void
  724. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  725. {
  726. struct lpfc_dmabuf *mp;
  727. uint16_t rpi;
  728. int rc;
  729. mp = (struct lpfc_dmabuf *) (pmb->context1);
  730. if (mp) {
  731. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  732. kfree(mp);
  733. }
  734. /*
  735. * If a REG_LOGIN succeeded after node is destroyed or node
  736. * is in re-discovery driver need to cleanup the RPI.
  737. */
  738. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  739. pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
  740. !pmb->mb.mbxStatus) {
  741. rpi = pmb->mb.un.varWords[0];
  742. lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
  743. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  744. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  745. if (rc != MBX_NOT_FINISHED)
  746. return;
  747. }
  748. mempool_free(pmb, phba->mbox_mem_pool);
  749. return;
  750. }
  751. int
  752. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  753. {
  754. MAILBOX_t *pmbox;
  755. LPFC_MBOXQ_t *pmb;
  756. int rc;
  757. LIST_HEAD(cmplq);
  758. phba->sli.slistat.mbox_event++;
  759. /* Get all completed mailboxe buffers into the cmplq */
  760. spin_lock_irq(&phba->hbalock);
  761. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  762. spin_unlock_irq(&phba->hbalock);
  763. /* Get a Mailbox buffer to setup mailbox commands for callback */
  764. do {
  765. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  766. if (pmb == NULL)
  767. break;
  768. pmbox = &pmb->mb;
  769. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  770. if (pmb->vport) {
  771. lpfc_debugfs_disc_trc(pmb->vport,
  772. LPFC_DISC_TRC_MBOX_VPORT,
  773. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  774. (uint32_t)pmbox->mbxCommand,
  775. pmbox->un.varWords[0],
  776. pmbox->un.varWords[1]);
  777. }
  778. else {
  779. lpfc_debugfs_disc_trc(phba->pport,
  780. LPFC_DISC_TRC_MBOX,
  781. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  782. (uint32_t)pmbox->mbxCommand,
  783. pmbox->un.varWords[0],
  784. pmbox->un.varWords[1]);
  785. }
  786. }
  787. /*
  788. * It is a fatal error if unknown mbox command completion.
  789. */
  790. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  791. MBX_SHUTDOWN) {
  792. /* Unknow mailbox command compl */
  793. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  794. "(%d):0323 Unknown Mailbox command "
  795. "%x Cmpl\n",
  796. pmb->vport ? pmb->vport->vpi : 0,
  797. pmbox->mbxCommand);
  798. phba->link_state = LPFC_HBA_ERROR;
  799. phba->work_hs = HS_FFER3;
  800. lpfc_handle_eratt(phba);
  801. continue;
  802. }
  803. if (pmbox->mbxStatus) {
  804. phba->sli.slistat.mbox_stat_err++;
  805. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  806. /* Mbox cmd cmpl error - RETRYing */
  807. lpfc_printf_log(phba, KERN_INFO,
  808. LOG_MBOX | LOG_SLI,
  809. "(%d):0305 Mbox cmd cmpl "
  810. "error - RETRYing Data: x%x "
  811. "x%x x%x x%x\n",
  812. pmb->vport ? pmb->vport->vpi :0,
  813. pmbox->mbxCommand,
  814. pmbox->mbxStatus,
  815. pmbox->un.varWords[0],
  816. pmb->vport->port_state);
  817. pmbox->mbxStatus = 0;
  818. pmbox->mbxOwner = OWN_HOST;
  819. spin_lock_irq(&phba->hbalock);
  820. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  821. spin_unlock_irq(&phba->hbalock);
  822. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  823. if (rc == MBX_SUCCESS)
  824. continue;
  825. }
  826. }
  827. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  828. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  829. "(%d):0307 Mailbox cmd x%x Cmpl x%p "
  830. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  831. pmb->vport ? pmb->vport->vpi : 0,
  832. pmbox->mbxCommand,
  833. pmb->mbox_cmpl,
  834. *((uint32_t *) pmbox),
  835. pmbox->un.varWords[0],
  836. pmbox->un.varWords[1],
  837. pmbox->un.varWords[2],
  838. pmbox->un.varWords[3],
  839. pmbox->un.varWords[4],
  840. pmbox->un.varWords[5],
  841. pmbox->un.varWords[6],
  842. pmbox->un.varWords[7]);
  843. if (pmb->mbox_cmpl)
  844. pmb->mbox_cmpl(phba,pmb);
  845. } while (1);
  846. return 0;
  847. }
  848. static struct lpfc_dmabuf *
  849. lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
  850. {
  851. struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
  852. uint32_t hbqno;
  853. void *virt; /* virtual address ptr */
  854. dma_addr_t phys; /* mapped address */
  855. unsigned long flags;
  856. /* Check whether HBQ is still in use */
  857. spin_lock_irqsave(&phba->hbalock, flags);
  858. if (!phba->hbq_in_use) {
  859. spin_unlock_irqrestore(&phba->hbalock, flags);
  860. return NULL;
  861. }
  862. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  863. if (hbq_entry == NULL) {
  864. spin_unlock_irqrestore(&phba->hbalock, flags);
  865. return NULL;
  866. }
  867. list_del(&hbq_entry->dbuf.list);
  868. hbqno = tag >> 16;
  869. new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  870. if (new_hbq_entry == NULL) {
  871. list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
  872. spin_unlock_irqrestore(&phba->hbalock, flags);
  873. return &hbq_entry->dbuf;
  874. }
  875. new_hbq_entry->tag = -1;
  876. phys = new_hbq_entry->dbuf.phys;
  877. virt = new_hbq_entry->dbuf.virt;
  878. new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys;
  879. new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt;
  880. hbq_entry->dbuf.phys = phys;
  881. hbq_entry->dbuf.virt = virt;
  882. lpfc_sli_free_hbq(phba, hbq_entry);
  883. list_add_tail(&new_hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
  884. spin_unlock_irqrestore(&phba->hbalock, flags);
  885. return &new_hbq_entry->dbuf;
  886. }
  887. static struct lpfc_dmabuf *
  888. lpfc_sli_get_buff(struct lpfc_hba *phba,
  889. struct lpfc_sli_ring *pring,
  890. uint32_t tag)
  891. {
  892. if (tag & QUE_BUFTAG_BIT)
  893. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  894. else
  895. return lpfc_sli_replace_hbqbuff(phba, tag);
  896. }
  897. static int
  898. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  899. struct lpfc_iocbq *saveq)
  900. {
  901. IOCB_t * irsp;
  902. WORD5 * w5p;
  903. uint32_t Rctl, Type;
  904. uint32_t match, i;
  905. struct lpfc_iocbq *iocbq;
  906. struct lpfc_dmabuf *dmzbuf;
  907. match = 0;
  908. irsp = &(saveq->iocb);
  909. if (irsp->ulpStatus == IOSTAT_NEED_BUFFER)
  910. return 1;
  911. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  912. if (pring->lpfc_sli_rcv_async_status)
  913. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  914. else
  915. lpfc_printf_log(phba,
  916. KERN_WARNING,
  917. LOG_SLI,
  918. "0316 Ring %d handler: unexpected "
  919. "ASYNC_STATUS iocb received evt_code "
  920. "0x%x\n",
  921. pring->ringno,
  922. irsp->un.asyncstat.evt_code);
  923. return 1;
  924. }
  925. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  926. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  927. if (irsp->ulpBdeCount > 0) {
  928. dmzbuf = lpfc_sli_get_buff(phba, pring,
  929. irsp->un.ulpWord[3]);
  930. lpfc_in_buf_free(phba, dmzbuf);
  931. }
  932. if (irsp->ulpBdeCount > 1) {
  933. dmzbuf = lpfc_sli_get_buff(phba, pring,
  934. irsp->unsli3.sli3Words[3]);
  935. lpfc_in_buf_free(phba, dmzbuf);
  936. }
  937. if (irsp->ulpBdeCount > 2) {
  938. dmzbuf = lpfc_sli_get_buff(phba, pring,
  939. irsp->unsli3.sli3Words[7]);
  940. lpfc_in_buf_free(phba, dmzbuf);
  941. }
  942. return 1;
  943. }
  944. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  945. if (irsp->ulpBdeCount != 0) {
  946. saveq->context2 = lpfc_sli_get_buff(phba, pring,
  947. irsp->un.ulpWord[3]);
  948. if (!saveq->context2)
  949. lpfc_printf_log(phba,
  950. KERN_ERR,
  951. LOG_SLI,
  952. "0341 Ring %d Cannot find buffer for "
  953. "an unsolicited iocb. tag 0x%x\n",
  954. pring->ringno,
  955. irsp->un.ulpWord[3]);
  956. }
  957. if (irsp->ulpBdeCount == 2) {
  958. saveq->context3 = lpfc_sli_get_buff(phba, pring,
  959. irsp->unsli3.sli3Words[7]);
  960. if (!saveq->context3)
  961. lpfc_printf_log(phba,
  962. KERN_ERR,
  963. LOG_SLI,
  964. "0342 Ring %d Cannot find buffer for an"
  965. " unsolicited iocb. tag 0x%x\n",
  966. pring->ringno,
  967. irsp->unsli3.sli3Words[7]);
  968. }
  969. list_for_each_entry(iocbq, &saveq->list, list) {
  970. irsp = &(iocbq->iocb);
  971. if (irsp->ulpBdeCount != 0) {
  972. iocbq->context2 = lpfc_sli_get_buff(phba, pring,
  973. irsp->un.ulpWord[3]);
  974. if (!iocbq->context2)
  975. lpfc_printf_log(phba,
  976. KERN_ERR,
  977. LOG_SLI,
  978. "0343 Ring %d Cannot find "
  979. "buffer for an unsolicited iocb"
  980. ". tag 0x%x\n", pring->ringno,
  981. irsp->un.ulpWord[3]);
  982. }
  983. if (irsp->ulpBdeCount == 2) {
  984. iocbq->context3 = lpfc_sli_get_buff(phba, pring,
  985. irsp->unsli3.sli3Words[7]);
  986. if (!iocbq->context3)
  987. lpfc_printf_log(phba,
  988. KERN_ERR,
  989. LOG_SLI,
  990. "0344 Ring %d Cannot find "
  991. "buffer for an unsolicited "
  992. "iocb. tag 0x%x\n",
  993. pring->ringno,
  994. irsp->unsli3.sli3Words[7]);
  995. }
  996. }
  997. }
  998. if (irsp->ulpBdeCount != 0 &&
  999. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  1000. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  1001. int found = 0;
  1002. /* search continue save q for same XRI */
  1003. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  1004. if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
  1005. list_add_tail(&saveq->list, &iocbq->list);
  1006. found = 1;
  1007. break;
  1008. }
  1009. }
  1010. if (!found)
  1011. list_add_tail(&saveq->clist,
  1012. &pring->iocb_continue_saveq);
  1013. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  1014. list_del_init(&iocbq->clist);
  1015. saveq = iocbq;
  1016. irsp = &(saveq->iocb);
  1017. } else
  1018. return 0;
  1019. }
  1020. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  1021. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  1022. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  1023. Rctl = FC_ELS_REQ;
  1024. Type = FC_ELS_DATA;
  1025. } else {
  1026. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  1027. Rctl = w5p->hcsw.Rctl;
  1028. Type = w5p->hcsw.Type;
  1029. /* Firmware Workaround */
  1030. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  1031. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  1032. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  1033. Rctl = FC_ELS_REQ;
  1034. Type = FC_ELS_DATA;
  1035. w5p->hcsw.Rctl = Rctl;
  1036. w5p->hcsw.Type = Type;
  1037. }
  1038. }
  1039. /* unSolicited Responses */
  1040. if (pring->prt[0].profile) {
  1041. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  1042. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  1043. saveq);
  1044. match = 1;
  1045. } else {
  1046. /* We must search, based on rctl / type
  1047. for the right routine */
  1048. for (i = 0; i < pring->num_mask; i++) {
  1049. if ((pring->prt[i].rctl == Rctl)
  1050. && (pring->prt[i].type == Type)) {
  1051. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1052. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  1053. (phba, pring, saveq);
  1054. match = 1;
  1055. break;
  1056. }
  1057. }
  1058. }
  1059. if (match == 0) {
  1060. /* Unexpected Rctl / Type received */
  1061. /* Ring <ringno> handler: unexpected
  1062. Rctl <Rctl> Type <Type> received */
  1063. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1064. "0313 Ring %d handler: unexpected Rctl x%x "
  1065. "Type x%x received\n",
  1066. pring->ringno, Rctl, Type);
  1067. }
  1068. return 1;
  1069. }
  1070. static struct lpfc_iocbq *
  1071. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  1072. struct lpfc_sli_ring *pring,
  1073. struct lpfc_iocbq *prspiocb)
  1074. {
  1075. struct lpfc_iocbq *cmd_iocb = NULL;
  1076. uint16_t iotag;
  1077. iotag = prspiocb->iocb.ulpIoTag;
  1078. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  1079. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  1080. list_del_init(&cmd_iocb->list);
  1081. pring->txcmplq_cnt--;
  1082. return cmd_iocb;
  1083. }
  1084. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1085. "0317 iotag x%x is out off "
  1086. "range: max iotag x%x wd0 x%x\n",
  1087. iotag, phba->sli.last_iotag,
  1088. *(((uint32_t *) &prspiocb->iocb) + 7));
  1089. return NULL;
  1090. }
  1091. static int
  1092. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1093. struct lpfc_iocbq *saveq)
  1094. {
  1095. struct lpfc_iocbq *cmdiocbp;
  1096. int rc = 1;
  1097. unsigned long iflag;
  1098. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  1099. spin_lock_irqsave(&phba->hbalock, iflag);
  1100. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  1101. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1102. if (cmdiocbp) {
  1103. if (cmdiocbp->iocb_cmpl) {
  1104. /*
  1105. * Post all ELS completions to the worker thread.
  1106. * All other are passed to the completion callback.
  1107. */
  1108. if (pring->ringno == LPFC_ELS_RING) {
  1109. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  1110. cmdiocbp->iocb_flag &=
  1111. ~LPFC_DRIVER_ABORTED;
  1112. saveq->iocb.ulpStatus =
  1113. IOSTAT_LOCAL_REJECT;
  1114. saveq->iocb.un.ulpWord[4] =
  1115. IOERR_SLI_ABORTED;
  1116. /* Firmware could still be in progress
  1117. * of DMAing payload, so don't free data
  1118. * buffer till after a hbeat.
  1119. */
  1120. saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
  1121. }
  1122. }
  1123. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  1124. } else
  1125. lpfc_sli_release_iocbq(phba, cmdiocbp);
  1126. } else {
  1127. /*
  1128. * Unknown initiating command based on the response iotag.
  1129. * This could be the case on the ELS ring because of
  1130. * lpfc_els_abort().
  1131. */
  1132. if (pring->ringno != LPFC_ELS_RING) {
  1133. /*
  1134. * Ring <ringno> handler: unexpected completion IoTag
  1135. * <IoTag>
  1136. */
  1137. lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI,
  1138. "0322 Ring %d handler: "
  1139. "unexpected completion IoTag x%x "
  1140. "Data: x%x x%x x%x x%x\n",
  1141. pring->ringno,
  1142. saveq->iocb.ulpIoTag,
  1143. saveq->iocb.ulpStatus,
  1144. saveq->iocb.un.ulpWord[4],
  1145. saveq->iocb.ulpCommand,
  1146. saveq->iocb.ulpContext);
  1147. }
  1148. }
  1149. return rc;
  1150. }
  1151. static void
  1152. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1153. {
  1154. struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
  1155. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  1156. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1157. /*
  1158. * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
  1159. * rsp ring <portRspMax>
  1160. */
  1161. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1162. "0312 Ring %d handler: portRspPut %d "
  1163. "is bigger then rsp ring %d\n",
  1164. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  1165. pring->numRiocb);
  1166. phba->link_state = LPFC_HBA_ERROR;
  1167. /*
  1168. * All error attention handlers are posted to
  1169. * worker thread
  1170. */
  1171. phba->work_ha |= HA_ERATT;
  1172. phba->work_hs = HS_FFER3;
  1173. lpfc_worker_wake_up(phba);
  1174. return;
  1175. }
  1176. void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
  1177. {
  1178. struct lpfc_sli *psli = &phba->sli;
  1179. struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
  1180. IOCB_t *irsp = NULL;
  1181. IOCB_t *entry = NULL;
  1182. struct lpfc_iocbq *cmdiocbq = NULL;
  1183. struct lpfc_iocbq rspiocbq;
  1184. struct lpfc_pgp *pgp;
  1185. uint32_t status;
  1186. uint32_t portRspPut, portRspMax;
  1187. int type;
  1188. uint32_t rsp_cmpl = 0;
  1189. uint32_t ha_copy;
  1190. unsigned long iflags;
  1191. pring->stats.iocb_event++;
  1192. pgp = (phba->sli_rev == 3) ?
  1193. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  1194. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1195. /*
  1196. * The next available response entry should never exceed the maximum
  1197. * entries. If it does, treat it as an adapter hardware error.
  1198. */
  1199. portRspMax = pring->numRiocb;
  1200. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1201. if (unlikely(portRspPut >= portRspMax)) {
  1202. lpfc_sli_rsp_pointers_error(phba, pring);
  1203. return;
  1204. }
  1205. rmb();
  1206. while (pring->rspidx != portRspPut) {
  1207. entry = lpfc_resp_iocb(phba, pring);
  1208. if (++pring->rspidx >= portRspMax)
  1209. pring->rspidx = 0;
  1210. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  1211. (uint32_t *) &rspiocbq.iocb,
  1212. phba->iocb_rsp_size);
  1213. irsp = &rspiocbq.iocb;
  1214. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  1215. pring->stats.iocb_rsp++;
  1216. rsp_cmpl++;
  1217. if (unlikely(irsp->ulpStatus)) {
  1218. /* Rsp ring <ringno> error: IOCB */
  1219. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1220. "0326 Rsp Ring %d error: IOCB Data: "
  1221. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1222. pring->ringno,
  1223. irsp->un.ulpWord[0],
  1224. irsp->un.ulpWord[1],
  1225. irsp->un.ulpWord[2],
  1226. irsp->un.ulpWord[3],
  1227. irsp->un.ulpWord[4],
  1228. irsp->un.ulpWord[5],
  1229. *(((uint32_t *) irsp) + 6),
  1230. *(((uint32_t *) irsp) + 7));
  1231. }
  1232. switch (type) {
  1233. case LPFC_ABORT_IOCB:
  1234. case LPFC_SOL_IOCB:
  1235. /*
  1236. * Idle exchange closed via ABTS from port. No iocb
  1237. * resources need to be recovered.
  1238. */
  1239. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  1240. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1241. "0314 IOCB cmd 0x%x "
  1242. "processed. Skipping "
  1243. "completion",
  1244. irsp->ulpCommand);
  1245. break;
  1246. }
  1247. spin_lock_irqsave(&phba->hbalock, iflags);
  1248. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  1249. &rspiocbq);
  1250. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1251. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  1252. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  1253. &rspiocbq);
  1254. }
  1255. break;
  1256. default:
  1257. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  1258. char adaptermsg[LPFC_MAX_ADPTMSG];
  1259. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  1260. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  1261. MAX_MSG_DATA);
  1262. dev_warn(&((phba->pcidev)->dev),
  1263. "lpfc%d: %s\n",
  1264. phba->brd_no, adaptermsg);
  1265. } else {
  1266. /* Unknown IOCB command */
  1267. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1268. "0321 Unknown IOCB command "
  1269. "Data: x%x, x%x x%x x%x x%x\n",
  1270. type, irsp->ulpCommand,
  1271. irsp->ulpStatus,
  1272. irsp->ulpIoTag,
  1273. irsp->ulpContext);
  1274. }
  1275. break;
  1276. }
  1277. /*
  1278. * The response IOCB has been processed. Update the ring
  1279. * pointer in SLIM. If the port response put pointer has not
  1280. * been updated, sync the pgp->rspPutInx and fetch the new port
  1281. * response put pointer.
  1282. */
  1283. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  1284. if (pring->rspidx == portRspPut)
  1285. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1286. }
  1287. ha_copy = readl(phba->HAregaddr);
  1288. ha_copy >>= (LPFC_FCP_RING * 4);
  1289. if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
  1290. spin_lock_irqsave(&phba->hbalock, iflags);
  1291. pring->stats.iocb_rsp_full++;
  1292. status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
  1293. writel(status, phba->CAregaddr);
  1294. readl(phba->CAregaddr);
  1295. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1296. }
  1297. if ((ha_copy & HA_R0CE_RSP) &&
  1298. (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  1299. spin_lock_irqsave(&phba->hbalock, iflags);
  1300. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  1301. pring->stats.iocb_cmd_empty++;
  1302. /* Force update of the local copy of cmdGetInx */
  1303. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1304. lpfc_sli_resume_iocb(phba, pring);
  1305. if ((pring->lpfc_sli_cmd_available))
  1306. (pring->lpfc_sli_cmd_available) (phba, pring);
  1307. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1308. }
  1309. return;
  1310. }
  1311. /*
  1312. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  1313. * to check it explicitly.
  1314. */
  1315. static int
  1316. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  1317. struct lpfc_sli_ring *pring, uint32_t mask)
  1318. {
  1319. struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
  1320. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  1321. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1322. IOCB_t *irsp = NULL;
  1323. IOCB_t *entry = NULL;
  1324. struct lpfc_iocbq *cmdiocbq = NULL;
  1325. struct lpfc_iocbq rspiocbq;
  1326. uint32_t status;
  1327. uint32_t portRspPut, portRspMax;
  1328. int rc = 1;
  1329. lpfc_iocb_type type;
  1330. unsigned long iflag;
  1331. uint32_t rsp_cmpl = 0;
  1332. spin_lock_irqsave(&phba->hbalock, iflag);
  1333. pring->stats.iocb_event++;
  1334. /*
  1335. * The next available response entry should never exceed the maximum
  1336. * entries. If it does, treat it as an adapter hardware error.
  1337. */
  1338. portRspMax = pring->numRiocb;
  1339. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1340. if (unlikely(portRspPut >= portRspMax)) {
  1341. lpfc_sli_rsp_pointers_error(phba, pring);
  1342. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1343. return 1;
  1344. }
  1345. rmb();
  1346. while (pring->rspidx != portRspPut) {
  1347. /*
  1348. * Fetch an entry off the ring and copy it into a local data
  1349. * structure. The copy involves a byte-swap since the
  1350. * network byte order and pci byte orders are different.
  1351. */
  1352. entry = lpfc_resp_iocb(phba, pring);
  1353. phba->last_completion_time = jiffies;
  1354. if (++pring->rspidx >= portRspMax)
  1355. pring->rspidx = 0;
  1356. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  1357. (uint32_t *) &rspiocbq.iocb,
  1358. phba->iocb_rsp_size);
  1359. INIT_LIST_HEAD(&(rspiocbq.list));
  1360. irsp = &rspiocbq.iocb;
  1361. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  1362. pring->stats.iocb_rsp++;
  1363. rsp_cmpl++;
  1364. if (unlikely(irsp->ulpStatus)) {
  1365. /*
  1366. * If resource errors reported from HBA, reduce
  1367. * queuedepths of the SCSI device.
  1368. */
  1369. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  1370. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  1371. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1372. lpfc_adjust_queue_depth(phba);
  1373. spin_lock_irqsave(&phba->hbalock, iflag);
  1374. }
  1375. /* Rsp ring <ringno> error: IOCB */
  1376. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1377. "0336 Rsp Ring %d error: IOCB Data: "
  1378. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1379. pring->ringno,
  1380. irsp->un.ulpWord[0],
  1381. irsp->un.ulpWord[1],
  1382. irsp->un.ulpWord[2],
  1383. irsp->un.ulpWord[3],
  1384. irsp->un.ulpWord[4],
  1385. irsp->un.ulpWord[5],
  1386. *(((uint32_t *) irsp) + 6),
  1387. *(((uint32_t *) irsp) + 7));
  1388. }
  1389. switch (type) {
  1390. case LPFC_ABORT_IOCB:
  1391. case LPFC_SOL_IOCB:
  1392. /*
  1393. * Idle exchange closed via ABTS from port. No iocb
  1394. * resources need to be recovered.
  1395. */
  1396. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  1397. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1398. "0333 IOCB cmd 0x%x"
  1399. " processed. Skipping"
  1400. " completion\n",
  1401. irsp->ulpCommand);
  1402. break;
  1403. }
  1404. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  1405. &rspiocbq);
  1406. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  1407. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  1408. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  1409. &rspiocbq);
  1410. } else {
  1411. spin_unlock_irqrestore(&phba->hbalock,
  1412. iflag);
  1413. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  1414. &rspiocbq);
  1415. spin_lock_irqsave(&phba->hbalock,
  1416. iflag);
  1417. }
  1418. }
  1419. break;
  1420. case LPFC_UNSOL_IOCB:
  1421. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1422. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  1423. spin_lock_irqsave(&phba->hbalock, iflag);
  1424. break;
  1425. default:
  1426. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  1427. char adaptermsg[LPFC_MAX_ADPTMSG];
  1428. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  1429. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  1430. MAX_MSG_DATA);
  1431. dev_warn(&((phba->pcidev)->dev),
  1432. "lpfc%d: %s\n",
  1433. phba->brd_no, adaptermsg);
  1434. } else {
  1435. /* Unknown IOCB command */
  1436. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1437. "0334 Unknown IOCB command "
  1438. "Data: x%x, x%x x%x x%x x%x\n",
  1439. type, irsp->ulpCommand,
  1440. irsp->ulpStatus,
  1441. irsp->ulpIoTag,
  1442. irsp->ulpContext);
  1443. }
  1444. break;
  1445. }
  1446. /*
  1447. * The response IOCB has been processed. Update the ring
  1448. * pointer in SLIM. If the port response put pointer has not
  1449. * been updated, sync the pgp->rspPutInx and fetch the new port
  1450. * response put pointer.
  1451. */
  1452. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  1453. if (pring->rspidx == portRspPut)
  1454. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1455. }
  1456. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  1457. pring->stats.iocb_rsp_full++;
  1458. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  1459. writel(status, phba->CAregaddr);
  1460. readl(phba->CAregaddr);
  1461. }
  1462. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  1463. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  1464. pring->stats.iocb_cmd_empty++;
  1465. /* Force update of the local copy of cmdGetInx */
  1466. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1467. lpfc_sli_resume_iocb(phba, pring);
  1468. if ((pring->lpfc_sli_cmd_available))
  1469. (pring->lpfc_sli_cmd_available) (phba, pring);
  1470. }
  1471. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1472. return rc;
  1473. }
  1474. int
  1475. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  1476. struct lpfc_sli_ring *pring, uint32_t mask)
  1477. {
  1478. struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
  1479. &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
  1480. &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1481. IOCB_t *entry;
  1482. IOCB_t *irsp = NULL;
  1483. struct lpfc_iocbq *rspiocbp = NULL;
  1484. struct lpfc_iocbq *next_iocb;
  1485. struct lpfc_iocbq *cmdiocbp;
  1486. struct lpfc_iocbq *saveq;
  1487. uint8_t iocb_cmd_type;
  1488. lpfc_iocb_type type;
  1489. uint32_t status, free_saveq;
  1490. uint32_t portRspPut, portRspMax;
  1491. int rc = 1;
  1492. unsigned long iflag;
  1493. spin_lock_irqsave(&phba->hbalock, iflag);
  1494. pring->stats.iocb_event++;
  1495. /*
  1496. * The next available response entry should never exceed the maximum
  1497. * entries. If it does, treat it as an adapter hardware error.
  1498. */
  1499. portRspMax = pring->numRiocb;
  1500. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1501. if (portRspPut >= portRspMax) {
  1502. /*
  1503. * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
  1504. * rsp ring <portRspMax>
  1505. */
  1506. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1507. "0303 Ring %d handler: portRspPut %d "
  1508. "is bigger then rsp ring %d\n",
  1509. pring->ringno, portRspPut, portRspMax);
  1510. phba->link_state = LPFC_HBA_ERROR;
  1511. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1512. phba->work_hs = HS_FFER3;
  1513. lpfc_handle_eratt(phba);
  1514. return 1;
  1515. }
  1516. rmb();
  1517. while (pring->rspidx != portRspPut) {
  1518. /*
  1519. * Build a completion list and call the appropriate handler.
  1520. * The process is to get the next available response iocb, get
  1521. * a free iocb from the list, copy the response data into the
  1522. * free iocb, insert to the continuation list, and update the
  1523. * next response index to slim. This process makes response
  1524. * iocb's in the ring available to DMA as fast as possible but
  1525. * pays a penalty for a copy operation. Since the iocb is
  1526. * only 32 bytes, this penalty is considered small relative to
  1527. * the PCI reads for register values and a slim write. When
  1528. * the ulpLe field is set, the entire Command has been
  1529. * received.
  1530. */
  1531. entry = lpfc_resp_iocb(phba, pring);
  1532. phba->last_completion_time = jiffies;
  1533. rspiocbp = __lpfc_sli_get_iocbq(phba);
  1534. if (rspiocbp == NULL) {
  1535. printk(KERN_ERR "%s: out of buffers! Failing "
  1536. "completion.\n", __FUNCTION__);
  1537. break;
  1538. }
  1539. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  1540. phba->iocb_rsp_size);
  1541. irsp = &rspiocbp->iocb;
  1542. if (++pring->rspidx >= portRspMax)
  1543. pring->rspidx = 0;
  1544. if (pring->ringno == LPFC_ELS_RING) {
  1545. lpfc_debugfs_slow_ring_trc(phba,
  1546. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1547. *(((uint32_t *) irsp) + 4),
  1548. *(((uint32_t *) irsp) + 6),
  1549. *(((uint32_t *) irsp) + 7));
  1550. }
  1551. writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
  1552. list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
  1553. pring->iocb_continueq_cnt++;
  1554. if (irsp->ulpLe) {
  1555. /*
  1556. * By default, the driver expects to free all resources
  1557. * associated with this iocb completion.
  1558. */
  1559. free_saveq = 1;
  1560. saveq = list_get_first(&pring->iocb_continueq,
  1561. struct lpfc_iocbq, list);
  1562. irsp = &(saveq->iocb);
  1563. list_del_init(&pring->iocb_continueq);
  1564. pring->iocb_continueq_cnt = 0;
  1565. pring->stats.iocb_rsp++;
  1566. /*
  1567. * If resource errors reported from HBA, reduce
  1568. * queuedepths of the SCSI device.
  1569. */
  1570. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  1571. (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
  1572. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1573. lpfc_adjust_queue_depth(phba);
  1574. spin_lock_irqsave(&phba->hbalock, iflag);
  1575. }
  1576. if (irsp->ulpStatus) {
  1577. /* Rsp ring <ringno> error: IOCB */
  1578. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1579. "0328 Rsp Ring %d error: "
  1580. "IOCB Data: "
  1581. "x%x x%x x%x x%x "
  1582. "x%x x%x x%x x%x "
  1583. "x%x x%x x%x x%x "
  1584. "x%x x%x x%x x%x\n",
  1585. pring->ringno,
  1586. irsp->un.ulpWord[0],
  1587. irsp->un.ulpWord[1],
  1588. irsp->un.ulpWord[2],
  1589. irsp->un.ulpWord[3],
  1590. irsp->un.ulpWord[4],
  1591. irsp->un.ulpWord[5],
  1592. *(((uint32_t *) irsp) + 6),
  1593. *(((uint32_t *) irsp) + 7),
  1594. *(((uint32_t *) irsp) + 8),
  1595. *(((uint32_t *) irsp) + 9),
  1596. *(((uint32_t *) irsp) + 10),
  1597. *(((uint32_t *) irsp) + 11),
  1598. *(((uint32_t *) irsp) + 12),
  1599. *(((uint32_t *) irsp) + 13),
  1600. *(((uint32_t *) irsp) + 14),
  1601. *(((uint32_t *) irsp) + 15));
  1602. }
  1603. /*
  1604. * Fetch the IOCB command type and call the correct
  1605. * completion routine. Solicited and Unsolicited
  1606. * IOCBs on the ELS ring get freed back to the
  1607. * lpfc_iocb_list by the discovery kernel thread.
  1608. */
  1609. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  1610. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  1611. if (type == LPFC_SOL_IOCB) {
  1612. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1613. rc = lpfc_sli_process_sol_iocb(phba, pring,
  1614. saveq);
  1615. spin_lock_irqsave(&phba->hbalock, iflag);
  1616. } else if (type == LPFC_UNSOL_IOCB) {
  1617. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1618. rc = lpfc_sli_process_unsol_iocb(phba, pring,
  1619. saveq);
  1620. spin_lock_irqsave(&phba->hbalock, iflag);
  1621. if (!rc)
  1622. free_saveq = 0;
  1623. } else if (type == LPFC_ABORT_IOCB) {
  1624. if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
  1625. ((cmdiocbp =
  1626. lpfc_sli_iocbq_lookup(phba, pring,
  1627. saveq)))) {
  1628. /* Call the specified completion
  1629. routine */
  1630. if (cmdiocbp->iocb_cmpl) {
  1631. spin_unlock_irqrestore(
  1632. &phba->hbalock,
  1633. iflag);
  1634. (cmdiocbp->iocb_cmpl) (phba,
  1635. cmdiocbp, saveq);
  1636. spin_lock_irqsave(
  1637. &phba->hbalock,
  1638. iflag);
  1639. } else
  1640. __lpfc_sli_release_iocbq(phba,
  1641. cmdiocbp);
  1642. }
  1643. } else if (type == LPFC_UNKNOWN_IOCB) {
  1644. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  1645. char adaptermsg[LPFC_MAX_ADPTMSG];
  1646. memset(adaptermsg, 0,
  1647. LPFC_MAX_ADPTMSG);
  1648. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  1649. MAX_MSG_DATA);
  1650. dev_warn(&((phba->pcidev)->dev),
  1651. "lpfc%d: %s\n",
  1652. phba->brd_no, adaptermsg);
  1653. } else {
  1654. /* Unknown IOCB command */
  1655. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1656. "0335 Unknown IOCB "
  1657. "command Data: x%x "
  1658. "x%x x%x x%x\n",
  1659. irsp->ulpCommand,
  1660. irsp->ulpStatus,
  1661. irsp->ulpIoTag,
  1662. irsp->ulpContext);
  1663. }
  1664. }
  1665. if (free_saveq) {
  1666. list_for_each_entry_safe(rspiocbp, next_iocb,
  1667. &saveq->list, list) {
  1668. list_del(&rspiocbp->list);
  1669. __lpfc_sli_release_iocbq(phba,
  1670. rspiocbp);
  1671. }
  1672. __lpfc_sli_release_iocbq(phba, saveq);
  1673. }
  1674. rspiocbp = NULL;
  1675. }
  1676. /*
  1677. * If the port response put pointer has not been updated, sync
  1678. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  1679. * response put pointer.
  1680. */
  1681. if (pring->rspidx == portRspPut) {
  1682. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1683. }
  1684. } /* while (pring->rspidx != portRspPut) */
  1685. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  1686. /* At least one response entry has been freed */
  1687. pring->stats.iocb_rsp_full++;
  1688. /* SET RxRE_RSP in Chip Att register */
  1689. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  1690. writel(status, phba->CAregaddr);
  1691. readl(phba->CAregaddr); /* flush */
  1692. }
  1693. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  1694. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  1695. pring->stats.iocb_cmd_empty++;
  1696. /* Force update of the local copy of cmdGetInx */
  1697. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1698. lpfc_sli_resume_iocb(phba, pring);
  1699. if ((pring->lpfc_sli_cmd_available))
  1700. (pring->lpfc_sli_cmd_available) (phba, pring);
  1701. }
  1702. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1703. return rc;
  1704. }
  1705. void
  1706. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1707. {
  1708. LIST_HEAD(completions);
  1709. struct lpfc_iocbq *iocb, *next_iocb;
  1710. IOCB_t *cmd = NULL;
  1711. if (pring->ringno == LPFC_ELS_RING) {
  1712. lpfc_fabric_abort_hba(phba);
  1713. }
  1714. /* Error everything on txq and txcmplq
  1715. * First do the txq.
  1716. */
  1717. spin_lock_irq(&phba->hbalock);
  1718. list_splice_init(&pring->txq, &completions);
  1719. pring->txq_cnt = 0;
  1720. /* Next issue ABTS for everything on the txcmplq */
  1721. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  1722. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  1723. spin_unlock_irq(&phba->hbalock);
  1724. while (!list_empty(&completions)) {
  1725. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  1726. cmd = &iocb->iocb;
  1727. list_del_init(&iocb->list);
  1728. if (!iocb->iocb_cmpl)
  1729. lpfc_sli_release_iocbq(phba, iocb);
  1730. else {
  1731. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  1732. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  1733. (iocb->iocb_cmpl) (phba, iocb, iocb);
  1734. }
  1735. }
  1736. }
  1737. int
  1738. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  1739. {
  1740. uint32_t status;
  1741. int i = 0;
  1742. int retval = 0;
  1743. /* Read the HBA Host Status Register */
  1744. status = readl(phba->HSregaddr);
  1745. /*
  1746. * Check status register every 100ms for 5 retries, then every
  1747. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  1748. * every 2.5 sec for 4.
  1749. * Break our of the loop if errors occurred during init.
  1750. */
  1751. while (((status & mask) != mask) &&
  1752. !(status & HS_FFERM) &&
  1753. i++ < 20) {
  1754. if (i <= 5)
  1755. msleep(10);
  1756. else if (i <= 10)
  1757. msleep(500);
  1758. else
  1759. msleep(2500);
  1760. if (i == 15) {
  1761. /* Do post */
  1762. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  1763. lpfc_sli_brdrestart(phba);
  1764. }
  1765. /* Read the HBA Host Status Register */
  1766. status = readl(phba->HSregaddr);
  1767. }
  1768. /* Check to see if any errors occurred during init */
  1769. if ((status & HS_FFERM) || (i >= 20)) {
  1770. phba->link_state = LPFC_HBA_ERROR;
  1771. retval = 1;
  1772. }
  1773. return retval;
  1774. }
  1775. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  1776. void lpfc_reset_barrier(struct lpfc_hba *phba)
  1777. {
  1778. uint32_t __iomem *resp_buf;
  1779. uint32_t __iomem *mbox_buf;
  1780. volatile uint32_t mbox;
  1781. uint32_t hc_copy;
  1782. int i;
  1783. uint8_t hdrtype;
  1784. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  1785. if (hdrtype != 0x80 ||
  1786. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  1787. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  1788. return;
  1789. /*
  1790. * Tell the other part of the chip to suspend temporarily all
  1791. * its DMA activity.
  1792. */
  1793. resp_buf = phba->MBslimaddr;
  1794. /* Disable the error attention */
  1795. hc_copy = readl(phba->HCregaddr);
  1796. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  1797. readl(phba->HCregaddr); /* flush */
  1798. phba->link_flag |= LS_IGNORE_ERATT;
  1799. if (readl(phba->HAregaddr) & HA_ERATT) {
  1800. /* Clear Chip error bit */
  1801. writel(HA_ERATT, phba->HAregaddr);
  1802. phba->pport->stopped = 1;
  1803. }
  1804. mbox = 0;
  1805. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  1806. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  1807. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  1808. mbox_buf = phba->MBslimaddr;
  1809. writel(mbox, mbox_buf);
  1810. for (i = 0;
  1811. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  1812. mdelay(1);
  1813. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  1814. if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
  1815. phba->pport->stopped)
  1816. goto restore_hc;
  1817. else
  1818. goto clear_errat;
  1819. }
  1820. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  1821. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  1822. mdelay(1);
  1823. clear_errat:
  1824. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  1825. mdelay(1);
  1826. if (readl(phba->HAregaddr) & HA_ERATT) {
  1827. writel(HA_ERATT, phba->HAregaddr);
  1828. phba->pport->stopped = 1;
  1829. }
  1830. restore_hc:
  1831. phba->link_flag &= ~LS_IGNORE_ERATT;
  1832. writel(hc_copy, phba->HCregaddr);
  1833. readl(phba->HCregaddr); /* flush */
  1834. }
  1835. int
  1836. lpfc_sli_brdkill(struct lpfc_hba *phba)
  1837. {
  1838. struct lpfc_sli *psli;
  1839. LPFC_MBOXQ_t *pmb;
  1840. uint32_t status;
  1841. uint32_t ha_copy;
  1842. int retval;
  1843. int i = 0;
  1844. psli = &phba->sli;
  1845. /* Kill HBA */
  1846. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1847. "0329 Kill HBA Data: x%x x%x\n",
  1848. phba->pport->port_state, psli->sli_flag);
  1849. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1850. if (!pmb)
  1851. return 1;
  1852. /* Disable the error attention */
  1853. spin_lock_irq(&phba->hbalock);
  1854. status = readl(phba->HCregaddr);
  1855. status &= ~HC_ERINT_ENA;
  1856. writel(status, phba->HCregaddr);
  1857. readl(phba->HCregaddr); /* flush */
  1858. phba->link_flag |= LS_IGNORE_ERATT;
  1859. spin_unlock_irq(&phba->hbalock);
  1860. lpfc_kill_board(phba, pmb);
  1861. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1862. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1863. if (retval != MBX_SUCCESS) {
  1864. if (retval != MBX_BUSY)
  1865. mempool_free(pmb, phba->mbox_mem_pool);
  1866. spin_lock_irq(&phba->hbalock);
  1867. phba->link_flag &= ~LS_IGNORE_ERATT;
  1868. spin_unlock_irq(&phba->hbalock);
  1869. return 1;
  1870. }
  1871. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  1872. mempool_free(pmb, phba->mbox_mem_pool);
  1873. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  1874. * attention every 100ms for 3 seconds. If we don't get ERATT after
  1875. * 3 seconds we still set HBA_ERROR state because the status of the
  1876. * board is now undefined.
  1877. */
  1878. ha_copy = readl(phba->HAregaddr);
  1879. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  1880. mdelay(100);
  1881. ha_copy = readl(phba->HAregaddr);
  1882. }
  1883. del_timer_sync(&psli->mbox_tmo);
  1884. if (ha_copy & HA_ERATT) {
  1885. writel(HA_ERATT, phba->HAregaddr);
  1886. phba->pport->stopped = 1;
  1887. }
  1888. spin_lock_irq(&phba->hbalock);
  1889. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  1890. phba->link_flag &= ~LS_IGNORE_ERATT;
  1891. spin_unlock_irq(&phba->hbalock);
  1892. psli->mbox_active = NULL;
  1893. lpfc_hba_down_post(phba);
  1894. phba->link_state = LPFC_HBA_ERROR;
  1895. return ha_copy & HA_ERATT ? 0 : 1;
  1896. }
  1897. int
  1898. lpfc_sli_brdreset(struct lpfc_hba *phba)
  1899. {
  1900. struct lpfc_sli *psli;
  1901. struct lpfc_sli_ring *pring;
  1902. uint16_t cfg_value;
  1903. int i;
  1904. psli = &phba->sli;
  1905. /* Reset HBA */
  1906. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1907. "0325 Reset HBA Data: x%x x%x\n",
  1908. phba->pport->port_state, psli->sli_flag);
  1909. /* perform board reset */
  1910. phba->fc_eventTag = 0;
  1911. phba->pport->fc_myDID = 0;
  1912. phba->pport->fc_prevDID = 0;
  1913. /* Turn off parity checking and serr during the physical reset */
  1914. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  1915. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  1916. (cfg_value &
  1917. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  1918. psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
  1919. /* Now toggle INITFF bit in the Host Control Register */
  1920. writel(HC_INITFF, phba->HCregaddr);
  1921. mdelay(1);
  1922. readl(phba->HCregaddr); /* flush */
  1923. writel(0, phba->HCregaddr);
  1924. readl(phba->HCregaddr); /* flush */
  1925. /* Restore PCI cmd register */
  1926. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  1927. /* Initialize relevant SLI info */
  1928. for (i = 0; i < psli->num_rings; i++) {
  1929. pring = &psli->ring[i];
  1930. pring->flag = 0;
  1931. pring->rspidx = 0;
  1932. pring->next_cmdidx = 0;
  1933. pring->local_getidx = 0;
  1934. pring->cmdidx = 0;
  1935. pring->missbufcnt = 0;
  1936. }
  1937. phba->link_state = LPFC_WARM_START;
  1938. return 0;
  1939. }
  1940. int
  1941. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  1942. {
  1943. MAILBOX_t *mb;
  1944. struct lpfc_sli *psli;
  1945. uint16_t skip_post;
  1946. volatile uint32_t word0;
  1947. void __iomem *to_slim;
  1948. spin_lock_irq(&phba->hbalock);
  1949. psli = &phba->sli;
  1950. /* Restart HBA */
  1951. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1952. "0337 Restart HBA Data: x%x x%x\n",
  1953. phba->pport->port_state, psli->sli_flag);
  1954. word0 = 0;
  1955. mb = (MAILBOX_t *) &word0;
  1956. mb->mbxCommand = MBX_RESTART;
  1957. mb->mbxHc = 1;
  1958. lpfc_reset_barrier(phba);
  1959. to_slim = phba->MBslimaddr;
  1960. writel(*(uint32_t *) mb, to_slim);
  1961. readl(to_slim); /* flush */
  1962. /* Only skip post after fc_ffinit is completed */
  1963. if (phba->pport->port_state) {
  1964. skip_post = 1;
  1965. word0 = 1; /* This is really setting up word1 */
  1966. } else {
  1967. skip_post = 0;
  1968. word0 = 0; /* This is really setting up word1 */
  1969. }
  1970. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  1971. writel(*(uint32_t *) mb, to_slim);
  1972. readl(to_slim); /* flush */
  1973. lpfc_sli_brdreset(phba);
  1974. phba->pport->stopped = 0;
  1975. phba->link_state = LPFC_INIT_START;
  1976. spin_unlock_irq(&phba->hbalock);
  1977. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  1978. psli->stats_start = get_seconds();
  1979. if (skip_post)
  1980. mdelay(100);
  1981. else
  1982. mdelay(2000);
  1983. lpfc_hba_down_post(phba);
  1984. return 0;
  1985. }
  1986. static int
  1987. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  1988. {
  1989. uint32_t status, i = 0;
  1990. /* Read the HBA Host Status Register */
  1991. status = readl(phba->HSregaddr);
  1992. /* Check status register to see what current state is */
  1993. i = 0;
  1994. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  1995. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  1996. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  1997. * 4.
  1998. */
  1999. if (i++ >= 20) {
  2000. /* Adapter failed to init, timeout, status reg
  2001. <status> */
  2002. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2003. "0436 Adapter failed to init, "
  2004. "timeout, status reg x%x, "
  2005. "FW Data: A8 x%x AC x%x\n", status,
  2006. readl(phba->MBslimaddr + 0xa8),
  2007. readl(phba->MBslimaddr + 0xac));
  2008. phba->link_state = LPFC_HBA_ERROR;
  2009. return -ETIMEDOUT;
  2010. }
  2011. /* Check to see if any errors occurred during init */
  2012. if (status & HS_FFERM) {
  2013. /* ERROR: During chipset initialization */
  2014. /* Adapter failed to init, chipset, status reg
  2015. <status> */
  2016. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2017. "0437 Adapter failed to init, "
  2018. "chipset, status reg x%x, "
  2019. "FW Data: A8 x%x AC x%x\n", status,
  2020. readl(phba->MBslimaddr + 0xa8),
  2021. readl(phba->MBslimaddr + 0xac));
  2022. phba->link_state = LPFC_HBA_ERROR;
  2023. return -EIO;
  2024. }
  2025. if (i <= 5) {
  2026. msleep(10);
  2027. } else if (i <= 10) {
  2028. msleep(500);
  2029. } else {
  2030. msleep(2500);
  2031. }
  2032. if (i == 15) {
  2033. /* Do post */
  2034. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2035. lpfc_sli_brdrestart(phba);
  2036. }
  2037. /* Read the HBA Host Status Register */
  2038. status = readl(phba->HSregaddr);
  2039. }
  2040. /* Check to see if any errors occurred during init */
  2041. if (status & HS_FFERM) {
  2042. /* ERROR: During chipset initialization */
  2043. /* Adapter failed to init, chipset, status reg <status> */
  2044. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2045. "0438 Adapter failed to init, chipset, "
  2046. "status reg x%x, "
  2047. "FW Data: A8 x%x AC x%x\n", status,
  2048. readl(phba->MBslimaddr + 0xa8),
  2049. readl(phba->MBslimaddr + 0xac));
  2050. phba->link_state = LPFC_HBA_ERROR;
  2051. return -EIO;
  2052. }
  2053. /* Clear all interrupt enable conditions */
  2054. writel(0, phba->HCregaddr);
  2055. readl(phba->HCregaddr); /* flush */
  2056. /* setup host attn register */
  2057. writel(0xffffffff, phba->HAregaddr);
  2058. readl(phba->HAregaddr); /* flush */
  2059. return 0;
  2060. }
  2061. int
  2062. lpfc_sli_hbq_count(void)
  2063. {
  2064. return ARRAY_SIZE(lpfc_hbq_defs);
  2065. }
  2066. static int
  2067. lpfc_sli_hbq_entry_count(void)
  2068. {
  2069. int hbq_count = lpfc_sli_hbq_count();
  2070. int count = 0;
  2071. int i;
  2072. for (i = 0; i < hbq_count; ++i)
  2073. count += lpfc_hbq_defs[i]->entry_count;
  2074. return count;
  2075. }
  2076. int
  2077. lpfc_sli_hbq_size(void)
  2078. {
  2079. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  2080. }
  2081. static int
  2082. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  2083. {
  2084. int hbq_count = lpfc_sli_hbq_count();
  2085. LPFC_MBOXQ_t *pmb;
  2086. MAILBOX_t *pmbox;
  2087. uint32_t hbqno;
  2088. uint32_t hbq_entry_index;
  2089. /* Get a Mailbox buffer to setup mailbox
  2090. * commands for HBA initialization
  2091. */
  2092. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2093. if (!pmb)
  2094. return -ENOMEM;
  2095. pmbox = &pmb->mb;
  2096. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  2097. phba->link_state = LPFC_INIT_MBX_CMDS;
  2098. phba->hbq_in_use = 1;
  2099. hbq_entry_index = 0;
  2100. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  2101. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  2102. phba->hbqs[hbqno].hbqPutIdx = 0;
  2103. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  2104. phba->hbqs[hbqno].entry_count =
  2105. lpfc_hbq_defs[hbqno]->entry_count;
  2106. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  2107. hbq_entry_index, pmb);
  2108. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  2109. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  2110. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  2111. mbxStatus <status>, ring <num> */
  2112. lpfc_printf_log(phba, KERN_ERR,
  2113. LOG_SLI | LOG_VPORT,
  2114. "1805 Adapter failed to init. "
  2115. "Data: x%x x%x x%x\n",
  2116. pmbox->mbxCommand,
  2117. pmbox->mbxStatus, hbqno);
  2118. phba->link_state = LPFC_HBA_ERROR;
  2119. mempool_free(pmb, phba->mbox_mem_pool);
  2120. return ENXIO;
  2121. }
  2122. }
  2123. phba->hbq_count = hbq_count;
  2124. mempool_free(pmb, phba->mbox_mem_pool);
  2125. /* Initially populate or replenish the HBQs */
  2126. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  2127. if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno))
  2128. return -ENOMEM;
  2129. }
  2130. return 0;
  2131. }
  2132. static int
  2133. lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
  2134. {
  2135. LPFC_MBOXQ_t *pmb;
  2136. uint32_t resetcount = 0, rc = 0, done = 0;
  2137. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2138. if (!pmb) {
  2139. phba->link_state = LPFC_HBA_ERROR;
  2140. return -ENOMEM;
  2141. }
  2142. phba->sli_rev = sli_mode;
  2143. while (resetcount < 2 && !done) {
  2144. spin_lock_irq(&phba->hbalock);
  2145. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  2146. spin_unlock_irq(&phba->hbalock);
  2147. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  2148. lpfc_sli_brdrestart(phba);
  2149. msleep(2500);
  2150. rc = lpfc_sli_chipset_init(phba);
  2151. if (rc)
  2152. break;
  2153. spin_lock_irq(&phba->hbalock);
  2154. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2155. spin_unlock_irq(&phba->hbalock);
  2156. resetcount++;
  2157. /* Call pre CONFIG_PORT mailbox command initialization. A
  2158. * value of 0 means the call was successful. Any other
  2159. * nonzero value is a failure, but if ERESTART is returned,
  2160. * the driver may reset the HBA and try again.
  2161. */
  2162. rc = lpfc_config_port_prep(phba);
  2163. if (rc == -ERESTART) {
  2164. phba->link_state = LPFC_LINK_UNKNOWN;
  2165. continue;
  2166. } else if (rc) {
  2167. break;
  2168. }
  2169. phba->link_state = LPFC_INIT_MBX_CMDS;
  2170. lpfc_config_port(phba, pmb);
  2171. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  2172. if (rc != MBX_SUCCESS) {
  2173. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2174. "0442 Adapter failed to init, mbxCmd x%x "
  2175. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  2176. pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0);
  2177. spin_lock_irq(&phba->hbalock);
  2178. phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
  2179. spin_unlock_irq(&phba->hbalock);
  2180. rc = -ENXIO;
  2181. } else {
  2182. done = 1;
  2183. phba->max_vpi = (phba->max_vpi &&
  2184. pmb->mb.un.varCfgPort.gmv) != 0
  2185. ? pmb->mb.un.varCfgPort.max_vpi
  2186. : 0;
  2187. }
  2188. }
  2189. if (!done) {
  2190. rc = -EINVAL;
  2191. goto do_prep_failed;
  2192. }
  2193. if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
  2194. (!pmb->mb.un.varCfgPort.cMA)) {
  2195. rc = -ENXIO;
  2196. }
  2197. do_prep_failed:
  2198. mempool_free(pmb, phba->mbox_mem_pool);
  2199. return rc;
  2200. }
  2201. int
  2202. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  2203. {
  2204. uint32_t rc;
  2205. int mode = 3;
  2206. switch (lpfc_sli_mode) {
  2207. case 2:
  2208. if (phba->cfg_enable_npiv) {
  2209. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  2210. "1824 NPIV enabled: Override lpfc_sli_mode "
  2211. "parameter (%d) to auto (0).\n",
  2212. lpfc_sli_mode);
  2213. break;
  2214. }
  2215. mode = 2;
  2216. break;
  2217. case 0:
  2218. case 3:
  2219. break;
  2220. default:
  2221. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  2222. "1819 Unrecognized lpfc_sli_mode "
  2223. "parameter: %d.\n", lpfc_sli_mode);
  2224. break;
  2225. }
  2226. rc = lpfc_do_config_port(phba, mode);
  2227. if (rc && lpfc_sli_mode == 3)
  2228. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
  2229. "1820 Unable to select SLI-3. "
  2230. "Not supported by adapter.\n");
  2231. if (rc && mode != 2)
  2232. rc = lpfc_do_config_port(phba, 2);
  2233. if (rc)
  2234. goto lpfc_sli_hba_setup_error;
  2235. if (phba->sli_rev == 3) {
  2236. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  2237. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  2238. phba->sli3_options |= LPFC_SLI3_ENABLED;
  2239. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  2240. } else {
  2241. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  2242. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  2243. phba->sli3_options = 0;
  2244. }
  2245. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2246. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  2247. phba->sli_rev, phba->max_vpi);
  2248. rc = lpfc_sli_ring_map(phba);
  2249. if (rc)
  2250. goto lpfc_sli_hba_setup_error;
  2251. /* Init HBQs */
  2252. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  2253. rc = lpfc_sli_hbq_setup(phba);
  2254. if (rc)
  2255. goto lpfc_sli_hba_setup_error;
  2256. }
  2257. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  2258. rc = lpfc_config_port_post(phba);
  2259. if (rc)
  2260. goto lpfc_sli_hba_setup_error;
  2261. return rc;
  2262. lpfc_sli_hba_setup_error:
  2263. phba->link_state = LPFC_HBA_ERROR;
  2264. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2265. "0445 Firmware initialization failed\n");
  2266. return rc;
  2267. }
  2268. /*! lpfc_mbox_timeout
  2269. *
  2270. * \pre
  2271. * \post
  2272. * \param hba Pointer to per struct lpfc_hba structure
  2273. * \param l1 Pointer to the driver's mailbox queue.
  2274. * \return
  2275. * void
  2276. *
  2277. * \b Description:
  2278. *
  2279. * This routine handles mailbox timeout events at timer interrupt context.
  2280. */
  2281. void
  2282. lpfc_mbox_timeout(unsigned long ptr)
  2283. {
  2284. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  2285. unsigned long iflag;
  2286. uint32_t tmo_posted;
  2287. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  2288. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  2289. if (!tmo_posted)
  2290. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  2291. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  2292. if (!tmo_posted)
  2293. lpfc_worker_wake_up(phba);
  2294. return;
  2295. }
  2296. void
  2297. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  2298. {
  2299. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  2300. MAILBOX_t *mb = &pmbox->mb;
  2301. struct lpfc_sli *psli = &phba->sli;
  2302. struct lpfc_sli_ring *pring;
  2303. if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
  2304. return;
  2305. }
  2306. /* Mbox cmd <mbxCommand> timeout */
  2307. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2308. "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  2309. mb->mbxCommand,
  2310. phba->pport->port_state,
  2311. phba->sli.sli_flag,
  2312. phba->sli.mbox_active);
  2313. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  2314. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  2315. * it to fail all oustanding SCSI IO.
  2316. */
  2317. spin_lock_irq(&phba->pport->work_port_lock);
  2318. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  2319. spin_unlock_irq(&phba->pport->work_port_lock);
  2320. spin_lock_irq(&phba->hbalock);
  2321. phba->link_state = LPFC_LINK_UNKNOWN;
  2322. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  2323. spin_unlock_irq(&phba->hbalock);
  2324. pring = &psli->ring[psli->fcp_ring];
  2325. lpfc_sli_abort_iocb_ring(phba, pring);
  2326. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  2327. "0345 Resetting board due to mailbox timeout\n");
  2328. /*
  2329. * lpfc_offline calls lpfc_sli_hba_down which will clean up
  2330. * on oustanding mailbox commands.
  2331. */
  2332. /* If resets are disabled then set error state and return. */
  2333. if (!phba->cfg_enable_hba_reset) {
  2334. phba->link_state = LPFC_HBA_ERROR;
  2335. return;
  2336. }
  2337. lpfc_offline_prep(phba);
  2338. lpfc_offline(phba);
  2339. lpfc_sli_brdrestart(phba);
  2340. lpfc_online(phba);
  2341. lpfc_unblock_mgmt_io(phba);
  2342. return;
  2343. }
  2344. int
  2345. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  2346. {
  2347. MAILBOX_t *mb;
  2348. struct lpfc_sli *psli = &phba->sli;
  2349. uint32_t status, evtctr;
  2350. uint32_t ha_copy;
  2351. int i;
  2352. unsigned long timeout;
  2353. unsigned long drvr_flag = 0;
  2354. volatile uint32_t word0, ldata;
  2355. void __iomem *to_slim;
  2356. int processing_queue = 0;
  2357. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  2358. if (!pmbox) {
  2359. /* processing mbox queue from intr_handler */
  2360. processing_queue = 1;
  2361. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2362. pmbox = lpfc_mbox_get(phba);
  2363. if (!pmbox) {
  2364. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2365. return MBX_SUCCESS;
  2366. }
  2367. }
  2368. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  2369. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  2370. if(!pmbox->vport) {
  2371. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2372. lpfc_printf_log(phba, KERN_ERR,
  2373. LOG_MBOX | LOG_VPORT,
  2374. "1806 Mbox x%x failed. No vport\n",
  2375. pmbox->mb.mbxCommand);
  2376. dump_stack();
  2377. goto out_not_finished;
  2378. }
  2379. }
  2380. /* If the PCI channel is in offline state, do not post mbox. */
  2381. if (unlikely(pci_channel_offline(phba->pcidev))) {
  2382. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2383. goto out_not_finished;
  2384. }
  2385. psli = &phba->sli;
  2386. mb = &pmbox->mb;
  2387. status = MBX_SUCCESS;
  2388. if (phba->link_state == LPFC_HBA_ERROR) {
  2389. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2390. /* Mbox command <mbxCommand> cannot issue */
  2391. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2392. goto out_not_finished;
  2393. }
  2394. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  2395. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  2396. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2397. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2398. goto out_not_finished;
  2399. }
  2400. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  2401. /* Polling for a mbox command when another one is already active
  2402. * is not allowed in SLI. Also, the driver must have established
  2403. * SLI2 mode to queue and process multiple mbox commands.
  2404. */
  2405. if (flag & MBX_POLL) {
  2406. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2407. /* Mbox command <mbxCommand> cannot issue */
  2408. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2409. goto out_not_finished;
  2410. }
  2411. if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
  2412. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2413. /* Mbox command <mbxCommand> cannot issue */
  2414. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2415. goto out_not_finished;
  2416. }
  2417. /* Another mailbox command is still being processed, queue this
  2418. * command to be processed later.
  2419. */
  2420. lpfc_mbox_put(phba, pmbox);
  2421. /* Mbox cmd issue - BUSY */
  2422. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2423. "(%d):0308 Mbox cmd issue - BUSY Data: "
  2424. "x%x x%x x%x x%x\n",
  2425. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  2426. mb->mbxCommand, phba->pport->port_state,
  2427. psli->sli_flag, flag);
  2428. psli->slistat.mbox_busy++;
  2429. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2430. if (pmbox->vport) {
  2431. lpfc_debugfs_disc_trc(pmbox->vport,
  2432. LPFC_DISC_TRC_MBOX_VPORT,
  2433. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  2434. (uint32_t)mb->mbxCommand,
  2435. mb->un.varWords[0], mb->un.varWords[1]);
  2436. }
  2437. else {
  2438. lpfc_debugfs_disc_trc(phba->pport,
  2439. LPFC_DISC_TRC_MBOX,
  2440. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  2441. (uint32_t)mb->mbxCommand,
  2442. mb->un.varWords[0], mb->un.varWords[1]);
  2443. }
  2444. return MBX_BUSY;
  2445. }
  2446. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  2447. /* If we are not polling, we MUST be in SLI2 mode */
  2448. if (flag != MBX_POLL) {
  2449. if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
  2450. (mb->mbxCommand != MBX_KILL_BOARD)) {
  2451. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2452. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2453. /* Mbox command <mbxCommand> cannot issue */
  2454. LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
  2455. goto out_not_finished;
  2456. }
  2457. /* timeout active mbox command */
  2458. mod_timer(&psli->mbox_tmo, (jiffies +
  2459. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  2460. }
  2461. /* Mailbox cmd <cmd> issue */
  2462. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2463. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  2464. "x%x\n",
  2465. pmbox->vport ? pmbox->vport->vpi : 0,
  2466. mb->mbxCommand, phba->pport->port_state,
  2467. psli->sli_flag, flag);
  2468. if (mb->mbxCommand != MBX_HEARTBEAT) {
  2469. if (pmbox->vport) {
  2470. lpfc_debugfs_disc_trc(pmbox->vport,
  2471. LPFC_DISC_TRC_MBOX_VPORT,
  2472. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  2473. (uint32_t)mb->mbxCommand,
  2474. mb->un.varWords[0], mb->un.varWords[1]);
  2475. }
  2476. else {
  2477. lpfc_debugfs_disc_trc(phba->pport,
  2478. LPFC_DISC_TRC_MBOX,
  2479. "MBOX Send: cmd:x%x mb:x%x x%x",
  2480. (uint32_t)mb->mbxCommand,
  2481. mb->un.varWords[0], mb->un.varWords[1]);
  2482. }
  2483. }
  2484. psli->slistat.mbox_cmd++;
  2485. evtctr = psli->slistat.mbox_event;
  2486. /* next set own bit for the adapter and copy over command word */
  2487. mb->mbxOwner = OWN_CHIP;
  2488. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2489. /* First copy command data to host SLIM area */
  2490. lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
  2491. } else {
  2492. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  2493. /* copy command data into host mbox for cmpl */
  2494. lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
  2495. MAILBOX_CMD_SIZE);
  2496. }
  2497. /* First copy mbox command data to HBA SLIM, skip past first
  2498. word */
  2499. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  2500. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  2501. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  2502. /* Next copy over first word, with mbxOwner set */
  2503. ldata = *((volatile uint32_t *)mb);
  2504. to_slim = phba->MBslimaddr;
  2505. writel(ldata, to_slim);
  2506. readl(to_slim); /* flush */
  2507. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  2508. /* switch over to host mailbox */
  2509. psli->sli_flag |= LPFC_SLI2_ACTIVE;
  2510. }
  2511. }
  2512. wmb();
  2513. switch (flag) {
  2514. case MBX_NOWAIT:
  2515. /* Set up reference to mailbox command */
  2516. psli->mbox_active = pmbox;
  2517. /* Interrupt board to do it */
  2518. writel(CA_MBATT, phba->CAregaddr);
  2519. readl(phba->CAregaddr); /* flush */
  2520. /* Don't wait for it to finish, just return */
  2521. break;
  2522. case MBX_POLL:
  2523. /* Set up null reference to mailbox command */
  2524. psli->mbox_active = NULL;
  2525. /* Interrupt board to do it */
  2526. writel(CA_MBATT, phba->CAregaddr);
  2527. readl(phba->CAregaddr); /* flush */
  2528. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2529. /* First read mbox status word */
  2530. word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
  2531. word0 = le32_to_cpu(word0);
  2532. } else {
  2533. /* First read mbox status word */
  2534. word0 = readl(phba->MBslimaddr);
  2535. }
  2536. /* Read the HBA Host Attention Register */
  2537. ha_copy = readl(phba->HAregaddr);
  2538. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  2539. mb->mbxCommand) *
  2540. 1000) + jiffies;
  2541. i = 0;
  2542. /* Wait for command to complete */
  2543. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  2544. (!(ha_copy & HA_MBATT) &&
  2545. (phba->link_state > LPFC_WARM_START))) {
  2546. if (time_after(jiffies, timeout)) {
  2547. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2548. spin_unlock_irqrestore(&phba->hbalock,
  2549. drvr_flag);
  2550. goto out_not_finished;
  2551. }
  2552. /* Check if we took a mbox interrupt while we were
  2553. polling */
  2554. if (((word0 & OWN_CHIP) != OWN_CHIP)
  2555. && (evtctr != psli->slistat.mbox_event))
  2556. break;
  2557. if (i++ > 10) {
  2558. spin_unlock_irqrestore(&phba->hbalock,
  2559. drvr_flag);
  2560. msleep(1);
  2561. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  2562. }
  2563. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2564. /* First copy command data */
  2565. word0 = *((volatile uint32_t *)
  2566. &phba->slim2p->mbx);
  2567. word0 = le32_to_cpu(word0);
  2568. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  2569. MAILBOX_t *slimmb;
  2570. volatile uint32_t slimword0;
  2571. /* Check real SLIM for any errors */
  2572. slimword0 = readl(phba->MBslimaddr);
  2573. slimmb = (MAILBOX_t *) & slimword0;
  2574. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  2575. && slimmb->mbxStatus) {
  2576. psli->sli_flag &=
  2577. ~LPFC_SLI2_ACTIVE;
  2578. word0 = slimword0;
  2579. }
  2580. }
  2581. } else {
  2582. /* First copy command data */
  2583. word0 = readl(phba->MBslimaddr);
  2584. }
  2585. /* Read the HBA Host Attention Register */
  2586. ha_copy = readl(phba->HAregaddr);
  2587. }
  2588. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2589. /* copy results back to user */
  2590. lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
  2591. MAILBOX_CMD_SIZE);
  2592. } else {
  2593. /* First copy command data */
  2594. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  2595. MAILBOX_CMD_SIZE);
  2596. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  2597. pmbox->context2) {
  2598. lpfc_memcpy_from_slim((void *)pmbox->context2,
  2599. phba->MBslimaddr + DMP_RSP_OFFSET,
  2600. mb->un.varDmp.word_cnt);
  2601. }
  2602. }
  2603. writel(HA_MBATT, phba->HAregaddr);
  2604. readl(phba->HAregaddr); /* flush */
  2605. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2606. status = mb->mbxStatus;
  2607. }
  2608. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2609. return status;
  2610. out_not_finished:
  2611. if (processing_queue) {
  2612. pmbox->mb.mbxStatus = MBX_NOT_FINISHED;
  2613. lpfc_mbox_cmpl_put(phba, pmbox);
  2614. }
  2615. return MBX_NOT_FINISHED;
  2616. }
  2617. /*
  2618. * Caller needs to hold lock.
  2619. */
  2620. static void
  2621. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2622. struct lpfc_iocbq *piocb)
  2623. {
  2624. /* Insert the caller's iocb in the txq tail for later processing. */
  2625. list_add_tail(&piocb->list, &pring->txq);
  2626. pring->txq_cnt++;
  2627. }
  2628. static struct lpfc_iocbq *
  2629. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2630. struct lpfc_iocbq **piocb)
  2631. {
  2632. struct lpfc_iocbq * nextiocb;
  2633. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  2634. if (!nextiocb) {
  2635. nextiocb = *piocb;
  2636. *piocb = NULL;
  2637. }
  2638. return nextiocb;
  2639. }
  2640. /*
  2641. * Lockless version of lpfc_sli_issue_iocb.
  2642. */
  2643. static int
  2644. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2645. struct lpfc_iocbq *piocb, uint32_t flag)
  2646. {
  2647. struct lpfc_iocbq *nextiocb;
  2648. IOCB_t *iocb;
  2649. if (piocb->iocb_cmpl && (!piocb->vport) &&
  2650. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  2651. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  2652. lpfc_printf_log(phba, KERN_ERR,
  2653. LOG_SLI | LOG_VPORT,
  2654. "1807 IOCB x%x failed. No vport\n",
  2655. piocb->iocb.ulpCommand);
  2656. dump_stack();
  2657. return IOCB_ERROR;
  2658. }
  2659. /* If the PCI channel is in offline state, do not post iocbs. */
  2660. if (unlikely(pci_channel_offline(phba->pcidev)))
  2661. return IOCB_ERROR;
  2662. /*
  2663. * We should never get an IOCB if we are in a < LINK_DOWN state
  2664. */
  2665. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  2666. return IOCB_ERROR;
  2667. /*
  2668. * Check to see if we are blocking IOCB processing because of a
  2669. * outstanding event.
  2670. */
  2671. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  2672. goto iocb_busy;
  2673. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  2674. /*
  2675. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  2676. * can be issued if the link is not up.
  2677. */
  2678. switch (piocb->iocb.ulpCommand) {
  2679. case CMD_QUE_RING_BUF_CN:
  2680. case CMD_QUE_RING_BUF64_CN:
  2681. /*
  2682. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  2683. * completion, iocb_cmpl MUST be 0.
  2684. */
  2685. if (piocb->iocb_cmpl)
  2686. piocb->iocb_cmpl = NULL;
  2687. /*FALLTHROUGH*/
  2688. case CMD_CREATE_XRI_CR:
  2689. case CMD_CLOSE_XRI_CN:
  2690. case CMD_CLOSE_XRI_CX:
  2691. break;
  2692. default:
  2693. goto iocb_busy;
  2694. }
  2695. /*
  2696. * For FCP commands, we must be in a state where we can process link
  2697. * attention events.
  2698. */
  2699. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  2700. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  2701. goto iocb_busy;
  2702. }
  2703. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  2704. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  2705. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  2706. if (iocb)
  2707. lpfc_sli_update_ring(phba, pring);
  2708. else
  2709. lpfc_sli_update_full_ring(phba, pring);
  2710. if (!piocb)
  2711. return IOCB_SUCCESS;
  2712. goto out_busy;
  2713. iocb_busy:
  2714. pring->stats.iocb_cmd_delay++;
  2715. out_busy:
  2716. if (!(flag & SLI_IOCB_RET_IOCB)) {
  2717. __lpfc_sli_ringtx_put(phba, pring, piocb);
  2718. return IOCB_SUCCESS;
  2719. }
  2720. return IOCB_BUSY;
  2721. }
  2722. int
  2723. lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2724. struct lpfc_iocbq *piocb, uint32_t flag)
  2725. {
  2726. unsigned long iflags;
  2727. int rc;
  2728. spin_lock_irqsave(&phba->hbalock, iflags);
  2729. rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
  2730. spin_unlock_irqrestore(&phba->hbalock, iflags);
  2731. return rc;
  2732. }
  2733. static int
  2734. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  2735. {
  2736. struct lpfc_sli *psli;
  2737. struct lpfc_sli_ring *pring;
  2738. psli = &phba->sli;
  2739. /* Adjust cmd/rsp ring iocb entries more evenly */
  2740. /* Take some away from the FCP ring */
  2741. pring = &psli->ring[psli->fcp_ring];
  2742. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2743. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2744. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2745. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2746. /* and give them to the extra ring */
  2747. pring = &psli->ring[psli->extra_ring];
  2748. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2749. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2750. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2751. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2752. /* Setup default profile for this ring */
  2753. pring->iotag_max = 4096;
  2754. pring->num_mask = 1;
  2755. pring->prt[0].profile = 0; /* Mask 0 */
  2756. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  2757. pring->prt[0].type = phba->cfg_multi_ring_type;
  2758. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  2759. return 0;
  2760. }
  2761. static void
  2762. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  2763. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  2764. {
  2765. IOCB_t *icmd;
  2766. uint16_t evt_code;
  2767. uint16_t temp;
  2768. struct temp_event temp_event_data;
  2769. struct Scsi_Host *shost;
  2770. icmd = &iocbq->iocb;
  2771. evt_code = icmd->un.asyncstat.evt_code;
  2772. temp = icmd->ulpContext;
  2773. if ((evt_code != ASYNC_TEMP_WARN) &&
  2774. (evt_code != ASYNC_TEMP_SAFE)) {
  2775. lpfc_printf_log(phba,
  2776. KERN_ERR,
  2777. LOG_SLI,
  2778. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  2779. " evt_code 0x%x\n",
  2780. pring->ringno,
  2781. icmd->un.asyncstat.evt_code);
  2782. return;
  2783. }
  2784. temp_event_data.data = (uint32_t)temp;
  2785. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  2786. if (evt_code == ASYNC_TEMP_WARN) {
  2787. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  2788. lpfc_printf_log(phba,
  2789. KERN_ERR,
  2790. LOG_TEMP,
  2791. "0347 Adapter is very hot, please take "
  2792. "corrective action. temperature : %d Celsius\n",
  2793. temp);
  2794. }
  2795. if (evt_code == ASYNC_TEMP_SAFE) {
  2796. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  2797. lpfc_printf_log(phba,
  2798. KERN_ERR,
  2799. LOG_TEMP,
  2800. "0340 Adapter temperature is OK now. "
  2801. "temperature : %d Celsius\n",
  2802. temp);
  2803. }
  2804. /* Send temperature change event to applications */
  2805. shost = lpfc_shost_from_vport(phba->pport);
  2806. fc_host_post_vendor_event(shost, fc_get_event_number(),
  2807. sizeof(temp_event_data), (char *) &temp_event_data,
  2808. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  2809. }
  2810. int
  2811. lpfc_sli_setup(struct lpfc_hba *phba)
  2812. {
  2813. int i, totiocbsize = 0;
  2814. struct lpfc_sli *psli = &phba->sli;
  2815. struct lpfc_sli_ring *pring;
  2816. psli->num_rings = MAX_CONFIGURED_RINGS;
  2817. psli->sli_flag = 0;
  2818. psli->fcp_ring = LPFC_FCP_RING;
  2819. psli->next_ring = LPFC_FCP_NEXT_RING;
  2820. psli->extra_ring = LPFC_EXTRA_RING;
  2821. psli->iocbq_lookup = NULL;
  2822. psli->iocbq_lookup_len = 0;
  2823. psli->last_iotag = 0;
  2824. for (i = 0; i < psli->num_rings; i++) {
  2825. pring = &psli->ring[i];
  2826. switch (i) {
  2827. case LPFC_FCP_RING: /* ring 0 - FCP */
  2828. /* numCiocb and numRiocb are used in config_port */
  2829. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  2830. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  2831. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2832. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2833. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2834. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2835. pring->sizeCiocb = (phba->sli_rev == 3) ?
  2836. SLI3_IOCB_CMD_SIZE :
  2837. SLI2_IOCB_CMD_SIZE;
  2838. pring->sizeRiocb = (phba->sli_rev == 3) ?
  2839. SLI3_IOCB_RSP_SIZE :
  2840. SLI2_IOCB_RSP_SIZE;
  2841. pring->iotag_ctr = 0;
  2842. pring->iotag_max =
  2843. (phba->cfg_hba_queue_depth * 2);
  2844. pring->fast_iotag = pring->iotag_max;
  2845. pring->num_mask = 0;
  2846. break;
  2847. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  2848. /* numCiocb and numRiocb are used in config_port */
  2849. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  2850. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  2851. pring->sizeCiocb = (phba->sli_rev == 3) ?
  2852. SLI3_IOCB_CMD_SIZE :
  2853. SLI2_IOCB_CMD_SIZE;
  2854. pring->sizeRiocb = (phba->sli_rev == 3) ?
  2855. SLI3_IOCB_RSP_SIZE :
  2856. SLI2_IOCB_RSP_SIZE;
  2857. pring->iotag_max = phba->cfg_hba_queue_depth;
  2858. pring->num_mask = 0;
  2859. break;
  2860. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  2861. /* numCiocb and numRiocb are used in config_port */
  2862. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  2863. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  2864. pring->sizeCiocb = (phba->sli_rev == 3) ?
  2865. SLI3_IOCB_CMD_SIZE :
  2866. SLI2_IOCB_CMD_SIZE;
  2867. pring->sizeRiocb = (phba->sli_rev == 3) ?
  2868. SLI3_IOCB_RSP_SIZE :
  2869. SLI2_IOCB_RSP_SIZE;
  2870. pring->fast_iotag = 0;
  2871. pring->iotag_ctr = 0;
  2872. pring->iotag_max = 4096;
  2873. pring->lpfc_sli_rcv_async_status =
  2874. lpfc_sli_async_event_handler;
  2875. pring->num_mask = 4;
  2876. pring->prt[0].profile = 0; /* Mask 0 */
  2877. pring->prt[0].rctl = FC_ELS_REQ;
  2878. pring->prt[0].type = FC_ELS_DATA;
  2879. pring->prt[0].lpfc_sli_rcv_unsol_event =
  2880. lpfc_els_unsol_event;
  2881. pring->prt[1].profile = 0; /* Mask 1 */
  2882. pring->prt[1].rctl = FC_ELS_RSP;
  2883. pring->prt[1].type = FC_ELS_DATA;
  2884. pring->prt[1].lpfc_sli_rcv_unsol_event =
  2885. lpfc_els_unsol_event;
  2886. pring->prt[2].profile = 0; /* Mask 2 */
  2887. /* NameServer Inquiry */
  2888. pring->prt[2].rctl = FC_UNSOL_CTL;
  2889. /* NameServer */
  2890. pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
  2891. pring->prt[2].lpfc_sli_rcv_unsol_event =
  2892. lpfc_ct_unsol_event;
  2893. pring->prt[3].profile = 0; /* Mask 3 */
  2894. /* NameServer response */
  2895. pring->prt[3].rctl = FC_SOL_CTL;
  2896. /* NameServer */
  2897. pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
  2898. pring->prt[3].lpfc_sli_rcv_unsol_event =
  2899. lpfc_ct_unsol_event;
  2900. break;
  2901. }
  2902. totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
  2903. (pring->numRiocb * pring->sizeRiocb);
  2904. }
  2905. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  2906. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  2907. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  2908. "SLI2 SLIM Data: x%x x%lx\n",
  2909. phba->brd_no, totiocbsize,
  2910. (unsigned long) MAX_SLIM_IOCB_SIZE);
  2911. }
  2912. if (phba->cfg_multi_ring_support == 2)
  2913. lpfc_extra_ring_setup(phba);
  2914. return 0;
  2915. }
  2916. int
  2917. lpfc_sli_queue_setup(struct lpfc_hba *phba)
  2918. {
  2919. struct lpfc_sli *psli;
  2920. struct lpfc_sli_ring *pring;
  2921. int i;
  2922. psli = &phba->sli;
  2923. spin_lock_irq(&phba->hbalock);
  2924. INIT_LIST_HEAD(&psli->mboxq);
  2925. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  2926. /* Initialize list headers for txq and txcmplq as double linked lists */
  2927. for (i = 0; i < psli->num_rings; i++) {
  2928. pring = &psli->ring[i];
  2929. pring->ringno = i;
  2930. pring->next_cmdidx = 0;
  2931. pring->local_getidx = 0;
  2932. pring->cmdidx = 0;
  2933. INIT_LIST_HEAD(&pring->txq);
  2934. INIT_LIST_HEAD(&pring->txcmplq);
  2935. INIT_LIST_HEAD(&pring->iocb_continueq);
  2936. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  2937. INIT_LIST_HEAD(&pring->postbufq);
  2938. }
  2939. spin_unlock_irq(&phba->hbalock);
  2940. return 1;
  2941. }
  2942. int
  2943. lpfc_sli_host_down(struct lpfc_vport *vport)
  2944. {
  2945. LIST_HEAD(completions);
  2946. struct lpfc_hba *phba = vport->phba;
  2947. struct lpfc_sli *psli = &phba->sli;
  2948. struct lpfc_sli_ring *pring;
  2949. struct lpfc_iocbq *iocb, *next_iocb;
  2950. int i;
  2951. unsigned long flags = 0;
  2952. uint16_t prev_pring_flag;
  2953. lpfc_cleanup_discovery_resources(vport);
  2954. spin_lock_irqsave(&phba->hbalock, flags);
  2955. for (i = 0; i < psli->num_rings; i++) {
  2956. pring = &psli->ring[i];
  2957. prev_pring_flag = pring->flag;
  2958. /* Only slow rings */
  2959. if (pring->ringno == LPFC_ELS_RING) {
  2960. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  2961. /* Set the lpfc data pending flag */
  2962. set_bit(LPFC_DATA_READY, &phba->data_flags);
  2963. }
  2964. /*
  2965. * Error everything on the txq since these iocbs have not been
  2966. * given to the FW yet.
  2967. */
  2968. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  2969. if (iocb->vport != vport)
  2970. continue;
  2971. list_move_tail(&iocb->list, &completions);
  2972. pring->txq_cnt--;
  2973. }
  2974. /* Next issue ABTS for everything on the txcmplq */
  2975. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  2976. list) {
  2977. if (iocb->vport != vport)
  2978. continue;
  2979. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  2980. }
  2981. pring->flag = prev_pring_flag;
  2982. }
  2983. spin_unlock_irqrestore(&phba->hbalock, flags);
  2984. while (!list_empty(&completions)) {
  2985. list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
  2986. if (!iocb->iocb_cmpl)
  2987. lpfc_sli_release_iocbq(phba, iocb);
  2988. else {
  2989. iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  2990. iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
  2991. (iocb->iocb_cmpl) (phba, iocb, iocb);
  2992. }
  2993. }
  2994. return 1;
  2995. }
  2996. int
  2997. lpfc_sli_hba_down(struct lpfc_hba *phba)
  2998. {
  2999. LIST_HEAD(completions);
  3000. struct lpfc_sli *psli = &phba->sli;
  3001. struct lpfc_sli_ring *pring;
  3002. struct lpfc_dmabuf *buf_ptr;
  3003. LPFC_MBOXQ_t *pmb;
  3004. struct lpfc_iocbq *iocb;
  3005. IOCB_t *cmd = NULL;
  3006. int i;
  3007. unsigned long flags = 0;
  3008. lpfc_hba_down_prep(phba);
  3009. lpfc_fabric_abort_hba(phba);
  3010. spin_lock_irqsave(&phba->hbalock, flags);
  3011. for (i = 0; i < psli->num_rings; i++) {
  3012. pring = &psli->ring[i];
  3013. /* Only slow rings */
  3014. if (pring->ringno == LPFC_ELS_RING) {
  3015. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  3016. /* Set the lpfc data pending flag */
  3017. set_bit(LPFC_DATA_READY, &phba->data_flags);
  3018. }
  3019. /*
  3020. * Error everything on the txq since these iocbs have not been
  3021. * given to the FW yet.
  3022. */
  3023. list_splice_init(&pring->txq, &completions);
  3024. pring->txq_cnt = 0;
  3025. }
  3026. spin_unlock_irqrestore(&phba->hbalock, flags);
  3027. while (!list_empty(&completions)) {
  3028. list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
  3029. cmd = &iocb->iocb;
  3030. if (!iocb->iocb_cmpl)
  3031. lpfc_sli_release_iocbq(phba, iocb);
  3032. else {
  3033. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3034. cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
  3035. (iocb->iocb_cmpl) (phba, iocb, iocb);
  3036. }
  3037. }
  3038. spin_lock_irqsave(&phba->hbalock, flags);
  3039. list_splice_init(&phba->elsbuf, &completions);
  3040. phba->elsbuf_cnt = 0;
  3041. phba->elsbuf_prev_cnt = 0;
  3042. spin_unlock_irqrestore(&phba->hbalock, flags);
  3043. while (!list_empty(&completions)) {
  3044. list_remove_head(&completions, buf_ptr,
  3045. struct lpfc_dmabuf, list);
  3046. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3047. kfree(buf_ptr);
  3048. }
  3049. /* Return any active mbox cmds */
  3050. del_timer_sync(&psli->mbox_tmo);
  3051. spin_lock_irqsave(&phba->hbalock, flags);
  3052. spin_lock(&phba->pport->work_port_lock);
  3053. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  3054. spin_unlock(&phba->pport->work_port_lock);
  3055. /* Return any pending or completed mbox cmds */
  3056. list_splice_init(&phba->sli.mboxq, &completions);
  3057. if (psli->mbox_active) {
  3058. list_add_tail(&psli->mbox_active->list, &completions);
  3059. psli->mbox_active = NULL;
  3060. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  3061. }
  3062. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  3063. spin_unlock_irqrestore(&phba->hbalock, flags);
  3064. while (!list_empty(&completions)) {
  3065. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  3066. pmb->mb.mbxStatus = MBX_NOT_FINISHED;
  3067. if (pmb->mbox_cmpl)
  3068. pmb->mbox_cmpl(phba,pmb);
  3069. }
  3070. return 1;
  3071. }
  3072. void
  3073. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  3074. {
  3075. uint32_t *src = srcp;
  3076. uint32_t *dest = destp;
  3077. uint32_t ldata;
  3078. int i;
  3079. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  3080. ldata = *src;
  3081. ldata = le32_to_cpu(ldata);
  3082. *dest = ldata;
  3083. src++;
  3084. dest++;
  3085. }
  3086. }
  3087. int
  3088. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3089. struct lpfc_dmabuf *mp)
  3090. {
  3091. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  3092. later */
  3093. spin_lock_irq(&phba->hbalock);
  3094. list_add_tail(&mp->list, &pring->postbufq);
  3095. pring->postbufq_cnt++;
  3096. spin_unlock_irq(&phba->hbalock);
  3097. return 0;
  3098. }
  3099. uint32_t
  3100. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  3101. {
  3102. spin_lock_irq(&phba->hbalock);
  3103. phba->buffer_tag_count++;
  3104. /*
  3105. * Always set the QUE_BUFTAG_BIT to distiguish between
  3106. * a tag assigned by HBQ.
  3107. */
  3108. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  3109. spin_unlock_irq(&phba->hbalock);
  3110. return phba->buffer_tag_count;
  3111. }
  3112. struct lpfc_dmabuf *
  3113. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3114. uint32_t tag)
  3115. {
  3116. struct lpfc_dmabuf *mp, *next_mp;
  3117. struct list_head *slp = &pring->postbufq;
  3118. /* Search postbufq, from the begining, looking for a match on tag */
  3119. spin_lock_irq(&phba->hbalock);
  3120. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  3121. if (mp->buffer_tag == tag) {
  3122. list_del_init(&mp->list);
  3123. pring->postbufq_cnt--;
  3124. spin_unlock_irq(&phba->hbalock);
  3125. return mp;
  3126. }
  3127. }
  3128. spin_unlock_irq(&phba->hbalock);
  3129. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3130. "0410 Cannot find virtual addr for buffer tag on "
  3131. "ring %d Data x%lx x%p x%p x%x\n",
  3132. pring->ringno, (unsigned long) tag,
  3133. slp->next, slp->prev, pring->postbufq_cnt);
  3134. return NULL;
  3135. }
  3136. struct lpfc_dmabuf *
  3137. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3138. dma_addr_t phys)
  3139. {
  3140. struct lpfc_dmabuf *mp, *next_mp;
  3141. struct list_head *slp = &pring->postbufq;
  3142. /* Search postbufq, from the begining, looking for a match on phys */
  3143. spin_lock_irq(&phba->hbalock);
  3144. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  3145. if (mp->phys == phys) {
  3146. list_del_init(&mp->list);
  3147. pring->postbufq_cnt--;
  3148. spin_unlock_irq(&phba->hbalock);
  3149. return mp;
  3150. }
  3151. }
  3152. spin_unlock_irq(&phba->hbalock);
  3153. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3154. "0410 Cannot find virtual addr for mapped buf on "
  3155. "ring %d Data x%llx x%p x%p x%x\n",
  3156. pring->ringno, (unsigned long long)phys,
  3157. slp->next, slp->prev, pring->postbufq_cnt);
  3158. return NULL;
  3159. }
  3160. static void
  3161. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3162. struct lpfc_iocbq *rspiocb)
  3163. {
  3164. IOCB_t *irsp = &rspiocb->iocb;
  3165. uint16_t abort_iotag, abort_context;
  3166. struct lpfc_iocbq *abort_iocb;
  3167. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3168. abort_iocb = NULL;
  3169. if (irsp->ulpStatus) {
  3170. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  3171. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  3172. spin_lock_irq(&phba->hbalock);
  3173. if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
  3174. abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
  3175. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
  3176. "0327 Cannot abort els iocb %p "
  3177. "with tag %x context %x, abort status %x, "
  3178. "abort code %x\n",
  3179. abort_iocb, abort_iotag, abort_context,
  3180. irsp->ulpStatus, irsp->un.ulpWord[4]);
  3181. /*
  3182. * If the iocb is not found in Firmware queue the iocb
  3183. * might have completed already. Do not free it again.
  3184. */
  3185. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  3186. spin_unlock_irq(&phba->hbalock);
  3187. lpfc_sli_release_iocbq(phba, cmdiocb);
  3188. return;
  3189. }
  3190. /*
  3191. * make sure we have the right iocbq before taking it
  3192. * off the txcmplq and try to call completion routine.
  3193. */
  3194. if (!abort_iocb ||
  3195. abort_iocb->iocb.ulpContext != abort_context ||
  3196. (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
  3197. spin_unlock_irq(&phba->hbalock);
  3198. else {
  3199. list_del_init(&abort_iocb->list);
  3200. pring->txcmplq_cnt--;
  3201. spin_unlock_irq(&phba->hbalock);
  3202. /* Firmware could still be in progress of DMAing
  3203. * payload, so don't free data buffer till after
  3204. * a hbeat.
  3205. */
  3206. abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
  3207. abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
  3208. abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
  3209. abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
  3210. (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
  3211. }
  3212. }
  3213. lpfc_sli_release_iocbq(phba, cmdiocb);
  3214. return;
  3215. }
  3216. static void
  3217. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3218. struct lpfc_iocbq *rspiocb)
  3219. {
  3220. IOCB_t *irsp = &rspiocb->iocb;
  3221. /* ELS cmd tag <ulpIoTag> completes */
  3222. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  3223. "0133 Ignoring ELS cmd tag x%x completion Data: "
  3224. "x%x x%x x%x\n",
  3225. irsp->ulpIoTag, irsp->ulpStatus,
  3226. irsp->un.ulpWord[4], irsp->ulpTimeout);
  3227. if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
  3228. lpfc_ct_free_iocb(phba, cmdiocb);
  3229. else
  3230. lpfc_els_free_iocb(phba, cmdiocb);
  3231. return;
  3232. }
  3233. int
  3234. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3235. struct lpfc_iocbq *cmdiocb)
  3236. {
  3237. struct lpfc_vport *vport = cmdiocb->vport;
  3238. struct lpfc_iocbq *abtsiocbp;
  3239. IOCB_t *icmd = NULL;
  3240. IOCB_t *iabt = NULL;
  3241. int retval = IOCB_ERROR;
  3242. /*
  3243. * There are certain command types we don't want to abort. And we
  3244. * don't want to abort commands that are already in the process of
  3245. * being aborted.
  3246. */
  3247. icmd = &cmdiocb->iocb;
  3248. if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
  3249. icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3250. (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
  3251. return 0;
  3252. /* If we're unloading, don't abort iocb on the ELS ring, but change the
  3253. * callback so that nothing happens when it finishes.
  3254. */
  3255. if ((vport->load_flag & FC_UNLOADING) &&
  3256. (pring->ringno == LPFC_ELS_RING)) {
  3257. if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
  3258. cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
  3259. else
  3260. cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
  3261. goto abort_iotag_exit;
  3262. }
  3263. /* issue ABTS for this IOCB based on iotag */
  3264. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  3265. if (abtsiocbp == NULL)
  3266. return 0;
  3267. /* This signals the response to set the correct status
  3268. * before calling the completion handler.
  3269. */
  3270. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  3271. iabt = &abtsiocbp->iocb;
  3272. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  3273. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  3274. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  3275. iabt->ulpLe = 1;
  3276. iabt->ulpClass = icmd->ulpClass;
  3277. if (phba->link_state >= LPFC_LINK_UP)
  3278. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  3279. else
  3280. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  3281. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  3282. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  3283. "0339 Abort xri x%x, original iotag x%x, "
  3284. "abort cmd iotag x%x\n",
  3285. iabt->un.acxri.abortContextTag,
  3286. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  3287. retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
  3288. abort_iotag_exit:
  3289. /*
  3290. * Caller to this routine should check for IOCB_ERROR
  3291. * and handle it properly. This routine no longer removes
  3292. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  3293. */
  3294. return retval;
  3295. }
  3296. static int
  3297. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  3298. uint16_t tgt_id, uint64_t lun_id,
  3299. lpfc_ctx_cmd ctx_cmd)
  3300. {
  3301. struct lpfc_scsi_buf *lpfc_cmd;
  3302. int rc = 1;
  3303. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  3304. return rc;
  3305. if (iocbq->vport != vport)
  3306. return rc;
  3307. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  3308. if (lpfc_cmd->pCmd == NULL)
  3309. return rc;
  3310. switch (ctx_cmd) {
  3311. case LPFC_CTX_LUN:
  3312. if ((lpfc_cmd->rdata->pnode) &&
  3313. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  3314. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  3315. rc = 0;
  3316. break;
  3317. case LPFC_CTX_TGT:
  3318. if ((lpfc_cmd->rdata->pnode) &&
  3319. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  3320. rc = 0;
  3321. break;
  3322. case LPFC_CTX_HOST:
  3323. rc = 0;
  3324. break;
  3325. default:
  3326. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  3327. __FUNCTION__, ctx_cmd);
  3328. break;
  3329. }
  3330. return rc;
  3331. }
  3332. int
  3333. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  3334. lpfc_ctx_cmd ctx_cmd)
  3335. {
  3336. struct lpfc_hba *phba = vport->phba;
  3337. struct lpfc_iocbq *iocbq;
  3338. int sum, i;
  3339. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  3340. iocbq = phba->sli.iocbq_lookup[i];
  3341. if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
  3342. ctx_cmd) == 0)
  3343. sum++;
  3344. }
  3345. return sum;
  3346. }
  3347. void
  3348. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3349. struct lpfc_iocbq *rspiocb)
  3350. {
  3351. lpfc_sli_release_iocbq(phba, cmdiocb);
  3352. return;
  3353. }
  3354. int
  3355. lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  3356. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
  3357. {
  3358. struct lpfc_hba *phba = vport->phba;
  3359. struct lpfc_iocbq *iocbq;
  3360. struct lpfc_iocbq *abtsiocb;
  3361. IOCB_t *cmd = NULL;
  3362. int errcnt = 0, ret_val = 0;
  3363. int i;
  3364. for (i = 1; i <= phba->sli.last_iotag; i++) {
  3365. iocbq = phba->sli.iocbq_lookup[i];
  3366. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  3367. abort_cmd) != 0)
  3368. continue;
  3369. /* issue ABTS for this IOCB based on iotag */
  3370. abtsiocb = lpfc_sli_get_iocbq(phba);
  3371. if (abtsiocb == NULL) {
  3372. errcnt++;
  3373. continue;
  3374. }
  3375. cmd = &iocbq->iocb;
  3376. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  3377. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  3378. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  3379. abtsiocb->iocb.ulpLe = 1;
  3380. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  3381. abtsiocb->vport = phba->pport;
  3382. if (lpfc_is_link_up(phba))
  3383. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  3384. else
  3385. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  3386. /* Setup callback routine and issue the command. */
  3387. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  3388. ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
  3389. if (ret_val == IOCB_ERROR) {
  3390. lpfc_sli_release_iocbq(phba, abtsiocb);
  3391. errcnt++;
  3392. continue;
  3393. }
  3394. }
  3395. return errcnt;
  3396. }
  3397. static void
  3398. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  3399. struct lpfc_iocbq *cmdiocbq,
  3400. struct lpfc_iocbq *rspiocbq)
  3401. {
  3402. wait_queue_head_t *pdone_q;
  3403. unsigned long iflags;
  3404. spin_lock_irqsave(&phba->hbalock, iflags);
  3405. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  3406. if (cmdiocbq->context2 && rspiocbq)
  3407. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  3408. &rspiocbq->iocb, sizeof(IOCB_t));
  3409. pdone_q = cmdiocbq->context_un.wait_queue;
  3410. if (pdone_q)
  3411. wake_up(pdone_q);
  3412. spin_unlock_irqrestore(&phba->hbalock, iflags);
  3413. return;
  3414. }
  3415. /*
  3416. * Issue the caller's iocb and wait for its completion, but no longer than the
  3417. * caller's timeout. Note that iocb_flags is cleared before the
  3418. * lpfc_sli_issue_call since the wake routine sets a unique value and by
  3419. * definition this is a wait function.
  3420. */
  3421. int
  3422. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  3423. struct lpfc_sli_ring *pring,
  3424. struct lpfc_iocbq *piocb,
  3425. struct lpfc_iocbq *prspiocbq,
  3426. uint32_t timeout)
  3427. {
  3428. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  3429. long timeleft, timeout_req = 0;
  3430. int retval = IOCB_SUCCESS;
  3431. uint32_t creg_val;
  3432. /*
  3433. * If the caller has provided a response iocbq buffer, then context2
  3434. * is NULL or its an error.
  3435. */
  3436. if (prspiocbq) {
  3437. if (piocb->context2)
  3438. return IOCB_ERROR;
  3439. piocb->context2 = prspiocbq;
  3440. }
  3441. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  3442. piocb->context_un.wait_queue = &done_q;
  3443. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  3444. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  3445. creg_val = readl(phba->HCregaddr);
  3446. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  3447. writel(creg_val, phba->HCregaddr);
  3448. readl(phba->HCregaddr); /* flush */
  3449. }
  3450. retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
  3451. if (retval == IOCB_SUCCESS) {
  3452. timeout_req = timeout * HZ;
  3453. timeleft = wait_event_timeout(done_q,
  3454. piocb->iocb_flag & LPFC_IO_WAKE,
  3455. timeout_req);
  3456. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  3457. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3458. "0331 IOCB wake signaled\n");
  3459. } else if (timeleft == 0) {
  3460. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3461. "0338 IOCB wait timeout error - no "
  3462. "wake response Data x%x\n", timeout);
  3463. retval = IOCB_TIMEDOUT;
  3464. } else {
  3465. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3466. "0330 IOCB wake NOT set, "
  3467. "Data x%x x%lx\n",
  3468. timeout, (timeleft / jiffies));
  3469. retval = IOCB_TIMEDOUT;
  3470. }
  3471. } else {
  3472. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3473. ":0332 IOCB wait issue failed, Data x%x\n",
  3474. retval);
  3475. retval = IOCB_ERROR;
  3476. }
  3477. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  3478. creg_val = readl(phba->HCregaddr);
  3479. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  3480. writel(creg_val, phba->HCregaddr);
  3481. readl(phba->HCregaddr); /* flush */
  3482. }
  3483. if (prspiocbq)
  3484. piocb->context2 = NULL;
  3485. piocb->context_un.wait_queue = NULL;
  3486. piocb->iocb_cmpl = NULL;
  3487. return retval;
  3488. }
  3489. int
  3490. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  3491. uint32_t timeout)
  3492. {
  3493. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  3494. int retval;
  3495. unsigned long flag;
  3496. /* The caller must leave context1 empty. */
  3497. if (pmboxq->context1)
  3498. return MBX_NOT_FINISHED;
  3499. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  3500. /* setup wake call as IOCB callback */
  3501. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  3502. /* setup context field to pass wait_queue pointer to wake function */
  3503. pmboxq->context1 = &done_q;
  3504. /* now issue the command */
  3505. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  3506. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  3507. wait_event_interruptible_timeout(done_q,
  3508. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  3509. timeout * HZ);
  3510. spin_lock_irqsave(&phba->hbalock, flag);
  3511. pmboxq->context1 = NULL;
  3512. /*
  3513. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  3514. * else do not free the resources.
  3515. */
  3516. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  3517. retval = MBX_SUCCESS;
  3518. else {
  3519. retval = MBX_TIMEOUT;
  3520. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3521. }
  3522. spin_unlock_irqrestore(&phba->hbalock, flag);
  3523. }
  3524. return retval;
  3525. }
  3526. int
  3527. lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
  3528. {
  3529. struct lpfc_vport *vport = phba->pport;
  3530. int i = 0;
  3531. uint32_t ha_copy;
  3532. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
  3533. if (i++ > LPFC_MBOX_TMO * 1000)
  3534. return 1;
  3535. /*
  3536. * Call lpfc_sli_handle_mb_event only if a mailbox cmd
  3537. * did finish. This way we won't get the misleading
  3538. * "Stray Mailbox Interrupt" message.
  3539. */
  3540. spin_lock_irq(&phba->hbalock);
  3541. ha_copy = phba->work_ha;
  3542. phba->work_ha &= ~HA_MBATT;
  3543. spin_unlock_irq(&phba->hbalock);
  3544. if (ha_copy & HA_MBATT)
  3545. if (lpfc_sli_handle_mb_event(phba) == 0)
  3546. i = 0;
  3547. msleep(1);
  3548. }
  3549. return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
  3550. }
  3551. irqreturn_t
  3552. lpfc_intr_handler(int irq, void *dev_id)
  3553. {
  3554. struct lpfc_hba *phba;
  3555. uint32_t ha_copy;
  3556. uint32_t work_ha_copy;
  3557. unsigned long status;
  3558. uint32_t control;
  3559. MAILBOX_t *mbox, *pmbox;
  3560. struct lpfc_vport *vport;
  3561. struct lpfc_nodelist *ndlp;
  3562. struct lpfc_dmabuf *mp;
  3563. LPFC_MBOXQ_t *pmb;
  3564. int rc;
  3565. /*
  3566. * Get the driver's phba structure from the dev_id and
  3567. * assume the HBA is not interrupting.
  3568. */
  3569. phba = (struct lpfc_hba *) dev_id;
  3570. if (unlikely(!phba))
  3571. return IRQ_NONE;
  3572. /* If the pci channel is offline, ignore all the interrupts. */
  3573. if (unlikely(pci_channel_offline(phba->pcidev)))
  3574. return IRQ_NONE;
  3575. phba->sli.slistat.sli_intr++;
  3576. /*
  3577. * Call the HBA to see if it is interrupting. If not, don't claim
  3578. * the interrupt
  3579. */
  3580. /* Ignore all interrupts during initialization. */
  3581. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  3582. return IRQ_NONE;
  3583. /*
  3584. * Read host attention register to determine interrupt source
  3585. * Clear Attention Sources, except Error Attention (to
  3586. * preserve status) and Link Attention
  3587. */
  3588. spin_lock(&phba->hbalock);
  3589. ha_copy = readl(phba->HAregaddr);
  3590. /* If somebody is waiting to handle an eratt don't process it
  3591. * here. The brdkill function will do this.
  3592. */
  3593. if (phba->link_flag & LS_IGNORE_ERATT)
  3594. ha_copy &= ~HA_ERATT;
  3595. writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  3596. readl(phba->HAregaddr); /* flush */
  3597. spin_unlock(&phba->hbalock);
  3598. if (unlikely(!ha_copy))
  3599. return IRQ_NONE;
  3600. work_ha_copy = ha_copy & phba->work_ha_mask;
  3601. if (unlikely(work_ha_copy)) {
  3602. if (work_ha_copy & HA_LATT) {
  3603. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  3604. /*
  3605. * Turn off Link Attention interrupts
  3606. * until CLEAR_LA done
  3607. */
  3608. spin_lock(&phba->hbalock);
  3609. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  3610. control = readl(phba->HCregaddr);
  3611. control &= ~HC_LAINT_ENA;
  3612. writel(control, phba->HCregaddr);
  3613. readl(phba->HCregaddr); /* flush */
  3614. spin_unlock(&phba->hbalock);
  3615. }
  3616. else
  3617. work_ha_copy &= ~HA_LATT;
  3618. }
  3619. if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
  3620. /*
  3621. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  3622. * the only slow ring.
  3623. */
  3624. status = (work_ha_copy &
  3625. (HA_RXMASK << (4*LPFC_ELS_RING)));
  3626. status >>= (4*LPFC_ELS_RING);
  3627. if (status & HA_RXMASK) {
  3628. spin_lock(&phba->hbalock);
  3629. control = readl(phba->HCregaddr);
  3630. lpfc_debugfs_slow_ring_trc(phba,
  3631. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  3632. control, status,
  3633. (uint32_t)phba->sli.slistat.sli_intr);
  3634. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  3635. lpfc_debugfs_slow_ring_trc(phba,
  3636. "ISR Disable ring:"
  3637. "pwork:x%x hawork:x%x wait:x%x",
  3638. phba->work_ha, work_ha_copy,
  3639. (uint32_t)((unsigned long)
  3640. &phba->work_waitq));
  3641. control &=
  3642. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  3643. writel(control, phba->HCregaddr);
  3644. readl(phba->HCregaddr); /* flush */
  3645. }
  3646. else {
  3647. lpfc_debugfs_slow_ring_trc(phba,
  3648. "ISR slow ring: pwork:"
  3649. "x%x hawork:x%x wait:x%x",
  3650. phba->work_ha, work_ha_copy,
  3651. (uint32_t)((unsigned long)
  3652. &phba->work_waitq));
  3653. }
  3654. spin_unlock(&phba->hbalock);
  3655. }
  3656. }
  3657. if (work_ha_copy & HA_ERATT) {
  3658. /*
  3659. * There was a link/board error. Read the
  3660. * status register to retrieve the error event
  3661. * and process it.
  3662. */
  3663. phba->sli.slistat.err_attn_event++;
  3664. /* Save status info */
  3665. phba->work_hs = readl(phba->HSregaddr);
  3666. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  3667. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  3668. /* Clear Chip error bit */
  3669. writel(HA_ERATT, phba->HAregaddr);
  3670. readl(phba->HAregaddr); /* flush */
  3671. phba->pport->stopped = 1;
  3672. }
  3673. spin_lock(&phba->hbalock);
  3674. if ((work_ha_copy & HA_MBATT) &&
  3675. (phba->sli.mbox_active)) {
  3676. pmb = phba->sli.mbox_active;
  3677. pmbox = &pmb->mb;
  3678. mbox = &phba->slim2p->mbx;
  3679. vport = pmb->vport;
  3680. /* First check out the status word */
  3681. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  3682. if (pmbox->mbxOwner != OWN_HOST) {
  3683. spin_unlock(&phba->hbalock);
  3684. /*
  3685. * Stray Mailbox Interrupt, mbxCommand <cmd>
  3686. * mbxStatus <status>
  3687. */
  3688. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  3689. LOG_SLI,
  3690. "(%d):0304 Stray Mailbox "
  3691. "Interrupt mbxCommand x%x "
  3692. "mbxStatus x%x\n",
  3693. (vport ? vport->vpi : 0),
  3694. pmbox->mbxCommand,
  3695. pmbox->mbxStatus);
  3696. /* clear mailbox attention bit */
  3697. work_ha_copy &= ~HA_MBATT;
  3698. } else {
  3699. phba->sli.mbox_active = NULL;
  3700. spin_unlock(&phba->hbalock);
  3701. phba->last_completion_time = jiffies;
  3702. del_timer(&phba->sli.mbox_tmo);
  3703. if (pmb->mbox_cmpl) {
  3704. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  3705. MAILBOX_CMD_SIZE);
  3706. }
  3707. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  3708. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  3709. lpfc_debugfs_disc_trc(vport,
  3710. LPFC_DISC_TRC_MBOX_VPORT,
  3711. "MBOX dflt rpi: : "
  3712. "status:x%x rpi:x%x",
  3713. (uint32_t)pmbox->mbxStatus,
  3714. pmbox->un.varWords[0], 0);
  3715. if (!pmbox->mbxStatus) {
  3716. mp = (struct lpfc_dmabuf *)
  3717. (pmb->context1);
  3718. ndlp = (struct lpfc_nodelist *)
  3719. pmb->context2;
  3720. /* Reg_LOGIN of dflt RPI was
  3721. * successful. new lets get
  3722. * rid of the RPI using the
  3723. * same mbox buffer.
  3724. */
  3725. lpfc_unreg_login(phba,
  3726. vport->vpi,
  3727. pmbox->un.varWords[0],
  3728. pmb);
  3729. pmb->mbox_cmpl =
  3730. lpfc_mbx_cmpl_dflt_rpi;
  3731. pmb->context1 = mp;
  3732. pmb->context2 = ndlp;
  3733. pmb->vport = vport;
  3734. rc = lpfc_sli_issue_mbox(phba,
  3735. pmb,
  3736. MBX_NOWAIT);
  3737. if (rc != MBX_BUSY)
  3738. lpfc_printf_log(phba,
  3739. KERN_ERR,
  3740. LOG_MBOX | LOG_SLI,
  3741. "0306 rc should have"
  3742. "been MBX_BUSY");
  3743. goto send_current_mbox;
  3744. }
  3745. }
  3746. spin_lock(&phba->pport->work_port_lock);
  3747. phba->pport->work_port_events &=
  3748. ~WORKER_MBOX_TMO;
  3749. spin_unlock(&phba->pport->work_port_lock);
  3750. lpfc_mbox_cmpl_put(phba, pmb);
  3751. }
  3752. } else
  3753. spin_unlock(&phba->hbalock);
  3754. if ((work_ha_copy & HA_MBATT) &&
  3755. (phba->sli.mbox_active == NULL)) {
  3756. send_current_mbox:
  3757. /* Process next mailbox command if there is one */
  3758. do {
  3759. rc = lpfc_sli_issue_mbox(phba, NULL,
  3760. MBX_NOWAIT);
  3761. } while (rc == MBX_NOT_FINISHED);
  3762. if (rc != MBX_SUCCESS)
  3763. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
  3764. LOG_SLI, "0349 rc should be "
  3765. "MBX_SUCCESS");
  3766. }
  3767. spin_lock(&phba->hbalock);
  3768. phba->work_ha |= work_ha_copy;
  3769. spin_unlock(&phba->hbalock);
  3770. lpfc_worker_wake_up(phba);
  3771. }
  3772. ha_copy &= ~(phba->work_ha_mask);
  3773. /*
  3774. * Process all events on FCP ring. Take the optimized path for
  3775. * FCP IO. Any other IO is slow path and is handled by
  3776. * the worker thread.
  3777. */
  3778. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  3779. status >>= (4*LPFC_FCP_RING);
  3780. if (status & HA_RXMASK)
  3781. lpfc_sli_handle_fast_ring_event(phba,
  3782. &phba->sli.ring[LPFC_FCP_RING],
  3783. status);
  3784. if (phba->cfg_multi_ring_support == 2) {
  3785. /*
  3786. * Process all events on extra ring. Take the optimized path
  3787. * for extra ring IO. Any other IO is slow path and is handled
  3788. * by the worker thread.
  3789. */
  3790. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  3791. status >>= (4*LPFC_EXTRA_RING);
  3792. if (status & HA_RXMASK) {
  3793. lpfc_sli_handle_fast_ring_event(phba,
  3794. &phba->sli.ring[LPFC_EXTRA_RING],
  3795. status);
  3796. }
  3797. }
  3798. return IRQ_HANDLED;
  3799. } /* lpfc_intr_handler */