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