123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- /*
- * linux/drivers/scsi/esas2r/esas2r_targdb.c
- * For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
- *
- * Copyright (c) 2001-2013 ATTO Technology, Inc.
- * (mailto:linuxdrivers@attotech.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * NO WARRANTY
- * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
- * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
- * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
- * solely responsible for determining the appropriateness of using and
- * distributing the Program and assumes all risks associated with its
- * exercise of rights under this Agreement, including but not limited to
- * the risks and costs of program errors, damage to or loss of data,
- * programs or equipment, and unavailability or interruption of operations.
- *
- * DISCLAIMER OF LIABILITY
- * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
- * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
- */
- #include "esas2r.h"
- void esas2r_targ_db_initialize(struct esas2r_adapter *a)
- {
- struct esas2r_target *t;
- for (t = a->targetdb; t < a->targetdb_end; t++) {
- memset(t, 0, sizeof(struct esas2r_target));
- t->target_state = TS_NOT_PRESENT;
- t->buffered_target_state = TS_NOT_PRESENT;
- t->new_target_state = TS_INVALID;
- }
- }
- void esas2r_targ_db_remove_all(struct esas2r_adapter *a, bool notify)
- {
- struct esas2r_target *t;
- unsigned long flags;
- for (t = a->targetdb; t < a->targetdb_end; t++) {
- if (t->target_state != TS_PRESENT)
- continue;
- spin_lock_irqsave(&a->mem_lock, flags);
- esas2r_targ_db_remove(a, t);
- spin_unlock_irqrestore(&a->mem_lock, flags);
- if (notify) {
- esas2r_trace("remove id:%d", esas2r_targ_get_id(t,
- a));
- esas2r_target_state_changed(a, esas2r_targ_get_id(t,
- a),
- TS_NOT_PRESENT);
- }
- }
- }
- void esas2r_targ_db_report_changes(struct esas2r_adapter *a)
- {
- struct esas2r_target *t;
- unsigned long flags;
- esas2r_trace_enter();
- if (test_bit(AF_DISC_PENDING, &a->flags)) {
- esas2r_trace_exit();
- return;
- }
- for (t = a->targetdb; t < a->targetdb_end; t++) {
- u8 state = TS_INVALID;
- spin_lock_irqsave(&a->mem_lock, flags);
- if (t->buffered_target_state != t->target_state)
- state = t->buffered_target_state = t->target_state;
- spin_unlock_irqrestore(&a->mem_lock, flags);
- if (state != TS_INVALID) {
- esas2r_trace("targ_db_report_changes:%d",
- esas2r_targ_get_id(
- t,
- a));
- esas2r_trace("state:%d", state);
- esas2r_target_state_changed(a,
- esas2r_targ_get_id(t,
- a),
- state);
- }
- }
- esas2r_trace_exit();
- }
- struct esas2r_target *esas2r_targ_db_add_raid(struct esas2r_adapter *a,
- struct esas2r_disc_context *
- dc)
- {
- struct esas2r_target *t;
- esas2r_trace_enter();
- if (dc->curr_virt_id >= ESAS2R_MAX_TARGETS) {
- esas2r_bugon();
- esas2r_trace_exit();
- return NULL;
- }
- t = a->targetdb + dc->curr_virt_id;
- if (t->target_state == TS_PRESENT) {
- esas2r_trace_exit();
- return NULL;
- }
- esas2r_hdebug("add RAID %s, T:%d", dc->raid_grp_name,
- esas2r_targ_get_id(
- t,
- a));
- if (dc->interleave == 0
- || dc->block_size == 0) {
- /* these are invalid values, don't create the target entry. */
- esas2r_hdebug("invalid RAID group dimensions");
- esas2r_trace_exit();
- return NULL;
- }
- t->block_size = dc->block_size;
- t->inter_byte = dc->interleave;
- t->inter_block = dc->interleave / dc->block_size;
- t->virt_targ_id = dc->curr_virt_id;
- t->phys_targ_id = ESAS2R_TARG_ID_INV;
- t->flags &= ~TF_PASS_THRU;
- t->flags |= TF_USED;
- t->identifier_len = 0;
- t->target_state = TS_PRESENT;
- return t;
- }
- struct esas2r_target *esas2r_targ_db_add_pthru(struct esas2r_adapter *a,
- struct esas2r_disc_context *dc,
- u8 *ident,
- u8 ident_len)
- {
- struct esas2r_target *t;
- esas2r_trace_enter();
- if (dc->curr_virt_id >= ESAS2R_MAX_TARGETS) {
- esas2r_bugon();
- esas2r_trace_exit();
- return NULL;
- }
- /* see if we found this device before. */
- t = esas2r_targ_db_find_by_ident(a, ident, ident_len);
- if (t == NULL) {
- t = a->targetdb + dc->curr_virt_id;
- if (ident_len > sizeof(t->identifier)
- || t->target_state == TS_PRESENT) {
- esas2r_trace_exit();
- return NULL;
- }
- }
- esas2r_hdebug("add PT; T:%d, V:%d, P:%d", esas2r_targ_get_id(t, a),
- dc->curr_virt_id,
- dc->curr_phys_id);
- t->block_size = 0;
- t->inter_byte = 0;
- t->inter_block = 0;
- t->virt_targ_id = dc->curr_virt_id;
- t->phys_targ_id = dc->curr_phys_id;
- t->identifier_len = ident_len;
- memcpy(t->identifier, ident, ident_len);
- t->flags |= TF_PASS_THRU | TF_USED;
- t->target_state = TS_PRESENT;
- return t;
- }
- void esas2r_targ_db_remove(struct esas2r_adapter *a, struct esas2r_target *t)
- {
- esas2r_trace_enter();
- t->target_state = TS_NOT_PRESENT;
- esas2r_trace("remove id:%d", esas2r_targ_get_id(t, a));
- esas2r_trace_exit();
- }
- struct esas2r_target *esas2r_targ_db_find_by_sas_addr(struct esas2r_adapter *a,
- u64 *sas_addr)
- {
- struct esas2r_target *t;
- for (t = a->targetdb; t < a->targetdb_end; t++)
- if (t->sas_addr == *sas_addr)
- return t;
- return NULL;
- }
- struct esas2r_target *esas2r_targ_db_find_by_ident(struct esas2r_adapter *a,
- void *identifier,
- u8 ident_len)
- {
- struct esas2r_target *t;
- for (t = a->targetdb; t < a->targetdb_end; t++) {
- if (ident_len == t->identifier_len
- && memcmp(&t->identifier[0], identifier,
- ident_len) == 0)
- return t;
- }
- return NULL;
- }
- u16 esas2r_targ_db_find_next_present(struct esas2r_adapter *a, u16 target_id)
- {
- u16 id = target_id + 1;
- while (id < ESAS2R_MAX_TARGETS) {
- struct esas2r_target *t = a->targetdb + id;
- if (t->target_state == TS_PRESENT)
- break;
- id++;
- }
- return id;
- }
- struct esas2r_target *esas2r_targ_db_find_by_virt_id(struct esas2r_adapter *a,
- u16 virt_id)
- {
- struct esas2r_target *t;
- for (t = a->targetdb; t < a->targetdb_end; t++) {
- if (t->target_state != TS_PRESENT)
- continue;
- if (t->virt_targ_id == virt_id)
- return t;
- }
- return NULL;
- }
- u16 esas2r_targ_db_get_tgt_cnt(struct esas2r_adapter *a)
- {
- u16 devcnt = 0;
- struct esas2r_target *t;
- unsigned long flags;
- spin_lock_irqsave(&a->mem_lock, flags);
- for (t = a->targetdb; t < a->targetdb_end; t++)
- if (t->target_state == TS_PRESENT)
- devcnt++;
- spin_unlock_irqrestore(&a->mem_lock, flags);
- return devcnt;
- }
|