URB数据传输路径:从URB到门铃
2026-11-27
本文链接为:http://www.usbzh.com/article/detail-1827.html ,欢迎转载,转载请附上本文链接。
USB设备驱动提交URB给USB主机层的函数为usb_submit_urb,该函数实际上做了一些URB内部数据处理之后会调用usb_hcd_submit_urb
int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
{
...
if (is_root_hub(urb->dev)) {
status = rh_urb_enqueue(hcd, urb);
} else {
status = map_urb_for_dma(hcd, urb, mem_flags);
if (likely(status == 0)) {
status = hcd->driver->urb_enqueue(hcd, urb, mem_flags);
if (unlikely(status))
unmap_urb_for_dma(hcd, urb);
}
}
...
}
hcd->driver->urb_enqueue对应的函数为XHCI驱动的xhci_urb_enqueue回调
static const struct hc_driver xhci_hc_driver = {
.description = "xhci-hcd",
.product_desc = "xHCI Host Controller",
.hcd_priv_size = sizeof(struct xhci_hcd),
.urb_enqueue = xhci_urb_enqueue,//入队
.urb_dequeue = xhci_urb_dequeue,//出队
}
xhci_urb_enqueue的调用关系如下:
xhci_urb_enqueue() xhci.c:1632
├─ xhci_queue_ctrl_tx() xhci-ring.c:3777
│ └─ giveback_first_trb() xhci-ring.c:3919
├─ xhci_queue_bulk_tx() xhci-ring.c:3618
│ └─ giveback_first_trb() xhci-ring.c:3771
├─ xhci_queue_intr_tx() xhci-ring.c:3490
│ └─ xhci_queue_bulk_tx()
│ └─ giveback_first_trb()
└─ xhci_queue_isoc_tx_prepare() xhci-ring.c:4277
└─ xhci_queue_isoc_tx()
└─ giveback_first_trb() xhci-ring.c:4244
xhci_urb_enqueue会根据不同的数据传输类型,分别调用相关的函数,处理URB->TD->TRB的过程。
当所有的TRB写入完成之后,调用giveback_first_trb,执行回写第一个TRB从而提交给硬件,再按下门铃,通过硬件开始处理刚写下的TRB。
static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id,
unsigned int ep_index, unsigned int stream_id, int start_cycle,
struct xhci_generic_trb *start_trb)
{
/*
* Pass all the TRBs to the hardware at once and make sure this write
* isn't reordered.
*/
wmb();
//设置cycle bit
if (start_cycle)
start_trb->field[3] |= cpu_to_le32(start_cycle);
else
start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE);
//0=用于xhci控制器,1~256用于设备
//(efine MAX_HC_SLOTS 256
xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id);
}
本文链接为:http://www.usbzh.com/article/detail-1827.html ,欢迎转载,转载请附上本文链接。
XHCI 1.2b 规范





