22 #include <linux/device.h>
23 #include <linux/errno.h>
27 #include <linux/kernel.h>
29 #include <linux/list.h>
30 #include <linux/module.h>
36 #include <asm/byteorder.h>
40 #define define_fw_printk_level(func, kern_level) \
41 void func(const struct fw_card *card, const char *fmt, ...) \
43 struct va_format vaf; \
46 va_start(args, fmt); \
49 printk(kern_level KBUILD_MODNAME " %s: %pV", \
50 dev_name(card->device), &vaf); \
72 static int descriptor_count;
74 static __be32 tmp_config_rom[256];
76 static size_t config_rom_length = 1 + 4 + 1 + 1;
78 #define BIB_CRC(v) ((v) << 0)
79 #define BIB_CRC_LENGTH(v) ((v) << 16)
80 #define BIB_INFO_LENGTH(v) ((v) << 24)
81 #define BIB_BUS_NAME 0x31333934
82 #define BIB_LINK_SPEED(v) ((v) << 0)
83 #define BIB_GENERATION(v) ((v) << 4)
84 #define BIB_MAX_ROM(v) ((v) << 8)
85 #define BIB_MAX_RECEIVE(v) ((v) << 12)
86 #define BIB_CYC_CLK_ACC(v) ((v) << 16)
87 #define BIB_PMC ((1) << 27)
88 #define BIB_BMC ((1) << 28)
89 #define BIB_ISC ((1) << 29)
90 #define BIB_CMC ((1) << 30)
91 #define BIB_IRMC ((1) << 31)
92 #define NODE_CAPABILITIES 0x0c0083c0
99 #define DEFAULT_SPLIT_TIMEOUT (2 * 8000)
101 #define CANON_OUI 0x000085
132 j = 7 + descriptor_count;
148 for (k = 0; k < desc->
length; k++)
157 for (i = 0; i <
j; i += length + 1)
160 WARN_ON(j != config_rom_length);
163 static void update_config_roms(
void)
168 generate_config_rom(card, tmp_config_rom);
169 card->
driver->set_config_rom(card, tmp_config_rom,
192 i += (desc->
data[
i] >> 16) + 1;
199 if (config_rom_length + required_space(desc) > 256) {
203 config_rom_length += required_space(desc);
207 update_config_roms();
222 config_rom_length -= required_space(desc);
226 update_config_roms();
232 static int reset_bus(
struct fw_card *card,
bool short_reset)
234 int reg = short_reset ? 5 : 1;
237 return card->
driver->update_phy_reg(card, reg, 0, bit);
277 &channel, &bandwidth,
true);
279 fw_notice(card,
"failed to allocate broadcast channel\n");
289 static const char gap_count_table[] = {
290 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40
305 int root_id, new_root_id, irm_id, bm_id, local_id;
308 bool root_device_is_running;
309 bool root_device_is_cmc;
310 bool irm_is_1394_1995_only;
312 __be32 transaction_data[2];
314 spin_lock_irq(&card->
lock);
317 spin_unlock_irq(&card->
lock);
324 fw_node_get(root_node);
325 root_device = root_node->
data;
326 root_device_is_running = root_device &&
328 root_device_is_cmc = root_device && root_device->
cmc;
331 irm_is_1394_1995_only = irm_device && irm_device->
config_rom &&
332 (irm_device->
config_rom[2] & 0x000000f0) == 0;
335 keep_this_irm = irm_device && irm_device->
config_rom &&
361 new_root_id = local_id;
362 fw_notice(card,
"%s, making local node (%02x) root\n",
363 "IRM has link off", new_root_id);
367 if (irm_is_1394_1995_only && !keep_this_irm) {
368 new_root_id = local_id;
369 fw_notice(card,
"%s, making local node (%02x) root\n",
370 "IRM is not 1394a compliant", new_root_id);
377 spin_unlock_irq(&card->
lock);
382 transaction_data, 8);
390 spin_lock_irq(&card->
lock);
393 bm_id == 0x3f ? local_id : 0xffc0 | bm_id;
394 spin_unlock_irq(&card->
lock);
398 if (local_id == irm_id)
399 allocate_broadcast_channel(card, generation);
414 spin_lock_irq(&card->
lock);
423 new_root_id = local_id;
424 fw_notice(card,
"BM lock failed (%s), making local node (%02x) root\n",
433 spin_unlock_irq(&card->
lock);
445 if (root_device ==
NULL) {
450 new_root_id = local_id;
451 }
else if (!root_device_is_running) {
456 spin_unlock_irq(&card->
lock);
458 }
else if (root_device_is_cmc) {
463 new_root_id = root_id;
470 new_root_id = local_id;
480 gap_count = gap_count_table[root_node->
max_hops];
491 (card->
gap_count != gap_count || new_root_id != root_id))
494 spin_unlock_irq(&card->
lock);
497 fw_notice(card,
"phy config: new root=%x, gap_count=%d\n",
498 new_root_id, gap_count);
500 reset_bus(card,
true);
505 if (root_device_is_cmc) {
513 transaction_data, 4);
518 if (local_id == irm_id)
519 allocate_broadcast_channel(card, generation);
522 fw_node_put(root_node);
546 kref_init(&card->
kref);
547 init_completion(&card->
done);
570 generate_config_rom(card, tmp_config_rom);
571 ret = card->
driver->enable(card, tmp_config_rom, config_rom_length);
599 static int dummy_update_phy_reg(
struct fw_card *card,
int address,
610 static void dummy_send_response(
struct fw_card *card,
struct fw_packet *packet)
615 static int dummy_cancel_packet(
struct fw_card *card,
struct fw_packet *packet)
620 static int dummy_enable_phys_dma(
struct fw_card *card,
659 .read_phy_reg = dummy_read_phy_reg,
660 .update_phy_reg = dummy_update_phy_reg,
661 .send_request = dummy_send_request,
662 .send_response = dummy_send_response,
663 .cancel_packet = dummy_cancel_packet,
664 .enable_phys_dma = dummy_enable_phys_dma,
665 .allocate_iso_context = dummy_allocate_iso_context,
666 .start_iso = dummy_start_iso,
667 .set_iso_channels = dummy_set_iso_channels,
668 .queue_iso = dummy_queue_iso,
669 .flush_queue_iso = dummy_flush_queue_iso,
670 .flush_iso_completions = dummy_flush_iso_completions,
685 card->
driver->update_phy_reg(card, 4,
690 list_del_init(&card->
link);
696 card->
driver = &dummy_driver;