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