qla_isr.c 56 KB

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