Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/ne2k/dp8390.c

    r5a6cc679 ra35b458  
    7474        /** Copy of RSR */
    7575        uint8_t status;
    76        
     76
    7777        /** Pointer to next frame */
    7878        uint8_t next;
    79        
     79
    8080        /** Receive Byte Count Low */
    8181        uint8_t rbcl;
    82        
     82
    8383        /** Receive Byte Count High */
    8484        uint8_t rbch;
     
    9595{
    9696        size_t i;
    97        
     97
    9898        for (i = 0; (i << 1) < size; i++)
    9999                *((uint16_t *) buf + i) = pio_read_16((ioport16_t *) (port));
     
    110110{
    111111        size_t i;
    112        
     112
    113113        for (i = 0; (i << 1) < size; i++)
    114114                pio_write_16((ioport16_t *) port, *((uint16_t *) buf + i));
     
    118118{
    119119        size_t esize = size & ~1;
    120        
     120
    121121        pio_write_8(ne2k->port + DP_RBCR0, esize & 0xff);
    122122        pio_write_8(ne2k->port + DP_RBCR1, (esize >> 8) & 0xff);
     
    124124        pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff);
    125125        pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
    126        
     126
    127127        if (esize != 0) {
    128128                pio_read_buf_16(ne2k->data_port, buf, esize);
     
    130130                buf += esize;
    131131        }
    132        
     132
    133133        if (size) {
    134134                assert(size == 1);
    135                
     135
    136136                uint16_t word = pio_read_16(ne2k->data_port);
    137137                memcpy(buf, &word, 1);
     
    143143        size_t esize_ru = (size + 1) & ~1;
    144144        size_t esize = size & ~1;
    145        
     145
    146146        pio_write_8(ne2k->port + DP_RBCR0, esize_ru & 0xff);
    147147        pio_write_8(ne2k->port + DP_RBCR1, (esize_ru >> 8) & 0xff);
     
    149149        pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff);
    150150        pio_write_8(ne2k->port + DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
    151        
     151
    152152        if (esize != 0) {
    153153                pio_write_buf_16(ne2k->data_port, buf, esize);
     
    155155                buf += esize;
    156156        }
    157        
     157
    158158        if (size) {
    159159                assert(size == 1);
    160                
     160
    161161                uint16_t word = 0;
    162                
     162
    163163                memcpy(&word, buf, 1);
    164164                pio_write_16(ne2k->data_port, word);
     
    169169{
    170170        unsigned int i;
    171        
     171
    172172        /* Reset the ethernet card */
    173173        uint8_t val = pio_read_8(ne2k->port + NE2K_RESET);
     
    175175        pio_write_8(ne2k->port + NE2K_RESET, val);
    176176        async_usleep(2000);
    177        
     177
    178178        /* Reset the DP8390 */
    179179        pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT);
     
    197197{
    198198        unsigned int i;
    199        
     199
    200200        ne2k_init(ne2k);
    201        
     201
    202202        /* Check if the DP8390 is really there */
    203203        uint8_t val = pio_read_8(ne2k->port + DP_CR);
    204204        if ((val & (CR_STP | CR_TXP | CR_DM_ABORT)) != (CR_STP | CR_DM_ABORT))
    205205                return EXDEV;
    206        
     206
    207207        /* Disable the receiver and init TCR and DCR */
    208208        pio_write_8(ne2k->port + DP_RCR, RCR_MON);
    209209        pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL);
    210210        pio_write_8(ne2k->port + DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
    211        
     211
    212212        /* Setup a transfer to get the MAC address */
    213213        pio_write_8(ne2k->port + DP_RBCR0, ETH_ADDR << 1);
     
    216216        pio_write_8(ne2k->port + DP_RSAR1, 0);
    217217        pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
    218        
     218
    219219        for (i = 0; i < ETH_ADDR; i++)
    220220                ne2k->mac.address[i] = pio_read_16(ne2k->data_port);
    221        
     221
    222222        return EOK;
    223223}
     
    226226{
    227227        memcpy(&ne2k->mac, address, sizeof(nic_address_t));
    228        
     228
    229229        pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STP);
    230        
     230
    231231        pio_write_8(ne2k->port + DP_RBCR0, ETH_ADDR << 1);
    232232        pio_write_8(ne2k->port + DP_RBCR1, 0);
     
    254254        if (!ne2k->probed)
    255255                return EXDEV;
    256        
     256
    257257        ne2k_init(ne2k);
    258        
     258
    259259        /*
    260260         * Setup send queue. Use the first
     
    266266        fibril_mutex_initialize(&ne2k->sq_mutex);
    267267        fibril_condvar_initialize(&ne2k->sq_cv);
    268        
     268
    269269        /*
    270270         * Setup receive ring buffer. Use all the rest
     
    275275        ne2k->start_page = ne2k->sq.page + SQ_PAGES;
    276276        ne2k->stop_page = ne2k->sq.page + NE2K_SIZE / DP_PAGE;
    277        
     277
    278278        /*
    279279         * Initialization of the DP8390 following the mandatory procedure
     
    281281         * Controller", National Semiconductor, July 1995, Page 29).
    282282         */
    283        
     283
    284284        /* Step 1: */
    285285        pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
    286        
     286
    287287        /* Step 2: */
    288288        pio_write_8(ne2k->port + DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
    289        
     289
    290290        /* Step 3: */
    291291        pio_write_8(ne2k->port + DP_RBCR0, 0);
    292292        pio_write_8(ne2k->port + DP_RBCR1, 0);
    293        
     293
    294294        /* Step 4: */
    295295        pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration);
    296        
     296
    297297        /* Step 5: */
    298298        pio_write_8(ne2k->port + DP_TCR, TCR_INTERNAL);
    299        
     299
    300300        /* Step 6: */
    301301        pio_write_8(ne2k->port + DP_BNRY, ne2k->start_page);
    302302        pio_write_8(ne2k->port + DP_PSTART, ne2k->start_page);
    303303        pio_write_8(ne2k->port + DP_PSTOP, ne2k->stop_page);
    304        
     304
    305305        /* Step 7: */
    306306        pio_write_8(ne2k->port + DP_ISR, 0xff);
    307        
     307
    308308        /* Step 8: */
    309309        pio_write_8(ne2k->port + DP_IMR,
    310310            IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE | IMR_OVWE | IMR_CNTE);
    311        
     311
    312312        /* Step 9: */
    313313        pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
    314        
     314
    315315        pio_write_8(ne2k->port + DP_PAR0, ne2k->mac.address[0]);
    316316        pio_write_8(ne2k->port + DP_PAR1, ne2k->mac.address[1]);
     
    319319        pio_write_8(ne2k->port + DP_PAR4, ne2k->mac.address[4]);
    320320        pio_write_8(ne2k->port + DP_PAR5, ne2k->mac.address[5]);
    321        
     321
    322322        pio_write_8(ne2k->port + DP_MAR0, 0);
    323323        pio_write_8(ne2k->port + DP_MAR1, 0);
     
    328328        pio_write_8(ne2k->port + DP_MAR6, 0);
    329329        pio_write_8(ne2k->port + DP_MAR7, 0);
    330        
     330
    331331        pio_write_8(ne2k->port + DP_CURR, ne2k->start_page + 1);
    332        
     332
    333333        /* Step 10: */
    334334        pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STA);
    335        
     335
    336336        /* Step 11: */
    337337        pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL);
    338        
     338
    339339        /* Reset counters by reading */
    340340        pio_read_8(ne2k->port + DP_CNTR0);
    341341        pio_read_8(ne2k->port + DP_CNTR1);
    342342        pio_read_8(ne2k->port + DP_CNTR2);
    343        
     343
    344344        /* Finish the initialization */
    345345        ne2k->up = true;
     
    415415
    416416        fibril_mutex_lock(&ne2k->sq_mutex);
    417        
     417
    418418        while (ne2k->sq.dirty) {
    419419                fibril_condvar_wait(&ne2k->sq_cv, &ne2k->sq_mutex);
    420420        }
    421        
     421
    422422        if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) {
    423423                fibril_mutex_unlock(&ne2k->sq_mutex);
     
    446446        if (frame == NULL)
    447447                return NULL;
    448        
     448
    449449        memset(frame->data, 0, length);
    450450        uint8_t last = page + length / DP_PAGE;
    451        
     451
    452452        if (last >= ne2k->stop_page) {
    453453                size_t left = (ne2k->stop_page - page) * DP_PAGE
     
    481481                //TODO: isn't some locking necessary here?
    482482                uint8_t boundary = pio_read_8(ne2k->port + DP_BNRY) + 1;
    483                
     483
    484484                if (boundary == ne2k->stop_page)
    485485                        boundary = ne2k->start_page;
    486                
     486
    487487                pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_STA);
    488488                uint8_t current = pio_read_8(ne2k->port + DP_CURR);
     
    491491                        /* No more frames to process */
    492492                        break;
    493                
     493
    494494                recv_header_t header;
    495495                size_t size = sizeof(header);
    496496                size_t offset = boundary * DP_PAGE;
    497                
     497
    498498                /* Get the frame header */
    499499                pio_write_8(ne2k->port + DP_RBCR0, size & 0xff);
     
    502502                pio_write_8(ne2k->port + DP_RSAR1, (offset >> 8) & 0xff);
    503503                pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
    504                
     504
    505505                pio_read_buf_16(ne2k->data_port, (void *) &header, size);
    506506
     
    508508                    (((size_t) header.rbcl) | (((size_t) header.rbch) << 8)) - size;
    509509                uint8_t next = header.next;
    510                
     510
    511511                if ((length < ETH_MIN_PACK_SIZE)
    512512                    || (length > ETH_MAX_PACK_SIZE_TAGGED)) {
     
    535535                                break;
    536536                }
    537                
     537
    538538                /*
    539539                 * Update the boundary pointer
     
    585585                        ne2k->sq.dirty = false;
    586586                        ne2k->sq.size = 0;
    587                        
     587
    588588                        /* Signal a next frame to be sent */
    589589                        fibril_condvar_broadcast(&ne2k->sq_cv);
     
    615615                ne2k_reset(ne2k);
    616616        }
    617        
     617
    618618        /* Unmask interrupts to be processed in the next round */
    619619        pio_write_8(ne2k->port + DP_IMR,
     
    627627        else
    628628                ne2k->receive_configuration &= ~RCR_AB;
    629        
     629
    630630        pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration);
    631631}
     
    637637        else
    638638                ne2k->receive_configuration &= ~RCR_AM;
    639        
     639
    640640        pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration);
    641641}
     
    647647        else
    648648                ne2k->receive_configuration &= ~RCR_PRO;
    649        
     649
    650650        pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration);
    651651}
     
    655655        /* Select Page 1 and stop all transfers */
    656656        pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
    657        
     657
    658658        pio_write_8(ne2k->port + DP_MAR0, (uint8_t) hash);
    659659        pio_write_8(ne2k->port + DP_MAR1, (uint8_t) (hash >> 8));
     
    664664        pio_write_8(ne2k->port + DP_MAR6, (uint8_t) (hash >> 48));
    665665        pio_write_8(ne2k->port + DP_MAR7, (uint8_t) (hash >> 56));
    666        
     666
    667667        /* Select Page 0 and resume transfers */
    668668        pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STA);
Note: See TracChangeset for help on using the changeset viewer.