1 /*
2 * Copyright (c) 2013-2023 Ali Mashtizadeh
3 * All rights reserved.
4 */
5
6 #include <stdbool.h>
7 #include <stdint.h>
8
9 #include <sys/kassert.h>
10 #include <sys/kdebug.h>
11 #include <sys/queue.h>
12 #include <sys/mbuf.h>
13 #include <sys/nic.h>
14 #include <sys/spinlock.h>
15
16 LIST_HEAD(NICList, NIC) nicList = LIST_HEAD_INITIALIZER(nicList);
17 uint64_t nextNICNo = 0;
18
19 void
NIC_AddNIC(NIC * nic)20 NIC_AddNIC(NIC *nic)
21 {
22 nic->nicNo = nextNICNo++;
23 LIST_INSERT_HEAD(&nicList, nic, entries);
24 }
25
26 void
NIC_RemoveNIC(NIC * nic)27 NIC_RemoveNIC(NIC *nic)
28 {
29 LIST_REMOVE(nic, entries);
30 }
31
32 NIC *
NIC_GetByID(uint64_t nicNo)33 NIC_GetByID(uint64_t nicNo)
34 {
35 NIC *n;
36
37 LIST_FOREACH(n, &nicList, entries) {
38 if (n->nicNo == nicNo)
39 return n;
40 }
41
42 return NULL;
43 }
44
45 void
Debug_NICs(int argc,const char * argv[])46 Debug_NICs(int argc, const char *argv[])
47 {
48 NIC *n;
49
50 LIST_FOREACH(n, &nicList, entries) {
51 kprintf("nic%lld: %02x:%02x:%02x:%02x:%02x:%02x\n", n->nicNo,
52 n->mac[0], n->mac[1], n->mac[2], n->mac[3], n->mac[4], n->mac[5]);
53 }
54 }
55
56 REGISTER_DBGCMD(nics, "List NICs", Debug_NICs);
57
58