1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Core IEEE1394 transaction logic 4 * 5 * Copyright (C) 2004-2006 Kristian Hoegsberg <krh@bitplanet.net> 6 */ 7 8 #include <linux/bug.h> 9 #include <linux/completion.h> 10 #include <linux/device.h> 11 #include <linux/errno.h> 12 #include <linux/firewire.h> 13 #include <linux/firewire-constants.h> 14 #include <linux/fs.h> 15 #include <linux/init.h> 16 #include <linux/idr.h> 17 #include <linux/jiffies.h> 18 #include <linux/kernel.h> 19 #include <linux/list.h> 20 #include <linux/module.h> 21 #include <linux/rculist.h> 22 #include <linux/slab.h> 23 #include <linux/spinlock.h> 24 #include <linux/string.h> 25 #include <linux/timer.h> 26 #include <linux/types.h> 27 #include <linux/workqueue.h> 28 29 #include <asm/byteorder.h> 30 31 #include "core.h" 32 #include <trace/events/firewire.h> 33 #include "packet-header-definitions.h" 34 35 #define HEADER_DESTINATION_IS_BROADCAST(header) \ 36 ((async_header_get_destination(header) & 0x3f) == 0x3f) 37 38 #define PHY_PACKET_CONFIG 0x0 39 #define PHY_PACKET_LINK_ON 0x1 40 #define PHY_PACKET_SELF_ID 0x2 41 42 #define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22)) 43 #define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23)) 44 #define PHY_IDENTIFIER(id) ((id) << 30) 45 46 /* returns 0 if the split timeout handler is already running */ 47 static int try_cancel_split_timeout(struct fw_transaction *t) 48 { 49 if (t->is_split_transaction) 50 return del_timer(&t->split_timeout_timer); 51 else 52 return 1; 53 } 54 55 static int close_transaction(struct fw_transaction *transaction, struct fw_card *card, int rcode, 56 u32 response_tstamp) 57 { 58 struct fw_transaction *t = NULL, *iter; 59 unsigned long flags; 60 61 spin_lock_irqsave(&card->lock, flags); 62 list_for_each_entry(iter, &card->transaction_list, link) { 63 if (iter == transaction) { 64 if (!try_cancel_split_timeout(iter)) { 65 spin_unlock_irqrestore(&card->lock, flags); 66 goto timed_out; 67 } 68 list_del_init(&iter->link); 69 card->tlabel_mask &= ~(1ULL << iter->tlabel); 70 t = iter; 71 break; 72 } 73 } 74 spin_unlock_irqrestore(&card->lock, flags); 75 76 if (t) { 77 if (!t->with_tstamp) { 78 t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data); 79 } else { 80 t->callback.with_tstamp(card, rcode, t->packet.timestamp, response_tstamp, 81 NULL, 0, t->callback_data); 82 } 83 return 0; 84 } 85 86 timed_out: 87 return -ENOENT; 88 } 89 90 /* 91 * Only valid for transactions that are potentially pending (ie have 92 * been sent). 93 */ 94 int fw_cancel_transaction(struct fw_card *card, 95 struct fw_transaction *transaction) 96 { 97 u32 tstamp; 98 99 /* 100 * Cancel the packet transmission if it's still queued. That 101 * will call the packet transmission callback which cancels 102 * the transaction. 103 */ 104 105 if (card->driver->cancel_packet(card, &transaction->packet) == 0) 106 return 0; 107 108 /* 109 * If the request packet has already been sent, we need to see 110 * if the transaction is still pending and remove it in that case. 111 */ 112 113 if (transaction->packet.ack == 0) { 114 // The timestamp is reused since it was just read now. 115 tstamp = transaction->packet.timestamp; 116 } else { 117 u32 curr_cycle_time = 0; 118 119 (void)fw_card_read_cycle_time(card, &curr_cycle_time); 120 tstamp = cycle_time_to_ohci_tstamp(curr_cycle_time); 121 } 122 123 return close_transaction(transaction, card, RCODE_CANCELLED, tstamp); 124 } 125 EXPORT_SYMBOL(fw_cancel_transaction); 126 127 static void split_transaction_timeout_callback(struct timer_list *timer) 128 { 129 struct fw_transaction *t = from_timer(t, timer, split_timeout_timer); 130 struct fw_card *card = t->card; 131 unsigned long flags; 132 133 spin_lock_irqsave(&card->lock, flags); 134 if (list_empty(&t->link)) { 135 spin_unlock_irqrestore(&card->lock, flags); 136 return; 137 } 138 list_del(&t->link); 139 card->tlabel_mask &= ~(1ULL << t->tlabel); 140 spin_unlock_irqrestore(&card->lock, flags); 141 142 if (!t->with_tstamp) { 143 t->callback.without_tstamp(card, RCODE_CANCELLED, NULL, 0, t->callback_data); 144 } else { 145 t->callback.with_tstamp(card, RCODE_CANCELLED, t->packet.timestamp, 146 t->split_timeout_cycle, NULL, 0, t->callback_data); 147 } 148 } 149 150 static void start_split_transaction_timeout(struct fw_transaction *t, 151 struct fw_card *card) 152 { 153 unsigned long flags; 154 155 spin_lock_irqsave(&card->lock, flags); 156 157 if (list_empty(&t->link) || WARN_ON(t->is_split_transaction)) { 158 spin_unlock_irqrestore(&card->lock, flags); 159 return; 160 } 161 162 t->is_split_transaction = true; 163 mod_timer(&t->split_timeout_timer, 164 jiffies + card->split_timeout_jiffies); 165 166 spin_unlock_irqrestore(&card->lock, flags); 167 } 168 169 static u32 compute_split_timeout_timestamp(struct fw_card *card, u32 request_timestamp); 170 171 static void transmit_complete_callback(struct fw_packet *packet, 172 struct fw_card *card, int status) 173 { 174 struct fw_transaction *t = 175 container_of(packet, struct fw_transaction, packet); 176 177 trace_async_request_outbound_complete((uintptr_t)t, packet->generation, packet->speed, 178 status, packet->timestamp); 179 180 switch (status) { 181 case ACK_COMPLETE: 182 close_transaction(t, card, RCODE_COMPLETE, packet->timestamp); 183 break; 184 case ACK_PENDING: 185 { 186 t->split_timeout_cycle = 187 compute_split_timeout_timestamp(card, packet->timestamp) & 0xffff; 188 start_split_transaction_timeout(t, card); 189 break; 190 } 191 case ACK_BUSY_X: 192 case ACK_BUSY_A: 193 case ACK_BUSY_B: 194 close_transaction(t, card, RCODE_BUSY, packet->timestamp); 195 break; 196 case ACK_DATA_ERROR: 197 close_transaction(t, card, RCODE_DATA_ERROR, packet->timestamp); 198 break; 199 case ACK_TYPE_ERROR: 200 close_transaction(t, card, RCODE_TYPE_ERROR, packet->timestamp); 201 break; 202 default: 203 /* 204 * In this case the ack is really a juju specific 205 * rcode, so just forward that to the callback. 206 */ 207 close_transaction(t, card, status, packet->timestamp); 208 break; 209 } 210 } 211 212 static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel, 213 int destination_id, int source_id, int generation, int speed, 214 unsigned long long offset, void *payload, size_t length) 215 { 216 int ext_tcode; 217 218 if (tcode == TCODE_STREAM_DATA) { 219 // The value of destination_id argument should include tag, channel, and sy fields 220 // as isochronous packet header has. 221 packet->header[0] = destination_id; 222 isoc_header_set_data_length(packet->header, length); 223 isoc_header_set_tcode(packet->header, TCODE_STREAM_DATA); 224 packet->header_length = 4; 225 packet->payload = payload; 226 packet->payload_length = length; 227 228 goto common; 229 } 230 231 if (tcode > 0x10) { 232 ext_tcode = tcode & ~0x10; 233 tcode = TCODE_LOCK_REQUEST; 234 } else 235 ext_tcode = 0; 236 237 async_header_set_retry(packet->header, RETRY_X); 238 async_header_set_tlabel(packet->header, tlabel); 239 async_header_set_tcode(packet->header, tcode); 240 async_header_set_destination(packet->header, destination_id); 241 async_header_set_source(packet->header, source_id); 242 async_header_set_offset(packet->header, offset); 243 244 switch (tcode) { 245 case TCODE_WRITE_QUADLET_REQUEST: 246 async_header_set_quadlet_data(packet->header, *(u32 *)payload); 247 packet->header_length = 16; 248 packet->payload_length = 0; 249 break; 250 251 case TCODE_LOCK_REQUEST: 252 case TCODE_WRITE_BLOCK_REQUEST: 253 async_header_set_data_length(packet->header, length); 254 async_header_set_extended_tcode(packet->header, ext_tcode); 255 packet->header_length = 16; 256 packet->payload = payload; 257 packet->payload_length = length; 258 break; 259 260 case TCODE_READ_QUADLET_REQUEST: 261 packet->header_length = 12; 262 packet->payload_length = 0; 263 break; 264 265 case TCODE_READ_BLOCK_REQUEST: 266 async_header_set_data_length(packet->header, length); 267 async_header_set_extended_tcode(packet->header, ext_tcode); 268 packet->header_length = 16; 269 packet->payload_length = 0; 270 break; 271 272 default: 273 WARN(1, "wrong tcode %d\n", tcode); 274 } 275 common: 276 packet->speed = speed; 277 packet->generation = generation; 278 packet->ack = 0; 279 packet->payload_mapped = false; 280 } 281 282 static int allocate_tlabel(struct fw_card *card) 283 { 284 int tlabel; 285 286 tlabel = card->current_tlabel; 287 while (card->tlabel_mask & (1ULL << tlabel)) { 288 tlabel = (tlabel + 1) & 0x3f; 289 if (tlabel == card->current_tlabel) 290 return -EBUSY; 291 } 292 293 card->current_tlabel = (tlabel + 1) & 0x3f; 294 card->tlabel_mask |= 1ULL << tlabel; 295 296 return tlabel; 297 } 298 299 /** 300 * __fw_send_request() - submit a request packet for transmission to generate callback for response 301 * subaction with or without time stamp. 302 * @card: interface to send the request at 303 * @t: transaction instance to which the request belongs 304 * @tcode: transaction code 305 * @destination_id: destination node ID, consisting of bus_ID and phy_ID 306 * @generation: bus generation in which request and response are valid 307 * @speed: transmission speed 308 * @offset: 48bit wide offset into destination's address space 309 * @payload: data payload for the request subaction 310 * @length: length of the payload, in bytes 311 * @callback: union of two functions whether to receive time stamp or not for response 312 * subaction. 313 * @with_tstamp: Whether to receive time stamp or not for response subaction. 314 * @callback_data: data to be passed to the transaction completion callback 315 * 316 * Submit a request packet into the asynchronous request transmission queue. 317 * Can be called from atomic context. If you prefer a blocking API, use 318 * fw_run_transaction() in a context that can sleep. 319 * 320 * In case of lock requests, specify one of the firewire-core specific %TCODE_ 321 * constants instead of %TCODE_LOCK_REQUEST in @tcode. 322 * 323 * Make sure that the value in @destination_id is not older than the one in 324 * @generation. Otherwise the request is in danger to be sent to a wrong node. 325 * 326 * In case of asynchronous stream packets i.e. %TCODE_STREAM_DATA, the caller 327 * needs to synthesize @destination_id with fw_stream_packet_destination_id(). 328 * It will contain tag, channel, and sy data instead of a node ID then. 329 * 330 * The payload buffer at @data is going to be DMA-mapped except in case of 331 * @length <= 8 or of local (loopback) requests. Hence make sure that the 332 * buffer complies with the restrictions of the streaming DMA mapping API. 333 * @payload must not be freed before the @callback is called. 334 * 335 * In case of request types without payload, @data is NULL and @length is 0. 336 * 337 * After the transaction is completed successfully or unsuccessfully, the 338 * @callback will be called. Among its parameters is the response code which 339 * is either one of the rcodes per IEEE 1394 or, in case of internal errors, 340 * the firewire-core specific %RCODE_SEND_ERROR. The other firewire-core 341 * specific rcodes (%RCODE_CANCELLED, %RCODE_BUSY, %RCODE_GENERATION, 342 * %RCODE_NO_ACK) denote transaction timeout, busy responder, stale request 343 * generation, or missing ACK respectively. 344 * 345 * Note some timing corner cases: fw_send_request() may complete much earlier 346 * than when the request packet actually hits the wire. On the other hand, 347 * transaction completion and hence execution of @callback may happen even 348 * before fw_send_request() returns. 349 */ 350 void __fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, 351 int destination_id, int generation, int speed, unsigned long long offset, 352 void *payload, size_t length, union fw_transaction_callback callback, 353 bool with_tstamp, void *callback_data) 354 { 355 unsigned long flags; 356 int tlabel; 357 358 /* 359 * Allocate tlabel from the bitmap and put the transaction on 360 * the list while holding the card spinlock. 361 */ 362 363 spin_lock_irqsave(&card->lock, flags); 364 365 tlabel = allocate_tlabel(card); 366 if (tlabel < 0) { 367 spin_unlock_irqrestore(&card->lock, flags); 368 if (!with_tstamp) { 369 callback.without_tstamp(card, RCODE_SEND_ERROR, NULL, 0, callback_data); 370 } else { 371 // Timestamping on behalf of hardware. 372 u32 curr_cycle_time = 0; 373 u32 tstamp; 374 375 (void)fw_card_read_cycle_time(card, &curr_cycle_time); 376 tstamp = cycle_time_to_ohci_tstamp(curr_cycle_time); 377 378 callback.with_tstamp(card, RCODE_SEND_ERROR, tstamp, tstamp, NULL, 0, 379 callback_data); 380 } 381 return; 382 } 383 384 t->node_id = destination_id; 385 t->tlabel = tlabel; 386 t->card = card; 387 t->is_split_transaction = false; 388 timer_setup(&t->split_timeout_timer, split_transaction_timeout_callback, 0); 389 t->callback = callback; 390 t->with_tstamp = with_tstamp; 391 t->callback_data = callback_data; 392 393 fw_fill_request(&t->packet, tcode, t->tlabel, destination_id, card->node_id, generation, 394 speed, offset, payload, length); 395 t->packet.callback = transmit_complete_callback; 396 397 list_add_tail(&t->link, &card->transaction_list); 398 399 spin_unlock_irqrestore(&card->lock, flags); 400 401 trace_async_request_outbound_initiate((uintptr_t)t, generation, speed, t->packet.header, payload, 402 tcode_is_read_request(tcode) ? 0 : length / 4); 403 404 card->driver->send_request(card, &t->packet); 405 } 406 EXPORT_SYMBOL_GPL(__fw_send_request); 407 408 struct transaction_callback_data { 409 struct completion done; 410 void *payload; 411 int rcode; 412 }; 413 414 static void transaction_callback(struct fw_card *card, int rcode, 415 void *payload, size_t length, void *data) 416 { 417 struct transaction_callback_data *d = data; 418 419 if (rcode == RCODE_COMPLETE) 420 memcpy(d->payload, payload, length); 421 d->rcode = rcode; 422 complete(&d->done); 423 } 424 425 /** 426 * fw_run_transaction() - send request and sleep until transaction is completed 427 * @card: card interface for this request 428 * @tcode: transaction code 429 * @destination_id: destination node ID, consisting of bus_ID and phy_ID 430 * @generation: bus generation in which request and response are valid 431 * @speed: transmission speed 432 * @offset: 48bit wide offset into destination's address space 433 * @payload: data payload for the request subaction 434 * @length: length of the payload, in bytes 435 * 436 * Returns the RCODE. See fw_send_request() for parameter documentation. 437 * Unlike fw_send_request(), @data points to the payload of the request or/and 438 * to the payload of the response. DMA mapping restrictions apply to outbound 439 * request payloads of >= 8 bytes but not to inbound response payloads. 440 */ 441 int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, 442 int generation, int speed, unsigned long long offset, 443 void *payload, size_t length) 444 { 445 struct transaction_callback_data d; 446 struct fw_transaction t; 447 448 timer_setup_on_stack(&t.split_timeout_timer, NULL, 0); 449 init_completion(&d.done); 450 d.payload = payload; 451 fw_send_request(card, &t, tcode, destination_id, generation, speed, 452 offset, payload, length, transaction_callback, &d); 453 wait_for_completion(&d.done); 454 destroy_timer_on_stack(&t.split_timeout_timer); 455 456 return d.rcode; 457 } 458 EXPORT_SYMBOL(fw_run_transaction); 459 460 static DEFINE_MUTEX(phy_config_mutex); 461 static DECLARE_COMPLETION(phy_config_done); 462 463 static void transmit_phy_packet_callback(struct fw_packet *packet, 464 struct fw_card *card, int status) 465 { 466 trace_async_phy_outbound_complete((uintptr_t)packet, packet->generation, status, 467 packet->timestamp); 468 complete(&phy_config_done); 469 } 470 471 static struct fw_packet phy_config_packet = { 472 .header_length = 12, 473 .header[0] = TCODE_LINK_INTERNAL << 4, 474 .payload_length = 0, 475 .speed = SCODE_100, 476 .callback = transmit_phy_packet_callback, 477 }; 478 479 void fw_send_phy_config(struct fw_card *card, 480 int node_id, int generation, int gap_count) 481 { 482 long timeout = DIV_ROUND_UP(HZ, 10); 483 u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG); 484 485 if (node_id != FW_PHY_CONFIG_NO_NODE_ID) 486 data |= PHY_CONFIG_ROOT_ID(node_id); 487 488 if (gap_count == FW_PHY_CONFIG_CURRENT_GAP_COUNT) { 489 gap_count = card->driver->read_phy_reg(card, 1); 490 if (gap_count < 0) 491 return; 492 493 gap_count &= 63; 494 if (gap_count == 63) 495 return; 496 } 497 data |= PHY_CONFIG_GAP_COUNT(gap_count); 498 499 mutex_lock(&phy_config_mutex); 500 501 phy_config_packet.header[1] = data; 502 phy_config_packet.header[2] = ~data; 503 phy_config_packet.generation = generation; 504 reinit_completion(&phy_config_done); 505 506 trace_async_phy_outbound_initiate((uintptr_t)&phy_config_packet, 507 phy_config_packet.generation, phy_config_packet.header[1], 508 phy_config_packet.header[2]); 509 510 card->driver->send_request(card, &phy_config_packet); 511 wait_for_completion_timeout(&phy_config_done, timeout); 512 513 mutex_unlock(&phy_config_mutex); 514 } 515 516 static struct fw_address_handler *lookup_overlapping_address_handler( 517 struct list_head *list, unsigned long long offset, size_t length) 518 { 519 struct fw_address_handler *handler; 520 521 list_for_each_entry_rcu(handler, list, link) { 522 if (handler->offset < offset + length && 523 offset < handler->offset + handler->length) 524 return handler; 525 } 526 527 return NULL; 528 } 529 530 static bool is_enclosing_handler(struct fw_address_handler *handler, 531 unsigned long long offset, size_t length) 532 { 533 return handler->offset <= offset && 534 offset + length <= handler->offset + handler->length; 535 } 536 537 static struct fw_address_handler *lookup_enclosing_address_handler( 538 struct list_head *list, unsigned long long offset, size_t length) 539 { 540 struct fw_address_handler *handler; 541 542 list_for_each_entry_rcu(handler, list, link) { 543 if (is_enclosing_handler(handler, offset, length)) 544 return handler; 545 } 546 547 return NULL; 548 } 549 550 static DEFINE_SPINLOCK(address_handler_list_lock); 551 static LIST_HEAD(address_handler_list); 552 553 const struct fw_address_region fw_high_memory_region = 554 { .start = FW_MAX_PHYSICAL_RANGE, .end = 0xffffe0000000ULL, }; 555 EXPORT_SYMBOL(fw_high_memory_region); 556 557 static const struct fw_address_region low_memory_region = 558 { .start = 0x000000000000ULL, .end = FW_MAX_PHYSICAL_RANGE, }; 559 560 #if 0 561 const struct fw_address_region fw_private_region = 562 { .start = 0xffffe0000000ULL, .end = 0xfffff0000000ULL, }; 563 const struct fw_address_region fw_csr_region = 564 { .start = CSR_REGISTER_BASE, 565 .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM_END, }; 566 const struct fw_address_region fw_unit_space_region = 567 { .start = 0xfffff0000900ULL, .end = 0x1000000000000ULL, }; 568 #endif /* 0 */ 569 570 /** 571 * fw_core_add_address_handler() - register for incoming requests 572 * @handler: callback 573 * @region: region in the IEEE 1212 node space address range 574 * 575 * region->start, ->end, and handler->length have to be quadlet-aligned. 576 * 577 * When a request is received that falls within the specified address range, 578 * the specified callback is invoked. The parameters passed to the callback 579 * give the details of the particular request. 580 * 581 * To be called in process context. 582 * Return value: 0 on success, non-zero otherwise. 583 * 584 * The start offset of the handler's address region is determined by 585 * fw_core_add_address_handler() and is returned in handler->offset. 586 * 587 * Address allocations are exclusive, except for the FCP registers. 588 */ 589 int fw_core_add_address_handler(struct fw_address_handler *handler, 590 const struct fw_address_region *region) 591 { 592 struct fw_address_handler *other; 593 int ret = -EBUSY; 594 595 if (region->start & 0xffff000000000003ULL || 596 region->start >= region->end || 597 region->end > 0x0001000000000000ULL || 598 handler->length & 3 || 599 handler->length == 0) 600 return -EINVAL; 601 602 spin_lock(&address_handler_list_lock); 603 604 handler->offset = region->start; 605 while (handler->offset + handler->length <= region->end) { 606 if (is_in_fcp_region(handler->offset, handler->length)) 607 other = NULL; 608 else 609 other = lookup_overlapping_address_handler 610 (&address_handler_list, 611 handler->offset, handler->length); 612 if (other != NULL) { 613 handler->offset += other->length; 614 } else { 615 list_add_tail_rcu(&handler->link, &address_handler_list); 616 ret = 0; 617 break; 618 } 619 } 620 621 spin_unlock(&address_handler_list_lock); 622 623 return ret; 624 } 625 EXPORT_SYMBOL(fw_core_add_address_handler); 626 627 /** 628 * fw_core_remove_address_handler() - unregister an address handler 629 * @handler: callback 630 * 631 * To be called in process context. 632 * 633 * When fw_core_remove_address_handler() returns, @handler->callback() is 634 * guaranteed to not run on any CPU anymore. 635 */ 636 void fw_core_remove_address_handler(struct fw_address_handler *handler) 637 { 638 spin_lock(&address_handler_list_lock); 639 list_del_rcu(&handler->link); 640 spin_unlock(&address_handler_list_lock); 641 synchronize_rcu(); 642 } 643 EXPORT_SYMBOL(fw_core_remove_address_handler); 644 645 struct fw_request { 646 struct kref kref; 647 struct fw_packet response; 648 u32 request_header[ASYNC_HEADER_QUADLET_COUNT]; 649 int ack; 650 u32 timestamp; 651 u32 length; 652 u32 data[]; 653 }; 654 655 void fw_request_get(struct fw_request *request) 656 { 657 kref_get(&request->kref); 658 } 659 660 static void release_request(struct kref *kref) 661 { 662 struct fw_request *request = container_of(kref, struct fw_request, kref); 663 664 kfree(request); 665 } 666 667 void fw_request_put(struct fw_request *request) 668 { 669 kref_put(&request->kref, release_request); 670 } 671 672 static void free_response_callback(struct fw_packet *packet, 673 struct fw_card *card, int status) 674 { 675 struct fw_request *request = container_of(packet, struct fw_request, response); 676 677 trace_async_response_outbound_complete((uintptr_t)request, packet->generation, 678 packet->speed, status, packet->timestamp); 679 680 // Decrease the reference count since not at in-flight. 681 fw_request_put(request); 682 683 // Decrease the reference count to release the object. 684 fw_request_put(request); 685 } 686 687 int fw_get_response_length(struct fw_request *r) 688 { 689 int tcode, ext_tcode, data_length; 690 691 tcode = async_header_get_tcode(r->request_header); 692 693 switch (tcode) { 694 case TCODE_WRITE_QUADLET_REQUEST: 695 case TCODE_WRITE_BLOCK_REQUEST: 696 return 0; 697 698 case TCODE_READ_QUADLET_REQUEST: 699 return 4; 700 701 case TCODE_READ_BLOCK_REQUEST: 702 data_length = async_header_get_data_length(r->request_header); 703 return data_length; 704 705 case TCODE_LOCK_REQUEST: 706 ext_tcode = async_header_get_extended_tcode(r->request_header); 707 data_length = async_header_get_data_length(r->request_header); 708 switch (ext_tcode) { 709 case EXTCODE_FETCH_ADD: 710 case EXTCODE_LITTLE_ADD: 711 return data_length; 712 default: 713 return data_length / 2; 714 } 715 716 default: 717 WARN(1, "wrong tcode %d\n", tcode); 718 return 0; 719 } 720 } 721 722 void fw_fill_response(struct fw_packet *response, u32 *request_header, 723 int rcode, void *payload, size_t length) 724 { 725 int tcode, tlabel, extended_tcode, source, destination; 726 727 tcode = async_header_get_tcode(request_header); 728 tlabel = async_header_get_tlabel(request_header); 729 source = async_header_get_destination(request_header); // Exchange. 730 destination = async_header_get_source(request_header); // Exchange. 731 extended_tcode = async_header_get_extended_tcode(request_header); 732 733 async_header_set_retry(response->header, RETRY_1); 734 async_header_set_tlabel(response->header, tlabel); 735 async_header_set_destination(response->header, destination); 736 async_header_set_source(response->header, source); 737 async_header_set_rcode(response->header, rcode); 738 response->header[2] = 0; // The field is reserved. 739 740 switch (tcode) { 741 case TCODE_WRITE_QUADLET_REQUEST: 742 case TCODE_WRITE_BLOCK_REQUEST: 743 async_header_set_tcode(response->header, TCODE_WRITE_RESPONSE); 744 response->header_length = 12; 745 response->payload_length = 0; 746 break; 747 748 case TCODE_READ_QUADLET_REQUEST: 749 async_header_set_tcode(response->header, TCODE_READ_QUADLET_RESPONSE); 750 if (payload != NULL) 751 async_header_set_quadlet_data(response->header, *(u32 *)payload); 752 else 753 async_header_set_quadlet_data(response->header, 0); 754 response->header_length = 16; 755 response->payload_length = 0; 756 break; 757 758 case TCODE_READ_BLOCK_REQUEST: 759 case TCODE_LOCK_REQUEST: 760 async_header_set_tcode(response->header, tcode + 2); 761 async_header_set_data_length(response->header, length); 762 async_header_set_extended_tcode(response->header, extended_tcode); 763 response->header_length = 16; 764 response->payload = payload; 765 response->payload_length = length; 766 break; 767 768 default: 769 WARN(1, "wrong tcode %d\n", tcode); 770 } 771 772 response->payload_mapped = false; 773 } 774 EXPORT_SYMBOL(fw_fill_response); 775 776 static u32 compute_split_timeout_timestamp(struct fw_card *card, 777 u32 request_timestamp) 778 { 779 unsigned int cycles; 780 u32 timestamp; 781 782 cycles = card->split_timeout_cycles; 783 cycles += request_timestamp & 0x1fff; 784 785 timestamp = request_timestamp & ~0x1fff; 786 timestamp += (cycles / 8000) << 13; 787 timestamp |= cycles % 8000; 788 789 return timestamp; 790 } 791 792 static struct fw_request *allocate_request(struct fw_card *card, 793 struct fw_packet *p) 794 { 795 struct fw_request *request; 796 u32 *data, length; 797 int request_tcode; 798 799 request_tcode = async_header_get_tcode(p->header); 800 switch (request_tcode) { 801 case TCODE_WRITE_QUADLET_REQUEST: 802 data = &p->header[3]; 803 length = 4; 804 break; 805 806 case TCODE_WRITE_BLOCK_REQUEST: 807 case TCODE_LOCK_REQUEST: 808 data = p->payload; 809 length = async_header_get_data_length(p->header); 810 break; 811 812 case TCODE_READ_QUADLET_REQUEST: 813 data = NULL; 814 length = 4; 815 break; 816 817 case TCODE_READ_BLOCK_REQUEST: 818 data = NULL; 819 length = async_header_get_data_length(p->header); 820 break; 821 822 default: 823 fw_notice(card, "ERROR - corrupt request received - %08x %08x %08x\n", 824 p->header[0], p->header[1], p->header[2]); 825 return NULL; 826 } 827 828 request = kmalloc(sizeof(*request) + length, GFP_ATOMIC); 829 if (request == NULL) 830 return NULL; 831 kref_init(&request->kref); 832 833 request->response.speed = p->speed; 834 request->response.timestamp = 835 compute_split_timeout_timestamp(card, p->timestamp); 836 request->response.generation = p->generation; 837 request->response.ack = 0; 838 request->response.callback = free_response_callback; 839 request->ack = p->ack; 840 request->timestamp = p->timestamp; 841 request->length = length; 842 if (data) 843 memcpy(request->data, data, length); 844 845 memcpy(request->request_header, p->header, sizeof(p->header)); 846 847 return request; 848 } 849 850 /** 851 * fw_send_response: - send response packet for asynchronous transaction. 852 * @card: interface to send the response at. 853 * @request: firewire request data for the transaction. 854 * @rcode: response code to send. 855 * 856 * Submit a response packet into the asynchronous response transmission queue. The @request 857 * is going to be released when the transmission successfully finishes later. 858 */ 859 void fw_send_response(struct fw_card *card, 860 struct fw_request *request, int rcode) 861 { 862 u32 *data = NULL; 863 unsigned int data_length = 0; 864 865 /* unified transaction or broadcast transaction: don't respond */ 866 if (request->ack != ACK_PENDING || 867 HEADER_DESTINATION_IS_BROADCAST(request->request_header)) { 868 fw_request_put(request); 869 return; 870 } 871 872 if (rcode == RCODE_COMPLETE) { 873 data = request->data; 874 data_length = fw_get_response_length(request); 875 } 876 877 fw_fill_response(&request->response, request->request_header, rcode, data, data_length); 878 879 // Increase the reference count so that the object is kept during in-flight. 880 fw_request_get(request); 881 882 trace_async_response_outbound_initiate((uintptr_t)request, request->response.generation, 883 request->response.speed, request->response.header, 884 data, data ? data_length / 4 : 0); 885 886 card->driver->send_response(card, &request->response); 887 } 888 EXPORT_SYMBOL(fw_send_response); 889 890 /** 891 * fw_get_request_speed() - returns speed at which the @request was received 892 * @request: firewire request data 893 */ 894 int fw_get_request_speed(struct fw_request *request) 895 { 896 return request->response.speed; 897 } 898 EXPORT_SYMBOL(fw_get_request_speed); 899 900 /** 901 * fw_request_get_timestamp: Get timestamp of the request. 902 * @request: The opaque pointer to request structure. 903 * 904 * Get timestamp when 1394 OHCI controller receives the asynchronous request subaction. The 905 * timestamp consists of the low order 3 bits of second field and the full 13 bits of count 906 * field of isochronous cycle time register. 907 * 908 * Returns: timestamp of the request. 909 */ 910 u32 fw_request_get_timestamp(const struct fw_request *request) 911 { 912 return request->timestamp; 913 } 914 EXPORT_SYMBOL_GPL(fw_request_get_timestamp); 915 916 static void handle_exclusive_region_request(struct fw_card *card, 917 struct fw_packet *p, 918 struct fw_request *request, 919 unsigned long long offset) 920 { 921 struct fw_address_handler *handler; 922 int tcode, destination, source; 923 924 destination = async_header_get_destination(p->header); 925 source = async_header_get_source(p->header); 926 tcode = async_header_get_tcode(p->header); 927 if (tcode == TCODE_LOCK_REQUEST) 928 tcode = 0x10 + async_header_get_extended_tcode(p->header); 929 930 rcu_read_lock(); 931 handler = lookup_enclosing_address_handler(&address_handler_list, 932 offset, request->length); 933 if (handler) 934 handler->address_callback(card, request, 935 tcode, destination, source, 936 p->generation, offset, 937 request->data, request->length, 938 handler->callback_data); 939 rcu_read_unlock(); 940 941 if (!handler) 942 fw_send_response(card, request, RCODE_ADDRESS_ERROR); 943 } 944 945 static void handle_fcp_region_request(struct fw_card *card, 946 struct fw_packet *p, 947 struct fw_request *request, 948 unsigned long long offset) 949 { 950 struct fw_address_handler *handler; 951 int tcode, destination, source; 952 953 if ((offset != (CSR_REGISTER_BASE | CSR_FCP_COMMAND) && 954 offset != (CSR_REGISTER_BASE | CSR_FCP_RESPONSE)) || 955 request->length > 0x200) { 956 fw_send_response(card, request, RCODE_ADDRESS_ERROR); 957 958 return; 959 } 960 961 tcode = async_header_get_tcode(p->header); 962 destination = async_header_get_destination(p->header); 963 source = async_header_get_source(p->header); 964 965 if (tcode != TCODE_WRITE_QUADLET_REQUEST && 966 tcode != TCODE_WRITE_BLOCK_REQUEST) { 967 fw_send_response(card, request, RCODE_TYPE_ERROR); 968 969 return; 970 } 971 972 rcu_read_lock(); 973 list_for_each_entry_rcu(handler, &address_handler_list, link) { 974 if (is_enclosing_handler(handler, offset, request->length)) 975 handler->address_callback(card, request, tcode, 976 destination, source, 977 p->generation, offset, 978 request->data, 979 request->length, 980 handler->callback_data); 981 } 982 rcu_read_unlock(); 983 984 fw_send_response(card, request, RCODE_COMPLETE); 985 } 986 987 void fw_core_handle_request(struct fw_card *card, struct fw_packet *p) 988 { 989 struct fw_request *request; 990 unsigned long long offset; 991 unsigned int tcode; 992 993 if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE) 994 return; 995 996 tcode = async_header_get_tcode(p->header); 997 if (tcode_is_link_internal(tcode)) { 998 trace_async_phy_inbound((uintptr_t)p, p->generation, p->ack, p->timestamp, 999 p->header[1], p->header[2]); 1000 fw_cdev_handle_phy_packet(card, p); 1001 return; 1002 } 1003 1004 request = allocate_request(card, p); 1005 if (request == NULL) { 1006 /* FIXME: send statically allocated busy packet. */ 1007 return; 1008 } 1009 1010 trace_async_request_inbound((uintptr_t)request, p->generation, p->speed, p->ack, 1011 p->timestamp, p->header, request->data, 1012 tcode_is_read_request(tcode) ? 0 : request->length / 4); 1013 1014 offset = async_header_get_offset(p->header); 1015 1016 if (!is_in_fcp_region(offset, request->length)) 1017 handle_exclusive_region_request(card, p, request, offset); 1018 else 1019 handle_fcp_region_request(card, p, request, offset); 1020 1021 } 1022 EXPORT_SYMBOL(fw_core_handle_request); 1023 1024 void fw_core_handle_response(struct fw_card *card, struct fw_packet *p) 1025 { 1026 struct fw_transaction *t = NULL, *iter; 1027 unsigned long flags; 1028 u32 *data; 1029 size_t data_length; 1030 int tcode, tlabel, source, rcode; 1031 1032 tcode = async_header_get_tcode(p->header); 1033 tlabel = async_header_get_tlabel(p->header); 1034 source = async_header_get_source(p->header); 1035 rcode = async_header_get_rcode(p->header); 1036 1037 // FIXME: sanity check packet, is length correct, does tcodes 1038 // and addresses match to the transaction request queried later. 1039 // 1040 // For the tracepoints event, let us decode the header here against the concern. 1041 1042 switch (tcode) { 1043 case TCODE_READ_QUADLET_RESPONSE: 1044 data = (u32 *) &p->header[3]; 1045 data_length = 4; 1046 break; 1047 1048 case TCODE_WRITE_RESPONSE: 1049 data = NULL; 1050 data_length = 0; 1051 break; 1052 1053 case TCODE_READ_BLOCK_RESPONSE: 1054 case TCODE_LOCK_RESPONSE: 1055 data = p->payload; 1056 data_length = async_header_get_data_length(p->header); 1057 break; 1058 1059 default: 1060 /* Should never happen, this is just to shut up gcc. */ 1061 data = NULL; 1062 data_length = 0; 1063 break; 1064 } 1065 1066 spin_lock_irqsave(&card->lock, flags); 1067 list_for_each_entry(iter, &card->transaction_list, link) { 1068 if (iter->node_id == source && iter->tlabel == tlabel) { 1069 if (!try_cancel_split_timeout(iter)) { 1070 spin_unlock_irqrestore(&card->lock, flags); 1071 goto timed_out; 1072 } 1073 list_del_init(&iter->link); 1074 card->tlabel_mask &= ~(1ULL << iter->tlabel); 1075 t = iter; 1076 break; 1077 } 1078 } 1079 spin_unlock_irqrestore(&card->lock, flags); 1080 1081 trace_async_response_inbound((uintptr_t)t, p->generation, p->speed, p->ack, p->timestamp, 1082 p->header, data, data_length / 4); 1083 1084 if (!t) { 1085 timed_out: 1086 fw_notice(card, "unsolicited response (source %x, tlabel %x)\n", 1087 source, tlabel); 1088 return; 1089 } 1090 1091 /* 1092 * The response handler may be executed while the request handler 1093 * is still pending. Cancel the request handler. 1094 */ 1095 card->driver->cancel_packet(card, &t->packet); 1096 1097 if (!t->with_tstamp) { 1098 t->callback.without_tstamp(card, rcode, data, data_length, t->callback_data); 1099 } else { 1100 t->callback.with_tstamp(card, rcode, t->packet.timestamp, p->timestamp, data, 1101 data_length, t->callback_data); 1102 } 1103 } 1104 EXPORT_SYMBOL(fw_core_handle_response); 1105 1106 /** 1107 * fw_rcode_string - convert a firewire result code to an error description 1108 * @rcode: the result code 1109 */ 1110 const char *fw_rcode_string(int rcode) 1111 { 1112 static const char *const names[] = { 1113 [RCODE_COMPLETE] = "no error", 1114 [RCODE_CONFLICT_ERROR] = "conflict error", 1115 [RCODE_DATA_ERROR] = "data error", 1116 [RCODE_TYPE_ERROR] = "type error", 1117 [RCODE_ADDRESS_ERROR] = "address error", 1118 [RCODE_SEND_ERROR] = "send error", 1119 [RCODE_CANCELLED] = "timeout", 1120 [RCODE_BUSY] = "busy", 1121 [RCODE_GENERATION] = "bus reset", 1122 [RCODE_NO_ACK] = "no ack", 1123 }; 1124 1125 if ((unsigned int)rcode < ARRAY_SIZE(names) && names[rcode]) 1126 return names[rcode]; 1127 else 1128 return "unknown"; 1129 } 1130 EXPORT_SYMBOL(fw_rcode_string); 1131 1132 static const struct fw_address_region topology_map_region = 1133 { .start = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP, 1134 .end = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP_END, }; 1135 1136 static void handle_topology_map(struct fw_card *card, struct fw_request *request, 1137 int tcode, int destination, int source, int generation, 1138 unsigned long long offset, void *payload, size_t length, 1139 void *callback_data) 1140 { 1141 int start; 1142 1143 if (!tcode_is_read_request(tcode)) { 1144 fw_send_response(card, request, RCODE_TYPE_ERROR); 1145 return; 1146 } 1147 1148 if ((offset & 3) > 0 || (length & 3) > 0) { 1149 fw_send_response(card, request, RCODE_ADDRESS_ERROR); 1150 return; 1151 } 1152 1153 start = (offset - topology_map_region.start) / 4; 1154 memcpy(payload, &card->topology_map[start], length); 1155 1156 fw_send_response(card, request, RCODE_COMPLETE); 1157 } 1158 1159 static struct fw_address_handler topology_map = { 1160 .length = 0x400, 1161 .address_callback = handle_topology_map, 1162 }; 1163 1164 static const struct fw_address_region registers_region = 1165 { .start = CSR_REGISTER_BASE, 1166 .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, }; 1167 1168 static void update_split_timeout(struct fw_card *card) 1169 { 1170 unsigned int cycles; 1171 1172 cycles = card->split_timeout_hi * 8000 + (card->split_timeout_lo >> 19); 1173 1174 /* minimum per IEEE 1394, maximum which doesn't overflow OHCI */ 1175 cycles = clamp(cycles, 800u, 3u * 8000u); 1176 1177 card->split_timeout_cycles = cycles; 1178 card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000); 1179 } 1180 1181 static void handle_registers(struct fw_card *card, struct fw_request *request, 1182 int tcode, int destination, int source, int generation, 1183 unsigned long long offset, void *payload, size_t length, 1184 void *callback_data) 1185 { 1186 int reg = offset & ~CSR_REGISTER_BASE; 1187 __be32 *data = payload; 1188 int rcode = RCODE_COMPLETE; 1189 unsigned long flags; 1190 1191 switch (reg) { 1192 case CSR_PRIORITY_BUDGET: 1193 if (!card->priority_budget_implemented) { 1194 rcode = RCODE_ADDRESS_ERROR; 1195 break; 1196 } 1197 fallthrough; 1198 1199 case CSR_NODE_IDS: 1200 /* 1201 * per IEEE 1394-2008 8.3.22.3, not IEEE 1394.1-2004 3.2.8 1202 * and 9.6, but interoperable with IEEE 1394.1-2004 bridges 1203 */ 1204 fallthrough; 1205 1206 case CSR_STATE_CLEAR: 1207 case CSR_STATE_SET: 1208 case CSR_CYCLE_TIME: 1209 case CSR_BUS_TIME: 1210 case CSR_BUSY_TIMEOUT: 1211 if (tcode == TCODE_READ_QUADLET_REQUEST) 1212 *data = cpu_to_be32(card->driver->read_csr(card, reg)); 1213 else if (tcode == TCODE_WRITE_QUADLET_REQUEST) 1214 card->driver->write_csr(card, reg, be32_to_cpu(*data)); 1215 else 1216 rcode = RCODE_TYPE_ERROR; 1217 break; 1218 1219 case CSR_RESET_START: 1220 if (tcode == TCODE_WRITE_QUADLET_REQUEST) 1221 card->driver->write_csr(card, CSR_STATE_CLEAR, 1222 CSR_STATE_BIT_ABDICATE); 1223 else 1224 rcode = RCODE_TYPE_ERROR; 1225 break; 1226 1227 case CSR_SPLIT_TIMEOUT_HI: 1228 if (tcode == TCODE_READ_QUADLET_REQUEST) { 1229 *data = cpu_to_be32(card->split_timeout_hi); 1230 } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) { 1231 spin_lock_irqsave(&card->lock, flags); 1232 card->split_timeout_hi = be32_to_cpu(*data) & 7; 1233 update_split_timeout(card); 1234 spin_unlock_irqrestore(&card->lock, flags); 1235 } else { 1236 rcode = RCODE_TYPE_ERROR; 1237 } 1238 break; 1239 1240 case CSR_SPLIT_TIMEOUT_LO: 1241 if (tcode == TCODE_READ_QUADLET_REQUEST) { 1242 *data = cpu_to_be32(card->split_timeout_lo); 1243 } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) { 1244 spin_lock_irqsave(&card->lock, flags); 1245 card->split_timeout_lo = 1246 be32_to_cpu(*data) & 0xfff80000; 1247 update_split_timeout(card); 1248 spin_unlock_irqrestore(&card->lock, flags); 1249 } else { 1250 rcode = RCODE_TYPE_ERROR; 1251 } 1252 break; 1253 1254 case CSR_MAINT_UTILITY: 1255 if (tcode == TCODE_READ_QUADLET_REQUEST) 1256 *data = card->maint_utility_register; 1257 else if (tcode == TCODE_WRITE_QUADLET_REQUEST) 1258 card->maint_utility_register = *data; 1259 else 1260 rcode = RCODE_TYPE_ERROR; 1261 break; 1262 1263 case CSR_BROADCAST_CHANNEL: 1264 if (tcode == TCODE_READ_QUADLET_REQUEST) 1265 *data = cpu_to_be32(card->broadcast_channel); 1266 else if (tcode == TCODE_WRITE_QUADLET_REQUEST) 1267 card->broadcast_channel = 1268 (be32_to_cpu(*data) & BROADCAST_CHANNEL_VALID) | 1269 BROADCAST_CHANNEL_INITIAL; 1270 else 1271 rcode = RCODE_TYPE_ERROR; 1272 break; 1273 1274 case CSR_BUS_MANAGER_ID: 1275 case CSR_BANDWIDTH_AVAILABLE: 1276 case CSR_CHANNELS_AVAILABLE_HI: 1277 case CSR_CHANNELS_AVAILABLE_LO: 1278 /* 1279 * FIXME: these are handled by the OHCI hardware and 1280 * the stack never sees these request. If we add 1281 * support for a new type of controller that doesn't 1282 * handle this in hardware we need to deal with these 1283 * transactions. 1284 */ 1285 BUG(); 1286 break; 1287 1288 default: 1289 rcode = RCODE_ADDRESS_ERROR; 1290 break; 1291 } 1292 1293 fw_send_response(card, request, rcode); 1294 } 1295 1296 static struct fw_address_handler registers = { 1297 .length = 0x400, 1298 .address_callback = handle_registers, 1299 }; 1300 1301 static void handle_low_memory(struct fw_card *card, struct fw_request *request, 1302 int tcode, int destination, int source, int generation, 1303 unsigned long long offset, void *payload, size_t length, 1304 void *callback_data) 1305 { 1306 /* 1307 * This catches requests not handled by the physical DMA unit, 1308 * i.e., wrong transaction types or unauthorized source nodes. 1309 */ 1310 fw_send_response(card, request, RCODE_TYPE_ERROR); 1311 } 1312 1313 static struct fw_address_handler low_memory = { 1314 .length = FW_MAX_PHYSICAL_RANGE, 1315 .address_callback = handle_low_memory, 1316 }; 1317 1318 MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>"); 1319 MODULE_DESCRIPTION("Core IEEE1394 transaction logic"); 1320 MODULE_LICENSE("GPL"); 1321 1322 static const u32 vendor_textual_descriptor[] = { 1323 /* textual descriptor leaf () */ 1324 0x00060000, 1325 0x00000000, 1326 0x00000000, 1327 0x4c696e75, /* L i n u */ 1328 0x78204669, /* x F i */ 1329 0x72657769, /* r e w i */ 1330 0x72650000, /* r e */ 1331 }; 1332 1333 static const u32 model_textual_descriptor[] = { 1334 /* model descriptor leaf () */ 1335 0x00030000, 1336 0x00000000, 1337 0x00000000, 1338 0x4a756a75, /* J u j u */ 1339 }; 1340 1341 static struct fw_descriptor vendor_id_descriptor = { 1342 .length = ARRAY_SIZE(vendor_textual_descriptor), 1343 .immediate = 0x03001f11, 1344 .key = 0x81000000, 1345 .data = vendor_textual_descriptor, 1346 }; 1347 1348 static struct fw_descriptor model_id_descriptor = { 1349 .length = ARRAY_SIZE(model_textual_descriptor), 1350 .immediate = 0x17023901, 1351 .key = 0x81000000, 1352 .data = model_textual_descriptor, 1353 }; 1354 1355 static int __init fw_core_init(void) 1356 { 1357 int ret; 1358 1359 fw_workqueue = alloc_workqueue("firewire", WQ_MEM_RECLAIM, 0); 1360 if (!fw_workqueue) 1361 return -ENOMEM; 1362 1363 ret = bus_register(&fw_bus_type); 1364 if (ret < 0) { 1365 destroy_workqueue(fw_workqueue); 1366 return ret; 1367 } 1368 1369 fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops); 1370 if (fw_cdev_major < 0) { 1371 bus_unregister(&fw_bus_type); 1372 destroy_workqueue(fw_workqueue); 1373 return fw_cdev_major; 1374 } 1375 1376 fw_core_add_address_handler(&topology_map, &topology_map_region); 1377 fw_core_add_address_handler(®isters, ®isters_region); 1378 fw_core_add_address_handler(&low_memory, &low_memory_region); 1379 fw_core_add_descriptor(&vendor_id_descriptor); 1380 fw_core_add_descriptor(&model_id_descriptor); 1381 1382 return 0; 1383 } 1384 1385 static void __exit fw_core_cleanup(void) 1386 { 1387 unregister_chrdev(fw_cdev_major, "firewire"); 1388 bus_unregister(&fw_bus_type); 1389 destroy_workqueue(fw_workqueue); 1390 idr_destroy(&fw_device_idr); 1391 } 1392 1393 module_init(fw_core_init); 1394 module_exit(fw_core_cleanup); 1395