ql4_isr.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  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. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Status Entry invalid "
  106. "handle 0x%x, sp=%p. This cmd may have already "
  107. "been completed.\n", ha->host_no, __func__,
  108. le32_to_cpu(sts_entry->handle), srb));
  109. ql4_printk(KERN_WARNING, ha, "%s invalid status entry:"
  110. " handle=0x%0x\n", __func__, sts_entry->handle);
  111. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  112. return;
  113. }
  114. cmd = srb->cmd;
  115. if (cmd == NULL) {
  116. DEBUG2(printk("scsi%ld: %s: Command already returned back to "
  117. "OS pkt->handle=%d srb=%p srb->state:%d\n",
  118. ha->host_no, __func__, sts_entry->handle,
  119. srb, srb->state));
  120. ql4_printk(KERN_WARNING, ha, "Command is NULL:"
  121. " already returned to OS (srb=%p)\n", srb);
  122. return;
  123. }
  124. ddb_entry = srb->ddb;
  125. if (ddb_entry == NULL) {
  126. cmd->result = DID_NO_CONNECT << 16;
  127. goto status_entry_exit;
  128. }
  129. residual = le32_to_cpu(sts_entry->residualByteCnt);
  130. /* Translate ISP error to a Linux SCSI error. */
  131. scsi_status = sts_entry->scsiStatus;
  132. switch (sts_entry->completionStatus) {
  133. case SCS_COMPLETE:
  134. if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
  135. cmd->result = DID_ERROR << 16;
  136. break;
  137. }
  138. if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
  139. scsi_set_resid(cmd, residual);
  140. if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
  141. cmd->underflow)) {
  142. cmd->result = DID_ERROR << 16;
  143. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
  144. "Mid-layer Data underrun0, "
  145. "xferlen = 0x%x, "
  146. "residual = 0x%x\n", ha->host_no,
  147. cmd->device->channel,
  148. cmd->device->id,
  149. cmd->device->lun, __func__,
  150. scsi_bufflen(cmd), residual));
  151. break;
  152. }
  153. }
  154. cmd->result = DID_OK << 16 | scsi_status;
  155. if (scsi_status != SCSI_CHECK_CONDITION)
  156. break;
  157. /* Copy Sense Data into sense buffer. */
  158. qla4xxx_copy_sense(ha, sts_entry, srb);
  159. break;
  160. case SCS_INCOMPLETE:
  161. /* Always set the status to DID_ERROR, since
  162. * all conditions result in that status anyway */
  163. cmd->result = DID_ERROR << 16;
  164. break;
  165. case SCS_RESET_OCCURRED:
  166. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Device RESET occurred\n",
  167. ha->host_no, cmd->device->channel,
  168. cmd->device->id, cmd->device->lun, __func__));
  169. cmd->result = DID_RESET << 16;
  170. break;
  171. case SCS_ABORTED:
  172. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: Abort occurred\n",
  173. ha->host_no, cmd->device->channel,
  174. cmd->device->id, cmd->device->lun, __func__));
  175. cmd->result = DID_RESET << 16;
  176. break;
  177. case SCS_TIMEOUT:
  178. DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: Timeout\n",
  179. ha->host_no, cmd->device->channel,
  180. cmd->device->id, cmd->device->lun));
  181. cmd->result = DID_TRANSPORT_DISRUPTED << 16;
  182. /*
  183. * Mark device missing so that we won't continue to send
  184. * I/O to this device. We should get a ddb state change
  185. * AEN soon.
  186. */
  187. if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
  188. qla4xxx_mark_device_missing(ha, ddb_entry);
  189. break;
  190. case SCS_DATA_UNDERRUN:
  191. case SCS_DATA_OVERRUN:
  192. if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
  193. (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
  194. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: " "Data overrun\n",
  195. ha->host_no,
  196. cmd->device->channel, cmd->device->id,
  197. cmd->device->lun, __func__));
  198. cmd->result = DID_ERROR << 16;
  199. break;
  200. }
  201. scsi_set_resid(cmd, residual);
  202. /*
  203. * If there is scsi_status, it takes precedense over
  204. * underflow condition.
  205. */
  206. if (scsi_status != 0) {
  207. cmd->result = DID_OK << 16 | scsi_status;
  208. if (scsi_status != SCSI_CHECK_CONDITION)
  209. break;
  210. /* Copy Sense Data into sense buffer. */
  211. qla4xxx_copy_sense(ha, sts_entry, srb);
  212. } else {
  213. /*
  214. * If RISC reports underrun and target does not
  215. * report it then we must have a lost frame, so
  216. * tell upper layer to retry it by reporting a
  217. * bus busy.
  218. */
  219. if ((sts_entry->iscsiFlags &
  220. ISCSI_FLAG_RESIDUAL_UNDER) == 0) {
  221. cmd->result = DID_BUS_BUSY << 16;
  222. } else if ((scsi_bufflen(cmd) - residual) <
  223. cmd->underflow) {
  224. /*
  225. * Handle mid-layer underflow???
  226. *
  227. * For kernels less than 2.4, the driver must
  228. * return an error if an underflow is detected.
  229. * For kernels equal-to and above 2.4, the
  230. * mid-layer will appearantly handle the
  231. * underflow by detecting the residual count --
  232. * unfortunately, we do not see where this is
  233. * actually being done. In the interim, we
  234. * will return DID_ERROR.
  235. */
  236. DEBUG2(printk("scsi%ld:%d:%d:%d: %s: "
  237. "Mid-layer Data underrun1, "
  238. "xferlen = 0x%x, "
  239. "residual = 0x%x\n", ha->host_no,
  240. cmd->device->channel,
  241. cmd->device->id,
  242. cmd->device->lun, __func__,
  243. scsi_bufflen(cmd), residual));
  244. cmd->result = DID_ERROR << 16;
  245. } else {
  246. cmd->result = DID_OK << 16;
  247. }
  248. }
  249. break;
  250. case SCS_DEVICE_LOGGED_OUT:
  251. case SCS_DEVICE_UNAVAILABLE:
  252. DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%d: SCS_DEVICE "
  253. "state: 0x%x\n", ha->host_no,
  254. cmd->device->channel, cmd->device->id,
  255. cmd->device->lun, sts_entry->completionStatus));
  256. /*
  257. * Mark device missing so that we won't continue to
  258. * send I/O to this device. We should get a ddb
  259. * state change AEN soon.
  260. */
  261. if (atomic_read(&ddb_entry->state) == DDB_STATE_ONLINE)
  262. qla4xxx_mark_device_missing(ha, ddb_entry);
  263. cmd->result = DID_TRANSPORT_DISRUPTED << 16;
  264. break;
  265. case SCS_QUEUE_FULL:
  266. /*
  267. * SCSI Mid-Layer handles device queue full
  268. */
  269. cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
  270. DEBUG2(printk("scsi%ld:%d:%d: %s: QUEUE FULL detected "
  271. "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
  272. " iResp=%02x\n", ha->host_no, cmd->device->id,
  273. cmd->device->lun, __func__,
  274. sts_entry->completionStatus,
  275. sts_entry->scsiStatus, sts_entry->state_flags,
  276. sts_entry->iscsiFlags,
  277. sts_entry->iscsiResponse));
  278. break;
  279. default:
  280. cmd->result = DID_ERROR << 16;
  281. break;
  282. }
  283. status_entry_exit:
  284. /* complete the request, if not waiting for status_continuation pkt */
  285. srb->cc_stat = sts_entry->completionStatus;
  286. if (ha->status_srb == NULL)
  287. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  288. }
  289. /**
  290. * qla4xxx_process_response_queue - process response queue completions
  291. * @ha: Pointer to host adapter structure.
  292. *
  293. * This routine process response queue completions in interrupt context.
  294. * Hardware_lock locked upon entry
  295. **/
  296. void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
  297. {
  298. uint32_t count = 0;
  299. struct srb *srb = NULL;
  300. struct status_entry *sts_entry;
  301. /* Process all responses from response queue */
  302. while ((ha->response_ptr->signature != RESPONSE_PROCESSED)) {
  303. sts_entry = (struct status_entry *) ha->response_ptr;
  304. count++;
  305. /* Advance pointers for next entry */
  306. if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
  307. ha->response_out = 0;
  308. ha->response_ptr = ha->response_ring;
  309. } else {
  310. ha->response_out++;
  311. ha->response_ptr++;
  312. }
  313. /* process entry */
  314. switch (sts_entry->hdr.entryType) {
  315. case ET_STATUS:
  316. /* Common status */
  317. qla4xxx_status_entry(ha, sts_entry);
  318. break;
  319. case ET_PASSTHRU_STATUS:
  320. break;
  321. case ET_STATUS_CONTINUATION:
  322. qla4xxx_status_cont_entry(ha,
  323. (struct status_cont_entry *) sts_entry);
  324. break;
  325. case ET_COMMAND:
  326. /* ISP device queue is full. Command not
  327. * accepted by ISP. Queue command for
  328. * later */
  329. srb = qla4xxx_del_from_active_array(ha,
  330. le32_to_cpu(sts_entry->
  331. handle));
  332. if (srb == NULL)
  333. goto exit_prq_invalid_handle;
  334. DEBUG2(printk("scsi%ld: %s: FW device queue full, "
  335. "srb %p\n", ha->host_no, __func__, srb));
  336. /* ETRY normally by sending it back with
  337. * DID_BUS_BUSY */
  338. srb->cmd->result = DID_BUS_BUSY << 16;
  339. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  340. break;
  341. case ET_CONTINUE:
  342. /* Just throw away the continuation entries */
  343. DEBUG2(printk("scsi%ld: %s: Continuation entry - "
  344. "ignoring\n", ha->host_no, __func__));
  345. break;
  346. default:
  347. /*
  348. * Invalid entry in response queue, reset RISC
  349. * firmware.
  350. */
  351. DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
  352. "response queue \n", ha->host_no,
  353. __func__,
  354. sts_entry->hdr.entryType));
  355. goto exit_prq_error;
  356. }
  357. ((struct response *)sts_entry)->signature = RESPONSE_PROCESSED;
  358. wmb();
  359. }
  360. /*
  361. * Tell ISP we're done with response(s). This also clears the interrupt.
  362. */
  363. ha->isp_ops->complete_iocb(ha);
  364. return;
  365. exit_prq_invalid_handle:
  366. DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
  367. ha->host_no, __func__, srb, sts_entry->hdr.entryType,
  368. sts_entry->completionStatus));
  369. exit_prq_error:
  370. ha->isp_ops->complete_iocb(ha);
  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_sts[MBOX_AEN_REG_COUNT];
  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 = 0; i < ha->mbox_status_count; i++)
  396. ha->mbox_status[i] = is_qla8022(ha)
  397. ? readl(&ha->qla4_8xxx_reg->mailbox_out[i])
  398. : readl(&ha->reg->mailbox[i]);
  399. set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
  400. if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
  401. complete(&ha->mbx_intr_comp);
  402. }
  403. } else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
  404. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  405. mbox_sts[i] = is_qla8022(ha)
  406. ? readl(&ha->qla4_8xxx_reg->mailbox_out[i])
  407. : readl(&ha->reg->mailbox[i]);
  408. /* Immediately process the AENs that don't require much work.
  409. * Only queue the database_changed AENs */
  410. if (ha->aen_log.count < MAX_AEN_ENTRIES) {
  411. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  412. ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
  413. mbox_sts[i];
  414. ha->aen_log.count++;
  415. }
  416. switch (mbox_status) {
  417. case MBOX_ASTS_SYSTEM_ERROR:
  418. /* Log Mailbox registers */
  419. ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
  420. if (ql4xdontresethba) {
  421. DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
  422. ha->host_no, __func__));
  423. } else {
  424. set_bit(AF_GET_CRASH_RECORD, &ha->flags);
  425. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  426. }
  427. break;
  428. case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
  429. case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
  430. case MBOX_ASTS_NVRAM_INVALID:
  431. case MBOX_ASTS_IP_ADDRESS_CHANGED:
  432. case MBOX_ASTS_DHCP_LEASE_EXPIRED:
  433. DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
  434. "Reset HA\n", ha->host_no, mbox_status));
  435. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  436. break;
  437. case MBOX_ASTS_LINK_UP:
  438. set_bit(AF_LINK_UP, &ha->flags);
  439. if (test_bit(AF_INIT_DONE, &ha->flags))
  440. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  441. ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
  442. break;
  443. case MBOX_ASTS_LINK_DOWN:
  444. clear_bit(AF_LINK_UP, &ha->flags);
  445. if (test_bit(AF_INIT_DONE, &ha->flags))
  446. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  447. ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
  448. break;
  449. case MBOX_ASTS_HEARTBEAT:
  450. ha->seconds_since_last_heartbeat = 0;
  451. break;
  452. case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
  453. DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
  454. "ACQUIRED\n", ha->host_no, mbox_status));
  455. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  456. break;
  457. case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
  458. case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
  459. * mode
  460. * only */
  461. case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
  462. case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
  463. case MBOX_ASTS_SUBNET_STATE_CHANGE:
  464. /* No action */
  465. DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
  466. mbox_status));
  467. break;
  468. case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
  469. printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
  470. "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
  471. mbox_sts[2], mbox_sts[3]);
  472. /* mbox_sts[2] = Old ACB state
  473. * mbox_sts[3] = new ACB state */
  474. if ((mbox_sts[3] == ACB_STATE_VALID) &&
  475. (mbox_sts[2] == ACB_STATE_TENTATIVE))
  476. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  477. else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
  478. (mbox_sts[2] == ACB_STATE_VALID))
  479. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  480. break;
  481. case MBOX_ASTS_MAC_ADDRESS_CHANGED:
  482. case MBOX_ASTS_DNS:
  483. /* No action */
  484. DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
  485. "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
  486. ha->host_no, mbox_sts[0],
  487. mbox_sts[1], mbox_sts[2]));
  488. break;
  489. case MBOX_ASTS_SELF_TEST_FAILED:
  490. case MBOX_ASTS_LOGIN_FAILED:
  491. /* No action */
  492. DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
  493. "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
  494. ha->host_no, mbox_sts[0], mbox_sts[1],
  495. mbox_sts[2], mbox_sts[3]));
  496. break;
  497. case MBOX_ASTS_DATABASE_CHANGED:
  498. /* Queue AEN information and process it in the DPC
  499. * routine */
  500. if (ha->aen_q_count > 0) {
  501. /* decrement available counter */
  502. ha->aen_q_count--;
  503. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  504. ha->aen_q[ha->aen_in].mbox_sts[i] =
  505. mbox_sts[i];
  506. /* print debug message */
  507. DEBUG2(printk("scsi%ld: AEN[%d] %04x queued"
  508. " mb1:0x%x mb2:0x%x mb3:0x%x mb4:0x%x\n",
  509. ha->host_no, ha->aen_in, mbox_sts[0],
  510. mbox_sts[1], mbox_sts[2], mbox_sts[3],
  511. mbox_sts[4]));
  512. /* advance pointer */
  513. ha->aen_in++;
  514. if (ha->aen_in == MAX_AEN_ENTRIES)
  515. ha->aen_in = 0;
  516. /* The DPC routine will process the aen */
  517. set_bit(DPC_AEN, &ha->dpc_flags);
  518. } else {
  519. DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
  520. "overflowed! AEN LOST!!\n",
  521. ha->host_no, __func__,
  522. mbox_sts[0]));
  523. DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
  524. ha->host_no));
  525. for (i = 0; i < MAX_AEN_ENTRIES; i++) {
  526. DEBUG2(printk("AEN[%d] %04x %04x %04x "
  527. "%04x\n", i, mbox_sts[0],
  528. mbox_sts[1], mbox_sts[2],
  529. mbox_sts[3]));
  530. }
  531. }
  532. break;
  533. default:
  534. DEBUG2(printk(KERN_WARNING
  535. "scsi%ld: AEN %04x UNKNOWN\n",
  536. ha->host_no, mbox_sts[0]));
  537. break;
  538. }
  539. } else {
  540. DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
  541. ha->host_no, mbox_status));
  542. ha->mbox_status[0] = mbox_status;
  543. }
  544. }
  545. /**
  546. * qla4_8xxx_interrupt_service_routine - isr
  547. * @ha: pointer to host adapter structure.
  548. *
  549. * This is the main interrupt service routine.
  550. * hardware_lock locked upon entry. runs in interrupt context.
  551. **/
  552. void qla4_8xxx_interrupt_service_routine(struct scsi_qla_host *ha,
  553. uint32_t intr_status)
  554. {
  555. /* Process response queue interrupt. */
  556. if (intr_status & HSRX_RISC_IOCB_INT)
  557. qla4xxx_process_response_queue(ha);
  558. /* Process mailbox/asynch event interrupt.*/
  559. if (intr_status & HSRX_RISC_MB_INT)
  560. qla4xxx_isr_decode_mailbox(ha,
  561. readl(&ha->qla4_8xxx_reg->mailbox_out[0]));
  562. /* clear the interrupt */
  563. writel(0, &ha->qla4_8xxx_reg->host_int);
  564. readl(&ha->qla4_8xxx_reg->host_int);
  565. }
  566. /**
  567. * qla4xxx_interrupt_service_routine - isr
  568. * @ha: pointer to host adapter structure.
  569. *
  570. * This is the main interrupt service routine.
  571. * hardware_lock locked upon entry. runs in interrupt context.
  572. **/
  573. void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
  574. uint32_t intr_status)
  575. {
  576. /* Process response queue interrupt. */
  577. if (intr_status & CSR_SCSI_COMPLETION_INTR)
  578. qla4xxx_process_response_queue(ha);
  579. /* Process mailbox/asynch event interrupt.*/
  580. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  581. qla4xxx_isr_decode_mailbox(ha,
  582. readl(&ha->reg->mailbox[0]));
  583. /* Clear Mailbox Interrupt */
  584. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  585. &ha->reg->ctrl_status);
  586. readl(&ha->reg->ctrl_status);
  587. }
  588. }
  589. /**
  590. * qla4_8xxx_spurious_interrupt - processes spurious interrupt
  591. * @ha: pointer to host adapter structure.
  592. * @reqs_count: .
  593. *
  594. **/
  595. static void qla4_8xxx_spurious_interrupt(struct scsi_qla_host *ha,
  596. uint8_t reqs_count)
  597. {
  598. if (reqs_count)
  599. return;
  600. DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
  601. if (is_qla8022(ha)) {
  602. writel(0, &ha->qla4_8xxx_reg->host_int);
  603. if (test_bit(AF_INTx_ENABLED, &ha->flags))
  604. qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
  605. 0xfbff);
  606. }
  607. ha->spurious_int_count++;
  608. }
  609. /**
  610. * qla4xxx_intr_handler - hardware interrupt handler.
  611. * @irq: Unused
  612. * @dev_id: Pointer to host adapter structure
  613. **/
  614. irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
  615. {
  616. struct scsi_qla_host *ha;
  617. uint32_t intr_status;
  618. unsigned long flags = 0;
  619. uint8_t reqs_count = 0;
  620. ha = (struct scsi_qla_host *) dev_id;
  621. if (!ha) {
  622. DEBUG2(printk(KERN_INFO
  623. "qla4xxx: Interrupt with NULL host ptr\n"));
  624. return IRQ_NONE;
  625. }
  626. spin_lock_irqsave(&ha->hardware_lock, flags);
  627. ha->isr_count++;
  628. /*
  629. * Repeatedly service interrupts up to a maximum of
  630. * MAX_REQS_SERVICED_PER_INTR
  631. */
  632. while (1) {
  633. /*
  634. * Read interrupt status
  635. */
  636. if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
  637. ha->response_out)
  638. intr_status = CSR_SCSI_COMPLETION_INTR;
  639. else
  640. intr_status = readl(&ha->reg->ctrl_status);
  641. if ((intr_status &
  642. (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
  643. if (reqs_count == 0)
  644. ha->spurious_int_count++;
  645. break;
  646. }
  647. if (intr_status & CSR_FATAL_ERROR) {
  648. DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
  649. "Status 0x%04x\n", ha->host_no,
  650. readl(isp_port_error_status (ha))));
  651. /* Issue Soft Reset to clear this error condition.
  652. * This will prevent the RISC from repeatedly
  653. * interrupting the driver; thus, allowing the DPC to
  654. * get scheduled to continue error recovery.
  655. * NOTE: Disabling RISC interrupts does not work in
  656. * this case, as CSR_FATAL_ERROR overrides
  657. * CSR_SCSI_INTR_ENABLE */
  658. if ((readl(&ha->reg->ctrl_status) &
  659. CSR_SCSI_RESET_INTR) == 0) {
  660. writel(set_rmask(CSR_SOFT_RESET),
  661. &ha->reg->ctrl_status);
  662. readl(&ha->reg->ctrl_status);
  663. }
  664. writel(set_rmask(CSR_FATAL_ERROR),
  665. &ha->reg->ctrl_status);
  666. readl(&ha->reg->ctrl_status);
  667. __qla4xxx_disable_intrs(ha);
  668. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  669. break;
  670. } else if (intr_status & CSR_SCSI_RESET_INTR) {
  671. clear_bit(AF_ONLINE, &ha->flags);
  672. __qla4xxx_disable_intrs(ha);
  673. writel(set_rmask(CSR_SCSI_RESET_INTR),
  674. &ha->reg->ctrl_status);
  675. readl(&ha->reg->ctrl_status);
  676. if (!test_bit(AF_HBA_GOING_AWAY, &ha->flags))
  677. set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  678. break;
  679. } else if (intr_status & INTR_PENDING) {
  680. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  681. ha->total_io_count++;
  682. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  683. break;
  684. }
  685. }
  686. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  687. return IRQ_HANDLED;
  688. }
  689. /**
  690. * qla4_8xxx_intr_handler - hardware interrupt handler.
  691. * @irq: Unused
  692. * @dev_id: Pointer to host adapter structure
  693. **/
  694. irqreturn_t qla4_8xxx_intr_handler(int irq, void *dev_id)
  695. {
  696. struct scsi_qla_host *ha = dev_id;
  697. uint32_t intr_status;
  698. uint32_t status;
  699. unsigned long flags = 0;
  700. uint8_t reqs_count = 0;
  701. ha->isr_count++;
  702. status = qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  703. if (!(status & ha->nx_legacy_intr.int_vec_bit))
  704. return IRQ_NONE;
  705. status = qla4_8xxx_rd_32(ha, ISR_INT_STATE_REG);
  706. if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
  707. DEBUG2(ql4_printk(KERN_INFO, ha,
  708. "%s legacy Int not triggered\n", __func__));
  709. return IRQ_NONE;
  710. }
  711. /* clear the interrupt */
  712. qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  713. /* read twice to ensure write is flushed */
  714. qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  715. qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  716. spin_lock_irqsave(&ha->hardware_lock, flags);
  717. while (1) {
  718. if (!(readl(&ha->qla4_8xxx_reg->host_int) &
  719. ISRX_82XX_RISC_INT)) {
  720. qla4_8xxx_spurious_interrupt(ha, reqs_count);
  721. break;
  722. }
  723. intr_status = readl(&ha->qla4_8xxx_reg->host_status);
  724. if ((intr_status &
  725. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  726. qla4_8xxx_spurious_interrupt(ha, reqs_count);
  727. break;
  728. }
  729. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  730. /* Enable Interrupt */
  731. qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
  732. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  733. break;
  734. }
  735. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  736. return IRQ_HANDLED;
  737. }
  738. irqreturn_t
  739. qla4_8xxx_msi_handler(int irq, void *dev_id)
  740. {
  741. struct scsi_qla_host *ha;
  742. ha = (struct scsi_qla_host *) dev_id;
  743. if (!ha) {
  744. DEBUG2(printk(KERN_INFO
  745. "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
  746. return IRQ_NONE;
  747. }
  748. ha->isr_count++;
  749. /* clear the interrupt */
  750. qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  751. /* read twice to ensure write is flushed */
  752. qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  753. qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  754. return qla4_8xxx_default_intr_handler(irq, dev_id);
  755. }
  756. /**
  757. * qla4_8xxx_default_intr_handler - hardware interrupt handler.
  758. * @irq: Unused
  759. * @dev_id: Pointer to host adapter structure
  760. *
  761. * This interrupt handler is called directly for MSI-X, and
  762. * called indirectly for MSI.
  763. **/
  764. irqreturn_t
  765. qla4_8xxx_default_intr_handler(int irq, void *dev_id)
  766. {
  767. struct scsi_qla_host *ha = dev_id;
  768. unsigned long flags;
  769. uint32_t intr_status;
  770. uint8_t reqs_count = 0;
  771. spin_lock_irqsave(&ha->hardware_lock, flags);
  772. while (1) {
  773. if (!(readl(&ha->qla4_8xxx_reg->host_int) &
  774. ISRX_82XX_RISC_INT)) {
  775. qla4_8xxx_spurious_interrupt(ha, reqs_count);
  776. break;
  777. }
  778. intr_status = readl(&ha->qla4_8xxx_reg->host_status);
  779. if ((intr_status &
  780. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  781. qla4_8xxx_spurious_interrupt(ha, reqs_count);
  782. break;
  783. }
  784. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  785. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  786. break;
  787. }
  788. ha->isr_count++;
  789. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  790. return IRQ_HANDLED;
  791. }
  792. irqreturn_t
  793. qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
  794. {
  795. struct scsi_qla_host *ha = dev_id;
  796. unsigned long flags;
  797. spin_lock_irqsave(&ha->hardware_lock, flags);
  798. qla4xxx_process_response_queue(ha);
  799. writel(0, &ha->qla4_8xxx_reg->host_int);
  800. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  801. ha->isr_count++;
  802. return IRQ_HANDLED;
  803. }
  804. /**
  805. * qla4xxx_process_aen - processes AENs generated by firmware
  806. * @ha: pointer to host adapter structure.
  807. * @process_aen: type of AENs to process
  808. *
  809. * Processes specific types of Asynchronous Events generated by firmware.
  810. * The type of AENs to process is specified by process_aen and can be
  811. * PROCESS_ALL_AENS 0
  812. * FLUSH_DDB_CHANGED_AENS 1
  813. * RELOGIN_DDB_CHANGED_AENS 2
  814. **/
  815. void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
  816. {
  817. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  818. struct aen *aen;
  819. int i;
  820. unsigned long flags;
  821. spin_lock_irqsave(&ha->hardware_lock, flags);
  822. while (ha->aen_out != ha->aen_in) {
  823. aen = &ha->aen_q[ha->aen_out];
  824. /* copy aen information to local structure */
  825. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  826. mbox_sts[i] = aen->mbox_sts[i];
  827. ha->aen_q_count++;
  828. ha->aen_out++;
  829. if (ha->aen_out == MAX_AEN_ENTRIES)
  830. ha->aen_out = 0;
  831. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  832. DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
  833. " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
  834. (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
  835. mbox_sts[0], mbox_sts[1], mbox_sts[2],
  836. mbox_sts[3], mbox_sts[4]));
  837. switch (mbox_sts[0]) {
  838. case MBOX_ASTS_DATABASE_CHANGED:
  839. if (process_aen == FLUSH_DDB_CHANGED_AENS) {
  840. DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
  841. "[%d] state=%04x FLUSHED!\n",
  842. ha->host_no, ha->aen_out,
  843. mbox_sts[0], mbox_sts[2],
  844. mbox_sts[3]));
  845. break;
  846. } else if (process_aen == RELOGIN_DDB_CHANGED_AENS) {
  847. /* for use during init time, we only want to
  848. * relogin non-active ddbs */
  849. struct ddb_entry *ddb_entry;
  850. ddb_entry =
  851. /* FIXME: name length? */
  852. qla4xxx_lookup_ddb_by_fw_index(ha,
  853. mbox_sts[2]);
  854. if (!ddb_entry)
  855. break;
  856. ddb_entry->dev_scan_wait_to_complete_relogin =
  857. 0;
  858. ddb_entry->dev_scan_wait_to_start_relogin =
  859. jiffies +
  860. ((ddb_entry->default_time2wait +
  861. 4) * HZ);
  862. DEBUG2(printk("scsi%ld: ddb [%d] initate"
  863. " RELOGIN after %d seconds\n",
  864. ha->host_no,
  865. ddb_entry->fw_ddb_index,
  866. ddb_entry->default_time2wait +
  867. 4));
  868. break;
  869. }
  870. if (mbox_sts[1] == 0) { /* Global DB change. */
  871. qla4xxx_reinitialize_ddb_list(ha);
  872. } else if (mbox_sts[1] == 1) { /* Specific device. */
  873. qla4xxx_process_ddb_changed(ha, mbox_sts[2],
  874. mbox_sts[3], mbox_sts[4]);
  875. }
  876. break;
  877. }
  878. spin_lock_irqsave(&ha->hardware_lock, flags);
  879. }
  880. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  881. }
  882. int qla4xxx_request_irqs(struct scsi_qla_host *ha)
  883. {
  884. int ret;
  885. if (!is_qla8022(ha))
  886. goto try_intx;
  887. if (ql4xenablemsix == 2)
  888. goto try_msi;
  889. if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
  890. goto try_intx;
  891. /* Trying MSI-X */
  892. ret = qla4_8xxx_enable_msix(ha);
  893. if (!ret) {
  894. DEBUG2(ql4_printk(KERN_INFO, ha,
  895. "MSI-X: Enabled (0x%X).\n", ha->revision_id));
  896. goto irq_attached;
  897. }
  898. ql4_printk(KERN_WARNING, ha,
  899. "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
  900. try_msi:
  901. /* Trying MSI */
  902. ret = pci_enable_msi(ha->pdev);
  903. if (!ret) {
  904. ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
  905. IRQF_DISABLED|IRQF_SHARED, DRIVER_NAME, ha);
  906. if (!ret) {
  907. DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
  908. set_bit(AF_MSI_ENABLED, &ha->flags);
  909. goto irq_attached;
  910. } else {
  911. ql4_printk(KERN_WARNING, ha,
  912. "MSI: Failed to reserve interrupt %d "
  913. "already in use.\n", ha->pdev->irq);
  914. pci_disable_msi(ha->pdev);
  915. }
  916. }
  917. ql4_printk(KERN_WARNING, ha,
  918. "MSI: Falling back-to INTx mode -- %d.\n", ret);
  919. try_intx:
  920. /* Trying INTx */
  921. ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
  922. IRQF_DISABLED|IRQF_SHARED, DRIVER_NAME, ha);
  923. if (!ret) {
  924. DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
  925. set_bit(AF_INTx_ENABLED, &ha->flags);
  926. goto irq_attached;
  927. } else {
  928. ql4_printk(KERN_WARNING, ha,
  929. "INTx: Failed to reserve interrupt %d already in"
  930. " use.\n", ha->pdev->irq);
  931. return ret;
  932. }
  933. irq_attached:
  934. set_bit(AF_IRQ_ATTACHED, &ha->flags);
  935. ha->host->irq = ha->pdev->irq;
  936. ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
  937. __func__, ha->pdev->irq);
  938. return ret;
  939. }
  940. void qla4xxx_free_irqs(struct scsi_qla_host *ha)
  941. {
  942. if (test_bit(AF_MSIX_ENABLED, &ha->flags))
  943. qla4_8xxx_disable_msix(ha);
  944. else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
  945. free_irq(ha->pdev->irq, ha);
  946. pci_disable_msi(ha->pdev);
  947. } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags))
  948. free_irq(ha->pdev->irq, ha);
  949. }