360 likes | 481 Views
This presentation outlines the development of a network driver for Ben Wei's Operating System (BOS), focusing on the e100 Ethernet controller's integration via PCI. Attendees will learn about key topics including memory management, timer interrupts, I/O operations, and thread scheduling. The agenda includes practical demos using QEMU, details on setting up the driver, and troubleshooting common issues encountered during implementation. This session is ideal for developers interested in OS development, particularly in understanding network driver programming.
E N D
TOSSUG JULUOSDev 星系主題 BOS & Network Driver Practice Ben Wei (A system creator)
Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 2
Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 3
Bos簡介 Bos (a.k.a Ben’s OS) 目前實作 • 簡易的記憶體管理 • Timer中斷處理 • 鍵盤I/O, 佇列 • 多個執行緒的多工切換 • 精簡 blibc函式庫 • bshell簡單的命令模式 (ps, uname, free, clear…) 4
Architecture lspci net Kthread (Bshell) PCI Func Network Driver CU RU Kernel Timer Mem Kernel E100 i82559ER 5
Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 6
lspci • OSDev.org“here I can find Programming Info on PCI?” • sysInLong: 讀取pci表內容 • sysOutLong: 寫入pci設備命令及資料 7
MIT OSE x86.h • uint32_t inl(int port) __asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port)); • voidoutl(intport, uint32_t data) __asm __volatile("outl %0,%w1" : : "a" (data), "d" (port)); 8
inl/outl NASM ;uint32_t _intl(int port) _inl: movedx, [esp+4] moveax, 0 in eax, dx ret ;void _outl(int port, uint32_t data) _outl: movedx, [esp+4] ; port moveax, [esp+8] ; data out dx, eax ret 9
PCI Config Read pciConfigRead(uint32_t bus, uint32_t slot, uint32_t func, uin32_t offset) address = (uint32_t)((bus << 16) | (slot << 11) | (func << 8) | (offset & 0xfc) | ((uint32_t)1<<31)); outl(0xCF8, address); data = (uint32_t)(intl(0xCFC); 10
Ethernet Controller Info 00:18.0 Vendor:8086, devid:1029, class:0200h(Ethernet Controller),r9,t0,irq11 11
Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 12
E100_attach 啟用流程 • 啟用後,這時便用使用到 io region 1: 0xc040,長度為64位元組,參考Intel 82559 • 需要將e100 做軟體重置 • e100_reset() • Disable CSR 中斷 • DMA Rings • 傳送的緩衝區Control Block List (CBL): cbl_init() • 接收用的緩衝區Receive Frame Area (RFA): rfa_init() 13
PCI enable e100 func • pci_func_enable(pci_pdata_t f) pci_conf_write(f, PCI_COMMAND_STATUS_REG, PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE); 執行結果 PCI function 00:18.0 (8086:1209) enabled 14
E100 Reset voide100_reset() { outl(e100.addr_base[E100_IO] + CSR_PORT, PORT_SW_RESET); delay(10); } 15
Tricky delay() __inline void delay(inti) { while(--i >=0) { inb(0x84); } } 16
Disable e100 interrupt r = e100_exec_cmd(CSR_INT, 1); printf("e100 CSR_INT ret=%d\n", r); • e100_exec_cmd (intcsr_comp, uint8_t cmd) outb(nic.io_base + csr_comp, cmd); do { scb_command = inb(nic.io_base + CSR_COMMAND); } while (scb_command != 0 && --retry > 0); return retry > 0; 17
DMA Rings • Control Block • Control Block List (CBL) • Receive Frame Area (RFA) 18
Control Block (CB) Transmit Control Block (TCB) 19
Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 21
transmit & receive • SendPacket data (transmit & receive) int e100_transmit (constchar *data, uint16_t len) • Receivepacket data int e100_receive (char *data) 22
Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 23
Demo 24
Demo - recap bos$ net PCI function 00:18.0 (8086:1209) enabled mem region 0: 4096 bytes at 0xf2020000 io region 1: 64 bytes at 0xc040 cblavail = 9, wait = 1, slot = 0x420000, irq=11 rfaavail = 10, wait = 0, slot = 0x420050 25
Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 26
Issues • 原使用e100設備序號,並不生效;後來研究OSE資料後,發現必須在qemu參數中設定,之後再使用設備序號1209來啟用e100(i82559er),如此才能正確執行在qemu環境。 • 系統在開發的過程中,偶遇到無法正常開機,這時GIT便可派上用場,來縮小問題發生的範圍。 27
Agenda • BOS 簡介 • lspci • e100_attach • Transmit & Receive • Demo • Issues • Qemu OSE 28
編繹Qemu OSE版本 $ configure--disable-sdl–prefix=/usr/local/qemuose $ --target-list=i386-softmmu $ make $ sudo make install 另外在Bos v0.21中執行Qemu時,將檢查/usr/local/qemuose,若存在則直接使用。 29
Qemu參數 • 參數 qemu-fda "../bos.img" -net user -net nic,model=i82559er • MIT OSE參數 (只在qemu 0.12.5-6.828中支援) -debug-e100 -pcap <file> 30
結論 • PCI 資訊的存取 • 啟用e100網路卡 • 設定並使用DMA Rings • 更好的偵錯方式來進行網卡開發 • 相關遇到問題的經驗分享 31
Q & A 32
JuluOSDev議程 • 有興趣一起開發Juluos的朋友們,請加入到juluosdev group at google,參與開發議程討論,位置詳見Julu.staros.mobi公告。 33
Glossary of Abbreviations • CB Control Block • CBL Command Block List • CSR Control/Status Registers • CU Command Unit • RFA Receive Frame Area • RFD Receive Frame Descriptor • RU Receive Unit • SCB System Control Block • TCB Transmit Command Block 35
參考資料及延伸閱讀 • MIT OSE • MIT OSE Lab6 • MIT OSE Tools • Intel 82559 • NASM x86 Quick Reference • OSDev.org • Where can I find programming info on PCI? • Differences Between AT&T and Intel assembler formats 36