@@ -63,21 +63,27 @@ enum gs_can_identify_mode {
6363};
6464
6565/* data types passed between host and device */
66+
67+ /* The firmware on the original USB2CAN by Geschwister Schneider
68+ * Technologie Entwicklungs- und Vertriebs UG exchanges all data
69+ * between the host and the device in host byte order. This is done
70+ * with the struct gs_host_config::byte_order member, which is sent
71+ * first to indicate the desired byte order.
72+ *
73+ * The widely used open source firmware candleLight doesn't support
74+ * this feature and exchanges the data in little endian byte order.
75+ */
6676struct gs_host_config {
67- u32 byte_order ;
77+ __le32 byte_order ;
6878} __packed ;
69- /* All data exchanged between host and device is exchanged in host byte order,
70- * thanks to the struct gs_host_config byte_order member, which is sent first
71- * to indicate the desired byte order.
72- */
7379
7480struct gs_device_config {
7581 u8 reserved1 ;
7682 u8 reserved2 ;
7783 u8 reserved3 ;
7884 u8 icount ;
79- u32 sw_version ;
80- u32 hw_version ;
85+ __le32 sw_version ;
86+ __le32 hw_version ;
8187} __packed ;
8288
8389#define GS_CAN_MODE_NORMAL 0
@@ -87,26 +93,26 @@ struct gs_device_config {
8793#define GS_CAN_MODE_ONE_SHOT BIT(3)
8894
8995struct gs_device_mode {
90- u32 mode ;
91- u32 flags ;
96+ __le32 mode ;
97+ __le32 flags ;
9298} __packed ;
9399
94100struct gs_device_state {
95- u32 state ;
96- u32 rxerr ;
97- u32 txerr ;
101+ __le32 state ;
102+ __le32 rxerr ;
103+ __le32 txerr ;
98104} __packed ;
99105
100106struct gs_device_bittiming {
101- u32 prop_seg ;
102- u32 phase_seg1 ;
103- u32 phase_seg2 ;
104- u32 sjw ;
105- u32 brp ;
107+ __le32 prop_seg ;
108+ __le32 phase_seg1 ;
109+ __le32 phase_seg2 ;
110+ __le32 sjw ;
111+ __le32 brp ;
106112} __packed ;
107113
108114struct gs_identify_mode {
109- u32 mode ;
115+ __le32 mode ;
110116} __packed ;
111117
112118#define GS_CAN_FEATURE_LISTEN_ONLY BIT(0)
@@ -117,23 +123,23 @@ struct gs_identify_mode {
117123#define GS_CAN_FEATURE_IDENTIFY BIT(5)
118124
119125struct gs_device_bt_const {
120- u32 feature ;
121- u32 fclk_can ;
122- u32 tseg1_min ;
123- u32 tseg1_max ;
124- u32 tseg2_min ;
125- u32 tseg2_max ;
126- u32 sjw_max ;
127- u32 brp_min ;
128- u32 brp_max ;
129- u32 brp_inc ;
126+ __le32 feature ;
127+ __le32 fclk_can ;
128+ __le32 tseg1_min ;
129+ __le32 tseg1_max ;
130+ __le32 tseg2_min ;
131+ __le32 tseg2_max ;
132+ __le32 sjw_max ;
133+ __le32 brp_min ;
134+ __le32 brp_max ;
135+ __le32 brp_inc ;
130136} __packed ;
131137
132138#define GS_CAN_FLAG_OVERFLOW 1
133139
134140struct gs_host_frame {
135141 u32 echo_id ;
136- u32 can_id ;
142+ __le32 can_id ;
137143
138144 u8 can_dlc ;
139145 u8 channel ;
@@ -329,13 +335,13 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
329335 if (!skb )
330336 return ;
331337
332- cf -> can_id = hf -> can_id ;
338+ cf -> can_id = le32_to_cpu ( hf -> can_id ) ;
333339
334340 cf -> can_dlc = get_can_dlc (hf -> can_dlc );
335341 memcpy (cf -> data , hf -> data , 8 );
336342
337343 /* ERROR frames tell us information about the controller */
338- if (hf -> can_id & CAN_ERR_FLAG )
344+ if (le32_to_cpu ( hf -> can_id ) & CAN_ERR_FLAG )
339345 gs_update_state (dev , cf );
340346
341347 netdev -> stats .rx_packets ++ ;
@@ -418,11 +424,11 @@ static int gs_usb_set_bittiming(struct net_device *netdev)
418424 if (!dbt )
419425 return - ENOMEM ;
420426
421- dbt -> prop_seg = bt -> prop_seg ;
422- dbt -> phase_seg1 = bt -> phase_seg1 ;
423- dbt -> phase_seg2 = bt -> phase_seg2 ;
424- dbt -> sjw = bt -> sjw ;
425- dbt -> brp = bt -> brp ;
427+ dbt -> prop_seg = cpu_to_le32 ( bt -> prop_seg ) ;
428+ dbt -> phase_seg1 = cpu_to_le32 ( bt -> phase_seg1 ) ;
429+ dbt -> phase_seg2 = cpu_to_le32 ( bt -> phase_seg2 ) ;
430+ dbt -> sjw = cpu_to_le32 ( bt -> sjw ) ;
431+ dbt -> brp = cpu_to_le32 ( bt -> brp ) ;
426432
427433 /* request bit timings */
428434 rc = usb_control_msg (interface_to_usbdev (intf ),
@@ -503,7 +509,7 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
503509
504510 cf = (struct can_frame * )skb -> data ;
505511
506- hf -> can_id = cf -> can_id ;
512+ hf -> can_id = cpu_to_le32 ( cf -> can_id ) ;
507513 hf -> can_dlc = cf -> can_dlc ;
508514 memcpy (hf -> data , cf -> data , cf -> can_dlc );
509515
@@ -573,6 +579,7 @@ static int gs_can_open(struct net_device *netdev)
573579 int rc , i ;
574580 struct gs_device_mode * dm ;
575581 u32 ctrlmode ;
582+ u32 flags = 0 ;
576583
577584 rc = open_candev (netdev );
578585 if (rc )
@@ -640,24 +647,24 @@ static int gs_can_open(struct net_device *netdev)
640647
641648 /* flags */
642649 ctrlmode = dev -> can .ctrlmode ;
643- dm -> flags = 0 ;
644650
645651 if (ctrlmode & CAN_CTRLMODE_LOOPBACK )
646- dm -> flags |= GS_CAN_MODE_LOOP_BACK ;
652+ flags |= GS_CAN_MODE_LOOP_BACK ;
647653 else if (ctrlmode & CAN_CTRLMODE_LISTENONLY )
648- dm -> flags |= GS_CAN_MODE_LISTEN_ONLY ;
654+ flags |= GS_CAN_MODE_LISTEN_ONLY ;
649655
650656 /* Controller is not allowed to retry TX
651657 * this mode is unavailable on atmels uc3c hardware
652658 */
653659 if (ctrlmode & CAN_CTRLMODE_ONE_SHOT )
654- dm -> flags |= GS_CAN_MODE_ONE_SHOT ;
660+ flags |= GS_CAN_MODE_ONE_SHOT ;
655661
656662 if (ctrlmode & CAN_CTRLMODE_3_SAMPLES )
657- dm -> flags |= GS_CAN_MODE_TRIPLE_SAMPLE ;
663+ flags |= GS_CAN_MODE_TRIPLE_SAMPLE ;
658664
659665 /* finally start device */
660- dm -> mode = GS_CAN_MODE_START ;
666+ dm -> mode = cpu_to_le32 (GS_CAN_MODE_START );
667+ dm -> flags = cpu_to_le32 (flags );
661668 rc = usb_control_msg (interface_to_usbdev (dev -> iface ),
662669 usb_sndctrlpipe (interface_to_usbdev (dev -> iface ), 0 ),
663670 GS_USB_BREQ_MODE ,
@@ -737,9 +744,9 @@ static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
737744 return - ENOMEM ;
738745
739746 if (do_identify )
740- imode -> mode = GS_CAN_IDENTIFY_ON ;
747+ imode -> mode = cpu_to_le32 ( GS_CAN_IDENTIFY_ON ) ;
741748 else
742- imode -> mode = GS_CAN_IDENTIFY_OFF ;
749+ imode -> mode = cpu_to_le32 ( GS_CAN_IDENTIFY_OFF ) ;
743750
744751 rc = usb_control_msg (interface_to_usbdev (dev -> iface ),
745752 usb_sndctrlpipe (interface_to_usbdev (dev -> iface ),
@@ -790,6 +797,7 @@ static struct gs_can *gs_make_candev(unsigned int channel,
790797 struct net_device * netdev ;
791798 int rc ;
792799 struct gs_device_bt_const * bt_const ;
800+ u32 feature ;
793801
794802 bt_const = kmalloc (sizeof (* bt_const ), GFP_KERNEL );
795803 if (!bt_const )
@@ -830,14 +838,14 @@ static struct gs_can *gs_make_candev(unsigned int channel,
830838
831839 /* dev setup */
832840 strcpy (dev -> bt_const .name , "gs_usb" );
833- dev -> bt_const .tseg1_min = bt_const -> tseg1_min ;
834- dev -> bt_const .tseg1_max = bt_const -> tseg1_max ;
835- dev -> bt_const .tseg2_min = bt_const -> tseg2_min ;
836- dev -> bt_const .tseg2_max = bt_const -> tseg2_max ;
837- dev -> bt_const .sjw_max = bt_const -> sjw_max ;
838- dev -> bt_const .brp_min = bt_const -> brp_min ;
839- dev -> bt_const .brp_max = bt_const -> brp_max ;
840- dev -> bt_const .brp_inc = bt_const -> brp_inc ;
841+ dev -> bt_const .tseg1_min = le32_to_cpu ( bt_const -> tseg1_min ) ;
842+ dev -> bt_const .tseg1_max = le32_to_cpu ( bt_const -> tseg1_max ) ;
843+ dev -> bt_const .tseg2_min = le32_to_cpu ( bt_const -> tseg2_min ) ;
844+ dev -> bt_const .tseg2_max = le32_to_cpu ( bt_const -> tseg2_max ) ;
845+ dev -> bt_const .sjw_max = le32_to_cpu ( bt_const -> sjw_max ) ;
846+ dev -> bt_const .brp_min = le32_to_cpu ( bt_const -> brp_min ) ;
847+ dev -> bt_const .brp_max = le32_to_cpu ( bt_const -> brp_max ) ;
848+ dev -> bt_const .brp_inc = le32_to_cpu ( bt_const -> brp_inc ) ;
841849
842850 dev -> udev = interface_to_usbdev (intf );
843851 dev -> iface = intf ;
@@ -854,28 +862,29 @@ static struct gs_can *gs_make_candev(unsigned int channel,
854862
855863 /* can setup */
856864 dev -> can .state = CAN_STATE_STOPPED ;
857- dev -> can .clock .freq = bt_const -> fclk_can ;
865+ dev -> can .clock .freq = le32_to_cpu ( bt_const -> fclk_can ) ;
858866 dev -> can .bittiming_const = & dev -> bt_const ;
859867 dev -> can .do_set_bittiming = gs_usb_set_bittiming ;
860868
861869 dev -> can .ctrlmode_supported = 0 ;
862870
863- if (bt_const -> feature & GS_CAN_FEATURE_LISTEN_ONLY )
871+ feature = le32_to_cpu (bt_const -> feature );
872+ if (feature & GS_CAN_FEATURE_LISTEN_ONLY )
864873 dev -> can .ctrlmode_supported |= CAN_CTRLMODE_LISTENONLY ;
865874
866- if (bt_const -> feature & GS_CAN_FEATURE_LOOP_BACK )
875+ if (feature & GS_CAN_FEATURE_LOOP_BACK )
867876 dev -> can .ctrlmode_supported |= CAN_CTRLMODE_LOOPBACK ;
868877
869- if (bt_const -> feature & GS_CAN_FEATURE_TRIPLE_SAMPLE )
878+ if (feature & GS_CAN_FEATURE_TRIPLE_SAMPLE )
870879 dev -> can .ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES ;
871880
872- if (bt_const -> feature & GS_CAN_FEATURE_ONE_SHOT )
881+ if (feature & GS_CAN_FEATURE_ONE_SHOT )
873882 dev -> can .ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT ;
874883
875884 SET_NETDEV_DEV (netdev , & intf -> dev );
876885
877- if (dconf -> sw_version > 1 )
878- if (bt_const -> feature & GS_CAN_FEATURE_IDENTIFY )
886+ if (le32_to_cpu ( dconf -> sw_version ) > 1 )
887+ if (feature & GS_CAN_FEATURE_IDENTIFY )
879888 netdev -> ethtool_ops = & gs_usb_ethtool_ops ;
880889
881890 kfree (bt_const );
@@ -910,7 +919,7 @@ static int gs_usb_probe(struct usb_interface *intf,
910919 if (!hconf )
911920 return - ENOMEM ;
912921
913- hconf -> byte_order = 0x0000beef ;
922+ hconf -> byte_order = cpu_to_le32 ( 0x0000beef ) ;
914923
915924 /* send host config */
916925 rc = usb_control_msg (interface_to_usbdev (intf ),
0 commit comments