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