Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 2 | * Copyright (c) 2015-2017 QLogic Corporation |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 3 | * |
Mintz, Yuval | e8f1cb5 | 2017-01-01 13:57:00 +0200 | [diff] [blame] | 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. |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <linux/types.h> |
| 34 | #include <asm/byteorder.h> |
| 35 | #include <linux/io.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/dma-mapping.h> |
| 38 | #include <linux/errno.h> |
| 39 | #include <linux/kernel.h> |
| 40 | #include <linux/mutex.h> |
| 41 | #include <linux/pci.h> |
| 42 | #include <linux/slab.h> |
| 43 | #include <linux/string.h> |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 44 | #include <linux/vmalloc.h> |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 45 | #include <linux/etherdevice.h> |
| 46 | #include <linux/qed/qed_chain.h> |
| 47 | #include <linux/qed/qed_if.h> |
| 48 | #include "qed.h" |
| 49 | #include "qed_cxt.h" |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 50 | #include "qed_dcbx.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 51 | #include "qed_dev_api.h" |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 52 | #include "qed_fcoe.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 53 | #include "qed_hsi.h" |
| 54 | #include "qed_hw.h" |
| 55 | #include "qed_init_ops.h" |
| 56 | #include "qed_int.h" |
Yuval Mintz | fc83182 | 2016-12-01 00:21:06 -0800 | [diff] [blame] | 57 | #include "qed_iscsi.h" |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 58 | #include "qed_ll2.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 59 | #include "qed_mcp.h" |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 60 | #include "qed_ooo.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 61 | #include "qed_reg_addr.h" |
| 62 | #include "qed_sp.h" |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 63 | #include "qed_sriov.h" |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 64 | #include "qed_vf.h" |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 65 | #include "qed_roce.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 66 | |
Wei Yongjun | 0caf5b2 | 2016-08-02 13:49:00 +0000 | [diff] [blame] | 67 | static DEFINE_SPINLOCK(qm_lock); |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 68 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 69 | #define QED_MIN_DPIS (4) |
| 70 | #define QED_MIN_PWM_REGION (QED_WID_SIZE * QED_MIN_DPIS) |
| 71 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 72 | /* API common to all protocols */ |
Ram Amrani | c2035ee | 2016-03-02 20:26:00 +0200 | [diff] [blame] | 73 | enum BAR_ID { |
| 74 | BAR_ID_0, /* used for GRC */ |
| 75 | BAR_ID_1 /* Used for doorbells */ |
| 76 | }; |
| 77 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 78 | static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id) |
Ram Amrani | c2035ee | 2016-03-02 20:26:00 +0200 | [diff] [blame] | 79 | { |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 80 | u32 bar_reg = (bar_id == BAR_ID_0 ? |
| 81 | PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE); |
| 82 | u32 val; |
Ram Amrani | c2035ee | 2016-03-02 20:26:00 +0200 | [diff] [blame] | 83 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 84 | if (IS_VF(p_hwfn->cdev)) |
| 85 | return 1 << 17; |
| 86 | |
| 87 | val = qed_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg); |
Ram Amrani | c2035ee | 2016-03-02 20:26:00 +0200 | [diff] [blame] | 88 | if (val) |
| 89 | return 1 << (val + 15); |
| 90 | |
| 91 | /* Old MFW initialized above registered only conditionally */ |
| 92 | if (p_hwfn->cdev->num_hwfns > 1) { |
| 93 | DP_INFO(p_hwfn, |
| 94 | "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n"); |
| 95 | return BAR_ID_0 ? 256 * 1024 : 512 * 1024; |
| 96 | } else { |
| 97 | DP_INFO(p_hwfn, |
| 98 | "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n"); |
| 99 | return 512 * 1024; |
| 100 | } |
| 101 | } |
| 102 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 103 | void qed_init_dp(struct qed_dev *cdev, u32 dp_module, u8 dp_level) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 104 | { |
| 105 | u32 i; |
| 106 | |
| 107 | cdev->dp_level = dp_level; |
| 108 | cdev->dp_module = dp_module; |
| 109 | for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) { |
| 110 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 111 | |
| 112 | p_hwfn->dp_level = dp_level; |
| 113 | p_hwfn->dp_module = dp_module; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | void qed_init_struct(struct qed_dev *cdev) |
| 118 | { |
| 119 | u8 i; |
| 120 | |
| 121 | for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) { |
| 122 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 123 | |
| 124 | p_hwfn->cdev = cdev; |
| 125 | p_hwfn->my_id = i; |
| 126 | p_hwfn->b_active = false; |
| 127 | |
| 128 | mutex_init(&p_hwfn->dmae_info.mutex); |
| 129 | } |
| 130 | |
| 131 | /* hwfn 0 is always active */ |
| 132 | cdev->hwfns[0].b_active = true; |
| 133 | |
| 134 | /* set the default cache alignment to 128 */ |
| 135 | cdev->cache_shift = 7; |
| 136 | } |
| 137 | |
| 138 | static void qed_qm_info_free(struct qed_hwfn *p_hwfn) |
| 139 | { |
| 140 | struct qed_qm_info *qm_info = &p_hwfn->qm_info; |
| 141 | |
| 142 | kfree(qm_info->qm_pq_params); |
| 143 | qm_info->qm_pq_params = NULL; |
| 144 | kfree(qm_info->qm_vport_params); |
| 145 | qm_info->qm_vport_params = NULL; |
| 146 | kfree(qm_info->qm_port_params); |
| 147 | qm_info->qm_port_params = NULL; |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 148 | kfree(qm_info->wfq_data); |
| 149 | qm_info->wfq_data = NULL; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void qed_resc_free(struct qed_dev *cdev) |
| 153 | { |
| 154 | int i; |
| 155 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 156 | if (IS_VF(cdev)) |
| 157 | return; |
| 158 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 159 | kfree(cdev->fw_data); |
| 160 | cdev->fw_data = NULL; |
| 161 | |
| 162 | kfree(cdev->reset_stats); |
| 163 | |
| 164 | for_each_hwfn(cdev, i) { |
| 165 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 166 | |
| 167 | qed_cxt_mngr_free(p_hwfn); |
| 168 | qed_qm_info_free(p_hwfn); |
| 169 | qed_spq_free(p_hwfn); |
| 170 | qed_eq_free(p_hwfn, p_hwfn->p_eq); |
| 171 | qed_consq_free(p_hwfn, p_hwfn->p_consq); |
| 172 | qed_int_free(p_hwfn); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 173 | #ifdef CONFIG_QED_LL2 |
| 174 | qed_ll2_free(p_hwfn, p_hwfn->p_ll2_info); |
| 175 | #endif |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 176 | if (p_hwfn->hw_info.personality == QED_PCI_FCOE) |
| 177 | qed_fcoe_free(p_hwfn, p_hwfn->p_fcoe_info); |
| 178 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 179 | if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) { |
Yuval Mintz | fc83182 | 2016-12-01 00:21:06 -0800 | [diff] [blame] | 180 | qed_iscsi_free(p_hwfn, p_hwfn->p_iscsi_info); |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 181 | qed_ooo_free(p_hwfn, p_hwfn->p_ooo_info); |
| 182 | } |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 183 | qed_iov_free(p_hwfn); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 184 | qed_dmae_info_free(p_hwfn); |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 185 | qed_dcbx_info_free(p_hwfn, p_hwfn->p_dcbx_info); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Sudarsana Reddy Kalluru | 7952929 | 2016-05-26 11:01:20 +0300 | [diff] [blame] | 189 | static int qed_init_qm_info(struct qed_hwfn *p_hwfn, bool b_sleepable) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 190 | { |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 191 | u8 num_vports, vf_offset = 0, i, vport_id, num_ports, curr_queue = 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 192 | struct qed_qm_info *qm_info = &p_hwfn->qm_info; |
| 193 | struct init_qm_port_params *p_qm_port; |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 194 | bool init_rdma_offload_pq = false; |
| 195 | bool init_pure_ack_pq = false; |
| 196 | bool init_ooo_pq = false; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 197 | u16 num_pqs, multi_cos_tcs = 1; |
Yuval Mintz | cc3d5eb | 2016-05-26 11:01:21 +0300 | [diff] [blame] | 198 | u8 pf_wfq = qm_info->pf_wfq; |
| 199 | u32 pf_rl = qm_info->pf_rl; |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 200 | u16 num_pf_rls = 0; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 201 | u16 num_vfs = 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 202 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 203 | #ifdef CONFIG_QED_SRIOV |
| 204 | if (p_hwfn->cdev->p_iov_info) |
| 205 | num_vfs = p_hwfn->cdev->p_iov_info->total_vfs; |
| 206 | #endif |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 207 | memset(qm_info, 0, sizeof(*qm_info)); |
| 208 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 209 | num_pqs = multi_cos_tcs + num_vfs + 1; /* The '1' is for pure-LB */ |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 210 | num_vports = (u8)RESC_NUM(p_hwfn, QED_VPORT); |
| 211 | |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 212 | if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) { |
| 213 | num_pqs++; /* for RoCE queue */ |
| 214 | init_rdma_offload_pq = true; |
| 215 | /* we subtract num_vfs because each require a rate limiter, |
| 216 | * and one default rate limiter |
| 217 | */ |
| 218 | if (p_hwfn->pf_params.rdma_pf_params.enable_dcqcn) |
| 219 | num_pf_rls = RESC_NUM(p_hwfn, QED_RL) - num_vfs - 1; |
| 220 | |
| 221 | num_pqs += num_pf_rls; |
| 222 | qm_info->num_pf_rls = (u8) num_pf_rls; |
| 223 | } |
| 224 | |
| 225 | if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) { |
| 226 | num_pqs += 2; /* for iSCSI pure-ACK / OOO queue */ |
| 227 | init_pure_ack_pq = true; |
| 228 | init_ooo_pq = true; |
| 229 | } |
| 230 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 231 | /* Sanity checking that setup requires legal number of resources */ |
| 232 | if (num_pqs > RESC_NUM(p_hwfn, QED_PQ)) { |
| 233 | DP_ERR(p_hwfn, |
| 234 | "Need too many Physical queues - 0x%04x when only %04x are available\n", |
| 235 | num_pqs, RESC_NUM(p_hwfn, QED_PQ)); |
| 236 | return -EINVAL; |
| 237 | } |
| 238 | |
| 239 | /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete. |
| 240 | */ |
Sudarsana Reddy Kalluru | 7952929 | 2016-05-26 11:01:20 +0300 | [diff] [blame] | 241 | qm_info->qm_pq_params = kcalloc(num_pqs, |
| 242 | sizeof(struct init_qm_pq_params), |
| 243 | b_sleepable ? GFP_KERNEL : GFP_ATOMIC); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 244 | if (!qm_info->qm_pq_params) |
| 245 | goto alloc_err; |
| 246 | |
Sudarsana Reddy Kalluru | 7952929 | 2016-05-26 11:01:20 +0300 | [diff] [blame] | 247 | qm_info->qm_vport_params = kcalloc(num_vports, |
| 248 | sizeof(struct init_qm_vport_params), |
| 249 | b_sleepable ? GFP_KERNEL |
| 250 | : GFP_ATOMIC); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 251 | if (!qm_info->qm_vport_params) |
| 252 | goto alloc_err; |
| 253 | |
Sudarsana Reddy Kalluru | 7952929 | 2016-05-26 11:01:20 +0300 | [diff] [blame] | 254 | qm_info->qm_port_params = kcalloc(MAX_NUM_PORTS, |
| 255 | sizeof(struct init_qm_port_params), |
| 256 | b_sleepable ? GFP_KERNEL |
| 257 | : GFP_ATOMIC); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 258 | if (!qm_info->qm_port_params) |
| 259 | goto alloc_err; |
| 260 | |
Sudarsana Reddy Kalluru | 7952929 | 2016-05-26 11:01:20 +0300 | [diff] [blame] | 261 | qm_info->wfq_data = kcalloc(num_vports, sizeof(struct qed_wfq_data), |
| 262 | b_sleepable ? GFP_KERNEL : GFP_ATOMIC); |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 263 | if (!qm_info->wfq_data) |
| 264 | goto alloc_err; |
| 265 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 266 | vport_id = (u8)RESC_START(p_hwfn, QED_VPORT); |
| 267 | |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 268 | /* First init rate limited queues */ |
| 269 | for (curr_queue = 0; curr_queue < num_pf_rls; curr_queue++) { |
| 270 | qm_info->qm_pq_params[curr_queue].vport_id = vport_id++; |
| 271 | qm_info->qm_pq_params[curr_queue].tc_id = |
| 272 | p_hwfn->hw_info.non_offload_tc; |
| 273 | qm_info->qm_pq_params[curr_queue].wrr_group = 1; |
| 274 | qm_info->qm_pq_params[curr_queue].rl_valid = 1; |
| 275 | } |
| 276 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 277 | /* First init per-TC PQs */ |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 278 | for (i = 0; i < multi_cos_tcs; i++) { |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 279 | struct init_qm_pq_params *params = |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 280 | &qm_info->qm_pq_params[curr_queue++]; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 281 | |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 282 | if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE || |
| 283 | p_hwfn->hw_info.personality == QED_PCI_ETH) { |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 284 | params->vport_id = vport_id; |
| 285 | params->tc_id = p_hwfn->hw_info.non_offload_tc; |
| 286 | params->wrr_group = 1; |
| 287 | } else { |
| 288 | params->vport_id = vport_id; |
| 289 | params->tc_id = p_hwfn->hw_info.offload_tc; |
| 290 | params->wrr_group = 1; |
| 291 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* Then init pure-LB PQ */ |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 295 | qm_info->pure_lb_pq = curr_queue; |
| 296 | qm_info->qm_pq_params[curr_queue].vport_id = |
| 297 | (u8) RESC_START(p_hwfn, QED_VPORT); |
| 298 | qm_info->qm_pq_params[curr_queue].tc_id = PURE_LB_TC; |
| 299 | qm_info->qm_pq_params[curr_queue].wrr_group = 1; |
| 300 | curr_queue++; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 301 | |
| 302 | qm_info->offload_pq = 0; |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 303 | if (init_rdma_offload_pq) { |
| 304 | qm_info->offload_pq = curr_queue; |
| 305 | qm_info->qm_pq_params[curr_queue].vport_id = vport_id; |
| 306 | qm_info->qm_pq_params[curr_queue].tc_id = |
| 307 | p_hwfn->hw_info.offload_tc; |
| 308 | qm_info->qm_pq_params[curr_queue].wrr_group = 1; |
| 309 | curr_queue++; |
| 310 | } |
| 311 | |
| 312 | if (init_pure_ack_pq) { |
| 313 | qm_info->pure_ack_pq = curr_queue; |
| 314 | qm_info->qm_pq_params[curr_queue].vport_id = vport_id; |
| 315 | qm_info->qm_pq_params[curr_queue].tc_id = |
| 316 | p_hwfn->hw_info.offload_tc; |
| 317 | qm_info->qm_pq_params[curr_queue].wrr_group = 1; |
| 318 | curr_queue++; |
| 319 | } |
| 320 | |
| 321 | if (init_ooo_pq) { |
| 322 | qm_info->ooo_pq = curr_queue; |
| 323 | qm_info->qm_pq_params[curr_queue].vport_id = vport_id; |
| 324 | qm_info->qm_pq_params[curr_queue].tc_id = DCBX_ISCSI_OOO_TC; |
| 325 | qm_info->qm_pq_params[curr_queue].wrr_group = 1; |
| 326 | curr_queue++; |
| 327 | } |
| 328 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 329 | /* Then init per-VF PQs */ |
| 330 | vf_offset = curr_queue; |
| 331 | for (i = 0; i < num_vfs; i++) { |
| 332 | /* First vport is used by the PF */ |
| 333 | qm_info->qm_pq_params[curr_queue].vport_id = vport_id + i + 1; |
| 334 | qm_info->qm_pq_params[curr_queue].tc_id = |
| 335 | p_hwfn->hw_info.non_offload_tc; |
| 336 | qm_info->qm_pq_params[curr_queue].wrr_group = 1; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 337 | qm_info->qm_pq_params[curr_queue].rl_valid = 1; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 338 | curr_queue++; |
| 339 | } |
| 340 | |
| 341 | qm_info->vf_queues_offset = vf_offset; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 342 | qm_info->num_pqs = num_pqs; |
| 343 | qm_info->num_vports = num_vports; |
| 344 | |
| 345 | /* Initialize qm port parameters */ |
| 346 | num_ports = p_hwfn->cdev->num_ports_in_engines; |
| 347 | for (i = 0; i < num_ports; i++) { |
| 348 | p_qm_port = &qm_info->qm_port_params[i]; |
| 349 | p_qm_port->active = 1; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 350 | if (num_ports == 4) |
| 351 | p_qm_port->active_phys_tcs = 0x7; |
| 352 | else |
| 353 | p_qm_port->active_phys_tcs = 0x9f; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 354 | p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports; |
| 355 | p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports; |
| 356 | } |
| 357 | |
| 358 | qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS; |
| 359 | |
| 360 | qm_info->start_pq = (u16)RESC_START(p_hwfn, QED_PQ); |
| 361 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 362 | qm_info->num_vf_pqs = num_vfs; |
| 363 | qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 364 | |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 365 | for (i = 0; i < qm_info->num_vports; i++) |
| 366 | qm_info->qm_vport_params[i].vport_wfq = 1; |
| 367 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 368 | qm_info->vport_rl_en = 1; |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 369 | qm_info->vport_wfq_en = 1; |
Yuval Mintz | cc3d5eb | 2016-05-26 11:01:21 +0300 | [diff] [blame] | 370 | qm_info->pf_rl = pf_rl; |
| 371 | qm_info->pf_wfq = pf_wfq; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 372 | |
| 373 | return 0; |
| 374 | |
| 375 | alloc_err: |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 376 | qed_qm_info_free(p_hwfn); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 377 | return -ENOMEM; |
| 378 | } |
| 379 | |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 380 | /* This function reconfigures the QM pf on the fly. |
| 381 | * For this purpose we: |
| 382 | * 1. reconfigure the QM database |
| 383 | * 2. set new values to runtime arrat |
| 384 | * 3. send an sdm_qm_cmd through the rbc interface to stop the QM |
| 385 | * 4. activate init tool in QM_PF stage |
| 386 | * 5. send an sdm_qm_cmd through rbc interface to release the QM |
| 387 | */ |
| 388 | int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 389 | { |
| 390 | struct qed_qm_info *qm_info = &p_hwfn->qm_info; |
| 391 | bool b_rc; |
| 392 | int rc; |
| 393 | |
| 394 | /* qm_info is allocated in qed_init_qm_info() which is already called |
| 395 | * from qed_resc_alloc() or previous call of qed_qm_reconf(). |
| 396 | * The allocated size may change each init, so we free it before next |
| 397 | * allocation. |
| 398 | */ |
| 399 | qed_qm_info_free(p_hwfn); |
| 400 | |
| 401 | /* initialize qed's qm data structure */ |
Sudarsana Reddy Kalluru | 7952929 | 2016-05-26 11:01:20 +0300 | [diff] [blame] | 402 | rc = qed_init_qm_info(p_hwfn, false); |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 403 | if (rc) |
| 404 | return rc; |
| 405 | |
| 406 | /* stop PF's qm queues */ |
| 407 | spin_lock_bh(&qm_lock); |
| 408 | b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true, |
| 409 | qm_info->start_pq, qm_info->num_pqs); |
| 410 | spin_unlock_bh(&qm_lock); |
| 411 | if (!b_rc) |
| 412 | return -EINVAL; |
| 413 | |
| 414 | /* clear the QM_PF runtime phase leftovers from previous init */ |
| 415 | qed_init_clear_rt_data(p_hwfn); |
| 416 | |
| 417 | /* prepare QM portion of runtime array */ |
| 418 | qed_qm_init_pf(p_hwfn); |
| 419 | |
| 420 | /* activate init tool on runtime array */ |
| 421 | rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id, |
| 422 | p_hwfn->hw_info.hw_mode); |
| 423 | if (rc) |
| 424 | return rc; |
| 425 | |
| 426 | /* start PF's qm queues */ |
| 427 | spin_lock_bh(&qm_lock); |
| 428 | b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true, |
| 429 | qm_info->start_pq, qm_info->num_pqs); |
| 430 | spin_unlock_bh(&qm_lock); |
| 431 | if (!b_rc) |
| 432 | return -EINVAL; |
| 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 437 | int qed_resc_alloc(struct qed_dev *cdev) |
| 438 | { |
Yuval Mintz | fc83182 | 2016-12-01 00:21:06 -0800 | [diff] [blame] | 439 | struct qed_iscsi_info *p_iscsi_info; |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 440 | struct qed_fcoe_info *p_fcoe_info; |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 441 | struct qed_ooo_info *p_ooo_info; |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 442 | #ifdef CONFIG_QED_LL2 |
| 443 | struct qed_ll2_info *p_ll2_info; |
| 444 | #endif |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 445 | struct qed_consq *p_consq; |
| 446 | struct qed_eq *p_eq; |
| 447 | int i, rc = 0; |
| 448 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 449 | if (IS_VF(cdev)) |
| 450 | return rc; |
| 451 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 452 | cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL); |
| 453 | if (!cdev->fw_data) |
| 454 | return -ENOMEM; |
| 455 | |
| 456 | for_each_hwfn(cdev, i) { |
| 457 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 458 | u32 n_eqes, num_cons; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 459 | |
| 460 | /* First allocate the context manager structure */ |
| 461 | rc = qed_cxt_mngr_alloc(p_hwfn); |
| 462 | if (rc) |
| 463 | goto alloc_err; |
| 464 | |
| 465 | /* Set the HW cid/tid numbers (in the contest manager) |
| 466 | * Must be done prior to any further computations. |
| 467 | */ |
| 468 | rc = qed_cxt_set_pf_params(p_hwfn); |
| 469 | if (rc) |
| 470 | goto alloc_err; |
| 471 | |
| 472 | /* Prepare and process QM requirements */ |
Sudarsana Reddy Kalluru | 7952929 | 2016-05-26 11:01:20 +0300 | [diff] [blame] | 473 | rc = qed_init_qm_info(p_hwfn, true); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 474 | if (rc) |
| 475 | goto alloc_err; |
| 476 | |
| 477 | /* Compute the ILT client partition */ |
| 478 | rc = qed_cxt_cfg_ilt_compute(p_hwfn); |
| 479 | if (rc) |
| 480 | goto alloc_err; |
| 481 | |
| 482 | /* CID map / ILT shadow table / T2 |
| 483 | * The talbes sizes are determined by the computations above |
| 484 | */ |
| 485 | rc = qed_cxt_tables_alloc(p_hwfn); |
| 486 | if (rc) |
| 487 | goto alloc_err; |
| 488 | |
| 489 | /* SPQ, must follow ILT because initializes SPQ context */ |
| 490 | rc = qed_spq_alloc(p_hwfn); |
| 491 | if (rc) |
| 492 | goto alloc_err; |
| 493 | |
| 494 | /* SP status block allocation */ |
| 495 | p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn, |
| 496 | RESERVED_PTT_DPC); |
| 497 | |
| 498 | rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt); |
| 499 | if (rc) |
| 500 | goto alloc_err; |
| 501 | |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 502 | rc = qed_iov_alloc(p_hwfn); |
| 503 | if (rc) |
| 504 | goto alloc_err; |
| 505 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 506 | /* EQ */ |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 507 | n_eqes = qed_chain_get_capacity(&p_hwfn->p_spq->chain); |
| 508 | if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) { |
| 509 | num_cons = qed_cxt_get_proto_cid_count(p_hwfn, |
| 510 | PROTOCOLID_ROCE, |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 511 | NULL) * 2; |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 512 | n_eqes += num_cons + 2 * MAX_NUM_VFS_BB; |
| 513 | } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) { |
| 514 | num_cons = |
| 515 | qed_cxt_get_proto_cid_count(p_hwfn, |
Yuval Mintz | 8c93bea | 2016-10-13 22:57:03 +0300 | [diff] [blame] | 516 | PROTOCOLID_ISCSI, |
| 517 | NULL); |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 518 | n_eqes += 2 * num_cons; |
| 519 | } |
| 520 | |
| 521 | if (n_eqes > 0xFFFF) { |
| 522 | DP_ERR(p_hwfn, |
| 523 | "Cannot allocate 0x%x EQ elements. The maximum of a u16 chain is 0x%x\n", |
| 524 | n_eqes, 0xFFFF); |
Wei Yongjun | 1b4985b | 2016-08-02 00:55:34 +0000 | [diff] [blame] | 525 | rc = -EINVAL; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 526 | goto alloc_err; |
Dan Carpenter | 9b15acb | 2015-11-05 11:41:28 +0300 | [diff] [blame] | 527 | } |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 528 | |
| 529 | p_eq = qed_eq_alloc(p_hwfn, (u16) n_eqes); |
| 530 | if (!p_eq) |
| 531 | goto alloc_no_mem; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 532 | p_hwfn->p_eq = p_eq; |
| 533 | |
| 534 | p_consq = qed_consq_alloc(p_hwfn); |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 535 | if (!p_consq) |
| 536 | goto alloc_no_mem; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 537 | p_hwfn->p_consq = p_consq; |
| 538 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 539 | #ifdef CONFIG_QED_LL2 |
| 540 | if (p_hwfn->using_ll2) { |
| 541 | p_ll2_info = qed_ll2_alloc(p_hwfn); |
| 542 | if (!p_ll2_info) |
| 543 | goto alloc_no_mem; |
| 544 | p_hwfn->p_ll2_info = p_ll2_info; |
| 545 | } |
| 546 | #endif |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 547 | |
| 548 | if (p_hwfn->hw_info.personality == QED_PCI_FCOE) { |
| 549 | p_fcoe_info = qed_fcoe_alloc(p_hwfn); |
| 550 | if (!p_fcoe_info) |
| 551 | goto alloc_no_mem; |
| 552 | p_hwfn->p_fcoe_info = p_fcoe_info; |
| 553 | } |
| 554 | |
Yuval Mintz | fc83182 | 2016-12-01 00:21:06 -0800 | [diff] [blame] | 555 | if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) { |
| 556 | p_iscsi_info = qed_iscsi_alloc(p_hwfn); |
| 557 | if (!p_iscsi_info) |
| 558 | goto alloc_no_mem; |
| 559 | p_hwfn->p_iscsi_info = p_iscsi_info; |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 560 | p_ooo_info = qed_ooo_alloc(p_hwfn); |
| 561 | if (!p_ooo_info) |
| 562 | goto alloc_no_mem; |
| 563 | p_hwfn->p_ooo_info = p_ooo_info; |
Yuval Mintz | fc83182 | 2016-12-01 00:21:06 -0800 | [diff] [blame] | 564 | } |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 565 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 566 | /* DMA info initialization */ |
| 567 | rc = qed_dmae_info_alloc(p_hwfn); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 568 | if (rc) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 569 | goto alloc_err; |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 570 | |
| 571 | /* DCBX initialization */ |
| 572 | rc = qed_dcbx_info_alloc(p_hwfn); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 573 | if (rc) |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 574 | goto alloc_err; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 578 | if (!cdev->reset_stats) |
Yuval Mintz | 83aeb93 | 2016-08-15 10:42:44 +0300 | [diff] [blame] | 579 | goto alloc_no_mem; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 580 | |
| 581 | return 0; |
| 582 | |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 583 | alloc_no_mem: |
| 584 | rc = -ENOMEM; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 585 | alloc_err: |
| 586 | qed_resc_free(cdev); |
| 587 | return rc; |
| 588 | } |
| 589 | |
| 590 | void qed_resc_setup(struct qed_dev *cdev) |
| 591 | { |
| 592 | int i; |
| 593 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 594 | if (IS_VF(cdev)) |
| 595 | return; |
| 596 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 597 | for_each_hwfn(cdev, i) { |
| 598 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 599 | |
| 600 | qed_cxt_mngr_setup(p_hwfn); |
| 601 | qed_spq_setup(p_hwfn); |
| 602 | qed_eq_setup(p_hwfn, p_hwfn->p_eq); |
| 603 | qed_consq_setup(p_hwfn, p_hwfn->p_consq); |
| 604 | |
| 605 | /* Read shadow of current MFW mailbox */ |
| 606 | qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt); |
| 607 | memcpy(p_hwfn->mcp_info->mfw_mb_shadow, |
| 608 | p_hwfn->mcp_info->mfw_mb_cur, |
| 609 | p_hwfn->mcp_info->mfw_mb_length); |
| 610 | |
| 611 | qed_int_setup(p_hwfn, p_hwfn->p_main_ptt); |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 612 | |
| 613 | qed_iov_setup(p_hwfn, p_hwfn->p_main_ptt); |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 614 | #ifdef CONFIG_QED_LL2 |
| 615 | if (p_hwfn->using_ll2) |
| 616 | qed_ll2_setup(p_hwfn, p_hwfn->p_ll2_info); |
| 617 | #endif |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 618 | if (p_hwfn->hw_info.personality == QED_PCI_FCOE) |
| 619 | qed_fcoe_setup(p_hwfn, p_hwfn->p_fcoe_info); |
| 620 | |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 621 | if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) { |
Yuval Mintz | fc83182 | 2016-12-01 00:21:06 -0800 | [diff] [blame] | 622 | qed_iscsi_setup(p_hwfn, p_hwfn->p_iscsi_info); |
Yuval Mintz | 1d6cff4 | 2016-12-01 00:21:07 -0800 | [diff] [blame] | 623 | qed_ooo_setup(p_hwfn, p_hwfn->p_ooo_info); |
| 624 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 628 | #define FINAL_CLEANUP_POLL_CNT (100) |
| 629 | #define FINAL_CLEANUP_POLL_TIME (10) |
| 630 | int qed_final_cleanup(struct qed_hwfn *p_hwfn, |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 631 | struct qed_ptt *p_ptt, u16 id, bool is_vf) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 632 | { |
| 633 | u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT; |
| 634 | int rc = -EBUSY; |
| 635 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 636 | addr = GTT_BAR0_MAP_REG_USDM_RAM + |
| 637 | USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 638 | |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 639 | if (is_vf) |
| 640 | id += 0x10; |
| 641 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 642 | command |= X_FINAL_CLEANUP_AGG_INT << |
| 643 | SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT; |
| 644 | command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT; |
| 645 | command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT; |
| 646 | command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 647 | |
| 648 | /* Make sure notification is not set before initiating final cleanup */ |
| 649 | if (REG_RD(p_hwfn, addr)) { |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 650 | DP_NOTICE(p_hwfn, |
| 651 | "Unexpected; Found final cleanup notification before initiating final cleanup\n"); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 652 | REG_WR(p_hwfn, addr, 0); |
| 653 | } |
| 654 | |
| 655 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 656 | "Sending final cleanup for PFVF[%d] [Command %08x\n]", |
| 657 | id, command); |
| 658 | |
| 659 | qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command); |
| 660 | |
| 661 | /* Poll until completion */ |
| 662 | while (!REG_RD(p_hwfn, addr) && count--) |
| 663 | msleep(FINAL_CLEANUP_POLL_TIME); |
| 664 | |
| 665 | if (REG_RD(p_hwfn, addr)) |
| 666 | rc = 0; |
| 667 | else |
| 668 | DP_NOTICE(p_hwfn, |
| 669 | "Failed to receive FW final cleanup notification\n"); |
| 670 | |
| 671 | /* Cleanup afterwards */ |
| 672 | REG_WR(p_hwfn, addr, 0); |
| 673 | |
| 674 | return rc; |
| 675 | } |
| 676 | |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 677 | static int qed_calc_hw_mode(struct qed_hwfn *p_hwfn) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 678 | { |
| 679 | int hw_mode = 0; |
| 680 | |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 681 | if (QED_IS_BB_B0(p_hwfn->cdev)) { |
| 682 | hw_mode |= 1 << MODE_BB; |
| 683 | } else if (QED_IS_AH(p_hwfn->cdev)) { |
| 684 | hw_mode |= 1 << MODE_K2; |
| 685 | } else { |
| 686 | DP_NOTICE(p_hwfn, "Unknown chip type %#x\n", |
| 687 | p_hwfn->cdev->type); |
| 688 | return -EINVAL; |
| 689 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 690 | |
| 691 | switch (p_hwfn->cdev->num_ports_in_engines) { |
| 692 | case 1: |
| 693 | hw_mode |= 1 << MODE_PORTS_PER_ENG_1; |
| 694 | break; |
| 695 | case 2: |
| 696 | hw_mode |= 1 << MODE_PORTS_PER_ENG_2; |
| 697 | break; |
| 698 | case 4: |
| 699 | hw_mode |= 1 << MODE_PORTS_PER_ENG_4; |
| 700 | break; |
| 701 | default: |
| 702 | DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n", |
| 703 | p_hwfn->cdev->num_ports_in_engines); |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 704 | return -EINVAL; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | switch (p_hwfn->cdev->mf_mode) { |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 708 | case QED_MF_DEFAULT: |
| 709 | case QED_MF_NPAR: |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 710 | hw_mode |= 1 << MODE_MF_SI; |
| 711 | break; |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 712 | case QED_MF_OVLAN: |
| 713 | hw_mode |= 1 << MODE_MF_SD; |
| 714 | break; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 715 | default: |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 716 | DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n"); |
| 717 | hw_mode |= 1 << MODE_MF_SI; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | hw_mode |= 1 << MODE_ASIC; |
| 721 | |
Yuval Mintz | 1af9dcf | 2016-05-26 11:01:22 +0300 | [diff] [blame] | 722 | if (p_hwfn->cdev->num_hwfns > 1) |
| 723 | hw_mode |= 1 << MODE_100G; |
| 724 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 725 | p_hwfn->hw_info.hw_mode = hw_mode; |
Yuval Mintz | 1af9dcf | 2016-05-26 11:01:22 +0300 | [diff] [blame] | 726 | |
| 727 | DP_VERBOSE(p_hwfn, (NETIF_MSG_PROBE | NETIF_MSG_IFUP), |
| 728 | "Configuring function for hw_mode: 0x%08x\n", |
| 729 | p_hwfn->hw_info.hw_mode); |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 730 | |
| 731 | return 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /* Init run time data for all PFs on an engine. */ |
| 735 | static void qed_init_cau_rt_data(struct qed_dev *cdev) |
| 736 | { |
| 737 | u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET; |
| 738 | int i, sb_id; |
| 739 | |
| 740 | for_each_hwfn(cdev, i) { |
| 741 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 742 | struct qed_igu_info *p_igu_info; |
| 743 | struct qed_igu_block *p_block; |
| 744 | struct cau_sb_entry sb_entry; |
| 745 | |
| 746 | p_igu_info = p_hwfn->hw_info.p_igu_info; |
| 747 | |
| 748 | for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(cdev); |
| 749 | sb_id++) { |
| 750 | p_block = &p_igu_info->igu_map.igu_blocks[sb_id]; |
| 751 | if (!p_block->is_pf) |
| 752 | continue; |
| 753 | |
| 754 | qed_init_cau_sb_entry(p_hwfn, &sb_entry, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 755 | p_block->function_id, 0, 0); |
| 756 | STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2, sb_entry); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | static int qed_hw_init_common(struct qed_hwfn *p_hwfn, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 762 | struct qed_ptt *p_ptt, int hw_mode) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 763 | { |
| 764 | struct qed_qm_info *qm_info = &p_hwfn->qm_info; |
| 765 | struct qed_qm_common_rt_init_params params; |
| 766 | struct qed_dev *cdev = p_hwfn->cdev; |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 767 | u8 vf_id, max_num_vfs; |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 768 | u16 num_pfs, pf_id; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 769 | u32 concrete_fid; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 770 | int rc = 0; |
| 771 | |
| 772 | qed_init_cau_rt_data(cdev); |
| 773 | |
| 774 | /* Program GTT windows */ |
| 775 | qed_gtt_init(p_hwfn); |
| 776 | |
| 777 | if (p_hwfn->mcp_info) { |
| 778 | if (p_hwfn->mcp_info->func_info.bandwidth_max) |
| 779 | qm_info->pf_rl_en = 1; |
| 780 | if (p_hwfn->mcp_info->func_info.bandwidth_min) |
| 781 | qm_info->pf_wfq_en = 1; |
| 782 | } |
| 783 | |
| 784 | memset(¶ms, 0, sizeof(params)); |
| 785 | params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engines; |
| 786 | params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port; |
| 787 | params.pf_rl_en = qm_info->pf_rl_en; |
| 788 | params.pf_wfq_en = qm_info->pf_wfq_en; |
| 789 | params.vport_rl_en = qm_info->vport_rl_en; |
| 790 | params.vport_wfq_en = qm_info->vport_wfq_en; |
| 791 | params.port_params = qm_info->qm_port_params; |
| 792 | |
| 793 | qed_qm_common_rt_init(p_hwfn, ¶ms); |
| 794 | |
| 795 | qed_cxt_hw_init_common(p_hwfn); |
| 796 | |
| 797 | /* Close gate from NIG to BRB/Storm; By default they are open, but |
| 798 | * we close them to prevent NIG from passing data to reset blocks. |
| 799 | * Should have been done in the ENGINE phase, but init-tool lacks |
| 800 | * proper port-pretend capabilities. |
| 801 | */ |
| 802 | qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0); |
| 803 | qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0); |
| 804 | qed_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1); |
| 805 | qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0); |
| 806 | qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0); |
| 807 | qed_port_unpretend(p_hwfn, p_ptt); |
| 808 | |
| 809 | rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode); |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 810 | if (rc) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 811 | return rc; |
| 812 | |
| 813 | qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0); |
| 814 | qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1); |
| 815 | |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 816 | if (QED_IS_BB(p_hwfn->cdev)) { |
| 817 | num_pfs = NUM_OF_ENG_PFS(p_hwfn->cdev); |
| 818 | for (pf_id = 0; pf_id < num_pfs; pf_id++) { |
| 819 | qed_fid_pretend(p_hwfn, p_ptt, pf_id); |
| 820 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0); |
| 821 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0); |
| 822 | } |
| 823 | /* pretend to original PF */ |
| 824 | qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id); |
| 825 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 826 | |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 827 | max_num_vfs = QED_IS_AH(cdev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB; |
| 828 | for (vf_id = 0; vf_id < max_num_vfs; vf_id++) { |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 829 | concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id); |
| 830 | qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid); |
| 831 | qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1); |
Yuval Mintz | 05fafbf | 2016-08-19 09:33:31 +0300 | [diff] [blame] | 832 | qed_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0); |
| 833 | qed_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1); |
| 834 | qed_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 835 | } |
| 836 | /* pretend to original PF */ |
| 837 | qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id); |
| 838 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 839 | return rc; |
| 840 | } |
| 841 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 842 | static int |
| 843 | qed_hw_init_dpi_size(struct qed_hwfn *p_hwfn, |
| 844 | struct qed_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus) |
| 845 | { |
| 846 | u32 dpi_page_size_1, dpi_page_size_2, dpi_page_size; |
| 847 | u32 dpi_bit_shift, dpi_count; |
| 848 | u32 min_dpis; |
| 849 | |
| 850 | /* Calculate DPI size */ |
| 851 | dpi_page_size_1 = QED_WID_SIZE * n_cpus; |
| 852 | dpi_page_size_2 = max_t(u32, QED_WID_SIZE, PAGE_SIZE); |
| 853 | dpi_page_size = max_t(u32, dpi_page_size_1, dpi_page_size_2); |
| 854 | dpi_page_size = roundup_pow_of_two(dpi_page_size); |
| 855 | dpi_bit_shift = ilog2(dpi_page_size / 4096); |
| 856 | |
| 857 | dpi_count = pwm_region_size / dpi_page_size; |
| 858 | |
| 859 | min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis; |
| 860 | min_dpis = max_t(u32, QED_MIN_DPIS, min_dpis); |
| 861 | |
| 862 | p_hwfn->dpi_size = dpi_page_size; |
| 863 | p_hwfn->dpi_count = dpi_count; |
| 864 | |
| 865 | qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift); |
| 866 | |
| 867 | if (dpi_count < min_dpis) |
| 868 | return -EINVAL; |
| 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | |
| 873 | enum QED_ROCE_EDPM_MODE { |
| 874 | QED_ROCE_EDPM_MODE_ENABLE = 0, |
| 875 | QED_ROCE_EDPM_MODE_FORCE_ON = 1, |
| 876 | QED_ROCE_EDPM_MODE_DISABLE = 2, |
| 877 | }; |
| 878 | |
| 879 | static int |
| 880 | qed_hw_init_pf_doorbell_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 881 | { |
| 882 | u32 pwm_regsize, norm_regsize; |
| 883 | u32 non_pwm_conn, min_addr_reg1; |
| 884 | u32 db_bar_size, n_cpus; |
| 885 | u32 roce_edpm_mode; |
| 886 | u32 pf_dems_shift; |
| 887 | int rc = 0; |
| 888 | u8 cond; |
| 889 | |
| 890 | db_bar_size = qed_hw_bar_size(p_hwfn, BAR_ID_1); |
| 891 | if (p_hwfn->cdev->num_hwfns > 1) |
| 892 | db_bar_size /= 2; |
| 893 | |
| 894 | /* Calculate doorbell regions */ |
| 895 | non_pwm_conn = qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) + |
| 896 | qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE, |
| 897 | NULL) + |
| 898 | qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, |
| 899 | NULL); |
| 900 | norm_regsize = roundup(QED_PF_DEMS_SIZE * non_pwm_conn, 4096); |
| 901 | min_addr_reg1 = norm_regsize / 4096; |
| 902 | pwm_regsize = db_bar_size - norm_regsize; |
| 903 | |
| 904 | /* Check that the normal and PWM sizes are valid */ |
| 905 | if (db_bar_size < norm_regsize) { |
| 906 | DP_ERR(p_hwfn->cdev, |
| 907 | "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n", |
| 908 | db_bar_size, norm_regsize); |
| 909 | return -EINVAL; |
| 910 | } |
| 911 | |
| 912 | if (pwm_regsize < QED_MIN_PWM_REGION) { |
| 913 | DP_ERR(p_hwfn->cdev, |
| 914 | "PWM region size 0x%0x is too small. Should be at least 0x%0x (Doorbell BAR size is 0x%x and normal region size is 0x%0x)\n", |
| 915 | pwm_regsize, |
| 916 | QED_MIN_PWM_REGION, db_bar_size, norm_regsize); |
| 917 | return -EINVAL; |
| 918 | } |
| 919 | |
| 920 | /* Calculate number of DPIs */ |
| 921 | roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode; |
| 922 | if ((roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE) || |
| 923 | ((roce_edpm_mode == QED_ROCE_EDPM_MODE_FORCE_ON))) { |
| 924 | /* Either EDPM is mandatory, or we are attempting to allocate a |
| 925 | * WID per CPU. |
| 926 | */ |
Ram Amrani | c2dedf8 | 2017-02-20 22:43:33 +0200 | [diff] [blame] | 927 | n_cpus = num_present_cpus(); |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 928 | rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus); |
| 929 | } |
| 930 | |
| 931 | cond = (rc && (roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE)) || |
| 932 | (roce_edpm_mode == QED_ROCE_EDPM_MODE_DISABLE); |
| 933 | if (cond || p_hwfn->dcbx_no_edpm) { |
| 934 | /* Either EDPM is disabled from user configuration, or it is |
| 935 | * disabled via DCBx, or it is not mandatory and we failed to |
| 936 | * allocated a WID per CPU. |
| 937 | */ |
| 938 | n_cpus = 1; |
| 939 | rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus); |
| 940 | |
| 941 | if (cond) |
| 942 | qed_rdma_dpm_bar(p_hwfn, p_ptt); |
| 943 | } |
| 944 | |
| 945 | DP_INFO(p_hwfn, |
| 946 | "doorbell bar: normal_region_size=%d, pwm_region_size=%d, dpi_size=%d, dpi_count=%d, roce_edpm=%s\n", |
| 947 | norm_regsize, |
| 948 | pwm_regsize, |
| 949 | p_hwfn->dpi_size, |
| 950 | p_hwfn->dpi_count, |
| 951 | ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ? |
| 952 | "disabled" : "enabled"); |
| 953 | |
| 954 | if (rc) { |
| 955 | DP_ERR(p_hwfn, |
| 956 | "Failed to allocate enough DPIs. Allocated %d but the current minimum is %d.\n", |
| 957 | p_hwfn->dpi_count, |
| 958 | p_hwfn->pf_params.rdma_pf_params.min_dpis); |
| 959 | return -EINVAL; |
| 960 | } |
| 961 | |
| 962 | p_hwfn->dpi_start_offset = norm_regsize; |
| 963 | |
| 964 | /* DEMS size is configured log2 of DWORDs, hence the division by 4 */ |
| 965 | pf_dems_shift = ilog2(QED_PF_DEMS_SIZE / 4); |
| 966 | qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift); |
| 967 | qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1); |
| 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 972 | static int qed_hw_init_port(struct qed_hwfn *p_hwfn, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 973 | struct qed_ptt *p_ptt, int hw_mode) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 974 | { |
Yuval Mintz | 05fafbf | 2016-08-19 09:33:31 +0300 | [diff] [blame] | 975 | return qed_init_run(p_hwfn, p_ptt, PHASE_PORT, |
| 976 | p_hwfn->port_id, hw_mode); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | static int qed_hw_init_pf(struct qed_hwfn *p_hwfn, |
| 980 | struct qed_ptt *p_ptt, |
Manish Chopra | 464f664 | 2016-04-14 01:38:29 -0400 | [diff] [blame] | 981 | struct qed_tunn_start_params *p_tunn, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 982 | int hw_mode, |
| 983 | bool b_hw_start, |
| 984 | enum qed_int_mode int_mode, |
| 985 | bool allow_npar_tx_switch) |
| 986 | { |
| 987 | u8 rel_pf_id = p_hwfn->rel_pf_id; |
| 988 | int rc = 0; |
| 989 | |
| 990 | if (p_hwfn->mcp_info) { |
| 991 | struct qed_mcp_function_info *p_info; |
| 992 | |
| 993 | p_info = &p_hwfn->mcp_info->func_info; |
| 994 | if (p_info->bandwidth_min) |
| 995 | p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min; |
| 996 | |
| 997 | /* Update rate limit once we'll actually have a link */ |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 998 | p_hwfn->qm_info.pf_rl = 100000; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | qed_cxt_hw_init_pf(p_hwfn); |
| 1002 | |
| 1003 | qed_int_igu_init_rt(p_hwfn); |
| 1004 | |
| 1005 | /* Set VLAN in NIG if needed */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1006 | if (hw_mode & BIT(MODE_MF_SD)) { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1007 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n"); |
| 1008 | STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1); |
| 1009 | STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET, |
| 1010 | p_hwfn->hw_info.ovlan); |
| 1011 | } |
| 1012 | |
| 1013 | /* Enable classification by MAC if needed */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1014 | if (hw_mode & BIT(MODE_MF_SI)) { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1015 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 1016 | "Configuring TAGMAC_CLS_TYPE\n"); |
| 1017 | STORE_RT_REG(p_hwfn, |
| 1018 | NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1); |
| 1019 | } |
| 1020 | |
| 1021 | /* Protocl Configuration */ |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 1022 | STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET, |
| 1023 | (p_hwfn->hw_info.personality == QED_PCI_ISCSI) ? 1 : 0); |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1024 | STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET, |
| 1025 | (p_hwfn->hw_info.personality == QED_PCI_FCOE) ? 1 : 0); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1026 | STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0); |
| 1027 | |
| 1028 | /* Cleanup chip from previous driver if such remains exist */ |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 1029 | rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false); |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1030 | if (rc) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1031 | return rc; |
| 1032 | |
| 1033 | /* PF Init sequence */ |
| 1034 | rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode); |
| 1035 | if (rc) |
| 1036 | return rc; |
| 1037 | |
| 1038 | /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */ |
| 1039 | rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode); |
| 1040 | if (rc) |
| 1041 | return rc; |
| 1042 | |
| 1043 | /* Pure runtime initializations - directly to the HW */ |
| 1044 | qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true); |
| 1045 | |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 1046 | rc = qed_hw_init_pf_doorbell_bar(p_hwfn, p_ptt); |
| 1047 | if (rc) |
| 1048 | return rc; |
| 1049 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1050 | if (b_hw_start) { |
| 1051 | /* enable interrupts */ |
| 1052 | qed_int_igu_enable(p_hwfn, p_ptt, int_mode); |
| 1053 | |
| 1054 | /* send function start command */ |
Yuval Mintz | 831bfb0e | 2016-05-11 16:36:25 +0300 | [diff] [blame] | 1055 | rc = qed_sp_pf_start(p_hwfn, p_tunn, p_hwfn->cdev->mf_mode, |
| 1056 | allow_npar_tx_switch); |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1057 | if (rc) { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1058 | DP_NOTICE(p_hwfn, "Function start ramrod failed\n"); |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1059 | return rc; |
| 1060 | } |
| 1061 | if (p_hwfn->hw_info.personality == QED_PCI_FCOE) { |
| 1062 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1, BIT(2)); |
| 1063 | qed_wr(p_hwfn, p_ptt, |
| 1064 | PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST, |
| 1065 | 0x100); |
| 1066 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1067 | } |
| 1068 | return rc; |
| 1069 | } |
| 1070 | |
| 1071 | static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn, |
| 1072 | struct qed_ptt *p_ptt, |
| 1073 | u8 enable) |
| 1074 | { |
| 1075 | u32 delay_idx = 0, val, set_val = enable ? 1 : 0; |
| 1076 | |
| 1077 | /* Change PF in PXP */ |
| 1078 | qed_wr(p_hwfn, p_ptt, |
| 1079 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val); |
| 1080 | |
| 1081 | /* wait until value is set - try for 1 second every 50us */ |
| 1082 | for (delay_idx = 0; delay_idx < 20000; delay_idx++) { |
| 1083 | val = qed_rd(p_hwfn, p_ptt, |
| 1084 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER); |
| 1085 | if (val == set_val) |
| 1086 | break; |
| 1087 | |
| 1088 | usleep_range(50, 60); |
| 1089 | } |
| 1090 | |
| 1091 | if (val != set_val) { |
| 1092 | DP_NOTICE(p_hwfn, |
| 1093 | "PFID_ENABLE_MASTER wasn't changed after a second\n"); |
| 1094 | return -EAGAIN; |
| 1095 | } |
| 1096 | |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
| 1100 | static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn, |
| 1101 | struct qed_ptt *p_main_ptt) |
| 1102 | { |
| 1103 | /* Read shadow of current MFW mailbox */ |
| 1104 | qed_mcp_read_mb(p_hwfn, p_main_ptt); |
| 1105 | memcpy(p_hwfn->mcp_info->mfw_mb_shadow, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1106 | p_hwfn->mcp_info->mfw_mb_cur, p_hwfn->mcp_info->mfw_mb_length); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | int qed_hw_init(struct qed_dev *cdev, |
Manish Chopra | 464f664 | 2016-04-14 01:38:29 -0400 | [diff] [blame] | 1110 | struct qed_tunn_start_params *p_tunn, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1111 | bool b_hw_start, |
| 1112 | enum qed_int_mode int_mode, |
| 1113 | bool allow_npar_tx_switch, |
| 1114 | const u8 *bin_fw_data) |
| 1115 | { |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1116 | u32 load_code, param, drv_mb_param; |
| 1117 | bool b_default_mtu = true; |
| 1118 | struct qed_hwfn *p_hwfn; |
| 1119 | int rc = 0, mfw_rc, i; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1120 | |
Sudarsana Reddy Kalluru | bb13ace | 2016-05-26 11:01:23 +0300 | [diff] [blame] | 1121 | if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) { |
| 1122 | DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n"); |
| 1123 | return -EINVAL; |
| 1124 | } |
| 1125 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1126 | if (IS_PF(cdev)) { |
| 1127 | rc = qed_init_fw_data(cdev, bin_fw_data); |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1128 | if (rc) |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1129 | return rc; |
| 1130 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1131 | |
| 1132 | for_each_hwfn(cdev, i) { |
| 1133 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 1134 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1135 | /* If management didn't provide a default, set one of our own */ |
| 1136 | if (!p_hwfn->hw_info.mtu) { |
| 1137 | p_hwfn->hw_info.mtu = 1500; |
| 1138 | b_default_mtu = false; |
| 1139 | } |
| 1140 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1141 | if (IS_VF(cdev)) { |
| 1142 | p_hwfn->b_int_enabled = 1; |
| 1143 | continue; |
| 1144 | } |
| 1145 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1146 | /* Enable DMAE in PXP */ |
| 1147 | rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true); |
| 1148 | |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1149 | rc = qed_calc_hw_mode(p_hwfn); |
| 1150 | if (rc) |
| 1151 | return rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1152 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1153 | rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt, &load_code); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1154 | if (rc) { |
| 1155 | DP_NOTICE(p_hwfn, "Failed sending LOAD_REQ command\n"); |
| 1156 | return rc; |
| 1157 | } |
| 1158 | |
| 1159 | qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt); |
| 1160 | |
| 1161 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 1162 | "Load request was sent. Resp:0x%x, Load code: 0x%x\n", |
| 1163 | rc, load_code); |
| 1164 | |
| 1165 | p_hwfn->first_on_engine = (load_code == |
| 1166 | FW_MSG_CODE_DRV_LOAD_ENGINE); |
| 1167 | |
| 1168 | switch (load_code) { |
| 1169 | case FW_MSG_CODE_DRV_LOAD_ENGINE: |
| 1170 | rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt, |
| 1171 | p_hwfn->hw_info.hw_mode); |
| 1172 | if (rc) |
| 1173 | break; |
| 1174 | /* Fall into */ |
| 1175 | case FW_MSG_CODE_DRV_LOAD_PORT: |
| 1176 | rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt, |
| 1177 | p_hwfn->hw_info.hw_mode); |
| 1178 | if (rc) |
| 1179 | break; |
| 1180 | |
| 1181 | /* Fall into */ |
| 1182 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
| 1183 | rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt, |
Manish Chopra | 464f664 | 2016-04-14 01:38:29 -0400 | [diff] [blame] | 1184 | p_tunn, p_hwfn->hw_info.hw_mode, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1185 | b_hw_start, int_mode, |
| 1186 | allow_npar_tx_switch); |
| 1187 | break; |
| 1188 | default: |
| 1189 | rc = -EINVAL; |
| 1190 | break; |
| 1191 | } |
| 1192 | |
| 1193 | if (rc) |
| 1194 | DP_NOTICE(p_hwfn, |
| 1195 | "init phase failed for loadcode 0x%x (rc %d)\n", |
| 1196 | load_code, rc); |
| 1197 | |
| 1198 | /* ACK mfw regardless of success or failure of initialization */ |
| 1199 | mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt, |
| 1200 | DRV_MSG_CODE_LOAD_DONE, |
| 1201 | 0, &load_code, ¶m); |
| 1202 | if (rc) |
| 1203 | return rc; |
| 1204 | if (mfw_rc) { |
| 1205 | DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n"); |
| 1206 | return mfw_rc; |
| 1207 | } |
| 1208 | |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 1209 | /* send DCBX attention request command */ |
| 1210 | DP_VERBOSE(p_hwfn, |
| 1211 | QED_MSG_DCB, |
| 1212 | "sending phony dcbx set command to trigger DCBx attention handling\n"); |
| 1213 | mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt, |
| 1214 | DRV_MSG_CODE_SET_DCBX, |
| 1215 | 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT, |
| 1216 | &load_code, ¶m); |
| 1217 | if (mfw_rc) { |
| 1218 | DP_NOTICE(p_hwfn, |
| 1219 | "Failed to send DCBX attention request\n"); |
| 1220 | return mfw_rc; |
| 1221 | } |
| 1222 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1223 | p_hwfn->hw_init_done = true; |
| 1224 | } |
| 1225 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1226 | if (IS_PF(cdev)) { |
| 1227 | p_hwfn = QED_LEADING_HWFN(cdev); |
| 1228 | drv_mb_param = (FW_MAJOR_VERSION << 24) | |
| 1229 | (FW_MINOR_VERSION << 16) | |
| 1230 | (FW_REVISION_VERSION << 8) | |
| 1231 | (FW_ENGINEERING_VERSION); |
| 1232 | rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt, |
| 1233 | DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER, |
| 1234 | drv_mb_param, &load_code, ¶m); |
| 1235 | if (rc) |
| 1236 | DP_INFO(p_hwfn, "Failed to update firmware version\n"); |
| 1237 | |
| 1238 | if (!b_default_mtu) { |
| 1239 | rc = qed_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt, |
| 1240 | p_hwfn->hw_info.mtu); |
| 1241 | if (rc) |
| 1242 | DP_INFO(p_hwfn, |
| 1243 | "Failed to update default mtu\n"); |
| 1244 | } |
| 1245 | |
| 1246 | rc = qed_mcp_ov_update_driver_state(p_hwfn, |
| 1247 | p_hwfn->p_main_ptt, |
| 1248 | QED_OV_DRIVER_STATE_DISABLED); |
| 1249 | if (rc) |
| 1250 | DP_INFO(p_hwfn, "Failed to update driver state\n"); |
| 1251 | |
| 1252 | rc = qed_mcp_ov_update_eswitch(p_hwfn, p_hwfn->p_main_ptt, |
| 1253 | QED_OV_ESWITCH_VEB); |
| 1254 | if (rc) |
| 1255 | DP_INFO(p_hwfn, "Failed to update eswitch mode\n"); |
| 1256 | } |
| 1257 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1258 | return 0; |
| 1259 | } |
| 1260 | |
| 1261 | #define QED_HW_STOP_RETRY_LIMIT (10) |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1262 | static void qed_hw_timers_stop(struct qed_dev *cdev, |
| 1263 | struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1264 | { |
| 1265 | int i; |
| 1266 | |
| 1267 | /* close timers */ |
| 1268 | qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0); |
| 1269 | qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0); |
| 1270 | |
| 1271 | for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) { |
| 1272 | if ((!qed_rd(p_hwfn, p_ptt, |
| 1273 | TM_REG_PF_SCAN_ACTIVE_CONN)) && |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1274 | (!qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK))) |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1275 | break; |
| 1276 | |
| 1277 | /* Dependent on number of connection/tasks, possibly |
| 1278 | * 1ms sleep is required between polls |
| 1279 | */ |
| 1280 | usleep_range(1000, 2000); |
| 1281 | } |
| 1282 | |
| 1283 | if (i < QED_HW_STOP_RETRY_LIMIT) |
| 1284 | return; |
| 1285 | |
| 1286 | DP_NOTICE(p_hwfn, |
| 1287 | "Timers linear scans are not over [Connection %02x Tasks %02x]\n", |
| 1288 | (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN), |
| 1289 | (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)); |
| 1290 | } |
| 1291 | |
| 1292 | void qed_hw_timers_stop_all(struct qed_dev *cdev) |
| 1293 | { |
| 1294 | int j; |
| 1295 | |
| 1296 | for_each_hwfn(cdev, j) { |
| 1297 | struct qed_hwfn *p_hwfn = &cdev->hwfns[j]; |
| 1298 | struct qed_ptt *p_ptt = p_hwfn->p_main_ptt; |
| 1299 | |
| 1300 | qed_hw_timers_stop(cdev, p_hwfn, p_ptt); |
| 1301 | } |
| 1302 | } |
| 1303 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1304 | int qed_hw_stop(struct qed_dev *cdev) |
| 1305 | { |
| 1306 | int rc = 0, t_rc; |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1307 | int j; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1308 | |
| 1309 | for_each_hwfn(cdev, j) { |
| 1310 | struct qed_hwfn *p_hwfn = &cdev->hwfns[j]; |
| 1311 | struct qed_ptt *p_ptt = p_hwfn->p_main_ptt; |
| 1312 | |
| 1313 | DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n"); |
| 1314 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1315 | if (IS_VF(cdev)) { |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 1316 | qed_vf_pf_int_cleanup(p_hwfn); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1317 | continue; |
| 1318 | } |
| 1319 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1320 | /* mark the hw as uninitialized... */ |
| 1321 | p_hwfn->hw_init_done = false; |
| 1322 | |
| 1323 | rc = qed_sp_pf_stop(p_hwfn); |
| 1324 | if (rc) |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1325 | DP_NOTICE(p_hwfn, |
| 1326 | "Failed to close PF against FW. Continue to stop HW to prevent illegal host access by the device\n"); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1327 | |
| 1328 | qed_wr(p_hwfn, p_ptt, |
| 1329 | NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1); |
| 1330 | |
| 1331 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0); |
| 1332 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0); |
| 1333 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0); |
| 1334 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0); |
| 1335 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0); |
| 1336 | |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1337 | qed_hw_timers_stop(cdev, p_hwfn, p_ptt); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1338 | |
| 1339 | /* Disable Attention Generation */ |
| 1340 | qed_int_igu_disable_int(p_hwfn, p_ptt); |
| 1341 | |
| 1342 | qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0); |
| 1343 | qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0); |
| 1344 | |
| 1345 | qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true); |
| 1346 | |
| 1347 | /* Need to wait 1ms to guarantee SBs are cleared */ |
| 1348 | usleep_range(1000, 2000); |
| 1349 | } |
| 1350 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1351 | if (IS_PF(cdev)) { |
| 1352 | /* Disable DMAE in PXP - in CMT, this should only be done for |
| 1353 | * first hw-function, and only after all transactions have |
| 1354 | * stopped for all active hw-functions. |
| 1355 | */ |
| 1356 | t_rc = qed_change_pci_hwfn(&cdev->hwfns[0], |
| 1357 | cdev->hwfns[0].p_main_ptt, false); |
| 1358 | if (t_rc != 0) |
| 1359 | rc = t_rc; |
| 1360 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1361 | |
| 1362 | return rc; |
| 1363 | } |
| 1364 | |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1365 | void qed_hw_stop_fastpath(struct qed_dev *cdev) |
| 1366 | { |
Yuval Mintz | 8c925c4 | 2016-03-02 20:26:03 +0200 | [diff] [blame] | 1367 | int j; |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1368 | |
| 1369 | for_each_hwfn(cdev, j) { |
| 1370 | struct qed_hwfn *p_hwfn = &cdev->hwfns[j]; |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 1371 | struct qed_ptt *p_ptt = p_hwfn->p_main_ptt; |
| 1372 | |
| 1373 | if (IS_VF(cdev)) { |
| 1374 | qed_vf_pf_int_cleanup(p_hwfn); |
| 1375 | continue; |
| 1376 | } |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1377 | |
| 1378 | DP_VERBOSE(p_hwfn, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1379 | NETIF_MSG_IFDOWN, "Shutting down the fastpath\n"); |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1380 | |
| 1381 | qed_wr(p_hwfn, p_ptt, |
| 1382 | NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1); |
| 1383 | |
| 1384 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0); |
| 1385 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0); |
| 1386 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0); |
| 1387 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0); |
| 1388 | qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0); |
| 1389 | |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1390 | qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false); |
| 1391 | |
| 1392 | /* Need to wait 1ms to guarantee SBs are cleared */ |
| 1393 | usleep_range(1000, 2000); |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn) |
| 1398 | { |
Yuval Mintz | dacd88d | 2016-05-11 16:36:16 +0300 | [diff] [blame] | 1399 | if (IS_VF(p_hwfn->cdev)) |
| 1400 | return; |
| 1401 | |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1402 | /* Re-open incoming traffic */ |
| 1403 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1404 | NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0); |
| 1405 | } |
| 1406 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1407 | static int qed_reg_assert(struct qed_hwfn *p_hwfn, |
| 1408 | struct qed_ptt *p_ptt, u32 reg, bool expected) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1409 | { |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1410 | u32 assert_val = qed_rd(p_hwfn, p_ptt, reg); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1411 | |
| 1412 | if (assert_val != expected) { |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 1413 | DP_NOTICE(p_hwfn, "Value at address 0x%08x != 0x%08x\n", |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1414 | reg, expected); |
| 1415 | return -EINVAL; |
| 1416 | } |
| 1417 | |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | int qed_hw_reset(struct qed_dev *cdev) |
| 1422 | { |
| 1423 | int rc = 0; |
| 1424 | u32 unload_resp, unload_param; |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1425 | u32 wol_param; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1426 | int i; |
| 1427 | |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1428 | switch (cdev->wol_config) { |
| 1429 | case QED_OV_WOL_DISABLED: |
| 1430 | wol_param = DRV_MB_PARAM_UNLOAD_WOL_DISABLED; |
| 1431 | break; |
| 1432 | case QED_OV_WOL_ENABLED: |
| 1433 | wol_param = DRV_MB_PARAM_UNLOAD_WOL_ENABLED; |
| 1434 | break; |
| 1435 | default: |
| 1436 | DP_NOTICE(cdev, |
| 1437 | "Unknown WoL configuration %02x\n", cdev->wol_config); |
| 1438 | /* Fallthrough */ |
| 1439 | case QED_OV_WOL_DEFAULT: |
| 1440 | wol_param = DRV_MB_PARAM_UNLOAD_WOL_MCP; |
| 1441 | } |
| 1442 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1443 | for_each_hwfn(cdev, i) { |
| 1444 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 1445 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1446 | if (IS_VF(cdev)) { |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 1447 | rc = qed_vf_pf_reset(p_hwfn); |
| 1448 | if (rc) |
| 1449 | return rc; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1450 | continue; |
| 1451 | } |
| 1452 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1453 | DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Resetting hw/fw\n"); |
| 1454 | |
| 1455 | /* Check for incorrect states */ |
| 1456 | qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt, |
| 1457 | QM_REG_USG_CNT_PF_TX, 0); |
| 1458 | qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt, |
| 1459 | QM_REG_USG_CNT_PF_OTHER, 0); |
| 1460 | |
| 1461 | /* Disable PF in HW blocks */ |
| 1462 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0); |
| 1463 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0); |
| 1464 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1465 | TCFC_REG_STRONG_ENABLE_PF, 0); |
| 1466 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1467 | CCFC_REG_STRONG_ENABLE_PF, 0); |
| 1468 | |
| 1469 | /* Send unload command to MCP */ |
| 1470 | rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt, |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1471 | DRV_MSG_CODE_UNLOAD_REQ, wol_param, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1472 | &unload_resp, &unload_param); |
| 1473 | if (rc) { |
| 1474 | DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_REQ failed\n"); |
| 1475 | unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE; |
| 1476 | } |
| 1477 | |
| 1478 | rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt, |
| 1479 | DRV_MSG_CODE_UNLOAD_DONE, |
| 1480 | 0, &unload_resp, &unload_param); |
| 1481 | if (rc) { |
| 1482 | DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_DONE failed\n"); |
| 1483 | return rc; |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | return rc; |
| 1488 | } |
| 1489 | |
| 1490 | /* Free hwfn memory and resources acquired in hw_hwfn_prepare */ |
| 1491 | static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn) |
| 1492 | { |
| 1493 | qed_ptt_pool_free(p_hwfn); |
| 1494 | kfree(p_hwfn->hw_info.p_igu_info); |
| 1495 | } |
| 1496 | |
| 1497 | /* Setup bar access */ |
Yuval Mintz | 12e09c6 | 2016-03-02 20:26:01 +0200 | [diff] [blame] | 1498 | static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1499 | { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1500 | /* clear indirect access */ |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1501 | if (QED_IS_AH(p_hwfn->cdev)) { |
| 1502 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1503 | PGLUE_B_REG_PGL_ADDR_E8_F0_K2, 0); |
| 1504 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1505 | PGLUE_B_REG_PGL_ADDR_EC_F0_K2, 0); |
| 1506 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1507 | PGLUE_B_REG_PGL_ADDR_F0_F0_K2, 0); |
| 1508 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1509 | PGLUE_B_REG_PGL_ADDR_F4_F0_K2, 0); |
| 1510 | } else { |
| 1511 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1512 | PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0); |
| 1513 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1514 | PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0); |
| 1515 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1516 | PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0); |
| 1517 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1518 | PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0); |
| 1519 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1520 | |
| 1521 | /* Clean Previous errors if such exist */ |
| 1522 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1523 | PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1524 | |
| 1525 | /* enable internal target-read */ |
| 1526 | qed_wr(p_hwfn, p_hwfn->p_main_ptt, |
| 1527 | PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | static void get_function_id(struct qed_hwfn *p_hwfn) |
| 1531 | { |
| 1532 | /* ME Register */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1533 | p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn, |
| 1534 | PXP_PF_ME_OPAQUE_ADDR); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1535 | |
| 1536 | p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR); |
| 1537 | |
| 1538 | p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf; |
| 1539 | p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid, |
| 1540 | PXP_CONCRETE_FID_PFID); |
| 1541 | p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid, |
| 1542 | PXP_CONCRETE_FID_PORT); |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 1543 | |
| 1544 | DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE, |
| 1545 | "Read ME register: Concrete 0x%08x Opaque 0x%04x\n", |
| 1546 | p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1547 | } |
| 1548 | |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame] | 1549 | static void qed_hw_set_feat(struct qed_hwfn *p_hwfn) |
| 1550 | { |
| 1551 | u32 *feat_num = p_hwfn->hw_info.feat_num; |
Mintz, Yuval | 5a1f965 | 2016-10-31 07:14:26 +0200 | [diff] [blame] | 1552 | struct qed_sb_cnt_info sb_cnt_info; |
Mintz, Yuval | 810bb1f | 2017-03-23 15:50:19 +0200 | [diff] [blame] | 1553 | u32 non_l2_sbs = 0; |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame] | 1554 | |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 1555 | if (IS_ENABLED(CONFIG_QED_RDMA) && |
| 1556 | p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) { |
| 1557 | /* Roce CNQ each requires: 1 status block + 1 CNQ. We divide |
| 1558 | * the status blocks equally between L2 / RoCE but with |
| 1559 | * consideration as to how many l2 queues / cnqs we have. |
| 1560 | */ |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 1561 | feat_num[QED_RDMA_CNQ] = |
Mintz, Yuval | 810bb1f | 2017-03-23 15:50:19 +0200 | [diff] [blame] | 1562 | min_t(u32, RESC_NUM(p_hwfn, QED_SB) / 2, |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 1563 | RESC_NUM(p_hwfn, QED_RDMA_CNQ_RAM)); |
Mintz, Yuval | 810bb1f | 2017-03-23 15:50:19 +0200 | [diff] [blame] | 1564 | |
| 1565 | non_l2_sbs = feat_num[QED_RDMA_CNQ]; |
Ram Amrani | 51ff172 | 2016-10-01 21:59:57 +0300 | [diff] [blame] | 1566 | } |
Yuval Mintz | 0189efb | 2016-10-13 22:57:02 +0300 | [diff] [blame] | 1567 | |
Mintz, Yuval | dec2653 | 2017-03-23 15:50:20 +0200 | [diff] [blame^] | 1568 | if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE || |
| 1569 | p_hwfn->hw_info.personality == QED_PCI_ETH) { |
| 1570 | /* Start by allocating VF queues, then PF's */ |
| 1571 | memset(&sb_cnt_info, 0, sizeof(sb_cnt_info)); |
| 1572 | qed_int_get_num_sbs(p_hwfn, &sb_cnt_info); |
| 1573 | feat_num[QED_VF_L2_QUE] = min_t(u32, |
| 1574 | RESC_NUM(p_hwfn, QED_L2_QUEUE), |
| 1575 | sb_cnt_info.sb_iov_cnt); |
| 1576 | feat_num[QED_PF_L2_QUE] = min_t(u32, |
| 1577 | RESC_NUM(p_hwfn, QED_SB) - |
| 1578 | non_l2_sbs, |
| 1579 | RESC_NUM(p_hwfn, |
| 1580 | QED_L2_QUEUE) - |
| 1581 | FEAT_NUM(p_hwfn, |
| 1582 | QED_VF_L2_QUE)); |
| 1583 | } |
Mintz, Yuval | 5a1f965 | 2016-10-31 07:14:26 +0200 | [diff] [blame] | 1584 | |
| 1585 | DP_VERBOSE(p_hwfn, |
| 1586 | NETIF_MSG_PROBE, |
Mintz, Yuval | 810bb1f | 2017-03-23 15:50:19 +0200 | [diff] [blame] | 1587 | "#PF_L2_QUEUES=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d #SBS=%d\n", |
Mintz, Yuval | 5a1f965 | 2016-10-31 07:14:26 +0200 | [diff] [blame] | 1588 | (int)FEAT_NUM(p_hwfn, QED_PF_L2_QUE), |
| 1589 | (int)FEAT_NUM(p_hwfn, QED_VF_L2_QUE), |
| 1590 | (int)FEAT_NUM(p_hwfn, QED_RDMA_CNQ), |
Mintz, Yuval | 810bb1f | 2017-03-23 15:50:19 +0200 | [diff] [blame] | 1591 | RESC_NUM(p_hwfn, QED_SB)); |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame] | 1592 | } |
| 1593 | |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1594 | static enum resource_id_enum qed_hw_get_mfw_res_id(enum qed_resources res_id) |
| 1595 | { |
| 1596 | enum resource_id_enum mfw_res_id = RESOURCE_NUM_INVALID; |
| 1597 | |
| 1598 | switch (res_id) { |
| 1599 | case QED_SB: |
| 1600 | mfw_res_id = RESOURCE_NUM_SB_E; |
| 1601 | break; |
| 1602 | case QED_L2_QUEUE: |
| 1603 | mfw_res_id = RESOURCE_NUM_L2_QUEUE_E; |
| 1604 | break; |
| 1605 | case QED_VPORT: |
| 1606 | mfw_res_id = RESOURCE_NUM_VPORT_E; |
| 1607 | break; |
| 1608 | case QED_RSS_ENG: |
| 1609 | mfw_res_id = RESOURCE_NUM_RSS_ENGINES_E; |
| 1610 | break; |
| 1611 | case QED_PQ: |
| 1612 | mfw_res_id = RESOURCE_NUM_PQ_E; |
| 1613 | break; |
| 1614 | case QED_RL: |
| 1615 | mfw_res_id = RESOURCE_NUM_RL_E; |
| 1616 | break; |
| 1617 | case QED_MAC: |
| 1618 | case QED_VLAN: |
| 1619 | /* Each VFC resource can accommodate both a MAC and a VLAN */ |
| 1620 | mfw_res_id = RESOURCE_VFC_FILTER_E; |
| 1621 | break; |
| 1622 | case QED_ILT: |
| 1623 | mfw_res_id = RESOURCE_ILT_E; |
| 1624 | break; |
| 1625 | case QED_LL2_QUEUE: |
| 1626 | mfw_res_id = RESOURCE_LL2_QUEUE_E; |
| 1627 | break; |
| 1628 | case QED_RDMA_CNQ_RAM: |
| 1629 | case QED_CMDQS_CQS: |
| 1630 | /* CNQ/CMDQS are the same resource */ |
| 1631 | mfw_res_id = RESOURCE_CQS_E; |
| 1632 | break; |
| 1633 | case QED_RDMA_STATS_QUEUE: |
| 1634 | mfw_res_id = RESOURCE_RDMA_STATS_QUEUE_E; |
| 1635 | break; |
| 1636 | default: |
| 1637 | break; |
| 1638 | } |
| 1639 | |
| 1640 | return mfw_res_id; |
| 1641 | } |
| 1642 | |
| 1643 | static u32 qed_hw_get_dflt_resc_num(struct qed_hwfn *p_hwfn, |
| 1644 | enum qed_resources res_id) |
| 1645 | { |
| 1646 | u8 num_funcs = p_hwfn->num_funcs_on_engine; |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1647 | bool b_ah = QED_IS_AH(p_hwfn->cdev); |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1648 | struct qed_sb_cnt_info sb_cnt_info; |
| 1649 | u32 dflt_resc_num = 0; |
| 1650 | |
| 1651 | switch (res_id) { |
| 1652 | case QED_SB: |
| 1653 | memset(&sb_cnt_info, 0, sizeof(sb_cnt_info)); |
| 1654 | qed_int_get_num_sbs(p_hwfn, &sb_cnt_info); |
| 1655 | dflt_resc_num = sb_cnt_info.sb_cnt; |
| 1656 | break; |
| 1657 | case QED_L2_QUEUE: |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1658 | dflt_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 |
| 1659 | : MAX_NUM_L2_QUEUES_BB) / num_funcs; |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1660 | break; |
| 1661 | case QED_VPORT: |
| 1662 | dflt_resc_num = MAX_NUM_VPORTS_BB / num_funcs; |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1663 | dflt_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 |
| 1664 | : MAX_NUM_VPORTS_BB) / num_funcs; |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1665 | break; |
| 1666 | case QED_RSS_ENG: |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1667 | dflt_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 |
| 1668 | : ETH_RSS_ENGINE_NUM_BB) / num_funcs; |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1669 | break; |
| 1670 | case QED_PQ: |
| 1671 | /* The granularity of the PQs is 8 */ |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1672 | dflt_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 |
| 1673 | : MAX_QM_TX_QUEUES_BB) / num_funcs; |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1674 | dflt_resc_num &= ~0x7; |
| 1675 | break; |
| 1676 | case QED_RL: |
| 1677 | dflt_resc_num = MAX_QM_GLOBAL_RLS / num_funcs; |
| 1678 | break; |
| 1679 | case QED_MAC: |
| 1680 | case QED_VLAN: |
| 1681 | /* Each VFC resource can accommodate both a MAC and a VLAN */ |
| 1682 | dflt_resc_num = ETH_NUM_MAC_FILTERS / num_funcs; |
| 1683 | break; |
| 1684 | case QED_ILT: |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1685 | dflt_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 |
| 1686 | : PXP_NUM_ILT_RECORDS_BB) / num_funcs; |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1687 | break; |
| 1688 | case QED_LL2_QUEUE: |
| 1689 | dflt_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs; |
| 1690 | break; |
| 1691 | case QED_RDMA_CNQ_RAM: |
| 1692 | case QED_CMDQS_CQS: |
| 1693 | /* CNQ/CMDQS are the same resource */ |
| 1694 | dflt_resc_num = NUM_OF_CMDQS_CQS / num_funcs; |
| 1695 | break; |
| 1696 | case QED_RDMA_STATS_QUEUE: |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1697 | dflt_resc_num = (b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2 |
| 1698 | : RDMA_NUM_STATISTIC_COUNTERS_BB) / |
| 1699 | num_funcs; |
| 1700 | |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1701 | break; |
| 1702 | default: |
| 1703 | break; |
| 1704 | } |
| 1705 | |
| 1706 | return dflt_resc_num; |
| 1707 | } |
| 1708 | |
| 1709 | static const char *qed_hw_get_resc_name(enum qed_resources res_id) |
| 1710 | { |
| 1711 | switch (res_id) { |
| 1712 | case QED_SB: |
| 1713 | return "SB"; |
| 1714 | case QED_L2_QUEUE: |
| 1715 | return "L2_QUEUE"; |
| 1716 | case QED_VPORT: |
| 1717 | return "VPORT"; |
| 1718 | case QED_RSS_ENG: |
| 1719 | return "RSS_ENG"; |
| 1720 | case QED_PQ: |
| 1721 | return "PQ"; |
| 1722 | case QED_RL: |
| 1723 | return "RL"; |
| 1724 | case QED_MAC: |
| 1725 | return "MAC"; |
| 1726 | case QED_VLAN: |
| 1727 | return "VLAN"; |
| 1728 | case QED_RDMA_CNQ_RAM: |
| 1729 | return "RDMA_CNQ_RAM"; |
| 1730 | case QED_ILT: |
| 1731 | return "ILT"; |
| 1732 | case QED_LL2_QUEUE: |
| 1733 | return "LL2_QUEUE"; |
| 1734 | case QED_CMDQS_CQS: |
| 1735 | return "CMDQS_CQS"; |
| 1736 | case QED_RDMA_STATS_QUEUE: |
| 1737 | return "RDMA_STATS_QUEUE"; |
| 1738 | default: |
| 1739 | return "UNKNOWN_RESOURCE"; |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | static int qed_hw_set_resc_info(struct qed_hwfn *p_hwfn, |
| 1744 | enum qed_resources res_id) |
| 1745 | { |
| 1746 | u32 dflt_resc_num = 0, dflt_resc_start = 0, mcp_resp, mcp_param; |
| 1747 | u32 *p_resc_num, *p_resc_start; |
| 1748 | struct resource_info resc_info; |
| 1749 | int rc; |
| 1750 | |
| 1751 | p_resc_num = &RESC_NUM(p_hwfn, res_id); |
| 1752 | p_resc_start = &RESC_START(p_hwfn, res_id); |
| 1753 | |
| 1754 | /* Default values assumes that each function received equal share */ |
| 1755 | dflt_resc_num = qed_hw_get_dflt_resc_num(p_hwfn, res_id); |
| 1756 | if (!dflt_resc_num) { |
| 1757 | DP_ERR(p_hwfn, |
| 1758 | "Failed to get default amount for resource %d [%s]\n", |
| 1759 | res_id, qed_hw_get_resc_name(res_id)); |
| 1760 | return -EINVAL; |
| 1761 | } |
| 1762 | dflt_resc_start = dflt_resc_num * p_hwfn->enabled_func_idx; |
| 1763 | |
| 1764 | memset(&resc_info, 0, sizeof(resc_info)); |
| 1765 | resc_info.res_id = qed_hw_get_mfw_res_id(res_id); |
| 1766 | if (resc_info.res_id == RESOURCE_NUM_INVALID) { |
| 1767 | DP_ERR(p_hwfn, |
| 1768 | "Failed to match resource %d [%s] with the MFW resources\n", |
| 1769 | res_id, qed_hw_get_resc_name(res_id)); |
| 1770 | return -EINVAL; |
| 1771 | } |
| 1772 | |
| 1773 | rc = qed_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, &resc_info, |
| 1774 | &mcp_resp, &mcp_param); |
| 1775 | if (rc) { |
| 1776 | DP_NOTICE(p_hwfn, |
| 1777 | "MFW response failure for an allocation request for resource %d [%s]\n", |
| 1778 | res_id, qed_hw_get_resc_name(res_id)); |
| 1779 | return rc; |
| 1780 | } |
| 1781 | |
| 1782 | /* Default driver values are applied in the following cases: |
| 1783 | * - The resource allocation MB command is not supported by the MFW |
| 1784 | * - There is an internal error in the MFW while processing the request |
| 1785 | * - The resource ID is unknown to the MFW |
| 1786 | */ |
| 1787 | if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK && |
| 1788 | mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_DEPRECATED) { |
| 1789 | DP_NOTICE(p_hwfn, |
| 1790 | "Resource %d [%s]: No allocation info was received [mcp_resp 0x%x]. Applying default values [num %d, start %d].\n", |
| 1791 | res_id, |
| 1792 | qed_hw_get_resc_name(res_id), |
| 1793 | mcp_resp, dflt_resc_num, dflt_resc_start); |
| 1794 | *p_resc_num = dflt_resc_num; |
| 1795 | *p_resc_start = dflt_resc_start; |
| 1796 | goto out; |
| 1797 | } |
| 1798 | |
| 1799 | /* Special handling for status blocks; Would be revised in future */ |
| 1800 | if (res_id == QED_SB) { |
| 1801 | resc_info.size -= 1; |
| 1802 | resc_info.offset -= p_hwfn->enabled_func_idx; |
| 1803 | } |
| 1804 | |
| 1805 | *p_resc_num = resc_info.size; |
| 1806 | *p_resc_start = resc_info.offset; |
| 1807 | |
| 1808 | out: |
| 1809 | /* PQs have to divide by 8 [that's the HW granularity]. |
| 1810 | * Reduce number so it would fit. |
| 1811 | */ |
| 1812 | if ((res_id == QED_PQ) && ((*p_resc_num % 8) || (*p_resc_start % 8))) { |
| 1813 | DP_INFO(p_hwfn, |
| 1814 | "PQs need to align by 8; Number %08x --> %08x, Start %08x --> %08x\n", |
| 1815 | *p_resc_num, |
| 1816 | (*p_resc_num) & ~0x7, |
| 1817 | *p_resc_start, (*p_resc_start) & ~0x7); |
| 1818 | *p_resc_num &= ~0x7; |
| 1819 | *p_resc_start &= ~0x7; |
| 1820 | } |
| 1821 | |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 1825 | static int qed_hw_get_resc(struct qed_hwfn *p_hwfn) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1826 | { |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1827 | bool b_ah = QED_IS_AH(p_hwfn->cdev); |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1828 | u8 res_id; |
| 1829 | int rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1830 | |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1831 | for (res_id = 0; res_id < QED_MAX_RESC; res_id++) { |
| 1832 | rc = qed_hw_set_resc_info(p_hwfn, res_id); |
| 1833 | if (rc) |
| 1834 | return rc; |
| 1835 | } |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 1836 | |
| 1837 | /* Sanity for ILT */ |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1838 | if ((b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_K2)) || |
| 1839 | (!b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_BB))) { |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 1840 | DP_NOTICE(p_hwfn, "Can't assign ILT pages [%08x,...,%08x]\n", |
| 1841 | RESC_START(p_hwfn, QED_ILT), |
| 1842 | RESC_END(p_hwfn, QED_ILT) - 1); |
| 1843 | return -EINVAL; |
| 1844 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1845 | |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame] | 1846 | qed_hw_set_feat(p_hwfn); |
| 1847 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1848 | DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE, |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 1849 | "The numbers for each resource are:\n"); |
| 1850 | for (res_id = 0; res_id < QED_MAX_RESC; res_id++) |
| 1851 | DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE, "%s = %d start = %d\n", |
| 1852 | qed_hw_get_resc_name(res_id), |
| 1853 | RESC_NUM(p_hwfn, res_id), |
| 1854 | RESC_START(p_hwfn, res_id)); |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 1855 | |
| 1856 | return 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1857 | } |
| 1858 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1859 | static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1860 | { |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1861 | u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities; |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1862 | u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1863 | struct qed_mcp_link_params *link; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1864 | |
| 1865 | /* Read global nvm_cfg address */ |
| 1866 | nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0); |
| 1867 | |
| 1868 | /* Verify MCP has initialized it */ |
| 1869 | if (!nvm_cfg_addr) { |
| 1870 | DP_NOTICE(p_hwfn, "Shared memory not initialized\n"); |
| 1871 | return -EINVAL; |
| 1872 | } |
| 1873 | |
| 1874 | /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */ |
| 1875 | nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4); |
| 1876 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1877 | addr = MCP_REG_SCRATCH + nvm_cfg1_offset + |
| 1878 | offsetof(struct nvm_cfg1, glob) + |
| 1879 | offsetof(struct nvm_cfg1_glob, core_cfg); |
| 1880 | |
| 1881 | core_cfg = qed_rd(p_hwfn, p_ptt, addr); |
| 1882 | |
| 1883 | switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >> |
| 1884 | NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) { |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1885 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1886 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G; |
| 1887 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1888 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1889 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G; |
| 1890 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1891 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1892 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G; |
| 1893 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1894 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1895 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F; |
| 1896 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1897 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1898 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E; |
| 1899 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1900 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1901 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G; |
| 1902 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1903 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1904 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G; |
| 1905 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1906 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1907 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G; |
| 1908 | break; |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1909 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G: |
| 1910 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X10G; |
| 1911 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1912 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1913 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G; |
| 1914 | break; |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 1915 | case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G: |
| 1916 | p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X25G; |
| 1917 | break; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1918 | default: |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1919 | DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n", core_cfg); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1920 | break; |
| 1921 | } |
| 1922 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1923 | /* Read default link configuration */ |
| 1924 | link = &p_hwfn->mcp_info->link_input; |
| 1925 | port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset + |
| 1926 | offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]); |
| 1927 | link_temp = qed_rd(p_hwfn, p_ptt, |
| 1928 | port_cfg_addr + |
| 1929 | offsetof(struct nvm_cfg1_port, speed_cap_mask)); |
Yuval Mintz | 83aeb93 | 2016-08-15 10:42:44 +0300 | [diff] [blame] | 1930 | link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK; |
| 1931 | link->speed.advertised_speeds = link_temp; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1932 | |
Yuval Mintz | 83aeb93 | 2016-08-15 10:42:44 +0300 | [diff] [blame] | 1933 | link_temp = link->speed.advertised_speeds; |
| 1934 | p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1935 | |
| 1936 | link_temp = qed_rd(p_hwfn, p_ptt, |
| 1937 | port_cfg_addr + |
| 1938 | offsetof(struct nvm_cfg1_port, link_settings)); |
| 1939 | switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >> |
| 1940 | NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) { |
| 1941 | case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG: |
| 1942 | link->speed.autoneg = true; |
| 1943 | break; |
| 1944 | case NVM_CFG1_PORT_DRV_LINK_SPEED_1G: |
| 1945 | link->speed.forced_speed = 1000; |
| 1946 | break; |
| 1947 | case NVM_CFG1_PORT_DRV_LINK_SPEED_10G: |
| 1948 | link->speed.forced_speed = 10000; |
| 1949 | break; |
| 1950 | case NVM_CFG1_PORT_DRV_LINK_SPEED_25G: |
| 1951 | link->speed.forced_speed = 25000; |
| 1952 | break; |
| 1953 | case NVM_CFG1_PORT_DRV_LINK_SPEED_40G: |
| 1954 | link->speed.forced_speed = 40000; |
| 1955 | break; |
| 1956 | case NVM_CFG1_PORT_DRV_LINK_SPEED_50G: |
| 1957 | link->speed.forced_speed = 50000; |
| 1958 | break; |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1959 | case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G: |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1960 | link->speed.forced_speed = 100000; |
| 1961 | break; |
| 1962 | default: |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1963 | DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n", link_temp); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK; |
| 1967 | link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET; |
| 1968 | link->pause.autoneg = !!(link_temp & |
| 1969 | NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG); |
| 1970 | link->pause.forced_rx = !!(link_temp & |
| 1971 | NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX); |
| 1972 | link->pause.forced_tx = !!(link_temp & |
| 1973 | NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX); |
| 1974 | link->loopback_mode = 0; |
| 1975 | |
| 1976 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 1977 | "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n", |
| 1978 | link->speed.forced_speed, link->speed.advertised_speeds, |
| 1979 | link->speed.autoneg, link->pause.autoneg); |
| 1980 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1981 | /* Read Multi-function information from shmem */ |
| 1982 | addr = MCP_REG_SCRATCH + nvm_cfg1_offset + |
| 1983 | offsetof(struct nvm_cfg1, glob) + |
| 1984 | offsetof(struct nvm_cfg1_glob, generic_cont0); |
| 1985 | |
| 1986 | generic_cont0 = qed_rd(p_hwfn, p_ptt, addr); |
| 1987 | |
| 1988 | mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >> |
| 1989 | NVM_CFG1_GLOB_MF_MODE_OFFSET; |
| 1990 | |
| 1991 | switch (mf_mode) { |
| 1992 | case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED: |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1993 | p_hwfn->cdev->mf_mode = QED_MF_OVLAN; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1994 | break; |
| 1995 | case NVM_CFG1_GLOB_MF_MODE_NPAR1_0: |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1996 | p_hwfn->cdev->mf_mode = QED_MF_NPAR; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1997 | break; |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 1998 | case NVM_CFG1_GLOB_MF_MODE_DEFAULT: |
| 1999 | p_hwfn->cdev->mf_mode = QED_MF_DEFAULT; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2000 | break; |
| 2001 | } |
| 2002 | DP_INFO(p_hwfn, "Multi function mode is %08x\n", |
| 2003 | p_hwfn->cdev->mf_mode); |
| 2004 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2005 | /* Read Multi-function information from shmem */ |
| 2006 | addr = MCP_REG_SCRATCH + nvm_cfg1_offset + |
| 2007 | offsetof(struct nvm_cfg1, glob) + |
| 2008 | offsetof(struct nvm_cfg1_glob, device_capabilities); |
| 2009 | |
| 2010 | device_capabilities = qed_rd(p_hwfn, p_ptt, addr); |
| 2011 | if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET) |
| 2012 | __set_bit(QED_DEV_CAP_ETH, |
| 2013 | &p_hwfn->hw_info.device_capabilities); |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 2014 | if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE) |
| 2015 | __set_bit(QED_DEV_CAP_FCOE, |
| 2016 | &p_hwfn->hw_info.device_capabilities); |
Yuval Mintz | c5ac931 | 2016-06-03 14:35:34 +0300 | [diff] [blame] | 2017 | if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI) |
| 2018 | __set_bit(QED_DEV_CAP_ISCSI, |
| 2019 | &p_hwfn->hw_info.device_capabilities); |
| 2020 | if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE) |
| 2021 | __set_bit(QED_DEV_CAP_ROCE, |
| 2022 | &p_hwfn->hw_info.device_capabilities); |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2023 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2024 | return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt); |
| 2025 | } |
| 2026 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2027 | static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2028 | { |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 2029 | u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id; |
| 2030 | u32 reg_function_hide, tmp, eng_mask, low_pfs_mask; |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2031 | struct qed_dev *cdev = p_hwfn->cdev; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2032 | |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2033 | num_funcs = QED_IS_AH(cdev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2034 | |
| 2035 | /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values |
| 2036 | * in the other bits are selected. |
| 2037 | * Bits 1-15 are for functions 1-15, respectively, and their value is |
| 2038 | * '0' only for enabled functions (function 0 always exists and |
| 2039 | * enabled). |
| 2040 | * In case of CMT, only the "even" functions are enabled, and thus the |
| 2041 | * number of functions for both hwfns is learnt from the same bits. |
| 2042 | */ |
| 2043 | reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE); |
| 2044 | |
| 2045 | if (reg_function_hide & 0x1) { |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2046 | if (QED_IS_BB(cdev)) { |
| 2047 | if (QED_PATH_ID(p_hwfn) && cdev->num_hwfns == 1) { |
| 2048 | num_funcs = 0; |
| 2049 | eng_mask = 0xaaaa; |
| 2050 | } else { |
| 2051 | num_funcs = 1; |
| 2052 | eng_mask = 0x5554; |
| 2053 | } |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2054 | } else { |
| 2055 | num_funcs = 1; |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2056 | eng_mask = 0xfffe; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | /* Get the number of the enabled functions on the engine */ |
| 2060 | tmp = (reg_function_hide ^ 0xffffffff) & eng_mask; |
| 2061 | while (tmp) { |
| 2062 | if (tmp & 0x1) |
| 2063 | num_funcs++; |
| 2064 | tmp >>= 0x1; |
| 2065 | } |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 2066 | |
| 2067 | /* Get the PF index within the enabled functions */ |
| 2068 | low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1; |
| 2069 | tmp = reg_function_hide & eng_mask & low_pfs_mask; |
| 2070 | while (tmp) { |
| 2071 | if (tmp & 0x1) |
| 2072 | enabled_func_idx--; |
| 2073 | tmp >>= 0x1; |
| 2074 | } |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | p_hwfn->num_funcs_on_engine = num_funcs; |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 2078 | p_hwfn->enabled_func_idx = enabled_func_idx; |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2079 | |
| 2080 | DP_VERBOSE(p_hwfn, |
| 2081 | NETIF_MSG_PROBE, |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 2082 | "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n", |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2083 | p_hwfn->rel_pf_id, |
| 2084 | p_hwfn->abs_pf_id, |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 2085 | p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2086 | } |
| 2087 | |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2088 | static void qed_hw_info_port_num_bb(struct qed_hwfn *p_hwfn, |
| 2089 | struct qed_ptt *p_ptt) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2090 | { |
| 2091 | u32 port_mode; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2092 | |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2093 | port_mode = qed_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB_B0); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2094 | |
| 2095 | if (port_mode < 3) { |
| 2096 | p_hwfn->cdev->num_ports_in_engines = 1; |
| 2097 | } else if (port_mode <= 5) { |
| 2098 | p_hwfn->cdev->num_ports_in_engines = 2; |
| 2099 | } else { |
| 2100 | DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n", |
| 2101 | p_hwfn->cdev->num_ports_in_engines); |
| 2102 | |
| 2103 | /* Default num_ports_in_engines to something */ |
| 2104 | p_hwfn->cdev->num_ports_in_engines = 1; |
| 2105 | } |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | static void qed_hw_info_port_num_ah(struct qed_hwfn *p_hwfn, |
| 2109 | struct qed_ptt *p_ptt) |
| 2110 | { |
| 2111 | u32 port; |
| 2112 | int i; |
| 2113 | |
| 2114 | p_hwfn->cdev->num_ports_in_engines = 0; |
| 2115 | |
| 2116 | for (i = 0; i < MAX_NUM_PORTS_K2; i++) { |
| 2117 | port = qed_rd(p_hwfn, p_ptt, |
| 2118 | CNIG_REG_NIG_PORT0_CONF_K2 + (i * 4)); |
| 2119 | if (port & 1) |
| 2120 | p_hwfn->cdev->num_ports_in_engines++; |
| 2121 | } |
| 2122 | |
| 2123 | if (!p_hwfn->cdev->num_ports_in_engines) { |
| 2124 | DP_NOTICE(p_hwfn, "All NIG ports are inactive\n"); |
| 2125 | |
| 2126 | /* Default num_ports_in_engine to something */ |
| 2127 | p_hwfn->cdev->num_ports_in_engines = 1; |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | static void qed_hw_info_port_num(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2132 | { |
| 2133 | if (QED_IS_BB(p_hwfn->cdev)) |
| 2134 | qed_hw_info_port_num_bb(p_hwfn, p_ptt); |
| 2135 | else |
| 2136 | qed_hw_info_port_num_ah(p_hwfn, p_ptt); |
| 2137 | } |
| 2138 | |
| 2139 | static int |
| 2140 | qed_get_hw_info(struct qed_hwfn *p_hwfn, |
| 2141 | struct qed_ptt *p_ptt, |
| 2142 | enum qed_pci_personality personality) |
| 2143 | { |
| 2144 | int rc; |
| 2145 | |
| 2146 | /* Since all information is common, only first hwfns should do this */ |
| 2147 | if (IS_LEAD_HWFN(p_hwfn)) { |
| 2148 | rc = qed_iov_hw_info(p_hwfn); |
| 2149 | if (rc) |
| 2150 | return rc; |
| 2151 | } |
| 2152 | |
| 2153 | qed_hw_info_port_num(p_hwfn, p_ptt); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2154 | |
| 2155 | qed_hw_get_nvm_info(p_hwfn, p_ptt); |
| 2156 | |
| 2157 | rc = qed_int_igu_read_cam(p_hwfn, p_ptt); |
| 2158 | if (rc) |
| 2159 | return rc; |
| 2160 | |
| 2161 | if (qed_mcp_is_init(p_hwfn)) |
| 2162 | ether_addr_copy(p_hwfn->hw_info.hw_mac_addr, |
| 2163 | p_hwfn->mcp_info->func_info.mac); |
| 2164 | else |
| 2165 | eth_random_addr(p_hwfn->hw_info.hw_mac_addr); |
| 2166 | |
| 2167 | if (qed_mcp_is_init(p_hwfn)) { |
| 2168 | if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET) |
| 2169 | p_hwfn->hw_info.ovlan = |
| 2170 | p_hwfn->mcp_info->func_info.ovlan; |
| 2171 | |
| 2172 | qed_mcp_cmd_port_init(p_hwfn, p_ptt); |
| 2173 | } |
| 2174 | |
| 2175 | if (qed_mcp_is_init(p_hwfn)) { |
| 2176 | enum qed_pci_personality protocol; |
| 2177 | |
| 2178 | protocol = p_hwfn->mcp_info->func_info.protocol; |
| 2179 | p_hwfn->hw_info.personality = protocol; |
| 2180 | } |
| 2181 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2182 | qed_get_num_funcs(p_hwfn, p_ptt); |
| 2183 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2184 | if (qed_mcp_is_init(p_hwfn)) |
| 2185 | p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu; |
| 2186 | |
Yuval Mintz | dbb799c | 2016-06-03 14:35:35 +0300 | [diff] [blame] | 2187 | return qed_hw_get_resc(p_hwfn); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2188 | } |
| 2189 | |
Yuval Mintz | 12e09c6 | 2016-03-02 20:26:01 +0200 | [diff] [blame] | 2190 | static int qed_get_dev_info(struct qed_dev *cdev) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2191 | { |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2192 | struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev); |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2193 | u16 device_id_mask; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2194 | u32 tmp; |
| 2195 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2196 | /* Read Vendor Id / Device Id */ |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 2197 | pci_read_config_word(cdev->pdev, PCI_VENDOR_ID, &cdev->vendor_id); |
| 2198 | pci_read_config_word(cdev->pdev, PCI_DEVICE_ID, &cdev->device_id); |
| 2199 | |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2200 | /* Determine type */ |
| 2201 | device_id_mask = cdev->device_id & QED_DEV_ID_MASK; |
| 2202 | switch (device_id_mask) { |
| 2203 | case QED_DEV_ID_MASK_BB: |
| 2204 | cdev->type = QED_DEV_TYPE_BB; |
| 2205 | break; |
| 2206 | case QED_DEV_ID_MASK_AH: |
| 2207 | cdev->type = QED_DEV_TYPE_AH; |
| 2208 | break; |
| 2209 | default: |
| 2210 | DP_NOTICE(p_hwfn, "Unknown device id 0x%x\n", cdev->device_id); |
| 2211 | return -EBUSY; |
| 2212 | } |
| 2213 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2214 | cdev->chip_num = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2215 | MISCS_REG_CHIP_NUM); |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2216 | cdev->chip_rev = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2217 | MISCS_REG_CHIP_REV); |
| 2218 | MASK_FIELD(CHIP_REV, cdev->chip_rev); |
| 2219 | |
| 2220 | /* Learn number of HW-functions */ |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2221 | tmp = qed_rd(p_hwfn, p_hwfn->p_main_ptt, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2222 | MISCS_REG_CMT_ENABLED_FOR_PAIR); |
| 2223 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2224 | if (tmp & (1 << p_hwfn->rel_pf_id)) { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2225 | DP_NOTICE(cdev->hwfns, "device in CMT mode\n"); |
| 2226 | cdev->num_hwfns = 2; |
| 2227 | } else { |
| 2228 | cdev->num_hwfns = 1; |
| 2229 | } |
| 2230 | |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2231 | cdev->chip_bond_id = qed_rd(p_hwfn, p_hwfn->p_main_ptt, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2232 | MISCS_REG_CHIP_TEST_REG) >> 4; |
| 2233 | MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id); |
Yuval Mintz | fc48b7a | 2016-02-15 13:22:35 -0500 | [diff] [blame] | 2234 | cdev->chip_metal = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2235 | MISCS_REG_CHIP_METAL); |
| 2236 | MASK_FIELD(CHIP_METAL, cdev->chip_metal); |
| 2237 | |
| 2238 | DP_INFO(cdev->hwfns, |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 2239 | "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n", |
| 2240 | QED_IS_BB(cdev) ? "BB" : "AH", |
| 2241 | 'A' + cdev->chip_rev, |
| 2242 | (int)cdev->chip_metal, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2243 | cdev->chip_num, cdev->chip_rev, |
| 2244 | cdev->chip_bond_id, cdev->chip_metal); |
Yuval Mintz | 12e09c6 | 2016-03-02 20:26:01 +0200 | [diff] [blame] | 2245 | |
| 2246 | if (QED_IS_BB(cdev) && CHIP_REV_IS_A0(cdev)) { |
| 2247 | DP_NOTICE(cdev->hwfns, |
| 2248 | "The chip type/rev (BB A0) is not supported!\n"); |
| 2249 | return -EINVAL; |
| 2250 | } |
| 2251 | |
| 2252 | return 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn, |
| 2256 | void __iomem *p_regview, |
| 2257 | void __iomem *p_doorbells, |
| 2258 | enum qed_pci_personality personality) |
| 2259 | { |
| 2260 | int rc = 0; |
| 2261 | |
| 2262 | /* Split PCI bars evenly between hwfns */ |
| 2263 | p_hwfn->regview = p_regview; |
| 2264 | p_hwfn->doorbells = p_doorbells; |
| 2265 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2266 | if (IS_VF(p_hwfn->cdev)) |
| 2267 | return qed_vf_hw_prepare(p_hwfn); |
| 2268 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2269 | /* Validate that chip access is feasible */ |
| 2270 | if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) { |
| 2271 | DP_ERR(p_hwfn, |
| 2272 | "Reading the ME register returns all Fs; Preventing further chip access\n"); |
| 2273 | return -EINVAL; |
| 2274 | } |
| 2275 | |
| 2276 | get_function_id(p_hwfn); |
| 2277 | |
Yuval Mintz | 12e09c6 | 2016-03-02 20:26:01 +0200 | [diff] [blame] | 2278 | /* Allocate PTT pool */ |
| 2279 | rc = qed_ptt_pool_alloc(p_hwfn); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 2280 | if (rc) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2281 | goto err0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2282 | |
Yuval Mintz | 12e09c6 | 2016-03-02 20:26:01 +0200 | [diff] [blame] | 2283 | /* Allocate the main PTT */ |
| 2284 | p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN); |
| 2285 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2286 | /* First hwfn learns basic information, e.g., number of hwfns */ |
Yuval Mintz | 12e09c6 | 2016-03-02 20:26:01 +0200 | [diff] [blame] | 2287 | if (!p_hwfn->my_id) { |
| 2288 | rc = qed_get_dev_info(p_hwfn->cdev); |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 2289 | if (rc) |
Yuval Mintz | 12e09c6 | 2016-03-02 20:26:01 +0200 | [diff] [blame] | 2290 | goto err1; |
| 2291 | } |
| 2292 | |
| 2293 | qed_hw_hwfn_prepare(p_hwfn); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2294 | |
| 2295 | /* Initialize MCP structure */ |
| 2296 | rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt); |
| 2297 | if (rc) { |
| 2298 | DP_NOTICE(p_hwfn, "Failed initializing mcp command\n"); |
| 2299 | goto err1; |
| 2300 | } |
| 2301 | |
| 2302 | /* Read the device configuration information from the HW and SHMEM */ |
| 2303 | rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality); |
| 2304 | if (rc) { |
| 2305 | DP_NOTICE(p_hwfn, "Failed to get HW information\n"); |
| 2306 | goto err2; |
| 2307 | } |
| 2308 | |
| 2309 | /* Allocate the init RT array and initialize the init-ops engine */ |
| 2310 | rc = qed_init_alloc(p_hwfn); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 2311 | if (rc) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2312 | goto err2; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2313 | |
| 2314 | return rc; |
| 2315 | err2: |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 2316 | if (IS_LEAD_HWFN(p_hwfn)) |
| 2317 | qed_iov_free_hw_info(p_hwfn->cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2318 | qed_mcp_free(p_hwfn); |
| 2319 | err1: |
| 2320 | qed_hw_hwfn_free(p_hwfn); |
| 2321 | err0: |
| 2322 | return rc; |
| 2323 | } |
| 2324 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2325 | int qed_hw_prepare(struct qed_dev *cdev, |
| 2326 | int personality) |
| 2327 | { |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2328 | struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev); |
| 2329 | int rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2330 | |
| 2331 | /* Store the precompiled init data ptrs */ |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2332 | if (IS_PF(cdev)) |
| 2333 | qed_init_iro_array(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2334 | |
| 2335 | /* Initialize the first hwfn - will learn number of hwfns */ |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2336 | rc = qed_hw_prepare_single(p_hwfn, |
| 2337 | cdev->regview, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2338 | cdev->doorbells, personality); |
| 2339 | if (rc) |
| 2340 | return rc; |
| 2341 | |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2342 | personality = p_hwfn->hw_info.personality; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2343 | |
| 2344 | /* Initialize the rest of the hwfns */ |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2345 | if (cdev->num_hwfns > 1) { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2346 | void __iomem *p_regview, *p_doorbell; |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2347 | u8 __iomem *addr; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2348 | |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2349 | /* adjust bar offset for second engine */ |
Ram Amrani | c2035ee | 2016-03-02 20:26:00 +0200 | [diff] [blame] | 2350 | addr = cdev->regview + qed_hw_bar_size(p_hwfn, BAR_ID_0) / 2; |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2351 | p_regview = addr; |
| 2352 | |
| 2353 | /* adjust doorbell bar offset for second engine */ |
Ram Amrani | c2035ee | 2016-03-02 20:26:00 +0200 | [diff] [blame] | 2354 | addr = cdev->doorbells + qed_hw_bar_size(p_hwfn, BAR_ID_1) / 2; |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2355 | p_doorbell = addr; |
| 2356 | |
| 2357 | /* prepare second hw function */ |
| 2358 | rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2359 | p_doorbell, personality); |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2360 | |
| 2361 | /* in case of error, need to free the previously |
| 2362 | * initiliazed hwfn 0. |
| 2363 | */ |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2364 | if (rc) { |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2365 | if (IS_PF(cdev)) { |
| 2366 | qed_init_free(p_hwfn); |
| 2367 | qed_mcp_free(p_hwfn); |
| 2368 | qed_hw_hwfn_free(p_hwfn); |
| 2369 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2370 | } |
| 2371 | } |
| 2372 | |
Ariel Elior | c78df14 | 2015-12-07 06:25:58 -0500 | [diff] [blame] | 2373 | return rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | void qed_hw_remove(struct qed_dev *cdev) |
| 2377 | { |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2378 | struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2379 | int i; |
| 2380 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2381 | if (IS_PF(cdev)) |
| 2382 | qed_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt, |
| 2383 | QED_OV_DRIVER_STATE_NOT_LOADED); |
| 2384 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2385 | for_each_hwfn(cdev, i) { |
| 2386 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 2387 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2388 | if (IS_VF(cdev)) { |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 2389 | qed_vf_pf_release(p_hwfn); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 2390 | continue; |
| 2391 | } |
| 2392 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2393 | qed_init_free(p_hwfn); |
| 2394 | qed_hw_hwfn_free(p_hwfn); |
| 2395 | qed_mcp_free(p_hwfn); |
| 2396 | } |
Yuval Mintz | 32a47e7 | 2016-05-11 16:36:12 +0300 | [diff] [blame] | 2397 | |
| 2398 | qed_iov_free_hw_info(cdev); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2399 | } |
| 2400 | |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2401 | static void qed_chain_free_next_ptr(struct qed_dev *cdev, |
| 2402 | struct qed_chain *p_chain) |
| 2403 | { |
| 2404 | void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL; |
| 2405 | dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0; |
| 2406 | struct qed_chain_next *p_next; |
| 2407 | u32 size, i; |
| 2408 | |
| 2409 | if (!p_virt) |
| 2410 | return; |
| 2411 | |
| 2412 | size = p_chain->elem_size * p_chain->usable_per_page; |
| 2413 | |
| 2414 | for (i = 0; i < p_chain->page_cnt; i++) { |
| 2415 | if (!p_virt) |
| 2416 | break; |
| 2417 | |
| 2418 | p_next = (struct qed_chain_next *)((u8 *)p_virt + size); |
| 2419 | p_virt_next = p_next->next_virt; |
| 2420 | p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys); |
| 2421 | |
| 2422 | dma_free_coherent(&cdev->pdev->dev, |
| 2423 | QED_CHAIN_PAGE_SIZE, p_virt, p_phys); |
| 2424 | |
| 2425 | p_virt = p_virt_next; |
| 2426 | p_phys = p_phys_next; |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | static void qed_chain_free_single(struct qed_dev *cdev, |
| 2431 | struct qed_chain *p_chain) |
| 2432 | { |
| 2433 | if (!p_chain->p_virt_addr) |
| 2434 | return; |
| 2435 | |
| 2436 | dma_free_coherent(&cdev->pdev->dev, |
| 2437 | QED_CHAIN_PAGE_SIZE, |
| 2438 | p_chain->p_virt_addr, p_chain->p_phys_addr); |
| 2439 | } |
| 2440 | |
| 2441 | static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain) |
| 2442 | { |
| 2443 | void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl; |
| 2444 | u32 page_cnt = p_chain->page_cnt, i, pbl_size; |
Mintz, Yuval | 6d937ac | 2016-11-29 16:47:01 +0200 | [diff] [blame] | 2445 | u8 *p_pbl_virt = p_chain->pbl_sp.p_virt_table; |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2446 | |
| 2447 | if (!pp_virt_addr_tbl) |
| 2448 | return; |
| 2449 | |
Mintz, Yuval | 6d937ac | 2016-11-29 16:47:01 +0200 | [diff] [blame] | 2450 | if (!p_pbl_virt) |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2451 | goto out; |
| 2452 | |
| 2453 | for (i = 0; i < page_cnt; i++) { |
| 2454 | if (!pp_virt_addr_tbl[i]) |
| 2455 | break; |
| 2456 | |
| 2457 | dma_free_coherent(&cdev->pdev->dev, |
| 2458 | QED_CHAIN_PAGE_SIZE, |
| 2459 | pp_virt_addr_tbl[i], |
| 2460 | *(dma_addr_t *)p_pbl_virt); |
| 2461 | |
| 2462 | p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE; |
| 2463 | } |
| 2464 | |
| 2465 | pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE; |
| 2466 | dma_free_coherent(&cdev->pdev->dev, |
| 2467 | pbl_size, |
Mintz, Yuval | 6d937ac | 2016-11-29 16:47:01 +0200 | [diff] [blame] | 2468 | p_chain->pbl_sp.p_virt_table, |
| 2469 | p_chain->pbl_sp.p_phys_table); |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2470 | out: |
| 2471 | vfree(p_chain->pbl.pp_virt_addr_tbl); |
| 2472 | } |
| 2473 | |
| 2474 | void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain) |
| 2475 | { |
| 2476 | switch (p_chain->mode) { |
| 2477 | case QED_CHAIN_MODE_NEXT_PTR: |
| 2478 | qed_chain_free_next_ptr(cdev, p_chain); |
| 2479 | break; |
| 2480 | case QED_CHAIN_MODE_SINGLE: |
| 2481 | qed_chain_free_single(cdev, p_chain); |
| 2482 | break; |
| 2483 | case QED_CHAIN_MODE_PBL: |
| 2484 | qed_chain_free_pbl(cdev, p_chain); |
| 2485 | break; |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | static int |
| 2490 | qed_chain_alloc_sanity_check(struct qed_dev *cdev, |
| 2491 | enum qed_chain_cnt_type cnt_type, |
| 2492 | size_t elem_size, u32 page_cnt) |
| 2493 | { |
| 2494 | u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt; |
| 2495 | |
| 2496 | /* The actual chain size can be larger than the maximal possible value |
| 2497 | * after rounding up the requested elements number to pages, and after |
| 2498 | * taking into acount the unusuable elements (next-ptr elements). |
| 2499 | * The size of a "u16" chain can be (U16_MAX + 1) since the chain |
| 2500 | * size/capacity fields are of a u32 type. |
| 2501 | */ |
| 2502 | if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 && |
Tomer Tayar | 3ef310a | 2017-03-14 15:25:59 +0200 | [diff] [blame] | 2503 | chain_size > ((u32)U16_MAX + 1)) || |
| 2504 | (cnt_type == QED_CHAIN_CNT_TYPE_U32 && chain_size > U32_MAX)) { |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2505 | DP_NOTICE(cdev, |
| 2506 | "The actual chain size (0x%llx) is larger than the maximal possible value\n", |
| 2507 | chain_size); |
| 2508 | return -EINVAL; |
| 2509 | } |
| 2510 | |
| 2511 | return 0; |
| 2512 | } |
| 2513 | |
| 2514 | static int |
| 2515 | qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain) |
| 2516 | { |
| 2517 | void *p_virt = NULL, *p_virt_prev = NULL; |
| 2518 | dma_addr_t p_phys = 0; |
| 2519 | u32 i; |
| 2520 | |
| 2521 | for (i = 0; i < p_chain->page_cnt; i++) { |
| 2522 | p_virt = dma_alloc_coherent(&cdev->pdev->dev, |
| 2523 | QED_CHAIN_PAGE_SIZE, |
| 2524 | &p_phys, GFP_KERNEL); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 2525 | if (!p_virt) |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2526 | return -ENOMEM; |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2527 | |
| 2528 | if (i == 0) { |
| 2529 | qed_chain_init_mem(p_chain, p_virt, p_phys); |
| 2530 | qed_chain_reset(p_chain); |
| 2531 | } else { |
| 2532 | qed_chain_init_next_ptr_elem(p_chain, p_virt_prev, |
| 2533 | p_virt, p_phys); |
| 2534 | } |
| 2535 | |
| 2536 | p_virt_prev = p_virt; |
| 2537 | } |
| 2538 | /* Last page's next element should point to the beginning of the |
| 2539 | * chain. |
| 2540 | */ |
| 2541 | qed_chain_init_next_ptr_elem(p_chain, p_virt_prev, |
| 2542 | p_chain->p_virt_addr, |
| 2543 | p_chain->p_phys_addr); |
| 2544 | |
| 2545 | return 0; |
| 2546 | } |
| 2547 | |
| 2548 | static int |
| 2549 | qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain) |
| 2550 | { |
| 2551 | dma_addr_t p_phys = 0; |
| 2552 | void *p_virt = NULL; |
| 2553 | |
| 2554 | p_virt = dma_alloc_coherent(&cdev->pdev->dev, |
| 2555 | QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 2556 | if (!p_virt) |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2557 | return -ENOMEM; |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2558 | |
| 2559 | qed_chain_init_mem(p_chain, p_virt, p_phys); |
| 2560 | qed_chain_reset(p_chain); |
| 2561 | |
| 2562 | return 0; |
| 2563 | } |
| 2564 | |
| 2565 | static int qed_chain_alloc_pbl(struct qed_dev *cdev, struct qed_chain *p_chain) |
| 2566 | { |
| 2567 | u32 page_cnt = p_chain->page_cnt, size, i; |
| 2568 | dma_addr_t p_phys = 0, p_pbl_phys = 0; |
| 2569 | void **pp_virt_addr_tbl = NULL; |
| 2570 | u8 *p_pbl_virt = NULL; |
| 2571 | void *p_virt = NULL; |
| 2572 | |
| 2573 | size = page_cnt * sizeof(*pp_virt_addr_tbl); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 2574 | pp_virt_addr_tbl = vzalloc(size); |
| 2575 | if (!pp_virt_addr_tbl) |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2576 | return -ENOMEM; |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2577 | |
| 2578 | /* The allocation of the PBL table is done with its full size, since it |
| 2579 | * is expected to be successive. |
| 2580 | * qed_chain_init_pbl_mem() is called even in a case of an allocation |
| 2581 | * failure, since pp_virt_addr_tbl was previously allocated, and it |
| 2582 | * should be saved to allow its freeing during the error flow. |
| 2583 | */ |
| 2584 | size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE; |
| 2585 | p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev, |
| 2586 | size, &p_pbl_phys, GFP_KERNEL); |
| 2587 | qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys, |
| 2588 | pp_virt_addr_tbl); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 2589 | if (!p_pbl_virt) |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2590 | return -ENOMEM; |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2591 | |
| 2592 | for (i = 0; i < page_cnt; i++) { |
| 2593 | p_virt = dma_alloc_coherent(&cdev->pdev->dev, |
| 2594 | QED_CHAIN_PAGE_SIZE, |
| 2595 | &p_phys, GFP_KERNEL); |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 2596 | if (!p_virt) |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2597 | return -ENOMEM; |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2598 | |
| 2599 | if (i == 0) { |
| 2600 | qed_chain_init_mem(p_chain, p_virt, p_phys); |
| 2601 | qed_chain_reset(p_chain); |
| 2602 | } |
| 2603 | |
| 2604 | /* Fill the PBL table with the physical address of the page */ |
| 2605 | *(dma_addr_t *)p_pbl_virt = p_phys; |
| 2606 | /* Keep the virtual address of the page */ |
| 2607 | p_chain->pbl.pp_virt_addr_tbl[i] = p_virt; |
| 2608 | |
| 2609 | p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE; |
| 2610 | } |
| 2611 | |
| 2612 | return 0; |
| 2613 | } |
| 2614 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2615 | int qed_chain_alloc(struct qed_dev *cdev, |
| 2616 | enum qed_chain_use_mode intended_use, |
| 2617 | enum qed_chain_mode mode, |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2618 | enum qed_chain_cnt_type cnt_type, |
| 2619 | u32 num_elems, size_t elem_size, struct qed_chain *p_chain) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2620 | { |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2621 | u32 page_cnt; |
| 2622 | int rc = 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2623 | |
| 2624 | if (mode == QED_CHAIN_MODE_SINGLE) |
| 2625 | page_cnt = 1; |
| 2626 | else |
| 2627 | page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode); |
| 2628 | |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2629 | rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt); |
| 2630 | if (rc) { |
| 2631 | DP_NOTICE(cdev, |
Joe Perches | 2591c28 | 2016-09-04 14:24:03 -0700 | [diff] [blame] | 2632 | "Cannot allocate a chain with the given arguments:\n"); |
| 2633 | DP_NOTICE(cdev, |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2634 | "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n", |
| 2635 | intended_use, mode, cnt_type, num_elems, elem_size); |
| 2636 | return rc; |
| 2637 | } |
| 2638 | |
| 2639 | qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use, |
| 2640 | mode, cnt_type); |
| 2641 | |
| 2642 | switch (mode) { |
| 2643 | case QED_CHAIN_MODE_NEXT_PTR: |
| 2644 | rc = qed_chain_alloc_next_ptr(cdev, p_chain); |
| 2645 | break; |
| 2646 | case QED_CHAIN_MODE_SINGLE: |
| 2647 | rc = qed_chain_alloc_single(cdev, p_chain); |
| 2648 | break; |
| 2649 | case QED_CHAIN_MODE_PBL: |
| 2650 | rc = qed_chain_alloc_pbl(cdev, p_chain); |
| 2651 | break; |
| 2652 | } |
| 2653 | if (rc) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2654 | goto nomem; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2655 | |
| 2656 | return 0; |
| 2657 | |
| 2658 | nomem: |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2659 | qed_chain_free(cdev, p_chain); |
| 2660 | return rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 2661 | } |
| 2662 | |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2663 | int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id) |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 2664 | { |
| 2665 | if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) { |
| 2666 | u16 min, max; |
| 2667 | |
Yuval Mintz | a91eb52 | 2016-06-03 14:35:32 +0300 | [diff] [blame] | 2668 | min = (u16) RESC_START(p_hwfn, QED_L2_QUEUE); |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 2669 | max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE); |
| 2670 | DP_NOTICE(p_hwfn, |
| 2671 | "l2_queue id [%d] is not valid, available indices [%d - %d]\n", |
| 2672 | src_id, min, max); |
| 2673 | |
| 2674 | return -EINVAL; |
| 2675 | } |
| 2676 | |
| 2677 | *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id; |
| 2678 | |
| 2679 | return 0; |
| 2680 | } |
| 2681 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 2682 | int qed_fw_vport(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id) |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 2683 | { |
| 2684 | if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) { |
| 2685 | u8 min, max; |
| 2686 | |
| 2687 | min = (u8)RESC_START(p_hwfn, QED_VPORT); |
| 2688 | max = min + RESC_NUM(p_hwfn, QED_VPORT); |
| 2689 | DP_NOTICE(p_hwfn, |
| 2690 | "vport id [%d] is not valid, available indices [%d - %d]\n", |
| 2691 | src_id, min, max); |
| 2692 | |
| 2693 | return -EINVAL; |
| 2694 | } |
| 2695 | |
| 2696 | *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id; |
| 2697 | |
| 2698 | return 0; |
| 2699 | } |
| 2700 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 2701 | int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id) |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 2702 | { |
| 2703 | if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) { |
| 2704 | u8 min, max; |
| 2705 | |
| 2706 | min = (u8)RESC_START(p_hwfn, QED_RSS_ENG); |
| 2707 | max = min + RESC_NUM(p_hwfn, QED_RSS_ENG); |
| 2708 | DP_NOTICE(p_hwfn, |
| 2709 | "rss_eng id [%d] is not valid, available indices [%d - %d]\n", |
| 2710 | src_id, min, max); |
| 2711 | |
| 2712 | return -EINVAL; |
| 2713 | } |
| 2714 | |
| 2715 | *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id; |
| 2716 | |
| 2717 | return 0; |
| 2718 | } |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 2719 | |
Yuval Mintz | 0a7fb11 | 2016-10-01 21:59:55 +0300 | [diff] [blame] | 2720 | static void qed_llh_mac_to_filter(u32 *p_high, u32 *p_low, |
| 2721 | u8 *p_filter) |
| 2722 | { |
| 2723 | *p_high = p_filter[1] | (p_filter[0] << 8); |
| 2724 | *p_low = p_filter[5] | (p_filter[4] << 8) | |
| 2725 | (p_filter[3] << 16) | (p_filter[2] << 24); |
| 2726 | } |
| 2727 | |
| 2728 | int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn, |
| 2729 | struct qed_ptt *p_ptt, u8 *p_filter) |
| 2730 | { |
| 2731 | u32 high = 0, low = 0, en; |
| 2732 | int i; |
| 2733 | |
| 2734 | if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn))) |
| 2735 | return 0; |
| 2736 | |
| 2737 | qed_llh_mac_to_filter(&high, &low, p_filter); |
| 2738 | |
| 2739 | /* Find a free entry and utilize it */ |
| 2740 | for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) { |
| 2741 | en = qed_rd(p_hwfn, p_ptt, |
| 2742 | NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32)); |
| 2743 | if (en) |
| 2744 | continue; |
| 2745 | qed_wr(p_hwfn, p_ptt, |
| 2746 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2747 | 2 * i * sizeof(u32), low); |
| 2748 | qed_wr(p_hwfn, p_ptt, |
| 2749 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2750 | (2 * i + 1) * sizeof(u32), high); |
| 2751 | qed_wr(p_hwfn, p_ptt, |
| 2752 | NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0); |
| 2753 | qed_wr(p_hwfn, p_ptt, |
| 2754 | NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE + |
| 2755 | i * sizeof(u32), 0); |
| 2756 | qed_wr(p_hwfn, p_ptt, |
| 2757 | NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1); |
| 2758 | break; |
| 2759 | } |
| 2760 | if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) { |
| 2761 | DP_NOTICE(p_hwfn, |
| 2762 | "Failed to find an empty LLH filter to utilize\n"); |
| 2763 | return -EINVAL; |
| 2764 | } |
| 2765 | |
| 2766 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2767 | "mac: %pM is added at %d\n", |
| 2768 | p_filter, i); |
| 2769 | |
| 2770 | return 0; |
| 2771 | } |
| 2772 | |
| 2773 | void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn, |
| 2774 | struct qed_ptt *p_ptt, u8 *p_filter) |
| 2775 | { |
| 2776 | u32 high = 0, low = 0; |
| 2777 | int i; |
| 2778 | |
| 2779 | if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn))) |
| 2780 | return; |
| 2781 | |
| 2782 | qed_llh_mac_to_filter(&high, &low, p_filter); |
| 2783 | |
| 2784 | /* Find the entry and clean it */ |
| 2785 | for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) { |
| 2786 | if (qed_rd(p_hwfn, p_ptt, |
| 2787 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2788 | 2 * i * sizeof(u32)) != low) |
| 2789 | continue; |
| 2790 | if (qed_rd(p_hwfn, p_ptt, |
| 2791 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2792 | (2 * i + 1) * sizeof(u32)) != high) |
| 2793 | continue; |
| 2794 | |
| 2795 | qed_wr(p_hwfn, p_ptt, |
| 2796 | NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0); |
| 2797 | qed_wr(p_hwfn, p_ptt, |
| 2798 | NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0); |
| 2799 | qed_wr(p_hwfn, p_ptt, |
| 2800 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2801 | (2 * i + 1) * sizeof(u32), 0); |
| 2802 | |
| 2803 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2804 | "mac: %pM is removed from %d\n", |
| 2805 | p_filter, i); |
| 2806 | break; |
| 2807 | } |
| 2808 | if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) |
| 2809 | DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n"); |
| 2810 | } |
| 2811 | |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 2812 | int |
| 2813 | qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn, |
| 2814 | struct qed_ptt *p_ptt, |
| 2815 | u16 source_port_or_eth_type, |
| 2816 | u16 dest_port, enum qed_llh_port_filter_type_t type) |
| 2817 | { |
| 2818 | u32 high = 0, low = 0, en; |
| 2819 | int i; |
| 2820 | |
| 2821 | if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn))) |
| 2822 | return 0; |
| 2823 | |
| 2824 | switch (type) { |
| 2825 | case QED_LLH_FILTER_ETHERTYPE: |
| 2826 | high = source_port_or_eth_type; |
| 2827 | break; |
| 2828 | case QED_LLH_FILTER_TCP_SRC_PORT: |
| 2829 | case QED_LLH_FILTER_UDP_SRC_PORT: |
| 2830 | low = source_port_or_eth_type << 16; |
| 2831 | break; |
| 2832 | case QED_LLH_FILTER_TCP_DEST_PORT: |
| 2833 | case QED_LLH_FILTER_UDP_DEST_PORT: |
| 2834 | low = dest_port; |
| 2835 | break; |
| 2836 | case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT: |
| 2837 | case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT: |
| 2838 | low = (source_port_or_eth_type << 16) | dest_port; |
| 2839 | break; |
| 2840 | default: |
| 2841 | DP_NOTICE(p_hwfn, |
| 2842 | "Non valid LLH protocol filter type %d\n", type); |
| 2843 | return -EINVAL; |
| 2844 | } |
| 2845 | /* Find a free entry and utilize it */ |
| 2846 | for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) { |
| 2847 | en = qed_rd(p_hwfn, p_ptt, |
| 2848 | NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32)); |
| 2849 | if (en) |
| 2850 | continue; |
| 2851 | qed_wr(p_hwfn, p_ptt, |
| 2852 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2853 | 2 * i * sizeof(u32), low); |
| 2854 | qed_wr(p_hwfn, p_ptt, |
| 2855 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2856 | (2 * i + 1) * sizeof(u32), high); |
| 2857 | qed_wr(p_hwfn, p_ptt, |
| 2858 | NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 1); |
| 2859 | qed_wr(p_hwfn, p_ptt, |
| 2860 | NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE + |
| 2861 | i * sizeof(u32), 1 << type); |
| 2862 | qed_wr(p_hwfn, p_ptt, |
| 2863 | NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1); |
| 2864 | break; |
| 2865 | } |
| 2866 | if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) { |
| 2867 | DP_NOTICE(p_hwfn, |
| 2868 | "Failed to find an empty LLH filter to utilize\n"); |
| 2869 | return -EINVAL; |
| 2870 | } |
| 2871 | switch (type) { |
| 2872 | case QED_LLH_FILTER_ETHERTYPE: |
| 2873 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2874 | "ETH type %x is added at %d\n", |
| 2875 | source_port_or_eth_type, i); |
| 2876 | break; |
| 2877 | case QED_LLH_FILTER_TCP_SRC_PORT: |
| 2878 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2879 | "TCP src port %x is added at %d\n", |
| 2880 | source_port_or_eth_type, i); |
| 2881 | break; |
| 2882 | case QED_LLH_FILTER_UDP_SRC_PORT: |
| 2883 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2884 | "UDP src port %x is added at %d\n", |
| 2885 | source_port_or_eth_type, i); |
| 2886 | break; |
| 2887 | case QED_LLH_FILTER_TCP_DEST_PORT: |
| 2888 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2889 | "TCP dst port %x is added at %d\n", dest_port, i); |
| 2890 | break; |
| 2891 | case QED_LLH_FILTER_UDP_DEST_PORT: |
| 2892 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2893 | "UDP dst port %x is added at %d\n", dest_port, i); |
| 2894 | break; |
| 2895 | case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT: |
| 2896 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2897 | "TCP src/dst ports %x/%x are added at %d\n", |
| 2898 | source_port_or_eth_type, dest_port, i); |
| 2899 | break; |
| 2900 | case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT: |
| 2901 | DP_VERBOSE(p_hwfn, NETIF_MSG_HW, |
| 2902 | "UDP src/dst ports %x/%x are added at %d\n", |
| 2903 | source_port_or_eth_type, dest_port, i); |
| 2904 | break; |
| 2905 | } |
| 2906 | return 0; |
| 2907 | } |
| 2908 | |
| 2909 | void |
| 2910 | qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn, |
| 2911 | struct qed_ptt *p_ptt, |
| 2912 | u16 source_port_or_eth_type, |
| 2913 | u16 dest_port, |
| 2914 | enum qed_llh_port_filter_type_t type) |
| 2915 | { |
| 2916 | u32 high = 0, low = 0; |
| 2917 | int i; |
| 2918 | |
| 2919 | if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn))) |
| 2920 | return; |
| 2921 | |
| 2922 | switch (type) { |
| 2923 | case QED_LLH_FILTER_ETHERTYPE: |
| 2924 | high = source_port_or_eth_type; |
| 2925 | break; |
| 2926 | case QED_LLH_FILTER_TCP_SRC_PORT: |
| 2927 | case QED_LLH_FILTER_UDP_SRC_PORT: |
| 2928 | low = source_port_or_eth_type << 16; |
| 2929 | break; |
| 2930 | case QED_LLH_FILTER_TCP_DEST_PORT: |
| 2931 | case QED_LLH_FILTER_UDP_DEST_PORT: |
| 2932 | low = dest_port; |
| 2933 | break; |
| 2934 | case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT: |
| 2935 | case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT: |
| 2936 | low = (source_port_or_eth_type << 16) | dest_port; |
| 2937 | break; |
| 2938 | default: |
| 2939 | DP_NOTICE(p_hwfn, |
| 2940 | "Non valid LLH protocol filter type %d\n", type); |
| 2941 | return; |
| 2942 | } |
| 2943 | |
| 2944 | for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) { |
| 2945 | if (!qed_rd(p_hwfn, p_ptt, |
| 2946 | NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32))) |
| 2947 | continue; |
| 2948 | if (!qed_rd(p_hwfn, p_ptt, |
| 2949 | NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32))) |
| 2950 | continue; |
| 2951 | if (!(qed_rd(p_hwfn, p_ptt, |
| 2952 | NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE + |
| 2953 | i * sizeof(u32)) & BIT(type))) |
| 2954 | continue; |
| 2955 | if (qed_rd(p_hwfn, p_ptt, |
| 2956 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2957 | 2 * i * sizeof(u32)) != low) |
| 2958 | continue; |
| 2959 | if (qed_rd(p_hwfn, p_ptt, |
| 2960 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2961 | (2 * i + 1) * sizeof(u32)) != high) |
| 2962 | continue; |
| 2963 | |
| 2964 | qed_wr(p_hwfn, p_ptt, |
| 2965 | NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0); |
| 2966 | qed_wr(p_hwfn, p_ptt, |
| 2967 | NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0); |
| 2968 | qed_wr(p_hwfn, p_ptt, |
| 2969 | NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE + |
| 2970 | i * sizeof(u32), 0); |
| 2971 | qed_wr(p_hwfn, p_ptt, |
| 2972 | NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0); |
| 2973 | qed_wr(p_hwfn, p_ptt, |
| 2974 | NIG_REG_LLH_FUNC_FILTER_VALUE + |
| 2975 | (2 * i + 1) * sizeof(u32), 0); |
| 2976 | break; |
| 2977 | } |
| 2978 | |
| 2979 | if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) |
| 2980 | DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n"); |
| 2981 | } |
| 2982 | |
Sudarsana Reddy Kalluru | 722003a | 2016-06-21 09:36:21 -0400 | [diff] [blame] | 2983 | static int qed_set_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, |
| 2984 | u32 hw_addr, void *p_eth_qzone, |
| 2985 | size_t eth_qzone_size, u8 timeset) |
| 2986 | { |
| 2987 | struct coalescing_timeset *p_coal_timeset; |
| 2988 | |
| 2989 | if (p_hwfn->cdev->int_coalescing_mode != QED_COAL_MODE_ENABLE) { |
| 2990 | DP_NOTICE(p_hwfn, "Coalescing configuration not enabled\n"); |
| 2991 | return -EINVAL; |
| 2992 | } |
| 2993 | |
| 2994 | p_coal_timeset = p_eth_qzone; |
| 2995 | memset(p_coal_timeset, 0, eth_qzone_size); |
| 2996 | SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset); |
| 2997 | SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1); |
| 2998 | qed_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size); |
| 2999 | |
| 3000 | return 0; |
| 3001 | } |
| 3002 | |
| 3003 | int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, |
| 3004 | u16 coalesce, u8 qid, u16 sb_id) |
| 3005 | { |
| 3006 | struct ustorm_eth_queue_zone eth_qzone; |
| 3007 | u8 timeset, timer_res; |
| 3008 | u16 fw_qid = 0; |
| 3009 | u32 address; |
| 3010 | int rc; |
| 3011 | |
| 3012 | /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */ |
| 3013 | if (coalesce <= 0x7F) { |
| 3014 | timer_res = 0; |
| 3015 | } else if (coalesce <= 0xFF) { |
| 3016 | timer_res = 1; |
| 3017 | } else if (coalesce <= 0x1FF) { |
| 3018 | timer_res = 2; |
| 3019 | } else { |
| 3020 | DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce); |
| 3021 | return -EINVAL; |
| 3022 | } |
| 3023 | timeset = (u8)(coalesce >> timer_res); |
| 3024 | |
| 3025 | rc = qed_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid); |
| 3026 | if (rc) |
| 3027 | return rc; |
| 3028 | |
| 3029 | rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, false); |
| 3030 | if (rc) |
| 3031 | goto out; |
| 3032 | |
| 3033 | address = BAR0_MAP_REG_USDM_RAM + USTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid); |
| 3034 | |
| 3035 | rc = qed_set_coalesce(p_hwfn, p_ptt, address, ð_qzone, |
| 3036 | sizeof(struct ustorm_eth_queue_zone), timeset); |
| 3037 | if (rc) |
| 3038 | goto out; |
| 3039 | |
| 3040 | p_hwfn->cdev->rx_coalesce_usecs = coalesce; |
| 3041 | out: |
| 3042 | return rc; |
| 3043 | } |
| 3044 | |
| 3045 | int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, |
| 3046 | u16 coalesce, u8 qid, u16 sb_id) |
| 3047 | { |
| 3048 | struct xstorm_eth_queue_zone eth_qzone; |
| 3049 | u8 timeset, timer_res; |
| 3050 | u16 fw_qid = 0; |
| 3051 | u32 address; |
| 3052 | int rc; |
| 3053 | |
| 3054 | /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */ |
| 3055 | if (coalesce <= 0x7F) { |
| 3056 | timer_res = 0; |
| 3057 | } else if (coalesce <= 0xFF) { |
| 3058 | timer_res = 1; |
| 3059 | } else if (coalesce <= 0x1FF) { |
| 3060 | timer_res = 2; |
| 3061 | } else { |
| 3062 | DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce); |
| 3063 | return -EINVAL; |
| 3064 | } |
| 3065 | timeset = (u8)(coalesce >> timer_res); |
| 3066 | |
| 3067 | rc = qed_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid); |
| 3068 | if (rc) |
| 3069 | return rc; |
| 3070 | |
| 3071 | rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, true); |
| 3072 | if (rc) |
| 3073 | goto out; |
| 3074 | |
| 3075 | address = BAR0_MAP_REG_XSDM_RAM + XSTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid); |
| 3076 | |
| 3077 | rc = qed_set_coalesce(p_hwfn, p_ptt, address, ð_qzone, |
| 3078 | sizeof(struct xstorm_eth_queue_zone), timeset); |
| 3079 | if (rc) |
| 3080 | goto out; |
| 3081 | |
| 3082 | p_hwfn->cdev->tx_coalesce_usecs = coalesce; |
| 3083 | out: |
| 3084 | return rc; |
| 3085 | } |
| 3086 | |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 3087 | /* Calculate final WFQ values for all vports and configure them. |
| 3088 | * After this configuration each vport will have |
| 3089 | * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT) |
| 3090 | */ |
| 3091 | static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn, |
| 3092 | struct qed_ptt *p_ptt, |
| 3093 | u32 min_pf_rate) |
| 3094 | { |
| 3095 | struct init_qm_vport_params *vport_params; |
| 3096 | int i; |
| 3097 | |
| 3098 | vport_params = p_hwfn->qm_info.qm_vport_params; |
| 3099 | |
| 3100 | for (i = 0; i < p_hwfn->qm_info.num_vports; i++) { |
| 3101 | u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed; |
| 3102 | |
| 3103 | vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) / |
| 3104 | min_pf_rate; |
| 3105 | qed_init_vport_wfq(p_hwfn, p_ptt, |
| 3106 | vport_params[i].first_tx_pq_id, |
| 3107 | vport_params[i].vport_wfq); |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn, |
| 3112 | u32 min_pf_rate) |
| 3113 | |
| 3114 | { |
| 3115 | int i; |
| 3116 | |
| 3117 | for (i = 0; i < p_hwfn->qm_info.num_vports; i++) |
| 3118 | p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1; |
| 3119 | } |
| 3120 | |
| 3121 | static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn, |
| 3122 | struct qed_ptt *p_ptt, |
| 3123 | u32 min_pf_rate) |
| 3124 | { |
| 3125 | struct init_qm_vport_params *vport_params; |
| 3126 | int i; |
| 3127 | |
| 3128 | vport_params = p_hwfn->qm_info.qm_vport_params; |
| 3129 | |
| 3130 | for (i = 0; i < p_hwfn->qm_info.num_vports; i++) { |
| 3131 | qed_init_wfq_default_param(p_hwfn, min_pf_rate); |
| 3132 | qed_init_vport_wfq(p_hwfn, p_ptt, |
| 3133 | vport_params[i].first_tx_pq_id, |
| 3134 | vport_params[i].vport_wfq); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | /* This function performs several validations for WFQ |
| 3139 | * configuration and required min rate for a given vport |
| 3140 | * 1. req_rate must be greater than one percent of min_pf_rate. |
| 3141 | * 2. req_rate should not cause other vports [not configured for WFQ explicitly] |
| 3142 | * rates to get less than one percent of min_pf_rate. |
| 3143 | * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate. |
| 3144 | */ |
| 3145 | static int qed_init_wfq_param(struct qed_hwfn *p_hwfn, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 3146 | u16 vport_id, u32 req_rate, u32 min_pf_rate) |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 3147 | { |
| 3148 | u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0; |
| 3149 | int non_requested_count = 0, req_count = 0, i, num_vports; |
| 3150 | |
| 3151 | num_vports = p_hwfn->qm_info.num_vports; |
| 3152 | |
| 3153 | /* Accounting for the vports which are configured for WFQ explicitly */ |
| 3154 | for (i = 0; i < num_vports; i++) { |
| 3155 | u32 tmp_speed; |
| 3156 | |
| 3157 | if ((i != vport_id) && |
| 3158 | p_hwfn->qm_info.wfq_data[i].configured) { |
| 3159 | req_count++; |
| 3160 | tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed; |
| 3161 | total_req_min_rate += tmp_speed; |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | /* Include current vport data as well */ |
| 3166 | req_count++; |
| 3167 | total_req_min_rate += req_rate; |
| 3168 | non_requested_count = num_vports - req_count; |
| 3169 | |
| 3170 | if (req_rate < min_pf_rate / QED_WFQ_UNIT) { |
| 3171 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 3172 | "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n", |
| 3173 | vport_id, req_rate, min_pf_rate); |
| 3174 | return -EINVAL; |
| 3175 | } |
| 3176 | |
| 3177 | if (num_vports > QED_WFQ_UNIT) { |
| 3178 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 3179 | "Number of vports is greater than %d\n", |
| 3180 | QED_WFQ_UNIT); |
| 3181 | return -EINVAL; |
| 3182 | } |
| 3183 | |
| 3184 | if (total_req_min_rate > min_pf_rate) { |
| 3185 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 3186 | "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n", |
| 3187 | total_req_min_rate, min_pf_rate); |
| 3188 | return -EINVAL; |
| 3189 | } |
| 3190 | |
| 3191 | total_left_rate = min_pf_rate - total_req_min_rate; |
| 3192 | |
| 3193 | left_rate_per_vp = total_left_rate / non_requested_count; |
| 3194 | if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) { |
| 3195 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 3196 | "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n", |
| 3197 | left_rate_per_vp, min_pf_rate); |
| 3198 | return -EINVAL; |
| 3199 | } |
| 3200 | |
| 3201 | p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate; |
| 3202 | p_hwfn->qm_info.wfq_data[vport_id].configured = true; |
| 3203 | |
| 3204 | for (i = 0; i < num_vports; i++) { |
| 3205 | if (p_hwfn->qm_info.wfq_data[i].configured) |
| 3206 | continue; |
| 3207 | |
| 3208 | p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp; |
| 3209 | } |
| 3210 | |
| 3211 | return 0; |
| 3212 | } |
| 3213 | |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 3214 | static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn, |
| 3215 | struct qed_ptt *p_ptt, u16 vp_id, u32 rate) |
| 3216 | { |
| 3217 | struct qed_mcp_link_state *p_link; |
| 3218 | int rc = 0; |
| 3219 | |
| 3220 | p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output; |
| 3221 | |
| 3222 | if (!p_link->min_pf_rate) { |
| 3223 | p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate; |
| 3224 | p_hwfn->qm_info.wfq_data[vp_id].configured = true; |
| 3225 | return rc; |
| 3226 | } |
| 3227 | |
| 3228 | rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate); |
| 3229 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 3230 | if (!rc) |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 3231 | qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, |
| 3232 | p_link->min_pf_rate); |
| 3233 | else |
| 3234 | DP_NOTICE(p_hwfn, |
| 3235 | "Validation failed while configuring min rate\n"); |
| 3236 | |
| 3237 | return rc; |
| 3238 | } |
| 3239 | |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 3240 | static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn, |
| 3241 | struct qed_ptt *p_ptt, |
| 3242 | u32 min_pf_rate) |
| 3243 | { |
| 3244 | bool use_wfq = false; |
| 3245 | int rc = 0; |
| 3246 | u16 i; |
| 3247 | |
| 3248 | /* Validate all pre configured vports for wfq */ |
| 3249 | for (i = 0; i < p_hwfn->qm_info.num_vports; i++) { |
| 3250 | u32 rate; |
| 3251 | |
| 3252 | if (!p_hwfn->qm_info.wfq_data[i].configured) |
| 3253 | continue; |
| 3254 | |
| 3255 | rate = p_hwfn->qm_info.wfq_data[i].min_speed; |
| 3256 | use_wfq = true; |
| 3257 | |
| 3258 | rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate); |
| 3259 | if (rc) { |
| 3260 | DP_NOTICE(p_hwfn, |
| 3261 | "WFQ validation failed while configuring min rate\n"); |
| 3262 | break; |
| 3263 | } |
| 3264 | } |
| 3265 | |
| 3266 | if (!rc && use_wfq) |
| 3267 | qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate); |
| 3268 | else |
| 3269 | qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate); |
| 3270 | |
| 3271 | return rc; |
| 3272 | } |
| 3273 | |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 3274 | /* Main API for qed clients to configure vport min rate. |
| 3275 | * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)] |
| 3276 | * rate - Speed in Mbps needs to be assigned to a given vport. |
| 3277 | */ |
| 3278 | int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate) |
| 3279 | { |
| 3280 | int i, rc = -EINVAL; |
| 3281 | |
| 3282 | /* Currently not supported; Might change in future */ |
| 3283 | if (cdev->num_hwfns > 1) { |
| 3284 | DP_NOTICE(cdev, |
| 3285 | "WFQ configuration is not supported for this device\n"); |
| 3286 | return rc; |
| 3287 | } |
| 3288 | |
| 3289 | for_each_hwfn(cdev, i) { |
| 3290 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 3291 | struct qed_ptt *p_ptt; |
| 3292 | |
| 3293 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 3294 | if (!p_ptt) |
| 3295 | return -EBUSY; |
| 3296 | |
| 3297 | rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate); |
| 3298 | |
Yuval Mintz | d572c43 | 2016-07-27 14:45:23 +0300 | [diff] [blame] | 3299 | if (rc) { |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 3300 | qed_ptt_release(p_hwfn, p_ptt); |
| 3301 | return rc; |
| 3302 | } |
| 3303 | |
| 3304 | qed_ptt_release(p_hwfn, p_ptt); |
| 3305 | } |
| 3306 | |
| 3307 | return rc; |
| 3308 | } |
| 3309 | |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 3310 | /* API to configure WFQ from mcp link change */ |
Mintz, Yuval | 6f437d4 | 2017-02-27 11:06:33 +0200 | [diff] [blame] | 3311 | void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev, |
| 3312 | struct qed_ptt *p_ptt, u32 min_pf_rate) |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 3313 | { |
| 3314 | int i; |
| 3315 | |
Yuval Mintz | 3e7cfce | 2016-05-26 11:01:24 +0300 | [diff] [blame] | 3316 | if (cdev->num_hwfns > 1) { |
| 3317 | DP_VERBOSE(cdev, |
| 3318 | NETIF_MSG_LINK, |
| 3319 | "WFQ configuration is not supported for this device\n"); |
| 3320 | return; |
| 3321 | } |
| 3322 | |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 3323 | for_each_hwfn(cdev, i) { |
| 3324 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 3325 | |
Mintz, Yuval | 6f437d4 | 2017-02-27 11:06:33 +0200 | [diff] [blame] | 3326 | __qed_configure_vp_wfq_on_link_change(p_hwfn, p_ptt, |
Manish Chopra | bcd197c | 2016-04-26 10:56:08 -0400 | [diff] [blame] | 3327 | min_pf_rate); |
| 3328 | } |
| 3329 | } |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 3330 | |
| 3331 | int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn, |
| 3332 | struct qed_ptt *p_ptt, |
| 3333 | struct qed_mcp_link_state *p_link, |
| 3334 | u8 max_bw) |
| 3335 | { |
| 3336 | int rc = 0; |
| 3337 | |
| 3338 | p_hwfn->mcp_info->func_info.bandwidth_max = max_bw; |
| 3339 | |
| 3340 | if (!p_link->line_speed && (max_bw != 100)) |
| 3341 | return rc; |
| 3342 | |
| 3343 | p_link->speed = (p_link->line_speed * max_bw) / 100; |
| 3344 | p_hwfn->qm_info.pf_rl = p_link->speed; |
| 3345 | |
| 3346 | /* Since the limiter also affects Tx-switched traffic, we don't want it |
| 3347 | * to limit such traffic in case there's no actual limit. |
| 3348 | * In that case, set limit to imaginary high boundary. |
| 3349 | */ |
| 3350 | if (max_bw == 100) |
| 3351 | p_hwfn->qm_info.pf_rl = 100000; |
| 3352 | |
| 3353 | rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id, |
| 3354 | p_hwfn->qm_info.pf_rl); |
| 3355 | |
| 3356 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 3357 | "Configured MAX bandwidth to be %08x Mb/sec\n", |
| 3358 | p_link->speed); |
| 3359 | |
| 3360 | return rc; |
| 3361 | } |
| 3362 | |
| 3363 | /* Main API to configure PF max bandwidth where bw range is [1 - 100] */ |
| 3364 | int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw) |
| 3365 | { |
| 3366 | int i, rc = -EINVAL; |
| 3367 | |
| 3368 | if (max_bw < 1 || max_bw > 100) { |
| 3369 | DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n"); |
| 3370 | return rc; |
| 3371 | } |
| 3372 | |
| 3373 | for_each_hwfn(cdev, i) { |
| 3374 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 3375 | struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev); |
| 3376 | struct qed_mcp_link_state *p_link; |
| 3377 | struct qed_ptt *p_ptt; |
| 3378 | |
| 3379 | p_link = &p_lead->mcp_info->link_output; |
| 3380 | |
| 3381 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 3382 | if (!p_ptt) |
| 3383 | return -EBUSY; |
| 3384 | |
| 3385 | rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt, |
| 3386 | p_link, max_bw); |
| 3387 | |
| 3388 | qed_ptt_release(p_hwfn, p_ptt); |
| 3389 | |
| 3390 | if (rc) |
| 3391 | break; |
| 3392 | } |
| 3393 | |
| 3394 | return rc; |
| 3395 | } |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 3396 | |
| 3397 | int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn, |
| 3398 | struct qed_ptt *p_ptt, |
| 3399 | struct qed_mcp_link_state *p_link, |
| 3400 | u8 min_bw) |
| 3401 | { |
| 3402 | int rc = 0; |
| 3403 | |
| 3404 | p_hwfn->mcp_info->func_info.bandwidth_min = min_bw; |
| 3405 | p_hwfn->qm_info.pf_wfq = min_bw; |
| 3406 | |
| 3407 | if (!p_link->line_speed) |
| 3408 | return rc; |
| 3409 | |
| 3410 | p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100; |
| 3411 | |
| 3412 | rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw); |
| 3413 | |
| 3414 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 3415 | "Configured MIN bandwidth to be %d Mb/sec\n", |
| 3416 | p_link->min_pf_rate); |
| 3417 | |
| 3418 | return rc; |
| 3419 | } |
| 3420 | |
| 3421 | /* Main API to configure PF min bandwidth where bw range is [1-100] */ |
| 3422 | int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw) |
| 3423 | { |
| 3424 | int i, rc = -EINVAL; |
| 3425 | |
| 3426 | if (min_bw < 1 || min_bw > 100) { |
| 3427 | DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n"); |
| 3428 | return rc; |
| 3429 | } |
| 3430 | |
| 3431 | for_each_hwfn(cdev, i) { |
| 3432 | struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; |
| 3433 | struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev); |
| 3434 | struct qed_mcp_link_state *p_link; |
| 3435 | struct qed_ptt *p_ptt; |
| 3436 | |
| 3437 | p_link = &p_lead->mcp_info->link_output; |
| 3438 | |
| 3439 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 3440 | if (!p_ptt) |
| 3441 | return -EBUSY; |
| 3442 | |
| 3443 | rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt, |
| 3444 | p_link, min_bw); |
| 3445 | if (rc) { |
| 3446 | qed_ptt_release(p_hwfn, p_ptt); |
| 3447 | return rc; |
| 3448 | } |
| 3449 | |
| 3450 | if (p_link->min_pf_rate) { |
| 3451 | u32 min_rate = p_link->min_pf_rate; |
| 3452 | |
| 3453 | rc = __qed_configure_vp_wfq_on_link_change(p_hwfn, |
| 3454 | p_ptt, |
| 3455 | min_rate); |
| 3456 | } |
| 3457 | |
| 3458 | qed_ptt_release(p_hwfn, p_ptt); |
| 3459 | } |
| 3460 | |
| 3461 | return rc; |
| 3462 | } |
Yuval Mintz | 733def6 | 2016-05-11 16:36:22 +0300 | [diff] [blame] | 3463 | |
| 3464 | void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 3465 | { |
| 3466 | struct qed_mcp_link_state *p_link; |
| 3467 | |
| 3468 | p_link = &p_hwfn->mcp_info->link_output; |
| 3469 | |
| 3470 | if (p_link->min_pf_rate) |
| 3471 | qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, |
| 3472 | p_link->min_pf_rate); |
| 3473 | |
| 3474 | memset(p_hwfn->qm_info.wfq_data, 0, |
| 3475 | sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports); |
| 3476 | } |
Mintz, Yuval | 9c79dda | 2017-03-14 16:23:54 +0200 | [diff] [blame] | 3477 | |
| 3478 | int qed_device_num_engines(struct qed_dev *cdev) |
| 3479 | { |
| 3480 | return QED_IS_BB(cdev) ? 2 : 1; |
| 3481 | } |