提交 757db2da 编写于 作者: J John Garry 提交者: Martin K. Petersen

scsi: hisi_sas: Introduce hisi_sas_phy_set_linkrate()

There is much common code and functionality between the HW versions to set
the PHY linkrate.

As such, this patch factors out the common code into a generic function
hisi_sas_phy_set_linkrate().
Signed-off-by: NJohn Garry <john.garry@huawei.com>
Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
上级 eb217359
...@@ -866,6 +866,33 @@ static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) ...@@ -866,6 +866,33 @@ static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags)
return hisi_sas_task_exec(task, gfp_flags, 0, NULL); return hisi_sas_task_exec(task, gfp_flags, 0, NULL);
} }
static void hisi_sas_phy_set_linkrate(struct hisi_hba *hisi_hba, int phy_no,
struct sas_phy_linkrates *r)
{
struct sas_phy_linkrates _r;
struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
struct asd_sas_phy *sas_phy = &phy->sas_phy;
enum sas_linkrate min, max;
if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) {
max = sas_phy->phy->maximum_linkrate;
min = r->minimum_linkrate;
} else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) {
max = r->maximum_linkrate;
min = sas_phy->phy->minimum_linkrate;
} else
return;
_r.maximum_linkrate = max;
_r.minimum_linkrate = min;
hisi_hba->hw->phy_disable(hisi_hba, phy_no);
msleep(100);
hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, &_r);
hisi_hba->hw->phy_start(hisi_hba, phy_no);
}
static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func, static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func,
void *funcdata) void *funcdata)
{ {
...@@ -889,7 +916,7 @@ static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func, ...@@ -889,7 +916,7 @@ static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func,
break; break;
case PHY_FUNC_SET_LINK_RATE: case PHY_FUNC_SET_LINK_RATE:
hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, funcdata); hisi_sas_phy_set_linkrate(hisi_hba, phy_no, funcdata);
break; break;
case PHY_FUNC_GET_EVENTS: case PHY_FUNC_GET_EVENTS:
if (hisi_hba->hw->get_events) { if (hisi_hba->hw->get_events) {
......
...@@ -855,39 +855,12 @@ static enum sas_linkrate phy_get_max_linkrate_v1_hw(void) ...@@ -855,39 +855,12 @@ static enum sas_linkrate phy_get_max_linkrate_v1_hw(void)
static void phy_set_linkrate_v1_hw(struct hisi_hba *hisi_hba, int phy_no, static void phy_set_linkrate_v1_hw(struct hisi_hba *hisi_hba, int phy_no,
struct sas_phy_linkrates *r) struct sas_phy_linkrates *r)
{ {
u32 prog_phy_link_rate = enum sas_linkrate max = r->maximum_linkrate;
hisi_sas_phy_read32(hisi_hba, phy_no, PROG_PHY_LINK_RATE); u32 prog_phy_link_rate = 0x800;
struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no];
struct asd_sas_phy *sas_phy = &phy->sas_phy;
int i;
enum sas_linkrate min, max;
u32 rate_mask = 0;
if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) {
max = sas_phy->phy->maximum_linkrate;
min = r->minimum_linkrate;
} else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) {
max = r->maximum_linkrate;
min = sas_phy->phy->minimum_linkrate;
} else
return;
sas_phy->phy->maximum_linkrate = max;
sas_phy->phy->minimum_linkrate = min;
max -= SAS_LINK_RATE_1_5_GBPS;
for (i = 0; i <= max; i++) prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
rate_mask |= 1 << (i * 2);
prog_phy_link_rate &= ~0xff;
prog_phy_link_rate |= rate_mask;
disable_phy_v1_hw(hisi_hba, phy_no);
msleep(100);
hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
prog_phy_link_rate); prog_phy_link_rate);
start_phy_v1_hw(hisi_hba, phy_no);
} }
static int get_wideport_bitmap_v1_hw(struct hisi_hba *hisi_hba, int port_id) static int get_wideport_bitmap_v1_hw(struct hisi_hba *hisi_hba, int port_id)
......
...@@ -1600,29 +1600,12 @@ static enum sas_linkrate phy_get_max_linkrate_v2_hw(void) ...@@ -1600,29 +1600,12 @@ static enum sas_linkrate phy_get_max_linkrate_v2_hw(void)
static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no, static void phy_set_linkrate_v2_hw(struct hisi_hba *hisi_hba, int phy_no,
struct sas_phy_linkrates *r) struct sas_phy_linkrates *r)
{ {
struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; enum sas_linkrate max = r->maximum_linkrate;
struct asd_sas_phy *sas_phy = &phy->sas_phy;
enum sas_linkrate min, max;
u32 prog_phy_link_rate = 0x800; u32 prog_phy_link_rate = 0x800;
if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) {
max = sas_phy->phy->maximum_linkrate;
min = r->minimum_linkrate;
} else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) {
max = r->maximum_linkrate;
min = sas_phy->phy->minimum_linkrate;
} else
return;
sas_phy->phy->maximum_linkrate = max;
sas_phy->phy->minimum_linkrate = min;
prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max); prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
disable_phy_v2_hw(hisi_hba, phy_no);
msleep(100);
hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
prog_phy_link_rate); prog_phy_link_rate);
start_phy_v2_hw(hisi_hba, phy_no);
} }
static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id) static int get_wideport_bitmap_v2_hw(struct hisi_hba *hisi_hba, int port_id)
......
...@@ -1879,29 +1879,12 @@ static int hisi_sas_v3_init(struct hisi_hba *hisi_hba) ...@@ -1879,29 +1879,12 @@ static int hisi_sas_v3_init(struct hisi_hba *hisi_hba)
static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no, static void phy_set_linkrate_v3_hw(struct hisi_hba *hisi_hba, int phy_no,
struct sas_phy_linkrates *r) struct sas_phy_linkrates *r)
{ {
struct hisi_sas_phy *phy = &hisi_hba->phy[phy_no]; enum sas_linkrate max = r->maximum_linkrate;
struct asd_sas_phy *sas_phy = &phy->sas_phy;
enum sas_linkrate min, max;
u32 prog_phy_link_rate = 0x800; u32 prog_phy_link_rate = 0x800;
if (r->maximum_linkrate == SAS_LINK_RATE_UNKNOWN) {
max = sas_phy->phy->maximum_linkrate;
min = r->minimum_linkrate;
} else if (r->minimum_linkrate == SAS_LINK_RATE_UNKNOWN) {
max = r->maximum_linkrate;
min = sas_phy->phy->minimum_linkrate;
} else
return;
sas_phy->phy->maximum_linkrate = max;
sas_phy->phy->minimum_linkrate = min;
prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max); prog_phy_link_rate |= hisi_sas_get_prog_phy_linkrate_mask(max);
disable_phy_v3_hw(hisi_hba, phy_no);
msleep(100);
hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE, hisi_sas_phy_write32(hisi_hba, phy_no, PROG_PHY_LINK_RATE,
prog_phy_link_rate); prog_phy_link_rate);
start_phy_v3_hw(hisi_hba, phy_no);
} }
static void interrupt_disable_v3_hw(struct hisi_hba *hisi_hba) static void interrupt_disable_v3_hw(struct hisi_hba *hisi_hba)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册