qla_isr.c 54 KB

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