ARM-Linux驅(qū)動--DM9000網(wǎng)卡驅(qū)動分析(一)_第1頁
ARM-Linux驅(qū)動--DM9000網(wǎng)卡驅(qū)動分析(一)_第2頁
ARM-Linux驅(qū)動--DM9000網(wǎng)卡驅(qū)動分析(一)_第3頁
ARM-Linux驅(qū)動--DM9000網(wǎng)卡驅(qū)動分析(一)_第4頁
ARM-Linux驅(qū)動--DM9000網(wǎng)卡驅(qū)動分析(一)_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、ARM-Linux驅(qū)動-DM9000網(wǎng)卡驅(qū)動分析(一)1、下圖是DM9000的引腳圖2、這里我們結(jié)合具體的開發(fā)板FL2440下面是FL2440和DM9000的引腳鏈接圖本人移植DM9000的時候?qū)⒃O(shè)備的資源定義放在了arch/arm/plat-s3c24xx/devs.c中,詳情點擊上一篇博文linux內(nèi)核移植-移植內(nèi)核到s3c2440下面是設(shè)備的資源定義cpp view plaincopy1. /*DM9000*/  2. /* 定義該設(shè)備使用的資源 */  3. static struct

2、60;resource s3c_dm9000_resource =    4.         0 =  /* 寄存器定義在mach-s3c2410/include/mach/map.h */  5.         .start = S3C24XX_PA_DM9000, /*&

3、#160;實際地址  0x20000300 */  6.         .end   = S3C24XX_PA_DM9000+ 0x3, /* 0x20000303 */  7.         .flags = IORESOURCE_MEM /* 

4、;資源標(biāo)志為地址資源 */  8.         ,   9.         1=   10.         .start = S3C24XX_PA_DM9000 + 0x4, /CMD pin 

5、;is A2 0x20000304  11.         .end = S3C24XX_PA_DM9000 + 0x4 + 0x7c, / 0x20000380  12.         .flags = IORESOURCE_MEM /* 資源標(biāo)志為地址

6、資源 */  13.         ,   14.         2 =    15.         .start = IRQ_EINT7, /* 中斷為外部7號中斷 */  

7、;16.         .end   = IRQ_EINT7, /* 中斷為外部7號中斷 */  17.         .flags = IORESOURCE_IRQ /* 資源標(biāo)志為中斷資源 */  18.      

8、60;  ,   19. ;   這里可以看到,DM9000網(wǎng)卡使用的地址空間資源在nGCS4地址區(qū)域,所以上圖的DM9000地址使能引腳連接nGCS4引腳。中斷使用的是EINT7外部中斷。接著定義平臺數(shù)據(jù)和平臺設(shè)備,代碼如下:cpp view plaincopy1. /* 定義平臺數(shù)據(jù) */  2. static struct dm9000_plat_data s3c_device_dm9000_platdata =

9、0;   3.         .flags= DM9000_PLATF_16BITONLY,   4. ;   5.   6. /* 定義平臺設(shè)備 */  7. struct platform_device s3c_device_dm9000 =    8.   &#

10、160;     .name= "dm9000", /設(shè)備名,該名稱與平臺設(shè)備驅(qū)動中的名稱一致  9.         .id= 0,   10.         .num_resources= ARRAY_SIZE(s3c_dm9000_resource), 

11、0; 11.         .resource= s3c_dm9000_resource, /定義設(shè)備的資源  12.         .dev=    13.                

12、60;.platform_data = &s3c_device_dm9000_platdata, /定義平臺數(shù)據(jù)  14.             15. ;   最后導(dǎo)出函數(shù)符號,保存函數(shù)地址和名稱cpp view plaincopy1. EXPORT_SYMBOL(s3c_device_dm9000);  3、設(shè)備啟動的初始化過程cpp view

13、 plaincopy1. MACHINE_START(S3C2440, "SMDK2440")  2.         /* Maintainer: Ben Dooks <> */  3.         .phys_io    &

14、#160;   = S3C2410_PA_UART,  4.         .io_pg_offst    = (u32)S3C24XX_VA_UART) >> 18) & 0xfffc,  5.         .boot_params 

15、;   = S3C2410_SDRAM_PA + 0x100,  6.   7.         .init_irq       = s3c24xx_init_irq,/* 初始化中斷 */  8.         .m

16、ap_io         = smdk2440_map_io,  9.         .init_machine   = smdk2440_machine_init,/定義設(shè)備的初始化函數(shù)  10.         .timer  &#

17、160;       = &s3c24xx_timer,  11. MACHINE_END  而后會執(zhí)行下面函數(shù)cpp view plaincopy1. static void _init smdk2440_machine_init(void)  2.   3.         s3c24xx_fb_set_p

18、latdata(&smdk2440_fb_info);  4.         s3c_i2c0_set_platdata(NULL);  5.           6.         s3c24xx_ts_set_platdata(&smdk2410_ts_cfg);/*

19、0;Added by yan */  7.           8.         platform_add_devices(smdk2440_devices, ARRAY_SIZE(smdk2440_devices);/* 向平臺中添加設(shè)備 */  9.      

20、   smdk_machine_init();  10.   下面是具體的設(shè)備列表cpp view plaincopy1. static struct platform_device *smdk2440_devices _initdata =   2.         &s3c_device_ohci,  3.  

21、60;      &s3c_device_lcd,/* ok */  4.         &s3c_device_wdt,/* ok */  5.         &s3c_device_i2c0,  6.     

22、;    &s3c_device_iis,  7.         &s3c_device_rtc,/* ok */  8.         &s3c24xx_uda134x,  9.         &s3

23、c_device_dm9000,  10.         &s3c_device_adc,/* ok */  11.         &s3c_device_ts,/* ok */  12.           13. ;

24、  這樣系統(tǒng)啟動時,會給設(shè)備列表中的設(shè)備分配資源(地址資源和中斷資源等)。4、信息傳輸中的信息封裝結(jié)構(gòu)4.1、sk_buff結(jié)構(gòu),定義在include/linux/skbuff.h中cpp view plaincopy1. struct sk_buff   2.         /* These two members must be first. */  

25、3.         struct sk_buff          *next;  4.         struct sk_buff          *prev;  5. &

26、#160; 6.         ktime_t                 tstamp;  7.   8.         struct sock    

27、0;        *sk;  9.         struct net_device       *dev;  10.   11.         /* 12.    

28、0;     * This is the control buffer. It is free to use for every 13.          * layer. Please put your private variables there.

29、60;If you 14.          * want to keep them across layers you have to do a skb_clone() 15.          * first. This is 

30、;owned by whoever has the skb queued ATM. 16.          */  17.         char               

31、     cb48 _aligned(8);  18.   19.         unsigned long           _skb_refdst;  20. #ifdef CONFIG_XFRM  21.    

32、;     struct  sec_path        *sp;  22. #endif  23.         unsigned int            len,  

33、24.                                 data_len;  25.         _u16    

34、60;              mac_len,  26.                                

35、60;hdr_len;  27.         union   28.                 _wsum          csum;  29.   

36、0;             struct   30.                         _u16   csum_start;  31.

37、                         _u16   csum_offset;  32.                  

38、60;33.           34.         _u32                   priority;  35.       &#

39、160; kmemcheck_bitfield_begin(flags1);  36.         _u8                    local_df:1,  37.        &

40、#160;                        cloned:1,  38.                      

41、           ip_summed:2,  39.                                 nohdr:1, 

42、 40.                                 nfctinfo:3;  41.         _u8   &#

43、160;                pkt_type:3,  42.                              

44、;   fclone:2,  43.                                 ipvs_property:1,  44.      &#

45、160;                          peeked:1,  45.                    &

46、#160;            nf_trace:1;  46.         kmemcheck_bitfield_end(flags1);  47.         _be16        

47、          protocol;  48.   49.         void                    (*destructor)(struct s

48、k_buff *skb);  50. #if defined(CONFIG_NF_CONNTRACK) | defined(CONFIG_NF_CONNTRACK_MODULE)  51.         struct nf_conntrack     *nfct;  52.        

49、; struct sk_buff          *nfct_reasm;  53. #endif  54. #ifdef CONFIG_BRIDGE_NETFILTER  55.         struct nf_bridge_info   *nf_bridge; 

50、0;56. #endif  57.   58.         int                     skb_iif;  59. #ifdef CONFIG_NET_SCHED  60.   

51、;      _u16                   tc_index;       /* traffic control index */  61. #ifdef CONFIG_NET_CLS_ACT&

52、#160; 62.         _u16                   tc_verd;        /* traffic control verdict */  63

53、. #endif  64. #endif  65.   66.         _u32                   rxhash;  67.   68.      

54、60;  kmemcheck_bitfield_begin(flags2);  69.         _u16                   queue_mapping:16;  70. #ifdef CONFIG_IPV6_NDISC_NODETYP

55、E  71.         _u8                    ndisc_nodetype:2,  72.              &

56、#160;                  deliver_no_wcard:1;  73. #else  74.         _u8             &#

57、160;      deliver_no_wcard:1;  75. #endif  76.         kmemcheck_bitfield_end(flags2);  77.   78.         /* 0/14 bit hole */ 

58、; 79.   80. #ifdef CONFIG_NET_DMA  81.         dma_cookie_t            dma_cookie;  82. #endif  83. #ifdef CONFIG_NETWORK_SECMARK  84.

59、        _u32                   secmark;  85. #endif  86.         union   87.   &

60、#160;             _u32           mark;  88.                 _u32    &#

61、160;      dropcount;  89.           90.   91.         _u16                 

62、  vlan_tci;  92.   93.         sk_buff_data_t          transport_header;  94.         sk_buff_data_t     

63、     network_header;  95.         sk_buff_data_t          mac_header;  96.         /* These elements must 

64、;be at the end, see alloc_skb() for details.  */  97.         sk_buff_data_t          tail;  98.         

65、sk_buff_data_t          end;  99.         unsigned char           *head,  100.         

66、60;                       *data;  101.         unsigned int            

67、;truesize;  102.         atomic_t                users;  103. ;  元素的含義如下(摘自內(nèi)核,源碼,版本) *struct sk_buff - socket buffer * next: Next bu

68、ffer inlist * prev: Previous buffer in list * sk: Socketwe are owned by * tstamp: Time we arrived * dev:Device we arrived on/are leaving by * transport_header:Transport layer header * network_header: Network layerheader * mac_header: Link layer header *_skb_re

69、fdst: destination entry (with norefcount bit) * sp:the security path, used for xfrm * cb: Control buffer. Freefor use by every layer. Put private vars here * len: Lengthof actual data * data_len: Data length * mac_len:Length of link layer header * hdr_len: writable head

70、erlength of cloned skb * csum: Checksum (must includestart/offset pair) * csum_start: Offset from skb->headwhere checksumming should start * csum_offset: Offset fromcsum_start where checksum should be stored * local_df:allow local fragmentation * cloned: Head may be clone

71、d(check refcnt to be sure) * nohdr: Payload reference only,must not modify header * pkt_type: Packet class *fclone: skbuff clone status * ip_summed: Driver fed us anIP checksum * priority: Packet queueing priority *users: User count - see datagram,tcp.c * protocol:

72、Packet protocol from driver * truesize: Buffer size  *head: Head of buffer * data: Data head pointer *tail: Tail pointer * end: End pointer *destructor: Destruct function * mark: Generic packetmark * nfct: Associated connection, if any *ipvs_property

73、: skbuff is owned by ipvs * peeked: thispacket has been seen already, so stats have been * done forit, don't do them again * nf_trace: netfilter packet traceflag * nfctinfo: Relationship of this skb to theconnection * nfct_reasm: netfilter conntrack re-assemblypointer

74、60;* nf_bridge: Saved data about a bridged frame - seebr_netfilter.c * skb_iif: ifindex of device we arrivedon * rxhash: the packet hash computed on receive *queue_mapping: Queue mapping for multiqueue devices *tc_index: Traffic control index * tc_verd: traffic controlverdic

75、t * ndisc_nodetype: router type (from link layer) *dma_cookie: a cookie to one of several possible DMA operations *done by skb DMA functions * secmark: security marking *vlan_tci: vlan tag control information關(guān)于sk_buff的更多分析見另一篇轉(zhuǎn)載的博文4.2、net_device關(guān)于net_device一個非常龐大的結(jié)構(gòu)體,定義在/inl

76、cude/linux/netdevice.h中如下:cpp view plaincopy1. struct net_device   2.   3.     /* 4.      * This is the first field of the "visible" part of this 

77、;structure 5.      * (i.e. as seen by users in the "Space.c" file).  It is the name 6.      * the interface. 7.      */&

78、#160; 8.     char            nameIFNAMSIZ;  9.   10.     struct pm_qos_request_list *pm_qos_req;  11.   12.     /* devic

79、e name hash chain */  13.     struct hlist_node   name_hlist;  14.     /* snmp alias */  15.     char         

80、   *ifalias;  16.   17.     /* 18.      *  I/O specific fields 19.      *  FIXME: Merge these and struct ifmap into one&

81、#160;20.      */  21.     unsigned long       mem_end;    /* shared mem end   */  22.     unsigned long   

82、;    mem_start;  /* shared mem start */  23.     unsigned long       base_addr;  /* device I/O address   */  24.    

83、; unsigned int        irq;        /* device IRQ number    */  25.   26.     /* 27.      *  Some

84、 hardware also needs these fields, but they are not 28.      *  part of the usual set specified in Space.c. 29.      */  30.   31.

85、     unsigned char       if_port;    /* Selectable AUI, TP,.*/  32.     unsigned char       dma;      

86、60; /* DMA channel      */  33.   34.     unsigned long       state;  35.   36.     struct list_head    dev_li

87、st;  37.     struct list_head    napi_list;  38.     struct list_head    unreg_list;  39.   40.     /* Net device features */ 

88、; 41.     unsigned long       features;  42. #define NETIF_F_SG      1   /* Scatter/gather IO. */  43. #define NETIF_F_IP_CSUM   &

89、#160; 2   /* Can checksum TCP/UDP over IPv4. */  44. #define NETIF_F_NO_CSUM     4   /* Does not require checksum. F.e. loopack. */  45. #define 

90、NETIF_F_HW_CSUM     8   /* Can checksum all the packets. */  46. #define NETIF_F_IPV6_CSUM   16  /* Can checksum TCP/UDP over IPV6 */  47. #define

91、0;NETIF_F_HIGHDMA     32  /* Can DMA to high memory. */  48. #define NETIF_F_FRAGLIST    64  /* Scatter/gather IO. */  49. #define NETIF_F_HW_VLAN_TX  

92、;128 /* Transmit VLAN hw acceleration */  50. #define NETIF_F_HW_VLAN_RX  256 /* Receive VLAN hw acceleration */  51. #define NETIF_F_HW_VLAN_FILTER  512 /* Receive filtering&

93、#160;on VLAN */  52. #define NETIF_F_VLAN_CHALLENGED 1024    /* Device cannot handle VLAN packets */  53. #define NETIF_F_GSO     2048    /* Enable so

94、ftware GSO. */  54. #define NETIF_F_LLTX        4096    /* LockLess TX - deprecated. Please */  55.             

95、60;       /* do not use LLTX in new drivers */  56. #define NETIF_F_NETNS_LOCAL 8192    /* Does not change network namespaces */  57. #define

96、0;NETIF_F_GRO     16384   /* Generic receive offload */  58. #define NETIF_F_LRO     32768   /* large receive offload */  59.   60. /* the&#

97、160;GSO_MASK reserves bits 16 through 23 */  61. #define NETIF_F_FCOE_CRC    (1 << 24) /* FCoE CRC32 */  62. #define NETIF_F_SCTP_CSUM   (1 << 25) /

98、* SCTP checksum offload */  63. #define NETIF_F_FCOE_MTU    (1 << 26) /* Supports max FCoE MTU, 2158 bytes*/  64. #define NETIF_F_NTUPLE      (1 

99、;<< 27) /* N-tuple filters supported */  65. #define NETIF_F_RXHASH      (1 << 28) /* Receive hashing offload */  66.   67.     /* Se

100、gmentation offload features */  68. #define NETIF_F_GSO_SHIFT   16  69. #define NETIF_F_GSO_MASK    0x00ff0000  70. #define NETIF_F_TSO     (SKB_GSO_TCPV4 << NETIF_

101、F_GSO_SHIFT)  71. #define NETIF_F_UFO     (SKB_GSO_UDP << NETIF_F_GSO_SHIFT)  72. #define NETIF_F_GSO_ROBUST  (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT)  73. #define NETIF_F_TSO_ECN  &

102、#160;  (SKB_GSO_TCP_ECN << NETIF_F_GSO_SHIFT)  74. #define NETIF_F_TSO6        (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)  75. #define NETIF_F_FSO     (SKB_GSO_FCOE 

103、;<< NETIF_F_GSO_SHIFT)  76.   77.     /* List of features with software fallbacks. */  78. #define NETIF_F_GSO_SOFTWARE    (NETIF_F_TSO | NETIF_F_TSO_ECN | NET

104、IF_F_TSO6)  79.   80.   81. #define NETIF_F_GEN_CSUM    (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)  82. #define NETIF_F_V4_CSUM     (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM)  83. #define&

105、#160;NETIF_F_V6_CSUM     (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)  84. #define NETIF_F_ALL_CSUM    (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM)  85.   86.     /* 87.    &#

106、160; * If one device supports one of these features, then enable them 88.      * for all in netdev_increment_features. 89.      */  90. #define N

107、ETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST |   91.                  NETIF_F_SG | NETIF_F_HIGHDMA |       92. &#

108、160;                NETIF_F_FRAGLIST)  93.   94.     /* Interface index. Unique device identifier    */  95.   

109、0; int         ifindex;  96.     int         iflink;  97.   98.     struct net_device_stats stats;  99.   

110、;100. #ifdef CONFIG_WIRELESS_EXT  101.     /* List of functions to handle Wireless Extensions (instead of ioctl). 102.      * See <net/iw_handler.h> for detail

111、s. Jean II */  103.     const struct iw_handler_def *   wireless_handlers;  104.     /* Instance data managed by the core of Wireless Extensions. 

112、;*/  105.     struct iw_public_data * wireless_data;  106. #endif  107.     /* Management operations */  108.     const struct net_device_ops *netdev_ops;&

113、#160; 109.     const struct ethtool_ops *ethtool_ops;  110.   111.     /* Hardware header description */  112.     const struct header_ops *header_ops;

114、0; 113.   114.     unsigned int        flags;  /* interface flags (a la BSD)   */  115.     unsigned short     

115、; gflags;  116.         unsigned short          priv_flags; /* Like 'flags' but invisible to userspace. */  117.    &

116、#160;unsigned short      padded; /* How much padding added by alloc_netdev() */  118.   119.     unsigned char       operstate; /* RFC2

117、863 operstate */  120.     unsigned char       link_mode; /* mapping policy to operstate */  121.   122.     unsigned int    

118、    mtu;    /* interface MTU value      */  123.     unsigned short      type;   /* interface hardware type  *

119、/  124.     unsigned short      hard_header_len;    /* hardware hdr length  */  125.   126.     /* extra head- and tailroom t

120、he hardware may need, but not in all cases 127.      * can this be guaranteed, especially tailroom. Some cases also use 128.      * LL_MAX_HEADER

121、 instead to allocate the skb. 129.      */  130.     unsigned short      needed_headroom;  131.     unsigned short     &

122、#160;needed_tailroom;  132.   133.     struct net_device   *master; /* Pointer to master device of a group, 134.              

123、0;        * which this device is member of. 135.                       */  136.   137.  &#

124、160;  /* Interface address info. */  138.     unsigned char       perm_addrMAX_ADDR_LEN; /* permanent hw address */  139.     unsigned char&

125、#160;      addr_len;   /* hardware address length  */  140.     unsigned short          dev_id;     /* for sha

126、red network cards */  141.   142.     spinlock_t      addr_list_lock;  143.     struct netdev_hw_addr_list  uc; /* Unicast mac addresses */ 

127、 144.     struct netdev_hw_addr_list  mc; /* Multicast mac addresses */  145.     int         uc_promisc;  146.     unsigned 

128、int        promiscuity;  147.     unsigned int        allmulti;  148.   149.   150.     /* Protocol specific pointers

129、60;*/  151.       152. #ifdef CONFIG_NET_DSA  153.     void            *dsa_ptr;   /* dsa specific data */  154. #endif&

130、#160; 155.     void            *atalk_ptr; /* AppleTalk link   */  156.     void            *ip

131、_ptr;    /* IPv4 specific data   */  157.     void                    *dn_ptr;       

132、 /* DECnet specific data */  158.     void                    *ip6_ptr;       /* IPv6 specific 

133、data */  159.     void            *ec_ptr;    /* Econet specific data */  160.     void        

134、    *ax25_ptr;  /* AX.25 specific data */  161.     struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data, 162.          

135、60;                 assign before registering */  163.   164. /* 165.  * Cache line mostly used on receive path (including eth_type_trans() 166.  */  167. 

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論