lpfc_sli.c 74 KB

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