64 static const char *phy_state_name(
enum sci_phy_states
state)
66 static const char *
const strings[] =
PHY_STATES;
68 return strings[
state];
73 #define SCIC_SDS_PHY_MAX_ARBITRATION_WAIT_TIME (700)
90 return &phy_to_host(iphy)->pdev->dev;
94 sci_phy_transport_layer_initialization(
struct isci_phy *iphy,
116 sci_phy_link_layer_initialization(
struct isci_phy *iphy,
120 struct sci_phy_user_params *phy_user;
124 u32 phy_configuration;
125 u32 parity_check = 0;
126 u32 parity_count = 0;
136 #define SCI_END_DEVICE 0x01
143 &llr->transmit_identification);
146 writel(0xFEDCBA98, &llr->sas_device_name_high);
147 writel(phy_idx, &llr->sas_device_name_low);
154 writel(0, &llr->identify_frame_phy_id);
158 phy_configuration =
readl(&llr->phy_configuration);
162 writel(phy_configuration, &llr->phy_configuration);
167 phy_cap.gen3_no_ssc = 1;
168 phy_cap.gen2_no_ssc = 1;
169 phy_cap.gen1_no_ssc = 1;
175 bool en_sata =
false;
177 u32 sata_spread = 0x2;
178 u32 sas_spread = 0x2;
180 phy_cap.gen3_ssc = 1;
181 phy_cap.gen2_ssc = 1;
182 phy_cap.gen1_ssc = 1;
185 en_sas = en_sata =
true;
187 sata_spread = ihost->
oem_parameters.controller.ssc_sata_tx_spread_level;
188 sas_spread = ihost->
oem_parameters.controller.ssc_sas_tx_spread_level;
204 reg |= (0x00100000 | (sas_type << 19));
208 reg |= sas_spread << 8;
219 reg =
readl(&llr->stp_control);
221 writel(reg, &llr->stp_control);
228 parity_check = phy_cap.all;
229 while (parity_check != 0) {
230 if (parity_check & 0x1)
238 if ((parity_count % 2) != 0)
241 writel(phy_cap.all, &llr->phy_capabilities);
247 phy_user->notify_enable_spin_up_insertion_frequency),
248 &llr->notify_enable_spinup_control);
254 phy_user->in_connection_align_insertion_frequency);
257 phy_user->align_insertion_frequency);
259 writel(clksm_value, &llr->clock_skew_management);
261 if (is_c0(ihost->
pdev) || is_c1(ihost->
pdev)) {
262 writel(0x04210400, &llr->afe_lookup_table_control);
263 writel(0x020A7C05, &llr->sas_primitive_timeout);
265 writel(0x02108421, &llr->afe_lookup_table_control);
270 switch (phy_user->max_speed_generation) {
271 case SCIC_SDS_PARM_GEN3_SPEED:
274 case SCIC_SDS_PARM_GEN2_SPEED:
282 writel(llctl, &llr->link_layer_control);
284 sp_timeouts =
readl(&llr->sas_phy_timeouts);
294 writel(sp_timeouts, &llr->sas_phy_timeouts);
296 if (is_a2(ihost->
pdev)) {
304 &llr->maximum_arbitration_wait_timer_timeout);
310 writel(0, &llr->link_layer_hang_detection_timeout);
318 static void phy_sata_timeout(
unsigned long data)
331 "%s: SCIC SDS Phy 0x%p did not receive signature fis before "
338 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
387 sci_phy_transport_layer_initialization(iphy, tl);
390 sci_phy_link_layer_initialization(iphy, ll);
424 static void sci_phy_suspend(
struct isci_phy *iphy)
426 u32 scu_sas_pcfg_value;
431 writel(scu_sas_pcfg_value,
439 u32 scu_sas_pcfg_value;
444 writel(scu_sas_pcfg_value,
456 struct sas_identify_frame *iaf;
469 enum sci_phy_states
state = iphy->
sm.current_state_id;
471 if (state != SCI_PHY_STOPPED) {
472 dev_dbg(sciphy_to_dev(iphy),
"%s: in wrong state: %s\n",
473 __func__, phy_state_name(state));
483 enum sci_phy_states
state = iphy->
sm.current_state_id;
486 case SCI_PHY_SUB_INITIAL:
487 case SCI_PHY_SUB_AWAIT_OSSP_EN:
488 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
489 case SCI_PHY_SUB_AWAIT_SAS_POWER:
490 case SCI_PHY_SUB_AWAIT_SATA_POWER:
491 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
492 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
493 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
494 case SCI_PHY_SUB_FINAL:
498 dev_dbg(sciphy_to_dev(iphy),
"%s: in wrong state: %s\n",
499 __func__, phy_state_name(state));
509 enum sci_phy_states
state = iphy->
sm.current_state_id;
511 if (state != SCI_PHY_READY) {
512 dev_dbg(sciphy_to_dev(iphy),
"%s: in wrong state: %s\n",
513 __func__, phy_state_name(state));
523 enum sci_phy_states
state = iphy->
sm.current_state_id;
526 case SCI_PHY_SUB_AWAIT_SAS_POWER: {
538 case SCI_PHY_SUB_AWAIT_SATA_POWER: {
539 u32 scu_sas_pcfg_value;
544 scu_sas_pcfg_value &=
547 writel(scu_sas_pcfg_value,
553 writel(scu_sas_pcfg_value,
562 dev_dbg(sciphy_to_dev(iphy),
"%s: in wrong state: %s\n",
563 __func__, phy_state_name(state));
568 static void sci_phy_start_sas_link_training(
struct isci_phy *iphy)
586 static void sci_phy_start_sata_link_training(
struct isci_phy *iphy)
608 static void sci_phy_complete_link_training(
struct isci_phy *iphy,
621 return "port selector";
623 return "port selection";
625 return "tx hard reset";
627 return "rx hard reset";
629 return "identify timeout";
633 return "sata spinup hold";
655 return "sata detect";
661 #define phy_event_dbg(iphy, state, code) \
662 dev_dbg(sciphy_to_dev(iphy), "phy-%d:%d: %s event: %s (%x)\n", \
663 phy_to_host(iphy)->id, iphy->phy_index, \
664 phy_state_name(state), phy_event_name(code), code)
666 #define phy_event_warn(iphy, state, code) \
667 dev_warn(sciphy_to_dev(iphy), "phy-%d:%d: %s event: %s (%x)\n", \
668 phy_to_host(iphy)->id, iphy->phy_index, \
669 phy_state_name(state), phy_event_name(code), code)
686 enum sci_phy_states
state = iphy->
sm.current_state_id;
689 case SCI_PHY_SUB_AWAIT_OSSP_EN:
692 sci_phy_start_sas_link_training(iphy);
696 sci_phy_start_sata_link_training(iphy);
711 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
721 SCI_PHY_SUB_AWAIT_IAF_UF);
726 SCI_PHY_SUB_AWAIT_IAF_UF);
731 SCI_PHY_SUB_AWAIT_IAF_UF);
737 sci_phy_start_sata_link_training(iphy);
759 case SCI_PHY_SUB_AWAIT_IAF_UF:
763 sci_phy_start_sas_link_training(iphy);
770 sci_phy_start_sata_link_training(iphy);
790 case SCI_PHY_SUB_AWAIT_SAS_POWER:
804 case SCI_PHY_SUB_AWAIT_SATA_POWER:
823 sci_phy_start_sas_link_training(iphy);
831 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
855 sci_phy_start_sas_link_training(iphy);
862 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
872 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
877 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
882 SCI_PHY_SUB_AWAIT_SIG_FIS_UF);
895 sci_phy_start_sas_link_training(iphy);
903 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
951 case SCI_PHY_RESETTING:
964 dev_dbg(sciphy_to_dev(iphy),
"%s: in wrong state: %s\n",
965 __func__, phy_state_name(state));
972 enum sci_phy_states
state = iphy->
sm.current_state_id;
978 case SCI_PHY_SUB_AWAIT_IAF_UF: {
980 struct sas_identify_frame iaf;
984 (
void **)&frame_words);
989 sci_swab32_cpy(&iaf, frame_words,
sizeof(iaf) /
sizeof(
u32));
990 if (iaf.frame_type == 0) {
995 spin_unlock_irqrestore(&iphy->
sas_phy.frame_rcvd_lock, flags);
1001 state = SCI_PHY_SUB_FINAL;
1006 state = SCI_PHY_SUB_AWAIT_SAS_POWER;
1012 "%s: PHY starting substate machine received "
1013 "unexpected frame id %x\n",
1014 __func__, frame_index);
1019 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: {
1021 u32 *fis_frame_data;
1025 (
void **)&frame_header);
1034 (
void **)&fis_frame_data);
1040 spin_unlock_irqrestore(&iphy->
sas_phy.frame_rcvd_lock, flags);
1048 "%s: PHY starting substate machine received "
1049 "unexpected frame id %x\n",
1050 __func__, frame_index);
1058 dev_dbg(sciphy_to_dev(iphy),
"%s: in wrong state: %s\n",
1059 __func__, phy_state_name(state));
1178 static void scu_link_layer_stop_protocol_engine(
1181 u32 scu_sas_pcfg_value;
1182 u32 enable_spinup_value;
1185 scu_sas_pcfg_value =
1187 scu_sas_pcfg_value |=
1191 writel(scu_sas_pcfg_value,
1200 static void scu_link_layer_start_oob(
struct isci_phy *iphy)
1230 static void scu_link_layer_tx_hard_reset(
1233 u32 phy_configuration_value;
1238 phy_configuration_value =
1241 phy_configuration_value |=
1244 writel(phy_configuration_value,
1250 writel(phy_configuration_value,
1266 scu_link_layer_stop_protocol_engine(iphy);
1268 if (iphy->
sm.previous_state_id != SCI_PHY_INITIAL)
1278 scu_link_layer_stop_protocol_engine(iphy);
1279 scu_link_layer_start_oob(iphy);
1285 if (iphy->
sm.previous_state_id == SCI_PHY_READY)
1304 sci_phy_suspend(iphy);
1318 scu_link_layer_tx_hard_reset(iphy);
1328 [SCI_PHY_INITIAL] = { },
1329 [SCI_PHY_STOPPED] = {
1330 .enter_state = sci_phy_stopped_state_enter,
1332 [SCI_PHY_STARTING] = {
1333 .enter_state = sci_phy_starting_state_enter,
1335 [SCI_PHY_SUB_INITIAL] = {
1336 .enter_state = sci_phy_starting_initial_substate_enter,
1338 [SCI_PHY_SUB_AWAIT_OSSP_EN] = { },
1339 [SCI_PHY_SUB_AWAIT_SAS_SPEED_EN] = { },
1340 [SCI_PHY_SUB_AWAIT_IAF_UF] = { },
1341 [SCI_PHY_SUB_AWAIT_SAS_POWER] = {
1342 .enter_state = sci_phy_starting_await_sas_power_substate_enter,
1343 .exit_state = sci_phy_starting_await_sas_power_substate_exit,
1345 [SCI_PHY_SUB_AWAIT_SATA_POWER] = {
1346 .enter_state = sci_phy_starting_await_sata_power_substate_enter,
1347 .exit_state = sci_phy_starting_await_sata_power_substate_exit
1349 [SCI_PHY_SUB_AWAIT_SATA_PHY_EN] = {
1350 .enter_state = sci_phy_starting_await_sata_phy_substate_enter,
1351 .exit_state = sci_phy_starting_await_sata_phy_substate_exit
1353 [SCI_PHY_SUB_AWAIT_SATA_SPEED_EN] = {
1354 .enter_state = sci_phy_starting_await_sata_speed_substate_enter,
1355 .exit_state = sci_phy_starting_await_sata_speed_substate_exit
1357 [SCI_PHY_SUB_AWAIT_SIG_FIS_UF] = {
1358 .enter_state = sci_phy_starting_await_sig_fis_uf_substate_enter,
1359 .exit_state = sci_phy_starting_await_sig_fis_uf_substate_exit
1361 [SCI_PHY_SUB_FINAL] = {
1362 .enter_state = sci_phy_starting_final_substate_enter,
1365 .enter_state = sci_phy_ready_state_enter,
1366 .exit_state = sci_phy_ready_state_exit,
1368 [SCI_PHY_RESETTING] = {
1369 .enter_state = sci_phy_resetting_state_enter,
1371 [SCI_PHY_FINAL] = { },
1377 sci_init_sm(&iphy->
sm, sci_phy_state_table, SCI_PHY_INITIAL);
1388 sci_init_timer(&iphy->
sata_timer, phy_sata_timeout);
1397 sci_sas_addr = oem->
phys[
index].sas_address.high;
1398 sci_sas_addr <<= 32;
1399 sci_sas_addr |= oem->
phys[
index].sas_address.low;
1408 iphy->
sas_phy.lldd_phy = iphy;
1438 unsigned long flags;
1441 "%s: phy %p; func %d; buf %p; isci phy %p, port %p\n",
1442 __func__, sas_phy, func, buf, iphy, port);
1447 scu_link_layer_start_oob(iphy);
1449 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1454 scu_link_layer_start_oob(iphy);
1457 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1469 struct sas_phy *
phy = sas_phy->
phy;
1481 "%s: phy %p; func %d NOT IMPLEMENTED!\n",
1482 __func__, sas_phy, func);