Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / drivers / scsi / esas2r / esas2r_io.c
bloba8df916cd57a53eccc356413e26ffbbcda847f9c
1 /*
2 * linux/drivers/scsi/esas2r/esas2r_io.c
3 * For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
5 * Copyright (c) 2001-2013 ATTO Technology, Inc.
6 * (mailto:linuxdrivers@attotech.com)mpt3sas/mpt3sas_trigger_diag.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * NO WARRANTY
19 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 * solely responsible for determining the appropriateness of using and
24 * distributing the Program and assumes all risks associated with its
25 * exercise of rights under this Agreement, including but not limited to
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
29 * DISCLAIMER OF LIABILITY
30 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
35 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
36 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
41 * USA.
44 #include "esas2r.h"
46 void esas2r_start_request(struct esas2r_adapter *a, struct esas2r_request *rq)
48 struct esas2r_target *t = NULL;
49 struct esas2r_request *startrq = rq;
50 unsigned long flags;
52 if (unlikely(test_bit(AF_DEGRADED_MODE, &a->flags) ||
53 test_bit(AF_POWER_DOWN, &a->flags))) {
54 if (rq->vrq->scsi.function == VDA_FUNC_SCSI)
55 rq->req_stat = RS_SEL2;
56 else
57 rq->req_stat = RS_DEGRADED;
58 } else if (likely(rq->vrq->scsi.function == VDA_FUNC_SCSI)) {
59 t = a->targetdb + rq->target_id;
61 if (unlikely(t >= a->targetdb_end
62 || !(t->flags & TF_USED))) {
63 rq->req_stat = RS_SEL;
64 } else {
65 /* copy in the target ID. */
66 rq->vrq->scsi.target_id = cpu_to_le16(t->virt_targ_id);
69 * Test if we want to report RS_SEL for missing target.
70 * Note that if AF_DISC_PENDING is set than this will
71 * go on the defer queue.
73 if (unlikely(t->target_state != TS_PRESENT &&
74 !test_bit(AF_DISC_PENDING, &a->flags)))
75 rq->req_stat = RS_SEL;
79 if (unlikely(rq->req_stat != RS_PENDING)) {
80 esas2r_complete_request(a, rq);
81 return;
84 esas2r_trace("rq=%p", rq);
85 esas2r_trace("rq->vrq->scsi.handle=%x", rq->vrq->scsi.handle);
87 if (rq->vrq->scsi.function == VDA_FUNC_SCSI) {
88 esas2r_trace("rq->target_id=%d", rq->target_id);
89 esas2r_trace("rq->vrq->scsi.flags=%x", rq->vrq->scsi.flags);
92 spin_lock_irqsave(&a->queue_lock, flags);
94 if (likely(list_empty(&a->defer_list) &&
95 !test_bit(AF_CHPRST_PENDING, &a->flags) &&
96 !test_bit(AF_FLASHING, &a->flags) &&
97 !test_bit(AF_DISC_PENDING, &a->flags)))
98 esas2r_local_start_request(a, startrq);
99 else
100 list_add_tail(&startrq->req_list, &a->defer_list);
102 spin_unlock_irqrestore(&a->queue_lock, flags);
106 * Starts the specified request. all requests have RS_PENDING set when this
107 * routine is called. The caller is usually esas2r_start_request, but
108 * esas2r_do_deferred_processes will start request that are deferred.
110 * The caller must ensure that requests can be started.
112 * esas2r_start_request will defer a request if there are already requests
113 * waiting or there is a chip reset pending. once the reset condition clears,
114 * esas2r_do_deferred_processes will call this function to start the request.
116 * When a request is started, it is placed on the active list and queued to
117 * the controller.
119 void esas2r_local_start_request(struct esas2r_adapter *a,
120 struct esas2r_request *rq)
122 esas2r_trace_enter();
123 esas2r_trace("rq=%p", rq);
124 esas2r_trace("rq->vrq:%p", rq->vrq);
125 esas2r_trace("rq->vrq_md->phys_addr:%x", rq->vrq_md->phys_addr);
127 if (unlikely(rq->vrq->scsi.function == VDA_FUNC_FLASH
128 && rq->vrq->flash.sub_func == VDA_FLASH_COMMIT))
129 set_bit(AF_FLASHING, &a->flags);
131 list_add_tail(&rq->req_list, &a->active_list);
132 esas2r_start_vda_request(a, rq);
133 esas2r_trace_exit();
134 return;
137 void esas2r_start_vda_request(struct esas2r_adapter *a,
138 struct esas2r_request *rq)
140 struct esas2r_inbound_list_source_entry *element;
141 u32 dw;
143 rq->req_stat = RS_STARTED;
145 * Calculate the inbound list entry location and the current state of
146 * toggle bit.
148 a->last_write++;
149 if (a->last_write >= a->list_size) {
150 a->last_write = 0;
151 /* update the toggle bit */
152 if (test_bit(AF_COMM_LIST_TOGGLE, &a->flags))
153 clear_bit(AF_COMM_LIST_TOGGLE, &a->flags);
154 else
155 set_bit(AF_COMM_LIST_TOGGLE, &a->flags);
158 element =
159 (struct esas2r_inbound_list_source_entry *)a->inbound_list_md.
160 virt_addr
161 + a->last_write;
163 /* Set the VDA request size if it was never modified */
164 if (rq->vda_req_sz == RQ_SIZE_DEFAULT)
165 rq->vda_req_sz = (u16)(a->max_vdareq_size / sizeof(u32));
167 element->address = cpu_to_le64(rq->vrq_md->phys_addr);
168 element->length = cpu_to_le32(rq->vda_req_sz);
170 /* Update the write pointer */
171 dw = a->last_write;
173 if (test_bit(AF_COMM_LIST_TOGGLE, &a->flags))
174 dw |= MU_ILW_TOGGLE;
176 esas2r_trace("rq->vrq->scsi.handle:%x", rq->vrq->scsi.handle);
177 esas2r_trace("dw:%x", dw);
178 esas2r_trace("rq->vda_req_sz:%x", rq->vda_req_sz);
179 esas2r_write_register_dword(a, MU_IN_LIST_WRITE, dw);
183 * Build the scatter/gather list for an I/O request according to the
184 * specifications placed in the s/g context. The caller must initialize
185 * context prior to the initial call by calling esas2r_sgc_init().
187 bool esas2r_build_sg_list_sge(struct esas2r_adapter *a,
188 struct esas2r_sg_context *sgc)
190 struct esas2r_request *rq = sgc->first_req;
191 union atto_vda_req *vrq = rq->vrq;
193 while (sgc->length) {
194 u32 rem = 0;
195 u64 addr;
196 u32 len;
198 len = (*sgc->get_phys_addr)(sgc, &addr);
200 if (unlikely(len == 0))
201 return false;
203 /* if current length is more than what's left, stop there */
204 if (unlikely(len > sgc->length))
205 len = sgc->length;
207 another_entry:
208 /* limit to a round number less than the maximum length */
209 if (len > SGE_LEN_MAX) {
211 * Save the remainder of the split. Whenever we limit
212 * an entry we come back around to build entries out
213 * of the leftover. We do this to prevent multiple
214 * calls to the get_phys_addr() function for an SGE
215 * that is too large.
217 rem = len - SGE_LEN_MAX;
218 len = SGE_LEN_MAX;
221 /* See if we need to allocate a new SGL */
222 if (unlikely(sgc->sge.a64.curr > sgc->sge.a64.limit)) {
223 u8 sgelen;
224 struct esas2r_mem_desc *sgl;
227 * If no SGls are available, return failure. The
228 * caller can call us later with the current context
229 * to pick up here.
231 sgl = esas2r_alloc_sgl(a);
233 if (unlikely(sgl == NULL))
234 return false;
236 /* Calculate the length of the last SGE filled in */
237 sgelen = (u8)((u8 *)sgc->sge.a64.curr
238 - (u8 *)sgc->sge.a64.last);
241 * Copy the last SGE filled in to the first entry of
242 * the new SGL to make room for the chain entry.
244 memcpy(sgl->virt_addr, sgc->sge.a64.last, sgelen);
246 /* Figure out the new curr pointer in the new segment */
247 sgc->sge.a64.curr =
248 (struct atto_vda_sge *)((u8 *)sgl->virt_addr +
249 sgelen);
251 /* Set the limit pointer and build the chain entry */
252 sgc->sge.a64.limit =
253 (struct atto_vda_sge *)((u8 *)sgl->virt_addr
254 + sgl_page_size
255 - sizeof(struct
256 atto_vda_sge));
257 sgc->sge.a64.last->length = cpu_to_le32(
258 SGE_CHAIN | SGE_ADDR_64);
259 sgc->sge.a64.last->address =
260 cpu_to_le64(sgl->phys_addr);
263 * Now, if there was a previous chain entry, then
264 * update it to contain the length of this segment
265 * and size of this chain. otherwise this is the
266 * first SGL, so set the chain_offset in the request.
268 if (sgc->sge.a64.chain) {
269 sgc->sge.a64.chain->length |=
270 cpu_to_le32(
271 ((u8 *)(sgc->sge.a64.
272 last + 1)
273 - (u8 *)rq->sg_table->
274 virt_addr)
275 + sizeof(struct atto_vda_sge) *
276 LOBIT(SGE_CHAIN_SZ));
277 } else {
278 vrq->scsi.chain_offset = (u8)
279 ((u8 *)sgc->
280 sge.a64.last -
281 (u8 *)vrq);
284 * This is the first SGL, so set the
285 * chain_offset and the VDA request size in
286 * the request.
288 rq->vda_req_sz =
289 (vrq->scsi.chain_offset +
290 sizeof(struct atto_vda_sge) +
292 / sizeof(u32);
296 * Remember this so when we get a new SGL filled in we
297 * can update the length of this chain entry.
299 sgc->sge.a64.chain = sgc->sge.a64.last;
301 /* Now link the new SGL onto the primary request. */
302 list_add(&sgl->next_desc, &rq->sg_table_head);
305 /* Update last one filled in */
306 sgc->sge.a64.last = sgc->sge.a64.curr;
308 /* Build the new SGE and update the S/G context */
309 sgc->sge.a64.curr->length = cpu_to_le32(SGE_ADDR_64 | len);
310 sgc->sge.a64.curr->address = cpu_to_le32(addr);
311 sgc->sge.a64.curr++;
312 sgc->cur_offset += len;
313 sgc->length -= len;
316 * Check if we previously split an entry. If so we have to
317 * pick up where we left off.
319 if (rem) {
320 addr += len;
321 len = rem;
322 rem = 0;
323 goto another_entry;
327 /* Mark the end of the SGL */
328 sgc->sge.a64.last->length |= cpu_to_le32(SGE_LAST);
331 * If there was a previous chain entry, update the length to indicate
332 * the length of this last segment.
334 if (sgc->sge.a64.chain) {
335 sgc->sge.a64.chain->length |= cpu_to_le32(
336 ((u8 *)(sgc->sge.a64.curr) -
337 (u8 *)rq->sg_table->virt_addr));
338 } else {
339 u16 reqsize;
342 * The entire VDA request was not used so lets
343 * set the size of the VDA request to be DMA'd
345 reqsize =
346 ((u16)((u8 *)sgc->sge.a64.last - (u8 *)vrq)
347 + sizeof(struct atto_vda_sge) + 3) / sizeof(u32);
350 * Only update the request size if it is bigger than what is
351 * already there. We can come in here twice for some management
352 * commands.
354 if (reqsize > rq->vda_req_sz)
355 rq->vda_req_sz = reqsize;
357 return true;
362 * Create PRD list for each I-block consumed by the command. This routine
363 * determines how much data is required from each I-block being consumed
364 * by the command. The first and last I-blocks can be partials and all of
365 * the I-blocks in between are for a full I-block of data.
367 * The interleave size is used to determine the number of bytes in the 1st
368 * I-block and the remaining I-blocks are what remeains.
370 static bool esas2r_build_prd_iblk(struct esas2r_adapter *a,
371 struct esas2r_sg_context *sgc)
373 struct esas2r_request *rq = sgc->first_req;
374 u64 addr;
375 u32 len;
376 struct esas2r_mem_desc *sgl;
377 u32 numchain = 1;
378 u32 rem = 0;
380 while (sgc->length) {
381 /* Get the next address/length pair */
383 len = (*sgc->get_phys_addr)(sgc, &addr);
385 if (unlikely(len == 0))
386 return false;
388 /* If current length is more than what's left, stop there */
390 if (unlikely(len > sgc->length))
391 len = sgc->length;
393 another_entry:
394 /* Limit to a round number less than the maximum length */
396 if (len > PRD_LEN_MAX) {
398 * Save the remainder of the split. whenever we limit
399 * an entry we come back around to build entries out
400 * of the leftover. We do this to prevent multiple
401 * calls to the get_phys_addr() function for an SGE
402 * that is too large.
404 rem = len - PRD_LEN_MAX;
405 len = PRD_LEN_MAX;
408 /* See if we need to allocate a new SGL */
409 if (sgc->sge.prd.sge_cnt == 0) {
410 if (len == sgc->length) {
412 * We only have 1 PRD entry left.
413 * It can be placed where the chain
414 * entry would have gone
417 /* Build the simple SGE */
418 sgc->sge.prd.curr->ctl_len = cpu_to_le32(
419 PRD_DATA | len);
420 sgc->sge.prd.curr->address = cpu_to_le64(addr);
422 /* Adjust length related fields */
423 sgc->cur_offset += len;
424 sgc->length -= len;
426 /* We use the reserved chain entry for data */
427 numchain = 0;
429 break;
432 if (sgc->sge.prd.chain) {
434 * Fill # of entries of current SGL in previous
435 * chain the length of this current SGL may not
436 * full.
439 sgc->sge.prd.chain->ctl_len |= cpu_to_le32(
440 sgc->sge.prd.sgl_max_cnt);
444 * If no SGls are available, return failure. The
445 * caller can call us later with the current context
446 * to pick up here.
449 sgl = esas2r_alloc_sgl(a);
451 if (unlikely(sgl == NULL))
452 return false;
455 * Link the new SGL onto the chain
456 * They are in reverse order
458 list_add(&sgl->next_desc, &rq->sg_table_head);
461 * An SGL was just filled in and we are starting
462 * a new SGL. Prime the chain of the ending SGL with
463 * info that points to the new SGL. The length gets
464 * filled in when the new SGL is filled or ended
467 sgc->sge.prd.chain = sgc->sge.prd.curr;
469 sgc->sge.prd.chain->ctl_len = cpu_to_le32(PRD_CHAIN);
470 sgc->sge.prd.chain->address =
471 cpu_to_le64(sgl->phys_addr);
474 * Start a new segment.
475 * Take one away and save for chain SGE
478 sgc->sge.prd.curr =
479 (struct atto_physical_region_description *)sgl
481 virt_addr;
482 sgc->sge.prd.sge_cnt = sgc->sge.prd.sgl_max_cnt - 1;
485 sgc->sge.prd.sge_cnt--;
486 /* Build the simple SGE */
487 sgc->sge.prd.curr->ctl_len = cpu_to_le32(PRD_DATA | len);
488 sgc->sge.prd.curr->address = cpu_to_le64(addr);
490 /* Used another element. Point to the next one */
492 sgc->sge.prd.curr++;
494 /* Adjust length related fields */
496 sgc->cur_offset += len;
497 sgc->length -= len;
500 * Check if we previously split an entry. If so we have to
501 * pick up where we left off.
504 if (rem) {
505 addr += len;
506 len = rem;
507 rem = 0;
508 goto another_entry;
512 if (!list_empty(&rq->sg_table_head)) {
513 if (sgc->sge.prd.chain) {
514 sgc->sge.prd.chain->ctl_len |=
515 cpu_to_le32(sgc->sge.prd.sgl_max_cnt
516 - sgc->sge.prd.sge_cnt
517 - numchain);
521 return true;
524 bool esas2r_build_sg_list_prd(struct esas2r_adapter *a,
525 struct esas2r_sg_context *sgc)
527 struct esas2r_request *rq = sgc->first_req;
528 u32 len = sgc->length;
529 struct esas2r_target *t = a->targetdb + rq->target_id;
530 u8 is_i_o = 0;
531 u16 reqsize;
532 struct atto_physical_region_description *curr_iblk_chn;
533 u8 *cdb = (u8 *)&rq->vrq->scsi.cdb[0];
536 * extract LBA from command so we can determine
537 * the I-Block boundary
540 if (rq->vrq->scsi.function == VDA_FUNC_SCSI
541 && t->target_state == TS_PRESENT
542 && !(t->flags & TF_PASS_THRU)) {
543 u32 lbalo = 0;
545 switch (rq->vrq->scsi.cdb[0]) {
546 case READ_16:
547 case WRITE_16:
549 lbalo =
550 MAKEDWORD(MAKEWORD(cdb[9],
551 cdb[8]),
552 MAKEWORD(cdb[7],
553 cdb[6]));
554 is_i_o = 1;
555 break;
558 case READ_12:
559 case WRITE_12:
560 case READ_10:
561 case WRITE_10:
563 lbalo =
564 MAKEDWORD(MAKEWORD(cdb[5],
565 cdb[4]),
566 MAKEWORD(cdb[3],
567 cdb[2]));
568 is_i_o = 1;
569 break;
572 case READ_6:
573 case WRITE_6:
575 lbalo =
576 MAKEDWORD(MAKEWORD(cdb[3],
577 cdb[2]),
578 MAKEWORD(cdb[1] & 0x1F,
579 0));
580 is_i_o = 1;
581 break;
584 default:
585 break;
588 if (is_i_o) {
589 u32 startlba;
591 rq->vrq->scsi.iblk_cnt_prd = 0;
593 /* Determine size of 1st I-block PRD list */
594 startlba = t->inter_block - (lbalo & (t->inter_block -
595 1));
596 sgc->length = startlba * t->block_size;
598 /* Chk if the 1st iblk chain starts at base of Iblock */
599 if ((lbalo & (t->inter_block - 1)) == 0)
600 rq->flags |= RF_1ST_IBLK_BASE;
602 if (sgc->length > len)
603 sgc->length = len;
604 } else {
605 sgc->length = len;
607 } else {
608 sgc->length = len;
611 /* get our starting chain address */
613 curr_iblk_chn =
614 (struct atto_physical_region_description *)sgc->sge.a64.curr;
616 sgc->sge.prd.sgl_max_cnt = sgl_page_size /
617 sizeof(struct
618 atto_physical_region_description);
620 /* create all of the I-block PRD lists */
622 while (len) {
623 sgc->sge.prd.sge_cnt = 0;
624 sgc->sge.prd.chain = NULL;
625 sgc->sge.prd.curr = curr_iblk_chn;
627 /* increment to next I-Block */
629 len -= sgc->length;
631 /* go build the next I-Block PRD list */
633 if (unlikely(!esas2r_build_prd_iblk(a, sgc)))
634 return false;
636 curr_iblk_chn++;
638 if (is_i_o) {
639 rq->vrq->scsi.iblk_cnt_prd++;
641 if (len > t->inter_byte)
642 sgc->length = t->inter_byte;
643 else
644 sgc->length = len;
648 /* figure out the size used of the VDA request */
650 reqsize = ((u16)((u8 *)curr_iblk_chn - (u8 *)rq->vrq))
651 / sizeof(u32);
654 * only update the request size if it is bigger than what is
655 * already there. we can come in here twice for some management
656 * commands.
659 if (reqsize > rq->vda_req_sz)
660 rq->vda_req_sz = reqsize;
662 return true;
665 static void esas2r_handle_pending_reset(struct esas2r_adapter *a, u32 currtime)
667 u32 delta = currtime - a->chip_init_time;
669 if (delta <= ESAS2R_CHPRST_WAIT_TIME) {
670 /* Wait before accessing registers */
671 } else if (delta >= ESAS2R_CHPRST_TIME) {
673 * The last reset failed so try again. Reset
674 * processing will give up after three tries.
676 esas2r_local_reset_adapter(a);
677 } else {
678 /* We can now see if the firmware is ready */
679 u32 doorbell;
681 doorbell = esas2r_read_register_dword(a, MU_DOORBELL_OUT);
682 if (doorbell == 0xFFFFFFFF || !(doorbell & DRBL_FORCE_INT)) {
683 esas2r_force_interrupt(a);
684 } else {
685 u32 ver = (doorbell & DRBL_FW_VER_MSK);
687 /* Driver supports API version 0 and 1 */
688 esas2r_write_register_dword(a, MU_DOORBELL_OUT,
689 doorbell);
690 if (ver == DRBL_FW_VER_0) {
691 set_bit(AF_CHPRST_DETECTED, &a->flags);
692 set_bit(AF_LEGACY_SGE_MODE, &a->flags);
694 a->max_vdareq_size = 128;
695 a->build_sgl = esas2r_build_sg_list_sge;
696 } else if (ver == DRBL_FW_VER_1) {
697 set_bit(AF_CHPRST_DETECTED, &a->flags);
698 clear_bit(AF_LEGACY_SGE_MODE, &a->flags);
700 a->max_vdareq_size = 1024;
701 a->build_sgl = esas2r_build_sg_list_prd;
702 } else {
703 esas2r_local_reset_adapter(a);
710 /* This function must be called once per timer tick */
711 void esas2r_timer_tick(struct esas2r_adapter *a)
713 u32 currtime = jiffies_to_msecs(jiffies);
714 u32 deltatime = currtime - a->last_tick_time;
716 a->last_tick_time = currtime;
718 /* count down the uptime */
719 if (a->chip_uptime &&
720 !test_bit(AF_CHPRST_PENDING, &a->flags) &&
721 !test_bit(AF_DISC_PENDING, &a->flags)) {
722 if (deltatime >= a->chip_uptime)
723 a->chip_uptime = 0;
724 else
725 a->chip_uptime -= deltatime;
728 if (test_bit(AF_CHPRST_PENDING, &a->flags)) {
729 if (!test_bit(AF_CHPRST_NEEDED, &a->flags) &&
730 !test_bit(AF_CHPRST_DETECTED, &a->flags))
731 esas2r_handle_pending_reset(a, currtime);
732 } else {
733 if (test_bit(AF_DISC_PENDING, &a->flags))
734 esas2r_disc_check_complete(a);
735 if (test_bit(AF_HEARTBEAT_ENB, &a->flags)) {
736 if (test_bit(AF_HEARTBEAT, &a->flags)) {
737 if ((currtime - a->heartbeat_time) >=
738 ESAS2R_HEARTBEAT_TIME) {
739 clear_bit(AF_HEARTBEAT, &a->flags);
740 esas2r_hdebug("heartbeat failed");
741 esas2r_log(ESAS2R_LOG_CRIT,
742 "heartbeat failed");
743 esas2r_bugon();
744 esas2r_local_reset_adapter(a);
746 } else {
747 set_bit(AF_HEARTBEAT, &a->flags);
748 a->heartbeat_time = currtime;
749 esas2r_force_interrupt(a);
754 if (atomic_read(&a->disable_cnt) == 0)
755 esas2r_do_deferred_processes(a);
759 * Send the specified task management function to the target and LUN
760 * specified in rqaux. in addition, immediately abort any commands that
761 * are queued but not sent to the device according to the rules specified
762 * by the task management function.
764 bool esas2r_send_task_mgmt(struct esas2r_adapter *a,
765 struct esas2r_request *rqaux, u8 task_mgt_func)
767 u16 targetid = rqaux->target_id;
768 u8 lun = (u8)le32_to_cpu(rqaux->vrq->scsi.flags);
769 bool ret = false;
770 struct esas2r_request *rq;
771 struct list_head *next, *element;
772 unsigned long flags;
774 LIST_HEAD(comp_list);
776 esas2r_trace_enter();
777 esas2r_trace("rqaux:%p", rqaux);
778 esas2r_trace("task_mgt_func:%x", task_mgt_func);
779 spin_lock_irqsave(&a->queue_lock, flags);
781 /* search the defer queue looking for requests for the device */
782 list_for_each_safe(element, next, &a->defer_list) {
783 rq = list_entry(element, struct esas2r_request, req_list);
785 if (rq->vrq->scsi.function == VDA_FUNC_SCSI
786 && rq->target_id == targetid
787 && (((u8)le32_to_cpu(rq->vrq->scsi.flags)) == lun
788 || task_mgt_func == 0x20)) { /* target reset */
789 /* Found a request affected by the task management */
790 if (rq->req_stat == RS_PENDING) {
792 * The request is pending or waiting. We can
793 * safelycomplete the request now.
795 if (esas2r_ioreq_aborted(a, rq, RS_ABORTED))
796 list_add_tail(&rq->comp_list,
797 &comp_list);
802 /* Send the task management request to the firmware */
803 rqaux->sense_len = 0;
804 rqaux->vrq->scsi.length = 0;
805 rqaux->target_id = targetid;
806 rqaux->vrq->scsi.flags |= cpu_to_le32(lun);
807 memset(rqaux->vrq->scsi.cdb, 0, sizeof(rqaux->vrq->scsi.cdb));
808 rqaux->vrq->scsi.flags |=
809 cpu_to_le16(task_mgt_func * LOBIT(FCP_CMND_TM_MASK));
811 if (test_bit(AF_FLASHING, &a->flags)) {
812 /* Assume success. if there are active requests, return busy */
813 rqaux->req_stat = RS_SUCCESS;
815 list_for_each_safe(element, next, &a->active_list) {
816 rq = list_entry(element, struct esas2r_request,
817 req_list);
818 if (rq->vrq->scsi.function == VDA_FUNC_SCSI
819 && rq->target_id == targetid
820 && (((u8)le32_to_cpu(rq->vrq->scsi.flags)) == lun
821 || task_mgt_func == 0x20)) /* target reset */
822 rqaux->req_stat = RS_BUSY;
825 ret = true;
828 spin_unlock_irqrestore(&a->queue_lock, flags);
830 if (!test_bit(AF_FLASHING, &a->flags))
831 esas2r_start_request(a, rqaux);
833 esas2r_comp_list_drain(a, &comp_list);
835 if (atomic_read(&a->disable_cnt) == 0)
836 esas2r_do_deferred_processes(a);
838 esas2r_trace_exit();
840 return ret;
843 void esas2r_reset_bus(struct esas2r_adapter *a)
845 esas2r_log(ESAS2R_LOG_INFO, "performing a bus reset");
847 if (!test_bit(AF_DEGRADED_MODE, &a->flags) &&
848 !test_bit(AF_CHPRST_PENDING, &a->flags) &&
849 !test_bit(AF_DISC_PENDING, &a->flags)) {
850 set_bit(AF_BUSRST_NEEDED, &a->flags);
851 set_bit(AF_BUSRST_PENDING, &a->flags);
852 set_bit(AF_OS_RESET, &a->flags);
854 esas2r_schedule_tasklet(a);
858 bool esas2r_ioreq_aborted(struct esas2r_adapter *a, struct esas2r_request *rq,
859 u8 status)
861 esas2r_trace_enter();
862 esas2r_trace("rq:%p", rq);
863 list_del_init(&rq->req_list);
864 if (rq->timeout > RQ_MAX_TIMEOUT) {
866 * The request timed out, but we could not abort it because a
867 * chip reset occurred. Return busy status.
869 rq->req_stat = RS_BUSY;
870 esas2r_trace_exit();
871 return true;
874 rq->req_stat = status;
875 esas2r_trace_exit();
876 return true;