xref: /openbmc/linux/drivers/scsi/isci/remote_node_table.h (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
188f3b62aSDan Williams /*
288f3b62aSDan Williams  * This file is provided under a dual BSD/GPLv2 license.  When using or
388f3b62aSDan Williams  * redistributing this file, you may do so under either license.
488f3b62aSDan Williams  *
588f3b62aSDan Williams  * GPL LICENSE SUMMARY
688f3b62aSDan Williams  *
788f3b62aSDan Williams  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
888f3b62aSDan Williams  *
988f3b62aSDan Williams  * This program is free software; you can redistribute it and/or modify
1088f3b62aSDan Williams  * it under the terms of version 2 of the GNU General Public License as
1188f3b62aSDan Williams  * published by the Free Software Foundation.
1288f3b62aSDan Williams  *
1388f3b62aSDan Williams  * This program is distributed in the hope that it will be useful, but
1488f3b62aSDan Williams  * WITHOUT ANY WARRANTY; without even the implied warranty of
1588f3b62aSDan Williams  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1688f3b62aSDan Williams  * General Public License for more details.
1788f3b62aSDan Williams  *
1888f3b62aSDan Williams  * You should have received a copy of the GNU General Public License
1988f3b62aSDan Williams  * along with this program; if not, write to the Free Software
2088f3b62aSDan Williams  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
2188f3b62aSDan Williams  * The full GNU General Public License is included in this distribution
2288f3b62aSDan Williams  * in the file called LICENSE.GPL.
2388f3b62aSDan Williams  *
2488f3b62aSDan Williams  * BSD LICENSE
2588f3b62aSDan Williams  *
2688f3b62aSDan Williams  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
2788f3b62aSDan Williams  * All rights reserved.
2888f3b62aSDan Williams  *
2988f3b62aSDan Williams  * Redistribution and use in source and binary forms, with or without
3088f3b62aSDan Williams  * modification, are permitted provided that the following conditions
3188f3b62aSDan Williams  * are met:
3288f3b62aSDan Williams  *
3388f3b62aSDan Williams  *   * Redistributions of source code must retain the above copyright
3488f3b62aSDan Williams  *     notice, this list of conditions and the following disclaimer.
3588f3b62aSDan Williams  *   * Redistributions in binary form must reproduce the above copyright
3688f3b62aSDan Williams  *     notice, this list of conditions and the following disclaimer in
3788f3b62aSDan Williams  *     the documentation and/or other materials provided with the
3888f3b62aSDan Williams  *     distribution.
3988f3b62aSDan Williams  *   * Neither the name of Intel Corporation nor the names of its
4088f3b62aSDan Williams  *     contributors may be used to endorse or promote products derived
4188f3b62aSDan Williams  *     from this software without specific prior written permission.
4288f3b62aSDan Williams  *
4388f3b62aSDan Williams  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4488f3b62aSDan Williams  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4588f3b62aSDan Williams  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4688f3b62aSDan Williams  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4788f3b62aSDan Williams  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4888f3b62aSDan Williams  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4988f3b62aSDan Williams  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5088f3b62aSDan Williams  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5188f3b62aSDan Williams  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5288f3b62aSDan Williams  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5388f3b62aSDan Williams  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5488f3b62aSDan Williams  */
5588f3b62aSDan Williams 
5688f3b62aSDan Williams #ifndef _SCIC_SDS_REMOTE_NODE_TABLE_H_
5788f3b62aSDan Williams #define _SCIC_SDS_REMOTE_NODE_TABLE_H_
5888f3b62aSDan Williams 
59ce2b3261SDan Williams #include "isci.h"
6088f3b62aSDan Williams 
6188f3b62aSDan Williams /**
6288f3b62aSDan Williams  *
6388f3b62aSDan Williams  *
64*45660591SChristophe JAILLET  * Remote node sets are sets of remote node index in the remote node table. The
6588f3b62aSDan Williams  * SCU hardware requires that STP remote node entries take three consecutive
6688f3b62aSDan Williams  * remote node index so the table is arranged in sets of three. The bits are
6788f3b62aSDan Williams  * used as 0111 0111 to make a byte and the bits define the set of three remote
6888f3b62aSDan Williams  * nodes to use as a sequence.
6988f3b62aSDan Williams  */
7088f3b62aSDan Williams #define SCIC_SDS_REMOTE_NODE_SETS_PER_BYTE 2
7188f3b62aSDan Williams 
7288f3b62aSDan Williams /**
7388f3b62aSDan Williams  *
7488f3b62aSDan Williams  *
7588f3b62aSDan Williams  * Since the remote node table is organized as DWORDS take the remote node sets
7688f3b62aSDan Williams  * in bytes and represent them in DWORDs. The lowest ordered bits are the ones
7788f3b62aSDan Williams  * used in case full DWORD is not being used. i.e. 0000 0000 0000 0000 0111
7888f3b62aSDan Williams  * 0111 0111 0111 // if only a single WORD is in use in the DWORD.
7988f3b62aSDan Williams  */
8088f3b62aSDan Williams #define SCIC_SDS_REMOTE_NODE_SETS_PER_DWORD \
8188f3b62aSDan Williams 	(sizeof(u32) * SCIC_SDS_REMOTE_NODE_SETS_PER_BYTE)
8288f3b62aSDan Williams /**
8388f3b62aSDan Williams  *
8488f3b62aSDan Williams  *
8588f3b62aSDan Williams  * This is a count of the numeber of remote nodes that can be represented in a
8688f3b62aSDan Williams  * byte
8788f3b62aSDan Williams  */
8888f3b62aSDan Williams #define SCIC_SDS_REMOTE_NODES_PER_BYTE	\
8988f3b62aSDan Williams 	(SCU_STP_REMOTE_NODE_COUNT * SCIC_SDS_REMOTE_NODE_SETS_PER_BYTE)
9088f3b62aSDan Williams 
9188f3b62aSDan Williams /**
9288f3b62aSDan Williams  *
9388f3b62aSDan Williams  *
9488f3b62aSDan Williams  * This is a count of the number of remote nodes that can be represented in a
9588f3b62aSDan Williams  * DWROD
9688f3b62aSDan Williams  */
9788f3b62aSDan Williams #define SCIC_SDS_REMOTE_NODES_PER_DWORD	\
9888f3b62aSDan Williams 	(sizeof(u32) * SCIC_SDS_REMOTE_NODES_PER_BYTE)
9988f3b62aSDan Williams 
10088f3b62aSDan Williams /**
10188f3b62aSDan Williams  *
10288f3b62aSDan Williams  *
10388f3b62aSDan Williams  * This is the number of bits in a remote node group
10488f3b62aSDan Williams  */
10588f3b62aSDan Williams #define SCIC_SDS_REMOTE_NODES_BITS_PER_GROUP   4
10688f3b62aSDan Williams 
10788f3b62aSDan Williams #define SCIC_SDS_REMOTE_NODE_TABLE_INVALID_INDEX      (0xFFFFFFFF)
10888f3b62aSDan Williams #define SCIC_SDS_REMOTE_NODE_TABLE_FULL_SLOT_VALUE    (0x07)
10988f3b62aSDan Williams #define SCIC_SDS_REMOTE_NODE_TABLE_EMPTY_SLOT_VALUE   (0x00)
11088f3b62aSDan Williams 
11188f3b62aSDan Williams /**
11288f3b62aSDan Williams  *
11388f3b62aSDan Williams  *
11488f3b62aSDan Williams  * Expander attached sata remote node count
11588f3b62aSDan Williams  */
11688f3b62aSDan Williams #define SCU_STP_REMOTE_NODE_COUNT        3
11788f3b62aSDan Williams 
11888f3b62aSDan Williams /**
11988f3b62aSDan Williams  *
12088f3b62aSDan Williams  *
12188f3b62aSDan Williams  * Expander or direct attached ssp remote node count
12288f3b62aSDan Williams  */
12388f3b62aSDan Williams #define SCU_SSP_REMOTE_NODE_COUNT        1
12488f3b62aSDan Williams 
12588f3b62aSDan Williams /**
12688f3b62aSDan Williams  *
12788f3b62aSDan Williams  *
12888f3b62aSDan Williams  * Direct attached STP remote node count
12988f3b62aSDan Williams  */
13088f3b62aSDan Williams #define SCU_SATA_REMOTE_NODE_COUNT       1
13188f3b62aSDan Williams 
13288f3b62aSDan Williams /**
13389a7301fSDan Williams  * struct sci_remote_node_table -
13488f3b62aSDan Williams  *
13588f3b62aSDan Williams  *
13688f3b62aSDan Williams  */
13789a7301fSDan Williams struct sci_remote_node_table {
13888f3b62aSDan Williams 	/**
13988f3b62aSDan Williams 	 * This field contains the array size in dwords
14088f3b62aSDan Williams 	 */
14188f3b62aSDan Williams 	u16 available_nodes_array_size;
14288f3b62aSDan Williams 
14388f3b62aSDan Williams 	/**
14488f3b62aSDan Williams 	 * This field contains the array size of the
14588f3b62aSDan Williams 	 */
14688f3b62aSDan Williams 	u16 group_array_size;
14788f3b62aSDan Williams 
14888f3b62aSDan Williams 	/**
14988f3b62aSDan Williams 	 * This field is the array of available remote node entries in bits.
15088f3b62aSDan Williams 	 * Because of the way STP remote node data is allocated on the SCU hardware
15188f3b62aSDan Williams 	 * the remote nodes must occupy three consecutive remote node context
15288f3b62aSDan Williams 	 * entries.  For ease of allocation and de-allocation we have broken the
15388f3b62aSDan Williams 	 * sets of three into a single nibble.  When the STP RNi is allocated all
15488f3b62aSDan Williams 	 * of the bits in the nibble are cleared.  This math results in a table size
15588f3b62aSDan Williams 	 * of MAX_REMOTE_NODES / CONSECUTIVE RNi ENTRIES for STP / 2 entries per byte.
15688f3b62aSDan Williams 	 */
15788f3b62aSDan Williams 	u32 available_remote_nodes[
15888f3b62aSDan Williams 		(SCI_MAX_REMOTE_DEVICES / SCIC_SDS_REMOTE_NODES_PER_DWORD)
15988f3b62aSDan Williams 		+ ((SCI_MAX_REMOTE_DEVICES % SCIC_SDS_REMOTE_NODES_PER_DWORD) != 0)];
16088f3b62aSDan Williams 
16188f3b62aSDan Williams 	/**
16288f3b62aSDan Williams 	 * This field is the nibble selector for the above table.  There are three
16388f3b62aSDan Williams 	 * possible selectors each for fast lookup when trying to find one, two or
16488f3b62aSDan Williams 	 * three remote node entries.
16588f3b62aSDan Williams 	 */
16688f3b62aSDan Williams 	u32 remote_node_groups[
16788f3b62aSDan Williams 		SCU_STP_REMOTE_NODE_COUNT][
16888f3b62aSDan Williams 		(SCI_MAX_REMOTE_DEVICES / (32 * SCU_STP_REMOTE_NODE_COUNT))
16988f3b62aSDan Williams 		+ ((SCI_MAX_REMOTE_DEVICES % (32 * SCU_STP_REMOTE_NODE_COUNT)) != 0)];
17088f3b62aSDan Williams 
17188f3b62aSDan Williams };
17288f3b62aSDan Williams 
17388f3b62aSDan Williams /* --------------------------------------------------------------------------- */
17488f3b62aSDan Williams 
17589a7301fSDan Williams void sci_remote_node_table_initialize(
17689a7301fSDan Williams 	struct sci_remote_node_table *remote_node_table,
17788f3b62aSDan Williams 	u32 remote_node_entries);
17888f3b62aSDan Williams 
17989a7301fSDan Williams u16 sci_remote_node_table_allocate_remote_node(
18089a7301fSDan Williams 	struct sci_remote_node_table *remote_node_table,
18188f3b62aSDan Williams 	u32 remote_node_count);
18288f3b62aSDan Williams 
18389a7301fSDan Williams void sci_remote_node_table_release_remote_node_index(
18489a7301fSDan Williams 	struct sci_remote_node_table *remote_node_table,
18588f3b62aSDan Williams 	u32 remote_node_count,
18688f3b62aSDan Williams 	u16 remote_node_index);
18788f3b62aSDan Williams 
18888f3b62aSDan Williams #endif /* _SCIC_SDS_REMOTE_NODE_TABLE_H_ */
189