qla_isr.c 54 KB

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