Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => A13 => Topic started by: leo on December 03, 2012, 05:43:03 PM

Title: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: leo on December 03, 2012, 05:43:03 PM
Hi,
i have proplems enabling the lan interface (MOD-ENC28J60 UEXT) over spi.
I compiled the kernel with active spi and the the ENC28J60 driver as a module.

'dmesg | grep spi' told me:

[    0.170000] [spi]: sw spi init !!
[    0.170000] [spi]: sw spi init fetch spi0 uning configuration failed
[    0.180000] [spi]: Get spi devices number failed
[    0.180000] [spi]: register spi devices board info failed
[    0.190000] [spi]: drivers/spi/spi_sunxi.c(L1871) get spi 2 para failed, err code = -4
[    0.190000] [spi]: source = sdram_pll_p, src_clk = 408000000, mclk 102000000
[    0.200000] [spi]: allwinners SoC SPI Driver loaded for Bus SPI-2 with 1 Slaves attached
[    0.210000] [spi]: [spi-2]: driver probe succeed, base dc8aa000, irq 12, dma_id 2!


'modprobe enc28j60' works but i cannot activate the interface afterwards. Probably i have to connect/register the ethernet driver with the spi bus but i have no idea how to do that. My skills in kernel hacking are very limited.
Can someone point out the way (or code) to enable the network interface?

Some more informations...

uname -a

Linux debian 3.0.52 #2 PREEMPT Mon Dec 3 13:58:15 CET 2012 armv7l GNU/Linux


Kernel .config

CONFIG_ENC28J60=m
CONFIG_SPI=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_SUN5I=y
CONFIG_SUN5I_SPI_NDMA=y


Kind reguards

Leo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: Fadil Berisha on December 03, 2012, 08:08:46 PM
Hi Leo,

Quote from: leo on December 03, 2012, 05:43:03 PM
I compiled the kernel with active spi and the the ENC28J60 driver as a module.
1st step is OK. You need to pass to kernel also spi device board info. This explain following message:
Quote
[    0.180000] [spi]: register spi devices board info failed
This info need to be included in your <board>.c file. Here is example with pi board: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=18397

Regards
Fadil Berisha

Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: olimex on December 04, 2012, 08:37:35 AM
this is very interesting! as if it works we can make easily A13-MICRO with wired ethernet!
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: leo on December 05, 2012, 04:47:25 PM
Thanks for your hints Fadil.
I followed the instructions from the Raspberry Pi forum but without much success.
I added the following lines to arch/arm/mach-sun5i/core.c:


#include <linux/spi/spi.h>
...
static struct spi_board_info spi_sun5i_info[] __initdata = {
{
.modalias = "enc28j60",
.max_speed_hz = 20000000,
.bus_num = 2,
.chip_select = 0,
.mode = SPI_MODE_0,
}
};
...
spi_register_board_info(spi_sun5i_info, ARRAY_SIZE(spi_sun5i_info));


With this kernel the enc28j60 module is recognized and loaded but i get the following error:


enc28j60 spi2.0: enc28j60 Ethernet driver 1.01 loaded
nc28j60 spi2.0: enc28j60: request irq 0 failed (ret = -16)
enc28j60: probe of spi2.0 failed with error -16


Something seems to be wrong with the IRQ assignment. Here is the corresponding code from
drivers/net/enc28j60.c:


/* Board setup must set the relevant edge trigger type;
* level triggers won't currently work.
*/
ret = request_irq(spi->irq, enc28j60_irq, 0, DRV_NAME, priv);

if (ret < 0) {
if (netif_msg_probe(priv))
dev_err(&spi->dev, DRV_NAME ": request irq %d failed "
"(ret = %d)\n", spi->irq, ret);
goto error_irq;
}


/proc/interrupts seems to be fine but the NIC is missing:


           CPU0       
  0:          0    sw_vic  axp_mfd
  2:        161    sw_vic  serial
  7:        908    sw_vic  sun5i-i2c.0
  8:         36    sw_vic  sun5i-i2c.1
  9:          0    sw_vic  sun5i-i2c.2
12:         55    sw_vic  sun5i-spi
22:       3376    sw_vic  timer0
27:          0    sw_vic  dma_irq
32:       6616    sw_vic  sunxi-mmc
37:          0    sw_vic  nand
39:         25    sw_vic  ehci_hcd:usb2
44:       3867    sw_vic  sunxi lcd0
47:       1925    sw_vic  sunxi scaler0
53:          0    sw_vic  cedar_dev
64:          0    sw_vic  ohci_hcd:usb3


After digging through the Crane Fex Guide i found another sollution. So i
added the following lines and created a new script.bin with:


[spi_devices]
spi_dev_num = 1

[spi_board0]
modalias = "enc28j60"
max_speed_hz = 20000000
bus_num = 2
chip_select = 0
mode = 0


The spi initalization looks perfect now but the error is the same:


[    0.170000] [spi]: sw spi init !!
[    0.170000] [spi]: sw spi init fetch spi0 uning configuration failed
[    0.180000] [spi]: Found 1 spi devices in config files
[    0.190000] [spi]: boards num modalias         max_spd_hz       bus_num  cs   mode
[    0.190000] [spi]: 0          enc28j60         20000000         2        0    0x0   
[    0.200000] [spi]: bus num = 2, spi used = 0
[    0.210000] [spi]: source = sdram_pll_p, src_clk = 408000000, mclk 102000000
[    0.210000] [spi]: allwinners SoC SPI Driver loaded for Bus SPI-2 with 1 Slaves attached
[    0.220000] [spi]: [spi-2]: driver probe succeed, base dc8aa000, irq 12, dma_id 2!
...
[    3.630000] enc28j60 spi2.0: enc28j60 Ethernet driver 1.01 loaded
[    3.720000] enc28j60 spi2.0: enc28j60: request irq 0 failed (ret = -16)
[    3.780000] enc28j60: probe of spi2.0 failed with error -16


So I'm stuck again. Whats the problem now and how to fix it?

Kind regards

Leo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on December 14, 2012, 05:31:35 PM
Hi Leo,

try to add

.irq = SW_INT_IRQNO_SPI02,

to you spi_board_info structure.

Let me know if it works with that.

BR
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lukas on December 16, 2012, 08:20:12 PM
Modification in "script.bin" is enough for me to make module load. No need for changing "core.c". But I'm stuck with the same error:
nc28j60 spi2.0: enc28j60: request irq 0 failed (ret = -16)
My kernel is 3.4.19.
When I make modifications in "core.c" compilers show errors in this line:
spi_register_board_info(spi_sun5i_info, ARRAY_SIZE(spi_sun5i_info));

Best regards,
Lukas
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: leo on December 17, 2012, 11:37:09 AM
Hi Lorenzo,

thank you. I added your code to the spi_board_info struct but still get an error. But now, the modul complains about IRQ 12 (the same IRQ of the spi controller) and not IRQ 0.


[    3.700000] enc28j60 spi2.0: enc28j60 Ethernet driver 1.01 loaded
[    3.760000] enc28j60 spi2.0: enc28j60: request irq 12 failed (ret = -16)
[    3.780000] enc28j60: probe of spi2.0 failed with error -16


According to the request_irq man page the error -16 means:
QuoteEBUSY There exists a registered handler for the requested interrupt.

Is it a problem related to shared interrupts?

Thanks in advance.

@Lukas

Did you put it in the right location?


void __init sw_core_init(void)
{
sw_pdev_init();
spi_register_board_info(spi_sun5i_info, ARRAY_SIZE(spi_sun5i_info));
}


Kind regards

Leo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lukas on December 17, 2012, 11:51:20 PM
Hi Leo,
Thank you for your info. You were right, I was putting it in wrong place. Now everything compiles fine.
I changed IRQ in spi info struct to 3 (free according to /proc/interrupts) and module has been registered successfully.
"ifconfig -a" shows "eth0" but that's everything. Ping doesn't work, activity LED just blinks funny :(

Best regards,
Lukas
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on December 18, 2012, 12:21:34 PM
Hi Lukas,

I think that the problem is that ENC28J60 requires an interrupt to work correctly. The interrupt must be connected to an external interrupt of A13, but the problem is that there is no information about how to manage them. So, unless we use the interrupt 0 (NMI) we're stucked.

I confirm that to configure the enc28j60 you can only change the script.txt file, because the function 'spi_register_board_info' is called inside the spi_sunxi.c file.

If I found something useful, I'll let you know.

BR
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on December 20, 2012, 06:27:41 PM
Hi,

good news here. I found how to enable enc28j60 interrupt and make the module (almost) working... Now I need your help to understand why rx always give me errors...

To make enc28j60 work undo mach-sun5i/core.c changes. You only need script.bin. Configure spi section of script.txt as follow:


[spi_devices]
spi_dev_num = 1

[spi1_para]
spi_used = 0
spi_cs_bitmap = 1
spi_cs0 = port:PG09<2><default><default><default>
spi_cs1 = port:PG13<2><default><default><default>
spi_sclk = port:PG10<2><default><default><default>
spi_mosi = port:PG11<2><default><default><default>
spi_miso = port:PG12<2><default><default><default>

[spi2_para]
spi_used = 1
spi_cs_bitmap = 3
spi_cs0 = port:PE00<4><default><default><default>
spi_cs1 = port:PB10<2><default><default><default>
spi_sclk = port:PE01<4><default><default><default>
spi_mosi = port:PE02<4><default><default><default>
spi_miso = port:PE03<4><default><default><default>

[spi_board0]
modalias = "enc28j60"
max_speed_hz = 20000000
chip_select = 0
bus_num = 2
mode = 0
spi_irq = port:PB04<6><default><default><default>


You will enable EINT18 on PB4 of your OlinuXino (GPIO alternate function 6). Now you need to make a hardware hack and connect the enc28j60 IRQ to this pin. You can easily do that by connecting the IRQ to PIN8 of GPIO connector.

Now you need to patch the enc28j60 module. I don't know how to attach a file, so here is the patch:


diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c
index 2837ce2..83ce803 100644
--- a/drivers/net/enc28j60.c
+++ b/drivers/net/enc28j60.c
@@ -31,8 +31,35 @@

#include "enc28j60_hw.h"

-#define DRV_NAME "enc28j60"
-#define DRV_VERSION "1.01"
+#include <mach/irqs.h>
+#include <mach/system.h>
+#include <mach/hardware.h>
+#include <mach/sys_config.h>
+
+#define DRV_NAME "enc28j60"
+#define DRV_VERSION "1.01"
+#define ENC28J60_IRQ_NO      (18)
+#define PIO_BASE_ADDRESS (PIO_BASE)
+#define PIO_RANGE_SIZE          (0x400)
+#define PIO_INT_STAT_OFFSET     (0x214)
+#define PIO_INT_CTRL_OFFSET     (0x210)
+
+typedef enum {
+     PIO_INT_CFG0_OFFSET = 0x200,
+     PIO_INT_CFG1_OFFSET = 0x204,
+     PIO_INT_CFG2_OFFSET = 0x208,
+     PIO_INT_CFG3_OFFSET = 0x20c,
+} int_cfg_offset;
+
+typedef enum{
+        POSITIVE_EDGE = 0x0,
+        NEGATIVE_EDGE = 0x1,
+        HIGH_LEVEL = 0x2,
+        LOW_LEVEL = 0x3,
+        DOUBLE_EDGE = 0x4
+} ext_int_mode;
+
+static int int_cfg_addr[]={PIO_INT_CFG0_OFFSET,PIO_INT_CFG1_OFFSET,PIO_INT_CFG2_OFFSET, PIO_INT_CFG3_OFFSET};

#define SPI_OPLEN 1

@@ -80,6 +107,9 @@ static struct {
u32 msg_enable;
} debug = { -1 };

+static user_gpio_set_t gpio_int_info[1];
+static void* __iomem gpio_addr = NULL;
+
/*
  * SPI read buffer
  * wait for the SPI transfer and copy received data to destination
@@ -1309,10 +1339,21 @@ static void enc28j60_tx_work_handler(struct work_struct *work)
enc28j60_hw_tx(priv);
}

-static irqreturn_t enc28j60_irq(int irq, void *dev_id)
+static void enc28j60_clear_penirq(struct spi_device *spi)
{
- struct enc28j60_net *priv = dev_id;
+ int reg_val;
+ reg_val = readl(gpio_addr + PIO_INT_STAT_OFFSET);
+       
+ if((reg_val = (reg_val&(1<<(ENC28J60_IRQ_NO))))){
+ dev_info(&spi->dev, DRV_NAME "==ENC28J60_CLEAR_IRQ_NO=\n");
+ writel(reg_val,gpio_addr + PIO_INT_STAT_OFFSET);
+ }
+ return;
+}
+

+static irqreturn_t enc28j60_irq(int irq, void *dev_id)
+{
/*
* Can't do anything in interrupt context because we need to
* block (spi_sync() is blocking) so fire of the interrupt
@@ -1320,8 +1361,27 @@ static irqreturn_t enc28j60_irq(int irq, void *dev_id)
* Remember that we access enc28j60 registers through SPI bus
* via spi_sync() call.
*/
- schedule_work(&priv->irq_work);
+
+ struct enc28j60_net *priv = dev_id;
+ int reg_val;
+ struct spi_device *spi = priv->spi;

+ dev_info(&spi->dev, DRV_NAME " ==========------ENC28J60 Interrupt-----============\n");
+
+ reg_val = readl(gpio_addr + PIO_INT_STAT_OFFSET);
+
+ /* Debug info */
+ //dev_info(&spi->dev, DRV_NAME " reg: %08X\n", reg_val);
+
+ if (reg_val&(1<<(ENC28J60_IRQ_NO))) {
+ dev_info(&spi->dev, DRV_NAME " ==ENC28J60 IRQ OK=\n");
+ writel(reg_val&(1<<(ENC28J60_IRQ_NO)), gpio_addr + PIO_INT_STAT_OFFSET);
+ schedule_work(&priv->irq_work);
+ } else {
+ dev_info(&spi->dev, DRV_NAME " Interrupt not for enc28j60 \n");
+ return IRQ_NONE;
+ }
+
return IRQ_HANDLED;
}

@@ -1546,6 +1606,12 @@ static int __devinit enc28j60_probe(struct spi_device *spi)
struct net_device *dev;
struct enc28j60_net *priv;
int ret = 0;
+ int gpio_int_hdle = 0;
+ __u32 reg_num = 0;
+ __u32 reg_addr = 0;
+ __u32 reg_val = 0;
+
+ spi->irq = SW_INT_IRQNO_PIO;

if (netif_msg_drv(&debug))
dev_info(&spi->dev, DRV_NAME " Ethernet driver %s loaded\n",
@@ -1585,7 +1651,44 @@ static int __devinit enc28j60_probe(struct spi_device *spi)
/* Board setup must set the relevant edge trigger type;
* level triggers won't currently work.
*/
- ret = request_irq(spi->irq, enc28j60_irq, 0, DRV_NAME, priv);
+ gpio_int_hdle = gpio_request_ex("spi_board0", "spi_irq");
+ if(!gpio_int_hdle) {
+ dev_info(&spi->dev, DRV_NAME " enc28j60 spi_irq param load failed. \n");
+ }
+ else {
+ dev_info(&spi->dev, DRV_NAME " enc28j60 spi_irq param load successfully. \n");
+ }
+
+ gpio_addr = ioremap(PIO_BASE_ADDRESS, PIO_RANGE_SIZE);
+ dev_info(&spi->dev, DRV_NAME " %s, gpio_addr = 0x%x. \n", __func__, (unsigned int)gpio_addr);
+ if(!gpio_addr) {
+ dev_info(&spi->dev, DRV_NAME " no available resources (0x%x).\n", (unsigned int)gpio_addr);
+ }
+
+ gpio_get_one_pin_status(gpio_int_hdle, gpio_int_info, "spi_irq", 1);
+ dev_info(&spi->dev, DRV_NAME " %s, %d: gpio_int_info, port = %d, port_num = %d. \n", __func__, __LINE__, \
+                gpio_int_info[0].port, gpio_int_info[0].port_num);
+
+ /* TODO -- this must be done with script param */
+ dev_info(&spi->dev, DRV_NAME " ENC28J60 interrupt configuration\n");
+ reg_num = (ENC28J60_IRQ_NO)%8;
+ reg_addr = (ENC28J60_IRQ_NO)/8;
+ reg_val = readl(gpio_addr + int_cfg_addr[reg_addr]);
+ reg_val &= (~(7 << (reg_num * 4)));
+ reg_val |= (NEGATIVE_EDGE << (reg_num * 4));
+ writel(reg_val,gpio_addr+int_cfg_addr[reg_addr]);
+
+ enc28j60_clear_penirq(spi);
+
+ reg_val = readl(gpio_addr+PIO_INT_CTRL_OFFSET);
+ reg_val |= (1 << (ENC28J60_IRQ_NO));
+ writel(reg_val,gpio_addr+PIO_INT_CTRL_OFFSET);
+
+ udelay(1);
+
+ /* Request for PIO shared interrupt */
+ ret = request_irq(SW_INT_IRQNO_PIO, enc28j60_irq, IRQF_TRIGGER_FALLING | IRQF_SHARED, DRV_NAME, priv);
+ //ret = request_irq(spi->irq, enc28j60_irq, 0, DRV_NAME, priv);
if (ret < 0) {
if (netif_msg_probe(priv))
dev_err(&spi->dev, DRV_NAME ": request irq %d failed "



Compile enc28j60 module and load it. You will see some debug on dmesg... This is an alfa version of the patch, so don't worry. The driver and the interrupt seems to work fine, but I have always errors on RX. Transmissions are fine, I can see ARP packets on my network.

In this code you can find all the instructions you need to set an external interrupt on the olinuxino, so this will be very useful for people who wants to use GPIO as external interrupt.

Please Olimex, if there is a better way to publish this pactch, let me know.

Best regards.
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lukas on December 22, 2012, 05:56:21 PM
Hi Lorenzo,
This is great news! Thank you!
With working TouchScreen too, A13 platform will be fully usable for many of us.
Could you pls. explain how to make this "hardware hack"? Where can I find IRQ pin on enc28j60 board?

BR,
Lukas
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on December 23, 2012, 02:58:30 PM
Hi Lukas,

just take a look at the datasheet or the hardware schematics. IRQ pin is indicated by the #INT symbol. You have to connect that signal to PB04 on GPIO connector.

Best regards.
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: mouha on January 04, 2013, 12:17:45 PM
Hi,

Is there a way to retrieve the compiled version and the .bin of this please ?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 04, 2013, 01:04:42 PM
Hi,

do you mean enc28j60.ko and script.bin? What kernel version are you running?

Maybe I can try to give you the binaries...

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: mouha on January 04, 2013, 01:17:49 PM
Quote from: lorenzo on January 04, 2013, 01:04:42 PM
Hi,

do you mean enc28j60.ko and script.bin? What kernel version are you running?

Maybe I can try to give you the binaries...

Lorenzo
Hi Lorenzo,

To get quick access I'm using the Debian_No_X olimex image.
Do I understood well : to retrieve the IRQ I'll also have to connect to the PB04 from GPIO connector ?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 04, 2013, 01:28:28 PM
Hi Mouha,

here is a link (https://dl.dropbox.com/u/96533863/enc28j60.zip) to a file which contains:
- script.bin
- uImage
- a folder named "3.0.52+" which must be put in your /lib/modules folder of rootfs

Yes you must connect #INT pin of enc28j60 to your PB04 (PIN8) of your GPIO connector.

BR
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: leo on January 04, 2013, 03:23:23 PM
Hi Lorenzo,

these are good news after vacation. :)
I tried both ways (your guide/dropbox files) to get the interface working but without much success. The failure is the same with both.
I think I wired everything correct. GPIO PIN 13 on GPIO-2 40pin connector ( PIN 8 ) with Ext 5 on enc28j60 ( #INT ). Without the wire the driver do not show the message: ==ENC28J60_CLEAR_IRQ_NO=

Here are some infos.

kernel spi config:

[    0.170000] [spi]: sw spi init !!
[    0.170000] [spi]: sw spi init fetch spi0 uning configuration failed
[    0.180000] [spi]: Found 1 spi devices in config files
[    0.180000] [spi]: boards num modalias         max_spd_hz       bus_num  cs   mode
[    0.190000] [spi]: 0          enc28j60         20000000         2        0    0x0   
[    0.200000] [spi]: bus num = 2, spi used = 3
[    0.200000] [spi]: source = sdram_pll_p, src_clk = 408000000, mclk 102000000
[    0.210000] [spi]: allwinners SoC SPI Driver loaded for Bus SPI-2 with 1 Slaves attached
[    0.220000] [spi]: [spi-2]: driver probe succeed, base dc8aa000, irq 12, dma_id 2!


on enc28j60 module load:

[    3.700000] enc28j60 spi2.0: enc28j60 Ethernet driver 1.01 loaded
[    3.800000] enc28j60 spi2.0: enc28j60 enc28j60 spi_irq param load successfully.
[    3.800000] enc28j60 spi2.0: enc28j60 enc28j60_probe, gpio_addr = 0xdc8c4800.
[    3.880000] enc28j60 spi2.0: enc28j60 enc28j60_probe, 1670: gpio_int_info, port = 2, port_num = 4.
[    3.890000] enc28j60 spi2.0: enc28j60 ENC28J60 interrupt configuration
[    3.890000] enc28j60 spi2.0: enc28j60==ENC28J60_CLEAR_IRQ_NO=
[    4.000000] net eth0: enc28j60 driver registered


on network initialization:

[   12.350000] enc28j60 spi2.0: enc28j60 ==========------ENC28J60 Interrupt-----============
[   12.350000] enc28j60 spi2.0: enc28j60 ==ENC28J60 IRQ OK=
[   12.360000] net eth0: link up - Half duplex
[   12.550000] enc28j60 spi2.0: enc28j60 ==========------ENC28J60 Interrupt-----============
[   12.550000] enc28j60 spi2.0: enc28j60 ==ENC28J60 IRQ OK=
[   12.860000] enc28j60 spi2.0: enc28j60 ==========------ENC28J60 Interrupt-----============
[   12.860000] enc28j60 spi2.0: enc28j60 ==ENC28J60 IRQ OK=
[   13.070000] enc28j60 spi2.0: enc28j60 ==========------ENC28J60 Interrupt-----============
[   13.070000] enc28j60 spi2.0: enc28j60 ==ENC28J60 IRQ OK=
[   13.190000] enc28j60 spi2.0: enc28j60 ==========------ENC28J60 Interrupt-----============
[   13.190000] enc28j60 spi2.0: enc28j60 ==ENC28J60 IRQ OK=
[   13.250000] enc28j60 spi2.0: enc28j60 ==========------ENC28J60 Interrupt-----============
[   13.250000] enc28j60 spi2.0: enc28j60 ==ENC28J60 IRQ OK=
[   13.550000] enc28j60 spi2.0: enc28j60 ==========------ENC28J60 Interrupt-----============
[   13.550000] enc28j60 spi2.0: enc28j60 ==ENC28J60 IRQ OK=
[   14.330000] enc28j60 spi2.0: enc28j60 ==========------ENC28J60 Interrupt-----============
[   14.330000] enc28j60 spi2.0: enc28j60 ==ENC28J60 IRQ OK=


These above messages last forever on the console.

/proc/interrupts

           CPU0       
  0:          0    sw_vic  axp_mfd
  2:        270    sw_vic  serial
  7:       4032    sw_vic  sun5i-i2c.0
  8:         36    sw_vic  sun5i-i2c.1
  9:          0    sw_vic  sun5i-i2c.2
12:      33399    sw_vic  sun5i-spi
22:      33131    sw_vic  timer0
27:          0    sw_vic  dma_irq
28:       1164    sw_vic  enc28j60
32:      31306    sw_vic  sunxi-mmc
37:          0    sw_vic  nand
39:         27    sw_vic  ehci_hcd:usb2
44:      38880    sw_vic  sunxi lcd0
47:      18988    sw_vic  sunxi scaler0
53:          0    sw_vic  cedar_dev
64:          0    sw_vic  ohci_hcd:usb3


ifconfig with a static ip

eth0      Link encap:Ethernet  HWaddr 96:69:32:dc:50:c9 
          inet addr:192.168.192.215  Bcast:192.168.192.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8 errors:509 dropped:0 overruns:0 frame:128
          TX packets:143 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:6006 (5.8 KiB)
          Interrupt:28


The RX buffer is empty and full of errors. I cannot ping any machine in the network.
Is it a hardware failure or did i something wrong? Any ideas?

Kind Regards
Leo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: mouha on January 04, 2013, 04:02:54 PM
Thanks Lorenzo,
I'll try ASAP and then check that I have - hope not- the same issue as Leo had.
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 04, 2013, 04:54:28 PM
Hi Leo, Mouha

I also have RX errors, because of wrong SPI read when interrupts occurs. I don't know which is the problem, but I haven't solved it yet.
If you try with wireshark sniffing the network you'll se ARP packets from enc28j60, so TX is ok. The problem is the RX side. It seems that memory is somehow corrupted, and data read have no sense. I also tried reducing SPI master clock speed, but I can't get enc28j60 working properly. About SPI speed, please set this parameters as follow:


max_speed_hz = 10000000


because enc28j60 support a maximum spi clock frequency of 10MHz. The script.bin in the zip file already have this parameter set correctly.

Hope that you can help me finding what's wrong with RX.

BR
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 09, 2013, 04:34:05 PM
Hi all,

I've made another step ahead... I patched the module to make half-duplex DMA working (info here http://www.spinics.net/lists/netdev/msg164257.html).
Now RX works, but I still have errors because I've some bytes messed up in the packets, so the transmission can't work.

You can find patch, bin module (3.0.52+ Kernel) and script.bin here:
https://dl.dropbox.com/u/96533863/enc28j60_new.tar.gz

Please try it and help me solving this new issue!

Thank you.
BR
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: mouha on January 09, 2013, 04:58:36 PM
nice  one !

Sorry I didn't have tested yet as I encouter other important that I need to resolve before.
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: leo on January 11, 2013, 03:06:27 PM
Hi Lorenzo,

i tried the patch with the new sunxi kernels (3.0.57 and 3.4.24) released 4 days ago.
I have the same behavior that you describe.
Anyway many thanks again.
I will take a look into it.

Kind Regards

Leo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 11, 2013, 07:11:12 PM
Hi Leo,

do you have any idea if the problem with rx is related to spi, to DMA, or to enc28j60.c? I think it is something in SPI or DMA. It seems that tx bytes aren't messed up, only rx.

Thank you.
BR
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 23, 2013, 01:49:43 PM
Hi Lorenzo,

Can you provide your source code for download? I am gonna try to help. thk
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 23, 2013, 03:17:41 PM
Hi,

here is a link where you can find also the src file of enc28j60:

https://dl.dropbox.com/u/96533863/enc28j60_new_src.tar.gz

Thank you.
BR

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 25, 2013, 04:58:42 AM
Hi,
For the foregoing below am using A13-Olinuxino_Rev_B.sch.

Well, I have seen some errors:

1) script.fex; the correct function for SPI is 3 not 4 and the pins are PE0(SPI2_CS), PE01(SPI2_CLK), PE02(SPI2_MOSI) and PE03(SPI2_MISO):

[spi2_para]
spi_used = 1
spi_cs_bitmap = 1
spi_cs0 = port:PE00<3><default><default><default>
spi_sclk = port:PE01<3><default><default><default>
spi_mosi = port:PE02<3><default><default><default>
spi_miso = port:PE03<3><default><default><default>


2) TXbuff maybe overwrite Rxbuff;
In spi_buf_read() is better to use:

u8 *tx_buf = priv->spi_transfer_buf_tx;
u8 *rx_buf = priv->spi_transfer_buf_rx;


But the original code also works if it is not used more than 4 bytes in tx_buf, is necessary to check every function call enc28j60_mem_read()...  ;D
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 25, 2013, 02:01:16 PM
Hi Viniciusfre,

according to this page http://linux-sunxi.org/A13/PIO, it seems that is the function 4 the correct one. Do you have different information about pin configuration? Why do you say that is the function 3 the correct one?

Are you working on original enc28j60 file or with the patched one? Why rx_buf and tx_buf should overwrite each other? tx_buf point to a different location respect to rx_buf? Am I losing something?

Do you have enc28j60 working with this modification?

Thank you.
BR
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 25, 2013, 03:43:42 PM
Hi,

About pin: http://linux-sunxi.org/Fex_Guide#7.3_.5Bspi2_para.5D (http://linux-sunxi.org/Fex_Guide#7.3_.5Bspi2_para.5D)

Sorry, I was referring to the original enc28j60 file.

u8 *rx_buf = priv->spi_transfer_buf + 4;
u8 *tx_buf = priv->spi_transfer_buf;
...
tx_buf[0] = ENC28J60_READ_BUF_MEM;
tx_buf[1] = tx_buf[2] = tx_buf[3] = 0; /* don't care */

if tx_buf is greater than 4, rx_buf is overwritten. Example: memcpy(x.spi_transfer_buf, data, len); with len>4

I have not enc28j60, i'm just using a radio that is SPI in the bus 2(SPI2), so I thought I could help.  ;D
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 25, 2013, 04:19:24 PM
Oh yes, help will be very appreciated  :D...

The link  http://linux-sunxi.org/Fex_Guide#7.3_.5Bspi2_para.5D it's just a guide, you don't have to refer to that values for pin configuration. Pin functions changes among different cpus.

Ok for tx and rx, but I think that the patched version is not afflicted by this issue.

Thank you.
BR

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 26, 2013, 09:03:48 PM
Hi lorenzo,

You have reason, correct function is 4...   :D

Your patch is ​​also right:

struct spi_transfer t = {
.tx_buf = tx_buf,
.rx_buf = NULL,
.len = SPI_OPLEN,
.cs_change = 1,
};

struct spi_transfer r = {
.tx_buf = NULL,
.rx_buf = data,
.len = len,
.cs_change = 0,
};

due to:

/* check in the __spi_async if use half duplex */
if(t->tx_buf && t->rx_buf)
    return -EINVAL;

right?

But it is better to keep u8 *rx_buf = priv->spi_transfer_buf + 4; u8 *tx_buf = priv->spi_transfer_buf;,
because is safer store in spi_transfer_buf instead of data. The code looks like this:

        u8 *rx_buf = priv->spi_transfer_buf + 4;
u8 *tx_buf = priv->spi_transfer_buf;

struct spi_transfer t = {
.tx_buf = tx_buf,
.rx_buf = NULL,
.len = SPI_OPLEN,
.cs_change = 0,
};

struct spi_transfer r = {
.tx_buf = NULL,
.rx_buf = rx_buf,
.len = len,
.cs_change = 1,
};

struct spi_message msg;
int ret;

tx_buf[0] = ENC28J60_READ_BUF_MEM; // tx_buf[0]=0x3A
tx_buf[1] = tx_buf[2] = tx_buf[3] = 0; /* don't care */

spi_message_init(&msg);
spi_message_add_tail(&t, &msg);
spi_message_add_tail(&r, &msg);
ret = spi_sync(priv->spi, &msg);
if (ret == 0) {
          memcpy(data, &rx_buf[SPI_OPLEN], len);
          ret = msg.status;
}
if (ret && netif_msg_drv(priv))
printk(KERN_DEBUG DRV_NAME ": %s() failed: ret = %d\n",
__func__, ret);

return ret;


Or we could use spi_write_then_read(). What do you think?

Is there still problem in the RX?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 28, 2013, 09:35:25 AM
Hi viniciusfre,

yes, I think you are right. It is better to use spi_transfer_buf instead of data. This morning I'm going to try with this code modification and let you know if something will change.

RX still have problems, maybe it could be something related to DMA.

Thanks.
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 28, 2013, 11:20:25 AM
Hi all,

thanks to the help of viniciusfre my enc28j60 is working fine now!
It looks like it was the data buffer which causes the problems and broke some data in the packet. I think the data buffer is valid only locally, so during the path to the spi it is not valid anymore...

You can find all the files you need here: https://dl.dropbox.com/u/96533863/enc28j60_v1.tar.gz

Please try it and let me know!

Thnak you again!
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 28, 2013, 12:09:15 PM
Hi all,

please use this version: https://dl.dropbox.com/u/96533863/enc28j60_v2.tar.gz

I removed dmesg debug so network is faster and more usable...

Thanks.
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 28, 2013, 02:42:42 PM
Hi Lorenzo.

Nice! ;D It is good news, because I plan to buy this Module for my project.

I was not sure, but I suspected that 'u8 *data' was being overwritten, because it is a pointer variable.

Good!  ;)

Try submit this patch the to linux-mainline or linux-sunxi
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 28, 2013, 03:15:59 PM
Hi viniciusfre,

do you know who is the maintainer of the linux-sunxi kernel?

Thank you again for the help ;) :D

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 28, 2013, 11:30:14 PM
Hi, i think that is Alejandro Mery(amery).

You can submit your patch here: https://groups.google.com/forum/?fromgroups=#!forum/linux-sunxi (https://groups.google.com/forum/?fromgroups=#!forum/linux-sunxi)

others:
http://linux-sunxi.org/Submitting_patches (http://linux-sunxi.org/Submitting_patches)
https://github.com/torvalds/linux/blob/master/Documentation/CodingStyle (https://github.com/torvalds/linux/blob/master/Documentation/CodingStyle)
http://linux-sunxi.org/Mailing_list (http://linux-sunxi.org/Mailing_list)
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: leo on January 30, 2013, 12:35:51 PM
Awesome work!  Thanks a lot!
I tested the patch today with the latest 3.0 und 3.4 kernels and your script.bin
At the beginning everything works like a charm.
Then i started testing with some massive traffic and huge file transfers and ran into troubles.
I tried some flood ping.

At the beginning everything looks good.


eth0      Link encap:Ethernet  HWaddr de:5d:5c:bd:5b:71 
          inet addr:192.168.192.215  Bcast:192.168.192.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:74585 errors:0 dropped:40 overruns:0 frame:0
          TX packets:74131 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7606752 (7.2 MiB)  TX bytes:7264290 (6.9 MiB)
          Interrupt:28


but then...


[  125.900000] [spi]: drivers/spi/spi_sunxi.c(L899) cpu tx data time out!
[  133.050000] ------------[ cut here ]------------
[  133.050000] WARNING: at net/sched/sch_generic.c:255 dev_watchdog+0x2a8/0x2d0()
[  133.060000] NETDEV WATCHDOG: eth0 (enc28j60): transmit queue 0 timed out
[  133.060000] Modules linked in: enc28j60
[  133.070000] [<c003a450>] (unwind_backtrace+0x0/0xfc) from [<c00582a0>] (warn_slowpath_common+0x4c/0x64)
[  133.080000] [<c00582a0>] (warn_slowpath_common+0x4c/0x64) from [<c005834c>] (warn_slowpath_fmt+0x30/0x40)
[  133.090000] [<c005834c>] (warn_slowpath_fmt+0x30/0x40) from [<c0438950>] (dev_watchdog+0x2a8/0x2d0)
[  133.100000] [<c0438950>] (dev_watchdog+0x2a8/0x2d0) from [<c0064b20>] (run_timer_softirq+0x124/0x280)
[  133.100000] [<c0064b20>] (run_timer_softirq+0x124/0x280) from [<c005e4dc>] (__do_softirq+0x88/0x118)
[  133.110000] [<c005e4dc>] (__do_softirq+0x88/0x118) from [<c005e760>] (irq_exit+0x60/0x68)
[  133.120000] [<c005e760>] (irq_exit+0x60/0x68) from [<c002e034>] (asm_do_IRQ+0x34/0x84)
[  133.130000] [<c002e034>] (asm_do_IRQ+0x34/0x84) from [<c0033e48>] (__irq_svc+0x48/0x12c)
[  133.140000] Exception stack(0xc06c7f78 to 0xc06c7fc0)
[  133.140000] 7f60:                                                       00000000 00000001
[  133.150000] 7f80: c06c7fc0 00000000 c06c6000 c0711b44 c06cb414 c06cb40c 40004059 413fc082
[  133.160000] 7fa0: 00000000 00000000 00000000 c06c7fc0 c0035448 c003544c 60000013 ffffffff
[  133.170000] [<c0033e48>] (__irq_svc+0x48/0x12c) from [<c003544c>] (default_idle+0x24/0x28)
[  133.180000] [<c003544c>] (default_idle+0x24/0x28) from [<c00358b0>] (cpu_idle+0x80/0xb4)
[  133.180000] [<c00358b0>] (cpu_idle+0x80/0xb4) from [<c00089d8>] (start_kernel+0x290/0x2e0)
[  133.190000] [<c00089d8>] (start_kernel+0x290/0x2e0) from [<40008054>] (0x40008054)
[  133.200000] ---[ end trace 79ba4c5eeb54235c ]---
[  133.210000] net eth0: link down
[  133.220000] net eth0: link up - Half duplex



eth0      Link encap:Ethernet  HWaddr de:5d:5c:bd:5b:71 
          inet addr:192.168.192.215  Bcast:192.168.192.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:97961 errors:0 dropped:41 overruns:0 frame:0
          TX packets:96774 errors:1 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:9990404 (9.5 MiB)  TX bytes:9483216 (9.0 MiB)
          Interrupt:28


The interface is still working but i get more link down and link up messages and TX errors are counting up.


[ 1153.010000] net eth0: link down
[ 1153.060000] net eth0: link up - Half duplex
[ 1217.300000] [spi]: drivers/spi/spi_sunxi.c(L899) cpu tx data time out!
[ 1225.010000] net eth0: link down
[ 1225.060000] net eth0: link up - Half duplex
[ 1239.410000] [spi]: drivers/spi/spi_sunxi.c(L899) cpu tx data time out!
[ 1245.010000] net eth0: link down
[ 1245.060000] net eth0: link up - Half duplex
[ 1277.360000] [spi]: drivers/spi/spi_sunxi.c(L899) cpu tx data time out!
[ 1285.010000] net eth0: link down
[ 1285.060000] net eth0: link up - Half duplex
[ 1367.720000] [spi]: drivers/spi/spi_sunxi.c(L899) cpu tx data time out!


Is it just a problem with my hardware? Can you please try if you get the same results when flood pinging or sending big files to the board.

Kind Reguards

Leo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 30, 2013, 01:32:33 PM
Hi Leo,

This error did not occur on the driver enc28j60.c, but on the spi_sunxi.c:

spin_lock_irqsave(&aw_spi->lock, flags);
for(; tx_len > 0; --tx_len) {
   writeb(*tx_buf++, base_addr + SPI_TXDATA_REG);
            }
   spin_unlock_irqrestore(&aw_spi->lock, flags);
   while(aw_spi_query_txfifo(base_addr)&&(--poll_time > 0) );/* txFIFO counter */
   if(poll_time <= 0) {
   spi_wrn("cpu tx data time out!\n");
}


Means that a timeout happened, poll_time reached zero.

This is because not being used DMA:

if(t->len <= BULK_DATA_BOUNDARY) {


Maybe now you can increase spi speed, .max_speed_hz = 20000000,
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 30, 2013, 01:52:57 PM
Hi viniciusfre, Leo

right viniciusfre, and I also have that kind of error that slow down the network performance.
Do you think that SPI sent without DMA is an issue, or the code is correct?

Why it shouldn't use DMA?

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 30, 2013, 02:01:35 PM
The platform driver spi_sunxi.c uses DMA only when t->len is greater than BULK_DATA_BOUNDARY(64)

if(t->len <= BULK_DATA_BOUNDARY) {
...
else {
            //spi_msg(" tx -> by dma\n");
            #if defined(CONFIG_SUN4I_SPI_NDMA) || defined(CONFIG_SUN5I_SPI_NDMA)
            aw_spi_sel_dma_type(0, base_addr);
            #else
            aw_spi_sel_dma_type(1, base_addr);
            #endif

Maybe now you can increase spi speed, .max_speed_hz = 20000000,

There is still another problem, I think you should keep this line also:
memcpy(data, &rx_buf[SPI_OPLEN], len);
because the first byte(data[0]) can be a dummy byte. RX packets:74585 errors:0 dropped:40 overruns:0 frame:0... 40 packets was dropped!

Enc28j60' datasheet says nothing about it, but the driver' author may be right.
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 31, 2013, 05:54:35 PM
Hi vinifr,


memcpy(data, &rx_buf[SPI_OPLEN], len);

this code could be right when using a single message for TX and RX, like it was in the original code. Now rx_buf should contain only RX data: I tried this code but it brings to RX errors and no valid frame reception.

Now the problem seems to be related to spi tx packets and timeout...

I already update max speed to 20MHz.

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on January 31, 2013, 06:24:58 PM
Quote from: lorenzo on January 31, 2013, 05:54:35 PM
Hi vinifr,


memcpy(data, &rx_buf[SPI_OPLEN], len);

this code could be right when using a single message for TX and RX, like it was in the original code. Now rx_buf should contain only RX data: I tried this code but it brings to RX errors and no valid frame reception.

Now the problem seems to be related to spi tx packets and timeout...

I already update max speed to 20MHz.

Lorenzo

Ok. The correct code is memcpy(data, rx_buf, len);

Strange, had you problems with dropped packages like Leo? Remember, enc28j60 is 10BASE-T, so your download rate must be less than 10Mbits/s. 

You guys have any other idea? :P
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on January 31, 2013, 07:35:05 PM
Hi vinifr,

yes I also have similar problem.
I modified spi_sunxi this way:


if(tx_buf){
        if(t->len <= 0) { //BULK_DATA_BOUNDARY) {


and things get better, I have a more stable and reliable connection... Removing non-DMA tx generates now these messages:


[ 2813.780000] dma0: IRQ with no loaded buffer?
[ 2821.010000] net eth1: link down
[ 2821.070000] net eth1: link up - Half duplex
[ 2837.240000] dma0: IRQ with no loaded buffer?
[ 2845.010000] net eth1: link down
[ 2845.060000] net eth1: link up - Half duplex


It seems that non-DMA tx generate timeout quite often, and DMA transfer bring to DMA irq issues...
I don't know how to overcome this problem... Any ideas?

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 01, 2013, 12:22:54 AM
Hi,

You enable only tx DMA, but do not rx DMA. I found the snippet of code:
case SW_DMALOAD_NONE:
printk(KERN_ERR "dma%d: IRQ with no loaded buffer?\n",
       chan->number);
break;

And your if accept empty buffer:
if(t->len <= 0) { //BULK_DATA_BOUNDARY) {

About tx timeout I suggest this alteration:

aw_spi_start_xfer(base_addr);
// write
if(tx_buf){    
if(t->len <= BULK_DATA_BOUNDARY) {           
            unsigned temp_tx_len = tx_len;
            unsigned int poll_time = 0x7ffff;
            //spi_msg(" tx -> by ahb\n");
            spin_lock_irqsave(&aw_spi->lock, flags);
            for(; tx_len > 0; --tx_len) {
                writeb(*tx_buf++, base_addr + SPI_TXDATA_REG);
            }
            spin_unlock_irqrestore(&aw_spi->lock, flags);
            while( temp_tx_len &&(--poll_time > 0) )/* txFIFO counter */
            {
  if(aw_spi_query_txfifo(base_addr))
  {
      --temp_tx_len;
          poll_time++;
  }
            }
            if(poll_time <= 0) {
                spi_wrn("cpu tx data time out!\n");
            }


Wow, this will not work ever? But do not give up, okay?  ;D ;)
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 04, 2013, 06:24:35 PM
Hi vinifr,

sorry but I had some other work to do and I have tried only today your patch:


aw_spi_start_xfer(base_addr);
// write
if(tx_buf){    
if(t->len <= BULK_DATA_BOUNDARY) {           
            unsigned temp_tx_len = tx_len;
            unsigned int poll_time = 0x7ffff;
            //spi_msg(" tx -> by ahb\n");
            spin_lock_irqsave(&aw_spi->lock, flags);
            for(; tx_len > 0; --tx_len) {
                writeb(*tx_buf++, base_addr + SPI_TXDATA_REG);
            }
            spin_unlock_irqrestore(&aw_spi->lock, flags);
            while( temp_tx_len &&(--poll_time > 0) )/* txFIFO counter */
            {
  if(aw_spi_query_txfifo(base_addr))
  {
      --temp_tx_len;
          poll_time++;
  }
            }
            if(poll_time <= 0) {
                spi_wrn("cpu tx data time out!\n");
            }


This patch can't work because aw_spi_query_txfifo(base_addr) return 0 if the TX queue has no more bytes to send. So if there are 0 bytes in the queue the TX is done. This code always wait for timeout before stop the loop, and this is not good.

It seems that tx timout errors were triggered by 2 bytes SPI transfer, that actually should never happen... Where 2 bytes transfers come from?

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 05, 2013, 05:11:40 AM
Wow, sorry, the correct would be:

while(--poll_time > 0) {/* txFIFO counter */
           
  if(aw_spi_query_txfifo(base_addr)) {      
          poll_time++; // a little more time
  } else {
              break;
          }
            }
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 05, 2013, 09:49:48 AM
This looks to be a potentally dangerous code: if there is 1 byte stuck in the fifo and you can't send that byte, you are inside an endless loop, because poll_time never decreases...

Today I'm going to take a deeper look to the code... Let's see if I can find a solution...

If you have any other ideas you're welcome!
Thank you.
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 05, 2013, 01:54:35 PM
We really have to find a solution. This probably is not the best, I could not think of other. But the variable always decreases, independent if() be true or false.

About patch, could you submit it?

My enc28j60 arrived yesterday, I can now do the tests.  ;D

As you know that rx packets are wrong?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 05, 2013, 02:03:50 PM
Fine, so you can also do some tests...
RX is fine now, we have only some issue for tx timout wich forces the network to reset, but RX works like a charm...

If the if() statement is always true you have: --poll_time and then poll_time++... So you actually don't change the value of the variable...

I was waiting to submit the patch to see if we find a solution for this issue... This afternoon I try anyway... Meanwhile you can use the link to the patched module...

Thanks.
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 05, 2013, 02:15:18 PM
There is a local specific for issues: https://github.com/linux-sunxi/linux-sunxi/issues?state=open (https://github.com/linux-sunxi/linux-sunxi/issues?state=open)
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 05, 2013, 05:03:29 PM
Hi,

I've submitted the patch, now let's wait for the replay...

:D
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 05, 2013, 07:00:30 PM
Hi,

after a lot of test, it seems that the problem with TX timeout is related to SPI speed: with 10MHz the enc28j60 works far better. Some tx errors are still present but with a very low frequency...

Please use it with 10MHz clock configuration!

Use this script.bin and module: https://dl.dropbox.com/u/96533863/enc28j60_v3.tar.gz (I did some small changes).

2013-02-05 17:10:28 (195 KB/s) - `VirtualBox-4.2.6-82870-Win.exe' saved [97461672/97461672]

Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 06, 2013, 11:55:56 PM
Nice! ;D Finally a functional enc28j60!

I have not had time to test it.  :-[

I'm trying to run the a13-olinuxino-micro...

I have a question, how you configured the external interruption?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 08, 2013, 04:41:24 AM
Hi lorenzo,

I talked to amery, he said: "the sunxi driver should be fixed to coexist with mainlined code, not the other way around."

So we need to change spi_sunxi.c, not enc28j60.c, taking into account that enc28j60.c is in the mainline.

In that case I'll submit a patch for spi_sunxi.c
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: JohnS on February 08, 2013, 12:05:51 PM
Where truly is the problem?  If it's in the mainline code then THAT is what should be fixed.  But only if it's there.

John
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 08, 2013, 12:22:44 PM
Hi all,

mmhhhh... well I don't think we can fix only spi_sunxi.c file, because IRQ management should be fixed in the enc28j60 driver, we can't fix it in the spi_sunxi module (maybe we can do IRQ registration, but I'm not sure about that)...
Well actually the enc28j60 patch should work only with A13, so maybe it cannot be merged with mainline version...

Anybody knows if it is possible to create a enc28j60 sunxi version of the driver?

Thanks.
Lorenzo
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 09, 2013, 11:48:27 AM
hi,

Which pins must be connected? I connected the wires: SCK, MOSI, MISO, INT, 3V3, GND and CS

I'm always getting this error: "link down"
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 09, 2013, 01:00:33 PM
Hi,

maybe RST is missing. Did you buy the MOD-ENC28J60 (https://www.olimex.com/Products/Modules/Ethernet/MOD-ENC28J60)?
You can check the connection on the schematic, but if you connect all the pins correctly it shouldn't be any problem.

Did you check script.bin file?

Talking to Alejandro about enc28j60 patch he told me that the only way is to produce a sunxi driver version, because I must change the module code to make it work correctly.
Next days I'll try to submit a modified version of the driver, with comments and informations about code changes, but I'm not sure it will be accepted to be part of the kernel...

cheers
Lorenzo Nava
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 09, 2013, 01:41:07 PM
hi lorenzo,

yes, I bought MOD-ENC28J60, but I'm not using the cable that came with it, i use wires. i hate wires >:(
RST i leave not connected.
https://www.olimex.com/Products/Modules/Ethernet/MOD-ENC28J60/ (https://www.olimex.com/Products/Modules/Ethernet/MOD-ENC28J60/)
schematic: https://www.olimex.com/Products/Modules/Ethernet/MOD-ENC28J60/resources/MOD-ENC28J60-schematic.pdf (https://www.olimex.com/Products/Modules/Ethernet/MOD-ENC28J60/resources/MOD-ENC28J60-schematic.pdf)

I reviewed the original code(enc28j60.c), it seems that he really needs to be changed. because spi_read_op() and spi_write_op do not set up .cs_change. However using an oscilloscope I see the CS pin down and then up, but I do not understand how that happens.  :o

spi_sunxi.c: line 979 and 994

/* update the new cs value */
cs_change = t->cs_change;
...
/* if zero ,keep active,otherwise deactived. */
   if (cs_change) {
aw_spi->cs_control(spi, 0);
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 09, 2013, 02:55:35 PM
Hi vinifr,

the other problem is that if you don't set tx_buf and rx_buf to NULL alternatively the DMA works with full duplex mode, and not with half duplex. The only way to make enc28j60 work is o use half duplex DMA transfers, so changes to enc28j60 are mandatory...

About enc28j60, it's very strange. What does dmesg report?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 09, 2013, 03:43:16 PM
I connected RST, the result is the same, but I saw it in the schematic is with the pull-up.

I tested in a13-olinuxino-wifi and a13-olinuxino-micro,also the same error.
script.fex for wifi: http://dl.dropbox.com/u/22273442/A13/script.fex (http://dl.dropbox.com/u/22273442/A13/script.fex)

I connect this way:
ENC pins --- A13(connector UEXT)
SCK(1) --- SPI2_CLK (9)
MOSI(2) --- SPI2_MOSI (8 )
MISO(3) --- SPI2_MISO (7)
WOL(4) --- no connected
INT(5) --- PIN8 (PB4)
...
3V3(10) --- 3V3(1)
GND(9) --- GND(2)
RST(8 ) --- no connected
CS(7) --- SPI2_CS0(10)
CLKOUT(6) --- no connected

MOD_ENC: http://dl.dropbox.com/u/22273442/A13/MOD-ENC.jpg (http://dl.dropbox.com/u/22273442/A13/MOD-ENC.jpg)
Connector UEXT: http://dl.dropbox.com/u/22273442/A13/UEXT.jpg (http://dl.dropbox.com/u/22273442/A13/UEXT.jpg)

Log:

[    0.190000] [spi]: sw spi init !!
[    0.190000] [spi]: sw spi init fetch spi0 uning configuration failed
[    0.190000] [spi]: Found 1 spi devices in config files
[    0.190000] [spi]: boards num modalias         max_spd_hz       bus_num  cs   mode
[    0.190000] [spi]: 0          enc28j60         10000000         2        0    0x0   
[    0.190000] [spi]: bus num = 2, spi used = 3
[    0.190000] [spi]: source = sdram_pll_p, src_clk = 408000000, mclk 102000000
[    0.190000] [spi]: allwinners SoC SPI Driver loaded for Bus SPI-2 with 1 Slaves attached
[    0.190000] [spi]: [spi-2]: driver probe succeed, base dc8aa000, irq 12, dma_id 2!
[    2.870000] enc28j60 spi2.0: enc28j60 Ethernet driver 1.01 loaded
[    3.070000] enc28j60 spi2.0: enc28j60 enc28j60 spi_irq param load successfully.
[    3.070000] enc28j60 spi2.0: enc28j60 enc28j60_probe, gpio_addr = 0xdc92a800.
[    3.250000] enc28j60 spi2.0: enc28j60 enc28j60_probe, 1713: gpio_int_info, port = 2, port_num = 4.
[    3.310000] enc28j60 spi2.0: enc28j60 ENC28J60 interrupt configuration
[    3.310000] enc28j60 spi2.0: enc28j60 driver registered

[   19.790000] net eth0: link down
[   19.790000] net eth0: normal mode
[   19.790000] net eth0: normal mode
[   19.810000] net eth0: multicast mode
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 09, 2013, 06:38:01 PM
Hi vinifr,

the link down message is normal, is the initial state of the network..
Try to issue
ifconfig -a
and let me know the result...
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 09, 2013, 07:06:28 PM
root@deb-a13:~# ifconfig

eth0      Link encap:Ethernet  Endereço de HW b6:8a:e2:15:79:2e 
          UP BROADCASTMULTICAST  MTU:1500  Métrica:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          IRQ:28

lo        Link encap:Loopback Local 
          inet end.: 127.0.0.1  Masc:255.0.0.0
          UP LOOPBACKRUNNING  MTU:16436  Métrica:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan3     Link encap:Ethernet  Endereço de HW 48:02:2a:c5:f1:82 
          inet end.: 192.168.1.4  Bcast:192.168.1.255  Masc:255.255.255.0
          UP BROADCASTRUNNING MULTICAST  MTU:1500  Métrica:1
          RX packets:106 errors:0 dropped:0 overruns:0 frame:0
          TX packets:91 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:1000
          RX bytes:13843 (13.5 KiB)  TX bytes:12566 (12.2 KiB)


root@deb-a13:~# ifconfig -a

eth0      Link encap:Ethernet  Endereço de HW b6:8a:e2:15:79:2e 
          UP BROADCASTMULTICAST  MTU:1500  Métrica:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          IRQ:28

lo        Link encap:Loopback Local 
          inet end.: 127.0.0.1  Masc:255.0.0.0
          UP LOOPBACKRUNNING  MTU:16436  Métrica:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

tunl0     Link encap:Túnel IPIP  Endereço de HW   
          NOARP  MTU:1480  Métrica:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan3     Link encap:Ethernet  Endereço de HW 48:02:2a:c5:f1:82 
          inet end.: 192.168.1.4  Bcast:192.168.1.255  Masc:255.255.255.0
          UP BROADCASTRUNNING MULTICAST  MTU:1500  Métrica:1
          RX packets:129 errors:0 dropped:0 overruns:0 frame:0
          TX packets:100 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:1000
          RX bytes:16315 (15.9 KiB)  TX bytes:15004 (14.6 KiB)


Note: My router has dhcp enabled
Info: my source power is 12V 1A

How is your /etc/network/interfaces?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 09, 2013, 08:11:09 PM
Hi,

I don't use the /etc/network/interfaces

If you issue
dhclient eth0
what is the result?

Did you also try with:
ifconfig eth0 down
Ifconfig eth0 192.168.1.150 up


Cheers
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 09, 2013, 09:05:56 PM
nothing happens  >:(
root@deb-a13:~# dhclient eth0

[   71.670000] net eth0: multicast mode
[   71.680000] net eth0: multicast mode


root@deb-a13:~# ifconfig

eth0      Link encap:Ethernet  Endereço de HW a6:fd:c1:18:c6:23 
          UP BROADCASTMULTICAST  MTU:1500  Métrica:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          IRQ:28

Static ip also does not work.  :o
Could you post your logs of spi2, net and ifconfig messages?

Wow, something is wrong, I think it's my connections. When i put my finger on the chip it is very VERY hot!
how is yours?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 10, 2013, 02:01:46 PM
Hi,

I don't have the enc28j60 module here with me, I will try tomorrow and let you know..
Spi and enc28j60 messages seem to be ok, I can't see any strange behaviour..

Your interface never switch to running mode? What the terminal shows when you issue dhclient command?
Which is the LED status on the ethernet interface?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 11, 2013, 07:14:10 AM
hi,

I found the problem, ENC28J50 not transmitting anything. I put my laptop as a router and it gets nothing.

I listen for packets via wireshark.

exactly, it does not change for running and only one LED lights.
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 11, 2013, 09:43:06 AM
Hi,

here is my dmesg, but read next post for solution (I hope) to your problem...

Her is my dmesg:


root@debian:~# dmesg | grep spi
[    0.190000] bus: 'spi': registered
[    0.190000] device class 'spi_master': registering
[    2.840000] [spi]: sw spi init !!
[    2.840000] [spi]: sw spi init fetch spi0 uning configuration failed
[    2.850000] [spi]: Found 1 spi devices in config files
[    2.860000] [spi]: boards num modalias         max_spd_hz       bus_num  cs   mode
[    2.870000] [spi]: 0          enc28j60         10000000         2        0    0x0
[    2.880000] Registering platform device 'sun5i-spi.2'. Parent at platform
[    2.890000] device: 'sun5i-spi.2': device_add
[    2.900000] bus: 'platform': add device sun5i-spi.2
[    2.910000] PM: Adding info for platform:sun5i-spi.2
[    2.920000] bus: 'platform': add driver sun5i-spi
[    2.930000] bus: 'platform': driver_probe_device: matched device sun5i-spi.2 with driver sun5i-spi
[    2.940000] bus: 'platform': really_probe: probing driver sun5i-spi with device sun5i-spi.2
[    2.950000] [spi]: bus num = 2, spi used = 3
[    2.960000] [spi]: source = sdram_pll_p, src_clk = 408000000, mclk 102000000
[    2.970000] device: 'spi2': device_add
[    2.980000] PM: Adding info for No Bus:spi2
[    2.990000] device: 'spi2.0': device_add
[    3.000000] bus: 'spi': add device spi2.0
[    3.000000] PM: Adding info for spi:spi2.0
[    3.010000] [spi]: allwinners SoC SPI Driver loaded for Bus SPI-2 with 1 Slaves attached
[    3.020000] [spi]: [spi-2]: driver probe succeed, base dc8aa000, irq 12, dma_id 2!
[    3.030000] driver: 'sun5i-spi.2': driver_bound: bound to device 'sun5i-spi'
[    3.040000] bus: 'platform': really_probe: bound device sun5i-spi.2 to driver sun5i-spi
[   11.610000] bus: 'spi': add driver enc28j60
[   11.680000] bus: 'spi': driver_probe_device: matched device spi2.0 with driver enc28j60
[   11.760000] bus: 'spi': really_probe: probing driver enc28j60 with device spi2.0
[   11.870000] enc28j60 spi2.0: enc28j60 Ethernet driver 1.01 loaded
[   12.120000] enc28j60 spi2.0: enc28j60 enc28j60 spi_irq param load successfully.
[   12.130000] enc28j60 spi2.0: enc28j60 enc28j60_probe, gpio_addr = 0xdd062800.
[   12.210000] enc28j60 spi2.0: enc28j60 enc28j60_probe, 1713: gpio_int_info, port = 2, port_num = 4.
[   12.240000] enc28j60 spi2.0: enc28j60 ENC28J60 interrupt configuration
[   12.260000] enc28j60 spi2.0: enc28j60==ENC28J60_CLEAR_IRQ_NO=
[   12.410000] driver: 'spi2.0': driver_bound: bound to device 'enc28j60'
[   12.460000] bus: 'spi': really_probe: bound device spi2.0 to driver enc28j60


and when I prompt ifconfig eth1 up (enc28j60 eth1 is on interface 1) dmesg shows:


[  135.200000] net eth1: link down
[  135.220000] net eth1: normal mode
[  135.220000] net eth1: normal mode
[  135.230000] net eth1: multicast mode
[  136.130000] net eth1: link up - Half duplex


And here is interrupt table:


root@debian:~# cat /proc/interrupts
           CPU0
  0:          0    sw_vic  axp_mfd
  2:        113    sw_vic  serial
  7:       4488    sw_vic  sun5i-i2c.0
  8:         36    sw_vic  sun5i-i2c.1
12:       5624    sw_vic  sun5i-spi
22:      37116    sw_vic  timer0
27:       1274    sw_vic  dma_irq
28:        153    sw_vic  enc28j60
29:          0    sw_vic  sun4i-ts
32:     239695    sw_vic  sunxi-mmc
37:          0    sw_vic  nand
39:       6344    sw_vic  ehci_hcd:usb2
44:      43065    sw_vic  sunxi lcd0
47:      21489    sw_vic  sunxi scaler0
53:          0    sw_vic  cedar_dev
64:          0    sw_vic  ohci_hcd:usb3
Err:          0
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 11, 2013, 09:52:40 AM
Hi vinifr,

I think I've found the error: in you script.fex file please change

csi_used = 1
to
csi_used = 0


Because CSI uses PE00 pin which conflicts with CS of SPI.

Cheers
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 11, 2013, 04:13:44 PM
hi Lorenzo, you will not believe! besides that error csi_used, I made another terrible mistake!!!

I connected the enc IRQ pin on pin 8 (VGA_DIS) instead of the pin 13 (pin8), I mixed with one another. hahah ;D

Is now functioning normally, with LED flashing and flag running:

root@deb-a13:~# ifconfig
eth0      Link encap:Ethernet  Endereço de HW 5e:28:52:e6:be:db 
          inet end.: 192.168.1.7  Bcast:192.168.1.255  Masc:255.255.255.0
          UP BROADCASTRUNNING MULTICAST  MTU:1500  Métrica:1
          RX packets:8799 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7468 errors:0 dropped:0 overruns:0 carrier:0
          colisões:0 txqueuelen:1000
          RX bytes:4911422 (4.6 MiB)  TX bytes:532671 (520.1 KiB)
          IRQ:28


[   25.260000] net eth0: link down
[   25.260000] net eth0: normal mode
[   25.260000] net eth0: normal mode
[   25.260000] net eth0: multicast mode
[   26.250000] net eth0: link up - Half duplex


thanks for help!

Are you using your version enc28j60_v2 or 3?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 11, 2013, 04:54:51 PM
 :D, yeah sometimes it happens...
I'm using version 3... In version 2 there is a small error in one spi operation function, so it is better to use v3...

You can enjoy your wired network now!  ;D

cheers
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 11, 2013, 06:00:54 PM
Another thing, you realize that the chip gets very hot?

Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 11, 2013, 06:46:26 PM
No, I didn't notice it (well, actually I've never checked that)... It's strange because it shouldn't have a high power consumption...

I'll try with a stress test and measure the temperature...

I've tried to send a proposal for a sun5i_enc28j60 driver:
https://groups.google.com/forum/?fromgroups=#!topic/linux-sunxi/iaxRsJorVh8

let's see what happens...

cheers
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 11, 2013, 10:11:27 PM
I tested your enc28j60_v3, is as good as v2, I have not lost any package! Now we can consider that the ENC28J60 is functional for A13. Good luck with the patch.

The patch I would submit to spi_sunxi.c do not will work because there is not gpio_to_irq() in sun4i-gpio driver. I tested my patch with your enc28j60_v3 and i get "cpu tx data time out!"

How you solved tx data timeout?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: lorenzo on February 11, 2013, 11:14:28 PM
The problem was in the spi clock frequency: when I reduced the frequency to 10MHz tx errors happen very very rarely.
I think the problem should be related to crosstalk: you shouldn't suffer of this issue because you have separate wires..

Have you experienced any tx errors? How was your network speed?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on February 12, 2013, 01:01:08 AM
Dont worry, this happens when I use my spi_sunxi.c version. with the original version works perfectly.

http://dl.dropbox.com/u/22273442/A13/spi_sunxi.c (http://dl.dropbox.com/u/22273442/A13/spi_sunxi.c)
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: huppyuy on August 11, 2014, 07:59:02 AM
you guys are so cool!! It make me cry!! :'(
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: huppyuy on August 11, 2014, 10:25:39 AM
I use your V3 patch in linux-sunxi-3.4.Kernel version is 3.4.90.
And I changed <mach/sys_config.h> to <plat/sys.config.h> because file is missing.
I also changed ndo_set_multicast_list to ndo_set_rx_mode because of the changing of kernel source.

When I am using ,I can dhclient but there are lots of logs like "drivers/spi/spi_sunxi.c(L583) unknow dma direction = 0".
Is that matters?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on August 11, 2014, 04:42:32 PM
I think this patch is no longer necessary, spi_sunxi driver have already support to communication full duplex.

Did you test mod-enc28j60 without patch?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: jo on December 02, 2014, 01:44:00 PM
Quote from: vinifr on August 11, 2014, 04:42:32 PM
I think this patch is no longer necessary, spi_sunxi driver have already support to communication full duplex.

Did you test mod-enc28j60 without patch?

I've tested mod-enc28j60 without the patch with an A13 board, but it doesn't work.


[spi_devices]
spi_dev_num = 1

[spi_board0]
modalias = "enc28j60"
max_speed_hz = 12000000
chip_select = 0
bus_num = 2
mode = 0
irq_gpio = 2
full_duplex = 0

[gpio_para]
gpio_used = 1
gpio_num = 14
gpio_pin_1 = port:PB03<1><default><default><default>
; PB04 is used in section [spi_board0]
gpio_pin_2 = port:PB04<6><default><default><default>
gpio_pin_3 = port:PB10<1><default><default><default>
...



[    0.137417] [spi]: 0          enc28j60         12000000         0        0    0x0
[    3.207358] enc28j60 spi2.0: enc28j60 Ethernet driver 1.01 loaded
[    3.212264] enc28j60 spi2.0: enc28j60 enc28j60 spi_irq param load successfully.
[    3.212293] enc28j60 spi2.0: enc28j60 enc28j60_probe, gpio_addr = 0xf1c20800.
[    3.212308] enc28j60 spi2.0: enc28j60 enc28j60_probe, 1710: gpio_int_info, port = 2, port_num = 4.
[    3.212318] enc28j60 spi2.0: enc28j60 ENC28J60 interrupt configuration
[    3.215980] net eth0: enc28j60 driver registered
[    3.494509] register rtw_netdev_ops to netdev_ops
[    8.141056] net eth0: link down
[    8.141098] net eth0: normal mode
[    8.141111] net eth0: normal mode
[    8.141149] net eth0: multicast mode


But it doesn't detects the cable.


# ip l l eth0
3: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
    link/ether 00:1e:4e:06:00:ee brd ff:ff:ff:ff:ff:ff
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on December 03, 2014, 01:27:06 AM
hi Jo,

You have to configure [spi_board0] and [spi2] too:
spi2_para]
spi_used = 1
spi_cs_bitmap = 3
spi_cs0 = port:PE00<4><default><default><default>
spi_cs1 = port:PB10<2><default><default><default>
spi_sclk = port:PE01<4><default><default><default>
spi_mosi = port:PE02<4><default><default><default>
spi_miso = port:PE03<4><default><default><default>

[spi_board0]
modalias = "enc28j60"
max_speed_hz = 20000000
chip_select = 0
bus_num = 2
mode = 0
spi_irq = port:PB04<6><default><default><default>
And change csi_used = 1 to csi_used = 0

If all work well, you shold see:

[    0.190000] [spi]: sw spi init !!
[    0.190000] [spi]: sw spi init fetch spi0 uning configuration failed
[    0.190000] [spi]: Found 1 spi devices in config files
[    0.190000] [spi]: boards num modalias         max_spd_hz       bus_num  cs   mode
[    0.190000] [spi]: 0          enc28j60         10000000         2        0    0x0   
[    0.190000] [spi]: bus num = 2, spi used = 3
[    0.190000] [spi]: source = sdram_pll_p, src_clk = 408000000, mclk 102000000
[    0.190000] [spi]: allwinners SoC SPI Driver loaded for Bus SPI-2 with 1 Slaves attached
[    0.190000] [spi]: [spi-2]: driver probe succeed, base dc8aa000, irq 12, dma_id 2!
[    2.870000] enc28j60 spi2.0: enc28j60 Ethernet driver 1.01 loaded
[    3.070000] enc28j60 spi2.0: enc28j60 enc28j60 spi_irq param load successfully.
[    3.070000] enc28j60 spi2.0: enc28j60 enc28j60_probe, gpio_addr = 0xdc92a800.
[    3.250000] enc28j60 spi2.0: enc28j60 enc28j60_probe, 1713: gpio_int_info, port = 2, port_num = 4.
[    3.310000] enc28j60 spi2.0: enc28j60 ENC28J60 interrupt configuration
[    3.310000] enc28j60 spi2.0: enc28j60 driver registered

[   19.790000] net eth0: link down
[   19.790000] net eth0: normal mode
[   19.790000] net eth0: normal mode
[   19.810000] net eth0: multicast mode
[  136.130000] net eth1: link up - Half duplex

if this message show up, net eth1: link up - Half duplex, means works!
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: jo on December 03, 2014, 12:06:41 PM
Quote from: vinifr on December 03, 2014, 01:27:06 AM

[spi_board0]
modalias = "enc28j60"
max_speed_hz = 20000000
chip_select = 0
bus_num = 2
mode = 0
spi_irq = port:PB04<6><default><default><default>
And change csi_used = 1 to csi_used = 0

[/code]
if this message show up, net eth1: link up - Half duplex, means works!

My spi2_para section looks like yours. So, this is fine. But I'm trying to get the interface working without the patch as you've said on August 11, 2014. I've took the branch sunxi-3.4 from the sunxi repository and tried to get it working. But it doesn't.

With the patched enc28j60 driver it works. Hence, the hardware is but. But there has to be something else missing in the code. At least, I found that using IRQF_TRIGGER_FALLING makes the interface detects the cable and gets set up. But I can't send/receive data. I get the kernel message drivers/spi/spi_sunxi.c(L583) unknow dma direction = 0, but I don't know where DMA gets configured or disabled.
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on December 05, 2014, 01:57:46 AM
hi,

There may be a conflict between the patch and new sunxi_spi.c. I'm not sure. :-[

Quotebut I don't know where DMA gets configured or disabled.

Configure the kernel using:
make ARCH=arm menuconfig
https://www.youtube.com/watch?v=ilDhOzmkORY (https://www.youtube.com/watch?v=ilDhOzmkORY)
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: jo on December 05, 2014, 01:55:23 PM
Quote from: vinifr on December 05, 2014, 01:57:46 AM
hi,

There may be a conflict between the patch and new sunxi_spi.c. I'm not sure. :-[

Quotebut I don't know where DMA gets configured or disabled.

Configure the kernel using:
make ARCH=arm menuconfig
https://www.youtube.com/watch?v=ilDhOzmkORY (https://www.youtube.com/watch?v=ilDhOzmkORY)

Yes, there's a conflict, because both want to use the same interrupt, but the patched enc28j60 uses TRIGGER_FAILING and sunxi_spi doesn't not, which makes the IRQ unsharable.

Isn't there anything in the script.fex to adapt for DMA?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: jo on December 05, 2014, 06:37:02 PM
For the record, I could prevent the message drivers/spi/spi_sunxi.c(L583) unknow dma direction = 0 by removing the kernel option CONFIG_SPI_SUNXI_NDMA. The network works fine (with patched enc28j60).
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on December 06, 2014, 09:03:38 PM
Good!  ;D
QuoteIsn't there anything in the script.fex to adapt for DMA?
There is not nothing in script.fex about DMA. As you said, removing kernel option CONFIG_SPI_SUNXI_NDMA is a solution.

We could also adapt the patch to work with DMA.
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: jo on December 08, 2014, 01:16:41 PM
Quote from: vinifr on December 06, 2014, 09:03:38 PM
Good!  ;D
QuoteIsn't there anything in the script.fex to adapt for DMA?
There is not nothing in script.fex about DMA. As you said, removing kernel option CONFIG_SPI_SUNXI_NDMA is a solution.

We could also adapt the patch to work with DMA.

As far as I understand the description of the kernel option, this doesn't remove DMA, but switches to a different form of DMA: DDMA => NDMA.

This selects SPI DMA mode with DMA transfer
Y select NDMA mode and N select DDMA mode


In the meantime, I saw that disabling this option causes these warnings:

[spi]: drivers/spi/spi_sunxi.c(L1025) cpu tx data time out!
[spi]: drivers/spi/spi_sunxi.c(L1025) cpu tx data time out!
------------[ cut here ]------------
WARNING: at net/sched/sch_generic.c:256 dev_watchdog+0x2c4/0x2d0()
NETDEV WATCHDOG: eth0 (enc28j60): transmit queue 0 timed out
Modules linked in: 8192cu(O) mali_drm mali disp_ump ump sun4i_ts enc28j60 [last unloaded: 8192cu]
[<c0012ac8>] (unwind_backtrace+0x0/0xec) from [<c00277ec>] (warn_slowpath_common+0x54/0x64)
[<c00277ec>] (warn_slowpath_common+0x54/0x64) from [<c002782c>] (warn_slowpath_fmt+0x30/0x40)
[<c002782c>] (warn_slowpath_fmt+0x30/0x40) from [<c02eefc4>] (dev_watchdog+0x2c4/0x2d0)
[<c02eefc4>] (dev_watchdog+0x2c4/0x2d0) from [<c0032c24>] (run_timer_softirq+0xec/0x27c)
[<c0032c24>] (run_timer_softirq+0xec/0x27c) from [<c002d2a0>] (__do_softirq+0xa4/0x134)
[<c002d2a0>] (__do_softirq+0xa4/0x134) from [<c002d730>] (irq_exit+0x60/0x64)
[<c002d730>] (irq_exit+0x60/0x64) from [<c000e8f8>] (handle_IRQ+0x3c/0x84)
[<c000e8f8>] (handle_IRQ+0x3c/0x84) from [<c000db34>] (__irq_svc+0x34/0x118)
[<c000db34>] (__irq_svc+0x34/0x118) from [<c000ea7c>] (default_idle+0x2c/0x30)
[<c000ea7c>] (default_idle+0x2c/0x30) from [<c000ecd4>] (cpu_idle+0x80/0xc4)
[<c000ecd4>] (cpu_idle+0x80/0xc4) from [<c045977c>] (start_kernel+0x2ac/0x2b8)
---[ end trace e6000e6a48c09caa ]---


They happen much more seldom than unknow dma direction = 0, but they don't sound fine, too.

Do you have any idea how to get rid of one or both of these messages? Is it difficult to get NDMA support?
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on March 19, 2015, 05:55:53 PM
Sorry, my knowledge about DMA is scarce.  :-[
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: Mr.D on March 02, 2016, 09:50:48 AM
Hi Guys ,

Did You manage to get this thing finally working well ?

Regards
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: vinifr on March 02, 2016, 01:25:47 PM
Hi Mr.D,

You should try mainline sunxi kernel: https://linux-sunxi.org/Mainline_Kernel_Howto (https://linux-sunxi.org/Mainline_Kernel_Howto) I'm pretty sure that using mainline kernel works!
Title: Re: MOD-ENC28J60 and Linux (Debian/GNU)
Post by: gunebakan on September 27, 2016, 02:32:21 PM
Quote from: vinifr on March 02, 2016, 01:25:47 PM
Hi Mr.D,

You should try mainline sunxi kernel: https://linux-sunxi.org/Mainline_Kernel_Howto (https://linux-sunxi.org/Mainline_Kernel_Howto) I'm pretty sure that using mainline kernel works!
Hi, i cant get it work with mainline kernel.when trying A20-som with patched enc28j60 driver.i get this error.RX is ok but when i try to ping i get this error.

Anybody know why it happen ?


Jan  1 00:18:34 A20-OLinuXino kernel: [  274.218372] ------------[ cut here ]------------
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.229188] WARNING: at net/sched/sch_generic.c:256 dev_watchdog+0x2b8/0x2c4()
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.242083] NETDEV WATCHDOG: eth0 (enc28j60): transmit queue 0 timed out
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.250625] Modules linked in: gt2005 ump
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.264028] [<c0015f90>] (unwind_backtrace+0x0/0x12c) from [<c00383d8>] (warn_slowpath_common+0x54/
0x64)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.281771] [<c00383d8>] (warn_slowpath_common+0x54/0x64) from [<c0038418>] (warn_slowpath_fmt+0x30
/0x40)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.299080] [<c0038418>] (warn_slowpath_fmt+0x30/0x40) from [<c046761c>] (dev_watchdog+0x2b8/0x2c4)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.316045] [<c046761c>] (dev_watchdog+0x2b8/0x2c4) from [<c00438a0>] (run_timer_softirq+0x118/0x26
c)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.333094] [<c00438a0>] (run_timer_softirq+0x118/0x26c) from [<c003e4d4>] (__do_softirq+0xbc/0x14c
)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.349104] [<c003e4d4>] (__do_softirq+0xbc/0x14c) from [<c003e9d4>] (irq_exit+0x90/0x94)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.363898] [<c003e9d4>] (irq_exit+0x90/0x94) from [<c000fbec>] (handle_IRQ+0x60/0xb0)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.378952] [<c000fbec>] (handle_IRQ+0x60/0xb0) from [<c00084e4>] (gic_handle_irq+0x28/0x58)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.394440] [<c00084e4>] (gic_handle_irq+0x28/0x58) from [<c000e880>] (__irq_svc+0x40/0x74)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.406536] Exception stack(0xc07f5f58 to 0xc07f5fa0)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.418459] 5f40:                                                       ffffffed 00000000
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.433508] 5f60: 13017000 00000000 c0867a88 c05629b0 c07f4000 c07f4000 c08099f0 c07f4028
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.448556] 5f80: c07f4000 00000000 00000016 c07f5fa0 c000ff2c c000ff30 60070013 ffffffff
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.463608] [<c000e880>] (__irq_svc+0x40/0x74) from [<c000ff30>] (default_idle+0x2c/0x30)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.478661] [<c000ff30>] (default_idle+0x2c/0x30) from [<c0010220>] (cpu_idle+0xdc/0x108)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.493891] [<c0010220>] (cpu_idle+0xdc/0x108) from [<c07c3838>] (start_kernel+0x310/0x31c)
Jan  1 00:18:34 A20-OLinuXino kernel: [  274.505816] ---[ end trace d4051d5e35a07756 ]---