Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  linux/drivers/scsi/esas2r/esas2r_targdb.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *      For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (c) 2001-2013 ATTO Technology, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  (mailto:linuxdrivers@attotech.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * modify it under the terms of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * as published by the Free Software Foundation; either version 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * of the License, or (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * NO WARRANTY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * solely responsible for determining the appropriateness of using and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * distributing the Program and assumes all risks associated with its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * exercise of rights under this Agreement, including but not limited to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * the risks and costs of program errors, damage to or loss of data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * programs or equipment, and unavailability or interruption of operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * DISCLAIMER OF LIABILITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * along with this program; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * USA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include "esas2r.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) void esas2r_targ_db_initialize(struct esas2r_adapter *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	for (t = a->targetdb; t < a->targetdb_end; t++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		memset(t, 0, sizeof(struct esas2r_target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		t->target_state = TS_NOT_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		t->buffered_target_state = TS_NOT_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		t->new_target_state = TS_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) void esas2r_targ_db_remove_all(struct esas2r_adapter *a, bool notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	for (t = a->targetdb; t < a->targetdb_end; t++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		if (t->target_state != TS_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		spin_lock_irqsave(&a->mem_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		esas2r_targ_db_remove(a, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		spin_unlock_irqrestore(&a->mem_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		if (notify) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			esas2r_trace("remove id:%d", esas2r_targ_get_id(t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 									a));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			esas2r_target_state_changed(a, esas2r_targ_get_id(t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 									  a),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 						    TS_NOT_PRESENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) void esas2r_targ_db_report_changes(struct esas2r_adapter *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	esas2r_trace_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (test_bit(AF_DISC_PENDING, &a->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		esas2r_trace_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	for (t = a->targetdb; t < a->targetdb_end; t++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		u8 state = TS_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		spin_lock_irqsave(&a->mem_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		if (t->buffered_target_state != t->target_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			state = t->buffered_target_state = t->target_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		spin_unlock_irqrestore(&a->mem_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (state != TS_INVALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			esas2r_trace("targ_db_report_changes:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				     esas2r_targ_get_id(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					     t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 					     a));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			esas2r_trace("state:%d", state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			esas2r_target_state_changed(a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 						    esas2r_targ_get_id(t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 								       a),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 						    state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	esas2r_trace_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct esas2r_target *esas2r_targ_db_add_raid(struct esas2r_adapter *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 					      struct esas2r_disc_context *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					      dc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	esas2r_trace_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (dc->curr_virt_id >= ESAS2R_MAX_TARGETS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		esas2r_bugon();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		esas2r_trace_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	t = a->targetdb + dc->curr_virt_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (t->target_state == TS_PRESENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		esas2r_trace_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	esas2r_hdebug("add RAID %s, T:%d", dc->raid_grp_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		      esas2r_targ_get_id(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			      t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			      a));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (dc->interleave == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	    || dc->block_size  == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		/* these are invalid values, don't create the target entry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		esas2r_hdebug("invalid RAID group dimensions");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		esas2r_trace_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	t->block_size = dc->block_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	t->inter_byte = dc->interleave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	t->inter_block = dc->interleave / dc->block_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	t->virt_targ_id = dc->curr_virt_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	t->phys_targ_id = ESAS2R_TARG_ID_INV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	t->flags &= ~TF_PASS_THRU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	t->flags |= TF_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	t->identifier_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	t->target_state = TS_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct esas2r_target *esas2r_targ_db_add_pthru(struct esas2r_adapter *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 					       struct esas2r_disc_context *dc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 					       u8 *ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 					       u8 ident_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	esas2r_trace_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (dc->curr_virt_id >= ESAS2R_MAX_TARGETS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		esas2r_bugon();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		esas2r_trace_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	/* see if we found this device before. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	t = esas2r_targ_db_find_by_ident(a, ident, ident_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (t == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		t = a->targetdb + dc->curr_virt_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (ident_len > sizeof(t->identifier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		    || t->target_state == TS_PRESENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			esas2r_trace_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	esas2r_hdebug("add PT; T:%d, V:%d, P:%d", esas2r_targ_get_id(t, a),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		      dc->curr_virt_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		      dc->curr_phys_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	t->block_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	t->inter_byte = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	t->inter_block = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	t->virt_targ_id = dc->curr_virt_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	t->phys_targ_id = dc->curr_phys_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	t->identifier_len = ident_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	memcpy(t->identifier, ident, ident_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	t->flags |= TF_PASS_THRU | TF_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	t->target_state = TS_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) void esas2r_targ_db_remove(struct esas2r_adapter *a, struct esas2r_target *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	esas2r_trace_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	t->target_state = TS_NOT_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	esas2r_trace("remove id:%d", esas2r_targ_get_id(t, a));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	esas2r_trace_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct esas2r_target *esas2r_targ_db_find_by_sas_addr(struct esas2r_adapter *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 						      u64 *sas_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	for (t = a->targetdb; t < a->targetdb_end; t++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		if (t->sas_addr == *sas_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct esas2r_target *esas2r_targ_db_find_by_ident(struct esas2r_adapter *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 						   void *identifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 						   u8 ident_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	for (t = a->targetdb; t < a->targetdb_end; t++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		if (ident_len == t->identifier_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		    && memcmp(&t->identifier[0], identifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			      ident_len) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) u16 esas2r_targ_db_find_next_present(struct esas2r_adapter *a, u16 target_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	u16 id = target_id + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	while (id < ESAS2R_MAX_TARGETS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		struct esas2r_target *t = a->targetdb + id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		if (t->target_state == TS_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct esas2r_target *esas2r_targ_db_find_by_virt_id(struct esas2r_adapter *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 						     u16 virt_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	for (t = a->targetdb; t < a->targetdb_end; t++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		if (t->target_state != TS_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		if (t->virt_targ_id == virt_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) u16 esas2r_targ_db_get_tgt_cnt(struct esas2r_adapter *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	u16 devcnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	struct esas2r_target *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	spin_lock_irqsave(&a->mem_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	for (t = a->targetdb; t < a->targetdb_end; t++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		if (t->target_state == TS_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			devcnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	spin_unlock_irqrestore(&a->mem_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return devcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }