Lines Matching +full:len +full:- +full:or +full:- +full:limit
5 * Copyright (c) 2001-2013 ATTO Technology, Inc.
8 * This program is free software; you can redistribute it and/or
11 * of the License, or (at your option) any later version.
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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
26 * the risks and costs of program errors, damage to or loss of data,
27 * programs or equipment, and unavailability or interruption of operations.
31 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
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
40 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
52 if (unlikely(test_bit(AF_DEGRADED_MODE, &a->flags) || in esas2r_start_request()
53 test_bit(AF_POWER_DOWN, &a->flags))) { in esas2r_start_request()
54 if (rq->vrq->scsi.function == VDA_FUNC_SCSI) in esas2r_start_request()
55 rq->req_stat = RS_SEL2; in esas2r_start_request()
57 rq->req_stat = RS_DEGRADED; in esas2r_start_request()
58 } else if (likely(rq->vrq->scsi.function == VDA_FUNC_SCSI)) { in esas2r_start_request()
59 t = a->targetdb + rq->target_id; in esas2r_start_request()
61 if (unlikely(t >= a->targetdb_end in esas2r_start_request()
62 || !(t->flags & TF_USED))) { in esas2r_start_request()
63 rq->req_stat = RS_SEL; in esas2r_start_request()
66 rq->vrq->scsi.target_id = cpu_to_le16(t->virt_targ_id); in esas2r_start_request()
73 if (unlikely(t->target_state != TS_PRESENT && in esas2r_start_request()
74 !test_bit(AF_DISC_PENDING, &a->flags))) in esas2r_start_request()
75 rq->req_stat = RS_SEL; in esas2r_start_request()
79 if (unlikely(rq->req_stat != RS_PENDING)) { in esas2r_start_request()
85 esas2r_trace("rq->vrq->scsi.handle=%x", rq->vrq->scsi.handle); in esas2r_start_request()
87 if (rq->vrq->scsi.function == VDA_FUNC_SCSI) { in esas2r_start_request()
88 esas2r_trace("rq->target_id=%d", rq->target_id); in esas2r_start_request()
89 esas2r_trace("rq->vrq->scsi.flags=%x", rq->vrq->scsi.flags); in esas2r_start_request()
92 spin_lock_irqsave(&a->queue_lock, flags); in esas2r_start_request()
94 if (likely(list_empty(&a->defer_list) && in esas2r_start_request()
95 !test_bit(AF_CHPRST_PENDING, &a->flags) && in esas2r_start_request()
96 !test_bit(AF_FLASHING, &a->flags) && in esas2r_start_request()
97 !test_bit(AF_DISC_PENDING, &a->flags))) in esas2r_start_request()
100 list_add_tail(&startrq->req_list, &a->defer_list); in esas2r_start_request()
102 spin_unlock_irqrestore(&a->queue_lock, flags); in esas2r_start_request()
113 * waiting or there is a chip reset pending. once the reset condition clears,
124 esas2r_trace("rq->vrq:%p", rq->vrq); in esas2r_local_start_request()
125 esas2r_trace("rq->vrq_md->phys_addr:%x", rq->vrq_md->phys_addr); in esas2r_local_start_request()
127 if (unlikely(rq->vrq->scsi.function == VDA_FUNC_FLASH in esas2r_local_start_request()
128 && rq->vrq->flash.sub_func == VDA_FLASH_COMMIT)) in esas2r_local_start_request()
129 set_bit(AF_FLASHING, &a->flags); in esas2r_local_start_request()
131 list_add_tail(&rq->req_list, &a->active_list); in esas2r_local_start_request()
143 rq->req_stat = RS_STARTED; in esas2r_start_vda_request()
148 a->last_write++; in esas2r_start_vda_request()
149 if (a->last_write >= a->list_size) { in esas2r_start_vda_request()
150 a->last_write = 0; in esas2r_start_vda_request()
152 if (test_bit(AF_COMM_LIST_TOGGLE, &a->flags)) in esas2r_start_vda_request()
153 clear_bit(AF_COMM_LIST_TOGGLE, &a->flags); in esas2r_start_vda_request()
155 set_bit(AF_COMM_LIST_TOGGLE, &a->flags); in esas2r_start_vda_request()
159 (struct esas2r_inbound_list_source_entry *)a->inbound_list_md. in esas2r_start_vda_request()
161 + a->last_write; in esas2r_start_vda_request()
164 if (rq->vda_req_sz == RQ_SIZE_DEFAULT) in esas2r_start_vda_request()
165 rq->vda_req_sz = (u16)(a->max_vdareq_size / sizeof(u32)); in esas2r_start_vda_request()
167 element->address = cpu_to_le64(rq->vrq_md->phys_addr); in esas2r_start_vda_request()
168 element->length = cpu_to_le32(rq->vda_req_sz); in esas2r_start_vda_request()
171 dw = a->last_write; in esas2r_start_vda_request()
173 if (test_bit(AF_COMM_LIST_TOGGLE, &a->flags)) in esas2r_start_vda_request()
176 esas2r_trace("rq->vrq->scsi.handle:%x", rq->vrq->scsi.handle); in esas2r_start_vda_request()
178 esas2r_trace("rq->vda_req_sz:%x", rq->vda_req_sz); in esas2r_start_vda_request()
190 struct esas2r_request *rq = sgc->first_req; in esas2r_build_sg_list_sge()
191 union atto_vda_req *vrq = rq->vrq; in esas2r_build_sg_list_sge()
193 while (sgc->length) { in esas2r_build_sg_list_sge()
196 u32 len; in esas2r_build_sg_list_sge() local
198 len = (*sgc->get_phys_addr)(sgc, &addr); in esas2r_build_sg_list_sge()
200 if (unlikely(len == 0)) in esas2r_build_sg_list_sge()
204 if (unlikely(len > sgc->length)) in esas2r_build_sg_list_sge()
205 len = sgc->length; in esas2r_build_sg_list_sge()
208 /* limit to a round number less than the maximum length */ in esas2r_build_sg_list_sge()
209 if (len > SGE_LEN_MAX) { in esas2r_build_sg_list_sge()
211 * Save the remainder of the split. Whenever we limit in esas2r_build_sg_list_sge()
217 rem = len - SGE_LEN_MAX; in esas2r_build_sg_list_sge()
218 len = SGE_LEN_MAX; in esas2r_build_sg_list_sge()
222 if (unlikely(sgc->sge.a64.curr > sgc->sge.a64.limit)) { in esas2r_build_sg_list_sge()
237 sgelen = (u8)((u8 *)sgc->sge.a64.curr in esas2r_build_sg_list_sge()
238 - (u8 *)sgc->sge.a64.last); in esas2r_build_sg_list_sge()
244 memcpy(sgl->virt_addr, sgc->sge.a64.last, sgelen); in esas2r_build_sg_list_sge()
247 sgc->sge.a64.curr = in esas2r_build_sg_list_sge()
248 (struct atto_vda_sge *)((u8 *)sgl->virt_addr + in esas2r_build_sg_list_sge()
251 /* Set the limit pointer and build the chain entry */ in esas2r_build_sg_list_sge()
252 sgc->sge.a64.limit = in esas2r_build_sg_list_sge()
253 (struct atto_vda_sge *)((u8 *)sgl->virt_addr in esas2r_build_sg_list_sge()
255 - sizeof(struct in esas2r_build_sg_list_sge()
257 sgc->sge.a64.last->length = cpu_to_le32( in esas2r_build_sg_list_sge()
259 sgc->sge.a64.last->address = in esas2r_build_sg_list_sge()
260 cpu_to_le64(sgl->phys_addr); in esas2r_build_sg_list_sge()
268 if (sgc->sge.a64.chain) { in esas2r_build_sg_list_sge()
269 sgc->sge.a64.chain->length |= in esas2r_build_sg_list_sge()
271 ((u8 *)(sgc->sge.a64. in esas2r_build_sg_list_sge()
273 - (u8 *)rq->sg_table-> in esas2r_build_sg_list_sge()
278 vrq->scsi.chain_offset = (u8) in esas2r_build_sg_list_sge()
279 ((u8 *)sgc-> in esas2r_build_sg_list_sge()
280 sge.a64.last - in esas2r_build_sg_list_sge()
288 rq->vda_req_sz = in esas2r_build_sg_list_sge()
289 (vrq->scsi.chain_offset + in esas2r_build_sg_list_sge()
299 sgc->sge.a64.chain = sgc->sge.a64.last; in esas2r_build_sg_list_sge()
302 list_add(&sgl->next_desc, &rq->sg_table_head); in esas2r_build_sg_list_sge()
306 sgc->sge.a64.last = sgc->sge.a64.curr; in esas2r_build_sg_list_sge()
309 sgc->sge.a64.curr->length = cpu_to_le32(SGE_ADDR_64 | len); in esas2r_build_sg_list_sge()
310 sgc->sge.a64.curr->address = cpu_to_le32(addr); in esas2r_build_sg_list_sge()
311 sgc->sge.a64.curr++; in esas2r_build_sg_list_sge()
312 sgc->cur_offset += len; in esas2r_build_sg_list_sge()
313 sgc->length -= len; in esas2r_build_sg_list_sge()
320 addr += len; in esas2r_build_sg_list_sge()
321 len = rem; in esas2r_build_sg_list_sge()
328 sgc->sge.a64.last->length |= cpu_to_le32(SGE_LAST); in esas2r_build_sg_list_sge()
334 if (sgc->sge.a64.chain) { in esas2r_build_sg_list_sge()
335 sgc->sge.a64.chain->length |= cpu_to_le32( in esas2r_build_sg_list_sge()
336 ((u8 *)(sgc->sge.a64.curr) - in esas2r_build_sg_list_sge()
337 (u8 *)rq->sg_table->virt_addr)); in esas2r_build_sg_list_sge()
346 ((u16)((u8 *)sgc->sge.a64.last - (u8 *)vrq) in esas2r_build_sg_list_sge()
354 if (reqsize > rq->vda_req_sz) in esas2r_build_sg_list_sge()
355 rq->vda_req_sz = reqsize; in esas2r_build_sg_list_sge()
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.
368 * I-block and the remaining I-blocks are what remeains.
373 struct esas2r_request *rq = sgc->first_req; in esas2r_build_prd_iblk()
375 u32 len; in esas2r_build_prd_iblk() local
380 while (sgc->length) { in esas2r_build_prd_iblk()
383 len = (*sgc->get_phys_addr)(sgc, &addr); in esas2r_build_prd_iblk()
385 if (unlikely(len == 0)) in esas2r_build_prd_iblk()
390 if (unlikely(len > sgc->length)) in esas2r_build_prd_iblk()
391 len = sgc->length; in esas2r_build_prd_iblk()
394 /* Limit to a round number less than the maximum length */ in esas2r_build_prd_iblk()
396 if (len > PRD_LEN_MAX) { in esas2r_build_prd_iblk()
398 * Save the remainder of the split. whenever we limit in esas2r_build_prd_iblk()
404 rem = len - PRD_LEN_MAX; in esas2r_build_prd_iblk()
405 len = PRD_LEN_MAX; in esas2r_build_prd_iblk()
409 if (sgc->sge.prd.sge_cnt == 0) { in esas2r_build_prd_iblk()
410 if (len == sgc->length) { in esas2r_build_prd_iblk()
418 sgc->sge.prd.curr->ctl_len = cpu_to_le32( in esas2r_build_prd_iblk()
419 PRD_DATA | len); in esas2r_build_prd_iblk()
420 sgc->sge.prd.curr->address = cpu_to_le64(addr); in esas2r_build_prd_iblk()
423 sgc->cur_offset += len; in esas2r_build_prd_iblk()
424 sgc->length -= len; in esas2r_build_prd_iblk()
432 if (sgc->sge.prd.chain) { in esas2r_build_prd_iblk()
439 sgc->sge.prd.chain->ctl_len |= cpu_to_le32( in esas2r_build_prd_iblk()
440 sgc->sge.prd.sgl_max_cnt); in esas2r_build_prd_iblk()
458 list_add(&sgl->next_desc, &rq->sg_table_head); in esas2r_build_prd_iblk()
464 * filled in when the new SGL is filled or ended in esas2r_build_prd_iblk()
467 sgc->sge.prd.chain = sgc->sge.prd.curr; in esas2r_build_prd_iblk()
469 sgc->sge.prd.chain->ctl_len = cpu_to_le32(PRD_CHAIN); in esas2r_build_prd_iblk()
470 sgc->sge.prd.chain->address = in esas2r_build_prd_iblk()
471 cpu_to_le64(sgl->phys_addr); in esas2r_build_prd_iblk()
478 sgc->sge.prd.curr = in esas2r_build_prd_iblk()
480 -> in esas2r_build_prd_iblk()
482 sgc->sge.prd.sge_cnt = sgc->sge.prd.sgl_max_cnt - 1; in esas2r_build_prd_iblk()
485 sgc->sge.prd.sge_cnt--; in esas2r_build_prd_iblk()
487 sgc->sge.prd.curr->ctl_len = cpu_to_le32(PRD_DATA | len); in esas2r_build_prd_iblk()
488 sgc->sge.prd.curr->address = cpu_to_le64(addr); in esas2r_build_prd_iblk()
492 sgc->sge.prd.curr++; in esas2r_build_prd_iblk()
496 sgc->cur_offset += len; in esas2r_build_prd_iblk()
497 sgc->length -= len; in esas2r_build_prd_iblk()
505 addr += len; in esas2r_build_prd_iblk()
506 len = rem; in esas2r_build_prd_iblk()
512 if (!list_empty(&rq->sg_table_head)) { in esas2r_build_prd_iblk()
513 if (sgc->sge.prd.chain) { in esas2r_build_prd_iblk()
514 sgc->sge.prd.chain->ctl_len |= in esas2r_build_prd_iblk()
515 cpu_to_le32(sgc->sge.prd.sgl_max_cnt in esas2r_build_prd_iblk()
516 - sgc->sge.prd.sge_cnt in esas2r_build_prd_iblk()
517 - numchain); in esas2r_build_prd_iblk()
527 struct esas2r_request *rq = sgc->first_req; in esas2r_build_sg_list_prd()
528 u32 len = sgc->length; in esas2r_build_sg_list_prd() local
529 struct esas2r_target *t = a->targetdb + rq->target_id; in esas2r_build_sg_list_prd()
533 u8 *cdb = (u8 *)&rq->vrq->scsi.cdb[0]; in esas2r_build_sg_list_prd()
537 * the I-Block boundary in esas2r_build_sg_list_prd()
540 if (rq->vrq->scsi.function == VDA_FUNC_SCSI in esas2r_build_sg_list_prd()
541 && t->target_state == TS_PRESENT in esas2r_build_sg_list_prd()
542 && !(t->flags & TF_PASS_THRU)) { in esas2r_build_sg_list_prd()
545 switch (rq->vrq->scsi.cdb[0]) { in esas2r_build_sg_list_prd()
591 rq->vrq->scsi.iblk_cnt_prd = 0; in esas2r_build_sg_list_prd()
593 /* Determine size of 1st I-block PRD list */ in esas2r_build_sg_list_prd()
594 startlba = t->inter_block - (lbalo & (t->inter_block - in esas2r_build_sg_list_prd()
596 sgc->length = startlba * t->block_size; in esas2r_build_sg_list_prd()
599 if ((lbalo & (t->inter_block - 1)) == 0) in esas2r_build_sg_list_prd()
600 rq->flags |= RF_1ST_IBLK_BASE; in esas2r_build_sg_list_prd()
602 if (sgc->length > len) in esas2r_build_sg_list_prd()
603 sgc->length = len; in esas2r_build_sg_list_prd()
605 sgc->length = len; in esas2r_build_sg_list_prd()
608 sgc->length = len; in esas2r_build_sg_list_prd()
614 (struct atto_physical_region_description *)sgc->sge.a64.curr; in esas2r_build_sg_list_prd()
616 sgc->sge.prd.sgl_max_cnt = sgl_page_size / in esas2r_build_sg_list_prd()
620 /* create all of the I-block PRD lists */ in esas2r_build_sg_list_prd()
622 while (len) { in esas2r_build_sg_list_prd()
623 sgc->sge.prd.sge_cnt = 0; in esas2r_build_sg_list_prd()
624 sgc->sge.prd.chain = NULL; in esas2r_build_sg_list_prd()
625 sgc->sge.prd.curr = curr_iblk_chn; in esas2r_build_sg_list_prd()
627 /* increment to next I-Block */ in esas2r_build_sg_list_prd()
629 len -= sgc->length; in esas2r_build_sg_list_prd()
631 /* go build the next I-Block PRD list */ in esas2r_build_sg_list_prd()
639 rq->vrq->scsi.iblk_cnt_prd++; in esas2r_build_sg_list_prd()
641 if (len > t->inter_byte) in esas2r_build_sg_list_prd()
642 sgc->length = t->inter_byte; in esas2r_build_sg_list_prd()
644 sgc->length = len; in esas2r_build_sg_list_prd()
650 reqsize = ((u16)((u8 *)curr_iblk_chn - (u8 *)rq->vrq)) in esas2r_build_sg_list_prd()
659 if (reqsize > rq->vda_req_sz) in esas2r_build_sg_list_prd()
660 rq->vda_req_sz = reqsize; in esas2r_build_sg_list_prd()
667 u32 delta = currtime - a->chip_init_time; in esas2r_handle_pending_reset()
691 set_bit(AF_CHPRST_DETECTED, &a->flags); in esas2r_handle_pending_reset()
692 set_bit(AF_LEGACY_SGE_MODE, &a->flags); in esas2r_handle_pending_reset()
694 a->max_vdareq_size = 128; in esas2r_handle_pending_reset()
695 a->build_sgl = esas2r_build_sg_list_sge; in esas2r_handle_pending_reset()
697 set_bit(AF_CHPRST_DETECTED, &a->flags); in esas2r_handle_pending_reset()
698 clear_bit(AF_LEGACY_SGE_MODE, &a->flags); in esas2r_handle_pending_reset()
700 a->max_vdareq_size = 1024; in esas2r_handle_pending_reset()
701 a->build_sgl = esas2r_build_sg_list_prd; in esas2r_handle_pending_reset()
714 u32 deltatime = currtime - a->last_tick_time; in esas2r_timer_tick()
716 a->last_tick_time = currtime; in esas2r_timer_tick()
719 if (a->chip_uptime && in esas2r_timer_tick()
720 !test_bit(AF_CHPRST_PENDING, &a->flags) && in esas2r_timer_tick()
721 !test_bit(AF_DISC_PENDING, &a->flags)) { in esas2r_timer_tick()
722 if (deltatime >= a->chip_uptime) in esas2r_timer_tick()
723 a->chip_uptime = 0; in esas2r_timer_tick()
725 a->chip_uptime -= deltatime; in esas2r_timer_tick()
728 if (test_bit(AF_CHPRST_PENDING, &a->flags)) { in esas2r_timer_tick()
729 if (!test_bit(AF_CHPRST_NEEDED, &a->flags) && in esas2r_timer_tick()
730 !test_bit(AF_CHPRST_DETECTED, &a->flags)) in esas2r_timer_tick()
733 if (test_bit(AF_DISC_PENDING, &a->flags)) in esas2r_timer_tick()
735 if (test_bit(AF_HEARTBEAT_ENB, &a->flags)) { in esas2r_timer_tick()
736 if (test_bit(AF_HEARTBEAT, &a->flags)) { in esas2r_timer_tick()
737 if ((currtime - a->heartbeat_time) >= in esas2r_timer_tick()
739 clear_bit(AF_HEARTBEAT, &a->flags); in esas2r_timer_tick()
747 set_bit(AF_HEARTBEAT, &a->flags); in esas2r_timer_tick()
748 a->heartbeat_time = currtime; in esas2r_timer_tick()
754 if (atomic_read(&a->disable_cnt) == 0) in esas2r_timer_tick()
767 u16 targetid = rqaux->target_id; in esas2r_send_task_mgmt()
768 u8 lun = (u8)le32_to_cpu(rqaux->vrq->scsi.flags); in esas2r_send_task_mgmt()
779 spin_lock_irqsave(&a->queue_lock, flags); in esas2r_send_task_mgmt()
782 list_for_each_safe(element, next, &a->defer_list) { in esas2r_send_task_mgmt()
785 if (rq->vrq->scsi.function == VDA_FUNC_SCSI in esas2r_send_task_mgmt()
786 && rq->target_id == targetid in esas2r_send_task_mgmt()
787 && (((u8)le32_to_cpu(rq->vrq->scsi.flags)) == lun in esas2r_send_task_mgmt()
790 if (rq->req_stat == RS_PENDING) { in esas2r_send_task_mgmt()
792 * The request is pending or waiting. We can in esas2r_send_task_mgmt()
796 list_add_tail(&rq->comp_list, in esas2r_send_task_mgmt()
803 rqaux->sense_len = 0; in esas2r_send_task_mgmt()
804 rqaux->vrq->scsi.length = 0; in esas2r_send_task_mgmt()
805 rqaux->target_id = targetid; in esas2r_send_task_mgmt()
806 rqaux->vrq->scsi.flags |= cpu_to_le32(lun); in esas2r_send_task_mgmt()
807 memset(rqaux->vrq->scsi.cdb, 0, sizeof(rqaux->vrq->scsi.cdb)); in esas2r_send_task_mgmt()
808 rqaux->vrq->scsi.flags |= in esas2r_send_task_mgmt()
811 if (test_bit(AF_FLASHING, &a->flags)) { in esas2r_send_task_mgmt()
813 rqaux->req_stat = RS_SUCCESS; in esas2r_send_task_mgmt()
815 list_for_each_safe(element, next, &a->active_list) { in esas2r_send_task_mgmt()
818 if (rq->vrq->scsi.function == VDA_FUNC_SCSI in esas2r_send_task_mgmt()
819 && rq->target_id == targetid in esas2r_send_task_mgmt()
820 && (((u8)le32_to_cpu(rq->vrq->scsi.flags)) == lun in esas2r_send_task_mgmt()
822 rqaux->req_stat = RS_BUSY; in esas2r_send_task_mgmt()
828 spin_unlock_irqrestore(&a->queue_lock, flags); in esas2r_send_task_mgmt()
830 if (!test_bit(AF_FLASHING, &a->flags)) in esas2r_send_task_mgmt()
835 if (atomic_read(&a->disable_cnt) == 0) in esas2r_send_task_mgmt()
847 if (!test_bit(AF_DEGRADED_MODE, &a->flags) && in esas2r_reset_bus()
848 !test_bit(AF_CHPRST_PENDING, &a->flags) && in esas2r_reset_bus()
849 !test_bit(AF_DISC_PENDING, &a->flags)) { in esas2r_reset_bus()
850 set_bit(AF_BUSRST_NEEDED, &a->flags); in esas2r_reset_bus()
851 set_bit(AF_BUSRST_PENDING, &a->flags); in esas2r_reset_bus()
852 set_bit(AF_OS_RESET, &a->flags); in esas2r_reset_bus()
863 list_del_init(&rq->req_list); in esas2r_ioreq_aborted()
864 if (rq->timeout > RQ_MAX_TIMEOUT) { in esas2r_ioreq_aborted()
869 rq->req_stat = RS_BUSY; in esas2r_ioreq_aborted()
874 rq->req_stat = status; in esas2r_ioreq_aborted()