ql4_isr.c 30 KB

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