Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Driver for OHCI 1394 controllers |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 3 | * |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 4 | * Copyright (C) 2003-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 | |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/poll.h> |
Andrew Morton | cf3e72f | 2006-12-27 14:36:37 -0800 | [diff] [blame] | 28 | #include <linux/dma-mapping.h> |
Al Viro | faa2fb4 | 2007-05-15 20:36:10 +0100 | [diff] [blame^] | 29 | #include <linux/mm.h> |
Andrew Morton | cf3e72f | 2006-12-27 14:36:37 -0800 | [diff] [blame] | 30 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 31 | #include <asm/uaccess.h> |
| 32 | #include <asm/semaphore.h> |
| 33 | |
| 34 | #include "fw-transaction.h" |
| 35 | #include "fw-ohci.h" |
| 36 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 37 | #define DESCRIPTOR_OUTPUT_MORE 0 |
| 38 | #define DESCRIPTOR_OUTPUT_LAST (1 << 12) |
| 39 | #define DESCRIPTOR_INPUT_MORE (2 << 12) |
| 40 | #define DESCRIPTOR_INPUT_LAST (3 << 12) |
| 41 | #define DESCRIPTOR_STATUS (1 << 11) |
| 42 | #define DESCRIPTOR_KEY_IMMEDIATE (2 << 8) |
| 43 | #define DESCRIPTOR_PING (1 << 7) |
| 44 | #define DESCRIPTOR_YY (1 << 6) |
| 45 | #define DESCRIPTOR_NO_IRQ (0 << 4) |
| 46 | #define DESCRIPTOR_IRQ_ERROR (1 << 4) |
| 47 | #define DESCRIPTOR_IRQ_ALWAYS (3 << 4) |
| 48 | #define DESCRIPTOR_BRANCH_ALWAYS (3 << 2) |
| 49 | #define DESCRIPTOR_WAIT (3 << 0) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 50 | |
| 51 | struct descriptor { |
| 52 | __le16 req_count; |
| 53 | __le16 control; |
| 54 | __le32 data_address; |
| 55 | __le32 branch_address; |
| 56 | __le16 res_count; |
| 57 | __le16 transfer_status; |
| 58 | } __attribute__((aligned(16))); |
| 59 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 60 | struct db_descriptor { |
| 61 | __le16 first_size; |
| 62 | __le16 control; |
| 63 | __le16 second_req_count; |
| 64 | __le16 first_req_count; |
| 65 | __le32 branch_address; |
| 66 | __le16 second_res_count; |
| 67 | __le16 first_res_count; |
| 68 | __le32 reserved0; |
| 69 | __le32 first_buffer; |
| 70 | __le32 second_buffer; |
| 71 | __le32 reserved1; |
| 72 | } __attribute__((aligned(16))); |
| 73 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 74 | #define CONTROL_SET(regs) (regs) |
| 75 | #define CONTROL_CLEAR(regs) ((regs) + 4) |
| 76 | #define COMMAND_PTR(regs) ((regs) + 12) |
| 77 | #define CONTEXT_MATCH(regs) ((regs) + 16) |
Kristian Høgsberg | 72e318e | 2007-02-06 14:49:31 -0500 | [diff] [blame] | 78 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 79 | struct ar_buffer { |
| 80 | struct descriptor descriptor; |
| 81 | struct ar_buffer *next; |
| 82 | __le32 data[0]; |
| 83 | }; |
| 84 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 85 | struct ar_context { |
| 86 | struct fw_ohci *ohci; |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 87 | struct ar_buffer *current_buffer; |
| 88 | struct ar_buffer *last_buffer; |
| 89 | void *pointer; |
Kristian Høgsberg | 72e318e | 2007-02-06 14:49:31 -0500 | [diff] [blame] | 90 | u32 regs; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 91 | struct tasklet_struct tasklet; |
| 92 | }; |
| 93 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 94 | struct context; |
| 95 | |
| 96 | typedef int (*descriptor_callback_t)(struct context *ctx, |
| 97 | struct descriptor *d, |
| 98 | struct descriptor *last); |
| 99 | struct context { |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 100 | struct fw_ohci *ohci; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 101 | u32 regs; |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 102 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 103 | struct descriptor *buffer; |
| 104 | dma_addr_t buffer_bus; |
| 105 | size_t buffer_size; |
| 106 | struct descriptor *head_descriptor; |
| 107 | struct descriptor *tail_descriptor; |
| 108 | struct descriptor *tail_descriptor_last; |
| 109 | struct descriptor *prev_descriptor; |
| 110 | |
| 111 | descriptor_callback_t callback; |
| 112 | |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 113 | struct tasklet_struct tasklet; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 114 | }; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 115 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 116 | #define IT_HEADER_SY(v) ((v) << 0) |
| 117 | #define IT_HEADER_TCODE(v) ((v) << 4) |
| 118 | #define IT_HEADER_CHANNEL(v) ((v) << 8) |
| 119 | #define IT_HEADER_TAG(v) ((v) << 14) |
| 120 | #define IT_HEADER_SPEED(v) ((v) << 16) |
| 121 | #define IT_HEADER_DATA_LENGTH(v) ((v) << 16) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 122 | |
| 123 | struct iso_context { |
| 124 | struct fw_iso_context base; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 125 | struct context context; |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 126 | void *header; |
| 127 | size_t header_length; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | #define CONFIG_ROM_SIZE 1024 |
| 131 | |
| 132 | struct fw_ohci { |
| 133 | struct fw_card card; |
| 134 | |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 135 | u32 version; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 136 | __iomem char *registers; |
| 137 | dma_addr_t self_id_bus; |
| 138 | __le32 *self_id_cpu; |
| 139 | struct tasklet_struct bus_reset_tasklet; |
Kristian Høgsberg | e636fe2 | 2007-01-26 00:38:04 -0500 | [diff] [blame] | 140 | int node_id; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 141 | int generation; |
| 142 | int request_generation; |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 143 | u32 bus_seconds; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 144 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 145 | /* |
| 146 | * Spinlock for accessing fw_ohci data. Never call out of |
| 147 | * this driver with this lock held. |
| 148 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 149 | spinlock_t lock; |
| 150 | u32 self_id_buffer[512]; |
| 151 | |
| 152 | /* Config rom buffers */ |
| 153 | __be32 *config_rom; |
| 154 | dma_addr_t config_rom_bus; |
| 155 | __be32 *next_config_rom; |
| 156 | dma_addr_t next_config_rom_bus; |
| 157 | u32 next_header; |
| 158 | |
| 159 | struct ar_context ar_request_ctx; |
| 160 | struct ar_context ar_response_ctx; |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 161 | struct context at_request_ctx; |
| 162 | struct context at_response_ctx; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 163 | |
| 164 | u32 it_context_mask; |
| 165 | struct iso_context *it_context_list; |
| 166 | u32 ir_context_mask; |
| 167 | struct iso_context *ir_context_list; |
| 168 | }; |
| 169 | |
Adrian Bunk | 95688e9 | 2007-01-22 19:17:37 +0100 | [diff] [blame] | 170 | static inline struct fw_ohci *fw_ohci(struct fw_card *card) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 171 | { |
| 172 | return container_of(card, struct fw_ohci, card); |
| 173 | } |
| 174 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 175 | #define IT_CONTEXT_CYCLE_MATCH_ENABLE 0x80000000 |
| 176 | #define IR_CONTEXT_BUFFER_FILL 0x80000000 |
| 177 | #define IR_CONTEXT_ISOCH_HEADER 0x40000000 |
| 178 | #define IR_CONTEXT_CYCLE_MATCH_ENABLE 0x20000000 |
| 179 | #define IR_CONTEXT_MULTI_CHANNEL_MODE 0x10000000 |
| 180 | #define IR_CONTEXT_DUAL_BUFFER_MODE 0x08000000 |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 181 | |
| 182 | #define CONTEXT_RUN 0x8000 |
| 183 | #define CONTEXT_WAKE 0x1000 |
| 184 | #define CONTEXT_DEAD 0x0800 |
| 185 | #define CONTEXT_ACTIVE 0x0400 |
| 186 | |
| 187 | #define OHCI1394_MAX_AT_REQ_RETRIES 0x2 |
| 188 | #define OHCI1394_MAX_AT_RESP_RETRIES 0x2 |
| 189 | #define OHCI1394_MAX_PHYS_RESP_RETRIES 0x8 |
| 190 | |
| 191 | #define FW_OHCI_MAJOR 240 |
| 192 | #define OHCI1394_REGISTER_SIZE 0x800 |
| 193 | #define OHCI_LOOP_COUNT 500 |
| 194 | #define OHCI1394_PCI_HCI_Control 0x40 |
| 195 | #define SELF_ID_BUF_SIZE 0x800 |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 196 | #define OHCI_TCODE_PHY_PACKET 0x0e |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 197 | #define OHCI_VERSION_1_1 0x010010 |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 198 | #define ISO_BUFFER_SIZE (64 * 1024) |
| 199 | #define AT_BUFFER_SIZE 4096 |
Kristian Høgsberg | 0edeefd | 2007-01-26 00:38:49 -0500 | [diff] [blame] | 200 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 201 | static char ohci_driver_name[] = KBUILD_MODNAME; |
| 202 | |
Adrian Bunk | 95688e9 | 2007-01-22 19:17:37 +0100 | [diff] [blame] | 203 | static inline void reg_write(const struct fw_ohci *ohci, int offset, u32 data) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 204 | { |
| 205 | writel(data, ohci->registers + offset); |
| 206 | } |
| 207 | |
Adrian Bunk | 95688e9 | 2007-01-22 19:17:37 +0100 | [diff] [blame] | 208 | static inline u32 reg_read(const struct fw_ohci *ohci, int offset) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 209 | { |
| 210 | return readl(ohci->registers + offset); |
| 211 | } |
| 212 | |
Adrian Bunk | 95688e9 | 2007-01-22 19:17:37 +0100 | [diff] [blame] | 213 | static inline void flush_writes(const struct fw_ohci *ohci) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 214 | { |
| 215 | /* Do a dummy read to flush writes. */ |
| 216 | reg_read(ohci, OHCI1394_Version); |
| 217 | } |
| 218 | |
| 219 | static int |
| 220 | ohci_update_phy_reg(struct fw_card *card, int addr, |
| 221 | int clear_bits, int set_bits) |
| 222 | { |
| 223 | struct fw_ohci *ohci = fw_ohci(card); |
| 224 | u32 val, old; |
| 225 | |
| 226 | reg_write(ohci, OHCI1394_PhyControl, OHCI1394_PhyControl_Read(addr)); |
| 227 | msleep(2); |
| 228 | val = reg_read(ohci, OHCI1394_PhyControl); |
| 229 | if ((val & OHCI1394_PhyControl_ReadDone) == 0) { |
| 230 | fw_error("failed to set phy reg bits.\n"); |
| 231 | return -EBUSY; |
| 232 | } |
| 233 | |
| 234 | old = OHCI1394_PhyControl_ReadData(val); |
| 235 | old = (old & ~clear_bits) | set_bits; |
| 236 | reg_write(ohci, OHCI1394_PhyControl, |
| 237 | OHCI1394_PhyControl_Write(addr, old)); |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 242 | static int ar_context_add_page(struct ar_context *ctx) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 243 | { |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 244 | struct device *dev = ctx->ohci->card.device; |
| 245 | struct ar_buffer *ab; |
| 246 | dma_addr_t ab_bus; |
| 247 | size_t offset; |
| 248 | |
| 249 | ab = (struct ar_buffer *) __get_free_page(GFP_ATOMIC); |
| 250 | if (ab == NULL) |
| 251 | return -ENOMEM; |
| 252 | |
| 253 | ab_bus = dma_map_single(dev, ab, PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 254 | if (dma_mapping_error(ab_bus)) { |
| 255 | free_page((unsigned long) ab); |
| 256 | return -ENOMEM; |
| 257 | } |
| 258 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 259 | memset(&ab->descriptor, 0, sizeof(ab->descriptor)); |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 260 | ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE | |
| 261 | DESCRIPTOR_STATUS | |
| 262 | DESCRIPTOR_BRANCH_ALWAYS); |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 263 | offset = offsetof(struct ar_buffer, data); |
| 264 | ab->descriptor.req_count = cpu_to_le16(PAGE_SIZE - offset); |
| 265 | ab->descriptor.data_address = cpu_to_le32(ab_bus + offset); |
| 266 | ab->descriptor.res_count = cpu_to_le16(PAGE_SIZE - offset); |
| 267 | ab->descriptor.branch_address = 0; |
| 268 | |
| 269 | dma_sync_single_for_device(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 270 | |
| 271 | ctx->last_buffer->descriptor.branch_address = ab_bus | 1; |
| 272 | ctx->last_buffer->next = ab; |
| 273 | ctx->last_buffer = ab; |
| 274 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 275 | reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 276 | flush_writes(ctx->ohci); |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 277 | |
| 278 | return 0; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 279 | } |
| 280 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 281 | static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 282 | { |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 283 | struct fw_ohci *ohci = ctx->ohci; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 284 | struct fw_packet p; |
| 285 | u32 status, length, tcode; |
Kristian Høgsberg | 0edeefd | 2007-01-26 00:38:49 -0500 | [diff] [blame] | 286 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 287 | p.header[0] = le32_to_cpu(buffer[0]); |
| 288 | p.header[1] = le32_to_cpu(buffer[1]); |
| 289 | p.header[2] = le32_to_cpu(buffer[2]); |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 290 | |
| 291 | tcode = (p.header[0] >> 4) & 0x0f; |
| 292 | switch (tcode) { |
| 293 | case TCODE_WRITE_QUADLET_REQUEST: |
| 294 | case TCODE_READ_QUADLET_RESPONSE: |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 295 | p.header[3] = (__force __u32) buffer[3]; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 296 | p.header_length = 16; |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 297 | p.payload_length = 0; |
| 298 | break; |
| 299 | |
| 300 | case TCODE_READ_BLOCK_REQUEST : |
| 301 | p.header[3] = le32_to_cpu(buffer[3]); |
| 302 | p.header_length = 16; |
| 303 | p.payload_length = 0; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 304 | break; |
| 305 | |
| 306 | case TCODE_WRITE_BLOCK_REQUEST: |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 307 | case TCODE_READ_BLOCK_RESPONSE: |
| 308 | case TCODE_LOCK_REQUEST: |
| 309 | case TCODE_LOCK_RESPONSE: |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 310 | p.header[3] = le32_to_cpu(buffer[3]); |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 311 | p.header_length = 16; |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 312 | p.payload_length = p.header[3] >> 16; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 313 | break; |
| 314 | |
| 315 | case TCODE_WRITE_RESPONSE: |
| 316 | case TCODE_READ_QUADLET_REQUEST: |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 317 | case OHCI_TCODE_PHY_PACKET: |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 318 | p.header_length = 12; |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 319 | p.payload_length = 0; |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 320 | break; |
| 321 | } |
| 322 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 323 | p.payload = (void *) buffer + p.header_length; |
| 324 | |
| 325 | /* FIXME: What to do about evt_* errors? */ |
| 326 | length = (p.header_length + p.payload_length + 3) / 4; |
| 327 | status = le32_to_cpu(buffer[length]); |
| 328 | |
| 329 | p.ack = ((status >> 16) & 0x1f) - 16; |
| 330 | p.speed = (status >> 21) & 0x7; |
| 331 | p.timestamp = status & 0xffff; |
| 332 | p.generation = ohci->request_generation; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 333 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 334 | /* |
| 335 | * The OHCI bus reset handler synthesizes a phy packet with |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 336 | * the new generation number when a bus reset happens (see |
| 337 | * section 8.4.2.3). This helps us determine when a request |
| 338 | * was received and make sure we send the response in the same |
| 339 | * generation. We only need this for requests; for responses |
| 340 | * we use the unique tlabel for finding the matching |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 341 | * request. |
| 342 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 343 | |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 344 | if (p.ack + 16 == 0x09) |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 345 | ohci->request_generation = (buffer[2] >> 16) & 0xff; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 346 | else if (ctx == &ohci->ar_request_ctx) |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 347 | fw_core_handle_request(&ohci->card, &p); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 348 | else |
Kristian Høgsberg | 2639a6f | 2007-01-26 00:37:57 -0500 | [diff] [blame] | 349 | fw_core_handle_response(&ohci->card, &p); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 350 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 351 | return buffer + length + 1; |
| 352 | } |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 353 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 354 | static void ar_context_tasklet(unsigned long data) |
| 355 | { |
| 356 | struct ar_context *ctx = (struct ar_context *)data; |
| 357 | struct fw_ohci *ohci = ctx->ohci; |
| 358 | struct ar_buffer *ab; |
| 359 | struct descriptor *d; |
| 360 | void *buffer, *end; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 361 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 362 | ab = ctx->current_buffer; |
| 363 | d = &ab->descriptor; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 364 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 365 | if (d->res_count == 0) { |
| 366 | size_t size, rest, offset; |
| 367 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 368 | /* |
| 369 | * This descriptor is finished and we may have a |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 370 | * packet split across this and the next buffer. We |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 371 | * reuse the page for reassembling the split packet. |
| 372 | */ |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 373 | |
| 374 | offset = offsetof(struct ar_buffer, data); |
| 375 | dma_unmap_single(ohci->card.device, |
| 376 | ab->descriptor.data_address - offset, |
| 377 | PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 378 | |
| 379 | buffer = ab; |
| 380 | ab = ab->next; |
| 381 | d = &ab->descriptor; |
| 382 | size = buffer + PAGE_SIZE - ctx->pointer; |
| 383 | rest = le16_to_cpu(d->req_count) - le16_to_cpu(d->res_count); |
| 384 | memmove(buffer, ctx->pointer, size); |
| 385 | memcpy(buffer + size, ab->data, rest); |
| 386 | ctx->current_buffer = ab; |
| 387 | ctx->pointer = (void *) ab->data + rest; |
| 388 | end = buffer + size + rest; |
| 389 | |
| 390 | while (buffer < end) |
| 391 | buffer = handle_ar_packet(ctx, buffer); |
| 392 | |
| 393 | free_page((unsigned long)buffer); |
| 394 | ar_context_add_page(ctx); |
| 395 | } else { |
| 396 | buffer = ctx->pointer; |
| 397 | ctx->pointer = end = |
| 398 | (void *) ab + PAGE_SIZE - le16_to_cpu(d->res_count); |
| 399 | |
| 400 | while (buffer < end) |
| 401 | buffer = handle_ar_packet(ctx, buffer); |
| 402 | } |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static int |
Kristian Høgsberg | 72e318e | 2007-02-06 14:49:31 -0500 | [diff] [blame] | 406 | ar_context_init(struct ar_context *ctx, struct fw_ohci *ohci, u32 regs) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 407 | { |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 408 | struct ar_buffer ab; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 409 | |
Kristian Høgsberg | 72e318e | 2007-02-06 14:49:31 -0500 | [diff] [blame] | 410 | ctx->regs = regs; |
| 411 | ctx->ohci = ohci; |
| 412 | ctx->last_buffer = &ab; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 413 | tasklet_init(&ctx->tasklet, ar_context_tasklet, (unsigned long)ctx); |
| 414 | |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 415 | ar_context_add_page(ctx); |
| 416 | ar_context_add_page(ctx); |
| 417 | ctx->current_buffer = ab.next; |
| 418 | ctx->pointer = ctx->current_buffer->data; |
| 419 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 420 | reg_write(ctx->ohci, COMMAND_PTR(ctx->regs), ab.descriptor.branch_address); |
| 421 | reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN); |
Kristian Høgsberg | 32b4609 | 2007-02-06 14:49:30 -0500 | [diff] [blame] | 422 | flush_writes(ctx->ohci); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 423 | |
| 424 | return 0; |
| 425 | } |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 426 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 427 | static void context_tasklet(unsigned long data) |
| 428 | { |
| 429 | struct context *ctx = (struct context *) data; |
| 430 | struct fw_ohci *ohci = ctx->ohci; |
| 431 | struct descriptor *d, *last; |
| 432 | u32 address; |
| 433 | int z; |
| 434 | |
| 435 | dma_sync_single_for_cpu(ohci->card.device, ctx->buffer_bus, |
| 436 | ctx->buffer_size, DMA_TO_DEVICE); |
| 437 | |
| 438 | d = ctx->tail_descriptor; |
| 439 | last = ctx->tail_descriptor_last; |
| 440 | |
| 441 | while (last->branch_address != 0) { |
| 442 | address = le32_to_cpu(last->branch_address); |
| 443 | z = address & 0xf; |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 444 | d = ctx->buffer + (address - ctx->buffer_bus) / sizeof(*d); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 445 | last = (z == 2) ? d : d + z - 1; |
| 446 | |
| 447 | if (!ctx->callback(ctx, d, last)) |
| 448 | break; |
| 449 | |
| 450 | ctx->tail_descriptor = d; |
| 451 | ctx->tail_descriptor_last = last; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | static int |
| 456 | context_init(struct context *ctx, struct fw_ohci *ohci, |
| 457 | size_t buffer_size, u32 regs, |
| 458 | descriptor_callback_t callback) |
| 459 | { |
| 460 | ctx->ohci = ohci; |
| 461 | ctx->regs = regs; |
| 462 | ctx->buffer_size = buffer_size; |
| 463 | ctx->buffer = kmalloc(buffer_size, GFP_KERNEL); |
| 464 | if (ctx->buffer == NULL) |
| 465 | return -ENOMEM; |
| 466 | |
| 467 | tasklet_init(&ctx->tasklet, context_tasklet, (unsigned long)ctx); |
| 468 | ctx->callback = callback; |
| 469 | |
| 470 | ctx->buffer_bus = |
| 471 | dma_map_single(ohci->card.device, ctx->buffer, |
| 472 | buffer_size, DMA_TO_DEVICE); |
| 473 | if (dma_mapping_error(ctx->buffer_bus)) { |
| 474 | kfree(ctx->buffer); |
| 475 | return -ENOMEM; |
| 476 | } |
| 477 | |
| 478 | ctx->head_descriptor = ctx->buffer; |
| 479 | ctx->prev_descriptor = ctx->buffer; |
| 480 | ctx->tail_descriptor = ctx->buffer; |
| 481 | ctx->tail_descriptor_last = ctx->buffer; |
| 482 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 483 | /* |
| 484 | * We put a dummy descriptor in the buffer that has a NULL |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 485 | * branch address and looks like it's been sent. That way we |
| 486 | * have a descriptor to append DMA programs to. Also, the |
| 487 | * ring buffer invariant is that it always has at least one |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 488 | * element so that head == tail means buffer full. |
| 489 | */ |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 490 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 491 | memset(ctx->head_descriptor, 0, sizeof(*ctx->head_descriptor)); |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 492 | ctx->head_descriptor->control = cpu_to_le16(DESCRIPTOR_OUTPUT_LAST); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 493 | ctx->head_descriptor->transfer_status = cpu_to_le16(0x8011); |
| 494 | ctx->head_descriptor++; |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 499 | static void |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 500 | context_release(struct context *ctx) |
| 501 | { |
| 502 | struct fw_card *card = &ctx->ohci->card; |
| 503 | |
| 504 | dma_unmap_single(card->device, ctx->buffer_bus, |
| 505 | ctx->buffer_size, DMA_TO_DEVICE); |
| 506 | kfree(ctx->buffer); |
| 507 | } |
| 508 | |
| 509 | static struct descriptor * |
| 510 | context_get_descriptors(struct context *ctx, int z, dma_addr_t *d_bus) |
| 511 | { |
| 512 | struct descriptor *d, *tail, *end; |
| 513 | |
| 514 | d = ctx->head_descriptor; |
| 515 | tail = ctx->tail_descriptor; |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 516 | end = ctx->buffer + ctx->buffer_size / sizeof(*d); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 517 | |
| 518 | if (d + z <= tail) { |
| 519 | goto has_space; |
| 520 | } else if (d > tail && d + z <= end) { |
| 521 | goto has_space; |
| 522 | } else if (d > tail && ctx->buffer + z <= tail) { |
| 523 | d = ctx->buffer; |
| 524 | goto has_space; |
| 525 | } |
| 526 | |
| 527 | return NULL; |
| 528 | |
| 529 | has_space: |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 530 | memset(d, 0, z * sizeof(*d)); |
| 531 | *d_bus = ctx->buffer_bus + (d - ctx->buffer) * sizeof(*d); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 532 | |
| 533 | return d; |
| 534 | } |
| 535 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 536 | static void context_run(struct context *ctx, u32 extra) |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 537 | { |
| 538 | struct fw_ohci *ohci = ctx->ohci; |
| 539 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 540 | reg_write(ohci, COMMAND_PTR(ctx->regs), |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 541 | le32_to_cpu(ctx->tail_descriptor_last->branch_address)); |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 542 | reg_write(ohci, CONTROL_CLEAR(ctx->regs), ~0); |
| 543 | reg_write(ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN | extra); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 544 | flush_writes(ohci); |
| 545 | } |
| 546 | |
| 547 | static void context_append(struct context *ctx, |
| 548 | struct descriptor *d, int z, int extra) |
| 549 | { |
| 550 | dma_addr_t d_bus; |
| 551 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 552 | d_bus = ctx->buffer_bus + (d - ctx->buffer) * sizeof(*d); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 553 | |
| 554 | ctx->head_descriptor = d + z + extra; |
| 555 | ctx->prev_descriptor->branch_address = cpu_to_le32(d_bus | z); |
| 556 | ctx->prev_descriptor = z == 2 ? d : d + z - 1; |
| 557 | |
| 558 | dma_sync_single_for_device(ctx->ohci->card.device, ctx->buffer_bus, |
| 559 | ctx->buffer_size, DMA_TO_DEVICE); |
| 560 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 561 | reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 562 | flush_writes(ctx->ohci); |
| 563 | } |
| 564 | |
| 565 | static void context_stop(struct context *ctx) |
| 566 | { |
| 567 | u32 reg; |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 568 | int i; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 569 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 570 | reg_write(ctx->ohci, CONTROL_CLEAR(ctx->regs), CONTEXT_RUN); |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 571 | flush_writes(ctx->ohci); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 572 | |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 573 | for (i = 0; i < 10; i++) { |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 574 | reg = reg_read(ctx->ohci, CONTROL_SET(ctx->regs)); |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 575 | if ((reg & CONTEXT_ACTIVE) == 0) |
| 576 | break; |
| 577 | |
| 578 | fw_notify("context_stop: still active (0x%08x)\n", reg); |
| 579 | msleep(1); |
| 580 | } |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 581 | } |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 582 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 583 | struct driver_data { |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 584 | struct fw_packet *packet; |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 585 | }; |
| 586 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 587 | /* |
| 588 | * This function apppends a packet to the DMA queue for transmission. |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 589 | * Must always be called with the ochi->lock held to ensure proper |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 590 | * generation handling and locking around packet queue manipulation. |
| 591 | */ |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 592 | static int |
| 593 | at_context_queue_packet(struct context *ctx, struct fw_packet *packet) |
| 594 | { |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 595 | struct fw_ohci *ohci = ctx->ohci; |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 596 | dma_addr_t d_bus, payload_bus; |
| 597 | struct driver_data *driver_data; |
| 598 | struct descriptor *d, *last; |
| 599 | __le32 *header; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 600 | int z, tcode; |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 601 | u32 reg; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 602 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 603 | d = context_get_descriptors(ctx, 4, &d_bus); |
| 604 | if (d == NULL) { |
| 605 | packet->ack = RCODE_SEND_ERROR; |
| 606 | return -1; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 607 | } |
| 608 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 609 | d[0].control = cpu_to_le16(DESCRIPTOR_KEY_IMMEDIATE); |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 610 | d[0].res_count = cpu_to_le16(packet->timestamp); |
| 611 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 612 | /* |
| 613 | * The DMA format for asyncronous link packets is different |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 614 | * from the IEEE1394 layout, so shift the fields around |
| 615 | * accordingly. If header_length is 8, it's a PHY packet, to |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 616 | * which we need to prepend an extra quadlet. |
| 617 | */ |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 618 | |
| 619 | header = (__le32 *) &d[1]; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 620 | if (packet->header_length > 8) { |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 621 | header[0] = cpu_to_le32((packet->header[0] & 0xffff) | |
| 622 | (packet->speed << 16)); |
| 623 | header[1] = cpu_to_le32((packet->header[1] & 0xffff) | |
| 624 | (packet->header[0] & 0xffff0000)); |
| 625 | header[2] = cpu_to_le32(packet->header[2]); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 626 | |
| 627 | tcode = (packet->header[0] >> 4) & 0x0f; |
| 628 | if (TCODE_IS_BLOCK_PACKET(tcode)) |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 629 | header[3] = cpu_to_le32(packet->header[3]); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 630 | else |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 631 | header[3] = (__force __le32) packet->header[3]; |
| 632 | |
| 633 | d[0].req_count = cpu_to_le16(packet->header_length); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 634 | } else { |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 635 | header[0] = cpu_to_le32((OHCI1394_phy_tcode << 4) | |
| 636 | (packet->speed << 16)); |
| 637 | header[1] = cpu_to_le32(packet->header[0]); |
| 638 | header[2] = cpu_to_le32(packet->header[1]); |
| 639 | d[0].req_count = cpu_to_le16(12); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 640 | } |
| 641 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 642 | driver_data = (struct driver_data *) &d[3]; |
| 643 | driver_data->packet = packet; |
Kristian Høgsberg | 20d1167 | 2007-03-26 19:18:19 -0400 | [diff] [blame] | 644 | packet->driver_data = driver_data; |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 645 | |
| 646 | if (packet->payload_length > 0) { |
| 647 | payload_bus = |
| 648 | dma_map_single(ohci->card.device, packet->payload, |
| 649 | packet->payload_length, DMA_TO_DEVICE); |
| 650 | if (dma_mapping_error(payload_bus)) { |
| 651 | packet->ack = RCODE_SEND_ERROR; |
| 652 | return -1; |
| 653 | } |
| 654 | |
| 655 | d[2].req_count = cpu_to_le16(packet->payload_length); |
| 656 | d[2].data_address = cpu_to_le32(payload_bus); |
| 657 | last = &d[2]; |
| 658 | z = 3; |
| 659 | } else { |
| 660 | last = &d[0]; |
| 661 | z = 2; |
| 662 | } |
| 663 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 664 | last->control |= cpu_to_le16(DESCRIPTOR_OUTPUT_LAST | |
| 665 | DESCRIPTOR_IRQ_ALWAYS | |
| 666 | DESCRIPTOR_BRANCH_ALWAYS); |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 667 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 668 | /* FIXME: Document how the locking works. */ |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 669 | if (ohci->generation != packet->generation) { |
| 670 | packet->ack = RCODE_GENERATION; |
| 671 | return -1; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 672 | } |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 673 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 674 | context_append(ctx, d, z, 4 - z); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 675 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 676 | /* If the context isn't already running, start it up. */ |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 677 | reg = reg_read(ctx->ohci, CONTROL_SET(ctx->regs)); |
Kristian Høgsberg | 053b308 | 2007-04-10 18:11:17 -0400 | [diff] [blame] | 678 | if ((reg & CONTEXT_RUN) == 0) |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 679 | context_run(ctx, 0); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 684 | static int handle_at_packet(struct context *context, |
| 685 | struct descriptor *d, |
| 686 | struct descriptor *last) |
| 687 | { |
| 688 | struct driver_data *driver_data; |
| 689 | struct fw_packet *packet; |
| 690 | struct fw_ohci *ohci = context->ohci; |
| 691 | dma_addr_t payload_bus; |
| 692 | int evt; |
| 693 | |
| 694 | if (last->transfer_status == 0) |
| 695 | /* This descriptor isn't done yet, stop iteration. */ |
| 696 | return 0; |
| 697 | |
| 698 | driver_data = (struct driver_data *) &d[3]; |
| 699 | packet = driver_data->packet; |
| 700 | if (packet == NULL) |
| 701 | /* This packet was cancelled, just continue. */ |
| 702 | return 1; |
| 703 | |
| 704 | payload_bus = le32_to_cpu(last->data_address); |
| 705 | if (payload_bus != 0) |
| 706 | dma_unmap_single(ohci->card.device, payload_bus, |
| 707 | packet->payload_length, DMA_TO_DEVICE); |
| 708 | |
| 709 | evt = le16_to_cpu(last->transfer_status) & 0x1f; |
| 710 | packet->timestamp = le16_to_cpu(last->res_count); |
| 711 | |
| 712 | switch (evt) { |
| 713 | case OHCI1394_evt_timeout: |
| 714 | /* Async response transmit timed out. */ |
| 715 | packet->ack = RCODE_CANCELLED; |
| 716 | break; |
| 717 | |
| 718 | case OHCI1394_evt_flushed: |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 719 | /* |
| 720 | * The packet was flushed should give same error as |
| 721 | * when we try to use a stale generation count. |
| 722 | */ |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 723 | packet->ack = RCODE_GENERATION; |
| 724 | break; |
| 725 | |
| 726 | case OHCI1394_evt_missing_ack: |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 727 | /* |
| 728 | * Using a valid (current) generation count, but the |
| 729 | * node is not on the bus or not sending acks. |
| 730 | */ |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 731 | packet->ack = RCODE_NO_ACK; |
| 732 | break; |
| 733 | |
| 734 | case ACK_COMPLETE + 0x10: |
| 735 | case ACK_PENDING + 0x10: |
| 736 | case ACK_BUSY_X + 0x10: |
| 737 | case ACK_BUSY_A + 0x10: |
| 738 | case ACK_BUSY_B + 0x10: |
| 739 | case ACK_DATA_ERROR + 0x10: |
| 740 | case ACK_TYPE_ERROR + 0x10: |
| 741 | packet->ack = evt - 0x10; |
| 742 | break; |
| 743 | |
| 744 | default: |
| 745 | packet->ack = RCODE_SEND_ERROR; |
| 746 | break; |
| 747 | } |
| 748 | |
| 749 | packet->callback(packet, &ohci->card, packet->ack); |
| 750 | |
| 751 | return 1; |
| 752 | } |
| 753 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 754 | #define HEADER_GET_DESTINATION(q) (((q) >> 16) & 0xffff) |
| 755 | #define HEADER_GET_TCODE(q) (((q) >> 4) & 0x0f) |
| 756 | #define HEADER_GET_OFFSET_HIGH(q) (((q) >> 0) & 0xffff) |
| 757 | #define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff) |
| 758 | #define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff) |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 759 | |
| 760 | static void |
| 761 | handle_local_rom(struct fw_ohci *ohci, struct fw_packet *packet, u32 csr) |
| 762 | { |
| 763 | struct fw_packet response; |
| 764 | int tcode, length, i; |
| 765 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 766 | tcode = HEADER_GET_TCODE(packet->header[0]); |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 767 | if (TCODE_IS_BLOCK_PACKET(tcode)) |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 768 | length = HEADER_GET_DATA_LENGTH(packet->header[3]); |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 769 | else |
| 770 | length = 4; |
| 771 | |
| 772 | i = csr - CSR_CONFIG_ROM; |
| 773 | if (i + length > CONFIG_ROM_SIZE) { |
| 774 | fw_fill_response(&response, packet->header, |
| 775 | RCODE_ADDRESS_ERROR, NULL, 0); |
| 776 | } else if (!TCODE_IS_READ_REQUEST(tcode)) { |
| 777 | fw_fill_response(&response, packet->header, |
| 778 | RCODE_TYPE_ERROR, NULL, 0); |
| 779 | } else { |
| 780 | fw_fill_response(&response, packet->header, RCODE_COMPLETE, |
| 781 | (void *) ohci->config_rom + i, length); |
| 782 | } |
| 783 | |
| 784 | fw_core_handle_response(&ohci->card, &response); |
| 785 | } |
| 786 | |
| 787 | static void |
| 788 | handle_local_lock(struct fw_ohci *ohci, struct fw_packet *packet, u32 csr) |
| 789 | { |
| 790 | struct fw_packet response; |
| 791 | int tcode, length, ext_tcode, sel; |
| 792 | __be32 *payload, lock_old; |
| 793 | u32 lock_arg, lock_data; |
| 794 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 795 | tcode = HEADER_GET_TCODE(packet->header[0]); |
| 796 | length = HEADER_GET_DATA_LENGTH(packet->header[3]); |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 797 | payload = packet->payload; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 798 | ext_tcode = HEADER_GET_EXTENDED_TCODE(packet->header[3]); |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 799 | |
| 800 | if (tcode == TCODE_LOCK_REQUEST && |
| 801 | ext_tcode == EXTCODE_COMPARE_SWAP && length == 8) { |
| 802 | lock_arg = be32_to_cpu(payload[0]); |
| 803 | lock_data = be32_to_cpu(payload[1]); |
| 804 | } else if (tcode == TCODE_READ_QUADLET_REQUEST) { |
| 805 | lock_arg = 0; |
| 806 | lock_data = 0; |
| 807 | } else { |
| 808 | fw_fill_response(&response, packet->header, |
| 809 | RCODE_TYPE_ERROR, NULL, 0); |
| 810 | goto out; |
| 811 | } |
| 812 | |
| 813 | sel = (csr - CSR_BUS_MANAGER_ID) / 4; |
| 814 | reg_write(ohci, OHCI1394_CSRData, lock_data); |
| 815 | reg_write(ohci, OHCI1394_CSRCompareData, lock_arg); |
| 816 | reg_write(ohci, OHCI1394_CSRControl, sel); |
| 817 | |
| 818 | if (reg_read(ohci, OHCI1394_CSRControl) & 0x80000000) |
| 819 | lock_old = cpu_to_be32(reg_read(ohci, OHCI1394_CSRData)); |
| 820 | else |
| 821 | fw_notify("swap not done yet\n"); |
| 822 | |
| 823 | fw_fill_response(&response, packet->header, |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 824 | RCODE_COMPLETE, &lock_old, sizeof(lock_old)); |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 825 | out: |
| 826 | fw_core_handle_response(&ohci->card, &response); |
| 827 | } |
| 828 | |
| 829 | static void |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 830 | handle_local_request(struct context *ctx, struct fw_packet *packet) |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 831 | { |
| 832 | u64 offset; |
| 833 | u32 csr; |
| 834 | |
Kristian Høgsberg | 473d28c | 2007-03-07 12:12:55 -0500 | [diff] [blame] | 835 | if (ctx == &ctx->ohci->at_request_ctx) { |
| 836 | packet->ack = ACK_PENDING; |
| 837 | packet->callback(packet, &ctx->ohci->card, packet->ack); |
| 838 | } |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 839 | |
| 840 | offset = |
| 841 | ((unsigned long long) |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 842 | HEADER_GET_OFFSET_HIGH(packet->header[1]) << 32) | |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 843 | packet->header[2]; |
| 844 | csr = offset - CSR_REGISTER_BASE; |
| 845 | |
| 846 | /* Handle config rom reads. */ |
| 847 | if (csr >= CSR_CONFIG_ROM && csr < CSR_CONFIG_ROM_END) |
| 848 | handle_local_rom(ctx->ohci, packet, csr); |
| 849 | else switch (csr) { |
| 850 | case CSR_BUS_MANAGER_ID: |
| 851 | case CSR_BANDWIDTH_AVAILABLE: |
| 852 | case CSR_CHANNELS_AVAILABLE_HI: |
| 853 | case CSR_CHANNELS_AVAILABLE_LO: |
| 854 | handle_local_lock(ctx->ohci, packet, csr); |
| 855 | break; |
| 856 | default: |
| 857 | if (ctx == &ctx->ohci->at_request_ctx) |
| 858 | fw_core_handle_request(&ctx->ohci->card, packet); |
| 859 | else |
| 860 | fw_core_handle_response(&ctx->ohci->card, packet); |
| 861 | break; |
| 862 | } |
Kristian Høgsberg | 473d28c | 2007-03-07 12:12:55 -0500 | [diff] [blame] | 863 | |
| 864 | if (ctx == &ctx->ohci->at_response_ctx) { |
| 865 | packet->ack = ACK_COMPLETE; |
| 866 | packet->callback(packet, &ctx->ohci->card, packet->ack); |
| 867 | } |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 868 | } |
Kristian Høgsberg | e636fe2 | 2007-01-26 00:38:04 -0500 | [diff] [blame] | 869 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 870 | static void |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 871 | at_context_transmit(struct context *ctx, struct fw_packet *packet) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 872 | { |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 873 | unsigned long flags; |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 874 | int retval; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 875 | |
| 876 | spin_lock_irqsave(&ctx->ohci->lock, flags); |
| 877 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 878 | if (HEADER_GET_DESTINATION(packet->header[0]) == ctx->ohci->node_id && |
Kristian Høgsberg | e636fe2 | 2007-01-26 00:38:04 -0500 | [diff] [blame] | 879 | ctx->ohci->generation == packet->generation) { |
Kristian Høgsberg | 93c4cce | 2007-01-26 00:38:26 -0500 | [diff] [blame] | 880 | spin_unlock_irqrestore(&ctx->ohci->lock, flags); |
| 881 | handle_local_request(ctx, packet); |
| 882 | return; |
Kristian Høgsberg | e636fe2 | 2007-01-26 00:38:04 -0500 | [diff] [blame] | 883 | } |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 884 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 885 | retval = at_context_queue_packet(ctx, packet); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 886 | spin_unlock_irqrestore(&ctx->ohci->lock, flags); |
| 887 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 888 | if (retval < 0) |
| 889 | packet->callback(packet, &ctx->ohci->card, packet->ack); |
| 890 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static void bus_reset_tasklet(unsigned long data) |
| 894 | { |
| 895 | struct fw_ohci *ohci = (struct fw_ohci *)data; |
Kristian Høgsberg | e636fe2 | 2007-01-26 00:38:04 -0500 | [diff] [blame] | 896 | int self_id_count, i, j, reg; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 897 | int generation, new_generation; |
| 898 | unsigned long flags; |
| 899 | |
| 900 | reg = reg_read(ohci, OHCI1394_NodeID); |
| 901 | if (!(reg & OHCI1394_NodeID_idValid)) { |
| 902 | fw_error("node ID not valid, new bus reset in progress\n"); |
| 903 | return; |
| 904 | } |
Kristian Høgsberg | e636fe2 | 2007-01-26 00:38:04 -0500 | [diff] [blame] | 905 | ohci->node_id = reg & 0xffff; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 906 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 907 | /* |
| 908 | * The count in the SelfIDCount register is the number of |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 909 | * bytes in the self ID receive buffer. Since we also receive |
| 910 | * the inverted quadlets and a header quadlet, we shift one |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 911 | * bit extra to get the actual number of self IDs. |
| 912 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 913 | |
| 914 | self_id_count = (reg_read(ohci, OHCI1394_SelfIDCount) >> 3) & 0x3ff; |
| 915 | generation = (le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff; |
| 916 | |
| 917 | for (i = 1, j = 0; j < self_id_count; i += 2, j++) { |
| 918 | if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1]) |
| 919 | fw_error("inconsistent self IDs\n"); |
| 920 | ohci->self_id_buffer[j] = le32_to_cpu(ohci->self_id_cpu[i]); |
| 921 | } |
| 922 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 923 | /* |
| 924 | * Check the consistency of the self IDs we just read. The |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 925 | * problem we face is that a new bus reset can start while we |
| 926 | * read out the self IDs from the DMA buffer. If this happens, |
| 927 | * the DMA buffer will be overwritten with new self IDs and we |
| 928 | * will read out inconsistent data. The OHCI specification |
| 929 | * (section 11.2) recommends a technique similar to |
| 930 | * linux/seqlock.h, where we remember the generation of the |
| 931 | * self IDs in the buffer before reading them out and compare |
| 932 | * it to the current generation after reading them out. If |
| 933 | * the two generations match we know we have a consistent set |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 934 | * of self IDs. |
| 935 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 936 | |
| 937 | new_generation = (reg_read(ohci, OHCI1394_SelfIDCount) >> 16) & 0xff; |
| 938 | if (new_generation != generation) { |
| 939 | fw_notify("recursive bus reset detected, " |
| 940 | "discarding self ids\n"); |
| 941 | return; |
| 942 | } |
| 943 | |
| 944 | /* FIXME: Document how the locking works. */ |
| 945 | spin_lock_irqsave(&ohci->lock, flags); |
| 946 | |
| 947 | ohci->generation = generation; |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 948 | context_stop(&ohci->at_request_ctx); |
| 949 | context_stop(&ohci->at_response_ctx); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 950 | reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset); |
| 951 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 952 | /* |
| 953 | * This next bit is unrelated to the AT context stuff but we |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 954 | * have to do it under the spinlock also. If a new config rom |
| 955 | * was set up before this reset, the old one is now no longer |
| 956 | * in use and we can free it. Update the config rom pointers |
| 957 | * to point to the current config rom and clear the |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 958 | * next_config_rom pointer so a new udpate can take place. |
| 959 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 960 | |
| 961 | if (ohci->next_config_rom != NULL) { |
| 962 | dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, |
| 963 | ohci->config_rom, ohci->config_rom_bus); |
| 964 | ohci->config_rom = ohci->next_config_rom; |
| 965 | ohci->config_rom_bus = ohci->next_config_rom_bus; |
| 966 | ohci->next_config_rom = NULL; |
| 967 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 968 | /* |
| 969 | * Restore config_rom image and manually update |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 970 | * config_rom registers. Writing the header quadlet |
| 971 | * will indicate that the config rom is ready, so we |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 972 | * do that last. |
| 973 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 974 | reg_write(ohci, OHCI1394_BusOptions, |
| 975 | be32_to_cpu(ohci->config_rom[2])); |
| 976 | ohci->config_rom[0] = cpu_to_be32(ohci->next_header); |
| 977 | reg_write(ohci, OHCI1394_ConfigROMhdr, ohci->next_header); |
| 978 | } |
| 979 | |
| 980 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 981 | |
Kristian Høgsberg | e636fe2 | 2007-01-26 00:38:04 -0500 | [diff] [blame] | 982 | fw_core_handle_bus_reset(&ohci->card, ohci->node_id, generation, |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 983 | self_id_count, ohci->self_id_buffer); |
| 984 | } |
| 985 | |
| 986 | static irqreturn_t irq_handler(int irq, void *data) |
| 987 | { |
| 988 | struct fw_ohci *ohci = data; |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 989 | u32 event, iso_event, cycle_time; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 990 | int i; |
| 991 | |
| 992 | event = reg_read(ohci, OHCI1394_IntEventClear); |
| 993 | |
| 994 | if (!event) |
| 995 | return IRQ_NONE; |
| 996 | |
| 997 | reg_write(ohci, OHCI1394_IntEventClear, event); |
| 998 | |
| 999 | if (event & OHCI1394_selfIDComplete) |
| 1000 | tasklet_schedule(&ohci->bus_reset_tasklet); |
| 1001 | |
| 1002 | if (event & OHCI1394_RQPkt) |
| 1003 | tasklet_schedule(&ohci->ar_request_ctx.tasklet); |
| 1004 | |
| 1005 | if (event & OHCI1394_RSPkt) |
| 1006 | tasklet_schedule(&ohci->ar_response_ctx.tasklet); |
| 1007 | |
| 1008 | if (event & OHCI1394_reqTxComplete) |
| 1009 | tasklet_schedule(&ohci->at_request_ctx.tasklet); |
| 1010 | |
| 1011 | if (event & OHCI1394_respTxComplete) |
| 1012 | tasklet_schedule(&ohci->at_response_ctx.tasklet); |
| 1013 | |
Kristian Høgsberg | c889475 | 2007-02-16 17:34:36 -0500 | [diff] [blame] | 1014 | iso_event = reg_read(ohci, OHCI1394_IsoRecvIntEventClear); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1015 | reg_write(ohci, OHCI1394_IsoRecvIntEventClear, iso_event); |
| 1016 | |
| 1017 | while (iso_event) { |
| 1018 | i = ffs(iso_event) - 1; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1019 | tasklet_schedule(&ohci->ir_context_list[i].context.tasklet); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1020 | iso_event &= ~(1 << i); |
| 1021 | } |
| 1022 | |
Kristian Høgsberg | c889475 | 2007-02-16 17:34:36 -0500 | [diff] [blame] | 1023 | iso_event = reg_read(ohci, OHCI1394_IsoXmitIntEventClear); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1024 | reg_write(ohci, OHCI1394_IsoXmitIntEventClear, iso_event); |
| 1025 | |
| 1026 | while (iso_event) { |
| 1027 | i = ffs(iso_event) - 1; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1028 | tasklet_schedule(&ohci->it_context_list[i].context.tasklet); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1029 | iso_event &= ~(1 << i); |
| 1030 | } |
| 1031 | |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 1032 | if (event & OHCI1394_cycle64Seconds) { |
| 1033 | cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); |
| 1034 | if ((cycle_time & 0x80000000) == 0) |
| 1035 | ohci->bus_seconds++; |
| 1036 | } |
| 1037 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1038 | return IRQ_HANDLED; |
| 1039 | } |
| 1040 | |
| 1041 | static int ohci_enable(struct fw_card *card, u32 *config_rom, size_t length) |
| 1042 | { |
| 1043 | struct fw_ohci *ohci = fw_ohci(card); |
| 1044 | struct pci_dev *dev = to_pci_dev(card->device); |
| 1045 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1046 | /* |
| 1047 | * When the link is not yet enabled, the atomic config rom |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1048 | * update mechanism described below in ohci_set_config_rom() |
| 1049 | * is not active. We have to update ConfigRomHeader and |
| 1050 | * BusOptions manually, and the write to ConfigROMmap takes |
| 1051 | * effect immediately. We tie this to the enabling of the |
| 1052 | * link, so we have a valid config rom before enabling - the |
| 1053 | * OHCI requires that ConfigROMhdr and BusOptions have valid |
| 1054 | * values before enabling. |
| 1055 | * |
| 1056 | * However, when the ConfigROMmap is written, some controllers |
| 1057 | * always read back quadlets 0 and 2 from the config rom to |
| 1058 | * the ConfigRomHeader and BusOptions registers on bus reset. |
| 1059 | * They shouldn't do that in this initial case where the link |
| 1060 | * isn't enabled. This means we have to use the same |
| 1061 | * workaround here, setting the bus header to 0 and then write |
| 1062 | * the right values in the bus reset tasklet. |
| 1063 | */ |
| 1064 | |
| 1065 | ohci->next_config_rom = |
| 1066 | dma_alloc_coherent(ohci->card.device, CONFIG_ROM_SIZE, |
| 1067 | &ohci->next_config_rom_bus, GFP_KERNEL); |
| 1068 | if (ohci->next_config_rom == NULL) |
| 1069 | return -ENOMEM; |
| 1070 | |
| 1071 | memset(ohci->next_config_rom, 0, CONFIG_ROM_SIZE); |
| 1072 | fw_memcpy_to_be32(ohci->next_config_rom, config_rom, length * 4); |
| 1073 | |
| 1074 | ohci->next_header = config_rom[0]; |
| 1075 | ohci->next_config_rom[0] = 0; |
| 1076 | reg_write(ohci, OHCI1394_ConfigROMhdr, 0); |
| 1077 | reg_write(ohci, OHCI1394_BusOptions, config_rom[2]); |
| 1078 | reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus); |
| 1079 | |
| 1080 | reg_write(ohci, OHCI1394_AsReqFilterHiSet, 0x80000000); |
| 1081 | |
| 1082 | if (request_irq(dev->irq, irq_handler, |
Thomas Gleixner | 65efffa | 2007-03-05 18:19:51 -0800 | [diff] [blame] | 1083 | IRQF_SHARED, ohci_driver_name, ohci)) { |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1084 | fw_error("Failed to allocate shared interrupt %d.\n", |
| 1085 | dev->irq); |
| 1086 | dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, |
| 1087 | ohci->config_rom, ohci->config_rom_bus); |
| 1088 | return -EIO; |
| 1089 | } |
| 1090 | |
| 1091 | reg_write(ohci, OHCI1394_HCControlSet, |
| 1092 | OHCI1394_HCControl_linkEnable | |
| 1093 | OHCI1394_HCControl_BIBimageValid); |
| 1094 | flush_writes(ohci); |
| 1095 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1096 | /* |
| 1097 | * We are ready to go, initiate bus reset to finish the |
| 1098 | * initialization. |
| 1099 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1100 | |
| 1101 | fw_core_initiate_bus_reset(&ohci->card, 1); |
| 1102 | |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | static int |
| 1107 | ohci_set_config_rom(struct fw_card *card, u32 *config_rom, size_t length) |
| 1108 | { |
| 1109 | struct fw_ohci *ohci; |
| 1110 | unsigned long flags; |
| 1111 | int retval = 0; |
| 1112 | __be32 *next_config_rom; |
| 1113 | dma_addr_t next_config_rom_bus; |
| 1114 | |
| 1115 | ohci = fw_ohci(card); |
| 1116 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1117 | /* |
| 1118 | * When the OHCI controller is enabled, the config rom update |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1119 | * mechanism is a bit tricky, but easy enough to use. See |
| 1120 | * section 5.5.6 in the OHCI specification. |
| 1121 | * |
| 1122 | * The OHCI controller caches the new config rom address in a |
| 1123 | * shadow register (ConfigROMmapNext) and needs a bus reset |
| 1124 | * for the changes to take place. When the bus reset is |
| 1125 | * detected, the controller loads the new values for the |
| 1126 | * ConfigRomHeader and BusOptions registers from the specified |
| 1127 | * config rom and loads ConfigROMmap from the ConfigROMmapNext |
| 1128 | * shadow register. All automatically and atomically. |
| 1129 | * |
| 1130 | * Now, there's a twist to this story. The automatic load of |
| 1131 | * ConfigRomHeader and BusOptions doesn't honor the |
| 1132 | * noByteSwapData bit, so with a be32 config rom, the |
| 1133 | * controller will load be32 values in to these registers |
| 1134 | * during the atomic update, even on litte endian |
| 1135 | * architectures. The workaround we use is to put a 0 in the |
| 1136 | * header quadlet; 0 is endian agnostic and means that the |
| 1137 | * config rom isn't ready yet. In the bus reset tasklet we |
| 1138 | * then set up the real values for the two registers. |
| 1139 | * |
| 1140 | * We use ohci->lock to avoid racing with the code that sets |
| 1141 | * ohci->next_config_rom to NULL (see bus_reset_tasklet). |
| 1142 | */ |
| 1143 | |
| 1144 | next_config_rom = |
| 1145 | dma_alloc_coherent(ohci->card.device, CONFIG_ROM_SIZE, |
| 1146 | &next_config_rom_bus, GFP_KERNEL); |
| 1147 | if (next_config_rom == NULL) |
| 1148 | return -ENOMEM; |
| 1149 | |
| 1150 | spin_lock_irqsave(&ohci->lock, flags); |
| 1151 | |
| 1152 | if (ohci->next_config_rom == NULL) { |
| 1153 | ohci->next_config_rom = next_config_rom; |
| 1154 | ohci->next_config_rom_bus = next_config_rom_bus; |
| 1155 | |
| 1156 | memset(ohci->next_config_rom, 0, CONFIG_ROM_SIZE); |
| 1157 | fw_memcpy_to_be32(ohci->next_config_rom, config_rom, |
| 1158 | length * 4); |
| 1159 | |
| 1160 | ohci->next_header = config_rom[0]; |
| 1161 | ohci->next_config_rom[0] = 0; |
| 1162 | |
| 1163 | reg_write(ohci, OHCI1394_ConfigROMmap, |
| 1164 | ohci->next_config_rom_bus); |
| 1165 | } else { |
| 1166 | dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, |
| 1167 | next_config_rom, next_config_rom_bus); |
| 1168 | retval = -EBUSY; |
| 1169 | } |
| 1170 | |
| 1171 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 1172 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1173 | /* |
| 1174 | * Now initiate a bus reset to have the changes take |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1175 | * effect. We clean up the old config rom memory and DMA |
| 1176 | * mappings in the bus reset tasklet, since the OHCI |
| 1177 | * controller could need to access it before the bus reset |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1178 | * takes effect. |
| 1179 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1180 | if (retval == 0) |
| 1181 | fw_core_initiate_bus_reset(&ohci->card, 1); |
| 1182 | |
| 1183 | return retval; |
| 1184 | } |
| 1185 | |
| 1186 | static void ohci_send_request(struct fw_card *card, struct fw_packet *packet) |
| 1187 | { |
| 1188 | struct fw_ohci *ohci = fw_ohci(card); |
| 1189 | |
| 1190 | at_context_transmit(&ohci->at_request_ctx, packet); |
| 1191 | } |
| 1192 | |
| 1193 | static void ohci_send_response(struct fw_card *card, struct fw_packet *packet) |
| 1194 | { |
| 1195 | struct fw_ohci *ohci = fw_ohci(card); |
| 1196 | |
| 1197 | at_context_transmit(&ohci->at_response_ctx, packet); |
| 1198 | } |
| 1199 | |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 1200 | static int ohci_cancel_packet(struct fw_card *card, struct fw_packet *packet) |
| 1201 | { |
| 1202 | struct fw_ohci *ohci = fw_ohci(card); |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 1203 | struct context *ctx = &ohci->at_request_ctx; |
| 1204 | struct driver_data *driver_data = packet->driver_data; |
| 1205 | int retval = -ENOENT; |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 1206 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 1207 | tasklet_disable(&ctx->tasklet); |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 1208 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 1209 | if (packet->ack != 0) |
| 1210 | goto out; |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 1211 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 1212 | driver_data->packet = NULL; |
| 1213 | packet->ack = RCODE_CANCELLED; |
| 1214 | packet->callback(packet, &ohci->card, packet->ack); |
| 1215 | retval = 0; |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 1216 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 1217 | out: |
| 1218 | tasklet_enable(&ctx->tasklet); |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 1219 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 1220 | return retval; |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 1221 | } |
| 1222 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1223 | static int |
| 1224 | ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation) |
| 1225 | { |
| 1226 | struct fw_ohci *ohci = fw_ohci(card); |
| 1227 | unsigned long flags; |
Stefan Richter | 907293d | 2007-01-23 21:11:43 +0100 | [diff] [blame] | 1228 | int n, retval = 0; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1229 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1230 | /* |
| 1231 | * FIXME: Make sure this bitmask is cleared when we clear the busReset |
| 1232 | * interrupt bit. Clear physReqResourceAllBuses on bus reset. |
| 1233 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1234 | |
| 1235 | spin_lock_irqsave(&ohci->lock, flags); |
| 1236 | |
| 1237 | if (ohci->generation != generation) { |
| 1238 | retval = -ESTALE; |
| 1239 | goto out; |
| 1240 | } |
| 1241 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1242 | /* |
| 1243 | * Note, if the node ID contains a non-local bus ID, physical DMA is |
| 1244 | * enabled for _all_ nodes on remote buses. |
| 1245 | */ |
Stefan Richter | 907293d | 2007-01-23 21:11:43 +0100 | [diff] [blame] | 1246 | |
| 1247 | n = (node_id & 0xffc0) == LOCAL_BUS ? node_id & 0x3f : 63; |
| 1248 | if (n < 32) |
| 1249 | reg_write(ohci, OHCI1394_PhyReqFilterLoSet, 1 << n); |
| 1250 | else |
| 1251 | reg_write(ohci, OHCI1394_PhyReqFilterHiSet, 1 << (n - 32)); |
| 1252 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1253 | flush_writes(ohci); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1254 | out: |
Stefan Richter | 6cad95f | 2007-01-21 20:46:45 +0100 | [diff] [blame] | 1255 | spin_unlock_irqrestore(&ohci->lock, flags); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1256 | return retval; |
| 1257 | } |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1258 | |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 1259 | static u64 |
| 1260 | ohci_get_bus_time(struct fw_card *card) |
| 1261 | { |
| 1262 | struct fw_ohci *ohci = fw_ohci(card); |
| 1263 | u32 cycle_time; |
| 1264 | u64 bus_time; |
| 1265 | |
| 1266 | cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer); |
| 1267 | bus_time = ((u64) ohci->bus_seconds << 32) | cycle_time; |
| 1268 | |
| 1269 | return bus_time; |
| 1270 | } |
| 1271 | |
Kristian Høgsberg | d2746dc | 2007-02-16 17:34:46 -0500 | [diff] [blame] | 1272 | static int handle_ir_dualbuffer_packet(struct context *context, |
| 1273 | struct descriptor *d, |
| 1274 | struct descriptor *last) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1275 | { |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1276 | struct iso_context *ctx = |
| 1277 | container_of(context, struct iso_context, context); |
| 1278 | struct db_descriptor *db = (struct db_descriptor *) d; |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1279 | __le32 *ir_header; |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1280 | size_t header_length; |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1281 | void *p, *end; |
| 1282 | int i; |
Kristian Høgsberg | d2746dc | 2007-02-16 17:34:46 -0500 | [diff] [blame] | 1283 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1284 | if (db->first_res_count > 0 && db->second_res_count > 0) |
| 1285 | /* This descriptor isn't done yet, stop iteration. */ |
| 1286 | return 0; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1287 | |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1288 | header_length = le16_to_cpu(db->first_req_count) - |
| 1289 | le16_to_cpu(db->first_res_count); |
| 1290 | |
| 1291 | i = ctx->header_length; |
| 1292 | p = db + 1; |
| 1293 | end = p + header_length; |
| 1294 | while (p < end && i + ctx->base.header_size <= PAGE_SIZE) { |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1295 | /* |
| 1296 | * The iso header is byteswapped to little endian by |
Kristian Høgsberg | 1553622 | 2007-04-10 18:11:16 -0400 | [diff] [blame] | 1297 | * the controller, but the remaining header quadlets |
| 1298 | * are big endian. We want to present all the headers |
| 1299 | * as big endian, so we have to swap the first |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1300 | * quadlet. |
| 1301 | */ |
Kristian Høgsberg | 1553622 | 2007-04-10 18:11:16 -0400 | [diff] [blame] | 1302 | *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4)); |
| 1303 | memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1304 | i += ctx->base.header_size; |
| 1305 | p += ctx->base.header_size + 4; |
| 1306 | } |
| 1307 | |
| 1308 | ctx->header_length = i; |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1309 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1310 | if (le16_to_cpu(db->control) & DESCRIPTOR_IRQ_ALWAYS) { |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1311 | ir_header = (__le32 *) (db + 1); |
| 1312 | ctx->base.callback(&ctx->base, |
| 1313 | le32_to_cpu(ir_header[0]) & 0xffff, |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1314 | ctx->header_length, ctx->header, |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1315 | ctx->base.callback_data); |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1316 | ctx->header_length = 0; |
| 1317 | } |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1318 | |
| 1319 | return 1; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1320 | } |
| 1321 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1322 | static int handle_it_packet(struct context *context, |
| 1323 | struct descriptor *d, |
| 1324 | struct descriptor *last) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1325 | { |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1326 | struct iso_context *ctx = |
| 1327 | container_of(context, struct iso_context, context); |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1328 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1329 | if (last->transfer_status == 0) |
| 1330 | /* This descriptor isn't done yet, stop iteration. */ |
| 1331 | return 0; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1332 | |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1333 | if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1334 | ctx->base.callback(&ctx->base, le16_to_cpu(last->res_count), |
| 1335 | 0, NULL, ctx->base.callback_data); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1336 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1337 | return 1; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1338 | } |
| 1339 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1340 | static struct fw_iso_context * |
Kristian Høgsberg | eb0306e | 2007-03-14 17:34:54 -0400 | [diff] [blame] | 1341 | ohci_allocate_iso_context(struct fw_card *card, int type, size_t header_size) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1342 | { |
| 1343 | struct fw_ohci *ohci = fw_ohci(card); |
| 1344 | struct iso_context *ctx, *list; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1345 | descriptor_callback_t callback; |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1346 | u32 *mask, regs; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1347 | unsigned long flags; |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1348 | int index, retval = -ENOMEM; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1349 | |
| 1350 | if (type == FW_ISO_CONTEXT_TRANSMIT) { |
| 1351 | mask = &ohci->it_context_mask; |
| 1352 | list = ohci->it_context_list; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1353 | callback = handle_it_packet; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1354 | } else { |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1355 | mask = &ohci->ir_context_mask; |
| 1356 | list = ohci->ir_context_list; |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1357 | callback = handle_ir_dualbuffer_packet; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1358 | } |
| 1359 | |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1360 | /* FIXME: We need a fallback for pre 1.1 OHCI. */ |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 1361 | if (callback == handle_ir_dualbuffer_packet && |
| 1362 | ohci->version < OHCI_VERSION_1_1) |
| 1363 | return ERR_PTR(-EINVAL); |
| 1364 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1365 | spin_lock_irqsave(&ohci->lock, flags); |
| 1366 | index = ffs(*mask) - 1; |
| 1367 | if (index >= 0) |
| 1368 | *mask &= ~(1 << index); |
| 1369 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 1370 | |
| 1371 | if (index < 0) |
| 1372 | return ERR_PTR(-EBUSY); |
| 1373 | |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1374 | if (type == FW_ISO_CONTEXT_TRANSMIT) |
| 1375 | regs = OHCI1394_IsoXmitContextBase(index); |
| 1376 | else |
| 1377 | regs = OHCI1394_IsoRcvContextBase(index); |
| 1378 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1379 | ctx = &list[index]; |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1380 | memset(ctx, 0, sizeof(*ctx)); |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1381 | ctx->header_length = 0; |
| 1382 | ctx->header = (void *) __get_free_page(GFP_KERNEL); |
| 1383 | if (ctx->header == NULL) |
| 1384 | goto out; |
| 1385 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1386 | retval = context_init(&ctx->context, ohci, ISO_BUFFER_SIZE, |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1387 | regs, callback); |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1388 | if (retval < 0) |
| 1389 | goto out_with_header; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1390 | |
| 1391 | return &ctx->base; |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1392 | |
| 1393 | out_with_header: |
| 1394 | free_page((unsigned long)ctx->header); |
| 1395 | out: |
| 1396 | spin_lock_irqsave(&ohci->lock, flags); |
| 1397 | *mask |= 1 << index; |
| 1398 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 1399 | |
| 1400 | return ERR_PTR(retval); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1401 | } |
| 1402 | |
Kristian Høgsberg | eb0306e | 2007-03-14 17:34:54 -0400 | [diff] [blame] | 1403 | static int ohci_start_iso(struct fw_iso_context *base, |
| 1404 | s32 cycle, u32 sync, u32 tags) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1405 | { |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1406 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1407 | struct fw_ohci *ohci = ctx->context.ohci; |
Kristian Høgsberg | 8a2f7d9 | 2007-03-28 14:26:10 -0400 | [diff] [blame] | 1408 | u32 control, match; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1409 | int index; |
| 1410 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1411 | if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) { |
| 1412 | index = ctx - ohci->it_context_list; |
Kristian Høgsberg | 8a2f7d9 | 2007-03-28 14:26:10 -0400 | [diff] [blame] | 1413 | match = 0; |
| 1414 | if (cycle >= 0) |
| 1415 | match = IT_CONTEXT_CYCLE_MATCH_ENABLE | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1416 | (cycle & 0x7fff) << 16; |
Kristian Høgsberg | 21efb3c | 2007-02-16 17:34:50 -0500 | [diff] [blame] | 1417 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1418 | reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 1 << index); |
| 1419 | reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, 1 << index); |
Kristian Høgsberg | 8a2f7d9 | 2007-03-28 14:26:10 -0400 | [diff] [blame] | 1420 | context_run(&ctx->context, match); |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1421 | } else { |
| 1422 | index = ctx - ohci->ir_context_list; |
Kristian Høgsberg | 8a2f7d9 | 2007-03-28 14:26:10 -0400 | [diff] [blame] | 1423 | control = IR_CONTEXT_DUAL_BUFFER_MODE | IR_CONTEXT_ISOCH_HEADER; |
| 1424 | match = (tags << 28) | (sync << 8) | ctx->base.channel; |
| 1425 | if (cycle >= 0) { |
| 1426 | match |= (cycle & 0x07fff) << 12; |
| 1427 | control |= IR_CONTEXT_CYCLE_MATCH_ENABLE; |
| 1428 | } |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1429 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1430 | reg_write(ohci, OHCI1394_IsoRecvIntEventClear, 1 << index); |
| 1431 | reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1 << index); |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1432 | reg_write(ohci, CONTEXT_MATCH(ctx->context.regs), match); |
Kristian Høgsberg | 8a2f7d9 | 2007-03-28 14:26:10 -0400 | [diff] [blame] | 1433 | context_run(&ctx->context, control); |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1434 | } |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1435 | |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 1439 | static int ohci_stop_iso(struct fw_iso_context *base) |
| 1440 | { |
| 1441 | struct fw_ohci *ohci = fw_ohci(base->card); |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1442 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 1443 | int index; |
| 1444 | |
| 1445 | if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) { |
| 1446 | index = ctx - ohci->it_context_list; |
| 1447 | reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 1 << index); |
| 1448 | } else { |
| 1449 | index = ctx - ohci->ir_context_list; |
| 1450 | reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 1 << index); |
| 1451 | } |
| 1452 | flush_writes(ohci); |
| 1453 | context_stop(&ctx->context); |
| 1454 | |
| 1455 | return 0; |
| 1456 | } |
| 1457 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1458 | static void ohci_free_iso_context(struct fw_iso_context *base) |
| 1459 | { |
| 1460 | struct fw_ohci *ohci = fw_ohci(base->card); |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1461 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1462 | unsigned long flags; |
| 1463 | int index; |
| 1464 | |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 1465 | ohci_stop_iso(base); |
| 1466 | context_release(&ctx->context); |
Kristian Høgsberg | 9b32d5f | 2007-02-16 17:34:44 -0500 | [diff] [blame] | 1467 | free_page((unsigned long)ctx->header); |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 1468 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1469 | spin_lock_irqsave(&ohci->lock, flags); |
| 1470 | |
| 1471 | if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) { |
| 1472 | index = ctx - ohci->it_context_list; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1473 | ohci->it_context_mask |= 1 << index; |
| 1474 | } else { |
| 1475 | index = ctx - ohci->ir_context_list; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1476 | ohci->ir_context_mask |= 1 << index; |
| 1477 | } |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1478 | |
| 1479 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 1480 | } |
| 1481 | |
| 1482 | static int |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1483 | ohci_queue_iso_transmit(struct fw_iso_context *base, |
| 1484 | struct fw_iso_packet *packet, |
| 1485 | struct fw_iso_buffer *buffer, |
| 1486 | unsigned long payload) |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1487 | { |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1488 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1489 | struct descriptor *d, *last, *pd; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1490 | struct fw_iso_packet *p; |
| 1491 | __le32 *header; |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 1492 | dma_addr_t d_bus, page_bus; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1493 | u32 z, header_z, payload_z, irq; |
| 1494 | u32 payload_index, payload_end_index, next_page_index; |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1495 | int page, end_page, i, length, offset; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1496 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1497 | /* |
| 1498 | * FIXME: Cycle lost behavior should be configurable: lose |
| 1499 | * packet, retransmit or terminate.. |
| 1500 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1501 | |
| 1502 | p = packet; |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 1503 | payload_index = payload; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1504 | |
| 1505 | if (p->skip) |
| 1506 | z = 1; |
| 1507 | else |
| 1508 | z = 2; |
| 1509 | if (p->header_length > 0) |
| 1510 | z++; |
| 1511 | |
| 1512 | /* Determine the first page the payload isn't contained in. */ |
| 1513 | end_page = PAGE_ALIGN(payload_index + p->payload_length) >> PAGE_SHIFT; |
| 1514 | if (p->payload_length > 0) |
| 1515 | payload_z = end_page - (payload_index >> PAGE_SHIFT); |
| 1516 | else |
| 1517 | payload_z = 0; |
| 1518 | |
| 1519 | z += payload_z; |
| 1520 | |
| 1521 | /* Get header size in number of descriptors. */ |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1522 | header_z = DIV_ROUND_UP(p->header_length, sizeof(*d)); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1523 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1524 | d = context_get_descriptors(&ctx->context, z + header_z, &d_bus); |
| 1525 | if (d == NULL) |
| 1526 | return -ENOMEM; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1527 | |
| 1528 | if (!p->skip) { |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1529 | d[0].control = cpu_to_le16(DESCRIPTOR_KEY_IMMEDIATE); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1530 | d[0].req_count = cpu_to_le16(8); |
| 1531 | |
| 1532 | header = (__le32 *) &d[1]; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1533 | header[0] = cpu_to_le32(IT_HEADER_SY(p->sy) | |
| 1534 | IT_HEADER_TAG(p->tag) | |
| 1535 | IT_HEADER_TCODE(TCODE_STREAM_DATA) | |
| 1536 | IT_HEADER_CHANNEL(ctx->base.channel) | |
| 1537 | IT_HEADER_SPEED(ctx->base.speed)); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1538 | header[1] = |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1539 | cpu_to_le32(IT_HEADER_DATA_LENGTH(p->header_length + |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1540 | p->payload_length)); |
| 1541 | } |
| 1542 | |
| 1543 | if (p->header_length > 0) { |
| 1544 | d[2].req_count = cpu_to_le16(p->header_length); |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1545 | d[2].data_address = cpu_to_le32(d_bus + z * sizeof(*d)); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1546 | memcpy(&d[z], p->header, p->header_length); |
| 1547 | } |
| 1548 | |
| 1549 | pd = d + z - payload_z; |
| 1550 | payload_end_index = payload_index + p->payload_length; |
| 1551 | for (i = 0; i < payload_z; i++) { |
| 1552 | page = payload_index >> PAGE_SHIFT; |
| 1553 | offset = payload_index & ~PAGE_MASK; |
| 1554 | next_page_index = (page + 1) << PAGE_SHIFT; |
| 1555 | length = |
| 1556 | min(next_page_index, payload_end_index) - payload_index; |
| 1557 | pd[i].req_count = cpu_to_le16(length); |
Kristian Høgsberg | 9aad812 | 2007-02-16 17:34:38 -0500 | [diff] [blame] | 1558 | |
| 1559 | page_bus = page_private(buffer->pages[page]); |
| 1560 | pd[i].data_address = cpu_to_le32(page_bus + offset); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1561 | |
| 1562 | payload_index += length; |
| 1563 | } |
| 1564 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1565 | if (p->interrupt) |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1566 | irq = DESCRIPTOR_IRQ_ALWAYS; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1567 | else |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1568 | irq = DESCRIPTOR_NO_IRQ; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1569 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1570 | last = z == 2 ? d : d + z - 1; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1571 | last->control |= cpu_to_le16(DESCRIPTOR_OUTPUT_LAST | |
| 1572 | DESCRIPTOR_STATUS | |
| 1573 | DESCRIPTOR_BRANCH_ALWAYS | |
Kristian Høgsberg | cbb59da | 2007-02-16 17:34:35 -0500 | [diff] [blame] | 1574 | irq); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1575 | |
Kristian Høgsberg | 3020073 | 2007-02-16 17:34:39 -0500 | [diff] [blame] | 1576 | context_append(&ctx->context, d, z, header_z); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1577 | |
| 1578 | return 0; |
| 1579 | } |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1580 | |
Kristian Høgsberg | 98b6cbe | 2007-02-16 17:34:51 -0500 | [diff] [blame] | 1581 | static int |
Kristian Høgsberg | d2746dc | 2007-02-16 17:34:46 -0500 | [diff] [blame] | 1582 | ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base, |
| 1583 | struct fw_iso_packet *packet, |
| 1584 | struct fw_iso_buffer *buffer, |
| 1585 | unsigned long payload) |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1586 | { |
| 1587 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
| 1588 | struct db_descriptor *db = NULL; |
| 1589 | struct descriptor *d; |
| 1590 | struct fw_iso_packet *p; |
| 1591 | dma_addr_t d_bus, page_bus; |
| 1592 | u32 z, header_z, length, rest; |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1593 | int page, offset, packet_count, header_size; |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1594 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1595 | /* |
| 1596 | * FIXME: Cycle lost behavior should be configurable: lose |
| 1597 | * packet, retransmit or terminate.. |
| 1598 | */ |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1599 | |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1600 | if (packet->skip) { |
| 1601 | d = context_get_descriptors(&ctx->context, 2, &d_bus); |
| 1602 | if (d == NULL) |
| 1603 | return -ENOMEM; |
| 1604 | |
| 1605 | db = (struct db_descriptor *) d; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1606 | db->control = cpu_to_le16(DESCRIPTOR_STATUS | |
| 1607 | DESCRIPTOR_BRANCH_ALWAYS | |
| 1608 | DESCRIPTOR_WAIT); |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1609 | db->first_size = cpu_to_le16(ctx->base.header_size + 4); |
| 1610 | context_append(&ctx->context, d, 2, 0); |
| 1611 | } |
Kristian Høgsberg | 98b6cbe | 2007-02-16 17:34:51 -0500 | [diff] [blame] | 1612 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1613 | p = packet; |
| 1614 | z = 2; |
| 1615 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1616 | /* |
| 1617 | * The OHCI controller puts the status word in the header |
| 1618 | * buffer too, so we need 4 extra bytes per packet. |
| 1619 | */ |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1620 | packet_count = p->header_length / ctx->base.header_size; |
| 1621 | header_size = packet_count * (ctx->base.header_size + 4); |
| 1622 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1623 | /* Get header size in number of descriptors. */ |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1624 | header_z = DIV_ROUND_UP(header_size, sizeof(*d)); |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1625 | page = payload >> PAGE_SHIFT; |
| 1626 | offset = payload & ~PAGE_MASK; |
| 1627 | rest = p->payload_length; |
| 1628 | |
| 1629 | /* FIXME: OHCI 1.0 doesn't support dual buffer receive */ |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1630 | /* FIXME: make packet-per-buffer/dual-buffer a context option */ |
| 1631 | while (rest > 0) { |
| 1632 | d = context_get_descriptors(&ctx->context, |
| 1633 | z + header_z, &d_bus); |
| 1634 | if (d == NULL) |
| 1635 | return -ENOMEM; |
| 1636 | |
| 1637 | db = (struct db_descriptor *) d; |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1638 | db->control = cpu_to_le16(DESCRIPTOR_STATUS | |
| 1639 | DESCRIPTOR_BRANCH_ALWAYS); |
Kristian Høgsberg | c70dc78 | 2007-03-14 17:34:53 -0400 | [diff] [blame] | 1640 | db->first_size = cpu_to_le16(ctx->base.header_size + 4); |
| 1641 | db->first_req_count = cpu_to_le16(header_size); |
Kristian Høgsberg | 1e1d196 | 2007-02-16 17:34:45 -0500 | [diff] [blame] | 1642 | db->first_res_count = db->first_req_count; |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1643 | db->first_buffer = cpu_to_le32(d_bus + sizeof(*db)); |
Stefan Richter | 373b2ed | 2007-03-04 14:45:18 +0100 | [diff] [blame] | 1644 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1645 | if (offset + rest < PAGE_SIZE) |
| 1646 | length = rest; |
| 1647 | else |
| 1648 | length = PAGE_SIZE - offset; |
| 1649 | |
Kristian Høgsberg | 1e1d196 | 2007-02-16 17:34:45 -0500 | [diff] [blame] | 1650 | db->second_req_count = cpu_to_le16(length); |
| 1651 | db->second_res_count = db->second_req_count; |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1652 | page_bus = page_private(buffer->pages[page]); |
| 1653 | db->second_buffer = cpu_to_le32(page_bus + offset); |
| 1654 | |
Kristian Høgsberg | cb2d2cd | 2007-02-16 17:34:47 -0500 | [diff] [blame] | 1655 | if (p->interrupt && length == rest) |
Kristian Høgsberg | a77754a | 2007-05-07 20:33:35 -0400 | [diff] [blame] | 1656 | db->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS); |
Kristian Høgsberg | cb2d2cd | 2007-02-16 17:34:47 -0500 | [diff] [blame] | 1657 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1658 | context_append(&ctx->context, d, z, header_z); |
| 1659 | offset = (offset + length) & ~PAGE_MASK; |
| 1660 | rest -= length; |
| 1661 | page++; |
| 1662 | } |
| 1663 | |
Kristian Høgsberg | d2746dc | 2007-02-16 17:34:46 -0500 | [diff] [blame] | 1664 | return 0; |
| 1665 | } |
Kristian Høgsberg | 21efb3c | 2007-02-16 17:34:50 -0500 | [diff] [blame] | 1666 | |
Kristian Høgsberg | d2746dc | 2007-02-16 17:34:46 -0500 | [diff] [blame] | 1667 | static int |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1668 | ohci_queue_iso(struct fw_iso_context *base, |
| 1669 | struct fw_iso_packet *packet, |
| 1670 | struct fw_iso_buffer *buffer, |
| 1671 | unsigned long payload) |
| 1672 | { |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 1673 | struct iso_context *ctx = container_of(base, struct iso_context, base); |
| 1674 | |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1675 | if (base->type == FW_ISO_CONTEXT_TRANSMIT) |
| 1676 | return ohci_queue_iso_transmit(base, packet, buffer, payload); |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 1677 | else if (ctx->context.ohci->version >= OHCI_VERSION_1_1) |
Kristian Høgsberg | d2746dc | 2007-02-16 17:34:46 -0500 | [diff] [blame] | 1678 | return ohci_queue_iso_receive_dualbuffer(base, packet, |
| 1679 | buffer, payload); |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 1680 | else |
| 1681 | /* FIXME: Implement fallback for OHCI 1.0 controllers. */ |
| 1682 | return -EINVAL; |
Kristian Høgsberg | 295e3fe | 2007-02-16 17:34:40 -0500 | [diff] [blame] | 1683 | } |
| 1684 | |
Stefan Richter | 21ebcd1 | 2007-01-14 15:29:07 +0100 | [diff] [blame] | 1685 | static const struct fw_card_driver ohci_driver = { |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1686 | .name = ohci_driver_name, |
| 1687 | .enable = ohci_enable, |
| 1688 | .update_phy_reg = ohci_update_phy_reg, |
| 1689 | .set_config_rom = ohci_set_config_rom, |
| 1690 | .send_request = ohci_send_request, |
| 1691 | .send_response = ohci_send_response, |
Kristian Høgsberg | 730c32f | 2007-02-06 14:49:32 -0500 | [diff] [blame] | 1692 | .cancel_packet = ohci_cancel_packet, |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1693 | .enable_phys_dma = ohci_enable_phys_dma, |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 1694 | .get_bus_time = ohci_get_bus_time, |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1695 | |
| 1696 | .allocate_iso_context = ohci_allocate_iso_context, |
| 1697 | .free_iso_context = ohci_free_iso_context, |
| 1698 | .queue_iso = ohci_queue_iso, |
Kristian Høgsberg | 69cdb72 | 2007-02-16 17:34:41 -0500 | [diff] [blame] | 1699 | .start_iso = ohci_start_iso, |
Kristian Høgsberg | b829566 | 2007-02-16 17:34:42 -0500 | [diff] [blame] | 1700 | .stop_iso = ohci_stop_iso, |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1701 | }; |
| 1702 | |
| 1703 | static int software_reset(struct fw_ohci *ohci) |
| 1704 | { |
| 1705 | int i; |
| 1706 | |
| 1707 | reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_softReset); |
| 1708 | |
| 1709 | for (i = 0; i < OHCI_LOOP_COUNT; i++) { |
| 1710 | if ((reg_read(ohci, OHCI1394_HCControlSet) & |
| 1711 | OHCI1394_HCControl_softReset) == 0) |
| 1712 | return 0; |
| 1713 | msleep(1); |
| 1714 | } |
| 1715 | |
| 1716 | return -EBUSY; |
| 1717 | } |
| 1718 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1719 | static int __devinit |
| 1720 | pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) |
| 1721 | { |
| 1722 | struct fw_ohci *ohci; |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 1723 | u32 bus_options, max_receive, link_speed; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1724 | u64 guid; |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1725 | int err; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1726 | size_t size; |
| 1727 | |
Kristian Høgsberg | 2d826cc | 2007-05-09 19:23:14 -0400 | [diff] [blame] | 1728 | ohci = kzalloc(sizeof(*ohci), GFP_KERNEL); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1729 | if (ohci == NULL) { |
| 1730 | fw_error("Could not malloc fw_ohci data.\n"); |
| 1731 | return -ENOMEM; |
| 1732 | } |
| 1733 | |
| 1734 | fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev); |
| 1735 | |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1736 | err = pci_enable_device(dev); |
| 1737 | if (err) { |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1738 | fw_error("Failed to enable OHCI hardware.\n"); |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1739 | goto fail_put_card; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | pci_set_master(dev); |
| 1743 | pci_write_config_dword(dev, OHCI1394_PCI_HCI_Control, 0); |
| 1744 | pci_set_drvdata(dev, ohci); |
| 1745 | |
| 1746 | spin_lock_init(&ohci->lock); |
| 1747 | |
| 1748 | tasklet_init(&ohci->bus_reset_tasklet, |
| 1749 | bus_reset_tasklet, (unsigned long)ohci); |
| 1750 | |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1751 | err = pci_request_region(dev, 0, ohci_driver_name); |
| 1752 | if (err) { |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1753 | fw_error("MMIO resource unavailable\n"); |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1754 | goto fail_disable; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | ohci->registers = pci_iomap(dev, 0, OHCI1394_REGISTER_SIZE); |
| 1758 | if (ohci->registers == NULL) { |
| 1759 | fw_error("Failed to remap registers\n"); |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1760 | err = -ENXIO; |
| 1761 | goto fail_iomem; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | if (software_reset(ohci)) { |
| 1765 | fw_error("Failed to reset ohci card.\n"); |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1766 | err = -EBUSY; |
| 1767 | goto fail_registers; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1768 | } |
| 1769 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1770 | /* |
| 1771 | * Now enable LPS, which we need in order to start accessing |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1772 | * most of the registers. In fact, on some cards (ALI M5251), |
| 1773 | * accessing registers in the SClk domain without LPS enabled |
| 1774 | * will lock up the machine. Wait 50msec to make sure we have |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1775 | * full link enabled. |
| 1776 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1777 | reg_write(ohci, OHCI1394_HCControlSet, |
| 1778 | OHCI1394_HCControl_LPS | |
| 1779 | OHCI1394_HCControl_postedWriteEnable); |
| 1780 | flush_writes(ohci); |
| 1781 | msleep(50); |
| 1782 | |
| 1783 | reg_write(ohci, OHCI1394_HCControlClear, |
| 1784 | OHCI1394_HCControl_noByteSwapData); |
| 1785 | |
| 1786 | reg_write(ohci, OHCI1394_LinkControlSet, |
| 1787 | OHCI1394_LinkControl_rcvSelfID | |
| 1788 | OHCI1394_LinkControl_cycleTimerEnable | |
| 1789 | OHCI1394_LinkControl_cycleMaster); |
| 1790 | |
| 1791 | ar_context_init(&ohci->ar_request_ctx, ohci, |
| 1792 | OHCI1394_AsReqRcvContextControlSet); |
| 1793 | |
| 1794 | ar_context_init(&ohci->ar_response_ctx, ohci, |
| 1795 | OHCI1394_AsRspRcvContextControlSet); |
| 1796 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 1797 | context_init(&ohci->at_request_ctx, ohci, AT_BUFFER_SIZE, |
| 1798 | OHCI1394_AsReqTrContextControlSet, handle_at_packet); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1799 | |
Kristian Høgsberg | f319b6a | 2007-03-07 12:12:49 -0500 | [diff] [blame] | 1800 | context_init(&ohci->at_response_ctx, ohci, AT_BUFFER_SIZE, |
| 1801 | OHCI1394_AsRspTrContextControlSet, handle_at_packet); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1802 | |
| 1803 | reg_write(ohci, OHCI1394_ATRetries, |
| 1804 | OHCI1394_MAX_AT_REQ_RETRIES | |
| 1805 | (OHCI1394_MAX_AT_RESP_RETRIES << 4) | |
| 1806 | (OHCI1394_MAX_PHYS_RESP_RETRIES << 8)); |
| 1807 | |
| 1808 | reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0); |
| 1809 | ohci->it_context_mask = reg_read(ohci, OHCI1394_IsoRecvIntMaskSet); |
| 1810 | reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0); |
| 1811 | size = sizeof(struct iso_context) * hweight32(ohci->it_context_mask); |
| 1812 | ohci->it_context_list = kzalloc(size, GFP_KERNEL); |
| 1813 | |
| 1814 | reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0); |
| 1815 | ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet); |
| 1816 | reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0); |
| 1817 | size = sizeof(struct iso_context) * hweight32(ohci->ir_context_mask); |
| 1818 | ohci->ir_context_list = kzalloc(size, GFP_KERNEL); |
| 1819 | |
| 1820 | if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) { |
| 1821 | fw_error("Out of memory for it/ir contexts.\n"); |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1822 | err = -ENOMEM; |
| 1823 | goto fail_registers; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | /* self-id dma buffer allocation */ |
| 1827 | ohci->self_id_cpu = dma_alloc_coherent(ohci->card.device, |
| 1828 | SELF_ID_BUF_SIZE, |
| 1829 | &ohci->self_id_bus, |
| 1830 | GFP_KERNEL); |
| 1831 | if (ohci->self_id_cpu == NULL) { |
| 1832 | fw_error("Out of memory for self ID buffer.\n"); |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1833 | err = -ENOMEM; |
| 1834 | goto fail_registers; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | reg_write(ohci, OHCI1394_SelfIDBuffer, ohci->self_id_bus); |
| 1838 | reg_write(ohci, OHCI1394_PhyUpperBound, 0x00010000); |
| 1839 | reg_write(ohci, OHCI1394_IntEventClear, ~0); |
| 1840 | reg_write(ohci, OHCI1394_IntMaskClear, ~0); |
| 1841 | reg_write(ohci, OHCI1394_IntMaskSet, |
| 1842 | OHCI1394_selfIDComplete | |
| 1843 | OHCI1394_RQPkt | OHCI1394_RSPkt | |
| 1844 | OHCI1394_reqTxComplete | OHCI1394_respTxComplete | |
| 1845 | OHCI1394_isochRx | OHCI1394_isochTx | |
Kristian Høgsberg | d60d7f1 | 2007-03-07 12:12:56 -0500 | [diff] [blame] | 1846 | OHCI1394_masterIntEnable | |
| 1847 | OHCI1394_cycle64Seconds); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1848 | |
| 1849 | bus_options = reg_read(ohci, OHCI1394_BusOptions); |
| 1850 | max_receive = (bus_options >> 12) & 0xf; |
| 1851 | link_speed = bus_options & 0x7; |
| 1852 | guid = ((u64) reg_read(ohci, OHCI1394_GUIDHi) << 32) | |
| 1853 | reg_read(ohci, OHCI1394_GUIDLo); |
| 1854 | |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1855 | err = fw_card_add(&ohci->card, max_receive, link_speed, guid); |
| 1856 | if (err < 0) |
| 1857 | goto fail_self_id; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1858 | |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 1859 | ohci->version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff; |
Kristian Høgsberg | 500be72 | 2007-02-16 17:34:43 -0500 | [diff] [blame] | 1860 | fw_notify("Added fw-ohci device %s, OHCI version %x.%x\n", |
Kristian Høgsberg | e364cf4 | 2007-02-16 17:34:49 -0500 | [diff] [blame] | 1861 | dev->dev.bus_id, ohci->version >> 16, ohci->version & 0xff); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1862 | |
| 1863 | return 0; |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1864 | |
| 1865 | fail_self_id: |
| 1866 | dma_free_coherent(ohci->card.device, SELF_ID_BUF_SIZE, |
| 1867 | ohci->self_id_cpu, ohci->self_id_bus); |
| 1868 | fail_registers: |
| 1869 | kfree(ohci->it_context_list); |
| 1870 | kfree(ohci->ir_context_list); |
| 1871 | pci_iounmap(dev, ohci->registers); |
| 1872 | fail_iomem: |
| 1873 | pci_release_region(dev, 0); |
| 1874 | fail_disable: |
| 1875 | pci_disable_device(dev); |
| 1876 | fail_put_card: |
| 1877 | fw_card_put(&ohci->card); |
| 1878 | |
| 1879 | return err; |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | static void pci_remove(struct pci_dev *dev) |
| 1883 | { |
| 1884 | struct fw_ohci *ohci; |
| 1885 | |
| 1886 | ohci = pci_get_drvdata(dev); |
Kristian Høgsberg | e254a4b | 2007-03-07 12:12:38 -0500 | [diff] [blame] | 1887 | reg_write(ohci, OHCI1394_IntMaskClear, ~0); |
| 1888 | flush_writes(ohci); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1889 | fw_core_remove_card(&ohci->card); |
| 1890 | |
Kristian Høgsberg | c781c06 | 2007-05-07 20:33:32 -0400 | [diff] [blame] | 1891 | /* |
| 1892 | * FIXME: Fail all pending packets here, now that the upper |
| 1893 | * layers can't queue any more. |
| 1894 | */ |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1895 | |
| 1896 | software_reset(ohci); |
| 1897 | free_irq(dev->irq, ohci); |
Kristian Høgsberg | d79406d | 2007-05-09 19:23:15 -0400 | [diff] [blame] | 1898 | dma_free_coherent(ohci->card.device, SELF_ID_BUF_SIZE, |
| 1899 | ohci->self_id_cpu, ohci->self_id_bus); |
| 1900 | kfree(ohci->it_context_list); |
| 1901 | kfree(ohci->ir_context_list); |
| 1902 | pci_iounmap(dev, ohci->registers); |
| 1903 | pci_release_region(dev, 0); |
| 1904 | pci_disable_device(dev); |
| 1905 | fw_card_put(&ohci->card); |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1906 | |
| 1907 | fw_notify("Removed fw-ohci device.\n"); |
| 1908 | } |
| 1909 | |
| 1910 | static struct pci_device_id pci_table[] = { |
| 1911 | { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_FIREWIRE_OHCI, ~0) }, |
| 1912 | { } |
| 1913 | }; |
| 1914 | |
| 1915 | MODULE_DEVICE_TABLE(pci, pci_table); |
| 1916 | |
| 1917 | static struct pci_driver fw_ohci_pci_driver = { |
| 1918 | .name = ohci_driver_name, |
| 1919 | .id_table = pci_table, |
| 1920 | .probe = pci_probe, |
| 1921 | .remove = pci_remove, |
| 1922 | }; |
| 1923 | |
| 1924 | MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>"); |
| 1925 | MODULE_DESCRIPTION("Driver for PCI OHCI IEEE1394 controllers"); |
| 1926 | MODULE_LICENSE("GPL"); |
| 1927 | |
Olaf Hering | 1e4c7b0 | 2007-05-05 23:17:13 +0200 | [diff] [blame] | 1928 | /* Provide a module alias so root-on-sbp2 initrds don't break. */ |
| 1929 | #ifndef CONFIG_IEEE1394_OHCI1394_MODULE |
| 1930 | MODULE_ALIAS("ohci1394"); |
| 1931 | #endif |
| 1932 | |
Kristian Høgsberg | ed56891 | 2006-12-19 19:58:35 -0500 | [diff] [blame] | 1933 | static int __init fw_ohci_init(void) |
| 1934 | { |
| 1935 | return pci_register_driver(&fw_ohci_pci_driver); |
| 1936 | } |
| 1937 | |
| 1938 | static void __exit fw_ohci_cleanup(void) |
| 1939 | { |
| 1940 | pci_unregister_driver(&fw_ohci_pci_driver); |
| 1941 | } |
| 1942 | |
| 1943 | module_init(fw_ohci_init); |
| 1944 | module_exit(fw_ohci_cleanup); |