qla_isr.c 54 KB

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