]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fa90c54f AV |
2 | * QLogic Fibre Channel HBA Driver |
3 | * Copyright (c) 2003-2005 QLogic Corporation | |
1da177e4 | 4 | * |
fa90c54f | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
1da177e4 LT |
6 | */ |
7 | #include "qla_def.h" | |
8 | ||
df7baa50 AV |
9 | #include <scsi/scsi_tcq.h> |
10 | ||
1da177e4 | 11 | static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t); |
9a853f71 | 12 | static void qla2x00_async_event(scsi_qla_host_t *, uint16_t *); |
1da177e4 | 13 | static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t); |
9a853f71 | 14 | static void qla2x00_status_entry(scsi_qla_host_t *, void *); |
1da177e4 LT |
15 | static void qla2x00_status_cont_entry(scsi_qla_host_t *, sts_cont_entry_t *); |
16 | static void qla2x00_error_entry(scsi_qla_host_t *, sts_entry_t *); | |
17 | static void qla2x00_ms_entry(scsi_qla_host_t *, ms_iocb_entry_t *); | |
18 | ||
9a853f71 AV |
19 | static void qla24xx_ms_entry(scsi_qla_host_t *, struct ct_entry_24xx *); |
20 | ||
1da177e4 LT |
21 | /** |
22 | * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200. | |
23 | * @irq: | |
24 | * @dev_id: SCSI driver HA context | |
1da177e4 LT |
25 | * |
26 | * Called by system whenever the host adapter generates an interrupt. | |
27 | * | |
28 | * Returns handled flag. | |
29 | */ | |
30 | irqreturn_t | |
7d12e780 | 31 | qla2100_intr_handler(int irq, void *dev_id) |
1da177e4 LT |
32 | { |
33 | scsi_qla_host_t *ha; | |
3d71644c | 34 | struct device_reg_2xxx __iomem *reg; |
1da177e4 LT |
35 | int status; |
36 | unsigned long flags; | |
37 | unsigned long iter; | |
9a853f71 | 38 | uint16_t mb[4]; |
1da177e4 LT |
39 | |
40 | ha = (scsi_qla_host_t *) dev_id; | |
41 | if (!ha) { | |
42 | printk(KERN_INFO | |
43 | "%s(): NULL host pointer\n", __func__); | |
44 | return (IRQ_NONE); | |
45 | } | |
46 | ||
3d71644c | 47 | reg = &ha->iobase->isp; |
1da177e4 LT |
48 | status = 0; |
49 | ||
50 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
51 | for (iter = 50; iter--; ) { | |
52 | if ((RD_REG_WORD(®->istatus) & ISR_RISC_INT) == 0) | |
53 | break; | |
54 | ||
55 | if (RD_REG_WORD(®->semaphore) & BIT_0) { | |
56 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
57 | RD_REG_WORD(®->hccr); | |
58 | ||
59 | /* Get mailbox data. */ | |
9a853f71 AV |
60 | mb[0] = RD_MAILBOX_REG(ha, reg, 0); |
61 | if (mb[0] > 0x3fff && mb[0] < 0x8000) { | |
62 | qla2x00_mbx_completion(ha, mb[0]); | |
1da177e4 | 63 | status |= MBX_INTERRUPT; |
9a853f71 AV |
64 | } else if (mb[0] > 0x7fff && mb[0] < 0xc000) { |
65 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | |
66 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
67 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | |
68 | qla2x00_async_event(ha, mb); | |
1da177e4 LT |
69 | } else { |
70 | /*EMPTY*/ | |
71 | DEBUG2(printk("scsi(%ld): Unrecognized " | |
9a853f71 AV |
72 | "interrupt type (%d).\n", |
73 | ha->host_no, mb[0])); | |
1da177e4 LT |
74 | } |
75 | /* Release mailbox registers. */ | |
76 | WRT_REG_WORD(®->semaphore, 0); | |
77 | RD_REG_WORD(®->semaphore); | |
78 | } else { | |
79 | qla2x00_process_response_queue(ha); | |
80 | ||
81 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
82 | RD_REG_WORD(®->hccr); | |
83 | } | |
84 | } | |
85 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
86 | ||
1da177e4 LT |
87 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
88 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
89 | spin_lock_irqsave(&ha->mbx_reg_lock, flags); | |
90 | ||
91 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); | |
92 | up(&ha->mbx_intr_sem); | |
93 | ||
94 | spin_unlock_irqrestore(&ha->mbx_reg_lock, flags); | |
95 | } | |
96 | ||
1da177e4 LT |
97 | return (IRQ_HANDLED); |
98 | } | |
99 | ||
100 | /** | |
101 | * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. | |
102 | * @irq: | |
103 | * @dev_id: SCSI driver HA context | |
1da177e4 LT |
104 | * |
105 | * Called by system whenever the host adapter generates an interrupt. | |
106 | * | |
107 | * Returns handled flag. | |
108 | */ | |
109 | irqreturn_t | |
7d12e780 | 110 | qla2300_intr_handler(int irq, void *dev_id) |
1da177e4 LT |
111 | { |
112 | scsi_qla_host_t *ha; | |
3d71644c | 113 | struct device_reg_2xxx __iomem *reg; |
1da177e4 LT |
114 | int status; |
115 | unsigned long flags; | |
116 | unsigned long iter; | |
117 | uint32_t stat; | |
1da177e4 | 118 | uint16_t hccr; |
9a853f71 | 119 | uint16_t mb[4]; |
1da177e4 LT |
120 | |
121 | ha = (scsi_qla_host_t *) dev_id; | |
122 | if (!ha) { | |
123 | printk(KERN_INFO | |
124 | "%s(): NULL host pointer\n", __func__); | |
125 | return (IRQ_NONE); | |
126 | } | |
127 | ||
3d71644c | 128 | reg = &ha->iobase->isp; |
1da177e4 LT |
129 | status = 0; |
130 | ||
131 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
132 | for (iter = 50; iter--; ) { | |
133 | stat = RD_REG_DWORD(®->u.isp2300.host_status); | |
134 | if (stat & HSR_RISC_PAUSED) { | |
135 | hccr = RD_REG_WORD(®->hccr); | |
136 | if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8)) | |
137 | qla_printk(KERN_INFO, ha, | |
138 | "Parity error -- HCCR=%x.\n", hccr); | |
139 | else | |
140 | qla_printk(KERN_INFO, ha, | |
9a853f71 | 141 | "RISC paused -- HCCR=%x.\n", hccr); |
1da177e4 LT |
142 | |
143 | /* | |
144 | * Issue a "HARD" reset in order for the RISC | |
145 | * interrupt bit to be cleared. Schedule a big | |
146 | * hammmer to get out of the RISC PAUSED state. | |
147 | */ | |
148 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | |
149 | RD_REG_WORD(®->hccr); | |
150 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
151 | break; | |
152 | } else if ((stat & HSR_RISC_INT) == 0) | |
153 | break; | |
154 | ||
1da177e4 | 155 | switch (stat & 0xff) { |
1da177e4 LT |
156 | case 0x1: |
157 | case 0x2: | |
158 | case 0x10: | |
159 | case 0x11: | |
9a853f71 | 160 | qla2x00_mbx_completion(ha, MSW(stat)); |
1da177e4 LT |
161 | status |= MBX_INTERRUPT; |
162 | ||
163 | /* Release mailbox registers. */ | |
164 | WRT_REG_WORD(®->semaphore, 0); | |
165 | break; | |
166 | case 0x12: | |
9a853f71 AV |
167 | mb[0] = MSW(stat); |
168 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | |
169 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
170 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | |
171 | qla2x00_async_event(ha, mb); | |
172 | break; | |
173 | case 0x13: | |
174 | qla2x00_process_response_queue(ha); | |
1da177e4 LT |
175 | break; |
176 | case 0x15: | |
9a853f71 AV |
177 | mb[0] = MBA_CMPLT_1_16BIT; |
178 | mb[1] = MSW(stat); | |
179 | qla2x00_async_event(ha, mb); | |
1da177e4 LT |
180 | break; |
181 | case 0x16: | |
9a853f71 AV |
182 | mb[0] = MBA_SCSI_COMPLETION; |
183 | mb[1] = MSW(stat); | |
184 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
185 | qla2x00_async_event(ha, mb); | |
1da177e4 LT |
186 | break; |
187 | default: | |
188 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " | |
9a853f71 | 189 | "(%d).\n", |
1da177e4 LT |
190 | ha->host_no, stat & 0xff)); |
191 | break; | |
192 | } | |
193 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | |
194 | RD_REG_WORD_RELAXED(®->hccr); | |
195 | } | |
196 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
197 | ||
1da177e4 LT |
198 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && |
199 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
200 | spin_lock_irqsave(&ha->mbx_reg_lock, flags); | |
201 | ||
202 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); | |
203 | up(&ha->mbx_intr_sem); | |
204 | ||
205 | spin_unlock_irqrestore(&ha->mbx_reg_lock, flags); | |
206 | } | |
207 | ||
1da177e4 LT |
208 | return (IRQ_HANDLED); |
209 | } | |
210 | ||
211 | /** | |
212 | * qla2x00_mbx_completion() - Process mailbox command completions. | |
213 | * @ha: SCSI driver HA context | |
214 | * @mb0: Mailbox0 register | |
215 | */ | |
216 | static void | |
217 | qla2x00_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0) | |
218 | { | |
219 | uint16_t cnt; | |
220 | uint16_t __iomem *wptr; | |
3d71644c | 221 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
222 | |
223 | /* Load return mailbox registers. */ | |
224 | ha->flags.mbox_int = 1; | |
225 | ha->mailbox_out[0] = mb0; | |
226 | wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 1); | |
227 | ||
228 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { | |
fa2a1ce5 | 229 | if (IS_QLA2200(ha) && cnt == 8) |
1da177e4 LT |
230 | wptr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8); |
231 | if (cnt == 4 || cnt == 5) | |
232 | ha->mailbox_out[cnt] = qla2x00_debounce_register(wptr); | |
233 | else | |
234 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); | |
fa2a1ce5 | 235 | |
1da177e4 LT |
236 | wptr++; |
237 | } | |
238 | ||
239 | if (ha->mcp) { | |
240 | DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n", | |
241 | __func__, ha->host_no, ha->mcp->mb[0])); | |
242 | } else { | |
243 | DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n", | |
244 | __func__, ha->host_no)); | |
245 | } | |
246 | } | |
247 | ||
248 | /** | |
249 | * qla2x00_async_event() - Process aynchronous events. | |
250 | * @ha: SCSI driver HA context | |
9a853f71 | 251 | * @mb: Mailbox registers (0 - 3) |
1da177e4 LT |
252 | */ |
253 | static void | |
9a853f71 | 254 | qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb) |
1da177e4 | 255 | { |
9a853f71 AV |
256 | #define LS_UNKNOWN 2 |
257 | static char *link_speeds[5] = { "1", "2", "?", "4", "10" }; | |
1da177e4 | 258 | char *link_speed; |
1da177e4 LT |
259 | uint16_t handle_cnt; |
260 | uint16_t cnt; | |
261 | uint32_t handles[5]; | |
3d71644c | 262 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
263 | uint32_t rscn_entry, host_pid; |
264 | uint8_t rscn_queue_index; | |
265 | ||
266 | /* Setup to process RIO completion. */ | |
267 | handle_cnt = 0; | |
1da177e4 LT |
268 | switch (mb[0]) { |
269 | case MBA_SCSI_COMPLETION: | |
9a853f71 | 270 | handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1])); |
1da177e4 LT |
271 | handle_cnt = 1; |
272 | break; | |
273 | case MBA_CMPLT_1_16BIT: | |
9a853f71 | 274 | handles[0] = mb[1]; |
1da177e4 LT |
275 | handle_cnt = 1; |
276 | mb[0] = MBA_SCSI_COMPLETION; | |
277 | break; | |
278 | case MBA_CMPLT_2_16BIT: | |
9a853f71 AV |
279 | handles[0] = mb[1]; |
280 | handles[1] = mb[2]; | |
1da177e4 LT |
281 | handle_cnt = 2; |
282 | mb[0] = MBA_SCSI_COMPLETION; | |
283 | break; | |
284 | case MBA_CMPLT_3_16BIT: | |
9a853f71 AV |
285 | handles[0] = mb[1]; |
286 | handles[1] = mb[2]; | |
287 | handles[2] = mb[3]; | |
1da177e4 LT |
288 | handle_cnt = 3; |
289 | mb[0] = MBA_SCSI_COMPLETION; | |
290 | break; | |
291 | case MBA_CMPLT_4_16BIT: | |
9a853f71 AV |
292 | handles[0] = mb[1]; |
293 | handles[1] = mb[2]; | |
294 | handles[2] = mb[3]; | |
1da177e4 LT |
295 | handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6); |
296 | handle_cnt = 4; | |
297 | mb[0] = MBA_SCSI_COMPLETION; | |
298 | break; | |
299 | case MBA_CMPLT_5_16BIT: | |
9a853f71 AV |
300 | handles[0] = mb[1]; |
301 | handles[1] = mb[2]; | |
302 | handles[2] = mb[3]; | |
1da177e4 LT |
303 | handles[3] = (uint32_t)RD_MAILBOX_REG(ha, reg, 6); |
304 | handles[4] = (uint32_t)RD_MAILBOX_REG(ha, reg, 7); | |
305 | handle_cnt = 5; | |
306 | mb[0] = MBA_SCSI_COMPLETION; | |
307 | break; | |
308 | case MBA_CMPLT_2_32BIT: | |
9a853f71 | 309 | handles[0] = le32_to_cpu((uint32_t)((mb[2] << 16) | mb[1])); |
1da177e4 LT |
310 | handles[1] = le32_to_cpu( |
311 | ((uint32_t)(RD_MAILBOX_REG(ha, reg, 7) << 16)) | | |
312 | RD_MAILBOX_REG(ha, reg, 6)); | |
313 | handle_cnt = 2; | |
314 | mb[0] = MBA_SCSI_COMPLETION; | |
315 | break; | |
316 | default: | |
317 | break; | |
318 | } | |
319 | ||
320 | switch (mb[0]) { | |
321 | case MBA_SCSI_COMPLETION: /* Fast Post */ | |
322 | if (!ha->flags.online) | |
323 | break; | |
324 | ||
325 | for (cnt = 0; cnt < handle_cnt; cnt++) | |
326 | qla2x00_process_completed_request(ha, handles[cnt]); | |
327 | break; | |
328 | ||
329 | case MBA_RESET: /* Reset */ | |
330 | DEBUG2(printk("scsi(%ld): Asynchronous RESET.\n", ha->host_no)); | |
331 | ||
332 | set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); | |
333 | break; | |
334 | ||
335 | case MBA_SYSTEM_ERR: /* System Error */ | |
336 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | |
337 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | |
338 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | |
339 | ||
340 | qla_printk(KERN_INFO, ha, | |
341 | "ISP System Error - mbx1=%xh mbx2=%xh mbx3=%xh.\n", | |
342 | mb[1], mb[2], mb[3]); | |
343 | ||
abbd8870 | 344 | ha->isp_ops.fw_dump(ha, 1); |
1da177e4 | 345 | |
044cc6c8 | 346 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
9a853f71 AV |
347 | if (mb[1] == 0 && mb[2] == 0) { |
348 | qla_printk(KERN_ERR, ha, | |
349 | "Unrecoverable Hardware Error: adapter " | |
350 | "marked OFFLINE!\n"); | |
351 | ha->flags.online = 0; | |
352 | } else | |
353 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
354 | } else if (mb[1] == 0) { | |
1da177e4 LT |
355 | qla_printk(KERN_INFO, ha, |
356 | "Unrecoverable Hardware Error: adapter marked " | |
357 | "OFFLINE!\n"); | |
358 | ha->flags.online = 0; | |
359 | } else | |
360 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
361 | break; | |
362 | ||
363 | case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */ | |
364 | DEBUG2(printk("scsi(%ld): ISP Request Transfer Error.\n", | |
365 | ha->host_no)); | |
366 | qla_printk(KERN_WARNING, ha, "ISP Request Transfer Error.\n"); | |
367 | ||
368 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
369 | break; | |
370 | ||
371 | case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */ | |
372 | DEBUG2(printk("scsi(%ld): ISP Response Transfer Error.\n", | |
373 | ha->host_no)); | |
374 | qla_printk(KERN_WARNING, ha, "ISP Response Transfer Error.\n"); | |
375 | ||
376 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
377 | break; | |
378 | ||
379 | case MBA_WAKEUP_THRES: /* Request Queue Wake-up */ | |
380 | DEBUG2(printk("scsi(%ld): Asynchronous WAKEUP_THRES.\n", | |
381 | ha->host_no)); | |
382 | break; | |
383 | ||
384 | case MBA_LIP_OCCURRED: /* Loop Initialization Procedure */ | |
1da177e4 LT |
385 | DEBUG2(printk("scsi(%ld): LIP occured (%x).\n", ha->host_no, |
386 | mb[1])); | |
387 | qla_printk(KERN_INFO, ha, "LIP occured (%x).\n", mb[1]); | |
388 | ||
389 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { | |
390 | atomic_set(&ha->loop_state, LOOP_DOWN); | |
391 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); | |
d97994dc | 392 | qla2x00_mark_all_devices_lost(ha, 1); |
1da177e4 LT |
393 | } |
394 | ||
395 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); | |
396 | ||
397 | ha->flags.management_server_logged_in = 0; | |
1da177e4 LT |
398 | break; |
399 | ||
400 | case MBA_LOOP_UP: /* Loop Up Event */ | |
1da177e4 LT |
401 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
402 | link_speed = link_speeds[0]; | |
d8b45213 | 403 | ha->link_data_rate = PORT_SPEED_1GB; |
1da177e4 | 404 | } else { |
9a853f71 | 405 | link_speed = link_speeds[LS_UNKNOWN]; |
1da177e4 LT |
406 | if (mb[1] < 5) |
407 | link_speed = link_speeds[mb[1]]; | |
408 | ha->link_data_rate = mb[1]; | |
409 | } | |
410 | ||
411 | DEBUG2(printk("scsi(%ld): Asynchronous LOOP UP (%s Gbps).\n", | |
412 | ha->host_no, link_speed)); | |
413 | qla_printk(KERN_INFO, ha, "LOOP UP detected (%s Gbps).\n", | |
414 | link_speed); | |
415 | ||
416 | ha->flags.management_server_logged_in = 0; | |
1da177e4 LT |
417 | break; |
418 | ||
419 | case MBA_LOOP_DOWN: /* Loop Down Event */ | |
9a853f71 AV |
420 | DEBUG2(printk("scsi(%ld): Asynchronous LOOP DOWN (%x).\n", |
421 | ha->host_no, mb[1])); | |
422 | qla_printk(KERN_INFO, ha, "LOOP DOWN detected (%x).\n", mb[1]); | |
1da177e4 LT |
423 | |
424 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { | |
425 | atomic_set(&ha->loop_state, LOOP_DOWN); | |
426 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); | |
427 | ha->device_flags |= DFLG_NO_CABLE; | |
d97994dc | 428 | qla2x00_mark_all_devices_lost(ha, 1); |
1da177e4 LT |
429 | } |
430 | ||
431 | ha->flags.management_server_logged_in = 0; | |
d8b45213 | 432 | ha->link_data_rate = PORT_SPEED_UNKNOWN; |
cca5335c AV |
433 | if (ql2xfdmienable) |
434 | set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags); | |
1da177e4 LT |
435 | break; |
436 | ||
437 | case MBA_LIP_RESET: /* LIP reset occurred */ | |
1da177e4 LT |
438 | DEBUG2(printk("scsi(%ld): Asynchronous LIP RESET (%x).\n", |
439 | ha->host_no, mb[1])); | |
440 | qla_printk(KERN_INFO, ha, | |
441 | "LIP reset occured (%x).\n", mb[1]); | |
442 | ||
443 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { | |
444 | atomic_set(&ha->loop_state, LOOP_DOWN); | |
445 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); | |
d97994dc | 446 | qla2x00_mark_all_devices_lost(ha, 1); |
1da177e4 LT |
447 | } |
448 | ||
449 | set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); | |
450 | ||
451 | ha->operating_mode = LOOP; | |
452 | ha->flags.management_server_logged_in = 0; | |
1da177e4 LT |
453 | break; |
454 | ||
455 | case MBA_POINT_TO_POINT: /* Point-to-Point */ | |
456 | if (IS_QLA2100(ha)) | |
457 | break; | |
458 | ||
459 | DEBUG2(printk("scsi(%ld): Asynchronous P2P MODE received.\n", | |
460 | ha->host_no)); | |
461 | ||
462 | /* | |
463 | * Until there's a transition from loop down to loop up, treat | |
464 | * this as loop down only. | |
465 | */ | |
466 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { | |
467 | atomic_set(&ha->loop_state, LOOP_DOWN); | |
468 | if (!atomic_read(&ha->loop_down_timer)) | |
469 | atomic_set(&ha->loop_down_timer, | |
470 | LOOP_DOWN_TIME); | |
d97994dc | 471 | qla2x00_mark_all_devices_lost(ha, 1); |
1da177e4 LT |
472 | } |
473 | ||
474 | if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) { | |
475 | set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); | |
476 | } | |
477 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); | |
478 | break; | |
479 | ||
480 | case MBA_CHG_IN_CONNECTION: /* Change in connection mode */ | |
481 | if (IS_QLA2100(ha)) | |
482 | break; | |
483 | ||
1da177e4 LT |
484 | DEBUG2(printk("scsi(%ld): Asynchronous Change In Connection " |
485 | "received.\n", | |
486 | ha->host_no)); | |
487 | qla_printk(KERN_INFO, ha, | |
488 | "Configuration change detected: value=%x.\n", mb[1]); | |
489 | ||
490 | if (atomic_read(&ha->loop_state) != LOOP_DOWN) { | |
fa2a1ce5 | 491 | atomic_set(&ha->loop_state, LOOP_DOWN); |
1da177e4 LT |
492 | if (!atomic_read(&ha->loop_down_timer)) |
493 | atomic_set(&ha->loop_down_timer, | |
494 | LOOP_DOWN_TIME); | |
d97994dc | 495 | qla2x00_mark_all_devices_lost(ha, 1); |
1da177e4 LT |
496 | } |
497 | ||
498 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); | |
499 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); | |
500 | break; | |
501 | ||
502 | case MBA_PORT_UPDATE: /* Port database update */ | |
1da177e4 LT |
503 | /* |
504 | * If PORT UPDATE is global (recieved LIP_OCCURED/LIP_RESET | |
505 | * event etc. earlier indicating loop is down) then process | |
506 | * it. Otherwise ignore it and Wait for RSCN to come in. | |
507 | */ | |
508 | atomic_set(&ha->loop_down_timer, 0); | |
509 | if (atomic_read(&ha->loop_state) != LOOP_DOWN && | |
510 | atomic_read(&ha->loop_state) != LOOP_DEAD) { | |
511 | DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE " | |
9a853f71 AV |
512 | "ignored %04x/%04x/%04x.\n", ha->host_no, mb[1], |
513 | mb[2], mb[3])); | |
1da177e4 LT |
514 | break; |
515 | } | |
516 | ||
517 | DEBUG2(printk("scsi(%ld): Asynchronous PORT UPDATE.\n", | |
518 | ha->host_no)); | |
519 | DEBUG(printk(KERN_INFO | |
9a853f71 AV |
520 | "scsi(%ld): Port database changed %04x %04x %04x.\n", |
521 | ha->host_no, mb[1], mb[2], mb[3])); | |
1da177e4 LT |
522 | |
523 | /* | |
524 | * Mark all devices as missing so we will login again. | |
525 | */ | |
526 | atomic_set(&ha->loop_state, LOOP_UP); | |
527 | ||
d97994dc | 528 | qla2x00_mark_all_devices_lost(ha, 1); |
1da177e4 LT |
529 | |
530 | ha->flags.rscn_queue_overflow = 1; | |
531 | ||
532 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); | |
533 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); | |
1da177e4 LT |
534 | break; |
535 | ||
536 | case MBA_RSCN_UPDATE: /* State Change Registration */ | |
1da177e4 LT |
537 | DEBUG2(printk("scsi(%ld): Asynchronous RSCR UPDATE.\n", |
538 | ha->host_no)); | |
539 | DEBUG(printk(KERN_INFO | |
540 | "scsi(%ld): RSCN database changed -- %04x %04x.\n", | |
541 | ha->host_no, mb[1], mb[2])); | |
542 | ||
543 | rscn_entry = (mb[1] << 16) | mb[2]; | |
544 | host_pid = (ha->d_id.b.domain << 16) | (ha->d_id.b.area << 8) | | |
545 | ha->d_id.b.al_pa; | |
546 | if (rscn_entry == host_pid) { | |
547 | DEBUG(printk(KERN_INFO | |
548 | "scsi(%ld): Ignoring RSCN update to local host " | |
549 | "port ID (%06x)\n", | |
550 | ha->host_no, host_pid)); | |
551 | break; | |
552 | } | |
553 | ||
554 | rscn_queue_index = ha->rscn_in_ptr + 1; | |
555 | if (rscn_queue_index == MAX_RSCN_COUNT) | |
556 | rscn_queue_index = 0; | |
557 | if (rscn_queue_index != ha->rscn_out_ptr) { | |
558 | ha->rscn_queue[ha->rscn_in_ptr] = rscn_entry; | |
559 | ha->rscn_in_ptr = rscn_queue_index; | |
560 | } else { | |
561 | ha->flags.rscn_queue_overflow = 1; | |
562 | } | |
563 | ||
564 | atomic_set(&ha->loop_state, LOOP_UPDATE); | |
565 | atomic_set(&ha->loop_down_timer, 0); | |
566 | ha->flags.management_server_logged_in = 0; | |
567 | ||
568 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); | |
569 | set_bit(RSCN_UPDATE, &ha->dpc_flags); | |
1da177e4 LT |
570 | break; |
571 | ||
572 | /* case MBA_RIO_RESPONSE: */ | |
573 | case MBA_ZIO_RESPONSE: | |
574 | DEBUG2(printk("scsi(%ld): [R|Z]IO update completion.\n", | |
575 | ha->host_no)); | |
576 | DEBUG(printk(KERN_INFO | |
577 | "scsi(%ld): [R|Z]IO update completion.\n", | |
578 | ha->host_no)); | |
579 | ||
044cc6c8 | 580 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
4fdfefe5 AV |
581 | qla24xx_process_response_queue(ha); |
582 | else | |
583 | qla2x00_process_response_queue(ha); | |
1da177e4 | 584 | break; |
9a853f71 AV |
585 | |
586 | case MBA_DISCARD_RND_FRAME: | |
587 | DEBUG2(printk("scsi(%ld): Discard RND Frame -- %04x %04x " | |
588 | "%04x.\n", ha->host_no, mb[1], mb[2], mb[3])); | |
589 | break; | |
45ebeb56 AV |
590 | |
591 | case MBA_TRACE_NOTIFICATION: | |
592 | DEBUG2(printk("scsi(%ld): Trace Notification -- %04x %04x.\n", | |
593 | ha->host_no, mb[1], mb[2])); | |
594 | break; | |
1da177e4 LT |
595 | } |
596 | } | |
597 | ||
df7baa50 AV |
598 | static void |
599 | qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data) | |
600 | { | |
601 | fc_port_t *fcport = data; | |
602 | ||
603 | if (fcport->ha->max_q_depth <= sdev->queue_depth) | |
604 | return; | |
605 | ||
606 | if (sdev->ordered_tags) | |
607 | scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, | |
608 | sdev->queue_depth + 1); | |
609 | else | |
610 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, | |
611 | sdev->queue_depth + 1); | |
612 | ||
613 | fcport->last_ramp_up = jiffies; | |
614 | ||
615 | DEBUG2(qla_printk(KERN_INFO, fcport->ha, | |
616 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n", | |
617 | fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun, | |
618 | sdev->queue_depth)); | |
619 | } | |
620 | ||
621 | static void | |
622 | qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data) | |
623 | { | |
624 | fc_port_t *fcport = data; | |
625 | ||
626 | if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1)) | |
627 | return; | |
628 | ||
629 | DEBUG2(qla_printk(KERN_INFO, fcport->ha, | |
630 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n", | |
631 | fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun, | |
632 | sdev->queue_depth)); | |
633 | } | |
634 | ||
635 | static inline void | |
636 | qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp) | |
637 | { | |
638 | fc_port_t *fcport; | |
639 | struct scsi_device *sdev; | |
640 | ||
641 | sdev = sp->cmd->device; | |
642 | if (sdev->queue_depth >= ha->max_q_depth) | |
643 | return; | |
644 | ||
645 | fcport = sp->fcport; | |
646 | if (time_before(jiffies, | |
647 | fcport->last_ramp_up + ql2xqfullrampup * HZ)) | |
648 | return; | |
649 | if (time_before(jiffies, | |
650 | fcport->last_queue_full + ql2xqfullrampup * HZ)) | |
651 | return; | |
652 | ||
df7baa50 AV |
653 | starget_for_each_device(sdev->sdev_target, fcport, |
654 | qla2x00_adjust_sdev_qdepth_up); | |
df7baa50 AV |
655 | } |
656 | ||
1da177e4 LT |
657 | /** |
658 | * qla2x00_process_completed_request() - Process a Fast Post response. | |
659 | * @ha: SCSI driver HA context | |
660 | * @index: SRB index | |
661 | */ | |
662 | static void | |
663 | qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index) | |
664 | { | |
665 | srb_t *sp; | |
666 | ||
667 | /* Validate handle. */ | |
668 | if (index >= MAX_OUTSTANDING_COMMANDS) { | |
669 | DEBUG2(printk("scsi(%ld): Invalid SCSI completion handle %d.\n", | |
670 | ha->host_no, index)); | |
671 | qla_printk(KERN_WARNING, ha, | |
672 | "Invalid SCSI completion handle %d.\n", index); | |
673 | ||
674 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
675 | return; | |
676 | } | |
677 | ||
678 | sp = ha->outstanding_cmds[index]; | |
679 | if (sp) { | |
680 | /* Free outstanding command slot. */ | |
681 | ha->outstanding_cmds[index] = NULL; | |
682 | ||
1da177e4 LT |
683 | CMD_COMPL_STATUS(sp->cmd) = 0L; |
684 | CMD_SCSI_STATUS(sp->cmd) = 0L; | |
685 | ||
686 | /* Save ISP completion status */ | |
687 | sp->cmd->result = DID_OK << 16; | |
df7baa50 AV |
688 | |
689 | qla2x00_ramp_up_queue_depth(ha, sp); | |
f4f051eb | 690 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
691 | } else { |
692 | DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n", | |
693 | ha->host_no)); | |
694 | qla_printk(KERN_WARNING, ha, | |
695 | "Invalid ISP SCSI completion handle\n"); | |
696 | ||
697 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
698 | } | |
699 | } | |
700 | ||
701 | /** | |
702 | * qla2x00_process_response_queue() - Process response queue entries. | |
703 | * @ha: SCSI driver HA context | |
704 | */ | |
705 | void | |
706 | qla2x00_process_response_queue(struct scsi_qla_host *ha) | |
707 | { | |
3d71644c | 708 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
1da177e4 LT |
709 | sts_entry_t *pkt; |
710 | uint16_t handle_cnt; | |
711 | uint16_t cnt; | |
712 | ||
713 | if (!ha->flags.online) | |
714 | return; | |
715 | ||
716 | while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) { | |
717 | pkt = (sts_entry_t *)ha->response_ring_ptr; | |
718 | ||
719 | ha->rsp_ring_index++; | |
720 | if (ha->rsp_ring_index == ha->response_q_length) { | |
721 | ha->rsp_ring_index = 0; | |
722 | ha->response_ring_ptr = ha->response_ring; | |
723 | } else { | |
724 | ha->response_ring_ptr++; | |
725 | } | |
726 | ||
727 | if (pkt->entry_status != 0) { | |
728 | DEBUG3(printk(KERN_INFO | |
729 | "scsi(%ld): Process error entry.\n", ha->host_no)); | |
730 | ||
731 | qla2x00_error_entry(ha, pkt); | |
732 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
733 | wmb(); | |
734 | continue; | |
735 | } | |
736 | ||
737 | switch (pkt->entry_type) { | |
738 | case STATUS_TYPE: | |
739 | qla2x00_status_entry(ha, pkt); | |
740 | break; | |
741 | case STATUS_TYPE_21: | |
742 | handle_cnt = ((sts21_entry_t *)pkt)->handle_count; | |
743 | for (cnt = 0; cnt < handle_cnt; cnt++) { | |
744 | qla2x00_process_completed_request(ha, | |
745 | ((sts21_entry_t *)pkt)->handle[cnt]); | |
746 | } | |
747 | break; | |
748 | case STATUS_TYPE_22: | |
749 | handle_cnt = ((sts22_entry_t *)pkt)->handle_count; | |
750 | for (cnt = 0; cnt < handle_cnt; cnt++) { | |
751 | qla2x00_process_completed_request(ha, | |
752 | ((sts22_entry_t *)pkt)->handle[cnt]); | |
753 | } | |
754 | break; | |
755 | case STATUS_CONT_TYPE: | |
756 | qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt); | |
757 | break; | |
758 | case MS_IOCB_TYPE: | |
759 | qla2x00_ms_entry(ha, (ms_iocb_entry_t *)pkt); | |
760 | break; | |
1da177e4 LT |
761 | default: |
762 | /* Type Not Supported. */ | |
763 | DEBUG4(printk(KERN_WARNING | |
764 | "scsi(%ld): Received unknown response pkt type %x " | |
765 | "entry status=%x.\n", | |
766 | ha->host_no, pkt->entry_type, pkt->entry_status)); | |
767 | break; | |
768 | } | |
769 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
770 | wmb(); | |
771 | } | |
772 | ||
773 | /* Adjust ring index */ | |
774 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), ha->rsp_ring_index); | |
775 | } | |
776 | ||
777 | /** | |
778 | * qla2x00_status_entry() - Process a Status IOCB entry. | |
779 | * @ha: SCSI driver HA context | |
780 | * @pkt: Entry pointer | |
781 | */ | |
782 | static void | |
9a853f71 | 783 | qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt) |
1da177e4 | 784 | { |
1da177e4 | 785 | srb_t *sp; |
1da177e4 LT |
786 | fc_port_t *fcport; |
787 | struct scsi_cmnd *cp; | |
9a853f71 AV |
788 | sts_entry_t *sts; |
789 | struct sts_entry_24xx *sts24; | |
1da177e4 LT |
790 | uint16_t comp_status; |
791 | uint16_t scsi_status; | |
792 | uint8_t lscsi_status; | |
793 | int32_t resid; | |
ed17c71b | 794 | uint32_t sense_len, rsp_info_len, resid_len, fw_resid_len; |
9a853f71 AV |
795 | uint8_t *rsp_info, *sense_data; |
796 | ||
797 | sts = (sts_entry_t *) pkt; | |
798 | sts24 = (struct sts_entry_24xx *) pkt; | |
044cc6c8 | 799 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
9a853f71 AV |
800 | comp_status = le16_to_cpu(sts24->comp_status); |
801 | scsi_status = le16_to_cpu(sts24->scsi_status) & SS_MASK; | |
802 | } else { | |
803 | comp_status = le16_to_cpu(sts->comp_status); | |
804 | scsi_status = le16_to_cpu(sts->scsi_status) & SS_MASK; | |
805 | } | |
1da177e4 LT |
806 | |
807 | /* Fast path completion. */ | |
9a853f71 AV |
808 | if (comp_status == CS_COMPLETE && scsi_status == 0) { |
809 | qla2x00_process_completed_request(ha, sts->handle); | |
1da177e4 LT |
810 | |
811 | return; | |
812 | } | |
813 | ||
814 | /* Validate handle. */ | |
9a853f71 AV |
815 | if (sts->handle < MAX_OUTSTANDING_COMMANDS) { |
816 | sp = ha->outstanding_cmds[sts->handle]; | |
817 | ha->outstanding_cmds[sts->handle] = NULL; | |
1da177e4 LT |
818 | } else |
819 | sp = NULL; | |
820 | ||
821 | if (sp == NULL) { | |
822 | DEBUG2(printk("scsi(%ld): Status Entry invalid handle.\n", | |
823 | ha->host_no)); | |
824 | qla_printk(KERN_WARNING, ha, "Status Entry invalid handle.\n"); | |
825 | ||
826 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
39a11240 | 827 | qla2xxx_wake_dpc(ha); |
1da177e4 LT |
828 | return; |
829 | } | |
830 | cp = sp->cmd; | |
831 | if (cp == NULL) { | |
832 | DEBUG2(printk("scsi(%ld): Command already returned back to OS " | |
75bc4190 | 833 | "pkt->handle=%d sp=%p.\n", ha->host_no, sts->handle, sp)); |
1da177e4 LT |
834 | qla_printk(KERN_WARNING, ha, |
835 | "Command is NULL: already returned to OS (sp=%p)\n", sp); | |
836 | ||
837 | return; | |
838 | } | |
839 | ||
9a853f71 AV |
840 | lscsi_status = scsi_status & STATUS_MASK; |
841 | CMD_ENTRY_STATUS(cp) = sts->entry_status; | |
1da177e4 LT |
842 | CMD_COMPL_STATUS(cp) = comp_status; |
843 | CMD_SCSI_STATUS(cp) = scsi_status; | |
844 | ||
bdf79621 | 845 | fcport = sp->fcport; |
1da177e4 | 846 | |
ed17c71b | 847 | sense_len = rsp_info_len = resid_len = fw_resid_len = 0; |
044cc6c8 | 848 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
9a853f71 AV |
849 | sense_len = le32_to_cpu(sts24->sense_len); |
850 | rsp_info_len = le32_to_cpu(sts24->rsp_data_len); | |
851 | resid_len = le32_to_cpu(sts24->rsp_residual_count); | |
ed17c71b | 852 | fw_resid_len = le32_to_cpu(sts24->residual_len); |
9a853f71 AV |
853 | rsp_info = sts24->data; |
854 | sense_data = sts24->data; | |
855 | host_to_fcp_swap(sts24->data, sizeof(sts24->data)); | |
856 | } else { | |
857 | sense_len = le16_to_cpu(sts->req_sense_length); | |
858 | rsp_info_len = le16_to_cpu(sts->rsp_info_len); | |
859 | resid_len = le32_to_cpu(sts->residual_length); | |
860 | rsp_info = sts->rsp_info; | |
861 | sense_data = sts->req_sense_data; | |
862 | } | |
863 | ||
1da177e4 LT |
864 | /* Check for any FCP transport errors. */ |
865 | if (scsi_status & SS_RESPONSE_INFO_LEN_VALID) { | |
9a853f71 | 866 | /* Sense data lies beyond any FCP RESPONSE data. */ |
044cc6c8 | 867 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
9a853f71 AV |
868 | sense_data += rsp_info_len; |
869 | if (rsp_info_len > 3 && rsp_info[3]) { | |
1da177e4 LT |
870 | DEBUG2(printk("scsi(%ld:%d:%d:%d) FCP I/O protocol " |
871 | "failure (%x/%02x%02x%02x%02x%02x%02x%02x%02x)..." | |
9a853f71 AV |
872 | "retrying command\n", ha->host_no, |
873 | cp->device->channel, cp->device->id, | |
874 | cp->device->lun, rsp_info_len, rsp_info[0], | |
875 | rsp_info[1], rsp_info[2], rsp_info[3], rsp_info[4], | |
876 | rsp_info[5], rsp_info[6], rsp_info[7])); | |
1da177e4 LT |
877 | |
878 | cp->result = DID_BUS_BUSY << 16; | |
f4f051eb | 879 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
880 | return; |
881 | } | |
882 | } | |
883 | ||
884 | /* | |
885 | * Based on Host and scsi status generate status code for Linux | |
886 | */ | |
887 | switch (comp_status) { | |
888 | case CS_COMPLETE: | |
df7baa50 | 889 | case CS_QUEUE_FULL: |
1da177e4 LT |
890 | if (scsi_status == 0) { |
891 | cp->result = DID_OK << 16; | |
892 | break; | |
893 | } | |
894 | if (scsi_status & (SS_RESIDUAL_UNDER | SS_RESIDUAL_OVER)) { | |
9a853f71 | 895 | resid = resid_len; |
1da177e4 LT |
896 | cp->resid = resid; |
897 | CMD_RESID_LEN(cp) = resid; | |
0da69df1 AV |
898 | |
899 | if (!lscsi_status && | |
900 | ((unsigned)(cp->request_bufflen - resid) < | |
901 | cp->underflow)) { | |
902 | qla_printk(KERN_INFO, ha, | |
903 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " | |
904 | "detected (%x of %x bytes)...returning " | |
905 | "error status.\n", ha->host_no, | |
906 | cp->device->channel, cp->device->id, | |
907 | cp->device->lun, resid, | |
908 | cp->request_bufflen); | |
909 | ||
910 | cp->result = DID_ERROR << 16; | |
911 | break; | |
912 | } | |
1da177e4 | 913 | } |
1da177e4 LT |
914 | cp->result = DID_OK << 16 | lscsi_status; |
915 | ||
df7baa50 AV |
916 | if (lscsi_status == SAM_STAT_TASK_SET_FULL) { |
917 | DEBUG2(printk(KERN_INFO | |
918 | "scsi(%ld): QUEUE FULL status detected " | |
919 | "0x%x-0x%x.\n", ha->host_no, comp_status, | |
920 | scsi_status)); | |
921 | ||
922 | /* Adjust queue depth for all luns on the port. */ | |
923 | fcport->last_queue_full = jiffies; | |
df7baa50 AV |
924 | starget_for_each_device(cp->device->sdev_target, |
925 | fcport, qla2x00_adjust_sdev_qdepth_down); | |
df7baa50 AV |
926 | break; |
927 | } | |
1da177e4 LT |
928 | if (lscsi_status != SS_CHECK_CONDITION) |
929 | break; | |
930 | ||
9a853f71 | 931 | /* Copy Sense Data into sense buffer. */ |
1da177e4 LT |
932 | memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer)); |
933 | ||
934 | if (!(scsi_status & SS_SENSE_LEN_VALID)) | |
935 | break; | |
936 | ||
9a853f71 AV |
937 | if (sense_len >= sizeof(cp->sense_buffer)) |
938 | sense_len = sizeof(cp->sense_buffer); | |
1da177e4 | 939 | |
9a853f71 AV |
940 | CMD_ACTUAL_SNSLEN(cp) = sense_len; |
941 | sp->request_sense_length = sense_len; | |
1da177e4 LT |
942 | sp->request_sense_ptr = cp->sense_buffer; |
943 | ||
944 | if (sp->request_sense_length > 32) | |
9a853f71 | 945 | sense_len = 32; |
1da177e4 | 946 | |
9a853f71 | 947 | memcpy(cp->sense_buffer, sense_data, sense_len); |
1da177e4 | 948 | |
9a853f71 AV |
949 | sp->request_sense_ptr += sense_len; |
950 | sp->request_sense_length -= sense_len; | |
1da177e4 LT |
951 | if (sp->request_sense_length != 0) |
952 | ha->status_srb = sp; | |
953 | ||
1da177e4 | 954 | DEBUG5(printk("%s(): Check condition Sense data, " |
9a853f71 AV |
955 | "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", __func__, |
956 | ha->host_no, cp->device->channel, cp->device->id, | |
957 | cp->device->lun, cp, cp->serial_number)); | |
958 | if (sense_len) | |
1da177e4 LT |
959 | DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, |
960 | CMD_ACTUAL_SNSLEN(cp))); | |
961 | break; | |
962 | ||
963 | case CS_DATA_UNDERRUN: | |
9a853f71 | 964 | resid = resid_len; |
ed17c71b RA |
965 | /* Use F/W calculated residual length. */ |
966 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) | |
967 | resid = fw_resid_len; | |
968 | ||
1da177e4 LT |
969 | if (scsi_status & SS_RESIDUAL_UNDER) { |
970 | cp->resid = resid; | |
971 | CMD_RESID_LEN(cp) = resid; | |
e038a1be AV |
972 | } else { |
973 | DEBUG2(printk(KERN_INFO | |
974 | "scsi(%ld:%d:%d) UNDERRUN status detected " | |
ed17c71b RA |
975 | "0x%x-0x%x. resid=0x%x fw_resid=0x%x cdb=0x%x " |
976 | "os_underflow=0x%x\n", ha->host_no, | |
977 | cp->device->id, cp->device->lun, comp_status, | |
978 | scsi_status, resid_len, resid, cp->cmnd[0], | |
979 | cp->underflow)); | |
e038a1be | 980 | |
1da177e4 LT |
981 | } |
982 | ||
983 | /* | |
fa2a1ce5 | 984 | * Check to see if SCSI Status is non zero. If so report SCSI |
1da177e4 LT |
985 | * Status. |
986 | */ | |
987 | if (lscsi_status != 0) { | |
1da177e4 LT |
988 | cp->result = DID_OK << 16 | lscsi_status; |
989 | ||
990 | if (lscsi_status != SS_CHECK_CONDITION) | |
991 | break; | |
992 | ||
993 | /* Copy Sense Data into sense buffer */ | |
994 | memset(cp->sense_buffer, 0, sizeof(cp->sense_buffer)); | |
995 | ||
996 | if (!(scsi_status & SS_SENSE_LEN_VALID)) | |
997 | break; | |
998 | ||
9a853f71 AV |
999 | if (sense_len >= sizeof(cp->sense_buffer)) |
1000 | sense_len = sizeof(cp->sense_buffer); | |
1da177e4 | 1001 | |
9a853f71 AV |
1002 | CMD_ACTUAL_SNSLEN(cp) = sense_len; |
1003 | sp->request_sense_length = sense_len; | |
1da177e4 LT |
1004 | sp->request_sense_ptr = cp->sense_buffer; |
1005 | ||
fa2a1ce5 | 1006 | if (sp->request_sense_length > 32) |
9a853f71 | 1007 | sense_len = 32; |
1da177e4 | 1008 | |
9a853f71 | 1009 | memcpy(cp->sense_buffer, sense_data, sense_len); |
1da177e4 | 1010 | |
9a853f71 AV |
1011 | sp->request_sense_ptr += sense_len; |
1012 | sp->request_sense_length -= sense_len; | |
1da177e4 LT |
1013 | if (sp->request_sense_length != 0) |
1014 | ha->status_srb = sp; | |
1015 | ||
1da177e4 LT |
1016 | DEBUG5(printk("%s(): Check condition Sense data, " |
1017 | "scsi(%ld:%d:%d:%d) cmd=%p pid=%ld\n", | |
9a853f71 AV |
1018 | __func__, ha->host_no, cp->device->channel, |
1019 | cp->device->id, cp->device->lun, cp, | |
1da177e4 | 1020 | cp->serial_number)); |
9a853f71 AV |
1021 | |
1022 | if (sense_len) | |
1da177e4 LT |
1023 | DEBUG5(qla2x00_dump_buffer(cp->sense_buffer, |
1024 | CMD_ACTUAL_SNSLEN(cp))); | |
1025 | } else { | |
1026 | /* | |
1027 | * If RISC reports underrun and target does not report | |
1028 | * it then we must have a lost frame, so tell upper | |
1029 | * layer to retry it by reporting a bus busy. | |
1030 | */ | |
1031 | if (!(scsi_status & SS_RESIDUAL_UNDER)) { | |
1032 | DEBUG2(printk("scsi(%ld:%d:%d:%d) Dropped " | |
1033 | "frame(s) detected (%x of %x bytes)..." | |
9a853f71 AV |
1034 | "retrying command.\n", ha->host_no, |
1035 | cp->device->channel, cp->device->id, | |
1036 | cp->device->lun, resid, | |
1da177e4 LT |
1037 | cp->request_bufflen)); |
1038 | ||
1039 | cp->result = DID_BUS_BUSY << 16; | |
1da177e4 LT |
1040 | break; |
1041 | } | |
1042 | ||
1043 | /* Handle mid-layer underflow */ | |
1044 | if ((unsigned)(cp->request_bufflen - resid) < | |
1045 | cp->underflow) { | |
1046 | qla_printk(KERN_INFO, ha, | |
1047 | "scsi(%ld:%d:%d:%d): Mid-layer underflow " | |
1048 | "detected (%x of %x bytes)...returning " | |
9a853f71 AV |
1049 | "error status.\n", ha->host_no, |
1050 | cp->device->channel, cp->device->id, | |
1051 | cp->device->lun, resid, | |
1da177e4 LT |
1052 | cp->request_bufflen); |
1053 | ||
1054 | cp->result = DID_ERROR << 16; | |
1055 | break; | |
1056 | } | |
1057 | ||
1058 | /* Everybody online, looking good... */ | |
1059 | cp->result = DID_OK << 16; | |
1060 | } | |
1061 | break; | |
1062 | ||
1063 | case CS_DATA_OVERRUN: | |
1064 | DEBUG2(printk(KERN_INFO | |
1065 | "scsi(%ld:%d:%d): OVERRUN status detected 0x%x-0x%x\n", | |
9a853f71 AV |
1066 | ha->host_no, cp->device->id, cp->device->lun, comp_status, |
1067 | scsi_status)); | |
1da177e4 LT |
1068 | DEBUG2(printk(KERN_INFO |
1069 | "CDB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", | |
1070 | cp->cmnd[0], cp->cmnd[1], cp->cmnd[2], cp->cmnd[3], | |
1071 | cp->cmnd[4], cp->cmnd[5])); | |
1072 | DEBUG2(printk(KERN_INFO | |
1073 | "PID=0x%lx req=0x%x xtra=0x%x -- returning DID_ERROR " | |
1074 | "status!\n", | |
9a853f71 | 1075 | cp->serial_number, cp->request_bufflen, resid_len)); |
1da177e4 LT |
1076 | |
1077 | cp->result = DID_ERROR << 16; | |
1078 | break; | |
1079 | ||
1080 | case CS_PORT_LOGGED_OUT: | |
1081 | case CS_PORT_CONFIG_CHG: | |
1082 | case CS_PORT_BUSY: | |
1083 | case CS_INCOMPLETE: | |
1084 | case CS_PORT_UNAVAILABLE: | |
1085 | /* | |
1086 | * If the port is in Target Down state, return all IOs for this | |
1087 | * Target with DID_NO_CONNECT ELSE Queue the IOs in the | |
1088 | * retry_queue. | |
1089 | */ | |
1da177e4 LT |
1090 | DEBUG2(printk("scsi(%ld:%d:%d): status_entry: Port Down " |
1091 | "pid=%ld, compl status=0x%x, port state=0x%x\n", | |
9a853f71 AV |
1092 | ha->host_no, cp->device->id, cp->device->lun, |
1093 | cp->serial_number, comp_status, | |
1da177e4 LT |
1094 | atomic_read(&fcport->state))); |
1095 | ||
f4f051eb | 1096 | cp->result = DID_BUS_BUSY << 16; |
1da177e4 | 1097 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
d97994dc | 1098 | qla2x00_mark_device_lost(ha, fcport, 1, 1); |
1da177e4 | 1099 | } |
1da177e4 LT |
1100 | break; |
1101 | ||
1102 | case CS_RESET: | |
1103 | DEBUG2(printk(KERN_INFO | |
1104 | "scsi(%ld): RESET status detected 0x%x-0x%x.\n", | |
1105 | ha->host_no, comp_status, scsi_status)); | |
1106 | ||
f4f051eb | 1107 | cp->result = DID_RESET << 16; |
1da177e4 LT |
1108 | break; |
1109 | ||
1110 | case CS_ABORTED: | |
fa2a1ce5 | 1111 | /* |
1da177e4 LT |
1112 | * hv2.19.12 - DID_ABORT does not retry the request if we |
1113 | * aborted this request then abort otherwise it must be a | |
1114 | * reset. | |
1115 | */ | |
1116 | DEBUG2(printk(KERN_INFO | |
1117 | "scsi(%ld): ABORT status detected 0x%x-0x%x.\n", | |
1118 | ha->host_no, comp_status, scsi_status)); | |
1119 | ||
1120 | cp->result = DID_RESET << 16; | |
1121 | break; | |
1122 | ||
1123 | case CS_TIMEOUT: | |
9a853f71 AV |
1124 | cp->result = DID_BUS_BUSY << 16; |
1125 | ||
044cc6c8 | 1126 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
9a853f71 AV |
1127 | DEBUG2(printk(KERN_INFO |
1128 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected " | |
1129 | "0x%x-0x%x\n", ha->host_no, cp->device->channel, | |
1130 | cp->device->id, cp->device->lun, comp_status, | |
1131 | scsi_status)); | |
1132 | break; | |
1133 | } | |
1da177e4 LT |
1134 | DEBUG2(printk(KERN_INFO |
1135 | "scsi(%ld:%d:%d:%d): TIMEOUT status detected 0x%x-0x%x " | |
9a853f71 AV |
1136 | "sflags=%x.\n", ha->host_no, cp->device->channel, |
1137 | cp->device->id, cp->device->lun, comp_status, scsi_status, | |
1138 | le16_to_cpu(sts->status_flags))); | |
1da177e4 | 1139 | |
9a853f71 AV |
1140 | /* Check to see if logout occurred. */ |
1141 | if ((le16_to_cpu(sts->status_flags) & SF_LOGOUT_SENT)) | |
d97994dc | 1142 | qla2x00_mark_device_lost(ha, fcport, 1, 1); |
1da177e4 LT |
1143 | break; |
1144 | ||
1da177e4 LT |
1145 | default: |
1146 | DEBUG3(printk("scsi(%ld): Error detected (unknown status) " | |
9a853f71 | 1147 | "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status)); |
1da177e4 LT |
1148 | qla_printk(KERN_INFO, ha, |
1149 | "Unknown status detected 0x%x-0x%x.\n", | |
1150 | comp_status, scsi_status); | |
1151 | ||
1152 | cp->result = DID_ERROR << 16; | |
1153 | break; | |
1154 | } | |
1155 | ||
1156 | /* Place command on done queue. */ | |
1157 | if (ha->status_srb == NULL) | |
f4f051eb | 1158 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
1159 | } |
1160 | ||
1161 | /** | |
1162 | * qla2x00_status_cont_entry() - Process a Status Continuations entry. | |
1163 | * @ha: SCSI driver HA context | |
1164 | * @pkt: Entry pointer | |
1165 | * | |
1166 | * Extended sense data. | |
1167 | */ | |
1168 | static void | |
1169 | qla2x00_status_cont_entry(scsi_qla_host_t *ha, sts_cont_entry_t *pkt) | |
1170 | { | |
1171 | uint8_t sense_sz = 0; | |
1172 | srb_t *sp = ha->status_srb; | |
1173 | struct scsi_cmnd *cp; | |
1174 | ||
1175 | if (sp != NULL && sp->request_sense_length != 0) { | |
1176 | cp = sp->cmd; | |
1177 | if (cp == NULL) { | |
1178 | DEBUG2(printk("%s(): Cmd already returned back to OS " | |
75bc4190 | 1179 | "sp=%p.\n", __func__, sp)); |
1da177e4 LT |
1180 | qla_printk(KERN_INFO, ha, |
1181 | "cmd is NULL: already returned to OS (sp=%p)\n", | |
fa2a1ce5 | 1182 | sp); |
1da177e4 LT |
1183 | |
1184 | ha->status_srb = NULL; | |
1185 | return; | |
1186 | } | |
1187 | ||
1188 | if (sp->request_sense_length > sizeof(pkt->data)) { | |
1189 | sense_sz = sizeof(pkt->data); | |
1190 | } else { | |
1191 | sense_sz = sp->request_sense_length; | |
1192 | } | |
1193 | ||
1194 | /* Move sense data. */ | |
044cc6c8 | 1195 | if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) |
9a853f71 | 1196 | host_to_fcp_swap(pkt->data, sizeof(pkt->data)); |
1da177e4 LT |
1197 | memcpy(sp->request_sense_ptr, pkt->data, sense_sz); |
1198 | DEBUG5(qla2x00_dump_buffer(sp->request_sense_ptr, sense_sz)); | |
1199 | ||
1200 | sp->request_sense_ptr += sense_sz; | |
1201 | sp->request_sense_length -= sense_sz; | |
1202 | ||
1203 | /* Place command on done queue. */ | |
1204 | if (sp->request_sense_length == 0) { | |
1da177e4 | 1205 | ha->status_srb = NULL; |
f4f051eb | 1206 | qla2x00_sp_compl(ha, sp); |
1da177e4 LT |
1207 | } |
1208 | } | |
1209 | } | |
1210 | ||
1211 | /** | |
1212 | * qla2x00_error_entry() - Process an error entry. | |
1213 | * @ha: SCSI driver HA context | |
1214 | * @pkt: Entry pointer | |
1215 | */ | |
1216 | static void | |
9a853f71 | 1217 | qla2x00_error_entry(scsi_qla_host_t *ha, sts_entry_t *pkt) |
1da177e4 LT |
1218 | { |
1219 | srb_t *sp; | |
1220 | ||
1221 | #if defined(QL_DEBUG_LEVEL_2) | |
1222 | if (pkt->entry_status & RF_INV_E_ORDER) | |
1223 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Order\n", __func__); | |
1224 | else if (pkt->entry_status & RF_INV_E_COUNT) | |
1225 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Count\n", __func__); | |
1226 | else if (pkt->entry_status & RF_INV_E_PARAM) | |
fa2a1ce5 | 1227 | qla_printk(KERN_ERR, ha, |
1da177e4 LT |
1228 | "%s: Invalid Entry Parameter\n", __func__); |
1229 | else if (pkt->entry_status & RF_INV_E_TYPE) | |
1230 | qla_printk(KERN_ERR, ha, "%s: Invalid Entry Type\n", __func__); | |
1231 | else if (pkt->entry_status & RF_BUSY) | |
1232 | qla_printk(KERN_ERR, ha, "%s: Busy\n", __func__); | |
1233 | else | |
1234 | qla_printk(KERN_ERR, ha, "%s: UNKNOWN flag error\n", __func__); | |
1235 | #endif | |
1236 | ||
1237 | /* Validate handle. */ | |
1238 | if (pkt->handle < MAX_OUTSTANDING_COMMANDS) | |
1239 | sp = ha->outstanding_cmds[pkt->handle]; | |
1240 | else | |
1241 | sp = NULL; | |
1242 | ||
1243 | if (sp) { | |
1244 | /* Free outstanding command slot. */ | |
1245 | ha->outstanding_cmds[pkt->handle] = NULL; | |
354d6b21 | 1246 | |
1da177e4 LT |
1247 | /* Bad payload or header */ |
1248 | if (pkt->entry_status & | |
1249 | (RF_INV_E_ORDER | RF_INV_E_COUNT | | |
1250 | RF_INV_E_PARAM | RF_INV_E_TYPE)) { | |
1251 | sp->cmd->result = DID_ERROR << 16; | |
1252 | } else if (pkt->entry_status & RF_BUSY) { | |
1253 | sp->cmd->result = DID_BUS_BUSY << 16; | |
1254 | } else { | |
1255 | sp->cmd->result = DID_ERROR << 16; | |
1256 | } | |
f4f051eb | 1257 | qla2x00_sp_compl(ha, sp); |
1da177e4 | 1258 | |
9a853f71 AV |
1259 | } else if (pkt->entry_type == COMMAND_A64_TYPE || pkt->entry_type == |
1260 | COMMAND_TYPE || pkt->entry_type == COMMAND_TYPE_7) { | |
1da177e4 LT |
1261 | DEBUG2(printk("scsi(%ld): Error entry - invalid handle\n", |
1262 | ha->host_no)); | |
1263 | qla_printk(KERN_WARNING, ha, | |
1264 | "Error entry - invalid handle\n"); | |
1265 | ||
1266 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
39a11240 | 1267 | qla2xxx_wake_dpc(ha); |
1da177e4 LT |
1268 | } |
1269 | } | |
1270 | ||
1271 | /** | |
1272 | * qla2x00_ms_entry() - Process a Management Server entry. | |
1273 | * @ha: SCSI driver HA context | |
1274 | * @index: Response queue out pointer | |
1275 | */ | |
1276 | static void | |
9a853f71 | 1277 | qla2x00_ms_entry(scsi_qla_host_t *ha, ms_iocb_entry_t *pkt) |
1da177e4 LT |
1278 | { |
1279 | srb_t *sp; | |
1280 | ||
1281 | DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n", | |
1282 | __func__, ha->host_no, pkt, pkt->handle1)); | |
1283 | ||
1284 | /* Validate handle. */ | |
1285 | if (pkt->handle1 < MAX_OUTSTANDING_COMMANDS) | |
1286 | sp = ha->outstanding_cmds[pkt->handle1]; | |
1287 | else | |
1288 | sp = NULL; | |
1289 | ||
1290 | if (sp == NULL) { | |
1291 | DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n", | |
1292 | ha->host_no)); | |
1293 | qla_printk(KERN_WARNING, ha, "MS entry - invalid handle\n"); | |
1294 | ||
1295 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
1296 | return; | |
1297 | } | |
1298 | ||
1299 | CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->status); | |
1300 | CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status; | |
1301 | ||
1302 | /* Free outstanding command slot. */ | |
1303 | ha->outstanding_cmds[pkt->handle1] = NULL; | |
1304 | ||
f4f051eb | 1305 | qla2x00_sp_compl(ha, sp); |
1da177e4 | 1306 | } |
9a853f71 AV |
1307 | |
1308 | ||
1309 | /** | |
1310 | * qla24xx_mbx_completion() - Process mailbox command completions. | |
1311 | * @ha: SCSI driver HA context | |
1312 | * @mb0: Mailbox0 register | |
1313 | */ | |
1314 | static void | |
1315 | qla24xx_mbx_completion(scsi_qla_host_t *ha, uint16_t mb0) | |
1316 | { | |
1317 | uint16_t cnt; | |
1318 | uint16_t __iomem *wptr; | |
1319 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | |
1320 | ||
1321 | /* Load return mailbox registers. */ | |
1322 | ha->flags.mbox_int = 1; | |
1323 | ha->mailbox_out[0] = mb0; | |
1324 | wptr = (uint16_t __iomem *)®->mailbox1; | |
1325 | ||
1326 | for (cnt = 1; cnt < ha->mbx_count; cnt++) { | |
1327 | ha->mailbox_out[cnt] = RD_REG_WORD(wptr); | |
1328 | wptr++; | |
1329 | } | |
1330 | ||
1331 | if (ha->mcp) { | |
1332 | DEBUG3(printk("%s(%ld): Got mailbox completion. cmd=%x.\n", | |
1333 | __func__, ha->host_no, ha->mcp->mb[0])); | |
1334 | } else { | |
1335 | DEBUG2_3(printk("%s(%ld): MBX pointer ERROR!\n", | |
1336 | __func__, ha->host_no)); | |
1337 | } | |
1338 | } | |
1339 | ||
1340 | /** | |
1341 | * qla24xx_process_response_queue() - Process response queue entries. | |
1342 | * @ha: SCSI driver HA context | |
1343 | */ | |
1344 | void | |
1345 | qla24xx_process_response_queue(struct scsi_qla_host *ha) | |
1346 | { | |
1347 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | |
1348 | struct sts_entry_24xx *pkt; | |
1349 | ||
1350 | if (!ha->flags.online) | |
1351 | return; | |
1352 | ||
1353 | while (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) { | |
1354 | pkt = (struct sts_entry_24xx *)ha->response_ring_ptr; | |
1355 | ||
1356 | ha->rsp_ring_index++; | |
1357 | if (ha->rsp_ring_index == ha->response_q_length) { | |
1358 | ha->rsp_ring_index = 0; | |
1359 | ha->response_ring_ptr = ha->response_ring; | |
1360 | } else { | |
1361 | ha->response_ring_ptr++; | |
1362 | } | |
1363 | ||
1364 | if (pkt->entry_status != 0) { | |
1365 | DEBUG3(printk(KERN_INFO | |
1366 | "scsi(%ld): Process error entry.\n", ha->host_no)); | |
1367 | ||
9a853f71 AV |
1368 | qla2x00_error_entry(ha, (sts_entry_t *) pkt); |
1369 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
1370 | wmb(); | |
1371 | continue; | |
1372 | } | |
1373 | ||
1374 | switch (pkt->entry_type) { | |
1375 | case STATUS_TYPE: | |
1376 | qla2x00_status_entry(ha, pkt); | |
1377 | break; | |
1378 | case STATUS_CONT_TYPE: | |
1379 | qla2x00_status_cont_entry(ha, (sts_cont_entry_t *)pkt); | |
1380 | break; | |
1381 | case MS_IOCB_TYPE: | |
1382 | qla24xx_ms_entry(ha, (struct ct_entry_24xx *)pkt); | |
1383 | break; | |
1384 | default: | |
1385 | /* Type Not Supported. */ | |
1386 | DEBUG4(printk(KERN_WARNING | |
1387 | "scsi(%ld): Received unknown response pkt type %x " | |
1388 | "entry status=%x.\n", | |
1389 | ha->host_no, pkt->entry_type, pkt->entry_status)); | |
1390 | break; | |
1391 | } | |
1392 | ((response_t *)pkt)->signature = RESPONSE_PROCESSED; | |
1393 | wmb(); | |
1394 | } | |
1395 | ||
1396 | /* Adjust ring index */ | |
1397 | WRT_REG_DWORD(®->rsp_q_out, ha->rsp_ring_index); | |
1398 | } | |
1399 | ||
1400 | /** | |
1401 | * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx. | |
1402 | * @irq: | |
1403 | * @dev_id: SCSI driver HA context | |
9a853f71 AV |
1404 | * |
1405 | * Called by system whenever the host adapter generates an interrupt. | |
1406 | * | |
1407 | * Returns handled flag. | |
1408 | */ | |
1409 | irqreturn_t | |
7d12e780 | 1410 | qla24xx_intr_handler(int irq, void *dev_id) |
9a853f71 AV |
1411 | { |
1412 | scsi_qla_host_t *ha; | |
1413 | struct device_reg_24xx __iomem *reg; | |
1414 | int status; | |
1415 | unsigned long flags; | |
1416 | unsigned long iter; | |
1417 | uint32_t stat; | |
1418 | uint32_t hccr; | |
1419 | uint16_t mb[4]; | |
1420 | ||
1421 | ha = (scsi_qla_host_t *) dev_id; | |
1422 | if (!ha) { | |
1423 | printk(KERN_INFO | |
1424 | "%s(): NULL host pointer\n", __func__); | |
1425 | return IRQ_NONE; | |
1426 | } | |
1427 | ||
1428 | reg = &ha->iobase->isp24; | |
1429 | status = 0; | |
1430 | ||
1431 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1432 | for (iter = 50; iter--; ) { | |
1433 | stat = RD_REG_DWORD(®->host_status); | |
1434 | if (stat & HSRX_RISC_PAUSED) { | |
1435 | hccr = RD_REG_DWORD(®->hccr); | |
1436 | ||
1437 | qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " | |
1438 | "Dumping firmware!\n", hccr); | |
1439 | qla24xx_fw_dump(ha, 1); | |
1440 | ||
1441 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
1442 | break; | |
1443 | } else if ((stat & HSRX_RISC_INT) == 0) | |
1444 | break; | |
1445 | ||
1446 | switch (stat & 0xff) { | |
1447 | case 0x1: | |
1448 | case 0x2: | |
1449 | case 0x10: | |
1450 | case 0x11: | |
1451 | qla24xx_mbx_completion(ha, MSW(stat)); | |
1452 | status |= MBX_INTERRUPT; | |
1453 | ||
1454 | break; | |
1455 | case 0x12: | |
1456 | mb[0] = MSW(stat); | |
1457 | mb[1] = RD_REG_WORD(®->mailbox1); | |
1458 | mb[2] = RD_REG_WORD(®->mailbox2); | |
1459 | mb[3] = RD_REG_WORD(®->mailbox3); | |
1460 | qla2x00_async_event(ha, mb); | |
1461 | break; | |
1462 | case 0x13: | |
1463 | qla24xx_process_response_queue(ha); | |
1464 | break; | |
1465 | default: | |
1466 | DEBUG2(printk("scsi(%ld): Unrecognized interrupt type " | |
1467 | "(%d).\n", | |
1468 | ha->host_no, stat & 0xff)); | |
1469 | break; | |
1470 | } | |
1471 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_INT); | |
1472 | RD_REG_DWORD_RELAXED(®->hccr); | |
1473 | } | |
1474 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1475 | ||
1476 | if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && | |
1477 | (status & MBX_INTERRUPT) && ha->flags.mbox_int) { | |
1478 | spin_lock_irqsave(&ha->mbx_reg_lock, flags); | |
1479 | ||
1480 | set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); | |
1481 | up(&ha->mbx_intr_sem); | |
1482 | ||
1483 | spin_unlock_irqrestore(&ha->mbx_reg_lock, flags); | |
1484 | } | |
1485 | ||
1486 | return IRQ_HANDLED; | |
1487 | } | |
1488 | ||
1489 | /** | |
1490 | * qla24xx_ms_entry() - Process a Management Server entry. | |
1491 | * @ha: SCSI driver HA context | |
1492 | * @index: Response queue out pointer | |
1493 | */ | |
1494 | static void | |
1495 | qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt) | |
1496 | { | |
1497 | srb_t *sp; | |
1498 | ||
1499 | DEBUG3(printk("%s(%ld): pkt=%p pkthandle=%d.\n", | |
1500 | __func__, ha->host_no, pkt, pkt->handle)); | |
1501 | ||
744f11fd AV |
1502 | DEBUG9(printk("%s: ct pkt dump:\n", __func__)); |
1503 | DEBUG9(qla2x00_dump_buffer((void *)pkt, sizeof(struct ct_entry_24xx))); | |
9a853f71 AV |
1504 | |
1505 | /* Validate handle. */ | |
1506 | if (pkt->handle < MAX_OUTSTANDING_COMMANDS) | |
1507 | sp = ha->outstanding_cmds[pkt->handle]; | |
1508 | else | |
1509 | sp = NULL; | |
1510 | ||
1511 | if (sp == NULL) { | |
1512 | DEBUG2(printk("scsi(%ld): MS entry - invalid handle\n", | |
1513 | ha->host_no)); | |
1514 | DEBUG10(printk("scsi(%ld): MS entry - invalid handle\n", | |
1515 | ha->host_no)); | |
1516 | qla_printk(KERN_WARNING, ha, "MS entry - invalid handle %d\n", | |
1517 | pkt->handle); | |
1518 | ||
1519 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | |
1520 | return; | |
1521 | } | |
1522 | ||
1523 | CMD_COMPL_STATUS(sp->cmd) = le16_to_cpu(pkt->comp_status); | |
1524 | CMD_ENTRY_STATUS(sp->cmd) = pkt->entry_status; | |
1525 | ||
1526 | /* Free outstanding command slot. */ | |
1527 | ha->outstanding_cmds[pkt->handle] = NULL; | |
1528 | ||
1529 | qla2x00_sp_compl(ha, sp); | |
1530 | } | |
1531 |