qla_isr.c 54 KB

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