blob: 4a9b37461c26ade19da8ff873d7a0c68841af444 [file] [log] [blame]
Kristian Høgsbergc781c062007-05-07 20:33:32 -04001/*
2 * Core IEEE1394 transaction logic
Kristian Høgsberg3038e352006-12-19 19:58:27 -05003 *
4 * Copyright (C) 2004-2006 Kristian Hoegsberg <krh@bitplanet.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
Stefan Richter2a0a2592008-03-20 23:48:23 +010021#include <linux/completion.h>
Stefan Richterd6053e02008-11-24 20:40:00 +010022#include <linux/idr.h>
Kristian Høgsberg3038e352006-12-19 19:58:27 -050023#include <linux/kernel.h>
Stefan Richterae1e5352008-06-18 18:20:45 +020024#include <linux/kref.h>
Kristian Høgsberg3038e352006-12-19 19:58:27 -050025#include <linux/module.h>
Stefan Richterc0220d62008-07-22 21:35:47 +020026#include <linux/mutex.h>
Kristian Høgsberg3038e352006-12-19 19:58:27 -050027#include <linux/init.h>
28#include <linux/interrupt.h>
29#include <linux/pci.h>
30#include <linux/delay.h>
31#include <linux/poll.h>
32#include <linux/list.h>
33#include <linux/kthread.h>
34#include <asm/uaccess.h>
Kristian Høgsberg3038e352006-12-19 19:58:27 -050035
36#include "fw-transaction.h"
37#include "fw-topology.h"
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050038#include "fw-device.h"
Kristian Høgsberg3038e352006-12-19 19:58:27 -050039
Kristian Høgsberga77754a2007-05-07 20:33:35 -040040#define HEADER_PRI(pri) ((pri) << 0)
41#define HEADER_TCODE(tcode) ((tcode) << 4)
42#define HEADER_RETRY(retry) ((retry) << 8)
43#define HEADER_TLABEL(tlabel) ((tlabel) << 10)
44#define HEADER_DESTINATION(destination) ((destination) << 16)
45#define HEADER_SOURCE(source) ((source) << 16)
46#define HEADER_RCODE(rcode) ((rcode) << 12)
47#define HEADER_OFFSET_HIGH(offset_high) ((offset_high) << 0)
48#define HEADER_DATA_LENGTH(length) ((length) << 16)
49#define HEADER_EXTENDED_TCODE(tcode) ((tcode) << 0)
Kristian Høgsberg3038e352006-12-19 19:58:27 -050050
Kristian Høgsberga77754a2007-05-07 20:33:35 -040051#define HEADER_GET_TCODE(q) (((q) >> 4) & 0x0f)
52#define HEADER_GET_TLABEL(q) (((q) >> 10) & 0x3f)
53#define HEADER_GET_RCODE(q) (((q) >> 12) & 0x0f)
54#define HEADER_GET_DESTINATION(q) (((q) >> 16) & 0xffff)
55#define HEADER_GET_SOURCE(q) (((q) >> 16) & 0xffff)
56#define HEADER_GET_OFFSET_HIGH(q) (((q) >> 0) & 0xffff)
57#define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff)
58#define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff)
Kristian Høgsberg3038e352006-12-19 19:58:27 -050059
Stefan Richtera7ea6782008-05-25 11:06:55 +020060#define HEADER_DESTINATION_IS_BROADCAST(q) \
61 (((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f))
62
Kristian Høgsberga77754a2007-05-07 20:33:35 -040063#define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22))
64#define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23))
65#define PHY_IDENTIFIER(id) ((id) << 30)
Kristian Høgsberg3038e352006-12-19 19:58:27 -050066
Stefan Richter53dca512008-12-14 21:47:04 +010067static int close_transaction(struct fw_transaction *transaction,
68 struct fw_card *card, int rcode,
69 u32 *payload, size_t length)
Kristian Høgsberg3038e352006-12-19 19:58:27 -050070{
Kristian Høgsberg730c32f2007-02-06 14:49:32 -050071 struct fw_transaction *t;
Kristian Høgsberg3038e352006-12-19 19:58:27 -050072 unsigned long flags;
73
74 spin_lock_irqsave(&card->lock, flags);
Kristian Høgsberg730c32f2007-02-06 14:49:32 -050075 list_for_each_entry(t, &card->transaction_list, link) {
76 if (t == transaction) {
77 list_del(&t->link);
78 card->tlabel_mask &= ~(1 << t->tlabel);
79 break;
80 }
81 }
Kristian Høgsberg3038e352006-12-19 19:58:27 -050082 spin_unlock_irqrestore(&card->lock, flags);
83
Kristian Høgsberg730c32f2007-02-06 14:49:32 -050084 if (&t->link != &card->transaction_list) {
85 t->callback(card, rcode, payload, length, t->callback_data);
86 return 0;
87 }
88
89 return -ENOENT;
Kristian Høgsberg3038e352006-12-19 19:58:27 -050090}
91
Kristian Høgsbergc781c062007-05-07 20:33:32 -040092/*
93 * Only valid for transactions that are potentially pending (ie have
94 * been sent).
95 */
Stefan Richter53dca512008-12-14 21:47:04 +010096int fw_cancel_transaction(struct fw_card *card,
97 struct fw_transaction *transaction)
Kristian Høgsberg730c32f2007-02-06 14:49:32 -050098{
Kristian Høgsbergc781c062007-05-07 20:33:32 -040099 /*
100 * Cancel the packet transmission if it's still queued. That
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500101 * will call the packet transmission callback which cancels
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400102 * the transaction.
103 */
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500104
105 if (card->driver->cancel_packet(card, &transaction->packet) == 0)
106 return 0;
107
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400108 /*
109 * If the request packet has already been sent, we need to see
110 * if the transaction is still pending and remove it in that case.
111 */
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500112
113 return close_transaction(transaction, card, RCODE_CANCELLED, NULL, 0);
114}
115EXPORT_SYMBOL(fw_cancel_transaction);
116
Stefan Richter53dca512008-12-14 21:47:04 +0100117static void transmit_complete_callback(struct fw_packet *packet,
118 struct fw_card *card, int status)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500119{
120 struct fw_transaction *t =
121 container_of(packet, struct fw_transaction, packet);
122
123 switch (status) {
124 case ACK_COMPLETE:
125 close_transaction(t, card, RCODE_COMPLETE, NULL, 0);
126 break;
127 case ACK_PENDING:
128 t->timestamp = packet->timestamp;
129 break;
130 case ACK_BUSY_X:
131 case ACK_BUSY_A:
132 case ACK_BUSY_B:
133 close_transaction(t, card, RCODE_BUSY, NULL, 0);
134 break;
135 case ACK_DATA_ERROR:
Kristian Høgsberge5f49c32007-01-26 00:38:34 -0500136 close_transaction(t, card, RCODE_DATA_ERROR, NULL, 0);
137 break;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500138 case ACK_TYPE_ERROR:
Kristian Høgsberge5f49c32007-01-26 00:38:34 -0500139 close_transaction(t, card, RCODE_TYPE_ERROR, NULL, 0);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500140 break;
141 default:
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400142 /*
143 * In this case the ack is really a juju specific
144 * rcode, so just forward that to the callback.
145 */
Kristian Høgsberge5f49c32007-01-26 00:38:34 -0500146 close_transaction(t, card, status, NULL, 0);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500147 break;
148 }
149}
150
Stefan Richter53dca512008-12-14 21:47:04 +0100151static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
Stefan Richterb9549bc2008-07-12 14:50:42 +0200152 int destination_id, int source_id, int generation, int speed,
Kristian Høgsberg36bfe492007-01-26 00:38:13 -0500153 unsigned long long offset, void *payload, size_t length)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500154{
155 int ext_tcode;
156
Stefan Richter18e9b102009-03-10 21:02:21 +0100157 if (tcode == TCODE_STREAM_DATA) {
158 packet->header[0] =
159 HEADER_DATA_LENGTH(length) |
160 destination_id |
161 HEADER_TCODE(TCODE_STREAM_DATA);
162 packet->header_length = 4;
163 packet->payload = payload;
164 packet->payload_length = length;
165
166 goto common;
167 }
168
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500169 if (tcode > 0x10) {
Jarod Wilson8f9f9632008-01-23 16:05:45 -0500170 ext_tcode = tcode & ~0x10;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500171 tcode = TCODE_LOCK_REQUEST;
172 } else
173 ext_tcode = 0;
174
175 packet->header[0] =
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400176 HEADER_RETRY(RETRY_X) |
177 HEADER_TLABEL(tlabel) |
178 HEADER_TCODE(tcode) |
Stefan Richterb9549bc2008-07-12 14:50:42 +0200179 HEADER_DESTINATION(destination_id);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500180 packet->header[1] =
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400181 HEADER_OFFSET_HIGH(offset >> 32) | HEADER_SOURCE(source_id);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500182 packet->header[2] =
183 offset;
184
185 switch (tcode) {
186 case TCODE_WRITE_QUADLET_REQUEST:
187 packet->header[3] = *(u32 *)payload;
188 packet->header_length = 16;
189 packet->payload_length = 0;
190 break;
191
192 case TCODE_LOCK_REQUEST:
193 case TCODE_WRITE_BLOCK_REQUEST:
194 packet->header[3] =
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400195 HEADER_DATA_LENGTH(length) |
196 HEADER_EXTENDED_TCODE(ext_tcode);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500197 packet->header_length = 16;
198 packet->payload = payload;
199 packet->payload_length = length;
200 break;
201
202 case TCODE_READ_QUADLET_REQUEST:
203 packet->header_length = 12;
204 packet->payload_length = 0;
205 break;
206
207 case TCODE_READ_BLOCK_REQUEST:
208 packet->header[3] =
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400209 HEADER_DATA_LENGTH(length) |
210 HEADER_EXTENDED_TCODE(ext_tcode);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500211 packet->header_length = 16;
212 packet->payload_length = 0;
213 break;
214 }
Stefan Richter18e9b102009-03-10 21:02:21 +0100215 common:
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500216 packet->speed = speed;
217 packet->generation = generation;
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500218 packet->ack = 0;
Stefan Richter1d1dc5e2008-12-10 00:20:38 +0100219 packet->payload_bus = 0;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500220}
221
222/**
223 * This function provides low-level access to the IEEE1394 transaction
224 * logic. Most C programs would use either fw_read(), fw_write() or
225 * fw_lock() instead - those function are convenience wrappers for
226 * this function. The fw_send_request() function is primarily
227 * provided as a flexible, one-stop entry point for languages bindings
228 * and protocol bindings.
229 *
230 * FIXME: Document this function further, in particular the possible
231 * values for rcode in the callback. In short, we map ACK_COMPLETE to
232 * RCODE_COMPLETE, internal errors set errno and set rcode to
233 * RCODE_SEND_ERROR (which is out of range for standard ieee1394
234 * rcodes). All other rcodes are forwarded unchanged. For all
235 * errors, payload is NULL, length is 0.
236 *
237 * Can not expect the callback to be called before the function
238 * returns, though this does happen in some cases (ACK_COMPLETE and
239 * errors).
240 *
241 * The payload is only used for write requests and must not be freed
242 * until the callback has been called.
243 *
244 * @param card the card from which to send the request
245 * @param tcode the tcode for this transaction. Do not use
Uwe Kleine-Königdbe7f762007-10-20 01:55:04 +0200246 * TCODE_LOCK_REQUEST directly, instead use TCODE_LOCK_MASK_SWAP
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500247 * etc. to specify tcode and ext_tcode.
Stefan Richter907293d2007-01-23 21:11:43 +0100248 * @param node_id the destination node ID (bus ID and PHY ID concatenated)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500249 * @param generation the generation for which node_id is valid
250 * @param speed the speed to use for sending the request
251 * @param offset the 48 bit offset on the destination node
252 * @param payload the data payload for the request subaction
253 * @param length the length in bytes of the data to read
254 * @param callback function to be called when the transaction is completed
255 * @param callback_data pointer to arbitrary data, which will be
256 * passed to the callback
Stefan Richter18e9b102009-03-10 21:02:21 +0100257 *
258 * In case of asynchronous stream packets i.e. TCODE_STREAM_DATA, the caller
259 * needs to synthesize @destination_id with fw_stream_packet_destination_id().
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500260 */
Stefan Richter53dca512008-12-14 21:47:04 +0100261void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode,
262 int destination_id, int generation, int speed,
263 unsigned long long offset, void *payload, size_t length,
264 fw_transaction_callback_t callback, void *callback_data)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500265{
266 unsigned long flags;
Stefan Richterb9549bc2008-07-12 14:50:42 +0200267 int tlabel;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500268
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400269 /*
270 * Bump the flush timer up 100ms first of all so we
271 * don't race with a flush timer callback.
272 */
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500273
274 mod_timer(&card->flush_timer, jiffies + DIV_ROUND_UP(HZ, 10));
275
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400276 /*
277 * Allocate tlabel from the bitmap and put the transaction on
278 * the list while holding the card spinlock.
279 */
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500280
281 spin_lock_irqsave(&card->lock, flags);
282
283 tlabel = card->current_tlabel;
284 if (card->tlabel_mask & (1 << tlabel)) {
285 spin_unlock_irqrestore(&card->lock, flags);
286 callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data);
287 return;
288 }
289
290 card->current_tlabel = (card->current_tlabel + 1) & 0x1f;
291 card->tlabel_mask |= (1 << tlabel);
292
Jay Fenlason1e119fa2008-07-20 14:20:53 +0200293 t->node_id = destination_id;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500294 t->tlabel = tlabel;
295 t->callback = callback;
296 t->callback_data = callback_data;
297
Jay Fenlason1e119fa2008-07-20 14:20:53 +0200298 fw_fill_request(&t->packet, tcode, t->tlabel,
299 destination_id, card->node_id, generation,
300 speed, offset, payload, length);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500301 t->packet.callback = transmit_complete_callback;
302
Stefan Richtere9aeb462008-07-12 14:50:06 +0200303 list_add_tail(&t->link, &card->transaction_list);
304
305 spin_unlock_irqrestore(&card->lock, flags);
306
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500307 card->driver->send_request(card, &t->packet);
308}
309EXPORT_SYMBOL(fw_send_request);
310
Jay Fenlason1e119fa2008-07-20 14:20:53 +0200311struct transaction_callback_data {
312 struct completion done;
313 void *payload;
314 int rcode;
315};
316
317static void transaction_callback(struct fw_card *card, int rcode,
318 void *payload, size_t length, void *data)
319{
320 struct transaction_callback_data *d = data;
321
322 if (rcode == RCODE_COMPLETE)
323 memcpy(d->payload, payload, length);
324 d->rcode = rcode;
325 complete(&d->done);
326}
327
328/**
329 * fw_run_transaction - send request and sleep until transaction is completed
330 *
331 * Returns the RCODE.
332 */
333int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
Stefan Richter53dca512008-12-14 21:47:04 +0100334 int generation, int speed, unsigned long long offset,
Stefan Richterba27e1f2009-03-05 19:07:00 +0100335 void *payload, size_t length)
Jay Fenlason1e119fa2008-07-20 14:20:53 +0200336{
337 struct transaction_callback_data d;
338 struct fw_transaction t;
339
340 init_completion(&d.done);
Stefan Richterba27e1f2009-03-05 19:07:00 +0100341 d.payload = payload;
Jay Fenlason1e119fa2008-07-20 14:20:53 +0200342 fw_send_request(card, &t, tcode, destination_id, generation, speed,
Stefan Richterba27e1f2009-03-05 19:07:00 +0100343 offset, payload, length, transaction_callback, &d);
Jay Fenlason1e119fa2008-07-20 14:20:53 +0200344 wait_for_completion(&d.done);
345
346 return d.rcode;
347}
348EXPORT_SYMBOL(fw_run_transaction);
349
Stefan Richterc0220d62008-07-22 21:35:47 +0200350static DEFINE_MUTEX(phy_config_mutex);
351static DECLARE_COMPLETION(phy_config_done);
Stefan Richterae1e5352008-06-18 18:20:45 +0200352
353static void transmit_phy_packet_callback(struct fw_packet *packet,
354 struct fw_card *card, int status)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500355{
Stefan Richterc0220d62008-07-22 21:35:47 +0200356 complete(&phy_config_done);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500357}
358
Stefan Richterc0220d62008-07-22 21:35:47 +0200359static struct fw_packet phy_config_packet = {
360 .header_length = 8,
361 .payload_length = 0,
362 .speed = SCODE_100,
363 .callback = transmit_phy_packet_callback,
364};
365
Kristian Høgsberg83db8012007-01-26 00:37:50 -0500366void fw_send_phy_config(struct fw_card *card,
367 int node_id, int generation, int gap_count)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500368{
Stefan Richterae1e5352008-06-18 18:20:45 +0200369 long timeout = DIV_ROUND_UP(HZ, 10);
Stefan Richter2a0a2592008-03-20 23:48:23 +0100370 u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG) |
371 PHY_CONFIG_ROOT_ID(node_id) |
372 PHY_CONFIG_GAP_COUNT(gap_count);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500373
Stefan Richterc0220d62008-07-22 21:35:47 +0200374 mutex_lock(&phy_config_mutex);
Kristian Høgsberg83db8012007-01-26 00:37:50 -0500375
Stefan Richterc0220d62008-07-22 21:35:47 +0200376 phy_config_packet.header[0] = data;
377 phy_config_packet.header[1] = ~data;
378 phy_config_packet.generation = generation;
379 INIT_COMPLETION(phy_config_done);
Stefan Richterae1e5352008-06-18 18:20:45 +0200380
Stefan Richterc0220d62008-07-22 21:35:47 +0200381 card->driver->send_request(card, &phy_config_packet);
382 wait_for_completion_timeout(&phy_config_done, timeout);
Stefan Richterae1e5352008-06-18 18:20:45 +0200383
Stefan Richterc0220d62008-07-22 21:35:47 +0200384 mutex_unlock(&phy_config_mutex);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500385}
386
387void fw_flush_transactions(struct fw_card *card)
388{
389 struct fw_transaction *t, *next;
390 struct list_head list;
391 unsigned long flags;
392
393 INIT_LIST_HEAD(&list);
394 spin_lock_irqsave(&card->lock, flags);
395 list_splice_init(&card->transaction_list, &list);
396 card->tlabel_mask = 0;
397 spin_unlock_irqrestore(&card->lock, flags);
398
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500399 list_for_each_entry_safe(t, next, &list, link) {
400 card->driver->cancel_packet(card, &t->packet);
401
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400402 /*
403 * At this point cancel_packet will never call the
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500404 * transaction callback, since we just took all the
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400405 * transactions out of the list. So do it here.
406 */
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500407 t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data);
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500408 }
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500409}
410
Stefan Richter53dca512008-12-14 21:47:04 +0100411static struct fw_address_handler *lookup_overlapping_address_handler(
412 struct list_head *list, unsigned long long offset, size_t length)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500413{
414 struct fw_address_handler *handler;
415
416 list_for_each_entry(handler, list, link) {
417 if (handler->offset < offset + length &&
418 offset < handler->offset + handler->length)
419 return handler;
420 }
421
422 return NULL;
423}
424
Stefan Richter53dca512008-12-14 21:47:04 +0100425static struct fw_address_handler *lookup_enclosing_address_handler(
426 struct list_head *list, unsigned long long offset, size_t length)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500427{
428 struct fw_address_handler *handler;
429
430 list_for_each_entry(handler, list, link) {
431 if (handler->offset <= offset &&
432 offset + length <= handler->offset + handler->length)
433 return handler;
434 }
435
436 return NULL;
437}
438
439static DEFINE_SPINLOCK(address_handler_lock);
440static LIST_HEAD(address_handler_list);
441
Stefan Richter21ebcd12007-01-14 15:29:07 +0100442const struct fw_address_region fw_high_memory_region =
Stefan Richter5af4e5e2007-01-21 20:45:32 +0100443 { .start = 0x000100000000ULL, .end = 0xffffe0000000ULL, };
Adrian Bunkdb8be072008-03-31 02:22:11 +0300444EXPORT_SYMBOL(fw_high_memory_region);
445
446#if 0
447const struct fw_address_region fw_low_memory_region =
448 { .start = 0x000000000000ULL, .end = 0x000100000000ULL, };
Stefan Richter21ebcd12007-01-14 15:29:07 +0100449const struct fw_address_region fw_private_region =
Stefan Richter5af4e5e2007-01-21 20:45:32 +0100450 { .start = 0xffffe0000000ULL, .end = 0xfffff0000000ULL, };
Stefan Richter21ebcd12007-01-14 15:29:07 +0100451const struct fw_address_region fw_csr_region =
Jarod Wilsoncca60972008-03-08 12:52:03 -0500452 { .start = CSR_REGISTER_BASE,
453 .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM_END, };
Stefan Richter21ebcd12007-01-14 15:29:07 +0100454const struct fw_address_region fw_unit_space_region =
Stefan Richter5af4e5e2007-01-21 20:45:32 +0100455 { .start = 0xfffff0000900ULL, .end = 0x1000000000000ULL, };
Adrian Bunkdb8be072008-03-31 02:22:11 +0300456#endif /* 0 */
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500457
458/**
Stefan Richter3e0b5f02008-12-14 19:21:01 +0100459 * fw_core_add_address_handler - register for incoming requests
460 * @handler: callback
461 * @region: region in the IEEE 1212 node space address range
462 *
463 * region->start, ->end, and handler->length have to be quadlet-aligned.
464 *
465 * When a request is received that falls within the specified address range,
466 * the specified callback is invoked. The parameters passed to the callback
467 * give the details of the particular request.
Stefan Richter1415d912007-07-17 02:10:16 +0200468 *
469 * Return value: 0 on success, non-zero otherwise.
470 * The start offset of the handler's address region is determined by
471 * fw_core_add_address_handler() and is returned in handler->offset.
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500472 */
Stefan Richter53dca512008-12-14 21:47:04 +0100473int fw_core_add_address_handler(struct fw_address_handler *handler,
474 const struct fw_address_region *region)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500475{
476 struct fw_address_handler *other;
477 unsigned long flags;
478 int ret = -EBUSY;
479
Stefan Richter3e0b5f02008-12-14 19:21:01 +0100480 if (region->start & 0xffff000000000003ULL ||
481 region->end & 0xffff000000000003ULL ||
482 region->start >= region->end ||
483 handler->length & 3 ||
484 handler->length == 0)
485 return -EINVAL;
486
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500487 spin_lock_irqsave(&address_handler_lock, flags);
488
Stefan Richter3e0b5f02008-12-14 19:21:01 +0100489 handler->offset = region->start;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500490 while (handler->offset + handler->length <= region->end) {
491 other =
492 lookup_overlapping_address_handler(&address_handler_list,
493 handler->offset,
494 handler->length);
495 if (other != NULL) {
Stefan Richter3e0b5f02008-12-14 19:21:01 +0100496 handler->offset += other->length;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500497 } else {
498 list_add_tail(&handler->link, &address_handler_list);
499 ret = 0;
500 break;
501 }
502 }
503
504 spin_unlock_irqrestore(&address_handler_lock, flags);
505
506 return ret;
507}
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500508EXPORT_SYMBOL(fw_core_add_address_handler);
509
510/**
Stefan Richter44be21b2008-12-14 19:21:31 +0100511 * fw_core_remove_address_handler - unregister an address handler
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500512 */
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500513void fw_core_remove_address_handler(struct fw_address_handler *handler)
514{
515 unsigned long flags;
516
517 spin_lock_irqsave(&address_handler_lock, flags);
518 list_del(&handler->link);
519 spin_unlock_irqrestore(&address_handler_lock, flags);
520}
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500521EXPORT_SYMBOL(fw_core_remove_address_handler);
522
523struct fw_request {
524 struct fw_packet response;
Kristian Høgsberg36bfe492007-01-26 00:38:13 -0500525 u32 request_header[4];
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500526 int ack;
527 u32 length;
528 u32 data[0];
529};
530
Stefan Richter53dca512008-12-14 21:47:04 +0100531static void free_response_callback(struct fw_packet *packet,
532 struct fw_card *card, int status)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500533{
534 struct fw_request *request;
535
536 request = container_of(packet, struct fw_request, response);
537 kfree(request);
538}
539
Stefan Richter53dca512008-12-14 21:47:04 +0100540void fw_fill_response(struct fw_packet *response, u32 *request_header,
541 int rcode, void *payload, size_t length)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500542{
543 int tcode, tlabel, extended_tcode, source, destination;
544
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400545 tcode = HEADER_GET_TCODE(request_header[0]);
546 tlabel = HEADER_GET_TLABEL(request_header[0]);
547 source = HEADER_GET_DESTINATION(request_header[0]);
548 destination = HEADER_GET_SOURCE(request_header[1]);
549 extended_tcode = HEADER_GET_EXTENDED_TCODE(request_header[3]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500550
551 response->header[0] =
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400552 HEADER_RETRY(RETRY_1) |
553 HEADER_TLABEL(tlabel) |
554 HEADER_DESTINATION(destination);
Kristian Høgsberg36bfe492007-01-26 00:38:13 -0500555 response->header[1] =
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400556 HEADER_SOURCE(source) |
557 HEADER_RCODE(rcode);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500558 response->header[2] = 0;
559
560 switch (tcode) {
561 case TCODE_WRITE_QUADLET_REQUEST:
562 case TCODE_WRITE_BLOCK_REQUEST:
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400563 response->header[0] |= HEADER_TCODE(TCODE_WRITE_RESPONSE);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500564 response->header_length = 12;
565 response->payload_length = 0;
566 break;
567
568 case TCODE_READ_QUADLET_REQUEST:
569 response->header[0] |=
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400570 HEADER_TCODE(TCODE_READ_QUADLET_RESPONSE);
Kristian Høgsberg93c4cce2007-01-26 00:38:26 -0500571 if (payload != NULL)
572 response->header[3] = *(u32 *)payload;
573 else
574 response->header[3] = 0;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500575 response->header_length = 16;
576 response->payload_length = 0;
577 break;
578
579 case TCODE_READ_BLOCK_REQUEST:
580 case TCODE_LOCK_REQUEST:
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400581 response->header[0] |= HEADER_TCODE(tcode + 2);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500582 response->header[3] =
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400583 HEADER_DATA_LENGTH(length) |
584 HEADER_EXTENDED_TCODE(extended_tcode);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500585 response->header_length = 16;
Kristian Høgsberg36bfe492007-01-26 00:38:13 -0500586 response->payload = payload;
587 response->payload_length = length;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500588 break;
589
590 default:
591 BUG();
592 return;
593 }
Stefan Richter1d1dc5e2008-12-10 00:20:38 +0100594
595 response->payload_bus = 0;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500596}
Kristian Høgsberg93c4cce2007-01-26 00:38:26 -0500597EXPORT_SYMBOL(fw_fill_response);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500598
Stefan Richter53dca512008-12-14 21:47:04 +0100599static struct fw_request *allocate_request(struct fw_packet *p)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500600{
601 struct fw_request *request;
602 u32 *data, length;
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500603 int request_tcode, t;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500604
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400605 request_tcode = HEADER_GET_TCODE(p->header[0]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500606 switch (request_tcode) {
607 case TCODE_WRITE_QUADLET_REQUEST:
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500608 data = &p->header[3];
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500609 length = 4;
610 break;
611
612 case TCODE_WRITE_BLOCK_REQUEST:
613 case TCODE_LOCK_REQUEST:
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500614 data = p->payload;
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400615 length = HEADER_GET_DATA_LENGTH(p->header[3]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500616 break;
617
618 case TCODE_READ_QUADLET_REQUEST:
619 data = NULL;
620 length = 4;
621 break;
622
623 case TCODE_READ_BLOCK_REQUEST:
624 data = NULL;
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400625 length = HEADER_GET_DATA_LENGTH(p->header[3]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500626 break;
627
628 default:
Stefan Richter0bf607c2008-05-31 19:01:26 +0200629 fw_error("ERROR - corrupt request received - %08x %08x %08x\n",
630 p->header[0], p->header[1], p->header[2]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500631 return NULL;
632 }
633
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400634 request = kmalloc(sizeof(*request) + length, GFP_ATOMIC);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500635 if (request == NULL)
636 return NULL;
637
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500638 t = (p->timestamp & 0x1fff) + 4000;
639 if (t >= 8000)
640 t = (p->timestamp & ~0x1fff) + 0x2000 + t - 8000;
641 else
642 t = (p->timestamp & ~0x1fff) + t;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500643
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500644 request->response.speed = p->speed;
645 request->response.timestamp = t;
646 request->response.generation = p->generation;
Kristian Høgsberg730c32f2007-02-06 14:49:32 -0500647 request->response.ack = 0;
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500648 request->response.callback = free_response_callback;
649 request->ack = p->ack;
Kristian Høgsberg93c4cce2007-01-26 00:38:26 -0500650 request->length = length;
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500651 if (data)
Kristian Høgsberg6e2e8422007-02-16 17:34:37 -0500652 memcpy(request->data, data, length);
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500653
Kristian Høgsberg2d826cc2007-05-09 19:23:14 -0400654 memcpy(request->request_header, p->header, sizeof(p->header));
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500655
656 return request;
657}
658
Stefan Richter53dca512008-12-14 21:47:04 +0100659void fw_send_response(struct fw_card *card,
660 struct fw_request *request, int rcode)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500661{
Stefan Richtera7ea6782008-05-25 11:06:55 +0200662 /* unified transaction or broadcast transaction: don't respond */
663 if (request->ack != ACK_PENDING ||
664 HEADER_DESTINATION_IS_BROADCAST(request->request_header[0])) {
Stefan Richter9c9bdf42007-07-17 02:15:36 +0200665 kfree(request);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500666 return;
Stefan Richter9c9bdf42007-07-17 02:15:36 +0200667 }
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500668
Kristian Høgsberg36bfe492007-01-26 00:38:13 -0500669 if (rcode == RCODE_COMPLETE)
670 fw_fill_response(&request->response, request->request_header,
671 rcode, request->data, request->length);
672 else
673 fw_fill_response(&request->response, request->request_header,
674 rcode, NULL, 0);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500675
676 card->driver->send_response(card, &request->response);
677}
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500678EXPORT_SYMBOL(fw_send_response);
679
Stefan Richter53dca512008-12-14 21:47:04 +0100680void fw_core_handle_request(struct fw_card *card, struct fw_packet *p)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500681{
682 struct fw_address_handler *handler;
683 struct fw_request *request;
684 unsigned long long offset;
685 unsigned long flags;
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500686 int tcode, destination, source;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500687
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500688 if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500689 return;
690
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500691 request = allocate_request(p);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500692 if (request == NULL) {
693 /* FIXME: send statically allocated busy packet. */
694 return;
695 }
696
697 offset =
698 ((unsigned long long)
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400699 HEADER_GET_OFFSET_HIGH(p->header[1]) << 32) | p->header[2];
700 tcode = HEADER_GET_TCODE(p->header[0]);
701 destination = HEADER_GET_DESTINATION(p->header[0]);
Rabin Vincent478b2332007-12-21 23:02:15 +0530702 source = HEADER_GET_SOURCE(p->header[1]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500703
704 spin_lock_irqsave(&address_handler_lock, flags);
705 handler = lookup_enclosing_address_handler(&address_handler_list,
706 offset, request->length);
707 spin_unlock_irqrestore(&address_handler_lock, flags);
708
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400709 /*
710 * FIXME: lookup the fw_node corresponding to the sender of
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500711 * this request and pass that to the address handler instead
712 * of the node ID. We may also want to move the address
713 * allocations to fw_node so we only do this callback if the
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400714 * upper layers registered it for this node.
715 */
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500716
717 if (handler == NULL)
718 fw_send_response(card, request, RCODE_ADDRESS_ERROR);
719 else
720 handler->address_callback(card, request,
721 tcode, destination, source,
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500722 p->generation, p->speed, offset,
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500723 request->data, request->length,
724 handler->callback_data);
725}
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500726EXPORT_SYMBOL(fw_core_handle_request);
727
Stefan Richter53dca512008-12-14 21:47:04 +0100728void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500729{
730 struct fw_transaction *t;
731 unsigned long flags;
732 u32 *data;
733 size_t data_length;
734 int tcode, tlabel, destination, source, rcode;
735
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400736 tcode = HEADER_GET_TCODE(p->header[0]);
737 tlabel = HEADER_GET_TLABEL(p->header[0]);
738 destination = HEADER_GET_DESTINATION(p->header[0]);
739 source = HEADER_GET_SOURCE(p->header[1]);
740 rcode = HEADER_GET_RCODE(p->header[1]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500741
742 spin_lock_irqsave(&card->lock, flags);
743 list_for_each_entry(t, &card->transaction_list, link) {
744 if (t->node_id == source && t->tlabel == tlabel) {
745 list_del(&t->link);
746 card->tlabel_mask &= ~(1 << t->tlabel);
747 break;
748 }
749 }
750 spin_unlock_irqrestore(&card->lock, flags);
751
752 if (&t->link == &card->transaction_list) {
Kristian Høgsberg32b46092007-02-06 14:49:30 -0500753 fw_notify("Unsolicited response (source %x, tlabel %x)\n",
754 source, tlabel);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500755 return;
756 }
757
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400758 /*
759 * FIXME: sanity check packet, is length correct, does tcodes
760 * and addresses match.
761 */
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500762
763 switch (tcode) {
764 case TCODE_READ_QUADLET_RESPONSE:
Kristian Høgsberg2639a6f2007-01-26 00:37:57 -0500765 data = (u32 *) &p->header[3];
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500766 data_length = 4;
767 break;
768
769 case TCODE_WRITE_RESPONSE:
770 data = NULL;
771 data_length = 0;
772 break;
773
774 case TCODE_READ_BLOCK_RESPONSE:
775 case TCODE_LOCK_RESPONSE:
Kristian Høgsberg93c4cce2007-01-26 00:38:26 -0500776 data = p->payload;
Kristian Høgsberga77754a2007-05-07 20:33:35 -0400777 data_length = HEADER_GET_DATA_LENGTH(p->header[3]);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500778 break;
779
780 default:
781 /* Should never happen, this is just to shut up gcc. */
782 data = NULL;
783 data_length = 0;
784 break;
785 }
786
Stefan Richter10a4c732008-03-16 00:56:41 +0100787 /*
788 * The response handler may be executed while the request handler
789 * is still pending. Cancel the request handler.
790 */
791 card->driver->cancel_packet(card, &t->packet);
792
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500793 t->callback(card, rcode, data, data_length, t->callback_data);
794}
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500795EXPORT_SYMBOL(fw_core_handle_response);
796
Stefan Richterae579882007-08-02 20:34:17 +0200797static const struct fw_address_region topology_map_region =
Jarod Wilsoncca60972008-03-08 12:52:03 -0500798 { .start = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP,
799 .end = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP_END, };
Kristian Høgsberg473d28c2007-03-07 12:12:55 -0500800
Stefan Richter53dca512008-12-14 21:47:04 +0100801static void handle_topology_map(struct fw_card *card, struct fw_request *request,
802 int tcode, int destination, int source, int generation,
803 int speed, unsigned long long offset,
804 void *payload, size_t length, void *callback_data)
Kristian Høgsberg473d28c2007-03-07 12:12:55 -0500805{
806 int i, start, end;
Stefan Richterefbf3902008-02-23 12:24:57 +0100807 __be32 *map;
Kristian Høgsberg473d28c2007-03-07 12:12:55 -0500808
809 if (!TCODE_IS_READ_REQUEST(tcode)) {
810 fw_send_response(card, request, RCODE_TYPE_ERROR);
811 return;
812 }
813
814 if ((offset & 3) > 0 || (length & 3) > 0) {
815 fw_send_response(card, request, RCODE_ADDRESS_ERROR);
816 return;
817 }
818
819 start = (offset - topology_map_region.start) / 4;
820 end = start + length / 4;
821 map = payload;
822
823 for (i = 0; i < length / 4; i++)
824 map[i] = cpu_to_be32(card->topology_map[start + i]);
825
826 fw_send_response(card, request, RCODE_COMPLETE);
827}
828
829static struct fw_address_handler topology_map = {
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500830 .length = 0x200,
Kristian Høgsberg473d28c2007-03-07 12:12:55 -0500831 .address_callback = handle_topology_map,
832};
833
Stefan Richterae579882007-08-02 20:34:17 +0200834static const struct fw_address_region registers_region =
Jarod Wilsoncca60972008-03-08 12:52:03 -0500835 { .start = CSR_REGISTER_BASE,
836 .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, };
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500837
Stefan Richter53dca512008-12-14 21:47:04 +0100838static void handle_registers(struct fw_card *card, struct fw_request *request,
839 int tcode, int destination, int source, int generation,
840 int speed, unsigned long long offset,
841 void *payload, size_t length, void *callback_data)
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500842{
Jarod Wilson15f0d832008-03-08 13:18:58 -0500843 int reg = offset & ~CSR_REGISTER_BASE;
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500844 unsigned long long bus_time;
845 __be32 *data = payload;
Stefan Richtere534fe12008-05-24 16:41:09 +0200846 int rcode = RCODE_COMPLETE;
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500847
848 switch (reg) {
849 case CSR_CYCLE_TIME:
850 case CSR_BUS_TIME:
851 if (!TCODE_IS_READ_REQUEST(tcode) || length != 4) {
Stefan Richtere534fe12008-05-24 16:41:09 +0200852 rcode = RCODE_TYPE_ERROR;
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500853 break;
854 }
855
856 bus_time = card->driver->get_bus_time(card);
857 if (reg == CSR_CYCLE_TIME)
858 *data = cpu_to_be32(bus_time);
859 else
860 *data = cpu_to_be32(bus_time >> 25);
Stefan Richtere534fe12008-05-24 16:41:09 +0200861 break;
862
863 case CSR_BROADCAST_CHANNEL:
864 if (tcode == TCODE_READ_QUADLET_REQUEST)
865 *data = cpu_to_be32(card->broadcast_channel);
866 else if (tcode == TCODE_WRITE_QUADLET_REQUEST)
867 card->broadcast_channel =
868 (be32_to_cpu(*data) & BROADCAST_CHANNEL_VALID) |
869 BROADCAST_CHANNEL_INITIAL;
870 else
871 rcode = RCODE_TYPE_ERROR;
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500872 break;
873
874 case CSR_BUS_MANAGER_ID:
875 case CSR_BANDWIDTH_AVAILABLE:
876 case CSR_CHANNELS_AVAILABLE_HI:
877 case CSR_CHANNELS_AVAILABLE_LO:
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400878 /*
879 * FIXME: these are handled by the OHCI hardware and
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500880 * the stack never sees these request. If we add
881 * support for a new type of controller that doesn't
882 * handle this in hardware we need to deal with these
Kristian Høgsbergc781c062007-05-07 20:33:32 -0400883 * transactions.
884 */
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500885 BUG();
886 break;
887
888 case CSR_BUSY_TIMEOUT:
889 /* FIXME: Implement this. */
Stefan Richtere534fe12008-05-24 16:41:09 +0200890
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500891 default:
Stefan Richtere534fe12008-05-24 16:41:09 +0200892 rcode = RCODE_ADDRESS_ERROR;
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500893 break;
894 }
Stefan Richtere534fe12008-05-24 16:41:09 +0200895
896 fw_send_response(card, request, rcode);
Kristian Høgsbergd60d7f12007-03-07 12:12:56 -0500897}
898
899static struct fw_address_handler registers = {
900 .length = 0x400,
901 .address_callback = handle_registers,
902};
903
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500904MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>");
905MODULE_DESCRIPTION("Core IEEE1394 transaction logic");
906MODULE_LICENSE("GPL");
907
Kristian Høgsberg937f6872007-03-07 12:12:36 -0500908static const u32 vendor_textual_descriptor[] = {
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500909 /* textual descriptor leaf () */
Kristian Høgsberg937f6872007-03-07 12:12:36 -0500910 0x00060000,
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500911 0x00000000,
912 0x00000000,
913 0x4c696e75, /* L i n u */
914 0x78204669, /* x F i */
915 0x72657769, /* r e w i */
Kristian Høgsberg937f6872007-03-07 12:12:36 -0500916 0x72650000, /* r e */
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500917};
918
Kristian Høgsberg937f6872007-03-07 12:12:36 -0500919static const u32 model_textual_descriptor[] = {
920 /* model descriptor leaf () */
921 0x00030000,
922 0x00000000,
923 0x00000000,
924 0x4a756a75, /* J u j u */
925};
926
927static struct fw_descriptor vendor_id_descriptor = {
928 .length = ARRAY_SIZE(vendor_textual_descriptor),
929 .immediate = 0x03d00d1e,
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500930 .key = 0x81000000,
Kristian Høgsberg937f6872007-03-07 12:12:36 -0500931 .data = vendor_textual_descriptor,
932};
933
934static struct fw_descriptor model_id_descriptor = {
935 .length = ARRAY_SIZE(model_textual_descriptor),
936 .immediate = 0x17000001,
937 .key = 0x81000000,
938 .data = model_textual_descriptor,
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500939};
940
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500941static int __init fw_core_init(void)
942{
Stefan Richter2dbd7d72008-12-14 21:45:45 +0100943 int ret;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500944
Stefan Richter2dbd7d72008-12-14 21:45:45 +0100945 ret = bus_register(&fw_bus_type);
946 if (ret < 0)
947 return ret;
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500948
Kristian Høgsberga3aca3d2007-03-07 12:12:44 -0500949 fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops);
950 if (fw_cdev_major < 0) {
951 bus_unregister(&fw_bus_type);
952 return fw_cdev_major;
953 }
954
Stefan Richterc490a6d2008-12-14 21:45:14 +0100955 fw_core_add_address_handler(&topology_map, &topology_map_region);
956 fw_core_add_address_handler(&registers, &registers_region);
957 fw_core_add_descriptor(&vendor_id_descriptor);
958 fw_core_add_descriptor(&model_id_descriptor);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500959
960 return 0;
961}
962
963static void __exit fw_core_cleanup(void)
964{
Kristian Høgsberga3aca3d2007-03-07 12:12:44 -0500965 unregister_chrdev(fw_cdev_major, "firewire");
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500966 bus_unregister(&fw_bus_type);
Stefan Richterd6053e02008-11-24 20:40:00 +0100967 idr_destroy(&fw_device_idr);
Kristian Høgsberg3038e352006-12-19 19:58:27 -0500968}
969
970module_init(fw_core_init);
971module_exit(fw_core_cleanup);