X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=drivers%2Ffirewire%2Ffw-transaction.c;h=03ae8a77c479f680da86de9cc1e407336bd23750;hb=d5545fa0056ff2982f8a6419bd9a6ba2674deefd;hp=4ca39f09f58a756c09afa26a047058c352e6f973;hpb=2639a6fb268e1f2a7700fe3d31cbca9b39aa3ad9;p=safe%2Fjmp%2Flinux-2.6 diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c index 4ca39f0..03ae8a7 100644 --- a/drivers/firewire/fw-transaction.c +++ b/drivers/firewire/fw-transaction.c @@ -1,6 +1,5 @@ -/* -*- c-basic-offset: 8 -*- - * - * fw-transaction.c - core IEEE1394 transaction logic +/* + * Core IEEE1394 transaction logic * * Copyright (C) 2004-2006 Kristian Hoegsberg * @@ -19,7 +18,9 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #include +#include #include #include #include @@ -29,49 +30,86 @@ #include #include #include -#include #include "fw-transaction.h" #include "fw-topology.h" #include "fw-device.h" -#define header_pri(pri) ((pri) << 0) -#define header_tcode(tcode) ((tcode) << 4) -#define header_retry(retry) ((retry) << 8) -#define header_tlabel(tlabel) ((tlabel) << 10) -#define header_destination(destination) ((destination) << 16) -#define header_source(source) ((source) << 16) -#define header_rcode(rcode) ((rcode) << 12) -#define header_offset_high(offset_high) ((offset_high) << 0) -#define header_data_length(length) ((length) << 16) -#define header_extended_tcode(tcode) ((tcode) << 0) - -#define header_get_tcode(q) (((q) >> 4) & 0x0f) -#define header_get_tlabel(q) (((q) >> 10) & 0x3f) -#define header_get_rcode(q) (((q) >> 4) & 0x0f) -#define header_get_destination(q) (((q) >> 16) & 0xffff) -#define header_get_source(q) (((q) >> 16) & 0xffff) -#define header_get_offset_high(q) (((q) >> 0) & 0xffff) -#define header_get_data_length(q) (((q) >> 16) & 0xffff) -#define header_get_extended_tcode(q) (((q) >> 0) & 0xffff) - -#define phy_config_gap_count(gap_count) (((gap_count) << 16) | (1 << 22)) -#define phy_config_root_id(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23)) -#define phy_identifier(id) ((id) << 30) - -static void -close_transaction(struct fw_transaction *t, struct fw_card *card, int rcode, - u32 * payload, size_t length) +#define HEADER_PRI(pri) ((pri) << 0) +#define HEADER_TCODE(tcode) ((tcode) << 4) +#define HEADER_RETRY(retry) ((retry) << 8) +#define HEADER_TLABEL(tlabel) ((tlabel) << 10) +#define HEADER_DESTINATION(destination) ((destination) << 16) +#define HEADER_SOURCE(source) ((source) << 16) +#define HEADER_RCODE(rcode) ((rcode) << 12) +#define HEADER_OFFSET_HIGH(offset_high) ((offset_high) << 0) +#define HEADER_DATA_LENGTH(length) ((length) << 16) +#define HEADER_EXTENDED_TCODE(tcode) ((tcode) << 0) + +#define HEADER_GET_TCODE(q) (((q) >> 4) & 0x0f) +#define HEADER_GET_TLABEL(q) (((q) >> 10) & 0x3f) +#define HEADER_GET_RCODE(q) (((q) >> 12) & 0x0f) +#define HEADER_GET_DESTINATION(q) (((q) >> 16) & 0xffff) +#define HEADER_GET_SOURCE(q) (((q) >> 16) & 0xffff) +#define HEADER_GET_OFFSET_HIGH(q) (((q) >> 0) & 0xffff) +#define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff) +#define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff) + +#define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22)) +#define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23)) +#define PHY_IDENTIFIER(id) ((id) << 30) + +static int +close_transaction(struct fw_transaction *transaction, + struct fw_card *card, int rcode, + u32 *payload, size_t length) { + struct fw_transaction *t; unsigned long flags; spin_lock_irqsave(&card->lock, flags); - card->tlabel_mask &= ~(1 << t->tlabel); - list_del(&t->link); + list_for_each_entry(t, &card->transaction_list, link) { + if (t == transaction) { + list_del(&t->link); + card->tlabel_mask &= ~(1 << t->tlabel); + break; + } + } spin_unlock_irqrestore(&card->lock, flags); - t->callback(card, rcode, payload, length, t->callback_data); + if (&t->link != &card->transaction_list) { + t->callback(card, rcode, payload, length, t->callback_data); + return 0; + } + + return -ENOENT; +} + +/* + * Only valid for transactions that are potentially pending (ie have + * been sent). + */ +int +fw_cancel_transaction(struct fw_card *card, + struct fw_transaction *transaction) +{ + /* + * Cancel the packet transmission if it's still queued. That + * will call the packet transmission callback which cancels + * the transaction. + */ + + if (card->driver->cancel_packet(card, &transaction->packet) == 0) + return 0; + + /* + * If the request packet has already been sent, we need to see + * if the transaction is still pending and remove it in that case. + */ + + return close_transaction(transaction, card, RCODE_CANCELLED, NULL, 0); } +EXPORT_SYMBOL(fw_cancel_transaction); static void transmit_complete_callback(struct fw_packet *packet, @@ -93,39 +131,41 @@ transmit_complete_callback(struct fw_packet *packet, close_transaction(t, card, RCODE_BUSY, NULL, 0); break; case ACK_DATA_ERROR: + close_transaction(t, card, RCODE_DATA_ERROR, NULL, 0); + break; case ACK_TYPE_ERROR: - close_transaction(t, card, RCODE_SEND_ERROR, NULL, 0); + close_transaction(t, card, RCODE_TYPE_ERROR, NULL, 0); break; default: - /* FIXME: In this case, status is a negative errno, - * corresponding to an OHCI specific transmit error - * code. We should map that to an RCODE instead of - * just the generic RCODE_SEND_ERROR. */ - close_transaction(t, card, RCODE_SEND_ERROR, NULL, 0); + /* + * In this case the ack is really a juju specific + * rcode, so just forward that to the callback. + */ + close_transaction(t, card, status, NULL, 0); break; } } static void -fw_fill_packet(struct fw_packet *packet, int tcode, int tlabel, - int node_id, int generation, int speed, - unsigned long long offset, void *payload, size_t length) +fw_fill_request(struct fw_packet *packet, int tcode, int tlabel, + int node_id, int source_id, int generation, int speed, + unsigned long long offset, void *payload, size_t length) { int ext_tcode; if (tcode > 0x10) { - ext_tcode = tcode - 0x10; + ext_tcode = tcode & ~0x10; tcode = TCODE_LOCK_REQUEST; } else ext_tcode = 0; packet->header[0] = - header_retry(RETRY_X) | - header_tlabel(tlabel) | - header_tcode(tcode) | - header_destination(node_id); + HEADER_RETRY(RETRY_X) | + HEADER_TLABEL(tlabel) | + HEADER_TCODE(tcode) | + HEADER_DESTINATION(node_id); packet->header[1] = - header_offset_high(offset >> 32) | header_source(0); + HEADER_OFFSET_HIGH(offset >> 32) | HEADER_SOURCE(source_id); packet->header[2] = offset; @@ -139,8 +179,8 @@ fw_fill_packet(struct fw_packet *packet, int tcode, int tlabel, case TCODE_LOCK_REQUEST: case TCODE_WRITE_BLOCK_REQUEST: packet->header[3] = - header_data_length(length) | - header_extended_tcode(ext_tcode); + HEADER_DATA_LENGTH(length) | + HEADER_EXTENDED_TCODE(ext_tcode); packet->header_length = 16; packet->payload = payload; packet->payload_length = length; @@ -153,8 +193,8 @@ fw_fill_packet(struct fw_packet *packet, int tcode, int tlabel, case TCODE_READ_BLOCK_REQUEST: packet->header[3] = - header_data_length(length) | - header_extended_tcode(ext_tcode); + HEADER_DATA_LENGTH(length) | + HEADER_EXTENDED_TCODE(ext_tcode); packet->header_length = 16; packet->payload_length = 0; break; @@ -162,6 +202,7 @@ fw_fill_packet(struct fw_packet *packet, int tcode, int tlabel, packet->speed = speed; packet->generation = generation; + packet->ack = 0; } /** @@ -188,7 +229,7 @@ fw_fill_packet(struct fw_packet *packet, int tcode, int tlabel, * * @param card the card from which to send the request * @param tcode the tcode for this transaction. Do not use - * TCODE_LOCK_REQUEST directly, insted use TCODE_LOCK_MASK_SWAP + * TCODE_LOCK_REQUEST directly, instead use TCODE_LOCK_MASK_SWAP * etc. to specify tcode and ext_tcode. * @param node_id the destination node ID (bus ID and PHY ID concatenated) * @param generation the generation for which node_id is valid @@ -208,18 +249,23 @@ fw_send_request(struct fw_card *card, struct fw_transaction *t, fw_transaction_callback_t callback, void *callback_data) { unsigned long flags; - int tlabel; + int tlabel, source; - /* Bump the flush timer up 100ms first of all so we - * don't race with a flush timer callback. */ + /* + * Bump the flush timer up 100ms first of all so we + * don't race with a flush timer callback. + */ mod_timer(&card->flush_timer, jiffies + DIV_ROUND_UP(HZ, 10)); - /* Allocate tlabel from the bitmap and put the transaction on - * the list while holding the card spinlock. */ + /* + * Allocate tlabel from the bitmap and put the transaction on + * the list while holding the card spinlock. + */ spin_lock_irqsave(&card->lock, flags); + source = card->node_id; tlabel = card->current_tlabel; if (card->tlabel_mask & (1 << tlabel)) { spin_unlock_irqrestore(&card->lock, flags); @@ -240,50 +286,67 @@ fw_send_request(struct fw_card *card, struct fw_transaction *t, t->callback = callback; t->callback_data = callback_data; - fw_fill_packet(&t->packet, tcode, t->tlabel, - node_id, generation, speed, offset, payload, length); + fw_fill_request(&t->packet, tcode, t->tlabel, + node_id, source, generation, + speed, offset, payload, length); t->packet.callback = transmit_complete_callback; card->driver->send_request(card, &t->packet); } EXPORT_SYMBOL(fw_send_request); -static void -transmit_phy_packet_callback(struct fw_packet *packet, - struct fw_card *card, int status) +struct fw_phy_packet { + struct fw_packet packet; + struct completion done; + struct kref kref; +}; + +static void phy_packet_release(struct kref *kref) { - kfree(packet); + struct fw_phy_packet *p = + container_of(kref, struct fw_phy_packet, kref); + kfree(p); } -static void send_phy_packet(struct fw_card *card, u32 data, int generation) +static void transmit_phy_packet_callback(struct fw_packet *packet, + struct fw_card *card, int status) { - struct fw_packet *packet; - - packet = kzalloc(sizeof *packet, GFP_ATOMIC); - if (packet == NULL) - return; + struct fw_phy_packet *p = + container_of(packet, struct fw_phy_packet, packet); - packet->header[0] = data; - packet->header[1] = ~data; - packet->header_length = 8; - packet->payload_length = 0; - packet->speed = SCODE_100; - packet->generation = generation; - packet->callback = transmit_phy_packet_callback; - - card->driver->send_request(card, packet); + complete(&p->done); + kref_put(&p->kref, phy_packet_release); } void fw_send_phy_config(struct fw_card *card, int node_id, int generation, int gap_count) { - u32 q; - - q = phy_identifier(PHY_PACKET_CONFIG) | - phy_config_root_id(node_id) | - phy_config_gap_count(gap_count); + struct fw_phy_packet *p; + long timeout = DIV_ROUND_UP(HZ, 10); + u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG) | + PHY_CONFIG_ROOT_ID(node_id) | + PHY_CONFIG_GAP_COUNT(gap_count); + + p = kmalloc(sizeof(*p), GFP_KERNEL); + if (p == NULL) + return; - send_phy_packet(card, q, generation); + p->packet.header[0] = data; + p->packet.header[1] = ~data; + p->packet.header_length = 8; + p->packet.payload_length = 0; + p->packet.speed = SCODE_100; + p->packet.generation = generation; + p->packet.callback = transmit_phy_packet_callback; + init_completion(&p->done); + kref_set(&p->kref, 2); + + card->driver->send_request(card, &p->packet); + timeout = wait_for_completion_timeout(&p->done, timeout); + kref_put(&p->kref, phy_packet_release); + + /* will leak p if the callback is never executed */ + WARN_ON(timeout == 0); } void fw_flush_transactions(struct fw_card *card) @@ -298,8 +361,16 @@ void fw_flush_transactions(struct fw_card *card) card->tlabel_mask = 0; spin_unlock_irqrestore(&card->lock, flags); - list_for_each_entry_safe(t, next, &list, link) + list_for_each_entry_safe(t, next, &list, link) { + card->driver->cancel_packet(card, &t->packet); + + /* + * At this point cancel_packet will never call the + * transaction callback, since we just took all the + * transactions out of the list. So do it here. + */ t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data); + } } static struct fw_address_handler * @@ -335,28 +406,33 @@ lookup_enclosing_address_handler(struct list_head *list, static DEFINE_SPINLOCK(address_handler_lock); static LIST_HEAD(address_handler_list); -const struct fw_address_region fw_low_memory_region = - { .start = 0x000000000000ULL, .end = 0x000100000000ULL, }; const struct fw_address_region fw_high_memory_region = { .start = 0x000100000000ULL, .end = 0xffffe0000000ULL, }; +EXPORT_SYMBOL(fw_high_memory_region); + +#if 0 +const struct fw_address_region fw_low_memory_region = + { .start = 0x000000000000ULL, .end = 0x000100000000ULL, }; const struct fw_address_region fw_private_region = { .start = 0xffffe0000000ULL, .end = 0xfffff0000000ULL, }; const struct fw_address_region fw_csr_region = - { .start = 0xfffff0000000ULL, .end = 0xfffff0000800ULL, }; + { .start = CSR_REGISTER_BASE, + .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM_END, }; const struct fw_address_region fw_unit_space_region = { .start = 0xfffff0000900ULL, .end = 0x1000000000000ULL, }; -EXPORT_SYMBOL(fw_low_memory_region); -EXPORT_SYMBOL(fw_high_memory_region); -EXPORT_SYMBOL(fw_private_region); -EXPORT_SYMBOL(fw_csr_region); -EXPORT_SYMBOL(fw_unit_space_region); +#endif /* 0 */ /** * Allocate a range of addresses in the node space of the OHCI * controller. When a request is received that falls within the * specified address range, the specified callback is invoked. The * parameters passed to the callback give the details of the - * particular request + * particular request. + * + * Return value: 0 on success, non-zero otherwise. + * The start offset of the handler's address region is determined by + * fw_core_add_address_handler() and is returned in handler->offset. + * The offset is quadlet-aligned. */ int fw_core_add_address_handler(struct fw_address_handler *handler, @@ -368,14 +444,15 @@ fw_core_add_address_handler(struct fw_address_handler *handler, spin_lock_irqsave(&address_handler_lock, flags); - handler->offset = region->start; + handler->offset = roundup(region->start, 4); while (handler->offset + handler->length <= region->end) { other = lookup_overlapping_address_handler(&address_handler_list, handler->offset, handler->length); if (other != NULL) { - handler->offset += other->length; + handler->offset = + roundup(other->offset + other->length, 4); } else { list_add_tail(&handler->link, &address_handler_list); ret = 0; @@ -409,6 +486,7 @@ EXPORT_SYMBOL(fw_core_remove_address_handler); struct fw_request { struct fw_packet response; + u32 request_header[4]; int ack; u32 length; u32 data[0]; @@ -424,50 +502,55 @@ free_response_callback(struct fw_packet *packet, kfree(request); } -static void -fw_fill_response(struct fw_packet *response, - struct fw_packet *request, void *data) +void +fw_fill_response(struct fw_packet *response, u32 *request_header, + int rcode, void *payload, size_t length) { int tcode, tlabel, extended_tcode, source, destination; - tcode = header_get_tcode(request->header[0]); - tlabel = header_get_tlabel(request->header[0]); - source = header_get_destination(request->header[0]); - destination = header_get_source(request->header[1]); - extended_tcode = header_get_extended_tcode(request->header[3]); + tcode = HEADER_GET_TCODE(request_header[0]); + tlabel = HEADER_GET_TLABEL(request_header[0]); + source = HEADER_GET_DESTINATION(request_header[0]); + destination = HEADER_GET_SOURCE(request_header[1]); + extended_tcode = HEADER_GET_EXTENDED_TCODE(request_header[3]); response->header[0] = - header_retry(RETRY_1) | - header_tlabel(tlabel) | - header_destination(destination); - response->header[1] = header_source(source); + HEADER_RETRY(RETRY_1) | + HEADER_TLABEL(tlabel) | + HEADER_DESTINATION(destination); + response->header[1] = + HEADER_SOURCE(source) | + HEADER_RCODE(rcode); response->header[2] = 0; switch (tcode) { case TCODE_WRITE_QUADLET_REQUEST: case TCODE_WRITE_BLOCK_REQUEST: - response->header[0] |= header_tcode(TCODE_WRITE_RESPONSE); + response->header[0] |= HEADER_TCODE(TCODE_WRITE_RESPONSE); response->header_length = 12; response->payload_length = 0; break; case TCODE_READ_QUADLET_REQUEST: response->header[0] |= - header_tcode(TCODE_READ_QUADLET_RESPONSE); - response->header[3] = 0; + HEADER_TCODE(TCODE_READ_QUADLET_RESPONSE); + if (payload != NULL) + response->header[3] = *(u32 *)payload; + else + response->header[3] = 0; response->header_length = 16; response->payload_length = 0; break; case TCODE_READ_BLOCK_REQUEST: case TCODE_LOCK_REQUEST: - response->header[0] |= header_tcode(tcode + 2); + response->header[0] |= HEADER_TCODE(tcode + 2); response->header[3] = - header_data_length(request->payload_length) | - header_extended_tcode(extended_tcode); + HEADER_DATA_LENGTH(length) | + HEADER_EXTENDED_TCODE(extended_tcode); response->header_length = 16; - response->payload = data; - response->payload_length = request->payload_length; + response->payload = payload; + response->payload_length = length; break; default: @@ -475,6 +558,7 @@ fw_fill_response(struct fw_packet *response, return; } } +EXPORT_SYMBOL(fw_fill_response); static struct fw_request * allocate_request(struct fw_packet *p) @@ -483,7 +567,7 @@ allocate_request(struct fw_packet *p) u32 *data, length; int request_tcode, t; - request_tcode = header_get_tcode(p->header[0]); + request_tcode = HEADER_GET_TCODE(p->header[0]); switch (request_tcode) { case TCODE_WRITE_QUADLET_REQUEST: data = &p->header[3]; @@ -493,7 +577,7 @@ allocate_request(struct fw_packet *p) case TCODE_WRITE_BLOCK_REQUEST: case TCODE_LOCK_REQUEST: data = p->payload; - length = header_get_data_length(p->header[3]); + length = HEADER_GET_DATA_LENGTH(p->header[3]); break; case TCODE_READ_QUADLET_REQUEST: @@ -503,15 +587,16 @@ allocate_request(struct fw_packet *p) case TCODE_READ_BLOCK_REQUEST: data = NULL; - length = header_get_data_length(p->header[3]); + length = HEADER_GET_DATA_LENGTH(p->header[3]); break; default: - BUG(); + fw_error("ERROR - corrupt request received - %08x %08x %08x\n", + p->header[0], p->header[1], p->header[2]); return NULL; } - request = kmalloc(sizeof *request + length, GFP_ATOMIC); + request = kmalloc(sizeof(*request) + length, GFP_ATOMIC); if (request == NULL) return NULL; @@ -524,13 +609,14 @@ allocate_request(struct fw_packet *p) request->response.speed = p->speed; request->response.timestamp = t; request->response.generation = p->generation; + request->response.ack = 0; request->response.callback = free_response_callback; request->ack = p->ack; - request->length = p->payload_length; + request->length = length; if (data) - memcpy(request->data, p->payload, p->payload_length); + memcpy(request->data, data, length); - fw_fill_response(&request->response, p, request->data); + memcpy(request->request_header, p->header, sizeof(p->header)); return request; } @@ -538,21 +624,22 @@ allocate_request(struct fw_packet *p) void fw_send_response(struct fw_card *card, struct fw_request *request, int rcode) { - int response_tcode; - - /* Broadcast packets are reported as ACK_COMPLETE, so this + /* + * Broadcast packets are reported as ACK_COMPLETE, so this * check is sufficient to ensure we don't send response to - * broadcast packets or posted writes. */ - if (request->ack != ACK_PENDING) + * broadcast packets or posted writes. + */ + if (request->ack != ACK_PENDING) { + kfree(request); return; + } - request->response.header[1] |= header_rcode(rcode); - response_tcode = header_get_tcode(request->response.header[0]); - if (rcode != RCODE_COMPLETE) - /* Clear the data_length field. */ - request->response.header[3] &= 0xffff; - else if (response_tcode == TCODE_READ_QUADLET_RESPONSE) - request->response.header[3] = request->data[0]; + if (rcode == RCODE_COMPLETE) + fw_fill_response(&request->response, request->request_header, + rcode, request->data, request->length); + else + fw_fill_response(&request->response, request->request_header, + rcode, NULL, 0); card->driver->send_response(card, &request->response); } @@ -567,11 +654,6 @@ fw_core_handle_request(struct fw_card *card, struct fw_packet *p) unsigned long flags; int tcode, destination, source; - if (p->payload_length > 2048) { - /* FIXME: send error response. */ - return; - } - if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE) return; @@ -583,21 +665,23 @@ fw_core_handle_request(struct fw_card *card, struct fw_packet *p) offset = ((unsigned long long) - header_get_offset_high(p->header[1]) << 32) | p->header[2]; - tcode = header_get_tcode(p->header[0]); - destination = header_get_destination(p->header[0]); - source = header_get_source(p->header[0]); + HEADER_GET_OFFSET_HIGH(p->header[1]) << 32) | p->header[2]; + tcode = HEADER_GET_TCODE(p->header[0]); + destination = HEADER_GET_DESTINATION(p->header[0]); + source = HEADER_GET_SOURCE(p->header[1]); spin_lock_irqsave(&address_handler_lock, flags); handler = lookup_enclosing_address_handler(&address_handler_list, offset, request->length); spin_unlock_irqrestore(&address_handler_lock, flags); - /* FIXME: lookup the fw_node corresponding to the sender of + /* + * FIXME: lookup the fw_node corresponding to the sender of * this request and pass that to the address handler instead * of the node ID. We may also want to move the address * allocations to fw_node so we only do this callback if the - * upper layers registered it for this node. */ + * upper layers registered it for this node. + */ if (handler == NULL) fw_send_response(card, request, RCODE_ADDRESS_ERROR); @@ -619,11 +703,11 @@ fw_core_handle_response(struct fw_card *card, struct fw_packet *p) size_t data_length; int tcode, tlabel, destination, source, rcode; - tcode = header_get_tcode(p->header[0]); - tlabel = header_get_tlabel(p->header[0]); - destination = header_get_destination(p->header[0]); - source = header_get_source(p->header[1]); - rcode = header_get_rcode(p->header[1]); + tcode = HEADER_GET_TCODE(p->header[0]); + tlabel = HEADER_GET_TLABEL(p->header[0]); + destination = HEADER_GET_DESTINATION(p->header[0]); + source = HEADER_GET_SOURCE(p->header[1]); + rcode = HEADER_GET_RCODE(p->header[1]); spin_lock_irqsave(&card->lock, flags); list_for_each_entry(t, &card->transaction_list, link) { @@ -636,12 +720,15 @@ fw_core_handle_response(struct fw_card *card, struct fw_packet *p) spin_unlock_irqrestore(&card->lock, flags); if (&t->link == &card->transaction_list) { - fw_notify("Unsolicited response\n"); + fw_notify("Unsolicited response (source %x, tlabel %x)\n", + source, tlabel); return; } - /* FIXME: sanity check packet, is length correct, does tcodes - * and addresses match. */ + /* + * FIXME: sanity check packet, is length correct, does tcodes + * and addresses match. + */ switch (tcode) { case TCODE_READ_QUADLET_RESPONSE: @@ -656,8 +743,8 @@ fw_core_handle_response(struct fw_card *card, struct fw_packet *p) case TCODE_READ_BLOCK_RESPONSE: case TCODE_LOCK_RESPONSE: - data = &p->header[4]; - data_length = header_get_data_length(p->header[3]); + data = p->payload; + data_length = HEADER_GET_DATA_LENGTH(p->header[3]); break; default: @@ -667,31 +754,148 @@ fw_core_handle_response(struct fw_card *card, struct fw_packet *p) break; } + /* + * The response handler may be executed while the request handler + * is still pending. Cancel the request handler. + */ + card->driver->cancel_packet(card, &t->packet); + t->callback(card, rcode, data, data_length, t->callback_data); } EXPORT_SYMBOL(fw_core_handle_response); +static const struct fw_address_region topology_map_region = + { .start = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP, + .end = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP_END, }; + +static void +handle_topology_map(struct fw_card *card, struct fw_request *request, + int tcode, int destination, int source, + int generation, int speed, + unsigned long long offset, + void *payload, size_t length, void *callback_data) +{ + int i, start, end; + __be32 *map; + + if (!TCODE_IS_READ_REQUEST(tcode)) { + fw_send_response(card, request, RCODE_TYPE_ERROR); + return; + } + + if ((offset & 3) > 0 || (length & 3) > 0) { + fw_send_response(card, request, RCODE_ADDRESS_ERROR); + return; + } + + start = (offset - topology_map_region.start) / 4; + end = start + length / 4; + map = payload; + + for (i = 0; i < length / 4; i++) + map[i] = cpu_to_be32(card->topology_map[start + i]); + + fw_send_response(card, request, RCODE_COMPLETE); +} + +static struct fw_address_handler topology_map = { + .length = 0x200, + .address_callback = handle_topology_map, +}; + +static const struct fw_address_region registers_region = + { .start = CSR_REGISTER_BASE, + .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, }; + +static void +handle_registers(struct fw_card *card, struct fw_request *request, + int tcode, int destination, int source, + int generation, int speed, + unsigned long long offset, + void *payload, size_t length, void *callback_data) +{ + int reg = offset & ~CSR_REGISTER_BASE; + unsigned long long bus_time; + __be32 *data = payload; + + switch (reg) { + case CSR_CYCLE_TIME: + case CSR_BUS_TIME: + if (!TCODE_IS_READ_REQUEST(tcode) || length != 4) { + fw_send_response(card, request, RCODE_TYPE_ERROR); + break; + } + + bus_time = card->driver->get_bus_time(card); + if (reg == CSR_CYCLE_TIME) + *data = cpu_to_be32(bus_time); + else + *data = cpu_to_be32(bus_time >> 25); + fw_send_response(card, request, RCODE_COMPLETE); + break; + + case CSR_BUS_MANAGER_ID: + case CSR_BANDWIDTH_AVAILABLE: + case CSR_CHANNELS_AVAILABLE_HI: + case CSR_CHANNELS_AVAILABLE_LO: + /* + * FIXME: these are handled by the OHCI hardware and + * the stack never sees these request. If we add + * support for a new type of controller that doesn't + * handle this in hardware we need to deal with these + * transactions. + */ + BUG(); + break; + + case CSR_BUSY_TIMEOUT: + /* FIXME: Implement this. */ + default: + fw_send_response(card, request, RCODE_ADDRESS_ERROR); + break; + } +} + +static struct fw_address_handler registers = { + .length = 0x400, + .address_callback = handle_registers, +}; + MODULE_AUTHOR("Kristian Hoegsberg "); MODULE_DESCRIPTION("Core IEEE1394 transaction logic"); MODULE_LICENSE("GPL"); -static const u32 vendor_textual_descriptor_data[] = { +static const u32 vendor_textual_descriptor[] = { /* textual descriptor leaf () */ - 0x00080000, + 0x00060000, 0x00000000, 0x00000000, 0x4c696e75, /* L i n u */ 0x78204669, /* x F i */ 0x72657769, /* r e w i */ - 0x72652028, /* r e ( */ - 0x4a554a55, /* J U J U */ - 0x29000000, /* ) */ + 0x72650000, /* r e */ }; -static struct fw_descriptor vendor_textual_descriptor = { - .length = ARRAY_SIZE(vendor_textual_descriptor_data), +static const u32 model_textual_descriptor[] = { + /* model descriptor leaf () */ + 0x00030000, + 0x00000000, + 0x00000000, + 0x4a756a75, /* J u j u */ +}; + +static struct fw_descriptor vendor_id_descriptor = { + .length = ARRAY_SIZE(vendor_textual_descriptor), + .immediate = 0x03d00d1e, + .key = 0x81000000, + .data = vendor_textual_descriptor, +}; + +static struct fw_descriptor model_id_descriptor = { + .length = ARRAY_SIZE(model_textual_descriptor), + .immediate = 0x17000001, .key = 0x81000000, - .data = vendor_textual_descriptor_data, + .data = model_textual_descriptor, }; static int __init fw_core_init(void) @@ -702,8 +906,24 @@ static int __init fw_core_init(void) if (retval < 0) return retval; + fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops); + if (fw_cdev_major < 0) { + bus_unregister(&fw_bus_type); + return fw_cdev_major; + } + + retval = fw_core_add_address_handler(&topology_map, + &topology_map_region); + BUG_ON(retval < 0); + + retval = fw_core_add_address_handler(®isters, + ®isters_region); + BUG_ON(retval < 0); + /* Add the vendor textual descriptor. */ - retval = fw_core_add_descriptor(&vendor_textual_descriptor); + retval = fw_core_add_descriptor(&vendor_id_descriptor); + BUG_ON(retval < 0); + retval = fw_core_add_descriptor(&model_id_descriptor); BUG_ON(retval < 0); return 0; @@ -711,6 +931,7 @@ static int __init fw_core_init(void) static void __exit fw_core_cleanup(void) { + unregister_chrdev(fw_cdev_major, "firewire"); bus_unregister(&fw_bus_type); }