ql4_isr.c 30 KB

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