xref: /OK3568_Linux_fs/kernel/drivers/scsi/qla4xxx/ql4_isr.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * QLogic iSCSI HBA Driver
4*4882a593Smuzhiyun  * Copyright (c)  2003-2013 QLogic Corporation
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include "ql4_def.h"
8*4882a593Smuzhiyun #include "ql4_glbl.h"
9*4882a593Smuzhiyun #include "ql4_dbg.h"
10*4882a593Smuzhiyun #include "ql4_inline.h"
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /**
13*4882a593Smuzhiyun  * qla4xxx_copy_sense - copy sense data	into cmd sense buffer
14*4882a593Smuzhiyun  * @ha: Pointer to host adapter structure.
15*4882a593Smuzhiyun  * @sts_entry: Pointer to status entry structure.
16*4882a593Smuzhiyun  * @srb: Pointer to srb structure.
17*4882a593Smuzhiyun  **/
qla4xxx_copy_sense(struct scsi_qla_host * ha,struct status_entry * sts_entry,struct srb * srb)18*4882a593Smuzhiyun static void qla4xxx_copy_sense(struct scsi_qla_host *ha,
19*4882a593Smuzhiyun                                struct status_entry *sts_entry,
20*4882a593Smuzhiyun                                struct srb *srb)
21*4882a593Smuzhiyun {
22*4882a593Smuzhiyun 	struct scsi_cmnd *cmd = srb->cmd;
23*4882a593Smuzhiyun 	uint16_t sense_len;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun 	memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
26*4882a593Smuzhiyun 	sense_len = le16_to_cpu(sts_entry->senseDataByteCnt);
27*4882a593Smuzhiyun 	if (sense_len == 0) {
28*4882a593Smuzhiyun 		DEBUG2(ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%d:%llu: %s:"
29*4882a593Smuzhiyun 				  " sense len 0\n", ha->host_no,
30*4882a593Smuzhiyun 				  cmd->device->channel, cmd->device->id,
31*4882a593Smuzhiyun 				  cmd->device->lun, __func__));
32*4882a593Smuzhiyun 		ha->status_srb = NULL;
33*4882a593Smuzhiyun 		return;
34*4882a593Smuzhiyun 	}
35*4882a593Smuzhiyun 	/* Save total available sense length,
36*4882a593Smuzhiyun 	 * not to exceed cmd's sense buffer size */
37*4882a593Smuzhiyun 	sense_len = min_t(uint16_t, sense_len, SCSI_SENSE_BUFFERSIZE);
38*4882a593Smuzhiyun 	srb->req_sense_ptr = cmd->sense_buffer;
39*4882a593Smuzhiyun 	srb->req_sense_len = sense_len;
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	/* Copy sense from sts_entry pkt */
42*4882a593Smuzhiyun 	sense_len = min_t(uint16_t, sense_len, IOCB_MAX_SENSEDATA_LEN);
43*4882a593Smuzhiyun 	memcpy(cmd->sense_buffer, sts_entry->senseData, sense_len);
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%llu: %s: sense key = %x, "
46*4882a593Smuzhiyun 		"ASL= %02x, ASC/ASCQ = %02x/%02x\n", ha->host_no,
47*4882a593Smuzhiyun 		cmd->device->channel, cmd->device->id,
48*4882a593Smuzhiyun 		cmd->device->lun, __func__,
49*4882a593Smuzhiyun 		sts_entry->senseData[2] & 0x0f,
50*4882a593Smuzhiyun 		sts_entry->senseData[7],
51*4882a593Smuzhiyun 		sts_entry->senseData[12],
52*4882a593Smuzhiyun 		sts_entry->senseData[13]));
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	DEBUG5(qla4xxx_dump_buffer(cmd->sense_buffer, sense_len));
55*4882a593Smuzhiyun 	srb->flags |= SRB_GOT_SENSE;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	/* Update srb, in case a sts_cont pkt follows */
58*4882a593Smuzhiyun 	srb->req_sense_ptr += sense_len;
59*4882a593Smuzhiyun 	srb->req_sense_len -= sense_len;
60*4882a593Smuzhiyun 	if (srb->req_sense_len != 0)
61*4882a593Smuzhiyun 		ha->status_srb = srb;
62*4882a593Smuzhiyun 	else
63*4882a593Smuzhiyun 		ha->status_srb = NULL;
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /**
67*4882a593Smuzhiyun  * qla4xxx_status_cont_entry - Process a Status Continuations entry.
68*4882a593Smuzhiyun  * @ha: SCSI driver HA context
69*4882a593Smuzhiyun  * @sts_cont: Entry pointer
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  * Extended sense data.
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun static void
qla4xxx_status_cont_entry(struct scsi_qla_host * ha,struct status_cont_entry * sts_cont)74*4882a593Smuzhiyun qla4xxx_status_cont_entry(struct scsi_qla_host *ha,
75*4882a593Smuzhiyun 			  struct status_cont_entry *sts_cont)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun 	struct srb *srb = ha->status_srb;
78*4882a593Smuzhiyun 	struct scsi_cmnd *cmd;
79*4882a593Smuzhiyun 	uint16_t sense_len;
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	if (srb == NULL)
82*4882a593Smuzhiyun 		return;
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	cmd = srb->cmd;
85*4882a593Smuzhiyun 	if (cmd == NULL) {
86*4882a593Smuzhiyun 		DEBUG2(printk(KERN_INFO "scsi%ld: %s: Cmd already returned "
87*4882a593Smuzhiyun 			"back to OS srb=%p srb->state:%d\n", ha->host_no,
88*4882a593Smuzhiyun 			__func__, srb, srb->state));
89*4882a593Smuzhiyun 		ha->status_srb = NULL;
90*4882a593Smuzhiyun 		return;
91*4882a593Smuzhiyun 	}
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	/* Copy sense data. */
94*4882a593Smuzhiyun 	sense_len = min_t(uint16_t, srb->req_sense_len,
95*4882a593Smuzhiyun 			  IOCB_MAX_EXT_SENSEDATA_LEN);
96*4882a593Smuzhiyun 	memcpy(srb->req_sense_ptr, sts_cont->ext_sense_data, sense_len);
97*4882a593Smuzhiyun 	DEBUG5(qla4xxx_dump_buffer(srb->req_sense_ptr, sense_len));
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun 	srb->req_sense_ptr += sense_len;
100*4882a593Smuzhiyun 	srb->req_sense_len -= sense_len;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	/* Place command on done queue. */
103*4882a593Smuzhiyun 	if (srb->req_sense_len == 0) {
104*4882a593Smuzhiyun 		kref_put(&srb->srb_ref, qla4xxx_srb_compl);
105*4882a593Smuzhiyun 		ha->status_srb = NULL;
106*4882a593Smuzhiyun 	}
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /**
110*4882a593Smuzhiyun  * qla4xxx_status_entry - processes status IOCBs
111*4882a593Smuzhiyun  * @ha: Pointer to host adapter structure.
112*4882a593Smuzhiyun  * @sts_entry: Pointer to status entry structure.
113*4882a593Smuzhiyun  **/
qla4xxx_status_entry(struct scsi_qla_host * ha,struct status_entry * sts_entry)114*4882a593Smuzhiyun static void qla4xxx_status_entry(struct scsi_qla_host *ha,
115*4882a593Smuzhiyun 				 struct status_entry *sts_entry)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun 	uint8_t scsi_status;
118*4882a593Smuzhiyun 	struct scsi_cmnd *cmd;
119*4882a593Smuzhiyun 	struct srb *srb;
120*4882a593Smuzhiyun 	struct ddb_entry *ddb_entry;
121*4882a593Smuzhiyun 	uint32_t residual;
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 	srb = qla4xxx_del_from_active_array(ha, le32_to_cpu(sts_entry->handle));
124*4882a593Smuzhiyun 	if (!srb) {
125*4882a593Smuzhiyun 		ql4_printk(KERN_WARNING, ha, "%s invalid status entry: "
126*4882a593Smuzhiyun 			   "handle=0x%0x, srb=%p\n", __func__,
127*4882a593Smuzhiyun 			   sts_entry->handle, srb);
128*4882a593Smuzhiyun 		if (is_qla80XX(ha))
129*4882a593Smuzhiyun 			set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
130*4882a593Smuzhiyun 		else
131*4882a593Smuzhiyun 			set_bit(DPC_RESET_HA, &ha->dpc_flags);
132*4882a593Smuzhiyun 		return;
133*4882a593Smuzhiyun 	}
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	cmd = srb->cmd;
136*4882a593Smuzhiyun 	if (cmd == NULL) {
137*4882a593Smuzhiyun 		DEBUG2(printk("scsi%ld: %s: Command already returned back to "
138*4882a593Smuzhiyun 			      "OS pkt->handle=%d srb=%p srb->state:%d\n",
139*4882a593Smuzhiyun 			      ha->host_no, __func__, sts_entry->handle,
140*4882a593Smuzhiyun 			      srb, srb->state));
141*4882a593Smuzhiyun 		ql4_printk(KERN_WARNING, ha, "Command is NULL:"
142*4882a593Smuzhiyun 		    " already returned to OS (srb=%p)\n", srb);
143*4882a593Smuzhiyun 		return;
144*4882a593Smuzhiyun 	}
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	ddb_entry = srb->ddb;
147*4882a593Smuzhiyun 	if (ddb_entry == NULL) {
148*4882a593Smuzhiyun 		cmd->result = DID_NO_CONNECT << 16;
149*4882a593Smuzhiyun 		goto status_entry_exit;
150*4882a593Smuzhiyun 	}
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	residual = le32_to_cpu(sts_entry->residualByteCnt);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	/* Translate ISP error to a Linux SCSI error. */
155*4882a593Smuzhiyun 	scsi_status = sts_entry->scsiStatus;
156*4882a593Smuzhiyun 	switch (sts_entry->completionStatus) {
157*4882a593Smuzhiyun 	case SCS_COMPLETE:
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 		if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) {
160*4882a593Smuzhiyun 			cmd->result = DID_ERROR << 16;
161*4882a593Smuzhiyun 			break;
162*4882a593Smuzhiyun 		}
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 		if (sts_entry->iscsiFlags &ISCSI_FLAG_RESIDUAL_UNDER) {
165*4882a593Smuzhiyun 			scsi_set_resid(cmd, residual);
166*4882a593Smuzhiyun 			if (!scsi_status && ((scsi_bufflen(cmd) - residual) <
167*4882a593Smuzhiyun 				cmd->underflow)) {
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun 				cmd->result = DID_ERROR << 16;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 				DEBUG2(printk("scsi%ld:%d:%d:%llu: %s: "
172*4882a593Smuzhiyun 					"Mid-layer Data underrun0, "
173*4882a593Smuzhiyun 					"xferlen = 0x%x, "
174*4882a593Smuzhiyun 					"residual = 0x%x\n", ha->host_no,
175*4882a593Smuzhiyun 					cmd->device->channel,
176*4882a593Smuzhiyun 					cmd->device->id,
177*4882a593Smuzhiyun 					cmd->device->lun, __func__,
178*4882a593Smuzhiyun 					scsi_bufflen(cmd), residual));
179*4882a593Smuzhiyun 				break;
180*4882a593Smuzhiyun 			}
181*4882a593Smuzhiyun 		}
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun 		cmd->result = DID_OK << 16 | scsi_status;
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun 		if (scsi_status != SCSI_CHECK_CONDITION)
186*4882a593Smuzhiyun 			break;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 		/* Copy Sense Data into sense buffer. */
189*4882a593Smuzhiyun 		qla4xxx_copy_sense(ha, sts_entry, srb);
190*4882a593Smuzhiyun 		break;
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	case SCS_INCOMPLETE:
193*4882a593Smuzhiyun 		/* Always set the status to DID_ERROR, since
194*4882a593Smuzhiyun 		 * all conditions result in that status anyway */
195*4882a593Smuzhiyun 		cmd->result = DID_ERROR << 16;
196*4882a593Smuzhiyun 		break;
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	case SCS_RESET_OCCURRED:
199*4882a593Smuzhiyun 		DEBUG2(printk("scsi%ld:%d:%d:%llu: %s: Device RESET occurred\n",
200*4882a593Smuzhiyun 			      ha->host_no, cmd->device->channel,
201*4882a593Smuzhiyun 			      cmd->device->id, cmd->device->lun, __func__));
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 		cmd->result = DID_RESET << 16;
204*4882a593Smuzhiyun 		break;
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 	case SCS_ABORTED:
207*4882a593Smuzhiyun 		DEBUG2(printk("scsi%ld:%d:%d:%llu: %s: Abort occurred\n",
208*4882a593Smuzhiyun 			      ha->host_no, cmd->device->channel,
209*4882a593Smuzhiyun 			      cmd->device->id, cmd->device->lun, __func__));
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun 		cmd->result = DID_RESET << 16;
212*4882a593Smuzhiyun 		break;
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun 	case SCS_TIMEOUT:
215*4882a593Smuzhiyun 		DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%llu: Timeout\n",
216*4882a593Smuzhiyun 			      ha->host_no, cmd->device->channel,
217*4882a593Smuzhiyun 			      cmd->device->id, cmd->device->lun));
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 		cmd->result = DID_TRANSPORT_DISRUPTED << 16;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 		/*
222*4882a593Smuzhiyun 		 * Mark device missing so that we won't continue to send
223*4882a593Smuzhiyun 		 * I/O to this device.	We should get a ddb state change
224*4882a593Smuzhiyun 		 * AEN soon.
225*4882a593Smuzhiyun 		 */
226*4882a593Smuzhiyun 		if (iscsi_is_session_online(ddb_entry->sess))
227*4882a593Smuzhiyun 			qla4xxx_mark_device_missing(ddb_entry->sess);
228*4882a593Smuzhiyun 		break;
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun 	case SCS_DATA_UNDERRUN:
231*4882a593Smuzhiyun 	case SCS_DATA_OVERRUN:
232*4882a593Smuzhiyun 		if ((sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_OVER) ||
233*4882a593Smuzhiyun 		     (sts_entry->completionStatus == SCS_DATA_OVERRUN)) {
234*4882a593Smuzhiyun 			DEBUG2(printk("scsi%ld:%d:%d:%llu: %s: " "Data overrun\n",
235*4882a593Smuzhiyun 				      ha->host_no,
236*4882a593Smuzhiyun 				      cmd->device->channel, cmd->device->id,
237*4882a593Smuzhiyun 				      cmd->device->lun, __func__));
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 			cmd->result = DID_ERROR << 16;
240*4882a593Smuzhiyun 			break;
241*4882a593Smuzhiyun 		}
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun 		scsi_set_resid(cmd, residual);
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun 		if (sts_entry->iscsiFlags & ISCSI_FLAG_RESIDUAL_UNDER) {
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun 			/* Both the firmware and target reported UNDERRUN:
248*4882a593Smuzhiyun 			 *
249*4882a593Smuzhiyun 			 * MID-LAYER UNDERFLOW case:
250*4882a593Smuzhiyun 			 * Some kernels do not properly detect midlayer
251*4882a593Smuzhiyun 			 * underflow, so we manually check it and return
252*4882a593Smuzhiyun 			 * ERROR if the minimum required data was not
253*4882a593Smuzhiyun 			 * received.
254*4882a593Smuzhiyun 			 *
255*4882a593Smuzhiyun 			 * ALL OTHER cases:
256*4882a593Smuzhiyun 			 * Fall thru to check scsi_status
257*4882a593Smuzhiyun 			 */
258*4882a593Smuzhiyun 			if (!scsi_status && (scsi_bufflen(cmd) - residual) <
259*4882a593Smuzhiyun 			    cmd->underflow) {
260*4882a593Smuzhiyun 				DEBUG2(ql4_printk(KERN_INFO, ha,
261*4882a593Smuzhiyun 						  "scsi%ld:%d:%d:%llu: %s: Mid-layer Data underrun, xferlen = 0x%x,residual = 0x%x\n",
262*4882a593Smuzhiyun 						   ha->host_no,
263*4882a593Smuzhiyun 						   cmd->device->channel,
264*4882a593Smuzhiyun 						   cmd->device->id,
265*4882a593Smuzhiyun 						   cmd->device->lun, __func__,
266*4882a593Smuzhiyun 						   scsi_bufflen(cmd),
267*4882a593Smuzhiyun 						   residual));
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 				cmd->result = DID_ERROR << 16;
270*4882a593Smuzhiyun 				break;
271*4882a593Smuzhiyun 			}
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun 		} else if (scsi_status != SAM_STAT_TASK_SET_FULL &&
274*4882a593Smuzhiyun 			   scsi_status != SAM_STAT_BUSY) {
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun 			/*
277*4882a593Smuzhiyun 			 * The firmware reports UNDERRUN, but the target does
278*4882a593Smuzhiyun 			 * not report it:
279*4882a593Smuzhiyun 			 *
280*4882a593Smuzhiyun 			 *   scsi_status     |    host_byte       device_byte
281*4882a593Smuzhiyun 			 *                   |     (19:16)          (7:0)
282*4882a593Smuzhiyun 			 *   =============   |    =========       ===========
283*4882a593Smuzhiyun 			 *   TASK_SET_FULL   |    DID_OK          scsi_status
284*4882a593Smuzhiyun 			 *   BUSY            |    DID_OK          scsi_status
285*4882a593Smuzhiyun 			 *   ALL OTHERS      |    DID_ERROR       scsi_status
286*4882a593Smuzhiyun 			 *
287*4882a593Smuzhiyun 			 *   Note: If scsi_status is task set full or busy,
288*4882a593Smuzhiyun 			 *   then this else if would fall thru to check the
289*4882a593Smuzhiyun 			 *   scsi_status and return DID_OK.
290*4882a593Smuzhiyun 			 */
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
293*4882a593Smuzhiyun 					  "scsi%ld:%d:%d:%llu: %s: Dropped frame(s) detected (0x%x of 0x%x bytes).\n",
294*4882a593Smuzhiyun 					  ha->host_no,
295*4882a593Smuzhiyun 					  cmd->device->channel,
296*4882a593Smuzhiyun 					  cmd->device->id,
297*4882a593Smuzhiyun 					  cmd->device->lun, __func__,
298*4882a593Smuzhiyun 					  residual,
299*4882a593Smuzhiyun 					  scsi_bufflen(cmd)));
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun 			cmd->result = DID_ERROR << 16 | scsi_status;
302*4882a593Smuzhiyun 			goto check_scsi_status;
303*4882a593Smuzhiyun 		}
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 		cmd->result = DID_OK << 16 | scsi_status;
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun check_scsi_status:
308*4882a593Smuzhiyun 		if (scsi_status == SAM_STAT_CHECK_CONDITION)
309*4882a593Smuzhiyun 			qla4xxx_copy_sense(ha, sts_entry, srb);
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 		break;
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun 	case SCS_DEVICE_LOGGED_OUT:
314*4882a593Smuzhiyun 	case SCS_DEVICE_UNAVAILABLE:
315*4882a593Smuzhiyun 		DEBUG2(printk(KERN_INFO "scsi%ld:%d:%d:%llu: SCS_DEVICE "
316*4882a593Smuzhiyun 		    "state: 0x%x\n", ha->host_no,
317*4882a593Smuzhiyun 		    cmd->device->channel, cmd->device->id,
318*4882a593Smuzhiyun 		    cmd->device->lun, sts_entry->completionStatus));
319*4882a593Smuzhiyun 		/*
320*4882a593Smuzhiyun 		 * Mark device missing so that we won't continue to
321*4882a593Smuzhiyun 		 * send I/O to this device.  We should get a ddb
322*4882a593Smuzhiyun 		 * state change AEN soon.
323*4882a593Smuzhiyun 		 */
324*4882a593Smuzhiyun 		if (iscsi_is_session_online(ddb_entry->sess))
325*4882a593Smuzhiyun 			qla4xxx_mark_device_missing(ddb_entry->sess);
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 		cmd->result = DID_TRANSPORT_DISRUPTED << 16;
328*4882a593Smuzhiyun 		break;
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun 	case SCS_QUEUE_FULL:
331*4882a593Smuzhiyun 		/*
332*4882a593Smuzhiyun 		 * SCSI Mid-Layer handles device queue full
333*4882a593Smuzhiyun 		 */
334*4882a593Smuzhiyun 		cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
335*4882a593Smuzhiyun 		DEBUG2(printk("scsi%ld:%d:%llu: %s: QUEUE FULL detected "
336*4882a593Smuzhiyun 			      "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
337*4882a593Smuzhiyun 			      " iResp=%02x\n", ha->host_no, cmd->device->id,
338*4882a593Smuzhiyun 			      cmd->device->lun, __func__,
339*4882a593Smuzhiyun 			      sts_entry->completionStatus,
340*4882a593Smuzhiyun 			      sts_entry->scsiStatus, sts_entry->state_flags,
341*4882a593Smuzhiyun 			      sts_entry->iscsiFlags,
342*4882a593Smuzhiyun 			      sts_entry->iscsiResponse));
343*4882a593Smuzhiyun 		break;
344*4882a593Smuzhiyun 
345*4882a593Smuzhiyun 	default:
346*4882a593Smuzhiyun 		cmd->result = DID_ERROR << 16;
347*4882a593Smuzhiyun 		break;
348*4882a593Smuzhiyun 	}
349*4882a593Smuzhiyun 
350*4882a593Smuzhiyun status_entry_exit:
351*4882a593Smuzhiyun 
352*4882a593Smuzhiyun 	/* complete the request, if not waiting for status_continuation pkt */
353*4882a593Smuzhiyun 	srb->cc_stat = sts_entry->completionStatus;
354*4882a593Smuzhiyun 	if (ha->status_srb == NULL)
355*4882a593Smuzhiyun 		kref_put(&srb->srb_ref, qla4xxx_srb_compl);
356*4882a593Smuzhiyun }
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun /**
359*4882a593Smuzhiyun  * qla4xxx_passthru_status_entry - processes passthru status IOCBs (0x3C)
360*4882a593Smuzhiyun  * @ha: Pointer to host adapter structure.
361*4882a593Smuzhiyun  * @sts_entry: Pointer to status entry structure.
362*4882a593Smuzhiyun  **/
qla4xxx_passthru_status_entry(struct scsi_qla_host * ha,struct passthru_status * sts_entry)363*4882a593Smuzhiyun static void qla4xxx_passthru_status_entry(struct scsi_qla_host *ha,
364*4882a593Smuzhiyun 					  struct passthru_status *sts_entry)
365*4882a593Smuzhiyun {
366*4882a593Smuzhiyun 	struct iscsi_task *task;
367*4882a593Smuzhiyun 	struct ddb_entry *ddb_entry;
368*4882a593Smuzhiyun 	struct ql4_task_data *task_data;
369*4882a593Smuzhiyun 	struct iscsi_cls_conn *cls_conn;
370*4882a593Smuzhiyun 	struct iscsi_conn *conn;
371*4882a593Smuzhiyun 	itt_t itt;
372*4882a593Smuzhiyun 	uint32_t fw_ddb_index;
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun 	itt = sts_entry->handle;
375*4882a593Smuzhiyun 	fw_ddb_index = le32_to_cpu(sts_entry->target);
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun 	ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, fw_ddb_index);
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun 	if (ddb_entry == NULL) {
380*4882a593Smuzhiyun 		ql4_printk(KERN_ERR, ha, "%s: Invalid target index = 0x%x\n",
381*4882a593Smuzhiyun 			   __func__, sts_entry->target);
382*4882a593Smuzhiyun 		return;
383*4882a593Smuzhiyun 	}
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun 	cls_conn = ddb_entry->conn;
386*4882a593Smuzhiyun 	conn = cls_conn->dd_data;
387*4882a593Smuzhiyun 	spin_lock(&conn->session->back_lock);
388*4882a593Smuzhiyun 	task = iscsi_itt_to_task(conn, itt);
389*4882a593Smuzhiyun 	spin_unlock(&conn->session->back_lock);
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun 	if (task == NULL) {
392*4882a593Smuzhiyun 		ql4_printk(KERN_ERR, ha, "%s: Task is NULL\n", __func__);
393*4882a593Smuzhiyun 		return;
394*4882a593Smuzhiyun 	}
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun 	task_data = task->dd_data;
397*4882a593Smuzhiyun 	memcpy(&task_data->sts, sts_entry, sizeof(struct passthru_status));
398*4882a593Smuzhiyun 	ha->iocb_cnt -= task_data->iocb_req_cnt;
399*4882a593Smuzhiyun 	queue_work(ha->task_wq, &task_data->task_work);
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun 
qla4xxx_del_mrb_from_active_array(struct scsi_qla_host * ha,uint32_t index)402*4882a593Smuzhiyun static struct mrb *qla4xxx_del_mrb_from_active_array(struct scsi_qla_host *ha,
403*4882a593Smuzhiyun 						     uint32_t index)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun 	struct mrb *mrb = NULL;
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun 	/* validate handle and remove from active array */
408*4882a593Smuzhiyun 	if (index >= MAX_MRB)
409*4882a593Smuzhiyun 		return mrb;
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun 	mrb = ha->active_mrb_array[index];
412*4882a593Smuzhiyun 	ha->active_mrb_array[index] = NULL;
413*4882a593Smuzhiyun 	if (!mrb)
414*4882a593Smuzhiyun 		return mrb;
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun 	/* update counters */
417*4882a593Smuzhiyun 	ha->iocb_cnt -= mrb->iocb_cnt;
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun 	return mrb;
420*4882a593Smuzhiyun }
421*4882a593Smuzhiyun 
qla4xxx_mbox_status_entry(struct scsi_qla_host * ha,struct mbox_status_iocb * mbox_sts_entry)422*4882a593Smuzhiyun static void qla4xxx_mbox_status_entry(struct scsi_qla_host *ha,
423*4882a593Smuzhiyun 				      struct mbox_status_iocb *mbox_sts_entry)
424*4882a593Smuzhiyun {
425*4882a593Smuzhiyun 	struct mrb *mrb;
426*4882a593Smuzhiyun 	uint32_t status;
427*4882a593Smuzhiyun 	uint32_t data_size;
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	mrb = qla4xxx_del_mrb_from_active_array(ha,
430*4882a593Smuzhiyun 					le32_to_cpu(mbox_sts_entry->handle));
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun 	if (mrb == NULL) {
433*4882a593Smuzhiyun 		ql4_printk(KERN_WARNING, ha, "%s: mrb[%d] is null\n", __func__,
434*4882a593Smuzhiyun 			   mbox_sts_entry->handle);
435*4882a593Smuzhiyun 		return;
436*4882a593Smuzhiyun 	}
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun 	switch (mrb->mbox_cmd) {
439*4882a593Smuzhiyun 	case MBOX_CMD_PING:
440*4882a593Smuzhiyun 		DEBUG2(ql4_printk(KERN_INFO, ha, "%s: mbox_cmd = 0x%x, "
441*4882a593Smuzhiyun 				  "mbox_sts[0] = 0x%x, mbox_sts[6] = 0x%x\n",
442*4882a593Smuzhiyun 				  __func__, mrb->mbox_cmd,
443*4882a593Smuzhiyun 				  mbox_sts_entry->out_mbox[0],
444*4882a593Smuzhiyun 				  mbox_sts_entry->out_mbox[6]));
445*4882a593Smuzhiyun 
446*4882a593Smuzhiyun 		if (mbox_sts_entry->out_mbox[0] == MBOX_STS_COMMAND_COMPLETE)
447*4882a593Smuzhiyun 			status = ISCSI_PING_SUCCESS;
448*4882a593Smuzhiyun 		else
449*4882a593Smuzhiyun 			status = mbox_sts_entry->out_mbox[6];
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun 		data_size = sizeof(mbox_sts_entry->out_mbox);
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun 		qla4xxx_post_ping_evt_work(ha, status, mrb->pid, data_size,
454*4882a593Smuzhiyun 					(uint8_t *) mbox_sts_entry->out_mbox);
455*4882a593Smuzhiyun 		break;
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	default:
458*4882a593Smuzhiyun 		DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: invalid mbox_cmd = "
459*4882a593Smuzhiyun 				  "0x%x\n", __func__, mrb->mbox_cmd));
460*4882a593Smuzhiyun 	}
461*4882a593Smuzhiyun 
462*4882a593Smuzhiyun 	kfree(mrb);
463*4882a593Smuzhiyun 	return;
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun /**
467*4882a593Smuzhiyun  * qla4xxx_process_response_queue - process response queue completions
468*4882a593Smuzhiyun  * @ha: Pointer to host adapter structure.
469*4882a593Smuzhiyun  *
470*4882a593Smuzhiyun  * This routine process response queue completions in interrupt context.
471*4882a593Smuzhiyun  * Hardware_lock locked upon entry
472*4882a593Smuzhiyun  **/
qla4xxx_process_response_queue(struct scsi_qla_host * ha)473*4882a593Smuzhiyun void qla4xxx_process_response_queue(struct scsi_qla_host *ha)
474*4882a593Smuzhiyun {
475*4882a593Smuzhiyun 	uint32_t count = 0;
476*4882a593Smuzhiyun 	struct srb *srb = NULL;
477*4882a593Smuzhiyun 	struct status_entry *sts_entry;
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun 	/* Process all responses from response queue */
480*4882a593Smuzhiyun 	while ((ha->response_ptr->signature != RESPONSE_PROCESSED)) {
481*4882a593Smuzhiyun 		sts_entry = (struct status_entry *) ha->response_ptr;
482*4882a593Smuzhiyun 		count++;
483*4882a593Smuzhiyun 
484*4882a593Smuzhiyun 		/* Advance pointers for next entry */
485*4882a593Smuzhiyun 		if (ha->response_out == (RESPONSE_QUEUE_DEPTH - 1)) {
486*4882a593Smuzhiyun 			ha->response_out = 0;
487*4882a593Smuzhiyun 			ha->response_ptr = ha->response_ring;
488*4882a593Smuzhiyun 		} else {
489*4882a593Smuzhiyun 			ha->response_out++;
490*4882a593Smuzhiyun 			ha->response_ptr++;
491*4882a593Smuzhiyun 		}
492*4882a593Smuzhiyun 
493*4882a593Smuzhiyun 		/* process entry */
494*4882a593Smuzhiyun 		switch (sts_entry->hdr.entryType) {
495*4882a593Smuzhiyun 		case ET_STATUS:
496*4882a593Smuzhiyun 			/* Common status */
497*4882a593Smuzhiyun 			qla4xxx_status_entry(ha, sts_entry);
498*4882a593Smuzhiyun 			break;
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun 		case ET_PASSTHRU_STATUS:
501*4882a593Smuzhiyun 			if (sts_entry->hdr.systemDefined == SD_ISCSI_PDU)
502*4882a593Smuzhiyun 				qla4xxx_passthru_status_entry(ha,
503*4882a593Smuzhiyun 					(struct passthru_status *)sts_entry);
504*4882a593Smuzhiyun 			else
505*4882a593Smuzhiyun 				ql4_printk(KERN_ERR, ha,
506*4882a593Smuzhiyun 					   "%s: Invalid status received\n",
507*4882a593Smuzhiyun 					   __func__);
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun 			break;
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun 		case ET_STATUS_CONTINUATION:
512*4882a593Smuzhiyun 			qla4xxx_status_cont_entry(ha,
513*4882a593Smuzhiyun 				(struct status_cont_entry *) sts_entry);
514*4882a593Smuzhiyun 			break;
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun 		case ET_COMMAND:
517*4882a593Smuzhiyun 			/* ISP device queue is full. Command not
518*4882a593Smuzhiyun 			 * accepted by ISP.  Queue command for
519*4882a593Smuzhiyun 			 * later */
520*4882a593Smuzhiyun 
521*4882a593Smuzhiyun 			srb = qla4xxx_del_from_active_array(ha,
522*4882a593Smuzhiyun 						    le32_to_cpu(sts_entry->
523*4882a593Smuzhiyun 								handle));
524*4882a593Smuzhiyun 			if (srb == NULL)
525*4882a593Smuzhiyun 				goto exit_prq_invalid_handle;
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun 			DEBUG2(printk("scsi%ld: %s: FW device queue full, "
528*4882a593Smuzhiyun 				      "srb %p\n", ha->host_no, __func__, srb));
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun 			/* ETRY normally by sending it back with
531*4882a593Smuzhiyun 			 * DID_BUS_BUSY */
532*4882a593Smuzhiyun 			srb->cmd->result = DID_BUS_BUSY << 16;
533*4882a593Smuzhiyun 			kref_put(&srb->srb_ref, qla4xxx_srb_compl);
534*4882a593Smuzhiyun 			break;
535*4882a593Smuzhiyun 
536*4882a593Smuzhiyun 		case ET_CONTINUE:
537*4882a593Smuzhiyun 			/* Just throw away the continuation entries */
538*4882a593Smuzhiyun 			DEBUG2(printk("scsi%ld: %s: Continuation entry - "
539*4882a593Smuzhiyun 				      "ignoring\n", ha->host_no, __func__));
540*4882a593Smuzhiyun 			break;
541*4882a593Smuzhiyun 
542*4882a593Smuzhiyun 		case ET_MBOX_STATUS:
543*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
544*4882a593Smuzhiyun 					  "%s: mbox status IOCB\n", __func__));
545*4882a593Smuzhiyun 			qla4xxx_mbox_status_entry(ha,
546*4882a593Smuzhiyun 					(struct mbox_status_iocb *)sts_entry);
547*4882a593Smuzhiyun 			break;
548*4882a593Smuzhiyun 
549*4882a593Smuzhiyun 		default:
550*4882a593Smuzhiyun 			/*
551*4882a593Smuzhiyun 			 * Invalid entry in response queue, reset RISC
552*4882a593Smuzhiyun 			 * firmware.
553*4882a593Smuzhiyun 			 */
554*4882a593Smuzhiyun 			DEBUG2(printk("scsi%ld: %s: Invalid entry %x in "
555*4882a593Smuzhiyun 				      "response queue \n", ha->host_no,
556*4882a593Smuzhiyun 				      __func__,
557*4882a593Smuzhiyun 				      sts_entry->hdr.entryType));
558*4882a593Smuzhiyun 			goto exit_prq_error;
559*4882a593Smuzhiyun 		}
560*4882a593Smuzhiyun 		((struct response *)sts_entry)->signature = RESPONSE_PROCESSED;
561*4882a593Smuzhiyun 		wmb();
562*4882a593Smuzhiyun 	}
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 	/*
565*4882a593Smuzhiyun 	 * Tell ISP we're done with response(s). This also clears the interrupt.
566*4882a593Smuzhiyun 	 */
567*4882a593Smuzhiyun 	ha->isp_ops->complete_iocb(ha);
568*4882a593Smuzhiyun 
569*4882a593Smuzhiyun 	return;
570*4882a593Smuzhiyun 
571*4882a593Smuzhiyun exit_prq_invalid_handle:
572*4882a593Smuzhiyun 	DEBUG2(printk("scsi%ld: %s: Invalid handle(srb)=%p type=%x IOCS=%x\n",
573*4882a593Smuzhiyun 		      ha->host_no, __func__, srb, sts_entry->hdr.entryType,
574*4882a593Smuzhiyun 		      sts_entry->completionStatus));
575*4882a593Smuzhiyun 
576*4882a593Smuzhiyun exit_prq_error:
577*4882a593Smuzhiyun 	ha->isp_ops->complete_iocb(ha);
578*4882a593Smuzhiyun 	set_bit(DPC_RESET_HA, &ha->dpc_flags);
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun /**
582*4882a593Smuzhiyun  * qla4_83xx_loopback_in_progress: Is loopback in progress?
583*4882a593Smuzhiyun  * @ha: Pointer to host adapter structure.
584*4882a593Smuzhiyun  * returns: 1 = loopback in progress, 0 = loopback not in progress
585*4882a593Smuzhiyun  **/
qla4_83xx_loopback_in_progress(struct scsi_qla_host * ha)586*4882a593Smuzhiyun static int qla4_83xx_loopback_in_progress(struct scsi_qla_host *ha)
587*4882a593Smuzhiyun {
588*4882a593Smuzhiyun 	int rval = 1;
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun 	if (is_qla8032(ha) || is_qla8042(ha)) {
591*4882a593Smuzhiyun 		if ((ha->idc_info.info2 & ENABLE_INTERNAL_LOOPBACK) ||
592*4882a593Smuzhiyun 		    (ha->idc_info.info2 & ENABLE_EXTERNAL_LOOPBACK)) {
593*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
594*4882a593Smuzhiyun 					  "%s: Loopback diagnostics in progress\n",
595*4882a593Smuzhiyun 					  __func__));
596*4882a593Smuzhiyun 			rval = 1;
597*4882a593Smuzhiyun 		} else {
598*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
599*4882a593Smuzhiyun 					  "%s: Loopback diagnostics not in progress\n",
600*4882a593Smuzhiyun 					  __func__));
601*4882a593Smuzhiyun 			rval = 0;
602*4882a593Smuzhiyun 		}
603*4882a593Smuzhiyun 	}
604*4882a593Smuzhiyun 
605*4882a593Smuzhiyun 	return rval;
606*4882a593Smuzhiyun }
607*4882a593Smuzhiyun 
qla4xxx_update_ipaddr_state(struct scsi_qla_host * ha,uint32_t ipaddr_idx,uint32_t ipaddr_fw_state)608*4882a593Smuzhiyun static void qla4xxx_update_ipaddr_state(struct scsi_qla_host *ha,
609*4882a593Smuzhiyun 					uint32_t ipaddr_idx,
610*4882a593Smuzhiyun 					uint32_t ipaddr_fw_state)
611*4882a593Smuzhiyun {
612*4882a593Smuzhiyun 	uint8_t ipaddr_state;
613*4882a593Smuzhiyun 	uint8_t ip_idx;
614*4882a593Smuzhiyun 
615*4882a593Smuzhiyun 	ip_idx = ipaddr_idx & 0xF;
616*4882a593Smuzhiyun 	ipaddr_state = qla4xxx_set_ipaddr_state((uint8_t)ipaddr_fw_state);
617*4882a593Smuzhiyun 
618*4882a593Smuzhiyun 	switch (ip_idx) {
619*4882a593Smuzhiyun 	case 0:
620*4882a593Smuzhiyun 		ha->ip_config.ipv4_addr_state = ipaddr_state;
621*4882a593Smuzhiyun 		break;
622*4882a593Smuzhiyun 	case 1:
623*4882a593Smuzhiyun 		ha->ip_config.ipv6_link_local_state = ipaddr_state;
624*4882a593Smuzhiyun 		break;
625*4882a593Smuzhiyun 	case 2:
626*4882a593Smuzhiyun 		ha->ip_config.ipv6_addr0_state = ipaddr_state;
627*4882a593Smuzhiyun 		break;
628*4882a593Smuzhiyun 	case 3:
629*4882a593Smuzhiyun 		ha->ip_config.ipv6_addr1_state = ipaddr_state;
630*4882a593Smuzhiyun 		break;
631*4882a593Smuzhiyun 	default:
632*4882a593Smuzhiyun 		ql4_printk(KERN_INFO, ha, "%s: Invalid IPADDR index %d\n",
633*4882a593Smuzhiyun 			   __func__, ip_idx);
634*4882a593Smuzhiyun 	}
635*4882a593Smuzhiyun }
636*4882a593Smuzhiyun 
qla4xxx_default_router_changed(struct scsi_qla_host * ha,uint32_t * mbox_sts)637*4882a593Smuzhiyun static void qla4xxx_default_router_changed(struct scsi_qla_host *ha,
638*4882a593Smuzhiyun 					   uint32_t *mbox_sts)
639*4882a593Smuzhiyun {
640*4882a593Smuzhiyun 	memcpy(&ha->ip_config.ipv6_default_router_addr.s6_addr32[0],
641*4882a593Smuzhiyun 	       &mbox_sts[2], sizeof(uint32_t));
642*4882a593Smuzhiyun 	memcpy(&ha->ip_config.ipv6_default_router_addr.s6_addr32[1],
643*4882a593Smuzhiyun 	       &mbox_sts[3], sizeof(uint32_t));
644*4882a593Smuzhiyun 	memcpy(&ha->ip_config.ipv6_default_router_addr.s6_addr32[2],
645*4882a593Smuzhiyun 	       &mbox_sts[4], sizeof(uint32_t));
646*4882a593Smuzhiyun 	memcpy(&ha->ip_config.ipv6_default_router_addr.s6_addr32[3],
647*4882a593Smuzhiyun 	       &mbox_sts[5], sizeof(uint32_t));
648*4882a593Smuzhiyun }
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun /**
651*4882a593Smuzhiyun  * qla4xxx_isr_decode_mailbox - decodes mailbox status
652*4882a593Smuzhiyun  * @ha: Pointer to host adapter structure.
653*4882a593Smuzhiyun  * @mbox_status: Mailbox status.
654*4882a593Smuzhiyun  *
655*4882a593Smuzhiyun  * This routine decodes the mailbox status during the ISR.
656*4882a593Smuzhiyun  * Hardware_lock locked upon entry. runs in interrupt context.
657*4882a593Smuzhiyun  **/
qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,uint32_t mbox_status)658*4882a593Smuzhiyun static void qla4xxx_isr_decode_mailbox(struct scsi_qla_host * ha,
659*4882a593Smuzhiyun 				       uint32_t mbox_status)
660*4882a593Smuzhiyun {
661*4882a593Smuzhiyun 	int i;
662*4882a593Smuzhiyun 	uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
663*4882a593Smuzhiyun 	__le32 __iomem *mailbox_out;
664*4882a593Smuzhiyun 	uint32_t opcode = 0;
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun 	if (is_qla8032(ha) || is_qla8042(ha))
667*4882a593Smuzhiyun 		mailbox_out = &ha->qla4_83xx_reg->mailbox_out[0];
668*4882a593Smuzhiyun 	else if (is_qla8022(ha))
669*4882a593Smuzhiyun 		mailbox_out = &ha->qla4_82xx_reg->mailbox_out[0];
670*4882a593Smuzhiyun 	else
671*4882a593Smuzhiyun 		mailbox_out = &ha->reg->mailbox[0];
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun 	if ((mbox_status == MBOX_STS_BUSY) ||
674*4882a593Smuzhiyun 	    (mbox_status == MBOX_STS_INTERMEDIATE_COMPLETION) ||
675*4882a593Smuzhiyun 	    (mbox_status >> 12 == MBOX_COMPLETION_STATUS)) {
676*4882a593Smuzhiyun 		ha->mbox_status[0] = mbox_status;
677*4882a593Smuzhiyun 
678*4882a593Smuzhiyun 		if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
679*4882a593Smuzhiyun 			/*
680*4882a593Smuzhiyun 			 * Copy all mailbox registers to a temporary
681*4882a593Smuzhiyun 			 * location and set mailbox command done flag
682*4882a593Smuzhiyun 			 */
683*4882a593Smuzhiyun 			for (i = 0; i < ha->mbox_status_count; i++)
684*4882a593Smuzhiyun 				ha->mbox_status[i] = readl(&mailbox_out[i]);
685*4882a593Smuzhiyun 
686*4882a593Smuzhiyun 			set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
687*4882a593Smuzhiyun 
688*4882a593Smuzhiyun 			if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags))
689*4882a593Smuzhiyun 				complete(&ha->mbx_intr_comp);
690*4882a593Smuzhiyun 		}
691*4882a593Smuzhiyun 	} else if (mbox_status >> 12 == MBOX_ASYNC_EVENT_STATUS) {
692*4882a593Smuzhiyun 		for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
693*4882a593Smuzhiyun 			mbox_sts[i] = readl(&mailbox_out[i]);
694*4882a593Smuzhiyun 
695*4882a593Smuzhiyun 		/* Immediately process the AENs that don't require much work.
696*4882a593Smuzhiyun 		 * Only queue the database_changed AENs */
697*4882a593Smuzhiyun 		if (ha->aen_log.count < MAX_AEN_ENTRIES) {
698*4882a593Smuzhiyun 			for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
699*4882a593Smuzhiyun 				ha->aen_log.entry[ha->aen_log.count].mbox_sts[i] =
700*4882a593Smuzhiyun 				    mbox_sts[i];
701*4882a593Smuzhiyun 			ha->aen_log.count++;
702*4882a593Smuzhiyun 		}
703*4882a593Smuzhiyun 		switch (mbox_status) {
704*4882a593Smuzhiyun 		case MBOX_ASTS_SYSTEM_ERROR:
705*4882a593Smuzhiyun 			/* Log Mailbox registers */
706*4882a593Smuzhiyun 			ql4_printk(KERN_INFO, ha, "%s: System Err\n", __func__);
707*4882a593Smuzhiyun 			qla4xxx_dump_registers(ha);
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun 			if ((is_qla8022(ha) && ql4xdontresethba) ||
710*4882a593Smuzhiyun 			    ((is_qla8032(ha) || is_qla8042(ha)) &&
711*4882a593Smuzhiyun 			     qla4_83xx_idc_dontreset(ha))) {
712*4882a593Smuzhiyun 				DEBUG2(printk("scsi%ld: %s:Don't Reset HBA\n",
713*4882a593Smuzhiyun 				    ha->host_no, __func__));
714*4882a593Smuzhiyun 			} else {
715*4882a593Smuzhiyun 				set_bit(AF_GET_CRASH_RECORD, &ha->flags);
716*4882a593Smuzhiyun 				set_bit(DPC_RESET_HA, &ha->dpc_flags);
717*4882a593Smuzhiyun 			}
718*4882a593Smuzhiyun 			break;
719*4882a593Smuzhiyun 
720*4882a593Smuzhiyun 		case MBOX_ASTS_REQUEST_TRANSFER_ERROR:
721*4882a593Smuzhiyun 		case MBOX_ASTS_RESPONSE_TRANSFER_ERROR:
722*4882a593Smuzhiyun 		case MBOX_ASTS_NVRAM_INVALID:
723*4882a593Smuzhiyun 		case MBOX_ASTS_IP_ADDRESS_CHANGED:
724*4882a593Smuzhiyun 		case MBOX_ASTS_DHCP_LEASE_EXPIRED:
725*4882a593Smuzhiyun 			DEBUG2(printk("scsi%ld: AEN %04x, ERROR Status, "
726*4882a593Smuzhiyun 				      "Reset HA\n", ha->host_no, mbox_status));
727*4882a593Smuzhiyun 			if (is_qla80XX(ha))
728*4882a593Smuzhiyun 				set_bit(DPC_RESET_HA_FW_CONTEXT,
729*4882a593Smuzhiyun 					&ha->dpc_flags);
730*4882a593Smuzhiyun 			else
731*4882a593Smuzhiyun 				set_bit(DPC_RESET_HA, &ha->dpc_flags);
732*4882a593Smuzhiyun 			break;
733*4882a593Smuzhiyun 
734*4882a593Smuzhiyun 		case MBOX_ASTS_LINK_UP:
735*4882a593Smuzhiyun 			set_bit(AF_LINK_UP, &ha->flags);
736*4882a593Smuzhiyun 			if (test_bit(AF_INIT_DONE, &ha->flags))
737*4882a593Smuzhiyun 				set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
738*4882a593Smuzhiyun 
739*4882a593Smuzhiyun 			ql4_printk(KERN_INFO, ha, "%s: LINK UP\n", __func__);
740*4882a593Smuzhiyun 			qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKUP,
741*4882a593Smuzhiyun 					      sizeof(mbox_sts),
742*4882a593Smuzhiyun 					      (uint8_t *) mbox_sts);
743*4882a593Smuzhiyun 
744*4882a593Smuzhiyun 			if ((is_qla8032(ha) || is_qla8042(ha)) &&
745*4882a593Smuzhiyun 			    ha->notify_link_up_comp)
746*4882a593Smuzhiyun 				complete(&ha->link_up_comp);
747*4882a593Smuzhiyun 
748*4882a593Smuzhiyun 			break;
749*4882a593Smuzhiyun 
750*4882a593Smuzhiyun 		case MBOX_ASTS_LINK_DOWN:
751*4882a593Smuzhiyun 			clear_bit(AF_LINK_UP, &ha->flags);
752*4882a593Smuzhiyun 			if (test_bit(AF_INIT_DONE, &ha->flags)) {
753*4882a593Smuzhiyun 				set_bit(DPC_LINK_CHANGED, &ha->dpc_flags);
754*4882a593Smuzhiyun 				qla4xxx_wake_dpc(ha);
755*4882a593Smuzhiyun 			}
756*4882a593Smuzhiyun 
757*4882a593Smuzhiyun 			ql4_printk(KERN_INFO, ha, "%s: LINK DOWN\n", __func__);
758*4882a593Smuzhiyun 			qla4xxx_post_aen_work(ha, ISCSI_EVENT_LINKDOWN,
759*4882a593Smuzhiyun 					      sizeof(mbox_sts),
760*4882a593Smuzhiyun 					      (uint8_t *) mbox_sts);
761*4882a593Smuzhiyun 			break;
762*4882a593Smuzhiyun 
763*4882a593Smuzhiyun 		case MBOX_ASTS_HEARTBEAT:
764*4882a593Smuzhiyun 			ha->seconds_since_last_heartbeat = 0;
765*4882a593Smuzhiyun 			break;
766*4882a593Smuzhiyun 
767*4882a593Smuzhiyun 		case MBOX_ASTS_DHCP_LEASE_ACQUIRED:
768*4882a593Smuzhiyun 			DEBUG2(printk("scsi%ld: AEN %04x DHCP LEASE "
769*4882a593Smuzhiyun 				      "ACQUIRED\n", ha->host_no, mbox_status));
770*4882a593Smuzhiyun 			set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
771*4882a593Smuzhiyun 			break;
772*4882a593Smuzhiyun 
773*4882a593Smuzhiyun 		case MBOX_ASTS_PROTOCOL_STATISTIC_ALARM:
774*4882a593Smuzhiyun 		case MBOX_ASTS_SCSI_COMMAND_PDU_REJECTED: /* Target
775*4882a593Smuzhiyun 							   * mode
776*4882a593Smuzhiyun 							   * only */
777*4882a593Smuzhiyun 		case MBOX_ASTS_UNSOLICITED_PDU_RECEIVED:  /* Connection mode */
778*4882a593Smuzhiyun 		case MBOX_ASTS_IPSEC_SYSTEM_FATAL_ERROR:
779*4882a593Smuzhiyun 		case MBOX_ASTS_SUBNET_STATE_CHANGE:
780*4882a593Smuzhiyun 		case MBOX_ASTS_DUPLICATE_IP:
781*4882a593Smuzhiyun 			/* No action */
782*4882a593Smuzhiyun 			DEBUG2(printk("scsi%ld: AEN %04x\n", ha->host_no,
783*4882a593Smuzhiyun 				      mbox_status));
784*4882a593Smuzhiyun 			break;
785*4882a593Smuzhiyun 
786*4882a593Smuzhiyun 		case MBOX_ASTS_IP_ADDR_STATE_CHANGED:
787*4882a593Smuzhiyun 			printk("scsi%ld: AEN %04x, mbox_sts[2]=%04x, "
788*4882a593Smuzhiyun 			    "mbox_sts[3]=%04x\n", ha->host_no, mbox_sts[0],
789*4882a593Smuzhiyun 			    mbox_sts[2], mbox_sts[3]);
790*4882a593Smuzhiyun 
791*4882a593Smuzhiyun 			qla4xxx_update_ipaddr_state(ha, mbox_sts[5],
792*4882a593Smuzhiyun 						    mbox_sts[3]);
793*4882a593Smuzhiyun 			/* mbox_sts[2] = Old ACB state
794*4882a593Smuzhiyun 			 * mbox_sts[3] = new ACB state */
795*4882a593Smuzhiyun 			if ((mbox_sts[3] == IP_ADDRSTATE_PREFERRED) &&
796*4882a593Smuzhiyun 			    ((mbox_sts[2] == IP_ADDRSTATE_TENTATIVE) ||
797*4882a593Smuzhiyun 			     (mbox_sts[2] == IP_ADDRSTATE_ACQUIRING))) {
798*4882a593Smuzhiyun 				set_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags);
799*4882a593Smuzhiyun 			} else if ((mbox_sts[3] == IP_ADDRSTATE_ACQUIRING) &&
800*4882a593Smuzhiyun 				   (mbox_sts[2] == IP_ADDRSTATE_PREFERRED)) {
801*4882a593Smuzhiyun 				if (is_qla80XX(ha))
802*4882a593Smuzhiyun 					set_bit(DPC_RESET_HA_FW_CONTEXT,
803*4882a593Smuzhiyun 						&ha->dpc_flags);
804*4882a593Smuzhiyun 				else
805*4882a593Smuzhiyun 					set_bit(DPC_RESET_HA, &ha->dpc_flags);
806*4882a593Smuzhiyun 			} else if (mbox_sts[3] == IP_ADDRSTATE_DISABLING) {
807*4882a593Smuzhiyun 				ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ACB in disabling state\n",
808*4882a593Smuzhiyun 					   ha->host_no, __func__);
809*4882a593Smuzhiyun 			} else if (mbox_sts[3] == IP_ADDRSTATE_UNCONFIGURED) {
810*4882a593Smuzhiyun 				complete(&ha->disable_acb_comp);
811*4882a593Smuzhiyun 				ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ACB state unconfigured\n",
812*4882a593Smuzhiyun 					   ha->host_no, __func__);
813*4882a593Smuzhiyun 			}
814*4882a593Smuzhiyun 			break;
815*4882a593Smuzhiyun 
816*4882a593Smuzhiyun 		case MBOX_ASTS_IPV6_LINK_MTU_CHANGE:
817*4882a593Smuzhiyun 		case MBOX_ASTS_IPV6_AUTO_PREFIX_IGNORED:
818*4882a593Smuzhiyun 		case MBOX_ASTS_IPV6_ND_LOCAL_PREFIX_IGNORED:
819*4882a593Smuzhiyun 			/* No action */
820*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha, "scsi%ld: AEN %04x\n",
821*4882a593Smuzhiyun 					  ha->host_no, mbox_status));
822*4882a593Smuzhiyun 			break;
823*4882a593Smuzhiyun 
824*4882a593Smuzhiyun 		case MBOX_ASTS_ICMPV6_ERROR_MSG_RCVD:
825*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
826*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x, IPv6 ERROR, "
827*4882a593Smuzhiyun 					  "mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3}=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
828*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0], mbox_sts[1],
829*4882a593Smuzhiyun 					  mbox_sts[2], mbox_sts[3], mbox_sts[4],
830*4882a593Smuzhiyun 					  mbox_sts[5]));
831*4882a593Smuzhiyun 			break;
832*4882a593Smuzhiyun 
833*4882a593Smuzhiyun 		case MBOX_ASTS_MAC_ADDRESS_CHANGED:
834*4882a593Smuzhiyun 		case MBOX_ASTS_DNS:
835*4882a593Smuzhiyun 			/* No action */
836*4882a593Smuzhiyun 			DEBUG2(printk(KERN_INFO "scsi%ld: AEN %04x, "
837*4882a593Smuzhiyun 				      "mbox_sts[1]=%04x, mbox_sts[2]=%04x\n",
838*4882a593Smuzhiyun 				      ha->host_no, mbox_sts[0],
839*4882a593Smuzhiyun 				      mbox_sts[1], mbox_sts[2]));
840*4882a593Smuzhiyun 			break;
841*4882a593Smuzhiyun 
842*4882a593Smuzhiyun 		case MBOX_ASTS_SELF_TEST_FAILED:
843*4882a593Smuzhiyun 		case MBOX_ASTS_LOGIN_FAILED:
844*4882a593Smuzhiyun 			/* No action */
845*4882a593Smuzhiyun 			DEBUG2(printk("scsi%ld: AEN %04x, mbox_sts[1]=%04x, "
846*4882a593Smuzhiyun 				      "mbox_sts[2]=%04x, mbox_sts[3]=%04x\n",
847*4882a593Smuzhiyun 				      ha->host_no, mbox_sts[0], mbox_sts[1],
848*4882a593Smuzhiyun 				      mbox_sts[2], mbox_sts[3]));
849*4882a593Smuzhiyun 			break;
850*4882a593Smuzhiyun 
851*4882a593Smuzhiyun 		case MBOX_ASTS_DATABASE_CHANGED:
852*4882a593Smuzhiyun 			/* Queue AEN information and process it in the DPC
853*4882a593Smuzhiyun 			 * routine */
854*4882a593Smuzhiyun 			if (ha->aen_q_count > 0) {
855*4882a593Smuzhiyun 
856*4882a593Smuzhiyun 				/* decrement available counter */
857*4882a593Smuzhiyun 				ha->aen_q_count--;
858*4882a593Smuzhiyun 
859*4882a593Smuzhiyun 				for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
860*4882a593Smuzhiyun 					ha->aen_q[ha->aen_in].mbox_sts[i] =
861*4882a593Smuzhiyun 					    mbox_sts[i];
862*4882a593Smuzhiyun 
863*4882a593Smuzhiyun 				/* print debug message */
864*4882a593Smuzhiyun 				DEBUG2(printk("scsi%ld: AEN[%d] %04x queued "
865*4882a593Smuzhiyun 					      "mb1:0x%x mb2:0x%x mb3:0x%x "
866*4882a593Smuzhiyun 					      "mb4:0x%x mb5:0x%x\n",
867*4882a593Smuzhiyun 					      ha->host_no, ha->aen_in,
868*4882a593Smuzhiyun 					      mbox_sts[0], mbox_sts[1],
869*4882a593Smuzhiyun 					      mbox_sts[2], mbox_sts[3],
870*4882a593Smuzhiyun 					      mbox_sts[4], mbox_sts[5]));
871*4882a593Smuzhiyun 
872*4882a593Smuzhiyun 				/* advance pointer */
873*4882a593Smuzhiyun 				ha->aen_in++;
874*4882a593Smuzhiyun 				if (ha->aen_in == MAX_AEN_ENTRIES)
875*4882a593Smuzhiyun 					ha->aen_in = 0;
876*4882a593Smuzhiyun 
877*4882a593Smuzhiyun 				/* The DPC routine will process the aen */
878*4882a593Smuzhiyun 				set_bit(DPC_AEN, &ha->dpc_flags);
879*4882a593Smuzhiyun 			} else {
880*4882a593Smuzhiyun 				DEBUG2(printk("scsi%ld: %s: aen %04x, queue "
881*4882a593Smuzhiyun 					      "overflowed!  AEN LOST!!\n",
882*4882a593Smuzhiyun 					      ha->host_no, __func__,
883*4882a593Smuzhiyun 					      mbox_sts[0]));
884*4882a593Smuzhiyun 
885*4882a593Smuzhiyun 				DEBUG2(printk("scsi%ld: DUMP AEN QUEUE\n",
886*4882a593Smuzhiyun 					      ha->host_no));
887*4882a593Smuzhiyun 
888*4882a593Smuzhiyun 				for (i = 0; i < MAX_AEN_ENTRIES; i++) {
889*4882a593Smuzhiyun 					DEBUG2(printk("AEN[%d] %04x %04x %04x "
890*4882a593Smuzhiyun 						      "%04x\n", i, mbox_sts[0],
891*4882a593Smuzhiyun 						      mbox_sts[1], mbox_sts[2],
892*4882a593Smuzhiyun 						      mbox_sts[3]));
893*4882a593Smuzhiyun 				}
894*4882a593Smuzhiyun 			}
895*4882a593Smuzhiyun 			break;
896*4882a593Smuzhiyun 
897*4882a593Smuzhiyun 		case MBOX_ASTS_TXSCVR_INSERTED:
898*4882a593Smuzhiyun 			DEBUG2(printk(KERN_WARNING
899*4882a593Smuzhiyun 			    "scsi%ld: AEN %04x Transceiver"
900*4882a593Smuzhiyun 			    " inserted\n",  ha->host_no, mbox_sts[0]));
901*4882a593Smuzhiyun 			break;
902*4882a593Smuzhiyun 
903*4882a593Smuzhiyun 		case MBOX_ASTS_TXSCVR_REMOVED:
904*4882a593Smuzhiyun 			DEBUG2(printk(KERN_WARNING
905*4882a593Smuzhiyun 			    "scsi%ld: AEN %04x Transceiver"
906*4882a593Smuzhiyun 			    " removed\n",  ha->host_no, mbox_sts[0]));
907*4882a593Smuzhiyun 			break;
908*4882a593Smuzhiyun 
909*4882a593Smuzhiyun 		case MBOX_ASTS_IDC_REQUEST_NOTIFICATION:
910*4882a593Smuzhiyun 			if (is_qla8032(ha) || is_qla8042(ha)) {
911*4882a593Smuzhiyun 				DEBUG2(ql4_printk(KERN_INFO, ha,
912*4882a593Smuzhiyun 						  "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
913*4882a593Smuzhiyun 						  ha->host_no, mbox_sts[0],
914*4882a593Smuzhiyun 						  mbox_sts[1], mbox_sts[2],
915*4882a593Smuzhiyun 						  mbox_sts[3], mbox_sts[4]));
916*4882a593Smuzhiyun 				opcode = mbox_sts[1] >> 16;
917*4882a593Smuzhiyun 				if ((opcode == MBOX_CMD_SET_PORT_CONFIG) ||
918*4882a593Smuzhiyun 				    (opcode == MBOX_CMD_PORT_RESET)) {
919*4882a593Smuzhiyun 					set_bit(DPC_POST_IDC_ACK,
920*4882a593Smuzhiyun 						&ha->dpc_flags);
921*4882a593Smuzhiyun 					ha->idc_info.request_desc = mbox_sts[1];
922*4882a593Smuzhiyun 					ha->idc_info.info1 = mbox_sts[2];
923*4882a593Smuzhiyun 					ha->idc_info.info2 = mbox_sts[3];
924*4882a593Smuzhiyun 					ha->idc_info.info3 = mbox_sts[4];
925*4882a593Smuzhiyun 					qla4xxx_wake_dpc(ha);
926*4882a593Smuzhiyun 				}
927*4882a593Smuzhiyun 			}
928*4882a593Smuzhiyun 			break;
929*4882a593Smuzhiyun 
930*4882a593Smuzhiyun 		case MBOX_ASTS_IDC_COMPLETE:
931*4882a593Smuzhiyun 			if (is_qla8032(ha) || is_qla8042(ha)) {
932*4882a593Smuzhiyun 				DEBUG2(ql4_printk(KERN_INFO, ha,
933*4882a593Smuzhiyun 						  "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x\n",
934*4882a593Smuzhiyun 						  ha->host_no, mbox_sts[0],
935*4882a593Smuzhiyun 						  mbox_sts[1], mbox_sts[2],
936*4882a593Smuzhiyun 						  mbox_sts[3], mbox_sts[4]));
937*4882a593Smuzhiyun 				DEBUG2(ql4_printk(KERN_INFO, ha,
938*4882a593Smuzhiyun 						  "scsi:%ld: AEN %04x IDC Complete notification\n",
939*4882a593Smuzhiyun 						  ha->host_no, mbox_sts[0]));
940*4882a593Smuzhiyun 
941*4882a593Smuzhiyun 				opcode = mbox_sts[1] >> 16;
942*4882a593Smuzhiyun 				if (ha->notify_idc_comp)
943*4882a593Smuzhiyun 					complete(&ha->idc_comp);
944*4882a593Smuzhiyun 
945*4882a593Smuzhiyun 				if ((opcode == MBOX_CMD_SET_PORT_CONFIG) ||
946*4882a593Smuzhiyun 				    (opcode == MBOX_CMD_PORT_RESET))
947*4882a593Smuzhiyun 					ha->idc_info.info2 = mbox_sts[3];
948*4882a593Smuzhiyun 
949*4882a593Smuzhiyun 				if (qla4_83xx_loopback_in_progress(ha)) {
950*4882a593Smuzhiyun 					set_bit(AF_LOOPBACK, &ha->flags);
951*4882a593Smuzhiyun 				} else {
952*4882a593Smuzhiyun 					clear_bit(AF_LOOPBACK, &ha->flags);
953*4882a593Smuzhiyun 					if (ha->saved_acb)
954*4882a593Smuzhiyun 						set_bit(DPC_RESTORE_ACB,
955*4882a593Smuzhiyun 							&ha->dpc_flags);
956*4882a593Smuzhiyun 				}
957*4882a593Smuzhiyun 				qla4xxx_wake_dpc(ha);
958*4882a593Smuzhiyun 			}
959*4882a593Smuzhiyun 			break;
960*4882a593Smuzhiyun 
961*4882a593Smuzhiyun 		case MBOX_ASTS_IPV6_DEFAULT_ROUTER_CHANGED:
962*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
963*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
964*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0], mbox_sts[1],
965*4882a593Smuzhiyun 					  mbox_sts[2], mbox_sts[3], mbox_sts[4],
966*4882a593Smuzhiyun 					  mbox_sts[5]));
967*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
968*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x Received IPv6 default router changed notification\n",
969*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0]));
970*4882a593Smuzhiyun 			qla4xxx_default_router_changed(ha, mbox_sts);
971*4882a593Smuzhiyun 			break;
972*4882a593Smuzhiyun 
973*4882a593Smuzhiyun 		case MBOX_ASTS_IDC_TIME_EXTEND_NOTIFICATION:
974*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
975*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
976*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0], mbox_sts[1],
977*4882a593Smuzhiyun 					  mbox_sts[2], mbox_sts[3], mbox_sts[4],
978*4882a593Smuzhiyun 					  mbox_sts[5]));
979*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
980*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x Received IDC Extend Timeout notification\n",
981*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0]));
982*4882a593Smuzhiyun 			/* new IDC timeout */
983*4882a593Smuzhiyun 			ha->idc_extend_tmo = mbox_sts[1];
984*4882a593Smuzhiyun 			break;
985*4882a593Smuzhiyun 
986*4882a593Smuzhiyun 		case MBOX_ASTS_INITIALIZATION_FAILED:
987*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
988*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x, mbox_sts[3]=%08x\n",
989*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0],
990*4882a593Smuzhiyun 					  mbox_sts[3]));
991*4882a593Smuzhiyun 			break;
992*4882a593Smuzhiyun 
993*4882a593Smuzhiyun 		case MBOX_ASTS_SYSTEM_WARNING_EVENT:
994*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_WARNING, ha,
995*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
996*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0], mbox_sts[1],
997*4882a593Smuzhiyun 					  mbox_sts[2], mbox_sts[3], mbox_sts[4],
998*4882a593Smuzhiyun 					  mbox_sts[5]));
999*4882a593Smuzhiyun 			break;
1000*4882a593Smuzhiyun 
1001*4882a593Smuzhiyun 		case MBOX_ASTS_DCBX_CONF_CHANGE:
1002*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
1003*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x, mbox_sts[1]=%08x, mbox_sts[2]=%08x, mbox_sts[3]=%08x, mbox_sts[4]=%08x mbox_sts[5]=%08x\n",
1004*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0], mbox_sts[1],
1005*4882a593Smuzhiyun 					  mbox_sts[2], mbox_sts[3], mbox_sts[4],
1006*4882a593Smuzhiyun 					  mbox_sts[5]));
1007*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha,
1008*4882a593Smuzhiyun 					  "scsi%ld: AEN %04x Received DCBX configuration changed notification\n",
1009*4882a593Smuzhiyun 					  ha->host_no, mbox_sts[0]));
1010*4882a593Smuzhiyun 			break;
1011*4882a593Smuzhiyun 
1012*4882a593Smuzhiyun 		default:
1013*4882a593Smuzhiyun 			DEBUG2(printk(KERN_WARNING
1014*4882a593Smuzhiyun 				      "scsi%ld: AEN %04x UNKNOWN\n",
1015*4882a593Smuzhiyun 				      ha->host_no, mbox_sts[0]));
1016*4882a593Smuzhiyun 			break;
1017*4882a593Smuzhiyun 		}
1018*4882a593Smuzhiyun 	} else {
1019*4882a593Smuzhiyun 		DEBUG2(printk("scsi%ld: Unknown mailbox status %08X\n",
1020*4882a593Smuzhiyun 			      ha->host_no, mbox_status));
1021*4882a593Smuzhiyun 
1022*4882a593Smuzhiyun 		ha->mbox_status[0] = mbox_status;
1023*4882a593Smuzhiyun 	}
1024*4882a593Smuzhiyun }
1025*4882a593Smuzhiyun 
qla4_83xx_interrupt_service_routine(struct scsi_qla_host * ha,uint32_t intr_status)1026*4882a593Smuzhiyun void qla4_83xx_interrupt_service_routine(struct scsi_qla_host *ha,
1027*4882a593Smuzhiyun 					 uint32_t intr_status)
1028*4882a593Smuzhiyun {
1029*4882a593Smuzhiyun 	/* Process mailbox/asynch event interrupt.*/
1030*4882a593Smuzhiyun 	if (intr_status) {
1031*4882a593Smuzhiyun 		qla4xxx_isr_decode_mailbox(ha,
1032*4882a593Smuzhiyun 				readl(&ha->qla4_83xx_reg->mailbox_out[0]));
1033*4882a593Smuzhiyun 		/* clear the interrupt */
1034*4882a593Smuzhiyun 		writel(0, &ha->qla4_83xx_reg->risc_intr);
1035*4882a593Smuzhiyun 	} else {
1036*4882a593Smuzhiyun 		qla4xxx_process_response_queue(ha);
1037*4882a593Smuzhiyun 	}
1038*4882a593Smuzhiyun 
1039*4882a593Smuzhiyun 	/* clear the interrupt */
1040*4882a593Smuzhiyun 	writel(0, &ha->qla4_83xx_reg->mb_int_mask);
1041*4882a593Smuzhiyun }
1042*4882a593Smuzhiyun 
1043*4882a593Smuzhiyun /**
1044*4882a593Smuzhiyun  * qla4_82xx_interrupt_service_routine - isr
1045*4882a593Smuzhiyun  * @ha: pointer to host adapter structure.
1046*4882a593Smuzhiyun  * @intr_status: Local interrupt status/type.
1047*4882a593Smuzhiyun  *
1048*4882a593Smuzhiyun  * This is the main interrupt service routine.
1049*4882a593Smuzhiyun  * hardware_lock locked upon entry. runs in interrupt context.
1050*4882a593Smuzhiyun  **/
qla4_82xx_interrupt_service_routine(struct scsi_qla_host * ha,uint32_t intr_status)1051*4882a593Smuzhiyun void qla4_82xx_interrupt_service_routine(struct scsi_qla_host *ha,
1052*4882a593Smuzhiyun     uint32_t intr_status)
1053*4882a593Smuzhiyun {
1054*4882a593Smuzhiyun 	/* Process response queue interrupt. */
1055*4882a593Smuzhiyun 	if ((intr_status & HSRX_RISC_IOCB_INT) &&
1056*4882a593Smuzhiyun 	    test_bit(AF_INIT_DONE, &ha->flags))
1057*4882a593Smuzhiyun 		qla4xxx_process_response_queue(ha);
1058*4882a593Smuzhiyun 
1059*4882a593Smuzhiyun 	/* Process mailbox/asynch event interrupt.*/
1060*4882a593Smuzhiyun 	if (intr_status & HSRX_RISC_MB_INT)
1061*4882a593Smuzhiyun 		qla4xxx_isr_decode_mailbox(ha,
1062*4882a593Smuzhiyun 		    readl(&ha->qla4_82xx_reg->mailbox_out[0]));
1063*4882a593Smuzhiyun 
1064*4882a593Smuzhiyun 	/* clear the interrupt */
1065*4882a593Smuzhiyun 	writel(0, &ha->qla4_82xx_reg->host_int);
1066*4882a593Smuzhiyun 	readl(&ha->qla4_82xx_reg->host_int);
1067*4882a593Smuzhiyun }
1068*4882a593Smuzhiyun 
1069*4882a593Smuzhiyun /**
1070*4882a593Smuzhiyun  * qla4xxx_interrupt_service_routine - isr
1071*4882a593Smuzhiyun  * @ha: pointer to host adapter structure.
1072*4882a593Smuzhiyun  * @intr_status: Local interrupt status/type.
1073*4882a593Smuzhiyun  *
1074*4882a593Smuzhiyun  * This is the main interrupt service routine.
1075*4882a593Smuzhiyun  * hardware_lock locked upon entry. runs in interrupt context.
1076*4882a593Smuzhiyun  **/
qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,uint32_t intr_status)1077*4882a593Smuzhiyun void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
1078*4882a593Smuzhiyun 				       uint32_t intr_status)
1079*4882a593Smuzhiyun {
1080*4882a593Smuzhiyun 	/* Process response queue interrupt. */
1081*4882a593Smuzhiyun 	if (intr_status & CSR_SCSI_COMPLETION_INTR)
1082*4882a593Smuzhiyun 		qla4xxx_process_response_queue(ha);
1083*4882a593Smuzhiyun 
1084*4882a593Smuzhiyun 	/* Process mailbox/asynch event	 interrupt.*/
1085*4882a593Smuzhiyun 	if (intr_status & CSR_SCSI_PROCESSOR_INTR) {
1086*4882a593Smuzhiyun 		qla4xxx_isr_decode_mailbox(ha,
1087*4882a593Smuzhiyun 					   readl(&ha->reg->mailbox[0]));
1088*4882a593Smuzhiyun 
1089*4882a593Smuzhiyun 		/* Clear Mailbox Interrupt */
1090*4882a593Smuzhiyun 		writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
1091*4882a593Smuzhiyun 		       &ha->reg->ctrl_status);
1092*4882a593Smuzhiyun 		readl(&ha->reg->ctrl_status);
1093*4882a593Smuzhiyun 	}
1094*4882a593Smuzhiyun }
1095*4882a593Smuzhiyun 
1096*4882a593Smuzhiyun /**
1097*4882a593Smuzhiyun  * qla4_82xx_spurious_interrupt - processes spurious interrupt
1098*4882a593Smuzhiyun  * @ha: pointer to host adapter structure.
1099*4882a593Smuzhiyun  * @reqs_count: .
1100*4882a593Smuzhiyun  *
1101*4882a593Smuzhiyun  **/
qla4_82xx_spurious_interrupt(struct scsi_qla_host * ha,uint8_t reqs_count)1102*4882a593Smuzhiyun static void qla4_82xx_spurious_interrupt(struct scsi_qla_host *ha,
1103*4882a593Smuzhiyun     uint8_t reqs_count)
1104*4882a593Smuzhiyun {
1105*4882a593Smuzhiyun 	if (reqs_count)
1106*4882a593Smuzhiyun 		return;
1107*4882a593Smuzhiyun 
1108*4882a593Smuzhiyun 	DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
1109*4882a593Smuzhiyun 	if (is_qla8022(ha)) {
1110*4882a593Smuzhiyun 		writel(0, &ha->qla4_82xx_reg->host_int);
1111*4882a593Smuzhiyun 		if (!ha->pdev->msi_enabled && !ha->pdev->msix_enabled)
1112*4882a593Smuzhiyun 			qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
1113*4882a593Smuzhiyun 			    0xfbff);
1114*4882a593Smuzhiyun 	}
1115*4882a593Smuzhiyun 	ha->spurious_int_count++;
1116*4882a593Smuzhiyun }
1117*4882a593Smuzhiyun 
1118*4882a593Smuzhiyun /**
1119*4882a593Smuzhiyun  * qla4xxx_intr_handler - hardware interrupt handler.
1120*4882a593Smuzhiyun  * @irq: Unused
1121*4882a593Smuzhiyun  * @dev_id: Pointer to host adapter structure
1122*4882a593Smuzhiyun  **/
qla4xxx_intr_handler(int irq,void * dev_id)1123*4882a593Smuzhiyun irqreturn_t qla4xxx_intr_handler(int irq, void *dev_id)
1124*4882a593Smuzhiyun {
1125*4882a593Smuzhiyun 	struct scsi_qla_host *ha;
1126*4882a593Smuzhiyun 	uint32_t intr_status;
1127*4882a593Smuzhiyun 	unsigned long flags = 0;
1128*4882a593Smuzhiyun 	uint8_t reqs_count = 0;
1129*4882a593Smuzhiyun 
1130*4882a593Smuzhiyun 	ha = (struct scsi_qla_host *) dev_id;
1131*4882a593Smuzhiyun 	if (!ha) {
1132*4882a593Smuzhiyun 		DEBUG2(printk(KERN_INFO
1133*4882a593Smuzhiyun 			      "qla4xxx: Interrupt with NULL host ptr\n"));
1134*4882a593Smuzhiyun 		return IRQ_NONE;
1135*4882a593Smuzhiyun 	}
1136*4882a593Smuzhiyun 
1137*4882a593Smuzhiyun 	spin_lock_irqsave(&ha->hardware_lock, flags);
1138*4882a593Smuzhiyun 
1139*4882a593Smuzhiyun 	ha->isr_count++;
1140*4882a593Smuzhiyun 	/*
1141*4882a593Smuzhiyun 	 * Repeatedly service interrupts up to a maximum of
1142*4882a593Smuzhiyun 	 * MAX_REQS_SERVICED_PER_INTR
1143*4882a593Smuzhiyun 	 */
1144*4882a593Smuzhiyun 	while (1) {
1145*4882a593Smuzhiyun 		/*
1146*4882a593Smuzhiyun 		 * Read interrupt status
1147*4882a593Smuzhiyun 		 */
1148*4882a593Smuzhiyun 		if (ha->isp_ops->rd_shdw_rsp_q_in(ha) !=
1149*4882a593Smuzhiyun 		    ha->response_out)
1150*4882a593Smuzhiyun 			intr_status = CSR_SCSI_COMPLETION_INTR;
1151*4882a593Smuzhiyun 		else
1152*4882a593Smuzhiyun 			intr_status = readl(&ha->reg->ctrl_status);
1153*4882a593Smuzhiyun 
1154*4882a593Smuzhiyun 		if ((intr_status &
1155*4882a593Smuzhiyun 		    (CSR_SCSI_RESET_INTR|CSR_FATAL_ERROR|INTR_PENDING)) == 0) {
1156*4882a593Smuzhiyun 			if (reqs_count == 0)
1157*4882a593Smuzhiyun 				ha->spurious_int_count++;
1158*4882a593Smuzhiyun 			break;
1159*4882a593Smuzhiyun 		}
1160*4882a593Smuzhiyun 
1161*4882a593Smuzhiyun 		if (intr_status & CSR_FATAL_ERROR) {
1162*4882a593Smuzhiyun 			DEBUG2(printk(KERN_INFO "scsi%ld: Fatal Error, "
1163*4882a593Smuzhiyun 				      "Status 0x%04x\n", ha->host_no,
1164*4882a593Smuzhiyun 				      readl(isp_port_error_status (ha))));
1165*4882a593Smuzhiyun 
1166*4882a593Smuzhiyun 			/* Issue Soft Reset to clear this error condition.
1167*4882a593Smuzhiyun 			 * This will prevent the RISC from repeatedly
1168*4882a593Smuzhiyun 			 * interrupting the driver; thus, allowing the DPC to
1169*4882a593Smuzhiyun 			 * get scheduled to continue error recovery.
1170*4882a593Smuzhiyun 			 * NOTE: Disabling RISC interrupts does not work in
1171*4882a593Smuzhiyun 			 * this case, as CSR_FATAL_ERROR overrides
1172*4882a593Smuzhiyun 			 * CSR_SCSI_INTR_ENABLE */
1173*4882a593Smuzhiyun 			if ((readl(&ha->reg->ctrl_status) &
1174*4882a593Smuzhiyun 			     CSR_SCSI_RESET_INTR) == 0) {
1175*4882a593Smuzhiyun 				writel(set_rmask(CSR_SOFT_RESET),
1176*4882a593Smuzhiyun 				       &ha->reg->ctrl_status);
1177*4882a593Smuzhiyun 				readl(&ha->reg->ctrl_status);
1178*4882a593Smuzhiyun 			}
1179*4882a593Smuzhiyun 
1180*4882a593Smuzhiyun 			writel(set_rmask(CSR_FATAL_ERROR),
1181*4882a593Smuzhiyun 			       &ha->reg->ctrl_status);
1182*4882a593Smuzhiyun 			readl(&ha->reg->ctrl_status);
1183*4882a593Smuzhiyun 
1184*4882a593Smuzhiyun 			__qla4xxx_disable_intrs(ha);
1185*4882a593Smuzhiyun 
1186*4882a593Smuzhiyun 			set_bit(DPC_RESET_HA, &ha->dpc_flags);
1187*4882a593Smuzhiyun 
1188*4882a593Smuzhiyun 			break;
1189*4882a593Smuzhiyun 		} else if (intr_status & CSR_SCSI_RESET_INTR) {
1190*4882a593Smuzhiyun 			clear_bit(AF_ONLINE, &ha->flags);
1191*4882a593Smuzhiyun 			__qla4xxx_disable_intrs(ha);
1192*4882a593Smuzhiyun 
1193*4882a593Smuzhiyun 			writel(set_rmask(CSR_SCSI_RESET_INTR),
1194*4882a593Smuzhiyun 			       &ha->reg->ctrl_status);
1195*4882a593Smuzhiyun 			readl(&ha->reg->ctrl_status);
1196*4882a593Smuzhiyun 
1197*4882a593Smuzhiyun 			if (!test_bit(AF_HA_REMOVAL, &ha->flags))
1198*4882a593Smuzhiyun 				set_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1199*4882a593Smuzhiyun 
1200*4882a593Smuzhiyun 			break;
1201*4882a593Smuzhiyun 		} else if (intr_status & INTR_PENDING) {
1202*4882a593Smuzhiyun 			ha->isp_ops->interrupt_service_routine(ha, intr_status);
1203*4882a593Smuzhiyun 			ha->total_io_count++;
1204*4882a593Smuzhiyun 			if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1205*4882a593Smuzhiyun 				break;
1206*4882a593Smuzhiyun 		}
1207*4882a593Smuzhiyun 	}
1208*4882a593Smuzhiyun 
1209*4882a593Smuzhiyun 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
1210*4882a593Smuzhiyun 
1211*4882a593Smuzhiyun 	return IRQ_HANDLED;
1212*4882a593Smuzhiyun }
1213*4882a593Smuzhiyun 
1214*4882a593Smuzhiyun /**
1215*4882a593Smuzhiyun  * qla4_82xx_intr_handler - hardware interrupt handler.
1216*4882a593Smuzhiyun  * @irq: Unused
1217*4882a593Smuzhiyun  * @dev_id: Pointer to host adapter structure
1218*4882a593Smuzhiyun  **/
qla4_82xx_intr_handler(int irq,void * dev_id)1219*4882a593Smuzhiyun irqreturn_t qla4_82xx_intr_handler(int irq, void *dev_id)
1220*4882a593Smuzhiyun {
1221*4882a593Smuzhiyun 	struct scsi_qla_host *ha = dev_id;
1222*4882a593Smuzhiyun 	uint32_t intr_status;
1223*4882a593Smuzhiyun 	uint32_t status;
1224*4882a593Smuzhiyun 	unsigned long flags = 0;
1225*4882a593Smuzhiyun 	uint8_t reqs_count = 0;
1226*4882a593Smuzhiyun 
1227*4882a593Smuzhiyun 	if (unlikely(pci_channel_offline(ha->pdev)))
1228*4882a593Smuzhiyun 		return IRQ_HANDLED;
1229*4882a593Smuzhiyun 
1230*4882a593Smuzhiyun 	ha->isr_count++;
1231*4882a593Smuzhiyun 	status = qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1232*4882a593Smuzhiyun 	if (!(status & ha->nx_legacy_intr.int_vec_bit))
1233*4882a593Smuzhiyun 		return IRQ_NONE;
1234*4882a593Smuzhiyun 
1235*4882a593Smuzhiyun 	status = qla4_82xx_rd_32(ha, ISR_INT_STATE_REG);
1236*4882a593Smuzhiyun 	if (!ISR_IS_LEGACY_INTR_TRIGGERED(status)) {
1237*4882a593Smuzhiyun 		DEBUG7(ql4_printk(KERN_INFO, ha,
1238*4882a593Smuzhiyun 				  "%s legacy Int not triggered\n", __func__));
1239*4882a593Smuzhiyun 		return IRQ_NONE;
1240*4882a593Smuzhiyun 	}
1241*4882a593Smuzhiyun 
1242*4882a593Smuzhiyun 	/* clear the interrupt */
1243*4882a593Smuzhiyun 	qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
1244*4882a593Smuzhiyun 
1245*4882a593Smuzhiyun 	/* read twice to ensure write is flushed */
1246*4882a593Smuzhiyun 	qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1247*4882a593Smuzhiyun 	qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1248*4882a593Smuzhiyun 
1249*4882a593Smuzhiyun 	spin_lock_irqsave(&ha->hardware_lock, flags);
1250*4882a593Smuzhiyun 	while (1) {
1251*4882a593Smuzhiyun 		if (!(readl(&ha->qla4_82xx_reg->host_int) &
1252*4882a593Smuzhiyun 		    ISRX_82XX_RISC_INT)) {
1253*4882a593Smuzhiyun 			qla4_82xx_spurious_interrupt(ha, reqs_count);
1254*4882a593Smuzhiyun 			break;
1255*4882a593Smuzhiyun 		}
1256*4882a593Smuzhiyun 		intr_status =  readl(&ha->qla4_82xx_reg->host_status);
1257*4882a593Smuzhiyun 		if ((intr_status &
1258*4882a593Smuzhiyun 		    (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0)  {
1259*4882a593Smuzhiyun 			qla4_82xx_spurious_interrupt(ha, reqs_count);
1260*4882a593Smuzhiyun 			break;
1261*4882a593Smuzhiyun 		}
1262*4882a593Smuzhiyun 
1263*4882a593Smuzhiyun 		ha->isp_ops->interrupt_service_routine(ha, intr_status);
1264*4882a593Smuzhiyun 
1265*4882a593Smuzhiyun 		/* Enable Interrupt */
1266*4882a593Smuzhiyun 		qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
1267*4882a593Smuzhiyun 
1268*4882a593Smuzhiyun 		if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1269*4882a593Smuzhiyun 			break;
1270*4882a593Smuzhiyun 	}
1271*4882a593Smuzhiyun 
1272*4882a593Smuzhiyun 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
1273*4882a593Smuzhiyun 	return IRQ_HANDLED;
1274*4882a593Smuzhiyun }
1275*4882a593Smuzhiyun 
1276*4882a593Smuzhiyun #define LEG_INT_PTR_B31		(1 << 31)
1277*4882a593Smuzhiyun #define LEG_INT_PTR_B30		(1 << 30)
1278*4882a593Smuzhiyun #define PF_BITS_MASK		(0xF << 16)
1279*4882a593Smuzhiyun 
1280*4882a593Smuzhiyun /**
1281*4882a593Smuzhiyun  * qla4_83xx_intr_handler - hardware interrupt handler.
1282*4882a593Smuzhiyun  * @irq: Unused
1283*4882a593Smuzhiyun  * @dev_id: Pointer to host adapter structure
1284*4882a593Smuzhiyun  **/
qla4_83xx_intr_handler(int irq,void * dev_id)1285*4882a593Smuzhiyun irqreturn_t qla4_83xx_intr_handler(int irq, void *dev_id)
1286*4882a593Smuzhiyun {
1287*4882a593Smuzhiyun 	struct scsi_qla_host *ha = dev_id;
1288*4882a593Smuzhiyun 	uint32_t leg_int_ptr = 0;
1289*4882a593Smuzhiyun 	unsigned long flags = 0;
1290*4882a593Smuzhiyun 
1291*4882a593Smuzhiyun 	ha->isr_count++;
1292*4882a593Smuzhiyun 	leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
1293*4882a593Smuzhiyun 
1294*4882a593Smuzhiyun 	/* Legacy interrupt is valid if bit31 of leg_int_ptr is set */
1295*4882a593Smuzhiyun 	if (!(leg_int_ptr & LEG_INT_PTR_B31)) {
1296*4882a593Smuzhiyun 		DEBUG7(ql4_printk(KERN_ERR, ha,
1297*4882a593Smuzhiyun 				  "%s: Legacy Interrupt Bit 31 not set, spurious interrupt!\n",
1298*4882a593Smuzhiyun 				  __func__));
1299*4882a593Smuzhiyun 		return IRQ_NONE;
1300*4882a593Smuzhiyun 	}
1301*4882a593Smuzhiyun 
1302*4882a593Smuzhiyun 	/* Validate the PCIE function ID set in leg_int_ptr bits [19..16] */
1303*4882a593Smuzhiyun 	if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit) {
1304*4882a593Smuzhiyun 		DEBUG7(ql4_printk(KERN_ERR, ha,
1305*4882a593Smuzhiyun 				  "%s: Incorrect function ID 0x%x in legacy interrupt register, ha->pf_bit = 0x%x\n",
1306*4882a593Smuzhiyun 				  __func__, (leg_int_ptr & PF_BITS_MASK),
1307*4882a593Smuzhiyun 				  ha->pf_bit));
1308*4882a593Smuzhiyun 		return IRQ_NONE;
1309*4882a593Smuzhiyun 	}
1310*4882a593Smuzhiyun 
1311*4882a593Smuzhiyun 	/* To de-assert legacy interrupt, write 0 to Legacy Interrupt Trigger
1312*4882a593Smuzhiyun 	 * Control register and poll till Legacy Interrupt Pointer register
1313*4882a593Smuzhiyun 	 * bit30 is 0.
1314*4882a593Smuzhiyun 	 */
1315*4882a593Smuzhiyun 	writel(0, &ha->qla4_83xx_reg->leg_int_trig);
1316*4882a593Smuzhiyun 	do {
1317*4882a593Smuzhiyun 		leg_int_ptr = readl(&ha->qla4_83xx_reg->leg_int_ptr);
1318*4882a593Smuzhiyun 		if ((leg_int_ptr & PF_BITS_MASK) != ha->pf_bit)
1319*4882a593Smuzhiyun 			break;
1320*4882a593Smuzhiyun 	} while (leg_int_ptr & LEG_INT_PTR_B30);
1321*4882a593Smuzhiyun 
1322*4882a593Smuzhiyun 	spin_lock_irqsave(&ha->hardware_lock, flags);
1323*4882a593Smuzhiyun 	leg_int_ptr = readl(&ha->qla4_83xx_reg->risc_intr);
1324*4882a593Smuzhiyun 	ha->isp_ops->interrupt_service_routine(ha, leg_int_ptr);
1325*4882a593Smuzhiyun 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
1326*4882a593Smuzhiyun 
1327*4882a593Smuzhiyun 	return IRQ_HANDLED;
1328*4882a593Smuzhiyun }
1329*4882a593Smuzhiyun 
1330*4882a593Smuzhiyun irqreturn_t
qla4_8xxx_msi_handler(int irq,void * dev_id)1331*4882a593Smuzhiyun qla4_8xxx_msi_handler(int irq, void *dev_id)
1332*4882a593Smuzhiyun {
1333*4882a593Smuzhiyun 	struct scsi_qla_host *ha;
1334*4882a593Smuzhiyun 
1335*4882a593Smuzhiyun 	ha = (struct scsi_qla_host *) dev_id;
1336*4882a593Smuzhiyun 	if (!ha) {
1337*4882a593Smuzhiyun 		DEBUG2(printk(KERN_INFO
1338*4882a593Smuzhiyun 		    "qla4xxx: MSIX: Interrupt with NULL host ptr\n"));
1339*4882a593Smuzhiyun 		return IRQ_NONE;
1340*4882a593Smuzhiyun 	}
1341*4882a593Smuzhiyun 
1342*4882a593Smuzhiyun 	ha->isr_count++;
1343*4882a593Smuzhiyun 	/* clear the interrupt */
1344*4882a593Smuzhiyun 	qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
1345*4882a593Smuzhiyun 
1346*4882a593Smuzhiyun 	/* read twice to ensure write is flushed */
1347*4882a593Smuzhiyun 	qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1348*4882a593Smuzhiyun 	qla4_82xx_rd_32(ha, ISR_INT_VECTOR);
1349*4882a593Smuzhiyun 
1350*4882a593Smuzhiyun 	return qla4_8xxx_default_intr_handler(irq, dev_id);
1351*4882a593Smuzhiyun }
1352*4882a593Smuzhiyun 
qla4_83xx_mailbox_intr_handler(int irq,void * dev_id)1353*4882a593Smuzhiyun static irqreturn_t qla4_83xx_mailbox_intr_handler(int irq, void *dev_id)
1354*4882a593Smuzhiyun {
1355*4882a593Smuzhiyun 	struct scsi_qla_host *ha = dev_id;
1356*4882a593Smuzhiyun 	unsigned long flags;
1357*4882a593Smuzhiyun 	uint32_t ival = 0;
1358*4882a593Smuzhiyun 
1359*4882a593Smuzhiyun 	spin_lock_irqsave(&ha->hardware_lock, flags);
1360*4882a593Smuzhiyun 
1361*4882a593Smuzhiyun 	ival = readl(&ha->qla4_83xx_reg->risc_intr);
1362*4882a593Smuzhiyun 	if (ival == 0) {
1363*4882a593Smuzhiyun 		ql4_printk(KERN_INFO, ha,
1364*4882a593Smuzhiyun 			   "%s: It is a spurious mailbox interrupt!\n",
1365*4882a593Smuzhiyun 			   __func__);
1366*4882a593Smuzhiyun 		ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
1367*4882a593Smuzhiyun 		ival &= ~INT_MASK_FW_MB;
1368*4882a593Smuzhiyun 		writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
1369*4882a593Smuzhiyun 		goto exit;
1370*4882a593Smuzhiyun 	}
1371*4882a593Smuzhiyun 
1372*4882a593Smuzhiyun 	qla4xxx_isr_decode_mailbox(ha,
1373*4882a593Smuzhiyun 				   readl(&ha->qla4_83xx_reg->mailbox_out[0]));
1374*4882a593Smuzhiyun 	writel(0, &ha->qla4_83xx_reg->risc_intr);
1375*4882a593Smuzhiyun 	ival = readl(&ha->qla4_83xx_reg->mb_int_mask);
1376*4882a593Smuzhiyun 	ival &= ~INT_MASK_FW_MB;
1377*4882a593Smuzhiyun 	writel(ival, &ha->qla4_83xx_reg->mb_int_mask);
1378*4882a593Smuzhiyun 	ha->isr_count++;
1379*4882a593Smuzhiyun exit:
1380*4882a593Smuzhiyun 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
1381*4882a593Smuzhiyun 	return IRQ_HANDLED;
1382*4882a593Smuzhiyun }
1383*4882a593Smuzhiyun 
1384*4882a593Smuzhiyun /**
1385*4882a593Smuzhiyun  * qla4_8xxx_default_intr_handler - hardware interrupt handler.
1386*4882a593Smuzhiyun  * @irq: Unused
1387*4882a593Smuzhiyun  * @dev_id: Pointer to host adapter structure
1388*4882a593Smuzhiyun  *
1389*4882a593Smuzhiyun  * This interrupt handler is called directly for MSI-X, and
1390*4882a593Smuzhiyun  * called indirectly for MSI.
1391*4882a593Smuzhiyun  **/
1392*4882a593Smuzhiyun irqreturn_t
qla4_8xxx_default_intr_handler(int irq,void * dev_id)1393*4882a593Smuzhiyun qla4_8xxx_default_intr_handler(int irq, void *dev_id)
1394*4882a593Smuzhiyun {
1395*4882a593Smuzhiyun 	struct scsi_qla_host *ha = dev_id;
1396*4882a593Smuzhiyun 	unsigned long   flags;
1397*4882a593Smuzhiyun 	uint32_t intr_status;
1398*4882a593Smuzhiyun 	uint8_t reqs_count = 0;
1399*4882a593Smuzhiyun 
1400*4882a593Smuzhiyun 	if (is_qla8032(ha) || is_qla8042(ha)) {
1401*4882a593Smuzhiyun 		qla4_83xx_mailbox_intr_handler(irq, dev_id);
1402*4882a593Smuzhiyun 	} else {
1403*4882a593Smuzhiyun 		spin_lock_irqsave(&ha->hardware_lock, flags);
1404*4882a593Smuzhiyun 		while (1) {
1405*4882a593Smuzhiyun 			if (!(readl(&ha->qla4_82xx_reg->host_int) &
1406*4882a593Smuzhiyun 			    ISRX_82XX_RISC_INT)) {
1407*4882a593Smuzhiyun 				qla4_82xx_spurious_interrupt(ha, reqs_count);
1408*4882a593Smuzhiyun 				break;
1409*4882a593Smuzhiyun 			}
1410*4882a593Smuzhiyun 
1411*4882a593Smuzhiyun 			intr_status =  readl(&ha->qla4_82xx_reg->host_status);
1412*4882a593Smuzhiyun 			if ((intr_status &
1413*4882a593Smuzhiyun 			    (HSRX_RISC_MB_INT | HSRX_RISC_IOCB_INT)) == 0) {
1414*4882a593Smuzhiyun 				qla4_82xx_spurious_interrupt(ha, reqs_count);
1415*4882a593Smuzhiyun 				break;
1416*4882a593Smuzhiyun 			}
1417*4882a593Smuzhiyun 
1418*4882a593Smuzhiyun 			ha->isp_ops->interrupt_service_routine(ha, intr_status);
1419*4882a593Smuzhiyun 
1420*4882a593Smuzhiyun 			if (++reqs_count == MAX_REQS_SERVICED_PER_INTR)
1421*4882a593Smuzhiyun 				break;
1422*4882a593Smuzhiyun 		}
1423*4882a593Smuzhiyun 		ha->isr_count++;
1424*4882a593Smuzhiyun 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
1425*4882a593Smuzhiyun 	}
1426*4882a593Smuzhiyun 	return IRQ_HANDLED;
1427*4882a593Smuzhiyun }
1428*4882a593Smuzhiyun 
1429*4882a593Smuzhiyun irqreturn_t
qla4_8xxx_msix_rsp_q(int irq,void * dev_id)1430*4882a593Smuzhiyun qla4_8xxx_msix_rsp_q(int irq, void *dev_id)
1431*4882a593Smuzhiyun {
1432*4882a593Smuzhiyun 	struct scsi_qla_host *ha = dev_id;
1433*4882a593Smuzhiyun 	unsigned long flags;
1434*4882a593Smuzhiyun 	int intr_status;
1435*4882a593Smuzhiyun 	uint32_t ival = 0;
1436*4882a593Smuzhiyun 
1437*4882a593Smuzhiyun 	spin_lock_irqsave(&ha->hardware_lock, flags);
1438*4882a593Smuzhiyun 	if (is_qla8032(ha) || is_qla8042(ha)) {
1439*4882a593Smuzhiyun 		ival = readl(&ha->qla4_83xx_reg->iocb_int_mask);
1440*4882a593Smuzhiyun 		if (ival == 0) {
1441*4882a593Smuzhiyun 			ql4_printk(KERN_INFO, ha, "%s: It is a spurious iocb interrupt!\n",
1442*4882a593Smuzhiyun 				   __func__);
1443*4882a593Smuzhiyun 			goto exit_msix_rsp_q;
1444*4882a593Smuzhiyun 		}
1445*4882a593Smuzhiyun 		qla4xxx_process_response_queue(ha);
1446*4882a593Smuzhiyun 		writel(0, &ha->qla4_83xx_reg->iocb_int_mask);
1447*4882a593Smuzhiyun 	} else {
1448*4882a593Smuzhiyun 		intr_status = readl(&ha->qla4_82xx_reg->host_status);
1449*4882a593Smuzhiyun 		if (intr_status & HSRX_RISC_IOCB_INT) {
1450*4882a593Smuzhiyun 			qla4xxx_process_response_queue(ha);
1451*4882a593Smuzhiyun 			writel(0, &ha->qla4_82xx_reg->host_int);
1452*4882a593Smuzhiyun 		} else {
1453*4882a593Smuzhiyun 			ql4_printk(KERN_INFO, ha, "%s: spurious iocb interrupt...\n",
1454*4882a593Smuzhiyun 				   __func__);
1455*4882a593Smuzhiyun 			goto exit_msix_rsp_q;
1456*4882a593Smuzhiyun 		}
1457*4882a593Smuzhiyun 	}
1458*4882a593Smuzhiyun 	ha->isr_count++;
1459*4882a593Smuzhiyun exit_msix_rsp_q:
1460*4882a593Smuzhiyun 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
1461*4882a593Smuzhiyun 	return IRQ_HANDLED;
1462*4882a593Smuzhiyun }
1463*4882a593Smuzhiyun 
1464*4882a593Smuzhiyun /**
1465*4882a593Smuzhiyun  * qla4xxx_process_aen - processes AENs generated by firmware
1466*4882a593Smuzhiyun  * @ha: pointer to host adapter structure.
1467*4882a593Smuzhiyun  * @process_aen: type of AENs to process
1468*4882a593Smuzhiyun  *
1469*4882a593Smuzhiyun  * Processes specific types of Asynchronous Events generated by firmware.
1470*4882a593Smuzhiyun  * The type of AENs to process is specified by process_aen and can be
1471*4882a593Smuzhiyun  *	PROCESS_ALL_AENS	 0
1472*4882a593Smuzhiyun  *	FLUSH_DDB_CHANGED_AENS	 1
1473*4882a593Smuzhiyun  *	RELOGIN_DDB_CHANGED_AENS 2
1474*4882a593Smuzhiyun  **/
qla4xxx_process_aen(struct scsi_qla_host * ha,uint8_t process_aen)1475*4882a593Smuzhiyun void qla4xxx_process_aen(struct scsi_qla_host * ha, uint8_t process_aen)
1476*4882a593Smuzhiyun {
1477*4882a593Smuzhiyun 	uint32_t mbox_sts[MBOX_AEN_REG_COUNT];
1478*4882a593Smuzhiyun 	struct aen *aen;
1479*4882a593Smuzhiyun 	int i;
1480*4882a593Smuzhiyun 	unsigned long flags;
1481*4882a593Smuzhiyun 
1482*4882a593Smuzhiyun 	spin_lock_irqsave(&ha->hardware_lock, flags);
1483*4882a593Smuzhiyun 	while (ha->aen_out != ha->aen_in) {
1484*4882a593Smuzhiyun 		aen = &ha->aen_q[ha->aen_out];
1485*4882a593Smuzhiyun 		/* copy aen information to local structure */
1486*4882a593Smuzhiyun 		for (i = 0; i < MBOX_AEN_REG_COUNT; i++)
1487*4882a593Smuzhiyun 			mbox_sts[i] = aen->mbox_sts[i];
1488*4882a593Smuzhiyun 
1489*4882a593Smuzhiyun 		ha->aen_q_count++;
1490*4882a593Smuzhiyun 		ha->aen_out++;
1491*4882a593Smuzhiyun 
1492*4882a593Smuzhiyun 		if (ha->aen_out == MAX_AEN_ENTRIES)
1493*4882a593Smuzhiyun 			ha->aen_out = 0;
1494*4882a593Smuzhiyun 
1495*4882a593Smuzhiyun 		spin_unlock_irqrestore(&ha->hardware_lock, flags);
1496*4882a593Smuzhiyun 
1497*4882a593Smuzhiyun 		DEBUG2(printk("qla4xxx(%ld): AEN[%d]=0x%08x, mbx1=0x%08x mbx2=0x%08x"
1498*4882a593Smuzhiyun 			" mbx3=0x%08x mbx4=0x%08x\n", ha->host_no,
1499*4882a593Smuzhiyun 			(ha->aen_out ? (ha->aen_out-1): (MAX_AEN_ENTRIES-1)),
1500*4882a593Smuzhiyun 			mbox_sts[0], mbox_sts[1], mbox_sts[2],
1501*4882a593Smuzhiyun 			mbox_sts[3], mbox_sts[4]));
1502*4882a593Smuzhiyun 
1503*4882a593Smuzhiyun 		switch (mbox_sts[0]) {
1504*4882a593Smuzhiyun 		case MBOX_ASTS_DATABASE_CHANGED:
1505*4882a593Smuzhiyun 			switch (process_aen) {
1506*4882a593Smuzhiyun 			case FLUSH_DDB_CHANGED_AENS:
1507*4882a593Smuzhiyun 				DEBUG2(printk("scsi%ld: AEN[%d] %04x, index "
1508*4882a593Smuzhiyun 					      "[%d] state=%04x FLUSHED!\n",
1509*4882a593Smuzhiyun 					      ha->host_no, ha->aen_out,
1510*4882a593Smuzhiyun 					      mbox_sts[0], mbox_sts[2],
1511*4882a593Smuzhiyun 					      mbox_sts[3]));
1512*4882a593Smuzhiyun 				break;
1513*4882a593Smuzhiyun 			case PROCESS_ALL_AENS:
1514*4882a593Smuzhiyun 			default:
1515*4882a593Smuzhiyun 				/* Specific device. */
1516*4882a593Smuzhiyun 				if (mbox_sts[1] == 1)
1517*4882a593Smuzhiyun 					qla4xxx_process_ddb_changed(ha,
1518*4882a593Smuzhiyun 						mbox_sts[2], mbox_sts[3],
1519*4882a593Smuzhiyun 						mbox_sts[4]);
1520*4882a593Smuzhiyun 				break;
1521*4882a593Smuzhiyun 			}
1522*4882a593Smuzhiyun 		}
1523*4882a593Smuzhiyun 		spin_lock_irqsave(&ha->hardware_lock, flags);
1524*4882a593Smuzhiyun 	}
1525*4882a593Smuzhiyun 	spin_unlock_irqrestore(&ha->hardware_lock, flags);
1526*4882a593Smuzhiyun }
1527*4882a593Smuzhiyun 
qla4xxx_request_irqs(struct scsi_qla_host * ha)1528*4882a593Smuzhiyun int qla4xxx_request_irqs(struct scsi_qla_host *ha)
1529*4882a593Smuzhiyun {
1530*4882a593Smuzhiyun 	int ret = 0;
1531*4882a593Smuzhiyun 	int rval = QLA_ERROR;
1532*4882a593Smuzhiyun 
1533*4882a593Smuzhiyun 	if (is_qla40XX(ha))
1534*4882a593Smuzhiyun 		goto try_intx;
1535*4882a593Smuzhiyun 
1536*4882a593Smuzhiyun 	if (ql4xenablemsix == 2) {
1537*4882a593Smuzhiyun 		/* Note: MSI Interrupts not supported for ISP8324 and ISP8042 */
1538*4882a593Smuzhiyun 		if (is_qla8032(ha) || is_qla8042(ha)) {
1539*4882a593Smuzhiyun 			ql4_printk(KERN_INFO, ha, "%s: MSI Interrupts not supported for ISP%04x, Falling back-to INTx mode\n",
1540*4882a593Smuzhiyun 				   __func__, ha->pdev->device);
1541*4882a593Smuzhiyun 			goto try_intx;
1542*4882a593Smuzhiyun 		}
1543*4882a593Smuzhiyun 		goto try_msi;
1544*4882a593Smuzhiyun 	}
1545*4882a593Smuzhiyun 
1546*4882a593Smuzhiyun 	if (ql4xenablemsix == 0 || ql4xenablemsix != 1)
1547*4882a593Smuzhiyun 		goto try_intx;
1548*4882a593Smuzhiyun 
1549*4882a593Smuzhiyun 	/* Trying MSI-X */
1550*4882a593Smuzhiyun 	ret = qla4_8xxx_enable_msix(ha);
1551*4882a593Smuzhiyun 	if (!ret) {
1552*4882a593Smuzhiyun 		DEBUG2(ql4_printk(KERN_INFO, ha,
1553*4882a593Smuzhiyun 		    "MSI-X: Enabled (0x%X).\n", ha->revision_id));
1554*4882a593Smuzhiyun 		goto irq_attached;
1555*4882a593Smuzhiyun 	} else {
1556*4882a593Smuzhiyun 		if (is_qla8032(ha) || is_qla8042(ha)) {
1557*4882a593Smuzhiyun 			ql4_printk(KERN_INFO, ha, "%s: ISP%04x: MSI-X: Falling back-to INTx mode. ret = %d\n",
1558*4882a593Smuzhiyun 				   __func__, ha->pdev->device, ret);
1559*4882a593Smuzhiyun 			goto try_intx;
1560*4882a593Smuzhiyun 		}
1561*4882a593Smuzhiyun 	}
1562*4882a593Smuzhiyun 
1563*4882a593Smuzhiyun 	ql4_printk(KERN_WARNING, ha,
1564*4882a593Smuzhiyun 	    "MSI-X: Falling back-to MSI mode -- %d.\n", ret);
1565*4882a593Smuzhiyun 
1566*4882a593Smuzhiyun try_msi:
1567*4882a593Smuzhiyun 	/* Trying MSI */
1568*4882a593Smuzhiyun 	ret = pci_alloc_irq_vectors(ha->pdev, 1, 1, PCI_IRQ_MSI);
1569*4882a593Smuzhiyun 	if (ret > 0) {
1570*4882a593Smuzhiyun 		ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
1571*4882a593Smuzhiyun 			0, DRIVER_NAME, ha);
1572*4882a593Smuzhiyun 		if (!ret) {
1573*4882a593Smuzhiyun 			DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1574*4882a593Smuzhiyun 			goto irq_attached;
1575*4882a593Smuzhiyun 		} else {
1576*4882a593Smuzhiyun 			ql4_printk(KERN_WARNING, ha,
1577*4882a593Smuzhiyun 			    "MSI: Failed to reserve interrupt %d "
1578*4882a593Smuzhiyun 			    "already in use.\n", ha->pdev->irq);
1579*4882a593Smuzhiyun 			pci_free_irq_vectors(ha->pdev);
1580*4882a593Smuzhiyun 		}
1581*4882a593Smuzhiyun 	}
1582*4882a593Smuzhiyun 
1583*4882a593Smuzhiyun try_intx:
1584*4882a593Smuzhiyun 	if (is_qla8022(ha)) {
1585*4882a593Smuzhiyun 		ql4_printk(KERN_WARNING, ha, "%s: ISP82xx Legacy interrupt not supported\n",
1586*4882a593Smuzhiyun 			   __func__);
1587*4882a593Smuzhiyun 		goto irq_not_attached;
1588*4882a593Smuzhiyun 	}
1589*4882a593Smuzhiyun 
1590*4882a593Smuzhiyun 	/* Trying INTx */
1591*4882a593Smuzhiyun 	ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
1592*4882a593Smuzhiyun 	    IRQF_SHARED, DRIVER_NAME, ha);
1593*4882a593Smuzhiyun 	if (!ret) {
1594*4882a593Smuzhiyun 		DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
1595*4882a593Smuzhiyun 		goto irq_attached;
1596*4882a593Smuzhiyun 
1597*4882a593Smuzhiyun 	} else {
1598*4882a593Smuzhiyun 		ql4_printk(KERN_WARNING, ha,
1599*4882a593Smuzhiyun 		    "INTx: Failed to reserve interrupt %d already in"
1600*4882a593Smuzhiyun 		    " use.\n", ha->pdev->irq);
1601*4882a593Smuzhiyun 		goto irq_not_attached;
1602*4882a593Smuzhiyun 	}
1603*4882a593Smuzhiyun 
1604*4882a593Smuzhiyun irq_attached:
1605*4882a593Smuzhiyun 	set_bit(AF_IRQ_ATTACHED, &ha->flags);
1606*4882a593Smuzhiyun 	ha->host->irq = ha->pdev->irq;
1607*4882a593Smuzhiyun 	ql4_printk(KERN_INFO, ha, "%s: irq %d attached\n",
1608*4882a593Smuzhiyun 		   __func__, ha->pdev->irq);
1609*4882a593Smuzhiyun 	rval = QLA_SUCCESS;
1610*4882a593Smuzhiyun irq_not_attached:
1611*4882a593Smuzhiyun 	return rval;
1612*4882a593Smuzhiyun }
1613*4882a593Smuzhiyun 
qla4xxx_free_irqs(struct scsi_qla_host * ha)1614*4882a593Smuzhiyun void qla4xxx_free_irqs(struct scsi_qla_host *ha)
1615*4882a593Smuzhiyun {
1616*4882a593Smuzhiyun 	if (!test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
1617*4882a593Smuzhiyun 		return;
1618*4882a593Smuzhiyun 
1619*4882a593Smuzhiyun 	if (ha->pdev->msix_enabled)
1620*4882a593Smuzhiyun 		free_irq(pci_irq_vector(ha->pdev, 1), ha);
1621*4882a593Smuzhiyun 	free_irq(pci_irq_vector(ha->pdev, 0), ha);
1622*4882a593Smuzhiyun 	pci_free_irq_vectors(ha->pdev);
1623*4882a593Smuzhiyun }
1624