From patchwork Thu Sep 13 09:21:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10599069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A1A514E5 for ; Thu, 13 Sep 2018 09:22:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68F672A936 for ; Thu, 13 Sep 2018 09:22:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CD0C2A93C; Thu, 13 Sep 2018 09:22:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7CB82A936 for ; Thu, 13 Sep 2018 09:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726821AbeIMOam (ORCPT ); Thu, 13 Sep 2018 10:30:42 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:46374 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbeIMOam (ORCPT ); Thu, 13 Sep 2018 10:30:42 -0400 Received: by mail-lj1-f196.google.com with SMTP id 203-v6so3992488ljj.13; Thu, 13 Sep 2018 02:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NvyjQMihlUHdoi57V5s5noOvDcWJQCxt1PQLEaYWtY4=; b=uFgei6WYWCBvEkcQtVweGI0aitdAe5azgluUXyyGcsb1/HlCD99vwTl5DyYWaq2DRQ zAoUUA3Jo7RDb5J2aD2UF+l4qN+Zw1KKd0WiZ5+V1GNsYETrTaoM3/15rWJG0AKuFMrB 4T44J/pCqIDsphbE2x8XVIKxUrMEahyGRGUL+uql9verBBH9iWcbsOjyM5Bf/cZOKsU2 sU3mN2FBWzsT7AcgJNd0etHOhygzwn9SyJBzBm7uPGXC2/gDXdGN0tfYpSNt8wEeb9HT wZ4apRf3MFOdwC0z4XoZ02M37Zt7rABt7wF5oRGlgIqKJO5mDFSq9PasxX1ReBhCroef gc5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NvyjQMihlUHdoi57V5s5noOvDcWJQCxt1PQLEaYWtY4=; b=OcV8ka5ETdZkGnegngR9hHEdVtpLwYd3ZwbPd6NtQWLlq0PhOwiQpaW/Ll+I+gqrtC up6wVEPnVY3PcQdUKNizWLYz43KdT/5IgOG8KtaE49oGhRpUrHk1Kd4jlZXhxun8DD+x g6UQ/TVPUlEhzMRHbO06RSsdlJUNdOC42ICctsokSmTBpi0iR1N7r0MTZexm7xegSzJV s8OV7S3/kaFG/6ZOVRWMrpcCqnHIVhlLgQAHHkQxubRkRBwXgvzwRZ68C64XeP3eXZJJ TdBBkg+XgiayF2u2BNrohmAvCt4EnNGxoxP3lhw504Dr9Fzrf0wdrbfreRicmlab5yNi GzOQ== X-Gm-Message-State: APzg51B/nA+VIsjrObankItPyts56JTBcNNljeSJ5sJw74P7LW7uKZMR w7SZZ93fkMA48Ukfo0FyR54= X-Google-Smtp-Source: ANB0Vdasamz84fHVn4cizh9CFNDuPxuKhuKGuujbRjSu8iPlLBxPbfGbekHA0KxgV//LpGjHAyv8eQ== X-Received: by 2002:a2e:947:: with SMTP id 68-v6mr3766863ljj.1.1536830521359; Thu, 13 Sep 2018 02:22:01 -0700 (PDT) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id m11-v6sm604363lfk.70.2018.09.13.02.22.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Sep 2018 02:22:00 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1g0Np3-0000DA-Fv; Thu, 13 Sep 2018 11:22:01 +0200 From: Johan Hovold To: Kristian Evensen Cc: linux-usb@vger.kernel.org, =?utf-8?q?Bj=C3=B8rn_Mork?= , Dan Williams , Lars Melin , linux-kernel@vger.kernel.org, stable , Johan Hovold Subject: [PATCH 1/2] USB: serial: option: improve Quectel EP06 detection Date: Thu, 13 Sep 2018 11:21:49 +0200 Message-Id: <20180913092152.770-1-johan@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913091753.GA3443@localhost> References: <20180913091753.GA3443@localhost> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kristian Evensen The Quectel EP06 (and EM06/EG06) LTE modem supports updating the USB configuration, without the VID/PID or configuration number changing. When the configuration is updated and interfaces are added/removed, the interface numbers are updated. This causes our current code for matching EP06 not to work as intended, as the assumption about reserved interfaces no longer holds. If for example the diagnostic (first) interface is removed, option will (try to) bind to the QMI interface. This patch improves EP06 detection by replacing the current match with two matches, and those matches check class, subclass and protocol as well as VID and PID. The diag interface exports class, subclass and protocol as 0xff. For the other serial interfaces, class is 0xff and subclass and protocol are both 0x0. The modem can export the following devices and always in this order: diag, nmea, at, ppp. qmi and adb. This means that diag can only ever be interface 0, and interface numbers 1-5 should be marked as reserved. The three other serial devices can have interface numbers 0-3, but I have not marked any interfaces as reserved. The reason is that the serial devices are the only interfaces exported by the device where subclass and protocol is 0x0. QMI exports the same class, subclass and protocol values as the diag interface. However, the two interfaces have different number of endpoints, QMI has three and diag two. I have added a check for number of interfaces if VID/PID matches the EP06, and we ignore the device if number of interfaces equals three (and subclass is set). Signed-off-by: Kristian Evensen Acked-by: Dan Williams [ johan: drop uneeded RSVD(5) for ADB ] Cc: stable Signed-off-by: Johan Hovold --- drivers/usb/serial/option.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 0215b70c4efc..382feafbd127 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c @@ -1081,8 +1081,9 @@ static const struct usb_device_id option_ids[] = { .driver_info = RSVD(4) }, { USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_BG96), .driver_info = RSVD(4) }, - { USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06), - .driver_info = RSVD(4) | RSVD(5) }, + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0xff, 0xff), + .driver_info = RSVD(1) | RSVD(2) | RSVD(3) | RSVD(4) }, + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0, 0) }, { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6001) }, { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CMU_300) }, { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6003), @@ -1985,6 +1986,7 @@ static int option_probe(struct usb_serial *serial, { struct usb_interface_descriptor *iface_desc = &serial->interface->cur_altsetting->desc; + struct usb_device_descriptor *dev_desc = &serial->dev->descriptor; unsigned long device_flags = id->driver_info; /* Never bind to the CD-Rom emulation interface */ @@ -1999,6 +2001,18 @@ static int option_probe(struct usb_serial *serial, if (device_flags & RSVD(iface_desc->bInterfaceNumber)) return -ENODEV; + /* + * Don't bind to the QMI device of the Quectel EP06/EG06/EM06. Class, + * subclass and protocol is 0xff for both the diagnostic port and the + * QMI interface, but the diagnostic port only has two endpoints (QMI + * has three). + */ + if (dev_desc->idVendor == cpu_to_le16(QUECTEL_VENDOR_ID) && + dev_desc->idProduct == cpu_to_le16(QUECTEL_PRODUCT_EP06) && + iface_desc->bInterfaceSubClass && iface_desc->bNumEndpoints == 3) { + return -ENODEV; + } + /* Store the device flags so we can use them during attach. */ usb_set_serial_data(serial, (void *)device_flags); From patchwork Thu Sep 13 09:21:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10599067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C46514E0 for ; Thu, 13 Sep 2018 09:22:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 595CA2A936 for ; Thu, 13 Sep 2018 09:22:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B84E2A93C; Thu, 13 Sep 2018 09:22:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D91562A936 for ; Thu, 13 Sep 2018 09:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727709AbeIMOaq (ORCPT ); Thu, 13 Sep 2018 10:30:46 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33208 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbeIMOap (ORCPT ); Thu, 13 Sep 2018 10:30:45 -0400 Received: by mail-lj1-f196.google.com with SMTP id s12-v6so4032000ljj.0; Thu, 13 Sep 2018 02:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WrpPmSf/Ir/AP2WGlMpgLdi04RIUiS4FuIpJJIM8Qcw=; b=gTzTTB6+HtkgjgS5YAIxcP8oN3ofdc6yeHk+Xw853yXm+lzLPy4MYo6ULvP5wmnBem Txof5CPTsntbGU5zbLiK2giLmukv2Wcfw9bnh8g2MNPHqL0YfS0gJhR101UknijzzMr6 jr6gEWSURWLH/Fao1uataEnv8jDEyuKqZSUxs4GZZ5QvLTFKSquBQkq5qqJ8PagFWzQ5 7vr+R9jiqfZKcCPJJ0WSu1WAoAJ98XwSLUbu7bbjkOfFgYTqWQBK6cqjhsiQhGEViiXr bPGq9FkjqsM29VIqBt3ciapr9EMNzHuRkbkK4Q5lDFuDfL680VxjZHZyWvk8vCD4KJYY Cb6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=WrpPmSf/Ir/AP2WGlMpgLdi04RIUiS4FuIpJJIM8Qcw=; b=VNILyuaulMtynot+QJjOJ0ZQTQHz7RIuIU6Fv6yqazs4WlxUF7yQcyfubl+MCmALSo e2Qx4XbnOxnpHqjUINTCIHfhHOKsECl/5hQQuOgJTfcb4yEdFEfsHl4hKJuhekndpcjd H897pS2/tT8eK59AL4NVNqAlSy90q8CP3lFvZ7MMZNaBtetSHL1mOTQf5fndu411Oyu4 2EoiaQVBEyheGg3hwIeDVrhxlachZhLwaisnzcbFpDFZESMifWmF0tELh43qZwrZ9n9Z qfcu1jkjzz8/og4cyxxHeGGuRwRiN5TpfH2D55hjiBGgOqslOJDEKgu5OA64UJgf7Axi qQNA== X-Gm-Message-State: APzg51AuFh4ngS+qKU4Yz4dxzKhGqRhPHr7xQBA3pWnNrkqyHYcaqRGF u4zz1nLGmb+wgCWt7yGYN3SUiPHs X-Google-Smtp-Source: ANB0VdapW6g5V2tGTcLU4RJ6qXrOKkBwm/aHmMeYzzu5GQ5bs03YhYKOaXuiZjSp/rdIxD5CFhF3XQ== X-Received: by 2002:a2e:291c:: with SMTP id u28-v6mr3834798lje.70.1536830525308; Thu, 13 Sep 2018 02:22:05 -0700 (PDT) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id q85-v6sm628461lfg.20.2018.09.13.02.22.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Sep 2018 02:22:04 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1g0Np7-0000DH-Ej; Thu, 13 Sep 2018 11:22:05 +0200 From: Johan Hovold To: Kristian Evensen Cc: linux-usb@vger.kernel.org, =?utf-8?q?Bj=C3=B8rn_Mork?= , Dan Williams , Lars Melin , linux-kernel@vger.kernel.org, Johan Hovold , stable Subject: [PATCH 2/2] USB: serial: option: add two-endpoints device-id flag Date: Thu, 13 Sep 2018 11:21:50 +0200 Message-Id: <20180913092152.770-2-johan@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913092152.770-1-johan@kernel.org> References: <20180913091753.GA3443@localhost> <20180913092152.770-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow matching on interfaces having two endpoints by adding a new device-id flag. This allows for the handling of devices whose interface numbers can change (e.g. Quectel EP06) to be contained in the device-id table. Cc: stable Signed-off-by: Johan Hovold --- drivers/usb/serial/option.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 382feafbd127..241a73e172a1 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c @@ -561,6 +561,9 @@ static void option_instat_callback(struct urb *urb); /* Interface is reserved */ #define RSVD(ifnum) ((BIT(ifnum) & 0xff) << 0) +/* Interface must have two endpoints */ +#define NUMEP2 BIT(16) + static const struct usb_device_id option_ids[] = { { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) }, @@ -1082,7 +1085,7 @@ static const struct usb_device_id option_ids[] = { { USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_BG96), .driver_info = RSVD(4) }, { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0xff, 0xff), - .driver_info = RSVD(1) | RSVD(2) | RSVD(3) | RSVD(4) }, + .driver_info = RSVD(1) | RSVD(2) | RSVD(3) | RSVD(4) | NUMEP2 }, { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0, 0) }, { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6001) }, { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CMU_300) }, @@ -1986,7 +1989,6 @@ static int option_probe(struct usb_serial *serial, { struct usb_interface_descriptor *iface_desc = &serial->interface->cur_altsetting->desc; - struct usb_device_descriptor *dev_desc = &serial->dev->descriptor; unsigned long device_flags = id->driver_info; /* Never bind to the CD-Rom emulation interface */ @@ -2002,16 +2004,11 @@ static int option_probe(struct usb_serial *serial, return -ENODEV; /* - * Don't bind to the QMI device of the Quectel EP06/EG06/EM06. Class, - * subclass and protocol is 0xff for both the diagnostic port and the - * QMI interface, but the diagnostic port only has two endpoints (QMI - * has three). + * Allow matching on bNumEndpoints for devices whose interface numbers + * change (e.g. Quectel EP06). */ - if (dev_desc->idVendor == cpu_to_le16(QUECTEL_VENDOR_ID) && - dev_desc->idProduct == cpu_to_le16(QUECTEL_PRODUCT_EP06) && - iface_desc->bInterfaceSubClass && iface_desc->bNumEndpoints == 3) { + if (device_flags & NUMEP2 && iface_desc->bNumEndpoints != 2) return -ENODEV; - } /* Store the device flags so we can use them during attach. */ usb_set_serial_data(serial, (void *)device_flags);