Page 3 - Contents; About This Manual
Contents About This Manual 1 Network Device Driver Environment 1.1 Include Files Section for a Network Driver . . . . . . . . . . . . . . . . . . . . . . . 1–3 1.2 Declarations Section for a Network Driver . . . . . . . . . . . . . . . . . . . . . . . 1–4 1.2.1 External and Forward Declarations . . ...
Page 4 - Saving the controller and softc Data Structure Pointers . .
3.6 Defining the Interrupt Handler ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3–6 3.7 Defining CSR Pointer Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3–6 3.8 Defining FIFO Maintenance Information . . . . . . . . . . . . . . . . . . . . . ....
Page 5 - Implementing the Autoconfiguration Support Section (attach); Initializing the Media Address and Media Header Lengths . . .; Implementing the unattach Routine
5.3.5 Entering the Packet Transmit Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–20 5.3.6 Saving Counters Prior to the Transmit Operation . . . . . . . . . . 5–21 5.3.7 Allocating Memory for a Test Packet . . . . . . . . . . . . . . . . . . . . . . . . . . 5–21 5.3.8 Using the Default...
Page 7 - Using Currently Set Flags (SIOCSIFFLAGS ioctl Command)
9.2.3 Transmitting the Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9–6 9.2.4 Accounting for Outgoing Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9–7 9.2.5 Updating Counters, Freeing the Transmit Buffer, andMarking the Output Pr...
Page 8 - Implementing the Interrupt Section; Processing Completed Receive and Transmit Operations .; Network Device Driver Configuration
12.15 Resetting the Device (SIOCIFRESET ioctl Command) . . . . . . . . . 12–11 12.16 Setting Device Characteristics (SIOCIFSETCHAR ioctlCommand) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12–11 12.17 Releasing the Simple ...
Page 9 - Tables
2–4 Window 4 Diagnostic Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2–11 3–1 Typical softc Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3–2 3–2 Mapping Alternate Names . . . . . . . . . . . . . . . . . . . . . ...
Page 11 - Audience
About This Manual This manual discusses how to write network device drivers for computersystems that run the Compaq Tru64™ UNIX operating system. Audience This manual is intended for systems engineers who: • Use standard library routines to develop programs in the C language • Know the Bourne shell ...
Page 12 - Scope of this Manual; ifnet
• Socket and XTI programming examples • TCP specific programming information • Information for Token Ring driver developers • Data link interface See the Tru64 UNIX Network Programmer ’s Guide for descriptions of thesetopics. Scope of this Manual This manual builds on the concepts and topics that ar...
Page 14 - Related Documentation; Examples; The directory; Manuals
Chapter 8 Describes how to implement an init interface and associated routines, usingthe if_el device driver ’s el_init( ) routine as an example. Chapter 9 Describes how to implement a start interface and associated routines, usingthe if_el device driver ’s el_start( ) routine as an example. Chapter...
Page 15 - Reference Pages; Reader’s Comments; You can send your comments in the following ways:
• Writing Device Drivers contains information that you need to developdevice drivers on the Compaq Tru64 UNIX operating system. • Writing Kernel Modules describes topics for all kernel modulessuch as kernel threads and writing kernel modules in a symmetricmultiprocessing (SMP) environment. • Writing...
Page 16 - Conventions; This manual uses the following conventions:
• Internet electronic mail: [email protected] A Reader ’s Comment form is located on your system in the followinglocation: /usr/doc/readers_comment.txt Please include the following information along with your comments: • The full title of the book and the order number. (The order number is...
Page 19 - Network Device Driver Environment; Network Device Driver Environment 1–1
1 Network Device Driver Environment A network device is responsible for both transmitting and receiving framesover the network media. Network devices have network device driversassociated with them. A network device driver attaches a network subsystemto a network interface, prepares the network inte...
Page 20 - Figure 1–1: Sections of a Network Device Driver; N e t wo r k D ev i c e D r i v e r; data structure. This means that a network; –2 Network Device Driver Environment
Figure 1–1: Sections of a Network Device Driver /* Include Files Section */ /* Configure Section */ /* Autoconfiguration Support Section */ /* Start Transmit Section */ N e t wo r k D ev i c e D r i v e r /* Declarations Section */ /* Initialization Section */ /* Ioctl Section */ /* Interrupt Sectio...
Page 21 - Include Files Section for a Network Driver; Network Device Driver Environment 1–3
Instead of registering its entry points in a dsent data structure, a network driver registers its entry points with the upper layers of the Tru64 UNIXoperating system in an ifnet data structure. For example, a network driver registers entry points for queueing data for transmission and for startingd...
Page 22 - ioctl; Declarations Section for a Network Driver; –4 Network Device Driver Environment
#include <netinet/ip.h> #include <netinet/ip_var.h>#include <netinet/if_ether.h> 3 #include <net/ether_driver.h> #include <io/common/devdriver.h> 4 #include <hal/cpuconf.h> #include <kern/thread.h> #include <kern/sched_prim.h> #include <kern/lock.h&...
Page 23 - Network Device Driver Environment 1–5
• External and forward declarations (Section 1.2.1) • Declaration of softc and controller data structure arrays (Section 1.2.2) • Declaration of the driver data structure (Section 1.2.3) • Definitions of driver-specific macros (Section 1.2.4) The following sections discuss each of these categories o...
Page 24 - Declaring softc and controller Data Structure Arrays; controller; –6 Network Device Driver Environment
4 Declares a pointer to the external task_t data structure called first_task . The task_t data structure is an opaque data structure; that is, all of its associated members are referenced and manipulated bythe Tru64 UNIX operating system and not by the user of kernel threads.Every kernel thread must...
Page 25 - Declaring and Initializing the driver Data Structure; Network Device Driver Environment 1–7
1.2.3 Declaring and Initializing the driver Data Structure The following code shows how the if_el device driver declares and initializes the driver data structure with the names of its entry points: static struct driver eldriver = { 1 el_probe, 0,el_attach, 0, 0, 0, 0, 0, "el", el_info,0, 0,...
Page 26 - –8 Network Device Driver Environment
READ_BUS_D8 Reads a byte (8 bits) from a device register. READ_BUS_D16 Reads a word (16 bits) from a device register. READ_BUS_D32 Reads a longword (32 bits) from a device register. READ_BUS_D64 Reads a quadword (64 bits) from a device register. WRITE_BUS_D8 Writes a byte (8 bits) to a device regist...
Page 27 - val; Macro
The second argument to the WRITE_CCR and the other write macros specifies the data to be written to the device register in bus addressspace. These write macros construct the second argument by referencingthe val variable. For the if_el driver, this data is typically one of the device register offset...
Page 28 - Configure Section for a Network Driver; –10 Network Device Driver Environment
Table 1–1: Driver-Specific Macros (cont.) Macro Description READ_RXS Read from the 3Com 3C5x9 device’s receive statusregister. READ_FDP Read from the 3Com 3C5x9 device’s FIFO diagnosticport register. 1.3 Configure Section for a Network Driver The configure section for a network device driver contain...
Page 29 - Network Device Driver Environment 1–11
1.7 Watchdog Section for a Network Driver The watchdog section for a network device driver contains a watchdog interface, which attempts to restart the adapter. The watchdog interface is optional in a network device driver. If the network device driver implementsit, watchdog is called by a kernel th...
Page 30 - –12 Network Device Driver Environment
interface to transmit the data. All network drivers must set the outputmember of the ifnet data structure to ether_output . 1–12 Network Device Driver Environment
Page 31 - Defining Device Register Offsets; Interrupt and Status Register Offset Definitions; Defining Device Register Offsets 2–1
2 Defining Device Register Offsets The device register header file defines the device register offsets for thedevice. The if_elreg.h file is the device register header file for the if_el device driver. It defines the device register offsets for the 3Com 3C5x9 seriesEthernet adapter. Specifically, th...
Page 32 - Command Port Register Offset Definitions; –2 Defining Device Register Offsets
2 Defines the interrupt latch bit position. 3 Defines the adapter failure bit position. 4 Defines the transmit complete bit position. 5 Defines the transmit available bit position. 6 Defines the receive complete bit position. 7 Defines the receive early bit position. 8 Defines the interrupt request ...
Page 33 - Defining Device Register Offsets 2–3
#define CMD_POWERUP (0x1b<<11) 31 #define CMD_POWERDOWN (0x1c<<11) 32 #define CMD_POWERAUTO (0x1d<<11) 33 1 Defines the offset for the I/O port of the command port register. 2 Defines the reset command bit position. 3 Defines the window selector for commands that are used to set up...
Page 34 - Window 0 Configuration Register Offset Definitions; –4 Defining Device Register Offsets
23 Defines an enumerated data type called rx_filter . The if_el device driver can assign one of the following values to CMD_FILTER : RF_IND Individual address RF_GRP Group address RF_BRD Broadcast address RF_PRM Promiscuous address 24 Defines the receive (RX) early threshold command. 25 Defines the ...
Page 35 - Figure 2–1: Window 0 Configuration Registers; Register; Defining Device Register Offsets 2–5
Figure 2–1: Window 0 Configuration Registers Register Manufacturer ID Register ZK-1267U-AI Constant W0_MID Adapter ID Register W0_AID Configuration Control Register W0_CCR Address Control Register W0_ACR Resource Configuration Register W0_RCR EEPROM Command Register W0_ECR EEPROM Data Register W0_ED...
Page 36 - –6 Defining Device Register Offsets
ECR_WRITE=0x0040, ECR_ERASE=0x00c0,ECR_EWENA=0x0030, ECR_EWDIS=0x0000, ECR_EAR= 0x0020, ECR_WAR= 0x0010 }; #define W0_EDR 0xc 11 1 Defines the offset for the manufacturer ID register. 2 Defines the offset for the adapter ID register. 3 Defines the offset for the configuration control register. 4 Def...
Page 37 - Window 3 Configuration Register Offset Definitions; Defining Device Register Offsets 2–7
8 Defines an enumerated data type called w0_rcr . The if_el device driver can assign one of the following bits to W0_RCR (the resource configuration register): RCR_IRQ Represents the interrupt request (IRQ). RCR_RSV Represents a reserved field. 9 Defines the offset for the EEPROM command register. 1...
Page 38 - Figure 2–2: Window 3 Configuration Registers; –8 Defining Device Register Offsets
Figure 2–2: Window 3 Configuration Registers Register Additional Setup Information2 Register ZK-1268U-AI Constant W3_ASI2 Additional Setup Information0 Register W3_ASI0 The following code shows the offset definitions for the registers that areassociated with the window 3 configuration registers: #de...
Page 39 - Window 1 Operational Register Offset Definitions; Figure 2–3: Window 1 Operational Registers; Receive Status Register; Constant; Transmit Status Register
ASI_RSIZE8 Indicates a RAM size of 8 kilobytes (the default). ASI_RSIZE32 Indicates a RAM size of 32 kilobytes. 2.5 Window 1 Operational Register Offset Definitions The window 1 operational registers include such registers as the receivestatus, the transmit status, and the request interrupt register...
Page 40 - –10 Defining Device Register Offsets
}; #define TX_INT 0x8000 5 #define W1_RXDATA 0x0 6 #define W1_TXDATA 0x0 7 #define W1_FREETX 0xc 8 1 Defines the offset for the receive status register. 2 Defines an enumerated data type called w1_rxstat . The if_el device driver can assign one of the following values to W1_RXSTAT (the receive statu...
Page 41 - Defines the offset for the free transmit bytes register.; Window 4 Diagnostic Register Offset Definitions; Figure 2–4: Window 4 Diagnostic Registers; Media Type and Status Register; Defining Device Register Offsets 2–11
8 Defines the offset for the free transmit bytes register. 2.6 Window 4 Diagnostic Register Offset Definitions The window 4 operational registers include such registers as the media typeand status register and the network diagnostic port register, as shown inFigure 2–4. Figure 2–4: Window 4 Diagnost...
Page 42 - –12 Defining Device Register Offsets
2 Defines an enumerated data type called w4_media . The if_el device driver can assign one of the following values to W4_MEDIA (the media type and status register): MD_TPE Indicates that 10BaseT cable is enabled. MD_COAXE Indicates that 10Base2 cable is enabled. MD_RES1 Reserved. MD_SQE Indicates th...
Page 43 - EEPROM Data Structure Definition; The following code shows the definition for the; Defines an EEPROM data structure called; Defining Device Register Offsets 2–13
2.7 EEPROM Data Structure Definition The following code shows the definition for the w3_eeprom data structure. This data structure stores information about the 3Com 3C5x9 device. struct w3_eeprom { 1 unsigned short addr[3];unsigned short pid; unsigned short mandata[3]; unsigned short mid; unsigned s...
Page 45 - Defining the softc Data Structure; All network device drivers define a; Defining the softc Data Structure 3–1
3 Defining the softc Data Structure All network device drivers define a softc data structure to contain the software context of the network device driver and to allow the driverinterfaces to share information. A softc data structure contains the following information: • Common information (Section 3...
Page 46 - Figure 3–1: Typical softc Data Structure; Defining Common Information; –2 Defining the softc Data Structure
Figure 3–1: Typical softc Data Structure Common Information Media State Information Enhanced Hardware Management Information Base Register Multicast Table Information Interrupt Handler ID CSR Pointer Information FIFO Maintenance Information Bus-Specific Information Broadcast Flag Debug Flag Autosens...
Page 47 - Defining the softc Data Structure 3–3
#define is_ac is_ed->ess_ac 2 #define ztime is_ed->ess_ztime 3 #define ctrblk is_ed->ess_ctrblk 4 #define is_if is_ac.ac_if 5 #define is_addr is_ac.ac_enaddr 6 1 Declares an instance of the ether_driver data structure and calls it is_ed . All network drivers must have an ether_driver data s...
Page 48 - Figure 3–2: Mapping Alternate Names; Enabling Support for Enhanced Hardware Management; ehm; Defining Media State Information; –4 Defining the softc Data Structure
Figure 3–2: Mapping Alternate Names ZK-1274U-AI #define is_ac ess_ac #define ztime #define is_if #define ac_enaddr #define ctrblk #define is_addr . . . . . . . . . ess_ztime ess_ctrblk . . . ac_if ac_hwaddr ether_driver arpcom 3.2 Enabling Support for Enhanced Hardware Management Enhanced hardware m...
Page 49 - probe; Defining the softc Data Structure 3–5
lan_media_mode usually reflects how the media is to be selected. (In contrast, the value that is stored in the lan_media member reflects the current setting of the device.) Typically, you set this member in thedriver ’s probe interface to the media mode constant that identifies the mode for the medi...
Page 50 - –6 Defining the softc Data Structure
member in the driver ’s probe interface to the media state constant that identifies the state for the media. You can set the lan_media member to the same constants that are listed for the lan_media_mode member in item 2. 3.4 Defining the Base Register The base register in a network driver ’s softc d...
Page 51 - Defining FIFO Maintenance Information; Defining the softc Data Structure 3–7
access a CSR directly. The driver-specific macros handle the read and writeoperations that are made on these device registers. The following code shows the declarations of the CSR addresses in the if_el device driver ’s el_softc data structure. Make sure that the CSR pointer information part of your...
Page 52 - cinfop; Defining the Broadcast Flag; Defining the Debug Flag; Defining Interrupt and Timeout Statistics; –8 Defining the softc Data Structure
2 Contains the I/O base address. 3 Contains a tag value that identifies 3Com 3C5x9 devices on an ISA bus. 4 Contains a value that indicates whether the user has ejected thePCMCIA card. 5 Contains a value that indicates whether the user has reloaded thePCMCIA card. 6 Contains a value that indicates w...
Page 53 - Defining the softc Data Structure 3–9
The following code shows the declarations of the timeout and interruptinformation in the if_el device driver ’s el_softc data structure: unsigned long txreset; 1 unsigned long xmit_tmo; 2 unsigned long tint; 3 unsigned long rint; 4 1 Contains the number of transmitter error resets. 2 Contains the nu...
Page 54 - Defining a Copy of the w3_eeprom Data Structure; Declaring the Simple Lock Data Structure; –10 Defining the softc Data Structure
3.15 Defining a Copy of the w3_eeprom Data Structure The w3_eeprom data structure copy in the if_el driver ’s el_softc data structure consists of information about the hardware-specific w3_eeprom data structure. The following code shows the declaration of this device-specific data structure. If your...
Page 55 - Implementing the Configure Section; Declaring Configure-Related Variables and the; Implementing the Configure Section 4–1
4 Implementing the Configure Section The configure section of a network device driver contains the codethat incorporates the device driver into the kernel, either statically ordynamically. In a static configuration, the device driver ’s configure interface registers callback routines, which allow th...
Page 56 - –2 Implementing the Configure Section
The following code shows the declaration of the variables and theinitialization of the cfg_subsys_attr_t data structure for the if_el device driver: static unsigned char el_pcmcia_optiondata[400] = ""; 1 static unsigned char el_isa_optiondata[300] = ""; 2 static unsigned char el_unus...
Page 57 - Implementing the Configure Section 4–3
6 Declares the lan_config_data structure, which contains all information specific to the el driver. The lan_configure common code uses this structure. 7 Declares an array of cfg_subsys_attr_t data structures and calls it el_attributes . 8 Describes the PCMCIA_Option attribute, which specifies the op...
Page 58 - –4 Implementing the Configure Section
represents a variety of information, including the if_el driver ’s interrupt polling requirements. 3 Declares an argument called indatalen to store the size of this input data structure. This argument represents the number of cfg_attr_t data structures included in indata . 4 Declares an argument for...
Page 59 - Implementing the Autoconfiguration; Implementing the Autoconfiguration Support Section (probe) 5–1
5 Implementing the Autoconfiguration Support Section (probe) The autoconfiguration support section contains the code that implements anetwork device driver ’s probe interface. A network device driver ’s probe interface determines whether the network device exists and is functional ona given system. ...
Page 60 - –2 Implementing the Autoconfiguration Support Section (probe)
• For subsequent probe operations, reads the EEPROM to determine if thehardware address (and thus the adapter) has changed (Section 5.1.10) • Registers the interrupt handler (Section 5.1.11) • Saves the controller and softc data structure pointers (Section 5.1.12) • Tries to allocate another control...
Page 61 - Implementing the Autoconfiguration Support Section (probe) 5–3
contained in the ctlr_num member of the controller data structure for this 3Com 3C5x9 device. 5 Declares a handler_intr_info data structure called el_intr_info . The handler_intr_info data structure is a generic data structure that contains interrupt handler information for buses that are connectedt...
Page 62 - unit; –4 Implementing the Autoconfiguration Support Section (probe)
5.1.2 Checking the Maximum Number of Devices That the Driver Supports The following code shows how to check for the maximum number of devicesthat the if_el device driver supports: if (unit >= el_MAXDEV) { 1 printf("el%d: el_probe: unit exceeds max supported devices\n", unit); return(0); 2...
Page 63 - Implementing the Autoconfiguration Support Section (probe) 5–5
case BUS_ISA: 8 if (get_config(ctlr, RES_PORT, NULL, &port_sel, 0) >= 0) { 9 reg = port_sel.base_address; 10 } else { 11 printf("el%d: Can’t get assigned IOBASE\n",unit); return(0); } if (get_config(ctlr, RES_IRQ, NULL, &irq_sel, 0) < 0) { 12 printf("el%d: Can’t get assigne...
Page 64 - reg; Allocating Memory for the softc Data Structure; –6 Implementing the Autoconfiguration Support Section (probe)
6 Calls the READ_BUS_D16 macro a second time to determine whether the EtherLink III is attached. If the data returned by READ_BUS_D16 is not 0x6d50, calls the printf( ) routine to display an appropriate message on the console terminal. 7 Returns the value 0 (zero) to indicate that the probe operatio...
Page 65 - Implementing the Autoconfiguration Support Section (probe) 5–7
if (el_softc[unit]) { 1 sc = el_softc[unit];sc->cardout = 0; sc->reprobe = 1; } else { 2 MALLOC(sc, void*, sizeof(struct el_softc), M_DEVBUF, M_WAIT | M_ZERO); if (!sc) { 3 printf("el%d: el_probe: failed to get buffer memory for softc\n", unit); return(0); 4 } 1 If the user removed and...
Page 66 - –8 Implementing the Autoconfiguration Support Section (probe)
2 Initializes all Ethernet statistics counters in the ether_driver data structure to 0 (zero). 5.1.6 Initializing the Enhanced Hardware Management Data Structure The following code shows how the el_probe( ) routine initializes the data structure for enhanced hardware management (EHM) support: lan_eh...
Page 67 - bus; Implementing the Autoconfiguration Support Section (probe) 5–9
sc->irq = 3; 3 sc->iobase = 0; 4 sc->ispcmcia = 1; 5 sc->cinfop =card_infop; pcmcia_register_event_callback(card_infop->socket_vnum, 6 CARD_REMOVAL_EVENT, (caddr_t)el_card_remove,(caddr_t)sc); if (multi_func_flag) 7 lan_set_attribute(sc->ehm.current_val, NET_MODEL_NDX, "3C562...
Page 68 - –10 Implementing the Autoconfiguration Support Section (probe)
5.1.9 Handling First-Time Probe Operations If the device has not already been probed, the el_probe( ) routine performs the following tasks: • Reads the EEPROM and saves it to a temporary data structure • Reads and saves the device’s physical address • Starts the autosense thread to determine the med...
Page 69 - Implementing the Autoconfiguration Support Section (probe) 5–11
for (i=0; i<(sizeof(struct w3_eeprom)/2); i++) { WRITE_ECR(sc, ECR_READ+i);DELAY(1000); *ed = READ_EDR(sc); ed++; } } for (i=0; i<3; i++) { 4 j = sc->eeprom.addr[i]; sc->is_addr[(i*2)] = (j>>8) & 0xff; sc->is_addr[(i*2)+1] = (j) & 0xff; } sc->lm_media_mode = LAN_MODE_...
Page 70 - 0 Handling Subsequent Probe Operations; –12 Implementing the Autoconfiguration Support Section (probe)
8 Calls the kernel_thread_w_arg( ) routine to create and start a kernel thread with timeshare scheduling. A kernel thread that iscreated with timeshare scheduling means that its priority degrades if itconsumes an inordinate amount of CPU resources. Make sure that yourdevice driver calls kernel_threa...
Page 71 - Implementing the Autoconfiguration Support Section (probe) 5–13
if (status == SUCCESS) { ee = (unsigned char *)&ee_copy;for (i = 0; i < (sizeof(struct w3_eeprom)); i++) { *ee = tuple_data_infop->TupleData[i]; ee++; } } else { printf("el%d: Can’t read multifunction card’s eeprom.\n", unit); if (sc->ispcmcia) pcmcia_unregister_event_callback(c...
Page 72 - –14 Implementing the Autoconfiguration Support Section (probe)
bcopy(&ee_copy, &sc->eeprom, sizeof(struct w3_eeprom)); 11 } } 1 If this is a multifunction card, reads the EEPROM data and savesit in a temporary data structure, ee_copy . If this is a 3Com 3C562 multifunction PC card, the EEPROM data is located in the cardinformation data structure. 2 I...
Page 73 - Implementing the Autoconfiguration Support Section (probe) 5–15
registration of interrupt handlers. All network device drivers are required toregister interrupt handlers. el_intr_info.configuration_st = (caddr_t)ctlr; 1 el_intr_info.intr = el_intr; 2 el_intr_info.param = (caddr_t)unit; 3 el_intr_info.config_type = CONTROLLER_CONFIG_TYPE; 4 if (ctlr->bus_hd-&g...
Page 74 - –16 Implementing the Autoconfiguration Support Section (probe)
This routine returns an opaque ihandler_id_t key, which is a unique number that identifies the interrupt handler to be actedon by subsequent calls to handler_del , handler_disable , and handler_enable . The hid member of the el_softc data structure stores this key. 9 If the return value from handler...
Page 75 - Implementing the Autoconfiguration Support Section (probe) 5–17
5.1.14 Registering the shutdown Routine The following code shows how the el_probe( ) routine registers its shutdown( ) routine. The kernel calls this routine when the system shuts down. The driver can specify an argument for the kernel to pass to theroutine at that time. if (!sc->reprobe) drvr_re...
Page 76 - –18 Implementing the Autoconfiguration Support Section (probe)
To determine the mode, el_autosense_thread( ) tries to send a test data packet in each of the possible modes. When it successfully transmits the datapacket, it sets the network interface to that mode. The lm_media_mode , lm_media , and lm_media_state members of the el_softc data structure keep track...
Page 77 - Implementing the Autoconfiguration Support Section (probe) 5–19
• Determines whether packets were transmitted successfully(Section 5.3.14) • Prints debug information (Section 5.3.15) • Sets up new media to try if transmit was unsuccessful (Section 5.3.16) • Establishes media if transmit was successful (Section 5.3.17) 5.3.1 Setting Up the el_autosense_thread Rou...
Page 78 - –20 Implementing the Autoconfiguration Support Section (probe)
5.3.3 Testing for the Termination Flag The following code shows how the el_autosense_thread( ) routine tests for the termination flag: while (thread_should_halt(sc->autosense_thread)) { 1 printf("el%d: Autosense thread exiting\n", ifp->if_unit); thread_halt_self(); 2 } 1 Performs an in...
Page 79 - Implementing the Autoconfiguration Support Section (probe) 5–21
simple_unlock(&sc->el_softc_lock); splx(s);thread_halt_self(); } 1 Enters a loop for transmitting a packet and determining if it succeeds.A packet must go out twice successfully for media selection to succeed.This algorithm probably will not work in all cases. 5.3.6 Saving Counters Prior to t...
Page 80 - mbuf; –22 Implementing the Autoconfiguration Support Section (probe)
ifp->if_unit, lan_media_strings_10[sc->lm_media]); good_xmits = 100; 1 Uses the default from ROM. 5.3.9 Setting the Media in the Hardware The following code shows how the el_autosense_thread( ) routine sets the media setting in the hardware: el_reset(ifp->if_unit); 1 break; 2 } else { 1 Dir...
Page 81 - 2 Setting a Timer for the Current Kernel Thread; Implementing the Autoconfiguration Support Section (probe) 5–23
5.3.12 Setting a Timer for the Current Kernel Thread The following code shows how the el_autosense_thread( ) routine sets a timer for the current kernel thread: wait = 0; while ((prev_tint == sc->tint) && 1 (prev_tmo == sc->xmit_tmo) && (wait++ < 4)) { assert_wait((vm_offset...
Page 82 - –24 Implementing the Autoconfiguration Support Section (probe)
WRITE_CMD(sc, CMD_WINDOW1); simple_unlock(&sc->el_softc_lock);splx(s); break; default: break; } 1 Tests for loss of carrier errors. Most network adapters give carriererrors if no cable is plugged in or if transceivers are not present. 5.3.14 Determining Whether Packets Were Transmitted Succes...
Page 83 - Implementing the Autoconfiguration Support Section (probe) 5–25
if (sc->lm_media_mode == LAN_MODE_AUTOSENSE) sc->lm_media = LAN_MEDIA_UTP; break; case LAN_MEDIA_BNC: if (sc->lm_media_mode == LAN_MODE_AUTOSENSE) sc->lm_media = LAN_MEDIA_AUI; break; case LAN_MEDIA_UTP: default: if (sc->lm_media_mode == LAN_MODE_AUTOSENSE) sc->lm_media = LAN_MEDIA...
Page 84 - –26 Implementing the Autoconfiguration Support Section (probe)
Because simple locks are spin locks, simple_lock( ) does not return until the lock has been obtained. The el_softc_lock member of the el_softc data structure points to a simple lock data structure. The if_el device driver declares this data structure by calling the decl_simple_lock_data( ) routine. ...
Page 85 - attach; Implementing the Autoconfiguration Support Section (attach) 6–1
6 Implementing the Autoconfiguration Support Section (attach) The autoconfiguration support section implements a network device driver ’s attach interface. A network device driver ’s attach interface establishes communication with the device. The interface initializes the pointer to the ifnet data s...
Page 86 - –2 Implementing the Autoconfiguration Support Section (attach)
of the controller. The bus configuration code passes this initialized controller data structure to the driver ’s probe and attach interfaces. 2 Declares a unit variable and initializes it to the controller number for this controller. This controller number identifies the specific 3Com3C5x9 controlle...
Page 87 - Setting Up the Media; Implementing the Autoconfiguration Support Section (attach) 6–3
header length is the size of the ether_header data structure plus 8 (the size of the maximum LLC header). The media headers are represented by the following data structures: ether_header The media header structure for Ethernet-relatedmedia. The if_ether.h file defines the ether_header structure. fdd...
Page 88 - –4 Implementing the Autoconfiguration Support Section (attach)
3 Sets the if_mtu member of the ifnet data structure for this device to the maximum transmission unit, which for Ethernet-related media isrepresented by the constant ETHERMTU . The following media-specific constants represent the maximumtransmission unit: ETHERMTU The maximum transmission unit forEt...
Page 89 - Initializing Simple Lock Information; Implementing the Autoconfiguration Support Section (attach) 6–5
8 Sets the sin_family member of the sockaddr_in data structure to the address family, which in this case is represented by the constant AF_INET . The socket.h file defines this and other address family constants. 6.4 Initializing Simple Lock Information The following code shows how the el_attach( ) ...
Page 90 - –6 Implementing the Autoconfiguration Support Section (attach)
6.5 Printing a Success Message The following code shows how the el_attach( ) routine prints a success message: printf("el%d: %s, hardware address: %s\n", unit, ifp->if_version, ether_sprintf(sc->is_addr)); 1 1 Calls the printf( ) routine to display the following information message on ...
Page 91 - Implementing the Autoconfiguration Support Section (attach) 6–7
3 Sets the if_start member of the ifnet data structure for this device to el_start , which is the if_el device driver ’s start transmit for output interface. 4 Sets the if_output member of the ifnet data structure for this device to ether_output , which is the if_el device driver ’s output interface...
Page 92 - Setting the Baud Rate; Attaching to the Packet Filter and the Network Layer; –8 Implementing the Autoconfiguration Support Section (attach)
8 Sets the if_version member of the ifnet data structure for this device to the string 3Com EtherLink III . 6.7 Setting the Baud Rate The following code shows how the el_attach( ) routine sets the baud rate: ifp->if_baudrate = ETHER_BANDWIDTH_10MB; 1 1 Sets the if_baudrate member of the ifnet dat...
Page 93 - Implementing the Autoconfiguration Support Section (attach) 6–9
2 Calls the if_attach( ) routine to attach an interface to the list of active interfaces. The argument to the if_attach( ) routine is a pointer to the ifnet data structure for with this device. 3 If the probe and attach operations were successful, increments the number of successfully configured el ...
Page 94 - Enabling the Interrupt Handler; hid; Starting the Polling Process; –10 Implementing the Autoconfiguration Support Section (attach)
6.11 Enabling the Interrupt Handler The following code shows how the el_attach( ) routine enables the interrupt handler: handler_enable(sc->hid); 1 1 Calls the handler_enable( ) routine to enable a previously registered interrupt handler. The el_probe( ) routine calls handler_add to register the ...
Page 95 - Note; autosense; Implementing the unattach Routine 7–1
7 Implementing the unattach Routine The el_unattach( ) routine is called to stop the device and to free memory and other resources prior to unloading the driver or powering off the busto which the device is attached. The el_unattach( ) routine undoes everything that was performed by the el_probe( ) ...
Page 96 - Verifying That the Interface Has Shut Down; –2 Implementing the unattach Routine
struct el_softc *sc = el_softc[unit]; struct ifnet *ifp = &sc->is_if; 1 Declares as an argument a pointer to a bus data structure and a controller data structure for this controller. The controller data structure contains such information as the controller type, the controllername, and the cu...
Page 97 - Implementing the unattach Routine 7–3
s variable. This value represents the CPU priority level that existed before the call to splimp( ) . 2 Calls the simple_lock( ) routine to assert a lock with exclusive access for the resource that is associated with the el_softc_lock data structure. This means that no other kernel thread can gain ac...
Page 98 - Terminating the Simple Lock; –4 Implementing the unattach Routine
7.6 Unregistering the PCMCIA Event Callback Routine The following code shows how the el_unattach( ) routine unregisters the PCMCIA event callback routine: if (sc->ispcmcia) 1 pcmcia_unregister_event_callback(sc->cinfop->socket_vnum, CARD_REMOVAL_EVENT,(caddr_t)el_card_remove); 1 For PCMCIA ...
Page 99 - unattach; Implementing the unattach Routine 7–5
7.10 Unregistering the Card from the Hardware Management Database The following code shows how the el_unattach( ) routine unregisters the card from the hardware management database: lan_ehm_free(&sc->ehm); 1 1 Frees up any memory allocated for enhanced hardware managementand unregisters this ...
Page 101 - Implementing the Initialization Section; Implementing the Initialization Section 8–1
8 Implementing the Initialization Section The initialization section prepares the network interface to transmit andreceive data packets. It can also allocate mbuf data structures for the receive ring. The if_el device driver implements the following routines in its initialization section: • el_init ...
Page 102 - –2 Implementing the Initialization Section
3 Declares a pointer to an ifnet data structure called ifp and initializes it to the address of the ifnet data structure for this device. The ifnet data structure is referenced through the is_if member of the el_softc data structure pointer. The is_if name is an alternate name for the ac_if member o...
Page 103 - Releasing the Simple Lock and Resetting the IPL; Implementing the Initialization Section 8–3
The el_softc_lock member of the el_softc data structure points to a simple lock data structure. The if_el device driver declares this data structure by calling the decl_simple_lock_data( ) routine. 8.1.4 Calling the el_init_locked Routine The following code shows how the el_init( ) routine calls the...
Page 104 - Resetting the Transmitter and Receiver; –4 Implementing the Initialization Section
• Sets the LAN media type attribute (Section 8.2.6) • Selects memory mapping (Section 8.2.7) • Resets the transmitter and receiver a second time (Section 8.2.8) • Sets the LAN address (Section 8.2.9) • Processes special flags (Section 8.2.10) • Sets the debug flag (Section 8.2.11) • Enables TX and R...
Page 105 - irq; Ensuring That the 10Base2 Transceiver Is Off; DELAY; Implementing the Initialization Section 8–5
This task is specific to the 3Com 3C5x9 device. Make sure that you performsimilar initialization tasks for the hardware device that your network drivercontrols. WRITE_CMD(sc, CMD_ACKINT+0xff); 1 1 Calls the WRITE_CMD macro to write data to the command port register. The data written to the command p...
Page 106 - –6 Implementing the Initialization Section
8.2.5 Setting the LAN Media The following code shows how the el_init_locked( ) routine sets the LAN media. This task is specific to the 3Com 3C5x9 device. You may wantto perform similar initialization tasks for the hardware device that yournetwork driver controls. i = READ_ACR(sc); 1 i &= ~ (ACR...
Page 107 - Resetting the Transmitter and Receiver Again; Implementing the Initialization Section 8–7
10 For the default case, sets the lm_media member to LAN_MEDIA_UTP (media mode is unshielded twisted pair cable). 11 Determines whether lm_media evaluates to LAN_MEDIA_UTP . 12 Calls WRITE_ACR to write to the address control register. The data to be written establishes the Ethernet unshielded twiste...
Page 108 - –8 Implementing the Initialization Section
WRITE_CMD(sc, CMD_TXRESET); 1 WRITE_CMD(sc, CMD_RXRESET); 2 1 Calls the WRITE_CMD macro to write data to the command port register. The data to be written is the transmit (TX) reset command( CMD_TXRESET ). 2 Calls the WRITE_CMD macro to write data to the command port register. In this call, the data...
Page 109 - Implementing the Initialization Section 8–9
else { lan_set_attribute(sc->ehm.current_val, NET_PROMISC_NDX, (void *)0); } WRITE_CMD(sc, CMD_FILTER+i); 7 1 If loopback mode is requested, enables it. 2 Sets the LAN loopback attribute for EHM support. 3 Selects to receive frames that are sent to both the local address and thebroadcast address....
Page 110 - –10 Implementing the Initialization Section
WRITE_CMD(sc, CMD_RXENA); 1 WRITE_CMD(sc, CMD_TXENA); 2 1 Calls the WRITE_CMD macro to write data to the command port register. The data to be written is the receive (RX) enable command ( CMD_RXENA ). 2 Calls the WRITE_CMD macro to write data to the command port register. In this call, the data to b...
Page 111 - ESUCCESS; Implementing the Initialization Section 8–11
ifp->if_flags |= IFF_RUNNING; 1 ifp->if_flags &= ~ IFF_OACTIVE; 2 1 Sets the IFF_RUNNING flag to mark the device as running. 2 Clears the IFF_OACTIVE flag to indicate that there is no output outstanding. 8.2.16 Starting the Autosense Kernel Thread The following code shows how the el_init_l...
Page 113 - Implementing the Start Section; start; Setting the IPL and Obtaining the Simple Lock; Implementing the Start Section 9–1
9 Implementing the Start Section The start section of a network device driver transmits data packets acrossthe network. When the network protocol has a data packet to transmit,it prepares the packet, then calls the start interface for the appropriate network device driver. The start interface transm...
Page 114 - Releasing the Simple Lock and Resetting the IPL; –2 Implementing the Start Section
2 Calls the simple_lock_try( ) routine to try to assert a lock with read and write access for the resource that is associated with the specifiedsimple lock. The el_start( ) routine calls simple_lock_try( ) rather than simple_lock( ) because simple_lock_try( ) returns immediately if the resource is a...
Page 115 - watchdog; Discarding All Transmits After the User Removes the PCMCIA; Implementing the Start Section 9–3
This simple lock was previously asserted by calling the simple_lock( ) or simple_lock_try( ) routine. 2 Calls the splx( ) routine to reset the CPU priority to the level that the s variable specifies. 9.2 Implementing the el_start_locked Routine The el_start_locked( ) routine performs the start opera...
Page 116 - Removing Packets from the Pending Queue and Preparing the; –4 Implementing the Start Section
IF_DEQUEUE(&ifp->if_snd, m); 3 while (m) { 4 m_freem(m); IF_DEQUEUE(&ifp->if_snd, m); } return; } 1 Declares a pointer to an ether_header data structure called eh . The ether_header data structure contains information that is associated with a 10 Mb/s and 100 Mb/s Ethernet header. 2 If...
Page 117 - Implementing the Start Section 9–5
mp = ms; 8 mn = mp->m_next; 9 len = mp->m_len; 10 while (mn != NULL) { 11 if (mn->m_len == 0) { mp->m_next = mn->m_next; mn->m_next = NULL; m_free(mn); } else { 12 len += mn->m_len; mp = mn; } mn = mp->m_next; } 1 While true, removes packets from the pending queue and has the...
Page 118 - –6 Implementing the Start Section
in the middle. The mfree( ) routine is called to free any zero-length memory buffers. 12 Otherwise, adds the length and sets the next memory buffer in thechain to the mp mbuf pointer. 9.2.3 Transmitting the Buffer The following code shows how the el_start_locked( ) routine transmits the buffer: WRIT...
Page 119 - the Output Process as Active; Implementing the Start Section 9–7
2 Copies transmit data from memory to the card using 32-bit writes. Onlya multiple of 4 bytes can be copied this way. 3 If some number of bytes (fewer than 4) remain in the current memorybuffer, the driver either copies those bytes directly to the card (if theywere the last bytes for the entire fram...
Page 120 - Indicating When to Start the Watchdog Routine; –8 Implementing the Start Section
9.2.6 Indicating When to Start the Watchdog Routine The following code shows how the el_start_locked( ) routine indicates the time for starting the driver ’s watchdog interface. Although this task is optional, we recommend that all network drivers perform this task. ifp->if_timer = 3; 1 } 1 Sets ...
Page 121 - Implementing a Watchdog Section; Setting the IPL and Obtaining the Simple Lock; Implementing a Watchdog Section 10–1
10 Implementing a Watchdog Section Network device drivers can take advantage of the watchdog timer. The network layer implements this mechanism to ensure that the network deviceis transmitting data. The driver starts the watchdog timer when it sends a transmit request to the device. After it receive...
Page 122 - 0–2 Implementing a Watchdog Section
2 Calls the simple_lock( ) routine to assert a lock with exclusive access for the resource that is associated with the el_softc_lock simple lock data structure pointer. This means that no other kernel thread cangain access to the locked resource until you call simple_unlock( ) to release it. Because...
Page 123 - Implementing the Reset Section; Implementing the Reset Section 11–1
11 Implementing the Reset Section The reset section of a network device driver contains the code that resets theLAN adapter when there is a network failure and there is a need to restartthe device. It resets all of the counters and local variables and can free upand reallocate all of the buffers tha...
Page 124 - 1–2 Implementing the Reset Section
3 Calls the el_reset_locked( ) routine, which performs the actual tasks that are associated with resetting the device. 4 Calls the simple_unlock( ) routine to release the simple lock for the el_softc data structure and then resets the CPU priority to the level that it was originally at upon entrance...
Page 125 - Implementing the ioctl Section; Table 12–1: Network ioctl Commands; ioctl Command
12 Implementing the ioctl Section The ioctl section of a network device driver contains the code that implementsa network device driver ’s ioctl interface. The ioctl interface performs miscellaneous tasks that have nothing to do with data packet transmissionand reception. Typically, it turns specifi...
Page 126 - 2–2 Implementing the ioctl Section
Table 12–1: Network ioctl Commands (cont.) ioctl Command Required Description For More Information SIOCSIFFLAGS Yes Ensures that theinterface is operatingcorrectly accordingto the interface flags( if_flags ). Section 12.12 SIOCSIPMTU Yes Sets the IP maximumtransmission unit(MTU). Section 12.13 SIOCS...
Page 127 - Implementing the ioctl Section 12–3
7 Casts the data argument to a data structure of type ifdevea for use with the SIOCRPHYSADDR ioctl command. 8 Casts the data argument to a data structure of type ctrreq for use with the SIOCRDCTRS and SIOCRDZCTRS ioctl commands. 9 Casts the data argument to a data structure of type ifchar for use wi...
Page 128 - 2–4 Implementing the ioctl Section
you call simple_unlock( ) to release it. Because simple locks are spin locks, simple_lock( ) does not return until the lock has been obtained. 12.4 Enabling Loopback Mode (SIOCENABLBACK ioctl Command) The following code shows how the el_ioctl( ) routine implements the SIOCENABLBACK ioctl command to ...
Page 129 - Implementing the ioctl Section 12–5
12.6 Reading Current and Default MAC Addresses (SIOCRPHYSADDR ioctl Command) The following code shows how the el_ioctl( ) routine implements the SIOCRPHYSADDR ioctl command to read the current and default MAC addresses when an application requests them: case SIOCRPHYSADDR: 1 bcopy(sc->is_addr, if...
Page 130 - Adding the Device to a Multicast Group; SIOCADDMULTI ioctl; 2–6 Implementing the ioctl Section
4 If the 3Com 3C5x9 device is running, calls the el_reset_locked( ) routine to restart the network interface with the new address. 5 Calls the simple_unlock( ) routine to release the simple lock for the resource that is associated with el_softc_lock . 6 Calls the splx( ) routine to reset the CPU pri...
Page 131 - Deleting the Device from a Multicast Group; SIOCDELMULTI ioctl; Implementing the ioctl Section 12–7
ether_sprintf(maddr), sc->is_multi.lan_mtable[j-1].muse); } } lan_build_mclist (mclist_buf, NET_SZ_MCLIST, &sc->is_multi); 5 lan_set_attribute(sc->ehm.current_val, NET_MCLIST_NDX, mclist_buf); break; 1 Determines whether the cmd argument is SIOCADDMULTI . 2 If the address is broadcast, ...
Page 132 - 2–8 Implementing the ioctl Section
if (sc->debug) { j = 0; printf("el%d: Dump of multicast table after DEL (%d entries)\n", unit, sc->is_multi.lan_nmulti); for (i=0; i<sc->is_multi.lan_nmulti; i++) { unsigned char *maddr; LAN_GET_MULTI(&sc->is_multi, maddr, j);printf(" %d %s (muse==%d)\n", i+1, ethe...
Page 133 - Table 12–2: Network Interface Counter Types; Network Interface; Bringing Up the Device (SIOCSIFADDR ioctl; Implementing the ioctl Section 12–9
2 Copies the current counters to the ctrreq data structure. 3 Indicates that these are Ethernet counters. 4 Returns the number of seconds since the counters were last zeroed. 5 If the user process requested the SIOCRDZCTRS command, zeroes the counters and sets the ztime member of the softc data stru...
Page 134 - 2–10 Implementing the ioctl Section
2 Marks the interface as up and calls the el_reset_locked( ) routine to start the network interface with the current settings. 3 Sets the counter cleared time (used by DECnet, netstat, clusters, and soforth). 12.12 Using Currently Set Flags (SIOCSIFFLAGS ioctl Command) The following code shows how t...
Page 135 - Setting Device Characteristics (SIOCIFSETCHAR; Implementing the ioctl Section 12–11
SIOCSMACSPEED and SIOCIFSETCHAR ioctl commands perform some of the same tasks.) case SIOCSMACSPEED: 1 bcopy(ifr->ifr_data, (u_char *)&speed, sizeof(u_short)); if ((speed != 0) && (speed != 10)) { 2 status = EINVAL; break; } break; 1 Determines whether the cmd argument is SIOCSMACSPEED...
Page 136 - 2–12 Implementing the ioctl Section
if (ifc->ifc_auto_sense != -1) { 5 if ((ifc->ifc_auto_sense == LAN_AUTOSENSE_ENABLE) && (sc->lm_media_mode != LAN_MODE_AUTOSENSE)) { sc->lm_media_mode = LAN_MODE_AUTOSENSE; need_reset++; } else if ((ifc->ifc_auto_sense == LAN_AUTOSENSE_DISABLE) && (sc->lm_media_mode...
Page 137 - Releasing the Simple Lock and Resetting the IPL; Implementing the ioctl Section 12–13
If the user sets media that the card does not have, the interface maynot work. 9 Selects the new mode. 10 Resets the device to pick up the new mode (if the interface was running). 11 The default case returns an error that indicates that the caller hasissued an invalid ioctl command. 12.17 Releasing ...
Page 139 - Implementing the Interrupt Section 13–1
13 Implementing the Interrupt Section The interrupt section of a network device driver contains the code that iscalled whenever the network interface transmits or receives a frame. The if_el device driver implements the following routines in its interrupt section: • el_intr( ) (Section 13.1) • el_ri...
Page 140 - Setting the IPL and Obtaining the Simple Lock; 3–2 Implementing the Interrupt Section
13.1.1 Setting the IPL and Obtaining the Simple Lock The following code shows how the el_intr( ) routine sets the CPU’s IPL and obtains the simple lock: static int el_intr(int unit) 1 { register u_int s;volatile u_int status; register struct el_softc *sc = el_softc[unit]; register struct ifnet *ifp ...
Page 141 - Processing Completed Receive and Transmit Operations; status; Implementing the Interrupt Section 13–3
13.1.3 Reading the Interrupt Status The following code shows how the el_intr( ) routine uses the READ_STS macro to read the interrupt status from the I/O status register: status = READ_STS(sc); 13.1.4 Processing Completed Receive and Transmit Operations The following code shows how the el_intr( ) ro...
Page 142 - Releasing the Simple Lock and Resetting the IPL; 3–4 Implementing the Interrupt Section
• If the status variable has the S_AF bit set, calls the el_error( ) routine to process the error. • Calls the READ_STS macro to read the interrupt status again from the I/O status register. 13.1.5 Acknowledging the Interrupt The following code shows how the el_intr( ) routine acknowledges the inter...
Page 143 - Indicating That the Interrupt Was Serviced; Counting the Receive Interrupt and Reading the Receive; Implementing the Interrupt Section 13–5
13.1.8 Indicating That the Interrupt Was Serviced The following code shows how the el_intr( ) routine indicates that the interrupt was serviced: return INTR_SERVICED; 1 } 1 Returns the INTR_SERVICED constant to the kernel interrupt dispatcher to indicate that el_intr( ) serviced the shared interrupt...
Page 144 - Pulling the Packets from the FIFO Buffer; The following code shows how the; 3–6 Implementing the Interrupt Section
13.2.2 Pulling the Packets from the FIFO Buffer The following code shows how the el_rint( ) routine pulls the packets from the first-in/first-out (FIFO) buffer. This task is specific to the hardwaredevice that is associated with the if_el device driver. If you need to perform a similar task with you...
Page 145 - Examining the First Part of the Packet; Implementing the Interrupt Section 13–7
2 Looks for errors. 3 Processes the error. 4 Processes the overrun error case. 5 Processes the runt and oversized error cases. 6 Processes the CRC error case. 7 Processes the alignment error case. 8 Discards the packet if none of the previous cases apply. This indicates asize error. 9 Allocates a bu...
Page 146 - Copying the Received Packet into the mbuf; 3–8 Implementing the Interrupt Section
if (bcmp(mtod(m, unsigned char *), etherbroadcastaddr, 6) != 0) { 8 int ix; LAN_FIND_MULTI(&sc->is_multi, mtod(m, unsigned char *), ix, i); 9 if ( (i != LAN_MULTI_FOUND) || 10 (sc->is_multi.lan_mtable[ix].muse == 0)) { m_freem(m); goto scrap; } } } } 1 If an mbuf was successfully allocated...
Page 147 - Implementing the Interrupt Section 13–9
eh = *(mtod(m, struct ether_header *)); 2 eh.ether_type = ntohs((unsigned short)eh.ether_type); 3 m->m_data += sizeof(struct ether_header); 4 ADD_RECV_PACKET(ifp, sc, m->m_pkthdr.len); 5 if (eh.ether_dhost[0] & 0x1) { ADD_RECV_MPACKET(ifp, sc, m->m_pkthdr.len); } i = READ_RXS(sc); 6 if ...
Page 148 - Reading the Transmit Status and Counting All Significant; 3–10 Implementing the Interrupt Section
if ((sc->debug) && (count <= 0)) printf("el%d: Receive in INFINITE loop %04X\n", ifp->if_unit, status); } 1 Calls the WRITE_CMD macro to write data to the command port register. The data to be written is the receive discard top packet command( CMD_RXDTP ). 13.3 Implementing ...
Page 149 - Managing Excessive Data Collisions; Implementing the Interrupt Section 13–11
WRITE_CMD(sc, CMD_TXRESET); DELAY(10); 4 WRITE_CMD(sc, CMD_TXENA); 1 Calls the READ_TXS macro to read the transmit status from the transmit status register. 2 Examines the status for a jabber or an underrun error. If either of theseerrors happened, then the transmitter must be reset. 3 Clears the tr...
Page 150 - 3–12 Implementing the Interrupt Section
2 Updates the softc data structure with the amount of space that is available in the transmit FIFO. 13.3.5 Queuing Other Transmits The following code shows how the el_tint( ) routine clears the output active flag to permit other transmits to be queued to the device: ifp->if_flags &= ~IFF_OACT...
Page 151 - Network Device Driver Configuration 14–1
14 Network Device Driver Configuration Device driver configuration incorporates device drivers into the kernel tomake them available to system administration and other utilities. Theoperating system provides two methods for configuring drivers into thekernel: static and dynamic. We recommend that yo...
Page 153 - Index; Index–1
Index Numbers and SpecialCharacters 10Base2 transceiver ensuring that it is off , 8–5 A allocating the ether_driver data structure , 5–7 attach interface , 6–1 registering adapters , 6–9 setting network attributes , 6–9 autoconfiguration attach interface , 6–1 probe interface , 5–1 autoconfiguration...
Page 154 - Index–2
of pending transmit frames , 13–4 of receive interrupt , 13–8 debug flag , 3–8 setting , 8–9 debug information printing , 5–24 declarations configure-related , 4–2 network device driver , 1–4 declarations section , 1–4 devdriver.h header file , 1–4 device bringing up , 12–9 marking as running , 8–10...
Page 155 - Index–3
initializing the enhanced hardware management data structure , 5–8 performing bus-specific tasks , 5–4 registering interrupt handlers , 5–15 registering the shutdown routine , 5–17 saving controller and el_softc data structure pointers , 5–16 setting up , 5–2 el_reset routine , 11–1 el_reset_locked ...
Page 156 - Index–4
interrupt handler enabling , 6–10 ID , 3–6 registering , 5–15 interrupt section , 1–11 implementing , 13–1 ioctl command SIOCADDMULTI , 12–6 SIOCDELMULTI , 12–7 SIOCDISABLBACK , 12–4 SIOCENABLBACK , 12–4 SIOCIFRESET , 12–11 SIOCIFSETCHAR , 12–11 SIOCRDCTRS , 12–8 SIOCRDZCTRS , 12–8 SIOCRPHYSADDR , 1...
Page 157 - Index–5
autoconfiguration support section , 1–10 configure section , 1–10 declarations , 1–4 environment , 1–1 include files , 1–3 initialization section , 1–10 interrupt section , 1–11 ioctl section , 1–11 output section , 1–11 register offsets , 2–1 reset section , 1–11 start section , 1–10 watchdog secti...
Page 158 - Index–6
ROM using the default from , 5–21 RX status reading , 13–5 S section autoconfiguration support , 1–10, 5–1, 6–1 configure , 1–10 declarations , 1–4 include files , 1–3 initialization , 1–10, 8–1 interrupt , 1–11, 13–1 ioctl , 1–11, 12–1 output , 1–11 reset , 1–11, 11–1 start , 1–10, 9–1 watchdog , 1...
Page 159 - Index–7
loading into the buffer , 5–22 transmitting , 5–22 timeout information in el_softc data structure , 3–9 rearming the next , 13–2 timer clearing , 10–2 transmit counting interrupts , 13–10 counting timeouts , 10–2 discarding all , 9–3 freeing buffer , 9–7 of pending packets , 8–11 processing complete...