gpib: agilent_82357a: Support some 82357B clones
PATCH v2 1/1 gpib: agilent_82357a: Support some 82357B clones
Some adapters marked as Agilent/Keysight 82357B are clones that contain their own firmware. They do not support XFER_STATUS and need slightly different initialization. Detect clone adapters that fail a firmware load and work around their quirks.
---
Changes since v1:
- Keep the exiting init sequence, add a small increase to FAST_TALKER_T1 on clones.
- Clear AWF_NO_FAST_TALKER_FIRST_BYTE on command writes for all adapters.
drivers/gpib/agilent_82357a/agilent_82357a.c | 43 +++++++++++++++++++- drivers/gpib/agilent_82357a/agilent_82357a.h | 2 + 2 files changed, 43 insertions(+), 2 deletions(-)
drivers/gpib/agilent_82357a/agilent_82357a.c +41 -2
@@ -567,7 +567,7 @@ static ssize_t agilent_82357a_generic_write(struct gpib_board *board, out_data[i++] =0 ;// secondary address when AWF_NO_ADDRESS is not set out_data[i] =AWF_NO_ADDRESS |AWF_NO_FAST_TALKER_FIRST_BYTE ;if (send_commands) - out_data[i] |=AWF_ATN |AWF_NO_FAST_TALKER ; + out_data[i] =AWF_ATN |AWF_NO_ADDRESS |AWF_NO_FAST_TALKER ;if (send_eoi) out_data[i] |=AWF_SEND_EOI ; ++i;
@@ -648,10 +648,19 @@ static ssize_t agilent_82357a_generic_write(struct gpib_board *board,return -ECOMM ; } } -return -ETIMEDOUT ; } +/* +* Clone adapters do not answer to XFER_STATUS, so use the +* bytes_written from the write complete interrupt. +*/ +if (a_priv->is_clone_82357b) { +mutex_unlock (&a_priv->bulk_transfer_lock); + *bytes_written = a_priv->write_complete_count; +return 0 ; + } + status_data =kmalloc (STATUS_DATA_LEN ,GFP_KERNEL );if (!status_data) {mutex_unlock (&a_priv->bulk_transfer_lock);
@@ -1114,6 +1123,12 @@ static void agilent_82357a_interrupt_complete(struct urb *urb) } interrupt_flags = transfer_buffer[0 ]; +if (urb->actual_length >=6 &&test_bit (AIF_WRITE_COMPLETE_BN , &interrupt_flags)) { + a_priv->write_complete_count = (u32 )transfer_buffer[2 ]; + a_priv->write_complete_count |= (u32 )transfer_buffer[3 ] <<8 ; + a_priv->write_complete_count |= (u32 )transfer_buffer[4 ] <<16 ; + a_priv->write_complete_count |= (u32 )transfer_buffer[5 ] <<24 ; + }if (test_bit (AIF_READ_COMPLETE_BN , &interrupt_flags))set_bit (AIF_READ_COMPLETE_BN , &a_priv->interrupt_flags);if (test_bit (AIF_WRITE_COMPLETE_BN , &interrupt_flags))
@@ -1213,6 +1228,26 @@ static void agilent_82357a_free_private(struct gpib_board *board) board->private_data =NULL ; } +static void agilent_82357a_detect_clone (struct agilent_82357a_priv *a_priv) +{ +struct usb_device *usb_dev =interface_to_usbdev (a_priv->bus_interface); +u8 *ret_data; +int retval; + + ret_data =kmalloc (1 ,GFP_KERNEL ); +if (!ret_data) +return ; + retval =usb_control_msg (usb_dev,usb_rcvctrlpipe (usb_dev,0 ),0xA0 , +USB_DIR_IN |USB_TYPE_VENDOR |USB_RECIP_DEVICE , +0xE600 ,0 , ret_data,1 ,100 ); +kfree (ret_data); +if (retval <0 ) { + a_priv->is_clone_82357b =1 ; +dev_info (&usb_dev->dev,"Clone 82357B detected (firmware load returned %i), using vendor quirks\n" , + retval); + } +} +#define INIT_NUM_REG_WRITES 18static int agilent_82357a_init (struct gpib_board *board) {
@@ -1223,6 +1258,9 @@ static int agilent_82357a_init(struct gpib_board *board)int retval;unsigned int nanosec; +if (a_priv->is_clone_82357b) + board->t1_nano_sec =819 ; + writes[0 ].address =LED_CONTROL ; writes[0 ].value =FAIL_LED_ON ; writes[1 ].address =RESET_TO_POWERUP ;
@@ -1346,6 +1384,7 @@ static int agilent_82357a_attach(struct gpib_board *board, const struct gpib_boacase USB_DEVICE_ID_AGILENT_82357B : a_priv->bulk_out_endpoint =AGILENT_82357B_BULK_OUT_ENDPOINT ; a_priv->interrupt_in_endpoint =AGILENT_82357B_INTERRUPT_IN_ENDPOINT ; +agilent_82357a_detect_clone (a_priv);break ;default :dev_err (&usb_dev->dev,"bug, unhandled product_id in switch?\n" );
drivers/gpib/agilent_82357a/agilent_82357a.h +2 -0
@@ -133,12 +133,14 @@ struct agilent_82357a_priv {struct mutex bulk_alloc_lock;// bulk transfer allocation lock struct mutex interrupt_alloc_lock;// interrupt allocation lock struct mutex control_alloc_lock;// control message allocation lock +u32 write_complete_count;// bytes transferred in last write struct timer_list bulk_timer;struct agilent_82357a_urb_ctx context;unsigned int bulk_out_endpoint;unsigned int interrupt_in_endpoint; unsigned is_cic : 1; unsigned ren_state : 1; + unsigned is_clone_82357b : 1; };struct agilent_82357a_register_pairlet {
Signature · 1 line
2.55.0
Dave Penkler
maintainerQuoted 5 lines · Tom Keller
Some adapters marked as Agilent/Keysight 82357B are clones that contain their own firmware. They do not support
XFER_STATUSand need slightly different initialization. Detect clone adapters that fail a firmware load and work around their quirks.
Quoted 7 lines
Signed-off-by Tom Keller <[email protected]>---
Changes since v1:
- Keep the exiting init sequence, add a small increase toFAST_TALKER_T1on clones.
- ClearAWF_NO_FAST_TALKER_FIRST_BYTEon command writes for all adapters.
Great, I tested this patch with my 2 82357B compatible adaptors, one which needs a firmware download and the other not and it worked fine. The Beiming adaptor, which does not need a firmware download, is not detected as a "clone" so the shipped code is still being used for it. I also tested systematically setting the FAST_TALKER_T1 to 819 and that works too. So we can drop the clone specific initialisation and just change the 800 ns value to 819. There is no visible change in userspace and the extra 21 ns should not have any noticeable impact. Detecting the "clone" as you propose is preferable to a module option since from the outside and userspace we can't really distinguish your clone from a genuine or other clone adaptor.
Quoted 79 lines
drivers/gpib/agilent_82357a/agilent_82357a.c | 43 +++++++++++++++++++- drivers/gpib/agilent_82357a/agilent_82357a.h | 2 + 2 files changed, 43 insertions(+), 2 deletions(-)drivers/gpib/agilent_82357a/agilent_82357a.c +37
-2@@ -567,7 +567,7 @@ static ssize_t agilent_82357a_generic_write(struct gpib_board *board, out_data[i++] =0 ;// secondary address when AWF_NO_ADDRESS is not set out_data[i] =AWF_NO_ADDRESS |AWF_NO_FAST_TALKER_FIRST_BYTE ;if (send_commands) - out_data[i] |=AWF_ATN |AWF_NO_FAST_TALKER ; + out_data[i] =AWF_ATN |AWF_NO_ADDRESS |AWF_NO_FAST_TALKER ;if (send_eoi) out_data[i] |=AWF_SEND_EOI ; ++i;@@ -648,10 +648,19 @@ static ssize_t agilent_82357a_generic_write(struct gpib_board *board,return -ECOMM ; } } -return -ETIMEDOUT ; } +/* +* Clone adapters do not answer to XFER_STATUS, so use the +* bytes_written from the write complete interrupt. +*/ +if (a_priv->is_clone_82357b) { +mutex_unlock (&a_priv->bulk_transfer_lock); + *bytes_written = a_priv->write_complete_count; +return 0 ; + } + status_data =kmalloc (STATUS_DATA_LEN ,GFP_KERNEL );if (!status_data) {mutex_unlock (&a_priv->bulk_transfer_lock);@@ -1114,6 +1123,12 @@ static void agilent_82357a_interrupt_complete(struct urb *urb) } interrupt_flags = transfer_buffer[0 ]; +if (urb->actual_length >=6 &&test_bit (AIF_WRITE_COMPLETE_BN , &interrupt_flags)) { + a_priv->write_complete_count = (u32 )transfer_buffer[2 ]; + a_priv->write_complete_count |= (u32 )transfer_buffer[3 ] <<8 ; + a_priv->write_complete_count |= (u32 )transfer_buffer[4 ] <<16 ; + a_priv->write_complete_count |= (u32 )transfer_buffer[5 ] <<24 ; + }if (test_bit (AIF_READ_COMPLETE_BN , &interrupt_flags))set_bit (AIF_READ_COMPLETE_BN , &a_priv->interrupt_flags);if (test_bit (AIF_WRITE_COMPLETE_BN , &interrupt_flags))@@ -1213,6 +1228,26 @@ static void agilent_82357a_free_private(struct gpib_board *board) board->private_data =NULL ; } +static void agilent_82357a_detect_clone (struct agilent_82357a_priv *a_priv) +{ +struct usb_device *usb_dev =interface_to_usbdev (a_priv->bus_interface); +u8 *ret_data; +int retval; + + ret_data =kmalloc (1 ,GFP_KERNEL ); +if (!ret_data) +return ; + retval =usb_control_msg (usb_dev,usb_rcvctrlpipe (usb_dev,0 ),0xA0 , +USB_DIR_IN |USB_TYPE_VENDOR |USB_RECIP_DEVICE , +0xE600 ,0 , ret_data,1 ,100 ); +kfree (ret_data); +if (retval <0 ) { + a_priv->is_clone_82357b =1 ; +dev_info (&usb_dev->dev,"Clone 82357B detected (firmware load returned %i), using vendor quirks\n" , + retval); + } +} +#define INIT_NUM_REG_WRITES 18static int agilent_82357a_init (struct gpib_board *board) {
drivers/gpib/agilent_82357a/agilent_82357a.c static int agilent_82357a_init(struct gpib_board *board) · line 1263
Quoted 6 lines
drivers/gpib/agilent_82357a/agilent_82357a.c +3
-0@@ -1223,6 +1258,9 @@ static int agilent_82357a_init(struct gpib_board *board)int retval;unsigned int nanosec; +if (a_priv->is_clone_82357b) + board->t1_nano_sec =819 ; +
We can drop this and just use 819 in the initial setting.
Quoted 34 lines
drivers/gpib/agilent_82357a/agilent_82357a.c +1
-0writes[0 ].address =LED_CONTROL ; writes[0 ].value =FAIL_LED_ON ; writes[1 ].address =RESET_TO_POWERUP ;@@ -1346,6 +1384,7 @@ static int agilent_82357a_attach(struct gpib_board *board, const struct gpib_boacase USB_DEVICE_ID_AGILENT_82357B : a_priv->bulk_out_endpoint =AGILENT_82357B_BULK_OUT_ENDPOINT ; a_priv->interrupt_in_endpoint =AGILENT_82357B_INTERRUPT_IN_ENDPOINT ; +agilent_82357a_detect_clone (a_priv);break ;default :dev_err (&usb_dev->dev,"bug, unhandled product_id in switch?\n" );drivers/gpib/agilent_82357a/agilent_82357a.h +2
-0@@ -133,12 +133,14 @@ struct agilent_82357a_priv {struct mutex bulk_alloc_lock;// bulk transfer allocation lock struct mutex interrupt_alloc_lock;// interrupt allocation lock struct mutex control_alloc_lock;// control message allocation lock +u32 write_complete_count;// bytes transferred in last write struct timer_list bulk_timer;struct agilent_82357a_urb_ctx context;unsigned int bulk_out_endpoint;unsigned int interrupt_in_endpoint; unsigned is_cic : 1; unsigned ren_state : 1; + unsigned is_clone_82357b : 1; };struct agilent_82357a_register_pairlet {Signature · 1 line
2.55.0
PATCH v3 1/1 gpib: agilent_82357a: Support some 82357B clones
Some adapters marked as Agilent/Keysight 82357B are clones that contain their own firmware. They do not support XFER_STATUS and need slightly relaxed timing. Detect clone adapters that fail a firmware load and work around their quirks.
---
Changes since v2:
- Use 819 ns as the default FAST_TALKER_T1 for all adapters and drop the clone-specific initialization.
- Reword the clone detection message.
Changes since v1:
- Keep the existing init sequence, add a small increase to FAST_TALKER_T1 on clones.
- Clear AWF_NO_FAST_TALKER_FIRST_BYTE on command writes for all adapters.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
drivers/gpib/agilent_82357a/agilent_82357a.c | 41 +++++++++++++++++++- drivers/gpib/agilent_82357a/agilent_82357a.h | 2 + 2 files changed, 41 insertions(+), 2 deletions(-)
drivers/gpib/agilent_82357a/agilent_82357a.c +39 -2
@@ -567,7 +567,7 @@ static ssize_t agilent_82357a_generic_write(struct gpib_board *board, out_data[i++] =0 ;// secondary address when AWF_NO_ADDRESS is not set out_data[i] =AWF_NO_ADDRESS |AWF_NO_FAST_TALKER_FIRST_BYTE ;if (send_commands) - out_data[i] |=AWF_ATN |AWF_NO_FAST_TALKER ; + out_data[i] =AWF_ATN |AWF_NO_ADDRESS |AWF_NO_FAST_TALKER ;if (send_eoi) out_data[i] |=AWF_SEND_EOI ; ++i;
@@ -652,6 +652,16 @@ static ssize_t agilent_82357a_generic_write(struct gpib_board *board,return -ETIMEDOUT ; } +/* +* Clone adapters do not answer to XFER_STATUS, so use the +* bytes_written from the write complete interrupt. +*/ +if (a_priv->is_clone_82357b) { +mutex_unlock (&a_priv->bulk_transfer_lock); + *bytes_written = a_priv->write_complete_count; +return 0 ; + } + status_data =kmalloc (STATUS_DATA_LEN ,GFP_KERNEL );if (!status_data) {mutex_unlock (&a_priv->bulk_transfer_lock);
@@ -1114,6 +1124,12 @@ static void agilent_82357a_interrupt_complete(struct urb *urb) } interrupt_flags = transfer_buffer[0 ]; +if (urb->actual_length >=6 &&test_bit (AIF_WRITE_COMPLETE_BN , &interrupt_flags)) { + a_priv->write_complete_count = (u32 )transfer_buffer[2 ]; + a_priv->write_complete_count |= (u32 )transfer_buffer[3 ] <<8 ; + a_priv->write_complete_count |= (u32 )transfer_buffer[4 ] <<16 ; + a_priv->write_complete_count |= (u32 )transfer_buffer[5 ] <<24 ; + }if (test_bit (AIF_READ_COMPLETE_BN , &interrupt_flags))set_bit (AIF_READ_COMPLETE_BN , &a_priv->interrupt_flags);if (test_bit (AIF_WRITE_COMPLETE_BN , &interrupt_flags))
@@ -1213,6 +1229,26 @@ static void agilent_82357a_free_private(struct gpib_board *board) board->private_data =NULL ; } +static void agilent_82357a_detect_clone (struct agilent_82357a_priv *a_priv) +{ +struct usb_device *usb_dev =interface_to_usbdev (a_priv->bus_interface); +u8 *ret_data; +int retval; + + ret_data =kmalloc (1 ,GFP_KERNEL ); +if (!ret_data) +return ; + retval =usb_control_msg (usb_dev,usb_rcvctrlpipe (usb_dev,0 ),0xA0 , +USB_DIR_IN |USB_TYPE_VENDOR |USB_RECIP_DEVICE , +0xE600 ,0 , ret_data,1 ,100 ); +kfree (ret_data); +if (retval <0 ) { + a_priv->is_clone_82357b =1 ; +dev_info (&usb_dev->dev,"82357B clone with firmware detected (CPUCS read returned %i)\n" , + retval); + } +} +#define INIT_NUM_REG_WRITES 18static int agilent_82357a_init (struct gpib_board *board) {
@@ -1346,6 +1382,7 @@ static int agilent_82357a_attach(struct gpib_board *board, const struct gpib_boacase USB_DEVICE_ID_AGILENT_82357B : a_priv->bulk_out_endpoint =AGILENT_82357B_BULK_OUT_ENDPOINT ; a_priv->interrupt_in_endpoint =AGILENT_82357B_INTERRUPT_IN_ENDPOINT ; +agilent_82357a_detect_clone (a_priv);break ;default :dev_err (&usb_dev->dev,"bug, unhandled product_id in switch?\n" );
@@ -1359,7 +1396,7 @@ static int agilent_82357a_attach(struct gpib_board *board, const struct gpib_boatimer_setup (&a_priv->bulk_timer, agilent_82357a_timeout_handler,0 ); - board->t1_nano_sec =800 ; + board->t1_nano_sec =819 ; retval =agilent_82357a_init (board);
drivers/gpib/agilent_82357a/agilent_82357a.h +2 -0
@@ -133,12 +133,14 @@ struct agilent_82357a_priv {struct mutex bulk_alloc_lock;// bulk transfer allocation lock struct mutex interrupt_alloc_lock;// interrupt allocation lock struct mutex control_alloc_lock;// control message allocation lock +u32 write_complete_count;// bytes transferred in last write struct timer_list bulk_timer;struct agilent_82357a_urb_ctx context;unsigned int bulk_out_endpoint;unsigned int interrupt_in_endpoint; unsigned is_cic : 1; unsigned ren_state : 1; + unsigned is_clone_82357b : 1; };struct agilent_82357a_register_pairlet {
Signature · 1 line
2.55.0
Quoted 6 lines · Tom Keller
Some adapters marked as Agilent/Keysight 82357B are clones that contain their own firmware. They do not support
XFER_STATUSand need slightly relaxed timing. Detect clone adapters that fail a firmware load and work around their quirks.Signed-off-by Tom Keller <[email protected]>
Quoted 126 lines
---
Changes since v2:
- Use 819 ns as the defaultFAST_TALKER_T1for all adapters and drop the clone-specific initialization.
- Reword the clone detection message.
Changes since v1:
- Keep the existing init sequence, add a small increase toFAST_TALKER_T1on clones.
- ClearAWF_NO_FAST_TALKER_FIRST_BYTEon command writes for all adapters.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/drivers/gpib/agilent_82357a/agilent_82357a.c | 41 +++++++++++++++++++- drivers/gpib/agilent_82357a/agilent_82357a.h | 2 + 2 files changed, 41 insertions(+), 2 deletions(-)drivers/gpib/agilent_82357a/agilent_82357a.c +39
-2@@ -567,7 +567,7 @@ static ssize_t agilent_82357a_generic_write(struct gpib_board *board, out_data[i++] =0 ;// secondary address when AWF_NO_ADDRESS is not set out_data[i] =AWF_NO_ADDRESS |AWF_NO_FAST_TALKER_FIRST_BYTE ;if (send_commands) - out_data[i] |=AWF_ATN |AWF_NO_FAST_TALKER ; + out_data[i] =AWF_ATN |AWF_NO_ADDRESS |AWF_NO_FAST_TALKER ;if (send_eoi) out_data[i] |=AWF_SEND_EOI ; ++i;@@ -652,6 +652,16 @@ static ssize_t agilent_82357a_generic_write(struct gpib_board *board,return -ETIMEDOUT ; } +/* +* Clone adapters do not answer to XFER_STATUS, so use the +* bytes_written from the write complete interrupt. +*/ +if (a_priv->is_clone_82357b) { +mutex_unlock (&a_priv->bulk_transfer_lock); + *bytes_written = a_priv->write_complete_count; +return 0 ; + } + status_data =kmalloc (STATUS_DATA_LEN ,GFP_KERNEL );if (!status_data) {mutex_unlock (&a_priv->bulk_transfer_lock);@@ -1114,6 +1124,12 @@ static void agilent_82357a_interrupt_complete(struct urb *urb) } interrupt_flags = transfer_buffer[0 ]; +if (urb->actual_length >=6 &&test_bit (AIF_WRITE_COMPLETE_BN , &interrupt_flags)) { + a_priv->write_complete_count = (u32 )transfer_buffer[2 ]; + a_priv->write_complete_count |= (u32 )transfer_buffer[3 ] <<8 ; + a_priv->write_complete_count |= (u32 )transfer_buffer[4 ] <<16 ; + a_priv->write_complete_count |= (u32 )transfer_buffer[5 ] <<24 ; + }if (test_bit (AIF_READ_COMPLETE_BN , &interrupt_flags))set_bit (AIF_READ_COMPLETE_BN , &a_priv->interrupt_flags);if (test_bit (AIF_WRITE_COMPLETE_BN , &interrupt_flags))@@ -1213,6 +1229,26 @@ static void agilent_82357a_free_private(struct gpib_board *board) board->private_data =NULL ; } +static void agilent_82357a_detect_clone (struct agilent_82357a_priv *a_priv) +{ +struct usb_device *usb_dev =interface_to_usbdev (a_priv->bus_interface); +u8 *ret_data; +int retval; + + ret_data =kmalloc (1 ,GFP_KERNEL ); +if (!ret_data) +return ; + retval =usb_control_msg (usb_dev,usb_rcvctrlpipe (usb_dev,0 ),0xA0 , +USB_DIR_IN |USB_TYPE_VENDOR |USB_RECIP_DEVICE , +0xE600 ,0 , ret_data,1 ,100 ); +kfree (ret_data); +if (retval <0 ) { + a_priv->is_clone_82357b =1 ; +dev_info (&usb_dev->dev,"82357B clone with firmware detected (CPUCS read returned %i)\n" , + retval); + } +} +#define INIT_NUM_REG_WRITES 18static int agilent_82357a_init (struct gpib_board *board) {@@ -1346,6 +1382,7 @@ static int agilent_82357a_attach(struct gpib_board *board, const struct gpib_boacase USB_DEVICE_ID_AGILENT_82357B : a_priv->bulk_out_endpoint =AGILENT_82357B_BULK_OUT_ENDPOINT ; a_priv->interrupt_in_endpoint =AGILENT_82357B_INTERRUPT_IN_ENDPOINT ; +agilent_82357a_detect_clone (a_priv);break ;default :dev_err (&usb_dev->dev,"bug, unhandled product_id in switch?\n" );@@ -1359,7 +1396,7 @@ static int agilent_82357a_attach(struct gpib_board *board, const struct gpib_boatimer_setup (&a_priv->bulk_timer, agilent_82357a_timeout_handler,0 ); - board->t1_nano_sec =800 ; + board->t1_nano_sec =819 ; retval =agilent_82357a_init (board);drivers/gpib/agilent_82357a/agilent_82357a.h +2
-0@@ -133,12 +133,14 @@ struct agilent_82357a_priv {struct mutex bulk_alloc_lock;// bulk transfer allocation lock struct mutex interrupt_alloc_lock;// interrupt allocation lock struct mutex control_alloc_lock;// control message allocation lock +u32 write_complete_count;// bytes transferred in last write struct timer_list bulk_timer;struct agilent_82357a_urb_ctx context;unsigned int bulk_out_endpoint;unsigned int interrupt_in_endpoint; unsigned is_cic : 1; unsigned ren_state : 1; + unsigned is_clone_82357b : 1; };struct agilent_82357a_register_pairlet {Signature · 1 line
2.55.0