Changeset d3c9b60 in mainline


Ignore:
Timestamp:
2011-01-06T14:42:39Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
506a805
Parents:
95ff5c4
Message:

cstyle & clutter removal

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

Legend:

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

    r95ff5c4 rd3c9b60  
    332332{
    333333        int dp_rcr_reg;
    334         int i;//, r;
     334        int i;
    335335       
    336336        /* General initialization */
     
    343343                        printf("%x%c", dep->de_address.ea_addr[i], i < 5 ? ':' : '\n');
    344344        }
    345 
    346         /* Initialization of the dp8390 following the mandatory procedure
     345       
     346        /*
     347         * Initialization of the dp8390 following the mandatory procedure
    347348         * in reference manual ("DP8390D/NS32490D NIC Network Interface
    348349         * Controller", National Semiconductor, July 1995, Page 29).
    349350         */
     351       
    350352        /* Step 1: */
    351353        outb_reg0(dep, DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
     354       
    352355        /* Step 2: */
    353356        if (dep->de_16bit)
     
    355358        else
    356359                outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | DCR_BMS);
     360       
    357361        /* Step 3: */
    358362        outb_reg0(dep, DP_RBCR0, 0);
    359363        outb_reg0(dep, DP_RBCR1, 0);
     364       
    360365        /* Step 4: */
    361366        dp_rcr_reg = 0;
    362         if (dep->de_flags &DEF_PROMISC)
     367       
     368        if (dep->de_flags & DEF_PROMISC)
    363369                dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
    364         if (dep->de_flags &DEF_BROAD)
     370       
     371        if (dep->de_flags & DEF_BROAD)
    365372                dp_rcr_reg |= RCR_AB;
    366         if (dep->de_flags &DEF_MULTI)
     373       
     374        if (dep->de_flags & DEF_MULTI)
    367375                dp_rcr_reg |= RCR_AM;
     376       
    368377        outb_reg0(dep, DP_RCR, dp_rcr_reg);
     378       
    369379        /* Step 5: */
    370380        outb_reg0(dep, DP_TCR, TCR_INTERNAL);
     381       
    371382        /* Step 6: */
    372383        outb_reg0(dep, DP_BNRY, dep->de_startpage);
    373384        outb_reg0(dep, DP_PSTART, dep->de_startpage);
    374385        outb_reg0(dep, DP_PSTOP, dep->de_stoppage);
     386       
    375387        /* Step 7: */
    376388        outb_reg0(dep, DP_ISR, 0xFF);
     389       
    377390        /* Step 8: */
    378391        outb_reg0(dep, DP_IMR, IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE |
    379                 IMR_OVWE | IMR_CNTE);
     392            IMR_OVWE | IMR_CNTE);
     393       
    380394        /* Step 9: */
    381395        outb_reg0(dep, DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
    382 
     396       
    383397        outb_reg1(dep, DP_PAR0, dep->de_address.ea_addr[0]);
    384398        outb_reg1(dep, DP_PAR1, dep->de_address.ea_addr[1]);
     
    387401        outb_reg1(dep, DP_PAR4, dep->de_address.ea_addr[4]);
    388402        outb_reg1(dep, DP_PAR5, dep->de_address.ea_addr[5]);
    389 
     403       
    390404        outb_reg1(dep, DP_MAR0, 0xff);
    391405        outb_reg1(dep, DP_MAR1, 0xff);
     
    396410        outb_reg1(dep, DP_MAR6, 0xff);
    397411        outb_reg1(dep, DP_MAR7, 0xff);
    398 
     412       
    399413        outb_reg1(dep, DP_CURR, dep->de_startpage + 1);
     414       
    400415        /* Step 10: */
    401416        outb_reg0(dep, DP_CR, CR_DM_ABORT | CR_STA);
     417       
    402418        /* Step 11: */
    403419        outb_reg0(dep, DP_TCR, TCR_NORMAL);
    404 
    405         inb_reg0(dep, DP_CNTR0);                /* reset counters by reading */
     420       
     421        inb_reg0(dep, DP_CNTR0);  /* Reset counters by reading */
    406422        inb_reg0(dep, DP_CNTR1);
    407423        inb_reg0(dep, DP_CNTR2);
    408 
     424       
    409425        /* Finish the initialization. */
    410426        dep->de_flags |= DEF_ENABLED;
    411         for (i= 0; i<dep->de_sendq_nr; i++)
     427        for (i = 0; i < dep->de_sendq_nr; i++)
    412428                dep->de_sendq[i].sq_filled= 0;
    413         dep->de_sendq_head= 0;
    414         dep->de_sendq_tail= 0;
    415         if (dep->de_16bit)
    416         {
     429       
     430        dep->de_sendq_head = 0;
     431        dep->de_sendq_tail = 0;
     432       
     433        if (dep->de_16bit) {
    417434                dep->de_user2nicf= dp_pio16_user2nic;
    418 //              dep->de_user2nicf_s= dp_pio16_user2nic_s;
    419435                dep->de_nic2userf= dp_pio16_nic2user;
    420 //              dep->de_nic2userf_s= dp_pio16_nic2user_s;
    421436                dep->de_getblockf= dp_pio16_getblock;
    422         }
    423         else
    424         {
     437        } else {
    425438                dep->de_user2nicf= dp_pio8_user2nic;
    426 //              dep->de_user2nicf_s= dp_pio8_user2nic_s;
    427439                dep->de_nic2userf= dp_pio8_nic2user;
    428 //              dep->de_nic2userf_s= dp_pio8_nic2user_s;
    429440                dep->de_getblockf= dp_pio8_getblock;
    430441        }
    431 
    432         /* Set the interrupt handler and policy. Do not automatically
    433          * reenable interrupts. Return the IRQ line number on interrupts.
    434          */
    435 /*      dep->de_hook = dep->de_irq;
    436         r= sys_irqsetpolicy(dep->de_irq, 0, &dep->de_hook);
    437         if (r != OK)
    438                 panic("DP8390", "sys_irqsetpolicy failed", r);
    439 
    440         r= sys_irqenable(&dep->de_hook);
    441         if (r != OK)
    442         {
    443                 panic("DP8390", "unable enable interrupts", r);
    444         }
    445 */
    446 }
    447 
    448 /*===========================================================================*
    449  *                              dp_reinit                                    *
    450  *===========================================================================*/
     442}
     443
    451444static void dp_reinit(dep)
    452445dpeth_t *dep;
  • uspace/srv/hw/netif/dp8390/dp8390.h

    r95ff5c4 rd3c9b60  
    222222struct dpeth;
    223223struct iovec_dat;
    224 //struct iovec_dat_s;
     224
    225225_PROTOTYPE(typedef void (*dp_initf_t), (struct dpeth *dep)              );
    226226_PROTOTYPE(typedef void (*dp_stopf_t), (struct dpeth *dep)              );
     
    228228                        struct iovec_dat *iovp, vir_bytes offset,
    229229                        int nic_addr, vir_bytes count) );
    230 //_PROTOTYPE(typedef void (*dp_user2nicf_s_t), (struct dpeth *dep,
    231 //                      struct iovec_dat_s *iovp, vir_bytes offset,
    232 //                      int nic_addr, vir_bytes count)                  );
    233230_PROTOTYPE(typedef void (*dp_nic2userf_t), (struct dpeth *dep,
    234231                        int nic_addr, struct iovec_dat *iovp,
    235232                        vir_bytes offset, vir_bytes count) );
    236 //_PROTOTYPE(typedef void (*dp_nic2userf_s_t), (struct dpeth *dep,
    237 //                      int nic_addr, struct iovec_dat_s *iovp,
    238 //                      vir_bytes offset, vir_bytes count)              );
    239 //#if 0
    240 //_PROTOTYPE(typedef void (*dp_getheaderf_t), (struct dpeth *dep,
    241 //                      int page, struct dp_rcvhdr *h, u16_t *eth_type) );
    242 //#endif
    243233_PROTOTYPE(typedef void (*dp_getblock_t), (struct dpeth *dep,
    244234                int page, size_t offset, size_t size, void *dst)        );
    245235
    246 /* iovectors are handled IOVEC_NR entries at a time. */
    247 //#define IOVEC_NR      16
    248 // no vectors allowed
    249 #define IOVEC_NR        1
    250 
    251 /*
    252 typedef int irq_hook_t;
    253 */
     236#define IOVEC_NR  1
     237
    254238typedef struct iovec_dat
    255239{
     
    275259/** Maximum number of waiting packets to be sent or received.
    276260 */
    277 #define MAX_PACKETS     4
     261#define MAX_PACKETS  4
    278262
    279263typedef struct dpeth
     
    282266         */
    283267        packet_t *packet_queue;
     268       
    284269        /** Outgoing packets count.
    285270         */
    286271        int packet_count;
    287 
     272       
    288273        /** Received packets queue.
    289274         */
    290275        packet_t *received_queue;
     276       
    291277        /** Received packets count.
    292278         */
     
    304290        int de_irq;
    305291        int de_int_pending;
    306 //      irq_hook_t de_hook;
    307292        dp_initf_t de_initf;
    308293        dp_stopf_t de_stopf;
    309294        char de_name[sizeof("dp8390#n")];
    310 
     295       
    311296        /* The initf function fills the following fields. Only cards that do
    312297         * programmed I/O fill in the de_pata_port field.
     
    322307        int de_startpage;
    323308        int de_stoppage;
    324 
    325         /* should be here - read even for ne2k isa init... */
    326         char de_pci;                    /* TRUE iff PCI device */
    327 
     309       
    328310        /* Do it yourself send queue */
    329         struct sendq
    330         {
     311        struct sendq {
    331312                int sq_filled;          /* this buffer contains a packet */
    332313                int sq_size;            /* with this size */
    333314                int sq_sendpage;        /* starting page of the buffer */
    334315        } de_sendq[SENDQ_NR];
     316       
    335317        int de_sendq_nr;
    336318        int de_sendq_head;              /* Enqueue at the head */
    337319        int de_sendq_tail;              /* Dequeue at the tail */
    338 
     320       
    339321        /* Fields for internal use by the dp8390 driver. */
    340322        int de_flags;
     
    342324        eth_stat_t de_stat;
    343325        iovec_dat_t de_read_iovec;
    344 //      iovec_dat_s_t de_read_iovec_s;
    345 //      int de_safecopy_read;
    346326        iovec_dat_t de_write_iovec;
    347 //      iovec_dat_s_t de_write_iovec_s;
    348327        iovec_dat_t de_tmp_iovec;
    349 //      iovec_dat_s_t de_tmp_iovec_s;
    350328        vir_bytes de_read_s;
    351329//      int de_client;
    352330//      message de_sendmsg;
    353331        dp_user2nicf_t de_user2nicf;
    354 //      dp_user2nicf_s_t de_user2nicf_s;
    355332        dp_nic2userf_t de_nic2userf;
    356 //      dp_nic2userf_s_t de_nic2userf_s;
    357333        dp_getblock_t de_getblockf;
    358334} dpeth_t;
  • uspace/srv/hw/netif/dp8390/ne2000.c

    r95ff5c4 rd3c9b60  
    7373void ne_init(struct dpeth *dep);
    7474
    75 /*===========================================================================*
    76  *                              ne_probe                                     *
    77  *===========================================================================*/
    78 int ne_probe(dep)
    79 dpeth_t *dep;
     75int ne_probe(dpeth_t *dep)
    8076{
    8177        int byte;
     
    8379        int loc1, loc2;
    8480        testf_t f;
    85 
    86         dep->de_dp8390_port= dep->de_base_port + NE_DP8390;
    87 
    88         /* We probe for an ne1000 or an ne2000 by testing whether the
     81       
     82        dep->de_dp8390_port = dep->de_base_port + NE_DP8390;
     83       
     84        /*
     85         * We probe for an ne1000 or an ne2000 by testing whether the
    8986         * on board is reachable through the dp8390. Note that the
    9087         * ne1000 is an 8bit card and has a memory region distict from
    9188         * the 16bit ne2000
    9289         */
    93 
    94         for (dep->de_16bit= 0; dep->de_16bit < 2; dep->de_16bit++)
    95         {
     90       
     91        for (dep->de_16bit = 0; dep->de_16bit < 2; dep->de_16bit++) {
    9692                /* Reset the ethernet card */
    9793                byte= inb_ne(dep, NE_RESET);
     
    9995                outb_ne(dep, NE_RESET, byte);
    10096                milli_delay(2);
    101 
     97               
    10298                /* Reset the dp8390 */
    10399                outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
    104                 for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RST) == 0); i++)
     100                for (i = 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++)
    105101                        ; /* Do nothing */
    106 
     102               
    107103                /* Check if the dp8390 is really there */
    108                 if ((inb_reg0(dep, DP_CR) &(CR_STP|CR_DM_ABORT)) !=
    109                         (CR_STP|CR_DM_ABORT))
    110                 {
     104                if ((inb_reg0(dep, DP_CR) & (CR_STP | CR_DM_ABORT)) !=
     105                    (CR_STP | CR_DM_ABORT))
    111106                        return 0;
    112                 }
    113 
     107               
    114108                /* Disable the receiver and init TCR and DCR. */
    115109                outb_reg0(dep, DP_RCR, RCR_MON);
    116110                outb_reg0(dep, DP_TCR, TCR_NORMAL);
    117                 if (dep->de_16bit)
    118                 {
     111                if (dep->de_16bit) {
    119112                        outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES |
    120                                 DCR_BMS);
    121                 }
    122                 else
    123                 {
     113                            DCR_BMS);
     114                } else {
    124115                        outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES |
    125                                 DCR_BMS);
    126                 }
    127 
    128                 if (dep->de_16bit)
    129                 {
     116                            DCR_BMS);
     117                }
     118               
     119                if (dep->de_16bit) {
    130120                        loc1= NE2000_START;
    131121                        loc2= NE2000_START + NE2000_SIZE - 4;
    132122                        f= test_16;
    133                 }
    134                 else
    135                 {
     123                } else {
    136124                        loc1= NE1000_START;
    137125                        loc2= NE1000_START + NE1000_SIZE - 4;
    138126                        f= test_8;
    139127                }
    140                 if (f(dep, loc1, pat0) && f(dep, loc1, pat1) &&
    141                         f(dep, loc1, pat2) && f(dep, loc1, pat3) &&
    142                         f(dep, loc2, pat0) && f(dep, loc2, pat1) &&
    143                         f(dep, loc2, pat2) && f(dep, loc2, pat3))
    144                 {
     128               
     129                if (f(dep, loc1, pat0) && f(dep, loc1, pat1) &&
     130                    f(dep, loc1, pat2) && f(dep, loc1, pat3) &&
     131                    f(dep, loc2, pat0) && f(dep, loc2, pat1) &&
     132                    f(dep, loc2, pat2) && f(dep, loc2, pat3)) {
    145133                        /* We don't need a memory segment */
    146                         dep->de_linmem= 0;
    147                         if (!dep->de_pci)
    148                                 dep->de_initf= ne_init;
    149                         dep->de_stopf= ne_stop;
     134                        dep->de_linmem = 0;
     135                        dep->de_initf = ne_init;
     136                        dep->de_stopf = ne_stop;
    150137                        return 1;
    151138                }
    152139        }
     140       
    153141        return 0;
    154142}
    155143
    156 /*===========================================================================*
    157  *                              ne_init                                      *
    158  *===========================================================================*/
    159 void ne_init(dep)
    160 dpeth_t *dep;
     144void ne_init(dpeth_t *dep)
    161145{
    162146        int i;
    163147        int word, sendq_nr;
    164 
     148       
    165149        /* Setup a transfer to get the ethernet address. */
    166150        if (dep->de_16bit)
     
    168152        else
    169153                outb_reg0(dep, DP_RBCR0, 6);
     154       
    170155        outb_reg0(dep, DP_RBCR1, 0);
    171156        outb_reg0(dep, DP_RSAR0, 0);
    172157        outb_reg0(dep, DP_RSAR1, 0);
    173158        outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
    174 
    175         for (i= 0; i<6; i++)
    176         {
    177                 if (dep->de_16bit)
    178                 {
    179                         word= inw_ne(dep, NE_DATA);
    180                         dep->de_address.ea_addr[i]= word;
    181                 }
    182                 else
    183                 {
     159       
     160        for (i = 0; i < 6; i++) {
     161                if (dep->de_16bit) {
     162                        word = inw_ne(dep, NE_DATA);
     163                        dep->de_address.ea_addr[i] = word;
     164                } else
    184165                        dep->de_address.ea_addr[i] = inb_ne(dep, NE_DATA);
    185                 }
    186         }
     166        }
     167       
    187168        dep->de_data_port= dep->de_base_port + NE_DATA;
    188         if (dep->de_16bit)
    189         {
     169        if (dep->de_16bit) {
    190170                dep->de_ramsize= NE2000_SIZE;
    191171                dep->de_offset_page= NE2000_START / DP_PAGESIZE;
    192         }
    193         else
    194         {
     172        } else {
    195173                dep->de_ramsize= NE1000_SIZE;
    196174                dep->de_offset_page= NE1000_START / DP_PAGESIZE;
    197175        }
    198 
     176       
    199177        /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
    200178        sendq_nr= dep->de_ramsize / 0x2000;
     179       
    201180        if (sendq_nr < 1)
    202                 sendq_nr= 1;
     181                sendq_nr = 1;
    203182        else if (sendq_nr > SENDQ_NR)
    204                 sendq_nr= SENDQ_NR;
    205         dep->de_sendq_nr= sendq_nr;
    206         for (i= 0; i<sendq_nr; i++)
    207         {
    208                 dep->de_sendq[i].sq_sendpage= dep->de_offset_page +
    209                         i*SENDQ_PAGES; 
    210         }
    211 
    212         dep->de_startpage= dep->de_offset_page + i*SENDQ_PAGES;
    213         dep->de_stoppage= dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
    214 
     183                sendq_nr = SENDQ_NR;
     184       
     185        dep->de_sendq_nr = sendq_nr;
     186        for (i = 0; i < sendq_nr; i++)
     187                dep->de_sendq[i].sq_sendpage= dep->de_offset_page + i * SENDQ_PAGES;
     188       
     189        dep->de_startpage = dep->de_offset_page + i * SENDQ_PAGES;
     190        dep->de_stoppage = dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
     191       
    215192        /* Can't override the default IRQ. */
    216193        dep->de_irq &= ~DEI_DEFAULT;
    217 
     194       
    218195        if (!debug)
    219196        {
Note: See TracChangeset for help on using the changeset viewer.