@@ -78,18 +78,25 @@ RX1IE: Receive Buffer 1 Full I questo non serve
78
78
#define AFTER_SUSPEND_POWER 4
79
79
#define AFTER_SUSPEND_RESTART 8
80
80
81
- #define X8H7_FLT_EXT 0x80000000
82
81
#define X8H7_STD_FLT_MAX 128
83
82
#define X8H7_EXT_FLT_MAX 64
84
83
85
84
/**
86
85
*/
87
- struct x8h7_can_filter {
88
- u32 id ;
89
- u32 mask ;
86
+ union x8h7_can_filter_message
87
+ {
88
+ struct __attribute__((packed ))
89
+ {
90
+ uint32_t idx ;
91
+ uint32_t id ;
92
+ uint32_t mask ;
93
+ } field ;
94
+ uint8_t buf [sizeof (uint32_t ) /* idx */ + sizeof (uint32_t ) /* id */ + sizeof (uint32_t ) /* mask */ ];
90
95
};
91
96
92
- union x8h7_can_message
97
+ /**
98
+ */
99
+ union x8h7_can_frame_message
93
100
{
94
101
struct __attribute__((packed ))
95
102
{
@@ -123,8 +130,9 @@ struct x8h7_can_priv {
123
130
int after_suspend ;
124
131
int restart_tx ;
125
132
126
- struct x8h7_can_filter std_flt [X8H7_STD_FLT_MAX ];
127
- struct x8h7_can_filter ext_flt [X8H7_EXT_FLT_MAX ];
133
+ struct can_filter std_flt [X8H7_STD_FLT_MAX ];
134
+ struct can_filter ext_flt [X8H7_EXT_FLT_MAX ];
135
+
128
136
struct mutex lock ;
129
137
};
130
138
@@ -274,7 +282,7 @@ static void x8h7_can_hook(void *arg, x8h7_pkt_t *pkt)
274
282
} else {
275
283
struct sk_buff * skb ;
276
284
struct can_frame * frame ;
277
- union x8h7_can_message x8h7_can_msg ;
285
+ union x8h7_can_frame_message x8h7_can_msg ;
278
286
279
287
skb = alloc_can_skb (priv -> net , & frame );
280
288
if (!skb ) {
@@ -286,7 +294,7 @@ static void x8h7_can_hook(void *arg, x8h7_pkt_t *pkt)
286
294
/* Copy header from raw byte-stream onto union. */
287
295
memcpy (x8h7_can_msg .buf , pkt -> data , X8H7_CAN_HEADER_SIZE );
288
296
289
- /* Extract can_id and can_dlc. Note: x8h7_can_message uses the exact
297
+ /* Extract can_id and can_dlc. Note: x8h7_can_frame_message uses the exact
290
298
* same flags for signaling extended/standard id mode or remote
291
299
* retransmit request as struct can_frame.
292
300
*/
@@ -522,7 +530,12 @@ static void x8h7_can_hw_rx(struct x8h7_can_priv *priv)
522
530
*/
523
531
static void x8h7_can_hw_tx (struct x8h7_can_priv * priv , struct can_frame * frame )
524
532
{
525
- union x8h7_can_message x8h7_can_msg ;
533
+ union x8h7_can_frame_message x8h7_can_msg ;
534
+ #ifdef DEBUG
535
+ char data_str [X8H7_CAN_FRAME_MAX_DATA_LEN * 4 ];
536
+ int i ;
537
+ int len ;
538
+ #endif
526
539
527
540
DBG_PRINT ("\n" );
528
541
@@ -535,14 +548,12 @@ static void x8h7_can_hw_tx(struct x8h7_can_priv *priv, struct can_frame *frame)
535
548
memcpy (x8h7_can_msg .field .data , frame -> data , x8h7_can_msg .field .len );
536
549
537
550
#ifdef DEBUG
538
- char data_str [X8H7_CAN_FRAME_MAX_DATA_LEN * 4 ] = {0 };
539
- int i = 0 , len = 0 ;
540
-
541
- for (i = 0 ; (i < frame -> can_dlc ) && (len < sizeof (data_str )); i ++ )
551
+ i = 0 ; len = 0 ;
552
+ for (i = 0 ; (i < x8h7_can_msg .field .len ) && (len < sizeof (data_str )); i ++ )
542
553
{
543
- len += snprintf (data_str + len , sizeof (data_str ) - len , " %02X" , can_msg .field .data [i ]);
554
+ len += snprintf (data_str + len , sizeof (data_str ) - len , " %02X" , x8h7_can_msg .field .data [i ]);
544
555
}
545
- DBG_PRINT ("Send CAN frame to H7: id = %08X, len = %d, data = [%s ]\n" , can_msg .field .id , can_msg .field .len , data_str );
556
+ DBG_PRINT ("Send CAN frame to H7: id = %08X, len = %d, data = [%s ]\n" , x8h7_can_msg .field .id , x8h7_can_msg .field .len , data_str );
546
557
#endif
547
558
548
559
x8h7_pkt_enq (priv -> periph ,
@@ -783,46 +794,20 @@ static const struct net_device_ops x8h7_can_netdev_ops = {
783
794
784
795
/**
785
796
*/
786
- static int x8h7_can_config_filter (struct x8h7_can_priv * priv ,
787
- const char * buf , int type )
797
+ static int x8h7_can_hw_config_filter (struct x8h7_can_priv * priv ,
798
+ uint32_t const idx ,
799
+ uint32_t const id ,
800
+ uint32_t const mask )
788
801
{
789
- u32 idx ;
790
- u32 id ;
791
- u32 mask ;
792
- int ret ;
793
- u32 data [3 ];
802
+ union x8h7_can_filter_message x8h7_msg ;
794
803
795
- ret = sscanf (buf , "%x %x %x" , & idx , & id , & mask );
796
- if (ret != 3 ) {
797
- DBG_ERROR ("invalid num of params\n" );
798
- return -1 ;
799
- }
800
-
801
- if (type == 0 ) {
802
- if ((idx >= X8H7_STD_FLT_MAX ) ||
803
- (id & ~0x7FF ) || (mask & ~0x7FF )) {
804
- DBG_ERROR ("invalid params\n" );
805
- return -1 ;
806
- }
807
- priv -> std_flt [idx ].id = id ;
808
- priv -> std_flt [idx ].mask = mask ;
809
- } else {
810
- if ((idx >= X8H7_EXT_FLT_MAX ) ||
811
- (id & ~0x1FFFFFFF ) || (mask & ~0x1FFFFFFF )) {
812
- DBG_ERROR ("invalid params\n" );
813
- return -1 ;
814
- }
815
- priv -> ext_flt [idx ].id = id ;
816
- priv -> ext_flt [idx ].mask = mask ;
817
- idx |= X8H7_FLT_EXT ;
818
- }
804
+ x8h7_msg .field .idx = idx ;
805
+ x8h7_msg .field .id = id ;
806
+ x8h7_msg .field .mask = mask ;
819
807
820
808
DBG_PRINT ("SEND idx %X, id %X, mask %X\n" , idx , id , mask );
821
809
822
- data [0 ] = idx ;
823
- data [1 ] = id ;
824
- data [2 ] = mask ;
825
- x8h7_pkt_enq (priv -> periph , X8H7_CAN_OC_FLT , sizeof (data ), data );
810
+ x8h7_pkt_enq (priv -> periph , X8H7_CAN_OC_FLT , sizeof (x8h7_msg .buf ), x8h7_msg .buf );
826
811
x8h7_pkt_send ();
827
812
828
813
return 0 ;
@@ -839,11 +824,12 @@ static ssize_t x8h7_can_sf_show(struct device *dev,
839
824
int i ;
840
825
841
826
len = 0 ;
842
- for (i = 0 ; i < X8H7_STD_FLT_MAX ; i ++ ) {
843
- if (priv -> std_flt [i ].mask ) {
827
+ for (i = 0 ; i < X8H7_STD_FLT_MAX ; i ++ )
828
+ {
829
+ if (priv -> std_flt [i ].can_mask ) {
844
830
len += snprintf (buf + len , PAGE_SIZE - len ,
845
831
"%02X %08X %08X\n" ,
846
- i , priv -> std_flt [i ].id , priv -> std_flt [i ].mask );
832
+ i , priv -> std_flt [i ].can_id , priv -> std_flt [i ].can_mask );
847
833
}
848
834
}
849
835
return len ;
@@ -857,13 +843,33 @@ static ssize_t x8h7_can_sf_store(struct device *dev,
857
843
const char * buf , size_t count )
858
844
{
859
845
struct x8h7_can_priv * priv = netdev_priv (to_net_dev (dev ));
846
+ uint32_t idx ;
847
+ uint32_t id ;
848
+ uint32_t mask ;
860
849
int ret ;
861
850
862
- ret = x8h7_can_config_filter (priv , buf , 0 );
851
+ ret = sscanf (buf , "%x %x %x" , & idx , & id , & mask );
852
+
853
+ if (ret != 3 ) {
854
+ DBG_ERROR ("invalid num of params\n" );
855
+ return - EINVAL ;
856
+ }
857
+
858
+ if ((idx >= X8H7_STD_FLT_MAX ) ||
859
+ (id & ~0x7FF ) || (mask & ~0x7FF )) {
860
+ DBG_ERROR ("invalid params\n" );
861
+ return - EINVAL ;
862
+ }
863
+
864
+ ret = x8h7_can_hw_config_filter (priv , idx , id , mask );
863
865
if (ret ) {
864
866
DBG_ERROR ("set filter\n" );
865
- return -1 ;
867
+ return - EIO ;
866
868
}
869
+
870
+ priv -> std_flt [idx ].can_id = id ;
871
+ priv -> std_flt [idx ].can_mask = mask ;
872
+
867
873
return count ;
868
874
}
869
875
@@ -880,10 +886,10 @@ static ssize_t x8h7_can_ef_show(struct device *dev,
880
886
len = 0 ;
881
887
for (i = 0 ; i < X8H7_EXT_FLT_MAX ; i ++ )
882
888
{
883
- if (priv -> ext_flt [i ].mask ) {
889
+ if (priv -> ext_flt [i ].can_mask ) {
884
890
len += snprintf (buf + len , PAGE_SIZE - len ,
885
891
"%02X %08X %08X\n" ,
886
- i , priv -> ext_flt [i ].id , priv -> ext_flt [i ].mask );
892
+ i , priv -> ext_flt [i ].can_id , priv -> ext_flt [i ].can_mask );
887
893
}
888
894
}
889
895
return len ;
@@ -898,12 +904,32 @@ static ssize_t x8h7_can_ef_store(struct device *dev,
898
904
{
899
905
struct x8h7_can_priv * priv = netdev_priv (to_net_dev (dev ));
900
906
int ret ;
907
+ uint32_t idx ;
908
+ uint32_t id ;
909
+ uint32_t mask ;
901
910
902
- ret = x8h7_can_config_filter (priv , buf , 1 );
911
+ ret = sscanf (buf , "%x %x %x" , & idx , & id , & mask );
912
+
913
+ if (ret != 3 ) {
914
+ DBG_ERROR ("invalid num of params\n" );
915
+ return - EINVAL ;
916
+ }
917
+
918
+ if ((idx >= X8H7_EXT_FLT_MAX ) ||
919
+ (id & ~0x1FFFFFFF ) || (mask & ~0x1FFFFFFF )) {
920
+ DBG_ERROR ("invalid params\n" );
921
+ return - EINVAL ;
922
+ }
923
+
924
+ ret = x8h7_can_hw_config_filter (priv , idx , (CAN_EFF_FLAG | id ), mask );
903
925
if (ret ) {
904
926
DBG_ERROR ("set filter\n" );
905
- return -1 ;
927
+ return - EIO ;
906
928
}
929
+
930
+ priv -> ext_flt [idx ].can_id = id ;
931
+ priv -> ext_flt [idx ].can_mask = mask ;
932
+
907
933
return count ;
908
934
}
909
935
0 commit comments