Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please enable CONFIG_ENC28J60=m #795

Closed
RadekHvizdos opened this issue Feb 4, 2015 · 69 comments
Closed

Please enable CONFIG_ENC28J60=m #795

RadekHvizdos opened this issue Feb 4, 2015 · 69 comments

Comments

@RadekHvizdos
Copy link

With 3.18 we have moved to device tree based configuration, so we no longer need to put SPI connection specific information into a board file. Could we now enable ENC28J60 as a module so that both armv6 and amrv7 distribution kernels support this ethernet controller?

http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=18397

Thanks!

@popcornmix
Copy link
Collaborator

Looks okay.

@pelwell
Copy link
Contributor

pelwell commented Feb 4, 2015

Ask me nicely and I'll create you an overlay to get it loaded.

@RadekHvizdos
Copy link
Author

Pretty please :)

You would make my day.

popcornmix added a commit to raspberrypi/firmware that referenced this issue Feb 8, 2015
See: raspberrypi/linux#782

kernel: i2c: Fix grabbing lock from atomic context in i2c driver
See: raspberrypi/linux#780

kernel: Add Add ENC28J60 SPI ethernet module
See: raspberrypi/linux#795
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Feb 8, 2015
See: raspberrypi/linux#782

kernel: i2c: Fix grabbing lock from atomic context in i2c driver
See: raspberrypi/linux#780

kernel: Add Add ENC28J60 SPI ethernet module
See: raspberrypi/linux#795
@popcornmix
Copy link
Collaborator

The module is enabled in latest rpi-update kernel.

@DougieLawson
Copy link

Thanks a million. That makes adding the eth0 on my A+ so much easier.

popcornmix added a commit to raspberrypi/firmware that referenced this issue Feb 8, 2015
See: raspberrypi/linux#782

kernel: config: Enable IP_NF_TARGET_CLUSTERIP
See: raspberrypi/linux#812

kernel: config: enable ENC28J60 SPI ethernet module
See: raspberrypi/linux#795
@pelwell
Copy link
Contributor

pelwell commented Feb 9, 2015

I haven't forgotten the overlay - I will get back to it eventually.

popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Feb 9, 2015
See: raspberrypi/linux#782

kernel: config: Enable IP_NF_TARGET_CLUSTERIP
See: raspberrypi/linux#812

kernel: config: enable ENC28J60 SPI ethernet module
See: raspberrypi/linux#795
@gajdipajti
Copy link

Wow, this is really good news.

@pelwell
Copy link
Contributor

pelwell commented Feb 27, 2015

The overlay and slightly tweaked module are now in the rpi-3.18.y branch. Build with 'dtbs' as a make target, and copy arch/arm/boot/dtbs/enc28j60-overlay.dtb to /boot/overlays, add 'dtoverlay=enc28j60' and reboot.

@popcornmix
Copy link
Collaborator

@pelwell's overlay is in latest rpi-update firmware.

popcornmix added a commit to raspberrypi/firmware that referenced this issue Feb 28, 2015
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Feb 28, 2015
@RadekHvizdos
Copy link
Author

Thanks a lot guys!

@pelwell
Copy link
Contributor

pelwell commented Mar 2, 2015

Are you happy to close this?

@pelwell
Copy link
Contributor

pelwell commented Mar 6, 2015

Closing for lack of response.

@pelwell pelwell closed this as completed Mar 6, 2015
@RadekHvizdos
Copy link
Author

Hi pelwell,
I am sorry, but I have not been available to test the implementation until now. I have tried it tonight with mixed results. The device tree overlay loads the kernel module, but the network interface does not work. It is as if the cable is not plugged in. I suspect the issue is with missing IRQ definitions in the overlay; any chance to investigate this?

Thank you and the team for your help so far.

eth1      Link encap:Ethernet  HWaddr 8e:41:c9:c3:dc:0f
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ethtool eth1
Settings for eth1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: No
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: No
        Speed: 10Mb/s
        Duplex: Half
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: off
        MDI-X: Unknown
        Current message level: 0x00000036 (54)
                               probe link ifdown ifup

@gajdipajti
Copy link

Same here, dmesg:

bcm2708_spi 20204000.spi: master is unqueued, this is deprecated
enc28j60 spi0.0: enc28j60 Ethernet driver 1.01 loaded
net eth0: enc28j60 driver registered
bcm2708_spi 20204000.spi: SPI Controller at 0x20204000 (irq 80)
net eth0: link down
net eth0: normal mode
net eth0: multicast mode

$ ip addr

eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
  link/ether 1e:3e:ab:b3:26:c8 brd ff:ff:ff:ff:ff:ff

@pelwell
Copy link
Contributor

pelwell commented Mar 6, 2015

I don't have a setup to test this. @DougieLawson, can you comment?

@DougieLawson
Copy link

Hi Phil,

I'm not sure my hardware is working, I've run it up on an Arduino and it doesn't appear to work there. So I have a new one being shipped from China (don't you love eBay).

When I get that I'll test it with the Arduino then on my A+.

@RadekHvizdos
Copy link
Author

Could we re-open this bug until we have a working implementation?

Thanks.

@DougieLawson
Copy link

My replacement hardware arrived today. I've tested this with Linux aplus 3.18.9+ #768 and it is not working.

I'll build a new 3.18.9 kernel tomorrow (with the patched version of bcm2708.c) and give that a try.

@DougieLawson
Copy link

I've got the hardware. I can't get it to work at all.

@pelwell
Copy link
Contributor

pelwell commented Mar 25, 2015

Can you elaborate? That doesn't give us much to work with.

@DougieLawson
Copy link

The interface appears to be active, I can assign a hw MAC address, DHCP (I'm running dhcpcd not isc-dhcp-client) fails to get a IP assigned by my router so gives it a 169.254.xxx.yyy address.

There's green and a winking orange light, the switch has a green light (the cable is known to be good as I've tested it with my 2B).

I can ping the local side of the interface, I can't send traffic out through my router. I can't ping in from the network.

That's running a kernel with the old hack for bcm2708.c and with the DT disabled.
Same effect with DT and your overlay.
Same effect with DT and my hacked full system DTB.

With this new hardware I've not tried it on my Arduino, but it's fresh from the Chinese ebayer that I bought it from.

@pelwell
Copy link
Contributor

pelwell commented Mar 25, 2015

Thanks - that's much clearer. Unfortunately I don't think there's much I can do here, unless somebody can narrow down where the problem is.

@gajdipajti
Copy link

@DougieLawson what does dmesg or ip addr show, is the cable plugged in?

@RadekHvizdos
Copy link
Author

Hi all,

Thank you for your assistance. The new overlay is working fine. I am getting reasonable throughput (386kB/s average, with peeks over 400kB/s) without any issues so far.

I have only tested the blob posted by pelwell, as the stock firmware has not been updated yet, and my Debian system can't compile the source (has old DT compiler). Hopefully the firmware will get updated soon so that we can close this topic.

Thanks again.

@RadekHvizdos
Copy link
Author

Hi all,

I was able to compile the latest DT overlay source and confirm it is working. I have also looked at SPI clock with an oscilloscope.
The default in DT is currently configured with spi-max-frequency = <12000000> as the default. But this is translated to 7.8MHz SPI clock as visible on my scope. According to http://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md, the SPI driver can only accept power of two integer divisors which results in the following possible SPI clock frequencies:

cdiv speed
2 125.0 MHz
4 62.5 MHz
8 31.2 MHz
16 15.6 MHz
32 7.8 MHz
64 3.9 MHz
128 1953 kHz
256 976 kHz
512 488 kHz
1024 244 kHz
2048 122 kHz
4096 61 kHz
8192 30.5 kHz
16384 15.2 kHz
32768 7629 Hz

This is working for most people, but the errata sheet for ENC28j60 describes a silicon bug for some revisions of this IC:

When the SPI clock from the host microcontroller is run at frequencies of less than 8 MHz, reading or writing to the MAC registers may be unreliable.

Work around
Two work arounds are presented; others may be available.

  1. Run the SPI at frequencies of at least 8 MHz.
  2. Generate an SPI clock of 25/2 (12.5 MHz), 25/3 (8.333 MHz), 25/4 (6.25 MHz),25/5 (5 MHz), etc., and synchronize with the 25 MHz clock entering OSC1 on the ENC28J60. This could potentially be accomplished by feeding the same 25 MHz clock into the ENC28J60 and host controller. Alternatively, the host controller could potentially be clocked off of the CLKOUT output of the ENC28J60.

Current default does not meet this requirement.

I propose to increase the default to 20000000 (chip maximum), which sets the SPI clock to 15.6 MHz (confirmed on the scope), well above the silicon bug. This has a side benefit of increasing the throughput from 386kB/s to 540kB/s on my Model A+. Perhaps some time in the future the divisor restriction will be lifted to allow us to use full 20MHz SPI clock.

I believe this would be a reasonable default; one can always lower the frequency by changing the overlay parameter.

Thanks

@msperl
Copy link
Contributor

msperl commented Mar 28, 2015

well - there is a patch in the pipeline for the spi-bcm2835 driver that should also handle this case.
it would mean that the clock-divider can be a multiple of 2 not a power of 2.
When it gets accepted into the kernel - probably with 4.1 - then we can backport it also into the foundation kernel.

But note that for me 20MHz did not work on my breadboard setup with multiple SPI devices - I am using 10MHz and there it works fine!

@pelwell
Copy link
Contributor

pelwell commented Mar 28, 2015

If you can point me at the patch, which must be for spi-bcm2835.c, then we may apply it to spi-bcm2708.c, i.e. the driver used by the stock RPi kernels.

@notro
Copy link
Contributor

notro commented Mar 28, 2015

[PATCH] SPI: BCM2835: clock divider can be a multiple of 2: https://www.marc.info/?l=linux-spi&m=142675575809112&w=3

@msperl
Copy link
Contributor

msperl commented Mar 28, 2015

The bcm2835 is now also loadable as a module with the right overlay - this was done to keep the development upstream...

@RadekHvizdos
Copy link
Author

Hi all,

I guess the SPI clock issue will take a bit longer to address. Let's keep the existing default for now.

@pelwell, could you please update the binary firmware with latest DT overlay?

Thanks

@popcornmix
Copy link
Collaborator

A firmware build is in progress, so whatever has been checked in will appear in next rpi-update.

popcornmix added a commit to raspberrypi/firmware that referenced this issue Apr 2, 2015
See: raspberrypi/linux#766

kernel: Guard fiq_fsm_spin_lock with fiq_enable check
See: raspberrypi/linux#913

kernel: BCM270x_DT: Add interrupt pin to enc28j60-overlay
See: raspberrypi/linux#795

kernel: Add Device Tree support for RPi-DAC
See: raspberrypi/linux#916

firmware: image_fx: Preserve the DATACORRUPT flag in the generated deinterlaced frame

firmware: image_encode: Send ABORT_ENCODE when flushing codec to avoid a hang

firmware: hdmi: Add config options for setting MAI threshold and dma priority
See: http://forum.kodi.tv/showthread.php?tid=222061

firmware: gencmd: Add command for querying if hvs asserts have occurred
See: #407
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Apr 2, 2015
See: raspberrypi/linux#766

kernel: Guard fiq_fsm_spin_lock with fiq_enable check
See: raspberrypi/linux#913

kernel: BCM270x_DT: Add interrupt pin to enc28j60-overlay
See: raspberrypi/linux#795

kernel: Add Device Tree support for RPi-DAC
See: raspberrypi/linux#916

firmware: image_fx: Preserve the DATACORRUPT flag in the generated deinterlaced frame

firmware: image_encode: Send ABORT_ENCODE when flushing codec to avoid a hang

firmware: hdmi: Add config options for setting MAI threshold and dma priority
See: http://forum.kodi.tv/showthread.php?tid=222061

firmware: gencmd: Add command for querying if hvs asserts have occurred
See: raspberrypi/firmware#407
@RadekHvizdos
Copy link
Author

Works like a charm!

@AMelbye
Copy link

AMelbye commented Apr 19, 2015

Hi, I've been trying for days now to make this device work, this thread has gotten me a lot closer, but I'm still not quite there.

I've done the following:

  1. created enc28j60-overlay.dts, entered the text posted by Pelwell and copied it to the /boot/overlays directory
  2. connected the module
  3. entered the following in /boot/config.txt:
    dtdebug=1
    dtparam=spi=on
    dtoverlay=enc28j60,int_pin=25

I get the following error message: "failed to load overlay 'enc28j60'". I've tried changing the filename of the overlay to things like enc28j60.dts, changing the extention to .dtb etc. but it didn't help

What am I doing wrong? I'm on kernel 3.18.7+

I've probably missed something pretty basic, I'm learning as I go. Could you please point me in the right direction?

@gajdipajti
Copy link

Update your kernel with sudo rpi-update, and you will get the latest kernel with the fixed overlay.
OR you can download just the overlay from here: https://github.com/Hexxeh/rpi-firmware/tree/master/overlays

@pelwell
Copy link
Contributor

pelwell commented Apr 19, 2015

You need to find a suitable version of dtc - the Device Tree compiler - to convert the .dts into a .dtb. You should really read the documentation here - it will save you a lot of time.

You can also download from here: https://github.com/raspberrypi/firmware/blob/master/boot/overlays/enc28j60-overlay.dtb

@madarax64
Copy link

Hey all,
Sorry about posting this when the issue is closed, but I can't seem to figure out how to set a fixed MAC address for this module. Every time I reboot I get a new MAC. I'm on the latest Jessie-Lite image, which has dhcpcd in it. Normally, adding hwaddr ether xx:xx:xx:xx:xx:xx to /etc/network/interfaces would fix this, but that file has relinquished control of the interfaces to dhcpcd which is giving me serious trouble.
Any help would be highly appreciated. Thanks!

@gajdipajti
Copy link

Hello, i wrote a shell script as a workaround, and added it to /etc/init.d/mac.sh:

#!/bin/sh
ifconfig eth0 down hw ether 00:11:22:33:44:66
ifconfig eth0 up 

Then sudo chmod +x /etc/init.d/mac.sh && sudo update-rc.d mac.sh defaults

But it would be a nice feature to use the Serial from /proc/cpuinfo

@msperl
Copy link
Contributor

msperl commented Jan 12, 2016

you could probably also create a udev rule to handle that for you, but do not ask about details how it works, but this maybe as a hint:
https://wiki.archlinux.org/index.php/MAC_address_spoofing#Method_2:_systemd-udevd

@madarax64
Copy link

Thanks, @gajdipajti , this workaround works (no pun intended). Incidentally I followed the steps from your blog https://gajdicookbook.wordpress.com to get the whole thing up and running :-) However, I was hoping for another solution, say some hidden device-tree binding for getting this done, so I could just specify the MAC address right in the .dts file or even in the dtoverlay=... directive in config.txt

Thanks @msperl , I'd seen this but it seems to assume that the device has a MAC address of xx:xx:xx:xx:xx:xx which you're trying to spoof into yy:yy:yy:yy:yy:yy. The issue here is that its impossible (at least to me) to determine what the MAC address the module got at boot-time (since its different on every boot), so I can't write a udev rule that essentially depends on knowledge I won't have :-) However, you've given me an idea. It just might be possible to use the driver as the matching attribute rather than the permanent MAC address xx:xx:xx:xx:xx:xx. Since in theory there will be only one device for which the enc28j60 kernel module is loaded, then maybe the rule can be adjusted to target that...I'll give that a shot and let you know how it goes. Thanks!

@DougieLawson
Copy link

Hi Phil,

I did much the same as Tamas. I've got a script that picks up the RPi serial number, prefixes that with B8:27:EB and issues a ifconfig eth0 ether B8:27:EB:xx:xx:xx

That makes it look like a real Raspberry Pi to anything that scans my network.
When I can get connected to my home VPN (can't do that from here due to the corporate firewall) I'll post a copy of my scruffy script.

Regards, Dougie

@msperl
Copy link
Contributor

msperl commented Jan 12, 2016

You probably could filter on the driver or on the first few bits of the mac - the driver uses some defaults pattern - you still need to figure out what it is... - or you filter on the driver type or similar (which - I believe is possible)

@msperl
Copy link
Contributor

msperl commented Jan 12, 2016

I guess the filter: DRIVERS=="enc28j60" instead of ATTR{address}=="XX:XX:XX:XX:XX:XX"should do the trick...
You could also check on the spi chip-select you have used with KERNELS=="spi*.0"

@DougieLawson
Copy link

#!/bin/bash
exit 0
raspberry="B8:27:EB:"
cpuid=$(cat /proc/cpuinfo | grep Serial | cut -c 21-26 | sed
's/\(..\)/\1:/g')
ifconfig eth0 hw ether $raspberry$cpuid

On 12 Jan 2016 4:48 pm, "msperl" [email protected] wrote:

I guess the filter: DRIVERS=="enc28j60" instead of
ATTR{address}=="XX:XX:XX:XX:XX:XX"should do the trick...
You could also check on the spi chip-select you have used with
KERNELS=="spi*.0"


Reply to this email directly or view it on GitHub
#795 (comment).

@DougieLawson
Copy link

I run that in /etc/network/if-pre-up.d on a system that doesn't have
raspberry-net-mods so that network-manager still works.
On 12 Jan 2016 5:24 pm, "Dougie Lawson" [email protected] wrote:

#!/bin/bash
exit 0
raspberry="B8:27:EB:"
cpuid=$(cat /proc/cpuinfo | grep Serial | cut -c 21-26 | sed
's/\(..\)/\1:/g')
ifconfig eth0 hw ether $raspberry$cpuid

On 12 Jan 2016 4:48 pm, "msperl" [email protected] wrote:

I guess the filter: DRIVERS=="enc28j60" instead of
ATTR{address}=="XX:XX:XX:XX:XX:XX"should do the trick...
You could also check on the spi chip-select you have used with
KERNELS=="spi*.0"


Reply to this email directly or view it on GitHub
#795 (comment).

@nickdesaulniers
Copy link
Contributor

nickdesaulniers commented Jun 23, 2016

Maybe a noob question, but can these be daisy chained, or do I need to make changes to my DTS?

Also, does the DTS tell you how the enc28j60 should be wired?

@pelwell
Copy link
Contributor

pelwell commented Jun 23, 2016

Please don't re-open closed issues for questions like this - use the Forums.

neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
See: raspberrypi/linux#766

kernel: Guard fiq_fsm_spin_lock with fiq_enable check
See: raspberrypi/linux#913

kernel: BCM270x_DT: Add interrupt pin to enc28j60-overlay
See: raspberrypi/linux#795

kernel: Add Device Tree support for RPi-DAC
See: raspberrypi/linux#916

firmware: image_fx: Preserve the DATACORRUPT flag in the generated deinterlaced frame

firmware: image_encode: Send ABORT_ENCODE when flushing codec to avoid a hang

firmware: hdmi: Add config options for setting MAI threshold and dma priority
See: http://forum.kodi.tv/showthread.php?tid=222061

firmware: gencmd: Add command for querying if hvs asserts have occurred
See: raspberrypi#407
@matiaspl
Copy link

I've just hit the very same bug as @DougieLawson "transmit queue 0" after 250-300 seconds after bootup. The interface looses it's DHCP-acquired IP (seems to drop to the private 169.254 class for whatever reason) and stops responding.

This is observed on the original RPi B (256M), newest kernel and overlays via rpi-update, stable Raspbian, module connected with int line on the default GPIO25, 15 cm cables. Has anyone found a reason for this to happen or even better - a solution?

@matiaspl
Copy link

There was a question on the forum about a very similar looking issue but unfortunately it didn't get any response (https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=187567)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests