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 | ||
274 | sci_base_state_machine_stop(&sci_phy->starting_substate_machine); | |
275 | ||
276 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
277 | SCI_BASE_PHY_STATE_STARTING); | |
278 | } | |
279 | ||
280 | /** | |
281 | * This method returns the port currently containing this phy. If the phy is | |
282 | * currently contained by the dummy port, then the phy is considered to not | |
283 | * be part of a port. | |
284 | * @sci_phy: This parameter specifies the phy for which to retrieve the | |
285 | * containing port. | |
286 | * | |
287 | * This method returns a handle to a port that contains the supplied phy. | |
288 | * NULL This value is returned if the phy is not part of a real | |
289 | * port (i.e. it's contained in the dummy port). !NULL All other | |
290 | * values indicate a handle/pointer to the port containing the phy. | |
291 | */ | |
292 | struct scic_sds_port *scic_sds_phy_get_port( | |
293 | struct scic_sds_phy *sci_phy) | |
294 | { | |
295 | if (scic_sds_port_get_index(sci_phy->owning_port) == SCIC_SDS_DUMMY_PORT) | |
296 | return NULL; | |
297 | ||
298 | return sci_phy->owning_port; | |
299 | } | |
300 | ||
301 | /** | |
302 | * This method will assign a port to the phy object. | |
303 | * @out]: sci_phy This parameter specifies the phy for which to assign a port | |
304 | * object. | |
305 | * | |
306 | * | |
307 | */ | |
308 | void scic_sds_phy_set_port( | |
309 | struct scic_sds_phy *sci_phy, | |
310 | struct scic_sds_port *sci_port) | |
311 | { | |
312 | sci_phy->owning_port = sci_port; | |
313 | ||
314 | if (sci_phy->bcn_received_while_port_unassigned) { | |
315 | sci_phy->bcn_received_while_port_unassigned = false; | |
316 | scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy); | |
317 | } | |
318 | } | |
319 | ||
320 | /** | |
321 | * This method will initialize the constructed phy | |
322 | * @sci_phy: | |
323 | * @link_layer_registers: | |
324 | * | |
325 | * enum sci_status | |
326 | */ | |
327 | enum sci_status scic_sds_phy_initialize( | |
328 | struct scic_sds_phy *sci_phy, | |
329 | struct scu_transport_layer_registers __iomem *transport_layer_registers, | |
330 | struct scu_link_layer_registers __iomem *link_layer_registers) | |
331 | { | |
332 | struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy); | |
333 | struct isci_host *ihost = scic_to_ihost(scic); | |
334 | ||
335 | /* Create the SIGNATURE FIS Timeout timer for this phy */ | |
336 | sci_phy->sata_timeout_timer = | |
337 | isci_timer_create( | |
338 | ihost, | |
339 | sci_phy, | |
340 | scic_sds_phy_sata_timeout); | |
341 | ||
342 | /* Perfrom the initialization of the TL hardware */ | |
343 | scic_sds_phy_transport_layer_initialization( | |
344 | sci_phy, | |
345 | transport_layer_registers); | |
346 | ||
347 | /* Perofrm the initialization of the PE hardware */ | |
348 | scic_sds_phy_link_layer_initialization(sci_phy, link_layer_registers); | |
349 | ||
350 | /* | |
351 | * There is nothing that needs to be done in this state just | |
352 | * transition to the stopped state. */ | |
353 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
354 | SCI_BASE_PHY_STATE_STOPPED); | |
355 | ||
356 | return SCI_SUCCESS; | |
357 | } | |
358 | ||
359 | /** | |
360 | * This method assigns the direct attached device ID for this phy. | |
361 | * | |
362 | * @sci_phy The phy for which the direct attached device id is to | |
363 | * be assigned. | |
364 | * @device_id The direct attached device ID to assign to the phy. | |
365 | * This will either be the RNi for the device or an invalid RNi if there | |
366 | * is no current device assigned to the phy. | |
367 | */ | |
368 | void scic_sds_phy_setup_transport( | |
369 | struct scic_sds_phy *sci_phy, | |
370 | u32 device_id) | |
371 | { | |
372 | u32 tl_control; | |
373 | ||
374 | writel(device_id, &sci_phy->transport_layer_registers->stp_rni); | |
375 | ||
376 | /* | |
377 | * The read should guarantee that the first write gets posted | |
378 | * before the next write | |
379 | */ | |
380 | tl_control = readl(&sci_phy->transport_layer_registers->control); | |
381 | tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE); | |
382 | writel(tl_control, &sci_phy->transport_layer_registers->control); | |
383 | } | |
384 | ||
385 | /** | |
386 | * | |
387 | * @sci_phy: The phy object to be suspended. | |
388 | * | |
389 | * This function will perform the register reads/writes to suspend the SCU | |
390 | * hardware protocol engine. none | |
391 | */ | |
392 | static void scic_sds_phy_suspend( | |
393 | struct scic_sds_phy *sci_phy) | |
394 | { | |
395 | u32 scu_sas_pcfg_value; | |
396 | ||
397 | scu_sas_pcfg_value = | |
398 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
399 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE); | |
400 | writel(scu_sas_pcfg_value, | |
401 | &sci_phy->link_layer_registers->phy_configuration); | |
402 | ||
403 | scic_sds_phy_setup_transport( | |
404 | sci_phy, | |
405 | SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX); | |
406 | } | |
407 | ||
408 | void scic_sds_phy_resume(struct scic_sds_phy *sci_phy) | |
409 | { | |
410 | u32 scu_sas_pcfg_value; | |
411 | ||
412 | scu_sas_pcfg_value = | |
413 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
414 | scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE); | |
415 | writel(scu_sas_pcfg_value, | |
416 | &sci_phy->link_layer_registers->phy_configuration); | |
417 | } | |
418 | ||
419 | void scic_sds_phy_get_sas_address(struct scic_sds_phy *sci_phy, | |
420 | struct sci_sas_address *sas_address) | |
421 | { | |
422 | sas_address->high = readl(&sci_phy->link_layer_registers->source_sas_address_high); | |
423 | sas_address->low = readl(&sci_phy->link_layer_registers->source_sas_address_low); | |
424 | } | |
425 | ||
426 | void scic_sds_phy_get_attached_sas_address(struct scic_sds_phy *sci_phy, | |
427 | struct sci_sas_address *sas_address) | |
428 | { | |
429 | struct sas_identify_frame *iaf; | |
430 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
431 | ||
432 | iaf = &iphy->frame_rcvd.iaf; | |
433 | memcpy(sas_address, iaf->sas_addr, SAS_ADDR_SIZE); | |
434 | } | |
435 | ||
436 | void scic_sds_phy_get_protocols(struct scic_sds_phy *sci_phy, | |
437 | struct scic_phy_proto *protocols) | |
438 | { | |
439 | protocols->all = | |
440 | (u16)(readl(&sci_phy-> | |
441 | link_layer_registers->transmit_identification) & | |
442 | 0x0000FFFF); | |
443 | } | |
444 | ||
445 | /** | |
446 | * This method will attempt to start the phy object. This request is only valid | |
447 | * when the phy is in the stopped state | |
448 | * @sci_phy: | |
449 | * | |
450 | * enum sci_status | |
451 | */ | |
452 | enum sci_status scic_sds_phy_start(struct scic_sds_phy *sci_phy) | |
453 | { | |
454 | return sci_phy->state_handlers->start_handler(sci_phy); | |
455 | } | |
456 | ||
457 | /** | |
458 | * This method will attempt to stop the phy object. | |
459 | * @sci_phy: | |
460 | * | |
461 | * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE | |
462 | * if the phy is not in a valid state to stop | |
463 | */ | |
464 | enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy) | |
465 | { | |
466 | return sci_phy->state_handlers->stop_handler(sci_phy); | |
467 | } | |
468 | ||
469 | /** | |
470 | * This method will attempt to reset the phy. This request is only valid when | |
471 | * the phy is in an ready state | |
472 | * @sci_phy: | |
473 | * | |
474 | * enum sci_status | |
475 | */ | |
476 | enum sci_status scic_sds_phy_reset( | |
477 | struct scic_sds_phy *sci_phy) | |
478 | { | |
479 | return sci_phy->state_handlers->reset_handler(sci_phy); | |
480 | } | |
481 | ||
482 | /** | |
483 | * This method will process the event code received. | |
484 | * @sci_phy: | |
485 | * @event_code: | |
486 | * | |
487 | * enum sci_status | |
488 | */ | |
489 | enum sci_status scic_sds_phy_event_handler( | |
490 | struct scic_sds_phy *sci_phy, | |
491 | u32 event_code) | |
492 | { | |
493 | return sci_phy->state_handlers->event_handler(sci_phy, event_code); | |
494 | } | |
495 | ||
496 | /** | |
497 | * This method will process the frame index received. | |
498 | * @sci_phy: | |
499 | * @frame_index: | |
500 | * | |
501 | * enum sci_status | |
502 | */ | |
503 | enum sci_status scic_sds_phy_frame_handler( | |
504 | struct scic_sds_phy *sci_phy, | |
505 | u32 frame_index) | |
506 | { | |
507 | return sci_phy->state_handlers->frame_handler(sci_phy, frame_index); | |
508 | } | |
509 | ||
510 | /** | |
511 | * This method will give the phy permission to consume power | |
512 | * @sci_phy: | |
513 | * | |
514 | * enum sci_status | |
515 | */ | |
516 | enum sci_status scic_sds_phy_consume_power_handler( | |
517 | struct scic_sds_phy *sci_phy) | |
518 | { | |
519 | return sci_phy->state_handlers->consume_power_handler(sci_phy); | |
520 | } | |
521 | ||
522 | /* | |
523 | * ***************************************************************************** | |
524 | * * SCIC SDS PHY HELPER FUNCTIONS | |
525 | * ***************************************************************************** */ | |
526 | ||
527 | ||
528 | /** | |
529 | * | |
530 | * @sci_phy: The phy object that received SAS PHY DETECTED. | |
531 | * | |
532 | * This method continues the link training for the phy as if it were a SAS PHY | |
533 | * instead of a SATA PHY. This is done because the completion queue had a SAS | |
534 | * PHY DETECTED event when the state machine was expecting a SATA PHY event. | |
535 | * none | |
536 | */ | |
537 | static void scic_sds_phy_start_sas_link_training( | |
538 | struct scic_sds_phy *sci_phy) | |
539 | { | |
540 | u32 phy_control; | |
541 | ||
542 | phy_control = | |
543 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
544 | phy_control |= SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD); | |
545 | writel(phy_control, | |
546 | &sci_phy->link_layer_registers->phy_configuration); | |
547 | ||
548 | sci_base_state_machine_change_state( | |
549 | &sci_phy->starting_substate_machine, | |
550 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN | |
551 | ); | |
552 | ||
553 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SAS; | |
554 | } | |
555 | ||
556 | /** | |
557 | * | |
558 | * @sci_phy: The phy object that received a SATA SPINUP HOLD event | |
559 | * | |
560 | * This method continues the link training for the phy as if it were a SATA PHY | |
561 | * instead of a SAS PHY. This is done because the completion queue had a SATA | |
562 | * SPINUP HOLD event when the state machine was expecting a SAS PHY event. none | |
563 | */ | |
564 | static void scic_sds_phy_start_sata_link_training( | |
565 | struct scic_sds_phy *sci_phy) | |
566 | { | |
567 | sci_base_state_machine_change_state( | |
568 | &sci_phy->starting_substate_machine, | |
569 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER | |
570 | ); | |
571 | ||
572 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA; | |
573 | } | |
574 | ||
575 | /** | |
576 | * scic_sds_phy_complete_link_training - perform processing common to | |
577 | * all protocols upon completion of link training. | |
578 | * @sci_phy: This parameter specifies the phy object for which link training | |
579 | * has completed. | |
580 | * @max_link_rate: This parameter specifies the maximum link rate to be | |
581 | * associated with this phy. | |
582 | * @next_state: This parameter specifies the next state for the phy's starting | |
583 | * sub-state machine. | |
584 | * | |
585 | */ | |
586 | static void scic_sds_phy_complete_link_training( | |
587 | struct scic_sds_phy *sci_phy, | |
588 | enum sas_linkrate max_link_rate, | |
589 | u32 next_state) | |
590 | { | |
591 | sci_phy->max_negotiated_speed = max_link_rate; | |
592 | ||
593 | sci_base_state_machine_change_state(&sci_phy->starting_substate_machine, | |
594 | next_state); | |
595 | } | |
596 | ||
597 | static void scic_sds_phy_restart_starting_state( | |
598 | struct scic_sds_phy *sci_phy) | |
599 | { | |
600 | /* Stop the current substate machine */ | |
601 | sci_base_state_machine_stop(&sci_phy->starting_substate_machine); | |
602 | ||
603 | /* Re-enter the base state machine starting state */ | |
604 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
605 | SCI_BASE_PHY_STATE_STARTING); | |
606 | } | |
607 | ||
608 | /* **************************************************************************** | |
609 | * SCIC SDS PHY general handlers | |
610 | ************************************************************************** */ | |
611 | static enum sci_status scic_sds_phy_starting_substate_general_stop_handler( | |
612 | struct scic_sds_phy *phy) | |
613 | { | |
614 | sci_base_state_machine_stop(&phy->starting_substate_machine); | |
615 | ||
616 | sci_base_state_machine_change_state(&phy->state_machine, | |
617 | SCI_BASE_PHY_STATE_STOPPED); | |
618 | ||
619 | return SCI_SUCCESS; | |
620 | } | |
621 | ||
622 | /* | |
623 | * ***************************************************************************** | |
624 | * * SCIC SDS PHY EVENT_HANDLERS | |
625 | * ***************************************************************************** */ | |
626 | ||
627 | /** | |
628 | * | |
629 | * @phy: This struct scic_sds_phy object which has received an event. | |
630 | * @event_code: This is the event code which the phy object is to decode. | |
631 | * | |
632 | * This method is called when an event notification is received for the phy | |
633 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - | |
634 | * decode the event - sas phy detected causes a state transition to the wait | |
635 | * for speed event notification. - any other events log a warning message and | |
636 | * set a failure status enum sci_status SCI_SUCCESS on any valid event notification | |
637 | * SCI_FAILURE on any unexpected event notifation | |
638 | */ | |
639 | static enum sci_status scic_sds_phy_starting_substate_await_ossp_event_handler( | |
640 | struct scic_sds_phy *sci_phy, | |
641 | u32 event_code) | |
642 | { | |
643 | u32 result = SCI_SUCCESS; | |
644 | ||
645 | switch (scu_get_event_code(event_code)) { | |
646 | case SCU_EVENT_SAS_PHY_DETECTED: | |
647 | scic_sds_phy_start_sas_link_training(sci_phy); | |
648 | sci_phy->is_in_link_training = true; | |
649 | break; | |
650 | ||
651 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
652 | scic_sds_phy_start_sata_link_training(sci_phy); | |
653 | sci_phy->is_in_link_training = true; | |
654 | break; | |
655 | ||
656 | default: | |
657 | dev_dbg(sciphy_to_dev(sci_phy), | |
658 | "%s: PHY starting substate machine received " | |
659 | "unexpected event_code %x\n", | |
660 | __func__, | |
661 | event_code); | |
662 | ||
663 | result = SCI_FAILURE; | |
664 | break; | |
665 | } | |
666 | ||
667 | return result; | |
668 | } | |
669 | ||
670 | /** | |
671 | * | |
672 | * @phy: This struct scic_sds_phy object which has received an event. | |
673 | * @event_code: This is the event code which the phy object is to decode. | |
674 | * | |
675 | * This method is called when an event notification is received for the phy | |
676 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - | |
677 | * decode the event - sas phy detected returns us back to this state. - speed | |
678 | * event detected causes a state transition to the wait for iaf. - identify | |
679 | * timeout is an un-expected event and the state machine is restarted. - link | |
680 | * failure events restart the starting state machine - any other events log a | |
681 | * warning message and set a failure status enum sci_status SCI_SUCCESS on any valid | |
682 | * event notification SCI_FAILURE on any unexpected event notifation | |
683 | */ | |
684 | static enum sci_status scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler( | |
685 | struct scic_sds_phy *sci_phy, | |
686 | u32 event_code) | |
687 | { | |
688 | u32 result = SCI_SUCCESS; | |
689 | ||
690 | switch (scu_get_event_code(event_code)) { | |
691 | case SCU_EVENT_SAS_PHY_DETECTED: | |
692 | /* | |
693 | * Why is this being reported again by the controller? | |
694 | * We would re-enter this state so just stay here */ | |
695 | break; | |
696 | ||
697 | case SCU_EVENT_SAS_15: | |
698 | case SCU_EVENT_SAS_15_SSC: | |
699 | scic_sds_phy_complete_link_training( | |
700 | sci_phy, | |
701 | SAS_LINK_RATE_1_5_GBPS, | |
702 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF); | |
703 | break; | |
704 | ||
705 | case SCU_EVENT_SAS_30: | |
706 | case SCU_EVENT_SAS_30_SSC: | |
707 | scic_sds_phy_complete_link_training( | |
708 | sci_phy, | |
709 | SAS_LINK_RATE_3_0_GBPS, | |
710 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF); | |
711 | break; | |
712 | ||
713 | case SCU_EVENT_SAS_60: | |
714 | case SCU_EVENT_SAS_60_SSC: | |
715 | scic_sds_phy_complete_link_training( | |
716 | sci_phy, | |
717 | SAS_LINK_RATE_6_0_GBPS, | |
718 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF); | |
719 | break; | |
720 | ||
721 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
722 | /* | |
723 | * We were doing SAS PHY link training and received a SATA PHY event | |
724 | * continue OOB/SN as if this were a SATA PHY */ | |
725 | scic_sds_phy_start_sata_link_training(sci_phy); | |
726 | break; | |
727 | ||
728 | case SCU_EVENT_LINK_FAILURE: | |
729 | /* Link failure change state back to the starting state */ | |
730 | scic_sds_phy_restart_starting_state(sci_phy); | |
731 | break; | |
732 | ||
733 | default: | |
734 | dev_warn(sciphy_to_dev(sci_phy), | |
735 | "%s: PHY starting substate machine received " | |
736 | "unexpected event_code %x\n", | |
737 | __func__, | |
738 | event_code); | |
739 | ||
740 | result = SCI_FAILURE; | |
741 | break; | |
742 | } | |
743 | ||
744 | return result; | |
745 | } | |
746 | ||
747 | /** | |
748 | * | |
749 | * @phy: This struct scic_sds_phy object which has received an event. | |
750 | * @event_code: This is the event code which the phy object is to decode. | |
751 | * | |
752 | * This method is called when an event notification is received for the phy | |
753 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - | |
754 | * decode the event - sas phy detected event backs up the state machine to the | |
755 | * await speed notification. - identify timeout is an un-expected event and the | |
756 | * state machine is restarted. - link failure events restart the starting state | |
757 | * machine - any other events log a warning message and set a failure status | |
758 | * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any | |
759 | * unexpected event notifation | |
760 | */ | |
761 | static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_event_handler( | |
762 | struct scic_sds_phy *sci_phy, | |
763 | u32 event_code) | |
764 | { | |
765 | u32 result = SCI_SUCCESS; | |
766 | ||
767 | switch (scu_get_event_code(event_code)) { | |
768 | case SCU_EVENT_SAS_PHY_DETECTED: | |
769 | /* Backup the state machine */ | |
770 | scic_sds_phy_start_sas_link_training(sci_phy); | |
771 | break; | |
772 | ||
773 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
774 | /* | |
775 | * We were doing SAS PHY link training and received a SATA PHY event | |
776 | * continue OOB/SN as if this were a SATA PHY */ | |
777 | scic_sds_phy_start_sata_link_training(sci_phy); | |
778 | break; | |
779 | ||
780 | case SCU_EVENT_RECEIVED_IDENTIFY_TIMEOUT: | |
781 | case SCU_EVENT_LINK_FAILURE: | |
782 | case SCU_EVENT_HARD_RESET_RECEIVED: | |
783 | /* Start the oob/sn state machine over again */ | |
784 | scic_sds_phy_restart_starting_state(sci_phy); | |
785 | break; | |
786 | ||
787 | default: | |
788 | dev_warn(sciphy_to_dev(sci_phy), | |
789 | "%s: PHY starting substate machine received " | |
790 | "unexpected event_code %x\n", | |
791 | __func__, | |
792 | event_code); | |
793 | ||
794 | result = SCI_FAILURE; | |
795 | break; | |
796 | } | |
797 | ||
798 | return result; | |
799 | } | |
800 | ||
801 | /** | |
802 | * | |
803 | * @phy: This struct scic_sds_phy object which has received an event. | |
804 | * @event_code: This is the event code which the phy object is to decode. | |
805 | * | |
806 | * This method is called when an event notification is received for the phy | |
807 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_POWER. - | |
808 | * decode the event - link failure events restart the starting state machine - | |
809 | * any other events log a warning message and set a failure status enum sci_status | |
810 | * SCI_SUCCESS on a link failure event SCI_FAILURE on any unexpected event | |
811 | * notifation | |
812 | */ | |
813 | static enum sci_status scic_sds_phy_starting_substate_await_sas_power_event_handler( | |
814 | struct scic_sds_phy *sci_phy, | |
815 | u32 event_code) | |
816 | { | |
817 | u32 result = SCI_SUCCESS; | |
818 | ||
819 | switch (scu_get_event_code(event_code)) { | |
820 | case SCU_EVENT_LINK_FAILURE: | |
821 | /* Link failure change state back to the starting state */ | |
822 | scic_sds_phy_restart_starting_state(sci_phy); | |
823 | break; | |
824 | ||
825 | default: | |
826 | dev_warn(sciphy_to_dev(sci_phy), | |
827 | "%s: PHY starting substate machine received unexpected " | |
828 | "event_code %x\n", | |
829 | __func__, | |
830 | event_code); | |
831 | ||
832 | result = SCI_FAILURE; | |
833 | break; | |
834 | } | |
835 | ||
836 | return result; | |
837 | } | |
838 | ||
839 | /** | |
840 | * | |
841 | * @phy: This struct scic_sds_phy object which has received an event. | |
842 | * @event_code: This is the event code which the phy object is to decode. | |
843 | * | |
844 | * This method is called when an event notification is received for the phy | |
845 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - | |
846 | * decode the event - link failure events restart the starting state machine - | |
847 | * sata spinup hold events are ignored since they are expected - any other | |
848 | * events log a warning message and set a failure status enum sci_status SCI_SUCCESS | |
849 | * on a link failure event SCI_FAILURE on any unexpected event notifation | |
850 | */ | |
851 | static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_handler( | |
852 | struct scic_sds_phy *sci_phy, | |
853 | u32 event_code) | |
854 | { | |
855 | u32 result = SCI_SUCCESS; | |
856 | ||
857 | switch (scu_get_event_code(event_code)) { | |
858 | case SCU_EVENT_LINK_FAILURE: | |
859 | /* Link failure change state back to the starting state */ | |
860 | scic_sds_phy_restart_starting_state(sci_phy); | |
861 | break; | |
862 | ||
863 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
864 | /* These events are received every 10ms and are expected while in this state */ | |
865 | break; | |
866 | ||
867 | case SCU_EVENT_SAS_PHY_DETECTED: | |
868 | /* | |
869 | * There has been a change in the phy type before OOB/SN for the | |
870 | * SATA finished start down the SAS link traning path. */ | |
871 | scic_sds_phy_start_sas_link_training(sci_phy); | |
872 | break; | |
873 | ||
874 | default: | |
875 | dev_warn(sciphy_to_dev(sci_phy), | |
876 | "%s: PHY starting substate machine received " | |
877 | "unexpected event_code %x\n", | |
878 | __func__, | |
879 | event_code); | |
880 | ||
881 | result = SCI_FAILURE; | |
882 | break; | |
883 | } | |
884 | ||
885 | return result; | |
886 | } | |
887 | ||
888 | /** | |
889 | * scic_sds_phy_starting_substate_await_sata_phy_event_handler - | |
890 | * @phy: This struct scic_sds_phy object which has received an event. | |
891 | * @event_code: This is the event code which the phy object is to decode. | |
892 | * | |
893 | * This method is called when an event notification is received for the phy | |
894 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - | |
895 | * decode the event - link failure events restart the starting state machine - | |
896 | * sata spinup hold events are ignored since they are expected - sata phy | |
897 | * detected event change to the wait speed event - any other events log a | |
898 | * warning message and set a failure status enum sci_status SCI_SUCCESS on a link | |
899 | * failure event SCI_FAILURE on any unexpected event notifation | |
900 | */ | |
901 | static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler( | |
902 | struct scic_sds_phy *sci_phy, u32 event_code) | |
903 | { | |
904 | u32 result = SCI_SUCCESS; | |
905 | ||
906 | switch (scu_get_event_code(event_code)) { | |
907 | case SCU_EVENT_LINK_FAILURE: | |
908 | /* Link failure change state back to the starting state */ | |
909 | scic_sds_phy_restart_starting_state(sci_phy); | |
910 | break; | |
911 | ||
912 | case SCU_EVENT_SATA_SPINUP_HOLD: | |
913 | /* These events might be received since we dont know how many may be in | |
914 | * the completion queue while waiting for power | |
915 | */ | |
916 | break; | |
917 | ||
918 | case SCU_EVENT_SATA_PHY_DETECTED: | |
919 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA; | |
920 | ||
921 | /* We have received the SATA PHY notification change state */ | |
922 | sci_base_state_machine_change_state(&sci_phy->starting_substate_machine, | |
923 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN); | |
924 | break; | |
925 | ||
926 | case SCU_EVENT_SAS_PHY_DETECTED: | |
927 | /* There has been a change in the phy type before OOB/SN for the | |
928 | * SATA finished start down the SAS link traning path. | |
929 | */ | |
930 | scic_sds_phy_start_sas_link_training(sci_phy); | |
931 | break; | |
932 | ||
933 | default: | |
934 | dev_warn(sciphy_to_dev(sci_phy), | |
935 | "%s: PHY starting substate machine received " | |
936 | "unexpected event_code %x\n", | |
937 | __func__, | |
938 | event_code); | |
939 | ||
940 | result = SCI_FAILURE; | |
941 | break; | |
942 | } | |
943 | ||
944 | return result; | |
945 | } | |
946 | ||
947 | /** | |
948 | * | |
949 | * @phy: This struct scic_sds_phy object which has received an event. | |
950 | * @event_code: This is the event code which the phy object is to decode. | |
951 | * | |
952 | * This method is called when an event notification is received for the phy | |
953 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. | |
954 | * - decode the event - sata phy detected returns us back to this state. - | |
955 | * speed event detected causes a state transition to the wait for signature. - | |
956 | * link failure events restart the starting state machine - any other events | |
957 | * log a warning message and set a failure status enum sci_status SCI_SUCCESS on any | |
958 | * valid event notification SCI_FAILURE on any unexpected event notifation | |
959 | */ | |
960 | static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_handler( | |
961 | struct scic_sds_phy *sci_phy, | |
962 | u32 event_code) | |
963 | { | |
964 | u32 result = SCI_SUCCESS; | |
965 | ||
966 | switch (scu_get_event_code(event_code)) { | |
967 | case SCU_EVENT_SATA_PHY_DETECTED: | |
968 | /* | |
969 | * The hardware reports multiple SATA PHY detected events | |
970 | * ignore the extras */ | |
971 | break; | |
972 | ||
973 | case SCU_EVENT_SATA_15: | |
974 | case SCU_EVENT_SATA_15_SSC: | |
975 | scic_sds_phy_complete_link_training( | |
976 | sci_phy, | |
977 | SAS_LINK_RATE_1_5_GBPS, | |
978 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF); | |
979 | break; | |
980 | ||
981 | case SCU_EVENT_SATA_30: | |
982 | case SCU_EVENT_SATA_30_SSC: | |
983 | scic_sds_phy_complete_link_training( | |
984 | sci_phy, | |
985 | SAS_LINK_RATE_3_0_GBPS, | |
986 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF); | |
987 | break; | |
988 | ||
989 | case SCU_EVENT_SATA_60: | |
990 | case SCU_EVENT_SATA_60_SSC: | |
991 | scic_sds_phy_complete_link_training( | |
992 | sci_phy, | |
993 | SAS_LINK_RATE_6_0_GBPS, | |
994 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF); | |
995 | break; | |
996 | ||
997 | case SCU_EVENT_LINK_FAILURE: | |
998 | /* Link failure change state back to the starting state */ | |
999 | scic_sds_phy_restart_starting_state(sci_phy); | |
1000 | break; | |
1001 | ||
1002 | case SCU_EVENT_SAS_PHY_DETECTED: | |
1003 | /* | |
1004 | * There has been a change in the phy type before OOB/SN for the | |
1005 | * SATA finished start down the SAS link traning path. */ | |
1006 | scic_sds_phy_start_sas_link_training(sci_phy); | |
1007 | break; | |
1008 | ||
1009 | default: | |
1010 | dev_warn(sciphy_to_dev(sci_phy), | |
1011 | "%s: PHY starting substate machine received " | |
1012 | "unexpected event_code %x\n", | |
1013 | __func__, | |
1014 | event_code); | |
1015 | ||
1016 | result = SCI_FAILURE; | |
1017 | break; | |
1018 | } | |
1019 | ||
1020 | return result; | |
1021 | } | |
1022 | ||
1023 | /** | |
1024 | * scic_sds_phy_starting_substate_await_sig_fis_event_handler - | |
1025 | * @phy: This struct scic_sds_phy object which has received an event. | |
1026 | * @event_code: This is the event code which the phy object is to decode. | |
1027 | * | |
1028 | * This method is called when an event notification is received for the phy | |
1029 | * object when in the state SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - | |
1030 | * decode the event - sas phy detected event backs up the state machine to the | |
1031 | * await speed notification. - identify timeout is an un-expected event and the | |
1032 | * state machine is restarted. - link failure events restart the starting state | |
1033 | * machine - any other events log a warning message and set a failure status | |
1034 | * enum sci_status SCI_SUCCESS on any valid event notification SCI_FAILURE on any | |
1035 | * unexpected event notifation | |
1036 | */ | |
1037 | static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler( | |
1038 | struct scic_sds_phy *sci_phy, u32 event_code) | |
1039 | { | |
1040 | u32 result = SCI_SUCCESS; | |
1041 | ||
1042 | switch (scu_get_event_code(event_code)) { | |
1043 | case SCU_EVENT_SATA_PHY_DETECTED: | |
1044 | /* Backup the state machine */ | |
1045 | sci_base_state_machine_change_state(&sci_phy->starting_substate_machine, | |
1046 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN); | |
1047 | break; | |
1048 | ||
1049 | case SCU_EVENT_LINK_FAILURE: | |
1050 | /* Link failure change state back to the starting state */ | |
1051 | scic_sds_phy_restart_starting_state(sci_phy); | |
1052 | break; | |
1053 | ||
1054 | default: | |
1055 | dev_warn(sciphy_to_dev(sci_phy), | |
1056 | "%s: PHY starting substate machine received " | |
1057 | "unexpected event_code %x\n", | |
1058 | __func__, | |
1059 | event_code); | |
1060 | ||
1061 | result = SCI_FAILURE; | |
1062 | break; | |
1063 | } | |
1064 | ||
1065 | return result; | |
1066 | } | |
1067 | ||
1068 | ||
1069 | /* | |
1070 | * ***************************************************************************** | |
1071 | * * SCIC SDS PHY FRAME_HANDLERS | |
1072 | * ***************************************************************************** */ | |
1073 | ||
1074 | /** | |
1075 | * | |
1076 | * @phy: This is struct scic_sds_phy object which is being requested to decode the | |
1077 | * frame data. | |
1078 | * @frame_index: This is the index of the unsolicited frame which was received | |
1079 | * for this phy. | |
1080 | * | |
1081 | * This method decodes the unsolicited frame when the struct scic_sds_phy is in the | |
1082 | * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Get the UF Header - If the UF | |
1083 | * is an IAF - Copy IAF data to local phy object IAF data buffer. - Change | |
1084 | * starting substate to wait power. - else - log warning message of unexpected | |
1085 | * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS | |
1086 | */ | |
1087 | static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler( | |
1088 | struct scic_sds_phy *sci_phy, u32 frame_index) | |
1089 | { | |
1090 | enum sci_status result; | |
1091 | u32 *frame_words; | |
1092 | struct sas_identify_frame iaf; | |
1093 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
1094 | ||
1095 | result = scic_sds_unsolicited_frame_control_get_header( | |
1096 | &(scic_sds_phy_get_controller(sci_phy)->uf_control), | |
1097 | frame_index, | |
1098 | (void **)&frame_words); | |
1099 | ||
1100 | if (result != SCI_SUCCESS) | |
1101 | return result; | |
1102 | ||
1103 | sci_swab32_cpy(&iaf, frame_words, sizeof(iaf) / sizeof(u32)); | |
1104 | if (iaf.frame_type == 0) { | |
1105 | u32 state; | |
1106 | ||
1107 | memcpy(&iphy->frame_rcvd.iaf, &iaf, sizeof(iaf)); | |
1108 | if (iaf.smp_tport) { | |
1109 | /* We got the IAF for an expander PHY go to the final | |
1110 | * state since there are no power requirements for | |
1111 | * expander phys. | |
1112 | */ | |
1113 | state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL; | |
1114 | } else { | |
1115 | /* We got the IAF we can now go to the await spinup | |
1116 | * semaphore state | |
1117 | */ | |
1118 | state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER; | |
1119 | } | |
1120 | sci_base_state_machine_change_state( | |
1121 | &sci_phy->starting_substate_machine, | |
1122 | state); | |
1123 | result = SCI_SUCCESS; | |
1124 | } else | |
1125 | dev_warn(sciphy_to_dev(sci_phy), | |
1126 | "%s: PHY starting substate machine received " | |
1127 | "unexpected frame id %x\n", | |
1128 | __func__, | |
1129 | frame_index); | |
1130 | ||
1131 | scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy), | |
1132 | frame_index); | |
1133 | ||
1134 | return result; | |
1135 | } | |
1136 | ||
1137 | /** | |
1138 | * | |
1139 | * @phy: This is struct scic_sds_phy object which is being requested to decode the | |
1140 | * frame data. | |
1141 | * @frame_index: This is the index of the unsolicited frame which was received | |
1142 | * for this phy. | |
1143 | * | |
1144 | * This method decodes the unsolicited frame when the struct scic_sds_phy is in the | |
1145 | * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Get the UF Header - If | |
1146 | * the UF is an SIGNATURE FIS - Copy IAF data to local phy object SIGNATURE FIS | |
1147 | * data buffer. - else - log warning message of unexpected unsolicted frame - | |
1148 | * release frame buffer enum sci_status SCI_SUCCESS Must decode the SIGNATURE FIS | |
1149 | * data | |
1150 | */ | |
1151 | static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler( | |
1152 | struct scic_sds_phy *sci_phy, | |
1153 | u32 frame_index) | |
1154 | { | |
1155 | enum sci_status result; | |
1156 | struct dev_to_host_fis *frame_header; | |
1157 | u32 *fis_frame_data; | |
1158 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); | |
1159 | ||
1160 | result = scic_sds_unsolicited_frame_control_get_header( | |
1161 | &(scic_sds_phy_get_controller(sci_phy)->uf_control), | |
1162 | frame_index, | |
1163 | (void **)&frame_header); | |
1164 | ||
1165 | if (result != SCI_SUCCESS) | |
1166 | return result; | |
1167 | ||
1168 | if ((frame_header->fis_type == FIS_REGD2H) && | |
1169 | !(frame_header->status & ATA_BUSY)) { | |
1170 | scic_sds_unsolicited_frame_control_get_buffer( | |
1171 | &(scic_sds_phy_get_controller(sci_phy)->uf_control), | |
1172 | frame_index, | |
1173 | (void **)&fis_frame_data); | |
1174 | ||
1175 | scic_sds_controller_copy_sata_response(&iphy->frame_rcvd.fis, | |
1176 | frame_header, | |
1177 | fis_frame_data); | |
1178 | ||
1179 | /* got IAF we can now go to the await spinup semaphore state */ | |
1180 | sci_base_state_machine_change_state(&sci_phy->starting_substate_machine, | |
1181 | SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL); | |
1182 | ||
1183 | result = SCI_SUCCESS; | |
1184 | } else | |
1185 | dev_warn(sciphy_to_dev(sci_phy), | |
1186 | "%s: PHY starting substate machine received " | |
1187 | "unexpected frame id %x\n", | |
1188 | __func__, | |
1189 | frame_index); | |
1190 | ||
1191 | /* Regardless of the result we are done with this frame with it */ | |
1192 | scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy), | |
1193 | frame_index); | |
1194 | ||
1195 | return result; | |
1196 | } | |
1197 | ||
1198 | /* | |
1199 | * ***************************************************************************** | |
1200 | * * SCIC SDS PHY POWER_HANDLERS | |
1201 | * ***************************************************************************** */ | |
1202 | ||
1203 | /* | |
1204 | * This method is called by the struct scic_sds_controller when the phy object is | |
1205 | * granted power. - The notify enable spinups are turned on for this phy object | |
1206 | * - The phy state machine is transitioned to the | |
1207 | * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS | |
1208 | */ | |
1209 | static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler( | |
1210 | struct scic_sds_phy *sci_phy) | |
1211 | { | |
1212 | u32 enable_spinup; | |
1213 | ||
1214 | enable_spinup = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control); | |
1215 | enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE); | |
1216 | writel(enable_spinup, &sci_phy->link_layer_registers->notify_enable_spinup_control); | |
1217 | ||
1218 | /* Change state to the final state this substate machine has run to completion */ | |
1219 | sci_base_state_machine_change_state(&sci_phy->starting_substate_machine, | |
1220 | SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL); | |
1221 | ||
1222 | return SCI_SUCCESS; | |
1223 | } | |
1224 | ||
1225 | /* | |
1226 | * This method is called by the struct scic_sds_controller when the phy object is | |
1227 | * granted power. - The phy state machine is transitioned to the | |
1228 | * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS | |
1229 | */ | |
1230 | static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler( | |
1231 | struct scic_sds_phy *sci_phy) | |
1232 | { | |
1233 | u32 scu_sas_pcfg_value; | |
1234 | ||
1235 | /* Release the spinup hold state and reset the OOB state machine */ | |
1236 | scu_sas_pcfg_value = | |
1237 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
1238 | scu_sas_pcfg_value &= | |
1239 | ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE)); | |
1240 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET); | |
1241 | writel(scu_sas_pcfg_value, | |
1242 | &sci_phy->link_layer_registers->phy_configuration); | |
1243 | ||
1244 | /* Now restart the OOB operation */ | |
1245 | scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET); | |
1246 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); | |
1247 | writel(scu_sas_pcfg_value, | |
1248 | &sci_phy->link_layer_registers->phy_configuration); | |
1249 | ||
1250 | /* Change state to the final state this substate machine has run to completion */ | |
1251 | sci_base_state_machine_change_state(&sci_phy->starting_substate_machine, | |
1252 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN); | |
1253 | ||
1254 | return SCI_SUCCESS; | |
1255 | } | |
1256 | ||
1257 | static enum sci_status default_phy_handler(struct scic_sds_phy *sci_phy, | |
1258 | const char *func) | |
1259 | { | |
1260 | dev_dbg(sciphy_to_dev(sci_phy), | |
1261 | "%s: in wrong state: %d\n", func, | |
1262 | sci_base_state_machine_get_state(&sci_phy->state_machine)); | |
1263 | return SCI_FAILURE_INVALID_STATE; | |
1264 | } | |
1265 | ||
1266 | static enum sci_status | |
1267 | scic_sds_phy_default_start_handler(struct scic_sds_phy *sci_phy) | |
1268 | { | |
1269 | return default_phy_handler(sci_phy, __func__); | |
1270 | } | |
1271 | ||
1272 | static enum sci_status | |
1273 | scic_sds_phy_default_stop_handler(struct scic_sds_phy *sci_phy) | |
1274 | { | |
1275 | return default_phy_handler(sci_phy, __func__); | |
1276 | } | |
1277 | ||
1278 | static enum sci_status | |
1279 | scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy) | |
1280 | { | |
1281 | return default_phy_handler(sci_phy, __func__); | |
1282 | } | |
1283 | ||
1284 | static enum sci_status | |
1285 | scic_sds_phy_default_destroy_handler(struct scic_sds_phy *sci_phy) | |
1286 | { | |
1287 | return default_phy_handler(sci_phy, __func__); | |
1288 | } | |
1289 | ||
1290 | static enum sci_status | |
1291 | scic_sds_phy_default_frame_handler(struct scic_sds_phy *sci_phy, | |
1292 | u32 frame_index) | |
1293 | { | |
1294 | struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy); | |
1295 | ||
1296 | default_phy_handler(sci_phy, __func__); | |
1297 | scic_sds_controller_release_frame(scic, frame_index); | |
1298 | ||
1299 | return SCI_FAILURE_INVALID_STATE; | |
1300 | } | |
1301 | ||
1302 | static enum sci_status | |
1303 | scic_sds_phy_default_event_handler(struct scic_sds_phy *sci_phy, | |
1304 | u32 event_code) | |
1305 | { | |
1306 | return default_phy_handler(sci_phy, __func__); | |
1307 | } | |
1308 | ||
1309 | static enum sci_status | |
1310 | scic_sds_phy_default_consume_power_handler(struct scic_sds_phy *sci_phy) | |
1311 | { | |
1312 | return default_phy_handler(sci_phy, __func__); | |
1313 | } | |
1314 | ||
1315 | ||
1316 | ||
1317 | static const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_table[] = { | |
1318 | [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = { | |
1319 | .start_handler = scic_sds_phy_default_start_handler, | |
1320 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1321 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1322 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1323 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1324 | .event_handler = scic_sds_phy_default_event_handler, | |
1325 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1326 | }, | |
1327 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = { | |
1328 | .start_handler = scic_sds_phy_default_start_handler, | |
1329 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1330 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1331 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1332 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1333 | .event_handler = scic_sds_phy_starting_substate_await_ossp_event_handler, | |
1334 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1335 | }, | |
1336 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = { | |
1337 | .start_handler = scic_sds_phy_default_start_handler, | |
1338 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1339 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1340 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1341 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1342 | .event_handler = scic_sds_phy_starting_substate_await_sas_phy_speed_event_handler, | |
1343 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1344 | }, | |
1345 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = { | |
1346 | .start_handler = scic_sds_phy_default_start_handler, | |
1347 | .stop_handler = scic_sds_phy_default_stop_handler, | |
1348 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1349 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1350 | .frame_handler = scic_sds_phy_starting_substate_await_iaf_uf_frame_handler, | |
1351 | .event_handler = scic_sds_phy_starting_substate_await_iaf_uf_event_handler, | |
1352 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1353 | }, | |
1354 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = { | |
1355 | .start_handler = scic_sds_phy_default_start_handler, | |
1356 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1357 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1358 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1359 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1360 | .event_handler = scic_sds_phy_starting_substate_await_sas_power_event_handler, | |
1361 | .consume_power_handler = scic_sds_phy_starting_substate_await_sas_power_consume_power_handler | |
1362 | }, | |
1363 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = { | |
1364 | .start_handler = scic_sds_phy_default_start_handler, | |
1365 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1366 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1367 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1368 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1369 | .event_handler = scic_sds_phy_starting_substate_await_sata_power_event_handler, | |
1370 | .consume_power_handler = scic_sds_phy_starting_substate_await_sata_power_consume_power_handler | |
1371 | }, | |
1372 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = { | |
1373 | .start_handler = scic_sds_phy_default_start_handler, | |
1374 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1375 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1376 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1377 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1378 | .event_handler = scic_sds_phy_starting_substate_await_sata_phy_event_handler, | |
1379 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1380 | }, | |
1381 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = { | |
1382 | .start_handler = scic_sds_phy_default_start_handler, | |
1383 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1384 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1385 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1386 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1387 | .event_handler = scic_sds_phy_starting_substate_await_sata_speed_event_handler, | |
1388 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1389 | }, | |
1390 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = { | |
1391 | .start_handler = scic_sds_phy_default_start_handler, | |
1392 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1393 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1394 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1395 | .frame_handler = scic_sds_phy_starting_substate_await_sig_fis_frame_handler, | |
1396 | .event_handler = scic_sds_phy_starting_substate_await_sig_fis_event_handler, | |
1397 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1398 | }, | |
1399 | [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = { | |
1400 | .start_handler = scic_sds_phy_default_start_handler, | |
1401 | .stop_handler = scic_sds_phy_starting_substate_general_stop_handler, | |
1402 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1403 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1404 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1405 | .event_handler = scic_sds_phy_default_event_handler, | |
1406 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1407 | } | |
1408 | }; | |
1409 | ||
1410 | /** | |
1411 | * scic_sds_phy_set_starting_substate_handlers() - | |
1412 | * | |
1413 | * This macro sets the starting substate handlers by state_id | |
1414 | */ | |
1415 | #define scic_sds_phy_set_starting_substate_handlers(phy, state_id) \ | |
1416 | scic_sds_phy_set_state_handlers(\ | |
1417 | (phy), \ | |
1418 | &scic_sds_phy_starting_substate_handler_table[(state_id)] \ | |
1419 | ) | |
1420 | ||
1421 | /* | |
1422 | * **************************************************************************** | |
1423 | * * PHY STARTING SUBSTATE METHODS | |
1424 | * **************************************************************************** */ | |
1425 | ||
1426 | /** | |
1427 | * scic_sds_phy_starting_initial_substate_enter - | |
1428 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1429 | * | |
1430 | * This method will perform the actions required by the struct scic_sds_phy on | |
1431 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL. - The initial state | |
1432 | * handlers are put in place for the struct scic_sds_phy object. - The state is | |
1433 | * changed to the wait phy type event notification. none | |
1434 | */ | |
1435 | static void scic_sds_phy_starting_initial_substate_enter(void *object) | |
1436 | { | |
1437 | struct scic_sds_phy *sci_phy = object; | |
1438 | ||
1439 | scic_sds_phy_set_starting_substate_handlers( | |
1440 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL); | |
1441 | ||
1442 | /* This is just an temporary state go off to the starting state */ | |
1443 | sci_base_state_machine_change_state(&sci_phy->starting_substate_machine, | |
1444 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN); | |
1445 | } | |
1446 | ||
1447 | /** | |
1448 | * | |
1449 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1450 | * | |
1451 | * This method will perform the actions required by the struct scic_sds_phy on | |
1452 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_PHY_TYPE_EN. - Set the | |
1453 | * struct scic_sds_phy object state handlers for this state. none | |
1454 | */ | |
1455 | static void scic_sds_phy_starting_await_ossp_en_substate_enter(void *object) | |
1456 | { | |
1457 | struct scic_sds_phy *sci_phy = object; | |
1458 | ||
1459 | scic_sds_phy_set_starting_substate_handlers( | |
1460 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN | |
1461 | ); | |
1462 | } | |
1463 | ||
1464 | /** | |
1465 | * | |
1466 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1467 | * | |
1468 | * This method will perform the actions required by the struct scic_sds_phy on | |
1469 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SPEED_EN. - Set the | |
1470 | * struct scic_sds_phy object state handlers for this state. none | |
1471 | */ | |
1472 | static void scic_sds_phy_starting_await_sas_speed_en_substate_enter( | |
1473 | void *object) | |
1474 | { | |
1475 | struct scic_sds_phy *sci_phy = object; | |
1476 | ||
1477 | scic_sds_phy_set_starting_substate_handlers( | |
1478 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN | |
1479 | ); | |
1480 | } | |
1481 | ||
1482 | /** | |
1483 | * | |
1484 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1485 | * | |
1486 | * This method will perform the actions required by the struct scic_sds_phy on | |
1487 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF. - Set the | |
1488 | * struct scic_sds_phy object state handlers for this state. none | |
1489 | */ | |
1490 | static void scic_sds_phy_starting_await_iaf_uf_substate_enter(void *object) | |
1491 | { | |
1492 | struct scic_sds_phy *sci_phy = object; | |
1493 | ||
1494 | scic_sds_phy_set_starting_substate_handlers( | |
1495 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF | |
1496 | ); | |
1497 | } | |
1498 | ||
1499 | /** | |
1500 | * | |
1501 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1502 | * | |
1503 | * This method will perform the actions required by the struct scic_sds_phy on | |
1504 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Set the | |
1505 | * struct scic_sds_phy object state handlers for this state. - Add this phy object to | |
1506 | * the power control queue none | |
1507 | */ | |
1508 | static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object) | |
1509 | { | |
1510 | struct scic_sds_phy *sci_phy = object; | |
1511 | ||
1512 | scic_sds_phy_set_starting_substate_handlers( | |
1513 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER | |
1514 | ); | |
1515 | ||
1516 | scic_sds_controller_power_control_queue_insert( | |
1517 | scic_sds_phy_get_controller(sci_phy), | |
1518 | sci_phy | |
1519 | ); | |
1520 | } | |
1521 | ||
1522 | /** | |
1523 | * | |
1524 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1525 | * | |
1526 | * This method will perform the actions required by the struct scic_sds_phy on exiting | |
1527 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER. - Remove the | |
1528 | * struct scic_sds_phy object from the power control queue. none | |
1529 | */ | |
1530 | static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object) | |
1531 | { | |
1532 | struct scic_sds_phy *sci_phy = object; | |
1533 | ||
1534 | scic_sds_controller_power_control_queue_remove( | |
1535 | scic_sds_phy_get_controller(sci_phy), sci_phy | |
1536 | ); | |
1537 | } | |
1538 | ||
1539 | /** | |
1540 | * | |
1541 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1542 | * | |
1543 | * This method will perform the actions required by the struct scic_sds_phy on | |
1544 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Set the | |
1545 | * struct scic_sds_phy object state handlers for this state. - Add this phy object to | |
1546 | * the power control queue none | |
1547 | */ | |
1548 | static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object) | |
1549 | { | |
1550 | struct scic_sds_phy *sci_phy = object; | |
1551 | ||
1552 | scic_sds_phy_set_starting_substate_handlers( | |
1553 | sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER | |
1554 | ); | |
1555 | ||
1556 | scic_sds_controller_power_control_queue_insert( | |
1557 | scic_sds_phy_get_controller(sci_phy), | |
1558 | sci_phy | |
1559 | ); | |
1560 | } | |
1561 | ||
1562 | /** | |
1563 | * | |
1564 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1565 | * | |
1566 | * This method will perform the actions required by the struct scic_sds_phy on exiting | |
1567 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER. - Remove the | |
1568 | * struct scic_sds_phy object from the power control queue. none | |
1569 | */ | |
1570 | static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object) | |
1571 | { | |
1572 | struct scic_sds_phy *sci_phy = object; | |
1573 | ||
1574 | scic_sds_controller_power_control_queue_remove( | |
1575 | scic_sds_phy_get_controller(sci_phy), | |
1576 | sci_phy | |
1577 | ); | |
1578 | } | |
1579 | ||
1580 | /** | |
1581 | * | |
1582 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1583 | * | |
1584 | * This function will perform the actions required by the struct scic_sds_phy on | |
1585 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. - Set the | |
1586 | * struct scic_sds_phy object state handlers for this state. none | |
1587 | */ | |
1588 | static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object) | |
1589 | { | |
1590 | struct scic_sds_phy *sci_phy = object; | |
1591 | ||
1592 | scic_sds_phy_set_starting_substate_handlers( | |
1593 | sci_phy, | |
1594 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN); | |
1595 | ||
1596 | isci_timer_start(sci_phy->sata_timeout_timer, | |
1597 | SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT); | |
1598 | } | |
1599 | ||
1600 | /** | |
1601 | * | |
1602 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1603 | * | |
1604 | * This method will perform the actions required by the struct scic_sds_phy | |
1605 | * on exiting | |
1606 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer | |
1607 | * that was started on entry to await sata phy event notification none | |
1608 | */ | |
1609 | static inline void scic_sds_phy_starting_await_sata_phy_substate_exit( | |
1610 | void *object) | |
1611 | { | |
1612 | struct scic_sds_phy *sci_phy = object; | |
1613 | ||
1614 | isci_timer_stop(sci_phy->sata_timeout_timer); | |
1615 | } | |
1616 | ||
1617 | /** | |
1618 | * | |
1619 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1620 | * | |
1621 | * This method will perform the actions required by the struct scic_sds_phy on | |
1622 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - Set the | |
1623 | * struct scic_sds_phy object state handlers for this state. none | |
1624 | */ | |
1625 | static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object) | |
1626 | { | |
1627 | struct scic_sds_phy *sci_phy = object; | |
1628 | ||
1629 | scic_sds_phy_set_starting_substate_handlers( | |
1630 | sci_phy, | |
1631 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN); | |
1632 | ||
1633 | isci_timer_start(sci_phy->sata_timeout_timer, | |
1634 | SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT); | |
1635 | } | |
1636 | ||
1637 | /** | |
1638 | * | |
1639 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1640 | * | |
1641 | * This function will perform the actions required by the | |
1642 | * struct scic_sds_phy on exiting | |
1643 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN. - stop the timer | |
1644 | * that was started on entry to await sata phy event notification none | |
1645 | */ | |
1646 | static inline void scic_sds_phy_starting_await_sata_speed_substate_exit( | |
1647 | void *object) | |
1648 | { | |
1649 | struct scic_sds_phy *sci_phy = object; | |
1650 | ||
1651 | isci_timer_stop(sci_phy->sata_timeout_timer); | |
1652 | } | |
1653 | ||
1654 | /** | |
1655 | * | |
1656 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1657 | * | |
1658 | * This function will perform the actions required by the struct scic_sds_phy on | |
1659 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Set the | |
1660 | * struct scic_sds_phy object state handlers for this state. | |
1661 | * - Start the SIGNATURE FIS | |
1662 | * timeout timer none | |
1663 | */ | |
1664 | static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object) | |
1665 | { | |
1666 | bool continue_to_ready_state; | |
1667 | struct scic_sds_phy *sci_phy = object; | |
1668 | ||
1669 | scic_sds_phy_set_starting_substate_handlers( | |
1670 | sci_phy, | |
1671 | SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF); | |
1672 | ||
1673 | continue_to_ready_state = scic_sds_port_link_detected( | |
1674 | sci_phy->owning_port, | |
1675 | sci_phy); | |
1676 | ||
1677 | if (continue_to_ready_state) { | |
1678 | /* | |
1679 | * Clear the PE suspend condition so we can actually | |
1680 | * receive SIG FIS | |
1681 | * The hardware will not respond to the XRDY until the PE | |
1682 | * suspend condition is cleared. | |
1683 | */ | |
1684 | scic_sds_phy_resume(sci_phy); | |
1685 | ||
1686 | isci_timer_start(sci_phy->sata_timeout_timer, | |
1687 | SCIC_SDS_SIGNATURE_FIS_TIMEOUT); | |
1688 | } else | |
1689 | sci_phy->is_in_link_training = false; | |
1690 | } | |
1691 | ||
1692 | /** | |
1693 | * | |
1694 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1695 | * | |
1696 | * This function will perform the actions required by the | |
1697 | * struct scic_sds_phy on exiting | |
1698 | * the SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF. - Stop the SIGNATURE | |
1699 | * FIS timeout timer. none | |
1700 | */ | |
1701 | static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit( | |
1702 | void *object) | |
1703 | { | |
1704 | struct scic_sds_phy *sci_phy = object; | |
1705 | ||
1706 | isci_timer_stop(sci_phy->sata_timeout_timer); | |
1707 | } | |
1708 | ||
1709 | /** | |
1710 | * | |
1711 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
1712 | * | |
1713 | * This method will perform the actions required by the struct scic_sds_phy on | |
1714 | * entering the SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. - Set the struct scic_sds_phy | |
1715 | * object state handlers for this state. - Change base state machine to the | |
1716 | * ready state. none | |
1717 | */ | |
1718 | static void scic_sds_phy_starting_final_substate_enter(void *object) | |
1719 | { | |
1720 | struct scic_sds_phy *sci_phy = object; | |
1721 | ||
1722 | scic_sds_phy_set_starting_substate_handlers(sci_phy, | |
1723 | SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL); | |
1724 | ||
1725 | /* State machine has run to completion so exit out and change | |
1726 | * the base state machine to the ready state | |
1727 | */ | |
1728 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1729 | SCI_BASE_PHY_STATE_READY); | |
1730 | } | |
1731 | ||
1732 | /* --------------------------------------------------------------------------- */ | |
1733 | ||
1734 | static const struct sci_base_state scic_sds_phy_starting_substates[] = { | |
1735 | [SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = { | |
1736 | .enter_state = scic_sds_phy_starting_initial_substate_enter, | |
1737 | }, | |
1738 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = { | |
1739 | .enter_state = scic_sds_phy_starting_await_ossp_en_substate_enter, | |
1740 | }, | |
1741 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = { | |
1742 | .enter_state = scic_sds_phy_starting_await_sas_speed_en_substate_enter, | |
1743 | }, | |
1744 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = { | |
1745 | .enter_state = scic_sds_phy_starting_await_iaf_uf_substate_enter, | |
1746 | }, | |
1747 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = { | |
1748 | .enter_state = scic_sds_phy_starting_await_sas_power_substate_enter, | |
1749 | .exit_state = scic_sds_phy_starting_await_sas_power_substate_exit, | |
1750 | }, | |
1751 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = { | |
1752 | .enter_state = scic_sds_phy_starting_await_sata_power_substate_enter, | |
1753 | .exit_state = scic_sds_phy_starting_await_sata_power_substate_exit | |
1754 | }, | |
1755 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = { | |
1756 | .enter_state = scic_sds_phy_starting_await_sata_phy_substate_enter, | |
1757 | .exit_state = scic_sds_phy_starting_await_sata_phy_substate_exit | |
1758 | }, | |
1759 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = { | |
1760 | .enter_state = scic_sds_phy_starting_await_sata_speed_substate_enter, | |
1761 | .exit_state = scic_sds_phy_starting_await_sata_speed_substate_exit | |
1762 | }, | |
1763 | [SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = { | |
1764 | .enter_state = scic_sds_phy_starting_await_sig_fis_uf_substate_enter, | |
1765 | .exit_state = scic_sds_phy_starting_await_sig_fis_uf_substate_exit | |
1766 | }, | |
1767 | [SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = { | |
1768 | .enter_state = scic_sds_phy_starting_final_substate_enter, | |
1769 | } | |
1770 | }; | |
1771 | ||
1772 | /* | |
1773 | * This method takes the struct scic_sds_phy from a stopped state and | |
1774 | * attempts to start it. - The phy state machine is transitioned to the | |
1775 | * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS | |
1776 | */ | |
1777 | static enum sci_status | |
1778 | scic_sds_phy_stopped_state_start_handler(struct scic_sds_phy *sci_phy) | |
1779 | { | |
1780 | struct isci_host *ihost; | |
1781 | struct scic_sds_controller *scic; | |
1782 | ||
1783 | scic = scic_sds_phy_get_controller(sci_phy), | |
1784 | ihost = scic_to_ihost(scic); | |
1785 | ||
1786 | /* Create the SIGNATURE FIS Timeout timer for this phy */ | |
1787 | sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy, | |
1788 | scic_sds_phy_sata_timeout); | |
1789 | ||
1790 | if (sci_phy->sata_timeout_timer) | |
1791 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1792 | SCI_BASE_PHY_STATE_STARTING); | |
1793 | ||
1794 | return SCI_SUCCESS; | |
1795 | } | |
1796 | ||
1797 | static enum sci_status | |
1798 | scic_sds_phy_stopped_state_destroy_handler(struct scic_sds_phy *sci_phy) | |
1799 | { | |
1800 | return SCI_SUCCESS; | |
1801 | } | |
1802 | ||
1803 | static enum sci_status | |
1804 | scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy *sci_phy) | |
1805 | { | |
1806 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1807 | SCI_BASE_PHY_STATE_STOPPED); | |
1808 | ||
1809 | return SCI_SUCCESS; | |
1810 | } | |
1811 | ||
1812 | static enum sci_status | |
1813 | scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy) | |
1814 | { | |
1815 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1816 | SCI_BASE_PHY_STATE_RESETTING); | |
1817 | ||
1818 | return SCI_SUCCESS; | |
1819 | } | |
1820 | ||
1821 | /** | |
1822 | * scic_sds_phy_ready_state_event_handler - | |
1823 | * @phy: This is the struct scic_sds_phy object which has received the event. | |
1824 | * | |
1825 | * This method request the struct scic_sds_phy handle the received event. The only | |
1826 | * event that we are interested in while in the ready state is the link failure | |
1827 | * event. - decoded event is a link failure - transition the struct scic_sds_phy back | |
1828 | * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will | |
1829 | * report a warning message enum sci_status SCI_SUCCESS if the event received is a | |
1830 | * link failure SCI_FAILURE_INVALID_STATE for any other event received. | |
1831 | */ | |
1832 | static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy, | |
1833 | u32 event_code) | |
1834 | { | |
1835 | enum sci_status result = SCI_FAILURE; | |
1836 | ||
1837 | switch (scu_get_event_code(event_code)) { | |
1838 | case SCU_EVENT_LINK_FAILURE: | |
1839 | /* Link failure change state back to the starting state */ | |
1840 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1841 | SCI_BASE_PHY_STATE_STARTING); | |
1842 | result = SCI_SUCCESS; | |
1843 | break; | |
1844 | ||
1845 | case SCU_EVENT_BROADCAST_CHANGE: | |
1846 | /* Broadcast change received. Notify the port. */ | |
1847 | if (scic_sds_phy_get_port(sci_phy) != NULL) | |
1848 | scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy); | |
1849 | else | |
1850 | sci_phy->bcn_received_while_port_unassigned = true; | |
1851 | break; | |
1852 | ||
1853 | default: | |
1854 | dev_warn(sciphy_to_dev(sci_phy), | |
1855 | "%sP SCIC PHY 0x%p ready state machine received " | |
1856 | "unexpected event_code %x\n", | |
1857 | __func__, sci_phy, event_code); | |
1858 | ||
1859 | result = SCI_FAILURE_INVALID_STATE; | |
1860 | break; | |
1861 | } | |
1862 | ||
1863 | return result; | |
1864 | } | |
1865 | ||
1866 | static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy, | |
1867 | u32 event_code) | |
1868 | { | |
1869 | enum sci_status result = SCI_FAILURE; | |
1870 | ||
1871 | switch (scu_get_event_code(event_code)) { | |
1872 | case SCU_EVENT_HARD_RESET_TRANSMITTED: | |
1873 | /* Link failure change state back to the starting state */ | |
1874 | sci_base_state_machine_change_state(&sci_phy->state_machine, | |
1875 | SCI_BASE_PHY_STATE_STARTING); | |
1876 | result = SCI_SUCCESS; | |
1877 | break; | |
1878 | ||
1879 | default: | |
1880 | dev_warn(sciphy_to_dev(sci_phy), | |
1881 | "%s: SCIC PHY 0x%p resetting state machine received " | |
1882 | "unexpected event_code %x\n", | |
1883 | __func__, sci_phy, event_code); | |
1884 | ||
1885 | result = SCI_FAILURE_INVALID_STATE; | |
1886 | break; | |
1887 | } | |
1888 | ||
1889 | return result; | |
1890 | } | |
1891 | ||
1892 | /* --------------------------------------------------------------------------- */ | |
1893 | ||
1894 | static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = { | |
1895 | [SCI_BASE_PHY_STATE_INITIAL] = { | |
1896 | .start_handler = scic_sds_phy_default_start_handler, | |
1897 | .stop_handler = scic_sds_phy_default_stop_handler, | |
1898 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1899 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1900 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1901 | .event_handler = scic_sds_phy_default_event_handler, | |
1902 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1903 | }, | |
1904 | [SCI_BASE_PHY_STATE_STOPPED] = { | |
1905 | .start_handler = scic_sds_phy_stopped_state_start_handler, | |
1906 | .stop_handler = scic_sds_phy_default_stop_handler, | |
1907 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1908 | .destruct_handler = scic_sds_phy_stopped_state_destroy_handler, | |
1909 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1910 | .event_handler = scic_sds_phy_default_event_handler, | |
1911 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1912 | }, | |
1913 | [SCI_BASE_PHY_STATE_STARTING] = { | |
1914 | .start_handler = scic_sds_phy_default_start_handler, | |
1915 | .stop_handler = scic_sds_phy_default_stop_handler, | |
1916 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1917 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1918 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1919 | .event_handler = scic_sds_phy_default_event_handler, | |
1920 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1921 | }, | |
1922 | [SCI_BASE_PHY_STATE_READY] = { | |
1923 | .start_handler = scic_sds_phy_default_start_handler, | |
1924 | .stop_handler = scic_sds_phy_ready_state_stop_handler, | |
1925 | .reset_handler = scic_sds_phy_ready_state_reset_handler, | |
1926 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1927 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1928 | .event_handler = scic_sds_phy_ready_state_event_handler, | |
1929 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1930 | }, | |
1931 | [SCI_BASE_PHY_STATE_RESETTING] = { | |
1932 | .start_handler = scic_sds_phy_default_start_handler, | |
1933 | .stop_handler = scic_sds_phy_default_stop_handler, | |
1934 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1935 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1936 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1937 | .event_handler = scic_sds_phy_resetting_state_event_handler, | |
1938 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1939 | }, | |
1940 | [SCI_BASE_PHY_STATE_FINAL] = { | |
1941 | .start_handler = scic_sds_phy_default_start_handler, | |
1942 | .stop_handler = scic_sds_phy_default_stop_handler, | |
1943 | .reset_handler = scic_sds_phy_default_reset_handler, | |
1944 | .destruct_handler = scic_sds_phy_default_destroy_handler, | |
1945 | .frame_handler = scic_sds_phy_default_frame_handler, | |
1946 | .event_handler = scic_sds_phy_default_event_handler, | |
1947 | .consume_power_handler = scic_sds_phy_default_consume_power_handler | |
1948 | } | |
1949 | }; | |
1950 | ||
1951 | /* | |
1952 | * **************************************************************************** | |
1953 | * * PHY STATE PRIVATE METHODS | |
1954 | * **************************************************************************** */ | |
1955 | ||
1956 | /** | |
1957 | * | |
1958 | * @sci_phy: This is the struct scic_sds_phy object to stop. | |
1959 | * | |
1960 | * This method will stop the struct scic_sds_phy object. This does not reset the | |
1961 | * protocol engine it just suspends it and places it in a state where it will | |
1962 | * not cause the end device to power up. none | |
1963 | */ | |
1964 | static void scu_link_layer_stop_protocol_engine( | |
1965 | struct scic_sds_phy *sci_phy) | |
1966 | { | |
1967 | u32 scu_sas_pcfg_value; | |
1968 | u32 enable_spinup_value; | |
1969 | ||
1970 | /* Suspend the protocol engine and place it in a sata spinup hold state */ | |
1971 | scu_sas_pcfg_value = | |
1972 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
1973 | scu_sas_pcfg_value |= | |
1974 | (SCU_SAS_PCFG_GEN_BIT(OOB_RESET) | | |
1975 | SCU_SAS_PCFG_GEN_BIT(SUSPEND_PROTOCOL_ENGINE) | | |
1976 | SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD)); | |
1977 | writel(scu_sas_pcfg_value, | |
1978 | &sci_phy->link_layer_registers->phy_configuration); | |
1979 | ||
1980 | /* Disable the notify enable spinup primitives */ | |
1981 | enable_spinup_value = readl(&sci_phy->link_layer_registers->notify_enable_spinup_control); | |
1982 | enable_spinup_value &= ~SCU_ENSPINUP_GEN_BIT(ENABLE); | |
1983 | writel(enable_spinup_value, &sci_phy->link_layer_registers->notify_enable_spinup_control); | |
1984 | } | |
1985 | ||
1986 | /** | |
1987 | * | |
1988 | * | |
1989 | * This method will start the OOB/SN state machine for this struct scic_sds_phy object. | |
1990 | */ | |
1991 | static void scu_link_layer_start_oob( | |
1992 | struct scic_sds_phy *sci_phy) | |
1993 | { | |
1994 | u32 scu_sas_pcfg_value; | |
1995 | ||
1996 | scu_sas_pcfg_value = | |
1997 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
1998 | scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); | |
1999 | scu_sas_pcfg_value &= | |
2000 | ~(SCU_SAS_PCFG_GEN_BIT(OOB_RESET) | | |
2001 | SCU_SAS_PCFG_GEN_BIT(HARD_RESET)); | |
2002 | writel(scu_sas_pcfg_value, | |
2003 | &sci_phy->link_layer_registers->phy_configuration); | |
2004 | } | |
2005 | ||
2006 | /** | |
2007 | * | |
2008 | * | |
2009 | * This method will transmit a hard reset request on the specified phy. The SCU | |
2010 | * hardware requires that we reset the OOB state machine and set the hard reset | |
2011 | * bit in the phy configuration register. We then must start OOB over with the | |
2012 | * hard reset bit set. | |
2013 | */ | |
2014 | static void scu_link_layer_tx_hard_reset( | |
2015 | struct scic_sds_phy *sci_phy) | |
2016 | { | |
2017 | u32 phy_configuration_value; | |
2018 | ||
2019 | /* | |
2020 | * SAS Phys must wait for the HARD_RESET_TX event notification to transition | |
2021 | * to the starting state. */ | |
2022 | phy_configuration_value = | |
2023 | readl(&sci_phy->link_layer_registers->phy_configuration); | |
2024 | phy_configuration_value |= | |
2025 | (SCU_SAS_PCFG_GEN_BIT(HARD_RESET) | | |
2026 | SCU_SAS_PCFG_GEN_BIT(OOB_RESET)); | |
2027 | writel(phy_configuration_value, | |
2028 | &sci_phy->link_layer_registers->phy_configuration); | |
2029 | ||
2030 | /* Now take the OOB state machine out of reset */ | |
2031 | phy_configuration_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE); | |
2032 | phy_configuration_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET); | |
2033 | writel(phy_configuration_value, | |
2034 | &sci_phy->link_layer_registers->phy_configuration); | |
2035 | } | |
2036 | ||
2037 | /* | |
2038 | * **************************************************************************** | |
2039 | * * PHY BASE STATE METHODS | |
2040 | * **************************************************************************** */ | |
2041 | ||
2042 | /** | |
2043 | * | |
2044 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
2045 | * | |
2046 | * This method will perform the actions required by the struct scic_sds_phy on | |
2047 | * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state | |
2048 | * handlers for the phy object base state machine initial state. none | |
2049 | */ | |
2050 | static void scic_sds_phy_initial_state_enter(void *object) | |
2051 | { | |
2052 | struct scic_sds_phy *sci_phy = object; | |
2053 | ||
2054 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_INITIAL); | |
2055 | } | |
2056 | ||
2057 | /** | |
2058 | * | |
2059 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
2060 | * | |
2061 | * This function will perform the actions required by the struct scic_sds_phy on | |
2062 | * entering the SCI_BASE_PHY_STATE_INITIAL. - This function sets the state | |
2063 | * handlers for the phy object base state machine initial state. - The SCU | |
2064 | * hardware is requested to stop the protocol engine. none | |
2065 | */ | |
2066 | static void scic_sds_phy_stopped_state_enter(void *object) | |
2067 | { | |
2068 | struct scic_sds_phy *sci_phy = object; | |
2069 | struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy); | |
2070 | struct isci_host *ihost = scic_to_ihost(scic); | |
2071 | ||
2072 | /* | |
2073 | * @todo We need to get to the controller to place this PE in a | |
2074 | * reset state | |
2075 | */ | |
2076 | ||
2077 | scic_sds_phy_set_base_state_handlers(sci_phy, | |
2078 | SCI_BASE_PHY_STATE_STOPPED); | |
2079 | ||
2080 | if (sci_phy->sata_timeout_timer != NULL) { | |
2081 | isci_del_timer(ihost, sci_phy->sata_timeout_timer); | |
2082 | ||
2083 | sci_phy->sata_timeout_timer = NULL; | |
2084 | } | |
2085 | ||
2086 | scu_link_layer_stop_protocol_engine(sci_phy); | |
2087 | ||
2088 | if (sci_phy->state_machine.previous_state_id != | |
2089 | SCI_BASE_PHY_STATE_INITIAL) | |
2090 | scic_sds_controller_link_down( | |
2091 | scic_sds_phy_get_controller(sci_phy), | |
2092 | scic_sds_phy_get_port(sci_phy), | |
2093 | sci_phy); | |
2094 | } | |
2095 | ||
2096 | /** | |
2097 | * | |
2098 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
2099 | * | |
2100 | * This method will perform the actions required by the struct scic_sds_phy on | |
2101 | * entering the SCI_BASE_PHY_STATE_STARTING. - This function sets the state | |
2102 | * handlers for the phy object base state machine starting state. - The SCU | |
2103 | * hardware is requested to start OOB/SN on this protocl engine. - The phy | |
2104 | * starting substate machine is started. - If the previous state was the ready | |
2105 | * state then the struct scic_sds_controller is informed that the phy has gone link | |
2106 | * down. none | |
2107 | */ | |
2108 | static void scic_sds_phy_starting_state_enter(void *object) | |
2109 | { | |
2110 | struct scic_sds_phy *sci_phy = object; | |
2111 | ||
2112 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_STARTING); | |
2113 | ||
2114 | scu_link_layer_stop_protocol_engine(sci_phy); | |
2115 | scu_link_layer_start_oob(sci_phy); | |
2116 | ||
2117 | /* We don't know what kind of phy we are going to be just yet */ | |
2118 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN; | |
2119 | sci_phy->bcn_received_while_port_unassigned = false; | |
2120 | ||
2121 | /* Change over to the starting substate machine to continue */ | |
2122 | sci_base_state_machine_start(&sci_phy->starting_substate_machine); | |
2123 | ||
2124 | if (sci_phy->state_machine.previous_state_id | |
2125 | == SCI_BASE_PHY_STATE_READY) { | |
2126 | scic_sds_controller_link_down( | |
2127 | scic_sds_phy_get_controller(sci_phy), | |
2128 | scic_sds_phy_get_port(sci_phy), | |
2129 | sci_phy | |
2130 | ); | |
2131 | } | |
2132 | } | |
2133 | ||
2134 | /** | |
2135 | * | |
2136 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
2137 | * | |
2138 | * This method will perform the actions required by the struct scic_sds_phy on | |
2139 | * entering the SCI_BASE_PHY_STATE_READY. - This function sets the state | |
2140 | * handlers for the phy object base state machine ready state. - The SCU | |
2141 | * hardware protocol engine is resumed. - The struct scic_sds_controller is informed | |
2142 | * that the phy object has gone link up. none | |
2143 | */ | |
2144 | static void scic_sds_phy_ready_state_enter(void *object) | |
2145 | { | |
2146 | struct scic_sds_phy *sci_phy = object; | |
2147 | ||
2148 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_READY); | |
2149 | ||
2150 | scic_sds_controller_link_up( | |
2151 | scic_sds_phy_get_controller(sci_phy), | |
2152 | scic_sds_phy_get_port(sci_phy), | |
2153 | sci_phy | |
2154 | ); | |
2155 | } | |
2156 | ||
2157 | /** | |
2158 | * | |
2159 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
2160 | * | |
2161 | * This method will perform the actions required by the struct scic_sds_phy on exiting | |
2162 | * the SCI_BASE_PHY_STATE_INITIAL. This function suspends the SCU hardware | |
2163 | * protocol engine represented by this struct scic_sds_phy object. none | |
2164 | */ | |
2165 | static void scic_sds_phy_ready_state_exit(void *object) | |
2166 | { | |
2167 | struct scic_sds_phy *sci_phy = object; | |
2168 | ||
2169 | scic_sds_phy_suspend(sci_phy); | |
2170 | } | |
2171 | ||
2172 | /** | |
2173 | * | |
2174 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
2175 | * | |
2176 | * This method will perform the actions required by the struct scic_sds_phy on | |
2177 | * entering the SCI_BASE_PHY_STATE_RESETTING. - This function sets the state | |
2178 | * handlers for the phy object base state machine resetting state. none | |
2179 | */ | |
2180 | static void scic_sds_phy_resetting_state_enter(void *object) | |
2181 | { | |
2182 | struct scic_sds_phy *sci_phy = object; | |
2183 | ||
2184 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_RESETTING); | |
2185 | ||
2186 | /* | |
2187 | * The phy is being reset, therefore deactivate it from the port. | |
2188 | * In the resetting state we don't notify the user regarding | |
2189 | * link up and link down notifications. */ | |
2190 | scic_sds_port_deactivate_phy(sci_phy->owning_port, sci_phy, false); | |
2191 | ||
2192 | if (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) { | |
2193 | scu_link_layer_tx_hard_reset(sci_phy); | |
2194 | } else { | |
2195 | /* | |
2196 | * The SCU does not need to have a discrete reset state so | |
2197 | * just go back to the starting state. | |
2198 | */ | |
2199 | sci_base_state_machine_change_state( | |
2200 | &sci_phy->state_machine, | |
2201 | SCI_BASE_PHY_STATE_STARTING); | |
2202 | } | |
2203 | } | |
2204 | ||
2205 | /** | |
2206 | * | |
2207 | * @object: This is the object which is cast to a struct scic_sds_phy object. | |
2208 | * | |
2209 | * This method will perform the actions required by the struct scic_sds_phy on | |
2210 | * entering the SCI_BASE_PHY_STATE_FINAL. - This function sets the state | |
2211 | * handlers for the phy object base state machine final state. none | |
2212 | */ | |
2213 | static void scic_sds_phy_final_state_enter(void *object) | |
2214 | { | |
2215 | struct scic_sds_phy *sci_phy = object; | |
2216 | ||
2217 | scic_sds_phy_set_base_state_handlers(sci_phy, SCI_BASE_PHY_STATE_FINAL); | |
2218 | ||
2219 | /* Nothing to do here */ | |
2220 | } | |
2221 | ||
2222 | /* --------------------------------------------------------------------------- */ | |
2223 | ||
2224 | static const struct sci_base_state scic_sds_phy_state_table[] = { | |
2225 | [SCI_BASE_PHY_STATE_INITIAL] = { | |
2226 | .enter_state = scic_sds_phy_initial_state_enter, | |
2227 | }, | |
2228 | [SCI_BASE_PHY_STATE_STOPPED] = { | |
2229 | .enter_state = scic_sds_phy_stopped_state_enter, | |
2230 | }, | |
2231 | [SCI_BASE_PHY_STATE_STARTING] = { | |
2232 | .enter_state = scic_sds_phy_starting_state_enter, | |
2233 | }, | |
2234 | [SCI_BASE_PHY_STATE_READY] = { | |
2235 | .enter_state = scic_sds_phy_ready_state_enter, | |
2236 | .exit_state = scic_sds_phy_ready_state_exit, | |
2237 | }, | |
2238 | [SCI_BASE_PHY_STATE_RESETTING] = { | |
2239 | .enter_state = scic_sds_phy_resetting_state_enter, | |
2240 | }, | |
2241 | [SCI_BASE_PHY_STATE_FINAL] = { | |
2242 | .enter_state = scic_sds_phy_final_state_enter, | |
2243 | }, | |
2244 | }; | |
2245 | ||
2246 | void scic_sds_phy_construct(struct scic_sds_phy *sci_phy, | |
2247 | struct scic_sds_port *owning_port, u8 phy_index) | |
2248 | { | |
2249 | sci_base_state_machine_construct(&sci_phy->state_machine, | |
2250 | sci_phy, | |
2251 | scic_sds_phy_state_table, | |
2252 | SCI_BASE_PHY_STATE_INITIAL); | |
2253 | ||
2254 | sci_base_state_machine_start(&sci_phy->state_machine); | |
2255 | ||
2256 | /* Copy the rest of the input data to our locals */ | |
2257 | sci_phy->owning_port = owning_port; | |
2258 | sci_phy->phy_index = phy_index; | |
2259 | sci_phy->bcn_received_while_port_unassigned = false; | |
2260 | sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_UNKNOWN; | |
2261 | sci_phy->link_layer_registers = NULL; | |
2262 | sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; | |
2263 | sci_phy->sata_timeout_timer = NULL; | |
2264 | ||
2265 | /* Initialize the the substate machines */ | |
2266 | sci_base_state_machine_construct(&sci_phy->starting_substate_machine, | |
2267 | sci_phy, | |
2268 | scic_sds_phy_starting_substates, | |
2269 | SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL); | |
2270 | } | |
6f231dda | 2271 | |
4b33981a | 2272 | void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index) |
6f231dda | 2273 | { |
150fc6fc | 2274 | union scic_oem_parameters oem; |
4b33981a DW |
2275 | u64 sci_sas_addr; |
2276 | __be64 sas_addr; | |
2277 | ||
2278 | scic_oem_parameters_get(&ihost->sci, &oem); | |
2279 | sci_sas_addr = oem.sds1.phys[index].sas_address.high; | |
2280 | sci_sas_addr <<= 32; | |
2281 | sci_sas_addr |= oem.sds1.phys[index].sas_address.low; | |
2282 | sas_addr = cpu_to_be64(sci_sas_addr); | |
2283 | memcpy(iphy->sas_addr, &sas_addr, sizeof(sas_addr)); | |
2284 | ||
2285 | iphy->isci_port = NULL; | |
2286 | iphy->sas_phy.enabled = 0; | |
2287 | iphy->sas_phy.id = index; | |
2288 | iphy->sas_phy.sas_addr = &iphy->sas_addr[0]; | |
2289 | iphy->sas_phy.frame_rcvd = (u8 *)&iphy->frame_rcvd; | |
2290 | iphy->sas_phy.ha = &ihost->sas_ha; | |
2291 | iphy->sas_phy.lldd_phy = iphy; | |
2292 | iphy->sas_phy.enabled = 1; | |
2293 | iphy->sas_phy.class = SAS; | |
2294 | iphy->sas_phy.iproto = SAS_PROTOCOL_ALL; | |
2295 | iphy->sas_phy.tproto = 0; | |
2296 | iphy->sas_phy.type = PHY_TYPE_PHYSICAL; | |
2297 | iphy->sas_phy.role = PHY_ROLE_INITIATOR; | |
2298 | iphy->sas_phy.oob_mode = OOB_NOT_CONNECTED; | |
2299 | iphy->sas_phy.linkrate = SAS_LINK_RATE_UNKNOWN; | |
2300 | memset(&iphy->frame_rcvd, 0, sizeof(iphy->frame_rcvd)); | |
6f231dda DW |
2301 | } |
2302 | ||
2303 | ||
2304 | /** | |
2305 | * isci_phy_control() - This function is one of the SAS Domain Template | |
2306 | * functions. This is a phy management function. | |
2307 | * @phy: This parameter specifies the sphy being controlled. | |
2308 | * @func: This parameter specifies the phy control function being invoked. | |
2309 | * @buf: This parameter is specific to the phy function being invoked. | |
2310 | * | |
2311 | * status, zero indicates success. | |
2312 | */ | |
4d07f7f3 DJ |
2313 | int isci_phy_control(struct asd_sas_phy *sas_phy, |
2314 | enum phy_func func, | |
2315 | void *buf) | |
6f231dda | 2316 | { |
4d07f7f3 DJ |
2317 | int ret = 0; |
2318 | struct isci_phy *iphy = sas_phy->lldd_phy; | |
2319 | struct isci_port *iport = iphy->isci_port; | |
2320 | struct isci_host *ihost = sas_phy->ha->lldd_ha; | |
2321 | unsigned long flags; | |
6f231dda | 2322 | |
4d07f7f3 DJ |
2323 | dev_dbg(&ihost->pdev->dev, |
2324 | "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n", | |
2325 | __func__, sas_phy, func, buf, iphy, iport); | |
6f231dda DW |
2326 | |
2327 | switch (func) { | |
4d07f7f3 DJ |
2328 | case PHY_FUNC_DISABLE: |
2329 | spin_lock_irqsave(&ihost->scic_lock, flags); | |
4b33981a | 2330 | scic_sds_phy_stop(&iphy->sci); |
4d07f7f3 DJ |
2331 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
2332 | break; | |
2333 | ||
6f231dda | 2334 | case PHY_FUNC_LINK_RESET: |
4d07f7f3 | 2335 | spin_lock_irqsave(&ihost->scic_lock, flags); |
4b33981a DW |
2336 | scic_sds_phy_stop(&iphy->sci); |
2337 | scic_sds_phy_start(&iphy->sci); | |
4d07f7f3 DJ |
2338 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
2339 | break; | |
2340 | ||
2341 | case PHY_FUNC_HARD_RESET: | |
2342 | if (!iport) | |
2343 | return -ENODEV; | |
6f231dda DW |
2344 | |
2345 | /* Perform the port reset. */ | |
4393aa4e | 2346 | ret = isci_port_perform_hard_reset(ihost, iport, iphy); |
6f231dda DW |
2347 | |
2348 | break; | |
2349 | ||
6f231dda | 2350 | default: |
4d07f7f3 DJ |
2351 | dev_dbg(&ihost->pdev->dev, |
2352 | "%s: phy %p; func %d NOT IMPLEMENTED!\n", | |
2353 | __func__, sas_phy, func); | |
2354 | ret = -ENOSYS; | |
6f231dda DW |
2355 | break; |
2356 | } | |
2357 | return ret; | |
2358 | } |