ql4_isr.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2006 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include "ql4_def.h"
  8. #include "ql4_glbl.h"
  9. #include "ql4_dbg.h"
  10. #include "ql4_inline.h"
  11. /**
  12. * qla4xxx_status_entry - processes status IOCBs
  13. * @ha: Pointer to host adapter structure.
  14. * @sts_entry: Pointer to status entry structure.
  15. **/
  16. static void qla4xxx_status_entry(struct scsi_qla_host *ha,
  17. struct status_entry *sts_entry)
  18. {
  19. uint8_t scsi_status;
  20. struct scsi_cmnd *cmd;
  21. struct srb *srb;
  22. struct ddb_entry *ddb_entry;
  23. uint32_t residual;
  24. uint16_t sensebytecnt;
  25. srb = qla4xxx_del_from_active_array(ha, le32_to_cpu(sts_entry->handle));
  26. if (!srb) {
  27. /* FIXMEdg: Don't we need to reset ISP in this case??? */
  28. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Status Entry invalid "
  29. "handle 0x%x, sp=%p. This cmd may have already "
  30. "been completed.\n", ha->host_no, __func__,
  31. le32_to_cpu(sts_entry->handle), srb));
  32. dev_warn(&ha->pdev->dev, "%s invalid status entry:"
  33. " handle=0x%0x\n", __func__, sts_entry->handle);
  34. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  35. return;
  36. }
  37. cmd = srb->cmd;
  38. if (cmd == NULL) {
  39. DEBUG2(printk("scsi%ld: %s: Command already returned back to "
  40. "OS pkt->handle=%d srb=%p srb->state:%d\n",
  41. ha->host_no, __func__, sts_entry->handle,
  42. srb, srb->state));
  43. dev_warn(&ha->pdev->dev, "Command is NULL:"
  44. " already returned to OS (srb=%p)\n", srb);
  45. return;
  46. }
  47. ddb_entry = srb->ddb;
  48. if (ddb_entry == NULL) {
  49. cmd->result = DID_NO_CONNECT << 16;
  50. goto status_entry_exit;
  51. }
  52. residual = le32_to_cpu(sts_entry->residualByteCnt);
  53. /* Translate ISP error to a Linux SCSI error. */
  54. scsi_status = sts_entry->scsiStatus;
  55. switch (sts_entry->completionStatus) {
  56. case SCS_COMPLETE:
  57. if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
  58. cmd->result = DID_ERROR << 16;
  59. break;
  60. }
  61. if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
  62. scsi_set_resid(cmd, residual);
  63. if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
  64. cmd->underflow)) {
  65. cmd->result = DID_ERROR << 16;
  66. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
  67. "Mid-layer Data underrun0, "
  68. "xferlen = 0x%x, "
  69. "residual = 0x%x\n", ha->host_no,
  70. cmd->device->channel,
  71. cmd->device->id,
  72. cmd->device->lun, __func__,
  73. scsi_bufflen(cmd), residual));
  74. break;
  75. }
  76. }
  77. cmd->result = DID_OK << 16 | scsi_status;
  78. if (scsi_status != SCSI_CHECK_CONDITION)
  79. break;
  80. /* Copy Sense Data into sense buffer. */
  81. memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  82. sensebytecnt = le16_to_cpu(sts_entry->senseDataByteCnt);
  83. if (sensebytecnt == 0)
  84. break;
  85. memcpy(cmd->sense_buffer, sts_entry->senseData,
  86. min_t(uint16_t, sensebytecnt, SCSI_SENSE_BUFFERSIZE));
  87. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: sense key = %x, "
  88. "ASC/ASCQ = %02x/%02x\n", ha->host_no,
  89. cmd->device->channel, cmd->device->id,
  90. cmd->device->lun, __func__,
  91. sts_entry->senseData[2] & 0x0f,
  92. sts_entry->senseData[12],
  93. sts_entry->senseData[13]));
  94. srb->flags |= SRB_GOT_SENSE;
  95. break;
  96. case SCS_INCOMPLETE:
  97. /* Always set the status to DID_ERROR, since
  98. * all conditions result in that status anyway */
  99. cmd->result = DID_ERROR << 16;
  100. break;
  101. case SCS_RESET_OCCURRED:
  102. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Device RESET occurred\n",
  103. ha->host_no, cmd->device->channel,
  104. cmd->device->id, cmd->device->lun, __func__));
  105. cmd->result = DID_RESET << 16;
  106. break;
  107. case SCS_ABORTED:
  108. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Abort occurred\n",
  109. ha->host_no, cmd->device->channel,
  110. cmd->device->id, cmd->device->lun, __func__));
  111. cmd->result = DID_RESET << 16;
  112. break;
  113. case SCS_TIMEOUT:
  114. DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: Timeout\n",
  115. ha->host_no, cmd->device->channel,
  116. cmd->device->id, cmd->device->lun));
  117. cmd->result = DID_BUS_BUSY << 16;
  118. /*
  119. * Mark device missing so that we won't continue to send
  120. * I/O to this device. We should get a ddb state change
  121. * AEN soon.
  122. */
  123. if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
  124. qla4xxx_mark_device_missing(ha, ddb_entry);
  125. break;
  126. case SCS_DATA_UNDERRUN:
  127. case SCS_DATA_OVERRUN:
  128. if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
  129. (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
  130. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun, "
  131. "residual = 0x%x\n", ha->host_no,
  132. cmd->device->channel, cmd->device->id,
  133. cmd->device->lun, __func__, residual));
  134. cmd->result = DID_ERROR << 16;
  135. break;
  136. }
  137. scsi_set_resid(cmd, residual);
  138. /*
  139. * If there is scsi_status, it takes precedense over
  140. * underflow condition.
  141. */
  142. if (scsi_status != 0) {
  143. cmd->result = DID_OK << 16 | scsi_status;
  144. if (scsi_status != SCSI_CHECK_CONDITION)
  145. break;
  146. /* Copy Sense Data into sense buffer. */
  147. memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  148. sensebytecnt =
  149. le16_to_cpu(sts_entry->senseDataByteCnt);
  150. if (sensebytecnt == 0)
  151. break;
  152. memcpy(cmd->sense_buffer, sts_entry->senseData,
  153. min_t(uint16_t, sensebytecnt, SCSI_SENSE_BUFFERSIZE));
  154. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: sense key = %x, "
  155. "ASC/ASCQ = %02x/%02x\n", ha->host_no,
  156. cmd->device->channel, cmd->device->id,
  157. cmd->device->lun, __func__,
  158. sts_entry->senseData[2] & 0x0f,
  159. sts_entry->senseData[12],
  160. sts_entry->senseData[13]));
  161. } else {
  162. /*
  163. * If RISC reports underrun and target does not
  164. * report it then we must have a lost frame, so
  165. * tell upper layer to retry it by reporting a
  166. * bus busy.
  167. */
  168. if ((sts_entry->iscsiFlags &
  169. ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
  170. cmd->result = DID_BUS_BUSY << 16;
  171. } else if ((scsi_bufflen(cmd) - residual) <
  172. cmd->underflow) {
  173. /*
  174. * Handle mid-layer underflow???
  175. *
  176. * For kernels less than 2.4, the driver must
  177. * return an error if an underflow is detected.
  178. * For kernels equal-to and above 2.4, the
  179. * mid-layer will appearantly handle the
  180. * underflow by detecting the residual count --
  181. * unfortunately, we do not see where this is
  182. * actually being done. In the interim, we
  183. * will return DID_ERROR.
  184. */
  185. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
  186. "Mid-layer Data underrun1, "
  187. "xferlen = 0x%x, "
  188. "residual = 0x%x\n", ha->host_no,
  189. cmd->device->channel,
  190. cmd->device->id,
  191. cmd->device->lun, __func__,
  192. scsi_bufflen(cmd), residual));
  193. cmd->result = DID_ERROR << 16;
  194. } else {
  195. cmd->result = DID_OK << 16;
  196. }
  197. }
  198. break;
  199. case SCS_DEVICE_LOGGED_OUT:
  200. case SCS_DEVICE_UNAVAILABLE:
  201. /*
  202. * Mark device missing so that we won't continue to
  203. * send I/O to this device. We should get a ddb
  204. * state change AEN soon.
  205. */
  206. if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
  207. qla4xxx_mark_device_missing(ha, ddb_entry);
  208. cmd->result = DID_BUS_BUSY << 16;
  209. break;
  210. case SCS_QUEUE_FULL:
  211. /*
  212. * SCSI Mid-Layer handles device queue full
  213. */
  214. cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
  215. DEBUG2(printk("scsi%ld:%d:%d: %s: QUEUE FULL detected "
  216. "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
  217. " iResp=%02x\n", ha->host_no, cmd->device->id,
  218. cmd->device->lun, __func__,
  219. sts_entry->completionStatus,
  220. sts_entry->scsiStatus, sts_entry->state_flags,
  221. sts_entry->iscsiFlags,
  222. sts_entry->iscsiResponse));
  223. break;
  224. default:
  225. cmd->result = DID_ERROR << 16;
  226. break;
  227. }
  228. status_entry_exit:
  229. /* complete the request */
  230. srb->cc_stat = sts_entry->completionStatus;
  231. qla4xxx_srb_compl(ha, srb);
  232. }
  233. /**
  234. * qla4xxx_process_response_queue - process response queue completions
  235. * @ha: Pointer to host adapter structure.
  236. *
  237. * This routine process response queue completions in interrupt context.
  238. * Hardware_lock locked upon entry
  239. **/
  240. static void qla4xxx_process_response_queue(struct scsi_qla_host * ha)
  241. {
  242. uint32_t count = 0;
  243. struct srb *srb = NULL;
  244. struct status_entry *sts_entry;
  245. /* Process all responses from response queue */
  246. while ((ha->response_in =
  247. (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in)) !=
  248. ha->response_out) {
  249. sts_entry = (struct status_entry *) ha->response_ptr;
  250. count++;
  251. /* Advance pointers for next entry */
  252. if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
  253. ha->response_out = 0;
  254. ha->response_ptr = ha->response_ring;
  255. } else {
  256. ha->response_out++;
  257. ha->response_ptr++;
  258. }
  259. /* process entry */
  260. switch (sts_entry->hdr.entryType) {
  261. case ET_STATUS:
  262. /*
  263. * Common status - Single completion posted in single
  264. * IOSB.
  265. */
  266. qla4xxx_status_entry(ha, sts_entry);
  267. break;
  268. case ET_PASSTHRU_STATUS:
  269. break;
  270. case ET_STATUS_CONTINUATION:
  271. /* Just throw away the status continuation entries */
  272. DEBUG2(printk("scsi%ld: %s: Status Continuation entry "
  273. "- ignoring\n", ha->host_no, __func__));
  274. break;
  275. case ET_COMMAND:
  276. /* ISP device queue is full. Command not
  277. * accepted by ISP. Queue command for
  278. * later */
  279. srb = qla4xxx_del_from_active_array(ha,
  280. le32_to_cpu(sts_entry->
  281. handle));
  282. if (srb == NULL)
  283. goto exit_prq_invalid_handle;
  284. DEBUG2(printk("scsi%ld: %s: FW device queue full, "
  285. "srb %p\n", ha->host_no, __func__, srb));
  286. /* ETRY normally by sending it back with
  287. * DID_BUS_BUSY */
  288. srb->cmd->result = DID_BUS_BUSY << 16;
  289. qla4xxx_srb_compl(ha, srb);
  290. break;
  291. case ET_CONTINUE:
  292. /* Just throw away the continuation entries */
  293. DEBUG2(printk("scsi%ld: %s: Continuation entry - "
  294. "ignoring\n", ha->host_no, __func__));
  295. break;
  296. default:
  297. /*
  298. * Invalid entry in response queue, reset RISC
  299. * firmware.
  300. */
  301. DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
  302. "response queue \n", ha->host_no,
  303. __func__,
  304. sts_entry->hdr.entryType));
  305. goto exit_prq_error;
  306. }
  307. }
  308. /*
  309. * Done with responses, update the ISP For QLA4010, this also clears
  310. * the interrupt.
  311. */
  312. writel(ha->response_out, &ha->reg->rsp_q_out);
  313. readl(&ha->reg->rsp_q_out);
  314. return;
  315. exit_prq_invalid_handle:
  316. DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
  317. ha->host_no, __func__, srb, sts_entry->hdr.entryType,
  318. sts_entry->completionStatus));
  319. exit_prq_error:
  320. writel(ha->response_out, &ha->reg->rsp_q_out);
  321. readl(&ha->reg->rsp_q_out);
  322. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  323. }
  324. /**
  325. * qla4xxx_isr_decode_mailbox - decodes mailbox status
  326. * @ha: Pointer to host adapter structure.
  327. * @mailbox_status: Mailbox status.
  328. *
  329. * This routine decodes the mailbox status during the ISR.
  330. * Hardware_lock locked upon entry. runs in interrupt context.
  331. **/
  332. static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
  333. uint32_t mbox_status)
  334. {
  335. int i;
  336. uint32_t mbox_stat2, mbox_stat3;
  337. if ((mbox_status == MBOX_STS_BUSY) ||
  338. (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
  339. (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
  340. ha->mbox_status[0] = mbox_status;
  341. if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
  342. /*
  343. * Copy all mailbox registers to a temporary
  344. * location and set mailbox command done flag
  345. */
  346. for (i = 1; i < ha->mbox_status_count; i++)
  347. ha->mbox_status[i] =
  348. readl(&ha->reg->mailbox[i]);
  349. set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  350. }
  351. } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
  352. /* Immediately process the AENs that don't require much work.
  353. * Only queue the database_changed AENs */
  354. if (ha->aen_log.count < MAX_AEN_ENTRIES) {
  355. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  356. ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
  357. readl(&ha->reg->mailbox[i]);
  358. ha->aen_log.count++;
  359. }
  360. switch (mbox_status) {
  361. case MBOX_ASTS_SYSTEM_ERROR:
  362. /* Log Mailbox registers */
  363. if (ql4xdontresethba) {
  364. DEBUG2(printk("%s:Dont Reset HBA\n",
  365. __func__));
  366. } else {
  367. set_bit(AF_GET_CRASH_RECORD, &ha->flags);
  368. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  369. }
  370. break;
  371. case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
  372. case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
  373. case MBOX_ASTS_NVRAM_INVALID:
  374. case MBOX_ASTS_IP_ADDRESS_CHANGED:
  375. case MBOX_ASTS_DHCP_LEASE_EXPIRED:
  376. DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
  377. "Reset HA\n", ha->host_no, mbox_status));
  378. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  379. break;
  380. case MBOX_ASTS_LINK_UP:
  381. DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK UP\n",
  382. ha->host_no, mbox_status));
  383. set_bit(AF_LINK_UP, &ha->flags);
  384. break;
  385. case MBOX_ASTS_LINK_DOWN:
  386. DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK DOWN\n",
  387. ha->host_no, mbox_status));
  388. clear_bit(AF_LINK_UP, &ha->flags);
  389. break;
  390. case MBOX_ASTS_HEARTBEAT:
  391. ha->seconds_since_last_heartbeat = 0;
  392. break;
  393. case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
  394. DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
  395. "ACQUIRED\n", ha->host_no, mbox_status));
  396. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  397. break;
  398. case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
  399. case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
  400. * mode
  401. * only */
  402. case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
  403. case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
  404. case MBOX_ASTS_SUBNET_STATE_CHANGE:
  405. /* No action */
  406. DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
  407. mbox_status));
  408. break;
  409. case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
  410. mbox_stat2 = readl(&ha->reg->mailbox[2]);
  411. mbox_stat3 = readl(&ha->reg->mailbox[3]);
  412. if ((mbox_stat3 == 5) && (mbox_stat2 == 3))
  413. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  414. else if ((mbox_stat3 == 2) && (mbox_stat2 == 5))
  415. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  416. break;
  417. case MBOX_ASTS_MAC_ADDRESS_CHANGED:
  418. case MBOX_ASTS_DNS:
  419. /* No action */
  420. DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
  421. "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
  422. ha->host_no, mbox_status,
  423. readl(&ha->reg->mailbox[1]),
  424. readl(&ha->reg->mailbox[2])));
  425. break;
  426. case MBOX_ASTS_SELF_TEST_FAILED:
  427. case MBOX_ASTS_LOGIN_FAILED:
  428. /* No action */
  429. DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
  430. "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
  431. ha->host_no, mbox_status,
  432. readl(&ha->reg->mailbox[1]),
  433. readl(&ha->reg->mailbox[2]),
  434. readl(&ha->reg->mailbox[3])));
  435. break;
  436. case MBOX_ASTS_DATABASE_CHANGED:
  437. /* Queue AEN information and process it in the DPC
  438. * routine */
  439. if (ha->aen_q_count > 0) {
  440. /* decrement available counter */
  441. ha->aen_q_count--;
  442. for (i = 1; i < MBOX_AEN_REG_COUNT; i++)
  443. ha->aen_q[ha->aen_in].mbox_sts[i] =
  444. readl(&ha->reg->mailbox[i]);
  445. ha->aen_q[ha->aen_in].mbox_sts[0] = mbox_status;
  446. /* print debug message */
  447. DEBUG2(printk("scsi%ld: AEN[%d] %04x queued"
  448. " mb1:0x%x mb2:0x%x mb3:0x%x mb4:0x%x\n",
  449. ha->host_no, ha->aen_in,
  450. mbox_status,
  451. ha->aen_q[ha->aen_in].mbox_sts[1],
  452. ha->aen_q[ha->aen_in].mbox_sts[2],
  453. ha->aen_q[ha->aen_in].mbox_sts[3],
  454. ha->aen_q[ha->aen_in]. mbox_sts[4]));
  455. /* advance pointer */
  456. ha->aen_in++;
  457. if (ha->aen_in == MAX_AEN_ENTRIES)
  458. ha->aen_in = 0;
  459. /* The DPC routine will process the aen */
  460. set_bit(DPC_AEN, &ha->dpc_flags);
  461. } else {
  462. DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
  463. "overflowed! AEN LOST!!\n",
  464. ha->host_no, __func__,
  465. mbox_status));
  466. DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
  467. ha->host_no));
  468. for (i = 0; i < MAX_AEN_ENTRIES; i++) {
  469. DEBUG2(printk("AEN[%d] %04x %04x %04x "
  470. "%04x\n", i,
  471. ha->aen_q[i].mbox_sts[0],
  472. ha->aen_q[i].mbox_sts[1],
  473. ha->aen_q[i].mbox_sts[2],
  474. ha->aen_q[i].mbox_sts[3]));
  475. }
  476. }
  477. break;
  478. default:
  479. DEBUG2(printk(KERN_WARNING
  480. "scsi%ld: AEN %04x UNKNOWN\n",
  481. ha->host_no, mbox_status));
  482. break;
  483. }
  484. } else {
  485. DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
  486. ha->host_no, mbox_status));
  487. ha->mbox_status[0] = mbox_status;
  488. }
  489. }
  490. /**
  491. * qla4xxx_interrupt_service_routine - isr
  492. * @ha: pointer to host adapter structure.
  493. *
  494. * This is the main interrupt service routine.
  495. * hardware_lock locked upon entry. runs in interrupt context.
  496. **/
  497. void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
  498. uint32_t intr_status)
  499. {
  500. /* Process response queue interrupt. */
  501. if (intr_status & CSR_SCSI_COMPLETION_INTR)
  502. qla4xxx_process_response_queue(ha);
  503. /* Process mailbox/asynch event interrupt.*/
  504. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  505. qla4xxx_isr_decode_mailbox(ha,
  506. readl(&ha->reg->mailbox[0]));
  507. /* Clear Mailbox Interrupt */
  508. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  509. &ha->reg->ctrl_status);
  510. readl(&ha->reg->ctrl_status);
  511. }
  512. }
  513. /**
  514. * qla4xxx_intr_handler - hardware interrupt handler.
  515. * @irq: Unused
  516. * @dev_id: Pointer to host adapter structure
  517. **/
  518. irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
  519. {
  520. struct scsi_qla_host *ha;
  521. uint32_t intr_status;
  522. unsigned long flags = 0;
  523. uint8_t reqs_count = 0;
  524. ha = (struct scsi_qla_host *) dev_id;
  525. if (!ha) {
  526. DEBUG2(printk(KERN_INFO
  527. "qla4xxx: Interrupt with NULL host ptr\n"));
  528. return IRQ_NONE;
  529. }
  530. spin_lock_irqsave(&ha->hardware_lock, flags);
  531. ha->isr_count++;
  532. /*
  533. * Repeatedly service interrupts up to a maximum of
  534. * MAX_REQS_SERVICED_PER_INTR
  535. */
  536. while (1) {
  537. /*
  538. * Read interrupt status
  539. */
  540. if (le32_to_cpu(ha->shadow_regs->rsp_q_in) !=
  541. ha->response_out)
  542. intr_status = CSR_SCSI_COMPLETION_INTR;
  543. else
  544. intr_status = readl(&ha->reg->ctrl_status);
  545. if ((intr_status &
  546. (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) ==
  547. 0) {
  548. if (reqs_count == 0)
  549. ha->spurious_int_count++;
  550. break;
  551. }
  552. if (intr_status & CSR_FATAL_ERROR) {
  553. DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
  554. "Status 0x%04x\n", ha->host_no,
  555. readl(isp_port_error_status (ha))));
  556. /* Issue Soft Reset to clear this error condition.
  557. * This will prevent the RISC from repeatedly
  558. * interrupting the driver; thus, allowing the DPC to
  559. * get scheduled to continue error recovery.
  560. * NOTE: Disabling RISC interrupts does not work in
  561. * this case, as CSR_FATAL_ERROR overrides
  562. * CSR_SCSI_INTR_ENABLE */
  563. if ((readl(&ha->reg->ctrl_status) &
  564. CSR_SCSI_RESET_INTR) == 0) {
  565. writel(set_rmask(CSR_SOFT_RESET),
  566. &ha->reg->ctrl_status);
  567. readl(&ha->reg->ctrl_status);
  568. }
  569. writel(set_rmask(CSR_FATAL_ERROR),
  570. &ha->reg->ctrl_status);
  571. readl(&ha->reg->ctrl_status);
  572. __qla4xxx_disable_intrs(ha);
  573. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  574. break;
  575. } else if (intr_status & CSR_SCSI_RESET_INTR) {
  576. clear_bit(AF_ONLINE, &ha->flags);
  577. __qla4xxx_disable_intrs(ha);
  578. writel(set_rmask(CSR_SCSI_RESET_INTR),
  579. &ha->reg->ctrl_status);
  580. readl(&ha->reg->ctrl_status);
  581. if (!ql4_mod_unload)
  582. set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  583. break;
  584. } else if (intr_status & INTR_PENDING) {
  585. qla4xxx_interrupt_service_routine(ha, intr_status);
  586. ha->total_io_count++;
  587. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  588. break;
  589. intr_status = 0;
  590. }
  591. }
  592. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  593. return IRQ_HANDLED;
  594. }
  595. /**
  596. * qla4xxx_process_aen - processes AENs generated by firmware
  597. * @ha: pointer to host adapter structure.
  598. * @process_aen: type of AENs to process
  599. *
  600. * Processes specific types of Asynchronous Events generated by firmware.
  601. * The type of AENs to process is specified by process_aen and can be
  602. * PROCESS_ALL_AENS 0
  603. * FLUSH_DDB_CHANGED_AENS 1
  604. * RELOGIN_DDB_CHANGED_AENS 2
  605. **/
  606. void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
  607. {
  608. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  609. struct aen *aen;
  610. int i;
  611. unsigned long flags;
  612. spin_lock_irqsave(&ha->hardware_lock, flags);
  613. while (ha->aen_out != ha->aen_in) {
  614. aen = &ha->aen_q[ha->aen_out];
  615. /* copy aen information to local structure */
  616. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  617. mbox_sts[i] = aen->mbox_sts[i];
  618. ha->aen_q_count++;
  619. ha->aen_out++;
  620. if (ha->aen_out == MAX_AEN_ENTRIES)
  621. ha->aen_out = 0;
  622. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  623. DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
  624. " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
  625. (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
  626. mbox_sts[0], mbox_sts[1], mbox_sts[2],
  627. mbox_sts[3], mbox_sts[4]));
  628. switch (mbox_sts[0]) {
  629. case MBOX_ASTS_DATABASE_CHANGED:
  630. if (process_aen == FLUSH_DDB_CHANGED_AENS) {
  631. DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
  632. "[%d] state=%04x FLUSHED!\n",
  633. ha->host_no, ha->aen_out,
  634. mbox_sts[0], mbox_sts[2],
  635. mbox_sts[3]));
  636. break;
  637. } else if (process_aen == RELOGIN_DDB_CHANGED_AENS) {
  638. /* for use during init time, we only want to
  639. * relogin non-active ddbs */
  640. struct ddb_entry *ddb_entry;
  641. ddb_entry =
  642. /* FIXME: name length? */
  643. qla4xxx_lookup_ddb_by_fw_index(ha,
  644. mbox_sts[2]);
  645. if (!ddb_entry)
  646. break;
  647. ddb_entry->dev_scan_wait_to_complete_relogin =
  648. 0;
  649. ddb_entry->dev_scan_wait_to_start_relogin =
  650. jiffies +
  651. ((ddb_entry->default_time2wait +
  652. 4) * HZ);
  653. DEBUG2(printk("scsi%ld: ddb index [%d] initate"
  654. " RELOGIN after %d seconds\n",
  655. ha->host_no,
  656. ddb_entry->fw_ddb_index,
  657. ddb_entry->default_time2wait +
  658. 4));
  659. break;
  660. }
  661. if (mbox_sts[1] == 0) { /* Global DB change. */
  662. qla4xxx_reinitialize_ddb_list(ha);
  663. } else if (mbox_sts[1] == 1) { /* Specific device. */
  664. qla4xxx_process_ddb_changed(ha, mbox_sts[2],
  665. mbox_sts[3]);
  666. }
  667. break;
  668. }
  669. spin_lock_irqsave(&ha->hardware_lock, flags);
  670. }
  671. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  672. }