qla_isr.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/delay.h>
  9. #include <scsi/scsi_tcq.h>
  10. static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
  11. static void qla2x00_process_completed_request(struct scsi_qla_host *,
  12. struct req_que *, uint32_t);
  13. static void qla2x00_status_entry(scsi_qla_host_t *, struct rsp_que *, void *);
  14. static void qla2x00_status_cont_entry(struct rsp_que *, sts_cont_entry_t *);
  15. static void qla2x00_error_entry(scsi_qla_host_t *, struct rsp_que *,
  16. sts_entry_t *);
  17. /**
  18. * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
  19. * @irq:
  20. * @dev_id: SCSI driver HA context
  21. *
  22. * Called by system whenever the host adapter generates an interrupt.
  23. *
  24. * Returns handled flag.
  25. */
  26. irqreturn_t
  27. qla2100_intr_handler(int irq, void *dev_id)
  28. {
  29. scsi_qla_host_t *vha;
  30. struct qla_hw_data *ha;
  31. struct device_reg_2xxx __iomem *reg;
  32. int status;
  33. unsigned long iter;
  34. uint16_t hccr;
  35. uint16_t mb[4];
  36. struct rsp_que *rsp;
  37. rsp = (struct rsp_que *) dev_id;
  38. if (!rsp) {
  39. printk(KERN_INFO
  40. "%s(): NULL response queue pointer\n", __func__);
  41. return (IRQ_NONE);
  42. }
  43. ha = rsp->hw;
  44. reg = &ha->iobase->isp;
  45. status = 0;
  46. spin_lock(&ha->hardware_lock);
  47. vha = pci_get_drvdata(ha->pdev);
  48. for (iter = 50; iter--; ) {
  49. hccr = RD_REG_WORD(&reg->hccr);
  50. if (hccr & HCCR_RISC_PAUSE) {
  51. if (pci_channel_offline(ha->pdev))
  52. break;
  53. /*
  54. * Issue a "HARD" reset in order for the RISC interrupt
  55. * bit to be cleared. Schedule a big hammmer to get
  56. * out of the RISC PAUSED state.
  57. */
  58. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  59. RD_REG_WORD(&reg->hccr);
  60. ha->isp_ops->fw_dump(vha, 1);
  61. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  62. break;
  63. } else if ((RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) == 0)
  64. break;
  65. if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
  66. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  67. RD_REG_WORD(&reg->hccr);
  68. /* Get mailbox data. */
  69. mb[0] = RD_MAILBOX_REG(ha, reg, 0);
  70. if (mb[0] > 0x3fff && mb[0] < 0x8000) {
  71. qla2x00_mbx_completion(vha, mb[0]);
  72. status |= MBX_INTERRUPT;
  73. } else if (mb[0] > 0x7fff && mb[0] < 0xc000) {
  74. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  75. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  76. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  77. qla2x00_async_event(vha, rsp, mb);
  78. } else {
  79. /*EMPTY*/
  80. DEBUG2(printk("scsi(%ld): Unrecognized "
  81. "interrupt type (%d).\n",
  82. vha->host_no, mb[0]));
  83. }
  84. /* Release mailbox registers. */
  85. WRT_REG_WORD(&reg->semaphore, 0);
  86. RD_REG_WORD(&reg->semaphore);
  87. } else {
  88. qla2x00_process_response_queue(rsp);
  89. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  90. RD_REG_WORD(&reg->hccr);
  91. }
  92. }
  93. spin_unlock(&ha->hardware_lock);
  94. if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
  95. (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
  96. set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  97. complete(&ha->mbx_intr_comp);
  98. }
  99. return (IRQ_HANDLED);
  100. }
  101. /**
  102. * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
  103. * @irq:
  104. * @dev_id: SCSI driver HA context
  105. *
  106. * Called by system whenever the host adapter generates an interrupt.
  107. *
  108. * Returns handled flag.
  109. */
  110. irqreturn_t
  111. qla2300_intr_handler(int irq, void *dev_id)
  112. {
  113. scsi_qla_host_t *vha;
  114. struct device_reg_2xxx __iomem *reg;
  115. int status;
  116. unsigned long iter;
  117. uint32_t stat;
  118. uint16_t hccr;
  119. uint16_t mb[4];
  120. struct rsp_que *rsp;
  121. struct qla_hw_data *ha;
  122. rsp = (struct rsp_que *) dev_id;
  123. if (!rsp) {
  124. printk(KERN_INFO
  125. "%s(): NULL response queue pointer\n", __func__);
  126. return (IRQ_NONE);
  127. }
  128. ha = rsp->hw;
  129. reg = &ha->iobase->isp;
  130. status = 0;
  131. spin_lock(&ha->hardware_lock);
  132. vha = pci_get_drvdata(ha->pdev);
  133. for (iter = 50; iter--; ) {
  134. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  135. if (stat & HSR_RISC_PAUSED) {
  136. if (pci_channel_offline(ha->pdev))
  137. break;
  138. hccr = RD_REG_WORD(&reg->hccr);
  139. if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
  140. qla_printk(KERN_INFO, ha, "Parity error -- "
  141. "HCCR=%x, Dumping firmware!\n", hccr);
  142. else
  143. qla_printk(KERN_INFO, ha, "RISC paused -- "
  144. "HCCR=%x, Dumping firmware!\n", hccr);
  145. /*
  146. * Issue a "HARD" reset in order for the RISC
  147. * interrupt bit to be cleared. Schedule a big
  148. * hammmer to get out of the RISC PAUSED state.
  149. */
  150. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  151. RD_REG_WORD(&reg->hccr);
  152. ha->isp_ops->fw_dump(vha, 1);
  153. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  154. break;
  155. } else if ((stat & HSR_RISC_INT) == 0)
  156. break;
  157. switch (stat & 0xff) {
  158. case 0x1:
  159. case 0x2:
  160. case 0x10:
  161. case 0x11:
  162. qla2x00_mbx_completion(vha, MSW(stat));
  163. status |= MBX_INTERRUPT;
  164. /* Release mailbox registers. */
  165. WRT_REG_WORD(&reg->semaphore, 0);
  166. break;
  167. case 0x12:
  168. mb[0] = MSW(stat);
  169. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  170. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  171. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  172. qla2x00_async_event(vha, rsp, mb);
  173. break;
  174. case 0x13:
  175. qla2x00_process_response_queue(rsp);
  176. break;
  177. case 0x15:
  178. mb[0] = MBA_CMPLT_1_16BIT;
  179. mb[1] = MSW(stat);
  180. qla2x00_async_event(vha, rsp, mb);
  181. break;
  182. case 0x16:
  183. mb[0] = MBA_SCSI_COMPLETION;
  184. mb[1] = MSW(stat);
  185. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  186. qla2x00_async_event(vha, rsp, mb);
  187. break;
  188. default:
  189. DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
  190. "(%d).\n",
  191. vha->host_no, stat & 0xff));
  192. break;
  193. }
  194. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  195. RD_REG_WORD_RELAXED(&reg->hccr);
  196. }
  197. spin_unlock(&ha->hardware_lock);
  198. if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
  199. (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
  200. set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  201. complete(&ha->mbx_intr_comp);
  202. }
  203. return (IRQ_HANDLED);
  204. }
  205. /**
  206. * qla2x00_mbx_completion() - Process mailbox command completions.
  207. * @ha: SCSI driver HA context
  208. * @mb0: Mailbox0 register
  209. */
  210. static void
  211. qla2x00_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
  212. {
  213. uint16_t cnt;
  214. uint16_t __iomem *wptr;
  215. struct qla_hw_data *ha = vha->hw;
  216. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  217. /* Load return mailbox registers. */
  218. ha->flags.mbox_int = 1;
  219. ha->mailbox_out[0] = mb0;
  220. wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1);
  221. for (cnt = 1; cnt < ha->mbx_count; cnt++) {
  222. if (IS_QLA2200(ha) && cnt == 8)
  223. wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8);
  224. if (cnt == 4 || cnt == 5)
  225. ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr);
  226. else
  227. ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
  228. wptr++;
  229. }
  230. if (ha->mcp) {
  231. DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
  232. __func__, vha->host_no, ha->mcp->mb[0]));
  233. } else {
  234. DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
  235. __func__, vha->host_no));
  236. }
  237. }
  238. static void
  239. qla81xx_idc_event(scsi_qla_host_t *vha, uint16_t aen, uint16_t descr)
  240. {
  241. static char *event[] =
  242. { "Complete", "Request Notification", "Time Extension" };
  243. int rval;
  244. struct device_reg_24xx __iomem *reg24 = &vha->hw->iobase->isp24;
  245. uint16_t __iomem *wptr;
  246. uint16_t cnt, timeout, mb[QLA_IDC_ACK_REGS];
  247. /* Seed data -- mailbox1 -> mailbox7. */
  248. wptr = (uint16_t __iomem *)&reg24->mailbox1;
  249. for (cnt = 0; cnt < QLA_IDC_ACK_REGS; cnt++, wptr++)
  250. mb[cnt] = RD_REG_WORD(wptr);
  251. DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
  252. "%04x %04x %04x %04x %04x %04x %04x.\n", vha->host_no,
  253. event[aen & 0xff],
  254. mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6]));
  255. /* Acknowledgement needed? [Notify && non-zero timeout]. */
  256. timeout = (descr >> 8) & 0xf;
  257. if (aen != MBA_IDC_NOTIFY || !timeout)
  258. return;
  259. DEBUG2(printk("scsi(%ld): Inter-Driver Commucation %s -- "
  260. "ACK timeout=%d.\n", vha->host_no, event[aen & 0xff], timeout));
  261. rval = qla2x00_post_idc_ack_work(vha, mb);
  262. if (rval != QLA_SUCCESS)
  263. qla_printk(KERN_WARNING, vha->hw,
  264. "IDC failed to post ACK.\n");
  265. }
  266. /**
  267. * qla2x00_async_event() - Process aynchronous events.
  268. * @ha: SCSI driver HA context
  269. * @mb: Mailbox registers (0 - 3)
  270. */
  271. void
  272. qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que *rsp, uint16_t *mb)
  273. {
  274. #define LS_UNKNOWN 2
  275. static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
  276. char *link_speed;
  277. uint16_t handle_cnt;
  278. uint16_t cnt;
  279. uint32_t handles[5];
  280. struct qla_hw_data *ha = vha->hw;
  281. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  282. uint32_t rscn_entry, host_pid;
  283. uint8_t rscn_queue_index;
  284. unsigned long flags;
  285. /* Setup to process RIO completion. */
  286. handle_cnt = 0;
  287. if (IS_QLA81XX(ha))
  288. goto skip_rio;
  289. switch (mb[0]) {
  290. case MBA_SCSI_COMPLETION:
  291. handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
  292. handle_cnt = 1;
  293. break;
  294. case MBA_CMPLT_1_16BIT:
  295. handles[0] = mb[1];
  296. handle_cnt = 1;
  297. mb[0] = MBA_SCSI_COMPLETION;
  298. break;
  299. case MBA_CMPLT_2_16BIT:
  300. handles[0] = mb[1];
  301. handles[1] = mb[2];
  302. handle_cnt = 2;
  303. mb[0] = MBA_SCSI_COMPLETION;
  304. break;
  305. case MBA_CMPLT_3_16BIT:
  306. handles[0] = mb[1];
  307. handles[1] = mb[2];
  308. handles[2] = mb[3];
  309. handle_cnt = 3;
  310. mb[0] = MBA_SCSI_COMPLETION;
  311. break;
  312. case MBA_CMPLT_4_16BIT:
  313. handles[0] = mb[1];
  314. handles[1] = mb[2];
  315. handles[2] = mb[3];
  316. handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
  317. handle_cnt = 4;
  318. mb[0] = MBA_SCSI_COMPLETION;
  319. break;
  320. case MBA_CMPLT_5_16BIT:
  321. handles[0] = mb[1];
  322. handles[1] = mb[2];
  323. handles[2] = mb[3];
  324. handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6);
  325. handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7);
  326. handle_cnt = 5;
  327. mb[0] = MBA_SCSI_COMPLETION;
  328. break;
  329. case MBA_CMPLT_2_32BIT:
  330. handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1]));
  331. handles[1] = le32_to_cpu(
  332. ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) |
  333. RD_MAILBOX_REG(ha, reg, 6));
  334. handle_cnt = 2;
  335. mb[0] = MBA_SCSI_COMPLETION;
  336. break;
  337. default:
  338. break;
  339. }
  340. skip_rio:
  341. switch (mb[0]) {
  342. case MBA_SCSI_COMPLETION: /* Fast Post */
  343. if (!vha->flags.online)
  344. break;
  345. for (cnt = 0; cnt < handle_cnt; cnt++)
  346. qla2x00_process_completed_request(vha, rsp->req,
  347. handles[cnt]);
  348. break;
  349. case MBA_RESET: /* Reset */
  350. DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n",
  351. vha->host_no));
  352. set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  353. break;
  354. case MBA_SYSTEM_ERR: /* System Error */
  355. qla_printk(KERN_INFO, ha,
  356. "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n",
  357. mb[1], mb[2], mb[3]);
  358. ha->isp_ops->fw_dump(vha, 1);
  359. if (IS_FWI2_CAPABLE(ha)) {
  360. if (mb[1] == 0 && mb[2] == 0) {
  361. qla_printk(KERN_ERR, ha,
  362. "Unrecoverable Hardware Error: adapter "
  363. "marked OFFLINE!\n");
  364. vha->flags.online = 0;
  365. } else
  366. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  367. } else if (mb[1] == 0) {
  368. qla_printk(KERN_INFO, ha,
  369. "Unrecoverable Hardware Error: adapter marked "
  370. "OFFLINE!\n");
  371. vha->flags.online = 0;
  372. } else
  373. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  374. break;
  375. case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
  376. DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n",
  377. vha->host_no));
  378. qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n");
  379. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  380. break;
  381. case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
  382. DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n",
  383. vha->host_no));
  384. qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n");
  385. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  386. break;
  387. case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
  388. DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n",
  389. vha->host_no));
  390. break;
  391. case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */
  392. DEBUG2(printk("scsi(%ld): LIP occurred (%x).\n", vha->host_no,
  393. mb[1]));
  394. qla_printk(KERN_INFO, ha, "LIP occurred (%x).\n", mb[1]);
  395. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  396. atomic_set(&vha->loop_state, LOOP_DOWN);
  397. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  398. qla2x00_mark_all_devices_lost(vha, 1);
  399. }
  400. if (vha->vp_idx) {
  401. atomic_set(&vha->vp_state, VP_FAILED);
  402. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  403. }
  404. set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
  405. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  406. vha->flags.management_server_logged_in = 0;
  407. qla2x00_post_aen_work(vha, FCH_EVT_LIP, mb[1]);
  408. break;
  409. case MBA_LOOP_UP: /* Loop Up Event */
  410. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  411. link_speed = link_speeds[0];
  412. ha->link_data_rate = PORT_SPEED_1GB;
  413. } else {
  414. link_speed = link_speeds[LS_UNKNOWN];
  415. if (mb[1] < 5)
  416. link_speed = link_speeds[mb[1]];
  417. else if (mb[1] == 0x13)
  418. link_speed = link_speeds[5];
  419. ha->link_data_rate = mb[1];
  420. }
  421. DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n",
  422. vha->host_no, link_speed));
  423. qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n",
  424. link_speed);
  425. vha->flags.management_server_logged_in = 0;
  426. qla2x00_post_aen_work(vha, FCH_EVT_LINKUP, ha->link_data_rate);
  427. break;
  428. case MBA_LOOP_DOWN: /* Loop Down Event */
  429. DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN "
  430. "(%x %x %x).\n", vha->host_no, mb[1], mb[2], mb[3]));
  431. qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x %x %x).\n",
  432. mb[1], mb[2], mb[3]);
  433. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  434. atomic_set(&vha->loop_state, LOOP_DOWN);
  435. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  436. vha->device_flags |= DFLG_NO_CABLE;
  437. qla2x00_mark_all_devices_lost(vha, 1);
  438. }
  439. if (vha->vp_idx) {
  440. atomic_set(&vha->vp_state, VP_FAILED);
  441. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  442. }
  443. vha->flags.management_server_logged_in = 0;
  444. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  445. qla2x00_post_aen_work(vha, FCH_EVT_LINKDOWN, 0);
  446. break;
  447. case MBA_LIP_RESET: /* LIP reset occurred */
  448. DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n",
  449. vha->host_no, mb[1]));
  450. qla_printk(KERN_INFO, ha,
  451. "LIP reset occurred (%x).\n", mb[1]);
  452. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  453. atomic_set(&vha->loop_state, LOOP_DOWN);
  454. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  455. qla2x00_mark_all_devices_lost(vha, 1);
  456. }
  457. if (vha->vp_idx) {
  458. atomic_set(&vha->vp_state, VP_FAILED);
  459. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  460. }
  461. set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  462. ha->operating_mode = LOOP;
  463. vha->flags.management_server_logged_in = 0;
  464. qla2x00_post_aen_work(vha, FCH_EVT_LIPRESET, mb[1]);
  465. break;
  466. /* case MBA_DCBX_COMPLETE: */
  467. case MBA_POINT_TO_POINT: /* Point-to-Point */
  468. if (IS_QLA2100(ha))
  469. break;
  470. if (IS_QLA81XX(ha))
  471. DEBUG2(printk("scsi(%ld): DCBX Completed -- %04x %04x "
  472. "%04x\n", vha->host_no, mb[1], mb[2], mb[3]));
  473. else
  474. DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE "
  475. "received.\n", vha->host_no));
  476. /*
  477. * Until there's a transition from loop down to loop up, treat
  478. * this as loop down only.
  479. */
  480. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  481. atomic_set(&vha->loop_state, LOOP_DOWN);
  482. if (!atomic_read(&vha->loop_down_timer))
  483. atomic_set(&vha->loop_down_timer,
  484. LOOP_DOWN_TIME);
  485. qla2x00_mark_all_devices_lost(vha, 1);
  486. }
  487. if (vha->vp_idx) {
  488. atomic_set(&vha->vp_state, VP_FAILED);
  489. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  490. }
  491. if (!(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)))
  492. set_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  493. set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
  494. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  495. ha->flags.gpsc_supported = 1;
  496. vha->flags.management_server_logged_in = 0;
  497. break;
  498. case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
  499. if (IS_QLA2100(ha))
  500. break;
  501. DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection "
  502. "received.\n",
  503. vha->host_no));
  504. qla_printk(KERN_INFO, ha,
  505. "Configuration change detected: value=%x.\n", mb[1]);
  506. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  507. atomic_set(&vha->loop_state, LOOP_DOWN);
  508. if (!atomic_read(&vha->loop_down_timer))
  509. atomic_set(&vha->loop_down_timer,
  510. LOOP_DOWN_TIME);
  511. qla2x00_mark_all_devices_lost(vha, 1);
  512. }
  513. if (vha->vp_idx) {
  514. atomic_set(&vha->vp_state, VP_FAILED);
  515. fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
  516. }
  517. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  518. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  519. break;
  520. case MBA_PORT_UPDATE: /* Port database update */
  521. /* Only handle SCNs for our Vport index. */
  522. if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
  523. break;
  524. /*
  525. * If PORT UPDATE is global (received LIP_OCCURRED/LIP_RESET
  526. * event etc. earlier indicating loop is down) then process
  527. * it. Otherwise ignore it and Wait for RSCN to come in.
  528. */
  529. atomic_set(&vha->loop_down_timer, 0);
  530. if (atomic_read(&vha->loop_state) != LOOP_DOWN &&
  531. atomic_read(&vha->loop_state) != LOOP_DEAD) {
  532. DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE "
  533. "ignored %04x/%04x/%04x.\n", vha->host_no, mb[1],
  534. mb[2], mb[3]));
  535. break;
  536. }
  537. DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n",
  538. vha->host_no));
  539. DEBUG(printk(KERN_INFO
  540. "scsi(%ld): Port database changed %04x %04x %04x.\n",
  541. vha->host_no, mb[1], mb[2], mb[3]));
  542. /*
  543. * Mark all devices as missing so we will login again.
  544. */
  545. atomic_set(&vha->loop_state, LOOP_UP);
  546. qla2x00_mark_all_devices_lost(vha, 1);
  547. vha->flags.rscn_queue_overflow = 1;
  548. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  549. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  550. break;
  551. case MBA_RSCN_UPDATE: /* State Change Registration */
  552. /* Check if the Vport has issued a SCR */
  553. if (vha->vp_idx && test_bit(VP_SCR_NEEDED, &vha->vp_flags))
  554. break;
  555. /* Only handle SCNs for our Vport index. */
  556. if (vha->vp_idx && vha->vp_idx != (mb[3] & 0xff))
  557. break;
  558. DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n",
  559. vha->host_no));
  560. DEBUG(printk(KERN_INFO
  561. "scsi(%ld): RSCN database changed -- %04x %04x %04x.\n",
  562. vha->host_no, mb[1], mb[2], mb[3]));
  563. rscn_entry = ((mb[1] & 0xff) << 16) | mb[2];
  564. host_pid = (vha->d_id.b.domain << 16) | (vha->d_id.b.area << 8)
  565. | vha->d_id.b.al_pa;
  566. if (rscn_entry == host_pid) {
  567. DEBUG(printk(KERN_INFO
  568. "scsi(%ld): Ignoring RSCN update to local host "
  569. "port ID (%06x)\n",
  570. vha->host_no, host_pid));
  571. break;
  572. }
  573. /* Ignore reserved bits from RSCN-payload. */
  574. rscn_entry = ((mb[1] & 0x3ff) << 16) | mb[2];
  575. rscn_queue_index = vha->rscn_in_ptr + 1;
  576. if (rscn_queue_index == MAX_RSCN_COUNT)
  577. rscn_queue_index = 0;
  578. if (rscn_queue_index != vha->rscn_out_ptr) {
  579. vha->rscn_queue[vha->rscn_in_ptr] = rscn_entry;
  580. vha->rscn_in_ptr = rscn_queue_index;
  581. } else {
  582. vha->flags.rscn_queue_overflow = 1;
  583. }
  584. atomic_set(&vha->loop_state, LOOP_UPDATE);
  585. atomic_set(&vha->loop_down_timer, 0);
  586. vha->flags.management_server_logged_in = 0;
  587. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  588. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  589. qla2x00_post_aen_work(vha, FCH_EVT_RSCN, rscn_entry);
  590. break;
  591. /* case MBA_RIO_RESPONSE: */
  592. case MBA_ZIO_RESPONSE:
  593. DEBUG3(printk("scsi(%ld): [R|Z]IO update completion.\n",
  594. vha->host_no));
  595. if (IS_FWI2_CAPABLE(ha))
  596. qla24xx_process_response_queue(vha, rsp);
  597. else
  598. qla2x00_process_response_queue(rsp);
  599. break;
  600. case MBA_DISCARD_RND_FRAME:
  601. DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x "
  602. "%04x.\n", vha->host_no, mb[1], mb[2], mb[3]));
  603. break;
  604. case MBA_TRACE_NOTIFICATION:
  605. DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n",
  606. vha->host_no, mb[1], mb[2]));
  607. break;
  608. case MBA_ISP84XX_ALERT:
  609. DEBUG2(printk("scsi(%ld): ISP84XX Alert Notification -- "
  610. "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
  611. spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
  612. switch (mb[1]) {
  613. case A84_PANIC_RECOVERY:
  614. qla_printk(KERN_INFO, ha, "Alert 84XX: panic recovery "
  615. "%04x %04x\n", mb[2], mb[3]);
  616. break;
  617. case A84_OP_LOGIN_COMPLETE:
  618. ha->cs84xx->op_fw_version = mb[3] << 16 | mb[2];
  619. DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
  620. "firmware version %x\n", ha->cs84xx->op_fw_version));
  621. break;
  622. case A84_DIAG_LOGIN_COMPLETE:
  623. ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
  624. DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX:"
  625. "diagnostic firmware version %x\n",
  626. ha->cs84xx->diag_fw_version));
  627. break;
  628. case A84_GOLD_LOGIN_COMPLETE:
  629. ha->cs84xx->diag_fw_version = mb[3] << 16 | mb[2];
  630. ha->cs84xx->fw_update = 1;
  631. DEBUG2(qla_printk(KERN_INFO, ha, "Alert 84XX: gold "
  632. "firmware version %x\n",
  633. ha->cs84xx->gold_fw_version));
  634. break;
  635. default:
  636. qla_printk(KERN_ERR, ha,
  637. "Alert 84xx: Invalid Alert %04x %04x %04x\n",
  638. mb[1], mb[2], mb[3]);
  639. }
  640. spin_unlock_irqrestore(&ha->cs84xx->access_lock, flags);
  641. break;
  642. case MBA_DCBX_START:
  643. DEBUG2(printk("scsi(%ld): DCBX Started -- %04x %04x %04x\n",
  644. vha->host_no, mb[1], mb[2], mb[3]));
  645. break;
  646. case MBA_DCBX_PARAM_UPDATE:
  647. DEBUG2(printk("scsi(%ld): DCBX Parameters Updated -- "
  648. "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
  649. break;
  650. case MBA_FCF_CONF_ERR:
  651. DEBUG2(printk("scsi(%ld): FCF Configuration Error -- "
  652. "%04x %04x %04x\n", vha->host_no, mb[1], mb[2], mb[3]));
  653. break;
  654. case MBA_IDC_COMPLETE:
  655. case MBA_IDC_NOTIFY:
  656. case MBA_IDC_TIME_EXT:
  657. qla81xx_idc_event(vha, mb[0], mb[1]);
  658. break;
  659. }
  660. if (!vha->vp_idx && ha->num_vhosts)
  661. qla2x00_alert_all_vps(rsp, mb);
  662. }
  663. static void
  664. qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
  665. {
  666. fc_port_t *fcport = data;
  667. struct scsi_qla_host *vha = fcport->vha;
  668. struct qla_hw_data *ha = vha->hw;
  669. struct req_que *req = NULL;
  670. if (!ql2xqfulltracking)
  671. return;
  672. req = vha->req;
  673. if (!req)
  674. return;
  675. if (req->max_q_depth <= sdev->queue_depth)
  676. return;
  677. if (sdev->ordered_tags)
  678. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
  679. sdev->queue_depth + 1);
  680. else
  681. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
  682. sdev->queue_depth + 1);
  683. fcport->last_ramp_up = jiffies;
  684. DEBUG2(qla_printk(KERN_INFO, ha,
  685. "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
  686. fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
  687. sdev->queue_depth));
  688. }
  689. static void
  690. qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
  691. {
  692. fc_port_t *fcport = data;
  693. if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
  694. return;
  695. DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
  696. "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
  697. fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
  698. sdev->queue_depth));
  699. }
  700. static inline void
  701. qla2x00_ramp_up_queue_depth(scsi_qla_host_t *vha, struct req_que *req,
  702. srb_t *sp)
  703. {
  704. fc_port_t *fcport;
  705. struct scsi_device *sdev;
  706. if (!ql2xqfulltracking)
  707. return;
  708. sdev = sp->cmd->device;
  709. if (sdev->queue_depth >= req->max_q_depth)
  710. return;
  711. fcport = sp->fcport;
  712. if (time_before(jiffies,
  713. fcport->last_ramp_up + ql2xqfullrampup * HZ))
  714. return;
  715. if (time_before(jiffies,
  716. fcport->last_queue_full + ql2xqfullrampup * HZ))
  717. return;
  718. starget_for_each_device(sdev->sdev_target, fcport,
  719. qla2x00_adjust_sdev_qdepth_up);
  720. }
  721. /**
  722. * qla2x00_process_completed_request() - Process a Fast Post response.
  723. * @ha: SCSI driver HA context
  724. * @index: SRB index
  725. */
  726. static void
  727. qla2x00_process_completed_request(struct scsi_qla_host *vha,
  728. struct req_que *req, uint32_t index)
  729. {
  730. srb_t *sp;
  731. struct qla_hw_data *ha = vha->hw;
  732. /* Validate handle. */
  733. if (index >= MAX_OUTSTANDING_COMMANDS) {
  734. DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n",
  735. vha->host_no, index));
  736. qla_printk(KERN_WARNING, ha,
  737. "Invalid SCSI completion handle %d.\n", index);
  738. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  739. return;
  740. }
  741. sp = req->outstanding_cmds[index];
  742. if (sp) {
  743. /* Free outstanding command slot. */
  744. req->outstanding_cmds[index] = NULL;
  745. /* Save ISP completion status */
  746. sp->cmd->result = DID_OK << 16;
  747. qla2x00_ramp_up_queue_depth(vha, req, sp);
  748. qla2x00_sp_compl(ha, sp);
  749. } else {
  750. DEBUG2(printk("scsi(%ld) Req:%d: Invalid ISP SCSI completion"
  751. " handle(%d)\n", vha->host_no, req->id, index));
  752. qla_printk(KERN_WARNING, ha,
  753. "Invalid ISP SCSI completion handle\n");
  754. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  755. }
  756. }
  757. /**
  758. * qla2x00_process_response_queue() - Process response queue entries.
  759. * @ha: SCSI driver HA context
  760. */
  761. void
  762. qla2x00_process_response_queue(struct rsp_que *rsp)
  763. {
  764. struct scsi_qla_host *vha;
  765. struct qla_hw_data *ha = rsp->hw;
  766. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  767. sts_entry_t *pkt;
  768. uint16_t handle_cnt;
  769. uint16_t cnt;
  770. vha = pci_get_drvdata(ha->pdev);
  771. if (!vha->flags.online)
  772. return;
  773. while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
  774. pkt = (sts_entry_t *)rsp->ring_ptr;
  775. rsp->ring_index++;
  776. if (rsp->ring_index == rsp->length) {
  777. rsp->ring_index = 0;
  778. rsp->ring_ptr = rsp->ring;
  779. } else {
  780. rsp->ring_ptr++;
  781. }
  782. if (pkt->entry_status != 0) {
  783. DEBUG3(printk(KERN_INFO
  784. "scsi(%ld): Process error entry.\n", vha->host_no));
  785. qla2x00_error_entry(vha, rsp, pkt);
  786. ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
  787. wmb();
  788. continue;
  789. }
  790. switch (pkt->entry_type) {
  791. case STATUS_TYPE:
  792. qla2x00_status_entry(vha, rsp, pkt);
  793. break;
  794. case STATUS_TYPE_21:
  795. handle_cnt = ((sts21_entry_t *)pkt)->handle_count;
  796. for (cnt = 0; cnt < handle_cnt; cnt++) {
  797. qla2x00_process_completed_request(vha, rsp->req,
  798. ((sts21_entry_t *)pkt)->handle[cnt]);
  799. }
  800. break;
  801. case STATUS_TYPE_22:
  802. handle_cnt = ((sts22_entry_t *)pkt)->handle_count;
  803. for (cnt = 0; cnt < handle_cnt; cnt++) {
  804. qla2x00_process_completed_request(vha, rsp->req,
  805. ((sts22_entry_t *)pkt)->handle[cnt]);
  806. }
  807. break;
  808. case STATUS_CONT_TYPE:
  809. qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
  810. break;
  811. default:
  812. /* Type Not Supported. */
  813. DEBUG4(printk(KERN_WARNING
  814. "scsi(%ld): Received unknown response pkt type %x "
  815. "entry status=%x.\n",
  816. vha->host_no, pkt->entry_type, pkt->entry_status));
  817. break;
  818. }
  819. ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
  820. wmb();
  821. }
  822. /* Adjust ring index */
  823. WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), rsp->ring_index);
  824. }
  825. static inline void
  826. qla2x00_handle_sense(srb_t *sp, uint8_t *sense_data, uint32_t sense_len,
  827. struct rsp_que *rsp)
  828. {
  829. struct scsi_cmnd *cp = sp->cmd;
  830. if (sense_len >= SCSI_SENSE_BUFFERSIZE)
  831. sense_len = SCSI_SENSE_BUFFERSIZE;
  832. sp->request_sense_length = sense_len;
  833. sp->request_sense_ptr = cp->sense_buffer;
  834. if (sp->request_sense_length > 32)
  835. sense_len = 32;
  836. memcpy(cp->sense_buffer, sense_data, sense_len);
  837. sp->request_sense_ptr += sense_len;
  838. sp->request_sense_length -= sense_len;
  839. if (sp->request_sense_length != 0)
  840. rsp->status_srb = sp;
  841. DEBUG5(printk("%s(): Check condition Sense data, scsi(%ld:%d:%d:%d) "
  842. "cmd=%p pid=%ld\n", __func__, sp->fcport->vha->host_no,
  843. cp->device->channel, cp->device->id, cp->device->lun, cp,
  844. cp->serial_number));
  845. if (sense_len)
  846. DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, sense_len));
  847. }
  848. /**
  849. * qla2x00_status_entry() - Process a Status IOCB entry.
  850. * @ha: SCSI driver HA context
  851. * @pkt: Entry pointer
  852. */
  853. static void
  854. qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
  855. {
  856. srb_t *sp;
  857. fc_port_t *fcport;
  858. struct scsi_cmnd *cp;
  859. sts_entry_t *sts;
  860. struct sts_entry_24xx *sts24;
  861. uint16_t comp_status;
  862. uint16_t scsi_status;
  863. uint8_t lscsi_status;
  864. int32_t resid;
  865. uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len;
  866. uint8_t *rsp_info, *sense_data;
  867. struct qla_hw_data *ha = vha->hw;
  868. uint32_t handle;
  869. uint16_t que;
  870. struct req_que *req;
  871. sts = (sts_entry_t *) pkt;
  872. sts24 = (struct sts_entry_24xx *) pkt;
  873. if (IS_FWI2_CAPABLE(ha)) {
  874. comp_status = le16_to_cpu(sts24->comp_status);
  875. scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK;
  876. } else {
  877. comp_status = le16_to_cpu(sts->comp_status);
  878. scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK;
  879. }
  880. handle = (uint32_t) LSW(sts->handle);
  881. que = MSW(sts->handle);
  882. req = ha->req_q_map[que];
  883. /* Fast path completion. */
  884. if (comp_status == CS_COMPLETE && scsi_status == 0) {
  885. qla2x00_process_completed_request(vha, req, handle);
  886. return;
  887. }
  888. /* Validate handle. */
  889. if (handle < MAX_OUTSTANDING_COMMANDS) {
  890. sp = req->outstanding_cmds[handle];
  891. req->outstanding_cmds[handle] = NULL;
  892. } else
  893. sp = NULL;
  894. if (sp == NULL) {
  895. DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n",
  896. vha->host_no));
  897. qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n");
  898. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  899. qla2xxx_wake_dpc(vha);
  900. return;
  901. }
  902. cp = sp->cmd;
  903. if (cp == NULL) {
  904. DEBUG2(printk("scsi(%ld): Command already returned back to OS "
  905. "pkt->handle=%d sp=%p.\n", vha->host_no, handle, sp));
  906. qla_printk(KERN_WARNING, ha,
  907. "Command is NULL: already returned to OS (sp=%p)\n", sp);
  908. return;
  909. }
  910. lscsi_status = scsi_status & STATUS_MASK;
  911. fcport = sp->fcport;
  912. sense_len = rsp_info_len = resid_len = fw_resid_len = 0;
  913. if (IS_FWI2_CAPABLE(ha)) {
  914. sense_len = le32_to_cpu(sts24->sense_len);
  915. rsp_info_len = le32_to_cpu(sts24->rsp_data_len);
  916. resid_len = le32_to_cpu(sts24->rsp_residual_count);
  917. fw_resid_len = le32_to_cpu(sts24->residual_len);
  918. rsp_info = sts24->data;
  919. sense_data = sts24->data;
  920. host_to_fcp_swap(sts24->data, sizeof(sts24->data));
  921. } else {
  922. sense_len = le16_to_cpu(sts->req_sense_length);
  923. rsp_info_len = le16_to_cpu(sts->rsp_info_len);
  924. resid_len = le32_to_cpu(sts->residual_length);
  925. rsp_info = sts->rsp_info;
  926. sense_data = sts->req_sense_data;
  927. }
  928. /* Check for any FCP transport errors. */
  929. if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) {
  930. /* Sense data lies beyond any FCP RESPONSE data. */
  931. if (IS_FWI2_CAPABLE(ha))
  932. sense_data += rsp_info_len;
  933. if (rsp_info_len > 3 && rsp_info[3]) {
  934. DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol "
  935. "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..."
  936. "retrying command\n", vha->host_no,
  937. cp->device->channel, cp->device->id,
  938. cp->device->lun, rsp_info_len, rsp_info[0],
  939. rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4],
  940. rsp_info[5], rsp_info[6], rsp_info[7]));
  941. cp->result = DID_BUS_BUSY << 16;
  942. qla2x00_sp_compl(ha, sp);
  943. return;
  944. }
  945. }
  946. /* Check for overrun. */
  947. if (IS_FWI2_CAPABLE(ha) && comp_status == CS_COMPLETE &&
  948. scsi_status & SS_RESIDUAL_OVER)
  949. comp_status = CS_DATA_OVERRUN;
  950. /*
  951. * Based on Host and scsi status generate status code for Linux
  952. */
  953. switch (comp_status) {
  954. case CS_COMPLETE:
  955. case CS_QUEUE_FULL:
  956. if (scsi_status == 0) {
  957. cp->result = DID_OK << 16;
  958. break;
  959. }
  960. if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) {
  961. resid = resid_len;
  962. scsi_set_resid(cp, resid);
  963. if (!lscsi_status &&
  964. ((unsigned)(scsi_bufflen(cp) - resid) <
  965. cp->underflow)) {
  966. qla_printk(KERN_INFO, ha,
  967. "scsi(%ld:%d:%d:%d): Mid-layer underflow "
  968. "detected (%x of %x bytes)...returning "
  969. "error status.\n", vha->host_no,
  970. cp->device->channel, cp->device->id,
  971. cp->device->lun, resid,
  972. scsi_bufflen(cp));
  973. cp->result = DID_ERROR << 16;
  974. break;
  975. }
  976. }
  977. cp->result = DID_OK << 16 | lscsi_status;
  978. if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
  979. DEBUG2(printk(KERN_INFO
  980. "scsi(%ld): QUEUE FULL status detected "
  981. "0x%x-0x%x.\n", vha->host_no, comp_status,
  982. scsi_status));
  983. /* Adjust queue depth for all luns on the port. */
  984. if (!ql2xqfulltracking)
  985. break;
  986. fcport->last_queue_full = jiffies;
  987. starget_for_each_device(cp->device->sdev_target,
  988. fcport, qla2x00_adjust_sdev_qdepth_down);
  989. break;
  990. }
  991. if (lscsi_status != SS_CHECK_CONDITION)
  992. break;
  993. memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  994. if (!(scsi_status & SS_SENSE_LEN_VALID))
  995. break;
  996. qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
  997. break;
  998. case CS_DATA_UNDERRUN:
  999. resid = resid_len;
  1000. /* Use F/W calculated residual length. */
  1001. if (IS_FWI2_CAPABLE(ha)) {
  1002. if (!(scsi_status & SS_RESIDUAL_UNDER)) {
  1003. lscsi_status = 0;
  1004. } else if (resid != fw_resid_len) {
  1005. scsi_status &= ~SS_RESIDUAL_UNDER;
  1006. lscsi_status = 0;
  1007. }
  1008. resid = fw_resid_len;
  1009. }
  1010. if (scsi_status & SS_RESIDUAL_UNDER) {
  1011. scsi_set_resid(cp, resid);
  1012. } else {
  1013. DEBUG2(printk(KERN_INFO
  1014. "scsi(%ld:%d:%d) UNDERRUN status detected "
  1015. "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x "
  1016. "os_underflow=0x%x\n", vha->host_no,
  1017. cp->device->id, cp->device->lun, comp_status,
  1018. scsi_status, resid_len, resid, cp->cmnd[0],
  1019. cp->underflow));
  1020. }
  1021. /*
  1022. * Check to see if SCSI Status is non zero. If so report SCSI
  1023. * Status.
  1024. */
  1025. if (lscsi_status != 0) {
  1026. cp->result = DID_OK << 16 | lscsi_status;
  1027. if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
  1028. DEBUG2(printk(KERN_INFO
  1029. "scsi(%ld): QUEUE FULL status detected "
  1030. "0x%x-0x%x.\n", vha->host_no, comp_status,
  1031. scsi_status));
  1032. /*
  1033. * Adjust queue depth for all luns on the
  1034. * port.
  1035. */
  1036. if (!ql2xqfulltracking)
  1037. break;
  1038. fcport->last_queue_full = jiffies;
  1039. starget_for_each_device(
  1040. cp->device->sdev_target, fcport,
  1041. qla2x00_adjust_sdev_qdepth_down);
  1042. break;
  1043. }
  1044. if (lscsi_status != SS_CHECK_CONDITION)
  1045. break;
  1046. memset(cp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  1047. if (!(scsi_status & SS_SENSE_LEN_VALID))
  1048. break;
  1049. qla2x00_handle_sense(sp, sense_data, sense_len, rsp);
  1050. } else {
  1051. /*
  1052. * If RISC reports underrun and target does not report
  1053. * it then we must have a lost frame, so tell upper
  1054. * layer to retry it by reporting an error.
  1055. */
  1056. if (!(scsi_status & SS_RESIDUAL_UNDER)) {
  1057. DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped "
  1058. "frame(s) detected (%x of %x bytes)..."
  1059. "retrying command.\n",
  1060. vha->host_no, cp->device->channel,
  1061. cp->device->id, cp->device->lun, resid,
  1062. scsi_bufflen(cp)));
  1063. cp->result = DID_ERROR << 16;
  1064. break;
  1065. }
  1066. /* Handle mid-layer underflow */
  1067. if ((unsigned)(scsi_bufflen(cp) - resid) <
  1068. cp->underflow) {
  1069. qla_printk(KERN_INFO, ha,
  1070. "scsi(%ld:%d:%d:%d): Mid-layer underflow "
  1071. "detected (%x of %x bytes)...returning "
  1072. "error status.\n", vha->host_no,
  1073. cp->device->channel, cp->device->id,
  1074. cp->device->lun, resid,
  1075. scsi_bufflen(cp));
  1076. cp->result = DID_ERROR << 16;
  1077. break;
  1078. }
  1079. /* Everybody online, looking good... */
  1080. cp->result = DID_OK << 16;
  1081. }
  1082. break;
  1083. case CS_DATA_OVERRUN:
  1084. DEBUG2(printk(KERN_INFO
  1085. "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n",
  1086. vha->host_no, cp->device->id, cp->device->lun, comp_status,
  1087. scsi_status));
  1088. DEBUG2(printk(KERN_INFO
  1089. "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
  1090. cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3],
  1091. cp->cmnd[4], cp->cmnd[5]));
  1092. DEBUG2(printk(KERN_INFO
  1093. "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR "
  1094. "status!\n",
  1095. cp->serial_number, scsi_bufflen(cp), resid_len));
  1096. cp->result = DID_ERROR << 16;
  1097. break;
  1098. case CS_PORT_LOGGED_OUT:
  1099. case CS_PORT_CONFIG_CHG:
  1100. case CS_PORT_BUSY:
  1101. case CS_INCOMPLETE:
  1102. case CS_PORT_UNAVAILABLE:
  1103. /*
  1104. * If the port is in Target Down state, return all IOs for this
  1105. * Target with DID_NO_CONNECT ELSE Queue the IOs in the
  1106. * retry_queue.
  1107. */
  1108. DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down "
  1109. "pid=%ld, compl status=0x%x, port state=0x%x\n",
  1110. vha->host_no, cp->device->id, cp->device->lun,
  1111. cp->serial_number, comp_status,
  1112. atomic_read(&fcport->state)));
  1113. /*
  1114. * We are going to have the fc class block the rport
  1115. * while we try to recover so instruct the mid layer
  1116. * to requeue until the class decides how to handle this.
  1117. */
  1118. cp->result = DID_TRANSPORT_DISRUPTED << 16;
  1119. if (atomic_read(&fcport->state) == FCS_ONLINE)
  1120. qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
  1121. break;
  1122. case CS_RESET:
  1123. DEBUG2(printk(KERN_INFO
  1124. "scsi(%ld): RESET status detected 0x%x-0x%x.\n",
  1125. vha->host_no, comp_status, scsi_status));
  1126. cp->result = DID_RESET << 16;
  1127. break;
  1128. case CS_ABORTED:
  1129. /*
  1130. * hv2.19.12 - DID_ABORT does not retry the request if we
  1131. * aborted this request then abort otherwise it must be a
  1132. * reset.
  1133. */
  1134. DEBUG2(printk(KERN_INFO
  1135. "scsi(%ld): ABORT status detected 0x%x-0x%x.\n",
  1136. vha->host_no, comp_status, scsi_status));
  1137. cp->result = DID_RESET << 16;
  1138. break;
  1139. case CS_TIMEOUT:
  1140. /*
  1141. * We are going to have the fc class block the rport
  1142. * while we try to recover so instruct the mid layer
  1143. * to requeue until the class decides how to handle this.
  1144. */
  1145. cp->result = DID_TRANSPORT_DISRUPTED << 16;
  1146. if (IS_FWI2_CAPABLE(ha)) {
  1147. DEBUG2(printk(KERN_INFO
  1148. "scsi(%ld:%d:%d:%d): TIMEOUT status detected "
  1149. "0x%x-0x%x\n", vha->host_no, cp->device->channel,
  1150. cp->device->id, cp->device->lun, comp_status,
  1151. scsi_status));
  1152. break;
  1153. }
  1154. DEBUG2(printk(KERN_INFO
  1155. "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x "
  1156. "sflags=%x.\n", vha->host_no, cp->device->channel,
  1157. cp->device->id, cp->device->lun, comp_status, scsi_status,
  1158. le16_to_cpu(sts->status_flags)));
  1159. /* Check to see if logout occurred. */
  1160. if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT))
  1161. qla2x00_mark_device_lost(fcport->vha, fcport, 1, 1);
  1162. break;
  1163. default:
  1164. DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
  1165. "0x%x-0x%x.\n", vha->host_no, comp_status, scsi_status));
  1166. qla_printk(KERN_INFO, ha,
  1167. "Unknown status detected 0x%x-0x%x.\n",
  1168. comp_status, scsi_status);
  1169. cp->result = DID_ERROR << 16;
  1170. break;
  1171. }
  1172. /* Place command on done queue. */
  1173. if (rsp->status_srb == NULL)
  1174. qla2x00_sp_compl(ha, sp);
  1175. }
  1176. /**
  1177. * qla2x00_status_cont_entry() - Process a Status Continuations entry.
  1178. * @ha: SCSI driver HA context
  1179. * @pkt: Entry pointer
  1180. *
  1181. * Extended sense data.
  1182. */
  1183. static void
  1184. qla2x00_status_cont_entry(struct rsp_que *rsp, sts_cont_entry_t *pkt)
  1185. {
  1186. uint8_t sense_sz = 0;
  1187. struct qla_hw_data *ha = rsp->hw;
  1188. srb_t *sp = rsp->status_srb;
  1189. struct scsi_cmnd *cp;
  1190. if (sp != NULL && sp->request_sense_length != 0) {
  1191. cp = sp->cmd;
  1192. if (cp == NULL) {
  1193. DEBUG2(printk("%s(): Cmd already returned back to OS "
  1194. "sp=%p.\n", __func__, sp));
  1195. qla_printk(KERN_INFO, ha,
  1196. "cmd is NULL: already returned to OS (sp=%p)\n",
  1197. sp);
  1198. rsp->status_srb = NULL;
  1199. return;
  1200. }
  1201. if (sp->request_sense_length > sizeof(pkt->data)) {
  1202. sense_sz = sizeof(pkt->data);
  1203. } else {
  1204. sense_sz = sp->request_sense_length;
  1205. }
  1206. /* Move sense data. */
  1207. if (IS_FWI2_CAPABLE(ha))
  1208. host_to_fcp_swap(pkt->data, sizeof(pkt->data));
  1209. memcpy(sp->request_sense_ptr, pkt->data, sense_sz);
  1210. DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz));
  1211. sp->request_sense_ptr += sense_sz;
  1212. sp->request_sense_length -= sense_sz;
  1213. /* Place command on done queue. */
  1214. if (sp->request_sense_length == 0) {
  1215. rsp->status_srb = NULL;
  1216. qla2x00_sp_compl(ha, sp);
  1217. }
  1218. }
  1219. }
  1220. /**
  1221. * qla2x00_error_entry() - Process an error entry.
  1222. * @ha: SCSI driver HA context
  1223. * @pkt: Entry pointer
  1224. */
  1225. static void
  1226. qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)
  1227. {
  1228. srb_t *sp;
  1229. struct qla_hw_data *ha = vha->hw;
  1230. uint32_t handle = LSW(pkt->handle);
  1231. uint16_t que = MSW(pkt->handle);
  1232. struct req_que *req = ha->req_q_map[que];
  1233. #if defined(QL_DEBUG_LEVEL_2)
  1234. if (pkt->entry_status & RF_INV_E_ORDER)
  1235. qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__);
  1236. else if (pkt->entry_status & RF_INV_E_COUNT)
  1237. qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__);
  1238. else if (pkt->entry_status & RF_INV_E_PARAM)
  1239. qla_printk(KERN_ERR, ha,
  1240. "%s: Invalid Entry Parameter\n", __func__);
  1241. else if (pkt->entry_status & RF_INV_E_TYPE)
  1242. qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__);
  1243. else if (pkt->entry_status & RF_BUSY)
  1244. qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__);
  1245. else
  1246. qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__);
  1247. #endif
  1248. /* Validate handle. */
  1249. if (handle < MAX_OUTSTANDING_COMMANDS)
  1250. sp = req->outstanding_cmds[handle];
  1251. else
  1252. sp = NULL;
  1253. if (sp) {
  1254. /* Free outstanding command slot. */
  1255. req->outstanding_cmds[handle] = NULL;
  1256. /* Bad payload or header */
  1257. if (pkt->entry_status &
  1258. (RF_INV_E_ORDER | RF_INV_E_COUNT |
  1259. RF_INV_E_PARAM | RF_INV_E_TYPE)) {
  1260. sp->cmd->result = DID_ERROR << 16;
  1261. } else if (pkt->entry_status & RF_BUSY) {
  1262. sp->cmd->result = DID_BUS_BUSY << 16;
  1263. } else {
  1264. sp->cmd->result = DID_ERROR << 16;
  1265. }
  1266. qla2x00_sp_compl(ha, sp);
  1267. } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type ==
  1268. COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) {
  1269. DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n",
  1270. vha->host_no));
  1271. qla_printk(KERN_WARNING, ha,
  1272. "Error entry - invalid handle\n");
  1273. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1274. qla2xxx_wake_dpc(vha);
  1275. }
  1276. }
  1277. /**
  1278. * qla24xx_mbx_completion() - Process mailbox command completions.
  1279. * @ha: SCSI driver HA context
  1280. * @mb0: Mailbox0 register
  1281. */
  1282. static void
  1283. qla24xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
  1284. {
  1285. uint16_t cnt;
  1286. uint16_t __iomem *wptr;
  1287. struct qla_hw_data *ha = vha->hw;
  1288. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1289. /* Load return mailbox registers. */
  1290. ha->flags.mbox_int = 1;
  1291. ha->mailbox_out[0] = mb0;
  1292. wptr = (uint16_t __iomem *)&reg->mailbox1;
  1293. for (cnt = 1; cnt < ha->mbx_count; cnt++) {
  1294. ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
  1295. wptr++;
  1296. }
  1297. if (ha->mcp) {
  1298. DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n",
  1299. __func__, vha->host_no, ha->mcp->mb[0]));
  1300. } else {
  1301. DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n",
  1302. __func__, vha->host_no));
  1303. }
  1304. }
  1305. /**
  1306. * qla24xx_process_response_queue() - Process response queue entries.
  1307. * @ha: SCSI driver HA context
  1308. */
  1309. void qla24xx_process_response_queue(struct scsi_qla_host *vha,
  1310. struct rsp_que *rsp)
  1311. {
  1312. struct sts_entry_24xx *pkt;
  1313. if (!vha->flags.online)
  1314. return;
  1315. while (rsp->ring_ptr->signature != RESPONSE_PROCESSED) {
  1316. pkt = (struct sts_entry_24xx *)rsp->ring_ptr;
  1317. rsp->ring_index++;
  1318. if (rsp->ring_index == rsp->length) {
  1319. rsp->ring_index = 0;
  1320. rsp->ring_ptr = rsp->ring;
  1321. } else {
  1322. rsp->ring_ptr++;
  1323. }
  1324. if (pkt->entry_status != 0) {
  1325. DEBUG3(printk(KERN_INFO
  1326. "scsi(%ld): Process error entry.\n", vha->host_no));
  1327. qla2x00_error_entry(vha, rsp, (sts_entry_t *) pkt);
  1328. ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
  1329. wmb();
  1330. continue;
  1331. }
  1332. switch (pkt->entry_type) {
  1333. case STATUS_TYPE:
  1334. qla2x00_status_entry(vha, rsp, pkt);
  1335. break;
  1336. case STATUS_CONT_TYPE:
  1337. qla2x00_status_cont_entry(rsp, (sts_cont_entry_t *)pkt);
  1338. break;
  1339. case VP_RPT_ID_IOCB_TYPE:
  1340. qla24xx_report_id_acquisition(vha,
  1341. (struct vp_rpt_id_entry_24xx *)pkt);
  1342. break;
  1343. default:
  1344. /* Type Not Supported. */
  1345. DEBUG4(printk(KERN_WARNING
  1346. "scsi(%ld): Received unknown response pkt type %x "
  1347. "entry status=%x.\n",
  1348. vha->host_no, pkt->entry_type, pkt->entry_status));
  1349. break;
  1350. }
  1351. ((response_t *)pkt)->signature = RESPONSE_PROCESSED;
  1352. wmb();
  1353. }
  1354. /* Adjust ring index */
  1355. WRT_REG_DWORD(rsp->rsp_q_out, rsp->ring_index);
  1356. }
  1357. static void
  1358. qla2xxx_check_risc_status(scsi_qla_host_t *vha)
  1359. {
  1360. int rval;
  1361. uint32_t cnt;
  1362. struct qla_hw_data *ha = vha->hw;
  1363. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1364. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
  1365. return;
  1366. rval = QLA_SUCCESS;
  1367. WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
  1368. RD_REG_DWORD(&reg->iobase_addr);
  1369. WRT_REG_DWORD(&reg->iobase_window, 0x0001);
  1370. for (cnt = 10000; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
  1371. rval == QLA_SUCCESS; cnt--) {
  1372. if (cnt) {
  1373. WRT_REG_DWORD(&reg->iobase_window, 0x0001);
  1374. udelay(10);
  1375. } else
  1376. rval = QLA_FUNCTION_TIMEOUT;
  1377. }
  1378. if (rval == QLA_SUCCESS)
  1379. goto next_test;
  1380. WRT_REG_DWORD(&reg->iobase_window, 0x0003);
  1381. for (cnt = 100; (RD_REG_DWORD(&reg->iobase_window) & BIT_0) == 0 &&
  1382. rval == QLA_SUCCESS; cnt--) {
  1383. if (cnt) {
  1384. WRT_REG_DWORD(&reg->iobase_window, 0x0003);
  1385. udelay(10);
  1386. } else
  1387. rval = QLA_FUNCTION_TIMEOUT;
  1388. }
  1389. if (rval != QLA_SUCCESS)
  1390. goto done;
  1391. next_test:
  1392. if (RD_REG_DWORD(&reg->iobase_c8) & BIT_3)
  1393. qla_printk(KERN_INFO, ha, "Additional code -- 0x55AA.\n");
  1394. done:
  1395. WRT_REG_DWORD(&reg->iobase_window, 0x0000);
  1396. RD_REG_DWORD(&reg->iobase_window);
  1397. }
  1398. /**
  1399. * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
  1400. * @irq:
  1401. * @dev_id: SCSI driver HA context
  1402. *
  1403. * Called by system whenever the host adapter generates an interrupt.
  1404. *
  1405. * Returns handled flag.
  1406. */
  1407. irqreturn_t
  1408. qla24xx_intr_handler(int irq, void *dev_id)
  1409. {
  1410. scsi_qla_host_t *vha;
  1411. struct qla_hw_data *ha;
  1412. struct device_reg_24xx __iomem *reg;
  1413. int status;
  1414. unsigned long iter;
  1415. uint32_t stat;
  1416. uint32_t hccr;
  1417. uint16_t mb[4];
  1418. struct rsp_que *rsp;
  1419. rsp = (struct rsp_que *) dev_id;
  1420. if (!rsp) {
  1421. printk(KERN_INFO
  1422. "%s(): NULL response queue pointer\n", __func__);
  1423. return IRQ_NONE;
  1424. }
  1425. ha = rsp->hw;
  1426. reg = &ha->iobase->isp24;
  1427. status = 0;
  1428. spin_lock(&ha->hardware_lock);
  1429. vha = pci_get_drvdata(ha->pdev);
  1430. for (iter = 50; iter--; ) {
  1431. stat = RD_REG_DWORD(&reg->host_status);
  1432. if (stat & HSRX_RISC_PAUSED) {
  1433. if (pci_channel_offline(ha->pdev))
  1434. break;
  1435. hccr = RD_REG_DWORD(&reg->hccr);
  1436. qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
  1437. "Dumping firmware!\n", hccr);
  1438. qla2xxx_check_risc_status(vha);
  1439. ha->isp_ops->fw_dump(vha, 1);
  1440. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1441. break;
  1442. } else if ((stat & HSRX_RISC_INT) == 0)
  1443. break;
  1444. switch (stat & 0xff) {
  1445. case 0x1:
  1446. case 0x2:
  1447. case 0x10:
  1448. case 0x11:
  1449. qla24xx_mbx_completion(vha, MSW(stat));
  1450. status |= MBX_INTERRUPT;
  1451. break;
  1452. case 0x12:
  1453. mb[0] = MSW(stat);
  1454. mb[1] = RD_REG_WORD(&reg->mailbox1);
  1455. mb[2] = RD_REG_WORD(&reg->mailbox2);
  1456. mb[3] = RD_REG_WORD(&reg->mailbox3);
  1457. qla2x00_async_event(vha, rsp, mb);
  1458. break;
  1459. case 0x13:
  1460. case 0x14:
  1461. qla24xx_process_response_queue(vha, rsp);
  1462. break;
  1463. default:
  1464. DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
  1465. "(%d).\n",
  1466. vha->host_no, stat & 0xff));
  1467. break;
  1468. }
  1469. WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
  1470. RD_REG_DWORD_RELAXED(&reg->hccr);
  1471. }
  1472. spin_unlock(&ha->hardware_lock);
  1473. if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
  1474. (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
  1475. set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  1476. complete(&ha->mbx_intr_comp);
  1477. }
  1478. return IRQ_HANDLED;
  1479. }
  1480. static irqreturn_t
  1481. qla24xx_msix_rsp_q(int irq, void *dev_id)
  1482. {
  1483. struct qla_hw_data *ha;
  1484. struct rsp_que *rsp;
  1485. struct device_reg_24xx __iomem *reg;
  1486. struct scsi_qla_host *vha;
  1487. rsp = (struct rsp_que *) dev_id;
  1488. if (!rsp) {
  1489. printk(KERN_INFO
  1490. "%s(): NULL response queue pointer\n", __func__);
  1491. return IRQ_NONE;
  1492. }
  1493. ha = rsp->hw;
  1494. reg = &ha->iobase->isp24;
  1495. spin_lock_irq(&ha->hardware_lock);
  1496. vha = qla25xx_get_host(rsp);
  1497. qla24xx_process_response_queue(vha, rsp);
  1498. WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
  1499. spin_unlock_irq(&ha->hardware_lock);
  1500. return IRQ_HANDLED;
  1501. }
  1502. static irqreturn_t
  1503. qla25xx_msix_rsp_q(int irq, void *dev_id)
  1504. {
  1505. struct qla_hw_data *ha;
  1506. struct rsp_que *rsp;
  1507. rsp = (struct rsp_que *) dev_id;
  1508. if (!rsp) {
  1509. printk(KERN_INFO
  1510. "%s(): NULL response queue pointer\n", __func__);
  1511. return IRQ_NONE;
  1512. }
  1513. ha = rsp->hw;
  1514. queue_work_on((int) (rsp->id - 1), ha->wq, &rsp->q_work);
  1515. return IRQ_HANDLED;
  1516. }
  1517. static irqreturn_t
  1518. qla24xx_msix_default(int irq, void *dev_id)
  1519. {
  1520. scsi_qla_host_t *vha;
  1521. struct qla_hw_data *ha;
  1522. struct rsp_que *rsp;
  1523. struct device_reg_24xx __iomem *reg;
  1524. int status;
  1525. uint32_t stat;
  1526. uint32_t hccr;
  1527. uint16_t mb[4];
  1528. rsp = (struct rsp_que *) dev_id;
  1529. if (!rsp) {
  1530. DEBUG(printk(
  1531. "%s(): NULL response queue pointer\n", __func__));
  1532. return IRQ_NONE;
  1533. }
  1534. ha = rsp->hw;
  1535. reg = &ha->iobase->isp24;
  1536. status = 0;
  1537. spin_lock_irq(&ha->hardware_lock);
  1538. vha = pci_get_drvdata(ha->pdev);
  1539. do {
  1540. stat = RD_REG_DWORD(&reg->host_status);
  1541. if (stat & HSRX_RISC_PAUSED) {
  1542. if (pci_channel_offline(ha->pdev))
  1543. break;
  1544. hccr = RD_REG_DWORD(&reg->hccr);
  1545. qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
  1546. "Dumping firmware!\n", hccr);
  1547. qla2xxx_check_risc_status(vha);
  1548. ha->isp_ops->fw_dump(vha, 1);
  1549. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1550. break;
  1551. } else if ((stat & HSRX_RISC_INT) == 0)
  1552. break;
  1553. switch (stat & 0xff) {
  1554. case 0x1:
  1555. case 0x2:
  1556. case 0x10:
  1557. case 0x11:
  1558. qla24xx_mbx_completion(vha, MSW(stat));
  1559. status |= MBX_INTERRUPT;
  1560. break;
  1561. case 0x12:
  1562. mb[0] = MSW(stat);
  1563. mb[1] = RD_REG_WORD(&reg->mailbox1);
  1564. mb[2] = RD_REG_WORD(&reg->mailbox2);
  1565. mb[3] = RD_REG_WORD(&reg->mailbox3);
  1566. qla2x00_async_event(vha, rsp, mb);
  1567. break;
  1568. case 0x13:
  1569. case 0x14:
  1570. qla24xx_process_response_queue(vha, rsp);
  1571. break;
  1572. default:
  1573. DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
  1574. "(%d).\n",
  1575. vha->host_no, stat & 0xff));
  1576. break;
  1577. }
  1578. WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
  1579. } while (0);
  1580. spin_unlock_irq(&ha->hardware_lock);
  1581. if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
  1582. (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
  1583. set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  1584. complete(&ha->mbx_intr_comp);
  1585. }
  1586. return IRQ_HANDLED;
  1587. }
  1588. /* Interrupt handling helpers. */
  1589. struct qla_init_msix_entry {
  1590. const char *name;
  1591. irq_handler_t handler;
  1592. };
  1593. static struct qla_init_msix_entry msix_entries[3] = {
  1594. { "qla2xxx (default)", qla24xx_msix_default },
  1595. { "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
  1596. { "qla2xxx (multiq)", qla25xx_msix_rsp_q },
  1597. };
  1598. static void
  1599. qla24xx_disable_msix(struct qla_hw_data *ha)
  1600. {
  1601. int i;
  1602. struct qla_msix_entry *qentry;
  1603. for (i = 0; i < ha->msix_count; i++) {
  1604. qentry = &ha->msix_entries[i];
  1605. if (qentry->have_irq)
  1606. free_irq(qentry->vector, qentry->rsp);
  1607. }
  1608. pci_disable_msix(ha->pdev);
  1609. kfree(ha->msix_entries);
  1610. ha->msix_entries = NULL;
  1611. ha->flags.msix_enabled = 0;
  1612. }
  1613. static int
  1614. qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
  1615. {
  1616. #define MIN_MSIX_COUNT 2
  1617. int i, ret;
  1618. struct msix_entry *entries;
  1619. struct qla_msix_entry *qentry;
  1620. entries = kzalloc(sizeof(struct msix_entry) * ha->msix_count,
  1621. GFP_KERNEL);
  1622. if (!entries)
  1623. return -ENOMEM;
  1624. for (i = 0; i < ha->msix_count; i++)
  1625. entries[i].entry = i;
  1626. ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
  1627. if (ret) {
  1628. if (ret < MIN_MSIX_COUNT)
  1629. goto msix_failed;
  1630. qla_printk(KERN_WARNING, ha,
  1631. "MSI-X: Failed to enable support -- %d/%d\n"
  1632. " Retry with %d vectors\n", ha->msix_count, ret, ret);
  1633. ha->msix_count = ret;
  1634. ret = pci_enable_msix(ha->pdev, entries, ha->msix_count);
  1635. if (ret) {
  1636. msix_failed:
  1637. qla_printk(KERN_WARNING, ha, "MSI-X: Failed to enable"
  1638. " support, giving up -- %d/%d\n",
  1639. ha->msix_count, ret);
  1640. goto msix_out;
  1641. }
  1642. ha->max_rsp_queues = ha->msix_count - 1;
  1643. }
  1644. ha->msix_entries = kzalloc(sizeof(struct qla_msix_entry) *
  1645. ha->msix_count, GFP_KERNEL);
  1646. if (!ha->msix_entries) {
  1647. ret = -ENOMEM;
  1648. goto msix_out;
  1649. }
  1650. ha->flags.msix_enabled = 1;
  1651. for (i = 0; i < ha->msix_count; i++) {
  1652. qentry = &ha->msix_entries[i];
  1653. qentry->vector = entries[i].vector;
  1654. qentry->entry = entries[i].entry;
  1655. qentry->have_irq = 0;
  1656. qentry->rsp = NULL;
  1657. }
  1658. /* Enable MSI-X vectors for the base queue */
  1659. for (i = 0; i < 2; i++) {
  1660. qentry = &ha->msix_entries[i];
  1661. ret = request_irq(qentry->vector, msix_entries[i].handler,
  1662. 0, msix_entries[i].name, rsp);
  1663. if (ret) {
  1664. qla_printk(KERN_WARNING, ha,
  1665. "MSI-X: Unable to register handler -- %x/%d.\n",
  1666. qentry->vector, ret);
  1667. qla24xx_disable_msix(ha);
  1668. ha->mqenable = 0;
  1669. goto msix_out;
  1670. }
  1671. qentry->have_irq = 1;
  1672. qentry->rsp = rsp;
  1673. rsp->msix = qentry;
  1674. }
  1675. /* Enable MSI-X vector for response queue update for queue 0 */
  1676. if (ha->mqiobase && (ha->max_rsp_queues > 1 || ha->max_req_queues > 1))
  1677. ha->mqenable = 1;
  1678. msix_out:
  1679. kfree(entries);
  1680. return ret;
  1681. }
  1682. int
  1683. qla2x00_request_irqs(struct qla_hw_data *ha, struct rsp_que *rsp)
  1684. {
  1685. int ret;
  1686. device_reg_t __iomem *reg = ha->iobase;
  1687. /* If possible, enable MSI-X. */
  1688. if (!IS_QLA2432(ha) && !IS_QLA2532(ha) &&
  1689. !IS_QLA8432(ha) && !IS_QLA8001(ha))
  1690. goto skip_msix;
  1691. if (IS_QLA2432(ha) && (ha->pdev->revision < QLA_MSIX_CHIP_REV_24XX ||
  1692. !QLA_MSIX_FW_MODE_1(ha->fw_attributes))) {
  1693. DEBUG2(qla_printk(KERN_WARNING, ha,
  1694. "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
  1695. ha->pdev->revision, ha->fw_attributes));
  1696. goto skip_msix;
  1697. }
  1698. if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
  1699. (ha->pdev->subsystem_device == 0x7040 ||
  1700. ha->pdev->subsystem_device == 0x7041 ||
  1701. ha->pdev->subsystem_device == 0x1705)) {
  1702. DEBUG2(qla_printk(KERN_WARNING, ha,
  1703. "MSI-X: Unsupported ISP2432 SSVID/SSDID (0x%X, 0x%X).\n",
  1704. ha->pdev->subsystem_vendor,
  1705. ha->pdev->subsystem_device));
  1706. goto skip_msi;
  1707. }
  1708. ret = qla24xx_enable_msix(ha, rsp);
  1709. if (!ret) {
  1710. DEBUG2(qla_printk(KERN_INFO, ha,
  1711. "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
  1712. ha->fw_attributes));
  1713. goto clear_risc_ints;
  1714. }
  1715. qla_printk(KERN_WARNING, ha,
  1716. "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
  1717. skip_msix:
  1718. if (!IS_QLA24XX(ha) && !IS_QLA2532(ha) && !IS_QLA8432(ha) &&
  1719. !IS_QLA8001(ha))
  1720. goto skip_msi;
  1721. ret = pci_enable_msi(ha->pdev);
  1722. if (!ret) {
  1723. DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
  1724. ha->flags.msi_enabled = 1;
  1725. }
  1726. skip_msi:
  1727. ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
  1728. IRQF_SHARED, QLA2XXX_DRIVER_NAME, rsp);
  1729. if (ret) {
  1730. qla_printk(KERN_WARNING, ha,
  1731. "Failed to reserve interrupt %d already in use.\n",
  1732. ha->pdev->irq);
  1733. goto fail;
  1734. }
  1735. ha->flags.inta_enabled = 1;
  1736. clear_risc_ints:
  1737. /*
  1738. * FIXME: Noted that 8014s were being dropped during NK testing.
  1739. * Timing deltas during MSI-X/INTa transitions?
  1740. */
  1741. if (IS_QLA81XX(ha))
  1742. goto fail;
  1743. spin_lock_irq(&ha->hardware_lock);
  1744. if (IS_FWI2_CAPABLE(ha)) {
  1745. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
  1746. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
  1747. } else {
  1748. WRT_REG_WORD(&reg->isp.semaphore, 0);
  1749. WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
  1750. WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
  1751. }
  1752. spin_unlock_irq(&ha->hardware_lock);
  1753. fail:
  1754. return ret;
  1755. }
  1756. void
  1757. qla2x00_free_irqs(scsi_qla_host_t *vha)
  1758. {
  1759. struct qla_hw_data *ha = vha->hw;
  1760. struct rsp_que *rsp = ha->rsp_q_map[0];
  1761. if (ha->flags.msix_enabled)
  1762. qla24xx_disable_msix(ha);
  1763. else if (ha->flags.inta_enabled) {
  1764. free_irq(ha->pdev->irq, rsp);
  1765. pci_disable_msi(ha->pdev);
  1766. }
  1767. }
  1768. int qla25xx_request_irq(struct rsp_que *rsp)
  1769. {
  1770. struct qla_hw_data *ha = rsp->hw;
  1771. struct qla_init_msix_entry *intr = &msix_entries[2];
  1772. struct qla_msix_entry *msix = rsp->msix;
  1773. int ret;
  1774. ret = request_irq(msix->vector, intr->handler, 0, intr->name, rsp);
  1775. if (ret) {
  1776. qla_printk(KERN_WARNING, ha,
  1777. "MSI-X: Unable to register handler -- %x/%d.\n",
  1778. msix->vector, ret);
  1779. return ret;
  1780. }
  1781. msix->have_irq = 1;
  1782. msix->rsp = rsp;
  1783. return ret;
  1784. }
  1785. struct scsi_qla_host *
  1786. qla25xx_get_host(struct rsp_que *rsp)
  1787. {
  1788. srb_t *sp;
  1789. struct qla_hw_data *ha = rsp->hw;
  1790. struct scsi_qla_host *vha = NULL;
  1791. struct sts_entry_24xx *pkt;
  1792. struct req_que *req;
  1793. uint16_t que;
  1794. uint32_t handle;
  1795. pkt = (struct sts_entry_24xx *) rsp->ring_ptr;
  1796. que = MSW(pkt->handle);
  1797. handle = (uint32_t) LSW(pkt->handle);
  1798. req = ha->req_q_map[que];
  1799. if (handle < MAX_OUTSTANDING_COMMANDS) {
  1800. sp = req->outstanding_cmds[handle];
  1801. if (sp)
  1802. return sp->fcport->vha;
  1803. else
  1804. goto base_que;
  1805. }
  1806. base_que:
  1807. vha = pci_get_drvdata(ha->pdev);
  1808. return vha;
  1809. }