qla_isr.c 62 KB

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