ql4_isr.c 30 KB

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