56 #include <linux/device.h>
70 #define SCU_CONTEXT_RAM_INIT_STALL_TIME 200
72 #define smu_max_ports(dcc_value) \
74 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_MASK) \
75 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_SHIFT) + 1 \
78 #define smu_max_task_contexts(dcc_value) \
80 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_MASK) \
81 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_SHIFT) + 1 \
84 #define smu_max_rncs(dcc_value) \
86 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_MASK) \
87 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_SHIFT) + 1 \
90 #define SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT 100
99 #define SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL 500
107 #define NORMALIZE_PUT_POINTER(x) \
108 ((x) & SMU_COMPLETION_QUEUE_PUT_POINTER_MASK)
117 #define NORMALIZE_EVENT_POINTER(x) \
119 ((x) & SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_MASK) \
120 >> SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_SHIFT \
129 #define NORMALIZE_GET_POINTER(x) \
130 ((x) & SMU_COMPLETION_QUEUE_GET_POINTER_MASK)
138 #define NORMALIZE_GET_POINTER_CYCLE_BIT(x) \
139 ((SMU_CQGR_CYCLE_BIT & (x)) << (31 - SMU_COMPLETION_QUEUE_GET_CYCLE_BIT_SHIFT))
146 #define COMPLETION_QUEUE_CYCLE_BIT(x) ((x) & 0x80000000)
159 handler = sm->
state_table[initial_state].enter_state;
181 static bool sci_controller_completion_queue_has_entries(
struct isci_host *ihost)
193 static bool sci_controller_isr(
struct isci_host *ihost)
195 if (sci_controller_completion_queue_has_entries(ihost))
224 if (sci_controller_isr(ihost))
230 static bool sci_controller_error_isr(
struct isci_host *ihost)
238 if (interrupt_status != 0) {
257 static void sci_controller_task_completion(
struct isci_host *ihost,
u32 ent)
272 static void sci_controller_sdma_completion(
struct isci_host *ihost,
u32 ent)
284 dev_warn(&ihost->
pdev->dev,
"%s: %x for io request %p\n",
285 __func__, ent, ireq);
295 __func__, ent, idev);
301 dev_warn(&ihost->
pdev->dev,
"%s: unknown completion type %x\n",
307 static void sci_controller_unsolicited_frame(
struct isci_host *ihost,
u32 ent)
349 if (index < ihost->remote_node_entries)
368 static void sci_controller_event_completion(
struct isci_host *ihost,
u32 ent)
381 "%s: SCIC Controller 0x%p received SMU command error "
395 "%s: SCIC Controller 0x%p received fatal controller "
416 "%s: SCIC Controller 0x%p received "
417 "event 0x%x for io request object "
418 "that doesnt exist.\n",
431 "%s: SCIC Controller 0x%p received "
432 "event 0x%x for remote device object "
433 "that doesnt exist.\n",
459 if (index < ihost->remote_node_entries) {
466 "%s: SCIC Controller 0x%p received event 0x%x "
467 "for remote device object 0x%0x that doesnt "
478 "%s: SCIC Controller received unknown event code %x\n",
485 static void sci_controller_process_completions(
struct isci_host *ihost)
487 u32 completion_count = 0;
495 "%s: completion queue beginning get:0x%08x\n",
520 "%s: completion queue entry:0x%08x\n",
526 sci_controller_task_completion(ihost, ent);
530 sci_controller_sdma_completion(ihost, ent);
534 sci_controller_unsolicited_frame(ihost, ent);
538 sci_controller_event_completion(ihost, ent);
546 sci_controller_event_completion(ihost, ent);
551 "%s: SCIC Controller received unknown "
552 "completion type %x\n",
560 if (completion_count > 0) {
575 "%s: completion queue ending get:0x%08x\n",
581 static void sci_controller_error_handler(
struct isci_host *ihost)
589 sci_controller_completion_queue_has_entries(ihost)) {
591 sci_controller_process_completions(ihost);
594 dev_err(&ihost->
pdev->dev,
"%s: status: %#x\n", __func__,
613 if (sci_controller_isr(ihost)) {
617 }
else if (sci_controller_error_isr(ihost)) {
619 sci_controller_error_handler(ihost);
631 if (sci_controller_error_isr(ihost))
632 sci_controller_error_handler(ihost);
645 static void isci_host_start_complete(
struct isci_host *ihost,
enum sci_status completion_status)
649 "controller start timed out, continuing...\n");
679 static u32 sci_controller_get_suggested_start_timeout(
struct isci_host *ihost)
704 static void sci_controller_enable_interrupts(
struct isci_host *ihost)
717 static void sci_controller_enable_port_task_scheduler(
struct isci_host *ihost)
719 u32 port_task_scheduler_value;
721 port_task_scheduler_value =
723 port_task_scheduler_value |=
726 writel(port_task_scheduler_value,
730 static void sci_controller_assign_task_entries(
struct isci_host *ihost)
751 static void sci_controller_initialize_completion_queue(
struct isci_host *ihost)
754 u32 completion_queue_control_value;
755 u32 completion_queue_get_value;
756 u32 completion_queue_put_value;
760 completion_queue_control_value =
764 writel(completion_queue_control_value,
769 completion_queue_get_value = (
776 writel(completion_queue_get_value,
780 completion_queue_put_value = (
785 writel(completion_queue_put_value,
798 static void sci_controller_initialize_unsolicited_frame_queue(
struct isci_host *ihost)
800 u32 frame_queue_control_value;
801 u32 frame_queue_get_value;
802 u32 frame_queue_put_value;
805 frame_queue_control_value =
808 writel(frame_queue_control_value,
809 &ihost->
scu_registers->sdma.unsolicited_frame_queue_control);
812 frame_queue_get_value = (
817 writel(frame_queue_get_value,
821 writel(frame_queue_put_value,
834 isci_host_start_complete(ihost, status);
838 static bool is_phy_starting(
struct isci_phy *iphy)
840 enum sci_phy_states
state;
842 state = iphy->
sm.current_state_id;
844 case SCI_PHY_STARTING:
845 case SCI_PHY_SUB_INITIAL:
846 case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN:
847 case SCI_PHY_SUB_AWAIT_IAF_UF:
848 case SCI_PHY_SUB_AWAIT_SAS_POWER:
849 case SCI_PHY_SUB_AWAIT_SATA_POWER:
850 case SCI_PHY_SUB_AWAIT_SATA_PHY_EN:
851 case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN:
852 case SCI_PHY_SUB_AWAIT_OSSP_EN:
853 case SCI_PHY_SUB_AWAIT_SIG_FIS_UF:
854 case SCI_PHY_SUB_FINAL:
867 u32 state = iphy->
sm.current_state_id;
935 return sci_controller_start_next_phy(ihost);
947 "%s: Controller stop operation failed "
948 "to stop phy %d because of status "
961 static void phy_startup_timeout(
unsigned long data)
976 status = sci_controller_start_next_phy(ihost);
980 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
996 __func__, ihost->
sm.current_state_id);
1018 sci_controller_enable_port_task_scheduler(ihost);
1021 sci_controller_assign_task_entries(ihost);
1024 sci_controller_initialize_completion_queue(ihost);
1027 sci_controller_initialize_unsolicited_frame_queue(ihost);
1038 sci_controller_start_next_phy(ihost);
1040 sci_mod_timer(&ihost->
timer, timeout);
1050 unsigned long tmo = sci_controller_get_suggested_start_timeout(ihost);
1055 sci_controller_start(ihost, tmo);
1056 sci_controller_enable_interrupts(ihost);
1060 static void isci_host_stop_complete(
struct isci_host *ihost)
1067 static void sci_controller_completion_handler(
struct isci_host *ihost)
1070 if (sci_controller_completion_queue_has_entries(ihost))
1071 sci_controller_process_completions(ihost);
1087 "%s: Normal - ireq/task = %p/%p\n",
1088 __func__, ireq, task);
1093 "%s: Error - ireq/task = %p/%p\n",
1094 __func__, ireq, task);
1122 sci_controller_completion_handler(ihost);
1162 __func__, ihost->
sm.current_state_id);
1166 sci_mod_timer(&ihost->
timer, timeout);
1185 switch (ihost->
sm.current_state_id) {
1198 __func__, ihost->
sm.current_state_id);
1219 "%s: Controller stop operation failed to stop "
1220 "phy %d because of status %d.\n",
1222 ihost->
phys[index].phy_index, phy_status);
1246 for (i = 0; i < isci_gpio_count(ihost); i++)
1255 wait_for_stop(ihost);
1262 sci_controller_stop_phys(ihost);
1270 sci_controller_reset(ihost);
1297 int id = isci_host->
id;
1305 int id = isci_host->
id;
1321 sci_del_timer(&ihost->
timer);
1324 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS 853
1325 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS 1280
1326 #define INTERRUPT_COALESCE_TIMEOUT_MAX_US 2700000
1327 #define INTERRUPT_COALESCE_NUMBER_MAX 256
1328 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN 7
1329 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX 28
1349 sci_controller_set_interrupt_coalescence(
struct isci_host *ihost,
1350 u32 coalesce_number,
1351 u32 coalesce_timeout)
1353 u8 timeout_encode = 0;
1399 if (coalesce_timeout == 0)
1403 coalesce_timeout = coalesce_timeout * 100;
1411 if (min <= coalesce_timeout && max > coalesce_timeout)
1413 else if (coalesce_timeout >= max && coalesce_timeout < min * 2
1415 if ((coalesce_timeout - max) < (2 * min - coalesce_timeout))
1458 sci_controller_set_interrupt_coalescence(ihost, 0, 0);
1466 sci_controller_set_interrupt_coalescence(ihost, 0, 0);
1485 "%s: Controller stop operation failed to "
1486 "stop port %d because of status %d.\n",
1512 "%s: Controller stop operation failed "
1513 "to stop device 0x%p because of "
1528 sci_controller_stop_devices(ihost);
1529 sci_controller_stop_ports(ihost);
1532 isci_host_stop_complete(ihost);
1539 sci_del_timer(&ihost->
timer);
1542 static void sci_controller_reset_hardware(
struct isci_host *ihost)
1567 sci_controller_reset_hardware(ihost);
1571 static const struct sci_base_state sci_controller_state_table[] = {
1573 .enter_state = sci_controller_initial_state_enter,
1579 .exit_state = sci_controller_starting_state_exit,
1582 .enter_state = sci_controller_ready_state_enter,
1583 .exit_state = sci_controller_ready_state_exit,
1586 .enter_state = sci_controller_resetting_state_enter,
1589 .enter_state = sci_controller_stopping_state_enter,
1590 .exit_state = sci_controller_stopping_state_exit,
1595 static void controller_timeout(
unsigned long data)
1600 unsigned long flags;
1611 isci_host_stop_complete(ihost);
1614 "%s: Controller timer fired when controller was not "
1615 "in a state being timed.\n",
1619 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1644 &ihost->
ports[SCI_MAX_PORTS], i);
1649 sci_init_timer(&ihost->
timer, controller_timeout);
1651 return sci_controller_reset(ihost);
1659 if (oem->
ports[i].phy_mask > SCIC_SDS_PARM_PHY_MASK_MAX)
1663 if (oem->
phys[i].sas_address.high == 0 &&
1664 oem->
phys[i].sas_address.low == 0)
1669 if (oem->
ports[i].phy_mask != 0)
1675 phy_mask |= oem->
ports[i].phy_mask;
1682 if (oem->
controller.max_concurr_spin_up > MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT ||
1687 if (version < ISCI_ROM_VER_1_1 && oem->
controller.do_enable_ssc != 1)
1704 test = oem->
controller.ssc_sas_tx_spread_level;
1714 }
else if (oem->
controller.ssc_sas_tx_type == 1) {
1734 MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT);
1737 MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT);
1740 static void power_control_timeout(
unsigned long data)
1745 unsigned long flags;
1769 if (ihost->
power_control.phys_granted_power >= max_spin_up(ihost))
1788 if (requester !=
NULL && requester != iphy) {
1811 spin_unlock_irqrestore(&ihost->
scic_lock, flags);
1819 if (ihost->
power_control.phys_granted_power < max_spin_up(ihost)) {
1844 current_phy = &ihost->
phys[
i];
1850 if (current_phy->
sm.current_state_id == SCI_PHY_READY &&
1858 if (i == SCI_MAX_PHYS) {
1877 static int is_long_cable(
int phy,
unsigned char selection_byte)
1879 return !!(selection_byte & (1 <<
phy));
1882 static int is_medium_cable(
int phy,
unsigned char selection_byte)
1884 return !!(selection_byte & (1 << (phy + 4)));
1889 unsigned char selection_byte)
1891 return ((selection_byte & (1 << phy)) ? 1 : 0)
1892 + (selection_byte & (1 << (phy + 4)) ? 2 : 0);
1895 static unsigned char *to_cable_select(
struct isci_host *ihost)
1897 if (is_cable_select_overridden())
1906 return decode_selection_byte(phy, *to_cable_select(ihost));
1911 static char *cable_names[] = {
1921 #define AFE_REGISTER_WRITE_DELAY 10
1923 static void sci_controller_afe_initialization(
struct isci_host *ihost)
1936 if (is_b0(pdev) || is_c0(pdev) || is_c1(pdev)) {
1947 else if (is_b0(pdev) || is_c0(pdev))
1949 else if (is_c1(pdev))
1957 else if (is_b0(pdev) || is_c0(pdev))
1959 else if (is_c1(pdev)) {
1973 }
while ((afe_status & 0x00001000) == 0);
1986 int cable_length_long =
1987 is_long_cable(phy_id, cable_selection_mask);
1988 int cable_length_medium =
1989 is_medium_cable(phy_id, cable_selection_mask);
2000 }
else if (is_b0(pdev)) {
2004 }
else if (is_c0(pdev)) {
2014 }
else if (is_c1(pdev)) {
2031 else if (is_b0(pdev)) {
2036 }
else if (is_c0(pdev)) {
2041 }
else if (is_c1(pdev)) {
2042 writel(cable_length_long ? 0x000002F7 : 0x000001F7,
2046 writel(cable_length_long ? 0x000002F4 : 0x000001F4,
2057 if (is_a2(pdev) || is_b0(pdev))
2063 else if (is_c0(pdev))
2065 else if (is_c1(pdev))
2072 else if (is_b0(pdev)) {
2077 }
else if (is_c0(pdev)) {
2086 }
else if (is_c1(pdev)) {
2087 writel(cable_length_long ? 0x01500C0C :
2088 cable_length_medium ? 0x01400C0D : 0x02400C0D,
2095 writel(cable_length_long ? 0x33091C1F :
2096 cable_length_medium ? 0x3315181F : 0x2B17161F,
2124 static void sci_controller_initialize_power_control(
struct isci_host *ihost)
2126 sci_init_timer(&ihost->
power_control.timer, power_control_timeout);
2143 __func__, ihost->
sm.current_state_id);
2149 sci_init_timer(&ihost->
phy_timer, phy_startup_timeout);
2154 sci_controller_initialize_power_control(ihost);
2161 sci_controller_afe_initialization(ihost);
2170 for (i = 100; i >= 1; i--) {
2246 static int sci_controller_dma_alloc(
struct isci_host *ihost)
2292 ihost->
reqs[
i] = ireq;
2298 static int sci_controller_mem_init(
struct isci_host *ihost)
2300 int err = sci_controller_dma_alloc(ihost);
2347 status = sci_controller_construct(ihost, scu_base(ihost), smu_base(ihost));
2351 "%s: sci_controller_construct failed - status = %x\n",
2358 status = sci_controller_initialize(ihost);
2362 "%s: sci_controller_initialize failed -"
2368 err = sci_controller_mem_init(ihost);
2374 for (i = 0; i < isci_gpio_count(ihost); i++)
2384 switch (ihost->
sm.current_state_id) {
2390 sci_controller_start_next_phy(ihost);
2398 "%s: SCIC Controller linkup event from phy %d in "
2399 "unexpected state %d\n", __func__, iphy->
phy_index,
2400 ihost->
sm.current_state_id);
2407 switch (ihost->
sm.current_state_id) {
2415 "%s: SCIC Controller linkdown event from phy %d in "
2416 "unexpected state %d\n",
2419 ihost->
sm.current_state_id);
2429 (ihost->
device_table[index]->sm.current_state_id == SCI_DEV_STOPPING))
2441 "SCIC Controller 0x%p remote device stopped event "
2442 "from device 0x%p in unexpected state %d\n",
2444 ihost->
sm.current_state_id);
2449 isci_host_stop_complete(ihost);
2455 __func__, ihost->
id, request);
2467 if (task_index < ihost->task_context_entries) {
2500 u32 remote_node_count = sci_remote_device_node_count(idev);
2509 *node_id = node_index;
2521 u32 remote_node_count = sci_remote_device_node_count(idev);
2537 memcpy(response_buffer, frame_header,
sizeof(
u32));
2575 if (isci_tci_space(ihost)) {
2576 u16 tci = isci_tci_alloc(ihost);
2591 if (isci_tci_active(ihost) == 0)
2612 __func__, ihost->
sm.current_state_id);
2637 __func__, ihost->
sm.current_state_id);
2642 dev_dbg(&ihost->
pdev->dev,
"%s: status=%d; ireq=%p; flags=%lx\n",
2643 __func__, status, ireq, ireq->
flags);
2676 switch (ihost->
sm.current_state_id) {
2690 __func__, ihost->
sm.current_state_id);
2702 __func__, ihost->
sm.current_state_id);
2728 "%s: SCIC Controller starting task from invalid "
2756 static int sci_write_gpio_tx_gp(
struct isci_host *ihost,
u8 reg_index,
u8 reg_count,
u8 *write_data)
2764 for (d = 0; d < isci_gpio_count(ihost); d++) {
2768 for (i = 0; i < 3; i++) {
2769 int bit = (i << 2) + 2;
2772 write_data, reg_index,
2778 val &= ~(bit << ((i << 2) + 2));
2793 u8 reg_count,
u8 *write_data)
2800 written = sci_write_gpio_tx_gp(ihost, reg_index, reg_count, write_data);