1e126ba97SEli Cohen /* 2302bdf68SSaeed Mahameed * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. 3e126ba97SEli Cohen * 4e126ba97SEli Cohen * This software is available to you under a choice of one of two 5e126ba97SEli Cohen * licenses. You may choose to be licensed under the terms of the GNU 6e126ba97SEli Cohen * General Public License (GPL) Version 2, available from the file 7e126ba97SEli Cohen * COPYING in the main directory of this source tree, or the 8e126ba97SEli Cohen * OpenIB.org BSD license below: 9e126ba97SEli Cohen * 10e126ba97SEli Cohen * Redistribution and use in source and binary forms, with or 11e126ba97SEli Cohen * without modification, are permitted provided that the following 12e126ba97SEli Cohen * conditions are met: 13e126ba97SEli Cohen * 14e126ba97SEli Cohen * - Redistributions of source code must retain the above 15e126ba97SEli Cohen * copyright notice, this list of conditions and the following 16e126ba97SEli Cohen * disclaimer. 17e126ba97SEli Cohen * 18e126ba97SEli Cohen * - Redistributions in binary form must reproduce the above 19e126ba97SEli Cohen * copyright notice, this list of conditions and the following 20e126ba97SEli Cohen * disclaimer in the documentation and/or other materials 21e126ba97SEli Cohen * provided with the distribution. 22e126ba97SEli Cohen * 23e126ba97SEli Cohen * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24e126ba97SEli Cohen * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25e126ba97SEli Cohen * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26e126ba97SEli Cohen * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27e126ba97SEli Cohen * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28e126ba97SEli Cohen * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29e126ba97SEli Cohen * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30e126ba97SEli Cohen * SOFTWARE. 31e126ba97SEli Cohen */ 32e126ba97SEli Cohen 33e126ba97SEli Cohen #include <linux/mlx5/driver.h> 34e126ba97SEli Cohen #include <linux/mlx5/cmd.h> 35e126ba97SEli Cohen #include <linux/module.h> 36e126ba97SEli Cohen #include "mlx5_core.h" 37e126ba97SEli Cohen 387cf7fa52SMajd Dibbiny static int mlx5_cmd_query_adapter(struct mlx5_core_dev *dev, u32 *out, 397cf7fa52SMajd Dibbiny int outlen) 40e126ba97SEli Cohen { 41c4f287c4SSaeed Mahameed u32 in[MLX5_ST_SZ_DW(query_adapter_in)] = {0}; 42211e6c80SMajd Dibbiny 43211e6c80SMajd Dibbiny MLX5_SET(query_adapter_in, in, opcode, MLX5_CMD_OP_QUERY_ADAPTER); 44c4f287c4SSaeed Mahameed return mlx5_cmd_exec(dev, in, sizeof(in), out, outlen); 45211e6c80SMajd Dibbiny } 46211e6c80SMajd Dibbiny 47211e6c80SMajd Dibbiny int mlx5_query_board_id(struct mlx5_core_dev *dev) 48211e6c80SMajd Dibbiny { 49211e6c80SMajd Dibbiny u32 *out; 50211e6c80SMajd Dibbiny int outlen = MLX5_ST_SZ_BYTES(query_adapter_out); 51e126ba97SEli Cohen int err; 52e126ba97SEli Cohen 53211e6c80SMajd Dibbiny out = kzalloc(outlen, GFP_KERNEL); 54e126ba97SEli Cohen if (!out) 55e126ba97SEli Cohen return -ENOMEM; 56e126ba97SEli Cohen 57211e6c80SMajd Dibbiny err = mlx5_cmd_query_adapter(dev, out, outlen); 58e126ba97SEli Cohen if (err) 59211e6c80SMajd Dibbiny goto out; 60e126ba97SEli Cohen 61211e6c80SMajd Dibbiny memcpy(dev->board_id, 62211e6c80SMajd Dibbiny MLX5_ADDR_OF(query_adapter_out, out, 63211e6c80SMajd Dibbiny query_adapter_struct.vsd_contd_psid), 64211e6c80SMajd Dibbiny MLX5_FLD_SZ_BYTES(query_adapter_out, 65211e6c80SMajd Dibbiny query_adapter_struct.vsd_contd_psid)); 66e126ba97SEli Cohen 67211e6c80SMajd Dibbiny out: 68e126ba97SEli Cohen kfree(out); 69e126ba97SEli Cohen return err; 70e126ba97SEli Cohen } 71e126ba97SEli Cohen 72211e6c80SMajd Dibbiny int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id) 73211e6c80SMajd Dibbiny { 74211e6c80SMajd Dibbiny u32 *out; 75211e6c80SMajd Dibbiny int outlen = MLX5_ST_SZ_BYTES(query_adapter_out); 76211e6c80SMajd Dibbiny int err; 77211e6c80SMajd Dibbiny 78211e6c80SMajd Dibbiny out = kzalloc(outlen, GFP_KERNEL); 79211e6c80SMajd Dibbiny if (!out) 80211e6c80SMajd Dibbiny return -ENOMEM; 81211e6c80SMajd Dibbiny 82211e6c80SMajd Dibbiny err = mlx5_cmd_query_adapter(mdev, out, outlen); 83211e6c80SMajd Dibbiny if (err) 84211e6c80SMajd Dibbiny goto out; 85211e6c80SMajd Dibbiny 86211e6c80SMajd Dibbiny *vendor_id = MLX5_GET(query_adapter_out, out, 87211e6c80SMajd Dibbiny query_adapter_struct.ieee_vendor_id); 88211e6c80SMajd Dibbiny out: 89211e6c80SMajd Dibbiny kfree(out); 90211e6c80SMajd Dibbiny return err; 91211e6c80SMajd Dibbiny } 92211e6c80SMajd Dibbiny EXPORT_SYMBOL(mlx5_core_query_vendor_id); 93211e6c80SMajd Dibbiny 9471862561SGal Pressman static int mlx5_get_pcam_reg(struct mlx5_core_dev *dev) 9571862561SGal Pressman { 9671862561SGal Pressman return mlx5_query_pcam_reg(dev, dev->caps.pcam, 9771862561SGal Pressman MLX5_PCAM_FEATURE_ENHANCED_FEATURES, 9871862561SGal Pressman MLX5_PCAM_REGS_5000_TO_507F); 9971862561SGal Pressman } 10071862561SGal Pressman 10171862561SGal Pressman static int mlx5_get_mcam_reg(struct mlx5_core_dev *dev) 10271862561SGal Pressman { 10371862561SGal Pressman return mlx5_query_mcam_reg(dev, dev->caps.mcam, 10471862561SGal Pressman MLX5_MCAM_FEATURE_ENHANCED_FEATURES, 10571862561SGal Pressman MLX5_MCAM_REGS_FIRST_128); 10671862561SGal Pressman } 10771862561SGal Pressman 108938fe83cSSaeed Mahameed int mlx5_query_hca_caps(struct mlx5_core_dev *dev) 109e126ba97SEli Cohen { 110e420f0c0SHaggai Eran int err; 111e420f0c0SHaggai Eran 112b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL); 113938fe83cSSaeed Mahameed if (err) 114938fe83cSSaeed Mahameed return err; 115e420f0c0SHaggai Eran 116938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, eth_net_offloads)) { 117b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS); 118938fe83cSSaeed Mahameed if (err) 119e420f0c0SHaggai Eran return err; 120e420f0c0SHaggai Eran } 121938fe83cSSaeed Mahameed 122938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, pg)) { 123b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ODP); 124938fe83cSSaeed Mahameed if (err) 125938fe83cSSaeed Mahameed return err; 126938fe83cSSaeed Mahameed } 127938fe83cSSaeed Mahameed 128938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, atomic)) { 129b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC); 130938fe83cSSaeed Mahameed if (err) 131938fe83cSSaeed Mahameed return err; 132938fe83cSSaeed Mahameed } 133938fe83cSSaeed Mahameed 134938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, roce)) { 135b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE); 136938fe83cSSaeed Mahameed if (err) 137938fe83cSSaeed Mahameed return err; 138938fe83cSSaeed Mahameed } 139938fe83cSSaeed Mahameed 140938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, nic_flow_table)) { 141b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE); 142938fe83cSSaeed Mahameed if (err) 143938fe83cSSaeed Mahameed return err; 144938fe83cSSaeed Mahameed } 145495716b1SSaeed Mahameed 146495716b1SSaeed Mahameed if (MLX5_CAP_GEN(dev, vport_group_manager) && 147495716b1SSaeed Mahameed MLX5_CAP_GEN(dev, eswitch_flow_table)) { 148b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE); 149495716b1SSaeed Mahameed if (err) 150495716b1SSaeed Mahameed return err; 151495716b1SSaeed Mahameed } 152495716b1SSaeed Mahameed 1539bd0a185SSaeed Mahameed if (MLX5_CAP_GEN(dev, eswitch_flow_table)) { 154b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH); 155d6666753SSaeed Mahameed if (err) 156d6666753SSaeed Mahameed return err; 157d6666753SSaeed Mahameed } 158d6666753SSaeed Mahameed 1593f0393a5SSagi Grimberg if (MLX5_CAP_GEN(dev, vector_calc)) { 1603f0393a5SSagi Grimberg err = mlx5_core_get_caps(dev, MLX5_CAP_VECTOR_CALC); 1613f0393a5SSagi Grimberg if (err) 1623f0393a5SSagi Grimberg return err; 1633f0393a5SSagi Grimberg } 1643f0393a5SSagi Grimberg 1651466cc5bSYevgeny Petrilin if (MLX5_CAP_GEN(dev, qos)) { 1661466cc5bSYevgeny Petrilin err = mlx5_core_get_caps(dev, MLX5_CAP_QOS); 1671466cc5bSYevgeny Petrilin if (err) 1681466cc5bSYevgeny Petrilin return err; 1691466cc5bSYevgeny Petrilin } 1701466cc5bSYevgeny Petrilin 17171862561SGal Pressman if (MLX5_CAP_GEN(dev, pcam_reg)) 17271862561SGal Pressman mlx5_get_pcam_reg(dev); 17371862561SGal Pressman 17471862561SGal Pressman if (MLX5_CAP_GEN(dev, mcam_reg)) 17571862561SGal Pressman mlx5_get_mcam_reg(dev); 17671862561SGal Pressman 177938fe83cSSaeed Mahameed return 0; 178938fe83cSSaeed Mahameed } 179e420f0c0SHaggai Eran 180e126ba97SEli Cohen int mlx5_cmd_init_hca(struct mlx5_core_dev *dev) 181e126ba97SEli Cohen { 18204ed5ad5SSaeed Mahameed u32 out[MLX5_ST_SZ_DW(init_hca_out)] = {0}; 18304ed5ad5SSaeed Mahameed u32 in[MLX5_ST_SZ_DW(init_hca_in)] = {0}; 184e126ba97SEli Cohen 18504ed5ad5SSaeed Mahameed MLX5_SET(init_hca_in, in, opcode, MLX5_CMD_OP_INIT_HCA); 186c4f287c4SSaeed Mahameed return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 187e126ba97SEli Cohen } 188e126ba97SEli Cohen 189e126ba97SEli Cohen int mlx5_cmd_teardown_hca(struct mlx5_core_dev *dev) 190e126ba97SEli Cohen { 19104ed5ad5SSaeed Mahameed u32 out[MLX5_ST_SZ_DW(teardown_hca_out)] = {0}; 19204ed5ad5SSaeed Mahameed u32 in[MLX5_ST_SZ_DW(teardown_hca_in)] = {0}; 193e126ba97SEli Cohen 19404ed5ad5SSaeed Mahameed MLX5_SET(teardown_hca_in, in, opcode, MLX5_CMD_OP_TEARDOWN_HCA); 195c4f287c4SSaeed Mahameed return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out)); 196e126ba97SEli Cohen } 197