usb储存之BOT/UAS内核驱动

usb储存驱动

声明

drivers/usb/storage/usb.c

static struct usb_driver usb_storage_driver = {
	.name =		DRV_NAME,
	.probe =	storage_probe, //这里是挂载
	.disconnect =	usb_stor_disconnect,
	.suspend =	usb_stor_suspend,
	.resume =	usb_stor_resume,
	.reset_resume =	usb_stor_reset_resume,
	.pre_reset =	usb_stor_pre_reset,
	.post_reset =	usb_stor_post_reset,
	.id_table =	usb_storage_usb_ids,
	.supports_autosuspend = 1,
	.soft_unbind =	1,
};

// 这里是usb主机储存控制器的驱动模板挂载
module_usb_stor_driver(usb_storage_driver, usb_stor_host_template, DRV_NAME);

普通BOT挂载流程

如果为UAS或非常规设备,则退出storage_probe。

drivers/usb/storage/usual-tables.c 的两个数组列表

  • 非规设备 ignore_ids[]
  • UAS列表 usb_storage_usb_ids[]

UAS判断:uas_use_uas_driver

	/* If uas is enabled and this device can do uas then ignore it. */
#if IS_ENABLED(CONFIG_USB_UAS)
	if (uas_use_uas_driver(intf, id, NULL))
		return -ENXIO;
#endif

非规设备判断:

	/*
	 * If the device isn't standard (is handled by a subdriver
	 * module) then don't accept it.
	 */
	if (usb_usual_ignore_device(intf))
		return -ENXIO;

然后就会走usb_stor_probe1和usb_stor_probe2流程

流式UAS挂载

drivers/usb/storage/uas.c
image

XHCI驱动重载

主要用于重写公版驱动行为

static const struct xhci_driver_overrides xhci_pci_overrides __initconst = {
	.reset = xhci_pci_setup,
	.update_hub_device = xhci_pci_update_hub_device,
};

//init
xhci_init_driver(&xhci_pci_hc_driver, &xhci_pci_overrides);

原理:非null时重新赋值函数指针
image

XHCI协议spec

https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf

USB储存 BOT(Bulk-Only Transport)CBW-UFI命令数据流

例子:https://www.usbzh.com/tool/bot-cbw-ufi-csw.html

SCSI协议

希捷:https://www.seagate.com/files/staticfiles/support/docs/manual/Interface manuals/100293068j.pdf

Others

sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA

  • FUA: Force Unit Access
  • DPO: Disable Page Out
posted @ 2025-10-15 19:09  蓝天上的云℡  阅读(5)  评论(0)    收藏  举报