Linux USB
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
	niklas.neronin@linux.intel.com,
	Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 21/21] xhci: sort out TRB Endpoint ID bitfield macros
Date: Wed, 26 Jun 2024 15:48:35 +0300	[thread overview]
Message-ID: <20240626124835.1023046-22-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20240626124835.1023046-1-mathias.nyman@linux.intel.com>

xhci macros that read and write endpoint ID bitfields of TRBs are mixing
the 1-based Endpoint ID as described in the xHCI specification, and
0-based endpoint index used by driver as an array index.

Sort this out by naming macros that deal with 1 based Endpoint ID fields
to *_EP_ID_*, and 0 based endpoint index values to *_EP_INDEX_*.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-ring.c |  6 +++---
 drivers/usb/host/xhci.h      | 33 ++++++++++++++-------------------
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 49f8f980776b..b7517c3c8059 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -715,7 +715,7 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci,
 		lower_32_bits(addr) | trb_sct | new_cycle,
 		upper_32_bits(addr),
 		STREAM_ID_FOR_TRB(stream_id), SLOT_ID_FOR_TRB(slot_id) |
-		EP_ID_FOR_TRB(ep_index) | TRB_TYPE(TRB_SET_DEQ), false);
+		EP_INDEX_FOR_TRB(ep_index) | TRB_TYPE(TRB_SET_DEQ), false);
 	if (ret < 0) {
 		xhci_free_command(xhci, cmd);
 		return ret;
@@ -4379,7 +4379,7 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd,
 			     int slot_id, unsigned int ep_index, int suspend)
 {
 	u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id);
-	u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
+	u32 trb_ep_index = EP_INDEX_FOR_TRB(ep_index);
 	u32 type = TRB_TYPE(TRB_STOP_RING);
 	u32 trb_suspend = SUSPEND_PORT_FOR_TRB(suspend);
 
@@ -4392,7 +4392,7 @@ int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd,
 			enum xhci_ep_reset_type reset_type)
 {
 	u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id);
-	u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
+	u32 trb_ep_index = EP_INDEX_FOR_TRB(ep_index);
 	u32 type = TRB_TYPE(TRB_RESET_EP);
 
 	if (reset_type == EP_SOFT_RESET)
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 65c84185c7fd..9fa1b58121f0 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -805,13 +805,19 @@ struct xhci_transfer_event {
 	__le32	flags;
 };
 
+/* Transfer event flags bitfield, also for select command completion events */
+#define TRB_TO_SLOT_ID(p)	(((p) >> 24) & 0xff)
+#define SLOT_ID_FOR_TRB(p)	(((p) & 0xff) << 24)
+
+#define TRB_TO_EP_ID(p)		(((p) >> 16) & 0x1f) /* Endpoint ID 1 - 31 */
+#define EP_ID_FOR_TRB(p)	(((p) & 0x1f) << 16)
+
+#define TRB_TO_EP_INDEX(p)	(TRB_TO_EP_ID(p) - 1) /* Endpoint index 0 - 30 */
+#define EP_INDEX_FOR_TRB(p)	((((p) + 1) & 0x1f) << 16)
+
 /* Transfer event TRB length bit mask */
-/* bits 0:23 */
 #define	EVENT_TRB_LEN(p)		((p) & 0xffffff)
 
-/** Transfer Event bit fields **/
-#define	TRB_TO_EP_ID(p)	(((p) >> 16) & 0x1f)
-
 /* Completion Code - only applicable for some types of TRBs */
 #define	COMP_CODE_MASK		(0xff << 24)
 #define GET_COMP_CODE(p)	(((p) & COMP_CODE_MASK) >> 24)
@@ -950,8 +956,6 @@ struct xhci_event_cmd {
 	__le32 flags;
 };
 
-/* flags bitmasks */
-
 /* Address device - disable SetAddress */
 #define TRB_BSR		(1<<9)
 
@@ -987,13 +991,8 @@ enum xhci_setup_dev {
 
 /* bits 16:23 are the virtual function ID */
 /* bits 24:31 are the slot ID */
-#define TRB_TO_SLOT_ID(p)	(((p) & (0xff<<24)) >> 24)
-#define SLOT_ID_FOR_TRB(p)	(((p) & 0xff) << 24)
 
 /* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */
-#define TRB_TO_EP_INDEX(p)		((((p) & (0x1f << 16)) >> 16) - 1)
-#define	EP_ID_FOR_TRB(p)		((((p) + 1) & 0x1f) << 16)
-
 #define SUSPEND_PORT_FOR_TRB(p)		(((p) & 1) << 23)
 #define TRB_TO_SUSPEND_PORT(p)		(((p) & (1 << 23)) >> 23)
 #define LAST_EP_INDEX			30
@@ -2023,8 +2022,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size,
 			field1, field0,
 			xhci_trb_comp_code_string(GET_COMP_CODE(field2)),
 			EVENT_TRB_LEN(field2), TRB_TO_SLOT_ID(field3),
-			/* Macro decrements 1, maybe it shouldn't?!? */
-			TRB_TO_EP_INDEX(field3) + 1,
+			TRB_TO_EP_ID(field3),
 			xhci_trb_type_string(type),
 			field3 & EVENT_DATA ? 'E' : 'e',
 			field3 & TRB_CYCLE ? 'C' : 'c');
@@ -2139,8 +2137,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size,
 			xhci_trb_type_string(type),
 			field1, field0,
 			TRB_TO_SLOT_ID(field3),
-			/* Macro decrements 1, maybe it shouldn't?!? */
-			TRB_TO_EP_INDEX(field3) + 1,
+			TRB_TO_EP_ID(field3),
 			field3 & TRB_TSP ? 'T' : 't',
 			field3 & TRB_CYCLE ? 'C' : 'c');
 		break;
@@ -2150,8 +2147,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size,
 			xhci_trb_type_string(type),
 			TRB_TO_SLOT_ID(field3),
 			TRB_TO_SUSPEND_PORT(field3),
-			/* Macro decrements 1, maybe it shouldn't?!? */
-			TRB_TO_EP_INDEX(field3) + 1,
+			TRB_TO_EP_ID(field3),
 			field3 & TRB_CYCLE ? 'C' : 'c');
 		break;
 	case TRB_SET_DEQ:
@@ -2161,8 +2157,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size,
 			field1, field0,
 			TRB_TO_STREAM_ID(field2),
 			TRB_TO_SLOT_ID(field3),
-			/* Macro decrements 1, maybe it shouldn't?!? */
-			TRB_TO_EP_INDEX(field3) + 1,
+			TRB_TO_EP_ID(field3),
 			field3 & TRB_CYCLE ? 'C' : 'c');
 		break;
 	case TRB_RESET_DEV:
-- 
2.25.1


      parent reply	other threads:[~2024-06-26 12:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-26 12:48 [PATCH 00/21] xhci features for usb-next Mathias Nyman
2024-06-26 12:48 ` [PATCH 01/21] xhci: Remove dead code in xhci_move_dequeue_past_td() Mathias Nyman
2024-06-26 12:48 ` [PATCH 02/21] xhci: show usb device name in xhci urb tracing Mathias Nyman
2024-06-26 12:48 ` [PATCH 03/21] xhci: Set correct transferred length for cancelled isoc transfers Mathias Nyman
2024-06-26 12:48 ` [PATCH 04/21] xhci: dbc: Allow users to modify DbC poll interval via sysfs Mathias Nyman
2024-06-26 12:48 ` [PATCH 05/21] usb: xhci: remove 'num_trbs' from struct 'xhci_td' Mathias Nyman
2024-06-26 12:48 ` [PATCH 06/21] usb: xhci: remove unused 'xhci' argument Mathias Nyman
2024-06-26 12:48 ` [PATCH 07/21] usb: xhci: remove unused argument from xhci_handle_cmd_config_ep() Mathias Nyman
2024-06-26 12:48 ` [PATCH 08/21] usb: xhci: remove unused argument from handle_port_status() Mathias Nyman
2024-06-26 12:48 ` [PATCH 09/21] usb: xhci: move link chain bit quirk checks into one helper function Mathias Nyman
2024-06-26 12:48 ` [PATCH 10/21] usb: xhci: move all segment re-numbering to xhci_link_rings() Mathias Nyman
2024-06-26 12:48 ` [PATCH 11/21] usb: xhci: move untargeted transfer event handling to a separate function Mathias Nyman
2024-06-26 12:48 ` [PATCH 12/21] usb: xhci: improve error message for targetless transfer event Mathias Nyman
2024-06-26 12:48 ` [PATCH 13/21] usb: xhci: remove obsolete sanity check debug messages Mathias Nyman
2024-06-26 12:48 ` [PATCH 14/21] xhci: rework xhci internal endpoint halt state detection Mathias Nyman
2024-06-26 12:48 ` [PATCH 15/21] usb: xhci: ensure skipped isoc TDs are returned when isoc ring is stopped Mathias Nyman
2024-06-26 12:48 ` [PATCH 16/21] usb: xhci: remove false xhci_giveback_urb_in_irq() header comment Mathias Nyman
2024-06-26 12:48 ` [PATCH 17/21] usb: xhci: remove infinite loop prevention Mathias Nyman
2024-06-26 12:48 ` [PATCH 18/21] usb: xhci: move process TD code out of the while loop Mathias Nyman
2024-06-26 12:48 ` [PATCH 19/21] usb: xhci: add 'goto' for halted endpoint check in handle_tx_event() Mathias Nyman
2024-08-02  9:21   ` Michał Pecio
2024-08-02  9:39     ` Neronin, Niklas
2024-06-26 12:48 ` [PATCH 20/21] xhci: Apply XHCI_RESET_TO_DEFAULT quirk to TGL Mathias Nyman
2024-06-26 12:48 ` Mathias Nyman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240626124835.1023046-22-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=niklas.neronin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox