2021-12-29 22:31:46 -08:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause-Views
|
|
|
|
/*
|
2023-06-26 11:44:57 -07:00
|
|
|
* Copyright (c) 2021-2023 The Regents of the University of California
|
2021-12-29 22:31:46 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mqnic.h"
|
|
|
|
|
2023-04-30 21:57:32 -07:00
|
|
|
struct mqnic_sched *mqnic_create_scheduler(struct mqnic_sched_block *block,
|
2022-04-24 23:01:15 -07:00
|
|
|
int index, struct mqnic_reg_block *rb)
|
2021-12-29 22:31:46 -08:00
|
|
|
{
|
2022-03-28 17:23:27 -07: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)
|
2023-04-30 21:57:32 -07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2021-12-29 22:31:46 -08:00
|
|
|
|
|
|
|
sched->dev = dev;
|
2022-03-28 17:23:27 -07:00
|
|
|
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);
|
|
|
|
|
2022-03-28 17:23:27 -07:00
|
|
|
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);
|
|
|
|
|
2023-04-30 21:57:32 -07:00
|
|
|
return sched;
|
2021-12-29 22:31:46 -08:00
|
|
|
}
|
|
|
|
|
2023-04-30 21:57:32 -07: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;
|
|
|
|
}
|
2022-04-25 00:47:37 -07:00
|
|
|
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);
|
|
|
|
}
|
2022-04-25 00:47:37 -07:00
|
|
|
EXPORT_SYMBOL(mqnic_scheduler_disable);
|