Main Page | Directories | File List | Globals

adi_net.c

Go to the documentation of this file.
00001 /*
00002  * kernel_drivers/adi/adi_net.c
00003  *
00004  * Copyright (c) 2003-2004 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2004/01
00008  * Author:      Lukasz Dembinski
00009  * Info:        adi_net.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <agnix/init.h>
00015 #include <agnix/adi/adi.h>
00016 #include <agnix/net/net.h>
00017 #include <agnix/irq.h>
00018 #include <agnix/memory.h>
00019 #include <agnix/strings.h>
00020 #include <agnix/console.h>
00021 #include <agnix/list.h>
00022 #include <agnix/spinlock.h>
00023 
00024 #define MOD_NAME                "NET: "
00025 
00026 struct list_head        adi_netdev_list;
00027 spinlock_t              adi_netdev_list_lock;
00028 
00029 int net_devices_last_id = 0;
00030 
00031 int adi_netdev_set_name(struct adi_netdev_s *netdev, char *if_name)
00032 {
00033     int name_len;
00034     
00035     name_len = strlen(if_name);
00036 
00037     if (name_len < NETDEV_NAME_MAX_LEN)
00038         memcpy(netdev->if_name, if_name, name_len);
00039     else
00040         memcpy(netdev->if_name, if_name, NETDEV_NAME_MAX_LEN);
00041 
00042     return 0;
00043 }
00044 
00045 int adi_netdev_compose_name(struct adi_netdev_s *netdev)
00046 {
00047     switch(netdev->if_layer_2.if_type) {
00048         case IF_TYPE_ETH:
00049             return eth_device_compose_name(netdev);
00050     }
00051 
00052     return 0;
00053 }
00054 
00055 int adi_netdev_set_id(struct adi_netdev_s *netdev)
00056 {
00057     netdev->if_id = net_devices_last_id;
00058     
00059     net_devices_last_id++;
00060     
00061     return 0;
00062 }
00063 
00064 struct adi_netdev_s *adi_netdev_find_by_name(char *name)
00065 {
00066     struct adi_netdev_s *netdev;
00067     struct list_head *tmp;
00068     int found;
00069     u32 flags;
00070 
00071     spin_lock_irqsave(&adi_netdev_list_lock, flags);    
00072     
00073     found = 0;
00074     list_for_each(tmp, &adi_netdev_list) {
00075         netdev = list_entry(tmp, struct adi_netdev_s, list);
00076         
00077         if (!word_cmp(netdev->if_name, name, NETDEV_NAME_MAX_LEN)) {
00078             found = 1;
00079             break;
00080         }
00081     }
00082     
00083     spin_unlock_irqrestore(&adi_netdev_list_lock, flags);
00084     
00085     if (found)
00086         return netdev;
00087 
00088     return NULL;
00089 }
00090 
00091 int adi_netdev_list_add(struct adi_netdev_s *netdev)
00092 {
00093     u32 flags;
00094     
00095     spin_lock_irqsave(&adi_netdev_list_lock, flags);
00096     list_add(&netdev->list, &adi_netdev_list);
00097     spin_unlock_irqrestore(&adi_netdev_list_lock, flags);
00098     
00099     return 0;
00100 }
00101 
00102 int adi_netdev_init(struct adi_netdev_s *netdev)
00103 {
00104     adi_netdev_compose_name(netdev);
00105 
00106     switch(netdev->if_layer_2.if_type) {
00107         case IF_TYPE_ETH:
00108             return eth_device_init(netdev);
00109 
00110         case IF_TYPE_FDDI:
00111             break;
00112 
00113         case IF_TYPE_TR:
00114             break;
00115     }
00116 
00117     return 0;
00118 }
00119 
00120 int adi_register_netdev(struct adi_netdev_s *netdev)
00121 {
00122     adi_netdev_set_id  (netdev);
00123     adi_netdev_list_add(netdev);
00124 
00125     switch (netdev->if_layer_2.if_type) {
00126         case IF_TYPE_ETH:
00127             return register_eth_device(netdev);
00128     }
00129 
00130     return 0;
00131 }
00132 
00133 struct adi_netdev_s *adi_netdev_alloc(void)
00134 {
00135     return (struct adi_netdev_s *)get_free_pages(0);
00136 }
00137 
00138 void adi_netdev_free(struct adi_netdev_s *netdev )
00139 {
00140     put_free_pages((u32)netdev, 0);
00141 }
00142 
00143 int adi_netdev_data_init(void)
00144 {       
00145     INIT_LIST_HEAD(&adi_netdev_list);
00146     spin_lock_init(&adi_netdev_list_lock);
00147 
00148     return 0;
00149 }
00150 
00151 int __init adi_netdrv_init(void)
00152 {
00153     printk(MOD_NAME "Initializing network drivers\n");
00154 
00155     adi_netdev_data_init();
00156 
00157 #if CONFIG_DRIVERS_NET_RTL_8029
00158     adi_netdrv_rtl_8029_init();
00159 #endif
00160 
00161     return 0;
00162 }
00163 
00164 void adi_netdev_print_interfaces(void)
00165 {
00166     struct adi_netdev_s *netdev;
00167     struct list_head *tmp;
00168     const char *link_encaps;
00169     u32 flags;
00170 
00171     spin_lock_irqsave(&adi_netdev_list_lock, flags);    
00172     
00173     list_for_each(tmp, &adi_netdev_list) {
00174         netdev = list_entry(tmp, struct adi_netdev_s, list);
00175         
00176         if (netdev->if_layer_2.if_type == IF_TYPE_ETH)
00177             link_encaps = "Ethernet";
00178         else
00179         if (netdev->if_layer_2.if_type == IF_TYPE_TR)
00180             link_encaps = "Tokenring";
00181         else
00182         if (netdev->if_layer_2.if_type == IF_TYPE_FDDI)
00183             link_encaps = "FDDI";
00184         else
00185             link_encaps = "Unknown";
00186         
00187         printf("\n%s\t Link encapsulation:%s     HWaddr %02x:%02x:%02x:%02x:%02x:%02x\n",
00188         netdev->if_name, link_encaps, 
00189         netdev->if_layer_2.if_addr[0], netdev->if_layer_2.if_addr[1], netdev->if_layer_2.if_addr[2], 
00190         netdev->if_layer_2.if_addr[3], netdev->if_layer_2.if_addr[4], netdev->if_layer_2.if_addr[5]);
00191         
00192         printf("\t Inet address: %d.%d.%d.%d     MTU: %d\n", 
00193         netdev->if_layer_3.if_addr.address[0], netdev->if_layer_3.if_addr.address[1],
00194         netdev->if_layer_3.if_addr.address[2], netdev->if_layer_3.if_addr.address[3],
00195         netdev->if_layer_2.if_mtu); 
00196     }
00197     
00198     spin_unlock_irqrestore(&adi_netdev_list_lock, flags);
00199 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix