16f231ddaSDan Williams /*
26f231ddaSDan Williams * This file is provided under a dual BSD/GPLv2 license. When using or
36f231ddaSDan Williams * redistributing this file, you may do so under either license.
46f231ddaSDan Williams *
56f231ddaSDan Williams * GPL LICENSE SUMMARY
66f231ddaSDan Williams *
76f231ddaSDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
86f231ddaSDan Williams *
96f231ddaSDan Williams * This program is free software; you can redistribute it and/or modify
106f231ddaSDan Williams * it under the terms of version 2 of the GNU General Public License as
116f231ddaSDan Williams * published by the Free Software Foundation.
126f231ddaSDan Williams *
136f231ddaSDan Williams * This program is distributed in the hope that it will be useful, but
146f231ddaSDan Williams * WITHOUT ANY WARRANTY; without even the implied warranty of
156f231ddaSDan Williams * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
166f231ddaSDan Williams * General Public License for more details.
176f231ddaSDan Williams *
186f231ddaSDan Williams * You should have received a copy of the GNU General Public License
196f231ddaSDan Williams * along with this program; if not, write to the Free Software
206f231ddaSDan Williams * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
216f231ddaSDan Williams * The full GNU General Public License is included in this distribution
226f231ddaSDan Williams * in the file called LICENSE.GPL.
236f231ddaSDan Williams *
246f231ddaSDan Williams * BSD LICENSE
256f231ddaSDan Williams *
266f231ddaSDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
276f231ddaSDan Williams * All rights reserved.
286f231ddaSDan Williams *
296f231ddaSDan Williams * Redistribution and use in source and binary forms, with or without
306f231ddaSDan Williams * modification, are permitted provided that the following conditions
316f231ddaSDan Williams * are met:
326f231ddaSDan Williams *
336f231ddaSDan Williams * * Redistributions of source code must retain the above copyright
346f231ddaSDan Williams * notice, this list of conditions and the following disclaimer.
356f231ddaSDan Williams * * Redistributions in binary form must reproduce the above copyright
366f231ddaSDan Williams * notice, this list of conditions and the following disclaimer in
376f231ddaSDan Williams * the documentation and/or other materials provided with the
386f231ddaSDan Williams * distribution.
396f231ddaSDan Williams * * Neither the name of Intel Corporation nor the names of its
406f231ddaSDan Williams * contributors may be used to endorse or promote products derived
416f231ddaSDan Williams * from this software without specific prior written permission.
426f231ddaSDan Williams *
436f231ddaSDan Williams * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
446f231ddaSDan Williams * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
456f231ddaSDan Williams * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
466f231ddaSDan Williams * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
476f231ddaSDan Williams * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
486f231ddaSDan Williams * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
496f231ddaSDan Williams * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
506f231ddaSDan Williams * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
516f231ddaSDan Williams * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
526f231ddaSDan Williams * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
536f231ddaSDan Williams * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
546f231ddaSDan Williams */
556f231ddaSDan Williams
565409bc3aSDan Williams #ifndef __ISCI_H__
575409bc3aSDan Williams #define __ISCI_H__
586f231ddaSDan Williams
596f231ddaSDan Williams #include <linux/interrupt.h>
6012ef6544SEdmund Nadolski #include <linux/types.h>
616f231ddaSDan Williams
62ce2b3261SDan Williams #define DRV_NAME "isci"
63ce2b3261SDan Williams #define SCI_PCI_BAR_COUNT 2
64ce2b3261SDan Williams #define SCI_NUM_MSI_X_INT 2
65ce2b3261SDan Williams #define SCI_SMU_BAR 0
66ce2b3261SDan Williams #define SCI_SMU_BAR_SIZE (16*1024)
67ce2b3261SDan Williams #define SCI_SCU_BAR 1
68ce2b3261SDan Williams #define SCI_SCU_BAR_SIZE (4*1024*1024)
69ce2b3261SDan Williams #define SCI_IO_SPACE_BAR0 2
70ce2b3261SDan Williams #define SCI_IO_SPACE_BAR1 3
71ce2b3261SDan Williams #define ISCI_CAN_QUEUE_VAL 250 /* < SCI_MAX_IO_REQUESTS ? */
72ce2b3261SDan Williams #define SCIC_CONTROLLER_STOP_TIMEOUT 5000
73ce2b3261SDan Williams
74ce2b3261SDan Williams #define SCI_CONTROLLER_INVALID_IO_TAG 0xFFFF
75ce2b3261SDan Williams
767c78da31SDan Williams #define SCI_MAX_PHYS (4UL)
77ce2b3261SDan Williams #define SCI_MAX_PORTS SCI_MAX_PHYS
78ce2b3261SDan Williams #define SCI_MAX_SMP_PHYS (384) /* not silicon constrained */
797c78da31SDan Williams #define SCI_MAX_REMOTE_DEVICES (256UL)
807c78da31SDan Williams #define SCI_MAX_IO_REQUESTS (256UL)
81dd047c8eSDan Williams #define SCI_MAX_SEQ (16)
82ce2b3261SDan Williams #define SCI_MAX_MSIX_MESSAGES (2)
83ce2b3261SDan Williams #define SCI_MAX_SCATTER_GATHER_ELEMENTS 130 /* not silicon constrained */
84ce2b3261SDan Williams #define SCI_MAX_CONTROLLERS 2
85ce2b3261SDan Williams #define SCI_MAX_DOMAINS SCI_MAX_PORTS
86ce2b3261SDan Williams
87ce2b3261SDan Williams #define SCU_MAX_CRITICAL_NOTIFICATIONS (384)
88994a9303SDan Williams #define SCU_MAX_EVENTS_SHIFT (7)
89994a9303SDan Williams #define SCU_MAX_EVENTS (1 << SCU_MAX_EVENTS_SHIFT)
90ce2b3261SDan Williams #define SCU_MAX_UNSOLICITED_FRAMES (128)
91ce2b3261SDan Williams #define SCU_MAX_COMPLETION_QUEUE_SCRATCH (128)
92ce2b3261SDan Williams #define SCU_MAX_COMPLETION_QUEUE_ENTRIES (SCU_MAX_CRITICAL_NOTIFICATIONS \
93ce2b3261SDan Williams + SCU_MAX_EVENTS \
94ce2b3261SDan Williams + SCU_MAX_UNSOLICITED_FRAMES \
95ce2b3261SDan Williams + SCI_MAX_IO_REQUESTS \
96ce2b3261SDan Williams + SCU_MAX_COMPLETION_QUEUE_SCRATCH)
97994a9303SDan Williams #define SCU_MAX_COMPLETION_QUEUE_SHIFT (ilog2(SCU_MAX_COMPLETION_QUEUE_ENTRIES))
98ce2b3261SDan Williams
99ce2b3261SDan Williams #define SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES (4096)
10054b5e3a4SDan Williams #define SCU_UNSOLICITED_FRAME_BUFFER_SIZE (1024U)
101ce2b3261SDan Williams #define SCU_INVALID_FRAME_INDEX (0xFFFF)
102ce2b3261SDan Williams
103ce2b3261SDan Williams #define SCU_IO_REQUEST_MAX_SGE_SIZE (0x00FFFFFF)
104ce2b3261SDan Williams #define SCU_IO_REQUEST_MAX_TRANSFER_LENGTH (0x00FFFFFF)
105ce2b3261SDan Williams
check_sizes(void)1067c78da31SDan Williams static inline void check_sizes(void)
1077c78da31SDan Williams {
1087c78da31SDan Williams BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_EVENTS);
1097c78da31SDan Williams BUILD_BUG_ON(SCU_MAX_UNSOLICITED_FRAMES <= 8);
1107c78da31SDan Williams BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_UNSOLICITED_FRAMES);
1117c78da31SDan Williams BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_COMPLETION_QUEUE_ENTRIES);
1127c78da31SDan Williams BUILD_BUG_ON(SCU_MAX_UNSOLICITED_FRAMES > SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES);
113ac668c69SDan Williams BUILD_BUG_ON_NOT_POWER_OF_2(SCI_MAX_IO_REQUESTS);
114dd047c8eSDan Williams BUILD_BUG_ON_NOT_POWER_OF_2(SCI_MAX_SEQ);
1157c78da31SDan Williams }
116ce2b3261SDan Williams
117ce2b3261SDan Williams /**
118ce2b3261SDan Williams * enum sci_status - This is the general return status enumeration for non-IO,
119ce2b3261SDan Williams * non-task management related SCI interface methods.
120ce2b3261SDan Williams *
121ce2b3261SDan Williams *
122ce2b3261SDan Williams */
123ce2b3261SDan Williams enum sci_status {
124ce2b3261SDan Williams /**
125ce2b3261SDan Williams * This member indicates successful completion.
126ce2b3261SDan Williams */
127ce2b3261SDan Williams SCI_SUCCESS = 0,
128ce2b3261SDan Williams
129ce2b3261SDan Williams /**
130ce2b3261SDan Williams * This value indicates that the calling method completed successfully,
131ce2b3261SDan Williams * but that the IO may have completed before having it's start method
132ce2b3261SDan Williams * invoked. This occurs during SAT translation for requests that do
133ce2b3261SDan Williams * not require an IO to the target or for any other requests that may
134ce2b3261SDan Williams * be completed without having to submit IO.
135ce2b3261SDan Williams */
136ce2b3261SDan Williams SCI_SUCCESS_IO_COMPLETE_BEFORE_START,
137ce2b3261SDan Williams
138ce2b3261SDan Williams /**
139ce2b3261SDan Williams * This Value indicates that the SCU hardware returned an early response
140ce2b3261SDan Williams * because the io request specified more data than is returned by the
141ce2b3261SDan Williams * target device (mode pages, inquiry data, etc.). The completion routine
142ce2b3261SDan Williams * will handle this case to get the actual number of bytes transferred.
143ce2b3261SDan Williams */
144ce2b3261SDan Williams SCI_SUCCESS_IO_DONE_EARLY,
145ce2b3261SDan Williams
146ce2b3261SDan Williams /**
147ce2b3261SDan Williams * This member indicates that the object for which a state change is
148ce2b3261SDan Williams * being requested is already in said state.
149ce2b3261SDan Williams */
150ce2b3261SDan Williams SCI_WARNING_ALREADY_IN_STATE,
151ce2b3261SDan Williams
152ce2b3261SDan Williams /**
153ce2b3261SDan Williams * This member indicates interrupt coalescence timer may cause SAS
154ce2b3261SDan Williams * specification compliance issues (i.e. SMP target mode response
155ce2b3261SDan Williams * frames must be returned within 1.9 milliseconds).
156ce2b3261SDan Williams */
157ce2b3261SDan Williams SCI_WARNING_TIMER_CONFLICT,
158ce2b3261SDan Williams
159ce2b3261SDan Williams /**
160ce2b3261SDan Williams * This field indicates a sequence of action is not completed yet. Mostly,
161ce2b3261SDan Williams * this status is used when multiple ATA commands are needed in a SATI translation.
162ce2b3261SDan Williams */
163ce2b3261SDan Williams SCI_WARNING_SEQUENCE_INCOMPLETE,
164ce2b3261SDan Williams
165ce2b3261SDan Williams /**
166ce2b3261SDan Williams * This member indicates that there was a general failure.
167ce2b3261SDan Williams */
168ce2b3261SDan Williams SCI_FAILURE,
169ce2b3261SDan Williams
170ce2b3261SDan Williams /**
171ce2b3261SDan Williams * This member indicates that the SCI implementation is unable to complete
172ce2b3261SDan Williams * an operation due to a critical flaw the prevents any further operation
173ce2b3261SDan Williams * (i.e. an invalid pointer).
174ce2b3261SDan Williams */
175ce2b3261SDan Williams SCI_FATAL_ERROR,
176ce2b3261SDan Williams
177ce2b3261SDan Williams /**
178ce2b3261SDan Williams * This member indicates the calling function failed, because the state
179ce2b3261SDan Williams * of the controller is in a state that prevents successful completion.
180ce2b3261SDan Williams */
181ce2b3261SDan Williams SCI_FAILURE_INVALID_STATE,
182ce2b3261SDan Williams
183ce2b3261SDan Williams /**
184ce2b3261SDan Williams * This member indicates the calling function failed, because there is
185ce2b3261SDan Williams * insufficient resources/memory to complete the request.
186ce2b3261SDan Williams */
187ce2b3261SDan Williams SCI_FAILURE_INSUFFICIENT_RESOURCES,
188ce2b3261SDan Williams
189ce2b3261SDan Williams /**
190ce2b3261SDan Williams * This member indicates the calling function failed, because the
191ce2b3261SDan Williams * controller object required for the operation can't be located.
192ce2b3261SDan Williams */
193ce2b3261SDan Williams SCI_FAILURE_CONTROLLER_NOT_FOUND,
194ce2b3261SDan Williams
195ce2b3261SDan Williams /**
196ce2b3261SDan Williams * This member indicates the calling function failed, because the
197ce2b3261SDan Williams * discovered controller type is not supported by the library.
198ce2b3261SDan Williams */
199ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_CONTROLLER_TYPE,
200ce2b3261SDan Williams
201ce2b3261SDan Williams /**
202ce2b3261SDan Williams * This member indicates the calling function failed, because the
203ce2b3261SDan Williams * requested initialization data version isn't supported.
204ce2b3261SDan Williams */
205ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_INIT_DATA_VERSION,
206ce2b3261SDan Williams
207ce2b3261SDan Williams /**
208ce2b3261SDan Williams * This member indicates the calling function failed, because the
209ce2b3261SDan Williams * requested configuration of SAS Phys into SAS Ports is not supported.
210ce2b3261SDan Williams */
211ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION,
212ce2b3261SDan Williams
213ce2b3261SDan Williams /**
214ce2b3261SDan Williams * This member indicates the calling function failed, because the
215ce2b3261SDan Williams * requested protocol is not supported by the remote device, port,
216ce2b3261SDan Williams * or controller.
217ce2b3261SDan Williams */
218ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_PROTOCOL,
219ce2b3261SDan Williams
220ce2b3261SDan Williams /**
221ce2b3261SDan Williams * This member indicates the calling function failed, because the
222ce2b3261SDan Williams * requested information type is not supported by the SCI implementation.
223ce2b3261SDan Williams */
224ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_INFORMATION_TYPE,
225ce2b3261SDan Williams
226ce2b3261SDan Williams /**
227ce2b3261SDan Williams * This member indicates the calling function failed, because the
228ce2b3261SDan Williams * device already exists.
229ce2b3261SDan Williams */
230ce2b3261SDan Williams SCI_FAILURE_DEVICE_EXISTS,
231ce2b3261SDan Williams
232ce2b3261SDan Williams /**
233ce2b3261SDan Williams * This member indicates the calling function failed, because adding
234ce2b3261SDan Williams * a phy to the object is not possible.
235ce2b3261SDan Williams */
236ce2b3261SDan Williams SCI_FAILURE_ADDING_PHY_UNSUPPORTED,
237ce2b3261SDan Williams
238ce2b3261SDan Williams /**
239ce2b3261SDan Williams * This member indicates the calling function failed, because the
240ce2b3261SDan Williams * requested information type is not supported by the SCI implementation.
241ce2b3261SDan Williams */
242ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD,
243ce2b3261SDan Williams
244ce2b3261SDan Williams /**
245ce2b3261SDan Williams * This member indicates the calling function failed, because the SCI
246ce2b3261SDan Williams * implementation does not support the supplied time limit.
247ce2b3261SDan Williams */
248ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_TIME_LIMIT,
249ce2b3261SDan Williams
250ce2b3261SDan Williams /**
251ce2b3261SDan Williams * This member indicates the calling method failed, because the SCI
252ce2b3261SDan Williams * implementation does not contain the specified Phy.
253ce2b3261SDan Williams */
254ce2b3261SDan Williams SCI_FAILURE_INVALID_PHY,
255ce2b3261SDan Williams
256ce2b3261SDan Williams /**
257ce2b3261SDan Williams * This member indicates the calling method failed, because the SCI
258ce2b3261SDan Williams * implementation does not contain the specified Port.
259ce2b3261SDan Williams */
260ce2b3261SDan Williams SCI_FAILURE_INVALID_PORT,
261ce2b3261SDan Williams
262ce2b3261SDan Williams /**
263ce2b3261SDan Williams * This member indicates the calling method was partly successful
264ce2b3261SDan Williams * The port was reset but not all phys in port are operational
265ce2b3261SDan Williams */
266ce2b3261SDan Williams SCI_FAILURE_RESET_PORT_PARTIAL_SUCCESS,
267ce2b3261SDan Williams
268ce2b3261SDan Williams /**
269ce2b3261SDan Williams * This member indicates that calling method failed
270ce2b3261SDan Williams * The port reset did not complete because none of the phys are operational
271ce2b3261SDan Williams */
272ce2b3261SDan Williams SCI_FAILURE_RESET_PORT_FAILURE,
273ce2b3261SDan Williams
274ce2b3261SDan Williams /**
275ce2b3261SDan Williams * This member indicates the calling method failed, because the SCI
276ce2b3261SDan Williams * implementation does not contain the specified remote device.
277ce2b3261SDan Williams */
278ce2b3261SDan Williams SCI_FAILURE_INVALID_REMOTE_DEVICE,
279ce2b3261SDan Williams
280ce2b3261SDan Williams /**
281ce2b3261SDan Williams * This member indicates the calling method failed, because the remote
282ce2b3261SDan Williams * device is in a bad state and requires a reset.
283ce2b3261SDan Williams */
284ce2b3261SDan Williams SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
285ce2b3261SDan Williams
286ce2b3261SDan Williams /**
287ce2b3261SDan Williams * This member indicates the calling method failed, because the SCI
288ce2b3261SDan Williams * implementation does not contain or support the specified IO tag.
289ce2b3261SDan Williams */
290ce2b3261SDan Williams SCI_FAILURE_INVALID_IO_TAG,
291ce2b3261SDan Williams
292ce2b3261SDan Williams /**
293ce2b3261SDan Williams * This member indicates that the operation failed and the user should
294ce2b3261SDan Williams * check the response data associated with the IO.
295ce2b3261SDan Williams */
296ce2b3261SDan Williams SCI_FAILURE_IO_RESPONSE_VALID,
297ce2b3261SDan Williams
298ce2b3261SDan Williams /**
299ce2b3261SDan Williams * This member indicates that the operation failed, the failure is
300ce2b3261SDan Williams * controller implementation specific, and the response data associated
301ce2b3261SDan Williams * with the request is not valid. You can query for the controller
30289a7301fSDan Williams * specific error information via sci_controller_get_request_status()
303ce2b3261SDan Williams */
304ce2b3261SDan Williams SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
305ce2b3261SDan Williams
306ce2b3261SDan Williams /**
307ce2b3261SDan Williams * This member indicated that the operation failed because the
308ce2b3261SDan Williams * user requested this IO to be terminated.
309ce2b3261SDan Williams */
310ce2b3261SDan Williams SCI_FAILURE_IO_TERMINATED,
311ce2b3261SDan Williams
312ce2b3261SDan Williams /**
313ce2b3261SDan Williams * This member indicates that the operation failed and the associated
314ce2b3261SDan Williams * request requires a SCSI abort task to be sent to the target.
315ce2b3261SDan Williams */
316ce2b3261SDan Williams SCI_FAILURE_IO_REQUIRES_SCSI_ABORT,
317ce2b3261SDan Williams
318ce2b3261SDan Williams /**
319ce2b3261SDan Williams * This member indicates that the operation failed because the supplied
320ce2b3261SDan Williams * device could not be located.
321ce2b3261SDan Williams */
322ce2b3261SDan Williams SCI_FAILURE_DEVICE_NOT_FOUND,
323ce2b3261SDan Williams
324ce2b3261SDan Williams /**
325ce2b3261SDan Williams * This member indicates that the operation failed because the
326ce2b3261SDan Williams * objects association is required and is not correctly set.
327ce2b3261SDan Williams */
328ce2b3261SDan Williams SCI_FAILURE_INVALID_ASSOCIATION,
329ce2b3261SDan Williams
330ce2b3261SDan Williams /**
331ce2b3261SDan Williams * This member indicates that the operation failed, because a timeout
332ce2b3261SDan Williams * occurred.
333ce2b3261SDan Williams */
334ce2b3261SDan Williams SCI_FAILURE_TIMEOUT,
335ce2b3261SDan Williams
336ce2b3261SDan Williams /**
337ce2b3261SDan Williams * This member indicates that the operation failed, because the user
338ce2b3261SDan Williams * specified a value that is either invalid or not supported.
339ce2b3261SDan Williams */
340ce2b3261SDan Williams SCI_FAILURE_INVALID_PARAMETER_VALUE,
341ce2b3261SDan Williams
342ce2b3261SDan Williams /**
343ce2b3261SDan Williams * This value indicates that the operation failed, because the number
344ce2b3261SDan Williams * of messages (MSI-X) is not supported.
345ce2b3261SDan Williams */
346ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_MESSAGE_COUNT,
347ce2b3261SDan Williams
348ce2b3261SDan Williams /**
349ce2b3261SDan Williams * This value indicates that the method failed due to a lack of
350ce2b3261SDan Williams * available NCQ tags.
351ce2b3261SDan Williams */
352ce2b3261SDan Williams SCI_FAILURE_NO_NCQ_TAG_AVAILABLE,
353ce2b3261SDan Williams
354ce2b3261SDan Williams /**
355ce2b3261SDan Williams * This value indicates that a protocol violation has occurred on the
356ce2b3261SDan Williams * link.
357ce2b3261SDan Williams */
358ce2b3261SDan Williams SCI_FAILURE_PROTOCOL_VIOLATION,
359ce2b3261SDan Williams
360ce2b3261SDan Williams /**
361ce2b3261SDan Williams * This value indicates a failure condition that retry may help to clear.
362ce2b3261SDan Williams */
363ce2b3261SDan Williams SCI_FAILURE_RETRY_REQUIRED,
364ce2b3261SDan Williams
365ce2b3261SDan Williams /**
366ce2b3261SDan Williams * This field indicates the retry limit was reached when a retry is attempted
367ce2b3261SDan Williams */
368ce2b3261SDan Williams SCI_FAILURE_RETRY_LIMIT_REACHED,
369ce2b3261SDan Williams
370ce2b3261SDan Williams /**
371ce2b3261SDan Williams * This member indicates the calling method was partly successful.
372ce2b3261SDan Williams * Mostly, this status is used when a LUN_RESET issued to an expander attached
373ce2b3261SDan Williams * STP device in READY NCQ substate needs to have RNC suspended/resumed
374ce2b3261SDan Williams * before posting TC.
375ce2b3261SDan Williams */
376ce2b3261SDan Williams SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS,
377ce2b3261SDan Williams
378ce2b3261SDan Williams /**
379ce2b3261SDan Williams * This field indicates an illegal phy connection based on the routing attribute
380ce2b3261SDan Williams * of both expander phy attached to each other.
381ce2b3261SDan Williams */
382ce2b3261SDan Williams SCI_FAILURE_ILLEGAL_ROUTING_ATTRIBUTE_CONFIGURATION,
383ce2b3261SDan Williams
384ce2b3261SDan Williams /**
385ce2b3261SDan Williams * This field indicates a CONFIG ROUTE INFO command has a response with function result
386ce2b3261SDan Williams * INDEX DOES NOT EXIST, usually means exceeding max route index.
387ce2b3261SDan Williams */
388ce2b3261SDan Williams SCI_FAILURE_EXCEED_MAX_ROUTE_INDEX,
389ce2b3261SDan Williams
390ce2b3261SDan Williams /**
391ce2b3261SDan Williams * This value indicates that an unsupported PCI device ID has been
392ce2b3261SDan Williams * specified. This indicates that attempts to invoke
39389a7301fSDan Williams * sci_library_allocate_controller() will fail.
394ce2b3261SDan Williams */
395ce2b3261SDan Williams SCI_FAILURE_UNSUPPORTED_PCI_DEVICE_ID
396ce2b3261SDan Williams
397ce2b3261SDan Williams };
398ce2b3261SDan Williams
399ce2b3261SDan Williams /**
400ce2b3261SDan Williams * enum sci_io_status - This enumeration depicts all of the possible IO
401ce2b3261SDan Williams * completion status values. Each value in this enumeration maps directly
402ce2b3261SDan Williams * to a value in the enum sci_status enumeration. Please refer to that
403ce2b3261SDan Williams * enumeration for detailed comments concerning what the status represents.
404ce2b3261SDan Williams *
405ce2b3261SDan Williams * Add the API to retrieve the SCU status from the core. Check to see that the
406ce2b3261SDan Williams * following status are properly handled: - SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL
407ce2b3261SDan Williams * - SCI_IO_FAILURE_INVALID_IO_TAG
408ce2b3261SDan Williams */
409ce2b3261SDan Williams enum sci_io_status {
410ce2b3261SDan Williams SCI_IO_SUCCESS = SCI_SUCCESS,
411ce2b3261SDan Williams SCI_IO_FAILURE = SCI_FAILURE,
412ce2b3261SDan Williams SCI_IO_SUCCESS_COMPLETE_BEFORE_START = SCI_SUCCESS_IO_COMPLETE_BEFORE_START,
413ce2b3261SDan Williams SCI_IO_SUCCESS_IO_DONE_EARLY = SCI_SUCCESS_IO_DONE_EARLY,
414ce2b3261SDan Williams SCI_IO_FAILURE_INVALID_STATE = SCI_FAILURE_INVALID_STATE,
415ce2b3261SDan Williams SCI_IO_FAILURE_INSUFFICIENT_RESOURCES = SCI_FAILURE_INSUFFICIENT_RESOURCES,
416ce2b3261SDan Williams SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL = SCI_FAILURE_UNSUPPORTED_PROTOCOL,
417ce2b3261SDan Williams SCI_IO_FAILURE_RESPONSE_VALID = SCI_FAILURE_IO_RESPONSE_VALID,
418ce2b3261SDan Williams SCI_IO_FAILURE_CONTROLLER_SPECIFIC_ERR = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
419ce2b3261SDan Williams SCI_IO_FAILURE_TERMINATED = SCI_FAILURE_IO_TERMINATED,
420ce2b3261SDan Williams SCI_IO_FAILURE_REQUIRES_SCSI_ABORT = SCI_FAILURE_IO_REQUIRES_SCSI_ABORT,
421ce2b3261SDan Williams SCI_IO_FAILURE_INVALID_PARAMETER_VALUE = SCI_FAILURE_INVALID_PARAMETER_VALUE,
422ce2b3261SDan Williams SCI_IO_FAILURE_NO_NCQ_TAG_AVAILABLE = SCI_FAILURE_NO_NCQ_TAG_AVAILABLE,
423ce2b3261SDan Williams SCI_IO_FAILURE_PROTOCOL_VIOLATION = SCI_FAILURE_PROTOCOL_VIOLATION,
424ce2b3261SDan Williams
425ce2b3261SDan Williams SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
426ce2b3261SDan Williams
427ce2b3261SDan Williams SCI_IO_FAILURE_RETRY_REQUIRED = SCI_FAILURE_RETRY_REQUIRED,
428ce2b3261SDan Williams SCI_IO_FAILURE_RETRY_LIMIT_REACHED = SCI_FAILURE_RETRY_LIMIT_REACHED,
429ce2b3261SDan Williams SCI_IO_FAILURE_INVALID_REMOTE_DEVICE = SCI_FAILURE_INVALID_REMOTE_DEVICE
430ce2b3261SDan Williams };
431ce2b3261SDan Williams
432ce2b3261SDan Williams /**
433ce2b3261SDan Williams * enum sci_task_status - This enumeration depicts all of the possible task
434ce2b3261SDan Williams * completion status values. Each value in this enumeration maps directly
435ce2b3261SDan Williams * to a value in the enum sci_status enumeration. Please refer to that
436ce2b3261SDan Williams * enumeration for detailed comments concerning what the status represents.
437ce2b3261SDan Williams *
438ce2b3261SDan Williams * Check to see that the following status are properly handled:
439ce2b3261SDan Williams */
440ce2b3261SDan Williams enum sci_task_status {
441ce2b3261SDan Williams SCI_TASK_SUCCESS = SCI_SUCCESS,
442ce2b3261SDan Williams SCI_TASK_FAILURE = SCI_FAILURE,
443ce2b3261SDan Williams SCI_TASK_FAILURE_INVALID_STATE = SCI_FAILURE_INVALID_STATE,
444ce2b3261SDan Williams SCI_TASK_FAILURE_INSUFFICIENT_RESOURCES = SCI_FAILURE_INSUFFICIENT_RESOURCES,
445ce2b3261SDan Williams SCI_TASK_FAILURE_UNSUPPORTED_PROTOCOL = SCI_FAILURE_UNSUPPORTED_PROTOCOL,
446ce2b3261SDan Williams SCI_TASK_FAILURE_INVALID_TAG = SCI_FAILURE_INVALID_IO_TAG,
447ce2b3261SDan Williams SCI_TASK_FAILURE_RESPONSE_VALID = SCI_FAILURE_IO_RESPONSE_VALID,
448ce2b3261SDan Williams SCI_TASK_FAILURE_CONTROLLER_SPECIFIC_ERR = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
449ce2b3261SDan Williams SCI_TASK_FAILURE_TERMINATED = SCI_FAILURE_IO_TERMINATED,
450ce2b3261SDan Williams SCI_TASK_FAILURE_INVALID_PARAMETER_VALUE = SCI_FAILURE_INVALID_PARAMETER_VALUE,
451ce2b3261SDan Williams
452ce2b3261SDan Williams SCI_TASK_FAILURE_REMOTE_DEVICE_RESET_REQUIRED = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
453ce2b3261SDan Williams SCI_TASK_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS = SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS
454ce2b3261SDan Williams
455ce2b3261SDan Williams };
4566f231ddaSDan Williams
457f1f52e75SDan Williams /**
458f1f52e75SDan Williams * sci_swab32_cpy - convert between scsi and scu-hardware byte format
459f1f52e75SDan Williams * @dest: receive the 4-byte endian swapped version of src
460f1f52e75SDan Williams * @src: word aligned source buffer
461f1f52e75SDan Williams *
462f1f52e75SDan Williams * scu hardware handles SSP/SMP control, response, and unidentified
463f1f52e75SDan Williams * frames in "big endian dword" order. Regardless of host endian this
464f1f52e75SDan Williams * is always a swab32()-per-dword conversion of the standard definition,
465f1f52e75SDan Williams * i.e. single byte fields swapped and multi-byte fields in little-
466f1f52e75SDan Williams * endian
467f1f52e75SDan Williams */
sci_swab32_cpy(void * _dest,void * _src,ssize_t word_cnt)468f1f52e75SDan Williams static inline void sci_swab32_cpy(void *_dest, void *_src, ssize_t word_cnt)
469f1f52e75SDan Williams {
470f1f52e75SDan Williams u32 *dest = _dest, *src = _src;
471f1f52e75SDan Williams
472f1f52e75SDan Williams while (--word_cnt >= 0)
473f1f52e75SDan Williams dest[word_cnt] = swab32(src[word_cnt]);
474f1f52e75SDan Williams }
475f1f52e75SDan Williams
476b5f18a20SDave Jiang extern unsigned char no_outbound_task_to;
477b5f18a20SDave Jiang extern u16 ssp_max_occ_to;
478b5f18a20SDave Jiang extern u16 stp_max_occ_to;
479b5f18a20SDave Jiang extern u16 ssp_inactive_to;
480b5f18a20SDave Jiang extern u16 stp_inactive_to;
481b5f18a20SDave Jiang extern unsigned char phy_gen;
482b5f18a20SDave Jiang extern unsigned char max_concurr_spinup;
4839fee607fSJeff Skirvin extern uint cable_selection_override;
484b5f18a20SDave Jiang
485c7ef4031SDan Williams irqreturn_t isci_msix_isr(int vec, void *data);
486c7ef4031SDan Williams irqreturn_t isci_intx_isr(int vec, void *data);
48792f4f0f5SDan Williams irqreturn_t isci_error_isr(int vec, void *data);
4885553ba2bSEdmund Nadolski
4895553ba2bSEdmund Nadolski /*
4905553ba2bSEdmund Nadolski * Each timer is associated with a cancellation flag that is set when
4915553ba2bSEdmund Nadolski * del_timer() is called and checked in the timer callback function. This
49289a7301fSDan Williams * is needed since del_timer_sync() cannot be called with sci_lock held.
4935553ba2bSEdmund Nadolski * For deinit however, del_timer_sync() is used without holding the lock.
4945553ba2bSEdmund Nadolski */
4955553ba2bSEdmund Nadolski struct sci_timer {
4965553ba2bSEdmund Nadolski struct timer_list timer;
4975553ba2bSEdmund Nadolski bool cancel;
4985553ba2bSEdmund Nadolski };
4995553ba2bSEdmund Nadolski
5005553ba2bSEdmund Nadolski static inline
sci_init_timer(struct sci_timer * tmr,void (* fn)(struct timer_list * t))501b0a2dc66SKees Cook void sci_init_timer(struct sci_timer *tmr, void (*fn)(struct timer_list *t))
5025553ba2bSEdmund Nadolski {
5038d5e2028SJason Yan tmr->cancel = false;
504b0a2dc66SKees Cook timer_setup(&tmr->timer, fn, 0);
5055553ba2bSEdmund Nadolski }
5065553ba2bSEdmund Nadolski
sci_mod_timer(struct sci_timer * tmr,unsigned long msec)5075553ba2bSEdmund Nadolski static inline void sci_mod_timer(struct sci_timer *tmr, unsigned long msec)
5085553ba2bSEdmund Nadolski {
5098d5e2028SJason Yan tmr->cancel = false;
5105553ba2bSEdmund Nadolski mod_timer(&tmr->timer, jiffies + msecs_to_jiffies(msec));
5115553ba2bSEdmund Nadolski }
5125553ba2bSEdmund Nadolski
sci_del_timer(struct sci_timer * tmr)5135553ba2bSEdmund Nadolski static inline void sci_del_timer(struct sci_timer *tmr)
5145553ba2bSEdmund Nadolski {
5158d5e2028SJason Yan tmr->cancel = true;
5165553ba2bSEdmund Nadolski del_timer(&tmr->timer);
5175553ba2bSEdmund Nadolski }
5185553ba2bSEdmund Nadolski
51912ef6544SEdmund Nadolski struct sci_base_state_machine {
52012ef6544SEdmund Nadolski const struct sci_base_state *state_table;
52112ef6544SEdmund Nadolski u32 initial_state_id;
52212ef6544SEdmund Nadolski u32 current_state_id;
52312ef6544SEdmund Nadolski u32 previous_state_id;
52412ef6544SEdmund Nadolski };
52512ef6544SEdmund Nadolski
52612ef6544SEdmund Nadolski typedef void (*sci_state_transition_t)(struct sci_base_state_machine *sm);
52712ef6544SEdmund Nadolski
52812ef6544SEdmund Nadolski struct sci_base_state {
52912ef6544SEdmund Nadolski sci_state_transition_t enter_state; /* Called on state entry */
53012ef6544SEdmund Nadolski sci_state_transition_t exit_state; /* Called on state exit */
53112ef6544SEdmund Nadolski };
53212ef6544SEdmund Nadolski
53312ef6544SEdmund Nadolski extern void sci_init_sm(struct sci_base_state_machine *sm,
53412ef6544SEdmund Nadolski const struct sci_base_state *state_table,
53512ef6544SEdmund Nadolski u32 initial_state);
53612ef6544SEdmund Nadolski extern void sci_change_state(struct sci_base_state_machine *sm, u32 next_state);
5375409bc3aSDan Williams #endif /* __ISCI_H__ */
538