qla_isr.c 55 KB

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