Changeset 0777f4c5 in mainline


Ignore:
Timestamp:
2011-01-06T15:41:05Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6fc0edd
Parents:
74864ac
Message:

improve dp_check_ints

Location:
uspace/srv/hw/netif/dp8390
Files:
3 edited

Legend:

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

    r74864ac r0777f4c5  
    478478}
    479479
    480 /*===========================================================================*
    481  *                              dp_check_ints                                *
    482  *===========================================================================*/
    483 void dp_check_ints(dep, isr)
    484 dpeth_t *dep;
    485 int isr;
    486 {
    487         int /*isr,*/ tsr;
     480void dp_check_ints(dpeth_t *dep)
     481{
     482        int isr, tsr;
    488483        int size, sendq_tail;
    489 
    490         if (!(dep->de_flags &DEF_ENABLED))
     484       
     485        if (!(dep->de_flags & DEF_ENABLED))
    491486                fprintf(stderr, "dp8390: got premature interrupt\n");
    492 
    493         for(;;)
    494         {
    495 //              isr = inb_reg0(dep, DP_ISR);
     487       
     488        for (;;) {
     489                isr = inb_reg0(dep, DP_ISR);
    496490                if (!isr)
    497491                        break;
     492               
    498493                outb_reg0(dep, DP_ISR, isr);
    499                 if (isr &(ISR_PTX|ISR_TXE))
    500                 {
    501                         if (isr &ISR_TXE)
    502                         {
     494               
     495                if (isr & (ISR_PTX | ISR_TXE)) {
     496                        if (isr & ISR_TXE)
    503497                                dep->de_stat.ets_sendErr++;
     498                        else {
     499                                tsr = inb_reg0(dep, DP_TSR);
     500                               
     501                                if (tsr & TSR_PTX)
     502                                        dep->de_stat.ets_packetT++;
     503                               
     504                                if (tsr & TSR_COL)
     505                                        dep->de_stat.ets_collision++;
     506                               
     507                                if (tsr & TSR_ABT)
     508                                        dep->de_stat.ets_transAb++;
     509                               
     510                                if (tsr & TSR_CRS)
     511                                        dep->de_stat.ets_carrSense++;
     512                               
     513                                if ((tsr & TSR_FU) && (++dep->de_stat.ets_fifoUnder <= 10))
     514                                        printf("%s: fifo underrun\n", dep->de_name);
     515                               
     516                                if ((tsr & TSR_CDH) && (++dep->de_stat.ets_CDheartbeat <= 10))
     517                                        printf("%s: CD heart beat failure\n", dep->de_name);
     518                               
     519                                if (tsr & TSR_OWC)
     520                                        dep->de_stat.ets_OWC++;
    504521                        }
    505                         else
    506                         {
    507                                 tsr = inb_reg0(dep, DP_TSR);
    508 
    509                                 if (tsr &TSR_PTX) dep->de_stat.ets_packetT++;
    510 #if 0   /* Reserved in later manuals, should be ignored */
    511                                 if (!(tsr &TSR_DFR))
    512                                 {
    513                                         /* In most (all?) implementations of
    514                                          * the dp8390, this bit is set
    515                                          * when the packet is not deferred
    516                                          */
    517                                         dep->de_stat.ets_transDef++;
    518                                 }
    519 #endif
    520                                 if (tsr &TSR_COL) dep->de_stat.ets_collision++;
    521                                 if (tsr &TSR_ABT) dep->de_stat.ets_transAb++;
    522                                 if (tsr &TSR_CRS) dep->de_stat.ets_carrSense++;
    523                                 if (tsr &TSR_FU
    524                                         && ++dep->de_stat.ets_fifoUnder <= 10)
    525                                 {
    526                                         printf("%s: fifo underrun\n",
    527                                                 dep->de_name);
    528                                 }
    529                                 if (tsr &TSR_CDH
    530                                         && ++dep->de_stat.ets_CDheartbeat <= 10)
    531                                 {
    532                                         printf("%s: CD heart beat failure\n",
    533                                                 dep->de_name);
    534                                 }
    535                                 if (tsr &TSR_OWC) dep->de_stat.ets_OWC++;
    536                         }
    537                         sendq_tail= dep->de_sendq_tail;
    538 
    539                         if (!(dep->de_sendq[sendq_tail].sq_filled))
    540                         {
     522                       
     523                        sendq_tail = dep->de_sendq_tail;
     524                       
     525                        if (!(dep->de_sendq[sendq_tail].sq_filled)) {
    541526                                /* Software bug? */
    542527                                assert(false);
    543 
     528                               
    544529                                /* Or hardware bug? */
    545                                 printf(
    546                                 "%s: transmit interrupt, but not sending\n",
    547                                         dep->de_name);
     530                                printf("%s: transmit interrupt, but not sending\n", dep->de_name);
    548531                                continue;
    549532                        }
    550                         dep->de_sendq[sendq_tail].sq_filled= 0;
     533                       
     534                        dep->de_sendq[sendq_tail].sq_filled = 0;
     535                       
    551536                        if (++sendq_tail == dep->de_sendq_nr)
    552                                 sendq_tail= 0;
    553                         dep->de_sendq_tail= sendq_tail;
    554                         if (dep->de_sendq[sendq_tail].sq_filled)
    555                         {
    556                                 size= dep->de_sendq[sendq_tail].sq_size;
     537                                sendq_tail = 0;
     538                       
     539                        dep->de_sendq_tail = sendq_tail;
     540                       
     541                        if (dep->de_sendq[sendq_tail].sq_filled) {
     542                                size = dep->de_sendq[sendq_tail].sq_size;
    557543                                outb_reg0(dep, DP_TPSR,
    558                                         dep->de_sendq[sendq_tail].sq_sendpage);
     544                                    dep->de_sendq[sendq_tail].sq_sendpage);
    559545                                outb_reg0(dep, DP_TBCR1, size >> 8);
    560                                 outb_reg0(dep, DP_TBCR0, size &0xff);
     546                                outb_reg0(dep, DP_TBCR0, size & 0xff);
    561547                                outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);
    562548                        }
     549                       
    563550//                      if (dep->de_flags &DEF_SEND_AVAIL)
    564551                                dp_send(dep);
    565552                }
    566 
    567                 if (isr &ISR_PRX)
    568                 {
     553               
     554                if (isr & ISR_PRX) {
    569555                        /* Only call dp_recv if there is a read request */
    570556//                      if (dep->de_flags) &DEF_READING)
     
    572558                }
    573559               
    574                 if (isr &ISR_RXE) dep->de_stat.ets_recvErr++;
    575                 if (isr &ISR_CNT)
    576                 {
     560                if (isr & ISR_RXE)
     561                        dep->de_stat.ets_recvErr++;
     562               
     563                if (isr & ISR_CNT) {
    577564                        dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0);
    578565                        dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1);
    579566                        dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2);
    580567                }
    581                 if (isr &ISR_OVW)
    582                 {
     568               
     569                if (isr & ISR_OVW) {
    583570                        dep->de_stat.ets_OVW++;
    584 #if 0
    585                         {printW(); printf(
    586                                 "%s: got overwrite warning\n", dep->de_name);}
    587 #endif
    588 /*                      if (dep->de_flags &DEF_READING)
    589                         {
    590                                 printf(
    591 "dp_check_ints: strange: overwrite warning and pending read request\n");
     571/*                      if (dep->de_flags & DEF_READING) {
     572                                printf("dp_check_ints: strange: overwrite warning and pending read request\n");
    592573                                dp_recv(dep);
    593574                        }
    594575*/              }
    595                 if (isr &ISR_RDC)
    596                 {
     576               
     577                if (isr & ISR_RDC) {
    597578                        /* Nothing to do */
    598579                }
    599                 if (isr &ISR_RST)
    600                 {
    601                         /* this means we got an interrupt but the ethernet
     580               
     581                if (isr & ISR_RST) {
     582                        /*
     583                         * This means we got an interrupt but the ethernet
    602584                         * chip is shutdown. We set the flag DEF_STOPPED,
    603585                         * and continue processing arrived packets. When the
    604586                         * receive buffer is empty, we reset the dp8390.
    605587                         */
    606 #if 0
    607                          {printW(); printf(
    608                                 "%s: NIC stopped\n", dep->de_name);}
    609 #endif
    610588                        dep->de_flags |= DEF_STOPPED;
    611589                        break;
    612590                }
    613                 isr = inb_reg0(dep, DP_ISR);
    614         }
    615 //      if ((dep->de_flags &(DEF_READING|DEF_STOPPED)) ==
    616 //                                              (DEF_READING|DEF_STOPPED))
    617         if ((dep->de_flags &DEF_STOPPED) == DEF_STOPPED)
    618         {
    619                 /* The chip is stopped, and all arrived packets are
    620                  * delivered.
     591        }
     592       
     593//      if ((dep->de_flags & (DEF_READING | DEF_STOPPED)) == (DEF_READING | DEF_STOPPED))
     594        if ((dep->de_flags & DEF_STOPPED) == DEF_STOPPED) {
     595                /*
     596                 * The chip is stopped, and all arrived packets
     597                 * are delivered.
    621598                 */
    622599                dp_reset(dep);
  • uspace/srv/hw/netif/dp8390/dp8390_drv.h

    r74864ac r0777f4c5  
    5555/** Processes the interrupt.
    5656 *  @param[in,out] dep The network interface structure.
    57  *  @param[in] isr The interrupt status register.
    5857 */
    59 void dp_check_ints(dpeth_t *dep, int isr);
     58void dp_check_ints(dpeth_t *dep);
    6059
    6160/** Probes and initializes the network interface.
  • uspace/srv/hw/netif/dp8390/dp8390_module.c

    r74864ac r0777f4c5  
    6161 *  @param[in] call The interrupt call.
    6262 */
    63 #define IRQ_GET_DEVICE(call)                    (device_id_t) IPC_GET_IMETHOD(*call)
    64 
    65 /** Returns the interrupt status register from the interrupt call.
    66  *  @param[in] call The interrupt call.
    67  */
    68 #define IPC_GET_ISR(call)                               (int) IPC_GET_ARG2(*call)
     63#define IRQ_GET_DEVICE(call)  (device_id_t) IPC_GET_IMETHOD(*call)
    6964
    7065/** DP8390 kernel interrupt command sequence.
    7166 */
    72 static irq_cmd_t        dp8390_cmds[] = {
    73         {       .cmd = CMD_PIO_READ_8,
     67static irq_cmd_t dp8390_cmds[] = {
     68        {
     69                .cmd = CMD_PIO_READ_8,
    7470                .addr = NULL,
    7571                .dstarg = 2
     
    8783/** DP8390 kernel interrupt code.
    8884 */
    89 static irq_code_t       dp8390_code = {
     85static irq_code_t dp8390_code = {
    9086        sizeof(dp8390_cmds) / sizeof(irq_cmd_t),
    9187        dp8390_cmds
     
    9793 *  @param[in] call The interrupt message.
    9894 */
    99 static void irq_handler(ipc_callid_t iid, ipc_call_t * call)
    100 {
    101         netif_device_t * device;
    102         dpeth_t * dep;
     95static void irq_handler(ipc_callid_t iid, ipc_call_t *call)
     96{
     97        netif_device_t *device;
     98        dpeth_t *dep;
    10399        packet_t *received;
    104100        device_id_t device_id;
    105101        int phone;
    106 
     102       
    107103        device_id = IRQ_GET_DEVICE(call);
    108104        fibril_rwlock_write_lock(&netif_globals.lock);
    109         if(find_device(device_id, &device) != EOK){
     105       
     106        if (find_device(device_id, &device) != EOK) {
    110107                fibril_rwlock_write_unlock(&netif_globals.lock);
    111108                return;
    112109        }
     110       
    113111        dep = (dpeth_t *) device->specific;
    114         if (dep->de_mode != DEM_ENABLED){
     112        if (dep->de_mode != DEM_ENABLED) {
    115113                fibril_rwlock_write_unlock(&netif_globals.lock);
    116114                return;
    117115        }
    118         assert(dep->de_flags &DEF_ENABLED);
     116       
     117        assert(dep->de_flags & DEF_ENABLED);
     118       
    119119        dep->de_int_pending = 0;
    120         dp_check_ints(dep, IPC_GET_ISR(call));
    121         if(dep->received_queue){
     120        dp_check_ints(dep);
     121       
     122        if (dep->received_queue) {
    122123                received = dep->received_queue;
    123124                phone = device->nil_phone;
     
    126127                fibril_rwlock_write_unlock(&netif_globals.lock);
    127128                nil_received_msg(phone, device_id, received, SERVICE_NONE);
    128         }else{
     129        } else
    129130                fibril_rwlock_write_unlock(&netif_globals.lock);
    130         }
    131131}
    132132
     
    136136 *  @returns The new state.
    137137 */
    138 static int change_state(netif_device_t * device, device_state_t state)
     138static int change_state(netif_device_t *device, device_state_t state)
    139139{
    140140        if (device->state != state) {
     
    150150}
    151151
    152 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     152int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
     153    ipc_call_t *answer, int *answer_count)
     154{
    153155        return ENOTSUP;
    154156}
     
    159161        eth_stat_t * de_stat;
    160162        int rc;
    161 
    162         if(! stats){
     163       
     164        if (!stats)
    163165                return EBADMEM;
    164         }
     166       
    165167        rc = find_device(device_id, &device);
    166168        if (rc != EOK)
    167169                return rc;
     170       
    168171        de_stat = &((dpeth_t *) device->specific)->de_stat;
     172       
    169173        null_device_stats(stats);
    170174        stats->receive_errors = de_stat->ets_recvErr;
     
    180184        stats->send_heartbeat_errors = de_stat->ets_CDheartbeat;
    181185        stats->send_window_errors = de_stat->ets_OWC;
    182         return EOK;
    183 }
    184 
    185 int netif_get_addr_message(device_id_t device_id, measured_string_t *address){
    186         netif_device_t * device;
    187         int rc;
    188 
    189         if(! address){
     186       
     187        return EOK;
     188}
     189
     190int netif_get_addr_message(device_id_t device_id, measured_string_t *address)
     191{
     192        netif_device_t *device;
     193        int rc;
     194       
     195        if (!address)
    190196                return EBADMEM;
    191         }
     197       
    192198        rc = find_device(device_id, &device);
    193199        if (rc != EOK)
    194200                return rc;
     201       
    195202        address->value = (char *) (&((dpeth_t *) device->specific)->de_address);
    196203        address->length = sizeof(ether_addr_t);
     
    198205}
    199206
    200 
    201 
    202 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
    203         netif_device_t * device;
    204         dpeth_t * dep;
    205         int rc;
    206 
     207int netif_probe_message(device_id_t device_id, int irq, uintptr_t io)
     208{
     209        netif_device_t *device;
     210        dpeth_t *dep;
     211        int rc;
     212       
    207213        device = (netif_device_t *) malloc(sizeof(netif_device_t));
    208         if(! device){
     214        if (!device)
    209215                return ENOMEM;
    210         }
     216       
    211217        dep = (dpeth_t *) malloc(sizeof(dpeth_t));
    212         if(! dep){
     218        if (!dep) {
    213219                free(device);
    214220                return ENOMEM;
    215221        }
     222       
    216223        bzero(device, sizeof(netif_device_t));
    217224        bzero(dep, sizeof(dpeth_t));
     
    222229        dep->de_irq = irq;
    223230        dep->de_mode = DEM_DISABLED;
     231       
    224232        //TODO address?
    225233        rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port);
     
    228236                free(device);
    229237                return rc;
    230         }       
     238        }
     239       
    231240        rc = do_probe(dep);
    232241        if (rc != EOK) {
     
    235244                return rc;
    236245        }
     246       
    237247        rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device);
    238         if (rc != EOK){
     248        if (rc != EOK) {
    239249                free(dep);
    240250                free(device);
    241251                return rc;
    242252        }
    243         return EOK;
    244 }
    245 
    246 int netif_send_message(device_id_t device_id, packet_t *packet, services_t sender){
    247         netif_device_t * device;
    248         dpeth_t * dep;
     253       
     254        return EOK;
     255}
     256
     257int netif_send_message(device_id_t device_id, packet_t *packet,
     258    services_t sender)
     259{
     260        netif_device_t *device;
     261        dpeth_t *dep;
    249262        packet_t *next;
    250263        int rc;
    251 
     264       
    252265        rc = find_device(device_id, &device);
    253266        if (rc != EOK)
    254267                return rc;
    255         if(device->state != NETIF_ACTIVE){
     268       
     269        if (device->state != NETIF_ACTIVE){
    256270                netif_pq_release(packet_get_id(packet));
    257271                return EFORWARD;
    258272        }
     273       
    259274        dep = (dpeth_t *) device->specific;
    260         // process packet queue
    261         do{
     275       
     276        /* Process packet queue */
     277        do {
    262278                next = pq_detach(packet);
    263                 if(do_pwrite(dep, packet, false) != EBUSY){
    264                         netif_pq_release(packet_get_id(packet));
    265                 }
     279               
     280                if (do_pwrite(dep, packet, false) != EBUSY)
     281                        netif_pq_release(packet_get_id(packet));\
     282               
    266283                packet = next;
    267         }while(packet);
    268         return EOK;
    269 }
    270 
    271 int netif_start_message(netif_device_t * device){
    272         dpeth_t * dep;
    273         int rc;
    274 
    275         if(device->state != NETIF_ACTIVE){
     284        } while(packet);
     285       
     286        return EOK;
     287}
     288
     289int netif_start_message(netif_device_t * device)
     290{
     291        dpeth_t *dep;
     292        int rc;
     293       
     294        if (device->state != NETIF_ACTIVE) {
    276295                dep = (dpeth_t *) device->specific;
    277296                dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR);
    278297                dp8390_cmds[2].addr = dp8390_cmds[0].addr;
     298               
    279299                rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code);
    280300                if (rc != EOK)
    281301                        return rc;
     302               
    282303                rc = do_init(dep, DL_BROAD_REQ);
    283304                if (rc != EOK) {
     
    285306                        return rc;
    286307                }
     308               
    287309                return change_state(device, NETIF_ACTIVE);
    288310        }
    289         return EOK;
    290 }
    291 
    292 int netif_stop_message(netif_device_t * device){
    293         dpeth_t * dep;
    294 
    295         if(device->state != NETIF_STOPPED){
     311       
     312        return EOK;
     313}
     314
     315int netif_stop_message(netif_device_t * device)
     316{
     317        dpeth_t *dep;
     318       
     319        if (device->state != NETIF_STOPPED) {
    296320                dep = (dpeth_t *) device->specific;
    297321                do_stop(dep);
     
    299323                return change_state(device, NETIF_STOPPED);
    300324        }
    301         return EOK;
    302 }
    303 
    304 int netif_initialize(void){
     325       
     326        return EOK;
     327}
     328
     329int netif_initialize(void)
     330{
    305331        sysarg_t phonehash;
    306 
    307332        async_set_interrupt_received(irq_handler);
    308 
    309333        return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0, 0, &phonehash);
    310334}
     
    316340 *
    317341 */
    318 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     342static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    319343{
    320344        /*
     
    324348        ipc_answer_0(iid, EOK);
    325349       
    326         while(true) {
     350        while (true) {
    327351                ipc_call_t answer;
    328352                int answer_count;
     
    348372}
    349373
    350 /** Starts the module.
     374/** Start the module.
    351375 *
    352376 *  @param argc The count of the command line arguments. Ignored parameter.
     
    359383int main(int argc, char *argv[])
    360384{
    361         int rc;
    362        
    363385        /* Start the module */
    364         rc = netif_module_start(netif_client_connection);
    365         return rc;
     386        return netif_module_start(netif_client_connection);
    366387}
    367388
Note: See TracChangeset for help on using the changeset viewer.