From owner-freebsd-drivers@FreeBSD.ORG Sun Sep 18 18:28:45 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A53DE16A41F for ; Sun, 18 Sep 2005 18:28:45 +0000 (GMT) (envelope-from ben@benswebs.com) Received: from ms-smtp-04.nyroc.rr.com (ms-smtp-04.nyroc.rr.com [24.24.2.58]) by mx1.FreeBSD.org (Postfix) with ESMTP id 16B1443D45 for ; Sun, 18 Sep 2005 18:28:44 +0000 (GMT) (envelope-from ben@benswebs.com) Received: from [127.0.0.1] (cpe-72-224-114-15.nycap.res.rr.com [72.224.114.15]) by ms-smtp-04.nyroc.rr.com (8.12.10/8.12.10) with ESMTP id j8IISeV4028453 for ; Sun, 18 Sep 2005 14:28:41 -0400 (EDT) Message-ID: <432DB1AD.7070202@benswebs.com> Date: Sun, 18 Sep 2005 14:27:57 -0400 From: Benjamin Rosenblum User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-drivers@freebsd.org X-Virus-Scanned: Symantec AntiVirus Scan Engine Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Problems with SK and EM network cards X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Sep 2005 18:28:45 -0000 Im having an issue with my new linksys eg1032 nic and the onboard intel 82547EI on my new server. ill go over both problems individually and include my dmesg below that. First the SK problem. Sep 18 13:43:50 Valhalla kernel: skc0: port 0xc400-0xc4ff mem 0xfeafec00-0xfeafecff irq 21 at device 5.0 on pci3 Sep 18 13:43:50 Valhalla kernel: skc0: failed: rid 0x10 is ioport, requested 3 Sep 18 13:43:50 Valhalla kernel: sk0: couldn't map ports/memory i have run this network card before on another system with out any problems, cant figure this one out im sure its something easy but i cant figure it out at all please help. now the EM problem. when i am running a very high network load (streaming video, dumping ALOT of data across the network, etc) the network card disconnects (i loose pings and all my transfers drop) and 15-20 seconds later it pops up on the console with "em0: Link is up 1000 Mbps Full Duplex" and then it starts working again. again im at a dead wall and really want my network to work properly so i can do what i need to do. Here are my uname and dmesg FreeBSD Valhalla.PHISIG 5.4-RELEASE FreeBSD 5.4-RELEASE #5: Sun Sep 18 13:41:21 EDT 2005 laser@Valhalla.PHISIG:/usr/src/sys/i386/compile/VALHALLA i386 Sep 18 14:11:16 Valhalla syslogd: kernel boot file is /boot/kernel/kernel Sep 18 14:11:16 Valhalla kernel: Copyright (c) 1992-2005 The FreeBSD Project. Sep 18 14:11:16 Valhalla kernel: Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 Sep 18 14:11:16 Valhalla kernel: The Regents of the University of California. All rights reserved. Sep 18 14:11:16 Valhalla kernel: FreeBSD 5.4-RELEASE #5: Sun Sep 18 13:41:21 EDT 2005 Sep 18 14:11:16 Valhalla kernel: laser@Valhalla.PHISIG:/usr/src/sys/i386/compile/VALHALLA Sep 18 14:11:16 Valhalla kernel: WARNING: debug.mpsafenet forced to 0 as ipsec requires Giant Sep 18 14:11:16 Valhalla kernel: WARNING: MPSAFE network stack disabled, expect reduced performance. Sep 18 14:11:16 Valhalla kernel: Timecounter "i8254" frequency 1193182 Hz quality 0 Sep 18 14:11:16 Valhalla kernel: CPU: Intel(R) Pentium(R) 4 CPU 3.20GHz (3192.02-MHz 686-class CPU) Sep 18 14:11:16 Valhalla kernel: Origin = "GenuineIntel" Id = 0xf41 Stepping = 1 Sep 18 14:11:16 Valhalla kernel: Features=0xbfebfbff Sep 18 14:11:16 Valhalla kernel: Hyperthreading: 2 logical CPUs Sep 18 14:11:16 Valhalla kernel: real memory = 2147418112 (2047 MB) Sep 18 14:11:16 Valhalla kernel: avail memory = 2095964160 (1998 MB) Sep 18 14:11:16 Valhalla kernel: ACPI APIC Table: Sep 18 14:11:16 Valhalla kernel: FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs Sep 18 14:11:16 Valhalla kernel: cpu0 (BSP): APIC ID: 0 Sep 18 14:11:16 Valhalla kernel: cpu1 (AP): APIC ID: 1 Sep 18 14:11:16 Valhalla kernel: ioapic0 irqs 0-23 on motherboard Sep 18 14:11:16 Valhalla kernel: ioapic1 irqs 24-47 on motherboard Sep 18 14:11:16 Valhalla kernel: hptmv6: RocketRAID 222x controller driver v1.01 (Jun 15 2005 10:17:49) Sep 18 14:11:16 Valhalla kernel: npx0: on motherboard Sep 18 14:11:16 Valhalla kernel: npx0: INT 16 interface Sep 18 14:11:16 Valhalla kernel: acpi0: on motherboard Sep 18 14:11:16 Valhalla kernel: acpi0: Power Button (fixed) Sep 18 14:11:16 Valhalla kernel: Timecounter "ACPI-fast" frequency 3579545 Hz quality 1000 Sep 18 14:11:16 Valhalla kernel: acpi_timer0: <24-bit timer at 3.579545MHz> port 0x808-0x80b on acpi0 Sep 18 14:11:16 Valhalla kernel: cpu0: on acpi0 Sep 18 14:11:16 Valhalla kernel: cpu1: on acpi0 Sep 18 14:11:16 Valhalla kernel: pcib0: port 0xcf8-0xcff on acpi0 Sep 18 14:11:16 Valhalla kernel: pci0: on pcib0 Sep 18 14:11:16 Valhalla kernel: pcib1: at device 3.0 on pci0 Sep 18 14:11:16 Valhalla kernel: pci1: on pcib1 Sep 18 14:11:16 Valhalla kernel: em0: port 0xac00-0xac1f mem 0xfc4c0000-0xfc4dffff,0xfc4e0000-0xfc4fffff irq 18 at device 1.0 on pci1 Sep 18 14:11:16 Valhalla kernel: em0: Ethernet address: 00:13:d4:5a:de:3d Sep 18 14:11:16 Valhalla kernel: em0: Speed:N/A Duplex:N/A Sep 18 14:11:16 Valhalla kernel: pcib2: at device 28.0 on pci0 Sep 18 14:11:16 Valhalla kernel: pci2: on pcib2 Sep 18 14:11:16 Valhalla kernel: hptmv60: port 0xb800-0xb8ff mem 0xfc900000-0xfc9fffff irq 25 at device 3.0 on pci2 Sep 18 14:11:16 Valhalla kernel: hptmv6: adapter at PCI 2:3:0, IRQ 25 Sep 18 14:11:16 Valhalla kernel: atapci0: port 0xb000-0xb07f,0xb400-0xb40f,0xbc00-0xbc3f mem 0xfc7c0000-0xfc7dffff,0xfc7ff000-0xfc7fffff irq 27 at device 5.0 on pci2 Sep 18 14:11:16 Valhalla kernel: atapci0: failed: rid 0x20 is memory, requested 4 Sep 18 14:11:16 Valhalla kernel: ata2: channel #0 on atapci0 Sep 18 14:11:16 Valhalla kernel: ata3: channel #1 on atapci0 Sep 18 14:11:16 Valhalla kernel: ata4: channel #2 on atapci0 Sep 18 14:11:16 Valhalla kernel: ata5: channel #3 on atapci0 Sep 18 14:11:16 Valhalla kernel: uhci0: port 0xe800-0xe81f irq 16 at device 29.0 on pci0 Sep 18 14:11:16 Valhalla kernel: usb0: on uhci0 Sep 18 14:11:16 Valhalla kernel: usb0: USB revision 1.0 Sep 18 14:11:16 Valhalla kernel: uhub0: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1 Sep 18 14:11:16 Valhalla kernel: uhub0: 2 ports with 2 removable, self powered Sep 18 14:11:16 Valhalla kernel: uhci1: port 0xec00-0xec1f irq 19 at device 29.1 on pci0 Sep 18 14:11:16 Valhalla kernel: usb1: on uhci1 Sep 18 14:11:16 Valhalla kernel: usb1: USB revision 1.0 Sep 18 14:11:16 Valhalla kernel: uhub1: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1 Sep 18 14:11:16 Valhalla kernel: uhub1: 2 ports with 2 removable, self powered Sep 18 14:11:16 Valhalla kernel: pci0: at device 29.4 (no driver attached) Sep 18 14:11:16 Valhalla kernel: pci0: at device 29.5 (no driver attached) Sep 18 14:11:16 Valhalla kernel: pci0: at device 29.7 (no driver attached) Sep 18 14:11:16 Valhalla kernel: pcib3: at device 30.0 on pci0 Sep 18 14:11:16 Valhalla kernel: pci3: on pcib3 Sep 18 14:11:16 Valhalla kernel: pci3: at device 3.0 (no driver attached) Sep 18 14:11:16 Valhalla kernel: skc0: port 0xc400-0xc4ff mem 0xfeafec00-0xfeafecff irq 21 at device 5.0 on pci3 Sep 18 14:11:16 Valhalla kernel: skc0: failed: rid 0x10 is ioport, requested 3 Sep 18 14:11:16 Valhalla kernel: sk0: couldn't map ports/memory Sep 18 14:11:16 Valhalla kernel: device_attach: skc0 attach returned 6 Sep 18 14:11:16 Valhalla kernel: adv0: port 0xc000-0xc0ff mem 0xfeafe800-0xfeafe8ff irq 22 at device 6.0 on pci3 Sep 18 14:11:16 Valhalla kernel: adv0: Warning EEPROM Checksum mismatch. Using default device parameters Sep 18 14:11:16 Valhalla kernel: adv0: AdvanSys SCSI Host Adapter, SCSI ID 7, queue depth 16 Sep 18 14:11:16 Valhalla kernel: isab0: at device 31.0 on pci0 Sep 18 14:11:16 Valhalla kernel: isa0: on isab0 Sep 18 14:11:16 Valhalla kernel: atapci1: port 0xfc00-0xfc0f,0x376,0x170-0x177,0x3f6,0x1f0-0x1f7 at device 31.1 on pci0 Sep 18 14:11:16 Valhalla kernel: ata0: channel #0 on atapci1 Sep 18 14:11:16 Valhalla kernel: ata1: channel #1 on atapci1 Sep 18 14:11:16 Valhalla kernel: pci0: at device 31.3 (no driver attached) Sep 18 14:11:16 Valhalla kernel: acpi_button0: on acpi0 Sep 18 14:11:16 Valhalla kernel: sio0: configured irq 4 not in bitmap of probed irqs 0 Sep 18 14:11:16 Valhalla kernel: sio0: port may not be enabled Sep 18 14:11:16 Valhalla kernel: sio0: <16550A-compatible COM port> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0 Sep 18 14:11:16 Valhalla kernel: sio0: type 16550A Sep 18 14:11:16 Valhalla kernel: sio1: configured irq 3 not in bitmap of probed irqs 0 Sep 18 14:11:16 Valhalla kernel: sio1: port may not be enabled Sep 18 14:11:16 Valhalla kernel: sio1: <16550A-compatible COM port> port 0x2f8-0x2ff irq 3 on acpi0 Sep 18 14:11:16 Valhalla kernel: sio1: type 16550A Sep 18 14:11:16 Valhalla kernel: fdc0: port 0x3f7,0x3f0-0x3f5 irq 6 drq 2 on acpi0 Sep 18 14:11:16 Valhalla kernel: fd0: <1440-KB 3.5" drive> on fdc0 drive 0 Sep 18 14:11:16 Valhalla kernel: ppc0: port 0x378-0x37f irq 7 on acpi0 Sep 18 14:11:16 Valhalla kernel: ppc0: Generic chipset (EPP/NIBBLE) in COMPATIBLE mode Sep 18 14:11:16 Valhalla kernel: ppbus0: on ppc0 Sep 18 14:11:16 Valhalla kernel: plip0: on ppbus0 Sep 18 14:11:16 Valhalla kernel: lpt0: on ppbus0 Sep 18 14:11:16 Valhalla kernel: lpt0: Interrupt-driven port Sep 18 14:11:16 Valhalla kernel: ppi0: on ppbus0 Sep 18 14:11:16 Valhalla kernel: atkbdc0: port 0x64,0x60 irq 1 on acpi0 Sep 18 14:11:16 Valhalla kernel: atkbd0: irq 1 on atkbdc0 Sep 18 14:11:16 Valhalla kernel: kbd0 at atkbd0 Sep 18 14:11:16 Valhalla kernel: orm0: at iomem 0xc0000-0xc7fff on isa0 Sep 18 14:11:16 Valhalla kernel: pmtimer0 on isa0 Sep 18 14:11:16 Valhalla kernel: sc0: at flags 0x100 on isa0 Sep 18 14:11:16 Valhalla kernel: sc0: VGA <16 virtual consoles, flags=0x300> Sep 18 14:11:16 Valhalla kernel: vga0: at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0 Sep 18 14:11:16 Valhalla kernel: hptmv6: start channel [0,0] Sep 18 14:11:16 Valhalla kernel: hptmv6: channel [0,0] started successfully Sep 18 14:11:16 Valhalla kernel: hptmv6: start channel [0,1] Sep 18 14:11:16 Valhalla kernel: hptmv6: channel [0,1] started successfully Sep 18 14:11:16 Valhalla kernel: hptmv6: start channel [0,2] Sep 18 14:11:16 Valhalla kernel: hptmv6: channel [0,2] started successfully Sep 18 14:11:16 Valhalla kernel: hptmv6: start channel [0,3] Sep 18 14:11:16 Valhalla kernel: hptmv6: channel [0,3] started successfully Sep 18 14:11:16 Valhalla kernel: hptmv6: start channel [0,4] Sep 18 14:11:16 Valhalla kernel: hptmv6: channel [0,4] started successfully Sep 18 14:11:16 Valhalla kernel: Timecounters tick every 1.000 msec Sep 18 14:11:16 Valhalla kernel: IPsec: Initialized Security Association Processing. Sep 18 14:11:16 Valhalla kernel: ipfw2 initialized, divert enabled, rule-based forwarding disabled, default to accept, logging disabled Sep 18 14:11:16 Valhalla kernel: ad0: 114440MB [232514/16/63] at ata0-master UDMA100 Sep 18 14:11:16 Valhalla kernel: acd0: DVDR at ata1-master PIO4 Sep 18 14:11:16 Valhalla kernel: acd1: DVDR at ata1-slave PIO4 Sep 18 14:11:16 Valhalla kernel: Waiting 15 seconds for SCSI devices to settle Sep 18 14:11:16 Valhalla kernel: da0 at hptmv60 bus 0 target 0 lun 0 Sep 18 14:11:16 Valhalla kernel: da0: Fixed Direct Access SCSI-0 device Sep 18 14:11:16 Valhalla kernel: da0: 1525760MB (3124756480 512 byte sectors: 255H 63S/T 194507C) Sep 18 14:11:16 Valhalla kernel: SMP: AP CPU #1 Launched! Sep 18 14:11:16 Valhalla kernel: Mounting root from ufs:/dev/ad0s1a Sep 18 14:11:18 Valhalla kernel: em0: Link is up 1000 Mbps Full Duplex Sep 18 14:11:19 Valhalla ntpd[453]: ntpd 4.2.0-a Sun May 8 06:01:21 UTC 2005 (1) Sep 18 14:14:13 Valhalla su: laser to root on /dev/ttyp0 From owner-freebsd-drivers@FreeBSD.ORG Mon Sep 19 22:40:40 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7185B16A421 for ; Mon, 19 Sep 2005 22:40:40 +0000 (GMT) (envelope-from prichardson@lincoln.ac.uk) Received: from harkonnen.lincoln.ac.uk (harkonnen.lincoln.ac.uk [194.80.59.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id CD3A343D49 for ; Mon, 19 Sep 2005 22:40:39 +0000 (GMT) (envelope-from prichardson@lincoln.ac.uk) Received: from aexcmb02.network.uni ([194.80.57.9]) by harkonnen.lincoln.ac.uk with esmtp (Exim 4.44) id 1EHUJG-0006CR-R3 for freebsd-drivers@freebsd.org; Mon, 19 Sep 2005 23:40:39 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Mon, 19 Sep 2005 23:40:26 +0100 Message-ID: <139F6E4BC4C585478FA84D02D90CC1CA04C5102C@aexcmb02.network.uni> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Newbie Device Driver writer... Thread-Index: AcW9ayFlfQC+7Mj/Qv+77txHr5dfbA== From: "Phil Richardson" To: X-AntiVirus-Scanner: Virus checked by harkonnen.lincoln.ac.uk using Sophie and Sophos AV X-SA-Exim-Connect-IP: 194.80.57.9 X-SA-Exim-Mail-From: prichardson@lincoln.ac.uk X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on harkonnen.lincoln.ac.uk X-Spam-Level: X-Spam-Status: No, score=-5.4 required=9.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.0.4 X-SA-Exim-Version: 4.2 (built Sun, 20 Feb 2005 16:05:43 +0000) X-SA-Exim-Scanned: Yes (on harkonnen.lincoln.ac.uk) Subject: Newbie Device Driver writer... X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Sep 2005 22:40:40 -0000 Hi. Im rather new to device driver writing under FreeBSD (in particular Im = using 5.4). I have a PCI based IO card (4x32bit TTL presentation) and = have written a simplistic driver thus far (basic handling is done = completely through IOCTL calls - but it works). However now I have started to think about using the device in a real way = I realise it would be nice to implement asynchronous use. Maybe not the = right term (forgive me) - but in essence I would really like to utilise = this device along with other devices (such as a socket or tty) and use = the Select() call to determine whats happening to who, and when. However - I cannot find any reference anywhere within source code (that = I can recognise at any rate) within existing device drivers (say sio.c) = that suggest how you link a device driver to the select() call itself (I = was expecting to find something like sio_select, much as sio_read, = sio_write and sio_ioctl for example - which shows my inexperience and = definate lack of understanding). Anyone care to give some advice on how the kernel select() call can be = linked into a home-made driver? A pointer to some documentation (dare I = say that - documentation is a bit thin on device drivers so ive = found...) would be a help. Trusting someone somewhere might have a pointer or clue out there..... Regards Phil From owner-freebsd-drivers@FreeBSD.ORG Mon Sep 19 23:06:33 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AFD9816A41F for ; Mon, 19 Sep 2005 23:06:33 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4EFE043D45 for ; Mon, 19 Sep 2005 23:06:33 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.3/8.13.3) with ESMTP id j8JN5luF027291; Mon, 19 Sep 2005 17:05:47 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Mon, 19 Sep 2005 17:05:59 -0600 (MDT) Message-Id: <20050919.170559.68164164.imp@bsdimp.com> To: prichardson@lincoln.ac.uk From: "M. Warner Losh" In-Reply-To: <139F6E4BC4C585478FA84D02D90CC1CA04C5102C@aexcmb02.network.uni> References: <139F6E4BC4C585478FA84D02D90CC1CA04C5102C@aexcmb02.network.uni> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Mon, 19 Sep 2005 17:05:48 -0600 (MDT) Cc: freebsd-drivers@freebsd.org Subject: Re: Newbie Device Driver writer... X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Sep 2005 23:06:33 -0000 In message: <139F6E4BC4C585478FA84D02D90CC1CA04C5102C@aexcmb02.network.uni> "Phil Richardson" writes: : Im rather new to device driver writing under FreeBSD (in particular : Im using 5.4). I have a PCI based IO card (4x32bit TTL presentation) : and have written a simplistic driver thus far (basic handling is : done completely through IOCTL calls - but it works). Sounds like an interesting device. : However now I have started to think about using the device in a real : way I realise it would be nice to implement asynchronous use. Maybe : not the right term (forgive me) - but in essence I would really like : to utilise this device along with other devices (such as a socket or : tty) and use the Select() call to determine whats happening to who, : and when. Event driven programming is what it sounds like. : However - I cannot find any reference anywhere within source code : (that I can recognise at any rate) within existing device drivers : (say sio.c) that suggest how you link a device driver to the : select() call itself (I was expecting to find something like : sio_select, much as sio_read, sio_write and sio_ioctl for example - : which shows my inexperience and definate lack of understanding). sio is a bad driver to look at, since it move much of its functionality into the tty layer, obscuring these simple things. : Anyone care to give some advice on how the kernel select() call can : be linked into a home-made driver? A pointer to some documentation : (dare I say that - documentation is a bit thin on device drivers so : ive found...) would be a help. You need to implment a d_poll_t function for your driver. : Trusting someone somewhere might have a pointer or clue out there..... I just started to take a look at our man pages, and realized that some work is needed to ferret out the information. First, you'll need to read up on the configuration phase of your device's life cycle. This is the traditional probe and attach routines. You can find good infromation about these in the various bus and device man pages (DEVICE_PROBE, DEVICE_ATTACH, bus_alloc_resource, etc). In your attach routine, you'll need to make the device visible to the filesystem. make_dev will do this. One of the arguments to make_dev is the cdevsw for your device. cdevsw is a structure that contains poiners to functions that get called for your device when the user interacts with it. I didn't see a man page for, so I'll give a quickie add-hoc one here. struct cdevsw { int d_version; u_int d_flags; const char *d_name; d_open_t *d_open; d_fdopen_t *d_fdopen; d_close_t *d_close; d_read_t *d_read; d_write_t *d_write; d_ioctl_t *d_ioctl; d_poll_t *d_poll; d_mmap_t *d_mmap; d_strategy_t *d_strategy; dumper_t *d_dump; d_kqfilter_t *d_kqfilter; d_purge_t *d_purge; d_spare2_t *d_spare2; uid_t d_uid; gid_t d_gid; mode_t d_mode; const char *d_kind; /* These fields should not be messed with by drivers */ LIST_ENTRY(cdevsw) d_list; LIST_HEAD(, cdev) d_devs; int d_spare3; struct cdevsw *d_gianttrick; }; d_version should be set to D_VERSION. d_flags should be one or more of the following: /* * Flags for d_flags which the drivers can set. */ #define D_MEMDISK 0x00010000 /* memory type disk */ #define D_TRACKCLOSE 0x00080000 /* track all closes */ #define D_MMAP_ANON 0x00100000 /* special treatment in vm_mmap.c */ #define D_PSEUDO 0x00200000 /* make_dev() can return NULL */ #define D_NEEDGIANT 0x00400000 /* driver want Giant */ Usually, D_NEEDGIANT and D_TRACKCLOSE are the only flags you need. >From the sounds of your device, it is unlikely to need anything else. d_name is the name of the device. d_open is called when the file is opened. You'll almost certainly want to create one of these. d_close is called when the last reference to the device goes away (unless D_TRACKCLOSE is called, in which case each close causes a call to d_close). d_read and d_write are called when the user calls read(2) and write(2) respectively. d_ioctl is used for device control. d_poll is used to indicate when the device has data. The rest aren't relevant for this discussion. cdevsw is usually initialized like so: static struct cdevsw crd_cdevsw = { .d_version = D_VERSION, .d_flags = D_NEEDGIANT, .d_open = fooopen, .d_close = fooclose, .d_read = fooread, .d_write = foowrite, .d_ioctl = fooioctl, .d_poll = foopoll, .d_name = "foo", }; Most of the routines are straight forward, so I'll not comment on them here (feel free to ask questions, however). d_poll is coded as follows: static int foopoll(struct cdev *dev, int events, d_thread_t *td) { int revents = 0; int s; struct softc *sc = dev->si_drv1; if (events & (POLLIN | POLLRDNORM)) revents |= events & (POLLIN | POLLRDNORM); if (events & (POLLOUT | POLLWRNORM)) revents |= events & (POLLIN | POLLRDNORM); /* Read polling */ if (events & POLLRDBAND) if (### test that there's more data ###) revents |= POLLRDBAND; if (revents == 0) selrecord(td, &slt->selp); return (revents); } then in your read routine, you'd have something like: static int fooread(struct cdev *dev, struct uio *uio, int ioflag) { struct softc *sc = dev->si_drv1; if !(### test that there's some data ###) && non-blocking return EAGAIN; while (### test that there's some data ###) && room in buffer copyout data if (!non-blocking) sleep for more data else break; } Warner From owner-freebsd-drivers@FreeBSD.ORG Tue Sep 20 17:44:04 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EDE4816A420 for ; Tue, 20 Sep 2005 17:44:04 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5573B43D53 for ; Tue, 20 Sep 2005 17:44:04 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from [10.50.41.233] (Not Verified[10.50.41.233]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Tue, 20 Sep 2005 13:59:51 -0400 From: John Baldwin To: freebsd-drivers@freebsd.org Date: Tue, 20 Sep 2005 11:40:30 -0400 User-Agent: KMail/1.8 References: <139F6E4BC4C585478FA84D02D90CC1CA04C5102C@aexcmb02.network.uni> <20050919.170559.68164164.imp@bsdimp.com> In-Reply-To: <20050919.170559.68164164.imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200509201140.31329.jhb@FreeBSD.org> Cc: prichardson@lincoln.ac.uk Subject: Re: Newbie Device Driver writer... X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Sep 2005 17:44:05 -0000 On Monday 19 September 2005 07:05 pm, M. Warner Losh wrote: > In message: <139F6E4BC4C585478FA84D02D90CC1CA04C5102C@aexcmb02.network.uni> > > "Phil Richardson" writes: > : Im rather new to device driver writing under FreeBSD (in particular > : Im using 5.4). I have a PCI based IO card (4x32bit TTL presentation) > : and have written a simplistic driver thus far (basic handling is > : done completely through IOCTL calls - but it works). > > Sounds like an interesting device. > > : However now I have started to think about using the device in a real > : way I realise it would be nice to implement asynchronous use. Maybe > : not the right term (forgive me) - but in essence I would really like > : to utilise this device along with other devices (such as a socket or > : tty) and use the Select() call to determine whats happening to who, > : and when. > > Event driven programming is what it sounds like. > > : However - I cannot find any reference anywhere within source code > : (that I can recognise at any rate) within existing device drivers > : (say sio.c) that suggest how you link a device driver to the > : select() call itself (I was expecting to find something like > : sio_select, much as sio_read, sio_write and sio_ioctl for example - > : which shows my inexperience and definate lack of understanding). > > sio is a bad driver to look at, since it move much of its > functionality into the tty layer, obscuring these simple things. > > : Anyone care to give some advice on how the kernel select() call can > : be linked into a home-made driver? A pointer to some documentation > : (dare I say that - documentation is a bit thin on device drivers so > : ive found...) would be a help. > > You need to implment a d_poll_t function for your driver. > > : Trusting someone somewhere might have a pointer or clue out there..... > > I just started to take a look at our man pages, and realized that some > work is needed to ferret out the information. > > First, you'll need to read up on the configuration phase of your > device's life cycle. This is the traditional probe and attach > routines. You can find good infromation about these in the various > bus and device man pages (DEVICE_PROBE, DEVICE_ATTACH, > bus_alloc_resource, etc). > > In your attach routine, you'll need to make the device visible to the > filesystem. make_dev will do this. One of the arguments to make_dev > is the cdevsw for your device. cdevsw is a structure that contains > poiners to functions that get called for your device when the user > interacts with it. I didn't see a man page for, so I'll give a > quickie add-hoc one here. > > struct cdevsw { > int d_version; > u_int d_flags; > const char *d_name; > d_open_t *d_open; > d_fdopen_t *d_fdopen; > d_close_t *d_close; > d_read_t *d_read; > d_write_t *d_write; > d_ioctl_t *d_ioctl; > d_poll_t *d_poll; > d_mmap_t *d_mmap; > d_strategy_t *d_strategy; > dumper_t *d_dump; > d_kqfilter_t *d_kqfilter; > d_purge_t *d_purge; > d_spare2_t *d_spare2; > uid_t d_uid; > gid_t d_gid; > mode_t d_mode; > const char *d_kind; > > /* These fields should not be messed with by drivers */ > LIST_ENTRY(cdevsw) d_list; > LIST_HEAD(, cdev) d_devs; > int d_spare3; > struct cdevsw *d_gianttrick; > }; > > d_version should be set to D_VERSION. > > d_flags should be one or more of the following: > /* > * Flags for d_flags which the drivers can set. > */ > #define D_MEMDISK 0x00010000 /* memory type disk */ > #define D_TRACKCLOSE 0x00080000 /* track all closes */ > #define D_MMAP_ANON 0x00100000 /* special treatment in vm_mmap.c */ > #define D_PSEUDO 0x00200000 /* make_dev() can return NULL */ > #define D_NEEDGIANT 0x00400000 /* driver want Giant */ > > Usually, D_NEEDGIANT and D_TRACKCLOSE are the only flags you need. > > >From the sounds of your device, it is unlikely to need anything else. > > d_name is the name of the device. > > d_open is called when the file is opened. You'll almost certainly > want to create one of these. > > d_close is called when the last reference to the device goes away > (unless D_TRACKCLOSE is called, in which case each close causes a > call to d_close). > > d_read and d_write are called when the user calls read(2) and write(2) > respectively. > > d_ioctl is used for device control. > > d_poll is used to indicate when the device has data. > > The rest aren't relevant for this discussion. > > cdevsw is usually initialized like so: > > static struct cdevsw crd_cdevsw = { > .d_version = D_VERSION, > .d_flags = D_NEEDGIANT, > .d_open = fooopen, > .d_close = fooclose, > .d_read = fooread, > .d_write = foowrite, > .d_ioctl = fooioctl, > .d_poll = foopoll, > .d_name = "foo", > }; > > Most of the routines are straight forward, so I'll not comment on them > here (feel free to ask questions, however). > > d_poll is coded as follows: > > static int > foopoll(struct cdev *dev, int events, d_thread_t *td) > { > int revents = 0; > int s; > struct softc *sc = dev->si_drv1; > > if (events & (POLLIN | POLLRDNORM)) > revents |= events & (POLLIN | POLLRDNORM); > > if (events & (POLLOUT | POLLWRNORM)) > revents |= events & (POLLIN | POLLRDNORM); > > /* Read polling */ > if (events & POLLRDBAND) > if (### test that there's more data ###) > revents |= POLLRDBAND; > > if (revents == 0) > selrecord(td, &slt->selp); > > return (revents); > } > > then in your read routine, you'd have something like: > > static int > fooread(struct cdev *dev, struct uio *uio, int ioflag) > { > struct softc *sc = dev->si_drv1; > > > if !(### test that there's some data ###) && non-blocking > return EAGAIN; > > while (### test that there's some data ###) && room in buffer > copyout data > if (!non-blocking) > sleep for more data > else > break; > } You'll also need to call selwakeup() in your interrupt routine when data becomes available to wake threads that have blocked in select(). -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org From owner-freebsd-drivers@FreeBSD.ORG Tue Sep 20 17:55:27 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0D78016A41F for ; Tue, 20 Sep 2005 17:55:27 +0000 (GMT) (envelope-from hlecuanda@gmail.com) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4F28843D48 for ; Tue, 20 Sep 2005 17:55:26 +0000 (GMT) (envelope-from hlecuanda@gmail.com) Received: by zproxy.gmail.com with SMTP id j2so286959nzf for ; Tue, 20 Sep 2005 10:55:25 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=V8uhK7x1nYPcoFzZ6sQpP5rwvm0iCo6dX4JfgxfE77OGGhSq9UUGhppisEdAkbVadoxTff8U1pOJULFI2IavLU1Yv6vxHj7//q5d0csUsUhnPq0NaJbjQhH1qCoqEe9TJ4GOpFaRNdAutKX6KiKy6XyxsohMGtOTReTEYXBxQ74= Received: by 10.54.140.10 with SMTP id n10mr1918558wrd; Tue, 20 Sep 2005 10:55:25 -0700 (PDT) Received: by 10.54.116.17 with HTTP; Tue, 20 Sep 2005 10:55:25 -0700 (PDT) Message-ID: Date: Tue, 20 Sep 2005 10:55:25 -0700 From: Hector Lecuanda To: freebsd-drivers@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: em on 5.x X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: hlecuanda@gmail.com List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Sep 2005 17:55:27 -0000 I have an Intel 82573 1000/PRO nic. I've seen that the 4.x branch supports this device, but 5.x does not. Is support for this device to be included in the near future?=20 who can I contact regarding patches to make it work? Thank You. --=20 -Hector Lecuanda PGP Public Key / Llave Publica PGP: http://lecuanda.com/pgp_pubkey.asc http://lecuanda.com/pgp_pubkey.txt From owner-freebsd-drivers@FreeBSD.ORG Tue Sep 20 19:50:10 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E284216A420 for ; Tue, 20 Sep 2005 19:50:10 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id EFF3743D45 for ; Tue, 20 Sep 2005 19:50:09 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from [10.50.41.233] (Not Verified[10.50.41.233]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Tue, 20 Sep 2005 16:05:58 -0400 From: John Baldwin To: freebsd-drivers@freebsd.org, hlecuanda@gmail.com Date: Tue, 20 Sep 2005 14:41:20 -0400 User-Agent: KMail/1.8 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200509201441.21121.jhb@FreeBSD.org> Cc: Subject: Re: em on 5.x X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Sep 2005 19:50:11 -0000 On Tuesday 20 September 2005 01:55 pm, Hector Lecuanda wrote: > I have an Intel 82573 1000/PRO nic. I've seen that the 4.x branch > supports this device, but 5.x does not. > > Is support for this device to be included in the near future? > who can I contact regarding patches to make it work? Erm, the em(4) driver is in 5.x. Also, this mailing list is more for questions about writing device drivers. For more general questions try either the questions@ or stable@ mailing lists. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org From owner-freebsd-drivers@FreeBSD.ORG Thu Sep 22 17:51:36 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E295016A41F for ; Thu, 22 Sep 2005 17:51:36 +0000 (GMT) (envelope-from freebsd@sopwith.solgatos.com) Received: from schitzo.solgatos.com (c-67-168-241-176.hsd1.or.comcast.net [67.168.241.176]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7153043D5D for ; Thu, 22 Sep 2005 17:51:33 +0000 (GMT) (envelope-from freebsd@sopwith.solgatos.com) Received: from sopwith.solgatos.com (uucp@localhost) by schitzo.solgatos.com (8.11.6/8.11.6) with UUCP id j8MHpZk14270 for freebsd-drivers@freebsd.org; Thu, 22 Sep 2005 10:51:35 -0700 Received: from localhost by sopwith.solgatos.com (8.8.8/6.24) id RAA07579; Thu, 22 Sep 2005 17:51:37 GMT Message-Id: <200509221751.RAA07579@sopwith.solgatos.com> To: freebsd-drivers@freebsd.org Date: Thu, 22 Sep 2005 10:51:37 +0100 From: Dieter Subject: Bolting Linux device drivers to FreeBSD kernel? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd@sopwith.solgatos.com List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2005 17:51:37 -0000 I have found the "project evil" interface for using a wintel device driver with a FreeBSD kernel. But search as I may, I cannot find any information on how to bolt a Linux device driver to a FreeBSD kernel? From owner-freebsd-drivers@FreeBSD.ORG Thu Sep 22 18:49:02 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AC07216A41F for ; Thu, 22 Sep 2005 18:49:02 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4A92943D46 for ; Thu, 22 Sep 2005 18:49:02 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.3/8.13.3) with ESMTP id j8MImRWP077325; Thu, 22 Sep 2005 12:48:27 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Thu, 22 Sep 2005 12:48:50 -0600 (MDT) Message-Id: <20050922.124850.48530671.imp@bsdimp.com> To: freebsd@sopwith.solgatos.com From: "M. Warner Losh" In-Reply-To: <200509221751.RAA07579@sopwith.solgatos.com> References: <200509221751.RAA07579@sopwith.solgatos.com> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Thu, 22 Sep 2005 12:48:28 -0600 (MDT) Cc: freebsd-drivers@freebsd.org Subject: Re: Bolting Linux device drivers to FreeBSD kernel? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2005 18:49:02 -0000 In message: <200509221751.RAA07579@sopwith.solgatos.com> Dieter writes: : I have found the "project evil" interface for using a wintel : device driver with a FreeBSD kernel. : : But search as I may, I cannot find any information on how to bolt : a Linux device driver to a FreeBSD kernel? Presently, no such generic interface exists to do this that I'm aware of. I've made various attempts in the past to do this. The amount of variation between ABIs of the different Linux releases makes it problematic to support binary Linux drivers on FreeBSD in a good, generic fashion. There's also some minor, but annoying, variation between different vendors of Linux's ABI, but I think those are mostly accidental (read bugs). Souce level compatibility hasn't been something that I've seen done at all. There are a few binary blobs that have been produced that have been made to run on FreeBSD. In these cases, a FreeBSD driver has been written to call into the binary blob. The ltmdm port is one example where this has been done fairly successfully. I've tried to get some binary drivers working on FreeBSD in the past, but ran into a peck of trouble trying to make them work. Mostly because the binary blob turned out to not be linux independent, and it did things that assumed a linux kernel had setup up something in a particular way which was hard to do with FreeBSD... So your milage may vary. Warner