From owner-svn-src-head@freebsd.org Tue Dec 15 12:05:08 2020 Return-Path: Delivered-To: svn-src-head@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 C37BA4B3E70; Tue, 15 Dec 2020 12:05:08 +0000 (UTC) (envelope-from hselasky@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 4CwH505Bzsz3mlt; Tue, 15 Dec 2020 12:05:08 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A0D76138BB; Tue, 15 Dec 2020 12:05:08 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0BFC58xq083034; Tue, 15 Dec 2020 12:05:08 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0BFC57bU083029; Tue, 15 Dec 2020 12:05:07 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202012151205.0BFC57bU083029@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 15 Dec 2020 12:05:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r368659 - in head/sys: compat/linuxkpi/common/src dev/usb sys X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in head/sys: compat/linuxkpi/common/src dev/usb sys X-SVN-Commit-Revision: 368659 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Dec 2020 12:05:08 -0000 Author: hselasky Date: Tue Dec 15 12:05:07 2020 New Revision: 368659 URL: https://svnweb.freebsd.org/changeset/base/368659 Log: 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 MFC after: 1 week Submitted by: Ma, Horse Sponsored by: Mellanox Technologies // NVIDIA Networking Modified: head/sys/compat/linuxkpi/common/src/linux_usb.c head/sys/dev/usb/usb_device.c head/sys/dev/usb/usb_request.c head/sys/dev/usb/usbdi.h head/sys/sys/param.h Modified: head/sys/compat/linuxkpi/common/src/linux_usb.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_usb.c Tue Dec 15 11:51:17 2020 (r368658) +++ head/sys/compat/linuxkpi/common/src/linux_usb.c Tue Dec 15 12:05:07 2020 (r368659) @@ -931,17 +931,12 @@ usb_linux_create_usb_device(struct usb_device *udev, d 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; Modified: head/sys/dev/usb/usb_device.c ============================================================================== --- head/sys/dev/usb/usb_device.c Tue Dec 15 11:51:17 2020 (r368658) +++ head/sys/dev/usb/usb_device.c Tue Dec 15 12:05:07 2020 (r368659) @@ -2,7 +2,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-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 @@ -905,6 +905,10 @@ usb_config_parse(struct usb_device *udev, uint8_t ifac /* update current number of endpoints */ ep_curr = ep_max; } + /* update number of alternate settings, if any */ + if (iface_index == USB_IFACE_INDEX_ANY) + iface->num_altsetting = ips.iface_index_alt + 1; + /* check for init */ if (do_init) { /* setup the USB interface structure */ Modified: head/sys/dev/usb/usb_request.c ============================================================================== --- head/sys/dev/usb/usb_request.c Tue Dec 15 11:51:17 2020 (r368658) +++ head/sys/dev/usb/usb_request.c Tue Dec 15 12:05:07 2020 (r368659) @@ -4,7 +4,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 @@ -1436,6 +1436,7 @@ usbd_req_set_alt_interface_no(struct usb_device *udev, { 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); @@ -1447,7 +1448,17 @@ usbd_req_set_alt_interface_no(struct usb_device *udev, 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); } /*------------------------------------------------------------------------* Modified: head/sys/dev/usb/usbdi.h ============================================================================== --- head/sys/dev/usb/usbdi.h Tue Dec 15 11:51:17 2020 (r368658) +++ head/sys/dev/usb/usbdi.h Tue Dec 15 12:05:07 2020 (r368659) @@ -174,6 +174,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; @@ -183,7 +186,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; }; Modified: head/sys/sys/param.h ============================================================================== --- head/sys/sys/param.h Tue Dec 15 11:51:17 2020 (r368658) +++ head/sys/sys/param.h Tue Dec 15 12:05:07 2020 (r368659) @@ -60,7 +60,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1300131 /* Master, propagated to newvers */ +#define __FreeBSD_version 1300132 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,