linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] peak_usb: rename usb option cmds definition and structs
@ 2015-03-16 10:57 Stephane Grosjean
  2015-03-16 10:57 ` [PATCH 2/2] peak_usb_fd: add support for ISO / non-ISO mode switching Stephane Grosjean
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stephane Grosjean @ 2015-03-16 10:57 UTC (permalink / raw)
  To: linux-can Mailing List; +Cc: Stephane Grosjean, Oliver Hartkopp

The PUCAN_CMD_RX_FRAME_(ENABLE|DISABLE) command has extended its purpose
and was therefore renamed to PUCAN_CMD_SET_(EN|DIS)_OPTION.

Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 drivers/net/can/usb/peak_usb/pcan_ucan.h   | 14 +++++-----
 drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 42 +++++++++++++++---------------
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_ucan.h b/drivers/net/can/usb/peak_usb/pcan_ucan.h
index 1ba7c25..1fb3330 100644
--- a/drivers/net/can/usb/peak_usb/pcan_ucan.h
+++ b/drivers/net/can/usb/peak_usb/pcan_ucan.h
@@ -26,8 +26,8 @@
 #define PUCAN_CMD_FILTER_STD		0x008
 #define PUCAN_CMD_TX_ABORT		0x009
 #define PUCAN_CMD_WR_ERR_CNT		0x00a
-#define PUCAN_CMD_RX_FRAME_ENABLE	0x00b
-#define PUCAN_CMD_RX_FRAME_DISABLE	0x00c
+#define PUCAN_CMD_SET_EN_OPTION		0x00b
+#define PUCAN_CMD_CLR_DIS_OPTION	0x00c
 #define PUCAN_CMD_END_OF_COLLECTION	0x3ff
 
 /* uCAN received messages list */
@@ -101,14 +101,14 @@ struct __packed pucan_wr_err_cnt {
 	u16	unused;
 };
 
-/* uCAN RX_FRAME_ENABLE command fields */
-#define PUCAN_FLTEXT_ERROR		0x0001
-#define PUCAN_FLTEXT_BUSLOAD		0x0002
+/* uCAN SET_EN/CLR_DIS _OPTION command fields */
+#define PUCAN_OPTION_ERROR		0x0001
+#define PUCAN_OPTION_BUSLOAD		0x0002
 
-struct __packed pucan_filter_ext {
+struct __packed pucan_options {
 	__le16	opcode_channel;
 
-	__le16	ext_mask;
+	__le16	options;
 	u32	unused;
 };
 
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
index 0bac0f1..7506a83 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
@@ -110,13 +110,13 @@ struct __packed pcan_ufd_led {
 	u8	unused[5];
 };
 
-/* Extended usage of uCAN commands CMD_RX_FRAME_xxxABLE for PCAN-USB Pro FD */
+/* Extended usage of uCAN commands CMD_xxx_xx_OPTION for PCAN-USB Pro FD */
 #define PCAN_UFD_FLTEXT_CALIBRATION	0x8000
 
-struct __packed pcan_ufd_filter_ext {
+struct __packed pcan_ufd_options {
 	__le16	opcode_channel;
 
-	__le16	ext_mask;
+	__le16	ucan_mask;
 	u16	unused;
 	__le16	usb_mask;
 };
@@ -321,21 +321,21 @@ static int pcan_usb_fd_set_filter_std(struct peak_usb_device *dev, int idx,
 	return pcan_usb_fd_send_cmd(dev, cmd);
 }
 
-/* set/unset notifications filter:
+/* set/unset options
  *
- *	onoff	sets(1)/unset(0) notifications
- *	mask	each bit defines a kind of notification to set/unset
+ *	onoff	set(1)/unset(0) options
+ *	mask	each bit defines a kind of options to set/unset
  */
-static int pcan_usb_fd_set_filter_ext(struct peak_usb_device *dev,
-				      bool onoff, u16 ext_mask, u16 usb_mask)
+static int pcan_usb_fd_set_options(struct peak_usb_device *dev,
+				   bool onoff, u16 ucan_mask, u16 usb_mask)
 {
-	struct pcan_ufd_filter_ext *cmd = pcan_usb_fd_cmd_buffer(dev);
+	struct pcan_ufd_options *cmd = pcan_usb_fd_cmd_buffer(dev);
 
 	cmd->opcode_channel = pucan_cmd_opcode_channel(dev,
-					(onoff) ? PUCAN_CMD_RX_FRAME_ENABLE :
-						  PUCAN_CMD_RX_FRAME_DISABLE);
+					(onoff) ? PUCAN_CMD_SET_EN_OPTION :
+						  PUCAN_CMD_CLR_DIS_OPTION);
 
-	cmd->ext_mask = cpu_to_le16(ext_mask);
+	cmd->ucan_mask = cpu_to_le16(ucan_mask);
 	cmd->usb_mask = cpu_to_le16(usb_mask);
 
 	/* send the command */
@@ -770,9 +770,9 @@ static int pcan_usb_fd_start(struct peak_usb_device *dev)
 				       &pcan_usb_pro_fd);
 
 		/* enable USB calibration messages */
-		err = pcan_usb_fd_set_filter_ext(dev, 1,
-						 PUCAN_FLTEXT_ERROR,
-						 PCAN_UFD_FLTEXT_CALIBRATION);
+		err = pcan_usb_fd_set_options(dev, 1,
+					      PUCAN_OPTION_ERROR,
+					      PCAN_UFD_FLTEXT_CALIBRATION);
 	}
 
 	pdev->usb_if->dev_opened_count++;
@@ -806,9 +806,9 @@ static int pcan_usb_fd_stop(struct peak_usb_device *dev)
 
 	/* turn off special msgs for that interface if no other dev opened */
 	if (pdev->usb_if->dev_opened_count == 1)
-		pcan_usb_fd_set_filter_ext(dev, 0,
-					   PUCAN_FLTEXT_ERROR,
-					   PCAN_UFD_FLTEXT_CALIBRATION);
+		pcan_usb_fd_set_options(dev, 0,
+					PUCAN_OPTION_ERROR,
+					PCAN_UFD_FLTEXT_CALIBRATION);
 	pdev->usb_if->dev_opened_count--;
 
 	return 0;
@@ -937,9 +937,9 @@ static void pcan_usb_fd_exit(struct peak_usb_device *dev)
 	if (dev->ctrl_idx == 0) {
 		/* turn off calibration message if any device were opened */
 		if (pdev->usb_if->dev_opened_count > 0)
-			pcan_usb_fd_set_filter_ext(dev, 0,
-						   PUCAN_FLTEXT_ERROR,
-						   PCAN_UFD_FLTEXT_CALIBRATION);
+			pcan_usb_fd_set_options(dev, 0,
+						PUCAN_OPTION_ERROR,
+						PCAN_UFD_FLTEXT_CALIBRATION);
 
 		/* tell USB adapter that the driver is being unloaded */
 		pcan_usb_fd_drv_loaded(dev, 0);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] peak_usb_fd: add support for ISO / non-ISO mode switching
  2015-03-16 10:57 [PATCH 1/2] peak_usb: rename usb option cmds definition and structs Stephane Grosjean
@ 2015-03-16 10:57 ` Stephane Grosjean
  2015-03-16 11:21 ` [PATCH 1/2] peak_usb: rename usb option cmds definition and structs Oliver Hartkopp
  2015-03-17 11:27 ` Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Stephane Grosjean @ 2015-03-16 10:57 UTC (permalink / raw)
  To: linux-can Mailing List; +Cc: Stephane Grosjean, Oliver Hartkopp

The PCAN USB (pro) FD adapters with firmware versions > 2.x support the
switching between ISO (default) and non-ISO conform bitstreams on the CAN bus.
The setting for the 2.x firmware adapters can be modified with the 'ip' tool
from the iproute2 package (option: fd-non-iso [on|off]).

Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 drivers/net/can/usb/peak_usb/pcan_ucan.h   |  1 +
 drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 31 ++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_ucan.h b/drivers/net/can/usb/peak_usb/pcan_ucan.h
index 1fb3330..e8fc495 100644
--- a/drivers/net/can/usb/peak_usb/pcan_ucan.h
+++ b/drivers/net/can/usb/peak_usb/pcan_ucan.h
@@ -104,6 +104,7 @@ struct __packed pucan_wr_err_cnt {
 /* uCAN SET_EN/CLR_DIS _OPTION command fields */
 #define PUCAN_OPTION_ERROR		0x0001
 #define PUCAN_OPTION_BUSLOAD		0x0002
+#define PUCAN_OPTION_CANDFDISO		0x0004
 
 struct __packed pucan_options {
 	__le16	opcode_channel;
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
index 7506a83..90bd96f 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
@@ -251,6 +251,27 @@ static int pcan_usb_fd_build_restart_cmd(struct peak_usb_device *dev, u8 *buf)
 	/* moves the pointer forward */
 	pc += sizeof(struct pucan_wr_err_cnt);
 
+	/* add command to switch from ISO to non-ISO mode, if fw allows it */
+	if (dev->can.ctrlmode_supported & CAN_CTRLMODE_FD_NON_ISO) {
+		struct pucan_options *puo = (struct pucan_options *)pc;
+
+		puo->opcode_channel =
+			(dev->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO) ?
+			pucan_cmd_opcode_channel(dev,
+						 PUCAN_CMD_CLR_DIS_OPTION) :
+			pucan_cmd_opcode_channel(dev, PUCAN_CMD_SET_EN_OPTION);
+
+		puo->options = cpu_to_le16(PUCAN_OPTION_CANDFDISO);
+
+		/* to be sure that no other extended bits will be taken into
+		 * account
+		 */
+		puo->unused = 0;
+
+		/* moves the pointer forward */
+		pc += sizeof(struct pucan_options);
+	}
+
 	/* next, go back to operational mode */
 	cmd = (struct pucan_command *)pc;
 	cmd->opcode_channel = pucan_cmd_opcode_channel(dev,
@@ -860,8 +881,14 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
 			 pdev->usb_if->fw_info.fw_version[2],
 			 dev->adapter->ctrl_count);
 
-		/* the currently supported hw is non-ISO */
-		dev->can.ctrlmode = CAN_CTRLMODE_FD_NON_ISO;
+		/* check for ability to switch between ISO/non-ISO modes */
+		if (pdev->usb_if->fw_info.fw_version[0] >= 2) {
+			/* firmware >= 2.x supports ISO/non-ISO switching */
+			dev->can.ctrlmode_supported |= CAN_CTRLMODE_FD_NON_ISO;
+		} else {
+			/* firmware < 2.x only supports fixed(!) non-ISO */
+			dev->can.ctrlmode |= CAN_CTRLMODE_FD_NON_ISO;
+		}
 
 		/* tell the hardware the can driver is running */
 		err = pcan_usb_fd_drv_loaded(dev, 1);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] peak_usb: rename usb option cmds definition and structs
  2015-03-16 10:57 [PATCH 1/2] peak_usb: rename usb option cmds definition and structs Stephane Grosjean
  2015-03-16 10:57 ` [PATCH 2/2] peak_usb_fd: add support for ISO / non-ISO mode switching Stephane Grosjean
@ 2015-03-16 11:21 ` Oliver Hartkopp
  2015-03-17 11:27 ` Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Oliver Hartkopp @ 2015-03-16 11:21 UTC (permalink / raw)
  To: Stephane Grosjean, Marc Kleine-Budde; +Cc: linux-can Mailing List

Both patches tested on Linux 4.0.0-rc4.

Thanks Stephane!

Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>



On 03/16/2015 11:57 AM, Stephane Grosjean wrote:
> The PUCAN_CMD_RX_FRAME_(ENABLE|DISABLE) command has extended its purpose
> and was therefore renamed to PUCAN_CMD_SET_(EN|DIS)_OPTION.
> 
> Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> ---
>  drivers/net/can/usb/peak_usb/pcan_ucan.h   | 14 +++++-----
>  drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 42 +++++++++++++++---------------
>  2 files changed, 28 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/net/can/usb/peak_usb/pcan_ucan.h b/drivers/net/can/usb/peak_usb/pcan_ucan.h
> index 1ba7c25..1fb3330 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_ucan.h
> +++ b/drivers/net/can/usb/peak_usb/pcan_ucan.h
> @@ -26,8 +26,8 @@
>  #define PUCAN_CMD_FILTER_STD		0x008
>  #define PUCAN_CMD_TX_ABORT		0x009
>  #define PUCAN_CMD_WR_ERR_CNT		0x00a
> -#define PUCAN_CMD_RX_FRAME_ENABLE	0x00b
> -#define PUCAN_CMD_RX_FRAME_DISABLE	0x00c
> +#define PUCAN_CMD_SET_EN_OPTION		0x00b
> +#define PUCAN_CMD_CLR_DIS_OPTION	0x00c
>  #define PUCAN_CMD_END_OF_COLLECTION	0x3ff
>  
>  /* uCAN received messages list */
> @@ -101,14 +101,14 @@ struct __packed pucan_wr_err_cnt {
>  	u16	unused;
>  };
>  
> -/* uCAN RX_FRAME_ENABLE command fields */
> -#define PUCAN_FLTEXT_ERROR		0x0001
> -#define PUCAN_FLTEXT_BUSLOAD		0x0002
> +/* uCAN SET_EN/CLR_DIS _OPTION command fields */
> +#define PUCAN_OPTION_ERROR		0x0001
> +#define PUCAN_OPTION_BUSLOAD		0x0002
>  
> -struct __packed pucan_filter_ext {
> +struct __packed pucan_options {
>  	__le16	opcode_channel;
>  
> -	__le16	ext_mask;
> +	__le16	options;
>  	u32	unused;
>  };
>  
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
> index 0bac0f1..7506a83 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
> @@ -110,13 +110,13 @@ struct __packed pcan_ufd_led {
>  	u8	unused[5];
>  };
>  
> -/* Extended usage of uCAN commands CMD_RX_FRAME_xxxABLE for PCAN-USB Pro FD */
> +/* Extended usage of uCAN commands CMD_xxx_xx_OPTION for PCAN-USB Pro FD */
>  #define PCAN_UFD_FLTEXT_CALIBRATION	0x8000
>  
> -struct __packed pcan_ufd_filter_ext {
> +struct __packed pcan_ufd_options {
>  	__le16	opcode_channel;
>  
> -	__le16	ext_mask;
> +	__le16	ucan_mask;
>  	u16	unused;
>  	__le16	usb_mask;
>  };
> @@ -321,21 +321,21 @@ static int pcan_usb_fd_set_filter_std(struct peak_usb_device *dev, int idx,
>  	return pcan_usb_fd_send_cmd(dev, cmd);
>  }
>  
> -/* set/unset notifications filter:
> +/* set/unset options
>   *
> - *	onoff	sets(1)/unset(0) notifications
> - *	mask	each bit defines a kind of notification to set/unset
> + *	onoff	set(1)/unset(0) options
> + *	mask	each bit defines a kind of options to set/unset
>   */
> -static int pcan_usb_fd_set_filter_ext(struct peak_usb_device *dev,
> -				      bool onoff, u16 ext_mask, u16 usb_mask)
> +static int pcan_usb_fd_set_options(struct peak_usb_device *dev,
> +				   bool onoff, u16 ucan_mask, u16 usb_mask)
>  {
> -	struct pcan_ufd_filter_ext *cmd = pcan_usb_fd_cmd_buffer(dev);
> +	struct pcan_ufd_options *cmd = pcan_usb_fd_cmd_buffer(dev);
>  
>  	cmd->opcode_channel = pucan_cmd_opcode_channel(dev,
> -					(onoff) ? PUCAN_CMD_RX_FRAME_ENABLE :
> -						  PUCAN_CMD_RX_FRAME_DISABLE);
> +					(onoff) ? PUCAN_CMD_SET_EN_OPTION :
> +						  PUCAN_CMD_CLR_DIS_OPTION);
>  
> -	cmd->ext_mask = cpu_to_le16(ext_mask);
> +	cmd->ucan_mask = cpu_to_le16(ucan_mask);
>  	cmd->usb_mask = cpu_to_le16(usb_mask);
>  
>  	/* send the command */
> @@ -770,9 +770,9 @@ static int pcan_usb_fd_start(struct peak_usb_device *dev)
>  				       &pcan_usb_pro_fd);
>  
>  		/* enable USB calibration messages */
> -		err = pcan_usb_fd_set_filter_ext(dev, 1,
> -						 PUCAN_FLTEXT_ERROR,
> -						 PCAN_UFD_FLTEXT_CALIBRATION);
> +		err = pcan_usb_fd_set_options(dev, 1,
> +					      PUCAN_OPTION_ERROR,
> +					      PCAN_UFD_FLTEXT_CALIBRATION);
>  	}
>  
>  	pdev->usb_if->dev_opened_count++;
> @@ -806,9 +806,9 @@ static int pcan_usb_fd_stop(struct peak_usb_device *dev)
>  
>  	/* turn off special msgs for that interface if no other dev opened */
>  	if (pdev->usb_if->dev_opened_count == 1)
> -		pcan_usb_fd_set_filter_ext(dev, 0,
> -					   PUCAN_FLTEXT_ERROR,
> -					   PCAN_UFD_FLTEXT_CALIBRATION);
> +		pcan_usb_fd_set_options(dev, 0,
> +					PUCAN_OPTION_ERROR,
> +					PCAN_UFD_FLTEXT_CALIBRATION);
>  	pdev->usb_if->dev_opened_count--;
>  
>  	return 0;
> @@ -937,9 +937,9 @@ static void pcan_usb_fd_exit(struct peak_usb_device *dev)
>  	if (dev->ctrl_idx == 0) {
>  		/* turn off calibration message if any device were opened */
>  		if (pdev->usb_if->dev_opened_count > 0)
> -			pcan_usb_fd_set_filter_ext(dev, 0,
> -						   PUCAN_FLTEXT_ERROR,
> -						   PCAN_UFD_FLTEXT_CALIBRATION);
> +			pcan_usb_fd_set_options(dev, 0,
> +						PUCAN_OPTION_ERROR,
> +						PCAN_UFD_FLTEXT_CALIBRATION);
>  
>  		/* tell USB adapter that the driver is being unloaded */
>  		pcan_usb_fd_drv_loaded(dev, 0);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] peak_usb: rename usb option cmds definition and structs
  2015-03-16 10:57 [PATCH 1/2] peak_usb: rename usb option cmds definition and structs Stephane Grosjean
  2015-03-16 10:57 ` [PATCH 2/2] peak_usb_fd: add support for ISO / non-ISO mode switching Stephane Grosjean
  2015-03-16 11:21 ` [PATCH 1/2] peak_usb: rename usb option cmds definition and structs Oliver Hartkopp
@ 2015-03-17 11:27 ` Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2015-03-17 11:27 UTC (permalink / raw)
  To: Stephane Grosjean, linux-can Mailing List; +Cc: Oliver Hartkopp

[-- Attachment #1: Type: text/plain, Size: 633 bytes --]

On 03/16/2015 11:57 AM, Stephane Grosjean wrote:
> The PUCAN_CMD_RX_FRAME_(ENABLE|DISABLE) command has extended its purpose
> and was therefore renamed to PUCAN_CMD_SET_(EN|DIS)_OPTION.
> 
> Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>

applied both to can/master.

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-17 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16 10:57 [PATCH 1/2] peak_usb: rename usb option cmds definition and structs Stephane Grosjean
2015-03-16 10:57 ` [PATCH 2/2] peak_usb_fd: add support for ISO / non-ISO mode switching Stephane Grosjean
2015-03-16 11:21 ` [PATCH 1/2] peak_usb: rename usb option cmds definition and structs Oliver Hartkopp
2015-03-17 11:27 ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).