From owner-freebsd-embedded@FreeBSD.ORG Tue Dec 20 15:25:47 2011 Return-Path: Delivered-To: freebsd-embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A82711065670; Tue, 20 Dec 2011 15:25:47 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from mail-vx0-f182.google.com (mail-vx0-f182.google.com [209.85.220.182]) by mx1.freebsd.org (Postfix) with ESMTP id 347EE8FC08; Tue, 20 Dec 2011 15:25:46 +0000 (UTC) Received: by vcbfk1 with SMTP id fk1so8579501vcb.13 for ; Tue, 20 Dec 2011 07:25:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=zB7FpXwh0kk9a4ymZHdJqh5roze1gsiaH0ufUBKjdeI=; b=hRnyys6RADyl7EY2/xaKsZ0VoxuaJH2gh0NwbT4WAzWdZdb2Rn49Lbr7cdm6Nf46xO WaUzSMGBk3FlAH5zRD3qfEuVIDxh9qsY+jiuHyu++03XhFa1f65EXg3WdVRgfRDm407X ANAmbIJ++Qu/CE41LA0fas5Az6ZPFHoQ0QO3I= MIME-Version: 1.0 Received: by 10.52.90.164 with SMTP id bx4mr1241699vdb.128.1324394746485; Tue, 20 Dec 2011 07:25:46 -0800 (PST) Sender: adrian.chadd@gmail.com Received: by 10.52.158.104 with HTTP; Tue, 20 Dec 2011 07:25:46 -0800 (PST) In-Reply-To: References: <0F6CC18F-6973-42A2-AC03-F01BF59458AE@lassitu.de> <1100F70E-9DA9-4163-AC9A-423ECE5AA9A3@lassitu.de> <18CABB46-9B9A-41CB-8742-6723C5FF4D67@lassitu.de> <2CBD8651-E132-49DC-A082-37A8F5C626EA@bsdimp.com> Date: Tue, 20 Dec 2011 07:25:46 -0800 X-Google-Sender-Auth: IWOQRproBKH5_gPwRP9XMa3s8h0 Message-ID: From: Adrian Chadd To: Stefan Bethke Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Oleksandr Tymoshenko , "freebsd-embedded@freebsd.org" Subject: Re: Updated switch/glue patch? X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Dec 2011 15:25:47 -0000 On 19 December 2011 23:39, Stefan Bethke wrote: > I2C runs at 100kHz, so a total delay per bit of 10 microseconds should al= ways work. =A0The datasheet for the RTL8366S shows that 4 microseconds for = SCL high and low, respectively, are the minimum, so it's even a bit faster. So that's "set SDA and toggle SCA" total? > Register access transfers 5 bytes (command, address*2, data*2) plus the a= ck bits, plus start and stop, for a total of 5*(8+1) + 2 =3D 47 clock cycle= s. At 100 kHz, that's 470 microseconds, with a delay of 8 ms per cycle it's= 376 microseconds. Right. > We could try and see how much quicker we can make the transaction, but I = think even at an order of magnitude faster, polling 2*5 PHY registers, it's= taking up too much CPU. =A0And looking at the MIB stats registers, we're f= acing the same question. Again, right. At this point we likely should just require preemption if we're going to try tinkering with this stuff. >> Sorry, but there has to be a better way to do this. Is it possible to >> just only poll a minimal set of PHY registers each second, rather than >> polling them all? > There is RTL8366RB_PLSR_BASE which has a byte per port, giving link statu= s and speed. =A0We could either forgo the generic PHY code completely, or d= o just the status check ourselves. It wouldn't be the first time that a custom PHY is used, right? :) One byte per port for link status and speed is going to be a lot nicer to deal with. The delay is still insanely long, but it's better than polling all of those status registers. So yes, it may be worthwhile just implementing a custom PHY interface in that file and using that, rather than using ukphy. Although ukphy works, it takes a long, long time to do anything. Re: MIB stats. That's going to have the same problem, but we can likely deal with it by simply doing it from userspace where the kernel _can_ interrupt. :) > I'm of two minds whether reusing the miibus code really is a good idea. = =A0The problem I have with it is mainly that it assumes that there is a str= uct ifnet that the miibus is attached to, and that that ifnet has exactly o= ne running phy. =A0So in my current implementation, I've simply created one= ifnet for each of the five ports that have PHYs on them. I personally think your current method of doing it is fine. The switch driver is small, it's reusing the media handling infrastructure; it doesn't look like you'll have to do much to write a custom PHY to replace ukphy. > On the other hand, I would hate to duplicate media handling code from ukp= hy and that infrastrucure inside the switch driver. > > At any rate, we should make PHY status polling and the MIB stats polling = optional (e.g. off, on demand, periodic), so users can decide if and when t= hey need it. > > I'll try and catch up with your git branch today. Thanks. I'll look at your subsequent email (iicbb_ack()) in a moment. I think the short-term way to move forward is to include a bare-bones replacement PHY just for that switch and disable MIB stats polling. That should be enough for the short term. I'd like to try and wrap this up so we can move onto other areas of the switch stuff - the management tool, the switch bus backend (ie, having a switch driver sit on either i2c, spi, miibus, which physical port does it hang off of, etc.) and looking at including other switch devices (ar8216/ar8316 at least to begin with.) Hm, and I also need to see whether it's worthwhile keeping the vlangroup config method, or whether the ar8216/ar8316 (and the others supported in zrouter) really want to support a set of VLANs per port. The AR8316 datasheet describes how it works - there's a table of known VLANs and a bitmap in each VLAN entry describing which ports are able to be used. There's also a way to configure port isolation, and the ingres/egres port is configured by a magic 2 byte header added to each ethernet frame. I don't know what the other switches offer. It's possible we need to support both - so we'll need a capability bit, identifying which API is to be used. So there's still lots to do. :) Adrian