xref: /haiku/src/add-ons/kernel/drivers/network/wlan/ralinkwifi/glue.c (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
1 /*
2  * Copyright 2009, Colin Günther, coling@gmx.de.
3  * All Rights Reserved. Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <sys/bus.h>
8 #include <sys/kernel.h>
9 
10 #include <dev/pci/pcivar.h>
11 
12 #include <machine/bus.h>
13 
14 #include <net/if.h>
15 #include <net/if_media.h>
16 
17 #include <net80211/ieee80211_var.h>
18 #include <net80211/ieee80211_amrr.h>
19 #include <net80211/ieee80211_ratectl.h>
20 
21 #include <dev/ral/rt2560reg.h>
22 #include <dev/ral/rt2560var.h>
23 #include <dev/ral/rt2661var.h>
24 #include <dev/ral/rt2860reg.h>
25 #include <dev/ral/rt2860var.h>
26 
27 
28 HAIKU_FBSD_WLAN_DRIVERS_GLUE(ralinkwifi)
29 HAIKU_DRIVER_REQUIREMENTS(FBSD_WLAN);
30 HAIKU_FIRMWARE_VERSION(0);
31 HAIKU_FIRMWARE_NAME_MAP({
32 	{"rt2561fw", "rt2561.ucode"},
33 	{"rt2561sfw", "rt2561s.ucode"},
34 	{"rt2661fw", "rt2661.ucode"},
35 	{"rt2860fw", "rt2860.ucode"},
36 	{"runfw", "rt2870.ucode"},
37 });
38 
39 NO_HAIKU_FBSD_MII_DRIVER();
40 NO_HAIKU_REENABLE_INTERRUPTS();
41 
42 extern driver_t* DRIVER_MODULE_NAME(ral, pci);
43 extern driver_t* DRIVER_MODULE_NAME(ural, uhub);
44 extern driver_t* DRIVER_MODULE_NAME(run, uhub);
45 extern driver_t* DRIVER_MODULE_NAME(rum, uhub);
46 
47 
48 status_t
49 __haiku_handle_fbsd_drivers_list(status_t (*handler)(driver_t *[], driver_t *[]))
50 {
51 	driver_t *pci_drivers[] = {
52 		DRIVER_MODULE_NAME(ral, pci),
53 		NULL
54 	};
55 	driver_t *usb_drivers[] = {
56 		DRIVER_MODULE_NAME(ural, uhub),
57 		DRIVER_MODULE_NAME(run, uhub),
58 		DRIVER_MODULE_NAME(rum, uhub),
59 		NULL
60 	};
61 	return (*handler)(pci_drivers, usb_drivers);
62 }
63 
64 
65 #define RT2661_INT_MASK_CSR			0x346c
66 #define RT2661_MCU_INT_MASK_CSR		0x0018
67 
68 
69 int
70 HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev)
71 {
72 	struct rt2560_softc* sc = (struct rt2560_softc*)device_get_softc(dev);
73 		// sc_ifp is common between context data structures
74 
75 	switch (pci_get_device(dev)) {
76 		case 0x0201:
77 			// disable interrupts
78 			RAL_WRITE(sc, RT2560_CSR8, 0xffffffff);
79 
80 			if (!(sc->sc_flags & RT2560_F_RUNNING)) {
81 				// don't re-enable interrupts if we're shutting down
82 				return 0;
83 			}
84 			break;
85 		case 0x0301:
86 		case 0x0302:
87 		case 0x0401:
88 			// disable MAC and MCU interrupts
89 			RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0xffffff7f);
90 			RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff);
91 
92 			if (!(sc->sc_flags & RAL_RUNNING)) {
93 				// don't re-enable interrupts if we're shutting down
94 				return 0;
95 			}
96 			break;
97 		default:
98 		{
99 			uint32 r;
100 			struct rt2860_softc* sc =
101 				(struct rt2860_softc*)device_get_softc(dev);
102 			r = RAL_READ(sc, RT2860_INT_STATUS);
103 			if (r == 0 || r == 0xffffffff)
104 				return 0;
105 
106 			atomic_set((int32*)&sc->sc_intr_status, r);
107 			break;
108 		}
109 	}
110 
111 	return 1;
112 }
113