116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom/*
216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet
316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * driver for Linux.
416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *
516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved.
616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *
716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * This software is available to you under a choice of one of two
816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * licenses.  You may choose to be licensed under the terms of the GNU
916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * General Public License (GPL) Version 2, available from the file
1016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * COPYING in the main directory of this source tree, or the
1116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * OpenIB.org BSD license below:
1216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *
1316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *     Redistribution and use in source and binary forms, with or
1416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *     without modification, are permitted provided that the following
1516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *     conditions are met:
1616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *
1716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *      - Redistributions of source code must retain the above
1816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *        copyright notice, this list of conditions and the following
1916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *        disclaimer.
2016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *
2116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *      - Redistributions in binary form must reproduce the above
2216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *        copyright notice, this list of conditions and the following
2316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *        disclaimer in the documentation and/or other materials
2416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *        provided with the distribution.
2516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *
2616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
3016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * SOFTWARE.
3416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom */
3516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
3616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#ifndef __T4VF_DEFS_H__
3716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define __T4VF_DEFS_H__
3816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
3916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#include "../cxgb4/t4_regs.h"
4016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
4116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom/*
4216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * The VF Register Map.
4316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *
4416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * The Scatter Gather Engine (SGE), Multiport Support module (MPS), PIO Local
4516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * bus module (PL) and CPU Interface Module (CIM) components are mapped via
4616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * the Slice to Module Map Table (see below) in the Physical Function Register
4716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * Map.  The Mail Box Data (MBDATA) range is mapped via the PCI-E Mailbox Base
4816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * and Offset registers in the PF Register Map.  The MBDATA base address is
4916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * quite constrained as it determines the Mailbox Data addresses for both PFs
5016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * and VFs, and therefore must fit in both the VF and PF Register Maps without
5116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * overlapping other registers.
5216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom */
5316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_SGE_BASE_ADDR	0x0000
5416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_MPS_BASE_ADDR	0x0100
5516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_PL_BASE_ADDR	0x0200
5616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_MBDATA_BASE_ADDR	0x0240
5716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_CIM_BASE_ADDR	0x0300
5816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
5916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_REGMAP_START	0x0000
6016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_REGMAP_SIZE	0x0400
6116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
6216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom/*
6316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * There's no hardware limitation which requires that the addresses of the
6416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * Mailbox Data in the fixed CIM PF map and the programmable VF map must
6516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * match.  However, it's a useful convention ...
6616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom */
6716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#if T4VF_MBDATA_BASE_ADDR != CIM_PF_MAILBOX_DATA
6816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#error T4VF_MBDATA_BASE_ADDR must match CIM_PF_MAILBOX_DATA!
6916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#endif
7016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
7116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom/*
7216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * Virtual Function "Slice to Module Map Table" definitions.
7316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom *
7416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * This table allows us to map subsets of the various module register sets
7516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * into the T4VF Register Map.  Each table entry identifies the index of the
7616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * module whose registers are being mapped, the offset within the module's
7716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * register set that the mapping should start at, the limit of the mapping,
7816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * and the offset within the T4VF Register Map to which the module's registers
7916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * are being mapped.  All addresses and qualtities are in terms of 32-bit
8016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * words.  The "limit" value is also in terms of 32-bit words and is equal to
8116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * the last address mapped in the T4VF Register Map 1 (i.e. it's a "<="
8216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * relation rather than a "<").
8316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom */
8416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_MOD_MAP(module, index, first, last) \
8516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom	T4VF_MOD_MAP_##module##_INDEX  = (index), \
8616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom	T4VF_MOD_MAP_##module##_FIRST  = (first), \
8716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom	T4VF_MOD_MAP_##module##_LAST   = (last), \
8816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom	T4VF_MOD_MAP_##module##_OFFSET = ((first)/4), \
8916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom	T4VF_MOD_MAP_##module##_BASE = \
9016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom		(T4VF_##module##_BASE_ADDR/4 + (first)/4), \
9116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom	T4VF_MOD_MAP_##module##_LIMIT = \
9216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom		(T4VF_##module##_BASE_ADDR/4 + (last)/4),
9316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
9416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define SGE_VF_KDOORBELL 0x0
9516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define SGE_VF_GTS 0x4
9616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define MPS_VF_CTL 0x0
9716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define MPS_VF_STAT_RX_VF_ERR_FRAMES_H 0xfc
9816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define PL_VF_WHOAMI 0x0
9916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define CIM_VF_EXT_MAILBOX_CTRL 0x0
10016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define CIM_VF_EXT_MAILBOX_STATUS 0x4
10116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
10216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedomenum {
10316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom    T4VF_MOD_MAP(SGE, 2, SGE_VF_KDOORBELL, SGE_VF_GTS)
10416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom    T4VF_MOD_MAP(MPS, 0, MPS_VF_CTL, MPS_VF_STAT_RX_VF_ERR_FRAMES_H)
10516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom    T4VF_MOD_MAP(PL,  3, PL_VF_WHOAMI, PL_VF_WHOAMI)
10616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom    T4VF_MOD_MAP(CIM, 1, CIM_VF_EXT_MAILBOX_CTRL, CIM_VF_EXT_MAILBOX_STATUS)
10716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom};
10816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
10916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom/*
11016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * There isn't a Slice to Module Map Table entry for the Mailbox Data
11116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * registers, but it's convenient to use similar names as above.  There are 8
11216f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * little-endian 64-bit Mailbox Data registers.  Note that the "instances"
11316f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * value below is in terms of 32-bit words which matches the "word" addressing
11416f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom * space we use above for the Slice to Module Map Space.
11516f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom */
11616f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define NUM_CIM_VF_MAILBOX_DATA_INSTANCES 16
11716f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
11816f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_MBDATA_FIRST	0
11916f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#define T4VF_MBDATA_LAST	((NUM_CIM_VF_MAILBOX_DATA_INSTANCES-1)*4)
12016f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom
12116f8bd4be7541215fe9dd772ed8bccee9a864d9cCasey Leedom#endif /* __T4T4VF_DEFS_H__ */
122