6b13f685e
김민수
BSP 최초 추가
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
#include <linux/device.h>
#include <linux/firewire.h>
#include <linux/firewire-constants.h>
#include <linux/export.h>
#include <linux/jiffies.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/spinlock.h>
#include "iso-resources.h"
int fw_iso_resources_init(struct fw_iso_resources *r, struct fw_unit *unit)
{
r->channels_mask = ~0uLL;
r->unit = fw_unit_get(unit);
mutex_init(&r->mutex);
r->allocated = false;
return 0;
}
EXPORT_SYMBOL(fw_iso_resources_init);
void fw_iso_resources_destroy(struct fw_iso_resources *r)
{
WARN_ON(r->allocated);
mutex_destroy(&r->mutex);
fw_unit_put(r->unit);
}
EXPORT_SYMBOL(fw_iso_resources_destroy);
static unsigned int packet_bandwidth(unsigned int max_payload_bytes, int speed)
{
unsigned int bytes, s400_bytes;
bytes = 3 * 4 + ALIGN(max_payload_bytes, 4);
if (speed <= SCODE_400)
s400_bytes = bytes * (1 << (SCODE_400 - speed));
else
s400_bytes = DIV_ROUND_UP(bytes, 1 << (speed - SCODE_400));
return s400_bytes;
}
static int current_bandwidth_overhead(struct fw_card *card)
{
return card->gap_count < 63 ? card->gap_count * 97 / 10 + 89 : 512;
}
static int wait_isoch_resource_delay_after_bus_reset(struct fw_card *card)
{
for (;;) {
s64 delay = (card->reset_jiffies + HZ) - get_jiffies_64();
if (delay <= 0)
return 0;
if (schedule_timeout_interruptible(delay) > 0)
return -ERESTARTSYS;
}
}
int fw_iso_resources_allocate(struct fw_iso_resources *r,
unsigned int max_payload_bytes, int speed)
{
struct fw_card *card = fw_parent_device(r->unit)->card;
int bandwidth, channel, err;
if (WARN_ON(r->allocated))
return -EBADFD;
r->bandwidth = packet_bandwidth(max_payload_bytes, speed);
retry_after_bus_reset:
spin_lock_irq(&card->lock);
r->generation = card->generation;
r->bandwidth_overhead = current_bandwidth_overhead(card);
spin_unlock_irq(&card->lock);
err = wait_isoch_resource_delay_after_bus_reset(card);
if (err < 0)
return err;
mutex_lock(&r->mutex);
bandwidth = r->bandwidth + r->bandwidth_overhead;
fw_iso_resource_manage(card, r->generation, r->channels_mask,
&channel, &bandwidth, true);
if (channel == -EAGAIN) {
mutex_unlock(&r->mutex);
goto retry_after_bus_reset;
}
if (channel >= 0) {
r->channel = channel;
r->allocated = true;
} else {
if (channel == -EBUSY)
dev_err(&r->unit->device,
"isochronous resources exhausted
");
else
dev_err(&r->unit->device,
"isochronous resource allocation failed
");
}
mutex_unlock(&r->mutex);
return channel;
}
EXPORT_SYMBOL(fw_iso_resources_allocate);
int fw_iso_resources_update(struct fw_iso_resources *r)
{
struct fw_card *card = fw_parent_device(r->unit)->card;
int bandwidth, channel;
mutex_lock(&r->mutex);
if (!r->allocated) {
mutex_unlock(&r->mutex);
return 0;
}
spin_lock_irq(&card->lock);
r->generation = card->generation;
r->bandwidth_overhead = current_bandwidth_overhead(card);
spin_unlock_irq(&card->lock);
bandwidth = r->bandwidth + r->bandwidth_overhead;
fw_iso_resource_manage(card, r->generation, 1uLL << r->channel,
&channel, &bandwidth, true);
if (channel < 0 && channel != -EAGAIN) {
r->allocated = false;
if (channel == -EBUSY)
dev_err(&r->unit->device,
"isochronous resources exhausted
");
else
dev_err(&r->unit->device,
"isochronous resource allocation failed
");
}
mutex_unlock(&r->mutex);
return channel;
}
EXPORT_SYMBOL(fw_iso_resources_update);
void fw_iso_resources_free(struct fw_iso_resources *r)
{
struct fw_card *card = fw_parent_device(r->unit)->card;
int bandwidth, channel;
mutex_lock(&r->mutex);
if (r->allocated) {
bandwidth = r->bandwidth + r->bandwidth_overhead;
fw_iso_resource_manage(card, r->generation, 1uLL << r->channel,
&channel, &bandwidth, false);
if (channel < 0)
dev_err(&r->unit->device,
"isochronous resource deallocation failed
");
r->allocated = false;
}
mutex_unlock(&r->mutex);
}
EXPORT_SYMBOL(fw_iso_resources_free);
|