Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::drivers::ethernet::IntelI217 Class Reference

Driver for the Intel I217 Ethernet Controller. More...

#include <intel_i217.h>

Inheritance diagram for MaxOS::drivers::ethernet::IntelI217:
MaxOS::drivers::ethernet::EthernetDriver MaxOS::hardwarecommunication::InterruptHandler MaxOS::drivers::Driver MaxOS::common::EventManager< EthernetDriverEvents >

Public Member Functions

 IntelI217 (hardwarecommunication::PCIDeviceDescriptor *device_descriptor)
 Constructs a new Intel I217 Ethernet driver. Gets the MAC address and clears the receive descriptor array.
 
uint32_t reset () final
 Reset the driver.
 
void activate () final
 Activate the driver.
 
void deactivate () final
 Deactivate the driver.
 
void handle_interrupt () final
 Handles an interrupt.
 
string vendor_name () final
 Get who created the device.
 
string device_name () final
 Get the device name of the driver.
 
void do_send (uint8_t *buffer, uint32_t size) final
 (Device Side) send the data
 
uint64_t get_media_access_control_address () final
 Get the MAC address.
 
- Public Member Functions inherited from MaxOS::drivers::ethernet::EthernetDriver
void send (uint8_t *buffer, uint32_t size)
 send data to the network via the driver backend
 
- Public Member Functions inherited from MaxOS::drivers::Driver
virtual void initialise ()
 Initialise the driver.
 
- Public Member Functions inherited from MaxOS::common::EventManager< EthernetDriverEvents >
void connect_event_handler (EventHandler< EthernetDriverEvents > *handler)
 connect an event handler to the event manager if it is not already connected
 
void disconnect_event_handler (EventHandler< EthernetDriverEvents > *handler)
 disconnect an event handler from the event manager if it is connected
 
Vector< Event< EthernetDriverEvents > * > raise_event (Event< EthernetDriverEvents > *event)
 Calls the on_event function of all the event m_handlers connected to the event manager and returns a list of the results.
 
- Public Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler
virtual system::cpu_status_thandle_interrupt (system::cpu_status_t *status)
 Handles an interrupt and returns the status.
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxOS::drivers::ethernet::EthernetDriver
static MediaAccessControlAddress create_media_access_control_address (uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, uint8_t digit5, uint8_t digit6)
 Create a Media Access Control Address.
 
- Protected Member Functions inherited from MaxOS::drivers::ethernet::EthernetDriver
void fire_data_received (uint8_t *buffer, uint32_t size)
 Handle the recieved data.
 
void fire_data_sent (uint8_t *buffer, uint32_t size)
 send data
 
- Protected Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler
 InterruptHandler (uint8_t interrupt_number, int64_t redirect=-1, uint64_t redirect_index=0)
 Creates a new interrupt handler and registers it with the interrupt manager.
 
 ~InterruptHandler ()
 Destroys the interrupt handler and unregisters it from the interrupt manager.
 
- Protected Attributes inherited from MaxOS::common::EventManager< EthernetDriverEvents >
Vector< EventHandler< EthernetDriverEvents > * > m_handlers
 
- Protected Attributes inherited from MaxOS::hardwarecommunication::InterruptHandler
uint8_t m_interrupt_number
 The interrupt number this handler handles.
 

Detailed Description

Driver for the Intel I217 Ethernet Controller.

Definition at line 64 of file intel_i217.h.

Constructor & Destructor Documentation

◆ IntelI217()

IntelI217::IntelI217 ( hardwarecommunication::PCIDeviceDescriptor device_descriptor)
explicit

Constructs a new Intel I217 Ethernet driver. Gets the MAC address and clears the receive descriptor array.

Parameters
device_descriptorThe PCI device descriptor for this device

Definition at line 33 of file intel_i217.cpp.

34 : InterruptHandler(0x20 + device_descriptor->interrupt) {
35
36 //Set the registers
37 control_register = 0x0000;
38 status_register = 0x0008;
39 eprom_register = 0x0014;
40 control_ext_register = 0x0018;
41 interrupt_mask_register = 0x00D0;
42
43 receive_control_register = 0x0100;
44 receive_descriptor_low_register = 0x2800;
45 receive_descriptor_high_register = 0x2804;
46 receive_descriptor_length_register = 0x2808;
47 receive_descriptor_head_register = 0x2810;
48 receive_descriptor_tail_register = 0x2818;
49
50 send_control_register = 0x0400;
51 send_descriptor_low_register = 0x3800;
52 send_descriptor_high_register = 0x3804;
53 send_descriptor_length_register = 0x3808;
54 send_descriptor_head_register = 0x3810;
55 send_descriptor_tail_register = 0x3818;
56
57 // Get BAR0 type, io_base address and MMIO base address
58 bar_type = 1; // deviceDescriptor -> has_memory_base ? 0 : 1; @todo Fix memory mapping from PCI as it is unable to get MAC from memory
59 port_base = device_descriptor->port_base;
60 //TODO: memBase = deviceDescriptor -> memory_base;
61
62 init_done = false;
63 active = false;
64
65 // Clear eprom
66 eprom_present = detect_ee_prom();
67
68
69 if (read_mac_address()) {
70 own_mac = create_media_access_control_address(mac_address[0], mac_address[1], mac_address[2], mac_address[3],
71 mac_address[4], mac_address[5]);
72
73 } else {
74 ASSERT(false, "ERROR, INIT FAILED, MAC ADDRESS NOT FOUND");
75 }
76
77 for (int i = 0; i < 0x80; i++) //Loop through all the registers
78 write(0x5200 + i * 4, 0); //Clear the receive descriptor array
79
80
81
82
83}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
static MediaAccessControlAddress create_media_access_control_address(uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, uint8_t digit5, uint8_t digit6)
Create a Media Access Control Address.
Definition ethernet.cpp:165
Handles a certain interrupt number.
Definition interrupts.h:30
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
Definition logger.h:100

References ASSERT, and MaxOS::drivers::ethernet::EthernetDriver::create_media_access_control_address().

Member Function Documentation

◆ activate()

void IntelI217::activate ( )
finalvirtual

Activate the driver.

Reimplemented from MaxOS::drivers::Driver.

Definition at line 298 of file intel_i217.cpp.

298 {
299
300
301 //Enable interrupts
302 write(interrupt_mask_register, 0x1F6DC); //Enable all interrupts
303 write(interrupt_mask_register, 0xff & ~4); //Enable all interrupts except link status change
304 read(0xc0); //Clear all interrupts
305
306 //while (!initDone); //Wait for the init to be done
307
308 //Initialise the send and receive descriptors
309 receive_init();
310 send_init();
311
312 active = true; // Set active to true
313
314}

◆ deactivate()

void IntelI217::deactivate ( )
finalvirtual

Deactivate the driver.

Reimplemented from MaxOS::drivers::Driver.

Definition at line 391 of file intel_i217.cpp.

391 {
393}
virtual void deactivate()
Deactivate the driver.
Definition driver.cpp:32

References MaxOS::drivers::Driver::deactivate().

◆ device_name()

string IntelI217::device_name ( )
finalvirtual

Get the device name of the driver.

Returns
The device name of the driver

Reimplemented from MaxOS::drivers::Driver.

Definition at line 399 of file intel_i217.cpp.

399 {
400 return "E1000 (i217)";
401}

◆ do_send()

void IntelI217::do_send ( uint8_t buffer,
uint32_t  size 
)
finalvirtual

(Device Side) send the data

Parameters
bufferThe buffer to handle
sizeThe size of the buffer

Reimplemented from MaxOS::drivers::ethernet::EthernetDriver.

Definition at line 356 of file intel_i217.cpp.

356 {
357
358 while (!active);
359
360 //Put params into send buffer
361 send_dsrctrs[current_send_buffer]->buffer_address = (uint64_t) buffer;
362 send_dsrctrs[current_send_buffer]->length = size;
363
364 //Set the commands
365 send_dsrctrs[current_send_buffer]->cmd = (1 << 0) // End of Packet
366 | (1 << 1) // Insert FCS
367 | (1 << 3) // Report Status
368 ;
369
370 send_dsrctrs[current_send_buffer]->status = 0;
371
372 uint8_t old_cur = current_send_buffer; //Save the current send buffer
373 current_send_buffer = (current_send_buffer + 1) % 8; //Increment the current send buffer
374 write(send_descriptor_tail_register, current_send_buffer); //write the current send buffer to the tail register
375
376 //Wait for the packet to be sent
377 while (!(send_dsrctrs[old_cur]->status & 0xff));
378
379}

◆ get_media_access_control_address()

uint64_t IntelI217::get_media_access_control_address ( )
finalvirtual

Get the MAC address.

Returns
the MAC address

Reimplemented from MaxOS::drivers::ethernet::EthernetDriver.

Definition at line 381 of file intel_i217.cpp.

381 {
382 while (own_mac == 0);
383 return own_mac;
384
385}

◆ handle_interrupt()

void IntelI217::handle_interrupt ( )
finalvirtual

Handles an interrupt.

Reimplemented from MaxOS::hardwarecommunication::InterruptHandler.

Definition at line 316 of file intel_i217.cpp.

316 {
317
318 write(interrupt_mask_register, 0x1); //Clear the interrupt or it will hang
319 uint32_t temp = read(0xc0); //read the interrupt status register
320
321 // if(temp & 0x04)
322 // m_driver_message_stream-> write("INTEL i217 START LINK");//initDone = true;
323 //
324 // if(temp & 0x10)
325 // m_driver_message_stream-> write("INTEL i217 GOOD THRESHOLD");
326
327 if (temp & 0x80) fetch_data_received();
328}

◆ reset()

uint32_t IntelI217::reset ( )
finalvirtual

Reset the driver.

Returns
How long in milliseconds it took to reset the driver

Reimplemented from MaxOS::drivers::Driver.

Definition at line 387 of file intel_i217.cpp.

387 {
388 return Driver::reset();
389}
virtual uint32_t reset()
Reset the driver.
Definition driver.cpp:48

References MaxOS::drivers::Driver::reset().

◆ vendor_name()

string IntelI217::vendor_name ( )
finalvirtual

Get who created the device.

Returns
The vendor name of the driver

Reimplemented from MaxOS::drivers::Driver.

Definition at line 395 of file intel_i217.cpp.

395 {
396 return "Intel";
397}

The documentation for this class was generated from the following files: