treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / scsi / esas2r / esas2r_int.c
blobf16d6bcf9bb6db3f3c3e5b381fdb312d315cad55
1 /*
2 * linux/drivers/scsi/esas2r/esas2r_int.c
3 * esas2r interrupt handling
5 * Copyright (c) 2001-2013 ATTO Technology, Inc.
6 * (mailto:linuxdrivers@attotech.com)
7 */
8 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
9 /*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * NO WARRANTY
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
45 #include "esas2r.h"
47 /* Local function prototypes */
48 static void esas2r_doorbell_interrupt(struct esas2r_adapter *a, u32 doorbell);
49 static void esas2r_get_outbound_responses(struct esas2r_adapter *a);
50 static void esas2r_process_bus_reset(struct esas2r_adapter *a);
53 * Poll the adapter for interrupts and service them.
54 * This function handles both legacy interrupts and MSI.
56 void esas2r_polled_interrupt(struct esas2r_adapter *a)
58 u32 intstat;
59 u32 doorbell;
61 esas2r_disable_chip_interrupts(a);
63 intstat = esas2r_read_register_dword(a, MU_INT_STATUS_OUT);
65 if (intstat & MU_INTSTAT_POST_OUT) {
66 /* clear the interrupt */
68 esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT,
69 MU_OLIS_INT);
70 esas2r_flush_register_dword(a, MU_OUT_LIST_INT_STAT);
72 esas2r_get_outbound_responses(a);
75 if (intstat & MU_INTSTAT_DRBL) {
76 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT);
77 if (doorbell != 0)
78 esas2r_doorbell_interrupt(a, doorbell);
81 esas2r_enable_chip_interrupts(a);
83 if (atomic_read(&a->disable_cnt) == 0)
84 esas2r_do_deferred_processes(a);
88 * Legacy and MSI interrupt handlers. Note that the legacy interrupt handler
89 * schedules a TASKLET to process events, whereas the MSI handler just
90 * processes interrupt events directly.
92 irqreturn_t esas2r_interrupt(int irq, void *dev_id)
94 struct esas2r_adapter *a = (struct esas2r_adapter *)dev_id;
96 if (!esas2r_adapter_interrupt_pending(a))
97 return IRQ_NONE;
99 set_bit(AF2_INT_PENDING, &a->flags2);
100 esas2r_schedule_tasklet(a);
102 return IRQ_HANDLED;
105 void esas2r_adapter_interrupt(struct esas2r_adapter *a)
107 u32 doorbell;
109 if (likely(a->int_stat & MU_INTSTAT_POST_OUT)) {
110 /* clear the interrupt */
111 esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT,
112 MU_OLIS_INT);
113 esas2r_flush_register_dword(a, MU_OUT_LIST_INT_STAT);
114 esas2r_get_outbound_responses(a);
117 if (unlikely(a->int_stat & MU_INTSTAT_DRBL)) {
118 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT);
119 if (doorbell != 0)
120 esas2r_doorbell_interrupt(a, doorbell);
123 a->int_mask = ESAS2R_INT_STS_MASK;
125 esas2r_enable_chip_interrupts(a);
127 if (likely(atomic_read(&a->disable_cnt) == 0))
128 esas2r_do_deferred_processes(a);
131 irqreturn_t esas2r_msi_interrupt(int irq, void *dev_id)
133 struct esas2r_adapter *a = (struct esas2r_adapter *)dev_id;
134 u32 intstat;
135 u32 doorbell;
137 intstat = esas2r_read_register_dword(a, MU_INT_STATUS_OUT);
139 if (likely(intstat & MU_INTSTAT_POST_OUT)) {
140 /* clear the interrupt */
142 esas2r_write_register_dword(a, MU_OUT_LIST_INT_STAT,
143 MU_OLIS_INT);
144 esas2r_flush_register_dword(a, MU_OUT_LIST_INT_STAT);
146 esas2r_get_outbound_responses(a);
149 if (unlikely(intstat & MU_INTSTAT_DRBL)) {
150 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT);
151 if (doorbell != 0)
152 esas2r_doorbell_interrupt(a, doorbell);
156 * Work around a chip bug and force a new MSI to be sent if one is
157 * still pending.
159 esas2r_disable_chip_interrupts(a);
160 esas2r_enable_chip_interrupts(a);
162 if (likely(atomic_read(&a->disable_cnt) == 0))
163 esas2r_do_deferred_processes(a);
165 esas2r_do_tasklet_tasks(a);
167 return 1;
172 static void esas2r_handle_outbound_rsp_err(struct esas2r_adapter *a,
173 struct esas2r_request *rq,
174 struct atto_vda_ob_rsp *rsp)
178 * For I/O requests, only copy the response if an error
179 * occurred and setup a callback to do error processing.
181 if (unlikely(rq->req_stat != RS_SUCCESS)) {
182 memcpy(&rq->func_rsp, &rsp->func_rsp, sizeof(rsp->func_rsp));
184 if (rq->req_stat == RS_ABORTED) {
185 if (rq->timeout > RQ_MAX_TIMEOUT)
186 rq->req_stat = RS_TIMEOUT;
187 } else if (rq->req_stat == RS_SCSI_ERROR) {
188 u8 scsistatus = rq->func_rsp.scsi_rsp.scsi_stat;
190 esas2r_trace("scsistatus: %x", scsistatus);
192 /* Any of these are a good result. */
193 if (scsistatus == SAM_STAT_GOOD || scsistatus ==
194 SAM_STAT_CONDITION_MET || scsistatus ==
195 SAM_STAT_INTERMEDIATE || scsistatus ==
196 SAM_STAT_INTERMEDIATE_CONDITION_MET) {
197 rq->req_stat = RS_SUCCESS;
198 rq->func_rsp.scsi_rsp.scsi_stat =
199 SAM_STAT_GOOD;
205 static void esas2r_get_outbound_responses(struct esas2r_adapter *a)
207 struct atto_vda_ob_rsp *rsp;
208 u32 rspput_ptr;
209 u32 rspget_ptr;
210 struct esas2r_request *rq;
211 u32 handle;
212 unsigned long flags;
214 LIST_HEAD(comp_list);
216 esas2r_trace_enter();
218 spin_lock_irqsave(&a->queue_lock, flags);
220 /* Get the outbound limit and pointers */
221 rspput_ptr = le32_to_cpu(*a->outbound_copy) & MU_OLC_WRT_PTR;
222 rspget_ptr = a->last_read;
224 esas2r_trace("rspput_ptr: %x, rspget_ptr: %x", rspput_ptr, rspget_ptr);
226 /* If we don't have anything to process, get out */
227 if (unlikely(rspget_ptr == rspput_ptr)) {
228 spin_unlock_irqrestore(&a->queue_lock, flags);
229 esas2r_trace_exit();
230 return;
233 /* Make sure the firmware is healthy */
234 if (unlikely(rspput_ptr >= a->list_size)) {
235 spin_unlock_irqrestore(&a->queue_lock, flags);
236 esas2r_bugon();
237 esas2r_local_reset_adapter(a);
238 esas2r_trace_exit();
239 return;
242 do {
243 rspget_ptr++;
245 if (rspget_ptr >= a->list_size)
246 rspget_ptr = 0;
248 rsp = (struct atto_vda_ob_rsp *)a->outbound_list_md.virt_addr
249 + rspget_ptr;
251 handle = rsp->handle;
253 /* Verify the handle range */
254 if (unlikely(LOWORD(handle) == 0
255 || LOWORD(handle) > num_requests +
256 num_ae_requests + 1)) {
257 esas2r_bugon();
258 continue;
261 /* Get the request for this handle */
262 rq = a->req_table[LOWORD(handle)];
264 if (unlikely(rq == NULL || rq->vrq->scsi.handle != handle)) {
265 esas2r_bugon();
266 continue;
269 list_del(&rq->req_list);
271 /* Get the completion status */
272 rq->req_stat = rsp->req_stat;
274 esas2r_trace("handle: %x", handle);
275 esas2r_trace("rq: %p", rq);
276 esas2r_trace("req_status: %x", rq->req_stat);
278 if (likely(rq->vrq->scsi.function == VDA_FUNC_SCSI)) {
279 esas2r_handle_outbound_rsp_err(a, rq, rsp);
280 } else {
282 * Copy the outbound completion struct for non-I/O
283 * requests.
285 memcpy(&rq->func_rsp, &rsp->func_rsp,
286 sizeof(rsp->func_rsp));
289 /* Queue the request for completion. */
290 list_add_tail(&rq->comp_list, &comp_list);
292 } while (rspget_ptr != rspput_ptr);
294 a->last_read = rspget_ptr;
295 spin_unlock_irqrestore(&a->queue_lock, flags);
297 esas2r_comp_list_drain(a, &comp_list);
298 esas2r_trace_exit();
302 * Perform all deferred processes for the adapter. Deferred
303 * processes can only be done while the current interrupt
304 * disable_cnt for the adapter is zero.
306 void esas2r_do_deferred_processes(struct esas2r_adapter *a)
308 int startreqs = 2;
309 struct esas2r_request *rq;
310 unsigned long flags;
313 * startreqs is used to control starting requests
314 * that are on the deferred queue
315 * = 0 - do not start any requests
316 * = 1 - can start discovery requests
317 * = 2 - can start any request
320 if (test_bit(AF_CHPRST_PENDING, &a->flags) ||
321 test_bit(AF_FLASHING, &a->flags))
322 startreqs = 0;
323 else if (test_bit(AF_DISC_PENDING, &a->flags))
324 startreqs = 1;
326 atomic_inc(&a->disable_cnt);
328 /* Clear off the completed list to be processed later. */
330 if (esas2r_is_tasklet_pending(a)) {
331 esas2r_schedule_tasklet(a);
333 startreqs = 0;
337 * If we can start requests then traverse the defer queue
338 * looking for requests to start or complete
340 if (startreqs && !list_empty(&a->defer_list)) {
341 LIST_HEAD(comp_list);
342 struct list_head *element, *next;
344 spin_lock_irqsave(&a->queue_lock, flags);
346 list_for_each_safe(element, next, &a->defer_list) {
347 rq = list_entry(element, struct esas2r_request,
348 req_list);
350 if (rq->req_stat != RS_PENDING) {
351 list_del(element);
352 list_add_tail(&rq->comp_list, &comp_list);
355 * Process discovery and OS requests separately. We
356 * can't hold up discovery requests when discovery is
357 * pending. In general, there may be different sets of
358 * conditions for starting different types of requests.
360 else if (rq->req_type == RT_DISC_REQ) {
361 list_del(element);
362 esas2r_disc_local_start_request(a, rq);
363 } else if (startreqs == 2) {
364 list_del(element);
365 esas2r_local_start_request(a, rq);
368 * Flashing could have been set by last local
369 * start
371 if (test_bit(AF_FLASHING, &a->flags))
372 break;
376 spin_unlock_irqrestore(&a->queue_lock, flags);
377 esas2r_comp_list_drain(a, &comp_list);
380 atomic_dec(&a->disable_cnt);
384 * Process an adapter reset (or one that is about to happen)
385 * by making sure all outstanding requests are completed that
386 * haven't been already.
388 void esas2r_process_adapter_reset(struct esas2r_adapter *a)
390 struct esas2r_request *rq = &a->general_req;
391 unsigned long flags;
392 struct esas2r_disc_context *dc;
394 LIST_HEAD(comp_list);
395 struct list_head *element;
397 esas2r_trace_enter();
399 spin_lock_irqsave(&a->queue_lock, flags);
401 /* abort the active discovery, if any. */
403 if (rq->interrupt_cx) {
404 dc = (struct esas2r_disc_context *)rq->interrupt_cx;
406 dc->disc_evt = 0;
408 clear_bit(AF_DISC_IN_PROG, &a->flags);
412 * just clear the interrupt callback for now. it will be dequeued if
413 * and when we find it on the active queue and we don't want the
414 * callback called. also set the dummy completion callback in case we
415 * were doing an I/O request.
418 rq->interrupt_cx = NULL;
419 rq->interrupt_cb = NULL;
421 rq->comp_cb = esas2r_dummy_complete;
423 /* Reset the read and write pointers */
425 *a->outbound_copy =
426 a->last_write =
427 a->last_read = a->list_size - 1;
429 set_bit(AF_COMM_LIST_TOGGLE, &a->flags);
431 /* Kill all the requests on the active list */
432 list_for_each(element, &a->defer_list) {
433 rq = list_entry(element, struct esas2r_request, req_list);
435 if (rq->req_stat == RS_STARTED)
436 if (esas2r_ioreq_aborted(a, rq, RS_ABORTED))
437 list_add_tail(&rq->comp_list, &comp_list);
440 spin_unlock_irqrestore(&a->queue_lock, flags);
441 esas2r_comp_list_drain(a, &comp_list);
442 esas2r_process_bus_reset(a);
443 esas2r_trace_exit();
446 static void esas2r_process_bus_reset(struct esas2r_adapter *a)
448 struct esas2r_request *rq;
449 struct list_head *element;
450 unsigned long flags;
452 LIST_HEAD(comp_list);
454 esas2r_trace_enter();
456 esas2r_hdebug("reset detected");
458 spin_lock_irqsave(&a->queue_lock, flags);
460 /* kill all the requests on the deferred queue */
461 list_for_each(element, &a->defer_list) {
462 rq = list_entry(element, struct esas2r_request, req_list);
463 if (esas2r_ioreq_aborted(a, rq, RS_ABORTED))
464 list_add_tail(&rq->comp_list, &comp_list);
467 spin_unlock_irqrestore(&a->queue_lock, flags);
469 esas2r_comp_list_drain(a, &comp_list);
471 if (atomic_read(&a->disable_cnt) == 0)
472 esas2r_do_deferred_processes(a);
474 clear_bit(AF_OS_RESET, &a->flags);
476 esas2r_trace_exit();
479 static void esas2r_chip_rst_needed_during_tasklet(struct esas2r_adapter *a)
482 clear_bit(AF_CHPRST_NEEDED, &a->flags);
483 clear_bit(AF_BUSRST_NEEDED, &a->flags);
484 clear_bit(AF_BUSRST_DETECTED, &a->flags);
485 clear_bit(AF_BUSRST_PENDING, &a->flags);
487 * Make sure we don't get attempt more than 3 resets
488 * when the uptime between resets does not exceed one
489 * minute. This will stop any situation where there is
490 * really something wrong with the hardware. The way
491 * this works is that we start with uptime ticks at 0.
492 * Each time we do a reset, we add 20 seconds worth to
493 * the count. Each time a timer tick occurs, as long
494 * as a chip reset is not pending, we decrement the
495 * tick count. If the uptime ticks ever gets to 60
496 * seconds worth, we disable the adapter from that
497 * point forward. Three strikes, you're out.
499 if (!esas2r_is_adapter_present(a) || (a->chip_uptime >=
500 ESAS2R_CHP_UPTIME_MAX)) {
501 esas2r_hdebug("*** adapter disabled ***");
504 * Ok, some kind of hard failure. Make sure we
505 * exit this loop with chip interrupts
506 * permanently disabled so we don't lock up the
507 * entire system. Also flag degraded mode to
508 * prevent the heartbeat from trying to recover.
511 set_bit(AF_DEGRADED_MODE, &a->flags);
512 set_bit(AF_DISABLED, &a->flags);
513 clear_bit(AF_CHPRST_PENDING, &a->flags);
514 clear_bit(AF_DISC_PENDING, &a->flags);
516 esas2r_disable_chip_interrupts(a);
517 a->int_mask = 0;
518 esas2r_process_adapter_reset(a);
520 esas2r_log(ESAS2R_LOG_CRIT,
521 "Adapter disabled because of hardware failure");
522 } else {
523 bool alrdyrst = test_and_set_bit(AF_CHPRST_STARTED, &a->flags);
525 if (!alrdyrst)
527 * Only disable interrupts if this is
528 * the first reset attempt.
530 esas2r_disable_chip_interrupts(a);
532 if ((test_bit(AF_POWER_MGT, &a->flags)) &&
533 !test_bit(AF_FIRST_INIT, &a->flags) && !alrdyrst) {
535 * Don't reset the chip on the first
536 * deferred power up attempt.
538 } else {
539 esas2r_hdebug("*** resetting chip ***");
540 esas2r_reset_chip(a);
543 /* Kick off the reinitialization */
544 a->chip_uptime += ESAS2R_CHP_UPTIME_CNT;
545 a->chip_init_time = jiffies_to_msecs(jiffies);
546 if (!test_bit(AF_POWER_MGT, &a->flags)) {
547 esas2r_process_adapter_reset(a);
549 if (!alrdyrst) {
550 /* Remove devices now that I/O is cleaned up. */
551 a->prev_dev_cnt =
552 esas2r_targ_db_get_tgt_cnt(a);
553 esas2r_targ_db_remove_all(a, false);
557 a->int_mask = 0;
561 static void esas2r_handle_chip_rst_during_tasklet(struct esas2r_adapter *a)
563 while (test_bit(AF_CHPRST_DETECTED, &a->flags)) {
565 * Balance the enable in esas2r_initadapter_hw.
566 * Esas2r_power_down already took care of it for power
567 * management.
569 if (!test_bit(AF_DEGRADED_MODE, &a->flags) &&
570 !test_bit(AF_POWER_MGT, &a->flags))
571 esas2r_disable_chip_interrupts(a);
573 /* Reinitialize the chip. */
574 esas2r_check_adapter(a);
575 esas2r_init_adapter_hw(a, 0);
577 if (test_bit(AF_CHPRST_NEEDED, &a->flags))
578 break;
580 if (test_bit(AF_POWER_MGT, &a->flags)) {
581 /* Recovery from power management. */
582 if (test_bit(AF_FIRST_INIT, &a->flags)) {
583 /* Chip reset during normal power up */
584 esas2r_log(ESAS2R_LOG_CRIT,
585 "The firmware was reset during a normal power-up sequence");
586 } else {
587 /* Deferred power up complete. */
588 clear_bit(AF_POWER_MGT, &a->flags);
589 esas2r_send_reset_ae(a, true);
591 } else {
592 /* Recovery from online chip reset. */
593 if (test_bit(AF_FIRST_INIT, &a->flags)) {
594 /* Chip reset during driver load */
595 } else {
596 /* Chip reset after driver load */
597 esas2r_send_reset_ae(a, false);
600 esas2r_log(ESAS2R_LOG_CRIT,
601 "Recovering from a chip reset while the chip was online");
604 clear_bit(AF_CHPRST_STARTED, &a->flags);
605 esas2r_enable_chip_interrupts(a);
608 * Clear this flag last! this indicates that the chip has been
609 * reset already during initialization.
611 clear_bit(AF_CHPRST_DETECTED, &a->flags);
616 /* Perform deferred tasks when chip interrupts are disabled */
617 void esas2r_do_tasklet_tasks(struct esas2r_adapter *a)
620 if (test_bit(AF_CHPRST_NEEDED, &a->flags) ||
621 test_bit(AF_CHPRST_DETECTED, &a->flags)) {
622 if (test_bit(AF_CHPRST_NEEDED, &a->flags))
623 esas2r_chip_rst_needed_during_tasklet(a);
625 esas2r_handle_chip_rst_during_tasklet(a);
628 if (test_bit(AF_BUSRST_NEEDED, &a->flags)) {
629 esas2r_hdebug("hard resetting bus");
631 clear_bit(AF_BUSRST_NEEDED, &a->flags);
633 if (test_bit(AF_FLASHING, &a->flags))
634 set_bit(AF_BUSRST_DETECTED, &a->flags);
635 else
636 esas2r_write_register_dword(a, MU_DOORBELL_IN,
637 DRBL_RESET_BUS);
640 if (test_bit(AF_BUSRST_DETECTED, &a->flags)) {
641 esas2r_process_bus_reset(a);
643 esas2r_log_dev(ESAS2R_LOG_WARN,
644 &(a->host->shost_gendev),
645 "scsi_report_bus_reset() called");
647 scsi_report_bus_reset(a->host, 0);
649 clear_bit(AF_BUSRST_DETECTED, &a->flags);
650 clear_bit(AF_BUSRST_PENDING, &a->flags);
652 esas2r_log(ESAS2R_LOG_WARN, "Bus reset complete");
655 if (test_bit(AF_PORT_CHANGE, &a->flags)) {
656 clear_bit(AF_PORT_CHANGE, &a->flags);
658 esas2r_targ_db_report_changes(a);
661 if (atomic_read(&a->disable_cnt) == 0)
662 esas2r_do_deferred_processes(a);
665 static void esas2r_doorbell_interrupt(struct esas2r_adapter *a, u32 doorbell)
667 if (!(doorbell & DRBL_FORCE_INT)) {
668 esas2r_trace_enter();
669 esas2r_trace("doorbell: %x", doorbell);
672 /* First clear the doorbell bits */
673 esas2r_write_register_dword(a, MU_DOORBELL_OUT, doorbell);
675 if (doorbell & DRBL_RESET_BUS)
676 set_bit(AF_BUSRST_DETECTED, &a->flags);
678 if (doorbell & DRBL_FORCE_INT)
679 clear_bit(AF_HEARTBEAT, &a->flags);
681 if (doorbell & DRBL_PANIC_REASON_MASK) {
682 esas2r_hdebug("*** Firmware Panic ***");
683 esas2r_log(ESAS2R_LOG_CRIT, "The firmware has panicked");
686 if (doorbell & DRBL_FW_RESET) {
687 set_bit(AF2_COREDUMP_AVAIL, &a->flags2);
688 esas2r_local_reset_adapter(a);
691 if (!(doorbell & DRBL_FORCE_INT))
692 esas2r_trace_exit();
695 void esas2r_force_interrupt(struct esas2r_adapter *a)
697 esas2r_write_register_dword(a, MU_DOORBELL_IN, DRBL_FORCE_INT |
698 DRBL_DRV_VER);
702 static void esas2r_lun_event(struct esas2r_adapter *a, union atto_vda_ae *ae,
703 u16 target, u32 length)
705 struct esas2r_target *t = a->targetdb + target;
706 u32 cplen = length;
707 unsigned long flags;
709 if (cplen > sizeof(t->lu_event))
710 cplen = sizeof(t->lu_event);
712 esas2r_trace("ae->lu.dwevent: %x", ae->lu.dwevent);
713 esas2r_trace("ae->lu.bystate: %x", ae->lu.bystate);
715 spin_lock_irqsave(&a->mem_lock, flags);
717 t->new_target_state = TS_INVALID;
719 if (ae->lu.dwevent & VDAAE_LU_LOST) {
720 t->new_target_state = TS_NOT_PRESENT;
721 } else {
722 switch (ae->lu.bystate) {
723 case VDAAE_LU_NOT_PRESENT:
724 case VDAAE_LU_OFFLINE:
725 case VDAAE_LU_DELETED:
726 case VDAAE_LU_FACTORY_DISABLED:
727 t->new_target_state = TS_NOT_PRESENT;
728 break;
730 case VDAAE_LU_ONLINE:
731 case VDAAE_LU_DEGRADED:
732 t->new_target_state = TS_PRESENT;
733 break;
737 if (t->new_target_state != TS_INVALID) {
738 memcpy(&t->lu_event, &ae->lu, cplen);
740 esas2r_disc_queue_event(a, DCDE_DEV_CHANGE);
743 spin_unlock_irqrestore(&a->mem_lock, flags);
748 void esas2r_ae_complete(struct esas2r_adapter *a, struct esas2r_request *rq)
750 union atto_vda_ae *ae =
751 (union atto_vda_ae *)rq->vda_rsp_data->ae_data.event_data;
752 u32 length = le32_to_cpu(rq->func_rsp.ae_rsp.length);
753 union atto_vda_ae *last =
754 (union atto_vda_ae *)(rq->vda_rsp_data->ae_data.event_data
755 + length);
757 esas2r_trace_enter();
758 esas2r_trace("length: %d", length);
760 if (length > sizeof(struct atto_vda_ae_data)
761 || (length & 3) != 0
762 || length == 0) {
763 esas2r_log(ESAS2R_LOG_WARN,
764 "The AE request response length (%p) is too long: %d",
765 rq, length);
767 esas2r_hdebug("aereq->length (0x%x) too long", length);
768 esas2r_bugon();
770 last = ae;
773 while (ae < last) {
774 u16 target;
776 esas2r_trace("ae: %p", ae);
777 esas2r_trace("ae->hdr: %p", &(ae->hdr));
779 length = ae->hdr.bylength;
781 if (length > (u32)((u8 *)last - (u8 *)ae)
782 || (length & 3) != 0
783 || length == 0) {
784 esas2r_log(ESAS2R_LOG_CRIT,
785 "the async event length is invalid (%p): %d",
786 ae, length);
788 esas2r_hdebug("ae->hdr.length (0x%x) invalid", length);
789 esas2r_bugon();
791 break;
794 esas2r_nuxi_ae_data(ae);
796 esas2r_queue_fw_event(a, fw_event_vda_ae, ae,
797 sizeof(union atto_vda_ae));
799 switch (ae->hdr.bytype) {
800 case VDAAE_HDR_TYPE_RAID:
802 if (ae->raid.dwflags & (VDAAE_GROUP_STATE
803 | VDAAE_RBLD_STATE
804 | VDAAE_MEMBER_CHG
805 | VDAAE_PART_CHG)) {
806 esas2r_log(ESAS2R_LOG_INFO,
807 "RAID event received - name:%s rebuild_state:%d group_state:%d",
808 ae->raid.acname,
809 ae->raid.byrebuild_state,
810 ae->raid.bygroup_state);
813 break;
815 case VDAAE_HDR_TYPE_LU:
816 esas2r_log(ESAS2R_LOG_INFO,
817 "LUN event received: event:%d target_id:%d LUN:%d state:%d",
818 ae->lu.dwevent,
819 ae->lu.id.tgtlun.wtarget_id,
820 ae->lu.id.tgtlun.bylun,
821 ae->lu.bystate);
823 target = ae->lu.id.tgtlun.wtarget_id;
825 if (target < ESAS2R_MAX_TARGETS)
826 esas2r_lun_event(a, ae, target, length);
828 break;
830 case VDAAE_HDR_TYPE_DISK:
831 esas2r_log(ESAS2R_LOG_INFO, "Disk event received");
832 break;
834 default:
836 /* Silently ignore the rest and let the apps deal with
837 * them.
840 break;
843 ae = (union atto_vda_ae *)((u8 *)ae + length);
846 /* Now requeue it. */
847 esas2r_start_ae_request(a, rq);
848 esas2r_trace_exit();
851 /* Send an asynchronous event for a chip reset or power management. */
852 void esas2r_send_reset_ae(struct esas2r_adapter *a, bool pwr_mgt)
854 struct atto_vda_ae_hdr ae;
856 if (pwr_mgt)
857 ae.bytype = VDAAE_HDR_TYPE_PWRMGT;
858 else
859 ae.bytype = VDAAE_HDR_TYPE_RESET;
861 ae.byversion = VDAAE_HDR_VER_0;
862 ae.byflags = 0;
863 ae.bylength = (u8)sizeof(struct atto_vda_ae_hdr);
865 if (pwr_mgt)
866 esas2r_hdebug("*** sending power management AE ***");
867 else
868 esas2r_hdebug("*** sending reset AE ***");
870 esas2r_queue_fw_event(a, fw_event_vda_ae, &ae,
871 sizeof(union atto_vda_ae));
874 void esas2r_dummy_complete(struct esas2r_adapter *a, struct esas2r_request *rq)
877 static void esas2r_check_req_rsp_sense(struct esas2r_adapter *a,
878 struct esas2r_request *rq)
880 u8 snslen, snslen2;
882 snslen = snslen2 = rq->func_rsp.scsi_rsp.sense_len;
884 if (snslen > rq->sense_len)
885 snslen = rq->sense_len;
887 if (snslen) {
888 if (rq->sense_buf)
889 memcpy(rq->sense_buf, rq->data_buf, snslen);
890 else
891 rq->sense_buf = (u8 *)rq->data_buf;
893 /* See about possible sense data */
894 if (snslen2 > 0x0c) {
895 u8 *s = (u8 *)rq->data_buf;
897 esas2r_trace_enter();
899 /* Report LUNS data has changed */
900 if (s[0x0c] == 0x3f && s[0x0d] == 0x0E) {
901 esas2r_trace("rq->target_id: %d",
902 rq->target_id);
903 esas2r_target_state_changed(a, rq->target_id,
904 TS_LUN_CHANGE);
907 esas2r_trace("add_sense_key=%x", s[0x0c]);
908 esas2r_trace("add_sense_qual=%x", s[0x0d]);
909 esas2r_trace_exit();
913 rq->sense_len = snslen;
917 void esas2r_complete_request(struct esas2r_adapter *a,
918 struct esas2r_request *rq)
920 if (rq->vrq->scsi.function == VDA_FUNC_FLASH
921 && rq->vrq->flash.sub_func == VDA_FLASH_COMMIT)
922 clear_bit(AF_FLASHING, &a->flags);
924 /* See if we setup a callback to do special processing */
926 if (rq->interrupt_cb) {
927 (*rq->interrupt_cb)(a, rq);
929 if (rq->req_stat == RS_PENDING) {
930 esas2r_start_request(a, rq);
931 return;
935 if (likely(rq->vrq->scsi.function == VDA_FUNC_SCSI)
936 && unlikely(rq->req_stat != RS_SUCCESS)) {
937 esas2r_check_req_rsp_sense(a, rq);
938 esas2r_log_request_failure(a, rq);
941 (*rq->comp_cb)(a, rq);