18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef _MLXSW_PCI_HW_H
58c2ecf20Sopenharmony_ci#define _MLXSW_PCI_HW_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/bitops.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "item.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define MLXSW_PCI_BAR0_SIZE		(1024 * 1024) /* 1MB */
128c2ecf20Sopenharmony_ci#define MLXSW_PCI_PAGE_SIZE		4096
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_BASE			0x71000
158c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_IN_PARAM_HI		MLXSW_PCI_CIR_BASE
168c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_IN_PARAM_LO		(MLXSW_PCI_CIR_BASE + 0x04)
178c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_IN_MODIFIER		(MLXSW_PCI_CIR_BASE + 0x08)
188c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_OUT_PARAM_HI		(MLXSW_PCI_CIR_BASE + 0x0C)
198c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_OUT_PARAM_LO		(MLXSW_PCI_CIR_BASE + 0x10)
208c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_TOKEN			(MLXSW_PCI_CIR_BASE + 0x14)
218c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_CTRL			(MLXSW_PCI_CIR_BASE + 0x18)
228c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_CTRL_GO_BIT		BIT(23)
238c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_CTRL_EVREQ_BIT		BIT(22)
248c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_CTRL_OPCODE_MOD_SHIFT	12
258c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_CTRL_STATUS_SHIFT		24
268c2ecf20Sopenharmony_ci#define MLXSW_PCI_CIR_TIMEOUT_MSECS		1000
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define MLXSW_PCI_SW_RESET_TIMEOUT_MSECS	900000
298c2ecf20Sopenharmony_ci#define MLXSW_PCI_SW_RESET_WAIT_MSECS		400
308c2ecf20Sopenharmony_ci#define MLXSW_PCI_FW_READY			0xA1844
318c2ecf20Sopenharmony_ci#define MLXSW_PCI_FW_READY_MASK			0xFFFF
328c2ecf20Sopenharmony_ci#define MLXSW_PCI_FW_READY_MAGIC		0x5E
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define MLXSW_PCI_DOORBELL_SDQ_OFFSET		0x000
358c2ecf20Sopenharmony_ci#define MLXSW_PCI_DOORBELL_RDQ_OFFSET		0x200
368c2ecf20Sopenharmony_ci#define MLXSW_PCI_DOORBELL_CQ_OFFSET		0x400
378c2ecf20Sopenharmony_ci#define MLXSW_PCI_DOORBELL_EQ_OFFSET		0x600
388c2ecf20Sopenharmony_ci#define MLXSW_PCI_DOORBELL_ARM_CQ_OFFSET	0x800
398c2ecf20Sopenharmony_ci#define MLXSW_PCI_DOORBELL_ARM_EQ_OFFSET	0xA00
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define MLXSW_PCI_DOORBELL(offset, type_offset, num)	\
428c2ecf20Sopenharmony_ci	((offset) + (type_offset) + (num) * 4)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define MLXSW_PCI_FREE_RUNNING_CLOCK_H(offset)	(offset)
458c2ecf20Sopenharmony_ci#define MLXSW_PCI_FREE_RUNNING_CLOCK_L(offset)	((offset) + 4)
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define MLXSW_PCI_CQS_MAX	96
488c2ecf20Sopenharmony_ci#define MLXSW_PCI_EQS_COUNT	2
498c2ecf20Sopenharmony_ci#define MLXSW_PCI_EQ_ASYNC_NUM	0
508c2ecf20Sopenharmony_ci#define MLXSW_PCI_EQ_COMP_NUM	1
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define MLXSW_PCI_SDQS_MIN	2 /* EMAD and control traffic */
538c2ecf20Sopenharmony_ci#define MLXSW_PCI_SDQ_EMAD_INDEX	0
548c2ecf20Sopenharmony_ci#define MLXSW_PCI_SDQ_EMAD_TC	0
558c2ecf20Sopenharmony_ci#define MLXSW_PCI_SDQ_CTL_TC	3
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define MLXSW_PCI_AQ_PAGES	8
588c2ecf20Sopenharmony_ci#define MLXSW_PCI_AQ_SIZE	(MLXSW_PCI_PAGE_SIZE * MLXSW_PCI_AQ_PAGES)
598c2ecf20Sopenharmony_ci#define MLXSW_PCI_WQE_SIZE	32 /* 32 bytes per element */
608c2ecf20Sopenharmony_ci#define MLXSW_PCI_CQE01_SIZE	16 /* 16 bytes per element */
618c2ecf20Sopenharmony_ci#define MLXSW_PCI_CQE2_SIZE	32 /* 32 bytes per element */
628c2ecf20Sopenharmony_ci#define MLXSW_PCI_CQE_SIZE_MAX	MLXSW_PCI_CQE2_SIZE
638c2ecf20Sopenharmony_ci#define MLXSW_PCI_EQE_SIZE	16 /* 16 bytes per element */
648c2ecf20Sopenharmony_ci#define MLXSW_PCI_WQE_COUNT	(MLXSW_PCI_AQ_SIZE / MLXSW_PCI_WQE_SIZE)
658c2ecf20Sopenharmony_ci#define MLXSW_PCI_CQE01_COUNT	(MLXSW_PCI_AQ_SIZE / MLXSW_PCI_CQE01_SIZE)
668c2ecf20Sopenharmony_ci#define MLXSW_PCI_CQE2_COUNT	(MLXSW_PCI_AQ_SIZE / MLXSW_PCI_CQE2_SIZE)
678c2ecf20Sopenharmony_ci#define MLXSW_PCI_EQE_COUNT	(MLXSW_PCI_AQ_SIZE / MLXSW_PCI_EQE_SIZE)
688c2ecf20Sopenharmony_ci#define MLXSW_PCI_EQE_UPDATE_COUNT	0x80
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define MLXSW_PCI_WQE_SG_ENTRIES	3
718c2ecf20Sopenharmony_ci#define MLXSW_PCI_WQE_TYPE_ETHERNET	0xA
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* pci_wqe_c
748c2ecf20Sopenharmony_ci * If set it indicates that a completion should be reported upon
758c2ecf20Sopenharmony_ci * execution of this descriptor.
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, wqe, c, 0x00, 31, 1);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* pci_wqe_lp
808c2ecf20Sopenharmony_ci * Local Processing, set if packet should be processed by the local
818c2ecf20Sopenharmony_ci * switch hardware:
828c2ecf20Sopenharmony_ci * For Ethernet EMAD (Direct Route and non Direct Route) -
838c2ecf20Sopenharmony_ci * must be set if packet destination is local device
848c2ecf20Sopenharmony_ci * For InfiniBand CTL - must be set if packet destination is local device
858c2ecf20Sopenharmony_ci * Otherwise it must be clear
868c2ecf20Sopenharmony_ci * Local Process packets must not exceed the size of 2K (including payload
878c2ecf20Sopenharmony_ci * and headers).
888c2ecf20Sopenharmony_ci */
898c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, wqe, lp, 0x00, 30, 1);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/* pci_wqe_type
928c2ecf20Sopenharmony_ci * Packet type.
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, wqe, type, 0x00, 23, 4);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* pci_wqe_byte_count
978c2ecf20Sopenharmony_ci * Size of i-th scatter/gather entry, 0 if entry is unused.
988c2ecf20Sopenharmony_ci */
998c2ecf20Sopenharmony_ciMLXSW_ITEM16_INDEXED(pci, wqe, byte_count, 0x02, 0, 14, 0x02, 0x00, false);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/* pci_wqe_address
1028c2ecf20Sopenharmony_ci * Physical address of i-th scatter/gather entry.
1038c2ecf20Sopenharmony_ci * Gather Entries must be 2Byte aligned.
1048c2ecf20Sopenharmony_ci */
1058c2ecf20Sopenharmony_ciMLXSW_ITEM64_INDEXED(pci, wqe, address, 0x08, 0, 64, 0x8, 0x0, false);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cienum mlxsw_pci_cqe_v {
1088c2ecf20Sopenharmony_ci	MLXSW_PCI_CQE_V0,
1098c2ecf20Sopenharmony_ci	MLXSW_PCI_CQE_V1,
1108c2ecf20Sopenharmony_ci	MLXSW_PCI_CQE_V2,
1118c2ecf20Sopenharmony_ci};
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci#define mlxsw_pci_cqe_item_helpers(name, v0, v1, v2)				\
1148c2ecf20Sopenharmony_cistatic inline u32 mlxsw_pci_cqe_##name##_get(enum mlxsw_pci_cqe_v v, char *cqe)	\
1158c2ecf20Sopenharmony_ci{										\
1168c2ecf20Sopenharmony_ci	switch (v) {								\
1178c2ecf20Sopenharmony_ci	default:								\
1188c2ecf20Sopenharmony_ci	case MLXSW_PCI_CQE_V0:							\
1198c2ecf20Sopenharmony_ci		return mlxsw_pci_cqe##v0##_##name##_get(cqe);			\
1208c2ecf20Sopenharmony_ci	case MLXSW_PCI_CQE_V1:							\
1218c2ecf20Sopenharmony_ci		return mlxsw_pci_cqe##v1##_##name##_get(cqe);			\
1228c2ecf20Sopenharmony_ci	case MLXSW_PCI_CQE_V2:							\
1238c2ecf20Sopenharmony_ci		return mlxsw_pci_cqe##v2##_##name##_get(cqe);			\
1248c2ecf20Sopenharmony_ci	}									\
1258c2ecf20Sopenharmony_ci}										\
1268c2ecf20Sopenharmony_cistatic inline void mlxsw_pci_cqe_##name##_set(enum mlxsw_pci_cqe_v v,		\
1278c2ecf20Sopenharmony_ci					      char *cqe, u32 val)		\
1288c2ecf20Sopenharmony_ci{										\
1298c2ecf20Sopenharmony_ci	switch (v) {								\
1308c2ecf20Sopenharmony_ci	default:								\
1318c2ecf20Sopenharmony_ci	case MLXSW_PCI_CQE_V0:							\
1328c2ecf20Sopenharmony_ci		mlxsw_pci_cqe##v0##_##name##_set(cqe, val);			\
1338c2ecf20Sopenharmony_ci		break;								\
1348c2ecf20Sopenharmony_ci	case MLXSW_PCI_CQE_V1:							\
1358c2ecf20Sopenharmony_ci		mlxsw_pci_cqe##v1##_##name##_set(cqe, val);			\
1368c2ecf20Sopenharmony_ci		break;								\
1378c2ecf20Sopenharmony_ci	case MLXSW_PCI_CQE_V2:							\
1388c2ecf20Sopenharmony_ci		mlxsw_pci_cqe##v2##_##name##_set(cqe, val);			\
1398c2ecf20Sopenharmony_ci		break;								\
1408c2ecf20Sopenharmony_ci	}									\
1418c2ecf20Sopenharmony_ci}
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci/* pci_cqe_lag
1448c2ecf20Sopenharmony_ci * Packet arrives from a port which is a LAG
1458c2ecf20Sopenharmony_ci */
1468c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe0, lag, 0x00, 23, 1);
1478c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe12, lag, 0x00, 24, 1);
1488c2ecf20Sopenharmony_cimlxsw_pci_cqe_item_helpers(lag, 0, 12, 12);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/* pci_cqe_system_port/lag_id
1518c2ecf20Sopenharmony_ci * When lag=0: System port on which the packet was received
1528c2ecf20Sopenharmony_ci * When lag=1:
1538c2ecf20Sopenharmony_ci * bits [15:4] LAG ID on which the packet was received
1548c2ecf20Sopenharmony_ci * bits [3:0] sub_port on which the packet was received
1558c2ecf20Sopenharmony_ci */
1568c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe, system_port, 0x00, 0, 16);
1578c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe0, lag_id, 0x00, 4, 12);
1588c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe12, lag_id, 0x00, 0, 16);
1598c2ecf20Sopenharmony_cimlxsw_pci_cqe_item_helpers(lag_id, 0, 12, 12);
1608c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe0, lag_subport, 0x00, 0, 4);
1618c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe12, lag_subport, 0x00, 16, 8);
1628c2ecf20Sopenharmony_cimlxsw_pci_cqe_item_helpers(lag_subport, 0, 12, 12);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/* pci_cqe_wqe_counter
1658c2ecf20Sopenharmony_ci * WQE count of the WQEs completed on the associated dqn
1668c2ecf20Sopenharmony_ci */
1678c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe, wqe_counter, 0x04, 16, 16);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/* pci_cqe_byte_count
1708c2ecf20Sopenharmony_ci * Byte count of received packets including additional two
1718c2ecf20Sopenharmony_ci * Reserved Bytes that are append to the end of the frame.
1728c2ecf20Sopenharmony_ci * Reserved for Send CQE.
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe, byte_count, 0x04, 0, 14);
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/* pci_cqe_trap_id
1778c2ecf20Sopenharmony_ci * Trap ID that captured the packet.
1788c2ecf20Sopenharmony_ci */
1798c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe, trap_id, 0x08, 0, 10);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* pci_cqe_crc
1828c2ecf20Sopenharmony_ci * Length include CRC. Indicates the length field includes
1838c2ecf20Sopenharmony_ci * the packet's CRC.
1848c2ecf20Sopenharmony_ci */
1858c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe0, crc, 0x0C, 8, 1);
1868c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe12, crc, 0x0C, 9, 1);
1878c2ecf20Sopenharmony_cimlxsw_pci_cqe_item_helpers(crc, 0, 12, 12);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci/* pci_cqe_e
1908c2ecf20Sopenharmony_ci * CQE with Error.
1918c2ecf20Sopenharmony_ci */
1928c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe0, e, 0x0C, 7, 1);
1938c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe12, e, 0x00, 27, 1);
1948c2ecf20Sopenharmony_cimlxsw_pci_cqe_item_helpers(e, 0, 12, 12);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci/* pci_cqe_sr
1978c2ecf20Sopenharmony_ci * 1 - Send Queue
1988c2ecf20Sopenharmony_ci * 0 - Receive Queue
1998c2ecf20Sopenharmony_ci */
2008c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe0, sr, 0x0C, 6, 1);
2018c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe12, sr, 0x00, 26, 1);
2028c2ecf20Sopenharmony_cimlxsw_pci_cqe_item_helpers(sr, 0, 12, 12);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* pci_cqe_dqn
2058c2ecf20Sopenharmony_ci * Descriptor Queue (DQ) Number.
2068c2ecf20Sopenharmony_ci */
2078c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe0, dqn, 0x0C, 1, 5);
2088c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe12, dqn, 0x0C, 1, 6);
2098c2ecf20Sopenharmony_cimlxsw_pci_cqe_item_helpers(dqn, 0, 12, 12);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/* pci_cqe_user_def_val_orig_pkt_len
2128c2ecf20Sopenharmony_ci * When trap_id is an ACL: User defined value from policy engine action.
2138c2ecf20Sopenharmony_ci */
2148c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe2, user_def_val_orig_pkt_len, 0x14, 0, 20);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/* pci_cqe_mirror_reason
2178c2ecf20Sopenharmony_ci * Mirror reason.
2188c2ecf20Sopenharmony_ci */
2198c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe2, mirror_reason, 0x18, 24, 8);
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/* pci_cqe_owner
2228c2ecf20Sopenharmony_ci * Ownership bit.
2238c2ecf20Sopenharmony_ci */
2248c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe01, owner, 0x0C, 0, 1);
2258c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, cqe2, owner, 0x1C, 0, 1);
2268c2ecf20Sopenharmony_cimlxsw_pci_cqe_item_helpers(owner, 01, 01, 2);
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/* pci_eqe_event_type
2298c2ecf20Sopenharmony_ci * Event type.
2308c2ecf20Sopenharmony_ci */
2318c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, eqe, event_type, 0x0C, 24, 8);
2328c2ecf20Sopenharmony_ci#define MLXSW_PCI_EQE_EVENT_TYPE_COMP	0x00
2338c2ecf20Sopenharmony_ci#define MLXSW_PCI_EQE_EVENT_TYPE_CMD	0x0A
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci/* pci_eqe_event_sub_type
2368c2ecf20Sopenharmony_ci * Event type.
2378c2ecf20Sopenharmony_ci */
2388c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, eqe, event_sub_type, 0x0C, 16, 8);
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci/* pci_eqe_cqn
2418c2ecf20Sopenharmony_ci * Completion Queue that triggered this EQE.
2428c2ecf20Sopenharmony_ci */
2438c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, eqe, cqn, 0x0C, 8, 7);
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci/* pci_eqe_owner
2468c2ecf20Sopenharmony_ci * Ownership bit.
2478c2ecf20Sopenharmony_ci */
2488c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, eqe, owner, 0x0C, 0, 1);
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/* pci_eqe_cmd_token
2518c2ecf20Sopenharmony_ci * Command completion event - token
2528c2ecf20Sopenharmony_ci */
2538c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, eqe, cmd_token, 0x00, 16, 16);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci/* pci_eqe_cmd_status
2568c2ecf20Sopenharmony_ci * Command completion event - status
2578c2ecf20Sopenharmony_ci */
2588c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, eqe, cmd_status, 0x00, 0, 8);
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci/* pci_eqe_cmd_out_param_h
2618c2ecf20Sopenharmony_ci * Command completion event - output parameter - higher part
2628c2ecf20Sopenharmony_ci */
2638c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, eqe, cmd_out_param_h, 0x04, 0, 32);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/* pci_eqe_cmd_out_param_l
2668c2ecf20Sopenharmony_ci * Command completion event - output parameter - lower part
2678c2ecf20Sopenharmony_ci */
2688c2ecf20Sopenharmony_ciMLXSW_ITEM32(pci, eqe, cmd_out_param_l, 0x08, 0, 32);
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci#endif
271