From nobody Tue Apr 26 17:24:24 2022 X-Original-To: freebsd-usb@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A109A1AB0710 for ; Tue, 26 Apr 2022 17:24:28 +0000 (UTC) (envelope-from farhan@farhan.codes) Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4Knpf33NT0z3C5l for ; Tue, 26 Apr 2022 17:24:27 +0000 (UTC) (envelope-from farhan@farhan.codes) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id D51CA3200981; Tue, 26 Apr 2022 13:24:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 26 Apr 2022 13:24:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=farhan.codes; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1650993865; x= 1651080265; bh=/JzzZOIVPvWPUoecusJjM9eSr7uKa302PhiGd8qWN5c=; b=j +hTPWVM4muMbZOun6jtuNhhjJYURpNk39CUlKUal6bVEwRly4Cs2c2GlzJbVdB3J 1EWTcJXLF3S+C5/NzCtQWvX69HKaJXsfdHnHDIgWuabIWHPwtN0LOA7Q1Xsl3p7v KnWmCIFEPG8ekFhCXiZ1wxVeU9nUwKBckICynHlO16CFXgm6pDpBjfV4xa/zpW5G w46MxmXeBTjKXipg71lMYeu3o3JMPb7XVoWtj2c/acR2JdZnB4DUfKg4bRXK87yc ++AxZzv3f4E48yfg6m9P/P1sy5KSVY5m5+9ypJowL/Vo9pNKdoKwrIjOQJCO0p1y XxDjmrrXIZqQ0Yn/p5BUA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1650993865; x=1651080265; bh=/JzzZOIVPvWPUoecusJjM9eSr7uK a302PhiGd8qWN5c=; b=gvcFD5mVhqg5JkSQRCGFhZlc/wPHwtAJdTM44k1kyWWu 9txkqoTgjW1DYg2g/pIpJ6IpPmF73uq0Zoqmj9qCG3uKyxUGq/kmd8L6VwApUV9L b2pg+DhUMAVYqN6W8bm4fNyoymxc3wIUwiuyVGeFKsZ/5tlNCfWcpQ8heQNaaBhX 3Htc9Qh4lY400LnFUs+NJ2r2OSrzeTYxdZss7WogB4TsO4702zsLMFR1f4tTs1Wg 5fklocFlGIoAmhDnZ2YLP7i6OJtmFXI3KkZA4D/jxc+iHkxxi0Az1PUhoBXJ8hEa +wjcteoJDtg38WT+A4H+yecEypFE0yexv6v+Ylffew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudefgddutdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkjghfggfgtgesthfure dttddtvdenucfhrhhomhephfgrrhhhrghnucfmhhgrnhcuoehfrghrhhgrnhesfhgrrhhh rghnrdgtohguvghsqeenucggtffrrghtthgvrhhnpeekudefgfdvleejteduhfdtfffhie euteelvdettdehhfekhfdtfeeuffehhfetfeenucffohhmrghinhepghhithhhuhgsrdgt ohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepfh grrhhhrghnsehfrghrhhgrnhdrtghouggvsh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Apr 2022 13:24:24 -0400 (EDT) From: Farhan Khan To: Hans Petter Selasky , freebsd-usb@freebsd.org Subject: Re: Trouble loading firmware to USB device Date: Tue, 26 Apr 2022 13:24:24 -0400 Message-ID: <2824644.e9J7NaK4W3@fedora> In-Reply-To: <8a94c6c0-3188-4a48-29bb-0511a6dcd7e1@selasky.org> References: <10080928.nUPlyArG6x@fedora> <8a94c6c0-3188-4a48-29bb-0511a6dcd7e1@selasky.org> List-Id: FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-usb List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-usb@freebsd.org X-BeenThere: freebsd-usb@freebsd.org MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Rspamd-Queue-Id: 4Knpf33NT0z3C5l X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=farhan.codes header.s=fm2 header.b="j +hTPWV"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=gvcFD5mV; dmarc=none; spf=pass (mx1.freebsd.org: domain of farhan@farhan.codes designates 64.147.123.24 as permitted sender) smtp.mailfrom=farhan@farhan.codes X-Spamd-Result: default: False [-3.60 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[farhan.codes:s=fm2,messagingengine.com:s=fm1]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:64.147.123.24]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MID_RHS_NOT_FQDN(0.50)[]; DMARC_NA(0.00)[farhan.codes]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; RCVD_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[farhan.codes:+,messagingengine.com:+]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-1.00)[-0.996]; MLMMJ_DEST(0.00)[freebsd-usb]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; CTE_CASE(0.50)[]; ASN(0.00)[asn:29838, ipnet:64.147.123.0/24, country:US]; RCVD_TLS_LAST(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[64.147.123.24:from] X-ThisMailContainsUnwantedMimeParts: N I mistakenly emailed Hans directly rather than copying the email list. Sorry, switched email clients :/ Keeping the full exchange below for one email round. On Tuesday, April 26, 2022 3:01:44 AM EDT you wrote: > On 4/26/22 07:42, Farhan Khan wrote: > > On Monday, April 25, 2022 4:21:04 AM EDT you wrote: > >> Hi, > >> > >>> status 0xeb023 > >>> >>> MA > >>> _SET|CAN_CANCEL_IMMED|DOING_CALLBACK|0>> > >>> > >>> 12:25:07.785438 usbus3.3 > >>> SUBM-INTR-EP=00000083,SPD=HIGH,NFR=1,SLEN=0,IVAL=1 > >>> > >>> frame[0] READ 1024 bytes > >>> flags 0xa > >> > >> You are asking for 1024 bytes. Try asking for only 64 bytes instead, > >> same as one wMaxPacket, before submitting the job. > >> > >> --HPS > > > > I believe my bufsize was already set to 64 (0x40). However, I do not see > > where I am reading or writing to the device except when loading/unloading > > the firmware. I just gave my code a read-through and do not see a > > reference to 1024. > > > > Regarding the 64-byte buffer, I went through OpenBSD's code base and when > > they open pipes (I believe the same as usbd_transfer_setup(9)), they > > allocate a 64- byte buffer and associate it with the Rx Interrupt pipe, > > as follows: > > > > ---START OPENBSD CODE--- > > > > isize = UGETW(ed->wMaxPacketSize); > > if (isize == 0) { > > > > printf("%s: invalid Rx intr pipe descriptor\n", > > > > usc->usb_dev.dv_xname); > > > > goto fail; > > > > } > > usc->ibuf = malloc(isize, M_USBDEV, M_NOWAIT); > > if (usc->ibuf == NULL) { > > > > printf("%s: could not allocate Rx intr buffer\n", > > > > usc->usb_dev.dv_xname); > > > > goto fail; > > > > } > > usc->ibuflen = isize; > > error = usbd_open_pipe_intr(usc->sc_iface, AR_PIPE_RX_INTR, > > > > USBD_SHORT_XFER_OK, &usc->rx_intr_pipe, usc, usc->ibuf, isize, > > athn_usb_intr, USBD_DEFAULT_INTERVAL); > > > > ---END OPENBSD CODE--- > > > > It appears to me like it is reading the size of the Max Packet size, > > allocating that many bytes and setting that as the equivalent of bufsize. > > Hi, > > > So my question is, where am I reading 1024 bytes, such that I need to > > change it to 64? > > The "usbdump" says that you have setup a receive buffer of 1024 bytes. > > Try adding some prints here: > > printf("====USB_ST_SETUP athn_usb_intr\n"); > > usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); > > Try to print usbd_xfer_max_len(xfer) . printf("---------The length is %d\n", usbd_xfer_max_len(xfer)); This is now giving me a size of 64. My usb_config bufsize is set to 64 (0x40). > > Also try to "make clean cleandepend" your module. I added this to my build script, which previously just ran `make clean`. > > And verify using usbdump again. This looks like what we want, I believe. ----- Endpoint 2 bLength = 0x0007 bDescriptorType = 0x0005 bEndpointAddress = 0x0083 bmAttributes = 0x0003 wMaxPacketSize = 0x0040 bInterval = 0x0001 bRefresh = 0x0000 bSynchAddress = 0x0000 Endpoint 3 bLength = 0x0007 bDescriptorType = 0x0005 bEndpointAddress = 0x0004 bmAttributes = 0x0003 wMaxPacketSize = 0x0040 bInterval = 0x0001 bRefresh = 0x0000 bSynchAddress = 0x0000 ----- > > Where is "" defined. I cannot find it! I was following how rtwn did it because this driver has a potential PCI component, not a single USB stand alone driver. That value is defined in /usr/ src/sys/dev/athn/athnvar.h ``` enum { ATHN_TX_DATA, ATHN_RX_DATA, ATHN_RX_INTR, ATHN_TX_INTR, ATHN_N_TRANSFERS, // A semi-copy from RTWN_N_TRANSFER }; ``` Github link: https://github.com/khanzf/freebsd/blob/ar9271/sys/dev/athn/ athnvar.h#L25 > > --HPS - Farhan