// SPDX-License-Identifier: GPL-2.0
/*
* KUnit tests
*
* Copyright (C) 2020, Intel Corporation
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
*/
#include <kunit/test.h>
#include <linux/idr.h>
#include "tb.h"
#include "tunnel.h"
static int __ida_init(struct kunit_resource *res, void *context)
{
struct ida *ida = context;
ida_init(ida);
res->data = ida;
return 0;
}
static void __ida_destroy(struct kunit_resource *res)
{
struct ida *ida = res->data;
ida_destroy(ida);
}
static void kunit_ida_init(struct kunit *test, struct ida *ida)
{
kunit_alloc_resource(test, __ida_init, __ida_destroy, GFP_KERNEL, ida);
}
static struct tb_switch *alloc_switch(struct kunit *test, u64 route,
u8 upstream_port, u8 max_port_number)
{
struct tb_switch *sw;
size_t size;
int i;
sw = kunit_kzalloc(test, sizeof(*sw), GFP_KERNEL);
if (!sw)
return NULL;
sw->config.upstream_port_number = upstream_port;
sw->config.depth = tb_route_length(route);
sw->config.route_hi = upper_32_bits(route);
sw->config.route_lo = lower_32_bits(route);
sw->config.enabled = 0;
sw->config.max_port_number = max_port_number;
size = (sw->config.max_port_number + 1) * sizeof(*sw->ports);
sw->ports = kunit_kzalloc(test, size, GFP_KERNEL);
if (!sw->ports)
return NULL;
for (i = 0; i <= sw->config.max_port_number; i++) {
sw->ports[i].sw = sw;
sw->ports[i].port = i;
sw->ports[i].config.port_number = i;
if (i) {
kunit_ida_init(test, &sw->ports[i].in_hopids);
kunit_ida_init(test, &sw->ports[i].out_hopids);
}
}
return sw;
}
static struct tb_switch *alloc_host(struct kunit *test)
{
struct tb_switch *sw;
sw = alloc_switch(test, 0, 7, 13);
if (!sw)
return NULL;
sw->config.vendor_id = 0x8086;
sw->config.device_id = 0x9a1b;
sw->ports[0].config.type = TB_TYPE_PORT;
sw->ports[0].config.max_in_hop_id = 7;
sw->ports[0].config.max_out_hop_id = 7;
sw->ports[1].config.type = TB_TYPE_PORT;
sw->ports[1].config.max_in_hop_id = 19;
sw->ports[1].config.max_out_hop_id = 19;
sw->ports[1].dual_link_port = &sw->ports[2];
sw->ports[2].config.type = TB_TYPE_PORT;
sw->ports[2].config.max_in_hop_id = 19;
sw->ports[2].config.max_out_hop_id = 19;
sw->ports[2].dual_link_port = &sw->ports[1];
sw->ports[2].link_nr = 1;
sw->ports[3].config.type = TB_TYPE_PORT;
sw->ports[3].config.max_in_hop_id = 19;
sw->ports[3].config.max_out_hop_id = 19;
sw->ports[3].dual_link_port = &sw->ports[4];
sw->ports[4].config.type = TB_TYPE_PORT;
sw->ports[4].config.max_in_hop_id = 19;
sw->ports[4].config.max_out_hop_id = 19;
sw->ports[4].dual_link_port = &sw->ports[3];
sw->ports[4].link_nr = 1;
sw->ports[5].config.type = TB_TYPE_DP_HDMI_IN;
sw->ports[5].config.max_in_hop_id = 9;
sw->ports[5].config.max_out_hop_id = 9;
sw->ports[5].cap_adap = -1;
sw->ports[6].config.type = TB_TYPE_DP_HDMI_IN;
sw->ports[6].config.max_in_hop_id = 9;
sw->ports[6].config.max_out_hop_id = 9;
sw->ports[6].cap_adap = -1;
sw->ports[7].config.type = TB_TYPE_NHI;
sw->ports[7].config.max_in_hop_id = 11;
sw->ports[7].config.max_out_hop_id = 11;
sw->ports[8].config.type = TB_TYPE_PCIE_DOWN;
sw->ports[8].config.max_in_hop_id = 8;
sw->ports[8].config.max_out_hop_id = 8;
sw->ports[9].config.type = TB_TYPE_PCIE_DOWN;
sw->ports[9].config.max_in_hop_id = 8;
sw->ports[9].config.max_out_hop_id = 8;
sw->ports[10].disabled = true;
sw->ports[11].
|