Annotation of kernel/bsd/dev/ppc/drvDECchip21040/DECchip21040.m, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: 
                     25: /*
                     26:  * Copyright (c) 1995-1996 NeXT Software, Inc.
                     27:  *
                     28:  * HISTORY
                     29:  *
                     30:  * 11-Dec-95   Dieter Siegmund at NeXT ([email protected])
                     31:  *             Split out 21040 and 21041 into separate personalities
                     32:  */
                     33: 
                     34: #import "DECchip21040.h"
                     35: 
                     36: //#define DEBUG
                     37: 
                     38: #import "DECchip2104xInline.h"
                     39: 
                     40: @implementation DECchip21040
                     41: 
                     42: /*
                     43:  * Public Instance Methods
                     44:  */
                     45: 
                     46: - initFromDeviceDescription:(IODeviceDescription *)devDesc
                     47: {
                     48:     IOPCIDevice *deviceDescription = (IOPCIDevice *)devDesc;
                     49:     const char  *interface;
                     50: 
                     51:     if ([super initFromDeviceDescription:devDesc] == nil) {
                     52:        return nil;
                     53:     }
                     54: 
                     55: #ifdef PERF
                     56:     perfQ = perfGetQueue(OUR_PRODUCER_NAME, &ourProducerId, 0);
                     57:     if (!perfQ)
                     58:        IOLog("%s: perfGetQueue failed\n", OUR_PRODUCER_NAME);
                     59:     else {
                     60:        IOLog("%s: perf logging enabled\n", OUR_PRODUCER_NAME);
                     61:        ev_p.len = sizeof(ev_p);
                     62:        ev_p.producerId = ourProducerId;
                     63:     }
                     64: #endif PERF
                     65: 
                     66:     [self mapMemoryRange:2 to:(vm_address_t *)&ioBase
                     67:          findSpace:YES cache:IO_CacheOff];
                     68:     
                     69:     irq = [deviceDescription interrupt];
                     70: 
                     71:     /* Select network interface */
                     72:     connector = connectorAUTO_e; /* default is auto select */
                     73:     interface = [[deviceDescription configTable] 
                     74:                        valueForStringKey: NETWORK_INTERFACE];
                     75:     if (interface != NULL) {
                     76:        int i;
                     77: 
                     78:        for (i = 0; i < NUM_CONNECTOR_TYPES; i++) {
                     79:            if (strcmp(interface, connectorType(i)) == 0) {
                     80:                connector = i;
                     81:                break;
                     82:            }
                     83:        }
                     84:     }
                     85: 
                     86:     [self getStationAddress:&myAddress];
                     87:     
                     88:     if ([self _allocateMemory] == NO) {
                     89:         [self free];
                     90:        return nil;
                     91:     }
                     92:     
                     93:     isPromiscuous = NO;
                     94:     multicastEnabled = NO;
                     95: 
                     96:     /* Inform user what we are upto here */
                     97:     IOLog("DECchip21040 based adapter at port 0x%0x irq %d", 
                     98:         ioBase, irq);
                     99:     
                    100:     if (connector != connectorAUTO_e) {
                    101:        IOLog(" interface %s", interface);
                    102:     }
                    103:     IOLog("\n");
                    104:     
                    105:     if (![self resetAndEnable:NO]) {
                    106:        [self free];
                    107:        return nil;
                    108:     }
                    109:     
                    110:     networkInterface = [super attachToNetworkWithAddress:myAddress];
                    111:     
                    112:     return self;
                    113: }
                    114: 
                    115: - (void)getStationAddress:(enet_addr_t *)ea
                    116: {
                    117:     getStationAddress(ioBase, ea);
                    118: }
                    119: 
                    120: /*
                    121:  * These are the magic values that need to be written to CSR 12, 14 and 15 to
                    122:  * enable appropriate network interfaces. These values are from the
                    123:  * respective hardware docs. 
                    124:  */
                    125: #define DEC_21040_RESET_SIA            0x0
                    126: 
                    127: #define DEC_21040_SIA0_10BT            0x00008f01
                    128: #define DEC_21040_SIA1_10BT            0x0000ffff
                    129: #define DEC_21040_SIA2_10BT            0x00000000
                    130: 
                    131: #define DEC_21040_SIA0_AUI             0x0000ef09
                    132: #define DEC_21040_SIA1_AUI             0x00000705
                    133: #define DEC_21040_SIA2_AUI             0x00000006
                    134: 
                    135: #define DEC_21040_SIA0_EXT             0x00008f09
                    136: #define DEC_21040_SIA1_EXT             0x00000705
                    137: #define DEC_21040_SIA2_EXT             0x00000006
                    138: 
                    139: - (void)_setInterface:(connector_t)netInterface
                    140: {
                    141:     writeCsr(ioBase, DEC_21X40_CSR13, DEC_21040_RESET_SIA);
                    142:     IOSleep(1);
                    143:     switch (netInterface) {
                    144:       case connectorTP_e:
                    145:        writeCsr(ioBase, DEC_21X40_CSR15, DEC_21040_SIA2_10BT);
                    146:        writeCsr(ioBase, DEC_21X40_CSR14, DEC_21040_SIA1_10BT);
                    147:        writeCsr(ioBase, DEC_21X40_CSR13, DEC_21040_SIA0_10BT);
                    148:        break;
                    149:       case connectorAUI_e:
                    150:        writeCsr(ioBase, DEC_21X40_CSR15, DEC_21040_SIA2_AUI);
                    151:        writeCsr(ioBase, DEC_21X40_CSR14, DEC_21040_SIA1_AUI);
                    152:        writeCsr(ioBase, DEC_21X40_CSR13, DEC_21040_SIA0_AUI);
                    153:        break;
                    154:       case connectorBNC_e:
                    155:        writeCsr(ioBase, DEC_21X40_CSR15, DEC_21040_SIA2_EXT);
                    156:        writeCsr(ioBase, DEC_21X40_CSR14, DEC_21040_SIA1_EXT);
                    157:        writeCsr(ioBase, DEC_21X40_CSR13, DEC_21040_SIA0_EXT);
                    158:        break;
                    159:       default:
                    160:        break;
                    161:     }
                    162:     IODelay(100);
                    163:     connector = netInterface;
                    164: }
                    165: 
                    166: - (void)selectInterface
                    167: {
                    168:     csrRegUnion reg;
                    169:     unsigned int time;
                    170:     
                    171:     /*
                    172:      * Auto-selection is done only once. 
                    173:      */
                    174:     if (connector != connectorAUTO_e) {
                    175:        [self _setInterface:connector];
                    176:        return;
                    177:     }
                    178:     
                    179:     /*
                    180:      * Try 10Base-T
                    181:      */
                    182:     [self _setInterface:connectorTP_e];
                    183:     
                    184:     /*
                    185:      * Check the SIA TP Link status
                    186:      */
                    187:     time = 1000;
                    188:     while (--time) {
                    189:        IODelay(1000);
                    190:        reg.data = readCsr(ioBase, DEC_21X40_CSR12);
                    191:        if (reg.csr12.lkf == 0) {
                    192: #ifdef DEBUG
                    193:            IOLog("%s: Using RJ-45 connector\n", [self name]);
                    194: #endif DEBUG
                    195:            return;
                    196:        }
                    197:     }
                    198:     
                    199:     /*
                    200:      * Try AUI now
                    201:      */
                    202:     [self _setInterface:connectorAUI_e];
                    203:     
                    204:     time = 1000;
                    205:     while (--time) {
                    206:        IODelay(1000);
                    207:        reg.data = readCsr(ioBase, DEC_21X40_CSR12);
                    208:        if (reg.csr12.ncr == 1) {
                    209: #ifdef DEBUG
                    210:            IOLog("%s: Using BNC connector\n", [self name]);
                    211: #endif DEBUG   
                    212:            [self _setInterface:connectorBNC_e];
                    213:            return;
                    214:        }
                    215:     }
                    216:     
                    217: #ifdef DEBUG
                    218:     IOLog("%s: Using AUI connector\n", [self name]);
                    219: #endif DEBUG   
                    220: }
                    221: 
                    222: @end
                    223: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.