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 { 41211e6c80SMajd Dibbiny u32 in[MLX5_ST_SZ_DW(query_adapter_in)]; 42211e6c80SMajd Dibbiny 43211e6c80SMajd Dibbiny memset(in, 0, sizeof(in)); 44211e6c80SMajd Dibbiny 45211e6c80SMajd Dibbiny MLX5_SET(query_adapter_in, in, opcode, MLX5_CMD_OP_QUERY_ADAPTER); 46211e6c80SMajd Dibbiny 47211e6c80SMajd Dibbiny return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, outlen); 48211e6c80SMajd Dibbiny } 49211e6c80SMajd Dibbiny 50211e6c80SMajd Dibbiny int mlx5_query_board_id(struct mlx5_core_dev *dev) 51211e6c80SMajd Dibbiny { 52211e6c80SMajd Dibbiny u32 *out; 53211e6c80SMajd Dibbiny int outlen = MLX5_ST_SZ_BYTES(query_adapter_out); 54e126ba97SEli Cohen int err; 55e126ba97SEli Cohen 56211e6c80SMajd Dibbiny out = kzalloc(outlen, GFP_KERNEL); 57e126ba97SEli Cohen if (!out) 58e126ba97SEli Cohen return -ENOMEM; 59e126ba97SEli Cohen 60211e6c80SMajd Dibbiny err = mlx5_cmd_query_adapter(dev, out, outlen); 61e126ba97SEli Cohen if (err) 62211e6c80SMajd Dibbiny goto out; 63e126ba97SEli Cohen 64211e6c80SMajd Dibbiny memcpy(dev->board_id, 65211e6c80SMajd Dibbiny MLX5_ADDR_OF(query_adapter_out, out, 66211e6c80SMajd Dibbiny query_adapter_struct.vsd_contd_psid), 67211e6c80SMajd Dibbiny MLX5_FLD_SZ_BYTES(query_adapter_out, 68211e6c80SMajd Dibbiny query_adapter_struct.vsd_contd_psid)); 69e126ba97SEli Cohen 70211e6c80SMajd Dibbiny out: 71e126ba97SEli Cohen kfree(out); 72e126ba97SEli Cohen return err; 73e126ba97SEli Cohen } 74e126ba97SEli Cohen 75211e6c80SMajd Dibbiny int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id) 76211e6c80SMajd Dibbiny { 77211e6c80SMajd Dibbiny u32 *out; 78211e6c80SMajd Dibbiny int outlen = MLX5_ST_SZ_BYTES(query_adapter_out); 79211e6c80SMajd Dibbiny int err; 80211e6c80SMajd Dibbiny 81211e6c80SMajd Dibbiny out = kzalloc(outlen, GFP_KERNEL); 82211e6c80SMajd Dibbiny if (!out) 83211e6c80SMajd Dibbiny return -ENOMEM; 84211e6c80SMajd Dibbiny 85211e6c80SMajd Dibbiny err = mlx5_cmd_query_adapter(mdev, out, outlen); 86211e6c80SMajd Dibbiny if (err) 87211e6c80SMajd Dibbiny goto out; 88211e6c80SMajd Dibbiny 89211e6c80SMajd Dibbiny *vendor_id = MLX5_GET(query_adapter_out, out, 90211e6c80SMajd Dibbiny query_adapter_struct.ieee_vendor_id); 91211e6c80SMajd Dibbiny out: 92211e6c80SMajd Dibbiny kfree(out); 93211e6c80SMajd Dibbiny return err; 94211e6c80SMajd Dibbiny } 95211e6c80SMajd Dibbiny EXPORT_SYMBOL(mlx5_core_query_vendor_id); 96211e6c80SMajd Dibbiny 97938fe83cSSaeed Mahameed int mlx5_query_hca_caps(struct mlx5_core_dev *dev) 98e126ba97SEli Cohen { 99e420f0c0SHaggai Eran int err; 100e420f0c0SHaggai Eran 101b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL); 102938fe83cSSaeed Mahameed if (err) 103938fe83cSSaeed Mahameed return err; 104e420f0c0SHaggai Eran 105938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, eth_net_offloads)) { 106b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS); 107938fe83cSSaeed Mahameed if (err) 108e420f0c0SHaggai Eran return err; 109e420f0c0SHaggai Eran } 110938fe83cSSaeed Mahameed 111938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, pg)) { 112b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ODP); 113938fe83cSSaeed Mahameed if (err) 114938fe83cSSaeed Mahameed return err; 115938fe83cSSaeed Mahameed } 116938fe83cSSaeed Mahameed 117938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, atomic)) { 118b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC); 119938fe83cSSaeed Mahameed if (err) 120938fe83cSSaeed Mahameed return err; 121938fe83cSSaeed Mahameed } 122938fe83cSSaeed Mahameed 123938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, roce)) { 124b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE); 125938fe83cSSaeed Mahameed if (err) 126938fe83cSSaeed Mahameed return err; 127938fe83cSSaeed Mahameed } 128938fe83cSSaeed Mahameed 129938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, nic_flow_table)) { 130b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE); 131938fe83cSSaeed Mahameed if (err) 132938fe83cSSaeed Mahameed return err; 133938fe83cSSaeed Mahameed } 134495716b1SSaeed Mahameed 135495716b1SSaeed Mahameed if (MLX5_CAP_GEN(dev, vport_group_manager) && 136495716b1SSaeed Mahameed MLX5_CAP_GEN(dev, eswitch_flow_table)) { 137b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE); 138495716b1SSaeed Mahameed if (err) 139495716b1SSaeed Mahameed return err; 140495716b1SSaeed Mahameed } 141495716b1SSaeed Mahameed 1429bd0a185SSaeed Mahameed if (MLX5_CAP_GEN(dev, eswitch_flow_table)) { 143b06e7de8SLeon Romanovsky err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH); 144d6666753SSaeed Mahameed if (err) 145d6666753SSaeed Mahameed return err; 146d6666753SSaeed Mahameed } 147d6666753SSaeed Mahameed 1483f0393a5SSagi Grimberg if (MLX5_CAP_GEN(dev, vector_calc)) { 1493f0393a5SSagi Grimberg err = mlx5_core_get_caps(dev, MLX5_CAP_VECTOR_CALC); 1503f0393a5SSagi Grimberg if (err) 1513f0393a5SSagi Grimberg return err; 1523f0393a5SSagi Grimberg } 1533f0393a5SSagi Grimberg 154938fe83cSSaeed Mahameed return 0; 155938fe83cSSaeed Mahameed } 156e420f0c0SHaggai Eran 157e126ba97SEli Cohen int mlx5_cmd_init_hca(struct mlx5_core_dev *dev) 158e126ba97SEli Cohen { 159e126ba97SEli Cohen struct mlx5_cmd_init_hca_mbox_in in; 160e126ba97SEli Cohen struct mlx5_cmd_init_hca_mbox_out out; 161e126ba97SEli Cohen int err; 162e126ba97SEli Cohen 163e126ba97SEli Cohen memset(&in, 0, sizeof(in)); 164e126ba97SEli Cohen memset(&out, 0, sizeof(out)); 165e126ba97SEli Cohen in.hdr.opcode = cpu_to_be16(MLX5_CMD_OP_INIT_HCA); 166e126ba97SEli Cohen err = mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out)); 167e126ba97SEli Cohen if (err) 168e126ba97SEli Cohen return err; 169e126ba97SEli Cohen 170e126ba97SEli Cohen if (out.hdr.status) 171e126ba97SEli Cohen err = mlx5_cmd_status_to_err(&out.hdr); 172e126ba97SEli Cohen 173e126ba97SEli Cohen return err; 174e126ba97SEli Cohen } 175e126ba97SEli Cohen 176e126ba97SEli Cohen int mlx5_cmd_teardown_hca(struct mlx5_core_dev *dev) 177e126ba97SEli Cohen { 178e126ba97SEli Cohen struct mlx5_cmd_teardown_hca_mbox_in in; 179e126ba97SEli Cohen struct mlx5_cmd_teardown_hca_mbox_out out; 180e126ba97SEli Cohen int err; 181e126ba97SEli Cohen 182e126ba97SEli Cohen memset(&in, 0, sizeof(in)); 183e126ba97SEli Cohen memset(&out, 0, sizeof(out)); 184e126ba97SEli Cohen in.hdr.opcode = cpu_to_be16(MLX5_CMD_OP_TEARDOWN_HCA); 185e126ba97SEli Cohen err = mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out)); 186e126ba97SEli Cohen if (err) 187e126ba97SEli Cohen return err; 188e126ba97SEli Cohen 189e126ba97SEli Cohen if (out.hdr.status) 190e126ba97SEli Cohen err = mlx5_cmd_status_to_err(&out.hdr); 191e126ba97SEli Cohen 192e126ba97SEli Cohen return err; 193e126ba97SEli Cohen } 194