ql4_isr.c 22 KB

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