The Pedigree Project 0.1
modules/drivers/common/3c90x/main.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/machine/Device.h"
21#include "pedigree/kernel/processor/types.h"
22#include "pedigree/kernel/utilities/List.h"
23#include "pedigree/kernel/utilities/new"
24#include "pedigree/kernel/utilities/utility.h"
25
26#include "3Com90x.h"
27#include "modules/Module.h"
28#include "modules/system/network-stack/NetworkStack.h"
29
30class Network;
31
32struct nic {
33 uint16_t vendor, device;
34 const char* type;
35 const char* desc;
36};
37
38static struct nic potential_nics[] = {
39 /* Original 90x revisions: */
40 {0x10b7, 0x9000, "3c905-tpo", "3Com900-TPO"}, /* 10 Base TPO */
41 {0x10b7, 0x9001, "3c905-t4", "3Com900-Combo"}, /* 10/100 T4 */
42 {0x10b7, 0x9050, "3c905-tpo100", "3Com905-TX"}, /* 100 Base TX / 10/100 TPO */
43 {0x10b7, 0x9051, "3c905-combo", "3Com905-T4"}, /* 100 Base T4 / 10 Base Combo */
44 /* Newer 90xB revisions: */
45 {0x10b7, 0x9004, "3c905b-tpo", "3Com900B-TPO"}, /* 10 Base TPO */
46 {0x10b7, 0x9005, "3c905b-combo", "3Com900B-Combo"}, /* 10 Base Combo */
47 {0x10b7, 0x9006, "3c905b-tpb2", "3Com900B-2/T"}, /* 10 Base TP and Base2 */
48 {0x10b7, 0x900a, "3c905b-fl", "3Com900B-FL"}, /* 10 Base FL */
49 {0x10b7, 0x9055, "3c905b-tpo100", "3Com905B-TX"}, /* 10/100 TPO */
50 {0x10b7, 0x9056, "3c905b-t4", "3Com905B-T4"}, /* 10/100 T4 */
51 {0x10b7, 0x9058, "3c905b-9058", "3Com905B-9058"}, /* Cyclone 10/100/BNC */
52 {0x10b7, 0x905a, "3c905b-fx", "3Com905B-FL"}, /* 100 Base FX / 10 Base FX */
53 /* Newer 90xC revision: */
54 {0x10b7, 0x9200, "3c905c-tpo", "3Com905C-TXM"}, /* 10/100 TPO {3C905C-TXM} */
55 {0x10b7, 0x9800, "3c980", "3Com980-Cyclone"}, /* Cyclone */
56 {0x10b7, 0x9805, "3c9805", "3Com9805"}, /* Dual Port Server Cyclone */
57 {0x10b7, 0x7646, "3csoho100-tx", "3CSOHO100-TX"}, /* Hurricane */
58 {0x10b7, 0x4500, "3c450", "3Com450 HomePNA Tornado"},
59};
60
61#define NUM_POTENTIAL_NICS (sizeof(potential_nics) / sizeof(potential_nics[0]))
62
63static bool bFound = false;
64static List<Nic3C90x*> g_Cards;
65
66static void probeDevice(Device* pDev) {
67 bFound = true;
68
69 // Create a new node
70 Nic3C90x* pCard = new Nic3C90x(reinterpret_cast<Network*>(pDev));
71 if (!pCard->isInitialised()) {
72 delete pCard;
73 return;
74 }
75
76 // Replace pDev with pCard
77 pCard->setParent(pDev->getParent());
78 pDev->getParent()->replaceChild(pDev, pCard);
79 g_Cards.pushBack(pCard);
80}
81
82static bool entry() {
83 for (unsigned int i = 0; i < NUM_POTENTIAL_NICS; i++)
84 Device::searchByVendorIdAndDeviceId(potential_nics[i].vendor, potential_nics[i].device,
85 probeDevice);
86
87 return bFound;
88}
89
90static void exit() {
91 auto removeCard = [](Device* device, Device* target) {
92 return device == target ? nullptr : device;
93 };
94 auto callback = pedigree_std::make_callable(removeCard);
95 while (g_Cards.count()) {
96 Nic3C90x* card = g_Cards.popFront();
98 Device::foreach (callback, 0, card);
99 }
100 bFound = false;
101}
102
103MODULE_INFO("3c90x", &entry, &exit, "network-stack");
static void foreach(Callback callback, Device *root=0)
Definition Device.cc:107
Device * getParent() const
Definition Device.h:166
void setParent(Device *p)
Definition Device.h:170
void replaceChild(Device *src, Device *dest)
Definition Device.cc:166
Definition List.h:61
void deRegisterDevice(Network *pDevice)
static NetworkStack & instance()