...
This commit is contained in:
parent
8082128fc1
commit
070fffd9c0
1 changed files with 36 additions and 64 deletions
|
@ -18,7 +18,7 @@
|
||||||
#define kmalloc malloc
|
#define kmalloc malloc
|
||||||
#define kfree(x,y) free(x)
|
#define kfree(x,y) free(x)
|
||||||
#define RCCE_shfree(x) VirtualFree(x,NULL,NULL);
|
#define RCCE_shfree(x) VirtualFree(x,NULL,NULL);
|
||||||
|
#define RCCE_shmalloc(x) VirtualAlloc((char*)0x41000000,x,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
|
||||||
#include "mailbox.h" /* mailbox_ptr_t */
|
#include "mailbox.h" /* mailbox_ptr_t */
|
||||||
#else
|
#else
|
||||||
#include <metalsvm/mailbox.h> /* mailbox_ptr_t */
|
#include <metalsvm/mailbox.h> /* mailbox_ptr_t */
|
||||||
|
@ -168,6 +168,7 @@ typedef struct mmnif_device_stats
|
||||||
|
|
||||||
} mmnif_device_stats_t;
|
} mmnif_device_stats_t;
|
||||||
|
|
||||||
|
/* receive descror structure */
|
||||||
typedef struct rx_desc
|
typedef struct rx_desc
|
||||||
{
|
{
|
||||||
uint8_t stat;
|
uint8_t stat;
|
||||||
|
@ -192,44 +193,48 @@ typedef struct mm_rx_buffer
|
||||||
uint16_t head;
|
uint16_t head;
|
||||||
uint16_t tail;
|
uint16_t tail;
|
||||||
spinlock_t rlock;
|
spinlock_t rlock;
|
||||||
/*
|
/* descritpor queue
|
||||||
*
|
* desc_table : descriptor table
|
||||||
|
* dcount : descriptor's free in queue
|
||||||
|
* dread : next descriptor to read
|
||||||
|
* dwrite : next descriptor to write
|
||||||
|
* dlock : lock to protect these members
|
||||||
*/
|
*/
|
||||||
rx_desc_t desc_table[MMNIF_MAX_DESCRIPTORS];
|
rx_desc_t desc_table[MMNIF_MAX_DESCRIPTORS];
|
||||||
uint8_t dcount;
|
uint8_t dcount;
|
||||||
uint8_t dread;
|
uint8_t dread;
|
||||||
uint8_t dwrite;
|
uint8_t dwrite;
|
||||||
spinlock_t dlock;
|
spinlock_t dlock;
|
||||||
|
|
||||||
} mm_rx_buffer_t;
|
} mm_rx_buffer_t;
|
||||||
|
|
||||||
typedef struct mmnif
|
typedef struct mmnif
|
||||||
{
|
{
|
||||||
struct mmnif_device_stats stats;
|
struct mmnif_device_stats stats;
|
||||||
|
|
||||||
/* Interface constants:
|
/* Interface constants:
|
||||||
* - ehternet address
|
* - ehternet address
|
||||||
* - local ip address
|
* - local ip address
|
||||||
*/
|
*/
|
||||||
struct eth_addr* ethaddr;
|
struct eth_addr* ethaddr;
|
||||||
uint32_t ipaddr;
|
uint32_t ipaddr;
|
||||||
|
|
||||||
/* memory interaction variables:
|
/* memory interaction variables:
|
||||||
* - transmit queue
|
* - transmit queue
|
||||||
* - pointer to transmit buffer
|
* - pointer to transmit buffer
|
||||||
* - pointer to recive buffer
|
* - pointer to recive buffer
|
||||||
*/
|
*/
|
||||||
uint8_t tx_queue;
|
uint8_t tx_queue;
|
||||||
uint8_t* tx_buff[MMNIF_TX_QUEUELEN];
|
uint8_t* tx_buff[MMNIF_TX_QUEUELEN];
|
||||||
mm_rx_buffer_t* rx_buff;
|
mm_rx_buffer_t* rx_buff;
|
||||||
|
|
||||||
spinlock_t lock;
|
/* lock to protect members
|
||||||
|
*/
|
||||||
|
spinlock_t lock;
|
||||||
|
|
||||||
sem_t com_poll;
|
/*
|
||||||
|
*/
|
||||||
|
sem_t com_poll;
|
||||||
|
|
||||||
/* comunication mailbox
|
|
||||||
*/
|
|
||||||
mailbox_ptr_t mbox;
|
|
||||||
}mmnif_t;
|
}mmnif_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,7 +258,7 @@ __inline int RCCE_ue(void){
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* trigger an interrupt on the remote processor
|
/* trigger an interrupt on the remote processor
|
||||||
*
|
* so he knows there is a packet to read
|
||||||
*/
|
*/
|
||||||
__inline int mmnif_trigger_irq(dest_ip)
|
__inline int mmnif_trigger_irq(dest_ip)
|
||||||
{
|
{
|
||||||
|
@ -279,45 +284,8 @@ __inline int mmnif_trigger_irq(dest_ip)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Allocate Shared Memory for communication this could be:
|
|
||||||
* - in Message Passing Buffer
|
|
||||||
* - Shared Memory Address Space (0x8000000 + )
|
|
||||||
*
|
|
||||||
* Note: under windows this is kernel space so we take arbitrary 0x41000000 here
|
|
||||||
*/
|
|
||||||
__inline void* mmnif_shmalloc()
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
mpb_size = sizeof(mm_rx_buffer_t) + MMNIF_RX_BUFFERLEN;
|
|
||||||
mpb_start_address = VirtualAlloc((char*)0x41000000 /*+
|
|
||||||
(mpb_size) * (own_ip_address - router_ip_address)*/,
|
|
||||||
mpb_size *MMNIF_CORES,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
|
|
||||||
|
|
||||||
return (char*)0x41000000 + (mpb_size) * (own_ip_address - router_ip_address);
|
|
||||||
#else
|
|
||||||
mpb_size = (sizeof(mm_rx_buffer_t) + MMNIF_RX_BUFFERLEN);
|
|
||||||
|
|
||||||
mpb_start_address = RCCE_shmalloc(mpb_size*MMNIF_CORES);
|
|
||||||
return mpb_start_address + (mpb_size) * (own_ip_address - router_ip_address);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mmnif_timestamp(): genereate a timestamp for the
|
|
||||||
* packets
|
|
||||||
*/
|
|
||||||
__inline int mmnif_timestamp()
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
return GetTickCount();
|
|
||||||
#else
|
|
||||||
return get_clock_tick();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* mmnif_get_device_stats(): Returns a copy of the
|
/* mmnif_get_device_stats(): Returns a copy of the
|
||||||
* current device
|
* current device
|
||||||
*/
|
*/
|
||||||
|
@ -333,7 +301,6 @@ mmnif_device_stats_t mmnif_get_device_stats()
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* mmnif_print_stats(): Print the devices stats of the
|
/* mmnif_print_stats(): Print the devices stats of the
|
||||||
* current device
|
* current device
|
||||||
*/
|
*/
|
||||||
|
@ -408,14 +375,15 @@ uint8_t mmnif_get_destination(struct netif* netif, struct pbuf* p)
|
||||||
return core;
|
return core;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* mmnif_rxbuff_alloc():
|
||||||
*
|
* this function allocates a continues chunk of memory
|
||||||
|
* right inside of the buffer which is used for communication
|
||||||
|
* with the remote end
|
||||||
*/
|
*/
|
||||||
uint32_t mmnif_rxbuff_alloc(uint8_t dest,uint16_t len)
|
uint32_t mmnif_rxbuff_alloc(uint8_t dest,uint16_t len)
|
||||||
{
|
{
|
||||||
mmnif_t* mmnif = mmnif_dev->state;
|
|
||||||
mm_rx_buffer_t* rb = (mm_rx_buffer_t*)((char*)mpb_start_address + ( dest -1 ) * mpb_size);
|
mm_rx_buffer_t* rb = (mm_rx_buffer_t*)((char*)mpb_start_address + ( dest -1 ) * mpb_size);
|
||||||
char* memblock = (char*)rb + sizeof(mm_rx_buffer_t);
|
char* memblock = (char*)rb + sizeof(mm_rx_buffer_t);
|
||||||
|
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
|
|
||||||
|
@ -506,12 +474,12 @@ uint32_t mmnif_rxbuff_alloc(uint8_t dest,uint16_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* mmnif_commit_packet: this function set the state of the (in advance)
|
||||||
*
|
* allocated packet to RDY so the recieve queue knows that it can be
|
||||||
|
* processed further
|
||||||
*/
|
*/
|
||||||
int mmnif_commit_packet(uint8_t dest,uint32_t addr)
|
int mmnif_commit_packet(uint8_t dest,uint32_t addr)
|
||||||
{
|
{
|
||||||
mmnif_t* mmnif = mmnif_dev->state;
|
|
||||||
mm_rx_buffer_t* rb = (mm_rx_buffer_t*)((char*)mpb_start_address + ( dest -1 ) * mpb_size);
|
mm_rx_buffer_t* rb = (mm_rx_buffer_t*)((char*)mpb_start_address + ( dest -1 ) * mpb_size);
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
@ -739,8 +707,12 @@ err_t mmnif_init(struct netif* netif)
|
||||||
|
|
||||||
/* Alloc and clear shared memory for rx_buff
|
/* Alloc and clear shared memory for rx_buff
|
||||||
*/
|
*/
|
||||||
mmnif->rx_buff = mmnif_shmalloc();
|
|
||||||
if (!(mmnif->rx_buff))
|
mpb_size = (sizeof(mm_rx_buffer_t) + MMNIF_RX_BUFFERLEN);
|
||||||
|
mpb_start_address = RCCE_shmalloc(mpb_size*MMNIF_CORES);
|
||||||
|
|
||||||
|
mmnif->rx_buff = mpb_start_address + (mpb_size) * (own_ip_address - router_ip_address);
|
||||||
|
if (!(mpb_start_address))
|
||||||
{
|
{
|
||||||
DEBUGPRINTF("mmnif init(): allocating shared memory failed\n");
|
DEBUGPRINTF("mmnif init(): allocating shared memory failed\n");
|
||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
|
|
Loading…
Add table
Reference in a new issue