Skip to content

Commit 26b4950

Browse files
author
Stefan Richter
committed
firewire: core: prefix log messages with card name
Associate all log messages from firewire-core with the respective card because some people have more than one card. E.g. firewire_ohci 0000:04:00.0: added OHCI v1.10 device as card 0, 8 IR + 8 IT contexts, quirks 0x0 firewire_ohci 0000:05:00.0: added OHCI v1.10 device as card 1, 8 IR + 8 IT contexts, quirks 0x0 firewire_core: created device fw0: GUID 0814438400000389, S800 firewire_core: phy config: new root=ffc1, gap_count=5 firewire_core: created device fw1: GUID 0814438400000388, S800 firewire_core: created device fw2: GUID 0001d202e06800d1, S800 turns into firewire_ohci 0000:04:00.0: added OHCI v1.10 device as card 0, 8 IR + 8 IT contexts, quirks 0x0 firewire_ohci 0000:05:00.0: added OHCI v1.10 device as card 1, 8 IR + 8 IT contexts, quirks 0x0 firewire_core 0000:04:00.0: created device fw0: GUID 0814438400000389, S800 firewire_core 0000:04:00.0: phy config: new root=ffc1, gap_count=5 firewire_core 0000:05:00.0: created device fw1: GUID 0814438400000388, S800 firewire_core 0000:04:00.0: created device fw2: GUID 0001d202e06800d1, S800 This increases the module size slightly; to keep this in check, turn the former printk wrapper macros into functions. Their implementation is largely copied from driver core's dev_printk counterparts. Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
1 parent 8408dc1 commit 26b4950

7 files changed

Lines changed: 72 additions & 57 deletions

File tree

‎drivers/firewire/core-card.c‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@
3737

3838
#include "core.h"
3939

40+
#define define_fw_printk_level(func, kern_level) \
41+
void func(const struct fw_card *card, const char *fmt, ...) \
42+
{ \
43+
struct va_format vaf; \
44+
va_list args; \
45+
\
46+
va_start(args, fmt); \
47+
vaf.fmt = fmt; \
48+
vaf.va = &args; \
49+
printk(kern_level KBUILD_MODNAME " %s: %pV", \
50+
dev_name(card->device), &vaf); \
51+
va_end(args); \
52+
}
53+
define_fw_printk_level(fw_err, KERN_ERR);
54+
define_fw_printk_level(fw_notice, KERN_NOTICE);
55+
4056
int fw_compute_block_crc(__be32 *block)
4157
{
4258
int length;
@@ -260,7 +276,7 @@ static void allocate_broadcast_channel(struct fw_card *card, int generation)
260276
fw_iso_resource_manage(card, generation, 1ULL << 31,
261277
&channel, &bandwidth, true);
262278
if (channel != 31) {
263-
fw_notify("failed to allocate broadcast channel\n");
279+
fw_notice(card, "failed to allocate broadcast channel\n");
264280
return;
265281
}
266282
card->broadcast_channel_allocated = true;
@@ -343,14 +359,14 @@ static void bm_work(struct work_struct *work)
343359

344360
if (!card->irm_node->link_on) {
345361
new_root_id = local_id;
346-
fw_notify("%s, making local node (%02x) root.\n",
362+
fw_notice(card, "%s, making local node (%02x) root\n",
347363
"IRM has link off", new_root_id);
348364
goto pick_me;
349365
}
350366

351367
if (irm_is_1394_1995_only && !keep_this_irm) {
352368
new_root_id = local_id;
353-
fw_notify("%s, making local node (%02x) root.\n",
369+
fw_notice(card, "%s, making local node (%02x) root\n",
354370
"IRM is not 1394a compliant", new_root_id);
355371
goto pick_me;
356372
}
@@ -405,7 +421,7 @@ static void bm_work(struct work_struct *work)
405421
* root, and thus, IRM.
406422
*/
407423
new_root_id = local_id;
408-
fw_notify("%s, making local node (%02x) root.\n",
424+
fw_notice(card, "%s, making local node (%02x) root\n",
409425
"BM lock failed", new_root_id);
410426
goto pick_me;
411427
}
@@ -478,8 +494,8 @@ static void bm_work(struct work_struct *work)
478494
spin_unlock_irq(&card->lock);
479495

480496
if (do_reset) {
481-
fw_notify("phy config: card %d, new root=%x, gap_count=%d\n",
482-
card->index, new_root_id, gap_count);
497+
fw_notice(card, "phy config: new root=%x, gap_count=%d\n",
498+
new_root_id, gap_count);
483499
fw_send_phy_config(card, new_root_id, generation, gap_count);
484500
reset_bus(card, true);
485501
/* Will allocate broadcast channel after the reset. */

‎drivers/firewire/core-cdev.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static void queue_bus_reset_event(struct client *client)
389389

390390
e = kzalloc(sizeof(*e), GFP_KERNEL);
391391
if (e == NULL) {
392-
fw_notify("Out of memory when allocating event\n");
392+
fw_notice(client->device->card, "out of memory when allocating event\n");
393393
return;
394394
}
395395

@@ -691,7 +691,7 @@ static void handle_request(struct fw_card *card, struct fw_request *request,
691691
r = kmalloc(sizeof(*r), GFP_ATOMIC);
692692
e = kmalloc(sizeof(*e), GFP_ATOMIC);
693693
if (r == NULL || e == NULL) {
694-
fw_notify("Out of memory when allocating event\n");
694+
fw_notice(card, "out of memory when allocating event\n");
695695
goto failed;
696696
}
697697
r->card = card;
@@ -928,7 +928,7 @@ static void iso_callback(struct fw_iso_context *context, u32 cycle,
928928

929929
e = kmalloc(sizeof(*e) + header_length, GFP_ATOMIC);
930930
if (e == NULL) {
931-
fw_notify("Out of memory when allocating event\n");
931+
fw_notice(context->card, "out of memory when allocating event\n");
932932
return;
933933
}
934934
e->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT;
@@ -948,7 +948,7 @@ static void iso_mc_callback(struct fw_iso_context *context,
948948

949949
e = kmalloc(sizeof(*e), GFP_ATOMIC);
950950
if (e == NULL) {
951-
fw_notify("Out of memory when allocating event\n");
951+
fw_notice(context->card, "out of memory when allocating event\n");
952952
return;
953953
}
954954
e->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL;
@@ -1548,7 +1548,7 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p)
15481548
list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) {
15491549
e = kmalloc(sizeof(*e) + 8, GFP_ATOMIC);
15501550
if (e == NULL) {
1551-
fw_notify("Out of memory when allocating event\n");
1551+
fw_notice(card, "out of memory when allocating event\n");
15521552
break;
15531553
}
15541554
e->phy_packet.closure = client->phy_receiver_closure;

‎drivers/firewire/core-device.c‎

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ static int read_rom(struct fw_device *device,
485485
*/
486486
static int read_config_rom(struct fw_device *device, int generation)
487487
{
488+
struct fw_card *card = device->card;
488489
const u32 *old_rom, *new_rom;
489490
u32 *rom, *stack;
490491
u32 sp, key;
@@ -529,12 +530,12 @@ static int read_config_rom(struct fw_device *device, int generation)
529530
*/
530531
if ((rom[2] & 0x7) < device->max_speed ||
531532
device->max_speed == SCODE_BETA ||
532-
device->card->beta_repeaters_present) {
533+
card->beta_repeaters_present) {
533534
u32 dummy;
534535

535536
/* for S1600 and S3200 */
536537
if (device->max_speed == SCODE_BETA)
537-
device->max_speed = device->card->link_speed;
538+
device->max_speed = card->link_speed;
538539

539540
while (device->max_speed > SCODE_100) {
540541
if (read_rom(device, generation, 0, &dummy) ==
@@ -576,9 +577,9 @@ static int read_config_rom(struct fw_device *device, int generation)
576577
* a firmware bug. Ignore this whole block, i.e.
577578
* simply set a fake block length of 0.
578579
*/
579-
fw_error("skipped invalid ROM block %x at %llx\n",
580-
rom[i],
581-
i * 4 | CSR_REGISTER_BASE | CSR_CONFIG_ROM);
580+
fw_err(card, "skipped invalid ROM block %x at %llx\n",
581+
rom[i],
582+
i * 4 | CSR_REGISTER_BASE | CSR_CONFIG_ROM);
582583
rom[i] = 0;
583584
end = i;
584585
}
@@ -604,9 +605,10 @@ static int read_config_rom(struct fw_device *device, int generation)
604605
* the ROM don't have to check offsets all the time.
605606
*/
606607
if (i + (rom[i] & 0xffffff) >= MAX_CONFIG_ROM_SIZE) {
607-
fw_error("skipped unsupported ROM entry %x at %llx\n",
608-
rom[i],
609-
i * 4 | CSR_REGISTER_BASE | CSR_CONFIG_ROM);
608+
fw_err(card,
609+
"skipped unsupported ROM entry %x at %llx\n",
610+
rom[i],
611+
i * 4 | CSR_REGISTER_BASE | CSR_CONFIG_ROM);
610612
rom[i] = 0;
611613
continue;
612614
}
@@ -673,7 +675,7 @@ static void create_units(struct fw_device *device)
673675
*/
674676
unit = kzalloc(sizeof(*unit), GFP_KERNEL);
675677
if (unit == NULL) {
676-
fw_error("failed to allocate memory for unit\n");
678+
fw_err(device->card, "out of memory for unit\n");
677679
continue;
678680
}
679681

@@ -875,7 +877,7 @@ static int lookup_existing_device(struct device *dev, void *data)
875877
smp_wmb(); /* update node_id before generation */
876878
old->generation = card->generation;
877879
old->config_rom_retries = 0;
878-
fw_notify("rediscovered device %s\n", dev_name(dev));
880+
fw_notice(card, "rediscovered device %s\n", dev_name(dev));
879881

880882
PREPARE_DELAYED_WORK(&old->work, fw_device_update);
881883
fw_schedule_device_work(old, 0);
@@ -956,6 +958,7 @@ static void fw_device_init(struct work_struct *work)
956958
{
957959
struct fw_device *device =
958960
container_of(work, struct fw_device, work.work);
961+
struct fw_card *card = device->card;
959962
struct device *revived_dev;
960963
int minor, ret;
961964

@@ -972,16 +975,16 @@ static void fw_device_init(struct work_struct *work)
972975
fw_schedule_device_work(device, RETRY_DELAY);
973976
} else {
974977
if (device->node->link_on)
975-
fw_notify("giving up on config rom for node id %x\n",
978+
fw_notice(card, "giving up on Config ROM for node id %x\n",
976979
device->node_id);
977-
if (device->node == device->card->root_node)
978-
fw_schedule_bm_work(device->card, 0);
980+
if (device->node == card->root_node)
981+
fw_schedule_bm_work(card, 0);
979982
fw_device_release(&device->device);
980983
}
981984
return;
982985
}
983986

984-
revived_dev = device_find_child(device->card->device,
987+
revived_dev = device_find_child(card->device,
985988
device, lookup_existing_device);
986989
if (revived_dev) {
987990
put_device(revived_dev);
@@ -1004,7 +1007,7 @@ static void fw_device_init(struct work_struct *work)
10041007

10051008
device->device.bus = &fw_bus_type;
10061009
device->device.type = &fw_device_type;
1007-
device->device.parent = device->card->device;
1010+
device->device.parent = card->device;
10081011
device->device.devt = MKDEV(fw_cdev_major, minor);
10091012
dev_set_name(&device->device, "fw%d", minor);
10101013

@@ -1016,7 +1019,7 @@ static void fw_device_init(struct work_struct *work)
10161019
&device->attribute_group);
10171020

10181021
if (device_add(&device->device)) {
1019-
fw_error("Failed to add device.\n");
1022+
fw_err(card, "failed to add device\n");
10201023
goto error_with_cdev;
10211024
}
10221025

@@ -1037,18 +1040,10 @@ static void fw_device_init(struct work_struct *work)
10371040
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
10381041
fw_schedule_device_work(device, SHUTDOWN_DELAY);
10391042
} else {
1040-
if (device->config_rom_retries)
1041-
fw_notify("created device %s: GUID %08x%08x, S%d00, "
1042-
"%d config ROM retries\n",
1043-
dev_name(&device->device),
1044-
device->config_rom[3], device->config_rom[4],
1045-
1 << device->max_speed,
1046-
device->config_rom_retries);
1047-
else
1048-
fw_notify("created device %s: GUID %08x%08x, S%d00\n",
1049-
dev_name(&device->device),
1050-
device->config_rom[3], device->config_rom[4],
1051-
1 << device->max_speed);
1043+
fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
1044+
dev_name(&device->device),
1045+
device->config_rom[3], device->config_rom[4],
1046+
1 << device->max_speed);
10521047
device->config_rom_retries = 0;
10531048

10541049
set_broadcast_channel(device, device->generation);
@@ -1060,8 +1055,8 @@ static void fw_device_init(struct work_struct *work)
10601055
* just end up running the IRM work a couple of extra times -
10611056
* pretty harmless.
10621057
*/
1063-
if (device->node == device->card->root_node)
1064-
fw_schedule_bm_work(device->card, 0);
1058+
if (device->node == card->root_node)
1059+
fw_schedule_bm_work(card, 0);
10651060

10661061
return;
10671062

@@ -1165,12 +1160,13 @@ static void fw_device_refresh(struct work_struct *work)
11651160
FW_DEVICE_RUNNING) == FW_DEVICE_GONE)
11661161
goto gone;
11671162

1168-
fw_notify("refreshed device %s\n", dev_name(&device->device));
1163+
fw_notice(card, "refreshed device %s\n", dev_name(&device->device));
11691164
device->config_rom_retries = 0;
11701165
goto out;
11711166

11721167
give_up:
1173-
fw_notify("giving up on refresh of device %s\n", dev_name(&device->device));
1168+
fw_notice(card, "giving up on refresh of device %s\n",
1169+
dev_name(&device->device));
11741170
gone:
11751171
atomic_set(&device->state, FW_DEVICE_GONE);
11761172
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);

‎drivers/firewire/core-topology.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,19 @@ static struct fw_node *build_tree(struct fw_card *card,
205205
next_sid = count_ports(sid, &port_count, &child_port_count);
206206

207207
if (next_sid == NULL) {
208-
fw_error("Inconsistent extended self IDs.\n");
208+
fw_err(card, "inconsistent extended self IDs\n");
209209
return NULL;
210210
}
211211

212212
q = *sid;
213213
if (phy_id != SELF_ID_PHY_ID(q)) {
214-
fw_error("PHY ID mismatch in self ID: %d != %d.\n",
215-
phy_id, SELF_ID_PHY_ID(q));
214+
fw_err(card, "PHY ID mismatch in self ID: %d != %d\n",
215+
phy_id, SELF_ID_PHY_ID(q));
216216
return NULL;
217217
}
218218

219219
if (child_port_count > stack_depth) {
220-
fw_error("Topology stack underflow\n");
220+
fw_err(card, "topology stack underflow\n");
221221
return NULL;
222222
}
223223

@@ -235,7 +235,7 @@ static struct fw_node *build_tree(struct fw_card *card,
235235

236236
node = fw_node_create(q, port_count, card->color);
237237
if (node == NULL) {
238-
fw_error("Out of memory while building topology.\n");
238+
fw_err(card, "out of memory while building topology\n");
239239
return NULL;
240240
}
241241

@@ -284,8 +284,8 @@ static struct fw_node *build_tree(struct fw_card *card,
284284
*/
285285
if ((next_sid == end && parent_count != 0) ||
286286
(next_sid < end && parent_count != 1)) {
287-
fw_error("Parent port inconsistency for node %d: "
288-
"parent_count=%d\n", phy_id, parent_count);
287+
fw_err(card, "parent port inconsistency for node %d: "
288+
"parent_count=%d\n", phy_id, parent_count);
289289
return NULL;
290290
}
291291

@@ -530,7 +530,7 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation,
530530
*/
531531
if (!is_next_generation(generation, card->generation) &&
532532
card->local_node != NULL) {
533-
fw_notify("skipped bus generations, destroying all nodes\n");
533+
fw_notice(card, "skipped bus generations, destroying all nodes\n");
534534
fw_destroy_nodes(card);
535535
card->bm_retries = 0;
536536
}
@@ -557,7 +557,7 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation,
557557
card->color++;
558558

559559
if (local_node == NULL) {
560-
fw_error("topology build failed\n");
560+
fw_err(card, "topology build failed\n");
561561
/* FIXME: We need to issue a bus reset in this case. */
562562
} else if (card->local_node == NULL) {
563563
card->local_node = local_node;

‎drivers/firewire/core-transaction.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static struct fw_request *allocate_request(struct fw_card *card,
770770
break;
771771

772772
default:
773-
fw_error("ERROR - corrupt request received - %08x %08x %08x\n",
773+
fw_notice(card, "ERROR - corrupt request received - %08x %08x %08x\n",
774774
p->header[0], p->header[1], p->header[2]);
775775
return NULL;
776776
}
@@ -960,7 +960,7 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
960960

961961
if (&t->link == &card->transaction_list) {
962962
timed_out:
963-
fw_notify("Unsolicited response (source %x, tlabel %x)\n",
963+
fw_notice(card, "unsolicited response (source %x, tlabel %x)\n",
964964
source, tlabel);
965965
return;
966966
}

‎drivers/firewire/core.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _FIREWIRE_CORE_H
22
#define _FIREWIRE_CORE_H
33

4+
#include <linux/compiler.h>
45
#include <linux/device.h>
56
#include <linux/fs.h>
67
#include <linux/list.h>
@@ -24,6 +25,11 @@ struct fw_packet;
2425

2526
/* -card */
2627

28+
extern __printf(2, 3)
29+
void fw_err(const struct fw_card *card, const char *fmt, ...);
30+
extern __printf(2, 3)
31+
void fw_notice(const struct fw_card *card, const char *fmt, ...);
32+
2733
/* bitfields within the PHY registers */
2834
#define PHY_LINK_ACTIVE 0x80
2935
#define PHY_CONTENDER 0x40

‎include/linux/firewire.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include <linux/atomic.h>
1818
#include <asm/byteorder.h>
1919

20-
#define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
21-
#define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
22-
2320
#define CSR_REGISTER_BASE 0xfffff0000000ULL
2421

2522
/* register offsets are relative to CSR_REGISTER_BASE */

0 commit comments

Comments
 (0)