@@ -1234,11 +1234,15 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie,
1234
1234
}
1235
1235
1236
1236
static void kvaser_pciefd_change_state (struct kvaser_pciefd_can * can ,
1237
+ const struct can_berr_counter * bec ,
1237
1238
struct can_frame * cf ,
1238
1239
enum can_state new_state ,
1239
1240
enum can_state tx_state ,
1240
1241
enum can_state rx_state )
1241
1242
{
1243
+ enum can_state old_state ;
1244
+
1245
+ old_state = can -> can .state ;
1242
1246
can_change_state (can -> can .dev , cf , tx_state , rx_state );
1243
1247
1244
1248
if (new_state == CAN_STATE_BUS_OFF ) {
@@ -1254,6 +1258,18 @@ static void kvaser_pciefd_change_state(struct kvaser_pciefd_can *can,
1254
1258
can_bus_off (ndev );
1255
1259
}
1256
1260
}
1261
+ if (old_state == CAN_STATE_BUS_OFF &&
1262
+ new_state == CAN_STATE_ERROR_ACTIVE &&
1263
+ can -> can .restart_ms ) {
1264
+ can -> can .can_stats .restarts ++ ;
1265
+ if (cf )
1266
+ cf -> can_id |= CAN_ERR_RESTARTED ;
1267
+ }
1268
+ if (cf && new_state != CAN_STATE_BUS_OFF ) {
1269
+ cf -> can_id |= CAN_ERR_CNT ;
1270
+ cf -> data [6 ] = bec -> txerr ;
1271
+ cf -> data [7 ] = bec -> rxerr ;
1272
+ }
1257
1273
}
1258
1274
1259
1275
static void kvaser_pciefd_packet_to_state (struct kvaser_pciefd_rx_packet * p ,
@@ -1299,14 +1315,7 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can,
1299
1315
kvaser_pciefd_packet_to_state (p , & bec , & new_state , & tx_state , & rx_state );
1300
1316
skb = alloc_can_err_skb (ndev , & cf );
1301
1317
if (new_state != old_state ) {
1302
- kvaser_pciefd_change_state (can , cf , new_state , tx_state , rx_state );
1303
- if (old_state == CAN_STATE_BUS_OFF &&
1304
- new_state == CAN_STATE_ERROR_ACTIVE &&
1305
- can -> can .restart_ms ) {
1306
- can -> can .can_stats .restarts ++ ;
1307
- if (skb )
1308
- cf -> can_id |= CAN_ERR_RESTARTED ;
1309
- }
1318
+ kvaser_pciefd_change_state (can , & bec , cf , new_state , tx_state , rx_state );
1310
1319
}
1311
1320
1312
1321
can -> err_rep_cnt ++ ;
@@ -1359,6 +1368,7 @@ static int kvaser_pciefd_handle_status_resp(struct kvaser_pciefd_can *can,
1359
1368
{
1360
1369
struct can_berr_counter bec ;
1361
1370
enum can_state old_state , new_state , tx_state , rx_state ;
1371
+ int ret = 0 ;
1362
1372
1363
1373
old_state = can -> can .state ;
1364
1374
@@ -1372,33 +1382,23 @@ static int kvaser_pciefd_handle_status_resp(struct kvaser_pciefd_can *can,
1372
1382
struct can_frame * cf ;
1373
1383
1374
1384
skb = alloc_can_err_skb (ndev , & cf );
1375
- if (!skb ) {
1385
+ kvaser_pciefd_change_state (can , & bec , cf , new_state , tx_state , rx_state );
1386
+ if (skb ) {
1387
+ kvaser_pciefd_set_skb_timestamp (can -> kv_pcie , skb , p -> timestamp );
1388
+ netif_rx (skb );
1389
+ } else {
1376
1390
ndev -> stats .rx_dropped ++ ;
1377
- return - ENOMEM ;
1391
+ netdev_warn (ndev , "No memory left for err_skb\n" );
1392
+ ret = - ENOMEM ;
1378
1393
}
1379
-
1380
- kvaser_pciefd_change_state (can , cf , new_state , tx_state , rx_state );
1381
- if (old_state == CAN_STATE_BUS_OFF &&
1382
- new_state == CAN_STATE_ERROR_ACTIVE &&
1383
- can -> can .restart_ms ) {
1384
- can -> can .can_stats .restarts ++ ;
1385
- cf -> can_id |= CAN_ERR_RESTARTED ;
1386
- }
1387
-
1388
- kvaser_pciefd_set_skb_timestamp (can -> kv_pcie , skb , p -> timestamp );
1389
-
1390
- cf -> data [6 ] = bec .txerr ;
1391
- cf -> data [7 ] = bec .rxerr ;
1392
-
1393
- netif_rx (skb );
1394
1394
}
1395
1395
can -> bec .txerr = bec .txerr ;
1396
1396
can -> bec .rxerr = bec .rxerr ;
1397
1397
/* Check if we need to poll the error counters */
1398
1398
if (bec .txerr || bec .rxerr )
1399
1399
mod_timer (& can -> bec_poll_timer , KVASER_PCIEFD_BEC_POLL_FREQ );
1400
1400
1401
- return 0 ;
1401
+ return ret ;
1402
1402
}
1403
1403
1404
1404
static int kvaser_pciefd_handle_status_packet (struct kvaser_pciefd * pcie ,
0 commit comments