qla_isr.c 54 KB

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