Commit | Line | Data |
---|---|---|
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 | ||
56 | #include "isci.h" | |
ce2b3261 | 57 | #include "host.h" |
6f231dda | 58 | #include "phy.h" |
d35bc1bd | 59 | #include "scu_event_codes.h" |
d35bc1bd | 60 | #include "timers.h" |
e2f8db50 | 61 | #include "probe_roms.h" |
6f231dda | 62 | |
d35bc1bd DW |
63 | /* Maximum arbitration wait time in micro-seconds */ |
64 | #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700) | |
65 | ||
66 | enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy) | |
67 | { | |
68 | return sci_phy->max_negotiated_speed; | |
69 | } | |
70 | ||
71 | /* | |
72 | * ***************************************************************************** | |
73 | * * SCIC SDS PHY Internal Methods | |
74 | * ***************************************************************************** */ | |
75 | ||
76 | /** | |
77 | * This method will initialize the phy transport layer registers | |
78 | * @sci_phy: | |
79 | * @transport_layer_registers | |
80 | * | |
81 | * enum sci_status | |
82 | */ | |
83 | static enum sci_status scic_sds_phy_transport_layer_initialization( | |
84 | struct scic_sds_phy *sci_phy, | |
85 | struct scu_transport_layer_registers __iomem *transport_layer_registers) | |
86 | { | |
87 | u32 tl_control; | |
88 | ||
89 | sci_phy->transport_layer_registers = transport_layer_registers; | |
90 | ||
91 | writel(SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX, | |
92 | &sci_phy->transport_layer_registers->stp_rni); | |
93 | ||
94 | /* | |
95 | * Hardware team recommends that we enable the STP prefetch for all | |
96 | * transports | |
97 | */ | |
98 | tl_control = readl(&sci_phy->transport_layer_registers->control); | |
99 | tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH); | |
100 | writel(tl_control, &sci_phy->transport_layer_registers->control); | |
101 | ||
102 | return SCI_SUCCESS; | |
103 | } | |
104 | ||
105 | /** | |
106 | * This method will initialize the phy link layer registers | |
107 | * @sci_phy: | |
108 | * @link_layer_registers: | |
109 | * | |
110 | * enum sci_status | |
111 | */ | |
112 | static enum sci_status | |
113 | scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy, | |
114 | struct scu_link_layer_registers __iomem *link_layer_registers) | |
115 | { | |
116 | struct scic_sds_controller *scic = | |
117 | sci_phy->owning_port->owning_controller; | |
118 | int phy_idx = sci_phy->phy_index; | |
119 | struct sci_phy_user_params *phy_user = | |
120 | &scic->user_parameters.sds1.phys[phy_idx]; | |
121 | struct sci_phy_oem_params *phy_oem = | |
122 | &scic->oem_parameters.sds1.phys[phy_idx]; | |
123 | u32 phy_configuration; | |
124 | struct scic_phy_cap phy_cap; | |
125 | u32 parity_check = 0; | |
126 | u32 parity_count = 0; | |
127 | u32 llctl, link_rate; | |
128 | u32 clksm_value = 0; | |
129 | ||
130 | sci_phy->link_layer_registers = link_layer_registers; | |
131 | ||
132 | /* Set our IDENTIFY frame data */ | |
133 | #define SCI_END_DEVICE 0x01 | |
134 | ||
135 | writel(SCU_SAS_TIID_GEN_BIT(SMP_INITIATOR) | | |
136 | SCU_SAS_TIID_GEN_BIT(SSP_INITIATOR) | | |
137 | SCU_SAS_TIID_GEN_BIT(STP_INITIATOR) | | |
138 | SCU_SAS_TIID_GEN_BIT(DA_SATA_HOST) | | |
139 | SCU_SAS_TIID_GEN_VAL(DEVICE_TYPE, SCI_END_DEVICE), | |
140 | &sci_phy->link_layer_registers->transmit_identification); | |
141 | ||
142 | /* Write the device SAS Address */ | |
143 | writel(0xFEDCBA98, | |
144 | &sci_phy->link_layer_registers->sas_device_name_high); | |
145 | writel(phy_idx, &sci_phy->link_layer_registers->sas_device_name_low); | |
146 | ||
147 | /* Write the source SAS Address */ | |
148 | writel(phy_oem->sas_address.high, | |
149 | &sci_phy->link_layer_registers->source_sas_address_high); | |
150 | writel(phy_oem->sas_address.low, | |
151 | &sci_phy->link_layer_registers->source_sas_address_low); | |
152 | ||
153 | /* Clear and Set the PHY Identifier */ | |
154 | writel(0, &sci_phy->link_layer_registers->identify_frame_phy_id); | |
155 | writel(SCU_SAS_TIPID_GEN_VALUE(ID, phy_idx), | |
156 | &sci_phy->link_layer_registers->identify_frame_phy_id); | |
157 | ||
158 | /* Change the initial state of the phy configuration register */ | |
159 | phy_configuration = | |
160 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
161 | ||
162 | /* Hold OOB state machine in reset */ | |
163 | phy_configuration |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET); | |
164 | writel(phy_configuration, | |
165 | &sci_phy->link_layer_registers->phy_configuration); | |
166 | ||
167 | /* Configure the SNW capabilities */ | |
168 | phy_cap.all = 0; | |
169 | phy_cap.start = 1; | |
170 | phy_cap.gen3_no_ssc = 1; | |
171 | phy_cap.gen2_no_ssc = 1; | |
172 | phy_cap.gen1_no_ssc = 1; | |
173 | if (scic->oem_parameters.sds1.controller.do_enable_ssc == true) { | |
174 | phy_cap.gen3_ssc = 1; | |
175 | phy_cap.gen2_ssc = 1; | |
176 | phy_cap.gen1_ssc = 1; | |
177 | } | |
178 | ||
179 | /* | |
180 | * The SAS specification indicates that the phy_capabilities that | |
181 | * are transmitted shall have an even parity. Calculate the parity. */ | |
182 | parity_check = phy_cap.all; | |
183 | while (parity_check != 0) { | |
184 | if (parity_check & 0x1) | |
185 | parity_count++; | |
186 | parity_check >>= 1; | |
187 | } | |
188 | ||
189 | /* | |
190 | * If parity indicates there are an odd number of bits set, then | |
191 | * set the parity bit to 1 in the phy capabilities. */ | |
192 | if ((parity_count % 2) != 0) | |
193 | phy_cap.parity = 1; | |
194 | ||
195 | writel(phy_cap.all, &sci_phy->link_layer_registers->phy_capabilities); | |
196 | ||
197 | /* Set the enable spinup period but disable the ability to send | |
198 | * notify enable spinup | |
199 | */ | |
200 | writel(SCU_ENSPINUP_GEN_VAL(COUNT, | |
201 | phy_user->notify_enable_spin_up_insertion_frequency), | |
202 | &sci_phy->link_layer_registers->notify_enable_spinup_control); | |
203 | ||
204 | /* Write the ALIGN Insertion Ferequency for connected phy and | |
205 | * inpendent of connected state | |
206 | */ | |
207 | clksm_value = SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(CONNECTED, | |
208 | phy_user->in_connection_align_insertion_frequency); | |
209 | ||
210 | clksm_value |= SCU_ALIGN_INSERTION_FREQUENCY_GEN_VAL(GENERAL, | |
211 | phy_user->align_insertion_frequency); | |
212 | ||
213 | writel(clksm_value, &sci_phy->link_layer_registers->clock_skew_management); | |
214 | ||
215 | /* @todo Provide a way to write this register correctly */ | |
216 | writel(0x02108421, | |
217 | &sci_phy->link_layer_registers->afe_lookup_table_control); | |
218 | ||
219 | llctl = SCU_SAS_LLCTL_GEN_VAL(NO_OUTBOUND_TASK_TIMEOUT, | |
220 | (u8)scic->user_parameters.sds1.no_outbound_task_timeout); | |
221 | ||
222 | switch(phy_user->max_speed_generation) { | |
223 | case SCIC_SDS_PARM_GEN3_SPEED: | |
224 | link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN3; | |
225 | break; | |
226 | case SCIC_SDS_PARM_GEN2_SPEED: | |
227 | link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN2; | |
228 | break; | |
229 | default: | |
230 | link_rate = SCU_SAS_LINK_LAYER_CONTROL_MAX_LINK_RATE_GEN1; | |
231 | break; | |
232 | } | |
233 | llctl |= SCU_SAS_LLCTL_GEN_VAL(MAX_LINK_RATE, link_rate); | |
234 | writel(llctl, &sci_phy->link_layer_registers->link_layer_control); | |
235 | ||
236 | if (is_a0() || is_a2()) { | |
237 | /* Program the max ARB time for the PHY to 700us so we inter-operate with | |
238 | * the PMC expander which shuts down PHYs if the expander PHY generates too | |
239 | * many breaks. This time value will guarantee that the initiator PHY will | |
240 | * generate the break. | |
241 | */ | |
242 | writel(SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME, | |
243 | &sci_phy->link_layer_registers->maximum_arbitration_wait_timer_timeout); | |
244 | } | |
245 | ||
246 | /* | |
247 | * Set the link layer hang detection to 500ms (0x1F4) from its default | |
248 | * value of 128ms. Max value is 511 ms. | |
249 | */ | |
250 | writel(0x1F4, &sci_phy->link_layer_registers->link_layer_hang_detection_timeout); | |
251 | ||
252 | /* We can exit the initial state to the stopped state */ | |
253 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
254 | SCI_BASE_PHY_STATE_STOPPED); | |
255 | ||
256 | return SCI_SUCCESS; | |
257 | } | |
258 | ||
259 | /** | |
260 | * This function will handle the sata SIGNATURE FIS timeout condition. It will | |
261 | * restart the starting substate machine since we dont know what has actually | |
262 | * happening. | |
263 | */ | |
264 | static void scic_sds_phy_sata_timeout(void *phy) | |
265 | { | |
266 | struct scic_sds_phy *sci_phy = phy; | |
267 | ||
268 | dev_dbg(sciphy_to_dev(sci_phy), | |
269 | "%s: SCIC SDS Phy 0x%p did not receive signature fis before " | |
270 | "timeout.\n", | |
271 | __func__, | |
272 | sci_phy); | |
273 | ||
d35bc1bd DW |
274 | sci_base_state_machine_change_state(&sci_phy->state_machine, |
275 | SCI_BASE_PHY_STATE_STARTING); | |
276 | } | |
277 | ||
278 | /** | |
279 | * This method returns the port currently containing this phy. If the phy is | |
280 | * currently contained by the dummy port, then the phy is considered to not | |
281 | * be part of a port. | |
282 | * @sci_phy: This parameter specifies the phy for which to retrieve the | |
283 | * containing port. | |
284 | * | |
285 | * This method returns a handle to a port that contains the supplied phy. | |
286 | * NULL This value is returned if the phy is not part of a real | |
287 | * port (i.e. it's contained in the dummy port). !NULL All other | |
288 | * values indicate a handle/pointer to the port containing the phy. | |
289 | */ | |
290 | struct scic_sds_port *scic_sds_phy_get_port( | |
291 | struct scic_sds_phy *sci_phy) | |
292 | { | |
293 | if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT) | |
294 | return NULL; | |
295 | ||
296 | return sci_phy->owning_port; | |
297 | } | |
298 | ||
299 | /** | |
300 | * This method will assign a port to the phy object. | |
301 | * @out]: sci_phy This parameter specifies the phy for which to assign a port | |
302 | * object. | |
303 | * | |
304 | * | |
305 | */ | |
306 | void scic_sds_phy_set_port( | |
307 | struct scic_sds_phy *sci_phy, | |
308 | struct scic_sds_port *sci_port) | |
309 | { | |
310 | sci_phy->owning_port = sci_port; | |
311 | ||
312 | if (sci_phy->bcn_received_while_port_unassigned) { | |
313 | sci_phy->bcn_received_while_port_unassigned = false; | |
314 | scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy); | |
315 | } | |
316 | } | |
317 | ||
318 | /** | |
319 | * This method will initialize the constructed phy | |
320 | * @sci_phy: | |
321 | * @link_layer_registers: | |
322 | * | |
323 | * enum sci_status | |
324 | */ | |
325 | enum sci_status scic_sds_phy_initialize( | |
326 | struct scic_sds_phy *sci_phy, | |
327 | struct scu_transport_layer_registers __iomem *transport_layer_registers, | |
328 | struct scu_link_layer_registers __iomem *link_layer_registers) | |
329 | { | |
330 | struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy); | |
331 | struct isci_host *ihost = scic_to_ihost(scic); | |
332 | ||
333 | /* Create the SIGNATURE FIS Timeout timer for this phy */ | |
334 | sci_phy->sata_timeout_timer = | |
335 | isci_timer_create( | |
336 | ihost, | |
337 | sci_phy, | |
338 | scic_sds_phy_sata_timeout); | |
339 | ||
340 | /* Perfrom the initialization of the TL hardware */ | |
341 | scic_sds_phy_transport_layer_initialization( | |
342 | sci_phy, | |
343 | transport_layer_registers); | |
344 | ||
345 | /* Perofrm the initialization of the PE hardware */ | |
346 | scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers); | |
347 | ||
348 | /* | |
349 | * There is nothing that needs to be done in this state just | |
350 | * transition to the stopped state. */ | |
351 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
352 | SCI_BASE_PHY_STATE_STOPPED); | |
353 | ||
354 | return SCI_SUCCESS; | |
355 | } | |
356 | ||
357 | /** | |
358 | * This method assigns the direct attached device ID for this phy. | |
359 | * | |
360 | * @sci_phy The phy for which the direct attached device id is to | |
361 | * be assigned. | |
362 | * @device_id The direct attached device ID to assign to the phy. | |
363 | * This will either be the RNi for the device or an invalid RNi if there | |
364 | * is no current device assigned to the phy. | |
365 | */ | |
366 | void scic_sds_phy_setup_transport( | |
367 | struct scic_sds_phy *sci_phy, | |
368 | u32 device_id) | |
369 | { | |
370 | u32 tl_control; | |
371 | ||
372 | writel(device_id, &sci_phy->transport_layer_registers->stp_rni); | |
373 | ||
374 | /* | |
375 | * The read should guarantee that the first write gets posted | |
376 | * before the next write | |
377 | */ | |
378 | tl_control = readl(&sci_phy->transport_layer_registers->control); | |
379 | tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE); | |
380 | writel(tl_control, &sci_phy->transport_layer_registers->control); | |
381 | } | |
382 | ||
383 | /** | |
384 | * | |
385 | * @sci_phy: The phy object to be suspended. | |
386 | * | |
387 | * This function will perform the register reads/writes to suspend the SCU | |
388 | * hardware protocol engine. none | |
389 | */ | |
390 | static void scic_sds_phy_suspend( | |
391 | struct scic_sds_phy *sci_phy) | |
392 | { | |
393 | u32 scu_sas_pcfg_value; | |
394 | ||
395 | scu_sas_pcfg_value = | |
396 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
397 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE); | |
398 | writel(scu_sas_pcfg_value, | |
399 | &sci_phy->link_layer_registers->phy_configuration); | |
400 | ||
401 | scic_sds_phy_setup_transport( | |
402 | sci_phy, | |
403 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); | |
404 | } | |
405 | ||
406 | void scic_sds_phy_resume(struct scic_sds_phy *sci_phy) | |
407 | { | |
408 | u32 scu_sas_pcfg_value; | |
409 | ||
410 | scu_sas_pcfg_value = | |
411 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
412 | scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE); | |
413 | writel(scu_sas_pcfg_value, | |
414 | &sci_phy->link_layer_registers->phy_configuration); | |
415 | } | |
416 | ||
417 | void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy, | |
418 | struct sci_sas_address *sas_address) | |
419 | { | |
420 | sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high); | |
421 | sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low); | |
422 | } | |
423 | ||
424 | void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy, | |
425 | struct sci_sas_address *sas_address) | |
426 | { | |
427 | struct sas_identify_frame *iaf; | |
428 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
429 | ||
430 | iaf = &iphy->frame_rcvd.iaf; | |
431 | memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE); | |
432 | } | |
433 | ||
434 | void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy, | |
435 | struct scic_phy_proto *protocols) | |
436 | { | |
437 | protocols->all = | |
438 | (u16)(readl(&sci_phy-> | |
439 | link_layer_registers->transmit_identification) & | |
440 | 0x0000FFFF); | |
441 | } | |
442 | ||
d35bc1bd DW |
443 | enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy) |
444 | { | |
966699b5 DW |
445 | struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller; |
446 | enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id; | |
447 | struct isci_host *ihost = scic_to_ihost(scic); | |
448 | ||
449 | if (state != SCI_BASE_PHY_STATE_STOPPED) { | |
450 | dev_dbg(sciphy_to_dev(sci_phy), | |
451 | "%s: in wrong state: %d\n", __func__, state); | |
452 | return SCI_FAILURE_INVALID_STATE; | |
453 | } | |
454 | ||
455 | /* Create the SIGNATURE FIS Timeout timer for this phy */ | |
456 | sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy, | |
457 | scic_sds_phy_sata_timeout); | |
458 | ||
459 | if (sci_phy->sata_timeout_timer) | |
460 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
461 | SCI_BASE_PHY_STATE_STARTING); | |
462 | ||
463 | return SCI_SUCCESS; | |
d35bc1bd DW |
464 | } |
465 | ||
d35bc1bd DW |
466 | enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy) |
467 | { | |
93153236 DW |
468 | enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id; |
469 | ||
470 | switch (state) { | |
471 | case SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL: | |
472 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN: | |
473 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN: | |
474 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER: | |
475 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER: | |
476 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN: | |
477 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN: | |
478 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF: | |
479 | case SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL: | |
480 | case SCI_BASE_PHY_STATE_READY: | |
481 | break; | |
482 | default: | |
483 | dev_dbg(sciphy_to_dev(sci_phy), | |
484 | "%s: in wrong state: %d\n", __func__, state); | |
485 | return SCI_FAILURE_INVALID_STATE; | |
486 | } | |
487 | ||
488 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
489 | SCI_BASE_PHY_STATE_STOPPED); | |
490 | return SCI_SUCCESS; | |
d35bc1bd DW |
491 | } |
492 | ||
0cf36fa9 | 493 | enum sci_status scic_sds_phy_reset(struct scic_sds_phy *sci_phy) |
d35bc1bd | 494 | { |
0cf36fa9 DW |
495 | enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id; |
496 | ||
497 | if (state != SCI_BASE_PHY_STATE_READY) { | |
498 | dev_dbg(sciphy_to_dev(sci_phy), | |
499 | "%s: in wrong state: %d\n", __func__, state); | |
500 | return SCI_FAILURE_INVALID_STATE; | |
501 | } | |
502 | ||
503 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
504 | SCI_BASE_PHY_STATE_RESETTING); | |
505 | return SCI_SUCCESS; | |
d35bc1bd DW |
506 | } |
507 | ||
508 | /** | |
509 | * This method will process the event code received. | |
510 | * @sci_phy: | |
511 | * @event_code: | |
512 | * | |
513 | * enum sci_status | |
514 | */ | |
515 | enum sci_status scic_sds_phy_event_handler( | |
516 | struct scic_sds_phy *sci_phy, | |
517 | u32 event_code) | |
518 | { | |
519 | return sci_phy->state_handlers->event_handler(sci_phy, event_code); | |
520 | } | |
521 | ||
c4441abc DW |
522 | enum sci_status scic_sds_phy_frame_handler(struct scic_sds_phy *sci_phy, |
523 | u32 frame_index) | |
d35bc1bd | 524 | { |
c4441abc DW |
525 | enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id; |
526 | struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller; | |
527 | enum sci_status result; | |
528 | ||
529 | switch (state) { | |
530 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF: { | |
531 | u32 *frame_words; | |
532 | struct sas_identify_frame iaf; | |
533 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
534 | ||
535 | result = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control, | |
536 | frame_index, | |
537 | (void **)&frame_words); | |
538 | ||
539 | if (result != SCI_SUCCESS) | |
540 | return result; | |
541 | ||
542 | sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32)); | |
543 | if (iaf.frame_type == 0) { | |
544 | u32 state; | |
545 | ||
546 | memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf)); | |
547 | if (iaf.smp_tport) { | |
548 | /* We got the IAF for an expander PHY go to the final | |
549 | * state since there are no power requirements for | |
550 | * expander phys. | |
551 | */ | |
552 | state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL; | |
553 | } else { | |
554 | /* We got the IAF we can now go to the await spinup | |
555 | * semaphore state | |
556 | */ | |
557 | state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER; | |
558 | } | |
559 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
560 | state); | |
561 | result = SCI_SUCCESS; | |
562 | } else | |
563 | dev_warn(sciphy_to_dev(sci_phy), | |
564 | "%s: PHY starting substate machine received " | |
565 | "unexpected frame id %x\n", | |
566 | __func__, frame_index); | |
567 | ||
568 | scic_sds_controller_release_frame(scic, frame_index); | |
569 | return result; | |
570 | } | |
571 | case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF: { | |
572 | struct dev_to_host_fis *frame_header; | |
573 | u32 *fis_frame_data; | |
574 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
575 | ||
576 | result = scic_sds_unsolicited_frame_control_get_header( | |
577 | &(scic_sds_phy_get_controller(sci_phy)->uf_control), | |
578 | frame_index, | |
579 | (void **)&frame_header); | |
580 | ||
581 | if (result != SCI_SUCCESS) | |
582 | return result; | |
583 | ||
584 | if ((frame_header->fis_type == FIS_REGD2H) && | |
585 | !(frame_header->status & ATA_BUSY)) { | |
586 | scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control, | |
587 | frame_index, | |
588 | (void **)&fis_frame_data); | |
589 | ||
590 | scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis, | |
591 | frame_header, | |
592 | fis_frame_data); | |
593 | ||
594 | /* got IAF we can now go to the await spinup semaphore state */ | |
595 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
596 | SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL); | |
597 | ||
598 | result = SCI_SUCCESS; | |
599 | } else | |
600 | dev_warn(sciphy_to_dev(sci_phy), | |
601 | "%s: PHY starting substate machine received " | |
602 | "unexpected frame id %x\n", | |
603 | __func__, frame_index); | |
604 | ||
605 | /* Regardless of the result we are done with this frame with it */ | |
606 | scic_sds_controller_release_frame(scic, frame_index); | |
607 | ||
608 | return result; | |
609 | } | |
610 | default: | |
611 | dev_dbg(sciphy_to_dev(sci_phy), | |
612 | "%s: in wrong state: %d\n", __func__, state); | |
613 | return SCI_FAILURE_INVALID_STATE; | |
614 | } | |
615 | ||
d35bc1bd DW |
616 | } |
617 | ||
618 | /** | |
619 | * This method will give the phy permission to consume power | |
620 | * @sci_phy: | |
621 | * | |
622 | * enum sci_status | |
623 | */ | |
624 | enum sci_status scic_sds_phy_consume_power_handler( | |
625 | struct scic_sds_phy *sci_phy) | |
626 | { | |
627 | return sci_phy->state_handlers->consume_power_handler(sci_phy); | |
628 | } | |
629 | ||
630 | /* | |
631 | * ***************************************************************************** | |
632 | * * SCIC SDS PHY HELPER FUNCTIONS | |
633 | * ***************************************************************************** */ | |
634 | ||
635 | ||
636 | /** | |
637 | * | |
638 | * @sci_phy: The phy object that received SAS PHY DETECTED. | |
639 | * | |
640 | * This method continues the link training for the phy as if it were a SAS PHY | |
641 | * instead of a SATA PHY. This is done because the completion queue had a SAS | |
642 | * PHY DETECTED event when the state machine was expecting a SATA PHY event. | |
643 | * none | |
644 | */ | |
645 | static void scic_sds_phy_start_sas_link_training( | |
646 | struct scic_sds_phy *sci_phy) | |
647 | { | |
648 | u32 phy_control; | |
649 | ||
650 | phy_control = | |
651 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
652 | phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD); | |
653 | writel(phy_control, | |
654 | &sci_phy->link_layer_registers->phy_configuration); | |
655 | ||
656 | sci_base_state_machine_change_state( | |
4a33c525 | 657 | &sci_phy->state_machine, |
d35bc1bd DW |
658 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN |
659 | ); | |
660 | ||
661 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS; | |
662 | } | |
663 | ||
664 | /** | |
665 | * | |
666 | * @sci_phy: The phy object that received a SATA SPINUP HOLD event | |
667 | * | |
668 | * This method continues the link training for the phy as if it were a SATA PHY | |
669 | * instead of a SAS PHY. This is done because the completion queue had a SATA | |
670 | * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none | |
671 | */ | |
672 | static void scic_sds_phy_start_sata_link_training( | |
673 | struct scic_sds_phy *sci_phy) | |
674 | { | |
675 | sci_base_state_machine_change_state( | |
4a33c525 | 676 | &sci_phy->state_machine, |
d35bc1bd DW |
677 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER |
678 | ); | |
679 | ||
680 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA; | |
681 | } | |
682 | ||
683 | /** | |
684 | * scic_sds_phy_complete_link_training - perform processing common to | |
685 | * all protocols upon completion of link training. | |
686 | * @sci_phy: This parameter specifies the phy object for which link training | |
687 | * has completed. | |
688 | * @max_link_rate: This parameter specifies the maximum link rate to be | |
689 | * associated with this phy. | |
690 | * @next_state: This parameter specifies the next state for the phy's starting | |
691 | * sub-state machine. | |
692 | * | |
693 | */ | |
694 | static void scic_sds_phy_complete_link_training( | |
695 | struct scic_sds_phy *sci_phy, | |
696 | enum sas_linkrate max_link_rate, | |
697 | u32 next_state) | |
698 | { | |
699 | sci_phy->max_negotiated_speed = max_link_rate; | |
700 | ||
4a33c525 | 701 | sci_base_state_machine_change_state(&sci_phy->state_machine, |
d35bc1bd DW |
702 | next_state); |
703 | } | |
704 | ||
705 | static void scic_sds_phy_restart_starting_state( | |
706 | struct scic_sds_phy *sci_phy) | |
707 | { | |
d35bc1bd DW |
708 | /* Re-enter the base state machine starting state */ |
709 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
710 | SCI_BASE_PHY_STATE_STARTING); | |
711 | } | |
712 | ||
d35bc1bd DW |
713 | /** |
714 | * | |
715 | * @phy: This struct scic_sds_phy object which has received an event. | |
716 | * @event_code: This is the event code which the phy object is to decode. | |
717 | * | |
718 | * This method is called when an event notification is received for the phy | |
719 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - | |
720 | * decode the event - sas phy detected causes a state transition to the wait | |
721 | * for speed event notification. - any other events log a warning message and | |
722 | * set a failure status enum sci_status SCI_SUCCESS on any valid event notification | |
723 | * SCI_FAILURE on any unexpected event notifation | |
724 | */ | |
725 | static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler( | |
726 | struct scic_sds_phy *sci_phy, | |
727 | u32 event_code) | |
728 | { | |
729 | u32 result = SCI_SUCCESS; | |
730 | ||
731 | switch (scu_get_event_code(event_code)) { | |
732 | case SCU_EVENT_SAS_PHY_DETECTED: | |
733 | scic_sds_phy_start_sas_link_training(sci_phy); | |
734 | sci_phy->is_in_link_training = true; | |
735 | break; | |
736 | ||
737 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
738 | scic_sds_phy_start_sata_link_training(sci_phy); | |
739 | sci_phy->is_in_link_training = true; | |
740 | break; | |
741 | ||
742 | default: | |
743 | dev_dbg(sciphy_to_dev(sci_phy), | |
744 | "%s: PHY starting substate machine received " | |
745 | "unexpected event_code %x\n", | |
746 | __func__, | |
747 | event_code); | |
748 | ||
749 | result = SCI_FAILURE; | |
750 | break; | |
751 | } | |
752 | ||
753 | return result; | |
754 | } | |
755 | ||
756 | /** | |
757 | * | |
758 | * @phy: This struct scic_sds_phy object which has received an event. | |
759 | * @event_code: This is the event code which the phy object is to decode. | |
760 | * | |
761 | * This method is called when an event notification is received for the phy | |
762 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - | |
763 | * decode the event - sas phy detected returns us back to this state. - speed | |
764 | * event detected causes a state transition to the wait for iaf. - identify | |
765 | * timeout is an un-expected event and the state machine is restarted. - link | |
766 | * failure events restart the starting state machine - any other events log a | |
767 | * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid | |
768 | * event notification SCI_FAILURE on any unexpected event notifation | |
769 | */ | |
770 | static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler( | |
771 | struct scic_sds_phy *sci_phy, | |
772 | u32 event_code) | |
773 | { | |
774 | u32 result = SCI_SUCCESS; | |
775 | ||
776 | switch (scu_get_event_code(event_code)) { | |
777 | case SCU_EVENT_SAS_PHY_DETECTED: | |
778 | /* | |
779 | * Why is this being reported again by the controller? | |
780 | * We would re-enter this state so just stay here */ | |
781 | break; | |
782 | ||
783 | case SCU_EVENT_SAS_15: | |
784 | case SCU_EVENT_SAS_15_SSC: | |
785 | scic_sds_phy_complete_link_training( | |
786 | sci_phy, | |
787 | SAS_LINK_RATE_1_5_GBPS, | |
788 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF); | |
789 | break; | |
790 | ||
791 | case SCU_EVENT_SAS_30: | |
792 | case SCU_EVENT_SAS_30_SSC: | |
793 | scic_sds_phy_complete_link_training( | |
794 | sci_phy, | |
795 | SAS_LINK_RATE_3_0_GBPS, | |
796 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF); | |
797 | break; | |
798 | ||
799 | case SCU_EVENT_SAS_60: | |
800 | case SCU_EVENT_SAS_60_SSC: | |
801 | scic_sds_phy_complete_link_training( | |
802 | sci_phy, | |
803 | SAS_LINK_RATE_6_0_GBPS, | |
804 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF); | |
805 | break; | |
806 | ||
807 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
808 | /* | |
809 | * We were doing SAS PHY link training and received a SATA PHY event | |
810 | * continue OOB/SN as if this were a SATA PHY */ | |
811 | scic_sds_phy_start_sata_link_training(sci_phy); | |
812 | break; | |
813 | ||
814 | case SCU_EVENT_LINK_FAILURE: | |
815 | /* Link failure change state back to the starting state */ | |
816 | scic_sds_phy_restart_starting_state(sci_phy); | |
817 | break; | |
818 | ||
819 | default: | |
820 | dev_warn(sciphy_to_dev(sci_phy), | |
821 | "%s: PHY starting substate machine received " | |
822 | "unexpected event_code %x\n", | |
823 | __func__, | |
824 | event_code); | |
825 | ||
826 | result = SCI_FAILURE; | |
827 | break; | |
828 | } | |
829 | ||
830 | return result; | |
831 | } | |
832 | ||
833 | /** | |
834 | * | |
835 | * @phy: This struct scic_sds_phy object which has received an event. | |
836 | * @event_code: This is the event code which the phy object is to decode. | |
837 | * | |
838 | * This method is called when an event notification is received for the phy | |
839 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - | |
840 | * decode the event - sas phy detected event backs up the state machine to the | |
841 | * await speed notification. - identify timeout is an un-expected event and the | |
842 | * state machine is restarted. - link failure events restart the starting state | |
843 | * machine - any other events log a warning message and set a failure status | |
844 | * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any | |
845 | * unexpected event notifation | |
846 | */ | |
847 | static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler( | |
848 | struct scic_sds_phy *sci_phy, | |
849 | u32 event_code) | |
850 | { | |
851 | u32 result = SCI_SUCCESS; | |
852 | ||
853 | switch (scu_get_event_code(event_code)) { | |
854 | case SCU_EVENT_SAS_PHY_DETECTED: | |
855 | /* Backup the state machine */ | |
856 | scic_sds_phy_start_sas_link_training(sci_phy); | |
857 | break; | |
858 | ||
859 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
860 | /* | |
861 | * We were doing SAS PHY link training and received a SATA PHY event | |
862 | * continue OOB/SN as if this were a SATA PHY */ | |
863 | scic_sds_phy_start_sata_link_training(sci_phy); | |
864 | break; | |
865 | ||
866 | case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT: | |
867 | case SCU_EVENT_LINK_FAILURE: | |
868 | case SCU_EVENT_HARD_RESET_RECEIVED: | |
869 | /* Start the oob/sn state machine over again */ | |
870 | scic_sds_phy_restart_starting_state(sci_phy); | |
871 | break; | |
872 | ||
873 | default: | |
874 | dev_warn(sciphy_to_dev(sci_phy), | |
875 | "%s: PHY starting substate machine received " | |
876 | "unexpected event_code %x\n", | |
877 | __func__, | |
878 | event_code); | |
879 | ||
880 | result = SCI_FAILURE; | |
881 | break; | |
882 | } | |
883 | ||
884 | return result; | |
885 | } | |
886 | ||
887 | /** | |
888 | * | |
889 | * @phy: This struct scic_sds_phy object which has received an event. | |
890 | * @event_code: This is the event code which the phy object is to decode. | |
891 | * | |
892 | * This method is called when an event notification is received for the phy | |
893 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. - | |
894 | * decode the event - link failure events restart the starting state machine - | |
895 | * any other events log a warning message and set a failure status enum sci_status | |
896 | * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event | |
897 | * notifation | |
898 | */ | |
899 | static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler( | |
900 | struct scic_sds_phy *sci_phy, | |
901 | u32 event_code) | |
902 | { | |
903 | u32 result = SCI_SUCCESS; | |
904 | ||
905 | switch (scu_get_event_code(event_code)) { | |
906 | case SCU_EVENT_LINK_FAILURE: | |
907 | /* Link failure change state back to the starting state */ | |
908 | scic_sds_phy_restart_starting_state(sci_phy); | |
909 | break; | |
910 | ||
911 | default: | |
912 | dev_warn(sciphy_to_dev(sci_phy), | |
913 | "%s: PHY starting substate machine received unexpected " | |
914 | "event_code %x\n", | |
915 | __func__, | |
916 | event_code); | |
917 | ||
918 | result = SCI_FAILURE; | |
919 | break; | |
920 | } | |
921 | ||
922 | return result; | |
923 | } | |
924 | ||
925 | /** | |
926 | * | |
927 | * @phy: This struct scic_sds_phy object which has received an event. | |
928 | * @event_code: This is the event code which the phy object is to decode. | |
929 | * | |
930 | * This method is called when an event notification is received for the phy | |
931 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - | |
932 | * decode the event - link failure events restart the starting state machine - | |
933 | * sata spinup hold events are ignored since they are expected - any other | |
934 | * events log a warning message and set a failure status enum sci_status SCI_SUCCESS | |
935 | * on a link failure event SCI_FAILURE on any unexpected event notifation | |
936 | */ | |
937 | static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler( | |
938 | struct scic_sds_phy *sci_phy, | |
939 | u32 event_code) | |
940 | { | |
941 | u32 result = SCI_SUCCESS; | |
942 | ||
943 | switch (scu_get_event_code(event_code)) { | |
944 | case SCU_EVENT_LINK_FAILURE: | |
945 | /* Link failure change state back to the starting state */ | |
946 | scic_sds_phy_restart_starting_state(sci_phy); | |
947 | break; | |
948 | ||
949 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
950 | /* These events are received every 10ms and are expected while in this state */ | |
951 | break; | |
952 | ||
953 | case SCU_EVENT_SAS_PHY_DETECTED: | |
954 | /* | |
955 | * There has been a change in the phy type before OOB/SN for the | |
956 | * SATA finished start down the SAS link traning path. */ | |
957 | scic_sds_phy_start_sas_link_training(sci_phy); | |
958 | break; | |
959 | ||
960 | default: | |
961 | dev_warn(sciphy_to_dev(sci_phy), | |
962 | "%s: PHY starting substate machine received " | |
963 | "unexpected event_code %x\n", | |
964 | __func__, | |
965 | event_code); | |
966 | ||
967 | result = SCI_FAILURE; | |
968 | break; | |
969 | } | |
970 | ||
971 | return result; | |
972 | } | |
973 | ||
974 | /** | |
975 | * scic_sds_phy_starting_substate_await_sata_phy_event_handler - | |
976 | * @phy: This struct scic_sds_phy object which has received an event. | |
977 | * @event_code: This is the event code which the phy object is to decode. | |
978 | * | |
979 | * This method is called when an event notification is received for the phy | |
980 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - | |
981 | * decode the event - link failure events restart the starting state machine - | |
982 | * sata spinup hold events are ignored since they are expected - sata phy | |
983 | * detected event change to the wait speed event - any other events log a | |
984 | * warning message and set a failure status enum sci_status SCI_SUCCESS on a link | |
985 | * failure event SCI_FAILURE on any unexpected event notifation | |
986 | */ | |
987 | static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler( | |
988 | struct scic_sds_phy *sci_phy, u32 event_code) | |
989 | { | |
990 | u32 result = SCI_SUCCESS; | |
991 | ||
992 | switch (scu_get_event_code(event_code)) { | |
993 | case SCU_EVENT_LINK_FAILURE: | |
994 | /* Link failure change state back to the starting state */ | |
995 | scic_sds_phy_restart_starting_state(sci_phy); | |
996 | break; | |
997 | ||
998 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
999 | /* These events might be received since we dont know how many may be in | |
1000 | * the completion queue while waiting for power | |
1001 | */ | |
1002 | break; | |
1003 | ||
1004 | case SCU_EVENT_SATA_PHY_DETECTED: | |
1005 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA; | |
1006 | ||
1007 | /* We have received the SATA PHY notification change state */ | |
4a33c525 | 1008 | sci_base_state_machine_change_state(&sci_phy->state_machine, |
d35bc1bd DW |
1009 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN); |
1010 | break; | |
1011 | ||
1012 | case SCU_EVENT_SAS_PHY_DETECTED: | |
1013 | /* There has been a change in the phy type before OOB/SN for the | |
1014 | * SATA finished start down the SAS link traning path. | |
1015 | */ | |
1016 | scic_sds_phy_start_sas_link_training(sci_phy); | |
1017 | break; | |
1018 | ||
1019 | default: | |
1020 | dev_warn(sciphy_to_dev(sci_phy), | |
1021 | "%s: PHY starting substate machine received " | |
1022 | "unexpected event_code %x\n", | |
1023 | __func__, | |
1024 | event_code); | |
1025 | ||
1026 | result = SCI_FAILURE; | |
1027 | break; | |
1028 | } | |
1029 | ||
1030 | return result; | |
1031 | } | |
1032 | ||
1033 | /** | |
1034 | * | |
1035 | * @phy: This struct scic_sds_phy object which has received an event. | |
1036 | * @event_code: This is the event code which the phy object is to decode. | |
1037 | * | |
1038 | * This method is called when an event notification is received for the phy | |
1039 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. | |
1040 | * - decode the event - sata phy detected returns us back to this state. - | |
1041 | * speed event detected causes a state transition to the wait for signature. - | |
1042 | * link failure events restart the starting state machine - any other events | |
1043 | * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any | |
1044 | * valid event notification SCI_FAILURE on any unexpected event notifation | |
1045 | */ | |
1046 | static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler( | |
1047 | struct scic_sds_phy *sci_phy, | |
1048 | u32 event_code) | |
1049 | { | |
1050 | u32 result = SCI_SUCCESS; | |
1051 | ||
1052 | switch (scu_get_event_code(event_code)) { | |
1053 | case SCU_EVENT_SATA_PHY_DETECTED: | |
1054 | /* | |
1055 | * The hardware reports multiple SATA PHY detected events | |
1056 | * ignore the extras */ | |
1057 | break; | |
1058 | ||
1059 | case SCU_EVENT_SATA_15: | |
1060 | case SCU_EVENT_SATA_15_SSC: | |
1061 | scic_sds_phy_complete_link_training( | |
1062 | sci_phy, | |
1063 | SAS_LINK_RATE_1_5_GBPS, | |
1064 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF); | |
1065 | break; | |
1066 | ||
1067 | case SCU_EVENT_SATA_30: | |
1068 | case SCU_EVENT_SATA_30_SSC: | |
1069 | scic_sds_phy_complete_link_training( | |
1070 | sci_phy, | |
1071 | SAS_LINK_RATE_3_0_GBPS, | |
1072 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF); | |
1073 | break; | |
1074 | ||
1075 | case SCU_EVENT_SATA_60: | |
1076 | case SCU_EVENT_SATA_60_SSC: | |
1077 | scic_sds_phy_complete_link_training( | |
1078 | sci_phy, | |
1079 | SAS_LINK_RATE_6_0_GBPS, | |
1080 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF); | |
1081 | break; | |
1082 | ||
1083 | case SCU_EVENT_LINK_FAILURE: | |
1084 | /* Link failure change state back to the starting state */ | |
1085 | scic_sds_phy_restart_starting_state(sci_phy); | |
1086 | break; | |
1087 | ||
1088 | case SCU_EVENT_SAS_PHY_DETECTED: | |
1089 | /* | |
1090 | * There has been a change in the phy type before OOB/SN for the | |
1091 | * SATA finished start down the SAS link traning path. */ | |
1092 | scic_sds_phy_start_sas_link_training(sci_phy); | |
1093 | break; | |
1094 | ||
1095 | default: | |
1096 | dev_warn(sciphy_to_dev(sci_phy), | |
1097 | "%s: PHY starting substate machine received " | |
1098 | "unexpected event_code %x\n", | |
1099 | __func__, | |
1100 | event_code); | |
1101 | ||
1102 | result = SCI_FAILURE; | |
1103 | break; | |
1104 | } | |
1105 | ||
1106 | return result; | |
1107 | } | |
1108 | ||
1109 | /** | |
1110 | * scic_sds_phy_starting_substate_await_sig_fis_event_handler - | |
1111 | * @phy: This struct scic_sds_phy object which has received an event. | |
1112 | * @event_code: This is the event code which the phy object is to decode. | |
1113 | * | |
1114 | * This method is called when an event notification is received for the phy | |
1115 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - | |
1116 | * decode the event - sas phy detected event backs up the state machine to the | |
1117 | * await speed notification. - identify timeout is an un-expected event and the | |
1118 | * state machine is restarted. - link failure events restart the starting state | |
1119 | * machine - any other events log a warning message and set a failure status | |
1120 | * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any | |
1121 | * unexpected event notifation | |
1122 | */ | |
1123 | static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler( | |
1124 | struct scic_sds_phy *sci_phy, u32 event_code) | |
1125 | { | |
1126 | u32 result = SCI_SUCCESS; | |
1127 | ||
1128 | switch (scu_get_event_code(event_code)) { | |
1129 | case SCU_EVENT_SATA_PHY_DETECTED: | |
1130 | /* Backup the state machine */ | |
4a33c525 | 1131 | sci_base_state_machine_change_state(&sci_phy->state_machine, |
d35bc1bd DW |
1132 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN); |
1133 | break; | |
1134 | ||
1135 | case SCU_EVENT_LINK_FAILURE: | |
1136 | /* Link failure change state back to the starting state */ | |
1137 | scic_sds_phy_restart_starting_state(sci_phy); | |
1138 | break; | |
1139 | ||
1140 | default: | |
1141 | dev_warn(sciphy_to_dev(sci_phy), | |
1142 | "%s: PHY starting substate machine received " | |
1143 | "unexpected event_code %x\n", | |
1144 | __func__, | |
1145 | event_code); | |
1146 | ||
1147 | result = SCI_FAILURE; | |
1148 | break; | |
1149 | } | |
1150 | ||
1151 | return result; | |
1152 | } | |
1153 | ||
d35bc1bd DW |
1154 | /* |
1155 | * This method is called by the struct scic_sds_controller when the phy object is | |
1156 | * granted power. - The notify enable spinups are turned on for this phy object | |
1157 | * - The phy state machine is transitioned to the | |
1158 | * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS | |
1159 | */ | |
1160 | static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler( | |
1161 | struct scic_sds_phy *sci_phy) | |
1162 | { | |
1163 | u32 enable_spinup; | |
1164 | ||
1165 | enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control); | |
1166 | enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE); | |
1167 | writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control); | |
1168 | ||
1169 | /* Change state to the final state this substate machine has run to completion */ | |
4a33c525 | 1170 | sci_base_state_machine_change_state(&sci_phy->state_machine, |
d35bc1bd DW |
1171 | SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL); |
1172 | ||
1173 | return SCI_SUCCESS; | |
1174 | } | |
1175 | ||
1176 | /* | |
1177 | * This method is called by the struct scic_sds_controller when the phy object is | |
1178 | * granted power. - The phy state machine is transitioned to the | |
1179 | * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS | |
1180 | */ | |
1181 | static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler( | |
1182 | struct scic_sds_phy *sci_phy) | |
1183 | { | |
1184 | u32 scu_sas_pcfg_value; | |
1185 | ||
1186 | /* Release the spinup hold state and reset the OOB state machine */ | |
1187 | scu_sas_pcfg_value = | |
1188 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
1189 | scu_sas_pcfg_value &= | |
1190 | ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE)); | |
1191 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET); | |
1192 | writel(scu_sas_pcfg_value, | |
1193 | &sci_phy->link_layer_registers->phy_configuration); | |
1194 | ||
1195 | /* Now restart the OOB operation */ | |
1196 | scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET); | |
1197 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); | |
1198 | writel(scu_sas_pcfg_value, | |
1199 | &sci_phy->link_layer_registers->phy_configuration); | |
1200 | ||
1201 | /* Change state to the final state this substate machine has run to completion */ | |
4a33c525 | 1202 | sci_base_state_machine_change_state(&sci_phy->state_machine, |
d35bc1bd DW |
1203 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN); |
1204 | ||
1205 | return SCI_SUCCESS; | |
1206 | } | |
1207 | ||
1208 | static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy, | |
1209 | const char *func) | |
1210 | { | |
1211 | dev_dbg(sciphy_to_dev(sci_phy), | |
1212 | "%s: in wrong state: %d\n", func, | |
1213 | sci_base_state_machine_get_state(&sci_phy->state_machine)); | |
1214 | return SCI_FAILURE_INVALID_STATE; | |
1215 | } | |
1216 | ||
d35bc1bd DW |
1217 | static enum sci_status |
1218 | scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy, | |
1219 | u32 event_code) | |
1220 | { | |
1221 | return default_phy_handler(sci_phy, __func__); | |
1222 | } | |
1223 | ||
1224 | static enum sci_status | |
1225 | scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy) | |
1226 | { | |
1227 | return default_phy_handler(sci_phy, __func__); | |
1228 | } | |
1229 | ||
4a33c525 AG |
1230 | /** |
1231 | * scic_sds_phy_ready_state_event_handler - | |
1232 | * @phy: This is the struct scic_sds_phy object which has received the event. | |
1233 | * | |
1234 | * This method request the struct scic_sds_phy handle the received event. The only | |
1235 | * event that we are interested in while in the ready state is the link failure | |
1236 | * event. - decoded event is a link failure - transition the struct scic_sds_phy back | |
1237 | * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will | |
1238 | * report a warning message enum sci_status SCI_SUCCESS if the event received is a | |
1239 | * link failure SCI_FAILURE_INVALID_STATE for any other event received. | |
1240 | */ | |
1241 | static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy, | |
1242 | u32 event_code) | |
1243 | { | |
1244 | enum sci_status result = SCI_FAILURE; | |
1245 | ||
1246 | switch (scu_get_event_code(event_code)) { | |
1247 | case SCU_EVENT_LINK_FAILURE: | |
1248 | /* Link failure change state back to the starting state */ | |
1249 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1250 | SCI_BASE_PHY_STATE_STARTING); | |
1251 | result = SCI_SUCCESS; | |
1252 | break; | |
1253 | ||
1254 | case SCU_EVENT_BROADCAST_CHANGE: | |
1255 | /* Broadcast change received. Notify the port. */ | |
1256 | if (scic_sds_phy_get_port(sci_phy) != NULL) | |
1257 | scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy); | |
1258 | else | |
1259 | sci_phy->bcn_received_while_port_unassigned = true; | |
1260 | break; | |
1261 | ||
1262 | default: | |
1263 | dev_warn(sciphy_to_dev(sci_phy), | |
1264 | "%sP SCIC PHY 0x%p ready state machine received " | |
1265 | "unexpected event_code %x\n", | |
1266 | __func__, sci_phy, event_code); | |
1267 | ||
1268 | result = SCI_FAILURE_INVALID_STATE; | |
1269 | break; | |
1270 | } | |
1271 | ||
1272 | return result; | |
1273 | } | |
1274 | ||
1275 | static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy, | |
1276 | u32 event_code) | |
1277 | { | |
1278 | enum sci_status result = SCI_FAILURE; | |
1279 | ||
1280 | switch (scu_get_event_code(event_code)) { | |
1281 | case SCU_EVENT_HARD_RESET_TRANSMITTED: | |
1282 | /* Link failure change state back to the starting state */ | |
1283 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1284 | SCI_BASE_PHY_STATE_STARTING); | |
1285 | result = SCI_SUCCESS; | |
1286 | break; | |
1287 | ||
1288 | default: | |
1289 | dev_warn(sciphy_to_dev(sci_phy), | |
1290 | "%s: SCIC PHY 0x%p resetting state machine received " | |
1291 | "unexpected event_code %x\n", | |
1292 | __func__, sci_phy, event_code); | |
1293 | ||
1294 | result = SCI_FAILURE_INVALID_STATE; | |
1295 | break; | |
1296 | } | |
1297 | ||
1298 | return result; | |
1299 | } | |
1300 | ||
1301 | /* --------------------------------------------------------------------------- */ | |
1302 | ||
1303 | static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = { | |
1304 | [SCI_BASE_PHY_STATE_INITIAL] = { | |
4a33c525 AG |
1305 | .event_handler = scic_sds_phy_default_event_handler, |
1306 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1307 | }, | |
1308 | [SCI_BASE_PHY_STATE_STOPPED] = { | |
4a33c525 AG |
1309 | .event_handler = scic_sds_phy_default_event_handler, |
1310 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1311 | }, | |
1312 | [SCI_BASE_PHY_STATE_STARTING] = { | |
4a33c525 AG |
1313 | .event_handler = scic_sds_phy_default_event_handler, |
1314 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1315 | }, | |
d35bc1bd | 1316 | [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = { |
d35bc1bd DW |
1317 | .event_handler = scic_sds_phy_default_event_handler, |
1318 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1319 | }, | |
1320 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = { | |
d35bc1bd DW |
1321 | .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler, |
1322 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1323 | }, | |
1324 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = { | |
d35bc1bd DW |
1325 | .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler, |
1326 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1327 | }, | |
1328 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = { | |
d35bc1bd DW |
1329 | .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler, |
1330 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1331 | }, | |
1332 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = { | |
d35bc1bd DW |
1333 | .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler, |
1334 | .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler | |
1335 | }, | |
1336 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = { | |
d35bc1bd DW |
1337 | .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler, |
1338 | .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler | |
1339 | }, | |
1340 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = { | |
d35bc1bd DW |
1341 | .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler, |
1342 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1343 | }, | |
1344 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = { | |
d35bc1bd DW |
1345 | .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler, |
1346 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1347 | }, | |
1348 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = { | |
d35bc1bd DW |
1349 | .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler, |
1350 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1351 | }, | |
1352 | [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = { | |
d35bc1bd DW |
1353 | .event_handler = scic_sds_phy_default_event_handler, |
1354 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
4a33c525 AG |
1355 | }, |
1356 | [SCI_BASE_PHY_STATE_READY] = { | |
4a33c525 AG |
1357 | .event_handler = scic_sds_phy_ready_state_event_handler, |
1358 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1359 | }, | |
1360 | [SCI_BASE_PHY_STATE_RESETTING] = { | |
4a33c525 AG |
1361 | .event_handler = scic_sds_phy_resetting_state_event_handler, |
1362 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1363 | }, | |
1364 | [SCI_BASE_PHY_STATE_FINAL] = { | |
4a33c525 AG |
1365 | .event_handler = scic_sds_phy_default_event_handler, |
1366 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
d35bc1bd DW |
1367 | } |
1368 | }; | |
1369 | ||
d35bc1bd DW |
1370 | /* |
1371 | * **************************************************************************** | |
1372 | * * PHY STARTING SUBSTATE METHODS | |
1373 | * **************************************************************************** */ | |
1374 | ||
1375 | /** | |
1376 | * scic_sds_phy_starting_initial_substate_enter - | |
1377 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1378 | * | |
1379 | * This method will perform the actions required by the struct scic_sds_phy on | |
1380 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state | |
1381 | * handlers are put in place for the struct scic_sds_phy object. - The state is | |
1382 | * changed to the wait phy type event notification. none | |
1383 | */ | |
1384 | static void scic_sds_phy_starting_initial_substate_enter(void *object) | |
1385 | { | |
1386 | struct scic_sds_phy *sci_phy = object; | |
1387 | ||
4a33c525 | 1388 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1389 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL); |
1390 | ||
1391 | /* This is just an temporary state go off to the starting state */ | |
4a33c525 | 1392 | sci_base_state_machine_change_state(&sci_phy->state_machine, |
d35bc1bd DW |
1393 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN); |
1394 | } | |
1395 | ||
1396 | /** | |
1397 | * | |
1398 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1399 | * | |
1400 | * This method will perform the actions required by the struct scic_sds_phy on | |
1401 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the | |
1402 | * struct scic_sds_phy object state handlers for this state. none | |
1403 | */ | |
1404 | static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object) | |
1405 | { | |
1406 | struct scic_sds_phy *sci_phy = object; | |
1407 | ||
4a33c525 | 1408 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1409 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN |
1410 | ); | |
1411 | } | |
1412 | ||
1413 | /** | |
1414 | * | |
1415 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1416 | * | |
1417 | * This method will perform the actions required by the struct scic_sds_phy on | |
1418 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the | |
1419 | * struct scic_sds_phy object state handlers for this state. none | |
1420 | */ | |
1421 | static void scic_sds_phy_starting_await_sas_speed_en_substate_enter( | |
1422 | void *object) | |
1423 | { | |
1424 | struct scic_sds_phy *sci_phy = object; | |
1425 | ||
4a33c525 | 1426 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1427 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN |
1428 | ); | |
1429 | } | |
1430 | ||
1431 | /** | |
1432 | * | |
1433 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1434 | * | |
1435 | * This method will perform the actions required by the struct scic_sds_phy on | |
1436 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the | |
1437 | * struct scic_sds_phy object state handlers for this state. none | |
1438 | */ | |
1439 | static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object) | |
1440 | { | |
1441 | struct scic_sds_phy *sci_phy = object; | |
1442 | ||
4a33c525 | 1443 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1444 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF |
1445 | ); | |
1446 | } | |
1447 | ||
1448 | /** | |
1449 | * | |
1450 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1451 | * | |
1452 | * This method will perform the actions required by the struct scic_sds_phy on | |
1453 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the | |
1454 | * struct scic_sds_phy object state handlers for this state. - Add this phy object to | |
1455 | * the power control queue none | |
1456 | */ | |
1457 | static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object) | |
1458 | { | |
1459 | struct scic_sds_phy *sci_phy = object; | |
1460 | ||
4a33c525 | 1461 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1462 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER |
1463 | ); | |
1464 | ||
1465 | scic_sds_controller_power_control_queue_insert( | |
1466 | scic_sds_phy_get_controller(sci_phy), | |
1467 | sci_phy | |
1468 | ); | |
1469 | } | |
1470 | ||
1471 | /** | |
1472 | * | |
1473 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1474 | * | |
1475 | * This method will perform the actions required by the struct scic_sds_phy on exiting | |
1476 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the | |
1477 | * struct scic_sds_phy object from the power control queue. none | |
1478 | */ | |
1479 | static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object) | |
1480 | { | |
1481 | struct scic_sds_phy *sci_phy = object; | |
1482 | ||
1483 | scic_sds_controller_power_control_queue_remove( | |
1484 | scic_sds_phy_get_controller(sci_phy), sci_phy | |
1485 | ); | |
1486 | } | |
1487 | ||
1488 | /** | |
1489 | * | |
1490 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1491 | * | |
1492 | * This method will perform the actions required by the struct scic_sds_phy on | |
1493 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the | |
1494 | * struct scic_sds_phy object state handlers for this state. - Add this phy object to | |
1495 | * the power control queue none | |
1496 | */ | |
1497 | static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object) | |
1498 | { | |
1499 | struct scic_sds_phy *sci_phy = object; | |
1500 | ||
4a33c525 | 1501 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1502 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER |
1503 | ); | |
1504 | ||
1505 | scic_sds_controller_power_control_queue_insert( | |
1506 | scic_sds_phy_get_controller(sci_phy), | |
1507 | sci_phy | |
1508 | ); | |
1509 | } | |
1510 | ||
1511 | /** | |
1512 | * | |
1513 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1514 | * | |
1515 | * This method will perform the actions required by the struct scic_sds_phy on exiting | |
1516 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the | |
1517 | * struct scic_sds_phy object from the power control queue. none | |
1518 | */ | |
1519 | static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object) | |
1520 | { | |
1521 | struct scic_sds_phy *sci_phy = object; | |
1522 | ||
1523 | scic_sds_controller_power_control_queue_remove( | |
1524 | scic_sds_phy_get_controller(sci_phy), | |
1525 | sci_phy | |
1526 | ); | |
1527 | } | |
1528 | ||
1529 | /** | |
1530 | * | |
1531 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1532 | * | |
1533 | * This function will perform the actions required by the struct scic_sds_phy on | |
1534 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the | |
1535 | * struct scic_sds_phy object state handlers for this state. none | |
1536 | */ | |
1537 | static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object) | |
1538 | { | |
1539 | struct scic_sds_phy *sci_phy = object; | |
1540 | ||
4a33c525 | 1541 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1542 | sci_phy, |
1543 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN); | |
1544 | ||
1545 | isci_timer_start(sci_phy->sata_timeout_timer, | |
1546 | SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT); | |
1547 | } | |
1548 | ||
1549 | /** | |
1550 | * | |
1551 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1552 | * | |
1553 | * This method will perform the actions required by the struct scic_sds_phy | |
1554 | * on exiting | |
1555 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer | |
1556 | * that was started on entry to await sata phy event notification none | |
1557 | */ | |
1558 | static inline void scic_sds_phy_starting_await_sata_phy_substate_exit( | |
1559 | void *object) | |
1560 | { | |
1561 | struct scic_sds_phy *sci_phy = object; | |
1562 | ||
1563 | isci_timer_stop(sci_phy->sata_timeout_timer); | |
1564 | } | |
1565 | ||
1566 | /** | |
1567 | * | |
1568 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1569 | * | |
1570 | * This method will perform the actions required by the struct scic_sds_phy on | |
1571 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the | |
1572 | * struct scic_sds_phy object state handlers for this state. none | |
1573 | */ | |
1574 | static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object) | |
1575 | { | |
1576 | struct scic_sds_phy *sci_phy = object; | |
1577 | ||
4a33c525 | 1578 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1579 | sci_phy, |
1580 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN); | |
1581 | ||
1582 | isci_timer_start(sci_phy->sata_timeout_timer, | |
1583 | SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT); | |
1584 | } | |
1585 | ||
1586 | /** | |
1587 | * | |
1588 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1589 | * | |
1590 | * This function will perform the actions required by the | |
1591 | * struct scic_sds_phy on exiting | |
1592 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer | |
1593 | * that was started on entry to await sata phy event notification none | |
1594 | */ | |
1595 | static inline void scic_sds_phy_starting_await_sata_speed_substate_exit( | |
1596 | void *object) | |
1597 | { | |
1598 | struct scic_sds_phy *sci_phy = object; | |
1599 | ||
1600 | isci_timer_stop(sci_phy->sata_timeout_timer); | |
1601 | } | |
1602 | ||
1603 | /** | |
1604 | * | |
1605 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1606 | * | |
1607 | * This function will perform the actions required by the struct scic_sds_phy on | |
1608 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the | |
1609 | * struct scic_sds_phy object state handlers for this state. | |
1610 | * - Start the SIGNATURE FIS | |
1611 | * timeout timer none | |
1612 | */ | |
1613 | static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object) | |
1614 | { | |
1615 | bool continue_to_ready_state; | |
1616 | struct scic_sds_phy *sci_phy = object; | |
1617 | ||
4a33c525 | 1618 | scic_sds_phy_set_base_state_handlers( |
d35bc1bd DW |
1619 | sci_phy, |
1620 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF); | |
1621 | ||
1622 | continue_to_ready_state = scic_sds_port_link_detected( | |
1623 | sci_phy->owning_port, | |
1624 | sci_phy); | |
1625 | ||
1626 | if (continue_to_ready_state) { | |
1627 | /* | |
1628 | * Clear the PE suspend condition so we can actually | |
1629 | * receive SIG FIS | |
1630 | * The hardware will not respond to the XRDY until the PE | |
1631 | * suspend condition is cleared. | |
1632 | */ | |
1633 | scic_sds_phy_resume(sci_phy); | |
1634 | ||
1635 | isci_timer_start(sci_phy->sata_timeout_timer, | |
1636 | SCIC_SDS_SIGNATURE_FIS_TIMEOUT); | |
1637 | } else | |
1638 | sci_phy->is_in_link_training = false; | |
1639 | } | |
1640 | ||
1641 | /** | |
1642 | * | |
1643 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1644 | * | |
1645 | * This function will perform the actions required by the | |
1646 | * struct scic_sds_phy on exiting | |
1647 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE | |
1648 | * FIS timeout timer. none | |
1649 | */ | |
1650 | static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit( | |
1651 | void *object) | |
1652 | { | |
1653 | struct scic_sds_phy *sci_phy = object; | |
1654 | ||
1655 | isci_timer_stop(sci_phy->sata_timeout_timer); | |
1656 | } | |
1657 | ||
1658 | /** | |
1659 | * | |
1660 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1661 | * | |
1662 | * This method will perform the actions required by the struct scic_sds_phy on | |
1663 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy | |
1664 | * object state handlers for this state. - Change base state machine to the | |
1665 | * ready state. none | |
1666 | */ | |
1667 | static void scic_sds_phy_starting_final_substate_enter(void *object) | |
1668 | { | |
1669 | struct scic_sds_phy *sci_phy = object; | |
1670 | ||
4a33c525 | 1671 | scic_sds_phy_set_base_state_handlers(sci_phy, |
d35bc1bd DW |
1672 | SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL); |
1673 | ||
1674 | /* State machine has run to completion so exit out and change | |
1675 | * the base state machine to the ready state | |
1676 | */ | |
1677 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1678 | SCI_BASE_PHY_STATE_READY); | |
1679 | } | |
1680 | ||
d35bc1bd DW |
1681 | /* |
1682 | * **************************************************************************** | |
1683 | * * PHY STATE PRIVATE METHODS | |
1684 | * **************************************************************************** */ | |
1685 | ||
1686 | /** | |
1687 | * | |
1688 | * @sci_phy: This is the struct scic_sds_phy object to stop. | |
1689 | * | |
1690 | * This method will stop the struct scic_sds_phy object. This does not reset the | |
1691 | * protocol engine it just suspends it and places it in a state where it will | |
1692 | * not cause the end device to power up. none | |
1693 | */ | |
1694 | static void scu_link_layer_stop_protocol_engine( | |
1695 | struct scic_sds_phy *sci_phy) | |
1696 | { | |
1697 | u32 scu_sas_pcfg_value; | |
1698 | u32 enable_spinup_value; | |
1699 | ||
1700 | /* Suspend the protocol engine and place it in a sata spinup hold state */ | |
1701 | scu_sas_pcfg_value = | |
1702 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
1703 | scu_sas_pcfg_value |= | |
1704 | (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) | | |
1705 | SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) | | |
1706 | SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD)); | |
1707 | writel(scu_sas_pcfg_value, | |
1708 | &sci_phy->link_layer_registers->phy_configuration); | |
1709 | ||
1710 | /* Disable the notify enable spinup primitives */ | |
1711 | enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control); | |
1712 | enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE); | |
1713 | writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control); | |
1714 | } | |
1715 | ||
1716 | /** | |
1717 | * | |
1718 | * | |
1719 | * This method will start the OOB/SN state machine for this struct scic_sds_phy object. | |
1720 | */ | |
1721 | static void scu_link_layer_start_oob( | |
1722 | struct scic_sds_phy *sci_phy) | |
1723 | { | |
1724 | u32 scu_sas_pcfg_value; | |
1725 | ||
1726 | scu_sas_pcfg_value = | |
1727 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
1728 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); | |
1729 | scu_sas_pcfg_value &= | |
1730 | ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) | | |
1731 | SCU_SAS_PCFG_GEN_BIT(HARD_RESET)); | |
1732 | writel(scu_sas_pcfg_value, | |
1733 | &sci_phy->link_layer_registers->phy_configuration); | |
1734 | } | |
1735 | ||
1736 | /** | |
1737 | * | |
1738 | * | |
1739 | * This method will transmit a hard reset request on the specified phy. The SCU | |
1740 | * hardware requires that we reset the OOB state machine and set the hard reset | |
1741 | * bit in the phy configuration register. We then must start OOB over with the | |
1742 | * hard reset bit set. | |
1743 | */ | |
1744 | static void scu_link_layer_tx_hard_reset( | |
1745 | struct scic_sds_phy *sci_phy) | |
1746 | { | |
1747 | u32 phy_configuration_value; | |
1748 | ||
1749 | /* | |
1750 | * SAS Phys must wait for the HARD_RESET_TX event notification to transition | |
1751 | * to the starting state. */ | |
1752 | phy_configuration_value = | |
1753 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
1754 | phy_configuration_value |= | |
1755 | (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) | | |
1756 | SCU_SAS_PCFG_GEN_BIT(OOB_RESET)); | |
1757 | writel(phy_configuration_value, | |
1758 | &sci_phy->link_layer_registers->phy_configuration); | |
1759 | ||
1760 | /* Now take the OOB state machine out of reset */ | |
1761 | phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); | |
1762 | phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET); | |
1763 | writel(phy_configuration_value, | |
1764 | &sci_phy->link_layer_registers->phy_configuration); | |
1765 | } | |
1766 | ||
1767 | /* | |
1768 | * **************************************************************************** | |
1769 | * * PHY BASE STATE METHODS | |
1770 | * **************************************************************************** */ | |
1771 | ||
1772 | /** | |
1773 | * | |
1774 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1775 | * | |
1776 | * This method will perform the actions required by the struct scic_sds_phy on | |
1777 | * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state | |
1778 | * handlers for the phy object base state machine initial state. none | |
1779 | */ | |
1780 | static void scic_sds_phy_initial_state_enter(void *object) | |
1781 | { | |
1782 | struct scic_sds_phy *sci_phy = object; | |
1783 | ||
1784 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL); | |
1785 | } | |
1786 | ||
1787 | /** | |
1788 | * | |
1789 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1790 | * | |
1791 | * This function will perform the actions required by the struct scic_sds_phy on | |
1792 | * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state | |
1793 | * handlers for the phy object base state machine initial state. - The SCU | |
1794 | * hardware is requested to stop the protocol engine. none | |
1795 | */ | |
1796 | static void scic_sds_phy_stopped_state_enter(void *object) | |
1797 | { | |
1798 | struct scic_sds_phy *sci_phy = object; | |
1799 | struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy); | |
1800 | struct isci_host *ihost = scic_to_ihost(scic); | |
1801 | ||
1802 | /* | |
1803 | * @todo We need to get to the controller to place this PE in a | |
1804 | * reset state | |
1805 | */ | |
1806 | ||
1807 | scic_sds_phy_set_base_state_handlers(sci_phy, | |
1808 | SCI_BASE_PHY_STATE_STOPPED); | |
1809 | ||
1810 | if (sci_phy->sata_timeout_timer != NULL) { | |
1811 | isci_del_timer(ihost, sci_phy->sata_timeout_timer); | |
1812 | ||
1813 | sci_phy->sata_timeout_timer = NULL; | |
1814 | } | |
1815 | ||
1816 | scu_link_layer_stop_protocol_engine(sci_phy); | |
1817 | ||
1818 | if (sci_phy->state_machine.previous_state_id != | |
1819 | SCI_BASE_PHY_STATE_INITIAL) | |
1820 | scic_sds_controller_link_down( | |
1821 | scic_sds_phy_get_controller(sci_phy), | |
1822 | scic_sds_phy_get_port(sci_phy), | |
1823 | sci_phy); | |
1824 | } | |
1825 | ||
1826 | /** | |
1827 | * | |
1828 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1829 | * | |
1830 | * This method will perform the actions required by the struct scic_sds_phy on | |
1831 | * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state | |
1832 | * handlers for the phy object base state machine starting state. - The SCU | |
1833 | * hardware is requested to start OOB/SN on this protocl engine. - The phy | |
1834 | * starting substate machine is started. - If the previous state was the ready | |
1835 | * state then the struct scic_sds_controller is informed that the phy has gone link | |
1836 | * down. none | |
1837 | */ | |
1838 | static void scic_sds_phy_starting_state_enter(void *object) | |
1839 | { | |
1840 | struct scic_sds_phy *sci_phy = object; | |
1841 | ||
1842 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING); | |
1843 | ||
1844 | scu_link_layer_stop_protocol_engine(sci_phy); | |
1845 | scu_link_layer_start_oob(sci_phy); | |
1846 | ||
1847 | /* We don't know what kind of phy we are going to be just yet */ | |
1848 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN; | |
1849 | sci_phy->bcn_received_while_port_unassigned = false; | |
1850 | ||
d35bc1bd DW |
1851 | if (sci_phy->state_machine.previous_state_id |
1852 | == SCI_BASE_PHY_STATE_READY) { | |
1853 | scic_sds_controller_link_down( | |
1854 | scic_sds_phy_get_controller(sci_phy), | |
1855 | scic_sds_phy_get_port(sci_phy), | |
1856 | sci_phy | |
1857 | ); | |
1858 | } | |
4a33c525 AG |
1859 | |
1860 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1861 | SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL); | |
d35bc1bd DW |
1862 | } |
1863 | ||
1864 | /** | |
1865 | * | |
1866 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1867 | * | |
1868 | * This method will perform the actions required by the struct scic_sds_phy on | |
1869 | * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state | |
1870 | * handlers for the phy object base state machine ready state. - The SCU | |
1871 | * hardware protocol engine is resumed. - The struct scic_sds_controller is informed | |
1872 | * that the phy object has gone link up. none | |
1873 | */ | |
1874 | static void scic_sds_phy_ready_state_enter(void *object) | |
1875 | { | |
1876 | struct scic_sds_phy *sci_phy = object; | |
1877 | ||
1878 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY); | |
1879 | ||
1880 | scic_sds_controller_link_up( | |
1881 | scic_sds_phy_get_controller(sci_phy), | |
1882 | scic_sds_phy_get_port(sci_phy), | |
1883 | sci_phy | |
1884 | ); | |
1885 | } | |
1886 | ||
1887 | /** | |
1888 | * | |
1889 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1890 | * | |
1891 | * This method will perform the actions required by the struct scic_sds_phy on exiting | |
1892 | * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware | |
1893 | * protocol engine represented by this struct scic_sds_phy object. none | |
1894 | */ | |
1895 | static void scic_sds_phy_ready_state_exit(void *object) | |
1896 | { | |
1897 | struct scic_sds_phy *sci_phy = object; | |
1898 | ||
1899 | scic_sds_phy_suspend(sci_phy); | |
1900 | } | |
1901 | ||
1902 | /** | |
1903 | * | |
1904 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1905 | * | |
1906 | * This method will perform the actions required by the struct scic_sds_phy on | |
1907 | * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state | |
1908 | * handlers for the phy object base state machine resetting state. none | |
1909 | */ | |
1910 | static void scic_sds_phy_resetting_state_enter(void *object) | |
1911 | { | |
1912 | struct scic_sds_phy *sci_phy = object; | |
1913 | ||
1914 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING); | |
1915 | ||
1916 | /* | |
1917 | * The phy is being reset, therefore deactivate it from the port. | |
1918 | * In the resetting state we don't notify the user regarding | |
1919 | * link up and link down notifications. */ | |
1920 | scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false); | |
1921 | ||
1922 | if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { | |
1923 | scu_link_layer_tx_hard_reset(sci_phy); | |
1924 | } else { | |
1925 | /* | |
1926 | * The SCU does not need to have a discrete reset state so | |
1927 | * just go back to the starting state. | |
1928 | */ | |
1929 | sci_base_state_machine_change_state( | |
1930 | &sci_phy->state_machine, | |
1931 | SCI_BASE_PHY_STATE_STARTING); | |
1932 | } | |
1933 | } | |
1934 | ||
1935 | /** | |
1936 | * | |
1937 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1938 | * | |
1939 | * This method will perform the actions required by the struct scic_sds_phy on | |
1940 | * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state | |
1941 | * handlers for the phy object base state machine final state. none | |
1942 | */ | |
1943 | static void scic_sds_phy_final_state_enter(void *object) | |
1944 | { | |
1945 | struct scic_sds_phy *sci_phy = object; | |
1946 | ||
1947 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL); | |
1948 | ||
1949 | /* Nothing to do here */ | |
1950 | } | |
1951 | ||
1952 | /* --------------------------------------------------------------------------- */ | |
1953 | ||
1954 | static const struct sci_base_state scic_sds_phy_state_table[] = { | |
1955 | [SCI_BASE_PHY_STATE_INITIAL] = { | |
1956 | .enter_state = scic_sds_phy_initial_state_enter, | |
1957 | }, | |
1958 | [SCI_BASE_PHY_STATE_STOPPED] = { | |
1959 | .enter_state = scic_sds_phy_stopped_state_enter, | |
1960 | }, | |
1961 | [SCI_BASE_PHY_STATE_STARTING] = { | |
1962 | .enter_state = scic_sds_phy_starting_state_enter, | |
1963 | }, | |
4a33c525 AG |
1964 | [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = { |
1965 | .enter_state = scic_sds_phy_starting_initial_substate_enter, | |
1966 | }, | |
1967 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = { | |
1968 | .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter, | |
1969 | }, | |
1970 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = { | |
1971 | .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter, | |
1972 | }, | |
1973 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = { | |
1974 | .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter, | |
1975 | }, | |
1976 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = { | |
1977 | .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter, | |
1978 | .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit, | |
1979 | }, | |
1980 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = { | |
1981 | .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter, | |
1982 | .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit | |
1983 | }, | |
1984 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = { | |
1985 | .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter, | |
1986 | .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit | |
1987 | }, | |
1988 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = { | |
1989 | .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter, | |
1990 | .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit | |
1991 | }, | |
1992 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = { | |
1993 | .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter, | |
1994 | .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit | |
1995 | }, | |
1996 | [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = { | |
1997 | .enter_state = scic_sds_phy_starting_final_substate_enter, | |
1998 | }, | |
d35bc1bd DW |
1999 | [SCI_BASE_PHY_STATE_READY] = { |
2000 | .enter_state = scic_sds_phy_ready_state_enter, | |
2001 | .exit_state = scic_sds_phy_ready_state_exit, | |
2002 | }, | |
2003 | [SCI_BASE_PHY_STATE_RESETTING] = { | |
2004 | .enter_state = scic_sds_phy_resetting_state_enter, | |
2005 | }, | |
2006 | [SCI_BASE_PHY_STATE_FINAL] = { | |
2007 | .enter_state = scic_sds_phy_final_state_enter, | |
2008 | }, | |
2009 | }; | |
2010 | ||
2011 | void scic_sds_phy_construct(struct scic_sds_phy *sci_phy, | |
2012 | struct scic_sds_port *owning_port, u8 phy_index) | |
2013 | { | |
2014 | sci_base_state_machine_construct(&sci_phy->state_machine, | |
2015 | sci_phy, | |
2016 | scic_sds_phy_state_table, | |
2017 | SCI_BASE_PHY_STATE_INITIAL); | |
2018 | ||
2019 | sci_base_state_machine_start(&sci_phy->state_machine); | |
2020 | ||
2021 | /* Copy the rest of the input data to our locals */ | |
2022 | sci_phy->owning_port = owning_port; | |
2023 | sci_phy->phy_index = phy_index; | |
2024 | sci_phy->bcn_received_while_port_unassigned = false; | |
2025 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN; | |
2026 | sci_phy->link_layer_registers = NULL; | |
2027 | sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; | |
2028 | sci_phy->sata_timeout_timer = NULL; | |
d35bc1bd | 2029 | } |
6f231dda | 2030 | |
4b33981a | 2031 | void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index) |
6f231dda | 2032 | { |
150fc6fc | 2033 | union scic_oem_parameters oem; |
4b33981a DW |
2034 | u64 sci_sas_addr; |
2035 | __be64 sas_addr; | |
2036 | ||
2037 | scic_oem_parameters_get(&ihost->sci, &oem); | |
2038 | sci_sas_addr = oem.sds1.phys[index].sas_address.high; | |
2039 | sci_sas_addr <<= 32; | |
2040 | sci_sas_addr |= oem.sds1.phys[index].sas_address.low; | |
2041 | sas_addr = cpu_to_be64(sci_sas_addr); | |
2042 | memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr)); | |
2043 | ||
2044 | iphy->isci_port = NULL; | |
2045 | iphy->sas_phy.enabled = 0; | |
2046 | iphy->sas_phy.id = index; | |
2047 | iphy->sas_phy.sas_addr = &iphy->sas_addr[0]; | |
2048 | iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd; | |
2049 | iphy->sas_phy.ha = &ihost->sas_ha; | |
2050 | iphy->sas_phy.lldd_phy = iphy; | |
2051 | iphy->sas_phy.enabled = 1; | |
2052 | iphy->sas_phy.class = SAS; | |
2053 | iphy->sas_phy.iproto = SAS_PROTOCOL_ALL; | |
2054 | iphy->sas_phy.tproto = 0; | |
2055 | iphy->sas_phy.type = PHY_TYPE_PHYSICAL; | |
2056 | iphy->sas_phy.role = PHY_ROLE_INITIATOR; | |
2057 | iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED; | |
2058 | iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN; | |
2059 | memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd)); | |
6f231dda DW |
2060 | } |
2061 | ||
2062 | ||
2063 | /** | |
2064 | * isci_phy_control() - This function is one of the SAS Domain Template | |
2065 | * functions. This is a phy management function. | |
2066 | * @phy: This parameter specifies the sphy being controlled. | |
2067 | * @func: This parameter specifies the phy control function being invoked. | |
2068 | * @buf: This parameter is specific to the phy function being invoked. | |
2069 | * | |
2070 | * status, zero indicates success. | |
2071 | */ | |
4d07f7f3 DJ |
2072 | int isci_phy_control(struct asd_sas_phy *sas_phy, |
2073 | enum phy_func func, | |
2074 | void *buf) | |
6f231dda | 2075 | { |
4d07f7f3 DJ |
2076 | int ret = 0; |
2077 | struct isci_phy *iphy = sas_phy->lldd_phy; | |
2078 | struct isci_port *iport = iphy->isci_port; | |
2079 | struct isci_host *ihost = sas_phy->ha->lldd_ha; | |
2080 | unsigned long flags; | |
6f231dda | 2081 | |
4d07f7f3 DJ |
2082 | dev_dbg(&ihost->pdev->dev, |
2083 | "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n", | |
2084 | __func__, sas_phy, func, buf, iphy, iport); | |
6f231dda DW |
2085 | |
2086 | switch (func) { | |
4d07f7f3 DJ |
2087 | case PHY_FUNC_DISABLE: |
2088 | spin_lock_irqsave(&ihost->scic_lock, flags); | |
4b33981a | 2089 | scic_sds_phy_stop(&iphy->sci); |
4d07f7f3 DJ |
2090 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
2091 | break; | |
2092 | ||
6f231dda | 2093 | case PHY_FUNC_LINK_RESET: |
4d07f7f3 | 2094 | spin_lock_irqsave(&ihost->scic_lock, flags); |
4b33981a DW |
2095 | scic_sds_phy_stop(&iphy->sci); |
2096 | scic_sds_phy_start(&iphy->sci); | |
4d07f7f3 DJ |
2097 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
2098 | break; | |
2099 | ||
2100 | case PHY_FUNC_HARD_RESET: | |
2101 | if (!iport) | |
2102 | return -ENODEV; | |
6f231dda DW |
2103 | |
2104 | /* Perform the port reset. */ | |
4393aa4e | 2105 | ret = isci_port_perform_hard_reset(ihost, iport, iphy); |
6f231dda DW |
2106 | |
2107 | break; | |
2108 | ||
6f231dda | 2109 | default: |
4d07f7f3 DJ |
2110 | dev_dbg(&ihost->pdev->dev, |
2111 | "%s: phy %p; func %d NOT IMPLEMENTED!\n", | |
2112 | __func__, sas_phy, func); | |
2113 | ret = -ENOSYS; | |
6f231dda DW |
2114 | break; |
2115 | } | |
2116 | return ret; | |
2117 | } |