xref: /haiku/src/add-ons/kernel/drivers/network/ether/dec21xxx/glue.c (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
1 /*
2  * Copyright 2011, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Author(s):
6  *		Axel Dörfler <axeld@pinc-software.de>
7  *		Siarzhuk Zharski <imker@gmx.li>
8  */
9 
10 
11 #include <sys/bus.h>
12 #include <sys/mutex.h>
13 #include <sys/systm.h>
14 #include <machine/bus.h>
15 #include <shared.h>
16 
17 #include <net/if.h>
18 #include <net/if_var.h>
19 
20 #include "if_dcreg.h"
21 
22 
23 HAIKU_FBSD_DRIVERS_GLUE(dec21xxx);
24 HAIKU_DRIVER_REQUIREMENTS(0);
25 
26 
27 int check_disable_interrupts_dc(device_t dev);
28 void reenable_interrupts_dc(device_t dev);
29 
30 extern int check_disable_interrupts_de(device_t dev);
31 extern void reenable_interrupts_de(device_t dev);
32 
33 
34 extern driver_t *DRIVER_MODULE_NAME(dc, pci);
35 extern driver_t *DRIVER_MODULE_NAME(de, pci);
36 
37 status_t
38 __haiku_handle_fbsd_drivers_list(status_t (*handler)(driver_t *[], driver_t *[]))
39 {
40 	driver_t *drivers[] = {
41 		DRIVER_MODULE_NAME(dc, pci),
42 		DRIVER_MODULE_NAME(de, pci),
43 		NULL
44 	};
45 	return (*handler)(drivers, NULL);
46 }
47 
48 
49 extern driver_t *DRIVER_MODULE_NAME(acphy, miibus);
50 extern driver_t *DRIVER_MODULE_NAME(amphy, miibus);
51 extern driver_t *DRIVER_MODULE_NAME(dcphy, miibus);
52 extern driver_t *DRIVER_MODULE_NAME(pnphy, miibus);
53 extern driver_t *DRIVER_MODULE_NAME(ukphy, miibus);
54 
55 driver_t *
56 __haiku_select_miibus_driver(device_t dev)
57 {
58 	driver_t *drivers[] = {
59 		DRIVER_MODULE_NAME(acphy, miibus),
60 		DRIVER_MODULE_NAME(amphy, miibus),
61 		DRIVER_MODULE_NAME(dcphy, miibus),
62 		DRIVER_MODULE_NAME(pnphy, miibus),
63 		DRIVER_MODULE_NAME(ukphy, miibus),
64 		NULL
65 	};
66 
67 	return __haiku_probe_miibus(dev, drivers);
68 }
69 
70 
71 int
72 HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev)
73 {
74 	uint16 name = *(uint16*)dev->device_name;
75 	switch (name) {
76 		case 'cd':
77 			return check_disable_interrupts_dc(dev);
78 		case 'ed':
79 			return check_disable_interrupts_de(dev);
80 		default:
81 			break;
82 	}
83 
84 	panic("Unsupported device: %#x (%s)!", name, dev->device_name);
85 	return 0;
86 }
87 
88 
89 void
90 HAIKU_REENABLE_INTERRUPTS(device_t dev)
91 {
92 	uint16 name = *(uint16*)dev->device_name;
93 	switch (name) {
94 		case 'cd':
95 			reenable_interrupts_dc(dev);
96 			break;
97 		case 'ed':
98 			reenable_interrupts_de(dev);
99 			break;
100 		default:
101 			panic("Unsupported device: %#x (%s)!", name, dev->device_name);
102 			break;
103 	}
104 }
105 
106 
107 int
108 check_disable_interrupts_dc(device_t dev)
109 {
110 	struct dc_softc *sc = device_get_softc(dev);
111 	uint16_t status;
112 	HAIKU_INTR_REGISTER_STATE;
113 
114 	HAIKU_INTR_REGISTER_ENTER();
115 
116 	status = CSR_READ_4(sc, DC_ISR);
117 	if (status == 0xffff) {
118 		HAIKU_INTR_REGISTER_LEAVE();
119 		return 0;
120 	}
121 
122 	if (status != 0 && (status & DC_INTRS) == 0) {
123 		CSR_WRITE_4(sc, DC_ISR, status);
124 		HAIKU_INTR_REGISTER_LEAVE();
125 		return 0;
126 	}
127 
128 	if ((status & DC_INTRS) == 0) {
129 		HAIKU_INTR_REGISTER_LEAVE();
130 		return 0;
131 	}
132 
133 	CSR_WRITE_4(sc, DC_IMR, 0);
134 
135 	HAIKU_INTR_REGISTER_LEAVE();
136 
137 	return 1;
138 }
139 
140 
141 void
142 reenable_interrupts_dc(device_t dev)
143 {
144 	struct dc_softc *sc = device_get_softc(dev);
145 	DC_LOCK(sc);
146 	CSR_WRITE_4(sc, DC_IMR, DC_INTRS);
147 	DC_UNLOCK(sc);
148 }
149 
150