ql4_isr.c 23 KB

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