lpfc_sli.c 74 KB

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