Skip to content

Commit db383d6

Browse files
committed
Merge branch 'for-usb-next' of git+ssh://master.kernel.org/pub/scm/linux/kernel/git/sarah/xhci into usb-next
* 'for-usb-next' of git+ssh://master.kernel.org/pub/scm/linux/kernel/git/sarah/xhci: xhci: Remove some unnecessary casts and tidy some endian swap code
2 parents 59c5f46 + f5960b6 commit db383d6

File tree

5 files changed

+52
-55
lines changed

5 files changed

+52
-55
lines changed

drivers/usb/host/xhci-dbg.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
266266
xhci_dbg(xhci, "Interrupter target = 0x%x\n",
267267
GET_INTR_TARGET(le32_to_cpu(trb->link.intr_target)));
268268
xhci_dbg(xhci, "Cycle bit = %u\n",
269-
(unsigned int) (le32_to_cpu(trb->link.control) & TRB_CYCLE));
269+
le32_to_cpu(trb->link.control) & TRB_CYCLE);
270270
xhci_dbg(xhci, "Toggle cycle bit = %u\n",
271-
(unsigned int) (le32_to_cpu(trb->link.control) & LINK_TOGGLE));
271+
le32_to_cpu(trb->link.control) & LINK_TOGGLE);
272272
xhci_dbg(xhci, "No Snoop bit = %u\n",
273-
(unsigned int) (le32_to_cpu(trb->link.control) & TRB_NO_SNOOP));
273+
le32_to_cpu(trb->link.control) & TRB_NO_SNOOP);
274274
break;
275275
case TRB_TYPE(TRB_TRANSFER):
276276
address = le64_to_cpu(trb->trans_event.buffer);
@@ -284,9 +284,9 @@ void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb)
284284
address = le64_to_cpu(trb->event_cmd.cmd_trb);
285285
xhci_dbg(xhci, "Command TRB pointer = %llu\n", address);
286286
xhci_dbg(xhci, "Completion status = %u\n",
287-
(unsigned int) GET_COMP_CODE(le32_to_cpu(trb->event_cmd.status)));
287+
GET_COMP_CODE(le32_to_cpu(trb->event_cmd.status)));
288288
xhci_dbg(xhci, "Flags = 0x%x\n",
289-
(unsigned int) le32_to_cpu(trb->event_cmd.flags));
289+
le32_to_cpu(trb->event_cmd.flags));
290290
break;
291291
default:
292292
xhci_dbg(xhci, "Unknown TRB with TRB type ID %u\n",
@@ -318,10 +318,10 @@ void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg)
318318
for (i = 0; i < TRBS_PER_SEGMENT; ++i) {
319319
trb = &seg->trbs[i];
320320
xhci_dbg(xhci, "@%016llx %08x %08x %08x %08x\n", addr,
321-
(u32)lower_32_bits(le64_to_cpu(trb->link.segment_ptr)),
322-
(u32)upper_32_bits(le64_to_cpu(trb->link.segment_ptr)),
323-
(unsigned int) le32_to_cpu(trb->link.intr_target),
324-
(unsigned int) le32_to_cpu(trb->link.control));
321+
lower_32_bits(le64_to_cpu(trb->link.segment_ptr)),
322+
upper_32_bits(le64_to_cpu(trb->link.segment_ptr)),
323+
le32_to_cpu(trb->link.intr_target),
324+
le32_to_cpu(trb->link.control));
325325
addr += sizeof(*trb);
326326
}
327327
}
@@ -402,8 +402,8 @@ void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
402402
addr,
403403
lower_32_bits(le64_to_cpu(entry->seg_addr)),
404404
upper_32_bits(le64_to_cpu(entry->seg_addr)),
405-
(unsigned int) le32_to_cpu(entry->seg_size),
406-
(unsigned int) le32_to_cpu(entry->rsvd));
405+
le32_to_cpu(entry->seg_size),
406+
le32_to_cpu(entry->rsvd));
407407
addr += sizeof(*entry);
408408
}
409409
}

drivers/usb/host/xhci-mem.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev,
8989
return;
9090
prev->next = next;
9191
if (link_trbs) {
92-
prev->trbs[TRBS_PER_SEGMENT-1].link.
93-
segment_ptr = cpu_to_le64(next->dma);
92+
prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr =
93+
cpu_to_le64(next->dma);
9494

9595
/* Set the last TRB in the segment to have a TRB type ID of Link TRB */
9696
val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control);
@@ -187,8 +187,8 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
187187

188188
if (link_trbs) {
189189
/* See section 4.9.2.1 and 6.4.4.1 */
190-
prev->trbs[TRBS_PER_SEGMENT-1].link.
191-
control |= cpu_to_le32(LINK_TOGGLE);
190+
prev->trbs[TRBS_PER_SEGMENT-1].link.control |=
191+
cpu_to_le32(LINK_TOGGLE);
192192
xhci_dbg(xhci, "Wrote link toggle flag to"
193193
" segment %p (virtual), 0x%llx (DMA)\n",
194194
prev, (unsigned long long)prev->dma);
@@ -549,8 +549,8 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
549549
addr = cur_ring->first_seg->dma |
550550
SCT_FOR_CTX(SCT_PRI_TR) |
551551
cur_ring->cycle_state;
552-
stream_info->stream_ctx_array[cur_stream].
553-
stream_ring = cpu_to_le64(addr);
552+
stream_info->stream_ctx_array[cur_stream].stream_ring =
553+
cpu_to_le64(addr);
554554
xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n",
555555
cur_stream, (unsigned long long) addr);
556556

@@ -786,7 +786,7 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
786786
xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n",
787787
slot_id,
788788
&xhci->dcbaa->dev_context_ptrs[slot_id],
789-
(unsigned long long) le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id]));
789+
le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id]));
790790

791791
return 1;
792792
fail:
@@ -890,19 +890,19 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
890890
ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG);
891891

892892
/* 3) Only the control endpoint is valid - one endpoint context */
893-
slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | (u32) udev->route);
893+
slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route);
894894
switch (udev->speed) {
895895
case USB_SPEED_SUPER:
896-
slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_SS);
896+
slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS);
897897
break;
898898
case USB_SPEED_HIGH:
899-
slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_HS);
899+
slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS);
900900
break;
901901
case USB_SPEED_FULL:
902-
slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_FS);
902+
slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS);
903903
break;
904904
case USB_SPEED_LOW:
905-
slot_ctx->dev_info |= cpu_to_le32((u32) SLOT_SPEED_LS);
905+
slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS);
906906
break;
907907
case USB_SPEED_WIRELESS:
908908
xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
@@ -916,7 +916,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
916916
port_num = xhci_find_real_port_number(xhci, udev);
917917
if (!port_num)
918918
return -EINVAL;
919-
slot_ctx->dev_info2 |= cpu_to_le32((u32) ROOT_HUB_PORT(port_num));
919+
slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(port_num));
920920
/* Set the port number in the virtual_device to the faked port number */
921921
for (top_dev = udev; top_dev->parent && top_dev->parent->parent;
922922
top_dev = top_dev->parent)

drivers/usb/host/xhci-ring.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,13 @@ static int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
113113
if (ring == xhci->event_ring)
114114
return trb == &seg->trbs[TRBS_PER_SEGMENT];
115115
else
116-
return (le32_to_cpu(trb->link.control) & TRB_TYPE_BITMASK)
117-
== TRB_TYPE(TRB_LINK);
116+
return TRB_TYPE_LINK_LE32(trb->link.control);
118117
}
119118

120119
static int enqueue_is_link_trb(struct xhci_ring *ring)
121120
{
122121
struct xhci_link_trb *link = &ring->enqueue->link;
123-
return ((le32_to_cpu(link->control) & TRB_TYPE_BITMASK) ==
124-
TRB_TYPE(TRB_LINK));
122+
return TRB_TYPE_LINK_LE32(link->control);
125123
}
126124

127125
/* Updates trb to point to the next TRB in the ring, and updates seg if the next
@@ -372,7 +370,7 @@ static struct xhci_segment *find_trb_seg(
372370
while (cur_seg->trbs > trb ||
373371
&cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
374372
generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic;
375-
if (le32_to_cpu(generic_trb->field[3]) & LINK_TOGGLE)
373+
if (generic_trb->field[3] & cpu_to_le32(LINK_TOGGLE))
376374
*cycle_state ^= 0x1;
377375
cur_seg = cur_seg->next;
378376
if (cur_seg == start_seg)
@@ -489,8 +487,8 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
489487
}
490488

491489
trb = &state->new_deq_ptr->generic;
492-
if ((le32_to_cpu(trb->field[3]) & TRB_TYPE_BITMASK) ==
493-
TRB_TYPE(TRB_LINK) && (le32_to_cpu(trb->field[3]) & LINK_TOGGLE))
490+
if (TRB_TYPE_LINK_LE32(trb->field[3]) &&
491+
(trb->field[3] & cpu_to_le32(LINK_TOGGLE)))
494492
state->new_cycle_state ^= 0x1;
495493
next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr);
496494

@@ -525,8 +523,7 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
525523
for (cur_seg = cur_td->start_seg, cur_trb = cur_td->first_trb;
526524
true;
527525
next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
528-
if ((le32_to_cpu(cur_trb->generic.field[3]) & TRB_TYPE_BITMASK)
529-
== TRB_TYPE(TRB_LINK)) {
526+
if (TRB_TYPE_LINK_LE32(cur_trb->generic.field[3])) {
530527
/* Unchain any chained Link TRBs, but
531528
* leave the pointers intact.
532529
*/
@@ -1000,7 +997,7 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
1000997
* but we don't care.
1001998
*/
1002999
xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n",
1003-
(unsigned int) GET_COMP_CODE(le32_to_cpu(event->status)));
1000+
GET_COMP_CODE(le32_to_cpu(event->status)));
10041001

10051002
/* HW with the reset endpoint quirk needs to have a configure endpoint
10061003
* command complete before the endpoint can be used. Queue that here
@@ -1458,7 +1455,8 @@ static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci,
14581455
* endpoint anyway. Check if a babble halted the
14591456
* endpoint.
14601457
*/
1461-
if ((le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) == EP_STATE_HALTED)
1458+
if ((ep_ctx->ep_info & cpu_to_le32(EP_STATE_MASK)) ==
1459+
cpu_to_le32(EP_STATE_HALTED))
14621460
return 1;
14631461

14641462
return 0;
@@ -1752,10 +1750,8 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
17521750
for (cur_trb = ep_ring->dequeue,
17531751
cur_seg = ep_ring->deq_seg; cur_trb != event_trb;
17541752
next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1755-
if ((le32_to_cpu(cur_trb->generic.field[3]) &
1756-
TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1757-
(le32_to_cpu(cur_trb->generic.field[3]) &
1758-
TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1753+
if (!TRB_TYPE_NOOP_LE32(cur_trb->generic.field[3]) &&
1754+
!TRB_TYPE_LINK_LE32(cur_trb->generic.field[3]))
17591755
len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2]));
17601756
}
17611757
len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) -
@@ -1888,10 +1884,8 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
18881884
for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg;
18891885
cur_trb != event_trb;
18901886
next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1891-
if ((le32_to_cpu(cur_trb->generic.field[3]) &
1892-
TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1893-
(le32_to_cpu(cur_trb->generic.field[3]) &
1894-
TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1887+
if (!TRB_TYPE_NOOP_LE32(cur_trb->generic.field[3]) &&
1888+
!TRB_TYPE_LINK_LE32(cur_trb->generic.field[3]))
18951889
td->urb->actual_length +=
18961890
TRB_LEN(le32_to_cpu(cur_trb->generic.field[2]));
18971891
}
@@ -2046,8 +2040,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
20462040
TRB_TO_SLOT_ID(le32_to_cpu(event->flags)),
20472041
ep_index);
20482042
xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
2049-
(unsigned int) (le32_to_cpu(event->flags)
2050-
& TRB_TYPE_BITMASK)>>10);
2043+
(le32_to_cpu(event->flags) &
2044+
TRB_TYPE_BITMASK)>>10);
20512045
xhci_print_trb_offsets(xhci, (union xhci_trb *) event);
20522046
if (ep->skip) {
20532047
ep->skip = false;
@@ -2104,9 +2098,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
21042098
* corresponding TD has been cancelled. Just ignore
21052099
* the TD.
21062100
*/
2107-
if ((le32_to_cpu(event_trb->generic.field[3])
2108-
& TRB_TYPE_BITMASK)
2109-
== TRB_TYPE(TRB_TR_NOOP)) {
2101+
if (TRB_TYPE_NOOP_LE32(event_trb->generic.field[3])) {
21102102
xhci_dbg(xhci,
21112103
"event_trb is a no-op TRB. Skip it\n");
21122104
goto cleanup;
@@ -2432,7 +2424,7 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
24322424
next->link.control |= cpu_to_le32(TRB_CHAIN);
24332425

24342426
wmb();
2435-
next->link.control ^= cpu_to_le32((u32) TRB_CYCLE);
2427+
next->link.control ^= cpu_to_le32(TRB_CYCLE);
24362428

24372429
/* Toggle the cycle bit after the last ring segment. */
24382430
if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) {

drivers/usb/host/xhci.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,8 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
13331333
/* If the HC already knows the endpoint is disabled,
13341334
* or the HCD has noted it is disabled, ignore this request
13351335
*/
1336-
if ((le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK) ==
1337-
EP_STATE_DISABLED ||
1336+
if (((ep_ctx->ep_info & cpu_to_le32(EP_STATE_MASK)) ==
1337+
cpu_to_le32(EP_STATE_DISABLED)) ||
13381338
le32_to_cpu(ctrl_ctx->drop_flags) &
13391339
xhci_get_endpoint_flag(&ep->desc)) {
13401340
xhci_warn(xhci, "xHCI %s called with disabled ep %p\n",
@@ -1725,8 +1725,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
17251725
/* Enqueue pointer can be left pointing to the link TRB,
17261726
* we must handle that
17271727
*/
1728-
if ((le32_to_cpu(command->command_trb->link.control)
1729-
& TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
1728+
if (TRB_TYPE_LINK_LE32(command->command_trb->link.control))
17301729
command->command_trb =
17311730
xhci->cmd_ring->enq_seg->next->trbs;
17321731

@@ -2519,8 +2518,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
25192518
/* Enqueue pointer can be left pointing to the link TRB,
25202519
* we must handle that
25212520
*/
2522-
if ((le32_to_cpu(reset_device_cmd->command_trb->link.control)
2523-
& TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
2521+
if (TRB_TYPE_LINK_LE32(reset_device_cmd->command_trb->link.control))
25242522
reset_device_cmd->command_trb =
25252523
xhci->cmd_ring->enq_seg->next->trbs;
25262524

drivers/usb/host/xhci.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,13 @@ union xhci_trb {
10651065
/* Get NEC firmware revision. */
10661066
#define TRB_NEC_GET_FW 49
10671067

1068+
#define TRB_TYPE_LINK(x) (((x) & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
1069+
/* Above, but for __le32 types -- can avoid work by swapping constants: */
1070+
#define TRB_TYPE_LINK_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
1071+
cpu_to_le32(TRB_TYPE(TRB_LINK)))
1072+
#define TRB_TYPE_NOOP_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
1073+
cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)))
1074+
10681075
#define NEC_FW_MINOR(p) (((p) >> 0) & 0xff)
10691076
#define NEC_FW_MAJOR(p) (((p) >> 8) & 0xff)
10701077

0 commit comments

Comments
 (0)