⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dm9000 network driver - linux_kernel google 网上论坛.htm

📁 Dm9000网络接口驱动大全
💻 HTM
📖 第 1 页 / 共 5 页
字号:
            target=_parent>...</A>@simtec.co.uk&gt; <BR>+ * &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Cleanup of code to 
            remove ifdefs <BR>+ * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; Allowed platform device data to 
            influence access width <BR>+ * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Reformatting areas of code <BR>+ 
            * <BR>+ * &nbsp; &nbsp; &nbsp; &nbsp;17-Mar-2005 &nbsp; Sascha Hauer 
            &lt;s.ha<A 
            href="http://groups.google.com/groups/unlock?msg=997a80484234d5ce&amp;_done=/group/linux.kernel/msg/997a80484234d5ce" 
            target=_parent>...</A>@pengutronix.de&gt; <BR>+ * &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* 
            removed 2.4 style module parameters <BR>+ * &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* removed 
            removed unused stat counter and fixed <BR>+ * &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;net_device_stats <BR>+ * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* introduced tx_timeout 
            function <BR>+ * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;* reworked locking <BR>+ */ <BR>+ 
            <BR>+#include &lt;linux/module.h&gt; <BR>+#include 
            &lt;linux/ioport.h&gt; <BR>+#include &lt;linux/netdevice.h&gt; 
            <BR>+#include &lt;linux/etherdevice.h&gt; <BR>+#include 
            &lt;linux/init.h&gt; <BR>+#include &lt;linux/skbuff.h&gt; 
            <BR>+#include &lt;linux/version.h&gt; <BR>+#include 
            &lt;linux/spinlock.h&gt; <BR>+#include &lt;linux/crc32.h&gt; 
            <BR>+#include &lt;linux/mii.h&gt; <BR>+#include 
            &lt;linux/dm9000.h&gt; <BR>+#include &lt;linux/delay.h&gt; <BR>+ 
            <BR>+#include &lt;asm/delay.h&gt; <BR>+#include &lt;asm/irq.h&gt; 
            <BR>+#include &lt;asm/io.h&gt; <BR>+ <BR>+#include "dm9000.h" <BR>+ 
            <BR>+/* Board/System/Debug information/definition ---------------- 
            */ <BR>+ <BR>+#define DM9000_PHY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; 0x40 &nbsp; &nbsp;/* PHY address 0x01 */ <BR>+ <BR>+#define 
            TRUE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            1 <BR>+#define FALSE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;0 <BR>+ <BR>+#define CARDNAME "dm9000" 
            <BR>+#define PFX CARDNAME ": " <BR>+ <BR>+#define DM9000_TIMER_WUT 
            &nbsp;jiffies+(HZ*2) &nbsp; &nbsp; &nbsp; /* timer wakeup time : 2 
            second */ <BR>+ <BR>+#define DM9000_DEBUG 0 <BR>+ <BR>+#if 
            DM9000_DEBUG &gt; 2 <BR>+#define PRINTK3(args...) 
            &nbsp;printk(CARDNAME ": " args) <BR>+#else <BR>+#define 
            PRINTK3(args...) &nbsp;do { } while(0) <BR>+#endif <BR>+ <BR>+#if 
            DM9000_DEBUG &gt; 1 <BR>+#define PRINTK2(args...) 
            &nbsp;printk(CARDNAME ": " args) <BR>+#else <BR>+#define 
            PRINTK2(args...) &nbsp;do { } while(0) <BR>+#endif <BR>+ <BR>+#if 
            DM9000_DEBUG &gt; 0 <BR>+#define PRINTK1(args...) 
            &nbsp;printk(CARDNAME ": " args) <BR>+#define PRINTK(args...) &nbsp; 
            printk(CARDNAME ": " args) <BR>+#else <BR>+#define PRINTK1(args...) 
            &nbsp;do { } while(0) <BR>+#define PRINTK(args...) &nbsp; 
            printk(KERN_DEBUG args) <BR>+#endif <BR>+ <BR>+/* <BR>+ * Transmit 
            timeout, default 5 seconds. <BR>+ */ <BR>+static int watchdog = 
            5000; <BR>+module_param(watchdog, int, 0400); 
            <BR>+MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds"); 
            <BR>+ <BR>+/* Structure/enum declaration 
            ------------------------------- */ <BR>+typedef struct board_info { 
            <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; void __iomem *io_addr; &nbsp;/* 
            Register I/O base address */ <BR>+ &nbsp; &nbsp; &nbsp; void __iomem 
            *io_data; &nbsp;/* Data I/O address */ <BR>+ &nbsp; &nbsp; &nbsp; 
            u16 irq; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* 
            IRQ */ <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; u16 tx_pkt_cnt; <BR>+ &nbsp; 
            &nbsp; &nbsp; u16 queue_pkt_len; <BR>+ &nbsp; &nbsp; &nbsp; u16 
            queue_start_addr; <BR>+ &nbsp; &nbsp; &nbsp; u16 dbug_cnt; <BR>+ 
            &nbsp; &nbsp; &nbsp; u8 io_mode; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; /* 0:word, 2:byte */ <BR>+ &nbsp; &nbsp; &nbsp; u8 phy_addr; 
            <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; void (*inblk)(void __iomem *port, 
            void *data, int length); <BR>+ &nbsp; &nbsp; &nbsp; void 
            (*outblk)(void __iomem *port, void *data, int length); <BR>+ &nbsp; 
            &nbsp; &nbsp; void (*dumpblk)(void __iomem *port, int length); <BR>+ 
            <BR>+ &nbsp; &nbsp; &nbsp; struct resource *addr_res; &nbsp; /* 
            resources found */ <BR>+ &nbsp; &nbsp; &nbsp; struct resource 
            *data_res; <BR>+ &nbsp; &nbsp; &nbsp; struct resource *addr_req; 
            &nbsp; /* resources requested */ <BR>+ &nbsp; &nbsp; &nbsp; struct 
            resource *data_req; <BR>+ &nbsp; &nbsp; &nbsp; struct resource 
            *irq_res; <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; struct timer_list timer; 
            <BR>+ &nbsp; &nbsp; &nbsp; struct net_device_stats stats; <BR>+ 
            &nbsp; &nbsp; &nbsp; unsigned char srom[128]; <BR>+ &nbsp; &nbsp; 
            &nbsp; spinlock_t lock; <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; struct 
            mii_if_info mii; <BR>+ &nbsp; &nbsp; &nbsp; u32 msg_enable; <BR>+} 
            board_info_t; <BR>+ <BR>+/* function declaration 
            ------------------------------------- */ <BR>+static int 
            dm9000_probe(struct device *); <BR>+static int dm9000_open(struct 
            net_device *); <BR>+static int dm9000_start_xmit(struct sk_buff *, 
            struct net_device *); <BR>+static int dm9000_stop(struct net_device 
            *); <BR>+static int dm9000_do_ioctl(struct net_device *, struct 
            ifreq *, int); <BR>+ <BR>+ <BR>+static void dm9000_timer(unsigned 
            long); <BR>+static void dm9000_init_dm9000(struct net_device *); 
            <BR>+ <BR>+static struct net_device_stats *dm9000_get_stats(struct 
            net_device *); <BR>+ <BR>+static irqreturn_t dm9000_interrupt(int, 
            void *, struct pt_regs *); <BR>+ <BR>+static int 
            dm9000_phy_read(struct net_device *dev, int phyaddr_unsused, int 
            reg); <BR>+static void dm9000_phy_write(struct net_device *dev, int 
            phyaddr_unused, int reg, <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int value); 
            <BR>+static u16 read_srom_word(board_info_t *, int); <BR>+static 
            void dm9000_rx(struct net_device *); <BR>+static void 
            dm9000_hash_table(struct net_device *); <BR>+ <BR>+//#define 
            DM9000_PROGRAM_EEPROM <BR>+#ifdef DM9000_PROGRAM_EEPROM <BR>+static 
            void program_eeprom(board_info_t * db); <BR>+#endif <BR>+/* DM9000 
            network board routine ---------------------------- */ <BR>+ 
            <BR>+static void <BR>+dm9000_reset(board_info_t * db) <BR>+{ <BR>+ 
            &nbsp; &nbsp; &nbsp; PRINTK1("dm9000x: resetting\n"); <BR>+ &nbsp; 
            &nbsp; &nbsp; /* RESET device */ <BR>+ &nbsp; &nbsp; &nbsp; 
            writeb(DM9000_NCR, db-&gt;io_addr); <BR>+ &nbsp; &nbsp; &nbsp; 
            udelay(200); <BR>+ &nbsp; &nbsp; &nbsp; writeb(NCR_RST, 
            db-&gt;io_data); <BR>+ &nbsp; &nbsp; &nbsp; udelay(200); <BR>+} 
            <BR>+ <BR>+/* <BR>+ * &nbsp; Read a byte from I/O port <BR>+ */ 
            <BR>+static u8 <BR>+ior(board_info_t * db, int reg) <BR>+{ <BR>+ 
            &nbsp; &nbsp; &nbsp; writeb(reg, db-&gt;io_addr); <BR>+ &nbsp; 
            &nbsp; &nbsp; return readb(db-&gt;io_data); <BR>+} <BR>+ <BR>+/* 
            <BR>+ * &nbsp; Write a byte to I/O port <BR>+ */ <BR>+ <BR>+static 
            void <BR>+iow(board_info_t * db, int reg, int value) <BR>+{ <BR>+ 
            &nbsp; &nbsp; &nbsp; writeb(reg, db-&gt;io_addr); <BR>+ &nbsp; 
            &nbsp; &nbsp; writeb(value, db-&gt;io_data); <BR>+} <BR>+ <BR>+/* 
            routines for sending block to chip */ <BR>+ <BR>+static void 
            dm9000_outblk_8bit(void __iomem *reg, void *data, int count) <BR>+{ 
            <BR>+ &nbsp; &nbsp; &nbsp; writesb(reg, data, count); <BR>+} <BR>+ 
            <BR>+static void dm9000_outblk_16bit(void __iomem *reg, void *data, 
            int count) <BR>+{ <BR>+ &nbsp; &nbsp; &nbsp; writesw(reg, data, 
            (count+1) &gt;&gt; 1); <BR>+} <BR>+ <BR>+static void 
            dm9000_outblk_32bit(void __iomem *reg, void *data, int count) <BR>+{ 
            <BR>+ &nbsp; &nbsp; &nbsp; writesl(reg, data, (count+3) &gt;&gt; 2); 
            <BR>+} <BR>+ <BR>+/* input block from chip to memory */ <BR>+ 
            <BR>+static void dm9000_inblk_8bit(void __iomem *reg, void *data, 
            int count) <BR>+{ <BR>+ &nbsp; &nbsp; &nbsp; readsb(reg, data, 
            count+1); <BR>+} <BR>+ <BR>+ <BR>+static void 
            dm9000_inblk_16bit(void __iomem *reg, void *data, int count) <BR>+{ 
            <BR>+ &nbsp; &nbsp; &nbsp; readsw(reg, data, (count+1) &gt;&gt; 1); 
            <BR>+} <BR>+ <BR>+static void dm9000_inblk_32bit(void __iomem *reg, 
            void *data, int count) <BR>+{ <BR>+ &nbsp; &nbsp; &nbsp; readsl(reg, 
            data, (count+3) &gt;&gt; 2); <BR>+} <BR>+ <BR>+/* dump block from 
            chip to null */ <BR>+ <BR>+static void dm9000_dumpblk_8bit(void 
            __iomem *reg, int count) <BR>+{ <BR>+ &nbsp; &nbsp; &nbsp; int i; 
            <BR>+ &nbsp; &nbsp; &nbsp; int tmp; <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; 
            for (i = 0; i &lt; count; i++) <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; tmp = readb(reg); <BR>+} <BR>+ <BR>+static void 
            dm9000_dumpblk_16bit(void __iomem *reg, int count) <BR>+{ <BR>+ 
            &nbsp; &nbsp; &nbsp; int i; <BR>+ &nbsp; &nbsp; &nbsp; int tmp; 
            <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; count = (count + 1) &gt;&gt; 1; 
            <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; for (i = 0; i &lt; count; i++) 
            <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmp = 
            readw(reg); <BR>+} <BR>+ <BR>+static void dm9000_dumpblk_32bit(void 
            __iomem *reg, int count) <BR>+{ <BR>+ &nbsp; &nbsp; &nbsp; int i; 
            <BR>+ &nbsp; &nbsp; &nbsp; int tmp; <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; 
            count = (count + 3) &gt;&gt; 2; <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; for 
            (i = 0; i &lt; count; i++) <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; tmp = readl(reg); <BR>+} <BR>+ <BR>+/* dm9000_set_io 
            <BR>+ * <BR>+ * select the specified set of io routines to use with 
            the <BR>+ * device <BR>+ */ <BR>+ <BR>+static void 
            dm9000_set_io(struct board_info *db, int byte_width) <BR>+{ <BR>+ 
            &nbsp; &nbsp; &nbsp; /* use the size of the data resource to work 
            out what IO <BR>+ &nbsp; &nbsp; &nbsp; &nbsp;* routines we want to 
            use <BR>+ &nbsp; &nbsp; &nbsp; &nbsp;*/ <BR>+ <BR>+ &nbsp; &nbsp; 
            &nbsp; switch (byte_width) { <BR>+ &nbsp; &nbsp; &nbsp; case 1: 
            <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            db-&gt;dumpblk = dm9000_dumpblk_8bit; <BR>+ &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; db-&gt;outblk &nbsp;= 
            dm9000_outblk_8bit; <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; db-&gt;inblk &nbsp; = dm9000_inblk_8bit; <BR>+ &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; <BR>+ <BR>+ &nbsp; &nbsp; 
            &nbsp; case 2: <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; db-&gt;dumpblk = dm9000_dumpblk_16bit; <BR>+ &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db-&gt;outblk &nbsp;= 
            dm9000_outblk_16bit; <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; db-&gt;inblk &nbsp; = dm9000_inblk_16bit; <BR>+ &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; <BR>+ &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>+ &nbsp; 
            &nbsp; &nbsp; case 3: <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; printk(KERN_ERR PFX ": 3 byte IO, falling back to 
            16bit\n"); <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            db-&gt;dumpblk = dm9000_dumpblk_16bit; <BR>+ &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; db-&gt;outblk &nbsp;= 
            dm9000_outblk_16bit; <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; db-&gt;inblk &nbsp; = dm9000_inblk_16bit; <BR>+ &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>+ <BR>+ &nbsp; &nbsp; 
            &nbsp; case 4: <BR>+ &nbsp; &nbsp; &nbsp; default: <BR>+ &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db-&gt;dumpblk = 
            dm9000_dumpblk_32bit; <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; db-&gt;outblk &nbsp;= dm9000_outblk_32bit; <BR>+ 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db-&gt;inblk &nbsp; 
            = dm9000_inblk_32bit; <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; break; <BR>+ &nbsp; &nbsp; &nbsp; } <BR>+} <BR>+ <BR>+ 
            <BR>+/* Our watchdog timed out. Called by the networking layer */ 
            <BR>+static void dm9000_timeout(struct net_device *dev) <BR>+{ <BR>+ 
            &nbsp; &nbsp; &nbsp; board_info_t *db = (board_info_t *) 
            dev-&gt;priv; <BR>+ &nbsp; &nbsp; &nbsp; u8 reg_save; <BR>+ &nbsp; 
            &nbsp; &nbsp; unsigned long flags; &nbsp; &nbsp; <BR>+ <BR>+ &nbsp; 
            &nbsp; &nbsp; /* Save previous register address */ <BR>+ &nbsp; 
            &nbsp; &nbsp; reg_save = readb(db-&gt;io_addr); <BR>+ &nbsp; &nbsp; 
            &nbsp; spin_lock_irqsave(db-&gt;lock,flags); <BR>+ <BR>+ &nbsp; 
            &nbsp; &nbsp; netif_stop_queue(dev); <BR>+ &nbsp; &nbsp; &nbsp; 
            dm9000_reset(db); <BR>+ &nbsp; &nbsp; &nbsp; 
            dm9000_init_dm9000(dev); <BR>+ &nbsp; &nbsp; &nbsp; /* We can accept 
            TX packets again */ <BR>+ &nbsp; &nbsp; &nbsp; dev-&gt;trans_start = 
            jiffies; <BR>+ &nbsp; &nbsp; &nbsp; netif_wake_queue(dev); <BR>+ 
            <BR>+ &nbsp; &nbsp; &nbsp; /* Restore previous register address */ 
            <BR>+ &nbsp; &nbsp; &nbsp; writeb(reg_save, db-&gt;io_addr); <BR>+ 
            &nbsp; &nbsp; &nbsp; spin_unlock_irqrestore(db-&gt;lock,flags); 
            <BR>+} <BR>+ <BR>+ <BR>+/* dm9000_release_board <BR>+ * <BR>+ * 
            release a board, and any mapped resources <BR>+ */ <BR>+ <BR>+static 
            void <BR>+dm9000_release_board(struct platform_device *pdev, struct 
            board_info *db) <BR>+{ <BR>+ &nbsp; &nbsp; &nbsp; if 
            (db-&gt;data_res == NULL) { <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; if (db-&gt;addr_res != NULL) <BR>+ &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            release_mem_region((unsigned long)db-&gt;io_addr, 4); <BR>+ &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; <BR>+ &nbsp; 
            &nbsp; &nbsp; } <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; /* unmap our 
            resources */ <BR>+ &nbsp; &nbsp; &nbsp; <BR>+ &nbsp; &nbsp; &nbsp; 
            iounmap(db-&gt;io_addr); <BR>+ &nbsp; &nbsp; &nbsp; 
            iounmap(db-&gt;io_data); <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; /* release 
            the resources */ <BR>+ <BR>+ &nbsp; &nbsp; &nbsp; if 
            (db-&gt;data_req != NULL) { <BR>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; release_resource(db-&gt;data_req); <BR>+ &nbsp; &nbsp; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -