Intel Ethernet i217: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
Fix typo regarding RX Descriptor Control register offset (0x3828 -> 0x2828) (tested on 82540EM)
m Bot: Replace deprecated source tag with syntaxhighlight
Line 110: Line 110:
Now lets define the data structures for the transmit and receive buffers
Now lets define the data structures for the transmit and receive buffers


<source lang="c">
<syntaxhighlight lang="c">


#define E1000_NUM_RX_DESC 32
#define E1000_NUM_RX_DESC 32
Line 134: Line 134:
} __attribute__((packed));
} __attribute__((packed));


</syntaxhighlight>
</source>


And finally some helper static methods for MMIO read/write operations and Ports I/O
And finally some helper static methods for MMIO read/write operations and Ports I/O


<source lang="c">
<syntaxhighlight lang="c">


class MMIOUtils
class MMIOUtils
Line 190: Line 190:
}
}


</syntaxhighlight>
</source>


<source lang="c">
<syntaxhighlight lang="c">
#ifndef PORTS_H_
#ifndef PORTS_H_
#define PORTS_H_
#define PORTS_H_
Line 327: Line 327:




</syntaxhighlight>
</source>


== The Driver Class Header (Class Definition)==
== The Driver Class Header (Class Definition)==




<source lang="c">
<syntaxhighlight lang="c">
class E1000 : public NetworkDriver
class E1000 : public NetworkDriver
{
{
Line 370: Line 370:
~E1000(); // Default Destructor
~E1000(); // Default Destructor
};
};
</syntaxhighlight>
</source>


== How the Gears Move (Class methods implementation) ==
== How the Gears Move (Class methods implementation) ==
Line 376: Line 376:
First of all we need to be able to send commands and read results from the NIC. It is important to detect the type of BAR0 and based on that the correct communication mechanism should be adopted. The following two methods encapsulate the read/write commands and uses MMIO or IO ports based on the value in BAR0 which is reflected in bar_type data member flag.
First of all we need to be able to send commands and read results from the NIC. It is important to detect the type of BAR0 and based on that the correct communication mechanism should be adopted. The following two methods encapsulate the read/write commands and uses MMIO or IO ports based on the value in BAR0 which is reflected in bar_type data member flag.


<source lang="c">
<syntaxhighlight lang="c">
void E1000::writeCommand( uint16_t p_address, uint32_t p_value)
void E1000::writeCommand( uint16_t p_address, uint32_t p_value)
{
{
Line 401: Line 401:
}
}
}
}
</syntaxhighlight>
</source>




Line 568: Line 568:


To enable interrupts
To enable interrupts
<source lang="c">
<syntaxhighlight lang="c">
void E1000::enableInterrupt()
void E1000::enableInterrupt()
{
{
Line 576: Line 576:


}
}
</syntaxhighlight>
</source>


As we have defined most of the building blocks and the helper methods lets define the main methods of the class.
As we have defined most of the building blocks and the helper methods lets define the main methods of the class.
Line 583: Line 583:
The constructor is responsible for fetching PCI related data and initialize the object internal state
The constructor is responsible for fetching PCI related data and initialize the object internal state


<source lang="c">
<syntaxhighlight lang="c">
E1000::E1000(PCIConfigHeader * p_pciConfigHeader) : NetworkDriver(p_pciConfigHeader)
E1000::E1000(PCIConfigHeader * p_pciConfigHeader) : NetworkDriver(p_pciConfigHeader)
{
{
Line 597: Line 597:
eerprom_exists = false;
eerprom_exists = false;
}
}
</syntaxhighlight>
</source>


The start method basically detects the EEPROM, reads the MAC addresses, setup rx and tx buffers, register the interrupt handler, and enable NIC interrupts
The start method basically detects the EEPROM, reads the MAC addresses, setup rx and tx buffers, register the interrupt handler, and enable NIC interrupts
Line 629: Line 629:


Your interrupt handler should eventually call the fire method which handles the NIC's events
Your interrupt handler should eventually call the fire method which handles the NIC's events
<source lang="c">
<syntaxhighlight lang="c">


void E1000::fire (InterruptContext * p_interruptContext)
void E1000::fire (InterruptContext * p_interruptContext)
Line 676: Line 676:
}
}


</syntaxhighlight>
</source>


Finally we define the sendPacket method as follows
Finally we define the sendPacket method as follows


<source lang="c">
<syntaxhighlight lang="c">


int E1000::sendPacket(const void * p_data, uint16_t p_len)
int E1000::sendPacket(const void * p_data, uint16_t p_len)
Line 695: Line 695:
}
}


</syntaxhighlight>
</source>




This is an example of how to instantiate an object of this class and startup you driver. I assume that you have scanned your PCI buses and loaded the found devices parameters into some data structures; in our example this is done by the PCIConfigManager class, which is outside the scope of this tutorial
This is an example of how to instantiate an object of this class and startup you driver. I assume that you have scanned your PCI buses and loaded the found devices parameters into some data structures; in our example this is done by the PCIConfigManager class, which is outside the scope of this tutorial


<source lang="c">
<syntaxhighlight lang="c">


pciConfigHeaderManager.initialize(); // Initialize the PCIConfigHeaderManager Object and scan PCI devices
pciConfigHeaderManager.initialize(); // Initialize the PCIConfigHeaderManager Object and scan PCI devices
Line 718: Line 718:
}
}


</syntaxhighlight>
</source>


== Summary and Wrap Up ==
== Summary and Wrap Up ==