From nobody Fri Apr 22 04:35:37 2022 X-Original-To: freebsd-drivers@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 4032B1A29DEE for ; Fri, 22 Apr 2022 04:35:40 +0000 (UTC) (envelope-from farhan@farhan.codes) Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 4Kl1mq1Rg1z3qjk for ; Fri, 22 Apr 2022 04:35:39 +0000 (UTC) (envelope-from farhan@farhan.codes) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 1C9A35C017D; Fri, 22 Apr 2022 00:35:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 22 Apr 2022 00:35:39 -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=1650602139; x= 1650688539; bh=DN5pCBvVDz5vgZt3Vu7LdoHw1X3ZY05eQGeFpEXgIds=; b=s fGioLZpnIlH+QWcWpOrsBVZ7MSaF4KUo8pw+VCMZcCgCVyd405OZfKthGmtHTNgV f++hkH4cWNNnDubNr3YFRKjEsOrwLXpguv7LWqFBBWT/U/Bi7AJG0RQRggi2gDEL HNHUlDIXW2UyLyLrqOsB75HYfVltenNtQNoMb+a3COjJYqowUh1OIy4OLCQ/97ug 84lpHckbPBSUChqSHTkrBtqLkK81XnY7lnPAxI3KZr1hbhJsYLnFsfV4YFTr3hCd xkT3mbCepjZD5Nsq9U/VN4Yv2ezCtK+ktGzEIo6GFJ40+1YKm3doLRcVEWOuDfVZ d62k0W6ElnJY0QA61Co6w== 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=1650602139; x=1650688539; bh=DN5pCBvVDz5vgZt3Vu7LdoHw1X3Z Y05eQGeFpEXgIds=; b=fxioJwbbpyP6Ciyhu8oqDTKEe/Dprx8683pXbBx+9Z0k LJFx0ePrBe3q6td0s42WS2LT667Gy6O5ZK/TnDjSl4/A7UNxVC5blZMGmF3AA5U9 wCvyHLKd9K2Gcly/g5RZevJ8upP+zHeLcfMdzgYz1485/e6bpi9/zn1WcXI7VGgw 7G44QboQCEfKLOZWkgabFfZncGfZqZZ1knt3dgiHi+J8Lpm7BcTaaG/PGCRGGFca Fgb8hkn4TSNOtpGU7UeH4iL1+B9QeO0di68R07sbw6p0flLREP/iFkxPfFltz4IL ojwi2UXfL1T3KrAxhpYq+RsabyNJyuEpkuPD1y9kbQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrtdefgdekgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepkffuhffvffgjfhgtfggggfesthejre dttderjeenucfhrhhomhephfgrrhhhrghnucfmhhgrnhcuoehfrghrhhgrnhesfhgrrhhh rghnrdgtohguvghsqeenucggtffrrghtthgvrhhnpeeuieetjefhteegheefudefvdethf dtteehudfgueejledtueefhfdttdeifffgudenucffohhmrghinhepfhhrvggvsghsugdr ohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hfrghrhhgrnhesfhgrrhhhrghnrdgtohguvghs X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Apr 2022 00:35:38 -0400 (EDT) Message-ID: Subject: Re: How do I write a driver and how do I find out what kernel API calls do? From: Farhan Khan To: Yusuf Khan , freebsd-drivers@freebsd.org Date: Fri, 22 Apr 2022 00:35:37 -0400 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 List-Id: Writing device drivers for FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-drivers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-drivers@freebsd.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4Kl1mq1Rg1z3qjk X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=farhan.codes header.s=fm2 header.b="s fGioLZ"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=fxioJwbb; dmarc=none; spf=pass (mx1.freebsd.org: domain of farhan@farhan.codes designates 66.111.4.26 as permitted sender) smtp.mailfrom=farhan@farhan.codes X-Spamd-Result: default: False [-3.60 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:66.111.4.26]; RWL_MAILSPIKE_GOOD(0.00)[66.111.4.26:from]; RCVD_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[farhan.codes:+,messagingengine.com:+]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FREEMAIL_TO(0.00)[gmail.com,freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:19151, ipnet:66.111.4.0/24, country:US]; RCVD_TLS_LAST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[66.111.4.26:from]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[farhan.codes:s=fm2,messagingengine.com:s=fm1]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[farhan.codes]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MLMMJ_DEST(0.00)[freebsd-drivers] X-ThisMailContainsUnwantedMimeParts: N On Thu, 2022-04-21 at 18:17 -0500, Yusuf Khan wrote: > Literally just copy paste the title here. > > Also where do I get documentation? Hi Yusuf! I'm no expert, but I got my (limited) knowledge from a few sources: 1. There is a section in the documentation on this topic: https://docs.freebsd.org/en/books/arch-handbook/driverbasics/ 2. There's a book called "FreeBSD Device Drivers: A Guide for the Intrepid". Its a bit dated but the concepts largely still apply. 3. I read a ton of sample drivers. I'm currently struggling through the USB stack, /usr/src/sys/dev/usb/wlan has a lot of good and simple WiFi drivers. If you want an example of a wifi driver that is both USB and PCI, look at rtwn(4). 4. Each stack has some documentation, so in the case of USB, I read the usbdi man page and looked at examples. 5. Look at other implementations in other BSDs - or even illumos. Ultimately its not FreeBSD but it helps provide some context, especially for someone like me who has to learn multiple layers/stack prior to understanding what is happening, specifically what is device- specific and what is OS-specific. There's a ton of overlap and in some cases, such as WiFi, they maintain a slightly older version and therefore simpler version of the same stack. In terms of the details of a specific device, I'm honestly just copying previous implementations, namely Linux and OpenBSD. There's a great presentation by an OpenBSD developer on how he wrote wifi device drivers with limited context. You can find it on YouTube as: "Getting started with OpenBSD device driver development, by Stefan Sperling (EuroBSDcon 2017)" I was hoping to write some documentation of my experiences, but I have no immediate plans. If you struggle with the same thing, maybe write your experiences for the benefit of the community. I hope this helps! btw, nice last name! - Farhan Khan