lpfc_sli.c 74 KB

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