60 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
61 #define SCU_DUMMY_INDEX (0xFFFF)
69 return strings[
state];
85 return &ihost->
pdev->dev;
110 mask |= (1 <<
index);
135 prop->
phy_mask = sci_port_get_phys(iport);
137 sci_port_get_protocols(iport, &prop->
local.protocols);
143 static void sci_port_bcn_enable(
struct isci_port *iport)
159 static void isci_port_bc_change_received(
struct isci_host *ihost,
164 "%s: isci_phy = %p, sas_phy = %p\n",
165 __func__, iphy, &iphy->
sas_phy);
168 sci_port_bcn_enable(iport);
177 unsigned long success =
true;
180 "%s: isci_port = %p\n",
188 u64 attached_sas_address;
200 attached_sas_address = properties.remote.sas_address.high;
201 attached_sas_address <<= 32;
202 attached_sas_address |= properties.remote.sas_address.low;
203 swab64s(&attached_sas_address);
206 &attached_sas_address,
sizeof(attached_sas_address));
209 iphy->
sas_phy.frame_rcvd_size =
sizeof(
struct sas_identify_frame);
215 dev_err(&isci_host->
pdev->dev,
"%s: unknown target\n", __func__);
221 spin_unlock_irqrestore(&iphy->
sas_phy.frame_rcvd_lock, flags);
239 static void isci_port_link_down(
struct isci_host *isci_host,
246 "%s: isci_port = %p\n", __func__, isci_port);
252 isci_phy->
sas_phy.port->num_phys == 1) {
262 "%s: isci_device = %p\n",
263 __func__, isci_device);
272 sas_phy_disconnected(&isci_phy->
sas_phy);
277 "%s: isci_port = %p - Done\n", __func__, isci_port);
280 static bool is_port_ready_state(
enum sci_port_states
state)
284 case SCI_PORT_SUB_WAITING:
285 case SCI_PORT_SUB_OPERATIONAL:
286 case SCI_PORT_SUB_CONFIGURING:
294 static void port_state_machine_change(
struct isci_port *iport,
295 enum sci_port_states state)
300 if (is_port_ready_state(old_state) && !is_port_ready_state(state))
315 static void isci_port_hard_reset_complete(
struct isci_port *isci_port,
321 "%s: isci_port = %p, completion_status=%x\n",
322 __func__, isci_port, completion_status);
332 struct isci_phy *iphy = &ihost->
phys[phy_idx];
338 isci_port_link_down(ihost, iphy, isci_port);
343 port_state_machine_change(isci_port, SCI_PORT_SUB_WAITING);
378 (phy_index == 0 || phy_index == 1))
382 if (iport->
phy_table[index] && index != phy_index)
383 existing_phy_index =
index;
388 if (existing_phy_index < SCI_MAX_PHYS &&
389 user->phys[phy_index].max_speed_generation !=
390 user->phys[existing_phy_index].max_speed_generation)
408 static bool sci_port_is_phy_mask_valid(
409 struct isci_port *iport,
413 if (((phy_mask & 0x0F) == 0x0F)
414 || ((phy_mask & 0x03) == 0x03)
415 || ((phy_mask & 0x01) == 0x01)
419 if (((phy_mask & 0x02) == 0x02)
423 if (((phy_mask & 0x0C) == 0x0C)
424 || ((phy_mask & 0x04) == 0x04)
428 if (((phy_mask & 0x08) == 0x08)
444 static struct isci_phy *sci_port_get_a_connected_phy(
struct isci_port *iport)
447 struct isci_phy *iphy;
461 static enum sci_status sci_port_set_phy(
struct isci_port *iport,
struct isci_phy *iphy)
483 static enum sci_status sci_port_clear_phy(
struct isci_port *iport,
struct isci_phy *iphy)
512 struct isci_phy *iphy;
518 iphy = sci_port_get_a_connected_phy(iport);
542 static void sci_port_construct_dummy_rnc(
struct isci_port *iport,
u16 rni)
550 rnc->
ssp.remote_sas_address_hi = 0;
551 rnc->
ssp.remote_sas_address_lo = 0;
553 rnc->
ssp.remote_node_index = rni;
554 rnc->
ssp.remote_node_port_width = 1;
557 rnc->
ssp.nexus_loss_timer_enable =
false;
558 rnc->
ssp.check_bit =
false;
559 rnc->
ssp.is_valid =
true;
560 rnc->
ssp.is_remote_node_context =
true;
561 rnc->
ssp.function_number = 0;
562 rnc->
ssp.arbitration_wait_time = 0;
570 static void sci_port_construct_dummy_task(
struct isci_port *iport,
u16 tag)
590 static void sci_port_destroy_dummy_resources(
struct isci_port *iport)
615 static void sci_port_resume_phy(
struct isci_port *iport,
struct isci_phy *iphy)
621 static void sci_port_activate_phy(
struct isci_port *iport,
622 struct isci_phy *iphy,
635 isci_port_link_up(ihost, iport, iphy);
658 if (do_notify_user ==
true)
659 isci_port_link_down(ihost, iphy, iport);
662 static void sci_port_invalid_link_up(
struct isci_port *iport,
struct isci_phy *iphy)
688 static void sci_port_general_link_up_handler(
struct isci_port *iport,
689 struct isci_phy *iphy,
703 if ((phy_sas_address.high == port_sas_address.high &&
704 phy_sas_address.low == port_sas_address.low) ||
708 sci_port_activate_phy(iport, iphy, flags);
710 port_state_machine_change(iport, SCI_PORT_READY);
712 sci_port_invalid_link_up(iport, iphy);
726 static bool sci_port_is_wide(
struct isci_port *iport)
737 return phy_count != 1;
758 if (sci_port_is_wide(iport)) {
759 sci_port_invalid_link_up(iport, iphy);
772 static void port_timeout(
unsigned long data)
785 current_state = iport->
sm.current_state_id;
787 if (current_state == SCI_PORT_RESETTING) {
791 port_state_machine_change(iport, SCI_PORT_FAILED);
792 }
else if (current_state == SCI_PORT_STOPPED) {
797 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
800 }
else if (current_state == SCI_PORT_STOPPING) {
802 "%s: port%d: stop complete timeout\n",
809 "%s: SCIC Port 0x%p is processing a timeout operation "
810 "in state %d.\n", __func__, iport, current_state);
814 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
824 static void sci_port_update_viit_entry(
struct isci_port *iport)
849 struct isci_phy *iphy;
862 return max_allowed_speed;
865 static void sci_port_suspend_port_task_scheduler(
struct isci_port *iport)
867 u32 pts_control_value;
883 static void sci_port_post_dummy_request(
struct isci_port *iport)
907 static void sci_port_abort_dummy_request(
struct isci_port *iport)
931 sci_port_resume_port_task_scheduler(
struct isci_port *iport)
933 u32 pts_control_value;
944 sci_port_suspend_port_task_scheduler(iport);
950 port_state_machine_change(iport,
951 SCI_PORT_SUB_OPERATIONAL);
955 static void scic_sds_port_ready_substate_waiting_exit(
959 sci_port_resume_port_task_scheduler(iport);
977 sci_port_resume_phy(iport, iport->
phy_table[index]);
981 sci_port_update_viit_entry(iport);
987 sci_port_post_dummy_request(iport);
990 static void sci_port_invalidate_dummy_remote_node(
struct isci_port *iport)
1000 rnc->
ssp.is_valid =
false;
1033 sci_port_abort_dummy_request(iport);
1039 sci_port_invalidate_dummy_remote_node(iport);
1051 port_state_machine_change(iport, SCI_PORT_SUB_WAITING);
1053 port_state_machine_change(iport, SCI_PORT_SUB_OPERATIONAL);
1060 enum sci_port_states
state;
1063 state = iport->
sm.current_state_id;
1064 if (state != SCI_PORT_STOPPED) {
1065 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1084 sci_port_construct_dummy_rnc(iport, rni);
1097 sci_port_construct_dummy_task(iport, tag);
1102 phy_mask = sci_port_get_phys(iport);
1109 if (sci_port_is_phy_mask_valid(iport, phy_mask) ==
true) {
1110 port_state_machine_change(iport,
1119 sci_port_destroy_dummy_resources(iport);
1126 enum sci_port_states
state;
1128 state = iport->
sm.current_state_id;
1130 case SCI_PORT_STOPPED:
1132 case SCI_PORT_SUB_WAITING:
1133 case SCI_PORT_SUB_OPERATIONAL:
1134 case SCI_PORT_SUB_CONFIGURING:
1135 case SCI_PORT_RESETTING:
1136 port_state_machine_change(iport,
1140 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1146 static enum sci_status sci_port_hard_reset(
struct isci_port *iport,
u32 timeout)
1149 struct isci_phy *iphy =
NULL;
1150 enum sci_port_states
state;
1153 state = iport->
sm.current_state_id;
1154 if (state != SCI_PORT_SUB_OPERATIONAL) {
1155 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1161 for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) {
1180 sci_mod_timer(&iport->
timer, timeout);
1183 port_state_machine_change(iport, SCI_PORT_RESETTING);
1197 struct isci_phy *iphy)
1200 enum sci_port_states
state;
1202 sci_port_bcn_enable(iport);
1204 state = iport->
sm.current_state_id;
1206 case SCI_PORT_STOPPED: {
1212 if (port_sas_address.
high != 0 && port_sas_address.
low != 0) {
1220 if (port_sas_address.
high != phy_sas_address.
high ||
1221 port_sas_address.
low != phy_sas_address.
low)
1224 return sci_port_set_phy(iport, iphy);
1226 case SCI_PORT_SUB_WAITING:
1227 case SCI_PORT_SUB_OPERATIONAL:
1228 status = sci_port_set_phy(iport, iphy);
1233 sci_port_general_link_up_handler(iport, iphy,
PF_NOTIFY|PF_RESUME);
1235 port_state_machine_change(iport, SCI_PORT_SUB_CONFIGURING);
1238 case SCI_PORT_SUB_CONFIGURING:
1239 status = sci_port_set_phy(iport, iphy);
1243 sci_port_general_link_up_handler(iport, iphy,
PF_NOTIFY);
1248 port_state_machine_change(iport,
1249 SCI_PORT_SUB_CONFIGURING);
1252 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1268 struct isci_phy *iphy)
1271 enum sci_port_states
state;
1273 state = iport->
sm.current_state_id;
1276 case SCI_PORT_STOPPED:
1277 return sci_port_clear_phy(iport, iphy);
1278 case SCI_PORT_SUB_OPERATIONAL:
1279 status = sci_port_clear_phy(iport, iphy);
1285 port_state_machine_change(iport,
1286 SCI_PORT_SUB_CONFIGURING);
1288 case SCI_PORT_SUB_CONFIGURING:
1289 status = sci_port_clear_phy(iport, iphy);
1298 port_state_machine_change(iport,
1299 SCI_PORT_SUB_CONFIGURING);
1302 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1309 struct isci_phy *iphy)
1311 enum sci_port_states
state;
1313 state = iport->
sm.current_state_id;
1315 case SCI_PORT_SUB_WAITING:
1319 sci_port_activate_phy(iport, iphy,
PF_NOTIFY|PF_RESUME);
1321 port_state_machine_change(iport,
1322 SCI_PORT_SUB_OPERATIONAL);
1324 case SCI_PORT_SUB_OPERATIONAL:
1325 sci_port_general_link_up_handler(iport, iphy,
PF_NOTIFY|PF_RESUME);
1327 case SCI_PORT_RESETTING:
1342 sci_port_general_link_up_handler(iport, iphy, PF_RESUME);
1345 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1352 struct isci_phy *iphy)
1354 enum sci_port_states
state;
1356 state = iport->
sm.current_state_id;
1358 case SCI_PORT_SUB_OPERATIONAL:
1366 port_state_machine_change(iport,
1367 SCI_PORT_SUB_WAITING);
1369 case SCI_PORT_RESETTING:
1375 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1385 enum sci_port_states
state;
1387 state = iport->
sm.current_state_id;
1389 case SCI_PORT_SUB_WAITING:
1391 case SCI_PORT_SUB_OPERATIONAL:
1395 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1405 enum sci_port_states
state;
1407 state = iport->
sm.current_state_id;
1409 case SCI_PORT_STOPPED:
1410 dev_warn(sciport_to_dev(iport),
"%s: in wrong state: %s\n",
1413 case SCI_PORT_STOPPING:
1414 sci_port_decrement_request_count(iport);
1417 port_state_machine_change(iport,
1420 case SCI_PORT_READY:
1421 case SCI_PORT_RESETTING:
1422 case SCI_PORT_FAILED:
1423 case SCI_PORT_SUB_WAITING:
1424 case SCI_PORT_SUB_OPERATIONAL:
1425 sci_port_decrement_request_count(iport);
1427 case SCI_PORT_SUB_CONFIGURING:
1428 sci_port_decrement_request_count(iport);
1430 port_state_machine_change(iport,
1431 SCI_PORT_SUB_OPERATIONAL);
1438 static void sci_port_enable_port_task_scheduler(
struct isci_port *iport)
1440 u32 pts_control_value;
1448 static void sci_port_disable_port_task_scheduler(
struct isci_port *iport)
1450 u32 pts_control_value;
1453 pts_control_value &=
1458 static void sci_port_post_dummy_remote_node(
struct isci_port *iport)
1467 rnc->
ssp.is_valid =
true;
1490 if (iport->
sm.previous_state_id == SCI_PORT_STOPPING) {
1495 sci_port_disable_port_task_scheduler(iport);
1504 sci_port_enable_port_task_scheduler(iport);
1513 prev_state = iport->
sm.previous_state_id;
1514 if (prev_state == SCI_PORT_RESETTING)
1515 isci_port_hard_reset_complete(iport,
SCI_SUCCESS);
1521 sci_port_post_dummy_remote_node(iport);
1524 port_state_machine_change(iport,
1525 SCI_PORT_SUB_WAITING);
1532 sci_del_timer(&iport->
timer);
1539 sci_del_timer(&iport->
timer);
1541 sci_port_destroy_dummy_resources(iport);
1564 for (phy_index = 0; phy_index <
SCI_MAX_PHYS; phy_index++) {
1565 if ((phy_mask >> phy_index) & 1) {
1568 ->link_layer_registers
1569 ->link_layer_hang_detection_timeout);
1577 [SCI_PORT_STOPPED] = {
1578 .enter_state = sci_port_stopped_state_enter,
1579 .exit_state = sci_port_stopped_state_exit
1581 [SCI_PORT_STOPPING] = {
1582 .exit_state = sci_port_stopping_state_exit
1584 [SCI_PORT_READY] = {
1585 .enter_state = sci_port_ready_state_enter,
1587 [SCI_PORT_SUB_WAITING] = {
1588 .enter_state = sci_port_ready_substate_waiting_enter,
1589 .exit_state = scic_sds_port_ready_substate_waiting_exit,
1591 [SCI_PORT_SUB_OPERATIONAL] = {
1592 .enter_state = sci_port_ready_substate_operational_enter,
1593 .exit_state = sci_port_ready_substate_operational_exit
1595 [SCI_PORT_SUB_CONFIGURING] = {
1596 .enter_state = sci_port_ready_substate_configuring_enter
1598 [SCI_PORT_RESETTING] = {
1599 .exit_state = sci_port_resetting_state_exit
1601 [SCI_PORT_FAILED] = {
1602 .enter_state = sci_port_failed_state_enter,
1607 struct isci_host *ihost)
1609 sci_init_sm(&iport->
sm, sci_port_state_table, SCI_PORT_STOPPED);
1627 sci_init_timer(&iport->
timer, port_timeout);
1640 isci_port_bc_change_received(ihost, iport, iphy);
1643 static void wait_port_reset(
struct isci_host *ihost,
struct isci_port *iport)
1649 struct isci_phy *iphy)
1651 unsigned long flags;
1661 #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1664 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1667 wait_port_reset(ihost, iport);
1670 "%s: iport = %p; hard reset completion\n",
1677 "%s: iport = %p; hard reset failed (0x%x)\n",
1686 "%s: iport = %p; sci_port_hard_reset call"
1688 __func__, iport, status);
1696 struct isci_port *iport = dev->
port->lldd_port;
1697 struct isci_host *ihost = dev_to_ihost(dev);
1699 unsigned long flags;
1703 idev = isci_lookup_device(dev);
1704 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1714 isci_put_device(idev);
1721 struct isci_host *ihost = phy->
ha->lldd_ha;
1722 struct isci_port *iport = phy->
port->lldd_port;
1723 unsigned long flags;
1737 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1739 if (i >= SCI_MAX_PHYS)
1741 __func__, (
long) (iport - &ihost->
ports[0]));
1746 struct isci_host *ihost = phy->
ha->lldd_ha;
1747 struct isci_phy *iphy = to_iphy(phy);
1749 struct isci_port *iport =
NULL;
1750 unsigned long flags;
1760 iport = &ihost->
ports[
i];
1764 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1766 if (i >= SCI_MAX_PORTS)