Skip to content

Commit

Permalink
driver/net/ethernet/faraday: Add ftmac100_debug control.
Browse files Browse the repository at this point in the history
  ~#  echo [0/1] > /proc/ftmac100_debug/debug

      0: Disable ftmac100.c debug message
      1: Enable ftmac100.c debug message

  ~#  echo [0/1/2/4] > /proc/ftmac100_debug/incr

      0: DISABLED
      1: INCR4
      2: INCR8
      3: INCR16

      * Note: Need to restart eth[x] to apply the change.
         ~# ifconfig eth0 down
         ~# udhcpc

Signed-off-by: Dylan Jhong <dylan@andestech.com>
Co-authored-by: Eric Lin <tesheng@andestech.com>
  • Loading branch information
2 people authored and Nylon Chen committed Jun 19, 2020
1 parent bb889b5 commit 86aca05
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 3 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/faraday/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#

obj-$(CONFIG_FTGMAC100) += ftgmac100.o
obj-$(CONFIG_FTMAC100) += ftmac100.o
obj-$(CONFIG_FTMAC100) += ftmac100.o ftmac100_debug.o
19 changes: 17 additions & 2 deletions drivers/net/ethernet/faraday/ftmac100.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@
#error invalid RX_BUF_SIZE
#endif

#define xprintk(...)

#define FTMAC100_RX_DESC(priv, index) (&priv->descs->rxdes[index])
#define FTMAC100_RX_DESC_EXT(priv, index) (&priv->descs->rxdes_ext[index])
#define FTMAC100_TX_DESC(priv, index) (&priv->descs->txdes[index])
#define FTMAC100_TX_DESC_EXT(priv, index) (&priv->descs->txdes_ext[index])

#define FTMAC100_CURRENT_RX_DESC_INDEX(priv) (priv->rx_pointer)
#define FTMAC100_CURRENT_TX_DESC_INDEX(priv) (priv->tx_pointer);
#define FTMAC100_CURRENT_CLEAN_TX_DESC_INDEX(priv) (priv->tx_clean_pointer);

/* ftmac100_debug parameters */
extern unsigned int FTMAC100_DEBUG;
extern unsigned int FTMAC100_INCR;

/******************************************************************************
* private data
*****************************************************************************/
Expand Down Expand Up @@ -194,7 +209,7 @@ static int ftmac100_start_hw(struct ftmac100 *priv)

// Enable DMA Burst & RXFIFO threshold
iowrite32(FTMAC100_DBLAC_RX_THR_EN | /* Enable fifo threshold arb */
FTMAC100_DBLAC_INCR16_EN | /* Enable INCR[4/8/16] DMA Burst, this option solve RX RPKT_LOST issue*/
FTMAC100_INCR | /* Enable INCR[4/8/16] DMA Burst, this option solve RX RPKT_LOST issue*/
FTMAC100_DBLAC_RXFIFO_HTHR(6) | /* 6/8 of FIFO high threshold */
FTMAC100_DBLAC_RXFIFO_LTHR(2), /* 2/8 of FIFO low threshold */
priv->base + FTMAC100_OFFSET_DBLAC);
Expand Down Expand Up @@ -938,7 +953,7 @@ static int ftmac100_poll(struct napi_struct *napi, int budget)

if (status & (FTMAC100_INT_NORXBUF | FTMAC100_INT_RPKT_LOST |
FTMAC100_INT_AHB_ERR | FTMAC100_INT_PHYSTS_CHG)) {
if (net_ratelimit())
if (net_ratelimit() && FTMAC100_DEBUG)
netdev_info(netdev, "[ISR] = 0x%x: %s%s%s%s\n", status,
status & FTMAC100_INT_NORXBUF ? "NORXBUF " : "",
status & FTMAC100_INT_RPKT_LOST ? "RPKT_LOST " : "",
Expand Down
189 changes: 189 additions & 0 deletions drivers/net/ethernet/faraday/ftmac100_debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* Copyright (C) 2009 Andes Technology Corporation
* Copyright (C) 2019 Andes Technology Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#include <linux/module.h>
#include <linux/blkdev.h>
#include <linux/proc_fs.h>
#include <asm/andesv5/csr.h>

#define INPUTLEN 32

/*************************************************************************************/

// 0: DISABLE
// 1: ENABLE
unsigned int FTMAC100_DEBUG = 0;

// 0: DISABLE
// 1: INCR4
// 2: INCR8
// 4: INCR16
unsigned int FTMAC100_INCR = 4;

/*************************************************************************************/

struct entry_struct{
char *name;
int perm;
struct file_operations *fops;
};

static struct proc_dir_entry *proc_ftmac100_debug;

#define DEBUG( enable, tagged, ...) \
do{ \
if(enable){ \
if(tagged) \
printk( "[ %30s() ] ", __func__); \
printk( __VA_ARGS__); \
} \
} while( 0)

static int debug = 0;
module_param(debug, int, 0);

static ssize_t ftmac100_proc_read(struct file *file, char __user *userbuf,
size_t count, loff_t *ppos)
{
int ret=0;
char buf[128]={0};
if (!strncmp(file->f_path.dentry->d_name.name, "debug", 5)){
ret = sprintf(buf, "FTMAC100 debug info: %s\n", (FTMAC100_DEBUG) ? "Enabled" : "Disabled");
}else if (!strncmp(file->f_path.dentry->d_name.name, "incr", 4)){
switch(FTMAC100_INCR){
case 0:
ret = sprintf(buf, "FTMAC100 INCR: %s\n", "Disabled");
break;
case 1:
ret = sprintf(buf, "FTMAC100 INCR: %d (INCR4)\n",FTMAC100_INCR);
break;
case 2:
ret = sprintf(buf, "FTMAC100 INCR: %d (INCR8)\n",FTMAC100_INCR);
break;
case 4:
ret = sprintf(buf, "FTMAC100 INCR: %d (INCR16)\n",FTMAC100_INCR);
break;
}
}else
return -EFAULT;

return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
}

static ssize_t ftmac100_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *ppos)
{

unsigned long en;
char inbuf[INPUTLEN];

if (count > INPUTLEN - 1)
count = INPUTLEN - 1;

if (copy_from_user(inbuf, buffer, count))
return -EFAULT;

inbuf[count] = '\0';

if (!sscanf(inbuf, "%lu", &en))
return -EFAULT;

if(!strncmp(file->f_path.dentry->d_name.name, "debug", 5)) {
FTMAC100_DEBUG = en;
} else if(!strncmp(file->f_path.dentry->d_name.name, "incr", 4)) {
switch(en){
case 0:
case 1:
case 2:
case 4:
FTMAC100_INCR = en;
printk("Please restart eth0 interface to apply INCR\n");
printk(" ~# ifconfig eth0 down\n");
printk(" ~# udhcpc\n");
break;
default:
printk("INCR value must be [0/1/2/4]\n");
printk(" 0: INCR disabled\n");
printk(" 1: INCR4\n");
printk(" 2: INCR8\n");
printk(" 4: INCR16\n");
}
} else {
return -EFAULT;
}

return count;
}

static struct file_operations en_fops = {
.open = simple_open,
.read = ftmac100_proc_read,
.write = ftmac100_proc_write,
};

static void create_seq_entry(struct entry_struct *e, mode_t mode,
struct proc_dir_entry *parent)
{

struct proc_dir_entry *entry = proc_create(e->name, mode, parent, e->fops);

if (!entry)
printk(KERN_ERR "invalid %s register.\n", e->name);
}

static void install_proc_table(struct entry_struct *table)
{
while (table->name) {

create_seq_entry(table, table->perm, proc_ftmac100_debug);
table++;
}
}

static void remove_proc_table(struct entry_struct *table)
{

while (table->name) {
remove_proc_entry(table->name, proc_ftmac100_debug);
table++;
}
}

struct entry_struct proc_table_ftmac100_debug[] = {

{"debug", 0644, &en_fops},
{"incr", 0644, &en_fops},
};
static int __init init_ftmac100_debug(void)
{

DEBUG(debug, 1, "ftmac100_debug module registered\n");

if(!(proc_ftmac100_debug = proc_mkdir("ftmac100_debug", NULL)))
return -ENOMEM;

install_proc_table(proc_table_ftmac100_debug);

return 0;
}

static void __exit cleanup_ftmac100_debug(void)
{

remove_proc_table(proc_table_ftmac100_debug);
remove_proc_entry("ftmac100_debug", NULL);

DEBUG(debug, 1, "ftmac100_debug module unregistered\n");
}

module_init(init_ftmac100_debug);
module_exit(cleanup_ftmac100_debug);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("ftmac100_debug Module");

0 comments on commit 86aca05

Please sign in to comment.