• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4  * All rights reserved.
5  *
6  */
7 
8 #include "baseband.h"
9 #include "channel.h"
10 #include "device.h"
11 #include "rf.h"
12 
13 static struct ieee80211_rate vnt_rates_bg[] = {
14 	{ .bitrate = 10,  .hw_value = RATE_1M },
15 	{ .bitrate = 20,  .hw_value = RATE_2M },
16 	{ .bitrate = 55,  .hw_value = RATE_5M },
17 	{ .bitrate = 110, .hw_value = RATE_11M },
18 	{ .bitrate = 60,  .hw_value = RATE_6M },
19 	{ .bitrate = 90,  .hw_value = RATE_9M },
20 	{ .bitrate = 120, .hw_value = RATE_12M },
21 	{ .bitrate = 180, .hw_value = RATE_18M },
22 	{ .bitrate = 240, .hw_value = RATE_24M },
23 	{ .bitrate = 360, .hw_value = RATE_36M },
24 	{ .bitrate = 480, .hw_value = RATE_48M },
25 	{ .bitrate = 540, .hw_value = RATE_54M },
26 };
27 
28 static struct ieee80211_rate vnt_rates_a[] = {
29 	{ .bitrate = 60,  .hw_value = RATE_6M },
30 	{ .bitrate = 90,  .hw_value = RATE_9M },
31 	{ .bitrate = 120, .hw_value = RATE_12M },
32 	{ .bitrate = 180, .hw_value = RATE_18M },
33 	{ .bitrate = 240, .hw_value = RATE_24M },
34 	{ .bitrate = 360, .hw_value = RATE_36M },
35 	{ .bitrate = 480, .hw_value = RATE_48M },
36 	{ .bitrate = 540, .hw_value = RATE_54M },
37 };
38 
39 static struct ieee80211_channel vnt_channels_2ghz[] = {
40 	{ .center_freq = 2412, .hw_value = 1 },
41 	{ .center_freq = 2417, .hw_value = 2 },
42 	{ .center_freq = 2422, .hw_value = 3 },
43 	{ .center_freq = 2427, .hw_value = 4 },
44 	{ .center_freq = 2432, .hw_value = 5 },
45 	{ .center_freq = 2437, .hw_value = 6 },
46 	{ .center_freq = 2442, .hw_value = 7 },
47 	{ .center_freq = 2447, .hw_value = 8 },
48 	{ .center_freq = 2452, .hw_value = 9 },
49 	{ .center_freq = 2457, .hw_value = 10 },
50 	{ .center_freq = 2462, .hw_value = 11 },
51 	{ .center_freq = 2467, .hw_value = 12 },
52 	{ .center_freq = 2472, .hw_value = 13 },
53 	{ .center_freq = 2484, .hw_value = 14 }
54 };
55 
56 static struct ieee80211_channel vnt_channels_5ghz[] = {
57 	{ .center_freq = 4915, .hw_value = 15 },
58 	{ .center_freq = 4920, .hw_value = 16 },
59 	{ .center_freq = 4925, .hw_value = 17 },
60 	{ .center_freq = 4935, .hw_value = 18 },
61 	{ .center_freq = 4940, .hw_value = 19 },
62 	{ .center_freq = 4945, .hw_value = 20 },
63 	{ .center_freq = 4960, .hw_value = 21 },
64 	{ .center_freq = 4980, .hw_value = 22 },
65 	{ .center_freq = 5035, .hw_value = 23 },
66 	{ .center_freq = 5040, .hw_value = 24 },
67 	{ .center_freq = 5045, .hw_value = 25 },
68 	{ .center_freq = 5055, .hw_value = 26 },
69 	{ .center_freq = 5060, .hw_value = 27 },
70 	{ .center_freq = 5080, .hw_value = 28 },
71 	{ .center_freq = 5170, .hw_value = 29 },
72 	{ .center_freq = 5180, .hw_value = 30 },
73 	{ .center_freq = 5190, .hw_value = 31 },
74 	{ .center_freq = 5200, .hw_value = 32 },
75 	{ .center_freq = 5210, .hw_value = 33 },
76 	{ .center_freq = 5220, .hw_value = 34 },
77 	{ .center_freq = 5230, .hw_value = 35 },
78 	{ .center_freq = 5240, .hw_value = 36 },
79 	{ .center_freq = 5260, .hw_value = 37 },
80 	{ .center_freq = 5280, .hw_value = 38 },
81 	{ .center_freq = 5300, .hw_value = 39 },
82 	{ .center_freq = 5320, .hw_value = 40 },
83 	{ .center_freq = 5500, .hw_value = 41 },
84 	{ .center_freq = 5520, .hw_value = 42 },
85 	{ .center_freq = 5540, .hw_value = 43 },
86 	{ .center_freq = 5560, .hw_value = 44 },
87 	{ .center_freq = 5580, .hw_value = 45 },
88 	{ .center_freq = 5600, .hw_value = 46 },
89 	{ .center_freq = 5620, .hw_value = 47 },
90 	{ .center_freq = 5640, .hw_value = 48 },
91 	{ .center_freq = 5660, .hw_value = 49 },
92 	{ .center_freq = 5680, .hw_value = 50 },
93 	{ .center_freq = 5700, .hw_value = 51 },
94 	{ .center_freq = 5745, .hw_value = 52 },
95 	{ .center_freq = 5765, .hw_value = 53 },
96 	{ .center_freq = 5785, .hw_value = 54 },
97 	{ .center_freq = 5805, .hw_value = 55 },
98 	{ .center_freq = 5825, .hw_value = 56 }
99 };
100 
101 static struct ieee80211_supported_band vnt_supported_2ghz_band = {
102 	.channels = vnt_channels_2ghz,
103 	.n_channels = ARRAY_SIZE(vnt_channels_2ghz),
104 	.bitrates = vnt_rates_bg,
105 	.n_bitrates = ARRAY_SIZE(vnt_rates_bg),
106 };
107 
108 static struct ieee80211_supported_band vnt_supported_5ghz_band = {
109 	.channels = vnt_channels_5ghz,
110 	.n_channels = ARRAY_SIZE(vnt_channels_5ghz),
111 	.bitrates = vnt_rates_a,
112 	.n_bitrates = ARRAY_SIZE(vnt_rates_a),
113 };
114 
vnt_init_band(struct vnt_private * priv,struct ieee80211_supported_band * supported_band,enum nl80211_band band)115 static void vnt_init_band(struct vnt_private *priv,
116 			  struct ieee80211_supported_band *supported_band,
117 			  enum nl80211_band band)
118 {
119 	int i;
120 
121 	for (i = 0; i < supported_band->n_channels; i++) {
122 		supported_band->channels[i].max_power = 0x3f;
123 		supported_band->channels[i].flags =
124 			IEEE80211_CHAN_NO_HT40;
125 	}
126 
127 	priv->hw->wiphy->bands[band] = supported_band;
128 }
129 
vnt_init_bands(struct vnt_private * priv)130 void vnt_init_bands(struct vnt_private *priv)
131 {
132 	switch (priv->byRFType) {
133 	case RF_AIROHA7230:
134 	case RF_UW2452:
135 	case RF_NOTHING:
136 	default:
137 		vnt_init_band(priv, &vnt_supported_5ghz_band,
138 			      NL80211_BAND_5GHZ);
139 		fallthrough;
140 	case RF_RFMD2959:
141 	case RF_AIROHA:
142 	case RF_AL2230S:
143 	case RF_UW2451:
144 	case RF_VT3226:
145 		vnt_init_band(priv, &vnt_supported_2ghz_band,
146 			      NL80211_BAND_2GHZ);
147 		break;
148 	}
149 }
150 
151 /**
152  * set_channel() - Set NIC media channel
153  *
154  * @priv: The adapter to be set
155  * @ch: Channel to be set
156  *
157  * Return Value: true if succeeded; false if failed.
158  *
159  */
set_channel(struct vnt_private * priv,struct ieee80211_channel * ch)160 bool set_channel(struct vnt_private *priv, struct ieee80211_channel *ch)
161 {
162 	bool ret = true;
163 
164 	if (priv->byCurrentCh == ch->hw_value)
165 		return ret;
166 
167 	/* Set VGA to max sensitivity */
168 	if (priv->bUpdateBBVGA &&
169 	    priv->byBBVGACurrent != priv->abyBBVGA[0]) {
170 		priv->byBBVGACurrent = priv->abyBBVGA[0];
171 
172 		bb_set_vga_gain_offset(priv, priv->byBBVGACurrent);
173 	}
174 
175 	/* clear NAV */
176 	MACvRegBitsOn(priv->PortOffset, MAC_REG_MACCR, MACCR_CLRNAV);
177 
178 	/* TX_PE will reserve 3 us for MAX2829 A mode only,
179 	 * it is for better TX throughput
180 	 */
181 
182 	if (priv->byRFType == RF_AIROHA7230)
183 		RFbAL7230SelectChannelPostProcess(priv, priv->byCurrentCh,
184 						  ch->hw_value);
185 
186 	priv->byCurrentCh = ch->hw_value;
187 	ret &= RFbSelectChannel(priv, priv->byRFType,
188 				ch->hw_value);
189 
190 	/* Init Synthesizer Table */
191 	if (priv->bEnablePSMode)
192 		RFvWriteWakeProgSyn(priv, priv->byRFType, ch->hw_value);
193 
194 	bb_software_reset(priv);
195 
196 	if (priv->byLocalID > REV_ID_VT3253_B1) {
197 		unsigned long flags;
198 
199 		spin_lock_irqsave(&priv->lock, flags);
200 
201 		/* set HW default power register */
202 		MACvSelectPage1(priv->PortOffset);
203 		RFbSetPower(priv, RATE_1M, priv->byCurrentCh);
204 		VNSvOutPortB(priv->PortOffset + MAC_REG_PWRCCK,
205 			     priv->byCurPwr);
206 		RFbSetPower(priv, RATE_6M, priv->byCurrentCh);
207 		VNSvOutPortB(priv->PortOffset + MAC_REG_PWROFDM,
208 			     priv->byCurPwr);
209 		MACvSelectPage0(priv->PortOffset);
210 
211 		spin_unlock_irqrestore(&priv->lock, flags);
212 	}
213 
214 	if (priv->byBBType == BB_TYPE_11B)
215 		RFbSetPower(priv, RATE_1M, priv->byCurrentCh);
216 	else
217 		RFbSetPower(priv, RATE_6M, priv->byCurrentCh);
218 
219 	return ret;
220 }
221