xref: /freebsd/sys/dev/mxge/mcp_gen_header.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1b2fc195eSAndrew Gallatin /*******************************************************************************
2*4d846d26SWarner Losh SPDX-License-Identifier: BSD-2-Clause
3b2fc195eSAndrew Gallatin 
4eb8e82f5SAndrew Gallatin Copyright (c) 2006-2007, Myricom Inc.
5b2fc195eSAndrew Gallatin All rights reserved.
6b2fc195eSAndrew Gallatin 
7b2fc195eSAndrew Gallatin Redistribution and use in source and binary forms, with or without
8b2fc195eSAndrew Gallatin modification, are permitted provided that the following conditions are met:
9b2fc195eSAndrew Gallatin 
10b2fc195eSAndrew Gallatin  1. Redistributions of source code must retain the above copyright notice,
11b2fc195eSAndrew Gallatin     this list of conditions and the following disclaimer.
12b2fc195eSAndrew Gallatin 
13eb8e82f5SAndrew Gallatin  2. Neither the name of the Myricom Inc, nor the names of its
14b2fc195eSAndrew Gallatin     contributors may be used to endorse or promote products derived from
15b2fc195eSAndrew Gallatin     this software without specific prior written permission.
16b2fc195eSAndrew Gallatin 
17b2fc195eSAndrew Gallatin THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18b2fc195eSAndrew Gallatin AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19b2fc195eSAndrew Gallatin IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20b2fc195eSAndrew Gallatin ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21b2fc195eSAndrew Gallatin LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22b2fc195eSAndrew Gallatin CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23b2fc195eSAndrew Gallatin SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24b2fc195eSAndrew Gallatin INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25b2fc195eSAndrew Gallatin CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26b2fc195eSAndrew Gallatin ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27b2fc195eSAndrew Gallatin POSSIBILITY OF SUCH DAMAGE.
28b2fc195eSAndrew Gallatin 
29b2fc195eSAndrew Gallatin $FreeBSD$
30b2fc195eSAndrew Gallatin ***************************************************************************/
31b2fc195eSAndrew Gallatin 
32b2fc195eSAndrew Gallatin #ifndef _mcp_gen_header_h
33b2fc195eSAndrew Gallatin #define _mcp_gen_header_h
34b2fc195eSAndrew Gallatin 
35b2fc195eSAndrew Gallatin /* this file define a standard header used as a first entry point to
36b2fc195eSAndrew Gallatin    exchange information between firmware/driver and driver.  The
37b2fc195eSAndrew Gallatin    header structure can be anywhere in the mcp. It will usually be in
38b2fc195eSAndrew Gallatin    the .data section, because some fields needs to be initialized at
39b2fc195eSAndrew Gallatin    compile time.
40b2fc195eSAndrew Gallatin    The 32bit word at offset MX_HEADER_PTR_OFFSET in the mcp must
41b2fc195eSAndrew Gallatin    contains the location of the header.
42b2fc195eSAndrew Gallatin 
43b2fc195eSAndrew Gallatin    Typically a MCP will start with the following:
44b2fc195eSAndrew Gallatin    .text
45b2fc195eSAndrew Gallatin      .space 52    ! to help catch MEMORY_INT errors
46b2fc195eSAndrew Gallatin      bt start     ! jump to real code
47b2fc195eSAndrew Gallatin      nop
48b2fc195eSAndrew Gallatin      .long _gen_mcp_header
49b2fc195eSAndrew Gallatin 
50b2fc195eSAndrew Gallatin    The source will have a definition like:
51b2fc195eSAndrew Gallatin 
52b2fc195eSAndrew Gallatin    mcp_gen_header_t gen_mcp_header = {
53b2fc195eSAndrew Gallatin       .header_length = sizeof(mcp_gen_header_t),
54b2fc195eSAndrew Gallatin       .mcp_type = MCP_TYPE_XXX,
55b2fc195eSAndrew Gallatin       .version = "something $Id: mcp_gen_header.h,v 1.1 2005/12/23 02:10:44 gallatin Exp $",
56b2fc195eSAndrew Gallatin       .mcp_globals = (unsigned)&Globals
57b2fc195eSAndrew Gallatin    };
58b2fc195eSAndrew Gallatin */
59b2fc195eSAndrew Gallatin 
60b2fc195eSAndrew Gallatin #define MCP_HEADER_PTR_OFFSET  0x3c
61b2fc195eSAndrew Gallatin 
62b2fc195eSAndrew Gallatin #define MCP_TYPE_MX 0x4d582020 /* "MX  " */
63b2fc195eSAndrew Gallatin #define MCP_TYPE_PCIE 0x70636965 /* "PCIE" pcie-only MCP */
64b2fc195eSAndrew Gallatin #define MCP_TYPE_ETH 0x45544820 /* "ETH " */
65b2fc195eSAndrew Gallatin #define MCP_TYPE_MCP0 0x4d435030 /* "MCP0" */
66b2fc195eSAndrew Gallatin 
67b2fc195eSAndrew Gallatin typedef struct mcp_gen_header {
68b2fc195eSAndrew Gallatin   /* the first 4 fields are filled at compile time */
69b2fc195eSAndrew Gallatin   unsigned header_length;
70b2fc195eSAndrew Gallatin   unsigned mcp_type;
71b2fc195eSAndrew Gallatin   char version[128];
72b2fc195eSAndrew Gallatin   unsigned mcp_globals; /* pointer to mcp-type specific structure */
73b2fc195eSAndrew Gallatin 
74b2fc195eSAndrew Gallatin   /* filled by the MCP at run-time */
75b2fc195eSAndrew Gallatin   unsigned sram_size;
76b2fc195eSAndrew Gallatin   unsigned string_specs;  /* either the original STRING_SPECS or a superset */
77b2fc195eSAndrew Gallatin   unsigned string_specs_len;
78b2fc195eSAndrew Gallatin 
79b2fc195eSAndrew Gallatin   /* Fields above this comment are guaranteed to be present.
80b2fc195eSAndrew Gallatin 
81b2fc195eSAndrew Gallatin      Fields below this comment are extensions added in later versions
82b2fc195eSAndrew Gallatin      of this struct, drivers should compare the header_length against
83b2fc195eSAndrew Gallatin      offsetof(field) to check wether a given MCP implements them.
84b2fc195eSAndrew Gallatin 
85b2fc195eSAndrew Gallatin      Never remove any field.  Keep everything naturally align.
86b2fc195eSAndrew Gallatin   */
87b2fc195eSAndrew Gallatin } mcp_gen_header_t;
88b2fc195eSAndrew Gallatin 
89b2fc195eSAndrew Gallatin /* Macro to create a simple mcp header */
90b2fc195eSAndrew Gallatin #define MCP_GEN_HEADER_DECL(type, version_str, global_ptr)	\
91b2fc195eSAndrew Gallatin   struct mcp_gen_header mcp_gen_header = {			\
92b2fc195eSAndrew Gallatin     sizeof (struct mcp_gen_header),				\
93b2fc195eSAndrew Gallatin     (type),							\
94b2fc195eSAndrew Gallatin     version_str,						\
95b2fc195eSAndrew Gallatin     (global_ptr),						\
96b2fc195eSAndrew Gallatin     SRAM_SIZE,							\
97b2fc195eSAndrew Gallatin     (unsigned int) STRING_SPECS,				\
98b2fc195eSAndrew Gallatin     256								\
99b2fc195eSAndrew Gallatin   }
100b2fc195eSAndrew Gallatin 
101b2fc195eSAndrew Gallatin #endif /* _mcp_gen_header_h */
102