Skip to content

Commit f47301b

Browse files
authored
Merge pull request #112 from Microsemi/nt-improve
Add a lock to protect NT partition operations
2 parents 7b1a015 + ed2a9cc commit f47301b

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

ntb_hw_switchtec.c

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ struct switchtec_ntb {
127127
enum ntb_width link_width;
128128
struct work_struct check_link_status_work;
129129
bool link_force_down;
130+
131+
struct mutex nt_op_lock;
130132
};
131133

132134
static struct switchtec_ntb *ntb_sndev(struct ntb_dev *ntb)
@@ -392,10 +394,11 @@ static int switchtec_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
392394
return -EINVAL;
393395
}
394396

397+
mutex_lock(&sndev->nt_op_lock);
395398
rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_LOCK,
396399
NTB_CTRL_PART_STATUS_LOCKED);
397400
if (rc)
398-
return rc;
401+
goto unlock_exit;
399402

400403
if (size == 0) {
401404
if (widx < nr_direct_mw)
@@ -426,6 +429,8 @@ static int switchtec_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
426429
NTB_CTRL_PART_STATUS_NORMAL);
427430
}
428431

432+
unlock_exit:
433+
mutex_unlock(&sndev->nt_op_lock);
429434
return rc;
430435
}
431436

@@ -1012,6 +1017,8 @@ static int switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
10121017
sndev->mmio_self_dbmsg = &sndev->mmio_dbmsg[sndev->self_partition];
10131018
sndev->mmio_peer_dbmsg = sndev->mmio_self_dbmsg;
10141019

1020+
mutex_init(&sndev->nt_op_lock);
1021+
10151022
return 0;
10161023
}
10171024

@@ -1023,10 +1030,11 @@ static int config_rsvd_lut_win(struct switchtec_ntb *sndev,
10231030
u32 ctl_val;
10241031
int rc;
10251032

1033+
mutex_lock(&sndev->nt_op_lock);
10261034
rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_LOCK,
10271035
NTB_CTRL_PART_STATUS_LOCKED);
10281036
if (rc)
1029-
return rc;
1037+
goto unlock_exit;
10301038

10311039
ctl_val = ioread32(&ctl->bar_entry[peer_bar].ctl);
10321040
ctl_val &= 0xFF;
@@ -1048,10 +1056,11 @@ static int config_rsvd_lut_win(struct switchtec_ntb *sndev,
10481056
dev_err(&sndev->stdev->dev,
10491057
"Error setting up reserved lut window: %08x / %08x\n",
10501058
bar_error, lut_error);
1051-
return rc;
10521059
}
10531060

1054-
return 0;
1061+
unlock_exit:
1062+
mutex_unlock(&sndev->nt_op_lock);
1063+
return rc;
10551064
}
10561065

10571066
static int add_req_id(struct switchtec_ntb *sndev,
@@ -1066,11 +1075,12 @@ static int add_req_id(struct switchtec_ntb *sndev,
10661075

10671076
table_size = ioread16(&mmio_ctrl->req_id_table_size);
10681077

1078+
mutex_lock(&sndev->nt_op_lock);
10691079
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
10701080
NTB_CTRL_PART_OP_LOCK,
10711081
NTB_CTRL_PART_STATUS_LOCKED);
10721082
if (rc)
1073-
return rc;
1083+
goto unlock_exit;
10741084

10751085
for (i = 0; i < table_size; i++) {
10761086
proxy_id = ioread32(&mmio_ctrl->req_id_table[i]);
@@ -1080,7 +1090,7 @@ static int add_req_id(struct switchtec_ntb *sndev,
10801090

10811091
if (proxy_id & NTB_CTRL_REQ_ID_EN &&
10821092
proxy_id >> 16 == req_id) {
1083-
goto unlock_exit;
1093+
goto nt_op_unlock_exit;
10841094
}
10851095
}
10861096

@@ -1101,7 +1111,7 @@ static int add_req_id(struct switchtec_ntb *sndev,
11011111
added = true;
11021112
}
11031113

1104-
unlock_exit:
1114+
nt_op_unlock_exit:
11051115
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
11061116
NTB_CTRL_PART_OP_CFG,
11071117
NTB_CTRL_PART_STATUS_NORMAL);
@@ -1114,9 +1124,11 @@ static int add_req_id(struct switchtec_ntb *sndev,
11141124
}
11151125

11161126
if (!added)
1117-
return -EFAULT;
1127+
rc = -EFAULT;
11181128

1119-
return 0;
1129+
unlock_exit:
1130+
mutex_unlock(&sndev->nt_op_lock);
1131+
return rc;
11201132
}
11211133

11221134
static int del_req_id(struct switchtec_ntb *sndev,
@@ -1130,11 +1142,12 @@ static int del_req_id(struct switchtec_ntb *sndev,
11301142

11311143
table_size = ioread16(&mmio_ctrl->req_id_table_size);
11321144

1145+
mutex_lock(&sndev->nt_op_lock);
11331146
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
11341147
NTB_CTRL_PART_OP_LOCK,
11351148
NTB_CTRL_PART_STATUS_LOCKED);
11361149
if (rc)
1137-
return rc;
1150+
goto unlock_exit;
11381151

11391152
for (i = 0; i < table_size; i++) {
11401153
rid = ioread32(&mmio_ctrl->req_id_table[i]);
@@ -1169,9 +1182,11 @@ static int del_req_id(struct switchtec_ntb *sndev,
11691182
}
11701183

11711184
if (!deleted)
1172-
return -ENXIO;
1185+
rc = -ENXIO;
11731186

1174-
return 0;
1187+
unlock_exit:
1188+
mutex_unlock(&sndev->nt_op_lock);
1189+
return rc;
11751190
}
11761191

11771192
static int clr_req_ids(struct switchtec_ntb *sndev,
@@ -1183,11 +1198,12 @@ static int clr_req_ids(struct switchtec_ntb *sndev,
11831198

11841199
table_size = ioread16(&mmio_ctrl->req_id_table_size);
11851200

1201+
mutex_lock(&sndev->nt_op_lock);
11861202
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
11871203
NTB_CTRL_PART_OP_LOCK,
11881204
NTB_CTRL_PART_STATUS_LOCKED);
11891205
if (rc)
1190-
return rc;
1206+
goto unlock_exit;
11911207

11921208
for (i = 0; i < table_size; i++)
11931209
iowrite32(0, &mmio_ctrl->req_id_table[i]);
@@ -1203,7 +1219,9 @@ static int clr_req_ids(struct switchtec_ntb *sndev,
12031219
error);
12041220
}
12051221

1206-
return 0;
1222+
unlock_exit:
1223+
mutex_unlock(&sndev->nt_op_lock);
1224+
return rc;
12071225
}
12081226

12091227
static int crosslink_setup_mws(struct switchtec_ntb *sndev,
@@ -1219,10 +1237,11 @@ static int crosslink_setup_mws(struct switchtec_ntb *sndev,
12191237
int xlate_pos;
12201238
u32 ctl_val;
12211239

1240+
mutex_lock(&sndev->nt_op_lock);
12221241
rc = switchtec_ntb_part_op(sndev, ctl, NTB_CTRL_PART_OP_LOCK,
12231242
NTB_CTRL_PART_STATUS_LOCKED);
12241243
if (rc)
1225-
return rc;
1244+
goto unlock_exit;
12261245

12271246
for (i = 0; i < sndev->nr_lut_mw; i++) {
12281247
if (i == ntb_dbmsg_lut_idx || i == ntb_req_id_lut_idx)
@@ -1268,10 +1287,11 @@ static int crosslink_setup_mws(struct switchtec_ntb *sndev,
12681287
dev_err(&sndev->stdev->dev,
12691288
"Error setting up cross link windows: %08x / %08x\n",
12701289
bar_error, lut_error);
1271-
return rc;
12721290
}
12731291

1274-
return 0;
1292+
unlock_exit:
1293+
mutex_unlock(&sndev->nt_op_lock);
1294+
return rc;
12751295
}
12761296

12771297
static int crosslink_setup_req_ids(struct switchtec_ntb *sndev,

0 commit comments

Comments
 (0)