@@ -153,7 +153,6 @@ enum hinic_mbox_tx_status {
153
153
(MBOX_MSG_ID(func_to_func_mbox) + 1) & MBOX_MSG_ID_MASK)
154
154
155
155
#define FUNC_ID_OFF_SET_8B 8
156
- #define FUNC_ID_OFF_SET_10B 10
157
156
158
157
/* max message counter wait to process for one function */
159
158
#define HINIC_MAX_MSG_CNT_TO_PROCESS 10
@@ -189,6 +188,37 @@ enum mbox_aeq_trig_type {
189
188
TRIGGER ,
190
189
};
191
190
191
+ static bool check_func_id (struct hinic_hwdev * hwdev , u16 src_func_idx ,
192
+ const void * buf_in , u16 in_size , u16 offset )
193
+ {
194
+ u16 func_idx ;
195
+
196
+ if (in_size < offset + sizeof (func_idx )) {
197
+ dev_warn (& hwdev -> hwif -> pdev -> dev ,
198
+ "Receive mailbox msg len: %d less than %d Bytes is invalid\n" ,
199
+ in_size , offset );
200
+ return false;
201
+ }
202
+
203
+ func_idx = * ((u16 * )((u8 * )buf_in + offset ));
204
+
205
+ if (src_func_idx != func_idx ) {
206
+ dev_warn (& hwdev -> hwif -> pdev -> dev ,
207
+ "Receive mailbox function id: 0x%x not equal to msg function id: 0x%x\n" ,
208
+ src_func_idx , func_idx );
209
+ return false;
210
+ }
211
+
212
+ return true;
213
+ }
214
+
215
+ bool hinic_mbox_check_func_id_8B (struct hinic_hwdev * hwdev , u16 func_idx ,
216
+ void * buf_in , u16 in_size )
217
+ {
218
+ return check_func_id (hwdev , func_idx , buf_in , in_size ,
219
+ FUNC_ID_OFF_SET_8B );
220
+ }
221
+
192
222
/**
193
223
* hinic_register_pf_mbox_cb - register mbox callback for pf
194
224
* @hwdev: the pointer to hw device
@@ -1205,15 +1235,156 @@ static void free_mbox_wb_status(struct hinic_mbox_func_to_func *func_to_func)
1205
1235
send_mbox -> wb_paddr );
1206
1236
}
1207
1237
1238
+ bool hinic_mbox_check_cmd_valid (struct hinic_hwdev * hwdev ,
1239
+ struct vf_cmd_check_handle * cmd_handle ,
1240
+ u16 vf_id , u8 cmd , void * buf_in ,
1241
+ u16 in_size , u8 size )
1242
+ {
1243
+ u16 src_idx = vf_id + hinic_glb_pf_vf_offset (hwdev -> hwif );
1244
+ int i ;
1245
+
1246
+ for (i = 0 ; i < size ; i ++ ) {
1247
+ if (cmd == cmd_handle [i ].cmd ) {
1248
+ if (cmd_handle [i ].check_cmd )
1249
+ return cmd_handle [i ].check_cmd (hwdev , src_idx ,
1250
+ buf_in , in_size );
1251
+ else
1252
+ return true;
1253
+ }
1254
+ }
1255
+
1256
+ dev_err (& hwdev -> hwif -> pdev -> dev ,
1257
+ "PF Receive VF(%d) unsupported cmd(0x%x)\n" ,
1258
+ vf_id + hinic_glb_pf_vf_offset (hwdev -> hwif ), cmd );
1259
+
1260
+ return false;
1261
+ }
1262
+
1263
+ static bool hinic_cmdq_check_vf_ctxt (struct hinic_hwdev * hwdev ,
1264
+ struct hinic_cmdq_ctxt * cmdq_ctxt )
1265
+ {
1266
+ struct hinic_cmdq_ctxt_info * ctxt_info = & cmdq_ctxt -> ctxt_info ;
1267
+ u64 curr_pg_pfn , wq_block_pfn ;
1268
+
1269
+ if (cmdq_ctxt -> ppf_idx != HINIC_HWIF_PPF_IDX (hwdev -> hwif ) ||
1270
+ cmdq_ctxt -> cmdq_type > HINIC_MAX_CMDQ_TYPES )
1271
+ return false;
1272
+
1273
+ curr_pg_pfn = HINIC_CMDQ_CTXT_PAGE_INFO_GET
1274
+ (ctxt_info -> curr_wqe_page_pfn , CURR_WQE_PAGE_PFN );
1275
+ wq_block_pfn = HINIC_CMDQ_CTXT_BLOCK_INFO_GET
1276
+ (ctxt_info -> wq_block_pfn , WQ_BLOCK_PFN );
1277
+ /* VF must use 0-level CLA */
1278
+ if (curr_pg_pfn != wq_block_pfn )
1279
+ return false;
1280
+
1281
+ return true;
1282
+ }
1283
+
1284
+ static bool check_cmdq_ctxt (struct hinic_hwdev * hwdev , u16 func_idx ,
1285
+ void * buf_in , u16 in_size )
1286
+ {
1287
+ if (!hinic_mbox_check_func_id_8B (hwdev , func_idx , buf_in , in_size ))
1288
+ return false;
1289
+
1290
+ return hinic_cmdq_check_vf_ctxt (hwdev , buf_in );
1291
+ }
1292
+
1293
+ #define HW_CTX_QPS_VALID (hw_ctxt ) \
1294
+ ((hw_ctxt)->rq_depth >= HINIC_QUEUE_MIN_DEPTH && \
1295
+ (hw_ctxt)->rq_depth <= HINIC_QUEUE_MAX_DEPTH && \
1296
+ (hw_ctxt)->sq_depth >= HINIC_QUEUE_MIN_DEPTH && \
1297
+ (hw_ctxt)->sq_depth <= HINIC_QUEUE_MAX_DEPTH && \
1298
+ (hw_ctxt)->rx_buf_sz_idx <= HINIC_MAX_RX_BUFFER_SIZE)
1299
+
1300
+ static bool hw_ctxt_qps_param_valid (struct hinic_cmd_hw_ioctxt * hw_ctxt )
1301
+ {
1302
+ if (HW_CTX_QPS_VALID (hw_ctxt ))
1303
+ return true;
1304
+
1305
+ if (!hw_ctxt -> rq_depth && !hw_ctxt -> sq_depth &&
1306
+ !hw_ctxt -> rx_buf_sz_idx )
1307
+ return true;
1308
+
1309
+ return false;
1310
+ }
1311
+
1312
+ static bool check_hwctxt (struct hinic_hwdev * hwdev , u16 func_idx ,
1313
+ void * buf_in , u16 in_size )
1314
+ {
1315
+ struct hinic_cmd_hw_ioctxt * hw_ctxt = buf_in ;
1316
+
1317
+ if (!hinic_mbox_check_func_id_8B (hwdev , func_idx , buf_in , in_size ))
1318
+ return false;
1319
+
1320
+ if (hw_ctxt -> ppf_idx != HINIC_HWIF_PPF_IDX (hwdev -> hwif ))
1321
+ return false;
1322
+
1323
+ if (hw_ctxt -> set_cmdq_depth ) {
1324
+ if (hw_ctxt -> cmdq_depth >= HINIC_QUEUE_MIN_DEPTH &&
1325
+ hw_ctxt -> cmdq_depth <= HINIC_QUEUE_MAX_DEPTH )
1326
+ return true;
1327
+
1328
+ return false;
1329
+ }
1330
+
1331
+ return hw_ctxt_qps_param_valid (hw_ctxt );
1332
+ }
1333
+
1334
+ static bool check_set_wq_page_size (struct hinic_hwdev * hwdev , u16 func_idx ,
1335
+ void * buf_in , u16 in_size )
1336
+ {
1337
+ struct hinic_wq_page_size * page_size_info = buf_in ;
1338
+
1339
+ if (!hinic_mbox_check_func_id_8B (hwdev , func_idx , buf_in , in_size ))
1340
+ return false;
1341
+
1342
+ if (page_size_info -> ppf_idx != HINIC_HWIF_PPF_IDX (hwdev -> hwif ))
1343
+ return false;
1344
+
1345
+ if (((1U << page_size_info -> page_size ) * SZ_4K ) !=
1346
+ HINIC_DEFAULT_WQ_PAGE_SIZE )
1347
+ return false;
1348
+
1349
+ return true;
1350
+ }
1351
+
1352
+ static struct vf_cmd_check_handle hw_cmd_support_vf [] = {
1353
+ {HINIC_COMM_CMD_START_FLR , hinic_mbox_check_func_id_8B },
1354
+ {HINIC_COMM_CMD_DMA_ATTR_SET , hinic_mbox_check_func_id_8B },
1355
+ {HINIC_COMM_CMD_CMDQ_CTXT_SET , check_cmdq_ctxt },
1356
+ {HINIC_COMM_CMD_CMDQ_CTXT_GET , check_cmdq_ctxt },
1357
+ {HINIC_COMM_CMD_HWCTXT_SET , check_hwctxt },
1358
+ {HINIC_COMM_CMD_HWCTXT_GET , check_hwctxt },
1359
+ {HINIC_COMM_CMD_SQ_HI_CI_SET , hinic_mbox_check_func_id_8B },
1360
+ {HINIC_COMM_CMD_RES_STATE_SET , hinic_mbox_check_func_id_8B },
1361
+ {HINIC_COMM_CMD_IO_RES_CLEAR , hinic_mbox_check_func_id_8B },
1362
+ {HINIC_COMM_CMD_CEQ_CTRL_REG_WR_BY_UP , hinic_mbox_check_func_id_8B },
1363
+ {HINIC_COMM_CMD_MSI_CTRL_REG_WR_BY_UP , hinic_mbox_check_func_id_8B },
1364
+ {HINIC_COMM_CMD_MSI_CTRL_REG_RD_BY_UP , hinic_mbox_check_func_id_8B },
1365
+ {HINIC_COMM_CMD_L2NIC_RESET , hinic_mbox_check_func_id_8B },
1366
+ {HINIC_COMM_CMD_PAGESIZE_SET , check_set_wq_page_size },
1367
+ };
1368
+
1208
1369
static int comm_pf_mbox_handler (void * handle , u16 vf_id , u8 cmd , void * buf_in ,
1209
1370
u16 in_size , void * buf_out , u16 * out_size )
1210
1371
{
1372
+ u8 size = ARRAY_SIZE (hw_cmd_support_vf );
1211
1373
struct hinic_hwdev * hwdev = handle ;
1212
1374
struct hinic_pfhwdev * pfhwdev ;
1213
1375
int err = 0 ;
1214
1376
1215
1377
pfhwdev = container_of (hwdev , struct hinic_pfhwdev , hwdev );
1216
1378
1379
+ if (!hinic_mbox_check_cmd_valid (handle , hw_cmd_support_vf , vf_id , cmd ,
1380
+ buf_in , in_size , size )) {
1381
+ dev_err (& hwdev -> hwif -> pdev -> dev ,
1382
+ "PF Receive VF: %d common cmd: 0x%x or mbox len: 0x%x is invalid\n" ,
1383
+ vf_id + hinic_glb_pf_vf_offset (hwdev -> hwif ), cmd ,
1384
+ in_size );
1385
+ return HINIC_MBOX_VF_CMD_ERROR ;
1386
+ }
1387
+
1217
1388
if (cmd == HINIC_COMM_CMD_START_FLR ) {
1218
1389
* out_size = 0 ;
1219
1390
} else {
0 commit comments