qla_isr.c 56 KB

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