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/delay.h> |
| 36 | #include <linux/errno.h> |
| 37 | #include <linux/kernel.h> |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 38 | #include <linux/slab.h> |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 39 | #include <linux/spinlock.h> |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 40 | #include <linux/string.h> |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 41 | #include <linux/etherdevice.h> |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 42 | #include "qed.h" |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 43 | #include "qed_dcbx.h" |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 44 | #include "qed_hsi.h" |
| 45 | #include "qed_hw.h" |
| 46 | #include "qed_mcp.h" |
| 47 | #include "qed_reg_addr.h" |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 48 | #include "qed_sriov.h" |
| 49 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 50 | #define CHIP_MCP_RESP_ITER_US 10 |
| 51 | |
| 52 | #define QED_DRV_MB_MAX_RETRIES (500 * 1000) /* Account for 5 sec */ |
| 53 | #define QED_MCP_RESET_RETRIES (50 * 1000) /* Account for 500 msec */ |
| 54 | |
| 55 | #define DRV_INNER_WR(_p_hwfn, _p_ptt, _ptr, _offset, _val) \ |
| 56 | qed_wr(_p_hwfn, _p_ptt, (_p_hwfn->mcp_info->_ptr + _offset), \ |
| 57 | _val) |
| 58 | |
| 59 | #define DRV_INNER_RD(_p_hwfn, _p_ptt, _ptr, _offset) \ |
| 60 | qed_rd(_p_hwfn, _p_ptt, (_p_hwfn->mcp_info->_ptr + _offset)) |
| 61 | |
| 62 | #define DRV_MB_WR(_p_hwfn, _p_ptt, _field, _val) \ |
| 63 | DRV_INNER_WR(p_hwfn, _p_ptt, drv_mb_addr, \ |
| 64 | offsetof(struct public_drv_mb, _field), _val) |
| 65 | |
| 66 | #define DRV_MB_RD(_p_hwfn, _p_ptt, _field) \ |
| 67 | DRV_INNER_RD(_p_hwfn, _p_ptt, drv_mb_addr, \ |
| 68 | offsetof(struct public_drv_mb, _field)) |
| 69 | |
| 70 | #define PDA_COMP (((FW_MAJOR_VERSION) + (FW_MINOR_VERSION << 8)) << \ |
| 71 | DRV_ID_PDA_COMP_VER_SHIFT) |
| 72 | |
| 73 | #define MCP_BYTES_PER_MBIT_SHIFT 17 |
| 74 | |
| 75 | bool qed_mcp_is_init(struct qed_hwfn *p_hwfn) |
| 76 | { |
| 77 | if (!p_hwfn->mcp_info || !p_hwfn->mcp_info->public_base) |
| 78 | return false; |
| 79 | return true; |
| 80 | } |
| 81 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 82 | void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 83 | { |
| 84 | u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base, |
| 85 | PUBLIC_PORT); |
| 86 | u32 mfw_mb_offsize = qed_rd(p_hwfn, p_ptt, addr); |
| 87 | |
| 88 | p_hwfn->mcp_info->port_addr = SECTION_ADDR(mfw_mb_offsize, |
| 89 | MFW_PORT(p_hwfn)); |
| 90 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 91 | "port_addr = 0x%x, port_id 0x%02x\n", |
| 92 | p_hwfn->mcp_info->port_addr, MFW_PORT(p_hwfn)); |
| 93 | } |
| 94 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 95 | void qed_mcp_read_mb(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 96 | { |
| 97 | u32 length = MFW_DRV_MSG_MAX_DWORDS(p_hwfn->mcp_info->mfw_mb_length); |
| 98 | u32 tmp, i; |
| 99 | |
| 100 | if (!p_hwfn->mcp_info->public_base) |
| 101 | return; |
| 102 | |
| 103 | for (i = 0; i < length; i++) { |
| 104 | tmp = qed_rd(p_hwfn, p_ptt, |
| 105 | p_hwfn->mcp_info->mfw_mb_addr + |
| 106 | (i << 2) + sizeof(u32)); |
| 107 | |
| 108 | /* The MB data is actually BE; Need to force it to cpu */ |
| 109 | ((u32 *)p_hwfn->mcp_info->mfw_mb_cur)[i] = |
| 110 | be32_to_cpu((__force __be32)tmp); |
| 111 | } |
| 112 | } |
| 113 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 114 | struct qed_mcp_cmd_elem { |
| 115 | struct list_head list; |
| 116 | struct qed_mcp_mb_params *p_mb_params; |
| 117 | u16 expected_seq_num; |
| 118 | bool b_is_completed; |
| 119 | }; |
| 120 | |
| 121 | /* Must be called while cmd_lock is acquired */ |
| 122 | static struct qed_mcp_cmd_elem * |
| 123 | qed_mcp_cmd_add_elem(struct qed_hwfn *p_hwfn, |
| 124 | struct qed_mcp_mb_params *p_mb_params, |
| 125 | u16 expected_seq_num) |
| 126 | { |
| 127 | struct qed_mcp_cmd_elem *p_cmd_elem = NULL; |
| 128 | |
| 129 | p_cmd_elem = kzalloc(sizeof(*p_cmd_elem), GFP_ATOMIC); |
| 130 | if (!p_cmd_elem) |
| 131 | goto out; |
| 132 | |
| 133 | p_cmd_elem->p_mb_params = p_mb_params; |
| 134 | p_cmd_elem->expected_seq_num = expected_seq_num; |
| 135 | list_add(&p_cmd_elem->list, &p_hwfn->mcp_info->cmd_list); |
| 136 | out: |
| 137 | return p_cmd_elem; |
| 138 | } |
| 139 | |
| 140 | /* Must be called while cmd_lock is acquired */ |
| 141 | static void qed_mcp_cmd_del_elem(struct qed_hwfn *p_hwfn, |
| 142 | struct qed_mcp_cmd_elem *p_cmd_elem) |
| 143 | { |
| 144 | list_del(&p_cmd_elem->list); |
| 145 | kfree(p_cmd_elem); |
| 146 | } |
| 147 | |
| 148 | /* Must be called while cmd_lock is acquired */ |
| 149 | static struct qed_mcp_cmd_elem *qed_mcp_cmd_get_elem(struct qed_hwfn *p_hwfn, |
| 150 | u16 seq_num) |
| 151 | { |
| 152 | struct qed_mcp_cmd_elem *p_cmd_elem = NULL; |
| 153 | |
| 154 | list_for_each_entry(p_cmd_elem, &p_hwfn->mcp_info->cmd_list, list) { |
| 155 | if (p_cmd_elem->expected_seq_num == seq_num) |
| 156 | return p_cmd_elem; |
| 157 | } |
| 158 | |
| 159 | return NULL; |
| 160 | } |
| 161 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 162 | int qed_mcp_free(struct qed_hwfn *p_hwfn) |
| 163 | { |
| 164 | if (p_hwfn->mcp_info) { |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 165 | struct qed_mcp_cmd_elem *p_cmd_elem, *p_tmp; |
| 166 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 167 | kfree(p_hwfn->mcp_info->mfw_mb_cur); |
| 168 | kfree(p_hwfn->mcp_info->mfw_mb_shadow); |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 169 | |
| 170 | spin_lock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 171 | list_for_each_entry_safe(p_cmd_elem, |
| 172 | p_tmp, |
| 173 | &p_hwfn->mcp_info->cmd_list, list) { |
| 174 | qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem); |
| 175 | } |
| 176 | spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 177 | } |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 178 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 179 | kfree(p_hwfn->mcp_info); |
Tomer Tayar | 3587cb8 | 2017-05-21 12:10:56 +0300 | [diff] [blame] | 180 | p_hwfn->mcp_info = NULL; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 185 | static int qed_load_mcp_offsets(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 186 | { |
| 187 | struct qed_mcp_info *p_info = p_hwfn->mcp_info; |
| 188 | u32 drv_mb_offsize, mfw_mb_offsize; |
| 189 | u32 mcp_pf_id = MCP_PF_ID(p_hwfn); |
| 190 | |
| 191 | p_info->public_base = qed_rd(p_hwfn, p_ptt, MISC_REG_SHARED_MEM_ADDR); |
| 192 | if (!p_info->public_base) |
| 193 | return 0; |
| 194 | |
| 195 | p_info->public_base |= GRCBASE_MCP; |
| 196 | |
| 197 | /* Calculate the driver and MFW mailbox address */ |
| 198 | drv_mb_offsize = qed_rd(p_hwfn, p_ptt, |
| 199 | SECTION_OFFSIZE_ADDR(p_info->public_base, |
| 200 | PUBLIC_DRV_MB)); |
| 201 | p_info->drv_mb_addr = SECTION_ADDR(drv_mb_offsize, mcp_pf_id); |
| 202 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 203 | "drv_mb_offsiz = 0x%x, drv_mb_addr = 0x%x mcp_pf_id = 0x%x\n", |
| 204 | drv_mb_offsize, p_info->drv_mb_addr, mcp_pf_id); |
| 205 | |
| 206 | /* Set the MFW MB address */ |
| 207 | mfw_mb_offsize = qed_rd(p_hwfn, p_ptt, |
| 208 | SECTION_OFFSIZE_ADDR(p_info->public_base, |
| 209 | PUBLIC_MFW_MB)); |
| 210 | p_info->mfw_mb_addr = SECTION_ADDR(mfw_mb_offsize, mcp_pf_id); |
| 211 | p_info->mfw_mb_length = (u16)qed_rd(p_hwfn, p_ptt, p_info->mfw_mb_addr); |
| 212 | |
| 213 | /* Get the current driver mailbox sequence before sending |
| 214 | * the first command |
| 215 | */ |
| 216 | p_info->drv_mb_seq = DRV_MB_RD(p_hwfn, p_ptt, drv_mb_header) & |
| 217 | DRV_MSG_SEQ_NUMBER_MASK; |
| 218 | |
| 219 | /* Get current FW pulse sequence */ |
| 220 | p_info->drv_pulse_seq = DRV_MB_RD(p_hwfn, p_ptt, drv_pulse_mb) & |
| 221 | DRV_PULSE_SEQ_MASK; |
| 222 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 223 | p_info->mcp_hist = qed_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 228 | int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 229 | { |
| 230 | struct qed_mcp_info *p_info; |
| 231 | u32 size; |
| 232 | |
| 233 | /* Allocate mcp_info structure */ |
Yuval Mintz | 60fffb3 | 2016-02-21 11:40:07 +0200 | [diff] [blame] | 234 | p_hwfn->mcp_info = kzalloc(sizeof(*p_hwfn->mcp_info), GFP_KERNEL); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 235 | if (!p_hwfn->mcp_info) |
| 236 | goto err; |
| 237 | p_info = p_hwfn->mcp_info; |
| 238 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 239 | /* Initialize the MFW spinlock */ |
| 240 | spin_lock_init(&p_info->cmd_lock); |
| 241 | spin_lock_init(&p_info->link_lock); |
| 242 | |
| 243 | INIT_LIST_HEAD(&p_info->cmd_list); |
| 244 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 245 | if (qed_load_mcp_offsets(p_hwfn, p_ptt) != 0) { |
| 246 | DP_NOTICE(p_hwfn, "MCP is not initialized\n"); |
| 247 | /* Do not free mcp_info here, since public_base indicate that |
| 248 | * the MCP is not initialized |
| 249 | */ |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | size = MFW_DRV_MSG_MAX_DWORDS(p_info->mfw_mb_length) * sizeof(u32); |
Yuval Mintz | 60fffb3 | 2016-02-21 11:40:07 +0200 | [diff] [blame] | 254 | p_info->mfw_mb_cur = kzalloc(size, GFP_KERNEL); |
Yuval Mintz | 83aeb93 | 2016-08-15 10:42:44 +0300 | [diff] [blame] | 255 | p_info->mfw_mb_shadow = kzalloc(size, GFP_KERNEL); |
Christophe Jaillet | eb2a6b8 | 2017-08-07 00:00:17 +0200 | [diff] [blame] | 256 | if (!p_info->mfw_mb_cur || !p_info->mfw_mb_shadow) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 257 | goto err; |
| 258 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 259 | return 0; |
| 260 | |
| 261 | err: |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 262 | qed_mcp_free(p_hwfn); |
| 263 | return -ENOMEM; |
| 264 | } |
| 265 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 266 | static void qed_mcp_reread_offsets(struct qed_hwfn *p_hwfn, |
| 267 | struct qed_ptt *p_ptt) |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 268 | { |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 269 | u32 generic_por_0 = qed_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0); |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 270 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 271 | /* Use MCP history register to check if MCP reset occurred between init |
| 272 | * time and now. |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 273 | */ |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 274 | if (p_hwfn->mcp_info->mcp_hist != generic_por_0) { |
| 275 | DP_VERBOSE(p_hwfn, |
| 276 | QED_MSG_SP, |
| 277 | "Rereading MCP offsets [mcp_hist 0x%08x, generic_por_0 0x%08x]\n", |
| 278 | p_hwfn->mcp_info->mcp_hist, generic_por_0); |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 279 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 280 | qed_load_mcp_offsets(p_hwfn, p_ptt); |
| 281 | qed_mcp_cmd_port_init(p_hwfn, p_ptt); |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 282 | } |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 283 | } |
| 284 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 285 | int qed_mcp_reset(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 286 | { |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 287 | u32 org_mcp_reset_seq, seq, delay = CHIP_MCP_RESP_ITER_US, cnt = 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 288 | int rc = 0; |
| 289 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 290 | /* Ensure that only a single thread is accessing the mailbox */ |
| 291 | spin_lock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 292 | |
| 293 | org_mcp_reset_seq = qed_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0); |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 294 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 295 | /* Set drv command along with the updated sequence */ |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 296 | qed_mcp_reread_offsets(p_hwfn, p_ptt); |
| 297 | seq = ++p_hwfn->mcp_info->drv_mb_seq; |
| 298 | DRV_MB_WR(p_hwfn, p_ptt, drv_mb_header, (DRV_MSG_CODE_MCP_RESET | seq)); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 299 | |
| 300 | do { |
| 301 | /* Wait for MFW response */ |
| 302 | udelay(delay); |
| 303 | /* Give the FW up to 500 second (50*1000*10usec) */ |
| 304 | } while ((org_mcp_reset_seq == qed_rd(p_hwfn, p_ptt, |
| 305 | MISCS_REG_GENERIC_POR_0)) && |
| 306 | (cnt++ < QED_MCP_RESET_RETRIES)); |
| 307 | |
| 308 | if (org_mcp_reset_seq != |
| 309 | qed_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0)) { |
| 310 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 311 | "MCP was reset after %d usec\n", cnt * delay); |
| 312 | } else { |
| 313 | DP_ERR(p_hwfn, "Failed to reset MCP\n"); |
| 314 | rc = -EAGAIN; |
| 315 | } |
| 316 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 317 | spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 318 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 319 | return rc; |
| 320 | } |
| 321 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 322 | /* Must be called while cmd_lock is acquired */ |
| 323 | static bool qed_mcp_has_pending_cmd(struct qed_hwfn *p_hwfn) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 324 | { |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 325 | struct qed_mcp_cmd_elem *p_cmd_elem; |
| 326 | |
| 327 | /* There is at most one pending command at a certain time, and if it |
| 328 | * exists - it is placed at the HEAD of the list. |
| 329 | */ |
| 330 | if (!list_empty(&p_hwfn->mcp_info->cmd_list)) { |
| 331 | p_cmd_elem = list_first_entry(&p_hwfn->mcp_info->cmd_list, |
| 332 | struct qed_mcp_cmd_elem, list); |
| 333 | return !p_cmd_elem->b_is_completed; |
| 334 | } |
| 335 | |
| 336 | return false; |
| 337 | } |
| 338 | |
| 339 | /* Must be called while cmd_lock is acquired */ |
| 340 | static int |
| 341 | qed_mcp_update_pending_cmd(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 342 | { |
| 343 | struct qed_mcp_mb_params *p_mb_params; |
| 344 | struct qed_mcp_cmd_elem *p_cmd_elem; |
| 345 | u32 mcp_resp; |
| 346 | u16 seq_num; |
| 347 | |
| 348 | mcp_resp = DRV_MB_RD(p_hwfn, p_ptt, fw_mb_header); |
| 349 | seq_num = (u16)(mcp_resp & FW_MSG_SEQ_NUMBER_MASK); |
| 350 | |
| 351 | /* Return if no new non-handled response has been received */ |
| 352 | if (seq_num != p_hwfn->mcp_info->drv_mb_seq) |
| 353 | return -EAGAIN; |
| 354 | |
| 355 | p_cmd_elem = qed_mcp_cmd_get_elem(p_hwfn, seq_num); |
| 356 | if (!p_cmd_elem) { |
| 357 | DP_ERR(p_hwfn, |
| 358 | "Failed to find a pending mailbox cmd that expects sequence number %d\n", |
| 359 | seq_num); |
| 360 | return -EINVAL; |
| 361 | } |
| 362 | |
| 363 | p_mb_params = p_cmd_elem->p_mb_params; |
| 364 | |
| 365 | /* Get the MFW response along with the sequence number */ |
| 366 | p_mb_params->mcp_resp = mcp_resp; |
| 367 | |
| 368 | /* Get the MFW param */ |
| 369 | p_mb_params->mcp_param = DRV_MB_RD(p_hwfn, p_ptt, fw_mb_param); |
| 370 | |
| 371 | /* Get the union data */ |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 372 | if (p_mb_params->p_data_dst != NULL && p_mb_params->data_dst_size) { |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 373 | u32 union_data_addr = p_hwfn->mcp_info->drv_mb_addr + |
| 374 | offsetof(struct public_drv_mb, |
| 375 | union_data); |
| 376 | qed_memcpy_from(p_hwfn, p_ptt, p_mb_params->p_data_dst, |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 377 | union_data_addr, p_mb_params->data_dst_size); |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | p_cmd_elem->b_is_completed = true; |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | /* Must be called while cmd_lock is acquired */ |
| 386 | static void __qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn, |
| 387 | struct qed_ptt *p_ptt, |
| 388 | struct qed_mcp_mb_params *p_mb_params, |
| 389 | u16 seq_num) |
| 390 | { |
| 391 | union drv_union_data union_data; |
| 392 | u32 union_data_addr; |
| 393 | |
| 394 | /* Set the union data */ |
| 395 | union_data_addr = p_hwfn->mcp_info->drv_mb_addr + |
| 396 | offsetof(struct public_drv_mb, union_data); |
| 397 | memset(&union_data, 0, sizeof(union_data)); |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 398 | if (p_mb_params->p_data_src != NULL && p_mb_params->data_src_size) |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 399 | memcpy(&union_data, p_mb_params->p_data_src, |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 400 | p_mb_params->data_src_size); |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 401 | qed_memcpy_to(p_hwfn, p_ptt, union_data_addr, &union_data, |
| 402 | sizeof(union_data)); |
| 403 | |
| 404 | /* Set the drv param */ |
| 405 | DRV_MB_WR(p_hwfn, p_ptt, drv_mb_param, p_mb_params->param); |
| 406 | |
| 407 | /* Set the drv command along with the sequence number */ |
| 408 | DRV_MB_WR(p_hwfn, p_ptt, drv_mb_header, (p_mb_params->cmd | seq_num)); |
| 409 | |
| 410 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 411 | "MFW mailbox: command 0x%08x param 0x%08x\n", |
| 412 | (p_mb_params->cmd | seq_num), p_mb_params->param); |
| 413 | } |
| 414 | |
| 415 | static int |
| 416 | _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn, |
| 417 | struct qed_ptt *p_ptt, |
| 418 | struct qed_mcp_mb_params *p_mb_params, |
| 419 | u32 max_retries, u32 delay) |
| 420 | { |
| 421 | struct qed_mcp_cmd_elem *p_cmd_elem; |
| 422 | u32 cnt = 0; |
| 423 | u16 seq_num; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 424 | int rc = 0; |
| 425 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 426 | /* Wait until the mailbox is non-occupied */ |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 427 | do { |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 428 | /* Exit the loop if there is no pending command, or if the |
| 429 | * pending command is completed during this iteration. |
| 430 | * The spinlock stays locked until the command is sent. |
| 431 | */ |
| 432 | |
| 433 | spin_lock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 434 | |
| 435 | if (!qed_mcp_has_pending_cmd(p_hwfn)) |
| 436 | break; |
| 437 | |
| 438 | rc = qed_mcp_update_pending_cmd(p_hwfn, p_ptt); |
| 439 | if (!rc) |
| 440 | break; |
| 441 | else if (rc != -EAGAIN) |
| 442 | goto err; |
| 443 | |
| 444 | spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 445 | udelay(delay); |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 446 | } while (++cnt < max_retries); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 447 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 448 | if (cnt >= max_retries) { |
| 449 | DP_NOTICE(p_hwfn, |
| 450 | "The MFW mailbox is occupied by an uncompleted command. Failed to send command 0x%08x [param 0x%08x].\n", |
| 451 | p_mb_params->cmd, p_mb_params->param); |
| 452 | return -EAGAIN; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 453 | } |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 454 | |
| 455 | /* Send the mailbox command */ |
| 456 | qed_mcp_reread_offsets(p_hwfn, p_ptt); |
| 457 | seq_num = ++p_hwfn->mcp_info->drv_mb_seq; |
| 458 | p_cmd_elem = qed_mcp_cmd_add_elem(p_hwfn, p_mb_params, seq_num); |
Dan Carpenter | c800460 | 2017-04-03 21:25:22 +0300 | [diff] [blame] | 459 | if (!p_cmd_elem) { |
| 460 | rc = -ENOMEM; |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 461 | goto err; |
Dan Carpenter | c800460 | 2017-04-03 21:25:22 +0300 | [diff] [blame] | 462 | } |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 463 | |
| 464 | __qed_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, seq_num); |
| 465 | spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 466 | |
| 467 | /* Wait for the MFW response */ |
| 468 | do { |
| 469 | /* Exit the loop if the command is already completed, or if the |
| 470 | * command is completed during this iteration. |
| 471 | * The spinlock stays locked until the list element is removed. |
| 472 | */ |
| 473 | |
| 474 | udelay(delay); |
| 475 | spin_lock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 476 | |
| 477 | if (p_cmd_elem->b_is_completed) |
| 478 | break; |
| 479 | |
| 480 | rc = qed_mcp_update_pending_cmd(p_hwfn, p_ptt); |
| 481 | if (!rc) |
| 482 | break; |
| 483 | else if (rc != -EAGAIN) |
| 484 | goto err; |
| 485 | |
| 486 | spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 487 | } while (++cnt < max_retries); |
| 488 | |
| 489 | if (cnt >= max_retries) { |
| 490 | DP_NOTICE(p_hwfn, |
| 491 | "The MFW failed to respond to command 0x%08x [param 0x%08x].\n", |
| 492 | p_mb_params->cmd, p_mb_params->param); |
| 493 | |
| 494 | spin_lock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 495 | qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem); |
| 496 | spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 497 | |
| 498 | return -EAGAIN; |
| 499 | } |
| 500 | |
| 501 | qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem); |
| 502 | spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); |
| 503 | |
| 504 | DP_VERBOSE(p_hwfn, |
| 505 | QED_MSG_SP, |
| 506 | "MFW mailbox: response 0x%08x param 0x%08x [after %d.%03d ms]\n", |
| 507 | p_mb_params->mcp_resp, |
| 508 | p_mb_params->mcp_param, |
| 509 | (cnt * delay) / 1000, (cnt * delay) % 1000); |
| 510 | |
| 511 | /* Clear the sequence number from the MFW response */ |
| 512 | p_mb_params->mcp_resp &= FW_MSG_CODE_MASK; |
| 513 | |
| 514 | return 0; |
| 515 | |
| 516 | err: |
| 517 | spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 518 | return rc; |
| 519 | } |
| 520 | |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 521 | static int qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn, |
| 522 | struct qed_ptt *p_ptt, |
| 523 | struct qed_mcp_mb_params *p_mb_params) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 524 | { |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 525 | size_t union_data_size = sizeof(union drv_union_data); |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 526 | u32 max_retries = QED_DRV_MB_MAX_RETRIES; |
| 527 | u32 delay = CHIP_MCP_RESP_ITER_US; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 528 | |
| 529 | /* MCP not initialized */ |
| 530 | if (!qed_mcp_is_init(p_hwfn)) { |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 531 | DP_NOTICE(p_hwfn, "MFW is not initialized!\n"); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 532 | return -EBUSY; |
| 533 | } |
| 534 | |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 535 | if (p_mb_params->data_src_size > union_data_size || |
| 536 | p_mb_params->data_dst_size > union_data_size) { |
| 537 | DP_ERR(p_hwfn, |
| 538 | "The provided size is larger than the union data size [src_size %u, dst_size %u, union_data_size %zu]\n", |
| 539 | p_mb_params->data_src_size, |
| 540 | p_mb_params->data_dst_size, union_data_size); |
| 541 | return -EINVAL; |
| 542 | } |
| 543 | |
Tomer Tayar | 4ed1eea | 2017-03-23 15:50:15 +0200 | [diff] [blame] | 544 | return _qed_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, max_retries, |
| 545 | delay); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 546 | } |
| 547 | |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 548 | int qed_mcp_cmd(struct qed_hwfn *p_hwfn, |
| 549 | struct qed_ptt *p_ptt, |
| 550 | u32 cmd, |
| 551 | u32 param, |
| 552 | u32 *o_mcp_resp, |
| 553 | u32 *o_mcp_param) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 554 | { |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 555 | struct qed_mcp_mb_params mb_params; |
| 556 | int rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 557 | |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 558 | memset(&mb_params, 0, sizeof(mb_params)); |
| 559 | mb_params.cmd = cmd; |
| 560 | mb_params.param = param; |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 561 | |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 562 | rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
| 563 | if (rc) |
| 564 | return rc; |
| 565 | |
| 566 | *o_mcp_resp = mb_params.mcp_resp; |
| 567 | *o_mcp_param = mb_params.mcp_param; |
| 568 | |
| 569 | return 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 570 | } |
| 571 | |
Tomer Tayar | 4102426 | 2016-09-05 14:35:10 +0300 | [diff] [blame] | 572 | int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn, |
| 573 | struct qed_ptt *p_ptt, |
| 574 | u32 cmd, |
| 575 | u32 param, |
| 576 | u32 *o_mcp_resp, |
| 577 | u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf) |
| 578 | { |
| 579 | struct qed_mcp_mb_params mb_params; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 580 | u8 raw_data[MCP_DRV_NVM_BUF_LEN]; |
Tomer Tayar | 4102426 | 2016-09-05 14:35:10 +0300 | [diff] [blame] | 581 | int rc; |
| 582 | |
| 583 | memset(&mb_params, 0, sizeof(mb_params)); |
| 584 | mb_params.cmd = cmd; |
| 585 | mb_params.param = param; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 586 | mb_params.p_data_dst = raw_data; |
| 587 | |
| 588 | /* Use the maximal value since the actual one is part of the response */ |
| 589 | mb_params.data_dst_size = MCP_DRV_NVM_BUF_LEN; |
| 590 | |
Tomer Tayar | 4102426 | 2016-09-05 14:35:10 +0300 | [diff] [blame] | 591 | rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
| 592 | if (rc) |
| 593 | return rc; |
| 594 | |
| 595 | *o_mcp_resp = mb_params.mcp_resp; |
| 596 | *o_mcp_param = mb_params.mcp_param; |
| 597 | |
| 598 | *o_txn_size = *o_mcp_param; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 599 | memcpy(o_buf, raw_data, *o_txn_size); |
Tomer Tayar | 4102426 | 2016-09-05 14:35:10 +0300 | [diff] [blame] | 600 | |
| 601 | return 0; |
| 602 | } |
| 603 | |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 604 | static bool |
| 605 | qed_mcp_can_force_load(u8 drv_role, |
| 606 | u8 exist_drv_role, |
| 607 | enum qed_override_force_load override_force_load) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 608 | { |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 609 | bool can_force_load = false; |
| 610 | |
| 611 | switch (override_force_load) { |
| 612 | case QED_OVERRIDE_FORCE_LOAD_ALWAYS: |
| 613 | can_force_load = true; |
| 614 | break; |
| 615 | case QED_OVERRIDE_FORCE_LOAD_NEVER: |
| 616 | can_force_load = false; |
| 617 | break; |
| 618 | default: |
| 619 | can_force_load = (drv_role == DRV_ROLE_OS && |
| 620 | exist_drv_role == DRV_ROLE_PREBOOT) || |
| 621 | (drv_role == DRV_ROLE_KDUMP && |
| 622 | exist_drv_role == DRV_ROLE_OS); |
| 623 | break; |
| 624 | } |
| 625 | |
| 626 | return can_force_load; |
| 627 | } |
| 628 | |
| 629 | static int qed_mcp_cancel_load_req(struct qed_hwfn *p_hwfn, |
| 630 | struct qed_ptt *p_ptt) |
| 631 | { |
| 632 | u32 resp = 0, param = 0; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 633 | int rc; |
| 634 | |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 635 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CANCEL_LOAD_REQ, 0, |
| 636 | &resp, ¶m); |
| 637 | if (rc) |
| 638 | DP_NOTICE(p_hwfn, |
| 639 | "Failed to send cancel load request, rc = %d\n", rc); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 640 | |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 641 | return rc; |
| 642 | } |
| 643 | |
| 644 | #define CONFIG_QEDE_BITMAP_IDX BIT(0) |
| 645 | #define CONFIG_QED_SRIOV_BITMAP_IDX BIT(1) |
| 646 | #define CONFIG_QEDR_BITMAP_IDX BIT(2) |
| 647 | #define CONFIG_QEDF_BITMAP_IDX BIT(4) |
| 648 | #define CONFIG_QEDI_BITMAP_IDX BIT(5) |
| 649 | #define CONFIG_QED_LL2_BITMAP_IDX BIT(6) |
| 650 | |
| 651 | static u32 qed_get_config_bitmap(void) |
| 652 | { |
| 653 | u32 config_bitmap = 0x0; |
| 654 | |
| 655 | if (IS_ENABLED(CONFIG_QEDE)) |
| 656 | config_bitmap |= CONFIG_QEDE_BITMAP_IDX; |
| 657 | |
| 658 | if (IS_ENABLED(CONFIG_QED_SRIOV)) |
| 659 | config_bitmap |= CONFIG_QED_SRIOV_BITMAP_IDX; |
| 660 | |
| 661 | if (IS_ENABLED(CONFIG_QED_RDMA)) |
| 662 | config_bitmap |= CONFIG_QEDR_BITMAP_IDX; |
| 663 | |
| 664 | if (IS_ENABLED(CONFIG_QED_FCOE)) |
| 665 | config_bitmap |= CONFIG_QEDF_BITMAP_IDX; |
| 666 | |
| 667 | if (IS_ENABLED(CONFIG_QED_ISCSI)) |
| 668 | config_bitmap |= CONFIG_QEDI_BITMAP_IDX; |
| 669 | |
| 670 | if (IS_ENABLED(CONFIG_QED_LL2)) |
| 671 | config_bitmap |= CONFIG_QED_LL2_BITMAP_IDX; |
| 672 | |
| 673 | return config_bitmap; |
| 674 | } |
| 675 | |
| 676 | struct qed_load_req_in_params { |
| 677 | u8 hsi_ver; |
| 678 | #define QED_LOAD_REQ_HSI_VER_DEFAULT 0 |
| 679 | #define QED_LOAD_REQ_HSI_VER_1 1 |
| 680 | u32 drv_ver_0; |
| 681 | u32 drv_ver_1; |
| 682 | u32 fw_ver; |
| 683 | u8 drv_role; |
| 684 | u8 timeout_val; |
| 685 | u8 force_cmd; |
| 686 | bool avoid_eng_reset; |
| 687 | }; |
| 688 | |
| 689 | struct qed_load_req_out_params { |
| 690 | u32 load_code; |
| 691 | u32 exist_drv_ver_0; |
| 692 | u32 exist_drv_ver_1; |
| 693 | u32 exist_fw_ver; |
| 694 | u8 exist_drv_role; |
| 695 | u8 mfw_hsi_ver; |
| 696 | bool drv_exists; |
| 697 | }; |
| 698 | |
| 699 | static int |
| 700 | __qed_mcp_load_req(struct qed_hwfn *p_hwfn, |
| 701 | struct qed_ptt *p_ptt, |
| 702 | struct qed_load_req_in_params *p_in_params, |
| 703 | struct qed_load_req_out_params *p_out_params) |
| 704 | { |
| 705 | struct qed_mcp_mb_params mb_params; |
| 706 | struct load_req_stc load_req; |
| 707 | struct load_rsp_stc load_rsp; |
| 708 | u32 hsi_ver; |
| 709 | int rc; |
| 710 | |
| 711 | memset(&load_req, 0, sizeof(load_req)); |
| 712 | load_req.drv_ver_0 = p_in_params->drv_ver_0; |
| 713 | load_req.drv_ver_1 = p_in_params->drv_ver_1; |
| 714 | load_req.fw_ver = p_in_params->fw_ver; |
| 715 | QED_MFW_SET_FIELD(load_req.misc0, LOAD_REQ_ROLE, p_in_params->drv_role); |
| 716 | QED_MFW_SET_FIELD(load_req.misc0, LOAD_REQ_LOCK_TO, |
| 717 | p_in_params->timeout_val); |
| 718 | QED_MFW_SET_FIELD(load_req.misc0, LOAD_REQ_FORCE, |
| 719 | p_in_params->force_cmd); |
| 720 | QED_MFW_SET_FIELD(load_req.misc0, LOAD_REQ_FLAGS0, |
| 721 | p_in_params->avoid_eng_reset); |
| 722 | |
| 723 | hsi_ver = (p_in_params->hsi_ver == QED_LOAD_REQ_HSI_VER_DEFAULT) ? |
| 724 | DRV_ID_MCP_HSI_VER_CURRENT : |
| 725 | (p_in_params->hsi_ver << DRV_ID_MCP_HSI_VER_SHIFT); |
| 726 | |
| 727 | memset(&mb_params, 0, sizeof(mb_params)); |
| 728 | mb_params.cmd = DRV_MSG_CODE_LOAD_REQ; |
| 729 | mb_params.param = PDA_COMP | hsi_ver | p_hwfn->cdev->drv_type; |
| 730 | mb_params.p_data_src = &load_req; |
| 731 | mb_params.data_src_size = sizeof(load_req); |
| 732 | mb_params.p_data_dst = &load_rsp; |
| 733 | mb_params.data_dst_size = sizeof(load_rsp); |
| 734 | |
| 735 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 736 | "Load Request: param 0x%08x [init_hw %d, drv_type %d, hsi_ver %d, pda 0x%04x]\n", |
| 737 | mb_params.param, |
| 738 | QED_MFW_GET_FIELD(mb_params.param, DRV_ID_DRV_INIT_HW), |
| 739 | QED_MFW_GET_FIELD(mb_params.param, DRV_ID_DRV_TYPE), |
| 740 | QED_MFW_GET_FIELD(mb_params.param, DRV_ID_MCP_HSI_VER), |
| 741 | QED_MFW_GET_FIELD(mb_params.param, DRV_ID_PDA_COMP_VER)); |
| 742 | |
| 743 | if (p_in_params->hsi_ver != QED_LOAD_REQ_HSI_VER_1) { |
| 744 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 745 | "Load Request: drv_ver 0x%08x_0x%08x, fw_ver 0x%08x, misc0 0x%08x [role %d, timeout %d, force %d, flags0 0x%x]\n", |
| 746 | load_req.drv_ver_0, |
| 747 | load_req.drv_ver_1, |
| 748 | load_req.fw_ver, |
| 749 | load_req.misc0, |
| 750 | QED_MFW_GET_FIELD(load_req.misc0, LOAD_REQ_ROLE), |
| 751 | QED_MFW_GET_FIELD(load_req.misc0, |
| 752 | LOAD_REQ_LOCK_TO), |
| 753 | QED_MFW_GET_FIELD(load_req.misc0, LOAD_REQ_FORCE), |
| 754 | QED_MFW_GET_FIELD(load_req.misc0, LOAD_REQ_FLAGS0)); |
| 755 | } |
| 756 | |
| 757 | rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 758 | if (rc) { |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 759 | DP_NOTICE(p_hwfn, "Failed to send load request, rc = %d\n", rc); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 760 | return rc; |
| 761 | } |
| 762 | |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 763 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 764 | "Load Response: resp 0x%08x\n", mb_params.mcp_resp); |
| 765 | p_out_params->load_code = mb_params.mcp_resp; |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 766 | |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 767 | if (p_in_params->hsi_ver != QED_LOAD_REQ_HSI_VER_1 && |
| 768 | p_out_params->load_code != FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1) { |
| 769 | DP_VERBOSE(p_hwfn, |
| 770 | QED_MSG_SP, |
| 771 | "Load Response: exist_drv_ver 0x%08x_0x%08x, exist_fw_ver 0x%08x, misc0 0x%08x [exist_role %d, mfw_hsi %d, flags0 0x%x]\n", |
| 772 | load_rsp.drv_ver_0, |
| 773 | load_rsp.drv_ver_1, |
| 774 | load_rsp.fw_ver, |
| 775 | load_rsp.misc0, |
| 776 | QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_ROLE), |
| 777 | QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_HSI), |
| 778 | QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_FLAGS0)); |
| 779 | |
| 780 | p_out_params->exist_drv_ver_0 = load_rsp.drv_ver_0; |
| 781 | p_out_params->exist_drv_ver_1 = load_rsp.drv_ver_1; |
| 782 | p_out_params->exist_fw_ver = load_rsp.fw_ver; |
| 783 | p_out_params->exist_drv_role = |
| 784 | QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_ROLE); |
| 785 | p_out_params->mfw_hsi_ver = |
| 786 | QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_HSI); |
| 787 | p_out_params->drv_exists = |
| 788 | QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_FLAGS0) & |
| 789 | LOAD_RSP_FLAGS0_DRV_EXISTS; |
| 790 | } |
| 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | static int eocre_get_mfw_drv_role(struct qed_hwfn *p_hwfn, |
| 796 | enum qed_drv_role drv_role, |
| 797 | u8 *p_mfw_drv_role) |
| 798 | { |
| 799 | switch (drv_role) { |
| 800 | case QED_DRV_ROLE_OS: |
| 801 | *p_mfw_drv_role = DRV_ROLE_OS; |
| 802 | break; |
| 803 | case QED_DRV_ROLE_KDUMP: |
| 804 | *p_mfw_drv_role = DRV_ROLE_KDUMP; |
| 805 | break; |
| 806 | default: |
| 807 | DP_ERR(p_hwfn, "Unexpected driver role %d\n", drv_role); |
| 808 | return -EINVAL; |
| 809 | } |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | enum qed_load_req_force { |
| 815 | QED_LOAD_REQ_FORCE_NONE, |
| 816 | QED_LOAD_REQ_FORCE_PF, |
| 817 | QED_LOAD_REQ_FORCE_ALL, |
| 818 | }; |
| 819 | |
| 820 | static void qed_get_mfw_force_cmd(struct qed_hwfn *p_hwfn, |
| 821 | |
| 822 | enum qed_load_req_force force_cmd, |
| 823 | u8 *p_mfw_force_cmd) |
| 824 | { |
| 825 | switch (force_cmd) { |
| 826 | case QED_LOAD_REQ_FORCE_NONE: |
| 827 | *p_mfw_force_cmd = LOAD_REQ_FORCE_NONE; |
| 828 | break; |
| 829 | case QED_LOAD_REQ_FORCE_PF: |
| 830 | *p_mfw_force_cmd = LOAD_REQ_FORCE_PF; |
| 831 | break; |
| 832 | case QED_LOAD_REQ_FORCE_ALL: |
| 833 | *p_mfw_force_cmd = LOAD_REQ_FORCE_ALL; |
| 834 | break; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | int qed_mcp_load_req(struct qed_hwfn *p_hwfn, |
| 839 | struct qed_ptt *p_ptt, |
| 840 | struct qed_load_req_params *p_params) |
| 841 | { |
| 842 | struct qed_load_req_out_params out_params; |
| 843 | struct qed_load_req_in_params in_params; |
| 844 | u8 mfw_drv_role, mfw_force_cmd; |
| 845 | int rc; |
| 846 | |
| 847 | memset(&in_params, 0, sizeof(in_params)); |
| 848 | in_params.hsi_ver = QED_LOAD_REQ_HSI_VER_DEFAULT; |
| 849 | in_params.drv_ver_0 = QED_VERSION; |
| 850 | in_params.drv_ver_1 = qed_get_config_bitmap(); |
| 851 | in_params.fw_ver = STORM_FW_VERSION; |
| 852 | rc = eocre_get_mfw_drv_role(p_hwfn, p_params->drv_role, &mfw_drv_role); |
| 853 | if (rc) |
| 854 | return rc; |
| 855 | |
| 856 | in_params.drv_role = mfw_drv_role; |
| 857 | in_params.timeout_val = p_params->timeout_val; |
| 858 | qed_get_mfw_force_cmd(p_hwfn, |
| 859 | QED_LOAD_REQ_FORCE_NONE, &mfw_force_cmd); |
| 860 | |
| 861 | in_params.force_cmd = mfw_force_cmd; |
| 862 | in_params.avoid_eng_reset = p_params->avoid_eng_reset; |
| 863 | |
| 864 | memset(&out_params, 0, sizeof(out_params)); |
| 865 | rc = __qed_mcp_load_req(p_hwfn, p_ptt, &in_params, &out_params); |
| 866 | if (rc) |
| 867 | return rc; |
| 868 | |
| 869 | /* First handle cases where another load request should/might be sent: |
| 870 | * - MFW expects the old interface [HSI version = 1] |
| 871 | * - MFW responds that a force load request is required |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 872 | */ |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 873 | if (out_params.load_code == FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1) { |
| 874 | DP_INFO(p_hwfn, |
| 875 | "MFW refused a load request due to HSI > 1. Resending with HSI = 1\n"); |
| 876 | |
| 877 | in_params.hsi_ver = QED_LOAD_REQ_HSI_VER_1; |
| 878 | memset(&out_params, 0, sizeof(out_params)); |
| 879 | rc = __qed_mcp_load_req(p_hwfn, p_ptt, &in_params, &out_params); |
| 880 | if (rc) |
| 881 | return rc; |
| 882 | } else if (out_params.load_code == |
| 883 | FW_MSG_CODE_DRV_LOAD_REFUSED_REQUIRES_FORCE) { |
| 884 | if (qed_mcp_can_force_load(in_params.drv_role, |
| 885 | out_params.exist_drv_role, |
| 886 | p_params->override_force_load)) { |
| 887 | DP_INFO(p_hwfn, |
| 888 | "A force load is required [{role, fw_ver, drv_ver}: loading={%d, 0x%08x, x%08x_0x%08x}, existing={%d, 0x%08x, 0x%08x_0x%08x}]\n", |
| 889 | in_params.drv_role, in_params.fw_ver, |
| 890 | in_params.drv_ver_0, in_params.drv_ver_1, |
| 891 | out_params.exist_drv_role, |
| 892 | out_params.exist_fw_ver, |
| 893 | out_params.exist_drv_ver_0, |
| 894 | out_params.exist_drv_ver_1); |
| 895 | |
| 896 | qed_get_mfw_force_cmd(p_hwfn, |
| 897 | QED_LOAD_REQ_FORCE_ALL, |
| 898 | &mfw_force_cmd); |
| 899 | |
| 900 | in_params.force_cmd = mfw_force_cmd; |
| 901 | memset(&out_params, 0, sizeof(out_params)); |
| 902 | rc = __qed_mcp_load_req(p_hwfn, p_ptt, &in_params, |
| 903 | &out_params); |
| 904 | if (rc) |
| 905 | return rc; |
| 906 | } else { |
| 907 | DP_NOTICE(p_hwfn, |
| 908 | "A force load is required [{role, fw_ver, drv_ver}: loading={%d, 0x%08x, x%08x_0x%08x}, existing={%d, 0x%08x, 0x%08x_0x%08x}] - Avoid\n", |
| 909 | in_params.drv_role, in_params.fw_ver, |
| 910 | in_params.drv_ver_0, in_params.drv_ver_1, |
| 911 | out_params.exist_drv_role, |
| 912 | out_params.exist_fw_ver, |
| 913 | out_params.exist_drv_ver_0, |
| 914 | out_params.exist_drv_ver_1); |
| 915 | DP_NOTICE(p_hwfn, |
| 916 | "Avoid sending a force load request to prevent disruption of active PFs\n"); |
| 917 | |
| 918 | qed_mcp_cancel_load_req(p_hwfn, p_ptt); |
| 919 | return -EBUSY; |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | /* Now handle the other types of responses. |
| 924 | * The "REFUSED_HSI_1" and "REFUSED_REQUIRES_FORCE" responses are not |
| 925 | * expected here after the additional revised load requests were sent. |
| 926 | */ |
| 927 | switch (out_params.load_code) { |
| 928 | case FW_MSG_CODE_DRV_LOAD_ENGINE: |
| 929 | case FW_MSG_CODE_DRV_LOAD_PORT: |
| 930 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
| 931 | if (out_params.mfw_hsi_ver != QED_LOAD_REQ_HSI_VER_1 && |
| 932 | out_params.drv_exists) { |
| 933 | /* The role and fw/driver version match, but the PF is |
| 934 | * already loaded and has not been unloaded gracefully. |
| 935 | */ |
| 936 | DP_NOTICE(p_hwfn, |
| 937 | "PF is already loaded\n"); |
| 938 | return -EINVAL; |
| 939 | } |
| 940 | break; |
| 941 | default: |
| 942 | DP_NOTICE(p_hwfn, |
| 943 | "Unexpected refusal to load request [resp 0x%08x]. Aborting.\n", |
| 944 | out_params.load_code); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 945 | return -EBUSY; |
| 946 | } |
| 947 | |
Tomer Tayar | 5d24bcf | 2017-03-28 15:12:52 +0300 | [diff] [blame] | 948 | p_params->load_code = out_params.load_code; |
| 949 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 950 | return 0; |
| 951 | } |
| 952 | |
Tomer Tayar | 1226337 | 2017-03-28 15:12:50 +0300 | [diff] [blame] | 953 | int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 954 | { |
| 955 | u32 wol_param, mcp_resp, mcp_param; |
| 956 | |
| 957 | switch (p_hwfn->cdev->wol_config) { |
| 958 | case QED_OV_WOL_DISABLED: |
| 959 | wol_param = DRV_MB_PARAM_UNLOAD_WOL_DISABLED; |
| 960 | break; |
| 961 | case QED_OV_WOL_ENABLED: |
| 962 | wol_param = DRV_MB_PARAM_UNLOAD_WOL_ENABLED; |
| 963 | break; |
| 964 | default: |
| 965 | DP_NOTICE(p_hwfn, |
| 966 | "Unknown WoL configuration %02x\n", |
| 967 | p_hwfn->cdev->wol_config); |
| 968 | /* Fallthrough */ |
| 969 | case QED_OV_WOL_DEFAULT: |
| 970 | wol_param = DRV_MB_PARAM_UNLOAD_WOL_MCP; |
| 971 | } |
| 972 | |
| 973 | return qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_UNLOAD_REQ, wol_param, |
| 974 | &mcp_resp, &mcp_param); |
| 975 | } |
| 976 | |
| 977 | int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 978 | { |
| 979 | struct qed_mcp_mb_params mb_params; |
| 980 | struct mcp_mac wol_mac; |
| 981 | |
| 982 | memset(&mb_params, 0, sizeof(mb_params)); |
| 983 | mb_params.cmd = DRV_MSG_CODE_UNLOAD_DONE; |
| 984 | |
| 985 | /* Set the primary MAC if WoL is enabled */ |
| 986 | if (p_hwfn->cdev->wol_config == QED_OV_WOL_ENABLED) { |
| 987 | u8 *p_mac = p_hwfn->cdev->wol_mac; |
| 988 | |
| 989 | memset(&wol_mac, 0, sizeof(wol_mac)); |
| 990 | wol_mac.mac_upper = p_mac[0] << 8 | p_mac[1]; |
| 991 | wol_mac.mac_lower = p_mac[2] << 24 | p_mac[3] << 16 | |
| 992 | p_mac[4] << 8 | p_mac[5]; |
| 993 | |
| 994 | DP_VERBOSE(p_hwfn, |
| 995 | (QED_MSG_SP | NETIF_MSG_IFDOWN), |
| 996 | "Setting WoL MAC: %pM --> [%08x,%08x]\n", |
| 997 | p_mac, wol_mac.mac_upper, wol_mac.mac_lower); |
| 998 | |
| 999 | mb_params.p_data_src = &wol_mac; |
| 1000 | mb_params.data_src_size = sizeof(wol_mac); |
| 1001 | } |
| 1002 | |
| 1003 | return qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
| 1004 | } |
| 1005 | |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 1006 | static void qed_mcp_handle_vf_flr(struct qed_hwfn *p_hwfn, |
| 1007 | struct qed_ptt *p_ptt) |
| 1008 | { |
| 1009 | u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base, |
| 1010 | PUBLIC_PATH); |
| 1011 | u32 mfw_path_offsize = qed_rd(p_hwfn, p_ptt, addr); |
| 1012 | u32 path_addr = SECTION_ADDR(mfw_path_offsize, |
| 1013 | QED_PATH_ID(p_hwfn)); |
| 1014 | u32 disabled_vfs[VF_MAX_STATIC / 32]; |
| 1015 | int i; |
| 1016 | |
| 1017 | DP_VERBOSE(p_hwfn, |
| 1018 | QED_MSG_SP, |
| 1019 | "Reading Disabled VF information from [offset %08x], path_addr %08x\n", |
| 1020 | mfw_path_offsize, path_addr); |
| 1021 | |
| 1022 | for (i = 0; i < (VF_MAX_STATIC / 32); i++) { |
| 1023 | disabled_vfs[i] = qed_rd(p_hwfn, p_ptt, |
| 1024 | path_addr + |
| 1025 | offsetof(struct public_path, |
| 1026 | mcp_vf_disabled) + |
| 1027 | sizeof(u32) * i); |
| 1028 | DP_VERBOSE(p_hwfn, (QED_MSG_SP | QED_MSG_IOV), |
| 1029 | "FLR-ed VFs [%08x,...,%08x] - %08x\n", |
| 1030 | i * 32, (i + 1) * 32 - 1, disabled_vfs[i]); |
| 1031 | } |
| 1032 | |
| 1033 | if (qed_iov_mark_vf_flr(p_hwfn, disabled_vfs)) |
| 1034 | qed_schedule_iov(p_hwfn, QED_IOV_WQ_FLR_FLAG); |
| 1035 | } |
| 1036 | |
| 1037 | int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn, |
| 1038 | struct qed_ptt *p_ptt, u32 *vfs_to_ack) |
| 1039 | { |
| 1040 | u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base, |
| 1041 | PUBLIC_FUNC); |
| 1042 | u32 mfw_func_offsize = qed_rd(p_hwfn, p_ptt, addr); |
| 1043 | u32 func_addr = SECTION_ADDR(mfw_func_offsize, |
| 1044 | MCP_PF_ID(p_hwfn)); |
| 1045 | struct qed_mcp_mb_params mb_params; |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 1046 | int rc; |
| 1047 | int i; |
| 1048 | |
| 1049 | for (i = 0; i < (VF_MAX_STATIC / 32); i++) |
| 1050 | DP_VERBOSE(p_hwfn, (QED_MSG_SP | QED_MSG_IOV), |
| 1051 | "Acking VFs [%08x,...,%08x] - %08x\n", |
| 1052 | i * 32, (i + 1) * 32 - 1, vfs_to_ack[i]); |
| 1053 | |
| 1054 | memset(&mb_params, 0, sizeof(mb_params)); |
| 1055 | mb_params.cmd = DRV_MSG_CODE_VF_DISABLED_DONE; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1056 | mb_params.p_data_src = vfs_to_ack; |
| 1057 | mb_params.data_src_size = VF_MAX_STATIC / 8; |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 1058 | rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
| 1059 | if (rc) { |
| 1060 | DP_NOTICE(p_hwfn, "Failed to pass ACK for VF flr to MFW\n"); |
| 1061 | return -EBUSY; |
| 1062 | } |
| 1063 | |
| 1064 | /* Clear the ACK bits */ |
| 1065 | for (i = 0; i < (VF_MAX_STATIC / 32); i++) |
| 1066 | qed_wr(p_hwfn, p_ptt, |
| 1067 | func_addr + |
| 1068 | offsetof(struct public_func, drv_ack_vf_disabled) + |
| 1069 | i * sizeof(u32), 0); |
| 1070 | |
| 1071 | return rc; |
| 1072 | } |
| 1073 | |
Zvi Nachmani | 334c03b | 2016-03-09 09:16:25 +0200 | [diff] [blame] | 1074 | static void qed_mcp_handle_transceiver_change(struct qed_hwfn *p_hwfn, |
| 1075 | struct qed_ptt *p_ptt) |
| 1076 | { |
| 1077 | u32 transceiver_state; |
| 1078 | |
| 1079 | transceiver_state = qed_rd(p_hwfn, p_ptt, |
| 1080 | p_hwfn->mcp_info->port_addr + |
| 1081 | offsetof(struct public_port, |
| 1082 | transceiver_data)); |
| 1083 | |
| 1084 | DP_VERBOSE(p_hwfn, |
| 1085 | (NETIF_MSG_HW | QED_MSG_SP), |
| 1086 | "Received transceiver state update [0x%08x] from mfw [Addr 0x%x]\n", |
| 1087 | transceiver_state, |
| 1088 | (u32)(p_hwfn->mcp_info->port_addr + |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1089 | offsetof(struct public_port, transceiver_data))); |
Zvi Nachmani | 334c03b | 2016-03-09 09:16:25 +0200 | [diff] [blame] | 1090 | |
| 1091 | transceiver_state = GET_FIELD(transceiver_state, |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1092 | ETH_TRANSCEIVER_STATE); |
Zvi Nachmani | 334c03b | 2016-03-09 09:16:25 +0200 | [diff] [blame] | 1093 | |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1094 | if (transceiver_state == ETH_TRANSCEIVER_STATE_PRESENT) |
Zvi Nachmani | 334c03b | 2016-03-09 09:16:25 +0200 | [diff] [blame] | 1095 | DP_NOTICE(p_hwfn, "Transceiver is present.\n"); |
| 1096 | else |
| 1097 | DP_NOTICE(p_hwfn, "Transceiver is unplugged.\n"); |
| 1098 | } |
| 1099 | |
Sudarsana Reddy Kalluru | 645874e | 2017-07-26 06:07:11 -0700 | [diff] [blame] | 1100 | static void qed_mcp_read_eee_config(struct qed_hwfn *p_hwfn, |
| 1101 | struct qed_ptt *p_ptt, |
| 1102 | struct qed_mcp_link_state *p_link) |
| 1103 | { |
| 1104 | u32 eee_status, val; |
| 1105 | |
| 1106 | p_link->eee_adv_caps = 0; |
| 1107 | p_link->eee_lp_adv_caps = 0; |
| 1108 | eee_status = qed_rd(p_hwfn, |
| 1109 | p_ptt, |
| 1110 | p_hwfn->mcp_info->port_addr + |
| 1111 | offsetof(struct public_port, eee_status)); |
| 1112 | p_link->eee_active = !!(eee_status & EEE_ACTIVE_BIT); |
| 1113 | val = (eee_status & EEE_LD_ADV_STATUS_MASK) >> EEE_LD_ADV_STATUS_OFFSET; |
| 1114 | if (val & EEE_1G_ADV) |
| 1115 | p_link->eee_adv_caps |= QED_EEE_1G_ADV; |
| 1116 | if (val & EEE_10G_ADV) |
| 1117 | p_link->eee_adv_caps |= QED_EEE_10G_ADV; |
| 1118 | val = (eee_status & EEE_LP_ADV_STATUS_MASK) >> EEE_LP_ADV_STATUS_OFFSET; |
| 1119 | if (val & EEE_1G_ADV) |
| 1120 | p_link->eee_lp_adv_caps |= QED_EEE_1G_ADV; |
| 1121 | if (val & EEE_10G_ADV) |
| 1122 | p_link->eee_lp_adv_caps |= QED_EEE_10G_ADV; |
| 1123 | } |
| 1124 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1125 | static void qed_mcp_handle_link_change(struct qed_hwfn *p_hwfn, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1126 | struct qed_ptt *p_ptt, bool b_reset) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1127 | { |
| 1128 | struct qed_mcp_link_state *p_link; |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 1129 | u8 max_bw, min_bw; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1130 | u32 status = 0; |
| 1131 | |
Mintz, Yuval | 65ed2ff | 2017-02-20 22:43:39 +0200 | [diff] [blame] | 1132 | /* Prevent SW/attentions from doing this at the same time */ |
| 1133 | spin_lock_bh(&p_hwfn->mcp_info->link_lock); |
| 1134 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1135 | p_link = &p_hwfn->mcp_info->link_output; |
| 1136 | memset(p_link, 0, sizeof(*p_link)); |
| 1137 | if (!b_reset) { |
| 1138 | status = qed_rd(p_hwfn, p_ptt, |
| 1139 | p_hwfn->mcp_info->port_addr + |
| 1140 | offsetof(struct public_port, link_status)); |
| 1141 | DP_VERBOSE(p_hwfn, (NETIF_MSG_LINK | QED_MSG_SP), |
| 1142 | "Received link update [0x%08x] from mfw [Addr 0x%x]\n", |
| 1143 | status, |
| 1144 | (u32)(p_hwfn->mcp_info->port_addr + |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1145 | offsetof(struct public_port, link_status))); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1146 | } else { |
| 1147 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 1148 | "Resetting link indications\n"); |
Mintz, Yuval | 65ed2ff | 2017-02-20 22:43:39 +0200 | [diff] [blame] | 1149 | goto out; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
Sudarsana Reddy Kalluru | fc916ff | 2016-03-09 09:16:23 +0200 | [diff] [blame] | 1152 | if (p_hwfn->b_drv_link_init) |
| 1153 | p_link->link_up = !!(status & LINK_STATUS_LINK_UP); |
| 1154 | else |
| 1155 | p_link->link_up = false; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1156 | |
| 1157 | p_link->full_duplex = true; |
| 1158 | switch ((status & LINK_STATUS_SPEED_AND_DUPLEX_MASK)) { |
| 1159 | case LINK_STATUS_SPEED_AND_DUPLEX_100G: |
| 1160 | p_link->speed = 100000; |
| 1161 | break; |
| 1162 | case LINK_STATUS_SPEED_AND_DUPLEX_50G: |
| 1163 | p_link->speed = 50000; |
| 1164 | break; |
| 1165 | case LINK_STATUS_SPEED_AND_DUPLEX_40G: |
| 1166 | p_link->speed = 40000; |
| 1167 | break; |
| 1168 | case LINK_STATUS_SPEED_AND_DUPLEX_25G: |
| 1169 | p_link->speed = 25000; |
| 1170 | break; |
| 1171 | case LINK_STATUS_SPEED_AND_DUPLEX_20G: |
| 1172 | p_link->speed = 20000; |
| 1173 | break; |
| 1174 | case LINK_STATUS_SPEED_AND_DUPLEX_10G: |
| 1175 | p_link->speed = 10000; |
| 1176 | break; |
| 1177 | case LINK_STATUS_SPEED_AND_DUPLEX_1000THD: |
| 1178 | p_link->full_duplex = false; |
| 1179 | /* Fall-through */ |
| 1180 | case LINK_STATUS_SPEED_AND_DUPLEX_1000TFD: |
| 1181 | p_link->speed = 1000; |
| 1182 | break; |
| 1183 | default: |
| 1184 | p_link->speed = 0; |
| 1185 | } |
| 1186 | |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1187 | if (p_link->link_up && p_link->speed) |
| 1188 | p_link->line_speed = p_link->speed; |
| 1189 | else |
| 1190 | p_link->line_speed = 0; |
| 1191 | |
| 1192 | max_bw = p_hwfn->mcp_info->func_info.bandwidth_max; |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 1193 | min_bw = p_hwfn->mcp_info->func_info.bandwidth_min; |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1194 | |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 1195 | /* Max bandwidth configuration */ |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1196 | __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt, p_link, max_bw); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1197 | |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 1198 | /* Min bandwidth configuration */ |
| 1199 | __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt, p_link, min_bw); |
Mintz, Yuval | 6f437d4 | 2017-02-27 11:06:33 +0200 | [diff] [blame] | 1200 | qed_configure_vp_wfq_on_link_change(p_hwfn->cdev, p_ptt, |
| 1201 | p_link->min_pf_rate); |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 1202 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1203 | p_link->an = !!(status & LINK_STATUS_AUTO_NEGOTIATE_ENABLED); |
| 1204 | p_link->an_complete = !!(status & |
| 1205 | LINK_STATUS_AUTO_NEGOTIATE_COMPLETE); |
| 1206 | p_link->parallel_detection = !!(status & |
| 1207 | LINK_STATUS_PARALLEL_DETECTION_USED); |
| 1208 | p_link->pfc_enabled = !!(status & LINK_STATUS_PFC_ENABLED); |
| 1209 | |
| 1210 | p_link->partner_adv_speed |= |
| 1211 | (status & LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE) ? |
| 1212 | QED_LINK_PARTNER_SPEED_1G_FD : 0; |
| 1213 | p_link->partner_adv_speed |= |
| 1214 | (status & LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE) ? |
| 1215 | QED_LINK_PARTNER_SPEED_1G_HD : 0; |
| 1216 | p_link->partner_adv_speed |= |
| 1217 | (status & LINK_STATUS_LINK_PARTNER_10G_CAPABLE) ? |
| 1218 | QED_LINK_PARTNER_SPEED_10G : 0; |
| 1219 | p_link->partner_adv_speed |= |
| 1220 | (status & LINK_STATUS_LINK_PARTNER_20G_CAPABLE) ? |
| 1221 | QED_LINK_PARTNER_SPEED_20G : 0; |
| 1222 | p_link->partner_adv_speed |= |
Sudarsana Reddy Kalluru | 054c67d | 2016-08-09 03:51:23 -0400 | [diff] [blame] | 1223 | (status & LINK_STATUS_LINK_PARTNER_25G_CAPABLE) ? |
| 1224 | QED_LINK_PARTNER_SPEED_25G : 0; |
| 1225 | p_link->partner_adv_speed |= |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1226 | (status & LINK_STATUS_LINK_PARTNER_40G_CAPABLE) ? |
| 1227 | QED_LINK_PARTNER_SPEED_40G : 0; |
| 1228 | p_link->partner_adv_speed |= |
| 1229 | (status & LINK_STATUS_LINK_PARTNER_50G_CAPABLE) ? |
| 1230 | QED_LINK_PARTNER_SPEED_50G : 0; |
| 1231 | p_link->partner_adv_speed |= |
| 1232 | (status & LINK_STATUS_LINK_PARTNER_100G_CAPABLE) ? |
| 1233 | QED_LINK_PARTNER_SPEED_100G : 0; |
| 1234 | |
| 1235 | p_link->partner_tx_flow_ctrl_en = |
| 1236 | !!(status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED); |
| 1237 | p_link->partner_rx_flow_ctrl_en = |
| 1238 | !!(status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED); |
| 1239 | |
| 1240 | switch (status & LINK_STATUS_LINK_PARTNER_FLOW_CONTROL_MASK) { |
| 1241 | case LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE: |
| 1242 | p_link->partner_adv_pause = QED_LINK_PARTNER_SYMMETRIC_PAUSE; |
| 1243 | break; |
| 1244 | case LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE: |
| 1245 | p_link->partner_adv_pause = QED_LINK_PARTNER_ASYMMETRIC_PAUSE; |
| 1246 | break; |
| 1247 | case LINK_STATUS_LINK_PARTNER_BOTH_PAUSE: |
| 1248 | p_link->partner_adv_pause = QED_LINK_PARTNER_BOTH_PAUSE; |
| 1249 | break; |
| 1250 | default: |
| 1251 | p_link->partner_adv_pause = 0; |
| 1252 | } |
| 1253 | |
| 1254 | p_link->sfp_tx_fault = !!(status & LINK_STATUS_SFP_TX_FAULT); |
| 1255 | |
Sudarsana Reddy Kalluru | 645874e | 2017-07-26 06:07:11 -0700 | [diff] [blame] | 1256 | if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE) |
| 1257 | qed_mcp_read_eee_config(p_hwfn, p_ptt, p_link); |
| 1258 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1259 | qed_link_update(p_hwfn); |
Mintz, Yuval | 65ed2ff | 2017-02-20 22:43:39 +0200 | [diff] [blame] | 1260 | out: |
| 1261 | spin_unlock_bh(&p_hwfn->mcp_info->link_lock); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1262 | } |
| 1263 | |
Yuval Mintz | 351a4ded | 2016-06-02 10:23:29 +0300 | [diff] [blame] | 1264 | int qed_mcp_set_link(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, bool b_up) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1265 | { |
| 1266 | struct qed_mcp_link_params *params = &p_hwfn->mcp_info->link_input; |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1267 | struct qed_mcp_mb_params mb_params; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1268 | struct eth_phy_cfg phy_cfg; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1269 | int rc = 0; |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1270 | u32 cmd; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1271 | |
| 1272 | /* Set the shmem configuration according to params */ |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1273 | memset(&phy_cfg, 0, sizeof(phy_cfg)); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1274 | cmd = b_up ? DRV_MSG_CODE_INIT_PHY : DRV_MSG_CODE_LINK_RESET; |
| 1275 | if (!params->speed.autoneg) |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1276 | phy_cfg.speed = params->speed.forced_speed; |
| 1277 | phy_cfg.pause |= (params->pause.autoneg) ? ETH_PAUSE_AUTONEG : 0; |
| 1278 | phy_cfg.pause |= (params->pause.forced_rx) ? ETH_PAUSE_RX : 0; |
| 1279 | phy_cfg.pause |= (params->pause.forced_tx) ? ETH_PAUSE_TX : 0; |
| 1280 | phy_cfg.adv_speed = params->speed.advertised_speeds; |
| 1281 | phy_cfg.loopback_mode = params->loopback_mode; |
Sudarsana Reddy Kalluru | 645874e | 2017-07-26 06:07:11 -0700 | [diff] [blame] | 1282 | if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE) { |
| 1283 | if (params->eee.enable) |
| 1284 | phy_cfg.eee_cfg |= EEE_CFG_EEE_ENABLED; |
| 1285 | if (params->eee.tx_lpi_enable) |
| 1286 | phy_cfg.eee_cfg |= EEE_CFG_TX_LPI; |
| 1287 | if (params->eee.adv_caps & QED_EEE_1G_ADV) |
| 1288 | phy_cfg.eee_cfg |= EEE_CFG_ADV_SPEED_1G; |
| 1289 | if (params->eee.adv_caps & QED_EEE_10G_ADV) |
| 1290 | phy_cfg.eee_cfg |= EEE_CFG_ADV_SPEED_10G; |
| 1291 | phy_cfg.eee_cfg |= (params->eee.tx_lpi_timer << |
| 1292 | EEE_TX_TIMER_USEC_OFFSET) & |
| 1293 | EEE_TX_TIMER_USEC_MASK; |
| 1294 | } |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1295 | |
Sudarsana Reddy Kalluru | fc916ff | 2016-03-09 09:16:23 +0200 | [diff] [blame] | 1296 | p_hwfn->b_drv_link_init = b_up; |
| 1297 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1298 | if (b_up) { |
| 1299 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 1300 | "Configuring Link: Speed 0x%08x, Pause 0x%08x, adv_speed 0x%08x, loopback 0x%08x, features 0x%08x\n", |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1301 | phy_cfg.speed, |
| 1302 | phy_cfg.pause, |
| 1303 | phy_cfg.adv_speed, |
| 1304 | phy_cfg.loopback_mode, |
| 1305 | phy_cfg.feature_config_flags); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1306 | } else { |
| 1307 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 1308 | "Resetting link\n"); |
| 1309 | } |
| 1310 | |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1311 | memset(&mb_params, 0, sizeof(mb_params)); |
| 1312 | mb_params.cmd = cmd; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1313 | mb_params.p_data_src = &phy_cfg; |
| 1314 | mb_params.data_src_size = sizeof(phy_cfg); |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1315 | rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1316 | |
| 1317 | /* if mcp fails to respond we must abort */ |
| 1318 | if (rc) { |
| 1319 | DP_ERR(p_hwfn, "MCP response failure, aborting\n"); |
| 1320 | return rc; |
| 1321 | } |
| 1322 | |
Mintz, Yuval | 65ed2ff | 2017-02-20 22:43:39 +0200 | [diff] [blame] | 1323 | /* Mimic link-change attention, done for several reasons: |
| 1324 | * - On reset, there's no guarantee MFW would trigger |
| 1325 | * an attention. |
| 1326 | * - On initialization, older MFWs might not indicate link change |
| 1327 | * during LFA, so we'll never get an UP indication. |
| 1328 | */ |
| 1329 | qed_mcp_handle_link_change(p_hwfn, p_ptt, !b_up); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1330 | |
| 1331 | return 0; |
| 1332 | } |
| 1333 | |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 1334 | static void qed_mcp_send_protocol_stats(struct qed_hwfn *p_hwfn, |
| 1335 | struct qed_ptt *p_ptt, |
| 1336 | enum MFW_DRV_MSG_TYPE type) |
| 1337 | { |
| 1338 | enum qed_mcp_protocol_type stats_type; |
| 1339 | union qed_mcp_protocol_stats stats; |
| 1340 | struct qed_mcp_mb_params mb_params; |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 1341 | u32 hsi_param; |
| 1342 | |
| 1343 | switch (type) { |
| 1344 | case MFW_DRV_MSG_GET_LAN_STATS: |
| 1345 | stats_type = QED_MCP_LAN_STATS; |
| 1346 | hsi_param = DRV_MSG_CODE_STATS_TYPE_LAN; |
| 1347 | break; |
| 1348 | case MFW_DRV_MSG_GET_FCOE_STATS: |
| 1349 | stats_type = QED_MCP_FCOE_STATS; |
| 1350 | hsi_param = DRV_MSG_CODE_STATS_TYPE_FCOE; |
| 1351 | break; |
| 1352 | case MFW_DRV_MSG_GET_ISCSI_STATS: |
| 1353 | stats_type = QED_MCP_ISCSI_STATS; |
| 1354 | hsi_param = DRV_MSG_CODE_STATS_TYPE_ISCSI; |
| 1355 | break; |
| 1356 | case MFW_DRV_MSG_GET_RDMA_STATS: |
| 1357 | stats_type = QED_MCP_RDMA_STATS; |
| 1358 | hsi_param = DRV_MSG_CODE_STATS_TYPE_RDMA; |
| 1359 | break; |
| 1360 | default: |
| 1361 | DP_NOTICE(p_hwfn, "Invalid protocol type %d\n", type); |
| 1362 | return; |
| 1363 | } |
| 1364 | |
| 1365 | qed_get_protocol_stats(p_hwfn->cdev, stats_type, &stats); |
| 1366 | |
| 1367 | memset(&mb_params, 0, sizeof(mb_params)); |
| 1368 | mb_params.cmd = DRV_MSG_CODE_GET_STATS; |
| 1369 | mb_params.param = hsi_param; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1370 | mb_params.p_data_src = &stats; |
| 1371 | mb_params.data_src_size = sizeof(stats); |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 1372 | qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
| 1373 | } |
| 1374 | |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1375 | static void qed_read_pf_bandwidth(struct qed_hwfn *p_hwfn, |
| 1376 | struct public_func *p_shmem_info) |
| 1377 | { |
| 1378 | struct qed_mcp_function_info *p_info; |
| 1379 | |
| 1380 | p_info = &p_hwfn->mcp_info->func_info; |
| 1381 | |
| 1382 | p_info->bandwidth_min = (p_shmem_info->config & |
| 1383 | FUNC_MF_CFG_MIN_BW_MASK) >> |
| 1384 | FUNC_MF_CFG_MIN_BW_SHIFT; |
| 1385 | if (p_info->bandwidth_min < 1 || p_info->bandwidth_min > 100) { |
| 1386 | DP_INFO(p_hwfn, |
| 1387 | "bandwidth minimum out of bounds [%02x]. Set to 1\n", |
| 1388 | p_info->bandwidth_min); |
| 1389 | p_info->bandwidth_min = 1; |
| 1390 | } |
| 1391 | |
| 1392 | p_info->bandwidth_max = (p_shmem_info->config & |
| 1393 | FUNC_MF_CFG_MAX_BW_MASK) >> |
| 1394 | FUNC_MF_CFG_MAX_BW_SHIFT; |
| 1395 | if (p_info->bandwidth_max < 1 || p_info->bandwidth_max > 100) { |
| 1396 | DP_INFO(p_hwfn, |
| 1397 | "bandwidth maximum out of bounds [%02x]. Set to 100\n", |
| 1398 | p_info->bandwidth_max); |
| 1399 | p_info->bandwidth_max = 100; |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | static u32 qed_mcp_get_shmem_func(struct qed_hwfn *p_hwfn, |
| 1404 | struct qed_ptt *p_ptt, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1405 | struct public_func *p_data, int pfid) |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1406 | { |
| 1407 | u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base, |
| 1408 | PUBLIC_FUNC); |
| 1409 | u32 mfw_path_offsize = qed_rd(p_hwfn, p_ptt, addr); |
| 1410 | u32 func_addr = SECTION_ADDR(mfw_path_offsize, pfid); |
| 1411 | u32 i, size; |
| 1412 | |
| 1413 | memset(p_data, 0, sizeof(*p_data)); |
| 1414 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1415 | size = min_t(u32, sizeof(*p_data), QED_SECTION_SIZE(mfw_path_offsize)); |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1416 | for (i = 0; i < size / sizeof(u32); i++) |
| 1417 | ((u32 *)p_data)[i] = qed_rd(p_hwfn, p_ptt, |
| 1418 | func_addr + (i << 2)); |
| 1419 | return size; |
| 1420 | } |
| 1421 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1422 | static void qed_mcp_update_bw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1423 | { |
| 1424 | struct qed_mcp_function_info *p_info; |
| 1425 | struct public_func shmem_info; |
| 1426 | u32 resp = 0, param = 0; |
| 1427 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1428 | qed_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn)); |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1429 | |
| 1430 | qed_read_pf_bandwidth(p_hwfn, &shmem_info); |
| 1431 | |
| 1432 | p_info = &p_hwfn->mcp_info->func_info; |
| 1433 | |
Manish Chopra | a64b02d | 2016-04-26 10:56:10 -0400 | [diff] [blame] | 1434 | qed_configure_pf_min_bandwidth(p_hwfn->cdev, p_info->bandwidth_min); |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1435 | qed_configure_pf_max_bandwidth(p_hwfn->cdev, p_info->bandwidth_max); |
| 1436 | |
| 1437 | /* Acknowledge the MFW */ |
| 1438 | qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BW_UPDATE_ACK, 0, &resp, |
| 1439 | ¶m); |
| 1440 | } |
| 1441 | |
Mintz, Yuval | 2a351fd9 | 2017-05-29 09:53:09 +0300 | [diff] [blame] | 1442 | static void qed_mcp_update_stag(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 1443 | { |
| 1444 | struct public_func shmem_info; |
| 1445 | u32 resp = 0, param = 0; |
| 1446 | |
| 1447 | qed_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn)); |
| 1448 | |
| 1449 | p_hwfn->mcp_info->func_info.ovlan = (u16)shmem_info.ovlan_stag & |
| 1450 | FUNC_MF_CFG_OV_STAG_MASK; |
| 1451 | p_hwfn->hw_info.ovlan = p_hwfn->mcp_info->func_info.ovlan; |
| 1452 | if ((p_hwfn->hw_info.hw_mode & BIT(MODE_MF_SD)) && |
| 1453 | (p_hwfn->hw_info.ovlan != QED_MCP_VLAN_UNSET)) { |
| 1454 | qed_wr(p_hwfn, p_ptt, |
| 1455 | NIG_REG_LLH_FUNC_TAG_VALUE, p_hwfn->hw_info.ovlan); |
| 1456 | qed_sp_pf_update_stag(p_hwfn); |
| 1457 | } |
| 1458 | |
| 1459 | /* Acknowledge the MFW */ |
| 1460 | qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_S_TAG_UPDATE_ACK, 0, |
| 1461 | &resp, ¶m); |
| 1462 | } |
| 1463 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1464 | int qed_mcp_handle_events(struct qed_hwfn *p_hwfn, |
| 1465 | struct qed_ptt *p_ptt) |
| 1466 | { |
| 1467 | struct qed_mcp_info *info = p_hwfn->mcp_info; |
| 1468 | int rc = 0; |
| 1469 | bool found = false; |
| 1470 | u16 i; |
| 1471 | |
| 1472 | DP_VERBOSE(p_hwfn, QED_MSG_SP, "Received message from MFW\n"); |
| 1473 | |
| 1474 | /* Read Messages from MFW */ |
| 1475 | qed_mcp_read_mb(p_hwfn, p_ptt); |
| 1476 | |
| 1477 | /* Compare current messages to old ones */ |
| 1478 | for (i = 0; i < info->mfw_mb_length; i++) { |
| 1479 | if (info->mfw_mb_cur[i] == info->mfw_mb_shadow[i]) |
| 1480 | continue; |
| 1481 | |
| 1482 | found = true; |
| 1483 | |
| 1484 | DP_VERBOSE(p_hwfn, NETIF_MSG_LINK, |
| 1485 | "Msg [%d] - old CMD 0x%02x, new CMD 0x%02x\n", |
| 1486 | i, info->mfw_mb_shadow[i], info->mfw_mb_cur[i]); |
| 1487 | |
| 1488 | switch (i) { |
| 1489 | case MFW_DRV_MSG_LINK_CHANGE: |
| 1490 | qed_mcp_handle_link_change(p_hwfn, p_ptt, false); |
| 1491 | break; |
Yuval Mintz | 0b55e27 | 2016-05-11 16:36:15 +0300 | [diff] [blame] | 1492 | case MFW_DRV_MSG_VF_DISABLED: |
| 1493 | qed_mcp_handle_vf_flr(p_hwfn, p_ptt); |
| 1494 | break; |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 1495 | case MFW_DRV_MSG_LLDP_DATA_UPDATED: |
| 1496 | qed_dcbx_mib_update_event(p_hwfn, p_ptt, |
| 1497 | QED_DCBX_REMOTE_LLDP_MIB); |
| 1498 | break; |
| 1499 | case MFW_DRV_MSG_DCBX_REMOTE_MIB_UPDATED: |
| 1500 | qed_dcbx_mib_update_event(p_hwfn, p_ptt, |
| 1501 | QED_DCBX_REMOTE_MIB); |
| 1502 | break; |
| 1503 | case MFW_DRV_MSG_DCBX_OPERATIONAL_MIB_UPDATED: |
| 1504 | qed_dcbx_mib_update_event(p_hwfn, p_ptt, |
| 1505 | QED_DCBX_OPERATIONAL_MIB); |
| 1506 | break; |
Zvi Nachmani | 334c03b | 2016-03-09 09:16:25 +0200 | [diff] [blame] | 1507 | case MFW_DRV_MSG_TRANSCEIVER_STATE_CHANGE: |
| 1508 | qed_mcp_handle_transceiver_change(p_hwfn, p_ptt); |
| 1509 | break; |
Sudarsana Reddy Kalluru | 6c75424 | 2016-08-16 10:51:03 -0400 | [diff] [blame] | 1510 | case MFW_DRV_MSG_GET_LAN_STATS: |
| 1511 | case MFW_DRV_MSG_GET_FCOE_STATS: |
| 1512 | case MFW_DRV_MSG_GET_ISCSI_STATS: |
| 1513 | case MFW_DRV_MSG_GET_RDMA_STATS: |
| 1514 | qed_mcp_send_protocol_stats(p_hwfn, p_ptt, i); |
| 1515 | break; |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1516 | case MFW_DRV_MSG_BW_UPDATE: |
| 1517 | qed_mcp_update_bw(p_hwfn, p_ptt); |
| 1518 | break; |
Mintz, Yuval | 2a351fd9 | 2017-05-29 09:53:09 +0300 | [diff] [blame] | 1519 | case MFW_DRV_MSG_S_TAG_UPDATE: |
| 1520 | qed_mcp_update_stag(p_hwfn, p_ptt); |
| 1521 | break; |
| 1522 | break; |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1523 | default: |
Mintz, Yuval | 3981594 | 2017-03-23 15:50:18 +0200 | [diff] [blame] | 1524 | DP_INFO(p_hwfn, "Unimplemented MFW message %d\n", i); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1525 | rc = -EINVAL; |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | /* ACK everything */ |
| 1530 | for (i = 0; i < MFW_DRV_MSG_MAX_DWORDS(info->mfw_mb_length); i++) { |
| 1531 | __be32 val = cpu_to_be32(((u32 *)info->mfw_mb_cur)[i]); |
| 1532 | |
| 1533 | /* MFW expect answer in BE, so we force write in that format */ |
| 1534 | qed_wr(p_hwfn, p_ptt, |
| 1535 | info->mfw_mb_addr + sizeof(u32) + |
| 1536 | MFW_DRV_MSG_MAX_DWORDS(info->mfw_mb_length) * |
| 1537 | sizeof(u32) + i * sizeof(u32), |
| 1538 | (__force u32)val); |
| 1539 | } |
| 1540 | |
| 1541 | if (!found) { |
| 1542 | DP_NOTICE(p_hwfn, |
| 1543 | "Received an MFW message indication but no new message!\n"); |
| 1544 | rc = -EINVAL; |
| 1545 | } |
| 1546 | |
| 1547 | /* Copy the new mfw messages into the shadow */ |
| 1548 | memcpy(info->mfw_mb_shadow, info->mfw_mb_cur, info->mfw_mb_length); |
| 1549 | |
| 1550 | return rc; |
| 1551 | } |
| 1552 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1553 | int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn, |
| 1554 | struct qed_ptt *p_ptt, |
| 1555 | u32 *p_mfw_ver, u32 *p_running_bundle_id) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1556 | { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1557 | u32 global_offsize; |
| 1558 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1559 | if (IS_VF(p_hwfn->cdev)) { |
| 1560 | if (p_hwfn->vf_iov_info) { |
| 1561 | struct pfvf_acquire_resp_tlv *p_resp; |
| 1562 | |
| 1563 | p_resp = &p_hwfn->vf_iov_info->acquire_resp; |
| 1564 | *p_mfw_ver = p_resp->pfdev_info.mfw_ver; |
| 1565 | return 0; |
| 1566 | } else { |
| 1567 | DP_VERBOSE(p_hwfn, |
| 1568 | QED_MSG_IOV, |
| 1569 | "VF requested MFW version prior to ACQUIRE\n"); |
| 1570 | return -EINVAL; |
| 1571 | } |
| 1572 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1573 | |
| 1574 | global_offsize = qed_rd(p_hwfn, p_ptt, |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1575 | SECTION_OFFSIZE_ADDR(p_hwfn-> |
| 1576 | mcp_info->public_base, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1577 | PUBLIC_GLOBAL)); |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1578 | *p_mfw_ver = |
| 1579 | qed_rd(p_hwfn, p_ptt, |
| 1580 | SECTION_ADDR(global_offsize, |
| 1581 | 0) + offsetof(struct public_global, mfw_ver)); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1582 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1583 | if (p_running_bundle_id != NULL) { |
| 1584 | *p_running_bundle_id = qed_rd(p_hwfn, p_ptt, |
| 1585 | SECTION_ADDR(global_offsize, 0) + |
| 1586 | offsetof(struct public_global, |
| 1587 | running_bundle_id)); |
| 1588 | } |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1589 | |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
Tomer Tayar | ae33666 | 2017-05-23 09:41:26 +0300 | [diff] [blame] | 1593 | int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn, |
| 1594 | struct qed_ptt *p_ptt, u32 *p_mbi_ver) |
| 1595 | { |
| 1596 | u32 nvm_cfg_addr, nvm_cfg1_offset, mbi_ver_addr; |
| 1597 | |
| 1598 | if (IS_VF(p_hwfn->cdev)) |
| 1599 | return -EINVAL; |
| 1600 | |
| 1601 | /* Read the address of the nvm_cfg */ |
| 1602 | nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0); |
| 1603 | if (!nvm_cfg_addr) { |
| 1604 | DP_NOTICE(p_hwfn, "Shared memory not initialized\n"); |
| 1605 | return -EINVAL; |
| 1606 | } |
| 1607 | |
| 1608 | /* Read the offset of nvm_cfg1 */ |
| 1609 | nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4); |
| 1610 | |
| 1611 | mbi_ver_addr = MCP_REG_SCRATCH + nvm_cfg1_offset + |
| 1612 | offsetof(struct nvm_cfg1, glob) + |
| 1613 | offsetof(struct nvm_cfg1_glob, mbi_version); |
| 1614 | *p_mbi_ver = qed_rd(p_hwfn, p_ptt, |
| 1615 | mbi_ver_addr) & |
| 1616 | (NVM_CFG1_GLOB_MBI_VERSION_0_MASK | |
| 1617 | NVM_CFG1_GLOB_MBI_VERSION_1_MASK | |
| 1618 | NVM_CFG1_GLOB_MBI_VERSION_2_MASK); |
| 1619 | |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1623 | int qed_mcp_get_media_type(struct qed_dev *cdev, u32 *p_media_type) |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1624 | { |
| 1625 | struct qed_hwfn *p_hwfn = &cdev->hwfns[0]; |
| 1626 | struct qed_ptt *p_ptt; |
| 1627 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1628 | if (IS_VF(cdev)) |
| 1629 | return -EINVAL; |
| 1630 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1631 | if (!qed_mcp_is_init(p_hwfn)) { |
Yuval Mintz | 525ef5c | 2016-08-15 10:42:45 +0300 | [diff] [blame] | 1632 | DP_NOTICE(p_hwfn, "MFW is not initialized!\n"); |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1633 | return -EBUSY; |
| 1634 | } |
| 1635 | |
| 1636 | *p_media_type = MEDIA_UNSPECIFIED; |
| 1637 | |
| 1638 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 1639 | if (!p_ptt) |
| 1640 | return -EBUSY; |
| 1641 | |
| 1642 | *p_media_type = qed_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr + |
| 1643 | offsetof(struct public_port, media_type)); |
| 1644 | |
| 1645 | qed_ptt_release(p_hwfn, p_ptt); |
| 1646 | |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
Mintz, Yuval | 6927e82 | 2016-10-31 07:14:25 +0200 | [diff] [blame] | 1650 | /* Old MFW has a global configuration for all PFs regarding RDMA support */ |
| 1651 | static void |
| 1652 | qed_mcp_get_shmem_proto_legacy(struct qed_hwfn *p_hwfn, |
| 1653 | enum qed_pci_personality *p_proto) |
| 1654 | { |
| 1655 | /* There wasn't ever a legacy MFW that published iwarp. |
| 1656 | * So at this point, this is either plain l2 or RoCE. |
| 1657 | */ |
| 1658 | if (test_bit(QED_DEV_CAP_ROCE, &p_hwfn->hw_info.device_capabilities)) |
| 1659 | *p_proto = QED_PCI_ETH_ROCE; |
| 1660 | else |
| 1661 | *p_proto = QED_PCI_ETH; |
| 1662 | |
| 1663 | DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP, |
| 1664 | "According to Legacy capabilities, L2 personality is %08x\n", |
| 1665 | (u32) *p_proto); |
| 1666 | } |
| 1667 | |
| 1668 | static int |
| 1669 | qed_mcp_get_shmem_proto_mfw(struct qed_hwfn *p_hwfn, |
| 1670 | struct qed_ptt *p_ptt, |
| 1671 | enum qed_pci_personality *p_proto) |
| 1672 | { |
| 1673 | u32 resp = 0, param = 0; |
| 1674 | int rc; |
| 1675 | |
| 1676 | rc = qed_mcp_cmd(p_hwfn, p_ptt, |
| 1677 | DRV_MSG_CODE_GET_PF_RDMA_PROTOCOL, 0, &resp, ¶m); |
| 1678 | if (rc) |
| 1679 | return rc; |
| 1680 | if (resp != FW_MSG_CODE_OK) { |
| 1681 | DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP, |
| 1682 | "MFW lacks support for command; Returns %08x\n", |
| 1683 | resp); |
| 1684 | return -EINVAL; |
| 1685 | } |
| 1686 | |
| 1687 | switch (param) { |
| 1688 | case FW_MB_PARAM_GET_PF_RDMA_NONE: |
| 1689 | *p_proto = QED_PCI_ETH; |
| 1690 | break; |
| 1691 | case FW_MB_PARAM_GET_PF_RDMA_ROCE: |
| 1692 | *p_proto = QED_PCI_ETH_ROCE; |
| 1693 | break; |
Mintz, Yuval | 6927e82 | 2016-10-31 07:14:25 +0200 | [diff] [blame] | 1694 | case FW_MB_PARAM_GET_PF_RDMA_IWARP: |
Michal Kalderon | e0a8f9d | 2017-09-24 12:09:42 +0300 | [diff] [blame] | 1695 | *p_proto = QED_PCI_ETH_IWARP; |
| 1696 | break; |
| 1697 | case FW_MB_PARAM_GET_PF_RDMA_BOTH: |
| 1698 | *p_proto = QED_PCI_ETH_RDMA; |
| 1699 | break; |
Mintz, Yuval | 6927e82 | 2016-10-31 07:14:25 +0200 | [diff] [blame] | 1700 | default: |
| 1701 | DP_NOTICE(p_hwfn, |
| 1702 | "MFW answers GET_PF_RDMA_PROTOCOL but param is %08x\n", |
| 1703 | param); |
| 1704 | return -EINVAL; |
| 1705 | } |
| 1706 | |
| 1707 | DP_VERBOSE(p_hwfn, |
| 1708 | NETIF_MSG_IFUP, |
| 1709 | "According to capabilities, L2 personality is %08x [resp %08x param %08x]\n", |
| 1710 | (u32) *p_proto, resp, param); |
| 1711 | return 0; |
| 1712 | } |
| 1713 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1714 | static int |
| 1715 | qed_mcp_get_shmem_proto(struct qed_hwfn *p_hwfn, |
| 1716 | struct public_func *p_info, |
Mintz, Yuval | 6927e82 | 2016-10-31 07:14:25 +0200 | [diff] [blame] | 1717 | struct qed_ptt *p_ptt, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1718 | enum qed_pci_personality *p_proto) |
| 1719 | { |
| 1720 | int rc = 0; |
| 1721 | |
| 1722 | switch (p_info->config & FUNC_MF_CFG_PROTOCOL_MASK) { |
| 1723 | case FUNC_MF_CFG_PROTOCOL_ETHERNET: |
Ram Amrani | 1fe582e | 2017-01-01 13:57:10 +0200 | [diff] [blame] | 1724 | if (!IS_ENABLED(CONFIG_QED_RDMA)) |
| 1725 | *p_proto = QED_PCI_ETH; |
| 1726 | else if (qed_mcp_get_shmem_proto_mfw(p_hwfn, p_ptt, p_proto)) |
Mintz, Yuval | 6927e82 | 2016-10-31 07:14:25 +0200 | [diff] [blame] | 1727 | qed_mcp_get_shmem_proto_legacy(p_hwfn, p_proto); |
Yuval Mintz | c5ac931 | 2016-06-03 14:35:34 +0300 | [diff] [blame] | 1728 | break; |
| 1729 | case FUNC_MF_CFG_PROTOCOL_ISCSI: |
| 1730 | *p_proto = QED_PCI_ISCSI; |
| 1731 | break; |
Arun Easi | 1e128c8 | 2017-02-15 06:28:22 -0800 | [diff] [blame] | 1732 | case FUNC_MF_CFG_PROTOCOL_FCOE: |
| 1733 | *p_proto = QED_PCI_FCOE; |
| 1734 | break; |
Yuval Mintz | c5ac931 | 2016-06-03 14:35:34 +0300 | [diff] [blame] | 1735 | case FUNC_MF_CFG_PROTOCOL_ROCE: |
| 1736 | DP_NOTICE(p_hwfn, "RoCE personality is not a valid value!\n"); |
Mintz, Yuval | 6927e82 | 2016-10-31 07:14:25 +0200 | [diff] [blame] | 1737 | /* Fallthrough */ |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1738 | default: |
| 1739 | rc = -EINVAL; |
| 1740 | } |
| 1741 | |
| 1742 | return rc; |
| 1743 | } |
| 1744 | |
| 1745 | int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn, |
| 1746 | struct qed_ptt *p_ptt) |
| 1747 | { |
| 1748 | struct qed_mcp_function_info *info; |
| 1749 | struct public_func shmem_info; |
| 1750 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1751 | qed_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn)); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1752 | info = &p_hwfn->mcp_info->func_info; |
| 1753 | |
| 1754 | info->pause_on_host = (shmem_info.config & |
| 1755 | FUNC_MF_CFG_PAUSE_ON_HOST_RING) ? 1 : 0; |
| 1756 | |
Mintz, Yuval | 6927e82 | 2016-10-31 07:14:25 +0200 | [diff] [blame] | 1757 | if (qed_mcp_get_shmem_proto(p_hwfn, &shmem_info, p_ptt, |
| 1758 | &info->protocol)) { |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1759 | DP_ERR(p_hwfn, "Unknown personality %08x\n", |
| 1760 | (u32)(shmem_info.config & FUNC_MF_CFG_PROTOCOL_MASK)); |
| 1761 | return -EINVAL; |
| 1762 | } |
| 1763 | |
Manish Chopra | 4b01e51 | 2016-04-26 10:56:09 -0400 | [diff] [blame] | 1764 | qed_read_pf_bandwidth(p_hwfn, &shmem_info); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1765 | |
| 1766 | if (shmem_info.mac_upper || shmem_info.mac_lower) { |
| 1767 | info->mac[0] = (u8)(shmem_info.mac_upper >> 8); |
| 1768 | info->mac[1] = (u8)(shmem_info.mac_upper); |
| 1769 | info->mac[2] = (u8)(shmem_info.mac_lower >> 24); |
| 1770 | info->mac[3] = (u8)(shmem_info.mac_lower >> 16); |
| 1771 | info->mac[4] = (u8)(shmem_info.mac_lower >> 8); |
| 1772 | info->mac[5] = (u8)(shmem_info.mac_lower); |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1773 | |
| 1774 | /* Store primary MAC for later possible WoL */ |
| 1775 | memcpy(&p_hwfn->cdev->wol_mac, info->mac, ETH_ALEN); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1776 | } else { |
| 1777 | DP_NOTICE(p_hwfn, "MAC is 0 in shmem\n"); |
| 1778 | } |
| 1779 | |
Mintz, Yuval | 5779675 | 2017-06-02 08:58:30 +0300 | [diff] [blame] | 1780 | info->wwn_port = (u64)shmem_info.fcoe_wwn_port_name_lower | |
| 1781 | (((u64)shmem_info.fcoe_wwn_port_name_upper) << 32); |
| 1782 | info->wwn_node = (u64)shmem_info.fcoe_wwn_node_name_lower | |
| 1783 | (((u64)shmem_info.fcoe_wwn_node_name_upper) << 32); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1784 | |
| 1785 | info->ovlan = (u16)(shmem_info.ovlan_stag & FUNC_MF_CFG_OV_STAG_MASK); |
| 1786 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1787 | info->mtu = (u16)shmem_info.mtu_size; |
| 1788 | |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1789 | p_hwfn->hw_info.b_wol_support = QED_WOL_SUPPORT_NONE; |
| 1790 | p_hwfn->cdev->wol_config = (u8)QED_OV_WOL_DEFAULT; |
| 1791 | if (qed_mcp_is_init(p_hwfn)) { |
| 1792 | u32 resp = 0, param = 0; |
| 1793 | int rc; |
| 1794 | |
| 1795 | rc = qed_mcp_cmd(p_hwfn, p_ptt, |
| 1796 | DRV_MSG_CODE_OS_WOL, 0, &resp, ¶m); |
| 1797 | if (rc) |
| 1798 | return rc; |
| 1799 | if (resp == FW_MSG_CODE_OS_WOL_SUPPORTED) |
| 1800 | p_hwfn->hw_info.b_wol_support = QED_WOL_SUPPORT_PME; |
| 1801 | } |
| 1802 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1803 | DP_VERBOSE(p_hwfn, (QED_MSG_SP | NETIF_MSG_IFUP), |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1804 | "Read configuration from shmem: pause_on_host %02x protocol %02x BW [%02x - %02x] MAC %02x:%02x:%02x:%02x:%02x:%02x wwn port %llx node %llx ovlan %04x wol %02x\n", |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1805 | info->pause_on_host, info->protocol, |
| 1806 | info->bandwidth_min, info->bandwidth_max, |
| 1807 | info->mac[0], info->mac[1], info->mac[2], |
| 1808 | info->mac[3], info->mac[4], info->mac[5], |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 1809 | info->wwn_port, info->wwn_node, |
| 1810 | info->ovlan, (u8)p_hwfn->hw_info.b_wol_support); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1811 | |
| 1812 | return 0; |
| 1813 | } |
| 1814 | |
Yuval Mintz | cc875c2 | 2015-10-26 11:02:31 +0200 | [diff] [blame] | 1815 | struct qed_mcp_link_params |
| 1816 | *qed_mcp_get_link_params(struct qed_hwfn *p_hwfn) |
| 1817 | { |
| 1818 | if (!p_hwfn || !p_hwfn->mcp_info) |
| 1819 | return NULL; |
| 1820 | return &p_hwfn->mcp_info->link_input; |
| 1821 | } |
| 1822 | |
| 1823 | struct qed_mcp_link_state |
| 1824 | *qed_mcp_get_link_state(struct qed_hwfn *p_hwfn) |
| 1825 | { |
| 1826 | if (!p_hwfn || !p_hwfn->mcp_info) |
| 1827 | return NULL; |
| 1828 | return &p_hwfn->mcp_info->link_output; |
| 1829 | } |
| 1830 | |
| 1831 | struct qed_mcp_link_capabilities |
| 1832 | *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn) |
| 1833 | { |
| 1834 | if (!p_hwfn || !p_hwfn->mcp_info) |
| 1835 | return NULL; |
| 1836 | return &p_hwfn->mcp_info->link_capabilities; |
| 1837 | } |
| 1838 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1839 | int qed_mcp_drain(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1840 | { |
| 1841 | u32 resp = 0, param = 0; |
| 1842 | int rc; |
| 1843 | |
| 1844 | rc = qed_mcp_cmd(p_hwfn, p_ptt, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1845 | DRV_MSG_CODE_NIG_DRAIN, 1000, &resp, ¶m); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1846 | |
| 1847 | /* Wait for the drain to complete before returning */ |
Yuval Mintz | 8f60baf | 2016-03-09 09:16:26 +0200 | [diff] [blame] | 1848 | msleep(1020); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1849 | |
| 1850 | return rc; |
| 1851 | } |
| 1852 | |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1853 | int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn, |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 1854 | struct qed_ptt *p_ptt, u32 *p_flash_size) |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1855 | { |
| 1856 | u32 flash_size; |
| 1857 | |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1858 | if (IS_VF(p_hwfn->cdev)) |
| 1859 | return -EINVAL; |
| 1860 | |
Manish Chopra | cee4d26 | 2015-10-26 11:02:28 +0200 | [diff] [blame] | 1861 | flash_size = qed_rd(p_hwfn, p_ptt, MCP_REG_NVM_CFG4); |
| 1862 | flash_size = (flash_size & MCP_REG_NVM_CFG4_FLASH_SIZE) >> |
| 1863 | MCP_REG_NVM_CFG4_FLASH_SIZE_SHIFT; |
| 1864 | flash_size = (1 << (flash_size + MCP_BYTES_PER_MBIT_SHIFT)); |
| 1865 | |
| 1866 | *p_flash_size = flash_size; |
| 1867 | |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
Mintz, Yuval | 88072fd | 2017-05-29 09:53:08 +0300 | [diff] [blame] | 1871 | static int |
| 1872 | qed_mcp_config_vf_msix_bb(struct qed_hwfn *p_hwfn, |
| 1873 | struct qed_ptt *p_ptt, u8 vf_id, u8 num) |
Yuval Mintz | 1408cc1f | 2016-05-11 16:36:14 +0300 | [diff] [blame] | 1874 | { |
| 1875 | u32 resp = 0, param = 0, rc_param = 0; |
| 1876 | int rc; |
| 1877 | |
| 1878 | /* Only Leader can configure MSIX, and need to take CMT into account */ |
| 1879 | if (!IS_LEAD_HWFN(p_hwfn)) |
| 1880 | return 0; |
| 1881 | num *= p_hwfn->cdev->num_hwfns; |
| 1882 | |
| 1883 | param |= (vf_id << DRV_MB_PARAM_CFG_VF_MSIX_VF_ID_SHIFT) & |
| 1884 | DRV_MB_PARAM_CFG_VF_MSIX_VF_ID_MASK; |
| 1885 | param |= (num << DRV_MB_PARAM_CFG_VF_MSIX_SB_NUM_SHIFT) & |
| 1886 | DRV_MB_PARAM_CFG_VF_MSIX_SB_NUM_MASK; |
| 1887 | |
| 1888 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CFG_VF_MSIX, param, |
| 1889 | &resp, &rc_param); |
| 1890 | |
| 1891 | if (resp != FW_MSG_CODE_DRV_CFG_VF_MSIX_DONE) { |
| 1892 | DP_NOTICE(p_hwfn, "VF[%d]: MFW failed to set MSI-X\n", vf_id); |
| 1893 | rc = -EINVAL; |
| 1894 | } else { |
| 1895 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 1896 | "Requested 0x%02x MSI-x interrupts from VF 0x%02x\n", |
| 1897 | num, vf_id); |
| 1898 | } |
| 1899 | |
| 1900 | return rc; |
| 1901 | } |
| 1902 | |
Mintz, Yuval | 88072fd | 2017-05-29 09:53:08 +0300 | [diff] [blame] | 1903 | static int |
| 1904 | qed_mcp_config_vf_msix_ah(struct qed_hwfn *p_hwfn, |
| 1905 | struct qed_ptt *p_ptt, u8 num) |
| 1906 | { |
| 1907 | u32 resp = 0, param = num, rc_param = 0; |
| 1908 | int rc; |
| 1909 | |
| 1910 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CFG_PF_VFS_MSIX, |
| 1911 | param, &resp, &rc_param); |
| 1912 | |
| 1913 | if (resp != FW_MSG_CODE_DRV_CFG_PF_VFS_MSIX_DONE) { |
| 1914 | DP_NOTICE(p_hwfn, "MFW failed to set MSI-X for VFs\n"); |
| 1915 | rc = -EINVAL; |
| 1916 | } else { |
| 1917 | DP_VERBOSE(p_hwfn, QED_MSG_IOV, |
| 1918 | "Requested 0x%02x MSI-x interrupts for VFs\n", num); |
| 1919 | } |
| 1920 | |
| 1921 | return rc; |
| 1922 | } |
| 1923 | |
| 1924 | int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn, |
| 1925 | struct qed_ptt *p_ptt, u8 vf_id, u8 num) |
| 1926 | { |
| 1927 | if (QED_IS_BB(p_hwfn->cdev)) |
| 1928 | return qed_mcp_config_vf_msix_bb(p_hwfn, p_ptt, vf_id, num); |
| 1929 | else |
| 1930 | return qed_mcp_config_vf_msix_ah(p_hwfn, p_ptt, num); |
| 1931 | } |
| 1932 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1933 | int |
| 1934 | qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn, |
| 1935 | struct qed_ptt *p_ptt, |
| 1936 | struct qed_mcp_drv_version *p_ver) |
| 1937 | { |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1938 | struct qed_mcp_mb_params mb_params; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1939 | struct drv_version_stc drv_version; |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1940 | __be32 val; |
| 1941 | u32 i; |
| 1942 | int rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1943 | |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1944 | memset(&drv_version, 0, sizeof(drv_version)); |
| 1945 | drv_version.version = p_ver->version; |
Yuval Mintz | 67a99b7 | 2016-09-19 17:47:41 +0300 | [diff] [blame] | 1946 | for (i = 0; i < (MCP_DRV_VER_STR_SIZE - 4) / sizeof(u32); i++) { |
| 1947 | val = cpu_to_be32(*((u32 *)&p_ver->name[i * sizeof(u32)])); |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1948 | *(__be32 *)&drv_version.name[i * sizeof(u32)] = val; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1949 | } |
| 1950 | |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1951 | memset(&mb_params, 0, sizeof(mb_params)); |
| 1952 | mb_params.cmd = DRV_MSG_CODE_SET_VERSION; |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 1953 | mb_params.p_data_src = &drv_version; |
| 1954 | mb_params.data_src_size = sizeof(drv_version); |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1955 | rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
| 1956 | if (rc) |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1957 | DP_ERR(p_hwfn, "MCP response failure, aborting\n"); |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1958 | |
Tomer Tayar | 5529bad | 2016-03-09 09:16:24 +0200 | [diff] [blame] | 1959 | return rc; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1960 | } |
Sudarsana Kalluru | 91420b8 | 2015-11-30 12:25:03 +0200 | [diff] [blame] | 1961 | |
Tomer Tayar | 4102426 | 2016-09-05 14:35:10 +0300 | [diff] [blame] | 1962 | int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 1963 | { |
| 1964 | u32 resp = 0, param = 0; |
| 1965 | int rc; |
| 1966 | |
| 1967 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MCP_HALT, 0, &resp, |
| 1968 | ¶m); |
| 1969 | if (rc) |
| 1970 | DP_ERR(p_hwfn, "MCP response failure, aborting\n"); |
| 1971 | |
| 1972 | return rc; |
| 1973 | } |
| 1974 | |
| 1975 | int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 1976 | { |
| 1977 | u32 value, cpu_mode; |
| 1978 | |
| 1979 | qed_wr(p_hwfn, p_ptt, MCP_REG_CPU_STATE, 0xffffffff); |
| 1980 | |
| 1981 | value = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE); |
| 1982 | value &= ~MCP_REG_CPU_MODE_SOFT_HALT; |
| 1983 | qed_wr(p_hwfn, p_ptt, MCP_REG_CPU_MODE, value); |
| 1984 | cpu_mode = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE); |
| 1985 | |
| 1986 | return (cpu_mode & MCP_REG_CPU_MODE_SOFT_HALT) ? -EAGAIN : 0; |
| 1987 | } |
| 1988 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 1989 | int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn, |
| 1990 | struct qed_ptt *p_ptt, |
| 1991 | enum qed_ov_client client) |
| 1992 | { |
| 1993 | u32 resp = 0, param = 0; |
| 1994 | u32 drv_mb_param; |
| 1995 | int rc; |
| 1996 | |
| 1997 | switch (client) { |
| 1998 | case QED_OV_CLIENT_DRV: |
| 1999 | drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_OS; |
| 2000 | break; |
| 2001 | case QED_OV_CLIENT_USER: |
| 2002 | drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_OTHER; |
| 2003 | break; |
| 2004 | case QED_OV_CLIENT_VENDOR_SPEC: |
| 2005 | drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_VENDOR_SPEC; |
| 2006 | break; |
| 2007 | default: |
| 2008 | DP_NOTICE(p_hwfn, "Invalid client type %d\n", client); |
| 2009 | return -EINVAL; |
| 2010 | } |
| 2011 | |
| 2012 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_CURR_CFG, |
| 2013 | drv_mb_param, &resp, ¶m); |
| 2014 | if (rc) |
| 2015 | DP_ERR(p_hwfn, "MCP response failure, aborting\n"); |
| 2016 | |
| 2017 | return rc; |
| 2018 | } |
| 2019 | |
| 2020 | int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn, |
| 2021 | struct qed_ptt *p_ptt, |
| 2022 | enum qed_ov_driver_state drv_state) |
| 2023 | { |
| 2024 | u32 resp = 0, param = 0; |
| 2025 | u32 drv_mb_param; |
| 2026 | int rc; |
| 2027 | |
| 2028 | switch (drv_state) { |
| 2029 | case QED_OV_DRIVER_STATE_NOT_LOADED: |
| 2030 | drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_NOT_LOADED; |
| 2031 | break; |
| 2032 | case QED_OV_DRIVER_STATE_DISABLED: |
| 2033 | drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_DISABLED; |
| 2034 | break; |
| 2035 | case QED_OV_DRIVER_STATE_ACTIVE: |
| 2036 | drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_ACTIVE; |
| 2037 | break; |
| 2038 | default: |
| 2039 | DP_NOTICE(p_hwfn, "Invalid driver state %d\n", drv_state); |
| 2040 | return -EINVAL; |
| 2041 | } |
| 2042 | |
| 2043 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE, |
| 2044 | drv_mb_param, &resp, ¶m); |
| 2045 | if (rc) |
| 2046 | DP_ERR(p_hwfn, "Failed to send driver state\n"); |
| 2047 | |
| 2048 | return rc; |
| 2049 | } |
| 2050 | |
| 2051 | int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn, |
| 2052 | struct qed_ptt *p_ptt, u16 mtu) |
| 2053 | { |
| 2054 | u32 resp = 0, param = 0; |
| 2055 | u32 drv_mb_param; |
| 2056 | int rc; |
| 2057 | |
| 2058 | drv_mb_param = (u32)mtu << DRV_MB_PARAM_OV_MTU_SIZE_SHIFT; |
| 2059 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_MTU, |
| 2060 | drv_mb_param, &resp, ¶m); |
| 2061 | if (rc) |
| 2062 | DP_ERR(p_hwfn, "Failed to send mtu value, rc = %d\n", rc); |
| 2063 | |
| 2064 | return rc; |
| 2065 | } |
| 2066 | |
| 2067 | int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn, |
| 2068 | struct qed_ptt *p_ptt, u8 *mac) |
| 2069 | { |
| 2070 | struct qed_mcp_mb_params mb_params; |
Mintz, Yuval | 1799100 | 2017-03-23 15:50:17 +0200 | [diff] [blame] | 2071 | u32 mfw_mac[2]; |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2072 | int rc; |
| 2073 | |
| 2074 | memset(&mb_params, 0, sizeof(mb_params)); |
| 2075 | mb_params.cmd = DRV_MSG_CODE_SET_VMAC; |
| 2076 | mb_params.param = DRV_MSG_CODE_VMAC_TYPE_MAC << |
| 2077 | DRV_MSG_CODE_VMAC_TYPE_SHIFT; |
| 2078 | mb_params.param |= MCP_PF_ID(p_hwfn); |
Tomer Tayar | 2f67af8c | 2017-03-23 15:50:16 +0200 | [diff] [blame] | 2079 | |
Mintz, Yuval | 1799100 | 2017-03-23 15:50:17 +0200 | [diff] [blame] | 2080 | /* MCP is BE, and on LE platforms PCI would swap access to SHMEM |
| 2081 | * in 32-bit granularity. |
| 2082 | * So the MAC has to be set in native order [and not byte order], |
| 2083 | * otherwise it would be read incorrectly by MFW after swap. |
| 2084 | */ |
| 2085 | mfw_mac[0] = mac[0] << 24 | mac[1] << 16 | mac[2] << 8 | mac[3]; |
| 2086 | mfw_mac[1] = mac[4] << 24 | mac[5] << 16; |
| 2087 | |
| 2088 | mb_params.p_data_src = (u8 *)mfw_mac; |
| 2089 | mb_params.data_src_size = 8; |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2090 | rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
| 2091 | if (rc) |
| 2092 | DP_ERR(p_hwfn, "Failed to send mac address, rc = %d\n", rc); |
| 2093 | |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 2094 | /* Store primary MAC for later possible WoL */ |
| 2095 | memcpy(p_hwfn->cdev->wol_mac, mac, ETH_ALEN); |
| 2096 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2097 | return rc; |
| 2098 | } |
| 2099 | |
| 2100 | int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn, |
| 2101 | struct qed_ptt *p_ptt, enum qed_ov_wol wol) |
| 2102 | { |
| 2103 | u32 resp = 0, param = 0; |
| 2104 | u32 drv_mb_param; |
| 2105 | int rc; |
| 2106 | |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 2107 | if (p_hwfn->hw_info.b_wol_support == QED_WOL_SUPPORT_NONE) { |
| 2108 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 2109 | "Can't change WoL configuration when WoL isn't supported\n"); |
| 2110 | return -EINVAL; |
| 2111 | } |
| 2112 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2113 | switch (wol) { |
| 2114 | case QED_OV_WOL_DEFAULT: |
| 2115 | drv_mb_param = DRV_MB_PARAM_WOL_DEFAULT; |
| 2116 | break; |
| 2117 | case QED_OV_WOL_DISABLED: |
| 2118 | drv_mb_param = DRV_MB_PARAM_WOL_DISABLED; |
| 2119 | break; |
| 2120 | case QED_OV_WOL_ENABLED: |
| 2121 | drv_mb_param = DRV_MB_PARAM_WOL_ENABLED; |
| 2122 | break; |
| 2123 | default: |
| 2124 | DP_ERR(p_hwfn, "Invalid wol state %d\n", wol); |
| 2125 | return -EINVAL; |
| 2126 | } |
| 2127 | |
| 2128 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_WOL, |
| 2129 | drv_mb_param, &resp, ¶m); |
| 2130 | if (rc) |
| 2131 | DP_ERR(p_hwfn, "Failed to send wol mode, rc = %d\n", rc); |
| 2132 | |
Mintz, Yuval | 14d3964 | 2016-10-31 07:14:23 +0200 | [diff] [blame] | 2133 | /* Store the WoL update for a future unload */ |
| 2134 | p_hwfn->cdev->wol_config = (u8)wol; |
| 2135 | |
Sudarsana Kalluru | 0fefbfb | 2016-10-31 07:14:21 +0200 | [diff] [blame] | 2136 | return rc; |
| 2137 | } |
| 2138 | |
| 2139 | int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn, |
| 2140 | struct qed_ptt *p_ptt, |
| 2141 | enum qed_ov_eswitch eswitch) |
| 2142 | { |
| 2143 | u32 resp = 0, param = 0; |
| 2144 | u32 drv_mb_param; |
| 2145 | int rc; |
| 2146 | |
| 2147 | switch (eswitch) { |
| 2148 | case QED_OV_ESWITCH_NONE: |
| 2149 | drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_NONE; |
| 2150 | break; |
| 2151 | case QED_OV_ESWITCH_VEB: |
| 2152 | drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_VEB; |
| 2153 | break; |
| 2154 | case QED_OV_ESWITCH_VEPA: |
| 2155 | drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_VEPA; |
| 2156 | break; |
| 2157 | default: |
| 2158 | DP_ERR(p_hwfn, "Invalid eswitch mode %d\n", eswitch); |
| 2159 | return -EINVAL; |
| 2160 | } |
| 2161 | |
| 2162 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_ESWITCH_MODE, |
| 2163 | drv_mb_param, &resp, ¶m); |
| 2164 | if (rc) |
| 2165 | DP_ERR(p_hwfn, "Failed to send eswitch mode, rc = %d\n", rc); |
| 2166 | |
| 2167 | return rc; |
| 2168 | } |
| 2169 | |
Yuval Mintz | 1a635e4 | 2016-08-15 10:42:43 +0300 | [diff] [blame] | 2170 | int qed_mcp_set_led(struct qed_hwfn *p_hwfn, |
| 2171 | struct qed_ptt *p_ptt, enum qed_led_mode mode) |
Sudarsana Kalluru | 91420b8 | 2015-11-30 12:25:03 +0200 | [diff] [blame] | 2172 | { |
| 2173 | u32 resp = 0, param = 0, drv_mb_param; |
| 2174 | int rc; |
| 2175 | |
| 2176 | switch (mode) { |
| 2177 | case QED_LED_MODE_ON: |
| 2178 | drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_ON; |
| 2179 | break; |
| 2180 | case QED_LED_MODE_OFF: |
| 2181 | drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_OFF; |
| 2182 | break; |
| 2183 | case QED_LED_MODE_RESTORE: |
| 2184 | drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_OPER; |
| 2185 | break; |
| 2186 | default: |
| 2187 | DP_NOTICE(p_hwfn, "Invalid LED mode %d\n", mode); |
| 2188 | return -EINVAL; |
| 2189 | } |
| 2190 | |
| 2191 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LED_MODE, |
| 2192 | drv_mb_param, &resp, ¶m); |
| 2193 | |
| 2194 | return rc; |
| 2195 | } |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 2196 | |
Tomer Tayar | 4102426 | 2016-09-05 14:35:10 +0300 | [diff] [blame] | 2197 | int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn, |
| 2198 | struct qed_ptt *p_ptt, u32 mask_parities) |
| 2199 | { |
| 2200 | u32 resp = 0, param = 0; |
| 2201 | int rc; |
| 2202 | |
| 2203 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MASK_PARITIES, |
| 2204 | mask_parities, &resp, ¶m); |
| 2205 | |
| 2206 | if (rc) { |
| 2207 | DP_ERR(p_hwfn, |
| 2208 | "MCP response failure for mask parities, aborting\n"); |
| 2209 | } else if (resp != FW_MSG_CODE_OK) { |
| 2210 | DP_ERR(p_hwfn, |
| 2211 | "MCP did not acknowledge mask parity request. Old MFW?\n"); |
| 2212 | rc = -EINVAL; |
| 2213 | } |
| 2214 | |
| 2215 | return rc; |
| 2216 | } |
| 2217 | |
Mintz, Yuval | 7a4b21b | 2016-10-31 07:14:22 +0200 | [diff] [blame] | 2218 | int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len) |
| 2219 | { |
| 2220 | u32 bytes_left = len, offset = 0, bytes_to_copy, read_len = 0; |
| 2221 | struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev); |
| 2222 | u32 resp = 0, resp_param = 0; |
| 2223 | struct qed_ptt *p_ptt; |
| 2224 | int rc = 0; |
| 2225 | |
| 2226 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 2227 | if (!p_ptt) |
| 2228 | return -EBUSY; |
| 2229 | |
| 2230 | while (bytes_left > 0) { |
| 2231 | bytes_to_copy = min_t(u32, bytes_left, MCP_DRV_NVM_BUF_LEN); |
| 2232 | |
| 2233 | rc = qed_mcp_nvm_rd_cmd(p_hwfn, p_ptt, |
| 2234 | DRV_MSG_CODE_NVM_READ_NVRAM, |
| 2235 | addr + offset + |
| 2236 | (bytes_to_copy << |
Tomer Tayar | da09091 | 2017-12-27 19:30:07 +0200 | [diff] [blame] | 2237 | DRV_MB_PARAM_NVM_LEN_OFFSET), |
Mintz, Yuval | 7a4b21b | 2016-10-31 07:14:22 +0200 | [diff] [blame] | 2238 | &resp, &resp_param, |
| 2239 | &read_len, |
| 2240 | (u32 *)(p_buf + offset)); |
| 2241 | |
| 2242 | if (rc || (resp != FW_MSG_CODE_NVM_OK)) { |
| 2243 | DP_NOTICE(cdev, "MCP command rc = %d\n", rc); |
| 2244 | break; |
| 2245 | } |
| 2246 | |
| 2247 | /* This can be a lengthy process, and it's possible scheduler |
| 2248 | * isn't preemptable. Sleep a bit to prevent CPU hogging. |
| 2249 | */ |
| 2250 | if (bytes_left % 0x1000 < |
| 2251 | (bytes_left - read_len) % 0x1000) |
| 2252 | usleep_range(1000, 2000); |
| 2253 | |
| 2254 | offset += read_len; |
| 2255 | bytes_left -= read_len; |
| 2256 | } |
| 2257 | |
| 2258 | cdev->mcp_nvm_resp = resp; |
| 2259 | qed_ptt_release(p_hwfn, p_ptt); |
| 2260 | |
| 2261 | return rc; |
| 2262 | } |
| 2263 | |
Sudarsana Reddy Kalluru | 03dc76c | 2016-04-28 20:20:52 -0400 | [diff] [blame] | 2264 | int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2265 | { |
| 2266 | u32 drv_mb_param = 0, rsp, param; |
| 2267 | int rc = 0; |
| 2268 | |
| 2269 | drv_mb_param = (DRV_MB_PARAM_BIST_REGISTER_TEST << |
| 2270 | DRV_MB_PARAM_BIST_TEST_INDEX_SHIFT); |
| 2271 | |
| 2272 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST, |
| 2273 | drv_mb_param, &rsp, ¶m); |
| 2274 | |
| 2275 | if (rc) |
| 2276 | return rc; |
| 2277 | |
| 2278 | if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) || |
| 2279 | (param != DRV_MB_PARAM_BIST_RC_PASSED)) |
| 2280 | rc = -EAGAIN; |
| 2281 | |
| 2282 | return rc; |
| 2283 | } |
| 2284 | |
| 2285 | int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2286 | { |
| 2287 | u32 drv_mb_param, rsp, param; |
| 2288 | int rc = 0; |
| 2289 | |
| 2290 | drv_mb_param = (DRV_MB_PARAM_BIST_CLOCK_TEST << |
| 2291 | DRV_MB_PARAM_BIST_TEST_INDEX_SHIFT); |
| 2292 | |
| 2293 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST, |
| 2294 | drv_mb_param, &rsp, ¶m); |
| 2295 | |
| 2296 | if (rc) |
| 2297 | return rc; |
| 2298 | |
| 2299 | if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) || |
| 2300 | (param != DRV_MB_PARAM_BIST_RC_PASSED)) |
| 2301 | rc = -EAGAIN; |
| 2302 | |
| 2303 | return rc; |
| 2304 | } |
Mintz, Yuval | 7a4b21b | 2016-10-31 07:14:22 +0200 | [diff] [blame] | 2305 | |
Sudarsana Reddy Kalluru | 43645ce | 2018-03-28 05:14:19 -0700 | [diff] [blame^] | 2306 | int qed_mcp_bist_nvm_get_num_images(struct qed_hwfn *p_hwfn, |
| 2307 | struct qed_ptt *p_ptt, |
| 2308 | u32 *num_images) |
Mintz, Yuval | 7a4b21b | 2016-10-31 07:14:22 +0200 | [diff] [blame] | 2309 | { |
| 2310 | u32 drv_mb_param = 0, rsp; |
| 2311 | int rc = 0; |
| 2312 | |
| 2313 | drv_mb_param = (DRV_MB_PARAM_BIST_NVM_TEST_NUM_IMAGES << |
| 2314 | DRV_MB_PARAM_BIST_TEST_INDEX_SHIFT); |
| 2315 | |
| 2316 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST, |
| 2317 | drv_mb_param, &rsp, num_images); |
| 2318 | if (rc) |
| 2319 | return rc; |
| 2320 | |
| 2321 | if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK)) |
| 2322 | rc = -EINVAL; |
| 2323 | |
| 2324 | return rc; |
| 2325 | } |
| 2326 | |
Sudarsana Reddy Kalluru | 43645ce | 2018-03-28 05:14:19 -0700 | [diff] [blame^] | 2327 | int qed_mcp_bist_nvm_get_image_att(struct qed_hwfn *p_hwfn, |
| 2328 | struct qed_ptt *p_ptt, |
| 2329 | struct bist_nvm_image_att *p_image_att, |
| 2330 | u32 image_index) |
Mintz, Yuval | 7a4b21b | 2016-10-31 07:14:22 +0200 | [diff] [blame] | 2331 | { |
| 2332 | u32 buf_size = 0, param, resp = 0, resp_param = 0; |
| 2333 | int rc; |
| 2334 | |
| 2335 | param = DRV_MB_PARAM_BIST_NVM_TEST_IMAGE_BY_INDEX << |
| 2336 | DRV_MB_PARAM_BIST_TEST_INDEX_SHIFT; |
| 2337 | param |= image_index << DRV_MB_PARAM_BIST_TEST_IMAGE_INDEX_SHIFT; |
| 2338 | |
| 2339 | rc = qed_mcp_nvm_rd_cmd(p_hwfn, p_ptt, |
| 2340 | DRV_MSG_CODE_BIST_TEST, param, |
| 2341 | &resp, &resp_param, |
| 2342 | &buf_size, |
| 2343 | (u32 *)p_image_att); |
| 2344 | if (rc) |
| 2345 | return rc; |
| 2346 | |
| 2347 | if (((resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) || |
| 2348 | (p_image_att->return_code != 1)) |
| 2349 | rc = -EINVAL; |
| 2350 | |
| 2351 | return rc; |
| 2352 | } |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 2353 | |
Sudarsana Reddy Kalluru | 43645ce | 2018-03-28 05:14:19 -0700 | [diff] [blame^] | 2354 | int qed_mcp_nvm_info_populate(struct qed_hwfn *p_hwfn) |
| 2355 | { |
| 2356 | struct qed_nvm_image_info *nvm_info = &p_hwfn->nvm_info; |
| 2357 | struct qed_ptt *p_ptt; |
| 2358 | int rc; |
| 2359 | u32 i; |
| 2360 | |
| 2361 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 2362 | if (!p_ptt) { |
| 2363 | DP_ERR(p_hwfn, "failed to acquire ptt\n"); |
| 2364 | return -EBUSY; |
| 2365 | } |
| 2366 | |
| 2367 | /* Acquire from MFW the amount of available images */ |
| 2368 | nvm_info->num_images = 0; |
| 2369 | rc = qed_mcp_bist_nvm_get_num_images(p_hwfn, |
| 2370 | p_ptt, &nvm_info->num_images); |
| 2371 | if (rc == -EOPNOTSUPP) { |
| 2372 | DP_INFO(p_hwfn, "DRV_MSG_CODE_BIST_TEST is not supported\n"); |
| 2373 | goto out; |
| 2374 | } else if (rc || !nvm_info->num_images) { |
| 2375 | DP_ERR(p_hwfn, "Failed getting number of images\n"); |
| 2376 | goto err0; |
| 2377 | } |
| 2378 | |
| 2379 | nvm_info->image_att = kmalloc(nvm_info->num_images * |
| 2380 | sizeof(struct bist_nvm_image_att), |
| 2381 | GFP_KERNEL); |
| 2382 | if (!nvm_info->image_att) { |
| 2383 | rc = -ENOMEM; |
| 2384 | goto err0; |
| 2385 | } |
| 2386 | |
| 2387 | /* Iterate over images and get their attributes */ |
| 2388 | for (i = 0; i < nvm_info->num_images; i++) { |
| 2389 | rc = qed_mcp_bist_nvm_get_image_att(p_hwfn, p_ptt, |
| 2390 | &nvm_info->image_att[i], i); |
| 2391 | if (rc) { |
| 2392 | DP_ERR(p_hwfn, |
| 2393 | "Failed getting image index %d attributes\n", i); |
| 2394 | goto err1; |
| 2395 | } |
| 2396 | |
| 2397 | DP_VERBOSE(p_hwfn, QED_MSG_SP, "image index %d, size %x\n", i, |
| 2398 | nvm_info->image_att[i].len); |
| 2399 | } |
| 2400 | out: |
| 2401 | qed_ptt_release(p_hwfn, p_ptt); |
| 2402 | return 0; |
| 2403 | |
| 2404 | err1: |
| 2405 | kfree(nvm_info->image_att); |
| 2406 | err0: |
| 2407 | qed_ptt_release(p_hwfn, p_ptt); |
| 2408 | return rc; |
| 2409 | } |
| 2410 | |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 2411 | static int |
| 2412 | qed_mcp_get_nvm_image_att(struct qed_hwfn *p_hwfn, |
| 2413 | struct qed_ptt *p_ptt, |
| 2414 | enum qed_nvm_images image_id, |
| 2415 | struct qed_nvm_image_att *p_image_att) |
| 2416 | { |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 2417 | enum nvm_image_type type; |
Sudarsana Reddy Kalluru | 43645ce | 2018-03-28 05:14:19 -0700 | [diff] [blame^] | 2418 | u32 i; |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 2419 | |
| 2420 | /* Translate image_id into MFW definitions */ |
| 2421 | switch (image_id) { |
| 2422 | case QED_NVM_IMAGE_ISCSI_CFG: |
| 2423 | type = NVM_TYPE_ISCSI_CFG; |
| 2424 | break; |
| 2425 | case QED_NVM_IMAGE_FCOE_CFG: |
| 2426 | type = NVM_TYPE_FCOE_CFG; |
| 2427 | break; |
| 2428 | default: |
| 2429 | DP_NOTICE(p_hwfn, "Unknown request of image_id %08x\n", |
| 2430 | image_id); |
| 2431 | return -EINVAL; |
| 2432 | } |
| 2433 | |
Sudarsana Reddy Kalluru | 43645ce | 2018-03-28 05:14:19 -0700 | [diff] [blame^] | 2434 | for (i = 0; i < p_hwfn->nvm_info.num_images; i++) |
| 2435 | if (type == p_hwfn->nvm_info.image_att[i].image_type) |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 2436 | break; |
Sudarsana Reddy Kalluru | 43645ce | 2018-03-28 05:14:19 -0700 | [diff] [blame^] | 2437 | if (i == p_hwfn->nvm_info.num_images) { |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 2438 | DP_VERBOSE(p_hwfn, QED_MSG_STORAGE, |
| 2439 | "Failed to find nvram image of type %08x\n", |
| 2440 | image_id); |
Sudarsana Reddy Kalluru | 43645ce | 2018-03-28 05:14:19 -0700 | [diff] [blame^] | 2441 | return -ENOENT; |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 2442 | } |
| 2443 | |
Sudarsana Reddy Kalluru | 43645ce | 2018-03-28 05:14:19 -0700 | [diff] [blame^] | 2444 | p_image_att->start_addr = p_hwfn->nvm_info.image_att[i].nvm_start_addr; |
| 2445 | p_image_att->length = p_hwfn->nvm_info.image_att[i].len; |
Mintz, Yuval | 20675b3 | 2017-06-02 08:58:32 +0300 | [diff] [blame] | 2446 | |
| 2447 | return 0; |
| 2448 | } |
| 2449 | |
| 2450 | int qed_mcp_get_nvm_image(struct qed_hwfn *p_hwfn, |
| 2451 | struct qed_ptt *p_ptt, |
| 2452 | enum qed_nvm_images image_id, |
| 2453 | u8 *p_buffer, u32 buffer_len) |
| 2454 | { |
| 2455 | struct qed_nvm_image_att image_att; |
| 2456 | int rc; |
| 2457 | |
| 2458 | memset(p_buffer, 0, buffer_len); |
| 2459 | |
| 2460 | rc = qed_mcp_get_nvm_image_att(p_hwfn, p_ptt, image_id, &image_att); |
| 2461 | if (rc) |
| 2462 | return rc; |
| 2463 | |
| 2464 | /* Validate sizes - both the image's and the supplied buffer's */ |
| 2465 | if (image_att.length <= 4) { |
| 2466 | DP_VERBOSE(p_hwfn, QED_MSG_STORAGE, |
| 2467 | "Image [%d] is too small - only %d bytes\n", |
| 2468 | image_id, image_att.length); |
| 2469 | return -EINVAL; |
| 2470 | } |
| 2471 | |
| 2472 | /* Each NVM image is suffixed by CRC; Upper-layer has no need for it */ |
| 2473 | image_att.length -= 4; |
| 2474 | |
| 2475 | if (image_att.length > buffer_len) { |
| 2476 | DP_VERBOSE(p_hwfn, |
| 2477 | QED_MSG_STORAGE, |
| 2478 | "Image [%d] is too big - %08x bytes where only %08x are available\n", |
| 2479 | image_id, image_att.length, buffer_len); |
| 2480 | return -ENOMEM; |
| 2481 | } |
| 2482 | |
| 2483 | return qed_mcp_nvm_read(p_hwfn->cdev, image_att.start_addr, |
| 2484 | p_buffer, image_att.length); |
| 2485 | } |
| 2486 | |
Tomer Tayar | 9c8517c | 2017-03-28 15:12:55 +0300 | [diff] [blame] | 2487 | static enum resource_id_enum qed_mcp_get_mfw_res_id(enum qed_resources res_id) |
| 2488 | { |
| 2489 | enum resource_id_enum mfw_res_id = RESOURCE_NUM_INVALID; |
| 2490 | |
| 2491 | switch (res_id) { |
| 2492 | case QED_SB: |
| 2493 | mfw_res_id = RESOURCE_NUM_SB_E; |
| 2494 | break; |
| 2495 | case QED_L2_QUEUE: |
| 2496 | mfw_res_id = RESOURCE_NUM_L2_QUEUE_E; |
| 2497 | break; |
| 2498 | case QED_VPORT: |
| 2499 | mfw_res_id = RESOURCE_NUM_VPORT_E; |
| 2500 | break; |
| 2501 | case QED_RSS_ENG: |
| 2502 | mfw_res_id = RESOURCE_NUM_RSS_ENGINES_E; |
| 2503 | break; |
| 2504 | case QED_PQ: |
| 2505 | mfw_res_id = RESOURCE_NUM_PQ_E; |
| 2506 | break; |
| 2507 | case QED_RL: |
| 2508 | mfw_res_id = RESOURCE_NUM_RL_E; |
| 2509 | break; |
| 2510 | case QED_MAC: |
| 2511 | case QED_VLAN: |
| 2512 | /* Each VFC resource can accommodate both a MAC and a VLAN */ |
| 2513 | mfw_res_id = RESOURCE_VFC_FILTER_E; |
| 2514 | break; |
| 2515 | case QED_ILT: |
| 2516 | mfw_res_id = RESOURCE_ILT_E; |
| 2517 | break; |
| 2518 | case QED_LL2_QUEUE: |
| 2519 | mfw_res_id = RESOURCE_LL2_QUEUE_E; |
| 2520 | break; |
| 2521 | case QED_RDMA_CNQ_RAM: |
| 2522 | case QED_CMDQS_CQS: |
| 2523 | /* CNQ/CMDQS are the same resource */ |
| 2524 | mfw_res_id = RESOURCE_CQS_E; |
| 2525 | break; |
| 2526 | case QED_RDMA_STATS_QUEUE: |
| 2527 | mfw_res_id = RESOURCE_RDMA_STATS_QUEUE_E; |
| 2528 | break; |
| 2529 | case QED_BDQ: |
| 2530 | mfw_res_id = RESOURCE_BDQ_E; |
| 2531 | break; |
| 2532 | default: |
| 2533 | break; |
| 2534 | } |
| 2535 | |
| 2536 | return mfw_res_id; |
| 2537 | } |
| 2538 | |
| 2539 | #define QED_RESC_ALLOC_VERSION_MAJOR 2 |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 2540 | #define QED_RESC_ALLOC_VERSION_MINOR 0 |
| 2541 | #define QED_RESC_ALLOC_VERSION \ |
| 2542 | ((QED_RESC_ALLOC_VERSION_MAJOR << \ |
| 2543 | DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR_SHIFT) | \ |
| 2544 | (QED_RESC_ALLOC_VERSION_MINOR << \ |
| 2545 | DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR_SHIFT)) |
Tomer Tayar | 9c8517c | 2017-03-28 15:12:55 +0300 | [diff] [blame] | 2546 | |
| 2547 | struct qed_resc_alloc_in_params { |
| 2548 | u32 cmd; |
| 2549 | enum qed_resources res_id; |
| 2550 | u32 resc_max_val; |
| 2551 | }; |
| 2552 | |
| 2553 | struct qed_resc_alloc_out_params { |
| 2554 | u32 mcp_resp; |
| 2555 | u32 mcp_param; |
| 2556 | u32 resc_num; |
| 2557 | u32 resc_start; |
| 2558 | u32 vf_resc_num; |
| 2559 | u32 vf_resc_start; |
| 2560 | u32 flags; |
| 2561 | }; |
| 2562 | |
| 2563 | static int |
| 2564 | qed_mcp_resc_allocation_msg(struct qed_hwfn *p_hwfn, |
| 2565 | struct qed_ptt *p_ptt, |
| 2566 | struct qed_resc_alloc_in_params *p_in_params, |
| 2567 | struct qed_resc_alloc_out_params *p_out_params) |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 2568 | { |
| 2569 | struct qed_mcp_mb_params mb_params; |
Tomer Tayar | 9c8517c | 2017-03-28 15:12:55 +0300 | [diff] [blame] | 2570 | struct resource_info mfw_resc_info; |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 2571 | int rc; |
| 2572 | |
Tomer Tayar | 9c8517c | 2017-03-28 15:12:55 +0300 | [diff] [blame] | 2573 | memset(&mfw_resc_info, 0, sizeof(mfw_resc_info)); |
Mintz, Yuval | bb48024 | 2016-11-06 17:12:27 +0200 | [diff] [blame] | 2574 | |
Tomer Tayar | 9c8517c | 2017-03-28 15:12:55 +0300 | [diff] [blame] | 2575 | mfw_resc_info.res_id = qed_mcp_get_mfw_res_id(p_in_params->res_id); |
| 2576 | if (mfw_resc_info.res_id == RESOURCE_NUM_INVALID) { |
| 2577 | DP_ERR(p_hwfn, |
| 2578 | "Failed to match resource %d [%s] with the MFW resources\n", |
| 2579 | p_in_params->res_id, |
| 2580 | qed_hw_get_resc_name(p_in_params->res_id)); |
| 2581 | return -EINVAL; |
| 2582 | } |
| 2583 | |
| 2584 | switch (p_in_params->cmd) { |
| 2585 | case DRV_MSG_SET_RESOURCE_VALUE_MSG: |
| 2586 | mfw_resc_info.size = p_in_params->resc_max_val; |
| 2587 | /* Fallthrough */ |
| 2588 | case DRV_MSG_GET_RESOURCE_ALLOC_MSG: |
| 2589 | break; |
| 2590 | default: |
| 2591 | DP_ERR(p_hwfn, "Unexpected resource alloc command [0x%08x]\n", |
| 2592 | p_in_params->cmd); |
| 2593 | return -EINVAL; |
| 2594 | } |
| 2595 | |
| 2596 | memset(&mb_params, 0, sizeof(mb_params)); |
| 2597 | mb_params.cmd = p_in_params->cmd; |
| 2598 | mb_params.param = QED_RESC_ALLOC_VERSION; |
| 2599 | mb_params.p_data_src = &mfw_resc_info; |
| 2600 | mb_params.data_src_size = sizeof(mfw_resc_info); |
| 2601 | mb_params.p_data_dst = mb_params.p_data_src; |
| 2602 | mb_params.data_dst_size = mb_params.data_src_size; |
| 2603 | |
| 2604 | DP_VERBOSE(p_hwfn, |
| 2605 | QED_MSG_SP, |
| 2606 | "Resource message request: cmd 0x%08x, res_id %d [%s], hsi_version %d.%d, val 0x%x\n", |
| 2607 | p_in_params->cmd, |
| 2608 | p_in_params->res_id, |
| 2609 | qed_hw_get_resc_name(p_in_params->res_id), |
| 2610 | QED_MFW_GET_FIELD(mb_params.param, |
| 2611 | DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR), |
| 2612 | QED_MFW_GET_FIELD(mb_params.param, |
| 2613 | DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR), |
| 2614 | p_in_params->resc_max_val); |
| 2615 | |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 2616 | rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params); |
| 2617 | if (rc) |
| 2618 | return rc; |
| 2619 | |
Tomer Tayar | 9c8517c | 2017-03-28 15:12:55 +0300 | [diff] [blame] | 2620 | p_out_params->mcp_resp = mb_params.mcp_resp; |
| 2621 | p_out_params->mcp_param = mb_params.mcp_param; |
| 2622 | p_out_params->resc_num = mfw_resc_info.size; |
| 2623 | p_out_params->resc_start = mfw_resc_info.offset; |
| 2624 | p_out_params->vf_resc_num = mfw_resc_info.vf_size; |
| 2625 | p_out_params->vf_resc_start = mfw_resc_info.vf_offset; |
| 2626 | p_out_params->flags = mfw_resc_info.flags; |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 2627 | |
| 2628 | DP_VERBOSE(p_hwfn, |
| 2629 | QED_MSG_SP, |
Tomer Tayar | 9c8517c | 2017-03-28 15:12:55 +0300 | [diff] [blame] | 2630 | "Resource message response: mfw_hsi_version %d.%d, num 0x%x, start 0x%x, vf_num 0x%x, vf_start 0x%x, flags 0x%08x\n", |
| 2631 | QED_MFW_GET_FIELD(p_out_params->mcp_param, |
| 2632 | FW_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR), |
| 2633 | QED_MFW_GET_FIELD(p_out_params->mcp_param, |
| 2634 | FW_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR), |
| 2635 | p_out_params->resc_num, |
| 2636 | p_out_params->resc_start, |
| 2637 | p_out_params->vf_resc_num, |
| 2638 | p_out_params->vf_resc_start, p_out_params->flags); |
| 2639 | |
| 2640 | return 0; |
| 2641 | } |
| 2642 | |
| 2643 | int |
| 2644 | qed_mcp_set_resc_max_val(struct qed_hwfn *p_hwfn, |
| 2645 | struct qed_ptt *p_ptt, |
| 2646 | enum qed_resources res_id, |
| 2647 | u32 resc_max_val, u32 *p_mcp_resp) |
| 2648 | { |
| 2649 | struct qed_resc_alloc_out_params out_params; |
| 2650 | struct qed_resc_alloc_in_params in_params; |
| 2651 | int rc; |
| 2652 | |
| 2653 | memset(&in_params, 0, sizeof(in_params)); |
| 2654 | in_params.cmd = DRV_MSG_SET_RESOURCE_VALUE_MSG; |
| 2655 | in_params.res_id = res_id; |
| 2656 | in_params.resc_max_val = resc_max_val; |
| 2657 | memset(&out_params, 0, sizeof(out_params)); |
| 2658 | rc = qed_mcp_resc_allocation_msg(p_hwfn, p_ptt, &in_params, |
| 2659 | &out_params); |
| 2660 | if (rc) |
| 2661 | return rc; |
| 2662 | |
| 2663 | *p_mcp_resp = out_params.mcp_resp; |
| 2664 | |
| 2665 | return 0; |
| 2666 | } |
| 2667 | |
| 2668 | int |
| 2669 | qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn, |
| 2670 | struct qed_ptt *p_ptt, |
| 2671 | enum qed_resources res_id, |
| 2672 | u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start) |
| 2673 | { |
| 2674 | struct qed_resc_alloc_out_params out_params; |
| 2675 | struct qed_resc_alloc_in_params in_params; |
| 2676 | int rc; |
| 2677 | |
| 2678 | memset(&in_params, 0, sizeof(in_params)); |
| 2679 | in_params.cmd = DRV_MSG_GET_RESOURCE_ALLOC_MSG; |
| 2680 | in_params.res_id = res_id; |
| 2681 | memset(&out_params, 0, sizeof(out_params)); |
| 2682 | rc = qed_mcp_resc_allocation_msg(p_hwfn, p_ptt, &in_params, |
| 2683 | &out_params); |
| 2684 | if (rc) |
| 2685 | return rc; |
| 2686 | |
| 2687 | *p_mcp_resp = out_params.mcp_resp; |
| 2688 | |
| 2689 | if (*p_mcp_resp == FW_MSG_CODE_RESOURCE_ALLOC_OK) { |
| 2690 | *p_resc_num = out_params.resc_num; |
| 2691 | *p_resc_start = out_params.resc_start; |
| 2692 | } |
Tomer Tayar | 2edbff8 | 2016-10-31 07:14:27 +0200 | [diff] [blame] | 2693 | |
| 2694 | return 0; |
| 2695 | } |
Mintz, Yuval | 18a69e3 | 2017-03-28 15:12:53 +0300 | [diff] [blame] | 2696 | |
| 2697 | int qed_mcp_initiate_pf_flr(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2698 | { |
| 2699 | u32 mcp_resp, mcp_param; |
| 2700 | |
| 2701 | return qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_INITIATE_PF_FLR, 0, |
| 2702 | &mcp_resp, &mcp_param); |
| 2703 | } |
Tomer Tayar | 95691c9 | 2017-03-28 15:12:54 +0300 | [diff] [blame] | 2704 | |
| 2705 | static int qed_mcp_resource_cmd(struct qed_hwfn *p_hwfn, |
| 2706 | struct qed_ptt *p_ptt, |
| 2707 | u32 param, u32 *p_mcp_resp, u32 *p_mcp_param) |
| 2708 | { |
| 2709 | int rc; |
| 2710 | |
| 2711 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_RESOURCE_CMD, param, |
| 2712 | p_mcp_resp, p_mcp_param); |
| 2713 | if (rc) |
| 2714 | return rc; |
| 2715 | |
| 2716 | if (*p_mcp_resp == FW_MSG_CODE_UNSUPPORTED) { |
| 2717 | DP_INFO(p_hwfn, |
| 2718 | "The resource command is unsupported by the MFW\n"); |
| 2719 | return -EINVAL; |
| 2720 | } |
| 2721 | |
| 2722 | if (*p_mcp_param == RESOURCE_OPCODE_UNKNOWN_CMD) { |
| 2723 | u8 opcode = QED_MFW_GET_FIELD(param, RESOURCE_CMD_REQ_OPCODE); |
| 2724 | |
| 2725 | DP_NOTICE(p_hwfn, |
| 2726 | "The resource command is unknown to the MFW [param 0x%08x, opcode %d]\n", |
| 2727 | param, opcode); |
| 2728 | return -EINVAL; |
| 2729 | } |
| 2730 | |
| 2731 | return rc; |
| 2732 | } |
| 2733 | |
| 2734 | int |
| 2735 | __qed_mcp_resc_lock(struct qed_hwfn *p_hwfn, |
| 2736 | struct qed_ptt *p_ptt, |
| 2737 | struct qed_resc_lock_params *p_params) |
| 2738 | { |
| 2739 | u32 param = 0, mcp_resp, mcp_param; |
| 2740 | u8 opcode; |
| 2741 | int rc; |
| 2742 | |
| 2743 | switch (p_params->timeout) { |
| 2744 | case QED_MCP_RESC_LOCK_TO_DEFAULT: |
| 2745 | opcode = RESOURCE_OPCODE_REQ; |
| 2746 | p_params->timeout = 0; |
| 2747 | break; |
| 2748 | case QED_MCP_RESC_LOCK_TO_NONE: |
| 2749 | opcode = RESOURCE_OPCODE_REQ_WO_AGING; |
| 2750 | p_params->timeout = 0; |
| 2751 | break; |
| 2752 | default: |
| 2753 | opcode = RESOURCE_OPCODE_REQ_W_AGING; |
| 2754 | break; |
| 2755 | } |
| 2756 | |
| 2757 | QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_RESC, p_params->resource); |
| 2758 | QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_OPCODE, opcode); |
| 2759 | QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_AGE, p_params->timeout); |
| 2760 | |
| 2761 | DP_VERBOSE(p_hwfn, |
| 2762 | QED_MSG_SP, |
| 2763 | "Resource lock request: param 0x%08x [age %d, opcode %d, resource %d]\n", |
| 2764 | param, p_params->timeout, opcode, p_params->resource); |
| 2765 | |
| 2766 | /* Attempt to acquire the resource */ |
| 2767 | rc = qed_mcp_resource_cmd(p_hwfn, p_ptt, param, &mcp_resp, &mcp_param); |
| 2768 | if (rc) |
| 2769 | return rc; |
| 2770 | |
| 2771 | /* Analyze the response */ |
| 2772 | p_params->owner = QED_MFW_GET_FIELD(mcp_param, RESOURCE_CMD_RSP_OWNER); |
| 2773 | opcode = QED_MFW_GET_FIELD(mcp_param, RESOURCE_CMD_RSP_OPCODE); |
| 2774 | |
| 2775 | DP_VERBOSE(p_hwfn, |
| 2776 | QED_MSG_SP, |
| 2777 | "Resource lock response: mcp_param 0x%08x [opcode %d, owner %d]\n", |
| 2778 | mcp_param, opcode, p_params->owner); |
| 2779 | |
| 2780 | switch (opcode) { |
| 2781 | case RESOURCE_OPCODE_GNT: |
| 2782 | p_params->b_granted = true; |
| 2783 | break; |
| 2784 | case RESOURCE_OPCODE_BUSY: |
| 2785 | p_params->b_granted = false; |
| 2786 | break; |
| 2787 | default: |
| 2788 | DP_NOTICE(p_hwfn, |
| 2789 | "Unexpected opcode in resource lock response [mcp_param 0x%08x, opcode %d]\n", |
| 2790 | mcp_param, opcode); |
| 2791 | return -EINVAL; |
| 2792 | } |
| 2793 | |
| 2794 | return 0; |
| 2795 | } |
| 2796 | |
| 2797 | int |
| 2798 | qed_mcp_resc_lock(struct qed_hwfn *p_hwfn, |
| 2799 | struct qed_ptt *p_ptt, struct qed_resc_lock_params *p_params) |
| 2800 | { |
| 2801 | u32 retry_cnt = 0; |
| 2802 | int rc; |
| 2803 | |
| 2804 | do { |
| 2805 | /* No need for an interval before the first iteration */ |
| 2806 | if (retry_cnt) { |
| 2807 | if (p_params->sleep_b4_retry) { |
| 2808 | u16 retry_interval_in_ms = |
| 2809 | DIV_ROUND_UP(p_params->retry_interval, |
| 2810 | 1000); |
| 2811 | |
| 2812 | msleep(retry_interval_in_ms); |
| 2813 | } else { |
| 2814 | udelay(p_params->retry_interval); |
| 2815 | } |
| 2816 | } |
| 2817 | |
| 2818 | rc = __qed_mcp_resc_lock(p_hwfn, p_ptt, p_params); |
| 2819 | if (rc) |
| 2820 | return rc; |
| 2821 | |
| 2822 | if (p_params->b_granted) |
| 2823 | break; |
| 2824 | } while (retry_cnt++ < p_params->retry_num); |
| 2825 | |
| 2826 | return 0; |
| 2827 | } |
| 2828 | |
| 2829 | int |
| 2830 | qed_mcp_resc_unlock(struct qed_hwfn *p_hwfn, |
| 2831 | struct qed_ptt *p_ptt, |
| 2832 | struct qed_resc_unlock_params *p_params) |
| 2833 | { |
| 2834 | u32 param = 0, mcp_resp, mcp_param; |
| 2835 | u8 opcode; |
| 2836 | int rc; |
| 2837 | |
| 2838 | opcode = p_params->b_force ? RESOURCE_OPCODE_FORCE_RELEASE |
| 2839 | : RESOURCE_OPCODE_RELEASE; |
| 2840 | QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_RESC, p_params->resource); |
| 2841 | QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_OPCODE, opcode); |
| 2842 | |
| 2843 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 2844 | "Resource unlock request: param 0x%08x [opcode %d, resource %d]\n", |
| 2845 | param, opcode, p_params->resource); |
| 2846 | |
| 2847 | /* Attempt to release the resource */ |
| 2848 | rc = qed_mcp_resource_cmd(p_hwfn, p_ptt, param, &mcp_resp, &mcp_param); |
| 2849 | if (rc) |
| 2850 | return rc; |
| 2851 | |
| 2852 | /* Analyze the response */ |
| 2853 | opcode = QED_MFW_GET_FIELD(mcp_param, RESOURCE_CMD_RSP_OPCODE); |
| 2854 | |
| 2855 | DP_VERBOSE(p_hwfn, QED_MSG_SP, |
| 2856 | "Resource unlock response: mcp_param 0x%08x [opcode %d]\n", |
| 2857 | mcp_param, opcode); |
| 2858 | |
| 2859 | switch (opcode) { |
| 2860 | case RESOURCE_OPCODE_RELEASED_PREVIOUS: |
| 2861 | DP_INFO(p_hwfn, |
| 2862 | "Resource unlock request for an already released resource [%d]\n", |
| 2863 | p_params->resource); |
| 2864 | /* Fallthrough */ |
| 2865 | case RESOURCE_OPCODE_RELEASED: |
| 2866 | p_params->b_released = true; |
| 2867 | break; |
| 2868 | case RESOURCE_OPCODE_WRONG_OWNER: |
| 2869 | p_params->b_released = false; |
| 2870 | break; |
| 2871 | default: |
| 2872 | DP_NOTICE(p_hwfn, |
| 2873 | "Unexpected opcode in resource unlock response [mcp_param 0x%08x, opcode %d]\n", |
| 2874 | mcp_param, opcode); |
| 2875 | return -EINVAL; |
| 2876 | } |
| 2877 | |
| 2878 | return 0; |
| 2879 | } |
sudarsana.kalluru@cavium.com | f470f22 | 2017-04-26 09:00:49 -0700 | [diff] [blame] | 2880 | |
| 2881 | void qed_mcp_resc_lock_default_init(struct qed_resc_lock_params *p_lock, |
| 2882 | struct qed_resc_unlock_params *p_unlock, |
| 2883 | enum qed_resc_lock |
| 2884 | resource, bool b_is_permanent) |
| 2885 | { |
| 2886 | if (p_lock) { |
| 2887 | memset(p_lock, 0, sizeof(*p_lock)); |
| 2888 | |
| 2889 | /* Permanent resources don't require aging, and there's no |
| 2890 | * point in trying to acquire them more than once since it's |
| 2891 | * unexpected another entity would release them. |
| 2892 | */ |
| 2893 | if (b_is_permanent) { |
| 2894 | p_lock->timeout = QED_MCP_RESC_LOCK_TO_NONE; |
| 2895 | } else { |
| 2896 | p_lock->retry_num = QED_MCP_RESC_LOCK_RETRY_CNT_DFLT; |
| 2897 | p_lock->retry_interval = |
| 2898 | QED_MCP_RESC_LOCK_RETRY_VAL_DFLT; |
| 2899 | p_lock->sleep_b4_retry = true; |
| 2900 | } |
| 2901 | |
| 2902 | p_lock->resource = resource; |
| 2903 | } |
| 2904 | |
| 2905 | if (p_unlock) { |
| 2906 | memset(p_unlock, 0, sizeof(*p_unlock)); |
| 2907 | p_unlock->resource = resource; |
| 2908 | } |
| 2909 | } |
Sudarsana Reddy Kalluru | 645874e | 2017-07-26 06:07:11 -0700 | [diff] [blame] | 2910 | |
| 2911 | int qed_mcp_get_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2912 | { |
| 2913 | u32 mcp_resp; |
| 2914 | int rc; |
| 2915 | |
| 2916 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GET_MFW_FEATURE_SUPPORT, |
| 2917 | 0, &mcp_resp, &p_hwfn->mcp_info->capabilities); |
| 2918 | if (!rc) |
| 2919 | DP_VERBOSE(p_hwfn, (QED_MSG_SP | NETIF_MSG_PROBE), |
| 2920 | "MFW supported features: %08x\n", |
| 2921 | p_hwfn->mcp_info->capabilities); |
| 2922 | |
| 2923 | return rc; |
| 2924 | } |
| 2925 | |
| 2926 | int qed_mcp_set_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 2927 | { |
| 2928 | u32 mcp_resp, mcp_param, features; |
| 2929 | |
| 2930 | features = DRV_MB_PARAM_FEATURE_SUPPORT_PORT_EEE; |
| 2931 | |
| 2932 | return qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_FEATURE_SUPPORT, |
| 2933 | features, &mcp_resp, &mcp_param); |
| 2934 | } |