Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/mlx5_core: Use hardware registers description header file

Add an auto generated header file that describes hardware registers along with
set of macros that set/get values. The macros do static checks to avoid
overflow, handle endianess, and overall provide a clean way to code commands.
Currently the header file is small and we will add structs as we make use of
the macros.
A few commands were removed from the commands enum since they are not supported
currently and will be added when support is available.

Signed-off-by: Eli Cohen <eli@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Eli Cohen and committed by
David S. Miller
d29b796a c7a08ac7

+188 -114
-36
drivers/net/ethernet/mellanox/mlx5/core/cmd.c
··· 357 357 case MLX5_CMD_OP_2ERR_QP: 358 358 return "2ERR_QP"; 359 359 360 - case MLX5_CMD_OP_RTS2SQD_QP: 361 - return "RTS2SQD_QP"; 362 - 363 - case MLX5_CMD_OP_SQD2RTS_QP: 364 - return "SQD2RTS_QP"; 365 - 366 360 case MLX5_CMD_OP_2RST_QP: 367 361 return "2RST_QP"; 368 362 369 363 case MLX5_CMD_OP_QUERY_QP: 370 364 return "QUERY_QP"; 371 - 372 - case MLX5_CMD_OP_CONF_SQP: 373 - return "CONF_SQP"; 374 365 375 366 case MLX5_CMD_OP_MAD_IFC: 376 367 return "MAD_IFC"; ··· 369 378 case MLX5_CMD_OP_INIT2INIT_QP: 370 379 return "INIT2INIT_QP"; 371 380 372 - case MLX5_CMD_OP_SUSPEND_QP: 373 - return "SUSPEND_QP"; 374 - 375 - case MLX5_CMD_OP_UNSUSPEND_QP: 376 - return "UNSUSPEND_QP"; 377 - 378 - case MLX5_CMD_OP_SQD2SQD_QP: 379 - return "SQD2SQD_QP"; 380 - 381 - case MLX5_CMD_OP_ALLOC_QP_COUNTER_SET: 382 - return "ALLOC_QP_COUNTER_SET"; 383 - 384 - case MLX5_CMD_OP_DEALLOC_QP_COUNTER_SET: 385 - return "DEALLOC_QP_COUNTER_SET"; 386 - 387 - case MLX5_CMD_OP_QUERY_QP_COUNTER_SET: 388 - return "QUERY_QP_COUNTER_SET"; 389 - 390 381 case MLX5_CMD_OP_CREATE_PSV: 391 382 return "CREATE_PSV"; 392 383 393 384 case MLX5_CMD_OP_DESTROY_PSV: 394 385 return "DESTROY_PSV"; 395 - 396 - case MLX5_CMD_OP_QUERY_PSV: 397 - return "QUERY_PSV"; 398 - 399 - case MLX5_CMD_OP_QUERY_SIG_RULE_TABLE: 400 - return "QUERY_SIG_RULE_TABLE"; 401 - 402 - case MLX5_CMD_OP_QUERY_BLOCK_SIZE_TABLE: 403 - return "QUERY_BLOCK_SIZE_TABLE"; 404 386 405 387 case MLX5_CMD_OP_CREATE_SRQ: 406 388 return "CREATE_SRQ";
-3
drivers/net/ethernet/mellanox/mlx5/core/qp.c
··· 184 184 [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, 185 185 [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, 186 186 [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTS2RTS_QP, 187 - [MLX5_QP_STATE_SQD] = MLX5_CMD_OP_RTS2SQD_QP, 188 187 }, 189 188 [MLX5_QP_STATE_SQD] = { 190 189 [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, 191 190 [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, 192 - [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_SQD2RTS_QP, 193 - [MLX5_QP_STATE_SQD] = MLX5_CMD_OP_SQD2SQD_QP, 194 191 }, 195 192 [MLX5_QP_STATE_SQER] = { 196 193 [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP,
+44
include/linux/mlx5/device.h
··· 44 44 #error Host endianness not defined 45 45 #endif 46 46 47 + /* helper macros */ 48 + #define __mlx5_nullp(typ) ((struct mlx5_ifc_##typ##_bits *)0) 49 + #define __mlx5_bit_sz(typ, fld) sizeof(__mlx5_nullp(typ)->fld) 50 + #define __mlx5_bit_off(typ, fld) ((unsigned)(unsigned long)(&(__mlx5_nullp(typ)->fld))) 51 + #define __mlx5_dw_off(typ, fld) (__mlx5_bit_off(typ, fld) / 32) 52 + #define __mlx5_64_off(typ, fld) (__mlx5_bit_off(typ, fld) / 64) 53 + #define __mlx5_dw_bit_off(typ, fld) (32 - __mlx5_bit_sz(typ, fld) - (__mlx5_bit_off(typ, fld) & 0x1f)) 54 + #define __mlx5_mask(typ, fld) ((u32)((1ull << __mlx5_bit_sz(typ, fld)) - 1)) 55 + #define __mlx5_dw_mask(typ, fld) (__mlx5_mask(typ, fld) << __mlx5_dw_bit_off(typ, fld)) 56 + #define __mlx5_st_sz_bits(typ) sizeof(struct mlx5_ifc_##typ##_bits) 57 + 58 + #define MLX5_FLD_SZ_BYTES(typ, fld) (__mlx5_bit_sz(typ, fld) / 8) 59 + #define MLX5_ST_SZ_BYTES(typ) (sizeof(struct mlx5_ifc_##typ##_bits) / 8) 60 + #define MLX5_ST_SZ_DW(typ) (sizeof(struct mlx5_ifc_##typ##_bits) / 32) 61 + #define MLX5_BYTE_OFF(typ, fld) (__mlx5_bit_off(typ, fld) / 8) 62 + #define MLX5_ADDR_OF(typ, p, fld) ((char *)(p) + MLX5_BYTE_OFF(typ, fld)) 63 + 64 + /* insert a value to a struct */ 65 + #define MLX5_SET(typ, p, fld, v) do { \ 66 + BUILD_BUG_ON(__mlx5_st_sz_bits(typ) % 32); \ 67 + *((__be32 *)(p) + __mlx5_dw_off(typ, fld)) = \ 68 + cpu_to_be32((be32_to_cpu(*((__be32 *)(p) + __mlx5_dw_off(typ, fld))) & \ 69 + (~__mlx5_dw_mask(typ, fld))) | (((v) & __mlx5_mask(typ, fld)) \ 70 + << __mlx5_dw_bit_off(typ, fld))); \ 71 + } while (0) 72 + 73 + #define MLX5_GET(typ, p, fld) ((be32_to_cpu(*((__be32 *)(p) +\ 74 + __mlx5_dw_off(typ, fld))) >> __mlx5_dw_bit_off(typ, fld)) & \ 75 + __mlx5_mask(typ, fld)) 76 + 77 + #define MLX5_GET_PR(typ, p, fld) ({ \ 78 + u32 ___t = MLX5_GET(typ, p, fld); \ 79 + pr_debug(#fld " = 0x%x\n", ___t); \ 80 + ___t; \ 81 + }) 82 + 83 + #define MLX5_SET64(typ, p, fld, v) do { \ 84 + BUILD_BUG_ON(__mlx5_bit_sz(typ, fld) != 64); \ 85 + BUILD_BUG_ON(__mlx5_bit_off(typ, fld) % 64); \ 86 + *((__be64 *)(p) + __mlx5_64_off(typ, fld)) = cpu_to_be64(v); \ 87 + } while (0) 88 + 89 + #define MLX5_GET64(typ, p, fld) be64_to_cpu(*((__be64 *)(p) + __mlx5_64_off(typ, fld))) 90 + 47 91 enum { 48 92 MLX5_MAX_COMMANDS = 32, 49 93 MLX5_CMD_DATA_BLOCK_SIZE = 512,
+1 -75
include/linux/mlx5/driver.h
··· 44 44 45 45 #include <linux/mlx5/device.h> 46 46 #include <linux/mlx5/doorbell.h> 47 + #include <linux/mlx5/mlx5_ifc.h> 47 48 48 49 enum { 49 50 MLX5_BOARD_ID_LEN = 64, ··· 97 96 MLX5_ATOMIC_MODE_64B = 6 << 16, 98 97 MLX5_ATOMIC_MODE_128B = 7 << 16, 99 98 MLX5_ATOMIC_MODE_256B = 8 << 16, 100 - }; 101 - 102 - enum { 103 - MLX5_CMD_OP_QUERY_HCA_CAP = 0x100, 104 - MLX5_CMD_OP_QUERY_ADAPTER = 0x101, 105 - MLX5_CMD_OP_INIT_HCA = 0x102, 106 - MLX5_CMD_OP_TEARDOWN_HCA = 0x103, 107 - MLX5_CMD_OP_ENABLE_HCA = 0x104, 108 - MLX5_CMD_OP_DISABLE_HCA = 0x105, 109 - MLX5_CMD_OP_QUERY_PAGES = 0x107, 110 - MLX5_CMD_OP_MANAGE_PAGES = 0x108, 111 - MLX5_CMD_OP_SET_HCA_CAP = 0x109, 112 - 113 - MLX5_CMD_OP_CREATE_MKEY = 0x200, 114 - MLX5_CMD_OP_QUERY_MKEY = 0x201, 115 - MLX5_CMD_OP_DESTROY_MKEY = 0x202, 116 - MLX5_CMD_OP_QUERY_SPECIAL_CONTEXTS = 0x203, 117 - 118 - MLX5_CMD_OP_CREATE_EQ = 0x301, 119 - MLX5_CMD_OP_DESTROY_EQ = 0x302, 120 - MLX5_CMD_OP_QUERY_EQ = 0x303, 121 - 122 - MLX5_CMD_OP_CREATE_CQ = 0x400, 123 - MLX5_CMD_OP_DESTROY_CQ = 0x401, 124 - MLX5_CMD_OP_QUERY_CQ = 0x402, 125 - MLX5_CMD_OP_MODIFY_CQ = 0x403, 126 - 127 - MLX5_CMD_OP_CREATE_QP = 0x500, 128 - MLX5_CMD_OP_DESTROY_QP = 0x501, 129 - MLX5_CMD_OP_RST2INIT_QP = 0x502, 130 - MLX5_CMD_OP_INIT2RTR_QP = 0x503, 131 - MLX5_CMD_OP_RTR2RTS_QP = 0x504, 132 - MLX5_CMD_OP_RTS2RTS_QP = 0x505, 133 - MLX5_CMD_OP_SQERR2RTS_QP = 0x506, 134 - MLX5_CMD_OP_2ERR_QP = 0x507, 135 - MLX5_CMD_OP_RTS2SQD_QP = 0x508, 136 - MLX5_CMD_OP_SQD2RTS_QP = 0x509, 137 - MLX5_CMD_OP_2RST_QP = 0x50a, 138 - MLX5_CMD_OP_QUERY_QP = 0x50b, 139 - MLX5_CMD_OP_CONF_SQP = 0x50c, 140 - MLX5_CMD_OP_MAD_IFC = 0x50d, 141 - MLX5_CMD_OP_INIT2INIT_QP = 0x50e, 142 - MLX5_CMD_OP_SUSPEND_QP = 0x50f, 143 - MLX5_CMD_OP_UNSUSPEND_QP = 0x510, 144 - MLX5_CMD_OP_SQD2SQD_QP = 0x511, 145 - MLX5_CMD_OP_ALLOC_QP_COUNTER_SET = 0x512, 146 - MLX5_CMD_OP_DEALLOC_QP_COUNTER_SET = 0x513, 147 - MLX5_CMD_OP_QUERY_QP_COUNTER_SET = 0x514, 148 - 149 - MLX5_CMD_OP_CREATE_PSV = 0x600, 150 - MLX5_CMD_OP_DESTROY_PSV = 0x601, 151 - MLX5_CMD_OP_QUERY_PSV = 0x602, 152 - MLX5_CMD_OP_QUERY_SIG_RULE_TABLE = 0x603, 153 - MLX5_CMD_OP_QUERY_BLOCK_SIZE_TABLE = 0x604, 154 - 155 - MLX5_CMD_OP_CREATE_SRQ = 0x700, 156 - MLX5_CMD_OP_DESTROY_SRQ = 0x701, 157 - MLX5_CMD_OP_QUERY_SRQ = 0x702, 158 - MLX5_CMD_OP_ARM_RQ = 0x703, 159 - MLX5_CMD_OP_RESIZE_SRQ = 0x704, 160 - 161 - MLX5_CMD_OP_ALLOC_PD = 0x800, 162 - MLX5_CMD_OP_DEALLOC_PD = 0x801, 163 - MLX5_CMD_OP_ALLOC_UAR = 0x802, 164 - MLX5_CMD_OP_DEALLOC_UAR = 0x803, 165 - 166 - MLX5_CMD_OP_ATTACH_TO_MCG = 0x806, 167 - MLX5_CMD_OP_DETACH_FROM_MCG = 0x807, 168 - 169 - 170 - MLX5_CMD_OP_ALLOC_XRCD = 0x80e, 171 - MLX5_CMD_OP_DEALLOC_XRCD = 0x80f, 172 - 173 - MLX5_CMD_OP_ACCESS_REG = 0x805, 174 - MLX5_CMD_OP_MAX = 0x810, 175 99 }; 176 100 177 101 enum {
+143
include/linux/mlx5/mlx5_ifc.h
··· 1 + /* 2 + * Copyright (c) 2014, Mellanox Technologies inc. All rights reserved. 3 + * 4 + * This software is available to you under a choice of one of two 5 + * licenses. You may choose to be licensed under the terms of the GNU 6 + * General Public License (GPL) Version 2, available from the file 7 + * COPYING in the main directory of this source tree, or the 8 + * OpenIB.org BSD license below: 9 + * 10 + * Redistribution and use in source and binary forms, with or 11 + * without modification, are permitted provided that the following 12 + * conditions are met: 13 + * 14 + * - Redistributions of source code must retain the above 15 + * copyright notice, this list of conditions and the following 16 + * disclaimer. 17 + * 18 + * - Redistributions in binary form must reproduce the above 19 + * copyright notice, this list of conditions and the following 20 + * disclaimer in the documentation and/or other materials 21 + * provided with the distribution. 22 + * 23 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 + * SOFTWARE. 31 + */ 32 + 33 + #ifndef MLX5_IFC_H 34 + #define MLX5_IFC_H 35 + 36 + enum { 37 + MLX5_CMD_OP_QUERY_HCA_CAP = 0x100, 38 + MLX5_CMD_OP_QUERY_ADAPTER = 0x101, 39 + MLX5_CMD_OP_INIT_HCA = 0x102, 40 + MLX5_CMD_OP_TEARDOWN_HCA = 0x103, 41 + MLX5_CMD_OP_ENABLE_HCA = 0x104, 42 + MLX5_CMD_OP_DISABLE_HCA = 0x105, 43 + MLX5_CMD_OP_QUERY_PAGES = 0x107, 44 + MLX5_CMD_OP_MANAGE_PAGES = 0x108, 45 + MLX5_CMD_OP_SET_HCA_CAP = 0x109, 46 + MLX5_CMD_OP_CREATE_MKEY = 0x200, 47 + MLX5_CMD_OP_QUERY_MKEY = 0x201, 48 + MLX5_CMD_OP_DESTROY_MKEY = 0x202, 49 + MLX5_CMD_OP_QUERY_SPECIAL_CONTEXTS = 0x203, 50 + MLX5_CMD_OP_PAGE_FAULT_RESUME = 0x204, 51 + MLX5_CMD_OP_CREATE_EQ = 0x301, 52 + MLX5_CMD_OP_DESTROY_EQ = 0x302, 53 + MLX5_CMD_OP_QUERY_EQ = 0x303, 54 + MLX5_CMD_OP_GEN_EQE = 0x304, 55 + MLX5_CMD_OP_CREATE_CQ = 0x400, 56 + MLX5_CMD_OP_DESTROY_CQ = 0x401, 57 + MLX5_CMD_OP_QUERY_CQ = 0x402, 58 + MLX5_CMD_OP_MODIFY_CQ = 0x403, 59 + MLX5_CMD_OP_CREATE_QP = 0x500, 60 + MLX5_CMD_OP_DESTROY_QP = 0x501, 61 + MLX5_CMD_OP_RST2INIT_QP = 0x502, 62 + MLX5_CMD_OP_INIT2RTR_QP = 0x503, 63 + MLX5_CMD_OP_RTR2RTS_QP = 0x504, 64 + MLX5_CMD_OP_RTS2RTS_QP = 0x505, 65 + MLX5_CMD_OP_SQERR2RTS_QP = 0x506, 66 + MLX5_CMD_OP_2ERR_QP = 0x507, 67 + MLX5_CMD_OP_2RST_QP = 0x50a, 68 + MLX5_CMD_OP_QUERY_QP = 0x50b, 69 + MLX5_CMD_OP_INIT2INIT_QP = 0x50e, 70 + MLX5_CMD_OP_CREATE_PSV = 0x600, 71 + MLX5_CMD_OP_DESTROY_PSV = 0x601, 72 + MLX5_CMD_OP_CREATE_SRQ = 0x700, 73 + MLX5_CMD_OP_DESTROY_SRQ = 0x701, 74 + MLX5_CMD_OP_QUERY_SRQ = 0x702, 75 + MLX5_CMD_OP_ARM_RQ = 0x703, 76 + MLX5_CMD_OP_RESIZE_SRQ = 0x704, 77 + MLX5_CMD_OP_CREATE_DCT = 0x710, 78 + MLX5_CMD_OP_DESTROY_DCT = 0x711, 79 + MLX5_CMD_OP_DRAIN_DCT = 0x712, 80 + MLX5_CMD_OP_QUERY_DCT = 0x713, 81 + MLX5_CMD_OP_ARM_DCT_FOR_KEY_VIOLATION = 0x714, 82 + MLX5_CMD_OP_QUERY_VPORT_STATE = 0x750, 83 + MLX5_CMD_OP_MODIFY_VPORT_STATE = 0x751, 84 + MLX5_CMD_OP_QUERY_ESW_VPORT_CONTEXT = 0x752, 85 + MLX5_CMD_OP_MODIFY_ESW_VPORT_CONTEXT = 0x753, 86 + MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT = 0x754, 87 + MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT = 0x755, 88 + MLX5_CMD_OP_QUERY_RCOE_ADDRESS = 0x760, 89 + MLX5_CMD_OP_SET_ROCE_ADDRESS = 0x761, 90 + MLX5_CMD_OP_QUERY_VPORT_COUNTER = 0x770, 91 + MLX5_CMD_OP_ALLOC_Q_COUNTER = 0x771, 92 + MLX5_CMD_OP_DEALLOC_Q_COUNTER = 0x772, 93 + MLX5_CMD_OP_QUERY_Q_COUNTER = 0x773, 94 + MLX5_CMD_OP_ALLOC_PD = 0x800, 95 + MLX5_CMD_OP_DEALLOC_PD = 0x801, 96 + MLX5_CMD_OP_ALLOC_UAR = 0x802, 97 + MLX5_CMD_OP_DEALLOC_UAR = 0x803, 98 + MLX5_CMD_OP_CONFIG_INT_MODERATION = 0x804, 99 + MLX5_CMD_OP_ACCESS_REG = 0x805, 100 + MLX5_CMD_OP_ATTACH_TO_MCG = 0x806, 101 + MLX5_CMD_OP_DETACH_FROM_MCG = 0x807, 102 + MLX5_CMD_OP_GET_DROPPED_PACKET_LOG = 0x80a, 103 + MLX5_CMD_OP_MAD_IFC = 0x50d, 104 + MLX5_CMD_OP_QUERY_MAD_DEMUX = 0x80b, 105 + MLX5_CMD_OP_SET_MAD_DEMUX = 0x80c, 106 + MLX5_CMD_OP_NOP = 0x80d, 107 + MLX5_CMD_OP_ALLOC_XRCD = 0x80e, 108 + MLX5_CMD_OP_DEALLOC_XRCD = 0x80f, 109 + MLX5_CMD_OP_SET_BURST_SIZE = 0x812, 110 + MLX5_CMD_OP_QUERY_BURST_SZIE = 0x813, 111 + MLX5_CMD_OP_ACTIVATE_TRACER = 0x814, 112 + MLX5_CMD_OP_DEACTIVATE_TRACER = 0x815, 113 + MLX5_CMD_OP_CREATE_SNIFFER_RULE = 0x820, 114 + MLX5_CMD_OP_DESTROY_SNIFFER_RULE = 0x821, 115 + MLX5_CMD_OP_QUERY_CONG_PARAMS = 0x822, 116 + MLX5_CMD_OP_MODIFY_CONG_PARAMS = 0x823, 117 + MLX5_CMD_OP_QUERY_CONG_STATISTICS = 0x824, 118 + MLX5_CMD_OP_CREATE_TIR = 0x900, 119 + MLX5_CMD_OP_MODIFY_TIR = 0x901, 120 + MLX5_CMD_OP_DESTROY_TIR = 0x902, 121 + MLX5_CMD_OP_QUERY_TIR = 0x903, 122 + MLX5_CMD_OP_CREATE_TIS = 0x912, 123 + MLX5_CMD_OP_MODIFY_TIS = 0x913, 124 + MLX5_CMD_OP_DESTROY_TIS = 0x914, 125 + MLX5_CMD_OP_QUERY_TIS = 0x915, 126 + MLX5_CMD_OP_CREATE_SQ = 0x904, 127 + MLX5_CMD_OP_MODIFY_SQ = 0x905, 128 + MLX5_CMD_OP_DESTROY_SQ = 0x906, 129 + MLX5_CMD_OP_QUERY_SQ = 0x907, 130 + MLX5_CMD_OP_CREATE_RQ = 0x908, 131 + MLX5_CMD_OP_MODIFY_RQ = 0x909, 132 + MLX5_CMD_OP_DESTROY_RQ = 0x90a, 133 + MLX5_CMD_OP_QUERY_RQ = 0x90b, 134 + MLX5_CMD_OP_CREATE_RMP = 0x90c, 135 + MLX5_CMD_OP_MODIFY_RMP = 0x90d, 136 + MLX5_CMD_OP_DESTROY_RMP = 0x90e, 137 + MLX5_CMD_OP_QUERY_RMP = 0x90f, 138 + MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY = 0x910, 139 + MLX5_CMD_OP_QUERY_FLOW_TABLE_ENTRY = 0x911, 140 + MLX5_CMD_OP_MAX = 0x911 141 + }; 142 + 143 + #endif /* MLX5_IFC_H */