ENC28J60 Ethernet Module Interfacing with Jetson Nano

It turned out it was a power problem. I fixed it by supplying 3V3 to the module.

However I’m now getting kernel panic about in 2-3 seconds after I plug in ethernet cable to the module.
Anybody knows why this might be happening? I am attaching the driver I modified to use interrupts - based on MCP2515 example in this forum to make interrupts work - enc28j60.c (45.6 KB) The module does not work without it.

[   48.329864] Kernel panic - not syncing: Watchdog detected hard LOCKUP on cpu 0   
[   48.337123] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 4.9.140-l4t-r32.4.2+ge3c8d1
[   48.345400] Hardware name: NVIDIA Jetson Nano
[   48.353150] Call trace:                                                          
[   48.355621] [<ffffff800808c0a8>] dump_backtrace+0x0/0x178                        
[   48.361037] [<ffffff800808c244>] show_stack+0x24/0x30                            
[   48.366102] [<ffffff800844e758>] dump_stack+0x98/0xc0                            
[   48.371168] [<ffffff80081bc5e0>] panic+0x118/0x27c                               
[   48.375975] [<ffffff800817eeb8>] watchdog_nmi_enable+0x0/0x60                    
[   48.381734] [<ffffff800817e064>] watchdog_timer_fn+0x8c/0x2a0                    
[   48.387494] [<ffffff8008136c78>] __hrtimer_run_queues+0xf8/0x350                 
[   48.393512] [<ffffff80081375b0>] hrtimer_interrupt+0xa8/0x1d8                    
[   48.399273] [<ffffff8008bc79c0>] tegra210_timer_isr+0x38/0x48                    
[   48.405033] [<ffffff800811fd98>] __handle_irq_event_percpu+0x60/0x280            
[   48.411487] [<ffffff800811ffe0>] handle_irq_event_percpu+0x28/0x70               
[   48.417679] [<ffffff8008120078>] handle_irq_event+0x50/0x80                      
[   48.423265] [<ffffff8008123c4c>] handle_fasteoi_irq+0xc4/0x1a0                   
[   48.429109] [<ffffff800811edcc>] generic_handle_irq+0x34/0x50                    
[   48.434867] [<ffffff800811f49c>] __handle_domain_irq+0x6c/0xc0                   
[   48.440711] [<ffffff8008080d2c>] gic_handle_irq+0x54/0xa8                        
[   48.446121] [<ffffff8008082c28>] el1_irq+0xe8/0x194                              
[   48.451013] [<ffffff8008b70274>] cpuidle_enter_state+0xec/0x380                  
[   48.456945] [<ffffff8008b7057c>] cpuidle_enter+0x34/0x48                         
[   48.462269] [<ffffff800810ff3c>] call_cpuidle+0x44/0x68                          
[   48.467506] [<ffffff800811027c>] cpu_startup_entry+0x18c/0x210                   
[   48.473354] [<ffffff8008092844>] secondary_start_kernel+0x13c/0x160              
[   48.479631] [<0000000080f271a4>] 0x80f271a4                                      
[   48.483827] SMP: stopping secondary CPUs                                         
[   48.487870] Kernel Offset: disabled                                              
[   48.491374] Memory Limit: none                                                   
[   48.517301] Rebooting in 5 seconds.. 

Here is how dmesg looks:

root@jetson-nano-qspi-sd:~# dmesg | grep eth0                                       
[    6.344103] net eth0: enc28j60 driver registered                                 
[   16.793892] net eth0: link down                                                  
[   16.797052] net eth0: multicast mode                                             
[   16.800750] net eth0: multicast mode                                             
[   16.804384] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready                   
[   16.843407] net eth0: multicast mode                                             
[   16.847004] net eth0: multicast mode                                             
[   16.850574] net eth0: multicast mode

Here is what I modified in enc28j60.c:

diff --git a/drivers/net/ethernet/microchip/enc28j60.c b/drivers/net/ethernet/microchip/enc28j60.c
index 0a26b11ca8f6..bbfb9236693d 100644
--- a/drivers/net/ethernet/microchip/enc28j60.c
+++ b/drivers/net/ethernet/microchip/enc28j60.c
@@ -30,6 +30,10 @@
 #include <linux/spi/spi.h>
 #include <linux/of_net.h>
 
+#include <linux/of_gpio.h>
+#include <asm-generic/gpio.h>
+
 #include "enc28j60_hw.h"
 
 #define DRV_NAME	"enc28j60"
@@ -1555,6 +1559,10 @@ static int enc28j60_probe(struct spi_device *spi)
 	const void *macaddr;
 	int ret = 0;
 
+	int gpio;
+	struct device_node *np = spi->dev.of_node;
+
 	if (netif_msg_drv(&debug))
 		dev_info(&spi->dev, DRV_NAME " Ethernet driver %s loaded\n",
 			DRV_VERSION);
@@ -1566,6 +1574,42 @@ static int enc28j60_probe(struct spi_device *spi)
 	}
 	priv = netdev_priv(dev);
 
+	/* If GPIO based interrupt is passed in device tree */
+	gpio = of_get_named_gpio(np, "interrupts", 0);
+	if (gpio < 0) {
+		dev_err(&spi->dev, "failed to get GPIO from device tree\n");
+	}
+
+	else {
+		ret = gpio_request(gpio, "enc28j60-gpio");
+		if (ret) {
+			dev_err(&spi->dev, "failed to request GPIO %d\n", gpio);
+			return ret;
+		}
+
+		ret = gpio_export(gpio, false);
+		if (ret) {
+			dev_err(&spi->dev, "failed to export GPIO %d\n", gpio);
+			return ret;
+		}
+
+		ret = gpio_direction_input(gpio);
+		if (ret) {
+			dev_err(&spi->dev, "failed to set pin to input state\n");
+			return -EINVAL;
+		}
+
+		/* IRQ setup */
+		ret = gpio_to_irq(gpio);
+		if (ret < 0) {
+			dev_err(&spi->dev, "failed to map GPIO to IRQ: %d\n", ret);
+			return -EINVAL;
+		}
+
+		spi->irq = ret;
+	}
+
 	priv->netdev = dev;	/* priv to netdev reference */
 	priv->spi = spi;	/* priv to spi reference */
 	priv->msg_enable = netif_msg_init(debug.msg_enable,

More info:

root@jetson-nano-qspi-sd:~# cat /proc/interrupts  | grep enc                        
299:          0          0          0          0      GPIO 200 Edge      enc28j60

Ifconfig (eth0 is the ENC28J60):

root@jetson-nano-qspi-sd:~# ifconfig                                                
eth0      Link encap:Ethernet  HWaddr 96:5F:7B:84:22:60                             
          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)                                    
          Interrupt:43                                                              
                                                                                    
eth1      Link encap:Ethernet  HWaddr 00:04:4B:E7:25:42                             
          inet addr:192.168.1.24  Bcast:192.168.1.255  Mask:255.255.255.0           
          inet6 addr: fe80::204:4bff:fee7:2542/64 Scope:Link                        
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1                        
          RX packets:79 errors:0 dropped:0 overruns:0 frame:0                       
          TX packets:57 errors:0 dropped:0 overruns:0 carrier:0                     
          collisions:0 txqueuelen:1000                                              
          RX bytes:10114 (9.8 KiB)  TX bytes:6871 (6.7 KiB)                         
          Interrupt:150 Base address:0xe000

I checked netdev: enc28j60 kernel panic fix. - Patchwork , no use.