ql4_isr.c 22 KB

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