SlideShare ist ein Scribd-Unternehmen logo
1 von 14
ETHERNET DEVICE DRIVER 
1
Application 
Socket interface 
TCP/UDP protocol 
IP protocol 
2 
網路Driver架構 
Ethernet Hardware Device Driver
它收送都是有封包關念 
它是一種broadcast的網路封包 
MAC位址必需向世界組織申請,在同一個 
local LAN需是唯一的,並且它只存在local 
LAN,在internet中會被去除。 
3 
認識ethernet封包 
Dest MAC Source MAC Type Payload 
6 bytes 6 bytes 2 bytes Max 1566 bytes 
Max 1580 bytes
4 
開發流程 
宣告struct 
net_device 結構變數 
或 
用alloc_etherdev() 
設定必要的callback 
fuction在上述的結構 
中 
呼叫 
register_netdev()註 
冊該driver 
系統呼叫init callback 
function初始化該元件 
啓動該介面時系統會 
呼叫open callback 
function 
送資料時系統呼叫 
hard_start_xmit 
callback function 
當收到資料時 
可呼叫 
netif_rx()往 
上層送資料
struct net_device 
struct net_device 
{ 
char name[IFNAMSIZ]; 
………………………………….. 
unsigned long base_addr; /* device I/O address */ 
unsigned int irq; /* device IRQ number */ 
struct net_device_stats* (*get_stats)(struct net_device *dev); 
const struct ethtool_ops *ethtool_ops; 
int (*open)(struct net_device *dev); 
int (*stop)(struct net_device *dev); 
void (*set_multicast_list)(struct net_device *dev); 
int (*do_ioctl)(struct net_device *dev, 
struct ifreq *ifr, int cmd); 
void (*tx_timeout) (struct net_device *dev); 
unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address, 
(before bcast 
because most packets are unicast) */ 
……………………………………. 
}
Module init example (dm9000.c) 
static struct platform_driver dm9000_driver = { 
.driver = { 
.name = "dm9000", 
.owner = THIS_MODULE, 
}, 
.probe = dm9000_probe, 
.remove = __devexit_p(dm9000_drv_remove), 
.suspend = dm9000_drv_suspend, 
.resume = dm9000_drv_resume, 
}; 
static int __init dm9000_init(void) 
{ 
printk(KERN_INFO "%s Ethernet Driver, V%sn", CARDNAME, DRV_VERSION); 
return platform_driver_register(&dm9000_driver); 
} 
static void __exitdm9000_cleanup(void) 
{ 
platform_driver_unregister(&dm9000_driver); 
} 
module_init(dm9000_init); 
module_exit(dm9000_cleanup);
Probe example (dm9000.c) 
static int __devinit dm9000_probe(struct platform_device *pdev) 
{ 
………………………. 
ndev = alloc_etherdev(sizeof(struct board_info)); 
……………………… 
db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 
……………………. 
db->addr_req = request_mem_region(db->addr_res->start, iosize, 
pdev->name); 
db->io_addr = ioremap(db->addr_res->start, iosize); 
/* fill in parameters for net-dev structure */ 
ndev->base_addr = (unsigned long)db->io_addr; 
ndev->irq = db->irq_res->start; 
/* driver system function */ 
ether_setup(ndev); 
ndev->open = &dm9000_open; 
ndev->hard_start_xmit = &dm9000_start_xmit; 
ndev->tx_timeout = &dm9000_timeout; 
ndev->watchdog_timeo = msecs_to_jiffies(watchdog); 
ndev->stop = &dm9000_stop; 
ndev->set_multicast_list = &dm9000_hash_table; 
ndev->ethtool_ops = &dm9000_ethtool_ops; 
ndev->do_ioctl = &dm9000_ioctl; 
………………. 
ret = register_netdev(ndev); 
return 0; 
}
上傳資料 
1) 可用interrupt service routine or polling將底層的資 
料收進來 
2) 呼叫netif_rx()上傳資料 
下傳資料 
1) 上層將會呼叫所註冊的hard_start_xmit() callback 
function 
Allocate buffer kernel API 
1) struct sk_buff *alloc_skb(unsigned int size,gfp_t 
priority) 
8 
如何上下傳資料
Start xmit example 
/* Move data to DM9000 TX RAM */ 
writeb(DM9000_MWCMD, db->io_addr); 
(db->outblk)(db->io_data, skb->data, skb->len); 
dev->stats.tx_bytes += skb->len; 
db->tx_pkt_cnt++; 
/* TX control: First packet immediately send, second packet queue */ 
if (db->tx_pkt_cnt == 1) { 
/* Set TX length to DM9000 */ 
iow(db, DM9000_TXPLL, skb->len); 
iow(db, DM9000_TXPLH, skb->len >> 8); 
/* Issue TX polling command */ 
iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ 
dev->trans_start = jiffies; /* save the time stamp */ 
} else { 
/* Second packet */ 
db->queue_pkt_len = skb->len; 
netif_stop_queue(dev); 
} 
/* free this SKB */ 
dev_kfree_skb(skb); 
return 0;
Receive packet interrupt example 
if (GoodPacket 
&& ((skb = dev_alloc_skb(RxLen + 4)) != NULL)) { 
skb_reserve(skb, 2); 
rdptr = (u8 *) skb_put(skb, RxLen - 4); 
/* Read received packet from RX SRAM */ 
(db->inblk)(db->io_data, rdptr, RxLen); 
dev->stats.rx_bytes += RxLen; 
/* Pass to upper layer */ 
skb->protocol = eth_type_trans(skb, dev); 
netif_rx(skb); 
dev->stats.rx_packets++; 
} else { 
/* need to dump the packet's data */ 
(db->dumpblk)(db->io_data, RxLen); 
}
struct sk_buff { 
struct sk_buff *next; 
struct sk_buff *prev; 
………………………….. 
unsigned char *data; 
unsigned int len; 
…………. 
} 
11 
skb buffer stream 
struct sk_buff { 
struct sk_buff *next; 
struct sk_buff *prev; 
………………………….. 
unsigned char *data; 
unsigned int len; 
…………. 
} 
Data 
buffer 
Data 
buffer
Tx/Rx Buffer Management 
12 
Buffer Descriptor 
Start Address 
Register 
+ 
BRXBDCNT+0 
… … 
BDMATXDPTR 
buffer pointer #1 
status length 
buffer pointer #2 
status length 
buffer pointer #N 
status length 
Buffer Descriptor Rx Buffer 
… … … 
buffer #1 
not used 
buffer #2 
not used 
buffer #N 
not used 
Memory for frame 
BRXBDCNT+1 
BRXBDCNT+(N-1) 
BRxBS of 
BDMARXLEN 
BRxBS of 
BDMARXLEN 
BRxBS of 
BDMARXLEN 
BDMA buffer 
descriptor 
counter of 
current pointer 
… 
Memory for Rx buffer descriptor
skb buffer由下而上時是由ethernet device 
driver allocate,而由上層的TCP free 
skb buffer由上而下時是由TCP allocate,而 
由底層的ethernet free 
其中在open的call back function需要 
netif_start_queue() 
在close時需要netif_stop_queue() 
在timeout時需要netif_wake_queue() 
13 
注意事項
若網路元件有支援DMA功能,則盡量使用 
以提供網路傳輸效能。 
若網路元件和CPU之間有共用的記憶體,記 
得必需要設定為non-cache。 
在中斷程式中最好不要做搬動資料的動作, 
最好使用schedule_work()來完成,可是這會 
有一個問題就是較不real-time。 
研讀程式drivers/net/my_mac.c 
14 
注意事項

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Embedded Operating System - Linux
Embedded Operating System - LinuxEmbedded Operating System - Linux
Embedded Operating System - Linux
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
 
Introduction to char device driver
Introduction to char device driverIntroduction to char device driver
Introduction to char device driver
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Linux device driver
Linux device driverLinux device driver
Linux device driver
 
PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to Userspace
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
 
Linux Device Driver’s
Linux Device Driver’sLinux Device Driver’s
Linux Device Driver’s
 
DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
 

Andere mochten auch

Ethernet and TCP optimizations
Ethernet and TCP optimizationsEthernet and TCP optimizations
Ethernet and TCP optimizationsJeff Squyres
 
introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack monad bobo
 
Three Reasons your Qualifying Income may Cause Confusion on an FHA Loan
Three Reasons your Qualifying Income may Cause Confusion on an FHA LoanThree Reasons your Qualifying Income may Cause Confusion on an FHA Loan
Three Reasons your Qualifying Income may Cause Confusion on an FHA LoanMortgage Commentator
 
物流系統解決方案
物流系統解決方案物流系統解決方案
物流系統解決方案艾鍗科技
 
艾鍗學院-單晶片韌體-CC2500通訊實驗
艾鍗學院-單晶片韌體-CC2500通訊實驗艾鍗學院-單晶片韌體-CC2500通訊實驗
艾鍗學院-單晶片韌體-CC2500通訊實驗艾鍗科技
 
Linux SD/MMC device driver
Linux SD/MMC device driverLinux SD/MMC device driver
Linux SD/MMC device driver艾鍗科技
 
艾鍗學院-單晶片韌體開發- LCM模組實驗
艾鍗學院-單晶片韌體開發- LCM模組實驗艾鍗學院-單晶片韌體開發- LCM模組實驗
艾鍗學院-單晶片韌體開發- LCM模組實驗艾鍗科技
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學 艾鍗科技
 
Networking in linux
Networking in linuxNetworking in linux
Networking in linuxVarnnit Jain
 
An Internet Based Interactive Data Acquisition System
An Internet Based Interactive Data Acquisition System An Internet Based Interactive Data Acquisition System
An Internet Based Interactive Data Acquisition System Saptarshi Nag
 
Linux Network commands
Linux Network commandsLinux Network commands
Linux Network commandsHanan Nmr
 
Chapter09 -- networking with unix and linux
Chapter09  -- networking with unix and linuxChapter09  -- networking with unix and linux
Chapter09 -- networking with unix and linuxRaja Waseem Akhtar
 
Linux Networking Explained
Linux Networking ExplainedLinux Networking Explained
Linux Networking ExplainedThomas Graf
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughThomas Graf
 
Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01Hajime Tazaki
 
Writing c code for the 8051
Writing c code for the 8051Writing c code for the 8051
Writing c code for the 8051Quản Minh Tú
 

Andere mochten auch (19)

Ethernet and TCP optimizations
Ethernet and TCP optimizationsEthernet and TCP optimizations
Ethernet and TCP optimizations
 
introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack
 
運動腰帶
運動腰帶運動腰帶
運動腰帶
 
Three Reasons your Qualifying Income may Cause Confusion on an FHA Loan
Three Reasons your Qualifying Income may Cause Confusion on an FHA LoanThree Reasons your Qualifying Income may Cause Confusion on an FHA Loan
Three Reasons your Qualifying Income may Cause Confusion on an FHA Loan
 
物流系統解決方案
物流系統解決方案物流系統解決方案
物流系統解決方案
 
艾鍗學院-單晶片韌體-CC2500通訊實驗
艾鍗學院-單晶片韌體-CC2500通訊實驗艾鍗學院-單晶片韌體-CC2500通訊實驗
艾鍗學院-單晶片韌體-CC2500通訊實驗
 
Linux SD/MMC device driver
Linux SD/MMC device driverLinux SD/MMC device driver
Linux SD/MMC device driver
 
艾鍗學院-單晶片韌體開發- LCM模組實驗
艾鍗學院-單晶片韌體開發- LCM模組實驗艾鍗學院-單晶片韌體開發- LCM模組實驗
艾鍗學院-單晶片韌體開發- LCM模組實驗
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學
 
Networking in linux
Networking in linuxNetworking in linux
Networking in linux
 
An Internet Based Interactive Data Acquisition System
An Internet Based Interactive Data Acquisition System An Internet Based Interactive Data Acquisition System
An Internet Based Interactive Data Acquisition System
 
Linux Network commands
Linux Network commandsLinux Network commands
Linux Network commands
 
Chapter09 -- networking with unix and linux
Chapter09  -- networking with unix and linuxChapter09  -- networking with unix and linux
Chapter09 -- networking with unix and linux
 
Linux Kernel Overview
Linux Kernel OverviewLinux Kernel Overview
Linux Kernel Overview
 
Interrupts
InterruptsInterrupts
Interrupts
 
Linux Networking Explained
Linux Networking ExplainedLinux Networking Explained
Linux Networking Explained
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
 
Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01
 
Writing c code for the 8051
Writing c code for the 8051Writing c code for the 8051
Writing c code for the 8051
 

Ähnlich wie Linux Ethernet device driver

Xdp and ebpf_maps
Xdp and ebpf_mapsXdp and ebpf_maps
Xdp and ebpf_mapslcplcp1
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Adrian Huang
 
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...Databricks
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux KernelKernel TLV
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsHisaki Ohara
 
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoCapturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoScyllaDB
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Kernel TLV
 
Introduction to Apache Mesos
Introduction to Apache MesosIntroduction to Apache Mesos
Introduction to Apache MesosJoe Stein
 
Owasp Indy Q2 2012 Advanced SQLi
Owasp Indy Q2 2012 Advanced SQLiOwasp Indy Q2 2012 Advanced SQLi
Owasp Indy Q2 2012 Advanced SQLiowaspindy
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver艾鍗科技
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelVitaly Nikolenko
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]RootedCON
 
Scaling IO-bound microservices
Scaling IO-bound microservicesScaling IO-bound microservices
Scaling IO-bound microservicesSalo Shp
 
Logical volume manager xfs
Logical volume manager xfsLogical volume manager xfs
Logical volume manager xfsSarwar Javaid
 
Sedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsSedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsIvan Shcheklein
 

Ähnlich wie Linux Ethernet device driver (20)

Xdp and ebpf_maps
Xdp and ebpf_mapsXdp and ebpf_maps
Xdp and ebpf_maps
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...
 
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
Analyzing the Performance Effects of Meltdown + Spectre on Apache Spark Workl...
 
Genode Compositions
Genode CompositionsGenode Compositions
Genode Compositions
 
Sockets and Socket-Buffer
Sockets and Socket-BufferSockets and Socket-Buffer
Sockets and Socket-Buffer
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux Kernel
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoCapturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
Introduction to Apache Mesos
Introduction to Apache MesosIntroduction to Apache Mesos
Introduction to Apache Mesos
 
Owasp Indy Q2 2012 Advanced SQLi
Owasp Indy Q2 2012 Advanced SQLiOwasp Indy Q2 2012 Advanced SQLi
Owasp Indy Q2 2012 Advanced SQLi
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
 
Apache Spark Workshop
Apache Spark WorkshopApache Spark Workshop
Apache Spark Workshop
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
 
netLec2.pdf
netLec2.pdfnetLec2.pdf
netLec2.pdf
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
 
Scaling IO-bound microservices
Scaling IO-bound microservicesScaling IO-bound microservices
Scaling IO-bound microservices
 
Using Netconf/Yang with OpenDalight
Using Netconf/Yang with OpenDalightUsing Netconf/Yang with OpenDalight
Using Netconf/Yang with OpenDalight
 
Logical volume manager xfs
Logical volume manager xfsLogical volume manager xfs
Logical volume manager xfs
 
Sedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsSedna XML Database: Executor Internals
Sedna XML Database: Executor Internals
 

Mehr von 艾鍗科技

TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition 艾鍗科技
 
Appendix 1 Goolge colab
Appendix 1 Goolge colabAppendix 1 Goolge colab
Appendix 1 Goolge colab艾鍗科技
 
Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用艾鍗科技
 
02 IoT implementation
02 IoT implementation02 IoT implementation
02 IoT implementation艾鍗科技
 
Tiny ML for spark Fun Edge
Tiny ML for spark Fun EdgeTiny ML for spark Fun Edge
Tiny ML for spark Fun Edge艾鍗科技
 
2. 機器學習簡介
2. 機器學習簡介2. 機器學習簡介
2. 機器學習簡介艾鍗科技
 
5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 艾鍗科技
 
心率血氧檢測與運動促進
心率血氧檢測與運動促進心率血氧檢測與運動促進
心率血氧檢測與運動促進艾鍗科技
 
利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆艾鍗科技
 
IoT感測器驅動程式 在樹莓派上實作
IoT感測器驅動程式在樹莓派上實作IoT感測器驅動程式在樹莓派上實作
IoT感測器驅動程式 在樹莓派上實作艾鍗科技
 
無線聲控遙控車
無線聲控遙控車無線聲控遙控車
無線聲控遙控車艾鍗科技
 
最佳光源的研究和實作
最佳光源的研究和實作最佳光源的研究和實作
最佳光源的研究和實作 艾鍗科技
 
無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車 艾鍗科技
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning艾鍗科技
 
人臉辨識考勤系統
人臉辨識考勤系統人臉辨識考勤系統
人臉辨識考勤系統艾鍗科技
 
智慧家庭Smart Home
智慧家庭Smart Home智慧家庭Smart Home
智慧家庭Smart Home艾鍗科技
 

Mehr von 艾鍗科技 (20)

TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
 
Appendix 1 Goolge colab
Appendix 1 Goolge colabAppendix 1 Goolge colab
Appendix 1 Goolge colab
 
Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用Project-IOT於餐館系統的應用
Project-IOT於餐館系統的應用
 
02 IoT implementation
02 IoT implementation02 IoT implementation
02 IoT implementation
 
Tiny ML for spark Fun Edge
Tiny ML for spark Fun EdgeTiny ML for spark Fun Edge
Tiny ML for spark Fun Edge
 
Openvino ncs2
Openvino ncs2Openvino ncs2
Openvino ncs2
 
Step motor
Step motorStep motor
Step motor
 
2. 機器學習簡介
2. 機器學習簡介2. 機器學習簡介
2. 機器學習簡介
 
5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron)
 
3. data features
3. data features3. data features
3. data features
 
心率血氧檢測與運動促進
心率血氧檢測與運動促進心率血氧檢測與運動促進
心率血氧檢測與運動促進
 
利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆利用音樂&情境燈幫助放鬆
利用音樂&情境燈幫助放鬆
 
IoT感測器驅動程式 在樹莓派上實作
IoT感測器驅動程式在樹莓派上實作IoT感測器驅動程式在樹莓派上實作
IoT感測器驅動程式 在樹莓派上實作
 
無線聲控遙控車
無線聲控遙控車無線聲控遙控車
無線聲控遙控車
 
最佳光源的研究和實作
最佳光源的研究和實作最佳光源的研究和實作
最佳光源的研究和實作
 
無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車無線監控網路攝影機與控制自走車
無線監控網路攝影機與控制自走車
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
人臉辨識考勤系統
人臉辨識考勤系統人臉辨識考勤系統
人臉辨識考勤系統
 
智慧家庭Smart Home
智慧家庭Smart Home智慧家庭Smart Home
智慧家庭Smart Home
 

Kürzlich hochgeladen

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Kürzlich hochgeladen (20)

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Linux Ethernet device driver

  • 2. Application Socket interface TCP/UDP protocol IP protocol 2 網路Driver架構 Ethernet Hardware Device Driver
  • 3. 它收送都是有封包關念 它是一種broadcast的網路封包 MAC位址必需向世界組織申請,在同一個 local LAN需是唯一的,並且它只存在local LAN,在internet中會被去除。 3 認識ethernet封包 Dest MAC Source MAC Type Payload 6 bytes 6 bytes 2 bytes Max 1566 bytes Max 1580 bytes
  • 4. 4 開發流程 宣告struct net_device 結構變數 或 用alloc_etherdev() 設定必要的callback fuction在上述的結構 中 呼叫 register_netdev()註 冊該driver 系統呼叫init callback function初始化該元件 啓動該介面時系統會 呼叫open callback function 送資料時系統呼叫 hard_start_xmit callback function 當收到資料時 可呼叫 netif_rx()往 上層送資料
  • 5. struct net_device struct net_device { char name[IFNAMSIZ]; ………………………………….. unsigned long base_addr; /* device I/O address */ unsigned int irq; /* device IRQ number */ struct net_device_stats* (*get_stats)(struct net_device *dev); const struct ethtool_ops *ethtool_ops; int (*open)(struct net_device *dev); int (*stop)(struct net_device *dev); void (*set_multicast_list)(struct net_device *dev); int (*do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); void (*tx_timeout) (struct net_device *dev); unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address, (before bcast because most packets are unicast) */ ……………………………………. }
  • 6. Module init example (dm9000.c) static struct platform_driver dm9000_driver = { .driver = { .name = "dm9000", .owner = THIS_MODULE, }, .probe = dm9000_probe, .remove = __devexit_p(dm9000_drv_remove), .suspend = dm9000_drv_suspend, .resume = dm9000_drv_resume, }; static int __init dm9000_init(void) { printk(KERN_INFO "%s Ethernet Driver, V%sn", CARDNAME, DRV_VERSION); return platform_driver_register(&dm9000_driver); } static void __exitdm9000_cleanup(void) { platform_driver_unregister(&dm9000_driver); } module_init(dm9000_init); module_exit(dm9000_cleanup);
  • 7. Probe example (dm9000.c) static int __devinit dm9000_probe(struct platform_device *pdev) { ………………………. ndev = alloc_etherdev(sizeof(struct board_info)); ……………………… db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ……………………. db->addr_req = request_mem_region(db->addr_res->start, iosize, pdev->name); db->io_addr = ioremap(db->addr_res->start, iosize); /* fill in parameters for net-dev structure */ ndev->base_addr = (unsigned long)db->io_addr; ndev->irq = db->irq_res->start; /* driver system function */ ether_setup(ndev); ndev->open = &dm9000_open; ndev->hard_start_xmit = &dm9000_start_xmit; ndev->tx_timeout = &dm9000_timeout; ndev->watchdog_timeo = msecs_to_jiffies(watchdog); ndev->stop = &dm9000_stop; ndev->set_multicast_list = &dm9000_hash_table; ndev->ethtool_ops = &dm9000_ethtool_ops; ndev->do_ioctl = &dm9000_ioctl; ………………. ret = register_netdev(ndev); return 0; }
  • 8. 上傳資料 1) 可用interrupt service routine or polling將底層的資 料收進來 2) 呼叫netif_rx()上傳資料 下傳資料 1) 上層將會呼叫所註冊的hard_start_xmit() callback function Allocate buffer kernel API 1) struct sk_buff *alloc_skb(unsigned int size,gfp_t priority) 8 如何上下傳資料
  • 9. Start xmit example /* Move data to DM9000 TX RAM */ writeb(DM9000_MWCMD, db->io_addr); (db->outblk)(db->io_data, skb->data, skb->len); dev->stats.tx_bytes += skb->len; db->tx_pkt_cnt++; /* TX control: First packet immediately send, second packet queue */ if (db->tx_pkt_cnt == 1) { /* Set TX length to DM9000 */ iow(db, DM9000_TXPLL, skb->len); iow(db, DM9000_TXPLH, skb->len >> 8); /* Issue TX polling command */ iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ dev->trans_start = jiffies; /* save the time stamp */ } else { /* Second packet */ db->queue_pkt_len = skb->len; netif_stop_queue(dev); } /* free this SKB */ dev_kfree_skb(skb); return 0;
  • 10. Receive packet interrupt example if (GoodPacket && ((skb = dev_alloc_skb(RxLen + 4)) != NULL)) { skb_reserve(skb, 2); rdptr = (u8 *) skb_put(skb, RxLen - 4); /* Read received packet from RX SRAM */ (db->inblk)(db->io_data, rdptr, RxLen); dev->stats.rx_bytes += RxLen; /* Pass to upper layer */ skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); dev->stats.rx_packets++; } else { /* need to dump the packet's data */ (db->dumpblk)(db->io_data, RxLen); }
  • 11. struct sk_buff { struct sk_buff *next; struct sk_buff *prev; ………………………….. unsigned char *data; unsigned int len; …………. } 11 skb buffer stream struct sk_buff { struct sk_buff *next; struct sk_buff *prev; ………………………….. unsigned char *data; unsigned int len; …………. } Data buffer Data buffer
  • 12. Tx/Rx Buffer Management 12 Buffer Descriptor Start Address Register + BRXBDCNT+0 … … BDMATXDPTR buffer pointer #1 status length buffer pointer #2 status length buffer pointer #N status length Buffer Descriptor Rx Buffer … … … buffer #1 not used buffer #2 not used buffer #N not used Memory for frame BRXBDCNT+1 BRXBDCNT+(N-1) BRxBS of BDMARXLEN BRxBS of BDMARXLEN BRxBS of BDMARXLEN BDMA buffer descriptor counter of current pointer … Memory for Rx buffer descriptor
  • 13. skb buffer由下而上時是由ethernet device driver allocate,而由上層的TCP free skb buffer由上而下時是由TCP allocate,而 由底層的ethernet free 其中在open的call back function需要 netif_start_queue() 在close時需要netif_stop_queue() 在timeout時需要netif_wake_queue() 13 注意事項
  • 14. 若網路元件有支援DMA功能,則盡量使用 以提供網路傳輸效能。 若網路元件和CPU之間有共用的記憶體,記 得必需要設定為non-cache。 在中斷程式中最好不要做搬動資料的動作, 最好使用schedule_work()來完成,可是這會 有一個問題就是較不real-time。 研讀程式drivers/net/my_mac.c 14 注意事項