From owner-dev-commits-src-all@freebsd.org Mon Dec 28 13:02:08 2020 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 128FF4B3CFD; Mon, 28 Dec 2020 13:02:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D4Hkm0490z3PPg; Mon, 28 Dec 2020 13:02:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E961619FDA; Mon, 28 Dec 2020 13:02:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 0BSD27QC023387; Mon, 28 Dec 2020 13:02:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 0BSD27PB023386; Mon, 28 Dec 2020 13:02:07 GMT (envelope-from git) Date: Mon, 28 Dec 2020 13:02:07 GMT Message-Id: <202012281302.0BSD27PB023386@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Hans Petter Selasky Subject: git: d511b855ed55 - stable/11 - MFC r368659 and r368664: Improve handling of alternate settings in the USB stack. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/stable/11 X-Git-Reftype: branch X-Git-Commit: d511b855ed55bf72e88f7b00fa1268379f30a792 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "Commit messages for all branches of the src repository." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Dec 2020 13:02:08 -0000 The branch stable/11 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=d511b855ed55bf72e88f7b00fa1268379f30a792 commit d511b855ed55bf72e88f7b00fa1268379f30a792 Author: Hans Petter Selasky AuthorDate: 2020-12-15 12:05:07 +0000 Commit: Hans Petter Selasky CommitDate: 2020-12-28 13:00:42 +0000 MFC r368659 and r368664: Improve handling of alternate settings in the USB stack. Allow setting the alternate interface number to fail when there is only one alternate setting present, to comply with the USB specification. Refactor how iface->num_altsetting is computed. Bump the __FreeBSD_version due to change of core USB structure. PR: 251856 Submitted by: Ma, Horse Sponsored by: Mellanox Technologies // NVIDIA Networking --- sys/compat/linuxkpi/common/src/linux_usb.c | 5 ----- sys/dev/usb/usb_device.c | 6 +++++- sys/dev/usb/usb_request.c | 15 +++++++++++++-- sys/dev/usb/usbdi.h | 4 +++- sys/sys/param.h | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_usb.c b/sys/compat/linuxkpi/common/src/linux_usb.c index abef31e20a07..1875bbfa5e11 100644 --- a/sys/compat/linuxkpi/common/src/linux_usb.c +++ b/sys/compat/linuxkpi/common/src/linux_usb.c @@ -937,17 +937,12 @@ usb_linux_create_usb_device(struct usb_device *udev, device_t dev) if (p_ui) { p_ui->altsetting = p_uhi - 1; p_ui->cur_altsetting = p_uhi - 1; - p_ui->num_altsetting = 1; p_ui->bsd_iface_index = iface_index; p_ui->linux_udev = udev; p_ui++; } iface_no_curr = iface_no; iface_index++; - } else { - if (p_ui) { - (p_ui - 1)->num_altsetting++; - } } break; diff --git a/sys/dev/usb/usb_device.c b/sys/dev/usb/usb_device.c index 0af33a3145ee..a502478fb4f5 100644 --- a/sys/dev/usb/usb_device.c +++ b/sys/dev/usb/usb_device.c @@ -1,6 +1,6 @@ /* $FreeBSD$ */ /*- - * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. + * Copyright (c) 2008-2020 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -898,6 +898,9 @@ usb_config_parse(struct usb_device *udev, uint8_t iface_index, uint8_t cmd) /* initialise interface */ do_init = 1; } + /* update number of alternate settings, if any */ + if (iface_index == USB_IFACE_INDEX_ANY) + iface->num_altsetting = ips.iface_index_alt + 1; } else do_init = 0; @@ -906,6 +909,7 @@ usb_config_parse(struct usb_device *udev, uint8_t iface_index, uint8_t cmd) /* update current number of endpoints */ ep_curr = ep_max; } + /* check for init */ if (do_init) { /* setup the USB interface structure */ diff --git a/sys/dev/usb/usb_request.c b/sys/dev/usb/usb_request.c index c6e43ec1e5a7..4ecd01df5877 100644 --- a/sys/dev/usb/usb_request.c +++ b/sys/dev/usb/usb_request.c @@ -2,7 +2,7 @@ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. * Copyright (c) 1998 Lennart Augustsson. All rights reserved. - * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. + * Copyright (c) 2008-2020 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -1433,6 +1433,7 @@ usbd_req_set_alt_interface_no(struct usb_device *udev, struct mtx *mtx, { struct usb_interface *iface = usbd_get_iface(udev, iface_index); struct usb_device_request req; + usb_error_t err; if ((iface == NULL) || (iface->idesc == NULL)) return (USB_ERR_INVAL); @@ -1444,7 +1445,17 @@ usbd_req_set_alt_interface_no(struct usb_device *udev, struct mtx *mtx, req.wIndex[0] = iface->idesc->bInterfaceNumber; req.wIndex[1] = 0; USETW(req.wLength, 0); - return (usbd_do_request(udev, mtx, &req, 0)); + err = usbd_do_request(udev, mtx, &req, 0); + if (err == USB_ERR_STALLED && iface->num_altsetting == 1) { + /* + * The USB specification chapter 9.4.10 says that USB + * devices having only one alternate setting are + * allowed to STALL this request. Ignore this failure. + */ + err = 0; + DPRINTF("Setting default alternate number failed. (ignored)\n"); + } + return (err); } /*------------------------------------------------------------------------* diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h index 5e8ba96f72f6..d43e751cb759 100644 --- a/sys/dev/usb/usbdi.h +++ b/sys/dev/usb/usbdi.h @@ -173,6 +173,9 @@ struct usb_endpoint { struct usb_interface { struct usb_interface_descriptor *idesc; device_t subdev; + /* Total number of alternate settings, from 1 to 256 */ + uint16_t num_altsetting; + /* Current alternate interface index, from 0 to 255 */ uint8_t alt_index; uint8_t parent_iface_index; @@ -182,7 +185,6 @@ struct usb_interface { struct usb_device *linux_udev; void *bsd_priv_sc; /* device specific information */ char *pnpinfo; /* additional PnP-info for this interface */ - uint8_t num_altsetting; /* number of alternate settings */ uint8_t bsd_iface_index; }; diff --git a/sys/sys/param.h b/sys/sys/param.h index 390255ade2de..1b52f24b2d6c 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1104510 /* Master, propagated to newvers */ +#define __FreeBSD_version 1104511 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,