fuchsiaネットワークカード汎用インタフェース層及びlegacy方式ネットワーク仮想化実現
8775 ワード
—— zircon\system\dev\ethernet\ethernet\ethernet.cpp
, ZX_PROTOCOL_ETHMAC 。
:EthDev0::EthBind-->EthDev0::AddDevice
eth::EthDev0 ; AddDevice, mac、feature , 。
ops 。
"/dev/class/ethernet/"
, path
"/dev/class/ethernet/000"
。
client fdio open path, , EthDev0::DdkOpen 。
EthDev0::DdkOpen-->EthDev::AddDevice
// , devfs , DdkMessage 。
FIDL , IPC devhost 。devhost devfs IPC 。devfs :
DevfsConnection::HandleRpc
devhost_fidl_handler --devmgr\devhost\rpc-server.cpp
conn->dev->MessageOp(msg, txn)
ops->message(zircon\system\ulib\ddktl\include\ddktl\device.h InitOp message = Message>, Message —— DdkMessage )
EthDev::DdkMessage --zircon\system\dev\ethernet\ethernet\ethernet.cpp
fuchsia_hardware_ethernet_Device_dispatch
kOps.Start
// start
MsgStartLocked
EthDev::StartLocked
tx/rx rings
TransmitThread
// TransmitThread
transmit_fifo_.read
transmit_fifo_.wait_one
Send
edev0_->TransmitInfoToNetbuf
edev0_->mac_.QueueTx
edev0_->TransmitEcho
PutTransmitInfo
TransmitFifoWrite
edev0_->mac_.Start
edev0_->list_idle_.erase
edev0_->list_active_.push_bac
receive_fifo_.signal_peer
, start 。 client
"eth-tx-thread"
, 。 client :
1
.clint open ( )
2
.fuchsia_hardware_ethernet_DeviceGetInfo,FIDL , (mac、feature )
3
.fuchsia_hardware_ethernet_DeviceGetFifos, , zx_fifo_create rx tx fifo, fifo , (client)
4
.client fifo (rx_depth、tx_depth; , buffer ), vmo , fuchsia_hardware_ethernet_DeviceSetIOBuffer, vmo 。
5
.fuchsia_hardware_ethernet_DeviceSetClientName, client
6
.fuchsia_hardware_ethernet_DeviceStart,start 。
7
. fifo ( VirtioNetLegacy WaitOnFifos), 。
VirtioNetLegacy , virtio 。
VirtioNetLegacy
1
. VirtioInprocessDevice
2
.rx_stream_(phys_mem, dispatcher, rx_queue(), rx_trace_flow_id(),&io_buf_), rx stream
3
.tx_stream_(phys_mem, dispatcher, tx_queue(), tx_trace_flow_id(),&io_buf_), tx stream
rx stream tx stream , queue VirtioNetLegacy::Stream::OnQueueReady queue_wait_ 。queue_wait_ VirtioQueueWaiter , virtio queue , queue virtio , OnQueueReady 。
VirtioNetLegacy::Stream::OnQueueReady
ReadPacketInfo
// virtio desc vmo(virtio vmo) offset len
io_buf_->vmo().write
// virtio vmo( vmo) , io_offset
fifo_entries_[fifo_num_entries_++] = {……}
// fifo_entries_( )
WaitOnFifoWritable
// fifo
fifo , OnFifoWritable
VirtioNetLegacy::Stream::OnFifoWritable
zx_fifo_write
// fifo
WaitOnQueue
// queue
fifo , :
fifo :
TransmitThread
transmit_fifo_.read
Send
GetTransmitInfo
// info
edev0_->TransmitInfoToNetbuf
edev0_->mac_.QueueTx
OPI2MacDevice::EthmacQueueTx
//
[edev0_->TransmitEcho
// ]
[ethmac_request_count_ ++]
//
PutTransmitInfo
TransmitFifoWrite
, :
OPI2MacDevice::ProcRxBuffer
ethmac_client_.Recv
// Recv
EthDev0::Recv
edev.RecvLocked
// list_active_ client
receive_fifo_.read
// fifo entry
memcpy
// entry,
receive_fifo_.write
// entry fifo
VirtioNetLegacy fifo OnFifoReadable :
VirtioNetLegacy::Stream::OnFifoReadable
zx_fifo_read
// fifo entries
entries, ;eth_fifo_entry_t.cookie desc head
ReadPacketInfo / cookie virtio desc head vmo(virtio vmo) offset len
io_buf_->vmo().read
// vmo( vmo) ( io_offset), virtio vmo
io_buf_->Free
// io buffer,
queue_->Return
// vring( , guest)
wait->Begin
//
client EthDev , 。
list_idle_
// client
idle :
1
.client open ( EthDev , idle )
2
.client stop ( client EthDev , active , idle )
idle :
1
. DdkUnbind , DestroyAllEthDev active idle, idle
2
.client close
3
.client start, ( client EthDev , idle , active )
list_active_
// client
active idle , 。
list_active_
1
. , active
2
.set status, active receive_fifo_.signal_peer
3
. , active
4
.loopback , active kStateTransmissionListen
5
.start、stop、destroy release ( )
list_idle_ :start、stop、open、destroy release ( )
netswitch 。 list_active_ list_idle_ client 。