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