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 38e126ba97SEli Cohen int mlx5_cmd_query_adapter(struct mlx5_core_dev *dev) 39e126ba97SEli Cohen { 40e126ba97SEli Cohen struct mlx5_cmd_query_adapter_mbox_out *out; 41e126ba97SEli Cohen struct mlx5_cmd_query_adapter_mbox_in in; 42e126ba97SEli Cohen int err; 43e126ba97SEli Cohen 44e126ba97SEli Cohen out = kzalloc(sizeof(*out), GFP_KERNEL); 45e126ba97SEli Cohen if (!out) 46e126ba97SEli Cohen return -ENOMEM; 47e126ba97SEli Cohen 48e126ba97SEli Cohen memset(&in, 0, sizeof(in)); 49e126ba97SEli Cohen in.hdr.opcode = cpu_to_be16(MLX5_CMD_OP_QUERY_ADAPTER); 50e126ba97SEli Cohen err = mlx5_cmd_exec(dev, &in, sizeof(in), out, sizeof(*out)); 51e126ba97SEli Cohen if (err) 52e126ba97SEli Cohen goto out_out; 53e126ba97SEli Cohen 54e126ba97SEli Cohen if (out->hdr.status) { 55e126ba97SEli Cohen err = mlx5_cmd_status_to_err(&out->hdr); 56e126ba97SEli Cohen goto out_out; 57e126ba97SEli Cohen } 58e126ba97SEli Cohen 59e126ba97SEli Cohen memcpy(dev->board_id, out->vsd_psid, sizeof(out->vsd_psid)); 60e126ba97SEli Cohen 61e126ba97SEli Cohen out_out: 62e126ba97SEli Cohen kfree(out); 63e126ba97SEli Cohen 64e126ba97SEli Cohen return err; 65e126ba97SEli Cohen } 66e126ba97SEli Cohen 67938fe83cSSaeed Mahameed int mlx5_query_hca_caps(struct mlx5_core_dev *dev) 68e126ba97SEli Cohen { 69e420f0c0SHaggai Eran int err; 70e420f0c0SHaggai Eran 71938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_CUR); 72e420f0c0SHaggai Eran if (err) 73938fe83cSSaeed Mahameed return err; 74e420f0c0SHaggai Eran 75938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL, HCA_CAP_OPMOD_GET_MAX); 76938fe83cSSaeed Mahameed if (err) 77938fe83cSSaeed Mahameed return err; 78e420f0c0SHaggai Eran 79938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, eth_net_offloads)) { 80938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS, 81938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_CUR); 82938fe83cSSaeed Mahameed if (err) 83938fe83cSSaeed Mahameed return err; 84938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS, 85938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_MAX); 86938fe83cSSaeed Mahameed if (err) 87e420f0c0SHaggai Eran return err; 88e420f0c0SHaggai Eran } 89938fe83cSSaeed Mahameed 90938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, pg)) { 91938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_ODP, 92938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_CUR); 93938fe83cSSaeed Mahameed if (err) 94938fe83cSSaeed Mahameed return err; 95938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_ODP, 96938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_MAX); 97938fe83cSSaeed Mahameed if (err) 98938fe83cSSaeed Mahameed return err; 99938fe83cSSaeed Mahameed } 100938fe83cSSaeed Mahameed 101938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, atomic)) { 102938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC, 103938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_CUR); 104938fe83cSSaeed Mahameed if (err) 105938fe83cSSaeed Mahameed return err; 106938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC, 107938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_MAX); 108938fe83cSSaeed Mahameed if (err) 109938fe83cSSaeed Mahameed return err; 110938fe83cSSaeed Mahameed } 111938fe83cSSaeed Mahameed 112938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, roce)) { 113938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE, 114938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_CUR); 115938fe83cSSaeed Mahameed if (err) 116938fe83cSSaeed Mahameed return err; 117938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE, 118938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_MAX); 119938fe83cSSaeed Mahameed if (err) 120938fe83cSSaeed Mahameed return err; 121938fe83cSSaeed Mahameed } 122938fe83cSSaeed Mahameed 123938fe83cSSaeed Mahameed if (MLX5_CAP_GEN(dev, nic_flow_table)) { 124938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE, 125938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_CUR); 126938fe83cSSaeed Mahameed if (err) 127938fe83cSSaeed Mahameed return err; 128938fe83cSSaeed Mahameed err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE, 129938fe83cSSaeed Mahameed HCA_CAP_OPMOD_GET_MAX); 130938fe83cSSaeed Mahameed if (err) 131938fe83cSSaeed Mahameed return err; 132938fe83cSSaeed Mahameed } 133938fe83cSSaeed Mahameed return 0; 134938fe83cSSaeed Mahameed } 135e420f0c0SHaggai Eran 136e126ba97SEli Cohen int mlx5_cmd_init_hca(struct mlx5_core_dev *dev) 137e126ba97SEli Cohen { 138e126ba97SEli Cohen struct mlx5_cmd_init_hca_mbox_in in; 139e126ba97SEli Cohen struct mlx5_cmd_init_hca_mbox_out out; 140e126ba97SEli Cohen int err; 141e126ba97SEli Cohen 142e126ba97SEli Cohen memset(&in, 0, sizeof(in)); 143e126ba97SEli Cohen memset(&out, 0, sizeof(out)); 144e126ba97SEli Cohen in.hdr.opcode = cpu_to_be16(MLX5_CMD_OP_INIT_HCA); 145e126ba97SEli Cohen err = mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out)); 146e126ba97SEli Cohen if (err) 147e126ba97SEli Cohen return err; 148e126ba97SEli Cohen 149e126ba97SEli Cohen if (out.hdr.status) 150e126ba97SEli Cohen err = mlx5_cmd_status_to_err(&out.hdr); 151e126ba97SEli Cohen 152e126ba97SEli Cohen return err; 153e126ba97SEli Cohen } 154e126ba97SEli Cohen 155e126ba97SEli Cohen int mlx5_cmd_teardown_hca(struct mlx5_core_dev *dev) 156e126ba97SEli Cohen { 157e126ba97SEli Cohen struct mlx5_cmd_teardown_hca_mbox_in in; 158e126ba97SEli Cohen struct mlx5_cmd_teardown_hca_mbox_out out; 159e126ba97SEli Cohen int err; 160e126ba97SEli Cohen 161e126ba97SEli Cohen memset(&in, 0, sizeof(in)); 162e126ba97SEli Cohen memset(&out, 0, sizeof(out)); 163e126ba97SEli Cohen in.hdr.opcode = cpu_to_be16(MLX5_CMD_OP_TEARDOWN_HCA); 164e126ba97SEli Cohen err = mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out)); 165e126ba97SEli Cohen if (err) 166e126ba97SEli Cohen return err; 167e126ba97SEli Cohen 168e126ba97SEli Cohen if (out.hdr.status) 169e126ba97SEli Cohen err = mlx5_cmd_status_to_err(&out.hdr); 170e126ba97SEli Cohen 171e126ba97SEli Cohen return err; 172e126ba97SEli Cohen } 173