diff mbox series

[atusb/fw,v2,3/3] atusb: fw: Provide TRAC status

Message ID 20220906082104.1338694-3-miquel.raynal@bootlin.com (mailing list archive)
State New, archived
Headers show
Series [atusb/fw,v2,1/3] Add .gitignore | expand

Commit Message

Miquel Raynal Sept. 6, 2022, 8:21 a.m. UTC
From: Alexander Aring <aahringo@redhat.com>

Upon Tx done condition, returning the sequence number is useful but we
might also return the TRAC value which is needed to ensure that the
packet we sent got ACKed.

We then need to read the TRAC status register upon Tx completion and
send this information to the atusb Linux driver as part of the status
message. First byte remains the sequence number for ensuring backward
compatibility, a second byte is added to forward the TRAC register
status.

We need to move the transition to RX_AACK_ON after reading the trac
register value. The current optimization by switchting to RX_AACK_ON
after invoking transceiver transmission could have the side effect that
the TRAC register is not read out before a frame is received. Receiving
another frame will overwrite the TRAC register. We can only switch to
RX_AACK_ON state after we read out the TRAC register.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>
[Miquel Raynal: Moved the data array out of the stack, rewrote commit log]
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---

Changes since v1:
* Fix race condition (Rx would mess with the TRAC value, so wait for the
  transmission to have been signaled and the TRAC register to have been
  read before changing the state to RX_AACK_ON (by Alexander).

 atusb/fw/mac.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Stefan Schmidt Oct. 12, 2022, 5:57 p.m. UTC | #1
Hello.

On 06.09.22 10:21, Miquel Raynal wrote:
> From: Alexander Aring <aahringo@redhat.com>
> 
> Upon Tx done condition, returning the sequence number is useful but we
> might also return the TRAC value which is needed to ensure that the
> packet we sent got ACKed.
> 
> We then need to read the TRAC status register upon Tx completion and
> send this information to the atusb Linux driver as part of the status
> message. First byte remains the sequence number for ensuring backward
> compatibility, a second byte is added to forward the TRAC register
> status.
> 
> We need to move the transition to RX_AACK_ON after reading the trac
> register value. The current optimization by switchting to RX_AACK_ON
> after invoking transceiver transmission could have the side effect that
> the TRAC register is not read out before a frame is received. Receiving
> another frame will overwrite the TRAC register. We can only switch to
> RX_AACK_ON state after we read out the TRAC register.
> 
> Signed-off-by: Alexander Aring <aahringo@redhat.com>
> Tested-by: Miquel Raynal <miquel.raynal@bootlin.com>
> [Miquel Raynal: Moved the data array out of the stack, rewrote commit log]
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
> 
> Changes since v1:
> * Fix race condition (Rx would mess with the TRAC value, so wait for the
>    transmission to have been signaled and the TRAC register to have been
>    read before changing the state to RX_AACK_ON (by Alexander).
> 
>   atusb/fw/mac.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/atusb/fw/mac.c b/atusb/fw/mac.c
> index 835002c..165ce30 100644
> --- a/atusb/fw/mac.c
> +++ b/atusb/fw/mac.c
> @@ -32,7 +32,7 @@ static uint8_t tx_buf[MAX_PSDU];
>   static uint8_t tx_size = 0;
>   static bool txing = 0;
>   static bool queued_tx_ack = 0;
> -static uint8_t next_seq, this_seq, queued_seq;
> +static uint8_t next_seq, this_seq, this_data[2], queued_data[2];
>   
>   
>   /* ----- Receive buffer management ----------------------------------------- */
> @@ -65,7 +65,8 @@ static void usb_next(void)
>   	}
>   
>   	if (queued_tx_ack) {
> -		usb_send(&eps[1], &queued_seq, 1, tx_ack_done, NULL);
> +		usb_send(&eps[1], queued_data, sizeof(queued_data),
> +			 tx_ack_done, NULL);
>   		queued_tx_ack = 0;	
>   	}
>   }
> @@ -124,11 +125,17 @@ static bool handle_irq(void)
>   
>   	if (txing) {
>   		if (eps[1].state == EP_IDLE) {
> -			usb_send(&eps[1], &this_seq, 1, tx_ack_done, NULL);
> +			this_data[0] = this_seq;
> +			this_data[1] = reg_read(REG_TRX_STATE);
> +			usb_send(&eps[1], this_data, sizeof(this_data),
> +				 tx_ack_done, NULL);
>   		} else {
>   			queued_tx_ack = 1;
> -			queued_seq = this_seq;
> +			queued_data[0] = this_seq;
> +			queued_data[1] = reg_read(REG_TRX_STATE);
>   		}
> +		change_state(TRX_CMD_PLL_ON);
> +		change_state(TRX_CMD_RX_AACK_ON);
>   		txing = 0;
>   		return 1;
>   	}
> @@ -215,13 +222,6 @@ static void do_tx(void *user)
>   
>   	txing = 1;
>   	this_seq = next_seq;
> -
> -	/*
> -	 * Wait until we reach BUSY_TX_ARET, so that we command the transition to
> -	 * RX_AACK_ON which will be executed upon TX completion.
> -	 */
> -	change_state(TRX_CMD_PLL_ON);
> -	change_state(TRX_CMD_RX_AACK_ON);
>   }
>   
>   
> @@ -242,7 +242,7 @@ void mac_reset(void)
>   	txing = 0;
>   	queued_tx_ack = 0;
>   	rx_in = rx_out = 0;
> -	next_seq = this_seq = queued_seq = 0;
> +	next_seq = this_seq = queued_data[0], queued_data[1] = 0;
>   
>   	/* enable CRC and PHY_RSSI (with RX_CRC_VALID) in SPI status return */
>   	reg_write(REG_TRX_CTRL_1,

Patch looks good on a first glance. I will need o un-dust my firmware 
repo and get this building and tested here. This will take a few days 
until I find enough time to do that.

Once we are happy with this I can go ahead and cut a v0.4 release and 
make sure it will land on atusb's that get produced after that date.
For the rest I will update the file in linux-firmware to flash.

regards
Stefan Schmidt
diff mbox series

Patch

diff --git a/atusb/fw/mac.c b/atusb/fw/mac.c
index 835002c..165ce30 100644
--- a/atusb/fw/mac.c
+++ b/atusb/fw/mac.c
@@ -32,7 +32,7 @@  static uint8_t tx_buf[MAX_PSDU];
 static uint8_t tx_size = 0;
 static bool txing = 0;
 static bool queued_tx_ack = 0;
-static uint8_t next_seq, this_seq, queued_seq;
+static uint8_t next_seq, this_seq, this_data[2], queued_data[2];
 
 
 /* ----- Receive buffer management ----------------------------------------- */
@@ -65,7 +65,8 @@  static void usb_next(void)
 	}
 
 	if (queued_tx_ack) {
-		usb_send(&eps[1], &queued_seq, 1, tx_ack_done, NULL);
+		usb_send(&eps[1], queued_data, sizeof(queued_data),
+			 tx_ack_done, NULL);
 		queued_tx_ack = 0;	
 	}
 }
@@ -124,11 +125,17 @@  static bool handle_irq(void)
 
 	if (txing) {
 		if (eps[1].state == EP_IDLE) {
-			usb_send(&eps[1], &this_seq, 1, tx_ack_done, NULL);
+			this_data[0] = this_seq;
+			this_data[1] = reg_read(REG_TRX_STATE);
+			usb_send(&eps[1], this_data, sizeof(this_data),
+				 tx_ack_done, NULL);
 		} else {
 			queued_tx_ack = 1;
-			queued_seq = this_seq;
+			queued_data[0] = this_seq;
+			queued_data[1] = reg_read(REG_TRX_STATE);
 		}
+		change_state(TRX_CMD_PLL_ON);
+		change_state(TRX_CMD_RX_AACK_ON);
 		txing = 0;
 		return 1;
 	}
@@ -215,13 +222,6 @@  static void do_tx(void *user)
 
 	txing = 1;
 	this_seq = next_seq;
-
-	/*
-	 * Wait until we reach BUSY_TX_ARET, so that we command the transition to
-	 * RX_AACK_ON which will be executed upon TX completion.
-	 */
-	change_state(TRX_CMD_PLL_ON);
-	change_state(TRX_CMD_RX_AACK_ON);
 }
 
 
@@ -242,7 +242,7 @@  void mac_reset(void)
 	txing = 0;
 	queued_tx_ack = 0;
 	rx_in = rx_out = 0;
-	next_seq = this_seq = queued_seq = 0;
+	next_seq = this_seq = queued_data[0], queued_data[1] = 0;
 
 	/* enable CRC and PHY_RSSI (with RX_CRC_VALID) in SPI status return */
 	reg_write(REG_TRX_CTRL_1,