Changeset 43b4314 in mainline for uspace/srv/hw/netif/dp8390/dp8390.c


Ignore:
Timestamp:
2011-01-10T23:22:05Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4fc2b3b
Parents:
abe95c9
Message:

refactor NE2000 up/down operations, do not configure the card prematurelly (during probing)

File:
1 edited

Legend:

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

    rabe95c9 r43b4314  
    8181
    8282/** NE2000 retry count */
    83 #define NE2K_RETRY  100
     83#define NE2K_RETRY  0x1000
    8484
    8585/** NE2000 error messages rate limiting */
     
    186186                memcpy(&word, buf, 1);
    187187                pio_write_16(ne2k->data_port, word);
     188        }
     189}
     190
     191static void ne2k_init(ne2k_t *ne2k)
     192{
     193        unsigned int i;
     194       
     195        /* Reset the ethernet card */
     196        uint8_t val = pio_read_8(ne2k->port + NE2K_RESET);
     197        usleep(2000);
     198        pio_write_8(ne2k->port + NE2K_RESET, val);
     199        usleep(2000);
     200       
     201        /* Reset the DP8390 */
     202        pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT);
     203        for (i = 0; i < NE2K_RETRY; i++) {
     204                if (pio_read_8(ne2k->port + DP_ISR) != 0)
     205                        break;
    188206        }
    189207}
     
    210228        ne2k->up = false;
    211229       
    212         /* Reset the ethernet card */
    213         uint8_t val = pio_read_8(ne2k->port + NE2K_RESET);
    214         usleep(2000);
    215         pio_write_8(ne2k->port + NE2K_RESET, val);
    216         usleep(2000);
    217        
    218         /* Reset the DP8390 */
    219         pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT);
    220         for (i = 0; i < 0x1000; i++) {
    221                 if (pio_read_8(ne2k->port + DP_ISR) != 0)
    222                         break;
    223         }
     230        ne2k_init(ne2k);
    224231       
    225232        /* Check if the DP8390 is really there */
    226         val = pio_read_8(ne2k->port + DP_CR);
     233        uint8_t val = pio_read_8(ne2k->port + DP_CR);
    227234        if ((val & (CR_STP | CR_DM_ABORT)) != (CR_STP | CR_DM_ABORT))
    228235                return EXDEV;
     
    242249        for (i = 0; i < ETH_ADDR; i++)
    243250                ne2k->mac[i] = pio_read_16(ne2k->data_port);
     251       
     252        ne2k->probed = true;
     253        return EOK;
     254}
     255
     256/** Start the network interface.
     257 *
     258 * @param[in,out] ne2k Network interface structure.
     259 *
     260 * @return EOK on success.
     261 * @return EXDEV if the network interface is disabled.
     262 *
     263 */
     264int ne2k_up(ne2k_t *ne2k)
     265{
     266        if (!ne2k->probed)
     267                return EXDEV;
     268       
     269        ne2k_init(ne2k);
    244270       
    245271        /*
     
    329355       
    330356        /* Finish the initialization */
    331         ne2k->probed = true;
    332         return EOK;
    333 }
    334 
    335 /** Start the network interface.
    336  *
    337  * @param[in,out] ne2k Network interface structure.
    338  *
    339  * @return EOK on success.
    340  * @return EXDEV if the network interface is disabled.
    341  *
    342  */
    343 int ne2k_up(ne2k_t *ne2k)
    344 {
    345         if (!ne2k->probed)
    346                 return EXDEV;
    347        
    348         pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_STA);
    349         pio_write_8(ne2k->port + DP_RCR, RCR_AB);
    350        
    351357        ne2k->up = true;
    352358        return EOK;
     
    362368        if ((ne2k->probed) && (ne2k->up)) {
    363369                pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT);
    364                
    365                 /* Reset the ethernet card */
    366                 uint8_t val = pio_read_8(ne2k->port + NE2K_RESET);
    367                 usleep(2000);
    368                 pio_write_8(ne2k->port + NE2K_RESET, val);
    369                
     370                ne2k_init(ne2k);
    370371                ne2k->up = false;
    371372        }
     
    420421        pio_write_8(ne2k->port + DP_RBCR1, 0);
    421422       
    422         for (i = 0; i < 0x1000; i++) {
     423        for (i = 0; i < NE2K_RETRY; i++) {
    423424                if ((pio_read_8(ne2k->port + DP_ISR) & ISR_RST) != 0)
    424425                        break;
     
    430431       
    431432        /* Acknowledge the ISR_RDC (remote DMA) interrupt */
    432         for (i = 0; i < 0x1000; i++) {
     433        for (i = 0; i < NE2K_RETRY; i++) {
    433434                if ((pio_read_8(ne2k->port + DP_ISR) & ISR_RDC) != 0)
    434435                        break;
Note: See TracChangeset for help on using the changeset viewer.