From 30aaa5fda397aec02de8a18d1afe477a019c215d Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 4 Jul 2011 13:02:19 -0700 Subject: [PATCH] review of Benedikt's virtual IP device --- drivers/net/mmnif.c | 68 ++++++++--------- drivers/net/mmnif.h | 25 ++++++- drivers/net/util.c | 22 +++++- drivers/net/util.h | 23 +++++- kernel/init.c | 20 +++-- kernel/main.c | 4 +- kernel/tests.c | 177 +++++++++++++++++++------------------------- 7 files changed, 184 insertions(+), 155 deletions(-) diff --git a/drivers/net/mmnif.c b/drivers/net/mmnif.c index a8d47d15..d5346d11 100644 --- a/drivers/net/mmnif.c +++ b/drivers/net/mmnif.c @@ -1,11 +1,28 @@ +/* + * Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of MetalSVM. + */ + /* * mmnif.c --- memmory mapped interface * * Virutal IP Interface for the concept processor SCC * - * virutally tested under Windows 7 - * - * Carl-Benedikt Krüger 2011 + * Carl-Benedikt Krueger 2011 * */ @@ -17,6 +34,8 @@ #include /* mailbox_ptr_t */ #endif +#ifdef CONFIG_LWIP + #include /* lwip netif */ #include /* inteface stats */ #include /* ethernet arp packets */ @@ -49,7 +68,6 @@ extern HANDLE hProc; #include -#include #include #include #include @@ -214,7 +232,7 @@ typedef struct mmnif #ifdef WIN32 -__inline int get_my_core_no(void) +__inline int RCCE_ue(void) { #ifndef RECV return 1; @@ -223,28 +241,8 @@ __inline int get_my_core_no(void) #endif } -#else - -__inline int get_my_core_no(void) -{ - unsigned int tmp; - unsigned int pid; - unsigned int x,y,z; - /* Determine the local IP address from the core number in the - * tile ID register - */ - tmp = ReadConfigReg(local_crb + RCK_TILEID); - x = (tmp>>3) & 0x0f; /* bits 06:03 */ - y = (tmp>>7) & 0x0f; /* bits 10:07 */ - z = (tmp ) & 0x07; /* bits 02:00 */ - pid = 12*y + 2*x + z; - /* Add 1 to the processor ID to avoid *.*.*.0 IP addresses */ - return pid; -} - #endif - /* * memory maped interface helper functions */ @@ -922,7 +920,7 @@ err_t mmnif_init(struct netif* netif) /* Generate MAC address */ mmnif_dev->hwaddr[0] = 0x11;mmnif_dev->hwaddr[1] = 0x22;mmnif_dev->hwaddr[2] = 0x33; - mmnif_dev->hwaddr[3] = 0x44;mmnif_dev->hwaddr[4] = 0x55;mmnif_dev->hwaddr[5] = get_my_core_no()*0x11 +0x66; + mmnif_dev->hwaddr[3] = 0x44;mmnif_dev->hwaddr[4] = 0x55;mmnif_dev->hwaddr[5] = RCCE_ue()*0x11 +0x66; /* * Initialize the snmp variables and counters inside the struct netif. @@ -932,7 +930,7 @@ err_t mmnif_init(struct netif* netif) NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, speed); /* administrative details */ - netif->name[0] = 'e'; + netif->name[0] = 'm'; netif->name[1] = 'n'; netif->num = num; num++; @@ -1214,7 +1212,7 @@ int mmnif_poll(void* e) /* mmnif_irqhandler(): handles incoming interrupts * its just a local wrapper for mmnif_rx() */ -void mmnif_irqhandler() +void mmnif_irqhandler(void) { mmnif_t* mmnif; /* return if mmnif_dev is not yet initialized*/ @@ -1233,7 +1231,7 @@ void mmnif_irqhandler() /* * Open the interface should be called by kernel to use this network interface */ -int mmnif_open() +int mmnif_open(void) { struct ip_addr ipaddr; struct ip_addr netmask; @@ -1243,10 +1241,10 @@ int mmnif_open() * Note: core 1 is the router core */ IP4_ADDR(&gw, 0,0,0,0); - IP4_ADDR(&ipaddr, 192,168,0,get_my_core_no() +1); - IP4_ADDR(&netmask, 255,0,0,0); + IP4_ADDR(&ipaddr, 192,168,0,RCCE_ue()+1); + IP4_ADDR(&netmask, 255,255,255,0); - own_ip_address+= get_my_core_no() +1; + own_ip_address += RCCE_ue()+1; #ifdef WIN32 mmnif_dev = malloc(sizeof(struct netif)); @@ -1271,7 +1269,7 @@ int mmnif_open() } /* set our network interface to the default interface for lwip*/ - netif_set_default(mmnif_dev); + //netif_set_default(mmnif_dev); /* tell lwip all initialization is done and we want to set it ab*/ netif_set_up(mmnif_dev); @@ -1308,7 +1306,7 @@ int mmnif_open() * close the interface should be called by kernel to close this interface and release resources * Note: it's temporarly empty. Support will be added. */ -int mmnif_close() +int mmnif_close(void) { mmnif_t* mmnif; @@ -1336,3 +1334,5 @@ int mmnif_close() #endif return NULL; } + +#endif diff --git a/drivers/net/mmnif.h b/drivers/net/mmnif.h index 6486e30b..012e8109 100644 --- a/drivers/net/mmnif.h +++ b/drivers/net/mmnif.h @@ -1,3 +1,22 @@ +/* + * Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of MetalSVM. + */ + #ifndef __MMNIF_H__ #define __MMNIF_H__ @@ -21,12 +40,12 @@ typedef int int32_t; /* * Initialize the network driver for mmn */ -int mmnif_open(); -int mmnif_close(); +int mmnif_open(void); +int mmnif_close(void); int mmnif_poll(void* e); int mmnif_worker(void* e); -void mmnif_irqhandler(); +void mmnif_irqhandler(void); #endif diff --git a/drivers/net/util.c b/drivers/net/util.c index 6a56716f..cf06fdd6 100644 --- a/drivers/net/util.c +++ b/drivers/net/util.c @@ -1,3 +1,22 @@ +/* + * Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of MetalSVM. + */ + #include "util.h" @@ -10,7 +29,8 @@ __inline int isprint(char e) // hex_dumb display network packets in a good way void hex_dump(unsigned n, const unsigned char* buf) { -int on_this_line = 0; + int on_this_line = 0; + while (n-- > 0) { kprintf("%02X ", *buf++); diff --git a/drivers/net/util.h b/drivers/net/util.h index 610f78f5..f35b7428 100644 --- a/drivers/net/util.h +++ b/drivers/net/util.h @@ -1,9 +1,26 @@ +/* + * Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems, + * RWTH Aachen University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of MetalSVM. + */ + #ifndef __UTIL__ #define __UTIL__ - // hex_dumb display network packets in a good way void hex_dump(unsigned n, const unsigned char* buf); - -#endif \ No newline at end of file +#endif diff --git a/kernel/init.c b/kernel/init.c index 1f053d08..1bda29e0 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -39,6 +39,7 @@ #endif #include #include +#include #ifdef CONFIG_ROCKCREEK #include #include @@ -113,6 +114,8 @@ int STDCALL network_task(void* arg) rtl8139if_wait(&netif, 1); udelay(500000); } +#else + mmnif_open(); #endif // start echo and ping server @@ -138,6 +141,8 @@ int STDCALL network_task(void* arg) int network_shutdown(void) { + mmnif_close(); + done = 1; return 0; @@ -150,13 +155,7 @@ static void tcp_init_ok(void* e) int network_init(void) { - tcpip_init(tcp_init_ok, NULL); - kprintf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); - mmnif_open(); - kprintf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); - return 0; - -#if 0 + int ret = 0; #if defined(CONFIG_LWIP) // Initialize lwIP modules @@ -164,9 +163,8 @@ int network_init(void) #endif #if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK)) - return create_kernel_task(&netid, network_task, NULL); -#else - return 0; -#endif + ret = create_kernel_task(&netid, network_task, NULL); #endif + + return ret; } diff --git a/kernel/main.c b/kernel/main.c index c28fb7c1..566ff932 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -110,8 +110,8 @@ int main(void) kprintf("Current allocated memory: %u KBytes\n", atomic_int32_read(&total_allocated_pages)*(PAGE_SIZE/1024)); kprintf("Current available memory: %u MBytes\n", atomic_int32_read(&total_available_pages)/((1024*1024)/PAGE_SIZE)); -// sleep(5); -// list_root(); + sleep(5); + list_root(); test_init(); per_core(current_task)->status = TASK_IDLE; reschedule(); diff --git a/kernel/tests.c b/kernel/tests.c index 4cd3a6c5..86076102 100644 --- a/kernel/tests.c +++ b/kernel/tests.c @@ -26,7 +26,6 @@ #include #ifdef CONFIG_ROCKCREEK #include -#include #include #include #include @@ -125,116 +124,93 @@ static int STDCALL join_test(void* arg) return 0; } -#ifdef CONFIG_LWIP -void ping_send_now(); -#endif - -__inline int get_core_no(void) +#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK) +static int STDCALL server_task(void* e) { - unsigned int tmp; - unsigned int pid; - unsigned int x,y,z; - /* Determine the local IP address from the core number in the - * tile ID register - */ - tmp = ReadConfigReg(0xF8000000 + 0x100); - x = (tmp>>3) & 0x0f; /* bits 06:03 */ - y = (tmp>>7) & 0x0f; /* bits 10:07 */ - z = (tmp ) & 0x07; /* bits 02:00 */ - pid = 12*y + 2*x + z; - /* Add 1 to the processor ID to avoid *.*.*.0 IP addresses */ - return pid; -} + int sockfd, newsockfd, portno, clilen; + char buffer[256]; + struct sockaddr_in serv_addr, cli_addr; + int n; - -void* server_task(void* e) -{ - int sockfd, newsockfd, portno, clilen; - char buffer[256]; - struct sockaddr_in serv_addr, cli_addr; - int n; - - /* First call to socket() function */ - sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sockfd < 0) - { - kprintf("ERROR opening socket"); - return; - } - /* Initialize socket structure */ - memset((char *) &serv_addr,0, sizeof(serv_addr)); - portno = 5001; - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; - serv_addr.sin_port = htons(portno); + /* First call to socket() function */ + sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (sockfd < 0) + { + kprintf("ERROR opening socket"); + return -1; + } + /* Initialize socket structure */ + memset((char *) &serv_addr,0, sizeof(serv_addr)); + portno = 5001; + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = INADDR_ANY; + serv_addr.sin_port = htons(portno); - kprintf("binding"); - /* Now bind the host address using bind() call.*/ - if (bind(sockfd, (struct sockaddr *) &serv_addr, - sizeof(serv_addr)) < 0) - { - kprintf("ERROR on binding"); - return; - } + kprintf("binding"); + /* Now bind the host address using bind() call.*/ + if (bind(sockfd, (struct sockaddr *) &serv_addr, + sizeof(serv_addr)) < 0) + { + kprintf("ERROR on binding"); + return -1; + } - /* Now start listening for the clients, here process will - * go in sleep mode and will wait for the incoming connection - */ - kprintf("listening"); - listen(sockfd,5); - clilen = sizeof(cli_addr); + /* Now start listening for the clients, here process will + * go in sleep mode and will wait for the incoming connection + */ + kprintf("listening"); + listen(sockfd,5); + clilen = sizeof(cli_addr); - /* Accept actual connection from the client */ - kprintf("accepting"); - newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, - &clilen); - if (newsockfd < 0) - { - kprintf("ERROR on accept"); - return; - } - /* If connection is established then start communicating */ - memset(buffer,0,256); - kprintf("recieving"); - n = read( newsockfd,buffer,255 ); - if (n < 0) - { - kprintf("ERROR reading from socket"); - return; - } - kprintf("Here is the message: %s\n",buffer); + /* Accept actual connection from the client */ + kprintf("accepting"); + newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen); + if (newsockfd < 0) + { + kprintf("ERROR on accept"); + return -1; + } + /* If connection is established then start communicating */ + memset(buffer,0,256); + kprintf("recieving"); + n = read( newsockfd,buffer, 255); + if (n < 0) + { + kprintf("ERROR reading from socket"); + return -1; + } + kprintf("Here is the message: %s\n",buffer); - /* Write a response to the client */ - kprintf("writing"); - n = write(newsockfd,"I got your message",18); - if (n < 0) - { - kprintf("ERROR writing to socket"); - return; - } - return 0; + /* Write a response to the client */ + kprintf("writing"); + n = write(newsockfd,"I got your message",18); + if (n < 0) + { + kprintf("ERROR writing to socket"); + return -1; + } + + return 0; } -void* client_task(void* e) +static int STDCALL client_task(void* e) { char dir[256]; int sd; - struct sockaddr_in sin; struct sockaddr_in pin; - struct hostent *hp; sleep(1); /* fill in the socket structure with host information */ memset(&pin, 0, sizeof(pin)); pin.sin_family = AF_INET; - pin.sin_addr.s_addr = inet_addr("192.168.0.2"); + pin.sin_addr.s_addr = inet_addr("192.168.0.1"); pin.sin_port = htons(5001); /* grab an Internet domain socket */ if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { kprintf("socketfail"); - return; + return -1; } kprintf("connecting with socket nr : %d",sd); @@ -242,19 +218,19 @@ void* client_task(void* e) if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) { kprintf("connectfail"); - return; + return -1; } kprintf("sending"); /* send a message to the server PORT on machine HOST */ if (send(sd, "HELLO THERE", strlen("HELLO THERE"), 0) == -1) { kprintf("sendfail"); - return; + return -1; } kprintf("recieving"); /* wait for a message to come back from the server */ if (recv(sd, dir, 256, 0) == -1) { kprintf("recvfail"); - return; + return -1; } /* spew-out the results and bail out of here! */ @@ -262,25 +238,25 @@ void* client_task(void* e) close(sd); - return NULL; + return 0; } - +#endif int test_init(void) { - - if (get_core_no()) - create_kernel_task(NULL,server_task,NULL); - else - create_kernel_task(NULL,client_task,NULL); - -#if 0 char* argv[] = {"/bin/tests", NULL}; sem_init(&producing, 1); sem_init(&consuming, 0); mailbox_int32_init(&mbox); +#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK) + if (!RCCE_ue()) + create_kernel_task(NULL,server_task,NULL); + else + create_kernel_task(NULL,client_task,NULL); +#endif + create_kernel_task(NULL, foo, "Hello from foo1\n"); //create_kernel_task(NULL, join_test, NULL); //create_kernel_task(NULL, producer, NULL); @@ -290,7 +266,6 @@ int test_init(void) create_user_task(NULL, "/bin/tests", argv); //create_user_task(NULL, "/bin/jacobi", argv); //create_user_task(NULL, "/bin/jacobi", argv); -#endif return 0; }