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 __ISCI_H__
57*4882a593Smuzhiyun #define __ISCI_H__
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun #include <linux/interrupt.h>
60*4882a593Smuzhiyun #include <linux/types.h>
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun #define DRV_NAME "isci"
63*4882a593Smuzhiyun #define SCI_PCI_BAR_COUNT 2
64*4882a593Smuzhiyun #define SCI_NUM_MSI_X_INT 2
65*4882a593Smuzhiyun #define SCI_SMU_BAR 0
66*4882a593Smuzhiyun #define SCI_SMU_BAR_SIZE (16*1024)
67*4882a593Smuzhiyun #define SCI_SCU_BAR 1
68*4882a593Smuzhiyun #define SCI_SCU_BAR_SIZE (4*1024*1024)
69*4882a593Smuzhiyun #define SCI_IO_SPACE_BAR0 2
70*4882a593Smuzhiyun #define SCI_IO_SPACE_BAR1 3
71*4882a593Smuzhiyun #define ISCI_CAN_QUEUE_VAL 250 /* < SCI_MAX_IO_REQUESTS ? */
72*4882a593Smuzhiyun #define SCIC_CONTROLLER_STOP_TIMEOUT 5000
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #define SCI_CONTROLLER_INVALID_IO_TAG 0xFFFF
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #define SCI_MAX_PHYS (4UL)
77*4882a593Smuzhiyun #define SCI_MAX_PORTS SCI_MAX_PHYS
78*4882a593Smuzhiyun #define SCI_MAX_SMP_PHYS (384) /* not silicon constrained */
79*4882a593Smuzhiyun #define SCI_MAX_REMOTE_DEVICES (256UL)
80*4882a593Smuzhiyun #define SCI_MAX_IO_REQUESTS (256UL)
81*4882a593Smuzhiyun #define SCI_MAX_SEQ (16)
82*4882a593Smuzhiyun #define SCI_MAX_MSIX_MESSAGES (2)
83*4882a593Smuzhiyun #define SCI_MAX_SCATTER_GATHER_ELEMENTS 130 /* not silicon constrained */
84*4882a593Smuzhiyun #define SCI_MAX_CONTROLLERS 2
85*4882a593Smuzhiyun #define SCI_MAX_DOMAINS SCI_MAX_PORTS
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun #define SCU_MAX_CRITICAL_NOTIFICATIONS (384)
88*4882a593Smuzhiyun #define SCU_MAX_EVENTS_SHIFT (7)
89*4882a593Smuzhiyun #define SCU_MAX_EVENTS (1 << SCU_MAX_EVENTS_SHIFT)
90*4882a593Smuzhiyun #define SCU_MAX_UNSOLICITED_FRAMES (128)
91*4882a593Smuzhiyun #define SCU_MAX_COMPLETION_QUEUE_SCRATCH (128)
92*4882a593Smuzhiyun #define SCU_MAX_COMPLETION_QUEUE_ENTRIES (SCU_MAX_CRITICAL_NOTIFICATIONS \
93*4882a593Smuzhiyun + SCU_MAX_EVENTS \
94*4882a593Smuzhiyun + SCU_MAX_UNSOLICITED_FRAMES \
95*4882a593Smuzhiyun + SCI_MAX_IO_REQUESTS \
96*4882a593Smuzhiyun + SCU_MAX_COMPLETION_QUEUE_SCRATCH)
97*4882a593Smuzhiyun #define SCU_MAX_COMPLETION_QUEUE_SHIFT (ilog2(SCU_MAX_COMPLETION_QUEUE_ENTRIES))
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun #define SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES (4096)
100*4882a593Smuzhiyun #define SCU_UNSOLICITED_FRAME_BUFFER_SIZE (1024U)
101*4882a593Smuzhiyun #define SCU_INVALID_FRAME_INDEX (0xFFFF)
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun #define SCU_IO_REQUEST_MAX_SGE_SIZE (0x00FFFFFF)
104*4882a593Smuzhiyun #define SCU_IO_REQUEST_MAX_TRANSFER_LENGTH (0x00FFFFFF)
105*4882a593Smuzhiyun
check_sizes(void)106*4882a593Smuzhiyun static inline void check_sizes(void)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_EVENTS);
109*4882a593Smuzhiyun BUILD_BUG_ON(SCU_MAX_UNSOLICITED_FRAMES <= 8);
110*4882a593Smuzhiyun BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_UNSOLICITED_FRAMES);
111*4882a593Smuzhiyun BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_COMPLETION_QUEUE_ENTRIES);
112*4882a593Smuzhiyun BUILD_BUG_ON(SCU_MAX_UNSOLICITED_FRAMES > SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES);
113*4882a593Smuzhiyun BUILD_BUG_ON_NOT_POWER_OF_2(SCI_MAX_IO_REQUESTS);
114*4882a593Smuzhiyun BUILD_BUG_ON_NOT_POWER_OF_2(SCI_MAX_SEQ);
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun /**
118*4882a593Smuzhiyun * enum sci_status - This is the general return status enumeration for non-IO,
119*4882a593Smuzhiyun * non-task management related SCI interface methods.
120*4882a593Smuzhiyun *
121*4882a593Smuzhiyun *
122*4882a593Smuzhiyun */
123*4882a593Smuzhiyun enum sci_status {
124*4882a593Smuzhiyun /**
125*4882a593Smuzhiyun * This member indicates successful completion.
126*4882a593Smuzhiyun */
127*4882a593Smuzhiyun SCI_SUCCESS = 0,
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun /**
130*4882a593Smuzhiyun * This value indicates that the calling method completed successfully,
131*4882a593Smuzhiyun * but that the IO may have completed before having it's start method
132*4882a593Smuzhiyun * invoked. This occurs during SAT translation for requests that do
133*4882a593Smuzhiyun * not require an IO to the target or for any other requests that may
134*4882a593Smuzhiyun * be completed without having to submit IO.
135*4882a593Smuzhiyun */
136*4882a593Smuzhiyun SCI_SUCCESS_IO_COMPLETE_BEFORE_START,
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun /**
139*4882a593Smuzhiyun * This Value indicates that the SCU hardware returned an early response
140*4882a593Smuzhiyun * because the io request specified more data than is returned by the
141*4882a593Smuzhiyun * target device (mode pages, inquiry data, etc.). The completion routine
142*4882a593Smuzhiyun * will handle this case to get the actual number of bytes transferred.
143*4882a593Smuzhiyun */
144*4882a593Smuzhiyun SCI_SUCCESS_IO_DONE_EARLY,
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun /**
147*4882a593Smuzhiyun * This member indicates that the object for which a state change is
148*4882a593Smuzhiyun * being requested is already in said state.
149*4882a593Smuzhiyun */
150*4882a593Smuzhiyun SCI_WARNING_ALREADY_IN_STATE,
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun /**
153*4882a593Smuzhiyun * This member indicates interrupt coalescence timer may cause SAS
154*4882a593Smuzhiyun * specification compliance issues (i.e. SMP target mode response
155*4882a593Smuzhiyun * frames must be returned within 1.9 milliseconds).
156*4882a593Smuzhiyun */
157*4882a593Smuzhiyun SCI_WARNING_TIMER_CONFLICT,
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun /**
160*4882a593Smuzhiyun * This field indicates a sequence of action is not completed yet. Mostly,
161*4882a593Smuzhiyun * this status is used when multiple ATA commands are needed in a SATI translation.
162*4882a593Smuzhiyun */
163*4882a593Smuzhiyun SCI_WARNING_SEQUENCE_INCOMPLETE,
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun /**
166*4882a593Smuzhiyun * This member indicates that there was a general failure.
167*4882a593Smuzhiyun */
168*4882a593Smuzhiyun SCI_FAILURE,
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /**
171*4882a593Smuzhiyun * This member indicates that the SCI implementation is unable to complete
172*4882a593Smuzhiyun * an operation due to a critical flaw the prevents any further operation
173*4882a593Smuzhiyun * (i.e. an invalid pointer).
174*4882a593Smuzhiyun */
175*4882a593Smuzhiyun SCI_FATAL_ERROR,
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /**
178*4882a593Smuzhiyun * This member indicates the calling function failed, because the state
179*4882a593Smuzhiyun * of the controller is in a state that prevents successful completion.
180*4882a593Smuzhiyun */
181*4882a593Smuzhiyun SCI_FAILURE_INVALID_STATE,
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun /**
184*4882a593Smuzhiyun * This member indicates the calling function failed, because there is
185*4882a593Smuzhiyun * insufficient resources/memory to complete the request.
186*4882a593Smuzhiyun */
187*4882a593Smuzhiyun SCI_FAILURE_INSUFFICIENT_RESOURCES,
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun /**
190*4882a593Smuzhiyun * This member indicates the calling function failed, because the
191*4882a593Smuzhiyun * controller object required for the operation can't be located.
192*4882a593Smuzhiyun */
193*4882a593Smuzhiyun SCI_FAILURE_CONTROLLER_NOT_FOUND,
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun /**
196*4882a593Smuzhiyun * This member indicates the calling function failed, because the
197*4882a593Smuzhiyun * discovered controller type is not supported by the library.
198*4882a593Smuzhiyun */
199*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_CONTROLLER_TYPE,
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun /**
202*4882a593Smuzhiyun * This member indicates the calling function failed, because the
203*4882a593Smuzhiyun * requested initialization data version isn't supported.
204*4882a593Smuzhiyun */
205*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_INIT_DATA_VERSION,
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun /**
208*4882a593Smuzhiyun * This member indicates the calling function failed, because the
209*4882a593Smuzhiyun * requested configuration of SAS Phys into SAS Ports is not supported.
210*4882a593Smuzhiyun */
211*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION,
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun /**
214*4882a593Smuzhiyun * This member indicates the calling function failed, because the
215*4882a593Smuzhiyun * requested protocol is not supported by the remote device, port,
216*4882a593Smuzhiyun * or controller.
217*4882a593Smuzhiyun */
218*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_PROTOCOL,
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun /**
221*4882a593Smuzhiyun * This member indicates the calling function failed, because the
222*4882a593Smuzhiyun * requested information type is not supported by the SCI implementation.
223*4882a593Smuzhiyun */
224*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_INFORMATION_TYPE,
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun /**
227*4882a593Smuzhiyun * This member indicates the calling function failed, because the
228*4882a593Smuzhiyun * device already exists.
229*4882a593Smuzhiyun */
230*4882a593Smuzhiyun SCI_FAILURE_DEVICE_EXISTS,
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun /**
233*4882a593Smuzhiyun * This member indicates the calling function failed, because adding
234*4882a593Smuzhiyun * a phy to the object is not possible.
235*4882a593Smuzhiyun */
236*4882a593Smuzhiyun SCI_FAILURE_ADDING_PHY_UNSUPPORTED,
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun /**
239*4882a593Smuzhiyun * This member indicates the calling function failed, because the
240*4882a593Smuzhiyun * requested information type is not supported by the SCI implementation.
241*4882a593Smuzhiyun */
242*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD,
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun /**
245*4882a593Smuzhiyun * This member indicates the calling function failed, because the SCI
246*4882a593Smuzhiyun * implementation does not support the supplied time limit.
247*4882a593Smuzhiyun */
248*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_TIME_LIMIT,
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun /**
251*4882a593Smuzhiyun * This member indicates the calling method failed, because the SCI
252*4882a593Smuzhiyun * implementation does not contain the specified Phy.
253*4882a593Smuzhiyun */
254*4882a593Smuzhiyun SCI_FAILURE_INVALID_PHY,
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun /**
257*4882a593Smuzhiyun * This member indicates the calling method failed, because the SCI
258*4882a593Smuzhiyun * implementation does not contain the specified Port.
259*4882a593Smuzhiyun */
260*4882a593Smuzhiyun SCI_FAILURE_INVALID_PORT,
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun /**
263*4882a593Smuzhiyun * This member indicates the calling method was partly successful
264*4882a593Smuzhiyun * The port was reset but not all phys in port are operational
265*4882a593Smuzhiyun */
266*4882a593Smuzhiyun SCI_FAILURE_RESET_PORT_PARTIAL_SUCCESS,
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun /**
269*4882a593Smuzhiyun * This member indicates that calling method failed
270*4882a593Smuzhiyun * The port reset did not complete because none of the phys are operational
271*4882a593Smuzhiyun */
272*4882a593Smuzhiyun SCI_FAILURE_RESET_PORT_FAILURE,
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun /**
275*4882a593Smuzhiyun * This member indicates the calling method failed, because the SCI
276*4882a593Smuzhiyun * implementation does not contain the specified remote device.
277*4882a593Smuzhiyun */
278*4882a593Smuzhiyun SCI_FAILURE_INVALID_REMOTE_DEVICE,
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun /**
281*4882a593Smuzhiyun * This member indicates the calling method failed, because the remote
282*4882a593Smuzhiyun * device is in a bad state and requires a reset.
283*4882a593Smuzhiyun */
284*4882a593Smuzhiyun SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun /**
287*4882a593Smuzhiyun * This member indicates the calling method failed, because the SCI
288*4882a593Smuzhiyun * implementation does not contain or support the specified IO tag.
289*4882a593Smuzhiyun */
290*4882a593Smuzhiyun SCI_FAILURE_INVALID_IO_TAG,
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun /**
293*4882a593Smuzhiyun * This member indicates that the operation failed and the user should
294*4882a593Smuzhiyun * check the response data associated with the IO.
295*4882a593Smuzhiyun */
296*4882a593Smuzhiyun SCI_FAILURE_IO_RESPONSE_VALID,
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun /**
299*4882a593Smuzhiyun * This member indicates that the operation failed, the failure is
300*4882a593Smuzhiyun * controller implementation specific, and the response data associated
301*4882a593Smuzhiyun * with the request is not valid. You can query for the controller
302*4882a593Smuzhiyun * specific error information via sci_controller_get_request_status()
303*4882a593Smuzhiyun */
304*4882a593Smuzhiyun SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun /**
307*4882a593Smuzhiyun * This member indicated that the operation failed because the
308*4882a593Smuzhiyun * user requested this IO to be terminated.
309*4882a593Smuzhiyun */
310*4882a593Smuzhiyun SCI_FAILURE_IO_TERMINATED,
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun /**
313*4882a593Smuzhiyun * This member indicates that the operation failed and the associated
314*4882a593Smuzhiyun * request requires a SCSI abort task to be sent to the target.
315*4882a593Smuzhiyun */
316*4882a593Smuzhiyun SCI_FAILURE_IO_REQUIRES_SCSI_ABORT,
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun /**
319*4882a593Smuzhiyun * This member indicates that the operation failed because the supplied
320*4882a593Smuzhiyun * device could not be located.
321*4882a593Smuzhiyun */
322*4882a593Smuzhiyun SCI_FAILURE_DEVICE_NOT_FOUND,
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun /**
325*4882a593Smuzhiyun * This member indicates that the operation failed because the
326*4882a593Smuzhiyun * objects association is required and is not correctly set.
327*4882a593Smuzhiyun */
328*4882a593Smuzhiyun SCI_FAILURE_INVALID_ASSOCIATION,
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun /**
331*4882a593Smuzhiyun * This member indicates that the operation failed, because a timeout
332*4882a593Smuzhiyun * occurred.
333*4882a593Smuzhiyun */
334*4882a593Smuzhiyun SCI_FAILURE_TIMEOUT,
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun /**
337*4882a593Smuzhiyun * This member indicates that the operation failed, because the user
338*4882a593Smuzhiyun * specified a value that is either invalid or not supported.
339*4882a593Smuzhiyun */
340*4882a593Smuzhiyun SCI_FAILURE_INVALID_PARAMETER_VALUE,
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun /**
343*4882a593Smuzhiyun * This value indicates that the operation failed, because the number
344*4882a593Smuzhiyun * of messages (MSI-X) is not supported.
345*4882a593Smuzhiyun */
346*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_MESSAGE_COUNT,
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun /**
349*4882a593Smuzhiyun * This value indicates that the method failed due to a lack of
350*4882a593Smuzhiyun * available NCQ tags.
351*4882a593Smuzhiyun */
352*4882a593Smuzhiyun SCI_FAILURE_NO_NCQ_TAG_AVAILABLE,
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun /**
355*4882a593Smuzhiyun * This value indicates that a protocol violation has occurred on the
356*4882a593Smuzhiyun * link.
357*4882a593Smuzhiyun */
358*4882a593Smuzhiyun SCI_FAILURE_PROTOCOL_VIOLATION,
359*4882a593Smuzhiyun
360*4882a593Smuzhiyun /**
361*4882a593Smuzhiyun * This value indicates a failure condition that retry may help to clear.
362*4882a593Smuzhiyun */
363*4882a593Smuzhiyun SCI_FAILURE_RETRY_REQUIRED,
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun /**
366*4882a593Smuzhiyun * This field indicates the retry limit was reached when a retry is attempted
367*4882a593Smuzhiyun */
368*4882a593Smuzhiyun SCI_FAILURE_RETRY_LIMIT_REACHED,
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun /**
371*4882a593Smuzhiyun * This member indicates the calling method was partly successful.
372*4882a593Smuzhiyun * Mostly, this status is used when a LUN_RESET issued to an expander attached
373*4882a593Smuzhiyun * STP device in READY NCQ substate needs to have RNC suspended/resumed
374*4882a593Smuzhiyun * before posting TC.
375*4882a593Smuzhiyun */
376*4882a593Smuzhiyun SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS,
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun /**
379*4882a593Smuzhiyun * This field indicates an illegal phy connection based on the routing attribute
380*4882a593Smuzhiyun * of both expander phy attached to each other.
381*4882a593Smuzhiyun */
382*4882a593Smuzhiyun SCI_FAILURE_ILLEGAL_ROUTING_ATTRIBUTE_CONFIGURATION,
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun /**
385*4882a593Smuzhiyun * This field indicates a CONFIG ROUTE INFO command has a response with function result
386*4882a593Smuzhiyun * INDEX DOES NOT EXIST, usually means exceeding max route index.
387*4882a593Smuzhiyun */
388*4882a593Smuzhiyun SCI_FAILURE_EXCEED_MAX_ROUTE_INDEX,
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun /**
391*4882a593Smuzhiyun * This value indicates that an unsupported PCI device ID has been
392*4882a593Smuzhiyun * specified. This indicates that attempts to invoke
393*4882a593Smuzhiyun * sci_library_allocate_controller() will fail.
394*4882a593Smuzhiyun */
395*4882a593Smuzhiyun SCI_FAILURE_UNSUPPORTED_PCI_DEVICE_ID
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun };
398*4882a593Smuzhiyun
399*4882a593Smuzhiyun /**
400*4882a593Smuzhiyun * enum sci_io_status - This enumeration depicts all of the possible IO
401*4882a593Smuzhiyun * completion status values. Each value in this enumeration maps directly
402*4882a593Smuzhiyun * to a value in the enum sci_status enumeration. Please refer to that
403*4882a593Smuzhiyun * enumeration for detailed comments concerning what the status represents.
404*4882a593Smuzhiyun *
405*4882a593Smuzhiyun * Add the API to retrieve the SCU status from the core. Check to see that the
406*4882a593Smuzhiyun * following status are properly handled: - SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL
407*4882a593Smuzhiyun * - SCI_IO_FAILURE_INVALID_IO_TAG
408*4882a593Smuzhiyun */
409*4882a593Smuzhiyun enum sci_io_status {
410*4882a593Smuzhiyun SCI_IO_SUCCESS = SCI_SUCCESS,
411*4882a593Smuzhiyun SCI_IO_FAILURE = SCI_FAILURE,
412*4882a593Smuzhiyun SCI_IO_SUCCESS_COMPLETE_BEFORE_START = SCI_SUCCESS_IO_COMPLETE_BEFORE_START,
413*4882a593Smuzhiyun SCI_IO_SUCCESS_IO_DONE_EARLY = SCI_SUCCESS_IO_DONE_EARLY,
414*4882a593Smuzhiyun SCI_IO_FAILURE_INVALID_STATE = SCI_FAILURE_INVALID_STATE,
415*4882a593Smuzhiyun SCI_IO_FAILURE_INSUFFICIENT_RESOURCES = SCI_FAILURE_INSUFFICIENT_RESOURCES,
416*4882a593Smuzhiyun SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL = SCI_FAILURE_UNSUPPORTED_PROTOCOL,
417*4882a593Smuzhiyun SCI_IO_FAILURE_RESPONSE_VALID = SCI_FAILURE_IO_RESPONSE_VALID,
418*4882a593Smuzhiyun SCI_IO_FAILURE_CONTROLLER_SPECIFIC_ERR = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
419*4882a593Smuzhiyun SCI_IO_FAILURE_TERMINATED = SCI_FAILURE_IO_TERMINATED,
420*4882a593Smuzhiyun SCI_IO_FAILURE_REQUIRES_SCSI_ABORT = SCI_FAILURE_IO_REQUIRES_SCSI_ABORT,
421*4882a593Smuzhiyun SCI_IO_FAILURE_INVALID_PARAMETER_VALUE = SCI_FAILURE_INVALID_PARAMETER_VALUE,
422*4882a593Smuzhiyun SCI_IO_FAILURE_NO_NCQ_TAG_AVAILABLE = SCI_FAILURE_NO_NCQ_TAG_AVAILABLE,
423*4882a593Smuzhiyun SCI_IO_FAILURE_PROTOCOL_VIOLATION = SCI_FAILURE_PROTOCOL_VIOLATION,
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun SCI_IO_FAILURE_RETRY_REQUIRED = SCI_FAILURE_RETRY_REQUIRED,
428*4882a593Smuzhiyun SCI_IO_FAILURE_RETRY_LIMIT_REACHED = SCI_FAILURE_RETRY_LIMIT_REACHED,
429*4882a593Smuzhiyun SCI_IO_FAILURE_INVALID_REMOTE_DEVICE = SCI_FAILURE_INVALID_REMOTE_DEVICE
430*4882a593Smuzhiyun };
431*4882a593Smuzhiyun
432*4882a593Smuzhiyun /**
433*4882a593Smuzhiyun * enum sci_task_status - This enumeration depicts all of the possible task
434*4882a593Smuzhiyun * completion status values. Each value in this enumeration maps directly
435*4882a593Smuzhiyun * to a value in the enum sci_status enumeration. Please refer to that
436*4882a593Smuzhiyun * enumeration for detailed comments concerning what the status represents.
437*4882a593Smuzhiyun *
438*4882a593Smuzhiyun * Check to see that the following status are properly handled:
439*4882a593Smuzhiyun */
440*4882a593Smuzhiyun enum sci_task_status {
441*4882a593Smuzhiyun SCI_TASK_SUCCESS = SCI_SUCCESS,
442*4882a593Smuzhiyun SCI_TASK_FAILURE = SCI_FAILURE,
443*4882a593Smuzhiyun SCI_TASK_FAILURE_INVALID_STATE = SCI_FAILURE_INVALID_STATE,
444*4882a593Smuzhiyun SCI_TASK_FAILURE_INSUFFICIENT_RESOURCES = SCI_FAILURE_INSUFFICIENT_RESOURCES,
445*4882a593Smuzhiyun SCI_TASK_FAILURE_UNSUPPORTED_PROTOCOL = SCI_FAILURE_UNSUPPORTED_PROTOCOL,
446*4882a593Smuzhiyun SCI_TASK_FAILURE_INVALID_TAG = SCI_FAILURE_INVALID_IO_TAG,
447*4882a593Smuzhiyun SCI_TASK_FAILURE_RESPONSE_VALID = SCI_FAILURE_IO_RESPONSE_VALID,
448*4882a593Smuzhiyun SCI_TASK_FAILURE_CONTROLLER_SPECIFIC_ERR = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
449*4882a593Smuzhiyun SCI_TASK_FAILURE_TERMINATED = SCI_FAILURE_IO_TERMINATED,
450*4882a593Smuzhiyun SCI_TASK_FAILURE_INVALID_PARAMETER_VALUE = SCI_FAILURE_INVALID_PARAMETER_VALUE,
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun SCI_TASK_FAILURE_REMOTE_DEVICE_RESET_REQUIRED = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
453*4882a593Smuzhiyun SCI_TASK_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS = SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS
454*4882a593Smuzhiyun
455*4882a593Smuzhiyun };
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun /**
458*4882a593Smuzhiyun * sci_swab32_cpy - convert between scsi and scu-hardware byte format
459*4882a593Smuzhiyun * @dest: receive the 4-byte endian swapped version of src
460*4882a593Smuzhiyun * @src: word aligned source buffer
461*4882a593Smuzhiyun *
462*4882a593Smuzhiyun * scu hardware handles SSP/SMP control, response, and unidentified
463*4882a593Smuzhiyun * frames in "big endian dword" order. Regardless of host endian this
464*4882a593Smuzhiyun * is always a swab32()-per-dword conversion of the standard definition,
465*4882a593Smuzhiyun * i.e. single byte fields swapped and multi-byte fields in little-
466*4882a593Smuzhiyun * endian
467*4882a593Smuzhiyun */
sci_swab32_cpy(void * _dest,void * _src,ssize_t word_cnt)468*4882a593Smuzhiyun static inline void sci_swab32_cpy(void *_dest, void *_src, ssize_t word_cnt)
469*4882a593Smuzhiyun {
470*4882a593Smuzhiyun u32 *dest = _dest, *src = _src;
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun while (--word_cnt >= 0)
473*4882a593Smuzhiyun dest[word_cnt] = swab32(src[word_cnt]);
474*4882a593Smuzhiyun }
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun extern unsigned char no_outbound_task_to;
477*4882a593Smuzhiyun extern u16 ssp_max_occ_to;
478*4882a593Smuzhiyun extern u16 stp_max_occ_to;
479*4882a593Smuzhiyun extern u16 ssp_inactive_to;
480*4882a593Smuzhiyun extern u16 stp_inactive_to;
481*4882a593Smuzhiyun extern unsigned char phy_gen;
482*4882a593Smuzhiyun extern unsigned char max_concurr_spinup;
483*4882a593Smuzhiyun extern uint cable_selection_override;
484*4882a593Smuzhiyun
485*4882a593Smuzhiyun irqreturn_t isci_msix_isr(int vec, void *data);
486*4882a593Smuzhiyun irqreturn_t isci_intx_isr(int vec, void *data);
487*4882a593Smuzhiyun irqreturn_t isci_error_isr(int vec, void *data);
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun /*
490*4882a593Smuzhiyun * Each timer is associated with a cancellation flag that is set when
491*4882a593Smuzhiyun * del_timer() is called and checked in the timer callback function. This
492*4882a593Smuzhiyun * is needed since del_timer_sync() cannot be called with sci_lock held.
493*4882a593Smuzhiyun * For deinit however, del_timer_sync() is used without holding the lock.
494*4882a593Smuzhiyun */
495*4882a593Smuzhiyun struct sci_timer {
496*4882a593Smuzhiyun struct timer_list timer;
497*4882a593Smuzhiyun bool cancel;
498*4882a593Smuzhiyun };
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun static inline
sci_init_timer(struct sci_timer * tmr,void (* fn)(struct timer_list * t))501*4882a593Smuzhiyun void sci_init_timer(struct sci_timer *tmr, void (*fn)(struct timer_list *t))
502*4882a593Smuzhiyun {
503*4882a593Smuzhiyun tmr->cancel = false;
504*4882a593Smuzhiyun timer_setup(&tmr->timer, fn, 0);
505*4882a593Smuzhiyun }
506*4882a593Smuzhiyun
sci_mod_timer(struct sci_timer * tmr,unsigned long msec)507*4882a593Smuzhiyun static inline void sci_mod_timer(struct sci_timer *tmr, unsigned long msec)
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun tmr->cancel = false;
510*4882a593Smuzhiyun mod_timer(&tmr->timer, jiffies + msecs_to_jiffies(msec));
511*4882a593Smuzhiyun }
512*4882a593Smuzhiyun
sci_del_timer(struct sci_timer * tmr)513*4882a593Smuzhiyun static inline void sci_del_timer(struct sci_timer *tmr)
514*4882a593Smuzhiyun {
515*4882a593Smuzhiyun tmr->cancel = true;
516*4882a593Smuzhiyun del_timer(&tmr->timer);
517*4882a593Smuzhiyun }
518*4882a593Smuzhiyun
519*4882a593Smuzhiyun struct sci_base_state_machine {
520*4882a593Smuzhiyun const struct sci_base_state *state_table;
521*4882a593Smuzhiyun u32 initial_state_id;
522*4882a593Smuzhiyun u32 current_state_id;
523*4882a593Smuzhiyun u32 previous_state_id;
524*4882a593Smuzhiyun };
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun typedef void (*sci_state_transition_t)(struct sci_base_state_machine *sm);
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun struct sci_base_state {
529*4882a593Smuzhiyun sci_state_transition_t enter_state; /* Called on state entry */
530*4882a593Smuzhiyun sci_state_transition_t exit_state; /* Called on state exit */
531*4882a593Smuzhiyun };
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun extern void sci_init_sm(struct sci_base_state_machine *sm,
534*4882a593Smuzhiyun const struct sci_base_state *state_table,
535*4882a593Smuzhiyun u32 initial_state);
536*4882a593Smuzhiyun extern void sci_change_state(struct sci_base_state_machine *sm, u32 next_state);
537*4882a593Smuzhiyun #endif /* __ISCI_H__ */
538