ql4_isr.c 22 KB

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