1
0
mirror of https://github.com/corundum/corundum.git synced 2025-01-16 08:12:53 +08:00
corundum/modules/mqnic/mqnic_scheduler.c

71 lines
1.7 KiB
C
Raw Normal View History

2021-12-29 22:31:46 -08:00
// SPDX-License-Identifier: BSD-2-Clause-Views
/*
* Copyright (c) 2021-2023 The Regents of the University of California
2021-12-29 22:31:46 -08:00
*/
#include "mqnic.h"
struct mqnic_sched *mqnic_create_scheduler(struct mqnic_sched_block *block,
int index, struct mqnic_reg_block *rb)
2021-12-29 22:31:46 -08:00
{
struct device *dev = block->dev;
2021-12-29 22:31:46 -08:00
struct mqnic_sched *sched;
sched = kzalloc(sizeof(*sched), GFP_KERNEL);
if (!sched)
return ERR_PTR(-ENOMEM);
2021-12-29 22:31:46 -08:00
sched->dev = dev;
sched->interface = block->interface;
sched->sched_block = block;
2021-12-29 22:31:46 -08:00
sched->index = index;
sched->rb = rb;
sched->type = rb->type;
sched->offset = ioread32(rb->regs + MQNIC_RB_SCHED_RR_REG_OFFSET);
sched->channel_count = ioread32(rb->regs + MQNIC_RB_SCHED_RR_REG_CH_COUNT);
sched->channel_stride = ioread32(rb->regs + MQNIC_RB_SCHED_RR_REG_CH_STRIDE);
sched->hw_addr = block->interface->hw_addr + sched->offset;
2021-12-29 22:31:46 -08:00
dev_info(dev, "Scheduler type: 0x%08x", sched->type);
dev_info(dev, "Scheduler offset: 0x%08x", sched->offset);
dev_info(dev, "Scheduler channel count: %d", sched->channel_count);
dev_info(dev, "Scheduler channel stride: 0x%08x", sched->channel_stride);
mqnic_scheduler_disable(sched);
return sched;
2021-12-29 22:31:46 -08:00
}
void mqnic_destroy_scheduler(struct mqnic_sched *sched)
2021-12-29 22:31:46 -08:00
{
mqnic_scheduler_disable(sched);
kfree(sched);
}
int mqnic_scheduler_enable(struct mqnic_sched *sched)
{
int k;
// enable scheduler
iowrite32(1, sched->rb->regs + MQNIC_RB_SCHED_RR_REG_CTRL);
// enable queues
for (k = 0; k < sched->channel_count; k++)
iowrite32(3, sched->hw_addr + k * sched->channel_stride);
return 0;
}
EXPORT_SYMBOL(mqnic_scheduler_enable);
2021-12-29 22:31:46 -08:00
void mqnic_scheduler_disable(struct mqnic_sched *sched)
{
// disable scheduler
iowrite32(0, sched->rb->regs + MQNIC_RB_SCHED_RR_REG_CTRL);
}
EXPORT_SYMBOL(mqnic_scheduler_disable);