scsi request, part usb mass storage class driver, bulk transfers
[quarnos.git] / resources / ne2k.cpp
blob8a5b2d1edaef1583035584fff8861a781f262435
1 /* Quarn OS
3 * NE2000 ethernet card
5 * Copyright (C) 2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "ne2k.h"
24 #include "pci.h"
26 #include "manes/manec.h"
28 using namespace resources;
30 void get_mac_addr(u8 *mac);
31 void ne2k_pci_init(pci_did pciaddr);
32 void ne2k_pci_send_packet(pci_did pciaddr, u8 *buff, u16 len);
34 p<net::nic> faar;
36 bool ne2k::init_device(p<did> id) {
37 device_id = id;
38 faar = this;
39 ne2k_pci_init(*id.cast<pci_did>());
40 return true;
43 bool ne2k::check_device(p<did> id) {
44 p<pci_did> pid = id.cast<pci_did>();
46 if (!pid.valid())
47 return false;
49 /* It must be an ethernet card */
50 unsigned int devclass = pid->get_bus().cast<pci>()->get_devclass(id) >> 8;
51 if (devclass != 0x0200)
52 return false;
54 unsigned int devid = pid->get_bus().cast<pci>()->get_devid(id);
55 /* It must be a *compatible* ethernet card (for example Realtek 8029) */
56 if (devid != 0x802910ec)
57 return false;
59 return true;
62 void ne2k::send_data(const buffer &x) {
63 ne2k_pci_send_packet(*device_id.cast<pci_did>(), (u8*)x.get_address(), x.get_size());
67 net::mac_addr ne2k::get_haddr() const {
68 u8 addr[6];
69 get_mac_addr(addr);
70 return net::mac_addr::from_be(*(u32*)addr, ((u16*)addr)[2]);
73 void ne2k::register_type() {
74 delegate<bool, p<did> > chk;
75 chk.function(&ne2k::check_device);
76 manes::manec::get()->register_driver<ne2k>("ne2k", "nic", chk);