lpfc_sli.c 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2007 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. /*
  39. * Define macro to log: Mailbox command x%x cannot issue Data
  40. * This allows multiple uses of lpfc_msgBlk0311
  41. * w/o perturbing log msg utility.
  42. */
  43. #define LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) \
  44. lpfc_printf_log(phba, \
  45. KERN_INFO, \
  46. LOG_MBOX | LOG_SLI, \
  47. "%d:0311 Mailbox command x%x cannot issue " \
  48. "Data: x%x x%x x%x\n", \
  49. phba->brd_no, \
  50. mb->mbxCommand, \
  51. phba->hba_state, \
  52. psli->sli_flag, \
  53. flag);
  54. /* There are only four IOCB completion types. */
  55. typedef enum _lpfc_iocb_type {
  56. LPFC_UNKNOWN_IOCB,
  57. LPFC_UNSOL_IOCB,
  58. LPFC_SOL_IOCB,
  59. LPFC_ABORT_IOCB
  60. } lpfc_iocb_type;
  61. struct lpfc_iocbq *
  62. lpfc_sli_get_iocbq(struct lpfc_hba * phba)
  63. {
  64. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  65. struct lpfc_iocbq * iocbq = NULL;
  66. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  67. return iocbq;
  68. }
  69. void
  70. lpfc_sli_release_iocbq(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
  71. {
  72. size_t start_clean = (size_t)(&((struct lpfc_iocbq *)NULL)->iocb);
  73. /*
  74. * Clean all volatile data fields, preserve iotag and node struct.
  75. */
  76. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  77. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  78. }
  79. /*
  80. * Translate the iocb command to an iocb command type used to decide the final
  81. * disposition of each completed IOCB.
  82. */
  83. static lpfc_iocb_type
  84. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  85. {
  86. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  87. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  88. return 0;
  89. switch (iocb_cmnd) {
  90. case CMD_XMIT_SEQUENCE_CR:
  91. case CMD_XMIT_SEQUENCE_CX:
  92. case CMD_XMIT_BCAST_CN:
  93. case CMD_XMIT_BCAST_CX:
  94. case CMD_ELS_REQUEST_CR:
  95. case CMD_ELS_REQUEST_CX:
  96. case CMD_CREATE_XRI_CR:
  97. case CMD_CREATE_XRI_CX:
  98. case CMD_GET_RPI_CN:
  99. case CMD_XMIT_ELS_RSP_CX:
  100. case CMD_GET_RPI_CR:
  101. case CMD_FCP_IWRITE_CR:
  102. case CMD_FCP_IWRITE_CX:
  103. case CMD_FCP_IREAD_CR:
  104. case CMD_FCP_IREAD_CX:
  105. case CMD_FCP_ICMND_CR:
  106. case CMD_FCP_ICMND_CX:
  107. case CMD_FCP_TSEND_CX:
  108. case CMD_FCP_TRSP_CX:
  109. case CMD_FCP_TRECEIVE_CX:
  110. case CMD_FCP_AUTO_TRSP_CX:
  111. case CMD_ADAPTER_MSG:
  112. case CMD_ADAPTER_DUMP:
  113. case CMD_XMIT_SEQUENCE64_CR:
  114. case CMD_XMIT_SEQUENCE64_CX:
  115. case CMD_XMIT_BCAST64_CN:
  116. case CMD_XMIT_BCAST64_CX:
  117. case CMD_ELS_REQUEST64_CR:
  118. case CMD_ELS_REQUEST64_CX:
  119. case CMD_FCP_IWRITE64_CR:
  120. case CMD_FCP_IWRITE64_CX:
  121. case CMD_FCP_IREAD64_CR:
  122. case CMD_FCP_IREAD64_CX:
  123. case CMD_FCP_ICMND64_CR:
  124. case CMD_FCP_ICMND64_CX:
  125. case CMD_FCP_TSEND64_CX:
  126. case CMD_FCP_TRSP64_CX:
  127. case CMD_FCP_TRECEIVE64_CX:
  128. case CMD_GEN_REQUEST64_CR:
  129. case CMD_GEN_REQUEST64_CX:
  130. case CMD_XMIT_ELS_RSP64_CX:
  131. type = LPFC_SOL_IOCB;
  132. break;
  133. case CMD_ABORT_XRI_CN:
  134. case CMD_ABORT_XRI_CX:
  135. case CMD_CLOSE_XRI_CN:
  136. case CMD_CLOSE_XRI_CX:
  137. case CMD_XRI_ABORTED_CX:
  138. case CMD_ABORT_MXRI64_CN:
  139. type = LPFC_ABORT_IOCB;
  140. break;
  141. case CMD_RCV_SEQUENCE_CX:
  142. case CMD_RCV_ELS_REQ_CX:
  143. case CMD_RCV_SEQUENCE64_CX:
  144. case CMD_RCV_ELS_REQ64_CX:
  145. type = LPFC_UNSOL_IOCB;
  146. break;
  147. default:
  148. type = LPFC_UNKNOWN_IOCB;
  149. break;
  150. }
  151. return type;
  152. }
  153. static int
  154. lpfc_sli_ring_map(struct lpfc_hba * phba, LPFC_MBOXQ_t *pmb)
  155. {
  156. struct lpfc_sli *psli = &phba->sli;
  157. MAILBOX_t *pmbox = &pmb->mb;
  158. int i, rc;
  159. for (i = 0; i < psli->num_rings; i++) {
  160. phba->hba_state = LPFC_INIT_MBX_CMDS;
  161. lpfc_config_ring(phba, i, pmb);
  162. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  163. if (rc != MBX_SUCCESS) {
  164. lpfc_printf_log(phba,
  165. KERN_ERR,
  166. LOG_INIT,
  167. "%d:0446 Adapter failed to init, "
  168. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  169. "ring %d\n",
  170. phba->brd_no,
  171. pmbox->mbxCommand,
  172. pmbox->mbxStatus,
  173. i);
  174. phba->hba_state = LPFC_HBA_ERROR;
  175. return -ENXIO;
  176. }
  177. }
  178. return 0;
  179. }
  180. static int
  181. lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba,
  182. struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb)
  183. {
  184. list_add_tail(&piocb->list, &pring->txcmplq);
  185. pring->txcmplq_cnt++;
  186. if (unlikely(pring->ringno == LPFC_ELS_RING))
  187. mod_timer(&phba->els_tmofunc,
  188. jiffies + HZ * (phba->fc_ratov << 1));
  189. return (0);
  190. }
  191. static struct lpfc_iocbq *
  192. lpfc_sli_ringtx_get(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
  193. {
  194. struct list_head *dlp;
  195. struct lpfc_iocbq *cmd_iocb;
  196. dlp = &pring->txq;
  197. cmd_iocb = NULL;
  198. list_remove_head((&pring->txq), cmd_iocb,
  199. struct lpfc_iocbq,
  200. list);
  201. if (cmd_iocb) {
  202. /* If the first ptr is not equal to the list header,
  203. * deque the IOCBQ_t and return it.
  204. */
  205. pring->txq_cnt--;
  206. }
  207. return (cmd_iocb);
  208. }
  209. static IOCB_t *
  210. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  211. {
  212. struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
  213. uint32_t max_cmd_idx = pring->numCiocb;
  214. IOCB_t *iocb = NULL;
  215. if ((pring->next_cmdidx == pring->cmdidx) &&
  216. (++pring->next_cmdidx >= max_cmd_idx))
  217. pring->next_cmdidx = 0;
  218. if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
  219. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  220. if (unlikely(pring->local_getidx >= max_cmd_idx)) {
  221. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  222. "%d:0315 Ring %d issue: portCmdGet %d "
  223. "is bigger then cmd ring %d\n",
  224. phba->brd_no, pring->ringno,
  225. pring->local_getidx, max_cmd_idx);
  226. phba->hba_state = LPFC_HBA_ERROR;
  227. /*
  228. * All error attention handlers are posted to
  229. * worker thread
  230. */
  231. phba->work_ha |= HA_ERATT;
  232. phba->work_hs = HS_FFER3;
  233. if (phba->work_wait)
  234. wake_up(phba->work_wait);
  235. return NULL;
  236. }
  237. if (pring->local_getidx == pring->next_cmdidx)
  238. return NULL;
  239. }
  240. iocb = IOCB_ENTRY(pring->cmdringaddr, pring->cmdidx);
  241. return iocb;
  242. }
  243. uint16_t
  244. lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
  245. {
  246. struct lpfc_iocbq ** new_arr;
  247. struct lpfc_iocbq ** old_arr;
  248. size_t new_len;
  249. struct lpfc_sli *psli = &phba->sli;
  250. uint16_t iotag;
  251. spin_lock_irq(phba->host->host_lock);
  252. iotag = psli->last_iotag;
  253. if(++iotag < psli->iocbq_lookup_len) {
  254. psli->last_iotag = iotag;
  255. psli->iocbq_lookup[iotag] = iocbq;
  256. spin_unlock_irq(phba->host->host_lock);
  257. iocbq->iotag = iotag;
  258. return iotag;
  259. }
  260. else if (psli->iocbq_lookup_len < (0xffff
  261. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  262. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  263. spin_unlock_irq(phba->host->host_lock);
  264. new_arr = kmalloc(new_len * sizeof (struct lpfc_iocbq *),
  265. GFP_KERNEL);
  266. if (new_arr) {
  267. memset((char *)new_arr, 0,
  268. new_len * sizeof (struct lpfc_iocbq *));
  269. spin_lock_irq(phba->host->host_lock);
  270. old_arr = psli->iocbq_lookup;
  271. if (new_len <= psli->iocbq_lookup_len) {
  272. /* highly unprobable case */
  273. kfree(new_arr);
  274. iotag = psli->last_iotag;
  275. if(++iotag < psli->iocbq_lookup_len) {
  276. psli->last_iotag = iotag;
  277. psli->iocbq_lookup[iotag] = iocbq;
  278. spin_unlock_irq(phba->host->host_lock);
  279. iocbq->iotag = iotag;
  280. return iotag;
  281. }
  282. spin_unlock_irq(phba->host->host_lock);
  283. return 0;
  284. }
  285. if (psli->iocbq_lookup)
  286. memcpy(new_arr, old_arr,
  287. ((psli->last_iotag + 1) *
  288. sizeof (struct lpfc_iocbq *)));
  289. psli->iocbq_lookup = new_arr;
  290. psli->iocbq_lookup_len = new_len;
  291. psli->last_iotag = iotag;
  292. psli->iocbq_lookup[iotag] = iocbq;
  293. spin_unlock_irq(phba->host->host_lock);
  294. iocbq->iotag = iotag;
  295. kfree(old_arr);
  296. return iotag;
  297. }
  298. } else
  299. spin_unlock_irq(phba->host->host_lock);
  300. lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
  301. "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  302. phba->brd_no, psli->last_iotag);
  303. return 0;
  304. }
  305. static void
  306. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  307. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  308. {
  309. /*
  310. * Set up an iotag
  311. */
  312. nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
  313. /*
  314. * Issue iocb command to adapter
  315. */
  316. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, sizeof (IOCB_t));
  317. wmb();
  318. pring->stats.iocb_cmd++;
  319. /*
  320. * If there is no completion routine to call, we can release the
  321. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  322. * that have no rsp ring completion, iocb_cmpl MUST be NULL.
  323. */
  324. if (nextiocb->iocb_cmpl)
  325. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  326. else
  327. lpfc_sli_release_iocbq(phba, nextiocb);
  328. /*
  329. * Let the HBA know what IOCB slot will be the next one the
  330. * driver will put a command into.
  331. */
  332. pring->cmdidx = pring->next_cmdidx;
  333. writel(pring->cmdidx, phba->MBslimaddr
  334. + (SLIMOFF + (pring->ringno * 2)) * 4);
  335. }
  336. static void
  337. lpfc_sli_update_full_ring(struct lpfc_hba * phba,
  338. struct lpfc_sli_ring *pring)
  339. {
  340. int ringno = pring->ringno;
  341. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  342. wmb();
  343. /*
  344. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  345. * The HBA will tell us when an IOCB entry is available.
  346. */
  347. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  348. readl(phba->CAregaddr); /* flush */
  349. pring->stats.iocb_cmd_full++;
  350. }
  351. static void
  352. lpfc_sli_update_ring(struct lpfc_hba * phba,
  353. struct lpfc_sli_ring *pring)
  354. {
  355. int ringno = pring->ringno;
  356. /*
  357. * Tell the HBA that there is work to do in this ring.
  358. */
  359. wmb();
  360. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  361. readl(phba->CAregaddr); /* flush */
  362. }
  363. static void
  364. lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
  365. {
  366. IOCB_t *iocb;
  367. struct lpfc_iocbq *nextiocb;
  368. /*
  369. * Check to see if:
  370. * (a) there is anything on the txq to send
  371. * (b) link is up
  372. * (c) link attention events can be processed (fcp ring only)
  373. * (d) IOCB processing is not blocked by the outstanding mbox command.
  374. */
  375. if (pring->txq_cnt &&
  376. (phba->hba_state > LPFC_LINK_DOWN) &&
  377. (pring->ringno != phba->sli.fcp_ring ||
  378. phba->sli.sli_flag & LPFC_PROCESS_LA) &&
  379. !(pring->flag & LPFC_STOP_IOCB_MBX)) {
  380. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  381. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  382. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  383. if (iocb)
  384. lpfc_sli_update_ring(phba, pring);
  385. else
  386. lpfc_sli_update_full_ring(phba, pring);
  387. }
  388. return;
  389. }
  390. /* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
  391. static void
  392. lpfc_sli_turn_on_ring(struct lpfc_hba * phba, int ringno)
  393. {
  394. struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[ringno];
  395. /* If the ring is active, flag it */
  396. if (phba->sli.ring[ringno].cmdringaddr) {
  397. if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
  398. phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
  399. /*
  400. * Force update of the local copy of cmdGetInx
  401. */
  402. phba->sli.ring[ringno].local_getidx
  403. = le32_to_cpu(pgp->cmdGetInx);
  404. spin_lock_irq(phba->host->host_lock);
  405. lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
  406. spin_unlock_irq(phba->host->host_lock);
  407. }
  408. }
  409. }
  410. static int
  411. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  412. {
  413. uint8_t ret;
  414. switch (mbxCommand) {
  415. case MBX_LOAD_SM:
  416. case MBX_READ_NV:
  417. case MBX_WRITE_NV:
  418. case MBX_RUN_BIU_DIAG:
  419. case MBX_INIT_LINK:
  420. case MBX_DOWN_LINK:
  421. case MBX_CONFIG_LINK:
  422. case MBX_CONFIG_RING:
  423. case MBX_RESET_RING:
  424. case MBX_READ_CONFIG:
  425. case MBX_READ_RCONFIG:
  426. case MBX_READ_SPARM:
  427. case MBX_READ_STATUS:
  428. case MBX_READ_RPI:
  429. case MBX_READ_XRI:
  430. case MBX_READ_REV:
  431. case MBX_READ_LNK_STAT:
  432. case MBX_REG_LOGIN:
  433. case MBX_UNREG_LOGIN:
  434. case MBX_READ_LA:
  435. case MBX_CLEAR_LA:
  436. case MBX_DUMP_MEMORY:
  437. case MBX_DUMP_CONTEXT:
  438. case MBX_RUN_DIAGS:
  439. case MBX_RESTART:
  440. case MBX_UPDATE_CFG:
  441. case MBX_DOWN_LOAD:
  442. case MBX_DEL_LD_ENTRY:
  443. case MBX_RUN_PROGRAM:
  444. case MBX_SET_MASK:
  445. case MBX_SET_SLIM:
  446. case MBX_UNREG_D_ID:
  447. case MBX_KILL_BOARD:
  448. case MBX_CONFIG_FARP:
  449. case MBX_BEACON:
  450. case MBX_LOAD_AREA:
  451. case MBX_RUN_BIU_DIAG64:
  452. case MBX_CONFIG_PORT:
  453. case MBX_READ_SPARM64:
  454. case MBX_READ_RPI64:
  455. case MBX_REG_LOGIN64:
  456. case MBX_READ_LA64:
  457. case MBX_FLASH_WR_ULA:
  458. case MBX_SET_DEBUG:
  459. case MBX_LOAD_EXP_ROM:
  460. ret = mbxCommand;
  461. break;
  462. default:
  463. ret = MBX_SHUTDOWN;
  464. break;
  465. }
  466. return (ret);
  467. }
  468. static void
  469. lpfc_sli_wake_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  470. {
  471. wait_queue_head_t *pdone_q;
  472. /*
  473. * If pdone_q is empty, the driver thread gave up waiting and
  474. * continued running.
  475. */
  476. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  477. pdone_q = (wait_queue_head_t *) pmboxq->context1;
  478. if (pdone_q)
  479. wake_up_interruptible(pdone_q);
  480. return;
  481. }
  482. void
  483. lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  484. {
  485. struct lpfc_dmabuf *mp;
  486. uint16_t rpi;
  487. int rc;
  488. mp = (struct lpfc_dmabuf *) (pmb->context1);
  489. if (mp) {
  490. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  491. kfree(mp);
  492. }
  493. /*
  494. * If a REG_LOGIN succeeded after node is destroyed or node
  495. * is in re-discovery driver need to cleanup the RPI.
  496. */
  497. if (!(phba->fc_flag & FC_UNLOADING) &&
  498. (pmb->mb.mbxCommand == MBX_REG_LOGIN64) &&
  499. (!pmb->mb.mbxStatus)) {
  500. rpi = pmb->mb.un.varWords[0];
  501. lpfc_unreg_login(phba, rpi, pmb);
  502. pmb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
  503. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  504. if (rc != MBX_NOT_FINISHED)
  505. return;
  506. }
  507. mempool_free( pmb, phba->mbox_mem_pool);
  508. return;
  509. }
  510. int
  511. lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
  512. {
  513. MAILBOX_t *mbox;
  514. MAILBOX_t *pmbox;
  515. LPFC_MBOXQ_t *pmb;
  516. struct lpfc_sli *psli;
  517. int i, rc;
  518. uint32_t process_next;
  519. psli = &phba->sli;
  520. /* We should only get here if we are in SLI2 mode */
  521. if (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE)) {
  522. return (1);
  523. }
  524. phba->sli.slistat.mbox_event++;
  525. /* Get a Mailbox buffer to setup mailbox commands for callback */
  526. if ((pmb = phba->sli.mbox_active)) {
  527. pmbox = &pmb->mb;
  528. mbox = &phba->slim2p->mbx;
  529. /* First check out the status word */
  530. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof (uint32_t));
  531. /* Sanity check to ensure the host owns the mailbox */
  532. if (pmbox->mbxOwner != OWN_HOST) {
  533. /* Lets try for a while */
  534. for (i = 0; i < 10240; i++) {
  535. /* First copy command data */
  536. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  537. sizeof (uint32_t));
  538. if (pmbox->mbxOwner == OWN_HOST)
  539. goto mbout;
  540. }
  541. /* Stray Mailbox Interrupt, mbxCommand <cmd> mbxStatus
  542. <status> */
  543. lpfc_printf_log(phba,
  544. KERN_WARNING,
  545. LOG_MBOX | LOG_SLI,
  546. "%d:0304 Stray Mailbox Interrupt "
  547. "mbxCommand x%x mbxStatus x%x\n",
  548. phba->brd_no,
  549. pmbox->mbxCommand,
  550. pmbox->mbxStatus);
  551. spin_lock_irq(phba->host->host_lock);
  552. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  553. spin_unlock_irq(phba->host->host_lock);
  554. return (1);
  555. }
  556. mbout:
  557. del_timer_sync(&phba->sli.mbox_tmo);
  558. phba->work_hba_events &= ~WORKER_MBOX_TMO;
  559. /*
  560. * It is a fatal error if unknown mbox command completion.
  561. */
  562. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  563. MBX_SHUTDOWN) {
  564. /* Unknow mailbox command compl */
  565. lpfc_printf_log(phba,
  566. KERN_ERR,
  567. LOG_MBOX | LOG_SLI,
  568. "%d:0323 Unknown Mailbox command %x Cmpl\n",
  569. phba->brd_no,
  570. pmbox->mbxCommand);
  571. phba->hba_state = LPFC_HBA_ERROR;
  572. phba->work_hs = HS_FFER3;
  573. lpfc_handle_eratt(phba);
  574. return (0);
  575. }
  576. phba->sli.mbox_active = NULL;
  577. if (pmbox->mbxStatus) {
  578. phba->sli.slistat.mbox_stat_err++;
  579. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  580. /* Mbox cmd cmpl error - RETRYing */
  581. lpfc_printf_log(phba,
  582. KERN_INFO,
  583. LOG_MBOX | LOG_SLI,
  584. "%d:0305 Mbox cmd cmpl error - "
  585. "RETRYing Data: x%x x%x x%x x%x\n",
  586. phba->brd_no,
  587. pmbox->mbxCommand,
  588. pmbox->mbxStatus,
  589. pmbox->un.varWords[0],
  590. phba->hba_state);
  591. pmbox->mbxStatus = 0;
  592. pmbox->mbxOwner = OWN_HOST;
  593. spin_lock_irq(phba->host->host_lock);
  594. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  595. spin_unlock_irq(phba->host->host_lock);
  596. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  597. if (rc == MBX_SUCCESS)
  598. return (0);
  599. }
  600. }
  601. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  602. lpfc_printf_log(phba,
  603. KERN_INFO,
  604. LOG_MBOX | LOG_SLI,
  605. "%d:0307 Mailbox cmd x%x Cmpl x%p "
  606. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
  607. phba->brd_no,
  608. pmbox->mbxCommand,
  609. pmb->mbox_cmpl,
  610. *((uint32_t *) pmbox),
  611. pmbox->un.varWords[0],
  612. pmbox->un.varWords[1],
  613. pmbox->un.varWords[2],
  614. pmbox->un.varWords[3],
  615. pmbox->un.varWords[4],
  616. pmbox->un.varWords[5],
  617. pmbox->un.varWords[6],
  618. pmbox->un.varWords[7]);
  619. if (pmb->mbox_cmpl) {
  620. lpfc_sli_pcimem_bcopy(mbox, pmbox, MAILBOX_CMD_SIZE);
  621. pmb->mbox_cmpl(phba,pmb);
  622. }
  623. }
  624. do {
  625. process_next = 0; /* by default don't loop */
  626. spin_lock_irq(phba->host->host_lock);
  627. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  628. /* Process next mailbox command if there is one */
  629. if ((pmb = lpfc_mbox_get(phba))) {
  630. spin_unlock_irq(phba->host->host_lock);
  631. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  632. if (rc == MBX_NOT_FINISHED) {
  633. pmb->mb.mbxStatus = MBX_NOT_FINISHED;
  634. pmb->mbox_cmpl(phba,pmb);
  635. process_next = 1;
  636. continue; /* loop back */
  637. }
  638. } else {
  639. spin_unlock_irq(phba->host->host_lock);
  640. /* Turn on IOCB processing */
  641. for (i = 0; i < phba->sli.num_rings; i++)
  642. lpfc_sli_turn_on_ring(phba, i);
  643. }
  644. } while (process_next);
  645. return (0);
  646. }
  647. static int
  648. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  649. struct lpfc_iocbq *saveq)
  650. {
  651. IOCB_t * irsp;
  652. WORD5 * w5p;
  653. uint32_t Rctl, Type;
  654. uint32_t match, i;
  655. match = 0;
  656. irsp = &(saveq->iocb);
  657. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
  658. || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)) {
  659. Rctl = FC_ELS_REQ;
  660. Type = FC_ELS_DATA;
  661. } else {
  662. w5p =
  663. (WORD5 *) & (saveq->iocb.un.
  664. ulpWord[5]);
  665. Rctl = w5p->hcsw.Rctl;
  666. Type = w5p->hcsw.Type;
  667. /* Firmware Workaround */
  668. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  669. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX)) {
  670. Rctl = FC_ELS_REQ;
  671. Type = FC_ELS_DATA;
  672. w5p->hcsw.Rctl = Rctl;
  673. w5p->hcsw.Type = Type;
  674. }
  675. }
  676. /* unSolicited Responses */
  677. if (pring->prt[0].profile) {
  678. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  679. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  680. saveq);
  681. match = 1;
  682. } else {
  683. /* We must search, based on rctl / type
  684. for the right routine */
  685. for (i = 0; i < pring->num_mask;
  686. i++) {
  687. if ((pring->prt[i].rctl ==
  688. Rctl)
  689. && (pring->prt[i].
  690. type == Type)) {
  691. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  692. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  693. (phba, pring, saveq);
  694. match = 1;
  695. break;
  696. }
  697. }
  698. }
  699. if (match == 0) {
  700. /* Unexpected Rctl / Type received */
  701. /* Ring <ringno> handler: unexpected
  702. Rctl <Rctl> Type <Type> received */
  703. lpfc_printf_log(phba,
  704. KERN_WARNING,
  705. LOG_SLI,
  706. "%d:0313 Ring %d handler: unexpected Rctl x%x "
  707. "Type x%x received \n",
  708. phba->brd_no,
  709. pring->ringno,
  710. Rctl,
  711. Type);
  712. }
  713. return(1);
  714. }
  715. static struct lpfc_iocbq *
  716. lpfc_sli_iocbq_lookup(struct lpfc_hba * phba,
  717. struct lpfc_sli_ring * pring,
  718. struct lpfc_iocbq * prspiocb)
  719. {
  720. struct lpfc_iocbq *cmd_iocb = NULL;
  721. uint16_t iotag;
  722. iotag = prspiocb->iocb.ulpIoTag;
  723. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  724. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  725. list_del(&cmd_iocb->list);
  726. pring->txcmplq_cnt--;
  727. return cmd_iocb;
  728. }
  729. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  730. "%d:0317 iotag x%x is out off "
  731. "range: max iotag x%x wd0 x%x\n",
  732. phba->brd_no, iotag,
  733. phba->sli.last_iotag,
  734. *(((uint32_t *) &prspiocb->iocb) + 7));
  735. return NULL;
  736. }
  737. static int
  738. lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
  739. struct lpfc_iocbq *saveq)
  740. {
  741. struct lpfc_iocbq * cmdiocbp;
  742. int rc = 1;
  743. unsigned long iflag;
  744. /* Based on the iotag field, get the cmd IOCB from the txcmplq */
  745. spin_lock_irqsave(phba->host->host_lock, iflag);
  746. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  747. if (cmdiocbp) {
  748. if (cmdiocbp->iocb_cmpl) {
  749. /*
  750. * Post all ELS completions to the worker thread.
  751. * All other are passed to the completion callback.
  752. */
  753. if (pring->ringno == LPFC_ELS_RING) {
  754. if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
  755. cmdiocbp->iocb_flag &=
  756. ~LPFC_DRIVER_ABORTED;
  757. saveq->iocb.ulpStatus =
  758. IOSTAT_LOCAL_REJECT;
  759. saveq->iocb.un.ulpWord[4] =
  760. IOERR_SLI_ABORTED;
  761. }
  762. spin_unlock_irqrestore(phba->host->host_lock,
  763. iflag);
  764. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  765. spin_lock_irqsave(phba->host->host_lock, iflag);
  766. }
  767. else {
  768. spin_unlock_irqrestore(phba->host->host_lock,
  769. iflag);
  770. (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
  771. spin_lock_irqsave(phba->host->host_lock, iflag);
  772. }
  773. } else
  774. lpfc_sli_release_iocbq(phba, cmdiocbp);
  775. } else {
  776. /*
  777. * Unknown initiating command based on the response iotag.
  778. * This could be the case on the ELS ring because of
  779. * lpfc_els_abort().
  780. */
  781. if (pring->ringno != LPFC_ELS_RING) {
  782. /*
  783. * Ring <ringno> handler: unexpected completion IoTag
  784. * <IoTag>
  785. */
  786. lpfc_printf_log(phba,
  787. KERN_WARNING,
  788. LOG_SLI,
  789. "%d:0322 Ring %d handler: unexpected "
  790. "completion IoTag x%x Data: x%x x%x x%x x%x\n",
  791. phba->brd_no,
  792. pring->ringno,
  793. saveq->iocb.ulpIoTag,
  794. saveq->iocb.ulpStatus,
  795. saveq->iocb.un.ulpWord[4],
  796. saveq->iocb.ulpCommand,
  797. saveq->iocb.ulpContext);
  798. }
  799. }
  800. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  801. return rc;
  802. }
  803. static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba,
  804. struct lpfc_sli_ring * pring)
  805. {
  806. struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
  807. /*
  808. * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
  809. * rsp ring <portRspMax>
  810. */
  811. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  812. "%d:0312 Ring %d handler: portRspPut %d "
  813. "is bigger then rsp ring %d\n",
  814. phba->brd_no, pring->ringno,
  815. le32_to_cpu(pgp->rspPutInx),
  816. pring->numRiocb);
  817. phba->hba_state = LPFC_HBA_ERROR;
  818. /*
  819. * All error attention handlers are posted to
  820. * worker thread
  821. */
  822. phba->work_ha |= HA_ERATT;
  823. phba->work_hs = HS_FFER3;
  824. if (phba->work_wait)
  825. wake_up(phba->work_wait);
  826. return;
  827. }
  828. void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
  829. {
  830. struct lpfc_sli * psli = &phba->sli;
  831. struct lpfc_sli_ring * pring = &psli->ring[LPFC_FCP_RING];
  832. IOCB_t *irsp = NULL;
  833. IOCB_t *entry = NULL;
  834. struct lpfc_iocbq *cmdiocbq = NULL;
  835. struct lpfc_iocbq rspiocbq;
  836. struct lpfc_pgp *pgp;
  837. uint32_t status;
  838. uint32_t portRspPut, portRspMax;
  839. int type;
  840. uint32_t rsp_cmpl = 0;
  841. void __iomem *to_slim;
  842. uint32_t ha_copy;
  843. pring->stats.iocb_event++;
  844. /* The driver assumes SLI-2 mode */
  845. pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
  846. /*
  847. * The next available response entry should never exceed the maximum
  848. * entries. If it does, treat it as an adapter hardware error.
  849. */
  850. portRspMax = pring->numRiocb;
  851. portRspPut = le32_to_cpu(pgp->rspPutInx);
  852. if (unlikely(portRspPut >= portRspMax)) {
  853. lpfc_sli_rsp_pointers_error(phba, pring);
  854. return;
  855. }
  856. rmb();
  857. while (pring->rspidx != portRspPut) {
  858. entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
  859. if (++pring->rspidx >= portRspMax)
  860. pring->rspidx = 0;
  861. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  862. (uint32_t *) &rspiocbq.iocb,
  863. sizeof (IOCB_t));
  864. irsp = &rspiocbq.iocb;
  865. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  866. pring->stats.iocb_rsp++;
  867. rsp_cmpl++;
  868. if (unlikely(irsp->ulpStatus)) {
  869. /* Rsp ring <ringno> error: IOCB */
  870. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  871. "%d:0326 Rsp Ring %d error: IOCB Data: "
  872. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  873. phba->brd_no, pring->ringno,
  874. irsp->un.ulpWord[0],
  875. irsp->un.ulpWord[1],
  876. irsp->un.ulpWord[2],
  877. irsp->un.ulpWord[3],
  878. irsp->un.ulpWord[4],
  879. irsp->un.ulpWord[5],
  880. *(((uint32_t *) irsp) + 6),
  881. *(((uint32_t *) irsp) + 7));
  882. }
  883. switch (type) {
  884. case LPFC_ABORT_IOCB:
  885. case LPFC_SOL_IOCB:
  886. /*
  887. * Idle exchange closed via ABTS from port. No iocb
  888. * resources need to be recovered.
  889. */
  890. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  891. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  892. "%d:0314 IOCB cmd 0x%x"
  893. " processed. Skipping"
  894. " completion", phba->brd_no,
  895. irsp->ulpCommand);
  896. break;
  897. }
  898. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  899. &rspiocbq);
  900. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  901. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  902. &rspiocbq);
  903. }
  904. break;
  905. default:
  906. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  907. char adaptermsg[LPFC_MAX_ADPTMSG];
  908. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  909. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  910. MAX_MSG_DATA);
  911. dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
  912. phba->brd_no, adaptermsg);
  913. } else {
  914. /* Unknown IOCB command */
  915. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  916. "%d:0321 Unknown IOCB command "
  917. "Data: x%x, x%x x%x x%x x%x\n",
  918. phba->brd_no, type,
  919. irsp->ulpCommand,
  920. irsp->ulpStatus,
  921. irsp->ulpIoTag,
  922. irsp->ulpContext);
  923. }
  924. break;
  925. }
  926. /*
  927. * The response IOCB has been processed. Update the ring
  928. * pointer in SLIM. If the port response put pointer has not
  929. * been updated, sync the pgp->rspPutInx and fetch the new port
  930. * response put pointer.
  931. */
  932. to_slim = phba->MBslimaddr +
  933. (SLIMOFF + (pring->ringno * 2) + 1) * 4;
  934. writeb(pring->rspidx, to_slim);
  935. if (pring->rspidx == portRspPut)
  936. portRspPut = le32_to_cpu(pgp->rspPutInx);
  937. }
  938. ha_copy = readl(phba->HAregaddr);
  939. ha_copy >>= (LPFC_FCP_RING * 4);
  940. if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
  941. pring->stats.iocb_rsp_full++;
  942. status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
  943. writel(status, phba->CAregaddr);
  944. readl(phba->CAregaddr);
  945. }
  946. if ((ha_copy & HA_R0CE_RSP) &&
  947. (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  948. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  949. pring->stats.iocb_cmd_empty++;
  950. /* Force update of the local copy of cmdGetInx */
  951. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  952. lpfc_sli_resume_iocb(phba, pring);
  953. if ((pring->lpfc_sli_cmd_available))
  954. (pring->lpfc_sli_cmd_available) (phba, pring);
  955. }
  956. return;
  957. }
  958. /*
  959. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  960. * to check it explicitly.
  961. */
  962. static int
  963. lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
  964. struct lpfc_sli_ring * pring, uint32_t mask)
  965. {
  966. struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
  967. IOCB_t *irsp = NULL;
  968. IOCB_t *entry = NULL;
  969. struct lpfc_iocbq *cmdiocbq = NULL;
  970. struct lpfc_iocbq rspiocbq;
  971. uint32_t status;
  972. uint32_t portRspPut, portRspMax;
  973. int rc = 1;
  974. lpfc_iocb_type type;
  975. unsigned long iflag;
  976. uint32_t rsp_cmpl = 0;
  977. void __iomem *to_slim;
  978. spin_lock_irqsave(phba->host->host_lock, iflag);
  979. pring->stats.iocb_event++;
  980. /*
  981. * The next available response entry should never exceed the maximum
  982. * entries. If it does, treat it as an adapter hardware error.
  983. */
  984. portRspMax = pring->numRiocb;
  985. portRspPut = le32_to_cpu(pgp->rspPutInx);
  986. if (unlikely(portRspPut >= portRspMax)) {
  987. lpfc_sli_rsp_pointers_error(phba, pring);
  988. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  989. return 1;
  990. }
  991. rmb();
  992. while (pring->rspidx != portRspPut) {
  993. /*
  994. * Fetch an entry off the ring and copy it into a local data
  995. * structure. The copy involves a byte-swap since the
  996. * network byte order and pci byte orders are different.
  997. */
  998. entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
  999. if (++pring->rspidx >= portRspMax)
  1000. pring->rspidx = 0;
  1001. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  1002. (uint32_t *) &rspiocbq.iocb,
  1003. sizeof (IOCB_t));
  1004. INIT_LIST_HEAD(&(rspiocbq.list));
  1005. irsp = &rspiocbq.iocb;
  1006. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  1007. pring->stats.iocb_rsp++;
  1008. rsp_cmpl++;
  1009. if (unlikely(irsp->ulpStatus)) {
  1010. /* Rsp ring <ringno> error: IOCB */
  1011. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1012. "%d:0336 Rsp Ring %d error: IOCB Data: "
  1013. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1014. phba->brd_no, pring->ringno,
  1015. irsp->un.ulpWord[0], irsp->un.ulpWord[1],
  1016. irsp->un.ulpWord[2], irsp->un.ulpWord[3],
  1017. irsp->un.ulpWord[4], irsp->un.ulpWord[5],
  1018. *(((uint32_t *) irsp) + 6),
  1019. *(((uint32_t *) irsp) + 7));
  1020. }
  1021. switch (type) {
  1022. case LPFC_ABORT_IOCB:
  1023. case LPFC_SOL_IOCB:
  1024. /*
  1025. * Idle exchange closed via ABTS from port. No iocb
  1026. * resources need to be recovered.
  1027. */
  1028. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  1029. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1030. "%d:0333 IOCB cmd 0x%x"
  1031. " processed. Skipping"
  1032. " completion\n", phba->brd_no,
  1033. irsp->ulpCommand);
  1034. break;
  1035. }
  1036. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  1037. &rspiocbq);
  1038. if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
  1039. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  1040. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  1041. &rspiocbq);
  1042. } else {
  1043. spin_unlock_irqrestore(
  1044. phba->host->host_lock, iflag);
  1045. (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
  1046. &rspiocbq);
  1047. spin_lock_irqsave(phba->host->host_lock,
  1048. iflag);
  1049. }
  1050. }
  1051. break;
  1052. case LPFC_UNSOL_IOCB:
  1053. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1054. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  1055. spin_lock_irqsave(phba->host->host_lock, iflag);
  1056. break;
  1057. default:
  1058. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  1059. char adaptermsg[LPFC_MAX_ADPTMSG];
  1060. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  1061. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  1062. MAX_MSG_DATA);
  1063. dev_warn(&((phba->pcidev)->dev), "lpfc%d: %s",
  1064. phba->brd_no, adaptermsg);
  1065. } else {
  1066. /* Unknown IOCB command */
  1067. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  1068. "%d:0334 Unknown IOCB command "
  1069. "Data: x%x, x%x x%x x%x x%x\n",
  1070. phba->brd_no, type, irsp->ulpCommand,
  1071. irsp->ulpStatus, irsp->ulpIoTag,
  1072. irsp->ulpContext);
  1073. }
  1074. break;
  1075. }
  1076. /*
  1077. * The response IOCB has been processed. Update the ring
  1078. * pointer in SLIM. If the port response put pointer has not
  1079. * been updated, sync the pgp->rspPutInx and fetch the new port
  1080. * response put pointer.
  1081. */
  1082. to_slim = phba->MBslimaddr +
  1083. (SLIMOFF + (pring->ringno * 2) + 1) * 4;
  1084. writel(pring->rspidx, to_slim);
  1085. if (pring->rspidx == portRspPut)
  1086. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1087. }
  1088. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  1089. pring->stats.iocb_rsp_full++;
  1090. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  1091. writel(status, phba->CAregaddr);
  1092. readl(phba->CAregaddr);
  1093. }
  1094. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  1095. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  1096. pring->stats.iocb_cmd_empty++;
  1097. /* Force update of the local copy of cmdGetInx */
  1098. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1099. lpfc_sli_resume_iocb(phba, pring);
  1100. if ((pring->lpfc_sli_cmd_available))
  1101. (pring->lpfc_sli_cmd_available) (phba, pring);
  1102. }
  1103. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1104. return rc;
  1105. }
  1106. int
  1107. lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
  1108. struct lpfc_sli_ring * pring, uint32_t mask)
  1109. {
  1110. IOCB_t *entry;
  1111. IOCB_t *irsp = NULL;
  1112. struct lpfc_iocbq *rspiocbp = NULL;
  1113. struct lpfc_iocbq *next_iocb;
  1114. struct lpfc_iocbq *cmdiocbp;
  1115. struct lpfc_iocbq *saveq;
  1116. struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
  1117. uint8_t iocb_cmd_type;
  1118. lpfc_iocb_type type;
  1119. uint32_t status, free_saveq;
  1120. uint32_t portRspPut, portRspMax;
  1121. int rc = 1;
  1122. unsigned long iflag;
  1123. void __iomem *to_slim;
  1124. spin_lock_irqsave(phba->host->host_lock, iflag);
  1125. pring->stats.iocb_event++;
  1126. /*
  1127. * The next available response entry should never exceed the maximum
  1128. * entries. If it does, treat it as an adapter hardware error.
  1129. */
  1130. portRspMax = pring->numRiocb;
  1131. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1132. if (portRspPut >= portRspMax) {
  1133. /*
  1134. * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
  1135. * rsp ring <portRspMax>
  1136. */
  1137. lpfc_printf_log(phba,
  1138. KERN_ERR,
  1139. LOG_SLI,
  1140. "%d:0303 Ring %d handler: portRspPut %d "
  1141. "is bigger then rsp ring %d\n",
  1142. phba->brd_no,
  1143. pring->ringno, portRspPut, portRspMax);
  1144. phba->hba_state = LPFC_HBA_ERROR;
  1145. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1146. phba->work_hs = HS_FFER3;
  1147. lpfc_handle_eratt(phba);
  1148. return 1;
  1149. }
  1150. rmb();
  1151. while (pring->rspidx != portRspPut) {
  1152. /*
  1153. * Build a completion list and call the appropriate handler.
  1154. * The process is to get the next available response iocb, get
  1155. * a free iocb from the list, copy the response data into the
  1156. * free iocb, insert to the continuation list, and update the
  1157. * next response index to slim. This process makes response
  1158. * iocb's in the ring available to DMA as fast as possible but
  1159. * pays a penalty for a copy operation. Since the iocb is
  1160. * only 32 bytes, this penalty is considered small relative to
  1161. * the PCI reads for register values and a slim write. When
  1162. * the ulpLe field is set, the entire Command has been
  1163. * received.
  1164. */
  1165. entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
  1166. rspiocbp = lpfc_sli_get_iocbq(phba);
  1167. if (rspiocbp == NULL) {
  1168. printk(KERN_ERR "%s: out of buffers! Failing "
  1169. "completion.\n", __FUNCTION__);
  1170. break;
  1171. }
  1172. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, sizeof (IOCB_t));
  1173. irsp = &rspiocbp->iocb;
  1174. if (++pring->rspidx >= portRspMax)
  1175. pring->rspidx = 0;
  1176. to_slim = phba->MBslimaddr + (SLIMOFF + (pring->ringno * 2)
  1177. + 1) * 4;
  1178. writel(pring->rspidx, to_slim);
  1179. if (list_empty(&(pring->iocb_continueq))) {
  1180. list_add(&rspiocbp->list, &(pring->iocb_continueq));
  1181. } else {
  1182. list_add_tail(&rspiocbp->list,
  1183. &(pring->iocb_continueq));
  1184. }
  1185. pring->iocb_continueq_cnt++;
  1186. if (irsp->ulpLe) {
  1187. /*
  1188. * By default, the driver expects to free all resources
  1189. * associated with this iocb completion.
  1190. */
  1191. free_saveq = 1;
  1192. saveq = list_get_first(&pring->iocb_continueq,
  1193. struct lpfc_iocbq, list);
  1194. irsp = &(saveq->iocb);
  1195. list_del_init(&pring->iocb_continueq);
  1196. pring->iocb_continueq_cnt = 0;
  1197. pring->stats.iocb_rsp++;
  1198. if (irsp->ulpStatus) {
  1199. /* Rsp ring <ringno> error: IOCB */
  1200. lpfc_printf_log(phba,
  1201. KERN_WARNING,
  1202. LOG_SLI,
  1203. "%d:0328 Rsp Ring %d error: IOCB Data: "
  1204. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  1205. phba->brd_no,
  1206. pring->ringno,
  1207. irsp->un.ulpWord[0],
  1208. irsp->un.ulpWord[1],
  1209. irsp->un.ulpWord[2],
  1210. irsp->un.ulpWord[3],
  1211. irsp->un.ulpWord[4],
  1212. irsp->un.ulpWord[5],
  1213. *(((uint32_t *) irsp) + 6),
  1214. *(((uint32_t *) irsp) + 7));
  1215. }
  1216. /*
  1217. * Fetch the IOCB command type and call the correct
  1218. * completion routine. Solicited and Unsolicited
  1219. * IOCBs on the ELS ring get freed back to the
  1220. * lpfc_iocb_list by the discovery kernel thread.
  1221. */
  1222. iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
  1223. type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
  1224. if (type == LPFC_SOL_IOCB) {
  1225. spin_unlock_irqrestore(phba->host->host_lock,
  1226. iflag);
  1227. rc = lpfc_sli_process_sol_iocb(phba, pring,
  1228. saveq);
  1229. spin_lock_irqsave(phba->host->host_lock, iflag);
  1230. } else if (type == LPFC_UNSOL_IOCB) {
  1231. spin_unlock_irqrestore(phba->host->host_lock,
  1232. iflag);
  1233. rc = lpfc_sli_process_unsol_iocb(phba, pring,
  1234. saveq);
  1235. spin_lock_irqsave(phba->host->host_lock, iflag);
  1236. } else if (type == LPFC_ABORT_IOCB) {
  1237. if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
  1238. ((cmdiocbp =
  1239. lpfc_sli_iocbq_lookup(phba, pring,
  1240. saveq)))) {
  1241. /* Call the specified completion
  1242. routine */
  1243. if (cmdiocbp->iocb_cmpl) {
  1244. spin_unlock_irqrestore(
  1245. phba->host->host_lock,
  1246. iflag);
  1247. (cmdiocbp->iocb_cmpl) (phba,
  1248. cmdiocbp, saveq);
  1249. spin_lock_irqsave(
  1250. phba->host->host_lock,
  1251. iflag);
  1252. } else
  1253. lpfc_sli_release_iocbq(phba,
  1254. cmdiocbp);
  1255. }
  1256. } else if (type == LPFC_UNKNOWN_IOCB) {
  1257. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  1258. char adaptermsg[LPFC_MAX_ADPTMSG];
  1259. memset(adaptermsg, 0,
  1260. LPFC_MAX_ADPTMSG);
  1261. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  1262. MAX_MSG_DATA);
  1263. dev_warn(&((phba->pcidev)->dev),
  1264. "lpfc%d: %s",
  1265. phba->brd_no, adaptermsg);
  1266. } else {
  1267. /* Unknown IOCB command */
  1268. lpfc_printf_log(phba,
  1269. KERN_ERR,
  1270. LOG_SLI,
  1271. "%d:0335 Unknown IOCB command "
  1272. "Data: x%x x%x x%x x%x\n",
  1273. phba->brd_no,
  1274. irsp->ulpCommand,
  1275. irsp->ulpStatus,
  1276. irsp->ulpIoTag,
  1277. irsp->ulpContext);
  1278. }
  1279. }
  1280. if (free_saveq) {
  1281. if (!list_empty(&saveq->list)) {
  1282. list_for_each_entry_safe(rspiocbp,
  1283. next_iocb,
  1284. &saveq->list,
  1285. list) {
  1286. list_del(&rspiocbp->list);
  1287. lpfc_sli_release_iocbq(phba,
  1288. rspiocbp);
  1289. }
  1290. }
  1291. lpfc_sli_release_iocbq(phba, saveq);
  1292. }
  1293. }
  1294. /*
  1295. * If the port response put pointer has not been updated, sync
  1296. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  1297. * response put pointer.
  1298. */
  1299. if (pring->rspidx == portRspPut) {
  1300. portRspPut = le32_to_cpu(pgp->rspPutInx);
  1301. }
  1302. } /* while (pring->rspidx != portRspPut) */
  1303. if ((rspiocbp != 0) && (mask & HA_R0RE_REQ)) {
  1304. /* At least one response entry has been freed */
  1305. pring->stats.iocb_rsp_full++;
  1306. /* SET RxRE_RSP in Chip Att register */
  1307. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  1308. writel(status, phba->CAregaddr);
  1309. readl(phba->CAregaddr); /* flush */
  1310. }
  1311. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  1312. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  1313. pring->stats.iocb_cmd_empty++;
  1314. /* Force update of the local copy of cmdGetInx */
  1315. pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1316. lpfc_sli_resume_iocb(phba, pring);
  1317. if ((pring->lpfc_sli_cmd_available))
  1318. (pring->lpfc_sli_cmd_available) (phba, pring);
  1319. }
  1320. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1321. return rc;
  1322. }
  1323. int
  1324. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1325. {
  1326. LIST_HEAD(completions);
  1327. struct lpfc_iocbq *iocb, *next_iocb;
  1328. IOCB_t *cmd = NULL;
  1329. int errcnt;
  1330. errcnt = 0;
  1331. /* Error everything on txq and txcmplq
  1332. * First do the txq.
  1333. */
  1334. spin_lock_irq(phba->host->host_lock);
  1335. list_splice_init(&pring->txq, &completions);
  1336. pring->txq_cnt = 0;
  1337. /* Next issue ABTS for everything on the txcmplq */
  1338. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
  1339. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  1340. spin_unlock_irq(phba->host->host_lock);
  1341. while (!list_empty(&completions)) {
  1342. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  1343. cmd = &iocb->iocb;
  1344. list_del(&iocb->list);
  1345. if (iocb->iocb_cmpl) {
  1346. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  1347. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  1348. (iocb->iocb_cmpl) (phba, iocb, iocb);
  1349. } else
  1350. lpfc_sli_release_iocbq(phba, iocb);
  1351. }
  1352. return errcnt;
  1353. }
  1354. int
  1355. lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
  1356. {
  1357. uint32_t status;
  1358. int i = 0;
  1359. int retval = 0;
  1360. /* Read the HBA Host Status Register */
  1361. status = readl(phba->HSregaddr);
  1362. /*
  1363. * Check status register every 100ms for 5 retries, then every
  1364. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  1365. * every 2.5 sec for 4.
  1366. * Break our of the loop if errors occurred during init.
  1367. */
  1368. while (((status & mask) != mask) &&
  1369. !(status & HS_FFERM) &&
  1370. i++ < 20) {
  1371. if (i <= 5)
  1372. msleep(10);
  1373. else if (i <= 10)
  1374. msleep(500);
  1375. else
  1376. msleep(2500);
  1377. if (i == 15) {
  1378. phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
  1379. lpfc_sli_brdrestart(phba);
  1380. }
  1381. /* Read the HBA Host Status Register */
  1382. status = readl(phba->HSregaddr);
  1383. }
  1384. /* Check to see if any errors occurred during init */
  1385. if ((status & HS_FFERM) || (i >= 20)) {
  1386. phba->hba_state = LPFC_HBA_ERROR;
  1387. retval = 1;
  1388. }
  1389. return retval;
  1390. }
  1391. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  1392. void lpfc_reset_barrier(struct lpfc_hba * phba)
  1393. {
  1394. uint32_t __iomem *resp_buf;
  1395. uint32_t __iomem *mbox_buf;
  1396. volatile uint32_t mbox;
  1397. uint32_t hc_copy;
  1398. int i;
  1399. uint8_t hdrtype;
  1400. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  1401. if (hdrtype != 0x80 ||
  1402. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  1403. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  1404. return;
  1405. /*
  1406. * Tell the other part of the chip to suspend temporarily all
  1407. * its DMA activity.
  1408. */
  1409. resp_buf = phba->MBslimaddr;
  1410. /* Disable the error attention */
  1411. hc_copy = readl(phba->HCregaddr);
  1412. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  1413. readl(phba->HCregaddr); /* flush */
  1414. phba->fc_flag |= FC_IGNORE_ERATT;
  1415. if (readl(phba->HAregaddr) & HA_ERATT) {
  1416. /* Clear Chip error bit */
  1417. writel(HA_ERATT, phba->HAregaddr);
  1418. phba->stopped = 1;
  1419. }
  1420. mbox = 0;
  1421. ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
  1422. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
  1423. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  1424. mbox_buf = phba->MBslimaddr;
  1425. writel(mbox, mbox_buf);
  1426. for (i = 0;
  1427. readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
  1428. mdelay(1);
  1429. if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
  1430. if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
  1431. phba->stopped)
  1432. goto restore_hc;
  1433. else
  1434. goto clear_errat;
  1435. }
  1436. ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
  1437. for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
  1438. mdelay(1);
  1439. clear_errat:
  1440. while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
  1441. mdelay(1);
  1442. if (readl(phba->HAregaddr) & HA_ERATT) {
  1443. writel(HA_ERATT, phba->HAregaddr);
  1444. phba->stopped = 1;
  1445. }
  1446. restore_hc:
  1447. phba->fc_flag &= ~FC_IGNORE_ERATT;
  1448. writel(hc_copy, phba->HCregaddr);
  1449. readl(phba->HCregaddr); /* flush */
  1450. }
  1451. int
  1452. lpfc_sli_brdkill(struct lpfc_hba * phba)
  1453. {
  1454. struct lpfc_sli *psli;
  1455. LPFC_MBOXQ_t *pmb;
  1456. uint32_t status;
  1457. uint32_t ha_copy;
  1458. int retval;
  1459. int i = 0;
  1460. psli = &phba->sli;
  1461. /* Kill HBA */
  1462. lpfc_printf_log(phba,
  1463. KERN_INFO,
  1464. LOG_SLI,
  1465. "%d:0329 Kill HBA Data: x%x x%x\n",
  1466. phba->brd_no,
  1467. phba->hba_state,
  1468. psli->sli_flag);
  1469. if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
  1470. GFP_KERNEL)) == 0)
  1471. return 1;
  1472. /* Disable the error attention */
  1473. spin_lock_irq(phba->host->host_lock);
  1474. status = readl(phba->HCregaddr);
  1475. status &= ~HC_ERINT_ENA;
  1476. writel(status, phba->HCregaddr);
  1477. readl(phba->HCregaddr); /* flush */
  1478. phba->fc_flag |= FC_IGNORE_ERATT;
  1479. spin_unlock_irq(phba->host->host_lock);
  1480. lpfc_kill_board(phba, pmb);
  1481. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1482. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  1483. if (retval != MBX_SUCCESS) {
  1484. if (retval != MBX_BUSY)
  1485. mempool_free(pmb, phba->mbox_mem_pool);
  1486. spin_lock_irq(phba->host->host_lock);
  1487. phba->fc_flag &= ~FC_IGNORE_ERATT;
  1488. spin_unlock_irq(phba->host->host_lock);
  1489. return 1;
  1490. }
  1491. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  1492. mempool_free(pmb, phba->mbox_mem_pool);
  1493. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  1494. * attention every 100ms for 3 seconds. If we don't get ERATT after
  1495. * 3 seconds we still set HBA_ERROR state because the status of the
  1496. * board is now undefined.
  1497. */
  1498. ha_copy = readl(phba->HAregaddr);
  1499. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  1500. mdelay(100);
  1501. ha_copy = readl(phba->HAregaddr);
  1502. }
  1503. del_timer_sync(&psli->mbox_tmo);
  1504. if (ha_copy & HA_ERATT) {
  1505. writel(HA_ERATT, phba->HAregaddr);
  1506. phba->stopped = 1;
  1507. }
  1508. spin_lock_irq(phba->host->host_lock);
  1509. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  1510. phba->fc_flag &= ~FC_IGNORE_ERATT;
  1511. spin_unlock_irq(phba->host->host_lock);
  1512. psli->mbox_active = NULL;
  1513. lpfc_hba_down_post(phba);
  1514. phba->hba_state = LPFC_HBA_ERROR;
  1515. return (ha_copy & HA_ERATT ? 0 : 1);
  1516. }
  1517. int
  1518. lpfc_sli_brdreset(struct lpfc_hba * phba)
  1519. {
  1520. struct lpfc_sli *psli;
  1521. struct lpfc_sli_ring *pring;
  1522. uint16_t cfg_value;
  1523. int i;
  1524. psli = &phba->sli;
  1525. /* Reset HBA */
  1526. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1527. "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
  1528. phba->hba_state, psli->sli_flag);
  1529. /* perform board reset */
  1530. phba->fc_eventTag = 0;
  1531. phba->fc_myDID = 0;
  1532. phba->fc_prevDID = 0;
  1533. /* Turn off parity checking and serr during the physical reset */
  1534. pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
  1535. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  1536. (cfg_value &
  1537. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  1538. psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
  1539. /* Now toggle INITFF bit in the Host Control Register */
  1540. writel(HC_INITFF, phba->HCregaddr);
  1541. mdelay(1);
  1542. readl(phba->HCregaddr); /* flush */
  1543. writel(0, phba->HCregaddr);
  1544. readl(phba->HCregaddr); /* flush */
  1545. /* Restore PCI cmd register */
  1546. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  1547. /* Initialize relevant SLI info */
  1548. for (i = 0; i < psli->num_rings; i++) {
  1549. pring = &psli->ring[i];
  1550. pring->flag = 0;
  1551. pring->rspidx = 0;
  1552. pring->next_cmdidx = 0;
  1553. pring->local_getidx = 0;
  1554. pring->cmdidx = 0;
  1555. pring->missbufcnt = 0;
  1556. }
  1557. phba->hba_state = LPFC_WARM_START;
  1558. return 0;
  1559. }
  1560. int
  1561. lpfc_sli_brdrestart(struct lpfc_hba * phba)
  1562. {
  1563. MAILBOX_t *mb;
  1564. struct lpfc_sli *psli;
  1565. uint16_t skip_post;
  1566. volatile uint32_t word0;
  1567. void __iomem *to_slim;
  1568. spin_lock_irq(phba->host->host_lock);
  1569. psli = &phba->sli;
  1570. /* Restart HBA */
  1571. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1572. "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
  1573. phba->hba_state, psli->sli_flag);
  1574. word0 = 0;
  1575. mb = (MAILBOX_t *) &word0;
  1576. mb->mbxCommand = MBX_RESTART;
  1577. mb->mbxHc = 1;
  1578. lpfc_reset_barrier(phba);
  1579. to_slim = phba->MBslimaddr;
  1580. writel(*(uint32_t *) mb, to_slim);
  1581. readl(to_slim); /* flush */
  1582. /* Only skip post after fc_ffinit is completed */
  1583. if (phba->hba_state) {
  1584. skip_post = 1;
  1585. word0 = 1; /* This is really setting up word1 */
  1586. } else {
  1587. skip_post = 0;
  1588. word0 = 0; /* This is really setting up word1 */
  1589. }
  1590. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  1591. writel(*(uint32_t *) mb, to_slim);
  1592. readl(to_slim); /* flush */
  1593. lpfc_sli_brdreset(phba);
  1594. phba->stopped = 0;
  1595. phba->hba_state = LPFC_INIT_START;
  1596. spin_unlock_irq(phba->host->host_lock);
  1597. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  1598. psli->stats_start = get_seconds();
  1599. if (skip_post)
  1600. mdelay(100);
  1601. else
  1602. mdelay(2000);
  1603. lpfc_hba_down_post(phba);
  1604. return 0;
  1605. }
  1606. static int
  1607. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  1608. {
  1609. uint32_t status, i = 0;
  1610. /* Read the HBA Host Status Register */
  1611. status = readl(phba->HSregaddr);
  1612. /* Check status register to see what current state is */
  1613. i = 0;
  1614. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  1615. /* Check every 100ms for 5 retries, then every 500ms for 5, then
  1616. * every 2.5 sec for 5, then reset board and every 2.5 sec for
  1617. * 4.
  1618. */
  1619. if (i++ >= 20) {
  1620. /* Adapter failed to init, timeout, status reg
  1621. <status> */
  1622. lpfc_printf_log(phba,
  1623. KERN_ERR,
  1624. LOG_INIT,
  1625. "%d:0436 Adapter failed to init, "
  1626. "timeout, status reg x%x\n",
  1627. phba->brd_no,
  1628. status);
  1629. phba->hba_state = LPFC_HBA_ERROR;
  1630. return -ETIMEDOUT;
  1631. }
  1632. /* Check to see if any errors occurred during init */
  1633. if (status & HS_FFERM) {
  1634. /* ERROR: During chipset initialization */
  1635. /* Adapter failed to init, chipset, status reg
  1636. <status> */
  1637. lpfc_printf_log(phba,
  1638. KERN_ERR,
  1639. LOG_INIT,
  1640. "%d:0437 Adapter failed to init, "
  1641. "chipset, status reg x%x\n",
  1642. phba->brd_no,
  1643. status);
  1644. phba->hba_state = LPFC_HBA_ERROR;
  1645. return -EIO;
  1646. }
  1647. if (i <= 5) {
  1648. msleep(10);
  1649. } else if (i <= 10) {
  1650. msleep(500);
  1651. } else {
  1652. msleep(2500);
  1653. }
  1654. if (i == 15) {
  1655. phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */
  1656. lpfc_sli_brdrestart(phba);
  1657. }
  1658. /* Read the HBA Host Status Register */
  1659. status = readl(phba->HSregaddr);
  1660. }
  1661. /* Check to see if any errors occurred during init */
  1662. if (status & HS_FFERM) {
  1663. /* ERROR: During chipset initialization */
  1664. /* Adapter failed to init, chipset, status reg <status> */
  1665. lpfc_printf_log(phba,
  1666. KERN_ERR,
  1667. LOG_INIT,
  1668. "%d:0438 Adapter failed to init, chipset, "
  1669. "status reg x%x\n",
  1670. phba->brd_no,
  1671. status);
  1672. phba->hba_state = LPFC_HBA_ERROR;
  1673. return -EIO;
  1674. }
  1675. /* Clear all interrupt enable conditions */
  1676. writel(0, phba->HCregaddr);
  1677. readl(phba->HCregaddr); /* flush */
  1678. /* setup host attn register */
  1679. writel(0xffffffff, phba->HAregaddr);
  1680. readl(phba->HAregaddr); /* flush */
  1681. return 0;
  1682. }
  1683. int
  1684. lpfc_sli_hba_setup(struct lpfc_hba * phba)
  1685. {
  1686. LPFC_MBOXQ_t *pmb;
  1687. uint32_t resetcount = 0, rc = 0, done = 0;
  1688. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1689. if (!pmb) {
  1690. phba->hba_state = LPFC_HBA_ERROR;
  1691. return -ENOMEM;
  1692. }
  1693. while (resetcount < 2 && !done) {
  1694. spin_lock_irq(phba->host->host_lock);
  1695. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  1696. spin_unlock_irq(phba->host->host_lock);
  1697. phba->hba_state = LPFC_STATE_UNKNOWN;
  1698. lpfc_sli_brdrestart(phba);
  1699. msleep(2500);
  1700. rc = lpfc_sli_chipset_init(phba);
  1701. if (rc)
  1702. break;
  1703. spin_lock_irq(phba->host->host_lock);
  1704. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  1705. spin_unlock_irq(phba->host->host_lock);
  1706. resetcount++;
  1707. /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
  1708. * means the call was successful. Any other nonzero value is a failure,
  1709. * but if ERESTART is returned, the driver may reset the HBA and try
  1710. * again.
  1711. */
  1712. rc = lpfc_config_port_prep(phba);
  1713. if (rc == -ERESTART) {
  1714. phba->hba_state = 0;
  1715. continue;
  1716. } else if (rc) {
  1717. break;
  1718. }
  1719. phba->hba_state = LPFC_INIT_MBX_CMDS;
  1720. lpfc_config_port(phba, pmb);
  1721. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1722. if (rc == MBX_SUCCESS)
  1723. done = 1;
  1724. else {
  1725. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1726. "%d:0442 Adapter failed to init, mbxCmd x%x "
  1727. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  1728. phba->brd_no, pmb->mb.mbxCommand,
  1729. pmb->mb.mbxStatus, 0);
  1730. phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
  1731. }
  1732. }
  1733. if (!done)
  1734. goto lpfc_sli_hba_setup_error;
  1735. rc = lpfc_sli_ring_map(phba, pmb);
  1736. if (rc)
  1737. goto lpfc_sli_hba_setup_error;
  1738. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  1739. rc = lpfc_config_port_post(phba);
  1740. if (rc)
  1741. goto lpfc_sli_hba_setup_error;
  1742. goto lpfc_sli_hba_setup_exit;
  1743. lpfc_sli_hba_setup_error:
  1744. phba->hba_state = LPFC_HBA_ERROR;
  1745. lpfc_sli_hba_setup_exit:
  1746. mempool_free(pmb, phba->mbox_mem_pool);
  1747. return rc;
  1748. }
  1749. /*! lpfc_mbox_timeout
  1750. *
  1751. * \pre
  1752. * \post
  1753. * \param hba Pointer to per struct lpfc_hba structure
  1754. * \param l1 Pointer to the driver's mailbox queue.
  1755. * \return
  1756. * void
  1757. *
  1758. * \b Description:
  1759. *
  1760. * This routine handles mailbox timeout events at timer interrupt context.
  1761. */
  1762. void
  1763. lpfc_mbox_timeout(unsigned long ptr)
  1764. {
  1765. struct lpfc_hba *phba;
  1766. unsigned long iflag;
  1767. phba = (struct lpfc_hba *)ptr;
  1768. spin_lock_irqsave(phba->host->host_lock, iflag);
  1769. if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
  1770. phba->work_hba_events |= WORKER_MBOX_TMO;
  1771. if (phba->work_wait)
  1772. wake_up(phba->work_wait);
  1773. }
  1774. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1775. }
  1776. void
  1777. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  1778. {
  1779. LPFC_MBOXQ_t *pmbox;
  1780. MAILBOX_t *mb;
  1781. struct lpfc_sli *psli = &phba->sli;
  1782. struct lpfc_sli_ring *pring;
  1783. spin_lock_irq(phba->host->host_lock);
  1784. if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
  1785. spin_unlock_irq(phba->host->host_lock);
  1786. return;
  1787. }
  1788. pmbox = phba->sli.mbox_active;
  1789. mb = &pmbox->mb;
  1790. /* Mbox cmd <mbxCommand> timeout */
  1791. lpfc_printf_log(phba,
  1792. KERN_ERR,
  1793. LOG_MBOX | LOG_SLI,
  1794. "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
  1795. phba->brd_no,
  1796. mb->mbxCommand,
  1797. phba->hba_state,
  1798. phba->sli.sli_flag,
  1799. phba->sli.mbox_active);
  1800. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  1801. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  1802. * it to fail all oustanding SCSI IO.
  1803. */
  1804. phba->hba_state = LPFC_STATE_UNKNOWN;
  1805. phba->work_hba_events &= ~WORKER_MBOX_TMO;
  1806. phba->fc_flag |= FC_ESTABLISH_LINK;
  1807. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  1808. spin_unlock_irq(phba->host->host_lock);
  1809. pring = &psli->ring[psli->fcp_ring];
  1810. lpfc_sli_abort_iocb_ring(phba, pring);
  1811. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  1812. "%d:0316 Resetting board due to mailbox timeout\n",
  1813. phba->brd_no);
  1814. /*
  1815. * lpfc_offline calls lpfc_sli_hba_down which will clean up
  1816. * on oustanding mailbox commands.
  1817. */
  1818. lpfc_offline_prep(phba);
  1819. lpfc_offline(phba);
  1820. lpfc_sli_brdrestart(phba);
  1821. if (lpfc_online(phba) == 0) /* Initialize the HBA */
  1822. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  1823. lpfc_unblock_mgmt_io(phba);
  1824. return;
  1825. }
  1826. int
  1827. lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
  1828. {
  1829. MAILBOX_t *mb;
  1830. struct lpfc_sli *psli;
  1831. uint32_t status, evtctr;
  1832. uint32_t ha_copy;
  1833. int i;
  1834. unsigned long drvr_flag = 0;
  1835. volatile uint32_t word0, ldata;
  1836. void __iomem *to_slim;
  1837. /* If the PCI channel is in offline state, do not post mbox. */
  1838. if (unlikely(pci_channel_offline(phba->pcidev)))
  1839. return MBX_NOT_FINISHED;
  1840. psli = &phba->sli;
  1841. spin_lock_irqsave(phba->host->host_lock, drvr_flag);
  1842. mb = &pmbox->mb;
  1843. status = MBX_SUCCESS;
  1844. if (phba->hba_state == LPFC_HBA_ERROR) {
  1845. spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
  1846. /* Mbox command <mbxCommand> cannot issue */
  1847. LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
  1848. return (MBX_NOT_FINISHED);
  1849. }
  1850. if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
  1851. !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
  1852. spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
  1853. LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
  1854. return (MBX_NOT_FINISHED);
  1855. }
  1856. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  1857. /* Polling for a mbox command when another one is already active
  1858. * is not allowed in SLI. Also, the driver must have established
  1859. * SLI2 mode to queue and process multiple mbox commands.
  1860. */
  1861. if (flag & MBX_POLL) {
  1862. spin_unlock_irqrestore(phba->host->host_lock,
  1863. drvr_flag);
  1864. /* Mbox command <mbxCommand> cannot issue */
  1865. LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
  1866. return (MBX_NOT_FINISHED);
  1867. }
  1868. if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
  1869. spin_unlock_irqrestore(phba->host->host_lock,
  1870. drvr_flag);
  1871. /* Mbox command <mbxCommand> cannot issue */
  1872. LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
  1873. return (MBX_NOT_FINISHED);
  1874. }
  1875. /* Handle STOP IOCB processing flag. This is only meaningful
  1876. * if we are not polling for mbox completion.
  1877. */
  1878. if (flag & MBX_STOP_IOCB) {
  1879. flag &= ~MBX_STOP_IOCB;
  1880. /* Now flag each ring */
  1881. for (i = 0; i < psli->num_rings; i++) {
  1882. /* If the ring is active, flag it */
  1883. if (psli->ring[i].cmdringaddr) {
  1884. psli->ring[i].flag |=
  1885. LPFC_STOP_IOCB_MBX;
  1886. }
  1887. }
  1888. }
  1889. /* Another mailbox command is still being processed, queue this
  1890. * command to be processed later.
  1891. */
  1892. lpfc_mbox_put(phba, pmbox);
  1893. /* Mbox cmd issue - BUSY */
  1894. lpfc_printf_log(phba,
  1895. KERN_INFO,
  1896. LOG_MBOX | LOG_SLI,
  1897. "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
  1898. phba->brd_no,
  1899. mb->mbxCommand,
  1900. phba->hba_state,
  1901. psli->sli_flag,
  1902. flag);
  1903. psli->slistat.mbox_busy++;
  1904. spin_unlock_irqrestore(phba->host->host_lock,
  1905. drvr_flag);
  1906. return (MBX_BUSY);
  1907. }
  1908. /* Handle STOP IOCB processing flag. This is only meaningful
  1909. * if we are not polling for mbox completion.
  1910. */
  1911. if (flag & MBX_STOP_IOCB) {
  1912. flag &= ~MBX_STOP_IOCB;
  1913. if (flag == MBX_NOWAIT) {
  1914. /* Now flag each ring */
  1915. for (i = 0; i < psli->num_rings; i++) {
  1916. /* If the ring is active, flag it */
  1917. if (psli->ring[i].cmdringaddr) {
  1918. psli->ring[i].flag |=
  1919. LPFC_STOP_IOCB_MBX;
  1920. }
  1921. }
  1922. }
  1923. }
  1924. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  1925. /* If we are not polling, we MUST be in SLI2 mode */
  1926. if (flag != MBX_POLL) {
  1927. if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
  1928. (mb->mbxCommand != MBX_KILL_BOARD)) {
  1929. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  1930. spin_unlock_irqrestore(phba->host->host_lock,
  1931. drvr_flag);
  1932. /* Mbox command <mbxCommand> cannot issue */
  1933. LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
  1934. return (MBX_NOT_FINISHED);
  1935. }
  1936. /* timeout active mbox command */
  1937. mod_timer(&psli->mbox_tmo, (jiffies +
  1938. (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
  1939. }
  1940. /* Mailbox cmd <cmd> issue */
  1941. lpfc_printf_log(phba,
  1942. KERN_INFO,
  1943. LOG_MBOX | LOG_SLI,
  1944. "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
  1945. phba->brd_no,
  1946. mb->mbxCommand,
  1947. phba->hba_state,
  1948. psli->sli_flag,
  1949. flag);
  1950. psli->slistat.mbox_cmd++;
  1951. evtctr = psli->slistat.mbox_event;
  1952. /* next set own bit for the adapter and copy over command word */
  1953. mb->mbxOwner = OWN_CHIP;
  1954. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  1955. /* First copy command data to host SLIM area */
  1956. lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE);
  1957. } else {
  1958. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  1959. /* copy command data into host mbox for cmpl */
  1960. lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx,
  1961. MAILBOX_CMD_SIZE);
  1962. }
  1963. /* First copy mbox command data to HBA SLIM, skip past first
  1964. word */
  1965. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  1966. lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
  1967. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  1968. /* Next copy over first word, with mbxOwner set */
  1969. ldata = *((volatile uint32_t *)mb);
  1970. to_slim = phba->MBslimaddr;
  1971. writel(ldata, to_slim);
  1972. readl(to_slim); /* flush */
  1973. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  1974. /* switch over to host mailbox */
  1975. psli->sli_flag |= LPFC_SLI2_ACTIVE;
  1976. }
  1977. }
  1978. wmb();
  1979. /* interrupt board to doit right away */
  1980. writel(CA_MBATT, phba->CAregaddr);
  1981. readl(phba->CAregaddr); /* flush */
  1982. switch (flag) {
  1983. case MBX_NOWAIT:
  1984. /* Don't wait for it to finish, just return */
  1985. psli->mbox_active = pmbox;
  1986. break;
  1987. case MBX_POLL:
  1988. psli->mbox_active = NULL;
  1989. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  1990. /* First read mbox status word */
  1991. word0 = *((volatile uint32_t *)&phba->slim2p->mbx);
  1992. word0 = le32_to_cpu(word0);
  1993. } else {
  1994. /* First read mbox status word */
  1995. word0 = readl(phba->MBslimaddr);
  1996. }
  1997. /* Read the HBA Host Attention Register */
  1998. ha_copy = readl(phba->HAregaddr);
  1999. i = lpfc_mbox_tmo_val(phba, mb->mbxCommand);
  2000. i *= 1000; /* Convert to ms */
  2001. /* Wait for command to complete */
  2002. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  2003. (!(ha_copy & HA_MBATT) &&
  2004. (phba->hba_state > LPFC_WARM_START))) {
  2005. if (i-- <= 0) {
  2006. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2007. spin_unlock_irqrestore(phba->host->host_lock,
  2008. drvr_flag);
  2009. return (MBX_NOT_FINISHED);
  2010. }
  2011. /* Check if we took a mbox interrupt while we were
  2012. polling */
  2013. if (((word0 & OWN_CHIP) != OWN_CHIP)
  2014. && (evtctr != psli->slistat.mbox_event))
  2015. break;
  2016. spin_unlock_irqrestore(phba->host->host_lock,
  2017. drvr_flag);
  2018. msleep(1);
  2019. spin_lock_irqsave(phba->host->host_lock, drvr_flag);
  2020. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2021. /* First copy command data */
  2022. word0 = *((volatile uint32_t *)
  2023. &phba->slim2p->mbx);
  2024. word0 = le32_to_cpu(word0);
  2025. if (mb->mbxCommand == MBX_CONFIG_PORT) {
  2026. MAILBOX_t *slimmb;
  2027. volatile uint32_t slimword0;
  2028. /* Check real SLIM for any errors */
  2029. slimword0 = readl(phba->MBslimaddr);
  2030. slimmb = (MAILBOX_t *) & slimword0;
  2031. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  2032. && slimmb->mbxStatus) {
  2033. psli->sli_flag &=
  2034. ~LPFC_SLI2_ACTIVE;
  2035. word0 = slimword0;
  2036. }
  2037. }
  2038. } else {
  2039. /* First copy command data */
  2040. word0 = readl(phba->MBslimaddr);
  2041. }
  2042. /* Read the HBA Host Attention Register */
  2043. ha_copy = readl(phba->HAregaddr);
  2044. }
  2045. if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
  2046. /* copy results back to user */
  2047. lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb,
  2048. MAILBOX_CMD_SIZE);
  2049. } else {
  2050. /* First copy command data */
  2051. lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
  2052. MAILBOX_CMD_SIZE);
  2053. if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
  2054. pmbox->context2) {
  2055. lpfc_memcpy_from_slim((void *)pmbox->context2,
  2056. phba->MBslimaddr + DMP_RSP_OFFSET,
  2057. mb->un.varDmp.word_cnt);
  2058. }
  2059. }
  2060. writel(HA_MBATT, phba->HAregaddr);
  2061. readl(phba->HAregaddr); /* flush */
  2062. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2063. status = mb->mbxStatus;
  2064. }
  2065. spin_unlock_irqrestore(phba->host->host_lock, drvr_flag);
  2066. return (status);
  2067. }
  2068. static int
  2069. lpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
  2070. struct lpfc_iocbq * piocb)
  2071. {
  2072. /* Insert the caller's iocb in the txq tail for later processing. */
  2073. list_add_tail(&piocb->list, &pring->txq);
  2074. pring->txq_cnt++;
  2075. return (0);
  2076. }
  2077. static struct lpfc_iocbq *
  2078. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2079. struct lpfc_iocbq ** piocb)
  2080. {
  2081. struct lpfc_iocbq * nextiocb;
  2082. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  2083. if (!nextiocb) {
  2084. nextiocb = *piocb;
  2085. *piocb = NULL;
  2086. }
  2087. return nextiocb;
  2088. }
  2089. int
  2090. lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2091. struct lpfc_iocbq *piocb, uint32_t flag)
  2092. {
  2093. struct lpfc_iocbq *nextiocb;
  2094. IOCB_t *iocb;
  2095. /* If the PCI channel is in offline state, do not post iocbs. */
  2096. if (unlikely(pci_channel_offline(phba->pcidev)))
  2097. return IOCB_ERROR;
  2098. /*
  2099. * We should never get an IOCB if we are in a < LINK_DOWN state
  2100. */
  2101. if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
  2102. return IOCB_ERROR;
  2103. /*
  2104. * Check to see if we are blocking IOCB processing because of a
  2105. * outstanding mbox command.
  2106. */
  2107. if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
  2108. goto iocb_busy;
  2109. if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) {
  2110. /*
  2111. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  2112. * can be issued if the link is not up.
  2113. */
  2114. switch (piocb->iocb.ulpCommand) {
  2115. case CMD_QUE_RING_BUF_CN:
  2116. case CMD_QUE_RING_BUF64_CN:
  2117. /*
  2118. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  2119. * completion, iocb_cmpl MUST be 0.
  2120. */
  2121. if (piocb->iocb_cmpl)
  2122. piocb->iocb_cmpl = NULL;
  2123. /*FALLTHROUGH*/
  2124. case CMD_CREATE_XRI_CR:
  2125. case CMD_CLOSE_XRI_CN:
  2126. case CMD_CLOSE_XRI_CX:
  2127. break;
  2128. default:
  2129. goto iocb_busy;
  2130. }
  2131. /*
  2132. * For FCP commands, we must be in a state where we can process link
  2133. * attention events.
  2134. */
  2135. } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
  2136. !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
  2137. goto iocb_busy;
  2138. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  2139. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  2140. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  2141. if (iocb)
  2142. lpfc_sli_update_ring(phba, pring);
  2143. else
  2144. lpfc_sli_update_full_ring(phba, pring);
  2145. if (!piocb)
  2146. return IOCB_SUCCESS;
  2147. goto out_busy;
  2148. iocb_busy:
  2149. pring->stats.iocb_cmd_delay++;
  2150. out_busy:
  2151. if (!(flag & SLI_IOCB_RET_IOCB)) {
  2152. lpfc_sli_ringtx_put(phba, pring, piocb);
  2153. return IOCB_SUCCESS;
  2154. }
  2155. return IOCB_BUSY;
  2156. }
  2157. static int
  2158. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  2159. {
  2160. struct lpfc_sli *psli;
  2161. struct lpfc_sli_ring *pring;
  2162. psli = &phba->sli;
  2163. /* Adjust cmd/rsp ring iocb entries more evenly */
  2164. /* Take some away from the FCP ring */
  2165. pring = &psli->ring[psli->fcp_ring];
  2166. pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2167. pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2168. pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2169. pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2170. /* and give them to the extra ring */
  2171. pring = &psli->ring[psli->extra_ring];
  2172. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2173. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2174. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2175. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2176. /* Setup default profile for this ring */
  2177. pring->iotag_max = 4096;
  2178. pring->num_mask = 1;
  2179. pring->prt[0].profile = 0; /* Mask 0 */
  2180. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  2181. pring->prt[0].type = phba->cfg_multi_ring_type;
  2182. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  2183. return 0;
  2184. }
  2185. int
  2186. lpfc_sli_setup(struct lpfc_hba *phba)
  2187. {
  2188. int i, totiocb = 0;
  2189. struct lpfc_sli *psli = &phba->sli;
  2190. struct lpfc_sli_ring *pring;
  2191. psli->num_rings = MAX_CONFIGURED_RINGS;
  2192. psli->sli_flag = 0;
  2193. psli->fcp_ring = LPFC_FCP_RING;
  2194. psli->next_ring = LPFC_FCP_NEXT_RING;
  2195. psli->extra_ring = LPFC_EXTRA_RING;
  2196. psli->iocbq_lookup = NULL;
  2197. psli->iocbq_lookup_len = 0;
  2198. psli->last_iotag = 0;
  2199. for (i = 0; i < psli->num_rings; i++) {
  2200. pring = &psli->ring[i];
  2201. switch (i) {
  2202. case LPFC_FCP_RING: /* ring 0 - FCP */
  2203. /* numCiocb and numRiocb are used in config_port */
  2204. pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  2205. pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  2206. pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  2207. pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  2208. pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  2209. pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  2210. pring->iotag_ctr = 0;
  2211. pring->iotag_max =
  2212. (phba->cfg_hba_queue_depth * 2);
  2213. pring->fast_iotag = pring->iotag_max;
  2214. pring->num_mask = 0;
  2215. break;
  2216. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  2217. /* numCiocb and numRiocb are used in config_port */
  2218. pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  2219. pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  2220. pring->num_mask = 0;
  2221. break;
  2222. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  2223. /* numCiocb and numRiocb are used in config_port */
  2224. pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  2225. pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  2226. pring->fast_iotag = 0;
  2227. pring->iotag_ctr = 0;
  2228. pring->iotag_max = 4096;
  2229. pring->num_mask = 4;
  2230. pring->prt[0].profile = 0; /* Mask 0 */
  2231. pring->prt[0].rctl = FC_ELS_REQ;
  2232. pring->prt[0].type = FC_ELS_DATA;
  2233. pring->prt[0].lpfc_sli_rcv_unsol_event =
  2234. lpfc_els_unsol_event;
  2235. pring->prt[1].profile = 0; /* Mask 1 */
  2236. pring->prt[1].rctl = FC_ELS_RSP;
  2237. pring->prt[1].type = FC_ELS_DATA;
  2238. pring->prt[1].lpfc_sli_rcv_unsol_event =
  2239. lpfc_els_unsol_event;
  2240. pring->prt[2].profile = 0; /* Mask 2 */
  2241. /* NameServer Inquiry */
  2242. pring->prt[2].rctl = FC_UNSOL_CTL;
  2243. /* NameServer */
  2244. pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
  2245. pring->prt[2].lpfc_sli_rcv_unsol_event =
  2246. lpfc_ct_unsol_event;
  2247. pring->prt[3].profile = 0; /* Mask 3 */
  2248. /* NameServer response */
  2249. pring->prt[3].rctl = FC_SOL_CTL;
  2250. /* NameServer */
  2251. pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
  2252. pring->prt[3].lpfc_sli_rcv_unsol_event =
  2253. lpfc_ct_unsol_event;
  2254. break;
  2255. }
  2256. totiocb += (pring->numCiocb + pring->numRiocb);
  2257. }
  2258. if (totiocb > MAX_SLI2_IOCB) {
  2259. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  2260. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2261. "%d:0462 Too many cmd / rsp ring entries in "
  2262. "SLI2 SLIM Data: x%x x%x\n",
  2263. phba->brd_no, totiocb, MAX_SLI2_IOCB);
  2264. }
  2265. if (phba->cfg_multi_ring_support == 2)
  2266. lpfc_extra_ring_setup(phba);
  2267. return 0;
  2268. }
  2269. int
  2270. lpfc_sli_queue_setup(struct lpfc_hba * phba)
  2271. {
  2272. struct lpfc_sli *psli;
  2273. struct lpfc_sli_ring *pring;
  2274. int i;
  2275. psli = &phba->sli;
  2276. spin_lock_irq(phba->host->host_lock);
  2277. INIT_LIST_HEAD(&psli->mboxq);
  2278. /* Initialize list headers for txq and txcmplq as double linked lists */
  2279. for (i = 0; i < psli->num_rings; i++) {
  2280. pring = &psli->ring[i];
  2281. pring->ringno = i;
  2282. pring->next_cmdidx = 0;
  2283. pring->local_getidx = 0;
  2284. pring->cmdidx = 0;
  2285. INIT_LIST_HEAD(&pring->txq);
  2286. INIT_LIST_HEAD(&pring->txcmplq);
  2287. INIT_LIST_HEAD(&pring->iocb_continueq);
  2288. INIT_LIST_HEAD(&pring->postbufq);
  2289. }
  2290. spin_unlock_irq(phba->host->host_lock);
  2291. return (1);
  2292. }
  2293. int
  2294. lpfc_sli_hba_down(struct lpfc_hba * phba)
  2295. {
  2296. LIST_HEAD(completions);
  2297. struct lpfc_sli *psli;
  2298. struct lpfc_sli_ring *pring;
  2299. LPFC_MBOXQ_t *pmb;
  2300. struct lpfc_iocbq *iocb;
  2301. IOCB_t *cmd = NULL;
  2302. int i;
  2303. unsigned long flags = 0;
  2304. psli = &phba->sli;
  2305. lpfc_hba_down_prep(phba);
  2306. spin_lock_irqsave(phba->host->host_lock, flags);
  2307. for (i = 0; i < psli->num_rings; i++) {
  2308. pring = &psli->ring[i];
  2309. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  2310. /*
  2311. * Error everything on the txq since these iocbs have not been
  2312. * given to the FW yet.
  2313. */
  2314. list_splice_init(&pring->txq, &completions);
  2315. pring->txq_cnt = 0;
  2316. }
  2317. spin_unlock_irqrestore(phba->host->host_lock, flags);
  2318. while (!list_empty(&completions)) {
  2319. iocb = list_get_first(&completions, struct lpfc_iocbq, list);
  2320. cmd = &iocb->iocb;
  2321. list_del(&iocb->list);
  2322. if (iocb->iocb_cmpl) {
  2323. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  2324. cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
  2325. (iocb->iocb_cmpl) (phba, iocb, iocb);
  2326. } else
  2327. lpfc_sli_release_iocbq(phba, iocb);
  2328. }
  2329. /* Return any active mbox cmds */
  2330. del_timer_sync(&psli->mbox_tmo);
  2331. spin_lock_irqsave(phba->host->host_lock, flags);
  2332. phba->work_hba_events &= ~WORKER_MBOX_TMO;
  2333. if (psli->mbox_active) {
  2334. pmb = psli->mbox_active;
  2335. pmb->mb.mbxStatus = MBX_NOT_FINISHED;
  2336. if (pmb->mbox_cmpl) {
  2337. spin_unlock_irqrestore(phba->host->host_lock, flags);
  2338. pmb->mbox_cmpl(phba,pmb);
  2339. spin_lock_irqsave(phba->host->host_lock, flags);
  2340. }
  2341. }
  2342. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2343. psli->mbox_active = NULL;
  2344. /* Return any pending mbox cmds */
  2345. while ((pmb = lpfc_mbox_get(phba)) != NULL) {
  2346. pmb->mb.mbxStatus = MBX_NOT_FINISHED;
  2347. if (pmb->mbox_cmpl) {
  2348. spin_unlock_irqrestore(phba->host->host_lock, flags);
  2349. pmb->mbox_cmpl(phba,pmb);
  2350. spin_lock_irqsave(phba->host->host_lock, flags);
  2351. }
  2352. }
  2353. INIT_LIST_HEAD(&psli->mboxq);
  2354. spin_unlock_irqrestore(phba->host->host_lock, flags);
  2355. return 1;
  2356. }
  2357. void
  2358. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  2359. {
  2360. uint32_t *src = srcp;
  2361. uint32_t *dest = destp;
  2362. uint32_t ldata;
  2363. int i;
  2364. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  2365. ldata = *src;
  2366. ldata = le32_to_cpu(ldata);
  2367. *dest = ldata;
  2368. src++;
  2369. dest++;
  2370. }
  2371. }
  2372. int
  2373. lpfc_sli_ringpostbuf_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
  2374. struct lpfc_dmabuf * mp)
  2375. {
  2376. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  2377. later */
  2378. list_add_tail(&mp->list, &pring->postbufq);
  2379. pring->postbufq_cnt++;
  2380. return 0;
  2381. }
  2382. struct lpfc_dmabuf *
  2383. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2384. dma_addr_t phys)
  2385. {
  2386. struct lpfc_dmabuf *mp, *next_mp;
  2387. struct list_head *slp = &pring->postbufq;
  2388. /* Search postbufq, from the begining, looking for a match on phys */
  2389. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  2390. if (mp->phys == phys) {
  2391. list_del_init(&mp->list);
  2392. pring->postbufq_cnt--;
  2393. return mp;
  2394. }
  2395. }
  2396. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2397. "%d:0410 Cannot find virtual addr for mapped buf on "
  2398. "ring %d Data x%llx x%p x%p x%x\n",
  2399. phba->brd_no, pring->ringno, (unsigned long long)phys,
  2400. slp->next, slp->prev, pring->postbufq_cnt);
  2401. return NULL;
  2402. }
  2403. static void
  2404. lpfc_sli_abort_els_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  2405. struct lpfc_iocbq * rspiocb)
  2406. {
  2407. IOCB_t *irsp;
  2408. uint16_t abort_iotag, abort_context;
  2409. struct lpfc_iocbq *abort_iocb, *rsp_ab_iocb;
  2410. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  2411. abort_iocb = NULL;
  2412. irsp = &rspiocb->iocb;
  2413. spin_lock_irq(phba->host->host_lock);
  2414. if (irsp->ulpStatus) {
  2415. abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
  2416. abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
  2417. if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
  2418. abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
  2419. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2420. "%d:0327 Cannot abort els iocb %p"
  2421. " with tag %x context %x\n",
  2422. phba->brd_no, abort_iocb,
  2423. abort_iotag, abort_context);
  2424. /*
  2425. * make sure we have the right iocbq before taking it
  2426. * off the txcmplq and try to call completion routine.
  2427. */
  2428. if (abort_iocb &&
  2429. abort_iocb->iocb.ulpContext == abort_context &&
  2430. abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
  2431. list_del(&abort_iocb->list);
  2432. pring->txcmplq_cnt--;
  2433. rsp_ab_iocb = lpfc_sli_get_iocbq(phba);
  2434. if (rsp_ab_iocb == NULL)
  2435. lpfc_sli_release_iocbq(phba, abort_iocb);
  2436. else {
  2437. abort_iocb->iocb_flag &=
  2438. ~LPFC_DRIVER_ABORTED;
  2439. rsp_ab_iocb->iocb.ulpStatus =
  2440. IOSTAT_LOCAL_REJECT;
  2441. rsp_ab_iocb->iocb.un.ulpWord[4] =
  2442. IOERR_SLI_ABORTED;
  2443. spin_unlock_irq(phba->host->host_lock);
  2444. (abort_iocb->iocb_cmpl)
  2445. (phba, abort_iocb, rsp_ab_iocb);
  2446. spin_lock_irq(phba->host->host_lock);
  2447. lpfc_sli_release_iocbq(phba, rsp_ab_iocb);
  2448. }
  2449. }
  2450. }
  2451. lpfc_sli_release_iocbq(phba, cmdiocb);
  2452. spin_unlock_irq(phba->host->host_lock);
  2453. return;
  2454. }
  2455. int
  2456. lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba,
  2457. struct lpfc_sli_ring * pring,
  2458. struct lpfc_iocbq * cmdiocb)
  2459. {
  2460. struct lpfc_iocbq *abtsiocbp;
  2461. IOCB_t *icmd = NULL;
  2462. IOCB_t *iabt = NULL;
  2463. int retval = IOCB_ERROR;
  2464. /* There are certain command types we don't want
  2465. * to abort.
  2466. */
  2467. icmd = &cmdiocb->iocb;
  2468. if ((icmd->ulpCommand == CMD_ABORT_XRI_CN) ||
  2469. (icmd->ulpCommand == CMD_CLOSE_XRI_CN))
  2470. return 0;
  2471. /* If we're unloading, interrupts are disabled so we
  2472. * need to cleanup the iocb here.
  2473. */
  2474. if (phba->fc_flag & FC_UNLOADING)
  2475. goto abort_iotag_exit;
  2476. /* issue ABTS for this IOCB based on iotag */
  2477. abtsiocbp = lpfc_sli_get_iocbq(phba);
  2478. if (abtsiocbp == NULL)
  2479. return 0;
  2480. /* This signals the response to set the correct status
  2481. * before calling the completion handler.
  2482. */
  2483. cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
  2484. iabt = &abtsiocbp->iocb;
  2485. iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
  2486. iabt->un.acxri.abortContextTag = icmd->ulpContext;
  2487. iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
  2488. iabt->ulpLe = 1;
  2489. iabt->ulpClass = icmd->ulpClass;
  2490. if (phba->hba_state >= LPFC_LINK_UP)
  2491. iabt->ulpCommand = CMD_ABORT_XRI_CN;
  2492. else
  2493. iabt->ulpCommand = CMD_CLOSE_XRI_CN;
  2494. abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
  2495. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2496. "%d:0339 Abort xri x%x, original iotag x%x, abort "
  2497. "cmd iotag x%x\n",
  2498. phba->brd_no, iabt->un.acxri.abortContextTag,
  2499. iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
  2500. retval = lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
  2501. abort_iotag_exit:
  2502. /* If we could not issue an abort dequeue the iocb and handle
  2503. * the completion here.
  2504. */
  2505. if (retval == IOCB_ERROR) {
  2506. list_del(&cmdiocb->list);
  2507. pring->txcmplq_cnt--;
  2508. if (cmdiocb->iocb_cmpl) {
  2509. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  2510. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  2511. spin_unlock_irq(phba->host->host_lock);
  2512. (cmdiocb->iocb_cmpl) (phba, cmdiocb, cmdiocb);
  2513. spin_lock_irq(phba->host->host_lock);
  2514. } else
  2515. lpfc_sli_release_iocbq(phba, cmdiocb);
  2516. }
  2517. return 1;
  2518. }
  2519. static int
  2520. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
  2521. uint64_t lun_id, uint32_t ctx,
  2522. lpfc_ctx_cmd ctx_cmd)
  2523. {
  2524. struct lpfc_scsi_buf *lpfc_cmd;
  2525. struct scsi_cmnd *cmnd;
  2526. int rc = 1;
  2527. if (!(iocbq->iocb_flag & LPFC_IO_FCP))
  2528. return rc;
  2529. lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  2530. cmnd = lpfc_cmd->pCmd;
  2531. if (cmnd == NULL)
  2532. return rc;
  2533. switch (ctx_cmd) {
  2534. case LPFC_CTX_LUN:
  2535. if ((cmnd->device->id == tgt_id) &&
  2536. (cmnd->device->lun == lun_id))
  2537. rc = 0;
  2538. break;
  2539. case LPFC_CTX_TGT:
  2540. if (cmnd->device->id == tgt_id)
  2541. rc = 0;
  2542. break;
  2543. case LPFC_CTX_CTX:
  2544. if (iocbq->iocb.ulpContext == ctx)
  2545. rc = 0;
  2546. break;
  2547. case LPFC_CTX_HOST:
  2548. rc = 0;
  2549. break;
  2550. default:
  2551. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  2552. __FUNCTION__, ctx_cmd);
  2553. break;
  2554. }
  2555. return rc;
  2556. }
  2557. int
  2558. lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2559. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
  2560. {
  2561. struct lpfc_iocbq *iocbq;
  2562. int sum, i;
  2563. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  2564. iocbq = phba->sli.iocbq_lookup[i];
  2565. if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
  2566. 0, ctx_cmd) == 0)
  2567. sum++;
  2568. }
  2569. return sum;
  2570. }
  2571. void
  2572. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  2573. struct lpfc_iocbq * rspiocb)
  2574. {
  2575. unsigned long iflags;
  2576. spin_lock_irqsave(phba->host->host_lock, iflags);
  2577. lpfc_sli_release_iocbq(phba, cmdiocb);
  2578. spin_unlock_irqrestore(phba->host->host_lock, iflags);
  2579. return;
  2580. }
  2581. int
  2582. lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  2583. uint16_t tgt_id, uint64_t lun_id, uint32_t ctx,
  2584. lpfc_ctx_cmd abort_cmd)
  2585. {
  2586. struct lpfc_iocbq *iocbq;
  2587. struct lpfc_iocbq *abtsiocb;
  2588. IOCB_t *cmd = NULL;
  2589. int errcnt = 0, ret_val = 0;
  2590. int i;
  2591. for (i = 1; i <= phba->sli.last_iotag; i++) {
  2592. iocbq = phba->sli.iocbq_lookup[i];
  2593. if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id,
  2594. 0, abort_cmd) != 0)
  2595. continue;
  2596. /* issue ABTS for this IOCB based on iotag */
  2597. abtsiocb = lpfc_sli_get_iocbq(phba);
  2598. if (abtsiocb == NULL) {
  2599. errcnt++;
  2600. continue;
  2601. }
  2602. cmd = &iocbq->iocb;
  2603. abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
  2604. abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
  2605. abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
  2606. abtsiocb->iocb.ulpLe = 1;
  2607. abtsiocb->iocb.ulpClass = cmd->ulpClass;
  2608. if (phba->hba_state >= LPFC_LINK_UP)
  2609. abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
  2610. else
  2611. abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
  2612. /* Setup callback routine and issue the command. */
  2613. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  2614. ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
  2615. if (ret_val == IOCB_ERROR) {
  2616. lpfc_sli_release_iocbq(phba, abtsiocb);
  2617. errcnt++;
  2618. continue;
  2619. }
  2620. }
  2621. return errcnt;
  2622. }
  2623. static void
  2624. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  2625. struct lpfc_iocbq *cmdiocbq,
  2626. struct lpfc_iocbq *rspiocbq)
  2627. {
  2628. wait_queue_head_t *pdone_q;
  2629. unsigned long iflags;
  2630. spin_lock_irqsave(phba->host->host_lock, iflags);
  2631. cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
  2632. if (cmdiocbq->context2 && rspiocbq)
  2633. memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
  2634. &rspiocbq->iocb, sizeof(IOCB_t));
  2635. pdone_q = cmdiocbq->context_un.wait_queue;
  2636. spin_unlock_irqrestore(phba->host->host_lock, iflags);
  2637. if (pdone_q)
  2638. wake_up(pdone_q);
  2639. return;
  2640. }
  2641. /*
  2642. * Issue the caller's iocb and wait for its completion, but no longer than the
  2643. * caller's timeout. Note that iocb_flags is cleared before the
  2644. * lpfc_sli_issue_call since the wake routine sets a unique value and by
  2645. * definition this is a wait function.
  2646. */
  2647. int
  2648. lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
  2649. struct lpfc_sli_ring * pring,
  2650. struct lpfc_iocbq * piocb,
  2651. struct lpfc_iocbq * prspiocbq,
  2652. uint32_t timeout)
  2653. {
  2654. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  2655. long timeleft, timeout_req = 0;
  2656. int retval = IOCB_SUCCESS;
  2657. uint32_t creg_val;
  2658. /*
  2659. * If the caller has provided a response iocbq buffer, then context2
  2660. * is NULL or its an error.
  2661. */
  2662. if (prspiocbq) {
  2663. if (piocb->context2)
  2664. return IOCB_ERROR;
  2665. piocb->context2 = prspiocbq;
  2666. }
  2667. piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
  2668. piocb->context_un.wait_queue = &done_q;
  2669. piocb->iocb_flag &= ~LPFC_IO_WAKE;
  2670. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  2671. creg_val = readl(phba->HCregaddr);
  2672. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  2673. writel(creg_val, phba->HCregaddr);
  2674. readl(phba->HCregaddr); /* flush */
  2675. }
  2676. retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
  2677. if (retval == IOCB_SUCCESS) {
  2678. timeout_req = timeout * HZ;
  2679. spin_unlock_irq(phba->host->host_lock);
  2680. timeleft = wait_event_timeout(done_q,
  2681. piocb->iocb_flag & LPFC_IO_WAKE,
  2682. timeout_req);
  2683. spin_lock_irq(phba->host->host_lock);
  2684. if (piocb->iocb_flag & LPFC_IO_WAKE) {
  2685. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2686. "%d:0331 IOCB wake signaled\n",
  2687. phba->brd_no);
  2688. } else if (timeleft == 0) {
  2689. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2690. "%d:0338 IOCB wait timeout error - no "
  2691. "wake response Data x%x\n",
  2692. phba->brd_no, timeout);
  2693. retval = IOCB_TIMEDOUT;
  2694. } else {
  2695. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2696. "%d:0330 IOCB wake NOT set, "
  2697. "Data x%x x%lx\n", phba->brd_no,
  2698. timeout, (timeleft / jiffies));
  2699. retval = IOCB_TIMEDOUT;
  2700. }
  2701. } else {
  2702. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  2703. "%d:0332 IOCB wait issue failed, Data x%x\n",
  2704. phba->brd_no, retval);
  2705. retval = IOCB_ERROR;
  2706. }
  2707. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  2708. creg_val = readl(phba->HCregaddr);
  2709. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  2710. writel(creg_val, phba->HCregaddr);
  2711. readl(phba->HCregaddr); /* flush */
  2712. }
  2713. if (prspiocbq)
  2714. piocb->context2 = NULL;
  2715. piocb->context_un.wait_queue = NULL;
  2716. piocb->iocb_cmpl = NULL;
  2717. return retval;
  2718. }
  2719. int
  2720. lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
  2721. uint32_t timeout)
  2722. {
  2723. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  2724. int retval;
  2725. /* The caller must leave context1 empty. */
  2726. if (pmboxq->context1 != 0) {
  2727. return (MBX_NOT_FINISHED);
  2728. }
  2729. /* setup wake call as IOCB callback */
  2730. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  2731. /* setup context field to pass wait_queue pointer to wake function */
  2732. pmboxq->context1 = &done_q;
  2733. /* now issue the command */
  2734. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  2735. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  2736. wait_event_interruptible_timeout(done_q,
  2737. pmboxq->mbox_flag & LPFC_MBX_WAKE,
  2738. timeout * HZ);
  2739. pmboxq->context1 = NULL;
  2740. /*
  2741. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  2742. * else do not free the resources.
  2743. */
  2744. if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
  2745. retval = MBX_SUCCESS;
  2746. else
  2747. retval = MBX_TIMEOUT;
  2748. }
  2749. return retval;
  2750. }
  2751. int
  2752. lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
  2753. {
  2754. int i = 0;
  2755. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !phba->stopped) {
  2756. if (i++ > LPFC_MBOX_TMO * 1000)
  2757. return 1;
  2758. if (lpfc_sli_handle_mb_event(phba) == 0)
  2759. i = 0;
  2760. msleep(1);
  2761. }
  2762. return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
  2763. }
  2764. irqreturn_t
  2765. lpfc_intr_handler(int irq, void *dev_id)
  2766. {
  2767. struct lpfc_hba *phba;
  2768. uint32_t ha_copy;
  2769. uint32_t work_ha_copy;
  2770. unsigned long status;
  2771. int i;
  2772. uint32_t control;
  2773. /*
  2774. * Get the driver's phba structure from the dev_id and
  2775. * assume the HBA is not interrupting.
  2776. */
  2777. phba = (struct lpfc_hba *) dev_id;
  2778. if (unlikely(!phba))
  2779. return IRQ_NONE;
  2780. /* If the pci channel is offline, ignore all the interrupts. */
  2781. if (unlikely(pci_channel_offline(phba->pcidev)))
  2782. return IRQ_NONE;
  2783. phba->sli.slistat.sli_intr++;
  2784. /*
  2785. * Call the HBA to see if it is interrupting. If not, don't claim
  2786. * the interrupt
  2787. */
  2788. /* Ignore all interrupts during initialization. */
  2789. if (unlikely(phba->hba_state < LPFC_LINK_DOWN))
  2790. return IRQ_NONE;
  2791. /*
  2792. * Read host attention register to determine interrupt source
  2793. * Clear Attention Sources, except Error Attention (to
  2794. * preserve status) and Link Attention
  2795. */
  2796. spin_lock(phba->host->host_lock);
  2797. ha_copy = readl(phba->HAregaddr);
  2798. /* If somebody is waiting to handle an eratt don't process it
  2799. * here. The brdkill function will do this.
  2800. */
  2801. if (phba->fc_flag & FC_IGNORE_ERATT)
  2802. ha_copy &= ~HA_ERATT;
  2803. writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  2804. readl(phba->HAregaddr); /* flush */
  2805. spin_unlock(phba->host->host_lock);
  2806. if (unlikely(!ha_copy))
  2807. return IRQ_NONE;
  2808. work_ha_copy = ha_copy & phba->work_ha_mask;
  2809. if (unlikely(work_ha_copy)) {
  2810. if (work_ha_copy & HA_LATT) {
  2811. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  2812. /*
  2813. * Turn off Link Attention interrupts
  2814. * until CLEAR_LA done
  2815. */
  2816. spin_lock(phba->host->host_lock);
  2817. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  2818. control = readl(phba->HCregaddr);
  2819. control &= ~HC_LAINT_ENA;
  2820. writel(control, phba->HCregaddr);
  2821. readl(phba->HCregaddr); /* flush */
  2822. spin_unlock(phba->host->host_lock);
  2823. }
  2824. else
  2825. work_ha_copy &= ~HA_LATT;
  2826. }
  2827. if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) {
  2828. for (i = 0; i < phba->sli.num_rings; i++) {
  2829. if (work_ha_copy & (HA_RXATT << (4*i))) {
  2830. /*
  2831. * Turn off Slow Rings interrupts
  2832. */
  2833. spin_lock(phba->host->host_lock);
  2834. control = readl(phba->HCregaddr);
  2835. control &= ~(HC_R0INT_ENA << i);
  2836. writel(control, phba->HCregaddr);
  2837. readl(phba->HCregaddr); /* flush */
  2838. spin_unlock(phba->host->host_lock);
  2839. }
  2840. }
  2841. }
  2842. if (work_ha_copy & HA_ERATT) {
  2843. phba->hba_state = LPFC_HBA_ERROR;
  2844. /*
  2845. * There was a link/board error. Read the
  2846. * status register to retrieve the error event
  2847. * and process it.
  2848. */
  2849. phba->sli.slistat.err_attn_event++;
  2850. /* Save status info */
  2851. phba->work_hs = readl(phba->HSregaddr);
  2852. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  2853. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  2854. /* Clear Chip error bit */
  2855. writel(HA_ERATT, phba->HAregaddr);
  2856. readl(phba->HAregaddr); /* flush */
  2857. phba->stopped = 1;
  2858. }
  2859. spin_lock(phba->host->host_lock);
  2860. phba->work_ha |= work_ha_copy;
  2861. if (phba->work_wait)
  2862. wake_up(phba->work_wait);
  2863. spin_unlock(phba->host->host_lock);
  2864. }
  2865. ha_copy &= ~(phba->work_ha_mask);
  2866. /*
  2867. * Process all events on FCP ring. Take the optimized path for
  2868. * FCP IO. Any other IO is slow path and is handled by
  2869. * the worker thread.
  2870. */
  2871. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  2872. status >>= (4*LPFC_FCP_RING);
  2873. if (status & HA_RXATT)
  2874. lpfc_sli_handle_fast_ring_event(phba,
  2875. &phba->sli.ring[LPFC_FCP_RING],
  2876. status);
  2877. if (phba->cfg_multi_ring_support == 2) {
  2878. /*
  2879. * Process all events on extra ring. Take the optimized path
  2880. * for extra ring IO. Any other IO is slow path and is handled
  2881. * by the worker thread.
  2882. */
  2883. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  2884. status >>= (4*LPFC_EXTRA_RING);
  2885. if (status & HA_RXATT) {
  2886. lpfc_sli_handle_fast_ring_event(phba,
  2887. &phba->sli.ring[LPFC_EXTRA_RING],
  2888. status);
  2889. }
  2890. }
  2891. return IRQ_HANDLED;
  2892. } /* lpfc_intr_handler */