diff options
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/isci/Makefile | 1 | ||||
-rw-r--r-- | drivers/scsi/isci/host.c | 39 | ||||
-rw-r--r-- | drivers/scsi/isci/host.h | 2 | ||||
-rw-r--r-- | drivers/scsi/isci/isci.h | 19 | ||||
-rw-r--r-- | drivers/scsi/isci/phy.c | 6 | ||||
-rw-r--r-- | drivers/scsi/isci/phy.h | 2 | ||||
-rw-r--r-- | drivers/scsi/isci/port.c | 6 | ||||
-rw-r--r-- | drivers/scsi/isci/remote_device.c | 6 | ||||
-rw-r--r-- | drivers/scsi/isci/remote_node_context.c | 8 | ||||
-rw-r--r-- | drivers/scsi/isci/remote_node_context.h | 2 | ||||
-rw-r--r-- | drivers/scsi/isci/request.c | 5 | ||||
-rw-r--r-- | drivers/scsi/isci/state_machine.c | 138 | ||||
-rw-r--r-- | drivers/scsi/isci/state_machine.h | 122 |
13 files changed, 62 insertions, 294 deletions
diff --git a/drivers/scsi/isci/Makefile b/drivers/scsi/isci/Makefile index ad58fe3acc72..42449701ad9e 100644 --- a/drivers/scsi/isci/Makefile +++ b/drivers/scsi/isci/Makefile | |||
@@ -2,7 +2,6 @@ obj-$(CONFIG_SCSI_ISCI) += isci.o | |||
2 | isci-objs := init.o phy.o request.o sata.o \ | 2 | isci-objs := init.o phy.o request.o sata.o \ |
3 | remote_device.o port.o \ | 3 | remote_device.o port.o \ |
4 | host.o task.o probe_roms.o \ | 4 | host.o task.o probe_roms.o \ |
5 | state_machine.o \ | ||
6 | remote_node_context.o \ | 5 | remote_node_context.o \ |
7 | remote_node_table.o \ | 6 | remote_node_table.o \ |
8 | unsolicited_frame_control.o \ | 7 | unsolicited_frame_control.o \ |
diff --git a/drivers/scsi/isci/host.c b/drivers/scsi/isci/host.c index 81ee64c0a4b7..f502882a2e17 100644 --- a/drivers/scsi/isci/host.c +++ b/drivers/scsi/isci/host.c | |||
@@ -197,6 +197,39 @@ | |||
197 | */ | 197 | */ |
198 | #define COMPLETION_QUEUE_CYCLE_BIT(x) ((x) & 0x80000000) | 198 | #define COMPLETION_QUEUE_CYCLE_BIT(x) ((x) & 0x80000000) |
199 | 199 | ||
200 | /* Init the state machine and call the state entry function (if any) */ | ||
201 | void sci_init_sm(struct sci_base_state_machine *sm, | ||
202 | const struct sci_base_state *state_table, u32 initial_state) | ||
203 | { | ||
204 | sci_state_transition_t handler; | ||
205 | |||
206 | sm->initial_state_id = initial_state; | ||
207 | sm->previous_state_id = initial_state; | ||
208 | sm->current_state_id = initial_state; | ||
209 | sm->state_table = state_table; | ||
210 | |||
211 | handler = sm->state_table[initial_state].enter_state; | ||
212 | if (handler) | ||
213 | handler(sm); | ||
214 | } | ||
215 | |||
216 | /* Call the state exit fn, update the current state, call the state entry fn */ | ||
217 | void sci_change_state(struct sci_base_state_machine *sm, u32 next_state) | ||
218 | { | ||
219 | sci_state_transition_t handler; | ||
220 | |||
221 | handler = sm->state_table[sm->current_state_id].exit_state; | ||
222 | if (handler) | ||
223 | handler(sm); | ||
224 | |||
225 | sm->previous_state_id = sm->current_state_id; | ||
226 | sm->current_state_id = next_state; | ||
227 | |||
228 | handler = sm->state_table[sm->current_state_id].enter_state; | ||
229 | if (handler) | ||
230 | handler(sm); | ||
231 | } | ||
232 | |||
200 | static bool scic_sds_controller_completion_queue_has_entries( | 233 | static bool scic_sds_controller_completion_queue_has_entries( |
201 | struct scic_sds_controller *scic) | 234 | struct scic_sds_controller *scic) |
202 | { | 235 | { |
@@ -1807,11 +1840,7 @@ static enum sci_status scic_controller_construct(struct scic_sds_controller *sci | |||
1807 | struct isci_host *ihost = scic_to_ihost(scic); | 1840 | struct isci_host *ihost = scic_to_ihost(scic); |
1808 | u8 i; | 1841 | u8 i; |
1809 | 1842 | ||
1810 | sci_base_state_machine_construct(&scic->sm, | 1843 | sci_init_sm(&scic->sm, scic_sds_controller_state_table, SCIC_INITIAL); |
1811 | scic_sds_controller_state_table, | ||
1812 | SCIC_INITIAL); | ||
1813 | |||
1814 | sci_base_state_machine_start(&scic->sm); | ||
1815 | 1844 | ||
1816 | scic->scu_registers = scu_base; | 1845 | scic->scu_registers = scu_base; |
1817 | scic->smu_registers = smu_base; | 1846 | scic->smu_registers = smu_base; |
diff --git a/drivers/scsi/isci/host.h b/drivers/scsi/isci/host.h index be09765ee1d5..4020cf7b6f2a 100644 --- a/drivers/scsi/isci/host.h +++ b/drivers/scsi/isci/host.h | |||
@@ -58,7 +58,7 @@ | |||
58 | #include "remote_device.h" | 58 | #include "remote_device.h" |
59 | #include "phy.h" | 59 | #include "phy.h" |
60 | #include "pool.h" | 60 | #include "pool.h" |
61 | #include "state_machine.h" | 61 | #include "isci.h" |
62 | #include "remote_node_table.h" | 62 | #include "remote_node_table.h" |
63 | #include "registers.h" | 63 | #include "registers.h" |
64 | #include "scu_unsolicited_frame.h" | 64 | #include "scu_unsolicited_frame.h" |
diff --git a/drivers/scsi/isci/isci.h b/drivers/scsi/isci/isci.h index 2fe5557d8590..80cfb45f8da1 100644 --- a/drivers/scsi/isci/isci.h +++ b/drivers/scsi/isci/isci.h | |||
@@ -57,6 +57,7 @@ | |||
57 | #define __ISCI_H__ | 57 | #define __ISCI_H__ |
58 | 58 | ||
59 | #include <linux/interrupt.h> | 59 | #include <linux/interrupt.h> |
60 | #include <linux/types.h> | ||
60 | 61 | ||
61 | #define DRV_NAME "isci" | 62 | #define DRV_NAME "isci" |
62 | #define SCI_PCI_BAR_COUNT 2 | 63 | #define SCI_PCI_BAR_COUNT 2 |
@@ -584,4 +585,22 @@ static inline void sci_del_timer(struct sci_timer *tmr) | |||
584 | del_timer(&tmr->timer); | 585 | del_timer(&tmr->timer); |
585 | } | 586 | } |
586 | 587 | ||
588 | struct sci_base_state_machine { | ||
589 | const struct sci_base_state *state_table; | ||
590 | u32 initial_state_id; | ||
591 | u32 current_state_id; | ||
592 | u32 previous_state_id; | ||
593 | }; | ||
594 | |||
595 | typedef void (*sci_state_transition_t)(struct sci_base_state_machine *sm); | ||
596 | |||
597 | struct sci_base_state { | ||
598 | sci_state_transition_t enter_state; /* Called on state entry */ | ||
599 | sci_state_transition_t exit_state; /* Called on state exit */ | ||
600 | }; | ||
601 | |||
602 | extern void sci_init_sm(struct sci_base_state_machine *sm, | ||
603 | const struct sci_base_state *state_table, | ||
604 | u32 initial_state); | ||
605 | extern void sci_change_state(struct sci_base_state_machine *sm, u32 next_state); | ||
587 | #endif /* __ISCI_H__ */ | 606 | #endif /* __ISCI_H__ */ |
diff --git a/drivers/scsi/isci/phy.c b/drivers/scsi/isci/phy.c index 9de21c719351..784c9a71333a 100644 --- a/drivers/scsi/isci/phy.c +++ b/drivers/scsi/isci/phy.c | |||
@@ -1294,11 +1294,7 @@ static const struct sci_base_state scic_sds_phy_state_table[] = { | |||
1294 | void scic_sds_phy_construct(struct scic_sds_phy *sci_phy, | 1294 | void scic_sds_phy_construct(struct scic_sds_phy *sci_phy, |
1295 | struct scic_sds_port *owning_port, u8 phy_index) | 1295 | struct scic_sds_port *owning_port, u8 phy_index) |
1296 | { | 1296 | { |
1297 | sci_base_state_machine_construct(&sci_phy->sm, | 1297 | sci_init_sm(&sci_phy->sm, scic_sds_phy_state_table, SCI_PHY_INITIAL); |
1298 | scic_sds_phy_state_table, | ||
1299 | SCI_PHY_INITIAL); | ||
1300 | |||
1301 | sci_base_state_machine_start(&sci_phy->sm); | ||
1302 | 1298 | ||
1303 | /* Copy the rest of the input data to our locals */ | 1299 | /* Copy the rest of the input data to our locals */ |
1304 | sci_phy->owning_port = owning_port; | 1300 | sci_phy->owning_port = owning_port; |
diff --git a/drivers/scsi/isci/phy.h b/drivers/scsi/isci/phy.h index 9d21d2754dbb..97ebee16f4b3 100644 --- a/drivers/scsi/isci/phy.h +++ b/drivers/scsi/isci/phy.h | |||
@@ -57,7 +57,7 @@ | |||
57 | 57 | ||
58 | #include <scsi/sas.h> | 58 | #include <scsi/sas.h> |
59 | #include <scsi/libsas.h> | 59 | #include <scsi/libsas.h> |
60 | #include "state_machine.h" | 60 | #include "isci.h" |
61 | #include "sas.h" | 61 | #include "sas.h" |
62 | 62 | ||
63 | /* This is the timeout value for the SATA phy to wait for a SIGNATURE FIS | 63 | /* This is the timeout value for the SATA phy to wait for a SIGNATURE FIS |
diff --git a/drivers/scsi/isci/port.c b/drivers/scsi/isci/port.c index 6370b93bd6ae..74f06f3c0735 100644 --- a/drivers/scsi/isci/port.c +++ b/drivers/scsi/isci/port.c | |||
@@ -1807,11 +1807,7 @@ static const struct sci_base_state scic_sds_port_state_table[] = { | |||
1807 | void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index, | 1807 | void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index, |
1808 | struct scic_sds_controller *scic) | 1808 | struct scic_sds_controller *scic) |
1809 | { | 1809 | { |
1810 | sci_base_state_machine_construct(&sci_port->sm, | 1810 | sci_init_sm(&sci_port->sm, scic_sds_port_state_table, SCI_PORT_STOPPED); |
1811 | scic_sds_port_state_table, | ||
1812 | SCI_PORT_STOPPED); | ||
1813 | |||
1814 | sci_base_state_machine_start(&sci_port->sm); | ||
1815 | 1811 | ||
1816 | sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT; | 1812 | sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT; |
1817 | sci_port->physical_port_index = index; | 1813 | sci_port->physical_port_index = index; |
diff --git a/drivers/scsi/isci/remote_device.c b/drivers/scsi/isci/remote_device.c index 6c93f20f3dd3..3b555dcbe569 100644 --- a/drivers/scsi/isci/remote_device.c +++ b/drivers/scsi/isci/remote_device.c | |||
@@ -1095,11 +1095,7 @@ static void scic_remote_device_construct(struct scic_sds_port *sci_port, | |||
1095 | sci_dev->owning_port = sci_port; | 1095 | sci_dev->owning_port = sci_port; |
1096 | sci_dev->started_request_count = 0; | 1096 | sci_dev->started_request_count = 0; |
1097 | 1097 | ||
1098 | sci_base_state_machine_construct(&sci_dev->sm, | 1098 | sci_init_sm(&sci_dev->sm, scic_sds_remote_device_state_table, SCI_DEV_INITIAL); |
1099 | scic_sds_remote_device_state_table, | ||
1100 | SCI_DEV_INITIAL); | ||
1101 | |||
1102 | sci_base_state_machine_start(&sci_dev->sm); | ||
1103 | 1099 | ||
1104 | scic_sds_remote_node_context_construct(&sci_dev->rnc, | 1100 | scic_sds_remote_node_context_construct(&sci_dev->rnc, |
1105 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); | 1101 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); |
diff --git a/drivers/scsi/isci/remote_node_context.c b/drivers/scsi/isci/remote_node_context.c index 24b1d8acf7b8..9e8967e19688 100644 --- a/drivers/scsi/isci/remote_node_context.c +++ b/drivers/scsi/isci/remote_node_context.c | |||
@@ -54,7 +54,7 @@ | |||
54 | */ | 54 | */ |
55 | 55 | ||
56 | #include "host.h" | 56 | #include "host.h" |
57 | #include "state_machine.h" | 57 | #include "isci.h" |
58 | #include "remote_device.h" | 58 | #include "remote_device.h" |
59 | #include "remote_node_context.h" | 59 | #include "remote_node_context.h" |
60 | #include "scu_event_codes.h" | 60 | #include "scu_event_codes.h" |
@@ -373,11 +373,7 @@ void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context | |||
373 | rnc->remote_node_index = remote_node_index; | 373 | rnc->remote_node_index = remote_node_index; |
374 | rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED; | 374 | rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED; |
375 | 375 | ||
376 | sci_base_state_machine_construct(&rnc->sm, | 376 | sci_init_sm(&rnc->sm, scic_sds_remote_node_context_state_table, SCI_RNC_INITIAL); |
377 | scic_sds_remote_node_context_state_table, | ||
378 | SCI_RNC_INITIAL); | ||
379 | |||
380 | sci_base_state_machine_start(&rnc->sm); | ||
381 | } | 377 | } |
382 | 378 | ||
383 | enum sci_status scic_sds_remote_node_context_event_handler(struct scic_sds_remote_node_context *sci_rnc, | 379 | enum sci_status scic_sds_remote_node_context_event_handler(struct scic_sds_remote_node_context *sci_rnc, |
diff --git a/drivers/scsi/isci/remote_node_context.h b/drivers/scsi/isci/remote_node_context.h index e6c7248be3f6..67a45b686a98 100644 --- a/drivers/scsi/isci/remote_node_context.h +++ b/drivers/scsi/isci/remote_node_context.h | |||
@@ -64,7 +64,7 @@ | |||
64 | * | 64 | * |
65 | */ | 65 | */ |
66 | 66 | ||
67 | #include "state_machine.h" | 67 | #include "isci.h" |
68 | 68 | ||
69 | /** | 69 | /** |
70 | * | 70 | * |
diff --git a/drivers/scsi/isci/request.c b/drivers/scsi/isci/request.c index 89f0ab925c27..8bd1f7dbad37 100644 --- a/drivers/scsi/isci/request.c +++ b/drivers/scsi/isci/request.c | |||
@@ -3077,10 +3077,7 @@ scic_sds_general_request_construct(struct scic_sds_controller *scic, | |||
3077 | u16 io_tag, | 3077 | u16 io_tag, |
3078 | struct scic_sds_request *sci_req) | 3078 | struct scic_sds_request *sci_req) |
3079 | { | 3079 | { |
3080 | sci_base_state_machine_construct(&sci_req->sm, | 3080 | sci_init_sm(&sci_req->sm, scic_sds_request_state_table, SCI_REQ_INIT); |
3081 | scic_sds_request_state_table, | ||
3082 | SCI_REQ_INIT); | ||
3083 | sci_base_state_machine_start(&sci_req->sm); | ||
3084 | 3081 | ||
3085 | sci_req->io_tag = io_tag; | 3082 | sci_req->io_tag = io_tag; |
3086 | sci_req->owning_controller = scic; | 3083 | sci_req->owning_controller = scic; |
diff --git a/drivers/scsi/isci/state_machine.c b/drivers/scsi/isci/state_machine.c deleted file mode 100644 index 8cfefb959f22..000000000000 --- a/drivers/scsi/isci/state_machine.c +++ /dev/null | |||
@@ -1,138 +0,0 @@ | |||
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 | |||
56 | /** | ||
57 | * This file contains all of the functionality common to all state machine | ||
58 | * object implementations. | ||
59 | * | ||
60 | * | ||
61 | */ | ||
62 | |||
63 | #include "state_machine.h" | ||
64 | |||
65 | static void sci_state_machine_exit_state(struct sci_base_state_machine *sm) | ||
66 | { | ||
67 | u32 state = sm->current_state_id; | ||
68 | sci_state_transition_t exit = sm->state_table[state].exit_state; | ||
69 | |||
70 | if (exit) | ||
71 | exit(sm); | ||
72 | } | ||
73 | |||
74 | static void sci_state_machine_enter_state(struct sci_base_state_machine *sm) | ||
75 | { | ||
76 | u32 state = sm->current_state_id; | ||
77 | sci_state_transition_t enter = sm->state_table[state].enter_state; | ||
78 | |||
79 | if (enter) | ||
80 | enter(sm); | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * This method will set the initial state and state table for the state | ||
85 | * machine. The caller should follow this request with the initialize | ||
86 | * request to cause the state machine to start. | ||
87 | * @sm: This parameter provides the state machine object to be | ||
88 | * constructed. | ||
89 | * @state_table: This parameter specifies the table of state objects that is | ||
90 | * managed by this state machine. | ||
91 | * @initial_state: This parameter specifies the value of the initial state for | ||
92 | * this state machine. | ||
93 | * | ||
94 | */ | ||
95 | void sci_base_state_machine_construct(struct sci_base_state_machine *sm, | ||
96 | const struct sci_base_state *state_table, | ||
97 | u32 initial_state) | ||
98 | { | ||
99 | sm->initial_state_id = initial_state; | ||
100 | sm->previous_state_id = initial_state; | ||
101 | sm->current_state_id = initial_state; | ||
102 | sm->state_table = state_table; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * This method will cause the state machine to enter the initial state. | ||
107 | * @sm: This parameter specifies the state machine that is to | ||
108 | * be started. | ||
109 | * | ||
110 | * sci_base_state_machine_construct() for how to set the initial state none | ||
111 | */ | ||
112 | void sci_base_state_machine_start(struct sci_base_state_machine *sm) | ||
113 | { | ||
114 | sm->current_state_id = sm->initial_state_id; | ||
115 | sci_state_machine_enter_state(sm); | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * This method will cause the state machine to exit it's current state only. | ||
120 | * @sm: This parameter specifies the state machine that is to | ||
121 | * be stopped. | ||
122 | * | ||
123 | */ | ||
124 | void sci_base_state_machine_stop( | ||
125 | struct sci_base_state_machine *sm) | ||
126 | { | ||
127 | sci_state_machine_exit_state(sm); | ||
128 | } | ||
129 | |||
130 | void sci_change_state(struct sci_base_state_machine *sm, u32 next_state) | ||
131 | { | ||
132 | sci_state_machine_exit_state(sm); | ||
133 | |||
134 | sm->previous_state_id = sm->current_state_id; | ||
135 | sm->current_state_id = next_state; | ||
136 | |||
137 | sci_state_machine_enter_state(sm); | ||
138 | } | ||
diff --git a/drivers/scsi/isci/state_machine.h b/drivers/scsi/isci/state_machine.h deleted file mode 100644 index 6cb55a0adc54..000000000000 --- a/drivers/scsi/isci/state_machine.h +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
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 | |||
56 | #ifndef _SCI_BASE_STATE_MACHINE_H_ | ||
57 | #define _SCI_BASE_STATE_MACHINE_H_ | ||
58 | |||
59 | #include <linux/types.h> | ||
60 | |||
61 | struct sci_base_state_machine; | ||
62 | typedef void (*sci_base_state_handler_t)(void); | ||
63 | typedef void (*sci_state_transition_t)(struct sci_base_state_machine *sm); | ||
64 | |||
65 | /** | ||
66 | * struct sci_base_state - The base state object abstracts the fields common to | ||
67 | * all state objects defined in SCI. | ||
68 | * | ||
69 | * | ||
70 | */ | ||
71 | struct sci_base_state { | ||
72 | /** | ||
73 | * This field is a function pointer that defines the method to be | ||
74 | * invoked when the state is entered. | ||
75 | */ | ||
76 | sci_state_transition_t enter_state; | ||
77 | |||
78 | /** | ||
79 | * This field is a function pointer that defines the method to be | ||
80 | * invoked when the state is exited. | ||
81 | */ | ||
82 | sci_state_transition_t exit_state; | ||
83 | }; | ||
84 | |||
85 | /** | ||
86 | * struct sci_base_state_machine - This structure defines the fields common to | ||
87 | * all state machines. | ||
88 | * | ||
89 | * | ||
90 | */ | ||
91 | struct sci_base_state_machine { | ||
92 | /** | ||
93 | * This field points to the start of the state machine's state table. | ||
94 | */ | ||
95 | const struct sci_base_state *state_table; | ||
96 | |||
97 | /** | ||
98 | * This field simply indicates the state value for the state machine's | ||
99 | * initial state. | ||
100 | */ | ||
101 | u32 initial_state_id; | ||
102 | |||
103 | /** | ||
104 | * This field indicates the current state of the state machine. | ||
105 | */ | ||
106 | u32 current_state_id; | ||
107 | |||
108 | /** | ||
109 | * This field indicates the previous state of the state machine. | ||
110 | */ | ||
111 | u32 previous_state_id; | ||
112 | |||
113 | }; | ||
114 | |||
115 | void sci_base_state_machine_construct(struct sci_base_state_machine *sm, | ||
116 | const struct sci_base_state *state_table, | ||
117 | u32 initial_state); | ||
118 | void sci_base_state_machine_start(struct sci_base_state_machine *sm); | ||
119 | void sci_base_state_machine_stop(struct sci_base_state_machine *sm); | ||
120 | void sci_change_state(struct sci_base_state_machine *sm, u32 next_state); | ||
121 | |||
122 | #endif /* _SCI_BASE_STATE_MACHINE_H_ */ | ||