iPXE
mcdi.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Driver for Solarflare network controllers and boards
3  *
4  * Written by Martin Habets <mhabets@solarflare.com>
5  *
6  * Copyright 2012-2017 Solarflare Communications Inc.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or any later version.
12  *
13  * You can also choose to distribute this program under the terms of
14  * the Unmodified Binary Distribution Licence (as given in the file
15  * COPYING.UBDL), provided that you have satisfied its requirements.
16  */
17 #ifndef SFC_MCDI_H
18 #define SFC_MCDI_H
19 
20 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
21 
22 #ifndef DIV_ROUND_UP
23 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
24 #endif
25 
26 #define MCDI_SEQ_MASK 0xf
27 
28 /* We expect that 16- and 32-bit fields in MCDI requests and responses
29  * are appropriately aligned, but 64-bit fields are only
30  * 32-bit-aligned. Also, on Siena we must copy to the MC shared
31  * memory strictly 32 bits at a time, so add any necessary padding.
32  */
33 #define MCDI_DECLARE_BUF(_name, _len) \
34  efx_dword_t _name[DIV_ROUND_UP(_len, 4)]
35 #define MCDI_DECLARE_BUF_OUT_OR_ERR(_name, _len) \
36  MCDI_DECLARE_BUF(_name, max_t(size_t, _len, 8))
37 #define _MCDI_PTR(_buf, _offset) \
38  ((u8 *)(_buf) + (_offset))
39 #define MCDI_PTR(_buf, _field) \
40  _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
41 #define _MCDI_CHECK_ALIGN(_ofst, _align) \
42  ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1)))
43 #define _MCDI_DWORD(_buf, _field) \
44  ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2))
45 
46 #define MCDI_WORD(_buf, _field) \
47  ((u16)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
48  le16_to_cpu(*(__force const __le16 *)MCDI_PTR(_buf, _field)))
49 #define MCDI_SET_DWORD(_buf, _field, _value) \
50  EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value)
51 #define MCDI_DWORD(_buf, _field) \
52  EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0)
53 #define MCDI_POPULATE_DWORD_1(_buf, _field, _name1, _value1) \
54  EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), \
55  MC_CMD_ ## _name1, _value1)
56 #define MCDI_POPULATE_DWORD_2(_buf, _field, _name1, _value1, \
57  _name2, _value2) \
58  EFX_POPULATE_DWORD_2(*_MCDI_DWORD(_buf, _field), \
59  MC_CMD_ ## _name1, _value1, \
60  MC_CMD_ ## _name2, _value2)
61 #define MCDI_POPULATE_DWORD_3(_buf, _field, _name1, _value1, \
62  _name2, _value2, _name3, _value3) \
63  EFX_POPULATE_DWORD_3(*_MCDI_DWORD(_buf, _field), \
64  MC_CMD_ ## _name1, _value1, \
65  MC_CMD_ ## _name2, _value2, \
66  MC_CMD_ ## _name3, _value3)
67 #define MCDI_POPULATE_DWORD_4(_buf, _field, _name1, _value1, \
68  _name2, _value2, _name3, _value3, \
69  _name4, _value4) \
70  EFX_POPULATE_DWORD_4(*_MCDI_DWORD(_buf, _field), \
71  MC_CMD_ ## _name1, _value1, \
72  MC_CMD_ ## _name2, _value2, \
73  MC_CMD_ ## _name3, _value3, \
74  MC_CMD_ ## _name4, _value4)
75 #define MCDI_POPULATE_DWORD_5(_buf, _field, _name1, _value1, \
76  _name2, _value2, _name3, _value3, \
77  _name4, _value4, _name5, _value5) \
78  EFX_POPULATE_DWORD_5(*_MCDI_DWORD(_buf, _field), \
79  MC_CMD_ ## _name1, _value1, \
80  MC_CMD_ ## _name2, _value2, \
81  MC_CMD_ ## _name3, _value3, \
82  MC_CMD_ ## _name4, _value4, \
83  MC_CMD_ ## _name5, _value5)
84 #define MCDI_POPULATE_DWORD_6(_buf, _field, _name1, _value1, \
85  _name2, _value2, _name3, _value3, \
86  _name4, _value4, _name5, _value5, \
87  _name6, _value6) \
88  EFX_POPULATE_DWORD_6(*_MCDI_DWORD(_buf, _field), \
89  MC_CMD_ ## _name1, _value1, \
90  MC_CMD_ ## _name2, _value2, \
91  MC_CMD_ ## _name3, _value3, \
92  MC_CMD_ ## _name4, _value4, \
93  MC_CMD_ ## _name5, _value5, \
94  MC_CMD_ ## _name6, _value6)
95 #define MCDI_POPULATE_DWORD_7(_buf, _field, _name1, _value1, \
96  _name2, _value2, _name3, _value3, \
97  _name4, _value4, _name5, _value5, \
98  _name6, _value6, _name7, _value7) \
99  EFX_POPULATE_DWORD_7(*_MCDI_DWORD(_buf, _field), \
100  MC_CMD_ ## _name1, _value1, \
101  MC_CMD_ ## _name2, _value2, \
102  MC_CMD_ ## _name3, _value3, \
103  MC_CMD_ ## _name4, _value4, \
104  MC_CMD_ ## _name5, _value5, \
105  MC_CMD_ ## _name6, _value6, \
106  MC_CMD_ ## _name7, _value7)
107 #define MCDI_SET_QWORD(_buf, _field, _value) \
108  do { \
109  EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \
110  EFX_DWORD_0, (u32)(_value)); \
111  EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \
112  EFX_DWORD_0, (u64)(_value) >> 32); \
113  } while (0)
114 #define MCDI_QWORD(_buf, _field) \
115  (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \
116  (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
117 #define MCDI_FIELD(_ptr, _type, _field) \
118  EFX_EXTRACT_DWORD( \
119  *(efx_dword_t *) \
120  _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
121  MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \
122  (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \
123  MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
124 
125 #define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \
126  (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\
127  + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align))
128 #define MCDI_DECLARE_STRUCT_PTR(_name) \
129  efx_dword_t *_name
130 #define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \
131  ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
132 #define MCDI_VAR_ARRAY_LEN(_len, _field) \
133  min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \
134  ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
135 #define MCDI_ARRAY_WORD(_buf, _field, _index) \
136  (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
137  le16_to_cpu(*(__force const __le16 *) \
138  _MCDI_ARRAY_PTR(_buf, _field, _index, 2)))
139 #define _MCDI_ARRAY_DWORD(_buf, _field, _index) \
140  (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \
141  (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
142 #define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \
143  EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \
144  EFX_DWORD_0, _value)
145 #define MCDI_ARRAY_DWORD(_buf, _field, _index) \
146  EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
147 #define _MCDI_ARRAY_QWORD(_buf, _field, _index) \
148  (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \
149  (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
150 #define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \
151  do { \
152  EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\
153  EFX_DWORD_0, (u32)(_value)); \
154  EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\
155  EFX_DWORD_0, (u64)(_value) >> 32); \
156  } while (0)
157 #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \
158  MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \
159  _type ## _TYPEDEF, _field2)
160 
161 #define MCDI_EVENT_FIELD(_ev, _field) \
162  EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
163 
164 #endif
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)