Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Core IEEE1394 transaction logic |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 3 | * |
| 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 Richter | 2a0a259 | 2008-03-20 23:48:23 +0100 | [diff] [blame] | 21 | #include <linux/completion.h> |
Stefan Richter | d6053e0 | 2008-11-24 20:40:00 +0100 | [diff] [blame] | 22 | #include <linux/idr.h> |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 23 | #include <linux/kernel.h> |
Stefan Richter | ae1e535 | 2008-06-18 18:20:45 +0200 | [diff] [blame] | 24 | #include <linux/kref.h> |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 25 | #include <linux/module.h> |
Stefan Richter | c0220d6 | 2008-07-22 21:35:47 +0200 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 27 | #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øgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 35 | |
| 36 | #include "fw-transaction.h" |
| 37 | #include "fw-topology.h" |
Kristian Høgsberg | 19a15b9 | 2006-12-19 19:58:31 -0500 | [diff] [blame] | 38 | #include "fw-device.h" |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 39 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 40 | #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øgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 50 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 51 | #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øgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 59 | |
Stefan Richter | a7ea678 | 2008-05-25 11:06:55 +0200 | [diff] [blame] | 60 | #define HEADER_DESTINATION_IS_BROADCAST(q) \ |
| 61 | (((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f)) |
| 62 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 63 | #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øgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 66 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 67 | static int close_transaction(struct fw_transaction *transaction, |
Stefan Richter | a38a00f | 2009-03-10 21:07:06 +0100 | [diff] [blame] | 68 | struct fw_card *card, int rcode) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 69 | { |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 70 | struct fw_transaction *t; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 71 | unsigned long flags; |
| 72 | |
| 73 | spin_lock_irqsave(&card->lock, flags); |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 74 | list_for_each_entry(t, &card->transaction_list, link) { |
| 75 | if (t == transaction) { |
| 76 | list_del(&t->link); |
| 77 | card->tlabel_mask &= ~(1 << t->tlabel); |
| 78 | break; |
| 79 | } |
| 80 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 81 | spin_unlock_irqrestore(&card->lock, flags); |
| 82 | |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 83 | if (&t->link != &card->transaction_list) { |
Stefan Richter | a38a00f | 2009-03-10 21:07:06 +0100 | [diff] [blame] | 84 | t->callback(card, rcode, NULL, 0, t->callback_data); |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | return -ENOENT; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 89 | } |
| 90 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 91 | /* |
| 92 | * Only valid for transactions that are potentially pending (ie have |
| 93 | * been sent). |
| 94 | */ |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 95 | int fw_cancel_transaction(struct fw_card *card, |
| 96 | struct fw_transaction *transaction) |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 97 | { |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 98 | /* |
| 99 | * Cancel the packet transmission if it's still queued. That |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 100 | * will call the packet transmission callback which cancels |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 101 | * the transaction. |
| 102 | */ |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 103 | |
| 104 | if (card->driver->cancel_packet(card, &transaction->packet) == 0) |
| 105 | return 0; |
| 106 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 107 | /* |
| 108 | * If the request packet has already been sent, we need to see |
| 109 | * if the transaction is still pending and remove it in that case. |
| 110 | */ |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 111 | |
Stefan Richter | a38a00f | 2009-03-10 21:07:06 +0100 | [diff] [blame] | 112 | return close_transaction(transaction, card, RCODE_CANCELLED); |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 113 | } |
| 114 | EXPORT_SYMBOL(fw_cancel_transaction); |
| 115 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 116 | static void transmit_complete_callback(struct fw_packet *packet, |
| 117 | struct fw_card *card, int status) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 118 | { |
| 119 | struct fw_transaction *t = |
| 120 | container_of(packet, struct fw_transaction, packet); |
| 121 | |
| 122 | switch (status) { |
| 123 | case ACK_COMPLETE: |
Stefan Richter | a38a00f | 2009-03-10 21:07:06 +0100 | [diff] [blame] | 124 | close_transaction(t, card, RCODE_COMPLETE); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 125 | break; |
| 126 | case ACK_PENDING: |
| 127 | t->timestamp = packet->timestamp; |
| 128 | break; |
| 129 | case ACK_BUSY_X: |
| 130 | case ACK_BUSY_A: |
| 131 | case ACK_BUSY_B: |
Stefan Richter | a38a00f | 2009-03-10 21:07:06 +0100 | [diff] [blame] | 132 | close_transaction(t, card, RCODE_BUSY); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 133 | break; |
| 134 | case ACK_DATA_ERROR: |
Stefan Richter | a38a00f | 2009-03-10 21:07:06 +0100 | [diff] [blame] | 135 | close_transaction(t, card, RCODE_DATA_ERROR); |
Kristian Høgsberg | e5f49c3 | 2007-01-26 00:38:34 -0500 | [diff] [blame] | 136 | break; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 137 | case ACK_TYPE_ERROR: |
Stefan Richter | a38a00f | 2009-03-10 21:07:06 +0100 | [diff] [blame] | 138 | close_transaction(t, card, RCODE_TYPE_ERROR); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 139 | break; |
| 140 | default: |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 141 | /* |
| 142 | * In this case the ack is really a juju specific |
| 143 | * rcode, so just forward that to the callback. |
| 144 | */ |
Stefan Richter | a38a00f | 2009-03-10 21:07:06 +0100 | [diff] [blame] | 145 | close_transaction(t, card, status); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 146 | break; |
| 147 | } |
| 148 | } |
| 149 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 150 | static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel, |
Stefan Richter | b9549bc | 2008-07-12 14:50:42 +0200 | [diff] [blame] | 151 | int destination_id, int source_id, int generation, int speed, |
Kristian Høgsberg | 36bfe49 | 2007-01-26 00:38:13 -0500 | [diff] [blame] | 152 | unsigned long long offset, void *payload, size_t length) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 153 | { |
| 154 | int ext_tcode; |
| 155 | |
Stefan Richter | 18e9b10f | 2009-03-10 21:02:21 +0100 | [diff] [blame] | 156 | if (tcode == TCODE_STREAM_DATA) { |
| 157 | packet->header[0] = |
| 158 | HEADER_DATA_LENGTH(length) | |
| 159 | destination_id | |
| 160 | HEADER_TCODE(TCODE_STREAM_DATA); |
| 161 | packet->header_length = 4; |
| 162 | packet->payload = payload; |
| 163 | packet->payload_length = length; |
| 164 | |
| 165 | goto common; |
| 166 | } |
| 167 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 168 | if (tcode > 0x10) { |
Jarod Wilson | 8f9f963 | 2008-01-23 16:05:45 -0500 | [diff] [blame] | 169 | ext_tcode = tcode & ~0x10; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 170 | tcode = TCODE_LOCK_REQUEST; |
| 171 | } else |
| 172 | ext_tcode = 0; |
| 173 | |
| 174 | packet->header[0] = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 175 | HEADER_RETRY(RETRY_X) | |
| 176 | HEADER_TLABEL(tlabel) | |
| 177 | HEADER_TCODE(tcode) | |
Stefan Richter | b9549bc | 2008-07-12 14:50:42 +0200 | [diff] [blame] | 178 | HEADER_DESTINATION(destination_id); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 179 | packet->header[1] = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 180 | HEADER_OFFSET_HIGH(offset >> 32) | HEADER_SOURCE(source_id); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 181 | packet->header[2] = |
| 182 | offset; |
| 183 | |
| 184 | switch (tcode) { |
| 185 | case TCODE_WRITE_QUADLET_REQUEST: |
| 186 | packet->header[3] = *(u32 *)payload; |
| 187 | packet->header_length = 16; |
| 188 | packet->payload_length = 0; |
| 189 | break; |
| 190 | |
| 191 | case TCODE_LOCK_REQUEST: |
| 192 | case TCODE_WRITE_BLOCK_REQUEST: |
| 193 | packet->header[3] = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 194 | HEADER_DATA_LENGTH(length) | |
| 195 | HEADER_EXTENDED_TCODE(ext_tcode); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 196 | packet->header_length = 16; |
| 197 | packet->payload = payload; |
| 198 | packet->payload_length = length; |
| 199 | break; |
| 200 | |
| 201 | case TCODE_READ_QUADLET_REQUEST: |
| 202 | packet->header_length = 12; |
| 203 | packet->payload_length = 0; |
| 204 | break; |
| 205 | |
| 206 | case TCODE_READ_BLOCK_REQUEST: |
| 207 | packet->header[3] = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 208 | HEADER_DATA_LENGTH(length) | |
| 209 | HEADER_EXTENDED_TCODE(ext_tcode); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 210 | packet->header_length = 16; |
| 211 | packet->payload_length = 0; |
| 212 | break; |
| 213 | } |
Stefan Richter | 18e9b10f | 2009-03-10 21:02:21 +0100 | [diff] [blame] | 214 | common: |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 215 | packet->speed = speed; |
| 216 | packet->generation = generation; |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 217 | packet->ack = 0; |
Stefan Richter | 1d1dc5e | 2008-12-10 00:20:38 +0100 | [diff] [blame] | 218 | packet->payload_bus = 0; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
| 222 | * This function provides low-level access to the IEEE1394 transaction |
| 223 | * logic. Most C programs would use either fw_read(), fw_write() or |
| 224 | * fw_lock() instead - those function are convenience wrappers for |
| 225 | * this function. The fw_send_request() function is primarily |
| 226 | * provided as a flexible, one-stop entry point for languages bindings |
| 227 | * and protocol bindings. |
| 228 | * |
| 229 | * FIXME: Document this function further, in particular the possible |
| 230 | * values for rcode in the callback. In short, we map ACK_COMPLETE to |
| 231 | * RCODE_COMPLETE, internal errors set errno and set rcode to |
| 232 | * RCODE_SEND_ERROR (which is out of range for standard ieee1394 |
| 233 | * rcodes). All other rcodes are forwarded unchanged. For all |
| 234 | * errors, payload is NULL, length is 0. |
| 235 | * |
| 236 | * Can not expect the callback to be called before the function |
| 237 | * returns, though this does happen in some cases (ACK_COMPLETE and |
| 238 | * errors). |
| 239 | * |
| 240 | * The payload is only used for write requests and must not be freed |
| 241 | * until the callback has been called. |
| 242 | * |
| 243 | * @param card the card from which to send the request |
| 244 | * @param tcode the tcode for this transaction. Do not use |
Uwe Kleine-König | dbe7f76 | 2007-10-20 01:55:04 +0200 | [diff] [blame] | 245 | * TCODE_LOCK_REQUEST directly, instead use TCODE_LOCK_MASK_SWAP |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 246 | * etc. to specify tcode and ext_tcode. |
Stefan Richter | 907293d | 2007-01-23 21:11:43 +0100 | [diff] [blame] | 247 | * @param node_id the destination node ID (bus ID and PHY ID concatenated) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 248 | * @param generation the generation for which node_id is valid |
| 249 | * @param speed the speed to use for sending the request |
| 250 | * @param offset the 48 bit offset on the destination node |
| 251 | * @param payload the data payload for the request subaction |
| 252 | * @param length the length in bytes of the data to read |
| 253 | * @param callback function to be called when the transaction is completed |
| 254 | * @param callback_data pointer to arbitrary data, which will be |
| 255 | * passed to the callback |
Stefan Richter | 18e9b10f | 2009-03-10 21:02:21 +0100 | [diff] [blame] | 256 | * |
| 257 | * In case of asynchronous stream packets i.e. TCODE_STREAM_DATA, the caller |
| 258 | * needs to synthesize @destination_id with fw_stream_packet_destination_id(). |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 259 | */ |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 260 | void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, |
| 261 | int destination_id, int generation, int speed, |
| 262 | unsigned long long offset, void *payload, size_t length, |
| 263 | fw_transaction_callback_t callback, void *callback_data) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 264 | { |
| 265 | unsigned long flags; |
Stefan Richter | b9549bc | 2008-07-12 14:50:42 +0200 | [diff] [blame] | 266 | int tlabel; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 267 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 268 | /* |
| 269 | * Bump the flush timer up 100ms first of all so we |
| 270 | * don't race with a flush timer callback. |
| 271 | */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 272 | |
| 273 | mod_timer(&card->flush_timer, jiffies + DIV_ROUND_UP(HZ, 10)); |
| 274 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 275 | /* |
| 276 | * Allocate tlabel from the bitmap and put the transaction on |
| 277 | * the list while holding the card spinlock. |
| 278 | */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 279 | |
| 280 | spin_lock_irqsave(&card->lock, flags); |
| 281 | |
| 282 | tlabel = card->current_tlabel; |
| 283 | if (card->tlabel_mask & (1 << tlabel)) { |
| 284 | spin_unlock_irqrestore(&card->lock, flags); |
| 285 | callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | card->current_tlabel = (card->current_tlabel + 1) & 0x1f; |
| 290 | card->tlabel_mask |= (1 << tlabel); |
| 291 | |
Jay Fenlason | 1e119fa | 2008-07-20 14:20:53 +0200 | [diff] [blame] | 292 | t->node_id = destination_id; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 293 | t->tlabel = tlabel; |
| 294 | t->callback = callback; |
| 295 | t->callback_data = callback_data; |
| 296 | |
Jay Fenlason | 1e119fa | 2008-07-20 14:20:53 +0200 | [diff] [blame] | 297 | fw_fill_request(&t->packet, tcode, t->tlabel, |
| 298 | destination_id, card->node_id, generation, |
| 299 | speed, offset, payload, length); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 300 | t->packet.callback = transmit_complete_callback; |
| 301 | |
Stefan Richter | e9aeb46 | 2008-07-12 14:50:06 +0200 | [diff] [blame] | 302 | list_add_tail(&t->link, &card->transaction_list); |
| 303 | |
| 304 | spin_unlock_irqrestore(&card->lock, flags); |
| 305 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 306 | card->driver->send_request(card, &t->packet); |
| 307 | } |
| 308 | EXPORT_SYMBOL(fw_send_request); |
| 309 | |
Jay Fenlason | 1e119fa | 2008-07-20 14:20:53 +0200 | [diff] [blame] | 310 | struct transaction_callback_data { |
| 311 | struct completion done; |
| 312 | void *payload; |
| 313 | int rcode; |
| 314 | }; |
| 315 | |
| 316 | static void transaction_callback(struct fw_card *card, int rcode, |
| 317 | void *payload, size_t length, void *data) |
| 318 | { |
| 319 | struct transaction_callback_data *d = data; |
| 320 | |
| 321 | if (rcode == RCODE_COMPLETE) |
| 322 | memcpy(d->payload, payload, length); |
| 323 | d->rcode = rcode; |
| 324 | complete(&d->done); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * fw_run_transaction - send request and sleep until transaction is completed |
| 329 | * |
| 330 | * Returns the RCODE. |
| 331 | */ |
| 332 | int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 333 | int generation, int speed, unsigned long long offset, |
Stefan Richter | ba27e1f | 2009-03-05 19:07:00 +0100 | [diff] [blame] | 334 | void *payload, size_t length) |
Jay Fenlason | 1e119fa | 2008-07-20 14:20:53 +0200 | [diff] [blame] | 335 | { |
| 336 | struct transaction_callback_data d; |
| 337 | struct fw_transaction t; |
| 338 | |
| 339 | init_completion(&d.done); |
Stefan Richter | ba27e1f | 2009-03-05 19:07:00 +0100 | [diff] [blame] | 340 | d.payload = payload; |
Jay Fenlason | 1e119fa | 2008-07-20 14:20:53 +0200 | [diff] [blame] | 341 | fw_send_request(card, &t, tcode, destination_id, generation, speed, |
Stefan Richter | ba27e1f | 2009-03-05 19:07:00 +0100 | [diff] [blame] | 342 | offset, payload, length, transaction_callback, &d); |
Jay Fenlason | 1e119fa | 2008-07-20 14:20:53 +0200 | [diff] [blame] | 343 | wait_for_completion(&d.done); |
| 344 | |
| 345 | return d.rcode; |
| 346 | } |
| 347 | EXPORT_SYMBOL(fw_run_transaction); |
| 348 | |
Stefan Richter | c0220d6 | 2008-07-22 21:35:47 +0200 | [diff] [blame] | 349 | static DEFINE_MUTEX(phy_config_mutex); |
| 350 | static DECLARE_COMPLETION(phy_config_done); |
Stefan Richter | ae1e535 | 2008-06-18 18:20:45 +0200 | [diff] [blame] | 351 | |
| 352 | static void transmit_phy_packet_callback(struct fw_packet *packet, |
| 353 | struct fw_card *card, int status) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 354 | { |
Stefan Richter | c0220d6 | 2008-07-22 21:35:47 +0200 | [diff] [blame] | 355 | complete(&phy_config_done); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 356 | } |
| 357 | |
Stefan Richter | c0220d6 | 2008-07-22 21:35:47 +0200 | [diff] [blame] | 358 | static struct fw_packet phy_config_packet = { |
| 359 | .header_length = 8, |
| 360 | .payload_length = 0, |
| 361 | .speed = SCODE_100, |
| 362 | .callback = transmit_phy_packet_callback, |
| 363 | }; |
| 364 | |
Kristian Høgsberg | 83db801 | 2007-01-26 00:37:50 -0500 | [diff] [blame] | 365 | void fw_send_phy_config(struct fw_card *card, |
| 366 | int node_id, int generation, int gap_count) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 367 | { |
Stefan Richter | ae1e535 | 2008-06-18 18:20:45 +0200 | [diff] [blame] | 368 | long timeout = DIV_ROUND_UP(HZ, 10); |
Stefan Richter | 2a0a259 | 2008-03-20 23:48:23 +0100 | [diff] [blame] | 369 | u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG) | |
| 370 | PHY_CONFIG_ROOT_ID(node_id) | |
| 371 | PHY_CONFIG_GAP_COUNT(gap_count); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 372 | |
Stefan Richter | c0220d6 | 2008-07-22 21:35:47 +0200 | [diff] [blame] | 373 | mutex_lock(&phy_config_mutex); |
Kristian Høgsberg | 83db801 | 2007-01-26 00:37:50 -0500 | [diff] [blame] | 374 | |
Stefan Richter | c0220d6 | 2008-07-22 21:35:47 +0200 | [diff] [blame] | 375 | phy_config_packet.header[0] = data; |
| 376 | phy_config_packet.header[1] = ~data; |
| 377 | phy_config_packet.generation = generation; |
| 378 | INIT_COMPLETION(phy_config_done); |
Stefan Richter | ae1e535 | 2008-06-18 18:20:45 +0200 | [diff] [blame] | 379 | |
Stefan Richter | c0220d6 | 2008-07-22 21:35:47 +0200 | [diff] [blame] | 380 | card->driver->send_request(card, &phy_config_packet); |
| 381 | wait_for_completion_timeout(&phy_config_done, timeout); |
Stefan Richter | ae1e535 | 2008-06-18 18:20:45 +0200 | [diff] [blame] | 382 | |
Stefan Richter | c0220d6 | 2008-07-22 21:35:47 +0200 | [diff] [blame] | 383 | mutex_unlock(&phy_config_mutex); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void fw_flush_transactions(struct fw_card *card) |
| 387 | { |
| 388 | struct fw_transaction *t, *next; |
| 389 | struct list_head list; |
| 390 | unsigned long flags; |
| 391 | |
| 392 | INIT_LIST_HEAD(&list); |
| 393 | spin_lock_irqsave(&card->lock, flags); |
| 394 | list_splice_init(&card->transaction_list, &list); |
| 395 | card->tlabel_mask = 0; |
| 396 | spin_unlock_irqrestore(&card->lock, flags); |
| 397 | |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 398 | list_for_each_entry_safe(t, next, &list, link) { |
| 399 | card->driver->cancel_packet(card, &t->packet); |
| 400 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 401 | /* |
| 402 | * At this point cancel_packet will never call the |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 403 | * transaction callback, since we just took all the |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 404 | * transactions out of the list. So do it here. |
| 405 | */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 406 | t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data); |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 407 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 408 | } |
| 409 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 410 | static struct fw_address_handler *lookup_overlapping_address_handler( |
| 411 | struct list_head *list, unsigned long long offset, size_t length) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 412 | { |
| 413 | struct fw_address_handler *handler; |
| 414 | |
| 415 | list_for_each_entry(handler, list, link) { |
| 416 | if (handler->offset < offset + length && |
| 417 | offset < handler->offset + handler->length) |
| 418 | return handler; |
| 419 | } |
| 420 | |
| 421 | return NULL; |
| 422 | } |
| 423 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 424 | static struct fw_address_handler *lookup_enclosing_address_handler( |
| 425 | struct list_head *list, unsigned long long offset, size_t length) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 426 | { |
| 427 | struct fw_address_handler *handler; |
| 428 | |
| 429 | list_for_each_entry(handler, list, link) { |
| 430 | if (handler->offset <= offset && |
| 431 | offset + length <= handler->offset + handler->length) |
| 432 | return handler; |
| 433 | } |
| 434 | |
| 435 | return NULL; |
| 436 | } |
| 437 | |
| 438 | static DEFINE_SPINLOCK(address_handler_lock); |
| 439 | static LIST_HEAD(address_handler_list); |
| 440 | |
Stefan Richter | 21ebcd1 | 2007-01-14 15:29:07 +0100 | [diff] [blame] | 441 | const struct fw_address_region fw_high_memory_region = |
Stefan Richter | 5af4e5e | 2007-01-21 20:45:32 +0100 | [diff] [blame] | 442 | { .start = 0x000100000000ULL, .end = 0xffffe0000000ULL, }; |
Adrian Bunk | db8be07 | 2008-03-31 02:22:11 +0300 | [diff] [blame] | 443 | EXPORT_SYMBOL(fw_high_memory_region); |
| 444 | |
| 445 | #if 0 |
| 446 | const struct fw_address_region fw_low_memory_region = |
| 447 | { .start = 0x000000000000ULL, .end = 0x000100000000ULL, }; |
Stefan Richter | 21ebcd1 | 2007-01-14 15:29:07 +0100 | [diff] [blame] | 448 | const struct fw_address_region fw_private_region = |
Stefan Richter | 5af4e5e | 2007-01-21 20:45:32 +0100 | [diff] [blame] | 449 | { .start = 0xffffe0000000ULL, .end = 0xfffff0000000ULL, }; |
Stefan Richter | 21ebcd1 | 2007-01-14 15:29:07 +0100 | [diff] [blame] | 450 | const struct fw_address_region fw_csr_region = |
Jarod Wilson | cca6097 | 2008-03-08 12:52:03 -0500 | [diff] [blame] | 451 | { .start = CSR_REGISTER_BASE, |
| 452 | .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM_END, }; |
Stefan Richter | 21ebcd1 | 2007-01-14 15:29:07 +0100 | [diff] [blame] | 453 | const struct fw_address_region fw_unit_space_region = |
Stefan Richter | 5af4e5e | 2007-01-21 20:45:32 +0100 | [diff] [blame] | 454 | { .start = 0xfffff0000900ULL, .end = 0x1000000000000ULL, }; |
Adrian Bunk | db8be07 | 2008-03-31 02:22:11 +0300 | [diff] [blame] | 455 | #endif /* 0 */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 456 | |
| 457 | /** |
Stefan Richter | 3e0b5f0 | 2008-12-14 19:21:01 +0100 | [diff] [blame] | 458 | * fw_core_add_address_handler - register for incoming requests |
| 459 | * @handler: callback |
| 460 | * @region: region in the IEEE 1212 node space address range |
| 461 | * |
| 462 | * region->start, ->end, and handler->length have to be quadlet-aligned. |
| 463 | * |
| 464 | * When a request is received that falls within the specified address range, |
| 465 | * the specified callback is invoked. The parameters passed to the callback |
| 466 | * give the details of the particular request. |
Stefan Richter | 1415d91 | 2007-07-17 02:10:16 +0200 | [diff] [blame] | 467 | * |
| 468 | * Return value: 0 on success, non-zero otherwise. |
| 469 | * The start offset of the handler's address region is determined by |
| 470 | * fw_core_add_address_handler() and is returned in handler->offset. |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 471 | */ |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 472 | int fw_core_add_address_handler(struct fw_address_handler *handler, |
| 473 | const struct fw_address_region *region) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 474 | { |
| 475 | struct fw_address_handler *other; |
| 476 | unsigned long flags; |
| 477 | int ret = -EBUSY; |
| 478 | |
Stefan Richter | 3e0b5f0 | 2008-12-14 19:21:01 +0100 | [diff] [blame] | 479 | if (region->start & 0xffff000000000003ULL || |
| 480 | region->end & 0xffff000000000003ULL || |
| 481 | region->start >= region->end || |
| 482 | handler->length & 3 || |
| 483 | handler->length == 0) |
| 484 | return -EINVAL; |
| 485 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 486 | spin_lock_irqsave(&address_handler_lock, flags); |
| 487 | |
Stefan Richter | 3e0b5f0 | 2008-12-14 19:21:01 +0100 | [diff] [blame] | 488 | handler->offset = region->start; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 489 | while (handler->offset + handler->length <= region->end) { |
| 490 | other = |
| 491 | lookup_overlapping_address_handler(&address_handler_list, |
| 492 | handler->offset, |
| 493 | handler->length); |
| 494 | if (other != NULL) { |
Stefan Richter | 3e0b5f0 | 2008-12-14 19:21:01 +0100 | [diff] [blame] | 495 | handler->offset += other->length; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 496 | } else { |
| 497 | list_add_tail(&handler->link, &address_handler_list); |
| 498 | ret = 0; |
| 499 | break; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | spin_unlock_irqrestore(&address_handler_lock, flags); |
| 504 | |
| 505 | return ret; |
| 506 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 507 | EXPORT_SYMBOL(fw_core_add_address_handler); |
| 508 | |
| 509 | /** |
Stefan Richter | 44be21b | 2008-12-14 19:21:31 +0100 | [diff] [blame] | 510 | * fw_core_remove_address_handler - unregister an address handler |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 511 | */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 512 | void fw_core_remove_address_handler(struct fw_address_handler *handler) |
| 513 | { |
| 514 | unsigned long flags; |
| 515 | |
| 516 | spin_lock_irqsave(&address_handler_lock, flags); |
| 517 | list_del(&handler->link); |
| 518 | spin_unlock_irqrestore(&address_handler_lock, flags); |
| 519 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 520 | EXPORT_SYMBOL(fw_core_remove_address_handler); |
| 521 | |
| 522 | struct fw_request { |
| 523 | struct fw_packet response; |
Kristian Høgsberg | 36bfe49 | 2007-01-26 00:38:13 -0500 | [diff] [blame] | 524 | u32 request_header[4]; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 525 | int ack; |
| 526 | u32 length; |
| 527 | u32 data[0]; |
| 528 | }; |
| 529 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 530 | static void free_response_callback(struct fw_packet *packet, |
| 531 | struct fw_card *card, int status) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 532 | { |
| 533 | struct fw_request *request; |
| 534 | |
| 535 | request = container_of(packet, struct fw_request, response); |
| 536 | kfree(request); |
| 537 | } |
| 538 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 539 | void fw_fill_response(struct fw_packet *response, u32 *request_header, |
| 540 | int rcode, void *payload, size_t length) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 541 | { |
| 542 | int tcode, tlabel, extended_tcode, source, destination; |
| 543 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 544 | tcode = HEADER_GET_TCODE(request_header[0]); |
| 545 | tlabel = HEADER_GET_TLABEL(request_header[0]); |
| 546 | source = HEADER_GET_DESTINATION(request_header[0]); |
| 547 | destination = HEADER_GET_SOURCE(request_header[1]); |
| 548 | extended_tcode = HEADER_GET_EXTENDED_TCODE(request_header[3]); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 549 | |
| 550 | response->header[0] = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 551 | HEADER_RETRY(RETRY_1) | |
| 552 | HEADER_TLABEL(tlabel) | |
| 553 | HEADER_DESTINATION(destination); |
Kristian Høgsberg | 36bfe49 | 2007-01-26 00:38:13 -0500 | [diff] [blame] | 554 | response->header[1] = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 555 | HEADER_SOURCE(source) | |
| 556 | HEADER_RCODE(rcode); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 557 | response->header[2] = 0; |
| 558 | |
| 559 | switch (tcode) { |
| 560 | case TCODE_WRITE_QUADLET_REQUEST: |
| 561 | case TCODE_WRITE_BLOCK_REQUEST: |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 562 | response->header[0] |= HEADER_TCODE(TCODE_WRITE_RESPONSE); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 563 | response->header_length = 12; |
| 564 | response->payload_length = 0; |
| 565 | break; |
| 566 | |
| 567 | case TCODE_READ_QUADLET_REQUEST: |
| 568 | response->header[0] |= |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 569 | HEADER_TCODE(TCODE_READ_QUADLET_RESPONSE); |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 570 | if (payload != NULL) |
| 571 | response->header[3] = *(u32 *)payload; |
| 572 | else |
| 573 | response->header[3] = 0; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 574 | response->header_length = 16; |
| 575 | response->payload_length = 0; |
| 576 | break; |
| 577 | |
| 578 | case TCODE_READ_BLOCK_REQUEST: |
| 579 | case TCODE_LOCK_REQUEST: |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 580 | response->header[0] |= HEADER_TCODE(tcode + 2); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 581 | response->header[3] = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 582 | HEADER_DATA_LENGTH(length) | |
| 583 | HEADER_EXTENDED_TCODE(extended_tcode); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 584 | response->header_length = 16; |
Kristian Høgsberg | 36bfe49 | 2007-01-26 00:38:13 -0500 | [diff] [blame] | 585 | response->payload = payload; |
| 586 | response->payload_length = length; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 587 | break; |
| 588 | |
| 589 | default: |
| 590 | BUG(); |
| 591 | return; |
| 592 | } |
Stefan Richter | 1d1dc5e | 2008-12-10 00:20:38 +0100 | [diff] [blame] | 593 | |
| 594 | response->payload_bus = 0; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 595 | } |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 596 | EXPORT_SYMBOL(fw_fill_response); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 597 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 598 | static struct fw_request *allocate_request(struct fw_packet *p) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 599 | { |
| 600 | struct fw_request *request; |
| 601 | u32 *data, length; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 602 | int request_tcode, t; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 603 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 604 | request_tcode = HEADER_GET_TCODE(p->header[0]); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 605 | switch (request_tcode) { |
| 606 | case TCODE_WRITE_QUADLET_REQUEST: |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 607 | data = &p->header[3]; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 608 | length = 4; |
| 609 | break; |
| 610 | |
| 611 | case TCODE_WRITE_BLOCK_REQUEST: |
| 612 | case TCODE_LOCK_REQUEST: |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 613 | data = p->payload; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 614 | length = HEADER_GET_DATA_LENGTH(p->header[3]); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 615 | break; |
| 616 | |
| 617 | case TCODE_READ_QUADLET_REQUEST: |
| 618 | data = NULL; |
| 619 | length = 4; |
| 620 | break; |
| 621 | |
| 622 | case TCODE_READ_BLOCK_REQUEST: |
| 623 | data = NULL; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 624 | length = HEADER_GET_DATA_LENGTH(p->header[3]); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 625 | break; |
| 626 | |
| 627 | default: |
Stefan Richter | 0bf607c | 2008-05-31 19:01:26 +0200 | [diff] [blame] | 628 | fw_error("ERROR - corrupt request received - %08x %08x %08x\n", |
| 629 | p->header[0], p->header[1], p->header[2]); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 630 | return NULL; |
| 631 | } |
| 632 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 633 | request = kmalloc(sizeof(*request) + length, GFP_ATOMIC); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 634 | if (request == NULL) |
| 635 | return NULL; |
| 636 | |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 637 | t = (p->timestamp & 0x1fff) + 4000; |
| 638 | if (t >= 8000) |
| 639 | t = (p->timestamp & ~0x1fff) + 0x2000 + t - 8000; |
| 640 | else |
| 641 | t = (p->timestamp & ~0x1fff) + t; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 642 | |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 643 | request->response.speed = p->speed; |
| 644 | request->response.timestamp = t; |
| 645 | request->response.generation = p->generation; |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 646 | request->response.ack = 0; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 647 | request->response.callback = free_response_callback; |
| 648 | request->ack = p->ack; |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 649 | request->length = length; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 650 | if (data) |
Kristian Høgsberg | 6e2e842 | 2007-02-16 17:34:37 -0500 | [diff] [blame] | 651 | memcpy(request->data, data, length); |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 652 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 653 | memcpy(request->request_header, p->header, sizeof(p->header)); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 654 | |
| 655 | return request; |
| 656 | } |
| 657 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 658 | void fw_send_response(struct fw_card *card, |
| 659 | struct fw_request *request, int rcode) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 660 | { |
Stefan Richter | a7ea678 | 2008-05-25 11:06:55 +0200 | [diff] [blame] | 661 | /* unified transaction or broadcast transaction: don't respond */ |
| 662 | if (request->ack != ACK_PENDING || |
| 663 | HEADER_DESTINATION_IS_BROADCAST(request->request_header[0])) { |
Stefan Richter | 9c9bdf4 | 2007-07-17 02:15:36 +0200 | [diff] [blame] | 664 | kfree(request); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 665 | return; |
Stefan Richter | 9c9bdf4 | 2007-07-17 02:15:36 +0200 | [diff] [blame] | 666 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 667 | |
Kristian Høgsberg | 36bfe49 | 2007-01-26 00:38:13 -0500 | [diff] [blame] | 668 | if (rcode == RCODE_COMPLETE) |
| 669 | fw_fill_response(&request->response, request->request_header, |
| 670 | rcode, request->data, request->length); |
| 671 | else |
| 672 | fw_fill_response(&request->response, request->request_header, |
| 673 | rcode, NULL, 0); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 674 | |
| 675 | card->driver->send_response(card, &request->response); |
| 676 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 677 | EXPORT_SYMBOL(fw_send_response); |
| 678 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 679 | void fw_core_handle_request(struct fw_card *card, struct fw_packet *p) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 680 | { |
| 681 | struct fw_address_handler *handler; |
| 682 | struct fw_request *request; |
| 683 | unsigned long long offset; |
| 684 | unsigned long flags; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 685 | int tcode, destination, source; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 686 | |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 687 | if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 688 | return; |
| 689 | |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 690 | request = allocate_request(p); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 691 | if (request == NULL) { |
| 692 | /* FIXME: send statically allocated busy packet. */ |
| 693 | return; |
| 694 | } |
| 695 | |
| 696 | offset = |
| 697 | ((unsigned long long) |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 698 | HEADER_GET_OFFSET_HIGH(p->header[1]) << 32) | p->header[2]; |
| 699 | tcode = HEADER_GET_TCODE(p->header[0]); |
| 700 | destination = HEADER_GET_DESTINATION(p->header[0]); |
Rabin Vincent | 478b233 | 2007-12-21 23:02:15 +0530 | [diff] [blame] | 701 | source = HEADER_GET_SOURCE(p->header[1]); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 702 | |
| 703 | spin_lock_irqsave(&address_handler_lock, flags); |
| 704 | handler = lookup_enclosing_address_handler(&address_handler_list, |
| 705 | offset, request->length); |
| 706 | spin_unlock_irqrestore(&address_handler_lock, flags); |
| 707 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 708 | /* |
| 709 | * FIXME: lookup the fw_node corresponding to the sender of |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 710 | * this request and pass that to the address handler instead |
| 711 | * of the node ID. We may also want to move the address |
| 712 | * allocations to fw_node so we only do this callback if the |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 713 | * upper layers registered it for this node. |
| 714 | */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 715 | |
| 716 | if (handler == NULL) |
| 717 | fw_send_response(card, request, RCODE_ADDRESS_ERROR); |
| 718 | else |
| 719 | handler->address_callback(card, request, |
| 720 | tcode, destination, source, |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 721 | p->generation, p->speed, offset, |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 722 | request->data, request->length, |
| 723 | handler->callback_data); |
| 724 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 725 | EXPORT_SYMBOL(fw_core_handle_request); |
| 726 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 727 | void fw_core_handle_response(struct fw_card *card, struct fw_packet *p) |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 728 | { |
| 729 | struct fw_transaction *t; |
| 730 | unsigned long flags; |
| 731 | u32 *data; |
| 732 | size_t data_length; |
| 733 | int tcode, tlabel, destination, source, rcode; |
| 734 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 735 | tcode = HEADER_GET_TCODE(p->header[0]); |
| 736 | tlabel = HEADER_GET_TLABEL(p->header[0]); |
| 737 | destination = HEADER_GET_DESTINATION(p->header[0]); |
| 738 | source = HEADER_GET_SOURCE(p->header[1]); |
| 739 | rcode = HEADER_GET_RCODE(p->header[1]); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 740 | |
| 741 | spin_lock_irqsave(&card->lock, flags); |
| 742 | list_for_each_entry(t, &card->transaction_list, link) { |
| 743 | if (t->node_id == source && t->tlabel == tlabel) { |
| 744 | list_del(&t->link); |
| 745 | card->tlabel_mask &= ~(1 << t->tlabel); |
| 746 | break; |
| 747 | } |
| 748 | } |
| 749 | spin_unlock_irqrestore(&card->lock, flags); |
| 750 | |
| 751 | if (&t->link == &card->transaction_list) { |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 752 | fw_notify("Unsolicited response (source %x, tlabel %x)\n", |
| 753 | source, tlabel); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 757 | /* |
| 758 | * FIXME: sanity check packet, is length correct, does tcodes |
| 759 | * and addresses match. |
| 760 | */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 761 | |
| 762 | switch (tcode) { |
| 763 | case TCODE_READ_QUADLET_RESPONSE: |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 764 | data = (u32 *) &p->header[3]; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 765 | data_length = 4; |
| 766 | break; |
| 767 | |
| 768 | case TCODE_WRITE_RESPONSE: |
| 769 | data = NULL; |
| 770 | data_length = 0; |
| 771 | break; |
| 772 | |
| 773 | case TCODE_READ_BLOCK_RESPONSE: |
| 774 | case TCODE_LOCK_RESPONSE: |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 775 | data = p->payload; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 776 | data_length = HEADER_GET_DATA_LENGTH(p->header[3]); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 777 | break; |
| 778 | |
| 779 | default: |
| 780 | /* Should never happen, this is just to shut up gcc. */ |
| 781 | data = NULL; |
| 782 | data_length = 0; |
| 783 | break; |
| 784 | } |
| 785 | |
Stefan Richter | 10a4c73 | 2008-03-16 00:56:41 +0100 | [diff] [blame] | 786 | /* |
| 787 | * The response handler may be executed while the request handler |
| 788 | * is still pending. Cancel the request handler. |
| 789 | */ |
| 790 | card->driver->cancel_packet(card, &t->packet); |
| 791 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 792 | t->callback(card, rcode, data, data_length, t->callback_data); |
| 793 | } |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 794 | EXPORT_SYMBOL(fw_core_handle_response); |
| 795 | |
Stefan Richter | ae57988 | 2007-08-02 20:34:17 +0200 | [diff] [blame] | 796 | static const struct fw_address_region topology_map_region = |
Jarod Wilson | cca6097 | 2008-03-08 12:52:03 -0500 | [diff] [blame] | 797 | { .start = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP, |
| 798 | .end = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP_END, }; |
Kristian Høgsberg | 473d28c | 2007-03-07 12:12:55 -0500 | [diff] [blame] | 799 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 800 | static void handle_topology_map(struct fw_card *card, struct fw_request *request, |
| 801 | int tcode, int destination, int source, int generation, |
| 802 | int speed, unsigned long long offset, |
| 803 | void *payload, size_t length, void *callback_data) |
Kristian Høgsberg | 473d28c | 2007-03-07 12:12:55 -0500 | [diff] [blame] | 804 | { |
| 805 | int i, start, end; |
Stefan Richter | efbf390 | 2008-02-23 12:24:57 +0100 | [diff] [blame] | 806 | __be32 *map; |
Kristian Høgsberg | 473d28c | 2007-03-07 12:12:55 -0500 | [diff] [blame] | 807 | |
| 808 | if (!TCODE_IS_READ_REQUEST(tcode)) { |
| 809 | fw_send_response(card, request, RCODE_TYPE_ERROR); |
| 810 | return; |
| 811 | } |
| 812 | |
| 813 | if ((offset & 3) > 0 || (length & 3) > 0) { |
| 814 | fw_send_response(card, request, RCODE_ADDRESS_ERROR); |
| 815 | return; |
| 816 | } |
| 817 | |
| 818 | start = (offset - topology_map_region.start) / 4; |
| 819 | end = start + length / 4; |
| 820 | map = payload; |
| 821 | |
| 822 | for (i = 0; i < length / 4; i++) |
| 823 | map[i] = cpu_to_be32(card->topology_map[start + i]); |
| 824 | |
| 825 | fw_send_response(card, request, RCODE_COMPLETE); |
| 826 | } |
| 827 | |
| 828 | static struct fw_address_handler topology_map = { |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 829 | .length = 0x200, |
Kristian Høgsberg | 473d28c | 2007-03-07 12:12:55 -0500 | [diff] [blame] | 830 | .address_callback = handle_topology_map, |
| 831 | }; |
| 832 | |
Stefan Richter | ae57988 | 2007-08-02 20:34:17 +0200 | [diff] [blame] | 833 | static const struct fw_address_region registers_region = |
Jarod Wilson | cca6097 | 2008-03-08 12:52:03 -0500 | [diff] [blame] | 834 | { .start = CSR_REGISTER_BASE, |
| 835 | .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, }; |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 836 | |
Stefan Richter | 53dca51 | 2008-12-14 21:47:04 +0100 | [diff] [blame] | 837 | static void handle_registers(struct fw_card *card, struct fw_request *request, |
| 838 | int tcode, int destination, int source, int generation, |
| 839 | int speed, unsigned long long offset, |
| 840 | void *payload, size_t length, void *callback_data) |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 841 | { |
Jarod Wilson | 15f0d83 | 2008-03-08 13:18:58 -0500 | [diff] [blame] | 842 | int reg = offset & ~CSR_REGISTER_BASE; |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 843 | unsigned long long bus_time; |
| 844 | __be32 *data = payload; |
Stefan Richter | e534fe1 | 2008-05-24 16:41:09 +0200 | [diff] [blame] | 845 | int rcode = RCODE_COMPLETE; |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 846 | |
| 847 | switch (reg) { |
| 848 | case CSR_CYCLE_TIME: |
| 849 | case CSR_BUS_TIME: |
| 850 | if (!TCODE_IS_READ_REQUEST(tcode) || length != 4) { |
Stefan Richter | e534fe1 | 2008-05-24 16:41:09 +0200 | [diff] [blame] | 851 | rcode = RCODE_TYPE_ERROR; |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 852 | break; |
| 853 | } |
| 854 | |
| 855 | bus_time = card->driver->get_bus_time(card); |
| 856 | if (reg == CSR_CYCLE_TIME) |
| 857 | *data = cpu_to_be32(bus_time); |
| 858 | else |
| 859 | *data = cpu_to_be32(bus_time >> 25); |
Stefan Richter | e534fe1 | 2008-05-24 16:41:09 +0200 | [diff] [blame] | 860 | break; |
| 861 | |
| 862 | case CSR_BROADCAST_CHANNEL: |
| 863 | if (tcode == TCODE_READ_QUADLET_REQUEST) |
| 864 | *data = cpu_to_be32(card->broadcast_channel); |
| 865 | else if (tcode == TCODE_WRITE_QUADLET_REQUEST) |
| 866 | card->broadcast_channel = |
| 867 | (be32_to_cpu(*data) & BROADCAST_CHANNEL_VALID) | |
| 868 | BROADCAST_CHANNEL_INITIAL; |
| 869 | else |
| 870 | rcode = RCODE_TYPE_ERROR; |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case CSR_BUS_MANAGER_ID: |
| 874 | case CSR_BANDWIDTH_AVAILABLE: |
| 875 | case CSR_CHANNELS_AVAILABLE_HI: |
| 876 | case CSR_CHANNELS_AVAILABLE_LO: |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 877 | /* |
| 878 | * FIXME: these are handled by the OHCI hardware and |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 879 | * the stack never sees these request. If we add |
| 880 | * support for a new type of controller that doesn't |
| 881 | * handle this in hardware we need to deal with these |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 882 | * transactions. |
| 883 | */ |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 884 | BUG(); |
| 885 | break; |
| 886 | |
| 887 | case CSR_BUSY_TIMEOUT: |
| 888 | /* FIXME: Implement this. */ |
Stefan Richter | e534fe1 | 2008-05-24 16:41:09 +0200 | [diff] [blame] | 889 | |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 890 | default: |
Stefan Richter | e534fe1 | 2008-05-24 16:41:09 +0200 | [diff] [blame] | 891 | rcode = RCODE_ADDRESS_ERROR; |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 892 | break; |
| 893 | } |
Stefan Richter | e534fe1 | 2008-05-24 16:41:09 +0200 | [diff] [blame] | 894 | |
| 895 | fw_send_response(card, request, rcode); |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | static struct fw_address_handler registers = { |
| 899 | .length = 0x400, |
| 900 | .address_callback = handle_registers, |
| 901 | }; |
| 902 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 903 | MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>"); |
| 904 | MODULE_DESCRIPTION("Core IEEE1394 transaction logic"); |
| 905 | MODULE_LICENSE("GPL"); |
| 906 | |
Kristian Høgsberg | 937f687 | 2007-03-07 12:12:36 -0500 | [diff] [blame] | 907 | static const u32 vendor_textual_descriptor[] = { |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 908 | /* textual descriptor leaf () */ |
Kristian Høgsberg | 937f687 | 2007-03-07 12:12:36 -0500 | [diff] [blame] | 909 | 0x00060000, |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 910 | 0x00000000, |
| 911 | 0x00000000, |
| 912 | 0x4c696e75, /* L i n u */ |
| 913 | 0x78204669, /* x F i */ |
| 914 | 0x72657769, /* r e w i */ |
Kristian Høgsberg | 937f687 | 2007-03-07 12:12:36 -0500 | [diff] [blame] | 915 | 0x72650000, /* r e */ |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 916 | }; |
| 917 | |
Kristian Høgsberg | 937f687 | 2007-03-07 12:12:36 -0500 | [diff] [blame] | 918 | static const u32 model_textual_descriptor[] = { |
| 919 | /* model descriptor leaf () */ |
| 920 | 0x00030000, |
| 921 | 0x00000000, |
| 922 | 0x00000000, |
| 923 | 0x4a756a75, /* J u j u */ |
| 924 | }; |
| 925 | |
| 926 | static struct fw_descriptor vendor_id_descriptor = { |
| 927 | .length = ARRAY_SIZE(vendor_textual_descriptor), |
| 928 | .immediate = 0x03d00d1e, |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 929 | .key = 0x81000000, |
Kristian Høgsberg | 937f687 | 2007-03-07 12:12:36 -0500 | [diff] [blame] | 930 | .data = vendor_textual_descriptor, |
| 931 | }; |
| 932 | |
| 933 | static struct fw_descriptor model_id_descriptor = { |
| 934 | .length = ARRAY_SIZE(model_textual_descriptor), |
| 935 | .immediate = 0x17000001, |
| 936 | .key = 0x81000000, |
| 937 | .data = model_textual_descriptor, |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 938 | }; |
| 939 | |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 940 | static int __init fw_core_init(void) |
| 941 | { |
Stefan Richter | 2dbd7d7 | 2008-12-14 21:45:45 +0100 | [diff] [blame] | 942 | int ret; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 943 | |
Stefan Richter | 2dbd7d7 | 2008-12-14 21:45:45 +0100 | [diff] [blame] | 944 | ret = bus_register(&fw_bus_type); |
| 945 | if (ret < 0) |
| 946 | return ret; |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 947 | |
Kristian Høgsberg | a3aca3d | 2007-03-07 12:12:44 -0500 | [diff] [blame] | 948 | fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops); |
| 949 | if (fw_cdev_major < 0) { |
| 950 | bus_unregister(&fw_bus_type); |
| 951 | return fw_cdev_major; |
| 952 | } |
| 953 | |
Stefan Richter | c490a6d | 2008-12-14 21:45:14 +0100 | [diff] [blame] | 954 | fw_core_add_address_handler(&topology_map, &topology_map_region); |
| 955 | fw_core_add_address_handler(®isters, ®isters_region); |
| 956 | fw_core_add_descriptor(&vendor_id_descriptor); |
| 957 | fw_core_add_descriptor(&model_id_descriptor); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
| 962 | static void __exit fw_core_cleanup(void) |
| 963 | { |
Kristian Høgsberg | a3aca3d | 2007-03-07 12:12:44 -0500 | [diff] [blame] | 964 | unregister_chrdev(fw_cdev_major, "firewire"); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 965 | bus_unregister(&fw_bus_type); |
Stefan Richter | d6053e0 | 2008-11-24 20:40:00 +0100 | [diff] [blame] | 966 | idr_destroy(&fw_device_idr); |
Kristian Høgsberg | 3038e35 | 2006-12-19 19:58:27 -0500 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | module_init(fw_core_init); |
| 970 | module_exit(fw_core_cleanup); |