xref: /openbmc/linux/drivers/rapidio/switches/idtcps.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
207590ff0SAlexandre Bounine /*
307590ff0SAlexandre Bounine  * IDT CPS RapidIO switches support
407590ff0SAlexandre Bounine  *
5058f88d6SAlexandre Bounine  * Copyright 2009-2010 Integrated Device Technology, Inc.
6058f88d6SAlexandre Bounine  * Alexandre Bounine <alexandre.bounine@idt.com>
707590ff0SAlexandre Bounine  */
807590ff0SAlexandre Bounine 
907590ff0SAlexandre Bounine #include <linux/rio.h>
1007590ff0SAlexandre Bounine #include <linux/rio_drv.h>
1107590ff0SAlexandre Bounine #include <linux/rio_ids.h>
122ec3ba69SAlexandre Bounine #include <linux/module.h>
1307590ff0SAlexandre Bounine #include "../rio.h"
1407590ff0SAlexandre Bounine 
15679395fdSAlexandre Bounine #define CPS_DEFAULT_ROUTE	0xde
1607590ff0SAlexandre Bounine #define CPS_NO_ROUTE		0xdf
1707590ff0SAlexandre Bounine 
187a88d628SAlexandre Bounine #define IDTCPS_RIO_DOMAIN 0xf20020
197a88d628SAlexandre Bounine 
2007590ff0SAlexandre Bounine static int
idtcps_route_add_entry(struct rio_mport * mport,u16 destid,u8 hopcount,u16 table,u16 route_destid,u8 route_port)2107590ff0SAlexandre Bounine idtcps_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
2207590ff0SAlexandre Bounine 		       u16 table, u16 route_destid, u8 route_port)
2307590ff0SAlexandre Bounine {
2407590ff0SAlexandre Bounine 	u32 result;
2507590ff0SAlexandre Bounine 
260bf2461fSAlexandre Bounine 	if (route_port == RIO_INVALID_ROUTE)
270bf2461fSAlexandre Bounine 		route_port = CPS_DEFAULT_ROUTE;
280bf2461fSAlexandre Bounine 
2907590ff0SAlexandre Bounine 	if (table == RIO_GLOBAL_TABLE) {
3007590ff0SAlexandre Bounine 		rio_mport_write_config_32(mport, destid, hopcount,
3107590ff0SAlexandre Bounine 				RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
3207590ff0SAlexandre Bounine 
3307590ff0SAlexandre Bounine 		rio_mport_read_config_32(mport, destid, hopcount,
3407590ff0SAlexandre Bounine 				RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
3507590ff0SAlexandre Bounine 
3607590ff0SAlexandre Bounine 		result = (0xffffff00 & result) | (u32)route_port;
3707590ff0SAlexandre Bounine 		rio_mport_write_config_32(mport, destid, hopcount,
3807590ff0SAlexandre Bounine 				RIO_STD_RTE_CONF_PORT_SEL_CSR, result);
3907590ff0SAlexandre Bounine 	}
4007590ff0SAlexandre Bounine 
4107590ff0SAlexandre Bounine 	return 0;
4207590ff0SAlexandre Bounine }
4307590ff0SAlexandre Bounine 
4407590ff0SAlexandre Bounine static int
idtcps_route_get_entry(struct rio_mport * mport,u16 destid,u8 hopcount,u16 table,u16 route_destid,u8 * route_port)4507590ff0SAlexandre Bounine idtcps_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
4607590ff0SAlexandre Bounine 		       u16 table, u16 route_destid, u8 *route_port)
4707590ff0SAlexandre Bounine {
4807590ff0SAlexandre Bounine 	u32 result;
4907590ff0SAlexandre Bounine 
5007590ff0SAlexandre Bounine 	if (table == RIO_GLOBAL_TABLE) {
5107590ff0SAlexandre Bounine 		rio_mport_write_config_32(mport, destid, hopcount,
5207590ff0SAlexandre Bounine 				RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
5307590ff0SAlexandre Bounine 
5407590ff0SAlexandre Bounine 		rio_mport_read_config_32(mport, destid, hopcount,
5507590ff0SAlexandre Bounine 				RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
5607590ff0SAlexandre Bounine 
57679395fdSAlexandre Bounine 		if (CPS_DEFAULT_ROUTE == (u8)result ||
58679395fdSAlexandre Bounine 		    CPS_NO_ROUTE == (u8)result)
59679395fdSAlexandre Bounine 			*route_port = RIO_INVALID_ROUTE;
60679395fdSAlexandre Bounine 		else
6107590ff0SAlexandre Bounine 			*route_port = (u8)result;
6207590ff0SAlexandre Bounine 	}
6307590ff0SAlexandre Bounine 
6407590ff0SAlexandre Bounine 	return 0;
6507590ff0SAlexandre Bounine }
6607590ff0SAlexandre Bounine 
6707590ff0SAlexandre Bounine static int
idtcps_route_clr_table(struct rio_mport * mport,u16 destid,u8 hopcount,u16 table)6807590ff0SAlexandre Bounine idtcps_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
6907590ff0SAlexandre Bounine 		       u16 table)
7007590ff0SAlexandre Bounine {
7107590ff0SAlexandre Bounine 	u32 i;
7207590ff0SAlexandre Bounine 
7307590ff0SAlexandre Bounine 	if (table == RIO_GLOBAL_TABLE) {
7407590ff0SAlexandre Bounine 		for (i = 0x80000000; i <= 0x800000ff;) {
7507590ff0SAlexandre Bounine 			rio_mport_write_config_32(mport, destid, hopcount,
7607590ff0SAlexandre Bounine 				RIO_STD_RTE_CONF_DESTID_SEL_CSR, i);
7707590ff0SAlexandre Bounine 			rio_mport_write_config_32(mport, destid, hopcount,
7807590ff0SAlexandre Bounine 				RIO_STD_RTE_CONF_PORT_SEL_CSR,
79679395fdSAlexandre Bounine 				(CPS_DEFAULT_ROUTE << 24) |
80679395fdSAlexandre Bounine 				(CPS_DEFAULT_ROUTE << 16) |
81679395fdSAlexandre Bounine 				(CPS_DEFAULT_ROUTE << 8) | CPS_DEFAULT_ROUTE);
8207590ff0SAlexandre Bounine 			i += 4;
8307590ff0SAlexandre Bounine 		}
8407590ff0SAlexandre Bounine 	}
8507590ff0SAlexandre Bounine 
8607590ff0SAlexandre Bounine 	return 0;
8707590ff0SAlexandre Bounine }
8807590ff0SAlexandre Bounine 
897a88d628SAlexandre Bounine static int
idtcps_set_domain(struct rio_mport * mport,u16 destid,u8 hopcount,u8 sw_domain)907a88d628SAlexandre Bounine idtcps_set_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
917a88d628SAlexandre Bounine 		       u8 sw_domain)
927a88d628SAlexandre Bounine {
937a88d628SAlexandre Bounine 	/*
947a88d628SAlexandre Bounine 	 * Switch domain configuration operates only at global level
957a88d628SAlexandre Bounine 	 */
967a88d628SAlexandre Bounine 	rio_mport_write_config_32(mport, destid, hopcount,
977a88d628SAlexandre Bounine 				  IDTCPS_RIO_DOMAIN, (u32)sw_domain);
987a88d628SAlexandre Bounine 	return 0;
997a88d628SAlexandre Bounine }
1007a88d628SAlexandre Bounine 
1017a88d628SAlexandre Bounine static int
idtcps_get_domain(struct rio_mport * mport,u16 destid,u8 hopcount,u8 * sw_domain)1027a88d628SAlexandre Bounine idtcps_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
1037a88d628SAlexandre Bounine 		       u8 *sw_domain)
1047a88d628SAlexandre Bounine {
1057a88d628SAlexandre Bounine 	u32 regval;
1067a88d628SAlexandre Bounine 
1077a88d628SAlexandre Bounine 	/*
1087a88d628SAlexandre Bounine 	 * Switch domain configuration operates only at global level
1097a88d628SAlexandre Bounine 	 */
1107a88d628SAlexandre Bounine 	rio_mport_read_config_32(mport, destid, hopcount,
1117a88d628SAlexandre Bounine 				IDTCPS_RIO_DOMAIN, &regval);
1127a88d628SAlexandre Bounine 
1137a88d628SAlexandre Bounine 	*sw_domain = (u8)(regval & 0xff);
1147a88d628SAlexandre Bounine 
1157a88d628SAlexandre Bounine 	return 0;
1167a88d628SAlexandre Bounine }
1177a88d628SAlexandre Bounine 
1182ec3ba69SAlexandre Bounine static struct rio_switch_ops idtcps_switch_ops = {
1192ec3ba69SAlexandre Bounine 	.owner = THIS_MODULE,
1202ec3ba69SAlexandre Bounine 	.add_entry = idtcps_route_add_entry,
1212ec3ba69SAlexandre Bounine 	.get_entry = idtcps_route_get_entry,
1222ec3ba69SAlexandre Bounine 	.clr_table = idtcps_route_clr_table,
1232ec3ba69SAlexandre Bounine 	.set_domain = idtcps_set_domain,
1242ec3ba69SAlexandre Bounine 	.get_domain = idtcps_get_domain,
1252ec3ba69SAlexandre Bounine 	.em_init = NULL,
1262ec3ba69SAlexandre Bounine 	.em_handle = NULL,
1272ec3ba69SAlexandre Bounine };
1282ec3ba69SAlexandre Bounine 
idtcps_probe(struct rio_dev * rdev,const struct rio_device_id * id)1292ec3ba69SAlexandre Bounine static int idtcps_probe(struct rio_dev *rdev, const struct rio_device_id *id)
130058f88d6SAlexandre Bounine {
131058f88d6SAlexandre Bounine 	pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
132058f88d6SAlexandre Bounine 
1332ec3ba69SAlexandre Bounine 	spin_lock(&rdev->rswitch->lock);
1342ec3ba69SAlexandre Bounine 
1352ec3ba69SAlexandre Bounine 	if (rdev->rswitch->ops) {
1362ec3ba69SAlexandre Bounine 		spin_unlock(&rdev->rswitch->lock);
1372ec3ba69SAlexandre Bounine 		return -EINVAL;
1382ec3ba69SAlexandre Bounine 	}
1392ec3ba69SAlexandre Bounine 
1402ec3ba69SAlexandre Bounine 	rdev->rswitch->ops = &idtcps_switch_ops;
1412ec3ba69SAlexandre Bounine 
1422ec3ba69SAlexandre Bounine 	if (rdev->do_enum) {
143dd5648c9SAlexandre Bounine 		/* set TVAL = ~50us */
144a93192a5SAlexandre Bounine 		rio_write_config_32(rdev,
145dd5648c9SAlexandre Bounine 			rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
1460bf2461fSAlexandre Bounine 		/* Ensure that default routing is disabled on startup */
1470bf2461fSAlexandre Bounine 		rio_write_config_32(rdev,
1480bf2461fSAlexandre Bounine 				    RIO_STD_RTE_DEFAULT_PORT, CPS_NO_ROUTE);
149dd5648c9SAlexandre Bounine 	}
150dd5648c9SAlexandre Bounine 
1512ec3ba69SAlexandre Bounine 	spin_unlock(&rdev->rswitch->lock);
152058f88d6SAlexandre Bounine 	return 0;
153058f88d6SAlexandre Bounine }
154058f88d6SAlexandre Bounine 
idtcps_remove(struct rio_dev * rdev)1552ec3ba69SAlexandre Bounine static void idtcps_remove(struct rio_dev *rdev)
1562ec3ba69SAlexandre Bounine {
1572ec3ba69SAlexandre Bounine 	pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
1582ec3ba69SAlexandre Bounine 	spin_lock(&rdev->rswitch->lock);
1592ec3ba69SAlexandre Bounine 	if (rdev->rswitch->ops != &idtcps_switch_ops) {
1602ec3ba69SAlexandre Bounine 		spin_unlock(&rdev->rswitch->lock);
1612ec3ba69SAlexandre Bounine 		return;
1622ec3ba69SAlexandre Bounine 	}
1632ec3ba69SAlexandre Bounine 	rdev->rswitch->ops = NULL;
1642ec3ba69SAlexandre Bounine 	spin_unlock(&rdev->rswitch->lock);
1652ec3ba69SAlexandre Bounine }
1662ec3ba69SAlexandre Bounine 
167c1b1418aSArvind Yadav static const struct rio_device_id idtcps_id_table[] = {
1682ec3ba69SAlexandre Bounine 	{RIO_DEVICE(RIO_DID_IDTCPS6Q, RIO_VID_IDT)},
1692ec3ba69SAlexandre Bounine 	{RIO_DEVICE(RIO_DID_IDTCPS8, RIO_VID_IDT)},
1702ec3ba69SAlexandre Bounine 	{RIO_DEVICE(RIO_DID_IDTCPS10Q, RIO_VID_IDT)},
1712ec3ba69SAlexandre Bounine 	{RIO_DEVICE(RIO_DID_IDTCPS12, RIO_VID_IDT)},
1722ec3ba69SAlexandre Bounine 	{RIO_DEVICE(RIO_DID_IDTCPS16, RIO_VID_IDT)},
1732ec3ba69SAlexandre Bounine 	{RIO_DEVICE(RIO_DID_IDT70K200, RIO_VID_IDT)},
1742ec3ba69SAlexandre Bounine 	{ 0, }	/* terminate list */
1752ec3ba69SAlexandre Bounine };
1762ec3ba69SAlexandre Bounine 
1772ec3ba69SAlexandre Bounine static struct rio_driver idtcps_driver = {
1782ec3ba69SAlexandre Bounine 	.name = "idtcps",
1792ec3ba69SAlexandre Bounine 	.id_table = idtcps_id_table,
1802ec3ba69SAlexandre Bounine 	.probe = idtcps_probe,
1812ec3ba69SAlexandre Bounine 	.remove = idtcps_remove,
1822ec3ba69SAlexandre Bounine };
1832ec3ba69SAlexandre Bounine 
idtcps_init(void)1842ec3ba69SAlexandre Bounine static int __init idtcps_init(void)
1852ec3ba69SAlexandre Bounine {
1862ec3ba69SAlexandre Bounine 	return rio_register_driver(&idtcps_driver);
1872ec3ba69SAlexandre Bounine }
1882ec3ba69SAlexandre Bounine 
idtcps_exit(void)1892ec3ba69SAlexandre Bounine static void __exit idtcps_exit(void)
1902ec3ba69SAlexandre Bounine {
1912ec3ba69SAlexandre Bounine 	rio_unregister_driver(&idtcps_driver);
1922ec3ba69SAlexandre Bounine }
1932ec3ba69SAlexandre Bounine 
1942ec3ba69SAlexandre Bounine device_initcall(idtcps_init);
1952ec3ba69SAlexandre Bounine module_exit(idtcps_exit);
1962ec3ba69SAlexandre Bounine 
1972ec3ba69SAlexandre Bounine MODULE_DESCRIPTION("IDT CPS Gen.1 Serial RapidIO switch family driver");
1982ec3ba69SAlexandre Bounine MODULE_AUTHOR("Integrated Device Technology, Inc.");
1992ec3ba69SAlexandre Bounine MODULE_LICENSE("GPL");
200