x86: interrupt return path checks kmsgs
[akaros.git] / kern / arch / i686 / ne2k.c
index 9cf09bf..5576550 100644 (file)
 
 #define SET_PAGE_0() (inb(ne2k_io_base_addr + NE2K_PG0_RW_CR) & 0x3F)
 
-extern uint32_t eth_up; // Fix this                               
-uint32_t ne2k_irq;      // And this
+uint32_t ne2k_irq;      // Fix this
 uint32_t ne2k_io_base_addr;
-char device_mac[6];
-
-extern uint32_t packet_buffer_count;
-extern char* packet_buffer[PACKET_BUFFER_SIZE];
-extern uint32_t packet_buffer_sizes[PACKET_BUFFER_SIZE];
-extern uint32_t packet_buffer_head;
-extern uint32_t packet_buffer_tail;
-spinlock_t packet_buffer_lock;
-
 
 void* base_page;
 uint32_t num_pages = 0;
 
-extern char *CT(PACKET_HEADER_SIZE + len) (*packet_wrap)(const char *CT(len) data, size_t len);
-extern int (*send_frame)(const char *CT(len) data, size_t len);
-
-
 void ne2k_init() {
        
        if (ne2k_scan_pci() < 0) return;
        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;
 
-        ne2k_setup_interrupts();
+       ne2k_setup_interrupts();
 
        eth_up = 1;
 
@@ -213,7 +202,13 @@ void ne2k_setup_interrupts() {
        // Kernel based interrupt stuff
        register_interrupt_handler(interrupt_handlers, KERNEL_IRQ_OFFSET + ne2k_irq, ne2k_interrupt_handler, (void *)0);
        
-       ioapic_route_irq(ne2k_irq, 6);  
+#ifdef __CONFIG_DISABLE_MPTABLES__
+       pic_unmask_irq(ne2k_irq);
+       unmask_lapic_lvt(LAPIC_LVT_LINT0);
+       enable_irq();
+#else
+       ioapic_route_irq(ne2k_irq, 0);  
+#endif
        
        SET_PAGE_0();
 
@@ -396,22 +391,35 @@ void ne2k_handle_rx_packet() {
                return;
        }
 
-       spin_lock(&packet_buffer_lock);
+#ifdef __CONFIG_APPSERVER__
+       // 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) {
+               handle_appserver_packet(rx_buffer, packet_len);
+               kfree(rx_buffer);
+               return;
+       }
+#endif
+
+       spin_lock(&packet_buffers_lock);
 
-       if (packet_buffer_count >= PACKET_BUFFER_SIZE) {
+       if (num_packet_buffers >= MAX_PACKET_BUFFERS) {
                printk("WARNING: DROPPING PACKET!\n");
-               spin_unlock(&packet_buffer_lock);
+               spin_unlock(&packet_buffers_lock);
                kfree(rx_buffer);
                return;
        }
 
-       packet_buffer[packet_buffer_tail] = rx_buffer;
-       packet_buffer_sizes[packet_buffer_tail] = packet_len;
+       packet_buffers[packet_buffers_tail] = rx_buffer;
+       packet_buffers_sizes[packet_buffers_tail] = packet_len;
 
-       packet_buffer_tail = (packet_buffer_tail + 1) % PACKET_BUFFER_SIZE;
-       packet_buffer_count = packet_buffer_count + 1;
+       packet_buffers_tail = (packet_buffers_tail + 1) % MAX_PACKET_BUFFERS;
+       num_packet_buffers++;
 
-       spin_unlock(&packet_buffer_lock);
+       spin_unlock(&packet_buffers_lock);
        
        return;
 }
@@ -482,7 +490,7 @@ int ne2k_send_frame(const char *data, size_t len) {
 
        for (int i = 0; i<len; i = i + 1) {
                outb(ne2k_io_base_addr + 0x10, *(uint8_t*)(data + i));
-               //printk("sent: %x\n", *(uint8_t*)(data + i));
+               //ne2k_debug("sent: %x\n", *(uint8_t*)(data + i));
        }
        
        while(( inb(ne2k_io_base_addr + NE2K_PG0_RW_ISR) & 0x40) == 0);