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 "3Com90x.h"
21 #include "modules/Module.h"
22 #include "pedigree/kernel/machine/Device.h"
23 #include "pedigree/kernel/processor/types.h"
24 #include "pedigree/kernel/utilities/new"
25 
26 class Network;
27 
28 struct nic
29 {
30  uint16_t vendor, device;
31  const char *type;
32  const char *desc;
33 };
34 
35 static struct nic potential_nics[] = {
36  /* Original 90x revisions: */
37  {0x10b7, 0x9000, "3c905-tpo", "3Com900-TPO"}, /* 10 Base TPO */
38  {0x10b7, 0x9001, "3c905-t4", "3Com900-Combo"}, /* 10/100 T4 */
39  {0x10b7, 0x9050, "3c905-tpo100",
40  "3Com905-TX"}, /* 100 Base TX / 10/100 TPO */
41  {0x10b7, 0x9051, "3c905-combo",
42  "3Com905-T4"}, /* 100 Base T4 / 10 Base Combo */
43  /* Newer 90xB revisions: */
44  {0x10b7, 0x9004, "3c905b-tpo", "3Com900B-TPO"}, /* 10 Base TPO */
45  {0x10b7, 0x9005, "3c905b-combo", "3Com900B-Combo"}, /* 10 Base Combo */
46  {0x10b7, 0x9006, "3c905b-tpb2", "3Com900B-2/T"}, /* 10 Base TP and Base2 */
47  {0x10b7, 0x900a, "3c905b-fl", "3Com900B-FL"}, /* 10 Base FL */
48  {0x10b7, 0x9055, "3c905b-tpo100", "3Com905B-TX"}, /* 10/100 TPO */
49  {0x10b7, 0x9056, "3c905b-t4", "3Com905B-T4"}, /* 10/100 T4 */
50  {0x10b7, 0x9058, "3c905b-9058", "3Com905B-9058"}, /* Cyclone 10/100/BNC */
51  {0x10b7, 0x905a, "3c905b-fx", "3Com905B-FL"}, /* 100 Base FX / 10 Base FX */
52  /* Newer 90xC revision: */
53  {0x10b7, 0x9200, "3c905c-tpo",
54  "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 
63 static bool bFound = false;
64 
65 static void probeDevice(Device *pDev)
66 {
67  bFound = true;
68 
69  // Create a new node
70  Nic3C90x *pCard = new Nic3C90x(reinterpret_cast<Network *>(pDev));
71 
72  // Replace pDev with pCard
73  pCard->setParent(pDev->getParent());
74  pDev->getParent()->replaceChild(pDev, pCard);
75 }
76 
77 static bool entry()
78 {
79  for (unsigned int i = 0; i < NUM_POTENTIAL_NICS; i++)
80  Device::searchByVendorIdAndDeviceId(
81  potential_nics[i].vendor, potential_nics[i].device, probeDevice);
82 
83  return bFound;
84 }
85 
86 static void exit()
87 {
88 }
89 
90 MODULE_INFO("3c90x", &entry, &exit, "network-stack");
void replaceChild(Device *src, Device *dest)
Definition: Device.cc:168
Definition: Device.h:43
void setParent(Device *p)
Definition: Device.h:154
Device * getParent() const
Definition: Device.h:149