Skip to content

Commit 54aa786

Browse files
Joey Zhangwesleywesley
authored andcommitted
ntb_hw_switchtec: Fix unable to set mw translation bug
When one host receives the link force down message from peer host, ntb_hw_switchtec driver and NTB client(e.g. ntb_transport) may simultaneously call function switchtec_ntb_part_op() to set up MWs. This will lead to the failure to set up the transport MW. To solve this, we put all the link status checking stuff in the same work queue. Signed-off-by: Joey Zhang <[email protected]>
1 parent 6eec61b commit 54aa786

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

ntb_hw_switchtec.c

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ struct switchtec_ntb {
123123
bool link_is_up;
124124
enum ntb_speed link_speed;
125125
enum ntb_width link_width;
126-
struct work_struct link_reinit_work;
126+
struct work_struct check_link_status_work;
127+
bool link_force_down;
127128
};
128129

129130
static struct switchtec_ntb *ntb_sndev(struct ntb_dev *ntb)
@@ -500,32 +501,11 @@ enum switchtec_msg {
500501

501502
static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev);
502503

503-
static void link_reinit_work(struct work_struct *work)
504-
{
505-
struct switchtec_ntb *sndev;
506-
507-
sndev = container_of(work, struct switchtec_ntb, link_reinit_work);
508-
switchtec_ntb_reinit_peer(sndev);
509-
}
510-
511-
static void switchtec_ntb_check_link(struct switchtec_ntb *sndev,
512-
enum switchtec_msg msg)
504+
static void switchtec_ntb_link_status_update(struct switchtec_ntb *sndev)
513505
{
514506
int link_sta;
515507
int old = sndev->link_is_up;
516508

517-
if (msg == MSG_LINK_FORCE_DOWN) {
518-
schedule_work(&sndev->link_reinit_work);
519-
520-
if (sndev->link_is_up) {
521-
sndev->link_is_up = 0;
522-
ntb_link_event(&sndev->ntb);
523-
dev_info(&sndev->stdev->dev, "ntb link forced down\n");
524-
}
525-
526-
return;
527-
}
528-
529509
link_sta = sndev->self_shared->link_sta;
530510
if (link_sta) {
531511
u64 peer = ioread64(&sndev->peer_shared->magic);
@@ -550,6 +530,38 @@ static void switchtec_ntb_check_link(struct switchtec_ntb *sndev,
550530
}
551531
}
552532

533+
static void check_link_status_work(struct work_struct *work)
534+
{
535+
struct switchtec_ntb *sndev;
536+
537+
sndev = container_of(work, struct switchtec_ntb,
538+
check_link_status_work);
539+
540+
if (sndev->link_force_down) {
541+
sndev->link_force_down = false;
542+
switchtec_ntb_reinit_peer(sndev);
543+
544+
if (sndev->link_is_up) {
545+
sndev->link_is_up = 0;
546+
ntb_link_event(&sndev->ntb);
547+
dev_info(&sndev->stdev->dev, "ntb link forced down\n");
548+
}
549+
550+
return;
551+
}
552+
553+
switchtec_ntb_link_status_update(sndev);
554+
}
555+
556+
static void switchtec_ntb_check_link(struct switchtec_ntb *sndev,
557+
enum switchtec_msg msg)
558+
{
559+
if (msg == MSG_LINK_FORCE_DOWN)
560+
sndev->link_force_down = true;
561+
562+
schedule_work(&sndev->check_link_status_work);
563+
}
564+
553565
static void switchtec_ntb_link_notification(struct switchtec_dev *stdev)
554566
{
555567
struct switchtec_ntb *sndev = stdev->sndev;
@@ -582,7 +594,7 @@ static int switchtec_ntb_link_enable(struct ntb_dev *ntb,
582594
sndev->self_shared->link_sta = 1;
583595
switchtec_ntb_send_msg(sndev, LINK_MESSAGE, MSG_LINK_UP);
584596

585-
switchtec_ntb_check_link(sndev, MSG_CHECK_LINK);
597+
switchtec_ntb_link_status_update(sndev);
586598

587599
return 0;
588600
}
@@ -596,7 +608,7 @@ static int switchtec_ntb_link_disable(struct ntb_dev *ntb)
596608
sndev->self_shared->link_sta = 0;
597609
switchtec_ntb_send_msg(sndev, LINK_MESSAGE, MSG_LINK_DOWN);
598610

599-
switchtec_ntb_check_link(sndev, MSG_CHECK_LINK);
611+
switchtec_ntb_link_status_update(sndev);
600612

601613
return 0;
602614
}
@@ -829,7 +841,8 @@ static int switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
829841
sndev->ntb.topo = NTB_TOPO_NONE;
830842
sndev->ntb.ops = &switchtec_ntb_ops;
831843

832-
INIT_WORK(&sndev->link_reinit_work, link_reinit_work);
844+
INIT_WORK(&sndev->check_link_status_work, check_link_status_work);
845+
sndev->link_force_down = false;
833846

834847
sndev->self_partition = sndev->stdev->partition;
835848

0 commit comments

Comments
 (0)