ql4_isr.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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. qla4xxx_srb_compl(ha, srb);
  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. qla4xxx_srb_compl(ha, srb);
  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. qla4xxx_srb_compl(ha, srb);
  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. DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK UP\n",
  431. ha->host_no, mbox_status));
  432. set_bit(AF_LINK_UP, &ha->flags);
  433. break;
  434. case MBOX_ASTS_LINK_DOWN:
  435. DEBUG2(printk("scsi%ld: AEN %04x Adapter LINK DOWN\n",
  436. ha->host_no, mbox_status));
  437. clear_bit(AF_LINK_UP, &ha->flags);
  438. break;
  439. case MBOX_ASTS_HEARTBEAT:
  440. ha->seconds_since_last_heartbeat = 0;
  441. break;
  442. case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
  443. DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
  444. "ACQUIRED\n", ha->host_no, mbox_status));
  445. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  446. break;
  447. case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
  448. case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
  449. * mode
  450. * only */
  451. case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
  452. case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
  453. case MBOX_ASTS_SUBNET_STATE_CHANGE:
  454. /* No action */
  455. DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
  456. mbox_status));
  457. break;
  458. case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
  459. mbox_stat2 = readl(&ha->reg->mailbox[2]);
  460. mbox_stat3 = readl(&ha->reg->mailbox[3]);
  461. if ((mbox_stat3 == 5) && (mbox_stat2 == 3))
  462. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  463. else if ((mbox_stat3 == 2) && (mbox_stat2 == 5))
  464. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  465. break;
  466. case MBOX_ASTS_MAC_ADDRESS_CHANGED:
  467. case MBOX_ASTS_DNS:
  468. /* No action */
  469. DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
  470. "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
  471. ha->host_no, mbox_status,
  472. readl(&ha->reg->mailbox[1]),
  473. readl(&ha->reg->mailbox[2])));
  474. break;
  475. case MBOX_ASTS_SELF_TEST_FAILED:
  476. case MBOX_ASTS_LOGIN_FAILED:
  477. /* No action */
  478. DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
  479. "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
  480. ha->host_no, mbox_status,
  481. readl(&ha->reg->mailbox[1]),
  482. readl(&ha->reg->mailbox[2]),
  483. readl(&ha->reg->mailbox[3])));
  484. break;
  485. case MBOX_ASTS_DATABASE_CHANGED:
  486. /* Queue AEN information and process it in the DPC
  487. * routine */
  488. if (ha->aen_q_count > 0) {
  489. /* decrement available counter */
  490. ha->aen_q_count--;
  491. for (i = 1; i < MBOX_AEN_REG_COUNT; i++)
  492. ha->aen_q[ha->aen_in].mbox_sts[i] =
  493. readl(&ha->reg->mailbox[i]);
  494. ha->aen_q[ha->aen_in].mbox_sts[0] = mbox_status;
  495. /* print debug message */
  496. DEBUG2(printk("scsi%ld: AEN[%d] %04x queued"
  497. " mb1:0x%x mb2:0x%x mb3:0x%x mb4:0x%x\n",
  498. ha->host_no, ha->aen_in,
  499. mbox_status,
  500. ha->aen_q[ha->aen_in].mbox_sts[1],
  501. ha->aen_q[ha->aen_in].mbox_sts[2],
  502. ha->aen_q[ha->aen_in].mbox_sts[3],
  503. ha->aen_q[ha->aen_in]. mbox_sts[4]));
  504. /* advance pointer */
  505. ha->aen_in++;
  506. if (ha->aen_in == MAX_AEN_ENTRIES)
  507. ha->aen_in = 0;
  508. /* The DPC routine will process the aen */
  509. set_bit(DPC_AEN, &ha->dpc_flags);
  510. } else {
  511. DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
  512. "overflowed! AEN LOST!!\n",
  513. ha->host_no, __func__,
  514. mbox_status));
  515. DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
  516. ha->host_no));
  517. for (i = 0; i < MAX_AEN_ENTRIES; i++) {
  518. DEBUG2(printk("AEN[%d] %04x %04x %04x "
  519. "%04x\n", i,
  520. ha->aen_q[i].mbox_sts[0],
  521. ha->aen_q[i].mbox_sts[1],
  522. ha->aen_q[i].mbox_sts[2],
  523. ha->aen_q[i].mbox_sts[3]));
  524. }
  525. }
  526. break;
  527. default:
  528. DEBUG2(printk(KERN_WARNING
  529. "scsi%ld: AEN %04x UNKNOWN\n",
  530. ha->host_no, mbox_status));
  531. break;
  532. }
  533. } else {
  534. DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
  535. ha->host_no, mbox_status));
  536. ha->mbox_status[0] = mbox_status;
  537. }
  538. }
  539. /**
  540. * qla4xxx_interrupt_service_routine - isr
  541. * @ha: pointer to host adapter structure.
  542. *
  543. * This is the main interrupt service routine.
  544. * hardware_lock locked upon entry. runs in interrupt context.
  545. **/
  546. void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
  547. uint32_t intr_status)
  548. {
  549. /* Process response queue interrupt. */
  550. if (intr_status & CSR_SCSI_COMPLETION_INTR)
  551. qla4xxx_process_response_queue(ha);
  552. /* Process mailbox/asynch event interrupt.*/
  553. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  554. qla4xxx_isr_decode_mailbox(ha,
  555. readl(&ha->reg->mailbox[0]));
  556. /* Clear Mailbox Interrupt */
  557. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  558. &ha->reg->ctrl_status);
  559. readl(&ha->reg->ctrl_status);
  560. }
  561. }
  562. /**
  563. * qla4xxx_intr_handler - hardware interrupt handler.
  564. * @irq: Unused
  565. * @dev_id: Pointer to host adapter structure
  566. **/
  567. irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
  568. {
  569. struct scsi_qla_host *ha;
  570. uint32_t intr_status;
  571. unsigned long flags = 0;
  572. uint8_t reqs_count = 0;
  573. ha = (struct scsi_qla_host *) dev_id;
  574. if (!ha) {
  575. DEBUG2(printk(KERN_INFO
  576. "qla4xxx: Interrupt with NULL host ptr\n"));
  577. return IRQ_NONE;
  578. }
  579. spin_lock_irqsave(&ha->hardware_lock, flags);
  580. ha->isr_count++;
  581. /*
  582. * Repeatedly service interrupts up to a maximum of
  583. * MAX_REQS_SERVICED_PER_INTR
  584. */
  585. while (1) {
  586. /*
  587. * Read interrupt status
  588. */
  589. if (le32_to_cpu(ha->shadow_regs->rsp_q_in) !=
  590. ha->response_out)
  591. intr_status = CSR_SCSI_COMPLETION_INTR;
  592. else
  593. intr_status = readl(&ha->reg->ctrl_status);
  594. if ((intr_status &
  595. (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) ==
  596. 0) {
  597. if (reqs_count == 0)
  598. ha->spurious_int_count++;
  599. break;
  600. }
  601. if (intr_status & CSR_FATAL_ERROR) {
  602. DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
  603. "Status 0x%04x\n", ha->host_no,
  604. readl(isp_port_error_status (ha))));
  605. /* Issue Soft Reset to clear this error condition.
  606. * This will prevent the RISC from repeatedly
  607. * interrupting the driver; thus, allowing the DPC to
  608. * get scheduled to continue error recovery.
  609. * NOTE: Disabling RISC interrupts does not work in
  610. * this case, as CSR_FATAL_ERROR overrides
  611. * CSR_SCSI_INTR_ENABLE */
  612. if ((readl(&ha->reg->ctrl_status) &
  613. CSR_SCSI_RESET_INTR) == 0) {
  614. writel(set_rmask(CSR_SOFT_RESET),
  615. &ha->reg->ctrl_status);
  616. readl(&ha->reg->ctrl_status);
  617. }
  618. writel(set_rmask(CSR_FATAL_ERROR),
  619. &ha->reg->ctrl_status);
  620. readl(&ha->reg->ctrl_status);
  621. __qla4xxx_disable_intrs(ha);
  622. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  623. break;
  624. } else if (intr_status & CSR_SCSI_RESET_INTR) {
  625. clear_bit(AF_ONLINE, &ha->flags);
  626. __qla4xxx_disable_intrs(ha);
  627. writel(set_rmask(CSR_SCSI_RESET_INTR),
  628. &ha->reg->ctrl_status);
  629. readl(&ha->reg->ctrl_status);
  630. if (!ql4_mod_unload)
  631. set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  632. break;
  633. } else if (intr_status & INTR_PENDING) {
  634. qla4xxx_interrupt_service_routine(ha, intr_status);
  635. ha->total_io_count++;
  636. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  637. break;
  638. intr_status = 0;
  639. }
  640. }
  641. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  642. return IRQ_HANDLED;
  643. }
  644. /**
  645. * qla4xxx_process_aen - processes AENs generated by firmware
  646. * @ha: pointer to host adapter structure.
  647. * @process_aen: type of AENs to process
  648. *
  649. * Processes specific types of Asynchronous Events generated by firmware.
  650. * The type of AENs to process is specified by process_aen and can be
  651. * PROCESS_ALL_AENS 0
  652. * FLUSH_DDB_CHANGED_AENS 1
  653. * RELOGIN_DDB_CHANGED_AENS 2
  654. **/
  655. void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
  656. {
  657. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  658. struct aen *aen;
  659. int i;
  660. unsigned long flags;
  661. spin_lock_irqsave(&ha->hardware_lock, flags);
  662. while (ha->aen_out != ha->aen_in) {
  663. aen = &ha->aen_q[ha->aen_out];
  664. /* copy aen information to local structure */
  665. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  666. mbox_sts[i] = aen->mbox_sts[i];
  667. ha->aen_q_count++;
  668. ha->aen_out++;
  669. if (ha->aen_out == MAX_AEN_ENTRIES)
  670. ha->aen_out = 0;
  671. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  672. DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
  673. " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
  674. (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
  675. mbox_sts[0], mbox_sts[1], mbox_sts[2],
  676. mbox_sts[3], mbox_sts[4]));
  677. switch (mbox_sts[0]) {
  678. case MBOX_ASTS_DATABASE_CHANGED:
  679. if (process_aen == FLUSH_DDB_CHANGED_AENS) {
  680. DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
  681. "[%d] state=%04x FLUSHED!\n",
  682. ha->host_no, ha->aen_out,
  683. mbox_sts[0], mbox_sts[2],
  684. mbox_sts[3]));
  685. break;
  686. } else if (process_aen == RELOGIN_DDB_CHANGED_AENS) {
  687. /* for use during init time, we only want to
  688. * relogin non-active ddbs */
  689. struct ddb_entry *ddb_entry;
  690. ddb_entry =
  691. /* FIXME: name length? */
  692. qla4xxx_lookup_ddb_by_fw_index(ha,
  693. mbox_sts[2]);
  694. if (!ddb_entry)
  695. break;
  696. ddb_entry->dev_scan_wait_to_complete_relogin =
  697. 0;
  698. ddb_entry->dev_scan_wait_to_start_relogin =
  699. jiffies +
  700. ((ddb_entry->default_time2wait +
  701. 4) * HZ);
  702. DEBUG2(printk("scsi%ld: ddb index [%d] initate"
  703. " RELOGIN after %d seconds\n",
  704. ha->host_no,
  705. ddb_entry->fw_ddb_index,
  706. ddb_entry->default_time2wait +
  707. 4));
  708. break;
  709. }
  710. if (mbox_sts[1] == 0) { /* Global DB change. */
  711. qla4xxx_reinitialize_ddb_list(ha);
  712. } else if (mbox_sts[1] == 1) { /* Specific device. */
  713. qla4xxx_process_ddb_changed(ha, mbox_sts[2],
  714. mbox_sts[3]);
  715. }
  716. break;
  717. }
  718. spin_lock_irqsave(&ha->hardware_lock, flags);
  719. }
  720. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  721. }