Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * IEEE 1394 for Linux | |
3 | * | |
4 | * Transaction support. | |
5 | * | |
6 | * Copyright (C) 1999 Andreas E. Bombe | |
7 | * | |
8 | * This code is licensed under the GPL. See the file COPYING in the root | |
9 | * directory of the kernel sources for details. | |
10 | */ | |
11 | ||
1da177e4 | 12 | #include <linux/bitops.h> |
7fb9addb | 13 | #include <linux/hardirq.h> |
9951903e | 14 | #include <linux/spinlock.h> |
3a23a81e | 15 | #include <linux/sched.h> /* because linux/wait.h is broken if CONFIG_SMP=n */ |
9951903e | 16 | #include <linux/wait.h> |
1da177e4 | 17 | |
d83e7d8e | 18 | #include <asm/bug.h> |
1da177e4 LT |
19 | #include <asm/errno.h> |
20 | ||
21 | #include "ieee1394.h" | |
22 | #include "ieee1394_types.h" | |
23 | #include "hosts.h" | |
24 | #include "ieee1394_core.h" | |
e27d3014 | 25 | #include "ieee1394_transactions.h" |
1da177e4 | 26 | |
1da177e4 LT |
27 | #define PREP_ASYNC_HEAD_ADDRESS(tc) \ |
28 | packet->tcode = tc; \ | |
29 | packet->header[0] = (packet->node_id << 16) | (packet->tlabel << 10) \ | |
30 | | (1 << 8) | (tc << 4); \ | |
31 | packet->header[1] = (packet->host->node_id << 16) | (addr >> 32); \ | |
32 | packet->header[2] = addr & 0xffffffff | |
33 | ||
9951903e SR |
34 | #ifndef HPSB_DEBUG_TLABELS |
35 | static | |
36 | #endif | |
37 | spinlock_t hpsb_tlabel_lock = SPIN_LOCK_UNLOCKED; | |
38 | ||
39 | static DECLARE_WAIT_QUEUE_HEAD(tlabel_wq); | |
40 | ||
1da177e4 LT |
41 | static void fill_async_readquad(struct hpsb_packet *packet, u64 addr) |
42 | { | |
16c333a3 JMH |
43 | PREP_ASYNC_HEAD_ADDRESS(TCODE_READQ); |
44 | packet->header_size = 12; | |
45 | packet->data_size = 0; | |
46 | packet->expect_response = 1; | |
1da177e4 LT |
47 | } |
48 | ||
16c333a3 JMH |
49 | static void fill_async_readblock(struct hpsb_packet *packet, u64 addr, |
50 | int length) | |
1da177e4 | 51 | { |
16c333a3 JMH |
52 | PREP_ASYNC_HEAD_ADDRESS(TCODE_READB); |
53 | packet->header[3] = length << 16; | |
54 | packet->header_size = 16; | |
55 | packet->data_size = 0; | |
56 | packet->expect_response = 1; | |
1da177e4 LT |
57 | } |
58 | ||
16c333a3 JMH |
59 | static void fill_async_writequad(struct hpsb_packet *packet, u64 addr, |
60 | quadlet_t data) | |
1da177e4 | 61 | { |
16c333a3 JMH |
62 | PREP_ASYNC_HEAD_ADDRESS(TCODE_WRITEQ); |
63 | packet->header[3] = data; | |
64 | packet->header_size = 16; | |
65 | packet->data_size = 0; | |
66 | packet->expect_response = 1; | |
1da177e4 LT |
67 | } |
68 | ||
16c333a3 JMH |
69 | static void fill_async_writeblock(struct hpsb_packet *packet, u64 addr, |
70 | int length) | |
1da177e4 | 71 | { |
16c333a3 JMH |
72 | PREP_ASYNC_HEAD_ADDRESS(TCODE_WRITEB); |
73 | packet->header[3] = length << 16; | |
74 | packet->header_size = 16; | |
75 | packet->expect_response = 1; | |
76 | packet->data_size = length + (length % 4 ? 4 - (length % 4) : 0); | |
1da177e4 LT |
77 | } |
78 | ||
79 | static void fill_async_lock(struct hpsb_packet *packet, u64 addr, int extcode, | |
16c333a3 | 80 | int length) |
1da177e4 | 81 | { |
16c333a3 JMH |
82 | PREP_ASYNC_HEAD_ADDRESS(TCODE_LOCK_REQUEST); |
83 | packet->header[3] = (length << 16) | extcode; | |
84 | packet->header_size = 16; | |
85 | packet->data_size = length; | |
86 | packet->expect_response = 1; | |
1da177e4 LT |
87 | } |
88 | ||
89 | static void fill_iso_packet(struct hpsb_packet *packet, int length, int channel, | |
16c333a3 | 90 | int tag, int sync) |
1da177e4 | 91 | { |
16c333a3 JMH |
92 | packet->header[0] = (length << 16) | (tag << 14) | (channel << 8) |
93 | | (TCODE_ISO_DATA << 4) | sync; | |
1da177e4 | 94 | |
16c333a3 JMH |
95 | packet->header_size = 4; |
96 | packet->data_size = length; | |
97 | packet->type = hpsb_iso; | |
98 | packet->tcode = TCODE_ISO_DATA; | |
1da177e4 LT |
99 | } |
100 | ||
101 | static void fill_phy_packet(struct hpsb_packet *packet, quadlet_t data) | |
102 | { | |
16c333a3 JMH |
103 | packet->header[0] = data; |
104 | packet->header[1] = ~data; | |
105 | packet->header_size = 8; | |
106 | packet->data_size = 0; | |
107 | packet->expect_response = 0; | |
108 | packet->type = hpsb_raw; /* No CRC added */ | |
109 | packet->speed_code = IEEE1394_SPEED_100; /* Force speed to be 100Mbps */ | |
1da177e4 LT |
110 | } |
111 | ||
112 | static void fill_async_stream_packet(struct hpsb_packet *packet, int length, | |
113 | int channel, int tag, int sync) | |
114 | { | |
115 | packet->header[0] = (length << 16) | (tag << 14) | (channel << 8) | |
16c333a3 | 116 | | (TCODE_STREAM_DATA << 4) | sync; |
1da177e4 LT |
117 | |
118 | packet->header_size = 4; | |
119 | packet->data_size = length; | |
120 | packet->type = hpsb_async; | |
121 | packet->tcode = TCODE_ISO_DATA; | |
122 | } | |
123 | ||
9951903e SR |
124 | /* same as hpsb_get_tlabel, except that it returns immediately */ |
125 | static int hpsb_get_tlabel_atomic(struct hpsb_packet *packet) | |
126 | { | |
127 | unsigned long flags, *tp; | |
128 | u8 *next; | |
129 | int tlabel, n = NODEID_TO_NODE(packet->node_id); | |
130 | ||
131 | /* Broadcast transactions are complete once the request has been sent. | |
132 | * Use the same transaction label for all broadcast transactions. */ | |
133 | if (unlikely(n == ALL_NODES)) { | |
134 | packet->tlabel = 0; | |
135 | return 0; | |
136 | } | |
137 | tp = packet->host->tl_pool[n].map; | |
138 | next = &packet->host->next_tl[n]; | |
139 | ||
140 | spin_lock_irqsave(&hpsb_tlabel_lock, flags); | |
141 | tlabel = find_next_zero_bit(tp, 64, *next); | |
142 | if (tlabel > 63) | |
143 | tlabel = find_first_zero_bit(tp, 64); | |
144 | if (tlabel > 63) { | |
145 | spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); | |
146 | return -EAGAIN; | |
147 | } | |
148 | __set_bit(tlabel, tp); | |
149 | *next = (tlabel + 1) & 63; | |
150 | spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); | |
151 | ||
152 | packet->tlabel = tlabel; | |
153 | return 0; | |
154 | } | |
155 | ||
1da177e4 LT |
156 | /** |
157 | * hpsb_get_tlabel - allocate a transaction label | |
9951903e | 158 | * @packet: the packet whose tlabel and tl_pool we set |
1da177e4 LT |
159 | * |
160 | * Every asynchronous transaction on the 1394 bus needs a transaction | |
161 | * label to match the response to the request. This label has to be | |
162 | * different from any other transaction label in an outstanding request to | |
163 | * the same node to make matching possible without ambiguity. | |
164 | * | |
165 | * There are 64 different tlabels, so an allocated tlabel has to be freed | |
166 | * with hpsb_free_tlabel() after the transaction is complete (unless it's | |
167 | * reused again for the same target node). | |
168 | * | |
169 | * Return value: Zero on success, otherwise non-zero. A non-zero return | |
170 | * generally means there are no available tlabels. If this is called out | |
171 | * of interrupt or atomic context, then it will sleep until can return a | |
9951903e | 172 | * tlabel or a signal is received. |
1da177e4 LT |
173 | */ |
174 | int hpsb_get_tlabel(struct hpsb_packet *packet) | |
175 | { | |
9951903e SR |
176 | if (irqs_disabled() || in_atomic()) |
177 | return hpsb_get_tlabel_atomic(packet); | |
178 | ||
179 | /* NB: The macro wait_event_interruptible() is called with a condition | |
180 | * argument with side effect. This is only possible because the side | |
181 | * effect does not occur until the condition became true, and | |
182 | * wait_event_interruptible() won't evaluate the condition again after | |
183 | * that. */ | |
184 | return wait_event_interruptible(tlabel_wq, | |
185 | !hpsb_get_tlabel_atomic(packet)); | |
1da177e4 LT |
186 | } |
187 | ||
188 | /** | |
189 | * hpsb_free_tlabel - free an allocated transaction label | |
9951903e | 190 | * @packet: packet whose tlabel and tl_pool needs to be cleared |
1da177e4 LT |
191 | * |
192 | * Frees the transaction label allocated with hpsb_get_tlabel(). The | |
193 | * tlabel has to be freed after the transaction is complete (i.e. response | |
194 | * was received for a split transaction or packet was sent for a unified | |
195 | * transaction). | |
196 | * | |
197 | * A tlabel must not be freed twice. | |
198 | */ | |
199 | void hpsb_free_tlabel(struct hpsb_packet *packet) | |
200 | { | |
9951903e SR |
201 | unsigned long flags, *tp; |
202 | int tlabel, n = NODEID_TO_NODE(packet->node_id); | |
1da177e4 | 203 | |
eaf88450 BC |
204 | if (unlikely(n == ALL_NODES)) |
205 | return; | |
9951903e SR |
206 | tp = packet->host->tl_pool[n].map; |
207 | tlabel = packet->tlabel; | |
208 | BUG_ON(tlabel > 63 || tlabel < 0); | |
1da177e4 | 209 | |
9951903e SR |
210 | spin_lock_irqsave(&hpsb_tlabel_lock, flags); |
211 | BUG_ON(!__test_and_clear_bit(tlabel, tp)); | |
212 | spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); | |
1da177e4 | 213 | |
9951903e | 214 | wake_up_interruptible(&tlabel_wq); |
1da177e4 LT |
215 | } |
216 | ||
afd6546d SR |
217 | /** |
218 | * hpsb_packet_success - Make sense of the ack and reply codes | |
219 | * | |
220 | * Make sense of the ack and reply codes and return more convenient error codes: | |
221 | * 0 = success. -%EBUSY = node is busy, try again. -%EAGAIN = error which can | |
222 | * probably resolved by retry. -%EREMOTEIO = node suffers from an internal | |
223 | * error. -%EACCES = this transaction is not allowed on requested address. | |
224 | * -%EINVAL = invalid address at node. | |
225 | */ | |
1da177e4 LT |
226 | int hpsb_packet_success(struct hpsb_packet *packet) |
227 | { | |
16c333a3 JMH |
228 | switch (packet->ack_code) { |
229 | case ACK_PENDING: | |
230 | switch ((packet->header[1] >> 12) & 0xf) { | |
231 | case RCODE_COMPLETE: | |
232 | return 0; | |
233 | case RCODE_CONFLICT_ERROR: | |
234 | return -EAGAIN; | |
235 | case RCODE_DATA_ERROR: | |
236 | return -EREMOTEIO; | |
237 | case RCODE_TYPE_ERROR: | |
238 | return -EACCES; | |
239 | case RCODE_ADDRESS_ERROR: | |
240 | return -EINVAL; | |
241 | default: | |
242 | HPSB_ERR("received reserved rcode %d from node %d", | |
243 | (packet->header[1] >> 12) & 0xf, | |
244 | packet->node_id); | |
245 | return -EAGAIN; | |
246 | } | |
d83e7d8e | 247 | BUG(); |
16c333a3 JMH |
248 | |
249 | case ACK_BUSY_X: | |
250 | case ACK_BUSY_A: | |
251 | case ACK_BUSY_B: | |
252 | return -EBUSY; | |
253 | ||
254 | case ACK_TYPE_ERROR: | |
255 | return -EACCES; | |
256 | ||
257 | case ACK_COMPLETE: | |
258 | if (packet->tcode == TCODE_WRITEQ | |
259 | || packet->tcode == TCODE_WRITEB) { | |
260 | return 0; | |
261 | } else { | |
262 | HPSB_ERR("impossible ack_complete from node %d " | |
263 | "(tcode %d)", packet->node_id, packet->tcode); | |
264 | return -EAGAIN; | |
265 | } | |
266 | ||
267 | case ACK_DATA_ERROR: | |
268 | if (packet->tcode == TCODE_WRITEB | |
269 | || packet->tcode == TCODE_LOCK_REQUEST) { | |
270 | return -EAGAIN; | |
271 | } else { | |
272 | HPSB_ERR("impossible ack_data_error from node %d " | |
273 | "(tcode %d)", packet->node_id, packet->tcode); | |
274 | return -EAGAIN; | |
275 | } | |
276 | ||
277 | case ACK_ADDRESS_ERROR: | |
278 | return -EINVAL; | |
279 | ||
280 | case ACK_TARDY: | |
281 | case ACK_CONFLICT_ERROR: | |
282 | case ACKX_NONE: | |
283 | case ACKX_SEND_ERROR: | |
284 | case ACKX_ABORTED: | |
285 | case ACKX_TIMEOUT: | |
286 | /* error while sending */ | |
287 | return -EAGAIN; | |
288 | ||
289 | default: | |
290 | HPSB_ERR("got invalid ack %d from node %d (tcode %d)", | |
291 | packet->ack_code, packet->node_id, packet->tcode); | |
292 | return -EAGAIN; | |
293 | } | |
d83e7d8e | 294 | BUG(); |
1da177e4 LT |
295 | } |
296 | ||
297 | struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node, | |
298 | u64 addr, size_t length) | |
299 | { | |
16c333a3 | 300 | struct hpsb_packet *packet; |
1da177e4 LT |
301 | |
302 | if (length == 0) | |
303 | return NULL; | |
304 | ||
305 | packet = hpsb_alloc_packet(length); | |
306 | if (!packet) | |
307 | return NULL; | |
308 | ||
309 | packet->host = host; | |
310 | packet->node_id = node; | |
311 | ||
312 | if (hpsb_get_tlabel(packet)) { | |
313 | hpsb_free_packet(packet); | |
314 | return NULL; | |
315 | } | |
316 | ||
317 | if (length == 4) | |
318 | fill_async_readquad(packet, addr); | |
319 | else | |
320 | fill_async_readblock(packet, addr, length); | |
321 | ||
322 | return packet; | |
323 | } | |
324 | ||
16c333a3 JMH |
325 | struct hpsb_packet *hpsb_make_writepacket(struct hpsb_host *host, nodeid_t node, |
326 | u64 addr, quadlet_t * buffer, | |
327 | size_t length) | |
1da177e4 LT |
328 | { |
329 | struct hpsb_packet *packet; | |
330 | ||
331 | if (length == 0) | |
332 | return NULL; | |
333 | ||
334 | packet = hpsb_alloc_packet(length); | |
335 | if (!packet) | |
336 | return NULL; | |
337 | ||
16c333a3 | 338 | if (length % 4) { /* zero padding bytes */ |
1da177e4 LT |
339 | packet->data[length >> 2] = 0; |
340 | } | |
341 | packet->host = host; | |
342 | packet->node_id = node; | |
343 | ||
344 | if (hpsb_get_tlabel(packet)) { | |
345 | hpsb_free_packet(packet); | |
346 | return NULL; | |
347 | } | |
348 | ||
349 | if (length == 4) { | |
350 | fill_async_writequad(packet, addr, buffer ? *buffer : 0); | |
351 | } else { | |
352 | fill_async_writeblock(packet, addr, length); | |
353 | if (buffer) | |
354 | memcpy(packet->data, buffer, length); | |
355 | } | |
356 | ||
357 | return packet; | |
358 | } | |
359 | ||
16c333a3 JMH |
360 | struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 * buffer, |
361 | int length, int channel, int tag, | |
362 | int sync) | |
1da177e4 LT |
363 | { |
364 | struct hpsb_packet *packet; | |
365 | ||
366 | if (length == 0) | |
367 | return NULL; | |
368 | ||
369 | packet = hpsb_alloc_packet(length); | |
370 | if (!packet) | |
371 | return NULL; | |
372 | ||
16c333a3 | 373 | if (length % 4) { /* zero padding bytes */ |
1da177e4 LT |
374 | packet->data[length >> 2] = 0; |
375 | } | |
376 | packet->host = host; | |
377 | ||
378 | if (hpsb_get_tlabel(packet)) { | |
379 | hpsb_free_packet(packet); | |
380 | return NULL; | |
381 | } | |
382 | ||
383 | fill_async_stream_packet(packet, length, channel, tag, sync); | |
384 | if (buffer) | |
385 | memcpy(packet->data, buffer, length); | |
386 | ||
387 | return packet; | |
388 | } | |
389 | ||
390 | struct hpsb_packet *hpsb_make_lockpacket(struct hpsb_host *host, nodeid_t node, | |
16c333a3 JMH |
391 | u64 addr, int extcode, |
392 | quadlet_t * data, quadlet_t arg) | |
1da177e4 LT |
393 | { |
394 | struct hpsb_packet *p; | |
395 | u32 length; | |
396 | ||
397 | p = hpsb_alloc_packet(8); | |
16c333a3 JMH |
398 | if (!p) |
399 | return NULL; | |
1da177e4 LT |
400 | |
401 | p->host = host; | |
402 | p->node_id = node; | |
403 | if (hpsb_get_tlabel(p)) { | |
404 | hpsb_free_packet(p); | |
405 | return NULL; | |
406 | } | |
407 | ||
408 | switch (extcode) { | |
409 | case EXTCODE_FETCH_ADD: | |
410 | case EXTCODE_LITTLE_ADD: | |
411 | length = 4; | |
412 | if (data) | |
413 | p->data[0] = *data; | |
414 | break; | |
415 | default: | |
416 | length = 8; | |
417 | if (data) { | |
418 | p->data[0] = arg; | |
419 | p->data[1] = *data; | |
420 | } | |
421 | break; | |
422 | } | |
423 | fill_async_lock(p, addr, extcode, length); | |
424 | ||
425 | return p; | |
426 | } | |
427 | ||
16c333a3 JMH |
428 | struct hpsb_packet *hpsb_make_lock64packet(struct hpsb_host *host, |
429 | nodeid_t node, u64 addr, int extcode, | |
430 | octlet_t * data, octlet_t arg) | |
1da177e4 LT |
431 | { |
432 | struct hpsb_packet *p; | |
433 | u32 length; | |
434 | ||
435 | p = hpsb_alloc_packet(16); | |
16c333a3 JMH |
436 | if (!p) |
437 | return NULL; | |
1da177e4 LT |
438 | |
439 | p->host = host; | |
440 | p->node_id = node; | |
441 | if (hpsb_get_tlabel(p)) { | |
442 | hpsb_free_packet(p); | |
443 | return NULL; | |
444 | } | |
445 | ||
446 | switch (extcode) { | |
447 | case EXTCODE_FETCH_ADD: | |
448 | case EXTCODE_LITTLE_ADD: | |
449 | length = 8; | |
450 | if (data) { | |
451 | p->data[0] = *data >> 32; | |
452 | p->data[1] = *data & 0xffffffff; | |
453 | } | |
454 | break; | |
455 | default: | |
456 | length = 16; | |
457 | if (data) { | |
458 | p->data[0] = arg >> 32; | |
459 | p->data[1] = arg & 0xffffffff; | |
460 | p->data[2] = *data >> 32; | |
461 | p->data[3] = *data & 0xffffffff; | |
462 | } | |
463 | break; | |
464 | } | |
465 | fill_async_lock(p, addr, extcode, length); | |
466 | ||
467 | return p; | |
468 | } | |
469 | ||
16c333a3 | 470 | struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, quadlet_t data) |
1da177e4 | 471 | { |
16c333a3 | 472 | struct hpsb_packet *p; |
1da177e4 | 473 | |
16c333a3 JMH |
474 | p = hpsb_alloc_packet(0); |
475 | if (!p) | |
476 | return NULL; | |
1da177e4 | 477 | |
16c333a3 JMH |
478 | p->host = host; |
479 | fill_phy_packet(p, data); | |
1da177e4 | 480 | |
16c333a3 | 481 | return p; |
1da177e4 LT |
482 | } |
483 | ||
484 | struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host, | |
485 | int length, int channel, | |
486 | int tag, int sync) | |
487 | { | |
488 | struct hpsb_packet *p; | |
489 | ||
490 | p = hpsb_alloc_packet(length); | |
16c333a3 JMH |
491 | if (!p) |
492 | return NULL; | |
1da177e4 LT |
493 | |
494 | p->host = host; | |
495 | fill_iso_packet(p, length, channel, tag, sync); | |
496 | ||
497 | p->generation = get_hpsb_generation(host); | |
498 | ||
499 | return p; | |
500 | } | |
501 | ||
502 | /* | |
503 | * FIXME - these functions should probably read from / write to user space to | |
504 | * avoid in kernel buffers for user space callers | |
505 | */ | |
506 | ||
afd6546d SR |
507 | /** |
508 | * hpsb_read - generic read function | |
509 | * | |
510 | * Recognizes the local node ID and act accordingly. Automatically uses a | |
511 | * quadlet read request if @length == 4 and and a block read request otherwise. | |
512 | * It does not yet support lengths that are not a multiple of 4. | |
513 | * | |
514 | * You must explicitly specifiy the @generation for which the node ID is valid, | |
515 | * to avoid sending packets to the wrong nodes when we race with a bus reset. | |
516 | */ | |
1da177e4 | 517 | int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation, |
16c333a3 | 518 | u64 addr, quadlet_t * buffer, size_t length) |
1da177e4 | 519 | { |
16c333a3 JMH |
520 | struct hpsb_packet *packet; |
521 | int retval = 0; | |
1da177e4 | 522 | |
16c333a3 JMH |
523 | if (length == 0) |
524 | return -EINVAL; | |
1da177e4 | 525 | |
16c333a3 | 526 | BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet |
1da177e4 LT |
527 | |
528 | packet = hpsb_make_readpacket(host, node, addr, length); | |
529 | ||
16c333a3 JMH |
530 | if (!packet) { |
531 | return -ENOMEM; | |
532 | } | |
1da177e4 LT |
533 | |
534 | packet->generation = generation; | |
16c333a3 | 535 | retval = hpsb_send_packet_and_wait(packet); |
1da177e4 LT |
536 | if (retval < 0) |
537 | goto hpsb_read_fail; | |
538 | ||
16c333a3 | 539 | retval = hpsb_packet_success(packet); |
1da177e4 | 540 | |
16c333a3 JMH |
541 | if (retval == 0) { |
542 | if (length == 4) { | |
543 | *buffer = packet->header[3]; | |
544 | } else { | |
545 | memcpy(buffer, packet->data, length); | |
546 | } | |
547 | } | |
1da177e4 | 548 | |
16c333a3 JMH |
549 | hpsb_read_fail: |
550 | hpsb_free_tlabel(packet); | |
551 | hpsb_free_packet(packet); | |
1da177e4 | 552 | |
16c333a3 | 553 | return retval; |
1da177e4 LT |
554 | } |
555 | ||
afd6546d SR |
556 | /** |
557 | * hpsb_write - generic write function | |
558 | * | |
559 | * Recognizes the local node ID and act accordingly. Automatically uses a | |
560 | * quadlet write request if @length == 4 and and a block write request | |
561 | * otherwise. It does not yet support lengths that are not a multiple of 4. | |
562 | * | |
563 | * You must explicitly specifiy the @generation for which the node ID is valid, | |
564 | * to avoid sending packets to the wrong nodes when we race with a bus reset. | |
565 | */ | |
1da177e4 | 566 | int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation, |
16c333a3 | 567 | u64 addr, quadlet_t * buffer, size_t length) |
1da177e4 LT |
568 | { |
569 | struct hpsb_packet *packet; | |
570 | int retval; | |
571 | ||
572 | if (length == 0) | |
573 | return -EINVAL; | |
574 | ||
16c333a3 | 575 | BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet |
1da177e4 | 576 | |
16c333a3 | 577 | packet = hpsb_make_writepacket(host, node, addr, buffer, length); |
1da177e4 LT |
578 | |
579 | if (!packet) | |
580 | return -ENOMEM; | |
581 | ||
582 | packet->generation = generation; | |
16c333a3 | 583 | retval = hpsb_send_packet_and_wait(packet); |
1da177e4 LT |
584 | if (retval < 0) |
585 | goto hpsb_write_fail; | |
586 | ||
16c333a3 | 587 | retval = hpsb_packet_success(packet); |
1da177e4 | 588 | |
16c333a3 JMH |
589 | hpsb_write_fail: |
590 | hpsb_free_tlabel(packet); | |
591 | hpsb_free_packet(packet); | |
1da177e4 | 592 | |
16c333a3 | 593 | return retval; |
1da177e4 LT |
594 | } |
595 | ||
9ac485dc | 596 | #if 0 |
1da177e4 LT |
597 | |
598 | int hpsb_lock(struct hpsb_host *host, nodeid_t node, unsigned int generation, | |
16c333a3 | 599 | u64 addr, int extcode, quadlet_t * data, quadlet_t arg) |
1da177e4 | 600 | { |
16c333a3 JMH |
601 | struct hpsb_packet *packet; |
602 | int retval = 0; | |
1da177e4 | 603 | |
16c333a3 | 604 | BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet |
1da177e4 LT |
605 | |
606 | packet = hpsb_make_lockpacket(host, node, addr, extcode, data, arg); | |
16c333a3 JMH |
607 | if (!packet) |
608 | return -ENOMEM; | |
1da177e4 LT |
609 | |
610 | packet->generation = generation; | |
16c333a3 | 611 | retval = hpsb_send_packet_and_wait(packet); |
1da177e4 LT |
612 | if (retval < 0) |
613 | goto hpsb_lock_fail; | |
614 | ||
16c333a3 | 615 | retval = hpsb_packet_success(packet); |
1da177e4 | 616 | |
16c333a3 JMH |
617 | if (retval == 0) { |
618 | *data = packet->data[0]; | |
619 | } | |
1da177e4 | 620 | |
16c333a3 JMH |
621 | hpsb_lock_fail: |
622 | hpsb_free_tlabel(packet); | |
623 | hpsb_free_packet(packet); | |
1da177e4 | 624 | |
16c333a3 | 625 | return retval; |
1da177e4 LT |
626 | } |
627 | ||
1da177e4 | 628 | int hpsb_send_gasp(struct hpsb_host *host, int channel, unsigned int generation, |
16c333a3 | 629 | quadlet_t * buffer, size_t length, u32 specifier_id, |
1da177e4 LT |
630 | unsigned int version) |
631 | { | |
632 | struct hpsb_packet *packet; | |
633 | int retval = 0; | |
634 | u16 specifier_id_hi = (specifier_id & 0x00ffff00) >> 8; | |
635 | u8 specifier_id_lo = specifier_id & 0xff; | |
636 | ||
637 | HPSB_VERBOSE("Send GASP: channel = %d, length = %Zd", channel, length); | |
638 | ||
639 | length += 8; | |
640 | ||
641 | packet = hpsb_make_streampacket(host, NULL, length, channel, 3, 0); | |
642 | if (!packet) | |
643 | return -ENOMEM; | |
644 | ||
645 | packet->data[0] = cpu_to_be32((host->node_id << 16) | specifier_id_hi); | |
16c333a3 JMH |
646 | packet->data[1] = |
647 | cpu_to_be32((specifier_id_lo << 24) | (version & 0x00ffffff)); | |
1da177e4 LT |
648 | |
649 | memcpy(&(packet->data[2]), buffer, length - 8); | |
650 | ||
651 | packet->generation = generation; | |
652 | ||
653 | packet->no_waiter = 1; | |
654 | ||
655 | retval = hpsb_send_packet(packet); | |
656 | if (retval < 0) | |
657 | hpsb_free_packet(packet); | |
658 | ||
659 | return retval; | |
660 | } | |
9ac485dc | 661 | |
16c333a3 | 662 | #endif /* 0 */ |