Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_pm.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /**
34  * @file
35  * API for OCS power managment
36  *
37  */
38 
39 #include "ocs.h"
40 #include "ocs_pm.h"
41 
42 /**
43  * @brief Handle Power Management Request
44  *
45  * Function is called by management or OS to request a change in the power state of
46  * the device controlled by the OCS driver. The API supports requesting the following:
47  *
48  * OCS_PM_PREPARE The device (in state S0) is notified that a power state change is
49  * forthcoming.
50  * OCS_PM_SLEEP The device is transitioned to state S3 (sleep/standby).
51  * OCS_PM_HIBERNATE The device is transitioned to state S4 (hibernate)
52  * OCS_PM_RESUME The device resumes
53  * OCS_PM_CANCEL Cancel any pending request. If a callback was expected for the
54  * pending request, the callback will be made with an error status
55  * indicating the request was cancelled.
56  *
57  * @param ocs pointer to device structure
58  * @param msg power manatement request message
59  * @param callback callback function to be invoked when request has completed.
60  * @param arg arbitrary argument that is passed to the callback
61  *
62  * Arguments to the callback function are as follows:
63  *
64  * ocs pointer to device structure
65  * status integer value indicating the success or failure of the requested operation. 0 for
66  * success, negative value for failure.
67  * arg pointer to the caller supplied argument
68  *
69  * @return 0 for success, callback is expected
70  * 1 for success, no callback
71  * negative value for failure, no callback
72  *
73  * For the OCS driver on the SLI4 adapters at the time of writing, SLEEP and HIBERNATE both transition to S3,
74  * assumming power on the device and memory is retained. IO's are quiesced, the port is offlined,
75  * interrupts are disabled, link is taken down. Back end calls will result, not disimilar to the
76  * bahavior of loss of link.
77  *
78  * RESUME will bring the port back online, initiate discovery (for initiator).
79  */
80 int32_t
81 ocs_pm_request(ocs_t *ocs, ocs_pm_msg_e msg, int32_t (*callback)(ocs_t *ocs, int32_t status, void *arg), void *arg)
82 {
83  int32_t rc = 1;
84 
85  switch (msg) {
86  case OCS_PM_PREPARE:
87  rc = 1;
88  break;
89  case OCS_PM_SLEEP:
90  rc = ocs_device_detach(ocs);
91  if (rc == 0) {
92  ocs->pm_context.pm_state = OCS_PM_STATE_S3;
93  rc = 1;
94  }
95  break;
96  case OCS_PM_HIBERNATE:
97  rc = ocs_device_detach(ocs);
98  if (rc == 0) {
99  ocs->pm_context.pm_state = OCS_PM_STATE_S4;
100  rc = 1;
101  }
102  break;
103  case OCS_PM_RESUME: {
104  rc = ocs_device_attach(ocs);
105  if (rc == 0) {
106  ocs->pm_context.pm_state = OCS_PM_STATE_S0;
107  rc = 1;
108  }
109  break;
110  }
111  }
112  return rc;
113 }
114 
115 
116 /**
117  * @brief Return driver power state
118  *
119  * The current power state is returned. Note, that in some implementations, the power state may differ
120  * from that requested and completed using ocs_pm_request(). (SLI4 HIBERNATE requests will sleep)
121  *
122  * @param ocs pointer to device structure
123  *
124  * @return the current power state is returned
125  */
127 ocs_pm_get_state(ocs_t *ocs)
128 {
129  return ocs->pm_context.pm_state;
130 }
131 
132 /**
133  * @brief Return driver power state as an ascii string
134  *
135  * The current power state is returned as a string.
136  *
137  * @param ocs poitner to device structure
138  *
139  * @return returns power state string
140  */
141 const char *ocs_pm_get_state_string(ocs_t *ocs)
142 {
143  switch (ocs_pm_get_state(ocs)) {
144  case OCS_PM_STATE_S0: return "S0";
145  case OCS_PM_STATE_S1: return "S1";
146  case OCS_PM_STATE_S2: return "S2";
147  case OCS_PM_STATE_S3: return "S3";
148  case OCS_PM_STATE_S4: return "S4";
149  }
150  return "S?";
151 }
const char * ocs_pm_get_state_string(ocs_t *ocs)
Return driver power state as an ascii string.
Definition: ocs_pm.c:141
int32_t ocs_device_detach(ocs_t *ocs)
free resources when pci device detach
ocs_pm_state_e ocs_pm_get_state(ocs_t *ocs)
Return driver power state.
Definition: ocs_pm.c:127
int32_t ocs_pm_request(ocs_t *ocs, ocs_pm_msg_e msg, int32_t(*callback)(ocs_t *ocs, int32_t status, void *arg), void *arg)
Handle Power Management Request.
Definition: ocs_pm.c:81
int32_t ocs_device_attach(ocs_t *ocs)
Initialize resources when pci devices attach.
ocs_pm_state_e
Power State values.
Definition: ocs_pm.h:56
ocs_pm_msg_e
Power State change message types.
Definition: ocs_pm.h:45