qla_isr.c 55 KB

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