···2828#include <common.h>
2929#include <command.h>
3030#include <dm.h>
3131+#include <dm/device_compat.h>
3132#include <log.h>
3233#include <malloc.h>
3334#include <memalign.h>
···10841085 return 0;
10851086}
1086108710881088+static int usb_device_is_ignored(u16 id_vendor, u16 id_product)
10891089+{
10901090+ ulong vid, pid;
10911091+ char *end;
10921092+ const char *cur = NULL;
10931093+10941094+ /* ignore list depends on env support */
10951095+ if (!CONFIG_IS_ENABLED(ENV_SUPPORT))
10961096+ return 0;
10971097+10981098+ cur = env_get("usb_ignorelist");
10991099+11001100+ /* parse "usb_ignorelist" strictly */
11011101+ while (cur && cur[0] != '\0') {
11021102+ vid = simple_strtoul(cur, &end, 0);
11031103+ /*
11041104+ * If strtoul did not parse a single digit or the next char is
11051105+ * not ':' the ignore list is malformed.
11061106+ */
11071107+ if (cur == end || end[0] != ':')
11081108+ return -EINVAL;
11091109+11101110+ cur = end + 1;
11111111+ pid = simple_strtoul(cur, &end, 0);
11121112+ /* Consider '*' as wildcard for the product ID */
11131113+ if (cur == end && end[0] == '*') {
11141114+ pid = U16_MAX + 1;
11151115+ end++;
11161116+ }
11171117+ /*
11181118+ * The ignore list is malformed if no product ID / wildcard was
11191119+ * parsed or entries are not separated by ',' or terminated with
11201120+ * '\0'.
11211121+ */
11221122+ if (cur == end || (end[0] != ',' && end[0] != '\0'))
11231123+ return -EINVAL;
11241124+11251125+ if (id_vendor == vid && (pid > U16_MAX || id_product == pid))
11261126+ return -ENODEV;
11271127+11281128+ if (end[0] == '\0')
11291129+ break;
11301130+ cur = end + 1;
11311131+ }
11321132+11331133+ return 0;
11341134+}
11351135+10871136int usb_select_config(struct usb_device *dev)
10881137{
10891138 unsigned char *tmpbuf = NULL;
···10981147 le16_to_cpus(&dev->descriptor.idVendor);
10991148 le16_to_cpus(&dev->descriptor.idProduct);
11001149 le16_to_cpus(&dev->descriptor.bcdDevice);
11501150+11511151+ /* ignore devices from usb_ignorelist */
11521152+ err = usb_device_is_ignored(dev->descriptor.idVendor,
11531153+ dev->descriptor.idProduct);
11541154+ if (err == -ENODEV) {
11551155+ debug("Ignoring USB device 0x%x:0x%x\n",
11561156+ dev->descriptor.idVendor, dev->descriptor.idProduct);
11571157+ return err;
11581158+ } else if (err == -EINVAL) {
11591159+ /*
11601160+ * Continue on "usb_ignorelist" parsing errors. The list is
11611161+ * parsed for each device returning the error would result in
11621162+ * ignoring all USB devices.
11631163+ * Since the parsing error is independent of the probed device
11641164+ * report errors with printf instead of dev_err.
11651165+ */
11661166+ printf("usb_ignorelist parse error in \"%s\"\n",
11671167+ env_get("usb_ignorelist"));
11681168+ } else if (err < 0) {
11691169+ return err;
11701170+ }
1101117111021172 /*
11031173 * Kingston DT Ultimate 32GB USB 3.0 seems to be extremely sensitive
+56-3
common/usb_kbd.c
···2424#include <usb.h>
25252626/*
2727+ * USB vendor and product IDs used for quirks.
2828+ */
2929+#define USB_VENDOR_ID_APPLE 0x05ac
3030+#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 0x029c
3131+#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 0x029a
3232+#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021 0x029f
3333+3434+#define USB_VENDOR_ID_KEYCHRON 0x3434
3535+3636+#define USB_HID_QUIRK_POLL_NO_REPORT_IDLE BIT(0)
3737+3838+/*
2739 * If overwrite_console returns 1, the stdin, stderr and stdout
2840 * are switched to the serial port, else the settings in the
2941 * environment are used
···106118 unsigned long last_report;
107119 struct int_queue *intq;
108120121121+ uint32_t ifnum;
122122+109123 uint32_t repeat_delay;
110124111125 uint32_t usb_in_pointer;
···150164 */
151165static void usb_kbd_setled(struct usb_device *dev)
152166{
153153- struct usb_interface *iface = &dev->config.if_desc[0];
154167 struct usb_kbd_pdata *data = dev->privptr;
168168+ struct usb_interface *iface = &dev->config.if_desc[data->ifnum];
155169 ALLOC_ALIGN_BUFFER(uint32_t, leds, 1, USB_DMA_MINALIGN);
156170157171 *leds = data->flags & USB_KBD_LEDMASK;
···365379#if defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP)
366380 struct usb_interface *iface;
367381 struct usb_kbd_pdata *data = dev->privptr;
368368- iface = &dev->config.if_desc[0];
382382+ iface = &dev->config.if_desc[data->ifnum];
369383 usb_get_report(dev, iface->desc.bInterfaceNumber,
370384 1, 0, data->new, USB_KBD_BOOT_REPORT_SIZE);
371385 if (memcmp(data->old, data->new, USB_KBD_BOOT_REPORT_SIZE)) {
···464478 struct usb_interface *iface;
465479 struct usb_endpoint_descriptor *ep;
466480 struct usb_kbd_pdata *data;
481481+ unsigned int quirks = 0;
467482 int epNum;
468483469484 if (dev->descriptor.bNumConfigurations != 1)
···496511497512 debug("USB KBD: found interrupt EP: 0x%x\n", ep->bEndpointAddress);
498513514514+ switch (dev->descriptor.idVendor) {
515515+ case USB_VENDOR_ID_APPLE:
516516+ case USB_VENDOR_ID_KEYCHRON:
517517+ quirks |= USB_HID_QUIRK_POLL_NO_REPORT_IDLE;
518518+ break;
519519+ default:
520520+ break;
521521+ }
522522+499523 data = malloc(sizeof(struct usb_kbd_pdata));
500524 if (!data) {
501525 printf("USB KBD: Error allocating private data\n");
···508532 /* allocate input buffer aligned and sized to USB DMA alignment */
509533 data->new = memalign(USB_DMA_MINALIGN,
510534 roundup(USB_KBD_BOOT_REPORT_SIZE, USB_DMA_MINALIGN));
535535+536536+ data->ifnum = ifnum;
511537512538 /* Insert private data into USB device structure */
513539 dev->privptr = data;
···534560 usb_set_idle(dev, iface->desc.bInterfaceNumber, 0, 0);
535561#endif
536562563563+ /*
564564+ * Apple and Keychron keyboards do not report the device state. Reports
565565+ * are only returned during key presses.
566566+ */
567567+ if (quirks & USB_HID_QUIRK_POLL_NO_REPORT_IDLE) {
568568+ debug("USB KBD: quirk: skip testing device state\n");
569569+ return 1;
570570+ }
537571 debug("USB KBD: enable interrupt pipe...\n");
538572#ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
539573 data->intq = create_int_queue(dev, data->intpipe, 1,
···561595{
562596 char *stdinname;
563597 struct stdio_dev usb_kbd_dev;
598598+ unsigned int ifnum;
599599+ unsigned int max_ifnum = min((unsigned int)USB_MAX_ACTIVE_INTERFACES,
600600+ (unsigned int)dev->config.no_of_if);
564601 int error;
565602566603 /* Try probing the keyboard */
567567- if (usb_kbd_probe_dev(dev, 0) != 1)
604604+ for (ifnum = 0; ifnum < max_ifnum; ifnum++) {
605605+ if (usb_kbd_probe_dev(dev, ifnum) == 1)
606606+ break;
607607+ }
608608+ if (ifnum >= max_ifnum)
568609 return -ENOENT;
569610570611 /* Register the keyboard */
···730771 .bInterfaceClass = USB_CLASS_HID,
731772 .bInterfaceSubClass = USB_SUB_HID_BOOT,
732773 .bInterfaceProtocol = USB_PROT_HID_KEYBOARD,
774774+ },
775775+ {
776776+ USB_DEVICE(USB_VENDOR_ID_APPLE,
777777+ USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
778778+ },
779779+ {
780780+ USB_DEVICE(USB_VENDOR_ID_APPLE,
781781+ USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021),
782782+ },
783783+ {
784784+ USB_DEVICE(USB_VENDOR_ID_APPLE,
785785+ USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021),
733786 },
734787 { } /* Terminating entry */
735788};
+13
doc/usage/environment.rst
···366366 This means the count of blocks we can receive before
367367 sending ack to server.
368368369369+usb_ignorelist
370370+ Ignore USB devices to prevent binding them to an USB device driver. This can
371371+ be used to ignore devices are for some reason undesirable or causes crashes
372372+ u-boot's USB stack.
373373+ An example for undesired behavior is the keyboard emulation of security keys
374374+ like Yubikeys. U-boot currently supports only a single USB keyboard device
375375+ so try to probe an useful keyboard device. The default environment blocks
376376+ Yubico devices as common devices emulating keyboards.
377377+ Devices are matched by idVendor and idProduct. The variable contains a comma
378378+ separated list of idVendor:idProduct pairs as hexadecimal numbers joined
379379+ by a colon. '*' functions as a wildcard for idProduct to block all devices
380380+ with the specified idVendor.
381381+369382vlan
370383 When set to a value < 4095 the traffic over
371384 Ethernet is encapsulated/received over 802.1q
+5
drivers/usb/host/xhci-ring.c
···685685 reset_ep(udev, ep_index);
686686687687 ring = virt_dev->eps[ep_index].ring;
688688+ if (!ring)
689689+ return -EINVAL;
690690+688691 /*
689692 * How much data is (potentially) left before the 64KB boundary?
690693 * XHCI Spec puts restriction( TABLE 49 and 6.4.1 section of XHCI Spec)
···871874 ep_index = usb_pipe_ep_index(pipe);
872875873876 ep_ring = virt_dev->eps[ep_index].ring;
877877+ if (!ep_ring)
878878+ return -EINVAL;
874879875880 /*
876881 * Check to see if the max packet size for the default control
+80-46
drivers/usb/host/xhci.c
···475475}
476476477477/**
478478- * Configure the endpoint, programming the device contexts.
478478+ * Fill endpoint contexts for interface descriptor ifdesc.
479479 *
480480- * @param udev pointer to the USB device structure
481481- * Return: returns the status of the xhci_configure_endpoints
480480+ * @param udev pointer to the USB device structure
481481+ * @param ctrl pointer to the xhci pravte device structure
482482+ * @param virt_dev pointer to the xhci virtual device structure
483483+ * @param ifdesc pointer to the USB interface config descriptor
484484+ * Return: returns the status of xhci_init_ep_contexts_if
482485 */
483483-static int xhci_set_configuration(struct usb_device *udev)
486486+static int xhci_init_ep_contexts_if(struct usb_device *udev,
487487+ struct xhci_ctrl *ctrl,
488488+ struct xhci_virt_device *virt_dev,
489489+ struct usb_interface *ifdesc
490490+ )
484491{
485485- struct xhci_container_ctx *in_ctx;
486486- struct xhci_container_ctx *out_ctx;
487487- struct xhci_input_control_ctx *ctrl_ctx;
488488- struct xhci_slot_ctx *slot_ctx;
489492 struct xhci_ep_ctx *ep_ctx[MAX_EP_CTX_NUM];
490493 int cur_ep;
491491- int max_ep_flag = 0;
492494 int ep_index;
493495 unsigned int dir;
494496 unsigned int ep_type;
495495- struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
496496- int num_of_ep;
497497- int ep_flag = 0;
498497 u64 trb_64 = 0;
499499- int slot_id = udev->slot_id;
500500- struct xhci_virt_device *virt_dev = ctrl->devs[slot_id];
501501- struct usb_interface *ifdesc;
502498 u32 max_esit_payload;
503499 unsigned int interval;
504500 unsigned int mult;
505501 unsigned int max_burst;
506502 unsigned int avg_trb_len;
507503 unsigned int err_count = 0;
508508-509509- out_ctx = virt_dev->out_ctx;
510510- in_ctx = virt_dev->in_ctx;
504504+ int num_of_ep = ifdesc->no_of_ep;
511505512512- num_of_ep = udev->config.if_desc[0].no_of_ep;
513513- ifdesc = &udev->config.if_desc[0];
514514-515515- ctrl_ctx = xhci_get_input_control_ctx(in_ctx);
516516- /* Initialize the input context control */
517517- ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG);
518518- ctrl_ctx->drop_flags = 0;
519519-520520- /* EP_FLAG gives values 1 & 4 for EP1OUT and EP2IN */
521521- for (cur_ep = 0; cur_ep < num_of_ep; cur_ep++) {
522522- ep_flag = xhci_get_ep_index(&ifdesc->ep_desc[cur_ep]);
523523- ctrl_ctx->add_flags |= cpu_to_le32(1 << (ep_flag + 1));
524524- if (max_ep_flag < ep_flag)
525525- max_ep_flag = ep_flag;
526526- }
527527-528528- xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size);
529529-530530- /* slot context */
531531- xhci_slot_copy(ctrl, in_ctx, out_ctx);
532532- slot_ctx = xhci_get_slot_ctx(ctrl, in_ctx);
533533- slot_ctx->dev_info &= ~(cpu_to_le32(LAST_CTX_MASK));
534534- slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(max_ep_flag + 1) | 0);
535535-536536- xhci_endpoint_copy(ctrl, in_ctx, out_ctx, 0);
537537-538538- /* filling up ep contexts */
539506 for (cur_ep = 0; cur_ep < num_of_ep; cur_ep++) {
540507 struct usb_endpoint_descriptor *endpt_desc = NULL;
541508 struct usb_ss_ep_comp_descriptor *ss_ep_comp_desc = NULL;
···561528 avg_trb_len = max_esit_payload;
562529563530 ep_index = xhci_get_ep_index(endpt_desc);
564564- ep_ctx[ep_index] = xhci_get_ep_ctx(ctrl, in_ctx, ep_index);
531531+ ep_ctx[ep_index] = xhci_get_ep_ctx(ctrl, virt_dev->in_ctx,
532532+ ep_index);
565533566534 /* Allocate the ep rings */
567535 virt_dev->eps[ep_index].ring = xhci_ring_alloc(ctrl, 1, true);
···612580 ep_ctx[ep_index]->reserved[0] =
613581 cpu_to_le32(EP_BPKTS(1) | EP_BBM(1));
614582 }
583583+ }
584584+585585+ return 0;
586586+}
587587+588588+/**
589589+ * Configure the endpoint, programming the device contexts.
590590+ *
591591+ * @param udev pointer to the USB device structure
592592+ * Return: returns the status of the xhci_configure_endpoints
593593+ */
594594+static int xhci_set_configuration(struct usb_device *udev)
595595+{
596596+ struct xhci_container_ctx *out_ctx;
597597+ struct xhci_container_ctx *in_ctx;
598598+ struct xhci_input_control_ctx *ctrl_ctx;
599599+ struct xhci_slot_ctx *slot_ctx;
600600+ int err;
601601+ int cur_ep;
602602+ int max_ep_flag = 0;
603603+ struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
604604+ int num_of_ep;
605605+ int ep_flag = 0;
606606+ int slot_id = udev->slot_id;
607607+ struct xhci_virt_device *virt_dev = ctrl->devs[slot_id];
608608+ struct usb_interface *ifdesc;
609609+ unsigned int ifnum;
610610+ unsigned int max_ifnum = min((unsigned int)USB_MAX_ACTIVE_INTERFACES,
611611+ (unsigned int)udev->config.no_of_if);
612612+613613+ out_ctx = virt_dev->out_ctx;
614614+ in_ctx = virt_dev->in_ctx;
615615+616616+ ctrl_ctx = xhci_get_input_control_ctx(in_ctx);
617617+ /* Initialize the input context control */
618618+ ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG);
619619+ ctrl_ctx->drop_flags = 0;
620620+621621+ for (ifnum = 0; ifnum < max_ifnum; ifnum++) {
622622+ ifdesc = &udev->config.if_desc[ifnum];
623623+ num_of_ep = ifdesc->no_of_ep;
624624+ /* EP_FLAG gives values 1 & 4 for EP1OUT and EP2IN */
625625+ for (cur_ep = 0; cur_ep < num_of_ep; cur_ep++) {
626626+ ep_flag = xhci_get_ep_index(&ifdesc->ep_desc[cur_ep]);
627627+ ctrl_ctx->add_flags |= cpu_to_le32(1 << (ep_flag + 1));
628628+ if (max_ep_flag < ep_flag)
629629+ max_ep_flag = ep_flag;
630630+ }
631631+ }
632632+633633+ xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size);
634634+635635+ /* slot context */
636636+ xhci_slot_copy(ctrl, in_ctx, out_ctx);
637637+ slot_ctx = xhci_get_slot_ctx(ctrl, in_ctx);
638638+ slot_ctx->dev_info &= ~(cpu_to_le32(LAST_CTX_MASK));
639639+ slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(max_ep_flag + 1) | 0);
640640+641641+ xhci_endpoint_copy(ctrl, in_ctx, out_ctx, 0);
642642+643643+ /* filling up ep contexts */
644644+ for (ifnum = 0; ifnum < max_ifnum; ifnum++) {
645645+ ifdesc = &udev->config.if_desc[ifnum];
646646+ err = xhci_init_ep_contexts_if(udev, ctrl, virt_dev, ifdesc);
647647+ if (err < 0)
648648+ return err;
615649 }
616650617651 return xhci_configure_endpoints(udev, false);
+11
include/env_default.h
···9999#ifdef CONFIG_SYS_SOC
100100 "soc=" CONFIG_SYS_SOC "\0"
101101#endif
102102+#ifdef CONFIG_USB_HOST
103103+ "usb_ignorelist="
104104+#ifdef CONFIG_USB_KEYBOARD
105105+ /* Ignore Yubico devices. Currently only a single USB keyboard device is
106106+ * supported and the emulated HID keyboard Yubikeys present is useless
107107+ * as keyboard.
108108+ */
109109+ "0x1050:*,"
110110+#endif
111111+ "\0"
112112+#endif
102113#ifdef CONFIG_ENV_IMPORT_FDT
103114 "env_fdt_path=" CONFIG_ENV_FDT_PATH "\0"
104115#endif
+6
include/usb.h
···4949 */
5050#define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000)
51515252+/*
5353+ * The xhcd hcd driver prepares only a limited number interfaces / endpoints.
5454+ * Define this limit so that drivers do not exceed it.
5555+ */
5656+#define USB_MAX_ACTIVE_INTERFACES 2
5757+5258/* device request (setup) */
5359struct devrequest {
5460 __u8 requesttype;