Ignore:
File:
1 edited

Legend:

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

    rf87c900 r66b628a  
    4343#include <ipc/ipc.h>
    4444#include <ipc/services.h>
    45 
    4645#include <net/modules.h>
    4746#include <packet_client.h>
     
    5150#include <netif_interface.h>
    5251#include <netif_local.h>
    53 
    5452#include "dp8390.h"
    5553#include "dp8390_drv.h"
     
    6058#define NAME  "dp8390"
    6159
    62 /** Returns the device from the interrupt call.
     60/** Return the device from the interrupt call.
     61 *
    6362 *  @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.
     63 *
     64 */
     65#define IRQ_GET_DEVICE(call)  ((device_id_t) IPC_GET_IMETHOD(call))
     66
     67/** Return the ISR from the interrupt call.
     68 *
    6869 *  @param[in] call The interrupt call.
    69  */
    70 #define IPC_GET_ISR(call)                               (int) IPC_GET_ARG2(*call)
     70 *
     71 */
     72#define IRQ_GET_ISR(call)  ((int) IPC_GET_ARG2(call))
    7173
    7274/** DP8390 kernel interrupt command sequence.
    7375 */
    74 static irq_cmd_t        dp8390_cmds[] = {
    75         {       .cmd = CMD_PIO_READ_8,
     76static irq_cmd_t dp8390_cmds[] = {
     77        {
     78                .cmd = CMD_PIO_READ_8,
    7679                .addr = NULL,
    7780                .dstarg = 2
    7881        },
    7982        {
     83                .cmd = CMD_BTEST,
     84                .value = 0x7f,
     85                .srcarg = 2,
     86                .dstarg = 3,
     87        },
     88        {
    8089                .cmd = CMD_PREDICATE,
    81                 .value = 1,
    82                 .srcarg = 2
     90                .value = 2,
     91                .srcarg = 3
    8392        },
    8493        {
     94                .cmd = CMD_PIO_WRITE_A_8,
     95                .addr = NULL,
     96                .srcarg = 3
     97        },
     98        {
    8599                .cmd = CMD_ACCEPT
    86100        }
     
    89103/** DP8390 kernel interrupt code.
    90104 */
    91 static irq_code_t       dp8390_code = {
     105static irq_code_t dp8390_code = {
    92106        sizeof(dp8390_cmds) / sizeof(irq_cmd_t),
    93107        dp8390_cmds
     
    99113 *  @param[in] call The interrupt message.
    100114 */
    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);
     115static void irq_handler(ipc_callid_t iid, ipc_call_t *call)
     116{
     117        device_id_t device_id = IRQ_GET_DEVICE(*call);
     118        netif_device_t *device;
     119        int nil_phone;
     120        dpeth_t *dep;
     121       
    110122        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);
     123       
     124        if (find_device(device_id, &device) == EOK) {
     125                nil_phone = device->nil_phone;
     126                dep = (dpeth_t *) device->specific;
     127        } else
     128                dep = NULL;
     129       
     130        fibril_rwlock_write_unlock(&netif_globals.lock);
     131       
     132        if ((dep != NULL) && (dep->up)) {
     133                assert(dep->enabled);
     134                dp_check_ints(nil_phone, device_id, dep, IRQ_GET_ISR(*call));
     135        }
    134136}
    135137
     
    139141 *  @returns The new state.
    140142 */
    141 static int change_state(netif_device_t * device, device_state_t state)
     143static int change_state(netif_device_t *device, device_state_t state)
    142144{
    143145        if (device->state != state) {
     
    153155}
    154156
    155 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     157int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
     158    ipc_call_t *answer, int *answer_count)
     159{
    156160        return ENOTSUP;
    157161}
     
    162166        eth_stat_t * de_stat;
    163167        int rc;
    164 
    165         if(! stats){
     168       
     169        if (!stats)
    166170                return EBADMEM;
    167         }
     171       
    168172        rc = find_device(device_id, &device);
    169173        if (rc != EOK)
    170174                return rc;
     175       
    171176        de_stat = &((dpeth_t *) device->specific)->de_stat;
     177       
    172178        null_device_stats(stats);
    173179        stats->receive_errors = de_stat->ets_recvErr;
     
    183189        stats->send_heartbeat_errors = de_stat->ets_CDheartbeat;
    184190        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;
    190         int rc;
    191 
    192         if(! address){
     191       
     192        return EOK;
     193}
     194
     195int netif_get_addr_message(device_id_t device_id, measured_string_t *address)
     196{
     197        netif_device_t *device;
     198        int rc;
     199       
     200        if (!address)
    193201                return EBADMEM;
    194         }
     202       
    195203        rc = find_device(device_id, &device);
    196204        if (rc != EOK)
    197205                return rc;
     206       
    198207        address->value = (char *) (&((dpeth_t *) device->specific)->de_address);
    199208        address->length = sizeof(ether_addr_t);
     
    201210}
    202211
    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;
    208         int rc;
    209 
     212int netif_probe_message(device_id_t device_id, int irq, uintptr_t io)
     213{
     214        netif_device_t *device;
     215        dpeth_t *dep;
     216        int rc;
     217       
    210218        device = (netif_device_t *) malloc(sizeof(netif_device_t));
    211         if(! device){
     219        if (!device)
    212220                return ENOMEM;
    213         }
     221       
    214222        dep = (dpeth_t *) malloc(sizeof(dpeth_t));
    215         if(! dep){
     223        if (!dep) {
    216224                free(device);
    217225                return ENOMEM;
    218226        }
     227       
    219228        bzero(device, sizeof(netif_device_t));
    220229        bzero(dep, sizeof(dpeth_t));
     
    224233        device->state = NETIF_STOPPED;
    225234        dep->de_irq = irq;
    226         dep->de_mode = DEM_DISABLED;
     235        dep->up = false;
     236       
    227237        //TODO address?
    228238        rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port);
     
    231241                free(device);
    232242                return rc;
    233         }       
     243        }
     244       
    234245        rc = do_probe(dep);
    235246        if (rc != EOK) {
     
    238249                return rc;
    239250        }
     251       
    240252        rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device);
    241         if (rc != EOK){
     253        if (rc != EOK) {
    242254                free(dep);
    243255                free(device);
    244256                return rc;
    245257        }
    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;
     258       
     259        return EOK;
     260}
     261
     262int netif_send_message(device_id_t device_id, packet_t *packet,
     263    services_t sender)
     264{
     265        netif_device_t *device;
     266        dpeth_t *dep;
    252267        packet_t *next;
    253268        int rc;
    254 
     269       
    255270        rc = find_device(device_id, &device);
    256271        if (rc != EOK)
    257272                return rc;
    258         if(device->state != NETIF_ACTIVE){
     273       
     274        if (device->state != NETIF_ACTIVE){
    259275                netif_pq_release(packet_get_id(packet));
    260276                return EFORWARD;
    261277        }
     278       
    262279        dep = (dpeth_t *) device->specific;
    263         // process packet queue
    264         do{
     280       
     281        /* Process packet queue */
     282        do {
    265283                next = pq_detach(packet);
    266                 if(do_pwrite(dep, packet, FALSE) != EBUSY){
     284               
     285                if (do_pwrite(dep, packet, false) != EBUSY)
    267286                        netif_pq_release(packet_get_id(packet));
    268                 }
     287               
    269288                packet = next;
    270         }while(packet);
    271         return EOK;
    272 }
    273 
    274 int netif_start_message(netif_device_t * device){
    275         dpeth_t * dep;
    276         int rc;
    277 
    278         if(device->state != NETIF_ACTIVE){
     289        } while (packet);
     290       
     291        return EOK;
     292}
     293
     294int netif_start_message(netif_device_t * device)
     295{
     296        dpeth_t *dep;
     297        int rc;
     298       
     299        if (device->state != NETIF_ACTIVE) {
    279300                dep = (dpeth_t *) device->specific;
    280301                dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR);
    281                 dp8390_cmds[2].addr = dp8390_cmds[0].addr;
     302                dp8390_cmds[3].addr = dp8390_cmds[0].addr;
     303               
    282304                rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code);
    283305                if (rc != EOK)
    284306                        return rc;
    285                 rc = do_init(dep, DL_BROAD_REQ);
     307               
     308                rc = do_init(dep);
    286309                if (rc != EOK) {
    287310                        ipc_unregister_irq(dep->de_irq, device->device_id);
    288311                        return rc;
    289312                }
     313               
    290314                return change_state(device, NETIF_ACTIVE);
    291315        }
    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){
     316       
     317        return EOK;
     318}
     319
     320int netif_stop_message(netif_device_t * device)
     321{
     322        dpeth_t *dep;
     323       
     324        if (device->state != NETIF_STOPPED) {
    299325                dep = (dpeth_t *) device->specific;
    300326                do_stop(dep);
     
    302328                return change_state(device, NETIF_STOPPED);
    303329        }
    304         return EOK;
    305 }
    306 
    307 int netif_initialize(void){
     330       
     331        return EOK;
     332}
     333
     334int netif_initialize(void)
     335{
    308336        sysarg_t phonehash;
    309 
    310337        async_set_interrupt_received(irq_handler);
    311 
    312338        return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0, 0, &phonehash);
    313339}
     
    319345 *
    320346 */
    321 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     347static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    322348{
    323349        /*
     
    327353        ipc_answer_0(iid, EOK);
    328354       
    329         while(true) {
     355        while (true) {
    330356                ipc_call_t answer;
    331357                int answer_count;
     
    351377}
    352378
    353 /** Starts the module.
     379/** Start the module.
    354380 *
    355381 *  @param argc The count of the command line arguments. Ignored parameter.
     
    362388int main(int argc, char *argv[])
    363389{
    364         int rc;
    365        
    366390        /* Start the module */
    367         rc = netif_module_start(netif_client_connection);
    368         return rc;
     391        return netif_module_start(netif_client_connection);
    369392}
    370393
Note: See TracChangeset for help on using the changeset viewer.