Skip to content

Commit 36b1235

Browse files
matnymangregkh
authored andcommitted
xhci: sort out TRB Endpoint ID bitfield macros
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b4c87bc commit 36b1235

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

drivers/usb/host/xhci-ring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci,
715715
lower_32_bits(addr) | trb_sct | new_cycle,
716716
upper_32_bits(addr),
717717
STREAM_ID_FOR_TRB(stream_id), SLOT_ID_FOR_TRB(slot_id) |
718-
EP_ID_FOR_TRB(ep_index) | TRB_TYPE(TRB_SET_DEQ), false);
718+
EP_INDEX_FOR_TRB(ep_index) | TRB_TYPE(TRB_SET_DEQ), false);
719719
if (ret < 0) {
720720
xhci_free_command(xhci, cmd);
721721
return ret;
@@ -4379,7 +4379,7 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd,
43794379
int slot_id, unsigned int ep_index, int suspend)
43804380
{
43814381
u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id);
4382-
u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
4382+
u32 trb_ep_index = EP_INDEX_FOR_TRB(ep_index);
43834383
u32 type = TRB_TYPE(TRB_STOP_RING);
43844384
u32 trb_suspend = SUSPEND_PORT_FOR_TRB(suspend);
43854385

@@ -4392,7 +4392,7 @@ int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd,
43924392
enum xhci_ep_reset_type reset_type)
43934393
{
43944394
u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id);
4395-
u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
4395+
u32 trb_ep_index = EP_INDEX_FOR_TRB(ep_index);
43964396
u32 type = TRB_TYPE(TRB_RESET_EP);
43974397

43984398
if (reset_type == EP_SOFT_RESET)

drivers/usb/host/xhci.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,19 @@ struct xhci_transfer_event {
806806
__le32 flags;
807807
};
808808

809+
/* Transfer event flags bitfield, also for select command completion events */
810+
#define TRB_TO_SLOT_ID(p) (((p) >> 24) & 0xff)
811+
#define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
812+
813+
#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f) /* Endpoint ID 1 - 31 */
814+
#define EP_ID_FOR_TRB(p) (((p) & 0x1f) << 16)
815+
816+
#define TRB_TO_EP_INDEX(p) (TRB_TO_EP_ID(p) - 1) /* Endpoint index 0 - 30 */
817+
#define EP_INDEX_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
818+
809819
/* Transfer event TRB length bit mask */
810-
/* bits 0:23 */
811820
#define EVENT_TRB_LEN(p) ((p) & 0xffffff)
812821

813-
/** Transfer Event bit fields **/
814-
#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
815-
816822
/* Completion Code - only applicable for some types of TRBs */
817823
#define COMP_CODE_MASK (0xff << 24)
818824
#define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
@@ -951,8 +957,6 @@ struct xhci_event_cmd {
951957
__le32 flags;
952958
};
953959

954-
/* flags bitmasks */
955-
956960
/* Address device - disable SetAddress */
957961
#define TRB_BSR (1<<9)
958962

@@ -988,13 +992,8 @@ enum xhci_setup_dev {
988992

989993
/* bits 16:23 are the virtual function ID */
990994
/* bits 24:31 are the slot ID */
991-
#define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24)
992-
#define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
993995

994996
/* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */
995-
#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
996-
#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
997-
998997
#define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23)
999998
#define TRB_TO_SUSPEND_PORT(p) (((p) & (1 << 23)) >> 23)
1000999
#define LAST_EP_INDEX 30
@@ -2025,8 +2024,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size,
20252024
field1, field0,
20262025
xhci_trb_comp_code_string(GET_COMP_CODE(field2)),
20272026
EVENT_TRB_LEN(field2), TRB_TO_SLOT_ID(field3),
2028-
/* Macro decrements 1, maybe it shouldn't?!? */
2029-
TRB_TO_EP_INDEX(field3) + 1,
2027+
TRB_TO_EP_ID(field3),
20302028
xhci_trb_type_string(type),
20312029
field3 & EVENT_DATA ? 'E' : 'e',
20322030
field3 & TRB_CYCLE ? 'C' : 'c');
@@ -2141,8 +2139,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size,
21412139
xhci_trb_type_string(type),
21422140
field1, field0,
21432141
TRB_TO_SLOT_ID(field3),
2144-
/* Macro decrements 1, maybe it shouldn't?!? */
2145-
TRB_TO_EP_INDEX(field3) + 1,
2142+
TRB_TO_EP_ID(field3),
21462143
field3 & TRB_TSP ? 'T' : 't',
21472144
field3 & TRB_CYCLE ? 'C' : 'c');
21482145
break;
@@ -2152,8 +2149,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size,
21522149
xhci_trb_type_string(type),
21532150
TRB_TO_SLOT_ID(field3),
21542151
TRB_TO_SUSPEND_PORT(field3),
2155-
/* Macro decrements 1, maybe it shouldn't?!? */
2156-
TRB_TO_EP_INDEX(field3) + 1,
2152+
TRB_TO_EP_ID(field3),
21572153
field3 & TRB_CYCLE ? 'C' : 'c');
21582154
break;
21592155
case TRB_SET_DEQ:
@@ -2163,8 +2159,7 @@ static inline const char *xhci_decode_trb(char *str, size_t size,
21632159
field1, field0,
21642160
TRB_TO_STREAM_ID(field2),
21652161
TRB_TO_SLOT_ID(field3),
2166-
/* Macro decrements 1, maybe it shouldn't?!? */
2167-
TRB_TO_EP_INDEX(field3) + 1,
2162+
TRB_TO_EP_ID(field3),
21682163
field3 & TRB_CYCLE ? 'C' : 'c');
21692164
break;
21702165
case TRB_RESET_DEV:

0 commit comments

Comments
 (0)