From owner-freebsd-hackers@freebsd.org Fri Jul 17 20:14:35 2020 Return-Path: Delivered-To: freebsd-hackers@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 3D34236DC17 for ; Fri, 17 Jul 2020 20:14:35 +0000 (UTC) (envelope-from bmcgover@cisco.com) Received: from rcdn-iport-6.cisco.com (rcdn-iport-6.cisco.com [173.37.86.77]) (using TLSv1.2 with cipher DHE-RSA-SEED-SHA (128/128 bits)) (Client CN "iport.cisco.com", Issuer "HydrantID SSL ICA G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B7j5N70v3z4TZT; Fri, 17 Jul 2020 20:14:32 +0000 (UTC) (envelope-from bmcgover@cisco.com) IronPort-PHdr: =?us-ascii?q?9a23=3AWEUY/RHPdNNOAONMMEDXMp1GYnJ96bzpIg4Y7I?= =?us-ascii?q?YmgLtSc6Oluo7vJ1Hb+e401Q+bc5/W5th/p6zRqa+zEWAD4JPUtncEfdQMUh?= =?us-ascii?q?IekswZkkQmB9LNEkz0KvPmLklYVMRPXVNo5Te3ZE5SHsutSUffr1eJwXgVAB?= =?us-ascii?q?qsfQZwL/7+T4jVicn/3uuu+prVNgNPgjf1Yb57IBis6wvLscxDiop5IaF3wR?= =?us-ascii?q?zM8XY=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DeAQAoBRJf/4sNJK1dAxYFAQEBAQE?= =?us-ascii?q?BAQEFAQEBEgEBAQMDAQEBQIFKgSMvIwYoBxEBXVgvLId5A41Gk3KEbIJTA1U?= =?us-ascii?q?LAQEBDAEBGAEKCgIEAQGECEQCghkCJDgTAgMBAQsBAQUBAQECAQYEbYVbDIV?= =?us-ascii?q?vAQEBBAEBEBUZAQEMIAsBEQEIEQQBAQFVAQkBHQoEAQcGAQQBBxUEAYMFgX5?= =?us-ascii?q?NAy4BDp9VAoE5iGF0gQEzgwEBAQWBMgGDVxiCDgMGgTgBgmmDSAKGPhqBQT+?= =?us-ascii?q?BEUOBT34+glwBBIEUJgEBAiAfDBqDAoItj2qJOCaBFZpgCoJdiFaGNIQghli?= =?us-ascii?q?fQ5F9iieUVgIEAgQFAg4BAQWBaiOBV3AVO4JpUBcCDY4eDBeBAgEIgkOFFIV?= =?us-ascii?q?CdBEmAgYIAQEDCXyMQYI1AQE?= X-IronPort-AV: E=Sophos;i="5.75,364,1589241600"; d="scan'208,217";a="801256865" Received: from alln-core-6.cisco.com ([173.36.13.139]) by rcdn-iport-6.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 17 Jul 2020 20:14:29 +0000 Received: from XCH-ALN-004.cisco.com (xch-aln-004.cisco.com [173.36.7.14]) by alln-core-6.cisco.com (8.15.2/8.15.2) with ESMTPS id 06HKETi4031364 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=FAIL); Fri, 17 Jul 2020 20:14:29 GMT Received: from xhs-rtp-002.cisco.com (64.101.210.229) by XCH-ALN-004.cisco.com (173.36.7.14) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Jul 2020 15:14:28 -0500 Received: from xhs-aln-003.cisco.com (173.37.135.120) by xhs-rtp-002.cisco.com (64.101.210.229) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 17 Jul 2020 16:14:27 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (173.37.151.57) by xhs-aln-003.cisco.com (173.37.135.120) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Fri, 17 Jul 2020 15:14:27 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n6o6SR/0h2ZINFg/A02Zk+AeKLnartGZ08WsbtBh8c6U+Fdk20duaLA1w8JK+jxpgS9sZFBTuhHdMkEMcd/VRtswkx7sTTGpOYOtaI0+8649UjYRh3WdIeKpJ3Glmk7IC+b0mRm7e0QUwp59BkoU6s6SvbKfVp+zuSK+uPtZG5zclZOTwmStL8LAo9Dqe5BMtVOO4PkUy4UntwC+eTp16bTyoGK9V0OaRAHKhC+IxYeppA0x5BMFI04et5P1pPevo0bE05PJxtC7dsULLA8dJB1Y70PFlMUAZsQt9Z1NFz8SyjVQbvyl+OB2jb58fx4ZwdXS3bHP4Xff647QsYD57Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F2DrNWo9sNAihfA/ZWW+syhi1U2bKKxXSz55H1ip9t8=; b=a+CLriKAPNGWzyE59op9XDhdYVR4/A99niXCvCJsOFkb1whI46ZFUHRcwceB3mHN2nEkRR8FtjbGALW1EwZkaCuslnzQLtyaZA2yYndlbos/tcSxhSCibf1yXBTB16QTtVWX9GKDY2XNBiOwNrpurydMJLq9crMDxdpkwhUpAiLBTP1YsyL5hyihNPa1K4NZn7nbNXMcUeuzg6/4og3tqO5+6zKDeFKJrp5l04KKLNuHmT/U9b4H/OYXNfqN2rRyrVjzBz4q6NA1vQyc85GDVO651ppnJh4JPkKj1p2I0/9HjKeg51E9vTgWWpy3g4uvEQ+T3VRx98EE77lFzw47RQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cisco.com; dmarc=pass action=none header.from=cisco.com; dkim=pass header.d=cisco.com; arc=none Received: from BL0PR11MB3442.namprd11.prod.outlook.com (2603:10b6:208:68::19) by MN2PR11MB4173.namprd11.prod.outlook.com (2603:10b6:208:137::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Fri, 17 Jul 2020 20:14:26 +0000 Received: from BL0PR11MB3442.namprd11.prod.outlook.com ([fe80::844f:50d2:7986:e539]) by BL0PR11MB3442.namprd11.prod.outlook.com ([fe80::844f:50d2:7986:e539%7]) with mapi id 15.20.3174.026; Fri, 17 Jul 2020 20:14:26 +0000 From: "Brian Mcgovern (bmcgover)" To: Daniel Ebdrup Jensen , "freebsd-hackers@freebsd.org" , John-Mark Gurney CC: Ian Lepore , Hans Petter Selasky Subject: Re: Question on structure of USB (specifically USB Serial) stack Thread-Topic: Question on structure of USB (specifically USB Serial) stack Thread-Index: AQHWXHYS3z0wT4II5U+lFc6NpNfYIQ== Date: Fri, 17 Jul 2020 20:14:26 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [2601:18c:d07f:d140:547b:bff9:d6a8:7b19] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 77505eaa-ce04-43be-199e-08d82a8e014e x-ms-traffictypediagnostic: MN2PR11MB4173: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: zuECJAyPeMXiCheov1SxMUlgczCC3VtvnDZq2TWbbfim/a7I7tT9Tx6+hxM9u/dlT8qbTn0g0cTQBSjS0H882fFVGYN03gkdBYhI0/4vxWp7KcV0ExS2VZdJh4B1VnOIp2q/0r6tMbpuZ1GjGN+9BhT0uS8DwEwDbaCMTzWUP0YMBJwvKWEvX0JdrvzyGlYF+XBy1QLFMWhF0kpW3Rai89RXb5JNzLoTxlQHGBAKbl87m8G4xqrIKJdszr2eMQvkMItmVy+BBDU78dsVRSFNDT8oCpOXHsoeQ4gddxfhjuT6watDwX/ECEoa/lhEJQoWHt1eYQypByoLin90g2Muged8ZzaE1ZachPWrkPZir9bCwJUMLABeBFcoavctJuuF5dYP+CmJp1Sl2fFA9r/gzg== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR11MB3442.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(396003)(39860400002)(366004)(136003)(346002)(376002)(66446008)(64756008)(66556008)(66946007)(66476007)(5660300002)(53546011)(6506007)(110136005)(76116006)(2906002)(186003)(52536014)(7696005)(4326008)(19627405001)(478600001)(966005)(71200400001)(33656002)(166002)(55016002)(9686003)(316002)(54906003)(86362001)(83380400001)(8676002)(8936002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: AeCQZ9izIfoHtIA/4QLrkMnrVDUr+mHPtzivURPrWIerzDMkFu3PY4GTWh79uQNkyhCLqh16QACccoPQlNIXrdtCnd2bcrJoRr6EdRbMuSgwAiw/2qAov+2tFn8yjgLlCL0vFjYGw+E/Y3GgfRVFZV/6Ui7FFNzdgGjWA5K/8rcEEd7yYVtVhOaF/3YXChvrWH7FaroWELozOgF8gaLHBV/+MEv99FFLxnwLzBKJAubsvSBrPpUb7yIZSZLU+zDY08zNntqKQb3kyue151gF+YfUKtVpPnkd4gSzt9N+zERy2seNbJKnqoAVPU53LnkzPsrwkLAKCZbgFdczP9xnzrtkZWvrifBYz9/XVopxG5DEI2slzkcVWOAgJdvWSVJyfKrB2aeuCbN5rJGRgOgBCIOHKOB1xGiKXEqkUHP9B//fNnszf+Kvh8wUlTQCXpMRTbqWEGNkrejYJRX+82BkiEzF4Mg6xH77RvK105JMU1C0ORPU78OZJmzAoPO6hEGQ/PCs3Yq34mPDhKmckN2jfTGCL47to5zEwqerRPNCX5b5hefrAg+RDn7wyqyILAJE x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BL0PR11MB3442.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77505eaa-ce04-43be-199e-08d82a8e014e X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jul 2020 20:14:26.6582 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5ae1af62-9505-4097-a69a-c1553ef7840e X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: EMg9wfEOA8ndEg1avY1nrk2kxecpjZKMDVD/X84bD1iaLIIXr242AtY8dGSk1AfkzQKDkXpQtepEkNMykqvBgw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4173 X-OriginatorOrg: cisco.com X-Outbound-SMTP-Client: 173.36.7.14, xch-aln-004.cisco.com X-Outbound-Node: alln-core-6.cisco.com X-Rspamd-Queue-Id: 4B7j5N70v3z4TZT X-Spamd-Bar: ----------- X-Spamd-Result: default: False [-11.27 / 15.00]; TO_DN_EQ_ADDR_SOME(0.00)[]; HAS_XOIP(0.00)[]; TO_DN_SOME(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[173.37.86.77:from]; R_SPF_ALLOW(-0.20)[+ip4:173.37.86.0/24]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_TRACE(0.00)[cisco.com:+,cisco.onmicrosoft.com:+]; DMARC_POLICY_ALLOW(-0.50)[cisco.com,quarantine]; NEURAL_HAM_SHORT(-1.72)[-1.718]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_TLS_LAST(0.00)[]; ARC_ALLOW(-1.00)[microsoft.com:s=arcselector9901:i=1]; ASN(0.00)[asn:109, ipnet:173.37.64.0/18, country:US]; FAKE_REPLY(1.00)[]; NEURAL_HAM_MEDIUM(-1.03)[-1.033]; R_DKIM_ALLOW(-0.20)[cisco.com:s=iport,cisco.onmicrosoft.com:s=selector2-cisco-onmicrosoft-com]; RCVD_DKIM_ARC_DNSWL_HI(-1.00)[]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_MED(-2.00)[cisco.com:dkim]; NEURAL_HAM_LONG(-1.02)[-1.024]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; TO_MATCH_ENVRCPT_SOME(0.00)[]; WHITELIST_SPF_DKIM(-3.00)[cisco.com:d:+,cisco.com:s:+]; RCVD_IN_DNSWL_HI(-0.50)[173.37.86.77:from]; RCVD_COUNT_SEVEN(0.00)[8] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.33 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2020 20:14:35 -0000 I installed both. The script looks like its working, the patch, not quite. = To explain, I did a quick log with the script to print out $1-$4. What I'm seeing in the log is this.... attach uftdi0 A9L5QT3S U384 attach uftdi1 A978RDEY U384 attach utfdi2 A9LITAWI U384 It appears the drivers are mapping all of the USB devices to /dev/cuaU384 a= nd friends. I am seeing appropriate entities in /dev/usb - e.g. I'm getting= 0.4.[0-2], 0.5.[0-2], and 0.6.[0-2]. This might be due to me not reverting= all my own changes back, so to be sure, I'm going to grab clean source and= reapply the patch, but I thought I'd mention it. Good to know there is suc= cess elsewhere. -B ________________________________ From: Daniel Ebdrup Jensen Sent: Friday, July 17, 2020 2:45 PM To: freebsd-hackers@freebsd.org Cc: Brian Mcgovern (bmcgover); Ian Lepore; Hans Petter Selasky Subject: Re: Question on structure of USB (specifically USB Serial) stack On Fri, Jul 17, 2020 at 11:30:34AM -0700, John-Mark Gurney wrote: >Brian Mcgovern (bmcgover) wrote this message on Fri, Jul 17, 2020 at 14:06= +0000: >> John-Mark Gurney said >> >> Look here: >> https://reviews.freebsd.org/D21886 >> >> I've added a script, linked here: >> https://www.funkthat.com/~jmg/FreeBSD/usbserialsn >> >> There are two modes, if the device has a serial number, that will be >> used. If the device has an empty serial number, it's usb bus and port >> number path will be used. >> >> Thank you. I'll take a look at the patch and script today. From a quick = once over, it looks like it'll meet my needs - pretty much keeping the devi= ce names unique and identifiable during reboots and detach/reattach events.= If I see any issues, I'll let you know. > >Just for clarification, the script does not require the patch to be >applied. That patch in the review was a separate effort. > >The script should likely work on past FreeBSD releases as well, but >I haven't tested it on them. > I'm using it on 12.1-RELEASE, and it works fine there. :) >> ________________________________ >> From: John-Mark Gurney >> Sent: Thursday, July 16, 2020 8:18 PM >> To: Brian Mcgovern (bmcgover) >> Cc: Ian Lepore ; Hans Petter Selasky ;= freebsd-hackers@freebsd.org >> Subject: Re: Question on structure of USB (specifically USB Serial) stac= k >> >> FreeBSD Hackers wrote this message on Thu, Jul 16, 2020 at 23:18 +0000: >> > Ian Lepore said: >> > >> > This seems to me to be one of those situations where answering the >> > exact question that was asked isn't the right thing to do. Instead it >> > needs to be answered with another question: What it is you're really >> > trying to accomplish, and why do you think doing this crazy-unsafe >> > casting is the only way to get it done? >> > >> > I get its crazy unsafe for the non-specific case. That is why I'm aski= ng the question - to see if there is a good way to get the info. >> > >> > What I'm hoping to do is pin some USB devices with FTDI interfaces to = more consistent name, similar to /dev/usb, based on the tree of struct usb_= device entries and their respective addresses. What I see with the cuaUXX f= ormatting is that if one gets rebooted or someone hits the power cord, it'l= l bounce fast enough that it'll come back with a different name. As a resul= t, even though we can get a consistent layout on power up, if you come back= a week or two later, everything is out of order. I was hoping that if I co= uld at least get an alias that mapped to the port the device was in, that w= ould be sufficient to find the "right one", regardless of what the cuaUX na= mes were doing. >> > >> > The reason for picking this particular section of the code is that it = appears I can get most of the work done locally and have similar behavior w= ith all of the devices that share ucom. However, if what I'm seeing as a hu= rdle is really a wall, I'm open to better ideas. >> >> Look here: >> https://reviews.freebsd.org/D21886 >> >> I've added a script, linked here: >> https://www.funkthat.com/~jmg/FreeBSD/usbserialsn >> >> There are two modes, if the device has a serial number, that will be >> used. If the device has an empty serial number, it's usb bus and port >> number path will be used. >> >> > Sent: Thursday, July 16, 2020 6:32 PM >> > To: Hans Petter Selasky ; Brian Mcgovern (bmcgover) <= bmcgover@cisco.com>; freebsd-hackers@freebsd.org >> > Subject: Re: Question on structure of USB (specifically USB Serial) st= ack >> > >> > On Thu, 2020-07-16 at 23:21 +0200, Hans Petter Selasky wrote: >> > > On 2020-07-16 22:20, Brian Mcgovern (bmcgover) via freebsd-hackers >> > > wrote: >> > > > All, >> > > > I'm doing some playing with the ucom code, and I'm down to a >> > > > link in the data that I'm just not confident I've parsed the code >> > > > correctly. In sys/dev/usb/serial/usb_serial.c, specifically in >> > > > ucom_attach_tty, I'm trying to get a reference to the usb_device >> > > > structure for the device used elsewhere in the USB code. The >> > > > specific devices I'm working with are USB->RJ 45 cables with a >> > > > built in FTDI chip, in case this matters >> > > > >> > > > It appears that the ucom_super_softc and ucom_softc structures >> > > > are available. From looking around the code, it appears the >> > > > sc_parent field of ucom_softc is pointing back to the uftdi_softc >> > > > structure in uftdi.c (for the uftdi case), so the path would be >> > > > ucom_softc->sc_parent->sc_udev, but my concern is going through th= e >> > > > void *, as it appears each of the devices that use ucom as the bas= e >> > > > have sc_udev in a different part of their structure, meaning I'm >> > > > likely going to crash the system if I plan on it being an FTDI >> > > > device, and its not. Is there a callback or a canonical mechanism >> > > > for accessing this part of the structure given a starting point of >> > > > the ucom_softc? Alternatively, are there any well defined >> > > > attributes I can use to figure out what that void* is pointing to, >> > > > or at least conditionalizing the code so I can dereference it >> > > > correctly? >> > > >> > > Hi, >> > > >> > > Usually using void pointers this way works fine, as long as you are >> > > careful. There is also something called __containerof() which can be >> > > used to get the pointer to a structure based on the pointer to a >> > > structure inside that structure, thinking of the struct ucom_softc, >> > > which is type-safe. >> > > >> > > >> > >> > You still can't just blindly cast ucom_softc->sc_parent back to a >> > struct uftdi_softc in ucom_tty_attach() because it will crash and burn >> > if any non-ftdi serial device is attached. Using __container_of() >> > doesn't change that in any way -- you must already know for certain >> > that the type pointed to by the pointer is the type you name in the >> > container_of() invocation. >> > >> > This seems to me to be one of those situations where answering the >> > exact question that was asked isn't the right thing to do. Instead it >> > needs to be answered with another question: What it is you're really >> > trying to accomplish, and why do you think doing this crazy-unsafe >> > casting is the only way to get it done? > >-- > John-Mark Gurney Voice: +1 415 225 5579 > > "All that I will do, has been done, All that I have, has not." >_______________________________________________ >freebsd-hackers@freebsd.org mailing list >https://lists.freebsd.org/mailman/listinfo/freebsd-hackers >To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"