Skip to content

Commit 95a042a

Browse files
committed
firewire: ohci: reduce the size of common context structure by extracting members into AT structure
In commit 386a415 ("firewire: ohci: cache the context run bit"), a running member was added to the context structure to cache the running state of a given DMA context. Although this member is accessible from IR, IT, and AT contexts, it is currently used only by the AT context. Additionally, the context structure includes a work item, which is also used by the AT context. Both members are unnecessary for IR and IT contexts. This commit refactors the code by moving these two members into a new structure specific to AT context. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Sakamoto <[email protected]>
1 parent 8145671 commit 95a042a

File tree

1 file changed

+49
-43
lines changed

1 file changed

+49
-43
lines changed

drivers/firewire/ohci.c

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ struct context {
128128
int total_allocation;
129129
u32 current_bus;
130130
bool running;
131-
bool flushing;
132131

133132
/*
134133
* List of page-sized buffers for storing DMA descriptors.
@@ -157,8 +156,12 @@ struct context {
157156
int prev_z;
158157

159158
descriptor_callback_t callback;
159+
};
160160

161+
struct at_context {
162+
struct context context;
161163
struct work_struct work;
164+
bool flushing;
162165
};
163166

164167
struct iso_context {
@@ -204,8 +207,8 @@ struct fw_ohci {
204207

205208
struct ar_context ar_request_ctx;
206209
struct ar_context ar_response_ctx;
207-
struct context at_request_ctx;
208-
struct context at_response_ctx;
210+
struct at_context at_request_ctx;
211+
struct at_context at_response_ctx;
209212

210213
u32 it_context_support;
211214
u32 it_context_mask; /* unoccupied IT contexts */
@@ -1178,9 +1181,9 @@ static void context_retire_descriptors(struct context *ctx)
11781181

11791182
static void ohci_at_context_work(struct work_struct *work)
11801183
{
1181-
struct context *ctx = from_work(ctx, work, work);
1184+
struct at_context *ctx = from_work(ctx, work, work);
11821185

1183-
context_retire_descriptors(ctx);
1186+
context_retire_descriptors(&ctx->context);
11841187
}
11851188

11861189
static void ohci_isoc_context_work(struct work_struct *work)
@@ -1382,17 +1385,17 @@ struct driver_data {
13821385
* Must always be called with the ochi->lock held to ensure proper
13831386
* generation handling and locking around packet queue manipulation.
13841387
*/
1385-
static int at_context_queue_packet(struct context *ctx,
1386-
struct fw_packet *packet)
1388+
static int at_context_queue_packet(struct at_context *ctx, struct fw_packet *packet)
13871389
{
1388-
struct fw_ohci *ohci = ctx->ohci;
1390+
struct context *context = &ctx->context;
1391+
struct fw_ohci *ohci = context->ohci;
13891392
dma_addr_t d_bus, payload_bus;
13901393
struct driver_data *driver_data;
13911394
struct descriptor *d, *last;
13921395
__le32 *header;
13931396
int z, tcode;
13941397

1395-
d = context_get_descriptors(ctx, 4, &d_bus);
1398+
d = context_get_descriptors(context, 4, &d_bus);
13961399
if (d == NULL) {
13971400
packet->ack = RCODE_SEND_ERROR;
13981401
return -1;
@@ -1422,7 +1425,7 @@ static int at_context_queue_packet(struct context *ctx,
14221425
ohci1394_at_data_set_destination_id(header,
14231426
async_header_get_destination(packet->header));
14241427

1425-
if (ctx == &ctx->ohci->at_response_ctx) {
1428+
if (ctx == &ohci->at_response_ctx) {
14261429
ohci1394_at_data_set_rcode(header, async_header_get_rcode(packet->header));
14271430
} else {
14281431
ohci1394_at_data_set_destination_offset(header,
@@ -1511,17 +1514,17 @@ static int at_context_queue_packet(struct context *ctx,
15111514
return -1;
15121515
}
15131516

1514-
context_append(ctx, d, z, 4 - z);
1517+
context_append(context, d, z, 4 - z);
15151518

1516-
if (ctx->running)
1517-
reg_write(ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE);
1519+
if (context->running)
1520+
reg_write(ohci, CONTROL_SET(context->regs), CONTEXT_WAKE);
15181521
else
1519-
context_run(ctx, 0);
1522+
context_run(context, 0);
15201523

15211524
return 0;
15221525
}
15231526

1524-
static void at_context_flush(struct context *ctx)
1527+
static void at_context_flush(struct at_context *ctx)
15251528
{
15261529
// Avoid dead lock due to programming mistake.
15271530
if (WARN_ON_ONCE(current_work() == &ctx->work))
@@ -1540,12 +1543,13 @@ static int handle_at_packet(struct context *context,
15401543
struct descriptor *d,
15411544
struct descriptor *last)
15421545
{
1546+
struct at_context *ctx = container_of(context, struct at_context, context);
1547+
struct fw_ohci *ohci = ctx->context.ohci;
15431548
struct driver_data *driver_data;
15441549
struct fw_packet *packet;
1545-
struct fw_ohci *ohci = context->ohci;
15461550
int evt;
15471551

1548-
if (last->transfer_status == 0 && !READ_ONCE(context->flushing))
1552+
if (last->transfer_status == 0 && !READ_ONCE(ctx->flushing))
15491553
/* This descriptor isn't done yet, stop iteration. */
15501554
return 0;
15511555

@@ -1579,7 +1583,7 @@ static int handle_at_packet(struct context *context,
15791583
break;
15801584

15811585
case OHCI1394_evt_missing_ack:
1582-
if (READ_ONCE(context->flushing))
1586+
if (READ_ONCE(ctx->flushing))
15831587
packet->ack = RCODE_GENERATION;
15841588
else {
15851589
/*
@@ -1601,7 +1605,7 @@ static int handle_at_packet(struct context *context,
16011605
break;
16021606

16031607
case OHCI1394_evt_no_status:
1604-
if (READ_ONCE(context->flushing)) {
1608+
if (READ_ONCE(ctx->flushing)) {
16051609
packet->ack = RCODE_GENERATION;
16061610
break;
16071611
}
@@ -1698,68 +1702,70 @@ static void handle_local_lock(struct fw_ohci *ohci,
16981702
fw_core_handle_response(&ohci->card, &response);
16991703
}
17001704

1701-
static void handle_local_request(struct context *ctx, struct fw_packet *packet)
1705+
static void handle_local_request(struct at_context *ctx, struct fw_packet *packet)
17021706
{
1707+
struct fw_ohci *ohci = ctx->context.ohci;
17031708
u64 offset, csr;
17041709

1705-
if (ctx == &ctx->ohci->at_request_ctx) {
1710+
if (ctx == &ohci->at_request_ctx) {
17061711
packet->ack = ACK_PENDING;
1707-
packet->callback(packet, &ctx->ohci->card, packet->ack);
1712+
packet->callback(packet, &ohci->card, packet->ack);
17081713
}
17091714

17101715
offset = async_header_get_offset(packet->header);
17111716
csr = offset - CSR_REGISTER_BASE;
17121717

17131718
/* Handle config rom reads. */
17141719
if (csr >= CSR_CONFIG_ROM && csr < CSR_CONFIG_ROM_END)
1715-
handle_local_rom(ctx->ohci, packet, csr);
1720+
handle_local_rom(ohci, packet, csr);
17161721
else switch (csr) {
17171722
case CSR_BUS_MANAGER_ID:
17181723
case CSR_BANDWIDTH_AVAILABLE:
17191724
case CSR_CHANNELS_AVAILABLE_HI:
17201725
case CSR_CHANNELS_AVAILABLE_LO:
1721-
handle_local_lock(ctx->ohci, packet, csr);
1726+
handle_local_lock(ohci, packet, csr);
17221727
break;
17231728
default:
1724-
if (ctx == &ctx->ohci->at_request_ctx)
1725-
fw_core_handle_request(&ctx->ohci->card, packet);
1729+
if (ctx == &ohci->at_request_ctx)
1730+
fw_core_handle_request(&ohci->card, packet);
17261731
else
1727-
fw_core_handle_response(&ctx->ohci->card, packet);
1732+
fw_core_handle_response(&ohci->card, packet);
17281733
break;
17291734
}
17301735

1731-
if (ctx == &ctx->ohci->at_response_ctx) {
1736+
if (ctx == &ohci->at_response_ctx) {
17321737
packet->ack = ACK_COMPLETE;
1733-
packet->callback(packet, &ctx->ohci->card, packet->ack);
1738+
packet->callback(packet, &ohci->card, packet->ack);
17341739
}
17351740
}
17361741

1737-
static void at_context_transmit(struct context *ctx, struct fw_packet *packet)
1742+
static void at_context_transmit(struct at_context *ctx, struct fw_packet *packet)
17381743
{
1744+
struct fw_ohci *ohci = ctx->context.ohci;
17391745
unsigned long flags;
17401746
int ret;
17411747

1742-
spin_lock_irqsave(&ctx->ohci->lock, flags);
1748+
spin_lock_irqsave(&ohci->lock, flags);
17431749

1744-
if (async_header_get_destination(packet->header) == ctx->ohci->node_id &&
1745-
ctx->ohci->generation == packet->generation) {
1746-
spin_unlock_irqrestore(&ctx->ohci->lock, flags);
1750+
if (async_header_get_destination(packet->header) == ohci->node_id &&
1751+
ohci->generation == packet->generation) {
1752+
spin_unlock_irqrestore(&ohci->lock, flags);
17471753

17481754
// Timestamping on behalf of the hardware.
1749-
packet->timestamp = cycle_time_to_ohci_tstamp(get_cycle_time(ctx->ohci));
1755+
packet->timestamp = cycle_time_to_ohci_tstamp(get_cycle_time(ohci));
17501756

17511757
handle_local_request(ctx, packet);
17521758
return;
17531759
}
17541760

17551761
ret = at_context_queue_packet(ctx, packet);
1756-
spin_unlock_irqrestore(&ctx->ohci->lock, flags);
1762+
spin_unlock_irqrestore(&ohci->lock, flags);
17571763

17581764
if (ret < 0) {
17591765
// Timestamping on behalf of the hardware.
1760-
packet->timestamp = cycle_time_to_ohci_tstamp(get_cycle_time(ctx->ohci));
1766+
packet->timestamp = cycle_time_to_ohci_tstamp(get_cycle_time(ohci));
17611767

1762-
packet->callback(packet, &ctx->ohci->card, packet->ack);
1768+
packet->callback(packet, &ohci->card, packet->ack);
17631769
}
17641770
}
17651771

@@ -2138,8 +2144,8 @@ static void bus_reset_work(struct work_struct *work)
21382144
// FIXME: Document how the locking works.
21392145
scoped_guard(spinlock_irq, &ohci->lock) {
21402146
ohci->generation = -1; // prevent AT packet queueing
2141-
context_stop(&ohci->at_request_ctx);
2142-
context_stop(&ohci->at_response_ctx);
2147+
context_stop(&ohci->at_request_ctx.context);
2148+
context_stop(&ohci->at_response_ctx.context);
21432149
}
21442150

21452151
/*
@@ -2683,7 +2689,7 @@ static void ohci_send_response(struct fw_card *card, struct fw_packet *packet)
26832689
static int ohci_cancel_packet(struct fw_card *card, struct fw_packet *packet)
26842690
{
26852691
struct fw_ohci *ohci = fw_ohci(card);
2686-
struct context *ctx = &ohci->at_request_ctx;
2692+
struct at_context *ctx = &ohci->at_request_ctx;
26872693
struct driver_data *driver_data = packet->driver_data;
26882694
int ret = -ENOENT;
26892695

@@ -3767,13 +3773,13 @@ static int pci_probe(struct pci_dev *dev,
37673773
if (err < 0)
37683774
return err;
37693775

3770-
err = context_init(&ohci->at_request_ctx, ohci,
3776+
err = context_init(&ohci->at_request_ctx.context, ohci,
37713777
OHCI1394_AsReqTrContextControlSet, handle_at_packet);
37723778
if (err < 0)
37733779
return err;
37743780
INIT_WORK(&ohci->at_request_ctx.work, ohci_at_context_work);
37753781

3776-
err = context_init(&ohci->at_response_ctx, ohci,
3782+
err = context_init(&ohci->at_response_ctx.context, ohci,
37773783
OHCI1394_AsRspTrContextControlSet, handle_at_packet);
37783784
if (err < 0)
37793785
return err;

0 commit comments

Comments
 (0)