XINU
Functions
ethwrite.c File Reference
#include <xinu.h>
Include dependency graph for ethwrite.c:

Go to the source code of this file.

Functions

int32 ethwrite (struct dentry *devptr, void *buf, uint32 count)
 

Function Documentation

◆ ethwrite()

int32 ethwrite ( struct dentry devptr,
void *  buf,
uint32  count 
)

Definition at line 9 of file ethwrite.c.

References eth_a_tx_desc::buffer, eth_a_tx_desc::buflen, eth_a_tx_desc::bufoff, ethcblk::csr, dentry::dvminor, ETH_AM335X_TDS_DIR, ETH_AM335X_TDS_EOP, ETH_AM335X_TDS_OWN, ETH_AM335X_TDS_P1, ETH_AM335X_TDS_SOP, ethertab, memcpy(), memset(), eth_a_tx_desc::next, NULL, ethcblk::osem, PACKLEN, eth_a_tx_desc::packlen, eth_a_tx_desc::stat, eth_a_csreg::stateram, eth_a_stateram::tx_hdp, ethcblk::txRing, ethcblk::txRingSize, ethcblk::txTail, and wait().

14 {
15  struct ethcblk *ethptr; /* Ether entry pointer */
16  struct eth_a_csreg *csrptr; /* Ethernet CSR pointer */
17  struct eth_a_tx_desc *tdescptr;/* Tx Desc. pointer */
18  struct eth_a_tx_desc *prev; /* Prev. Desc. pointer */
19 
20  ethptr = &ethertab[devptr->dvminor];
21 
22  /* Get the pointer to the Ethernet CSR */
23  csrptr = (struct eth_a_csreg *)ethptr->csr;
24 
25  /* Wait for an empty slot in the queue */
26  wait(ethptr->osem);
27 
28  /* Get the pointer to the next descriptor */
29  tdescptr = (struct eth_a_tx_desc *)ethptr->txRing +
30  ethptr->txTail;
31 
32  /* Adjust count if greater than max. possible packet size */
33  if(count > PACKLEN) {
34  count = PACKLEN;
35  }
36 
37  /* Initialize the descriptor */
38  tdescptr->next = NULL;
39  tdescptr->buflen = count;
40  tdescptr->bufoff = 0;
41  tdescptr->packlen = count;
42  tdescptr->stat = (ETH_AM335X_TDS_SOP | /* Start of packet */
43  ETH_AM335X_TDS_EOP | /* End of packet */
44  ETH_AM335X_TDS_OWN | /* Own flag set for DMA */
45  ETH_AM335X_TDS_DIR | /* Directed packet */
46  ETH_AM335X_TDS_P1); /* Output port is port1 */
47 
48  /* Copy the packet into the Tx buffer */
49  memcpy((char *)tdescptr->buffer, buf, count);
50 
51  /* TODO Figure out why we need this hack */
52  /* This ethernet device does not send packets smaller than 60 */
53  /* bytes; So pad a small packet to make it 60 bytes long */
54 
55  if(count < 60) {
56  memset((char *)tdescptr->buffer+count, 0, 60-count);
57  tdescptr->buflen = 60;
58  tdescptr->packlen = 60;
59  }
60 
61  /* Insert the descriptor into Tx queue */
62 
63  if(csrptr->stateram->tx_hdp[0] == 0) {
64  /* Tx queue is empty, this desc. will be the first */
65  csrptr->stateram->tx_hdp[0] = (uint32)tdescptr;
66  }
67  else {
68  /* Tx queue not empty, insert at end */
69  prev = (struct eth_a_tx_desc *)
70  csrptr->stateram->tx_hdp[0];
71  while(prev->next != NULL) {
72  prev = prev->next;
73  }
74  prev->next = tdescptr;
75  }
76 
77  /* Increment the tail index of the Tx ring */
78  ethptr->txTail++;
79  if(ethptr->txTail >= ethptr->txRingSize) {
80  ethptr->txTail = 0;
81  }
82 
83  return count;
84 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
uint16 buflen
DMAバッファの長さ
Definition: am335x_eth.h:357
uint16 stat
DMA状態
Definition: am335x_eth.h:363
uint32 txTail
Definition: ether.h:92
#define ETH_AM335X_TDS_SOP
TX(送信)パケットの開始
Definition: am335x_eth.h:367
int32 dvminor
Definition: conf.h:8
Ethernet subsystemレジスタ構造体
Definition: am335x_eth.h:297
DMA TX(送信)ディスクリプタ
Definition: am335x_eth.h:350
Definition: ether.h:68
uint16 packlen
DMAパケットの長さ
Definition: am335x_eth.h:361
struct eth_a_tx_desc * next
次のDMA TX(受信)ディスクリプタ
Definition: am335x_eth.h:353
struct ethcblk ethertab[]
Definition: ethinit.c:7
uint32 tx_hdp[8]
TX(送信) チャネル0〜7 先頭ディスクリプタへのポインタ
Definition: am335x_eth.h:126
#define PACKLEN
Definition: net.h:50
volatile struct eth_a_stateram * stateram
CPSW_STATERANレジスタ
Definition: am335x_eth.h:304
#define ETH_AM335X_TDS_DIR
不明
Definition: am335x_eth.h:375
#define ETH_AM335X_TDS_OWN
DMAが所持するディスクリプタ
Definition: am335x_eth.h:371
#define ETH_AM335X_TDS_P1
不明
Definition: am335x_eth.h:377
void * txRing
Definition: ether.h:89
#define ETH_AM335X_TDS_EOP
TX(送信)パケットの終了
Definition: am335x_eth.h:369
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
uint16 bufoff
DMAバッファのオフセット
Definition: am335x_eth.h:359
syscall wait(sid32)
Definition: wait.c:9
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * csr
Definition: ether.h:76
uint32 txRingSize
Definition: ether.h:93
uint32 buffer
DMAバッファ
Definition: am335x_eth.h:355
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
sid32 osem
Definition: ether.h:103
Here is the call graph for this function: