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