Appserver up and running on hardware for x86...
authorKevin Klues <klueska@ros-dev.(none)>
Wed, 14 Apr 2010 04:50:13 +0000 (21:50 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:42 +0000 (17:35 -0700)
kern/arch/i686/frontend.c
kern/arch/i686/ne2k.c
kern/arch/i686/nic_common.c
kern/arch/i686/nic_common.h
kern/arch/i686/rl8168.c

index 3b45abd..80167b3 100644 (file)
@@ -65,6 +65,7 @@ int handle_appserver_packet(const char* p, size_t size)
        // fire the response
        if(send_frame((char*)response_packet,response_size) != response_size)
                panic("couldn't send appserver packet!");
+       kfree(response_packet);
 
        return 0;
        
index 0d49ff9..db4aeee 100644 (file)
@@ -85,6 +85,9 @@ void ne2k_init() {
        ne2k_mem_alloc();
        ne2k_configure_nic();
        ne2k_read_mac();
+       printk("Network Card MAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n", 
+          device_mac[0],device_mac[1],device_mac[2],
+          device_mac[3],device_mac[4],device_mac[5]);
        //ne2k_test_interrupts();
        send_frame = &ne2k_send_frame;
 
index ea8d2c4..7156e62 100644 (file)
@@ -22,7 +22,7 @@ int (*send_frame)(const char *data, size_t len);
 // Global variables for managing ethernet packets over a nic
 // Again, since these are global for all network cards we are 
 // limited to only one for now
-char device_mac[6];
+unsigned char device_mac[6];
 uint8_t eth_up = 0; 
 uint32_t num_packet_buffers = 0;
 char* packet_buffers[MAX_PACKET_BUFFERS];
index a7c279e..1c105b8 100644 (file)
@@ -11,7 +11,7 @@
 #define MIN_FRAME_SIZE   60 // See the spec...
 
 // Maximum packet buffers we can handle at any given time
-#define MAX_PACKET_BUFFERS    1024
+#define MAX_PACKET_BUFFERS    32 //1024
  
 // Global send_frame function pointer
 // Means we can only have one network card per system right now...
@@ -20,7 +20,7 @@ extern int (*send_frame)(const char *data, size_t len);
 // Global variables for managing ethernet packets over a nic
 // Again, since these are global for all network cards we are 
 // limited to only one for now
-extern char device_mac[6];
+extern unsigned char device_mac[6];
 extern uint8_t eth_up;
 extern uint32_t num_packet_buffers;
 extern char* packet_buffers[MAX_PACKET_BUFFERS];
index 8ff74e2..add840a 100644 (file)
@@ -99,6 +99,9 @@ void rl8168_init() {
 
        if (rl8168_scan_pci() < 0) return;
        rl8168_read_mac();
+       printk("Network Card MAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n", 
+          device_mac[0],device_mac[1],device_mac[2],
+          device_mac[3],device_mac[4],device_mac[5]);
        rl8168_setup_descriptors();
        rl8168_configure();
        rl8168_setup_interrupts();
@@ -336,7 +339,7 @@ void rl8168_setup_interrupts() {
 #else
        register_interrupt_handler(interrupt_handlers, KERNEL_IRQ_OFFSET + rl8168_irq, rl8168_interrupt_handler, 0);
 #endif
-       ioapic_route_irq(rl8168_irq, NE2K_IRQ_CPU);     
+       ioapic_route_irq(rl8168_irq, 1);        
        
        return;
 }
@@ -506,13 +509,26 @@ void rl8168_handle_rx_packet() {
                rx_des_loop_cur = (rx_des_loop_cur + 1) % NUM_RX_DESCRIPTORS;
                
        } while (!(current_command & DES_LS_MASK));
-       
+
+       // Treat as a syscall frontend response packet if eth_type says so
+       // Will eventually go away, so not too worried about elegance here...
+       #include <frontend.h>
+       #include <arch/frontend.h>
+       uint16_t eth_type = htons(*(uint16_t*)(rx_buffer + 12));
+       if(eth_type == APPSERVER_ETH_TYPE) {
+               rx_des_cur = rx_des_loop_cur;
+               rl8168_process_frame(rx_buffer, frame_size, current_command);
+               handle_appserver_packet(rx_buffer, frame_size);
+               kfree(rx_buffer);
+               return;
+       }
 
        spin_lock(&packet_buffers_lock);
 
        if (num_packet_buffers >= MAX_PACKET_BUFFERS) {
-               printk("WARNING: DROPPING PACKET!\n");
+               //printk("WARNING: DROPPING PACKET!\n");
                spin_unlock(&packet_buffers_lock);
+               rx_des_cur = rx_des_loop_cur;
                kfree(rx_buffer);
                return;
        }
@@ -526,7 +542,7 @@ void rl8168_handle_rx_packet() {
        spin_unlock(&packet_buffers_lock);
                                
        rx_des_cur = rx_des_loop_cur;
-                               
+
        // Chew on the frame data. Command bits should be the same for all frags.
        rl8168_process_frame(rx_buffer, frame_size, current_command);
        
@@ -627,7 +643,11 @@ int rl8168_send_frame(const char *data, size_t len) {
 
        tx_des_cur = (tx_des_cur + 1) % NUM_TX_DESCRIPTORS;
        
-       //rl8168_frame_debug("-->Sent packet.\n");
+       rl8168_frame_debug("--> Sending Packet\n");
+       for(int i=0; i<len; i++)
+               rl8168_frame_debug("%x ", (unsigned int)(unsigned char)(data[i]));
+       rl8168_frame_debug("\n");
+       rl8168_frame_debug("--> Sent packet.\n");
        
        outb(rl8168_io_base_addr + RL_TX_CTRL_REG, RL_TX_SEND_MASK);