OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Oct 30, 2020 7:05 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Where to start for writing a driver for Intel Ethennet i217
PostPosted: Sat Apr 11, 2015 12:14 pm 
Offline
Member
Member

Joined: Tue Oct 29, 2013 1:13 pm
Posts: 207
Hi,

I have just finished my E1000 driver following the attempts shared by others on OSDev and other on the online forums. It took me a while until I have it working with my OS. The same applies to Realtec. Both drivers I have works on VMs mainly Qemu, VBox, and Bochs.

Now, I have a a Thinkpad W540 and it has Intel Ethernet Connection I217 ethernet card, and I have Kubuntu installed which detects it as e1000e.

My problem is that the intel datasheet is very larger ( over 370 pages) and the linux e1000e is very complex as it has to account for a lot of other intel NICs.

My objective is to understand, and with this huge amount of dry documentation and code that supports a lot of NICs and features it is very difficult to achieve the needed understanding.


I would appreciate it If anyone has some pointers to tutorials in a step by step approach.


Thanks.
Karim.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Sat Apr 11, 2015 12:27 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 16, 2014 5:33 pm
Posts: 213
Location: Costa Rica
  1. Go the easiest way, that is, read a 370-page specification.
  2. Go the middle way, that is, try to read Linux kernel code.
  3. Go the hardest way, that is, ask in a OSDev forum about an easy "step by step" tutorial, just because you don't like 1 and 2.

_________________
Happy New Code!
Hello World in Brainfuck :D:
Code:
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Mon Apr 13, 2015 12:37 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9288
Location: On the balcony, where I can actually keep 1½m distance
There are a few things that all network cards have and what they can do. If you really know how your existing drivers work, then reproducing the relevant steps according to the other specification should give you a faster approach than trying to understand everything as a whole. Chances are that 75% of that specification is either trivial or superfluous for what you want to do for starters.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Mon Apr 13, 2015 2:24 am 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 304
Location: Germany
kemosparc wrote:
I would appreciate it If anyone has some pointers to tutorials in a step by step approach.
I'm trying hard to be nice here.

You're osdeving, this means that you will have to read specs 300+ pages long. There aren't any tutorials on that topic, simply because there's no need for them. You're one of maybe a few hundred people who are developing a driver for that hardware. It's not worth the while to spend hours to write a tutorial. When working on something only few people do, you'll have to get rid of the idea that you'll get the code with a tutorial, with the only thing left being copy&pasting it.

_________________
vineyard, a x86 OS.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Mon Apr 13, 2015 5:01 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
You might consider adding a wiki entry for both "e1000" and "e1000e" (assuming that they are significantly different), and filling them in with any relevant information, like memory addresses, registers, values and maybe even some sample code. That would speed things up for the next guy.

Or girl.

Hmm, never thought about it, but are there any female osdevers on here?

I think that deserves its own post...

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Mon Apr 13, 2015 5:12 am 
Offline
Member
Member

Joined: Tue Jan 20, 2015 9:01 am
Posts: 119
SpyderTL wrote:
Hmm, never thought about it, but are there any female osdevers on here?

I think that deserves its own post...

Recently it was addressed and mods locked that topic. They know better what they do. :)


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Mon Apr 13, 2015 1:28 pm 
Offline
Member
Member

Joined: Tue Oct 29, 2013 1:13 pm
Posts: 207
Hi,

Thank you all guys for your replies.

One thing that is not relevant to the post, which is that I did not get any email notifications except for the first reply from KemyLand, and I just logged in to reply to him after I got the driver working, and I found all of your replies.

Okay, the important thing is that I have got the driver working with some glitches that I am now working on, despite the "easy" answer from KemyLand :) I just started from the e1000 driver I already have.

What I needed actually is some sort of info and direction rather than how to do it. What I needed, after reaching partially a working driver, is that I can start with the e1000 to make it work with the Intel Ethernet Connection I217 ethernet card; this is basically the kind of stuff I expect to get from OSDev. Basically to find someone who have done it before and can assure me that I am on the right track without necessarily telling me how to do it, of course if I can get more details on how to do it which I do get most of the time from OSDev it is most appreciated; basically something close to Combuster's reply.

I don't have a problem with reading 370 pages in essence, but reading 370 pages of "Inel Datasheet" to reach this information which is "I can use e1000" with some modification to make it work is kind of a waste of time. In my opinion Intel data sheets are very dry and are only good if you know what you are looking for, and unfortunately I did not. Such manuals and data sheets have no chronological order and does not show in most of the cases the rational of the Intel designer of the corresponding device. Moreover, I am in the middle of my PhD. and I do read a lot every day, basically reading is a normal daily practice for me, so I have no problem with reading something that I can learn from, but not 370 pages of data sheet without any confirmed hope that it will give me what I want.

Basically, the problem with Intel manuals and data sheets is that they are written for someone who already understand and they don't teach anything, they just state facts in a dry manner, and here comes the benefit of something like OSDev, complement the facts with a practical knowledge.

Anyways, I think that one of the beneficial things that one can do before reading 370 pages is to ask, may be you can get an answer that will direct you to what you should read and short cut a lot of unimportant reading that you might do just because you are afraid of missing something.

Finally, I really appreciate this forum and I have learned a lot from it and I would have spent more time to get such knowledge if it were not OSDev, I also appreciate the amount of work and time being put from you guys to answer questions, it is a tremendous free service that really means a lot to people like me; please keep it up as we need it.


Thank you guys,
Karim.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Mon Apr 13, 2015 1:39 pm 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1067
Location: Germany
Now that you have something working, let me go the lazy route and ask you something... ;)

How different are e1000 and e1000e in your opinion? Does it make sense to have a common driver for both, or are they different enough to have separate drivers? I think I'll be implementing e1000e suport sooner or later and I'm not quite sure if I should start from scratch or extend the e1000 driver.

A quick look suggested that the registers have the same names and offsets, but the bits the first register that the CDI e1000 driver actually uses (EERD for accessing the EEPROM) has a completely different layout. If that's the exception, I might just add a special case for that, but if it continues like this, just starting over might be a better use of my time.

_________________
Developer of tyndur - community OS of Lowlevel (German)


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Mon Apr 13, 2015 2:12 pm 
Offline
Member
Member

Joined: Tue Oct 29, 2013 1:13 pm
Posts: 207
Hi Kevin,

Let me share with you what happened in the past two days.

I tried the data sheet but I could not get except that they both share, e1000 and e1000e, the same addresses as you have stated.

I looked quickly at the linux driver and it was very difficult to follow, as it accounts for a lot of NIC models.

I had to guess, so I decided to try to load the E1000 driver I had, but it got stuck at reading the MAC address from the EEPROM.

I looked back to the Intel data sheet for the I217 and I found that address 0x00014 is listed empty without the specs table, so I guessed that it might not be the right way to read the mac address from the EEPROM.

Only then I decided to look at Pure64 as I remember I had it running on a machine that Linux loaded for e1000e driver.

I recommend you to look at the src/BareMetal-OS/os/drivers/net/i8254x.asm

Basically with the I217 avoid using the EEPROM, and read the mac address from mem_base 0x5400 and the initialization of the buffers is the same as e1000. I conform for the RX buffer as I can receive data, but I have problems sending data so I am not sure with the TX buffers.

I have it working now and it can receive data but I have a problem with sending, and I am working on it right now.

I am not sure that this will apply to all NICs that work with e1000e but for the I217 this is what happened with me.

Thanks,
Karim.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Mon Apr 13, 2015 5:00 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 16, 2014 5:33 pm
Posts: 213
Location: Costa Rica
kemosparc wrote:
I tried the data sheet but I could not get except that they both share, e1000 and e1000e, the same addresses as you have stated.

I looked quickly at the linux driver and it was very difficult to follow, as it accounts for a lot of NIC models.

I had to guess, so I decided to try to load the E1000 driver I had, but it got stuck at reading the MAC address from the EEPROM.

I looked back to the Intel data sheet for the I217 and I found that address 0x00014 is listed empty without the specs table, so I guessed that it might not be the right way to read the mac address from the EEPROM.

Only then I decided to look at Pure64 as I remember I had it running on a machine that Linux loaded for e1000e driver.

I recommend you to look at the src/BareMetal-OS/os/drivers/net/i8254x.asm

Basically with the I217 avoid using the EEPROM, and read the mac address from mem_base 0x5400 and the initialization of the buffers is the same as e1000. I conform for the RX buffer as I can receive data, but I have problems sending data so I am not sure with the TX buffers.

I have it working now and it can receive data but I have a problem with sending, and I am working on it right now.


That's what we were expecting from you, doing real OSDeving =D> . BTW, sorry for my first (sarcastic) post. I did though you really were lazy and wanted a "step-by-step" tutorial, but I was wrong :wink: .

We'ld be very grateful if you could add your new knowledge to the wiki (not a tutorial [-X !), because, as has been said before, it can help the next guy/girl.

_________________
Happy New Code!
Hello World in Brainfuck :D:
Code:
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Tue Apr 14, 2015 9:34 am 
Offline
Member
Member

Joined: Tue Oct 29, 2013 1:13 pm
Posts: 207
Sure,

I can do that, but I need to get the send go through first.

I am planning to work on it during the next weekend.

I will let you know as soon as I have the full driver working (send/receive) on my thinkpad W540 :)

Thanks,
Karim.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Thu Apr 16, 2015 11:45 am 
Offline
Member
Member

Joined: Tue Oct 29, 2013 1:13 pm
Posts: 207
Hi,

I have been trying to make the driver send packets with no luck.

I printed the status register of the card I217 on my W540 and its value is 0x80083 but when I start my OS on QEMU it is 0x800080783.

The bits that are cleared are as follows:
Bit 8 : Master read Completions Blocked
Bit 9 : LAN Init Done
Bit 10: PHY reset Asserted
Bit 31:Clock Control 1/4

I cannot get those bits to be set as in QEMU.

But the card receives packets !?

Any ideas?

Thanks,
Karim.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Fri Apr 17, 2015 12:47 pm 
Offline
Member
Member

Joined: Tue Oct 29, 2013 1:13 pm
Posts: 207
Hi KemyLand,

Okay finally got it working. Not only for I217 but also Intel 82577LM. At least those are the ones I have and was able to try on.

I would like to share the code I have but to be of benefit I will have to share about 5 classes in 10 files.

I don't know how you prepare the Wiki, and how much details you want me to provide. I am willing to provide all the code related to the e1000 driver that supports the above two cards.

Important: the driver I have does not utilize all the features of the cards, but at least it initializes them and is able to send and receive packets; basic functionality.

Thanks,
Karim.


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Fri Apr 17, 2015 8:26 pm 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
You can take a look at some of the other hardware wiki pages to get an idea of the format, but it's pretty much just describing the hardware, the interface details (memory addresses, port numbers, etc.), and the process of comminicating with the device.

I wouldn't put too much source code in the hardware wiki page, itself. But I would put most/all of it in a separate page under your user name. And I would put links on both pages.

The PCI IDE Controller entry is a good example, although it has a ton of source in the wiki entry.

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: Where to start for writing a driver for Intel Ethennet i
PostPosted: Sat Apr 18, 2015 5:49 am 
Offline
Member
Member

Joined: Tue Oct 29, 2013 1:13 pm
Posts: 207
Hi,

Where I can add a Wiki page?

Or should I prepare the content and post it as a reply ?

Thanks,
Karim.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group