Ignore:
Timestamp:
2011-01-09T12:18:00Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
54de5ebd
Parents:
a3eeef45 (diff), 9d12059 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hw/netif/dp8390/dp8390_module.c

    ra3eeef45 ra676574  
    4141#include <err.h>
    4242#include <malloc.h>
     43#include <sysinfo.h>
    4344#include <ipc/ipc.h>
    4445#include <ipc/services.h>
    45 
     46#include <ipc/irc.h>
    4647#include <net/modules.h>
    4748#include <packet_client.h>
     
    5152#include <netif_interface.h>
    5253#include <netif_local.h>
    53 
    5454#include "dp8390.h"
    5555#include "dp8390_drv.h"
     
    6060#define NAME  "dp8390"
    6161
    62 /** Returns the device from the interrupt call.
     62/** Return the device from the interrupt call.
     63 *
    6364 *  @param[in] call The interrupt call.
    64  */
    65 #define IRQ_GET_DEVICE(call)                    (device_id_t) IPC_GET_IMETHOD(*call)
    66 
    67 /** Returns the interrupt status register from the interrupt call.
     65 *
     66 */
     67#define IRQ_GET_DEVICE(call)  ((device_id_t) IPC_GET_IMETHOD(call))
     68
     69/** Return the ISR from the interrupt call.
     70 *
    6871 *  @param[in] call The interrupt call.
    69  */
    70 #define IPC_GET_ISR(call)                               (int) IPC_GET_ARG2(*call)
     72 *
     73 */
     74#define IRQ_GET_ISR(call)  ((int) IPC_GET_ARG2(call))
     75
     76static int irc_service = 0;
     77static int irc_phone = -1;
    7178
    7279/** DP8390 kernel interrupt command sequence.
    7380 */
    74 static irq_cmd_t        dp8390_cmds[] = {
    75         {       .cmd = CMD_PIO_READ_8,
     81static irq_cmd_t dp8390_cmds[] = {
     82        {
     83                .cmd = CMD_PIO_READ_8,
    7684                .addr = NULL,
    7785                .dstarg = 2
    7886        },
    7987        {
     88                .cmd = CMD_BTEST,
     89                .value = 0x7f,
     90                .srcarg = 2,
     91                .dstarg = 3,
     92        },
     93        {
    8094                .cmd = CMD_PREDICATE,
    81                 .value = 1,
    82                 .srcarg = 2
     95                .value = 2,
     96                .srcarg = 3
     97        },
     98        {
     99                .cmd = CMD_PIO_WRITE_A_8,
     100                .addr = NULL,
     101                .srcarg = 3
    83102        },
    84103        {
     
    89108/** DP8390 kernel interrupt code.
    90109 */
    91 static irq_code_t       dp8390_code = {
     110static irq_code_t dp8390_code = {
    92111        sizeof(dp8390_cmds) / sizeof(irq_cmd_t),
    93112        dp8390_cmds
     
    99118 *  @param[in] call The interrupt message.
    100119 */
    101 static void irq_handler(ipc_callid_t iid, ipc_call_t * call)
    102 {
    103         netif_device_t * device;
    104         dpeth_t * dep;
    105         packet_t *received;
    106         device_id_t device_id;
    107         int phone;
    108 
    109         device_id = IRQ_GET_DEVICE(call);
     120static void irq_handler(ipc_callid_t iid, ipc_call_t *call)
     121{
     122        device_id_t device_id = IRQ_GET_DEVICE(*call);
     123        netif_device_t *device;
     124        int nil_phone;
     125        dpeth_t *dep;
     126       
    110127        fibril_rwlock_write_lock(&netif_globals.lock);
    111         if(find_device(device_id, &device) != EOK){
    112                 fibril_rwlock_write_unlock(&netif_globals.lock);
    113                 return;
    114         }
    115         dep = (dpeth_t *) device->specific;
    116         if (dep->de_mode != DEM_ENABLED){
    117                 fibril_rwlock_write_unlock(&netif_globals.lock);
    118                 return;
    119         }
    120         assert(dep->de_flags &DEF_ENABLED);
    121         dep->de_int_pending = 0;
    122         dp_check_ints(dep, IPC_GET_ISR(call));
    123         if(dep->received_queue){
    124                 received = dep->received_queue;
    125                 phone = device->nil_phone;
    126                 dep->received_queue = NULL;
    127                 dep->received_count = 0;
    128                 fibril_rwlock_write_unlock(&netif_globals.lock);
    129                 nil_received_msg(phone, device_id, received, SERVICE_NONE);
    130         }else{
    131                 fibril_rwlock_write_unlock(&netif_globals.lock);
    132         }
    133         ipc_answer_0(iid, EOK);
    134 }
    135 
    136 /** Changes the network interface state.
     128       
     129        if (find_device(device_id, &device) == EOK) {
     130                nil_phone = device->nil_phone;
     131                dep = (dpeth_t *) device->specific;
     132        } else
     133                dep = NULL;
     134       
     135        fibril_rwlock_write_unlock(&netif_globals.lock);
     136       
     137        if ((dep != NULL) && (dep->up)) {
     138                assert(dep->enabled);
     139                dp_check_ints(nil_phone, device_id, dep, IRQ_GET_ISR(*call));
     140        }
     141}
     142
     143/** Change the network interface state.
     144 *
    137145 *  @param[in,out] device The network interface.
    138  *  @param[in] state The new state.
    139  *  @returns The new state.
    140  */
    141 static int change_state(netif_device_t * device, device_state_t state)
     146 *  @param[in]     state  The new state.
     147 *
     148 *  @return The new state.
     149 *
     150 */
     151static int change_state(netif_device_t *device, device_state_t state)
    142152{
    143153        if (device->state != state) {
     
    153163}
    154164
    155 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     165int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
     166    ipc_call_t *answer, int *answer_count)
     167{
    156168        return ENOTSUP;
    157169}
     
    162174        eth_stat_t * de_stat;
    163175        int rc;
    164 
    165         if(! stats){
     176       
     177        if (!stats)
    166178                return EBADMEM;
    167         }
     179       
    168180        rc = find_device(device_id, &device);
    169181        if (rc != EOK)
    170182                return rc;
     183       
    171184        de_stat = &((dpeth_t *) device->specific)->de_stat;
     185       
    172186        null_device_stats(stats);
    173187        stats->receive_errors = de_stat->ets_recvErr;
     
    183197        stats->send_heartbeat_errors = de_stat->ets_CDheartbeat;
    184198        stats->send_window_errors = de_stat->ets_OWC;
    185         return EOK;
    186 }
    187 
    188 int netif_get_addr_message(device_id_t device_id, measured_string_t *address){
    189         netif_device_t * device;
     199       
     200        return EOK;
     201}
     202
     203int netif_get_addr_message(device_id_t device_id, measured_string_t *address)
     204{
     205        netif_device_t *device;
    190206        int rc;
    191 
    192         if(! address){
     207       
     208        if (!address)
    193209                return EBADMEM;
    194         }
     210       
    195211        rc = find_device(device_id, &device);
    196212        if (rc != EOK)
    197213                return rc;
    198         address->value = (char *) (&((dpeth_t *) device->specific)->de_address);
     214       
     215        address->value = (uint8_t *) &((dpeth_t *) device->specific)->de_address;
    199216        address->length = sizeof(ether_addr_t);
    200217        return EOK;
    201218}
    202219
    203 
    204 
    205 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
    206         netif_device_t * device;
    207         dpeth_t * dep;
     220int netif_probe_message(device_id_t device_id, int irq, uintptr_t io)
     221{
     222        netif_device_t *device;
     223        dpeth_t *dep;
    208224        int rc;
    209 
     225       
    210226        device = (netif_device_t *) malloc(sizeof(netif_device_t));
    211         if(! device){
     227        if (!device)
    212228                return ENOMEM;
    213         }
     229       
    214230        dep = (dpeth_t *) malloc(sizeof(dpeth_t));
    215         if(! dep){
     231        if (!dep) {
    216232                free(device);
    217233                return ENOMEM;
    218234        }
     235       
    219236        bzero(device, sizeof(netif_device_t));
    220237        bzero(dep, sizeof(dpeth_t));
     
    224241        device->state = NETIF_STOPPED;
    225242        dep->de_irq = irq;
    226         dep->de_mode = DEM_DISABLED;
     243        dep->up = false;
     244       
    227245        //TODO address?
    228246        rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port);
     
    231249                free(device);
    232250                return rc;
    233         }       
     251        }
     252       
    234253        rc = do_probe(dep);
    235254        if (rc != EOK) {
     
    238257                return rc;
    239258        }
     259       
    240260        rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device);
    241         if (rc != EOK){
     261        if (rc != EOK) {
    242262                free(dep);
    243263                free(device);
    244264                return rc;
    245265        }
    246         return EOK;
    247 }
    248 
    249 int netif_send_message(device_id_t device_id, packet_t *packet, services_t sender){
    250         netif_device_t * device;
    251         dpeth_t * dep;
     266       
     267        return EOK;
     268}
     269
     270int netif_send_message(device_id_t device_id, packet_t *packet,
     271    services_t sender)
     272{
     273        netif_device_t *device;
     274        dpeth_t *dep;
    252275        packet_t *next;
    253276        int rc;
    254 
     277       
    255278        rc = find_device(device_id, &device);
    256279        if (rc != EOK)
    257280                return rc;
    258         if(device->state != NETIF_ACTIVE){
     281       
     282        if (device->state != NETIF_ACTIVE) {
    259283                netif_pq_release(packet_get_id(packet));
    260284                return EFORWARD;
    261285        }
     286       
    262287        dep = (dpeth_t *) device->specific;
    263         // process packet queue
    264         do{
     288       
     289        /* Process packet queue */
     290        do {
    265291                next = pq_detach(packet);
    266                 if(do_pwrite(dep, packet, FALSE) != EBUSY){
     292               
     293                if (do_pwrite(dep, packet, false) != EBUSY)
    267294                        netif_pq_release(packet_get_id(packet));
    268                 }
     295               
    269296                packet = next;
    270         }while(packet);
    271         return EOK;
    272 }
    273 
    274 int netif_start_message(netif_device_t * device){
    275         dpeth_t * dep;
     297        } while (packet);
     298       
     299        return EOK;
     300}
     301
     302int netif_start_message(netif_device_t * device)
     303{
     304        dpeth_t *dep;
    276305        int rc;
    277 
    278         if(device->state != NETIF_ACTIVE){
     306       
     307        if (device->state != NETIF_ACTIVE) {
    279308                dep = (dpeth_t *) device->specific;
    280309                dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR);
    281                 dp8390_cmds[2].addr = dp8390_cmds[0].addr;
     310                dp8390_cmds[3].addr = dp8390_cmds[0].addr;
     311               
    282312                rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code);
    283313                if (rc != EOK)
    284314                        return rc;
    285                 rc = do_init(dep, DL_BROAD_REQ);
     315               
     316                rc = do_init(dep);
    286317                if (rc != EOK) {
    287318                        ipc_unregister_irq(dep->de_irq, device->device_id);
    288319                        return rc;
    289320                }
    290                 return change_state(device, NETIF_ACTIVE);
    291         }
    292         return EOK;
    293 }
    294 
    295 int netif_stop_message(netif_device_t * device){
    296         dpeth_t * dep;
    297 
    298         if(device->state != NETIF_STOPPED){
     321               
     322                rc = change_state(device, NETIF_ACTIVE);
     323               
     324                if (irc_service)
     325                        async_msg_1(irc_phone, IRC_ENABLE_INTERRUPT, dep->de_irq);
     326               
     327                return rc;
     328        }
     329       
     330        return EOK;
     331}
     332
     333int netif_stop_message(netif_device_t * device)
     334{
     335        dpeth_t *dep;
     336       
     337        if (device->state != NETIF_STOPPED) {
    299338                dep = (dpeth_t *) device->specific;
    300339                do_stop(dep);
     
    302341                return change_state(device, NETIF_STOPPED);
    303342        }
    304         return EOK;
    305 }
    306 
    307 int netif_initialize(void){
     343       
     344        return EOK;
     345}
     346
     347int netif_initialize(void)
     348{
     349        sysarg_t apic;
     350        sysarg_t i8259;
     351       
     352        if ((sysinfo_get_value("apic", &apic) == EOK) && (apic))
     353                irc_service = SERVICE_APIC;
     354        else if ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))
     355                irc_service = SERVICE_I8259;
     356       
     357        if (irc_service) {
     358                while (irc_phone < 0) {
     359                        irc_phone = ipc_connect_me_to_blocking(PHONE_NS, irc_service,
     360                            0, 0);
     361                }
     362        }
     363       
     364        async_set_interrupt_received(irq_handler);
     365       
    308366        sysarg_t phonehash;
    309 
    310         async_set_interrupt_received(irq_handler);
    311 
    312367        return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0, 0, &phonehash);
    313368}
     
    319374 *
    320375 */
    321 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     376static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    322377{
    323378        /*
     
    327382        ipc_answer_0(iid, EOK);
    328383       
    329         while(true) {
     384        while (true) {
    330385                ipc_call_t answer;
    331386                int answer_count;
     
    351406}
    352407
    353 /** Starts the module.
     408/** Start the module.
    354409 *
    355410 *  @param argc The count of the command line arguments. Ignored parameter.
     
    362417int main(int argc, char *argv[])
    363418{
    364         int rc;
    365        
    366419        /* Start the module */
    367         rc = netif_module_start(netif_client_connection);
    368         return rc;
     420        return netif_module_start(netif_client_connection);
    369421}
    370422
Note: See TracChangeset for help on using the changeset viewer.