forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/net/can/c_can/c_can.c
....@@ -344,15 +344,6 @@
344344 }
345345 }
346346
347
-static inline void c_can_activate_all_lower_rx_msg_obj(struct net_device *dev,
348
- int iface)
349
-{
350
- int i;
351
-
352
- for (i = C_CAN_MSG_OBJ_RX_FIRST; i <= C_CAN_MSG_RX_LOW_LAST; i++)
353
- c_can_object_get(dev, iface, i, IF_COMM_CLR_NEWDAT);
354
-}
355
-
356347 static int c_can_handle_lost_msg_obj(struct net_device *dev,
357348 int iface, int objno, u32 ctrl)
358349 {
....@@ -903,6 +894,9 @@
903894 struct can_berr_counter bec;
904895
905896 switch (error_type) {
897
+ case C_CAN_NO_ERROR:
898
+ priv->can.state = CAN_STATE_ERROR_ACTIVE;
899
+ break;
906900 case C_CAN_ERROR_WARNING:
907901 /* error warning state */
908902 priv->can.can_stats.error_warning++;
....@@ -933,6 +927,13 @@
933927 ERR_CNT_RP_SHIFT;
934928
935929 switch (error_type) {
930
+ case C_CAN_NO_ERROR:
931
+ /* error warning state */
932
+ cf->can_id |= CAN_ERR_CRTL;
933
+ cf->data[1] = CAN_ERR_CRTL_ACTIVE;
934
+ cf->data[6] = bec.txerr;
935
+ cf->data[7] = bec.rxerr;
936
+ break;
936937 case C_CAN_ERROR_WARNING:
937938 /* error warning state */
938939 cf->can_id |= CAN_ERR_CRTL;
....@@ -1077,11 +1078,17 @@
10771078 /* handle bus recovery events */
10781079 if ((!(curr & STATUS_BOFF)) && (last & STATUS_BOFF)) {
10791080 netdev_dbg(dev, "left bus off state\n");
1080
- priv->can.state = CAN_STATE_ERROR_ACTIVE;
1081
+ work_done += c_can_handle_state_change(dev, C_CAN_ERROR_PASSIVE);
10811082 }
1083
+
10821084 if ((!(curr & STATUS_EPASS)) && (last & STATUS_EPASS)) {
10831085 netdev_dbg(dev, "left error passive state\n");
1084
- priv->can.state = CAN_STATE_ERROR_ACTIVE;
1086
+ work_done += c_can_handle_state_change(dev, C_CAN_ERROR_WARNING);
1087
+ }
1088
+
1089
+ if ((!(curr & STATUS_EWARN)) && (last & STATUS_EWARN)) {
1090
+ netdev_dbg(dev, "left error warning state\n");
1091
+ work_done += c_can_handle_state_change(dev, C_CAN_NO_ERROR);
10851092 }
10861093
10871094 /* handle lec errors on the bus */
....@@ -1276,12 +1283,22 @@
12761283 time_after(time_out, jiffies))
12771284 cpu_relax();
12781285
1279
- if (time_after(jiffies, time_out))
1280
- return -ETIMEDOUT;
1286
+ if (time_after(jiffies, time_out)) {
1287
+ ret = -ETIMEDOUT;
1288
+ goto err_out;
1289
+ }
12811290
12821291 ret = c_can_start(dev);
1283
- if (!ret)
1284
- c_can_irq_control(priv, true);
1292
+ if (ret)
1293
+ goto err_out;
1294
+
1295
+ c_can_irq_control(priv, true);
1296
+
1297
+ return 0;
1298
+
1299
+err_out:
1300
+ c_can_reset_ram(priv, false);
1301
+ c_can_pm_runtime_put_sync(priv);
12851302
12861303 return ret;
12871304 }