ql4_isr.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2010 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. uint16_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. qla4xxx_dump_registers(ha);
  421. if (ql4xdontresethba) {
  422. DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
  423. ha->host_no, __func__));
  424. } else {
  425. set_bit(AF_GET_CRASH_RECORD, &ha->flags);
  426. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  427. }
  428. break;
  429. case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
  430. case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
  431. case MBOX_ASTS_NVRAM_INVALID:
  432. case MBOX_ASTS_IP_ADDRESS_CHANGED:
  433. case MBOX_ASTS_DHCP_LEASE_EXPIRED:
  434. DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
  435. "Reset HA\n", ha->host_no, mbox_status));
  436. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  437. break;
  438. case MBOX_ASTS_LINK_UP:
  439. set_bit(AF_LINK_UP, &ha->flags);
  440. if (test_bit(AF_INIT_DONE, &ha->flags))
  441. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  442. ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
  443. break;
  444. case MBOX_ASTS_LINK_DOWN:
  445. clear_bit(AF_LINK_UP, &ha->flags);
  446. if (test_bit(AF_INIT_DONE, &ha->flags))
  447. set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
  448. ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
  449. break;
  450. case MBOX_ASTS_HEARTBEAT:
  451. ha->seconds_since_last_heartbeat = 0;
  452. break;
  453. case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
  454. DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
  455. "ACQUIRED\n", ha->host_no, mbox_status));
  456. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  457. break;
  458. case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
  459. case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
  460. * mode
  461. * only */
  462. case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED: /* Connection mode */
  463. case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
  464. case MBOX_ASTS_SUBNET_STATE_CHANGE:
  465. /* No action */
  466. DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
  467. mbox_status));
  468. break;
  469. case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
  470. printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
  471. "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
  472. mbox_sts[2], mbox_sts[3]);
  473. /* mbox_sts[2] = Old ACB state
  474. * mbox_sts[3] = new ACB state */
  475. if ((mbox_sts[3] == ACB_STATE_VALID) &&
  476. ((mbox_sts[2] == ACB_STATE_TENTATIVE) ||
  477. (mbox_sts[2] == ACB_STATE_ACQUIRING)))
  478. set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
  479. else if ((mbox_sts[3] == ACB_STATE_ACQUIRING) &&
  480. (mbox_sts[2] == ACB_STATE_VALID))
  481. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  482. break;
  483. case MBOX_ASTS_MAC_ADDRESS_CHANGED:
  484. case MBOX_ASTS_DNS:
  485. /* No action */
  486. DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
  487. "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
  488. ha->host_no, mbox_sts[0],
  489. mbox_sts[1], mbox_sts[2]));
  490. break;
  491. case MBOX_ASTS_SELF_TEST_FAILED:
  492. case MBOX_ASTS_LOGIN_FAILED:
  493. /* No action */
  494. DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
  495. "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
  496. ha->host_no, mbox_sts[0], mbox_sts[1],
  497. mbox_sts[2], mbox_sts[3]));
  498. break;
  499. case MBOX_ASTS_DATABASE_CHANGED:
  500. /* Queue AEN information and process it in the DPC
  501. * routine */
  502. if (ha->aen_q_count > 0) {
  503. /* decrement available counter */
  504. ha->aen_q_count--;
  505. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  506. ha->aen_q[ha->aen_in].mbox_sts[i] =
  507. mbox_sts[i];
  508. /* print debug message */
  509. DEBUG2(printk("scsi%ld: AEN[%d] %04x queued"
  510. " mb1:0x%x mb2:0x%x mb3:0x%x mb4:0x%x\n",
  511. ha->host_no, ha->aen_in, mbox_sts[0],
  512. mbox_sts[1], mbox_sts[2], mbox_sts[3],
  513. mbox_sts[4]));
  514. /* advance pointer */
  515. ha->aen_in++;
  516. if (ha->aen_in == MAX_AEN_ENTRIES)
  517. ha->aen_in = 0;
  518. /* The DPC routine will process the aen */
  519. set_bit(DPC_AEN, &ha->dpc_flags);
  520. } else {
  521. DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
  522. "overflowed! AEN LOST!!\n",
  523. ha->host_no, __func__,
  524. mbox_sts[0]));
  525. DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
  526. ha->host_no));
  527. for (i = 0; i < MAX_AEN_ENTRIES; i++) {
  528. DEBUG2(printk("AEN[%d] %04x %04x %04x "
  529. "%04x\n", i, mbox_sts[0],
  530. mbox_sts[1], mbox_sts[2],
  531. mbox_sts[3]));
  532. }
  533. }
  534. break;
  535. case MBOX_ASTS_TXSCVR_INSERTED:
  536. DEBUG2(printk(KERN_WARNING
  537. "scsi%ld: AEN %04x Transceiver"
  538. " inserted\n", ha->host_no, mbox_sts[0]));
  539. break;
  540. case MBOX_ASTS_TXSCVR_REMOVED:
  541. DEBUG2(printk(KERN_WARNING
  542. "scsi%ld: AEN %04x Transceiver"
  543. " removed\n", ha->host_no, mbox_sts[0]));
  544. break;
  545. default:
  546. DEBUG2(printk(KERN_WARNING
  547. "scsi%ld: AEN %04x UNKNOWN\n",
  548. ha->host_no, mbox_sts[0]));
  549. break;
  550. }
  551. } else {
  552. DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
  553. ha->host_no, mbox_status));
  554. ha->mbox_status[0] = mbox_status;
  555. }
  556. }
  557. /**
  558. * qla4_8xxx_interrupt_service_routine - isr
  559. * @ha: pointer to host adapter structure.
  560. *
  561. * This is the main interrupt service routine.
  562. * hardware_lock locked upon entry. runs in interrupt context.
  563. **/
  564. void qla4_8xxx_interrupt_service_routine(struct scsi_qla_host *ha,
  565. uint32_t intr_status)
  566. {
  567. /* Process response queue interrupt. */
  568. if (intr_status & HSRX_RISC_IOCB_INT)
  569. qla4xxx_process_response_queue(ha);
  570. /* Process mailbox/asynch event interrupt.*/
  571. if (intr_status & HSRX_RISC_MB_INT)
  572. qla4xxx_isr_decode_mailbox(ha,
  573. readl(&ha->qla4_8xxx_reg->mailbox_out[0]));
  574. /* clear the interrupt */
  575. writel(0, &ha->qla4_8xxx_reg->host_int);
  576. readl(&ha->qla4_8xxx_reg->host_int);
  577. }
  578. /**
  579. * qla4xxx_interrupt_service_routine - isr
  580. * @ha: pointer to host adapter structure.
  581. *
  582. * This is the main interrupt service routine.
  583. * hardware_lock locked upon entry. runs in interrupt context.
  584. **/
  585. void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
  586. uint32_t intr_status)
  587. {
  588. /* Process response queue interrupt. */
  589. if (intr_status & CSR_SCSI_COMPLETION_INTR)
  590. qla4xxx_process_response_queue(ha);
  591. /* Process mailbox/asynch event interrupt.*/
  592. if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
  593. qla4xxx_isr_decode_mailbox(ha,
  594. readl(&ha->reg->mailbox[0]));
  595. /* Clear Mailbox Interrupt */
  596. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  597. &ha->reg->ctrl_status);
  598. readl(&ha->reg->ctrl_status);
  599. }
  600. }
  601. /**
  602. * qla4_8xxx_spurious_interrupt - processes spurious interrupt
  603. * @ha: pointer to host adapter structure.
  604. * @reqs_count: .
  605. *
  606. **/
  607. static void qla4_8xxx_spurious_interrupt(struct scsi_qla_host *ha,
  608. uint8_t reqs_count)
  609. {
  610. if (reqs_count)
  611. return;
  612. DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
  613. if (is_qla8022(ha)) {
  614. writel(0, &ha->qla4_8xxx_reg->host_int);
  615. if (test_bit(AF_INTx_ENABLED, &ha->flags))
  616. qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
  617. 0xfbff);
  618. }
  619. ha->spurious_int_count++;
  620. }
  621. /**
  622. * qla4xxx_intr_handler - hardware interrupt handler.
  623. * @irq: Unused
  624. * @dev_id: Pointer to host adapter structure
  625. **/
  626. irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
  627. {
  628. struct scsi_qla_host *ha;
  629. uint32_t intr_status;
  630. unsigned long flags = 0;
  631. uint8_t reqs_count = 0;
  632. ha = (struct scsi_qla_host *) dev_id;
  633. if (!ha) {
  634. DEBUG2(printk(KERN_INFO
  635. "qla4xxx: Interrupt with NULL host ptr\n"));
  636. return IRQ_NONE;
  637. }
  638. spin_lock_irqsave(&ha->hardware_lock, flags);
  639. ha->isr_count++;
  640. /*
  641. * Repeatedly service interrupts up to a maximum of
  642. * MAX_REQS_SERVICED_PER_INTR
  643. */
  644. while (1) {
  645. /*
  646. * Read interrupt status
  647. */
  648. if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
  649. ha->response_out)
  650. intr_status = CSR_SCSI_COMPLETION_INTR;
  651. else
  652. intr_status = readl(&ha->reg->ctrl_status);
  653. if ((intr_status &
  654. (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
  655. if (reqs_count == 0)
  656. ha->spurious_int_count++;
  657. break;
  658. }
  659. if (intr_status & CSR_FATAL_ERROR) {
  660. DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
  661. "Status 0x%04x\n", ha->host_no,
  662. readl(isp_port_error_status (ha))));
  663. /* Issue Soft Reset to clear this error condition.
  664. * This will prevent the RISC from repeatedly
  665. * interrupting the driver; thus, allowing the DPC to
  666. * get scheduled to continue error recovery.
  667. * NOTE: Disabling RISC interrupts does not work in
  668. * this case, as CSR_FATAL_ERROR overrides
  669. * CSR_SCSI_INTR_ENABLE */
  670. if ((readl(&ha->reg->ctrl_status) &
  671. CSR_SCSI_RESET_INTR) == 0) {
  672. writel(set_rmask(CSR_SOFT_RESET),
  673. &ha->reg->ctrl_status);
  674. readl(&ha->reg->ctrl_status);
  675. }
  676. writel(set_rmask(CSR_FATAL_ERROR),
  677. &ha->reg->ctrl_status);
  678. readl(&ha->reg->ctrl_status);
  679. __qla4xxx_disable_intrs(ha);
  680. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  681. break;
  682. } else if (intr_status & CSR_SCSI_RESET_INTR) {
  683. clear_bit(AF_ONLINE, &ha->flags);
  684. __qla4xxx_disable_intrs(ha);
  685. writel(set_rmask(CSR_SCSI_RESET_INTR),
  686. &ha->reg->ctrl_status);
  687. readl(&ha->reg->ctrl_status);
  688. if (!test_bit(AF_HBA_GOING_AWAY, &ha->flags))
  689. set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  690. break;
  691. } else if (intr_status & INTR_PENDING) {
  692. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  693. ha->total_io_count++;
  694. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  695. break;
  696. }
  697. }
  698. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  699. return IRQ_HANDLED;
  700. }
  701. /**
  702. * qla4_8xxx_intr_handler - hardware interrupt handler.
  703. * @irq: Unused
  704. * @dev_id: Pointer to host adapter structure
  705. **/
  706. irqreturn_t qla4_8xxx_intr_handler(int irq, void *dev_id)
  707. {
  708. struct scsi_qla_host *ha = dev_id;
  709. uint32_t intr_status;
  710. uint32_t status;
  711. unsigned long flags = 0;
  712. uint8_t reqs_count = 0;
  713. if (unlikely(pci_channel_offline(ha->pdev)))
  714. return IRQ_HANDLED;
  715. ha->isr_count++;
  716. status = qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  717. if (!(status & ha->nx_legacy_intr.int_vec_bit))
  718. return IRQ_NONE;
  719. status = qla4_8xxx_rd_32(ha, ISR_INT_STATE_REG);
  720. if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
  721. DEBUG2(ql4_printk(KERN_INFO, ha,
  722. "%s legacy Int not triggered\n", __func__));
  723. return IRQ_NONE;
  724. }
  725. /* clear the interrupt */
  726. qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  727. /* read twice to ensure write is flushed */
  728. qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  729. qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  730. spin_lock_irqsave(&ha->hardware_lock, flags);
  731. while (1) {
  732. if (!(readl(&ha->qla4_8xxx_reg->host_int) &
  733. ISRX_82XX_RISC_INT)) {
  734. qla4_8xxx_spurious_interrupt(ha, reqs_count);
  735. break;
  736. }
  737. intr_status = readl(&ha->qla4_8xxx_reg->host_status);
  738. if ((intr_status &
  739. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  740. qla4_8xxx_spurious_interrupt(ha, reqs_count);
  741. break;
  742. }
  743. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  744. /* Enable Interrupt */
  745. qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
  746. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  747. break;
  748. }
  749. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  750. return IRQ_HANDLED;
  751. }
  752. irqreturn_t
  753. qla4_8xxx_msi_handler(int irq, void *dev_id)
  754. {
  755. struct scsi_qla_host *ha;
  756. ha = (struct scsi_qla_host *) dev_id;
  757. if (!ha) {
  758. DEBUG2(printk(KERN_INFO
  759. "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
  760. return IRQ_NONE;
  761. }
  762. ha->isr_count++;
  763. /* clear the interrupt */
  764. qla4_8xxx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
  765. /* read twice to ensure write is flushed */
  766. qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  767. qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
  768. return qla4_8xxx_default_intr_handler(irq, dev_id);
  769. }
  770. /**
  771. * qla4_8xxx_default_intr_handler - hardware interrupt handler.
  772. * @irq: Unused
  773. * @dev_id: Pointer to host adapter structure
  774. *
  775. * This interrupt handler is called directly for MSI-X, and
  776. * called indirectly for MSI.
  777. **/
  778. irqreturn_t
  779. qla4_8xxx_default_intr_handler(int irq, void *dev_id)
  780. {
  781. struct scsi_qla_host *ha = dev_id;
  782. unsigned long flags;
  783. uint32_t intr_status;
  784. uint8_t reqs_count = 0;
  785. spin_lock_irqsave(&ha->hardware_lock, flags);
  786. while (1) {
  787. if (!(readl(&ha->qla4_8xxx_reg->host_int) &
  788. ISRX_82XX_RISC_INT)) {
  789. qla4_8xxx_spurious_interrupt(ha, reqs_count);
  790. break;
  791. }
  792. intr_status = readl(&ha->qla4_8xxx_reg->host_status);
  793. if ((intr_status &
  794. (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
  795. qla4_8xxx_spurious_interrupt(ha, reqs_count);
  796. break;
  797. }
  798. ha->isp_ops->interrupt_service_routine(ha, intr_status);
  799. if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
  800. break;
  801. }
  802. ha->isr_count++;
  803. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  804. return IRQ_HANDLED;
  805. }
  806. irqreturn_t
  807. qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
  808. {
  809. struct scsi_qla_host *ha = dev_id;
  810. unsigned long flags;
  811. spin_lock_irqsave(&ha->hardware_lock, flags);
  812. qla4xxx_process_response_queue(ha);
  813. writel(0, &ha->qla4_8xxx_reg->host_int);
  814. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  815. ha->isr_count++;
  816. return IRQ_HANDLED;
  817. }
  818. /**
  819. * qla4xxx_process_aen - processes AENs generated by firmware
  820. * @ha: pointer to host adapter structure.
  821. * @process_aen: type of AENs to process
  822. *
  823. * Processes specific types of Asynchronous Events generated by firmware.
  824. * The type of AENs to process is specified by process_aen and can be
  825. * PROCESS_ALL_AENS 0
  826. * FLUSH_DDB_CHANGED_AENS 1
  827. * RELOGIN_DDB_CHANGED_AENS 2
  828. **/
  829. void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
  830. {
  831. uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
  832. struct aen *aen;
  833. int i;
  834. unsigned long flags;
  835. spin_lock_irqsave(&ha->hardware_lock, flags);
  836. while (ha->aen_out != ha->aen_in) {
  837. aen = &ha->aen_q[ha->aen_out];
  838. /* copy aen information to local structure */
  839. for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
  840. mbox_sts[i] = aen->mbox_sts[i];
  841. ha->aen_q_count++;
  842. ha->aen_out++;
  843. if (ha->aen_out == MAX_AEN_ENTRIES)
  844. ha->aen_out = 0;
  845. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  846. DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
  847. " mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
  848. (ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
  849. mbox_sts[0], mbox_sts[1], mbox_sts[2],
  850. mbox_sts[3], mbox_sts[4]));
  851. switch (mbox_sts[0]) {
  852. case MBOX_ASTS_DATABASE_CHANGED:
  853. if (process_aen == FLUSH_DDB_CHANGED_AENS) {
  854. DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
  855. "[%d] state=%04x FLUSHED!\n",
  856. ha->host_no, ha->aen_out,
  857. mbox_sts[0], mbox_sts[2],
  858. mbox_sts[3]));
  859. break;
  860. } else if (process_aen == RELOGIN_DDB_CHANGED_AENS) {
  861. /* for use during init time, we only want to
  862. * relogin non-active ddbs */
  863. struct ddb_entry *ddb_entry;
  864. ddb_entry =
  865. /* FIXME: name length? */
  866. qla4xxx_lookup_ddb_by_fw_index(ha,
  867. mbox_sts[2]);
  868. if (!ddb_entry)
  869. break;
  870. ddb_entry->dev_scan_wait_to_complete_relogin =
  871. 0;
  872. ddb_entry->dev_scan_wait_to_start_relogin =
  873. jiffies +
  874. ((ddb_entry->default_time2wait +
  875. 4) * HZ);
  876. DEBUG2(printk("scsi%ld: ddb [%d] initiate"
  877. " RELOGIN after %d seconds\n",
  878. ha->host_no,
  879. ddb_entry->fw_ddb_index,
  880. ddb_entry->default_time2wait +
  881. 4));
  882. break;
  883. }
  884. if (mbox_sts[1] == 0) { /* Global DB change. */
  885. qla4xxx_reinitialize_ddb_list(ha);
  886. } else if (mbox_sts[1] == 1) { /* Specific device. */
  887. qla4xxx_process_ddb_changed(ha, mbox_sts[2],
  888. mbox_sts[3], mbox_sts[4]);
  889. }
  890. break;
  891. }
  892. spin_lock_irqsave(&ha->hardware_lock, flags);
  893. }
  894. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  895. }
  896. int qla4xxx_request_irqs(struct scsi_qla_host *ha)
  897. {
  898. int ret;
  899. if (!is_qla8022(ha))
  900. goto try_intx;
  901. if (ql4xenablemsix == 2)
  902. goto try_msi;
  903. if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
  904. goto try_intx;
  905. /* Trying MSI-X */
  906. ret = qla4_8xxx_enable_msix(ha);
  907. if (!ret) {
  908. DEBUG2(ql4_printk(KERN_INFO, ha,
  909. "MSI-X: Enabled (0x%X).\n", ha->revision_id));
  910. goto irq_attached;
  911. }
  912. ql4_printk(KERN_WARNING, ha,
  913. "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
  914. try_msi:
  915. /* Trying MSI */
  916. ret = pci_enable_msi(ha->pdev);
  917. if (!ret) {
  918. ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
  919. 0, DRIVER_NAME, ha);
  920. if (!ret) {
  921. DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
  922. set_bit(AF_MSI_ENABLED, &ha->flags);
  923. goto irq_attached;
  924. } else {
  925. ql4_printk(KERN_WARNING, ha,
  926. "MSI: Failed to reserve interrupt %d "
  927. "already in use.\n", ha->pdev->irq);
  928. pci_disable_msi(ha->pdev);
  929. }
  930. }
  931. ql4_printk(KERN_WARNING, ha,
  932. "MSI: Falling back-to INTx mode -- %d.\n", ret);
  933. try_intx:
  934. /* Trying INTx */
  935. ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
  936. IRQF_SHARED, DRIVER_NAME, ha);
  937. if (!ret) {
  938. DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
  939. set_bit(AF_INTx_ENABLED, &ha->flags);
  940. goto irq_attached;
  941. } else {
  942. ql4_printk(KERN_WARNING, ha,
  943. "INTx: Failed to reserve interrupt %d already in"
  944. " use.\n", ha->pdev->irq);
  945. return ret;
  946. }
  947. irq_attached:
  948. set_bit(AF_IRQ_ATTACHED, &ha->flags);
  949. ha->host->irq = ha->pdev->irq;
  950. ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
  951. __func__, ha->pdev->irq);
  952. return ret;
  953. }
  954. void qla4xxx_free_irqs(struct scsi_qla_host *ha)
  955. {
  956. if (test_bit(AF_MSIX_ENABLED, &ha->flags))
  957. qla4_8xxx_disable_msix(ha);
  958. else if (test_and_clear_bit(AF_MSI_ENABLED, &ha->flags)) {
  959. free_irq(ha->pdev->irq, ha);
  960. pci_disable_msi(ha->pdev);
  961. } else if (test_and_clear_bit(AF_INTx_ENABLED, &ha->flags))
  962. free_irq(ha->pdev->irq, ha);
  963. }