qla_isr.c 54 KB

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