xref: /OK3568_Linux_fs/kernel/drivers/scsi/isci/remote_node_table.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
3*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
11*4882a593Smuzhiyun  * published by the Free Software Foundation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
15*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16*4882a593Smuzhiyun  * General Public License for more details.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
19*4882a593Smuzhiyun  * along with this program; if not, write to the Free Software
20*4882a593Smuzhiyun  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21*4882a593Smuzhiyun  * The full GNU General Public License is included in this distribution
22*4882a593Smuzhiyun  * in the file called LICENSE.GPL.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * BSD LICENSE
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27*4882a593Smuzhiyun  * All rights reserved.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
30*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
31*4882a593Smuzhiyun  * are met:
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  *   * Redistributions of source code must retain the above copyright
34*4882a593Smuzhiyun  *     notice, this list of conditions and the following disclaimer.
35*4882a593Smuzhiyun  *   * Redistributions in binary form must reproduce the above copyright
36*4882a593Smuzhiyun  *     notice, this list of conditions and the following disclaimer in
37*4882a593Smuzhiyun  *     the documentation and/or other materials provided with the
38*4882a593Smuzhiyun  *     distribution.
39*4882a593Smuzhiyun  *   * Neither the name of Intel Corporation nor the names of its
40*4882a593Smuzhiyun  *     contributors may be used to endorse or promote products derived
41*4882a593Smuzhiyun  *     from this software without specific prior written permission.
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #ifndef _SCIC_SDS_REMOTE_NODE_TABLE_H_
57*4882a593Smuzhiyun #define _SCIC_SDS_REMOTE_NODE_TABLE_H_
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun #include "isci.h"
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /**
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  *
64*4882a593Smuzhiyun  * Remote node sets are sets of remote node index in the remote node table. The
65*4882a593Smuzhiyun  * SCU hardware requires that STP remote node entries take three consecutive
66*4882a593Smuzhiyun  * remote node index so the table is arranged in sets of three. The bits are
67*4882a593Smuzhiyun  * used as 0111 0111 to make a byte and the bits define the set of three remote
68*4882a593Smuzhiyun  * nodes to use as a sequence.
69*4882a593Smuzhiyun  */
70*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODE_SETS_PER_BYTE 2
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /**
73*4882a593Smuzhiyun  *
74*4882a593Smuzhiyun  *
75*4882a593Smuzhiyun  * Since the remote node table is organized as DWORDS take the remote node sets
76*4882a593Smuzhiyun  * in bytes and represent them in DWORDs. The lowest ordered bits are the ones
77*4882a593Smuzhiyun  * used in case full DWORD is not being used. i.e. 0000 0000 0000 0000 0111
78*4882a593Smuzhiyun  * 0111 0111 0111 // if only a single WORD is in use in the DWORD.
79*4882a593Smuzhiyun  */
80*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODE_SETS_PER_DWORD \
81*4882a593Smuzhiyun 	(sizeof(u32) * SCIC_SDS_REMOTE_NODE_SETS_PER_BYTE)
82*4882a593Smuzhiyun /**
83*4882a593Smuzhiyun  *
84*4882a593Smuzhiyun  *
85*4882a593Smuzhiyun  * This is a count of the numeber of remote nodes that can be represented in a
86*4882a593Smuzhiyun  * byte
87*4882a593Smuzhiyun  */
88*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODES_PER_BYTE	\
89*4882a593Smuzhiyun 	(SCU_STP_REMOTE_NODE_COUNT * SCIC_SDS_REMOTE_NODE_SETS_PER_BYTE)
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun /**
92*4882a593Smuzhiyun  *
93*4882a593Smuzhiyun  *
94*4882a593Smuzhiyun  * This is a count of the number of remote nodes that can be represented in a
95*4882a593Smuzhiyun  * DWROD
96*4882a593Smuzhiyun  */
97*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODES_PER_DWORD	\
98*4882a593Smuzhiyun 	(sizeof(u32) * SCIC_SDS_REMOTE_NODES_PER_BYTE)
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun /**
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  *
103*4882a593Smuzhiyun  * This is the number of bits in a remote node group
104*4882a593Smuzhiyun  */
105*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODES_BITS_PER_GROUP   4
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODE_TABLE_INVALID_INDEX      (0xFFFFFFFF)
108*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODE_TABLE_FULL_SLOT_VALUE    (0x07)
109*4882a593Smuzhiyun #define SCIC_SDS_REMOTE_NODE_TABLE_EMPTY_SLOT_VALUE   (0x00)
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /**
112*4882a593Smuzhiyun  *
113*4882a593Smuzhiyun  *
114*4882a593Smuzhiyun  * Expander attached sata remote node count
115*4882a593Smuzhiyun  */
116*4882a593Smuzhiyun #define SCU_STP_REMOTE_NODE_COUNT        3
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /**
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  * Expander or direct attached ssp remote node count
122*4882a593Smuzhiyun  */
123*4882a593Smuzhiyun #define SCU_SSP_REMOTE_NODE_COUNT        1
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /**
126*4882a593Smuzhiyun  *
127*4882a593Smuzhiyun  *
128*4882a593Smuzhiyun  * Direct attached STP remote node count
129*4882a593Smuzhiyun  */
130*4882a593Smuzhiyun #define SCU_SATA_REMOTE_NODE_COUNT       1
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun /**
133*4882a593Smuzhiyun  * struct sci_remote_node_table -
134*4882a593Smuzhiyun  *
135*4882a593Smuzhiyun  *
136*4882a593Smuzhiyun  */
137*4882a593Smuzhiyun struct sci_remote_node_table {
138*4882a593Smuzhiyun 	/**
139*4882a593Smuzhiyun 	 * This field contains the array size in dwords
140*4882a593Smuzhiyun 	 */
141*4882a593Smuzhiyun 	u16 available_nodes_array_size;
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	/**
144*4882a593Smuzhiyun 	 * This field contains the array size of the
145*4882a593Smuzhiyun 	 */
146*4882a593Smuzhiyun 	u16 group_array_size;
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	/**
149*4882a593Smuzhiyun 	 * This field is the array of available remote node entries in bits.
150*4882a593Smuzhiyun 	 * Because of the way STP remote node data is allocated on the SCU hardware
151*4882a593Smuzhiyun 	 * the remote nodes must occupy three consecutive remote node context
152*4882a593Smuzhiyun 	 * entries.  For ease of allocation and de-allocation we have broken the
153*4882a593Smuzhiyun 	 * sets of three into a single nibble.  When the STP RNi is allocated all
154*4882a593Smuzhiyun 	 * of the bits in the nibble are cleared.  This math results in a table size
155*4882a593Smuzhiyun 	 * of MAX_REMOTE_NODES / CONSECUTIVE RNi ENTRIES for STP / 2 entries per byte.
156*4882a593Smuzhiyun 	 */
157*4882a593Smuzhiyun 	u32 available_remote_nodes[
158*4882a593Smuzhiyun 		(SCI_MAX_REMOTE_DEVICES / SCIC_SDS_REMOTE_NODES_PER_DWORD)
159*4882a593Smuzhiyun 		+ ((SCI_MAX_REMOTE_DEVICES % SCIC_SDS_REMOTE_NODES_PER_DWORD) != 0)];
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	/**
162*4882a593Smuzhiyun 	 * This field is the nibble selector for the above table.  There are three
163*4882a593Smuzhiyun 	 * possible selectors each for fast lookup when trying to find one, two or
164*4882a593Smuzhiyun 	 * three remote node entries.
165*4882a593Smuzhiyun 	 */
166*4882a593Smuzhiyun 	u32 remote_node_groups[
167*4882a593Smuzhiyun 		SCU_STP_REMOTE_NODE_COUNT][
168*4882a593Smuzhiyun 		(SCI_MAX_REMOTE_DEVICES / (32 * SCU_STP_REMOTE_NODE_COUNT))
169*4882a593Smuzhiyun 		+ ((SCI_MAX_REMOTE_DEVICES % (32 * SCU_STP_REMOTE_NODE_COUNT)) != 0)];
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun };
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun /* --------------------------------------------------------------------------- */
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun void sci_remote_node_table_initialize(
176*4882a593Smuzhiyun 	struct sci_remote_node_table *remote_node_table,
177*4882a593Smuzhiyun 	u32 remote_node_entries);
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun u16 sci_remote_node_table_allocate_remote_node(
180*4882a593Smuzhiyun 	struct sci_remote_node_table *remote_node_table,
181*4882a593Smuzhiyun 	u32 remote_node_count);
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun void sci_remote_node_table_release_remote_node_index(
184*4882a593Smuzhiyun 	struct sci_remote_node_table *remote_node_table,
185*4882a593Smuzhiyun 	u32 remote_node_count,
186*4882a593Smuzhiyun 	u16 remote_node_index);
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun #endif /* _SCIC_SDS_REMOTE_NODE_TABLE_H_ */
189