xref: /haiku/src/add-ons/kernel/drivers/network/wlan/ralinkwifi/glue.c (revision b2acee1cb986b696adfad7daabfe9279949a3e54)
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 
20 #include <dev/ral/rt2560reg.h>
21 #include <dev/ral/rt2560var.h>
22 #include <dev/ral/rt2661var.h>
23 #include <dev/ral/rt2860reg.h>
24 #include <dev/ral/rt2860var.h>
25 
26 
27 HAIKU_FBSD_WLAN_DRIVER_GLUE(ralinkwifi, ral, pci)
28 HAIKU_DRIVER_REQUIREMENTS(FBSD_TASKQUEUES | FBSD_SWI_TASKQUEUE | FBSD_WLAN);
29 HAIKU_FIRMWARE_VERSION(0);
30 HAIKU_FIRMWARE_NAME_MAP(4) = {
31 	{"rt2561fw", "rt2561.bin"},
32 	{"rt2561sfw", "rt2561s.bin"},
33 	{"rt2661fw", "rt2661.bin"},
34 	{"rt2860fw", "rt2860.bin"}
35 };
36 
37 NO_HAIKU_FBSD_MII_DRIVER();
38 NO_HAIKU_REENABLE_INTERRUPTS();
39 
40 
41 #define RT2661_INT_MASK_CSR			0x346c
42 #define RT2661_MCU_INT_MASK_CSR		0x0018
43 
44 
45 int
46 HAIKU_CHECK_DISABLE_INTERRUPTS(device_t dev)
47 {
48 	struct rt2560_softc* sc = (struct rt2560_softc*)device_get_softc(dev);
49 		// sc_ifp is common between context data structures
50 
51 	switch (pci_get_device(dev)) {
52 		case 0x0201:
53 			// disable interrupts
54 			RAL_WRITE(sc, RT2560_CSR8, 0xffffffff);
55 
56 			if (!(sc->sc_flags & RT2560_F_RUNNING)) {
57 				// don't re-enable interrupts if we're shutting down
58 				return 0;
59 			}
60 			break;
61 		case 0x0301:
62 		case 0x0302:
63 		case 0x0401:
64 			// disable MAC and MCU interrupts
65 			RAL_WRITE(sc, RT2661_INT_MASK_CSR, 0xffffff7f);
66 			RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff);
67 
68 			if (!(sc->sc_flags & RAL_RUNNING)) {
69 				// don't re-enable interrupts if we're shutting down
70 				return 0;
71 			}
72 			break;
73 		default:
74 		{
75 			uint32 r;
76 			struct rt2860_softc* sc =
77 				(struct rt2860_softc*)device_get_softc(dev);
78 			r = RAL_READ(sc, RT2860_INT_STATUS);
79 			if (r == 0 || r == 0xffffffff)
80 				return 0;
81 
82 			atomic_set((int32*)&sc->sc_intr_status, r);
83 			break;
84 		}
85 	}
86 
87 	return 1;
88 }
89