Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
| 2 | * Copyright (c) 2015 QLogic Corporation |
| 3 | * |
| 4 | * This software is available under the terms of the GNU General Public License |
| 5 | * (GPL) Version 2, available from the file COPYING in the main directory of |
| 6 | * this source tree. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <asm/byteorder.h> |
| 11 | #include <linux/bitops.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/string.h> |
| 16 | #include "qed.h" |
| 17 | #include "qed_cxt.h" |
| 18 | #include "qed_dcbx.h" |
| 19 | #include "qed_hsi.h" |
| 20 | #include "qed_sp.h" |
| 21 | |
| 22 | #define QED_DCBX_MAX_MIB_READ_TRY (100) |
| 23 | #define QED_ETH_TYPE_DEFAULT (0) |
| 24 | #define QED_ETH_TYPE_ROCE (0x8915) |
| 25 | #define QED_UDP_PORT_TYPE_ROCE_V2 (0x12B7) |
| 26 | #define QED_ETH_TYPE_FCOE (0x8906) |
| 27 | #define QED_TCP_PORT_ISCSI (0xCBC) |
| 28 | |
| 29 | #define QED_DCBX_INVALID_PRIORITY 0xFF |
| 30 | |
| 31 | /* Get Traffic Class from priority traffic class table, 4 bits represent |
| 32 | * the traffic class corresponding to the priority. |
| 33 | */ |
| 34 | #define QED_DCBX_PRIO2TC(prio_tc_tbl, prio) \ |
| 35 | ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7) |
| 36 | |
| 37 | static const struct qed_dcbx_app_metadata qed_dcbx_app_update[] = { |
| 38 | {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_DEFAULT}, |
| 39 | {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_DEFAULT}, |
| 40 | {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_DEFAULT}, |
| 41 | {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_DEFAULT}, |
| 42 | {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH} |
| 43 | }; |
| 44 | |
| 45 | static bool qed_dcbx_app_ethtype(u32 app_info_bitmap) |
| 46 | { |
| 47 | return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) == |
| 48 | DCBX_APP_SF_ETHTYPE); |
| 49 | } |
| 50 | |
| 51 | static bool qed_dcbx_app_port(u32 app_info_bitmap) |
| 52 | { |
| 53 | return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) == |
| 54 | DCBX_APP_SF_PORT); |
| 55 | } |
| 56 | |
| 57 | static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id) |
| 58 | { |
| 59 | return !!(qed_dcbx_app_ethtype(app_info_bitmap) && |
| 60 | proto_id == QED_ETH_TYPE_DEFAULT); |
| 61 | } |
| 62 | |
| 63 | static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id) |
| 64 | { |
| 65 | return !!(qed_dcbx_app_port(app_info_bitmap) && |
| 66 | proto_id == QED_TCP_PORT_ISCSI); |
| 67 | } |
| 68 | |
| 69 | static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id) |
| 70 | { |
| 71 | return !!(qed_dcbx_app_ethtype(app_info_bitmap) && |
| 72 | proto_id == QED_ETH_TYPE_FCOE); |
| 73 | } |
| 74 | |
| 75 | static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id) |
| 76 | { |
| 77 | return !!(qed_dcbx_app_ethtype(app_info_bitmap) && |
| 78 | proto_id == QED_ETH_TYPE_ROCE); |
| 79 | } |
| 80 | |
| 81 | static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id) |
| 82 | { |
| 83 | return !!(qed_dcbx_app_port(app_info_bitmap) && |
| 84 | proto_id == QED_UDP_PORT_TYPE_ROCE_V2); |
| 85 | } |
| 86 | |
| 87 | static void |
| 88 | qed_dcbx_dp_protocol(struct qed_hwfn *p_hwfn, struct qed_dcbx_results *p_data) |
| 89 | { |
| 90 | enum dcbx_protocol_type id; |
| 91 | int i; |
| 92 | |
| 93 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, "DCBX negotiated: %d\n", |
| 94 | p_data->dcbx_enabled); |
| 95 | |
| 96 | for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) { |
| 97 | id = qed_dcbx_app_update[i].id; |
| 98 | |
| 99 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, |
| 100 | "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n", |
| 101 | qed_dcbx_app_update[i].name, p_data->arr[id].update, |
| 102 | p_data->arr[id].enable, p_data->arr[id].priority, |
| 103 | p_data->arr[id].tc, p_hwfn->hw_info.num_tc); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | static void |
| 108 | qed_dcbx_set_params(struct qed_dcbx_results *p_data, |
| 109 | struct qed_hw_info *p_info, |
| 110 | bool enable, |
| 111 | bool update, |
| 112 | u8 prio, |
| 113 | u8 tc, |
| 114 | enum dcbx_protocol_type type, |
| 115 | enum qed_pci_personality personality) |
| 116 | { |
| 117 | /* PF update ramrod data */ |
| 118 | p_data->arr[type].update = update; |
| 119 | p_data->arr[type].enable = enable; |
| 120 | p_data->arr[type].priority = prio; |
| 121 | p_data->arr[type].tc = tc; |
| 122 | |
| 123 | /* QM reconf data */ |
| 124 | if (p_info->personality == personality) { |
| 125 | if (personality == QED_PCI_ETH) |
| 126 | p_info->non_offload_tc = tc; |
| 127 | else |
| 128 | p_info->offload_tc = tc; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /* Update app protocol data and hw_info fields with the TLV info */ |
| 133 | static void |
| 134 | qed_dcbx_update_app_info(struct qed_dcbx_results *p_data, |
| 135 | struct qed_hwfn *p_hwfn, |
| 136 | bool enable, |
| 137 | bool update, |
| 138 | u8 prio, u8 tc, enum dcbx_protocol_type type) |
| 139 | { |
| 140 | struct qed_hw_info *p_info = &p_hwfn->hw_info; |
| 141 | enum qed_pci_personality personality; |
| 142 | enum dcbx_protocol_type id; |
| 143 | char *name; |
| 144 | int i; |
| 145 | |
| 146 | for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) { |
| 147 | id = qed_dcbx_app_update[i].id; |
| 148 | |
| 149 | if (type != id) |
| 150 | continue; |
| 151 | |
| 152 | personality = qed_dcbx_app_update[i].personality; |
| 153 | name = qed_dcbx_app_update[i].name; |
| 154 | |
| 155 | qed_dcbx_set_params(p_data, p_info, enable, update, |
| 156 | prio, tc, type, personality); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | static bool |
| 161 | qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn, |
| 162 | u32 app_prio_bitmap, |
| 163 | u16 id, enum dcbx_protocol_type *type) |
| 164 | { |
| 165 | if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id)) { |
| 166 | *type = DCBX_PROTOCOL_FCOE; |
| 167 | } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id)) { |
| 168 | *type = DCBX_PROTOCOL_ROCE; |
| 169 | } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id)) { |
| 170 | *type = DCBX_PROTOCOL_ISCSI; |
| 171 | } else if (qed_dcbx_default_tlv(app_prio_bitmap, id)) { |
| 172 | *type = DCBX_PROTOCOL_ETH; |
| 173 | } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id)) { |
| 174 | *type = DCBX_PROTOCOL_ROCE_V2; |
| 175 | } else { |
| 176 | *type = DCBX_MAX_PROTOCOL_TYPE; |
| 177 | DP_ERR(p_hwfn, |
| 178 | "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n", |
| 179 | id, app_prio_bitmap); |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | /* Parse app TLV's to update TC information in hw_info structure for |
| 187 | * reconfiguring QM. Get protocol specific data for PF update ramrod command. |
| 188 | */ |
| 189 | static int |
| 190 | qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn, |
| 191 | struct qed_dcbx_results *p_data, |
| 192 | struct dcbx_app_priority_entry *p_tbl, |
| 193 | u32 pri_tc_tbl, int count, bool dcbx_enabled) |
| 194 | { |
Dan Carpenter | 54b9430 | 2016-05-23 13:19:35 +0300 | [diff] [blame] | 195 | u8 tc, priority_map; |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 196 | enum dcbx_protocol_type type; |
| 197 | u16 protocol_id; |
Dan Carpenter | 54b9430 | 2016-05-23 13:19:35 +0300 | [diff] [blame] | 198 | int priority; |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 199 | bool enable; |
| 200 | int i; |
| 201 | |
| 202 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count); |
| 203 | |
| 204 | /* Parse APP TLV */ |
| 205 | for (i = 0; i < count; i++) { |
| 206 | protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry, |
| 207 | DCBX_APP_PROTOCOL_ID); |
| 208 | priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry, |
| 209 | DCBX_APP_PRI_MAP); |
| 210 | priority = ffs(priority_map) - 1; |
| 211 | if (priority < 0) { |
| 212 | DP_ERR(p_hwfn, "Invalid priority\n"); |
| 213 | return -EINVAL; |
| 214 | } |
| 215 | |
| 216 | tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority); |
| 217 | if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry, |
| 218 | protocol_id, &type)) { |
| 219 | /* ETH always have the enable bit reset, as it gets |
| 220 | * vlan information per packet. For other protocols, |
| 221 | * should be set according to the dcbx_enabled |
| 222 | * indication, but we only got here if there was an |
| 223 | * app tlv for the protocol, so dcbx must be enabled. |
| 224 | */ |
Sudarsana Reddy Kalluru | ec7c7f5 | 2016-05-24 05:25:23 -0400 | [diff] [blame] | 225 | enable = !(type == DCBX_PROTOCOL_ETH); |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 226 | |
| 227 | qed_dcbx_update_app_info(p_data, p_hwfn, enable, true, |
| 228 | priority, tc, type); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /* If RoCE-V2 TLV is not detected, driver need to use RoCE app |
| 233 | * data for RoCE-v2 not the default app data. |
| 234 | */ |
| 235 | if (!p_data->arr[DCBX_PROTOCOL_ROCE_V2].update && |
| 236 | p_data->arr[DCBX_PROTOCOL_ROCE].update) { |
| 237 | tc = p_data->arr[DCBX_PROTOCOL_ROCE].tc; |
| 238 | priority = p_data->arr[DCBX_PROTOCOL_ROCE].priority; |
| 239 | qed_dcbx_update_app_info(p_data, p_hwfn, true, true, |
| 240 | priority, tc, DCBX_PROTOCOL_ROCE_V2); |
| 241 | } |
| 242 | |
| 243 | /* Update ramrod protocol data and hw_info fields |
| 244 | * with default info when corresponding APP TLV's are not detected. |
| 245 | * The enabled field has a different logic for ethernet as only for |
| 246 | * ethernet dcb should disabled by default, as the information arrives |
| 247 | * from the OS (unless an explicit app tlv was present). |
| 248 | */ |
| 249 | tc = p_data->arr[DCBX_PROTOCOL_ETH].tc; |
| 250 | priority = p_data->arr[DCBX_PROTOCOL_ETH].priority; |
| 251 | for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) { |
| 252 | if (p_data->arr[type].update) |
| 253 | continue; |
| 254 | |
Sudarsana Reddy Kalluru | 6ad8c63 | 2016-06-08 06:22:10 -0400 | [diff] [blame^] | 255 | enable = !(type == DCBX_PROTOCOL_ETH); |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 256 | qed_dcbx_update_app_info(p_data, p_hwfn, enable, true, |
| 257 | priority, tc, type); |
| 258 | } |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | /* Parse app TLV's to update TC information in hw_info structure for |
| 264 | * reconfiguring QM. Get protocol specific data for PF update ramrod command. |
| 265 | */ |
| 266 | static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn) |
| 267 | { |
| 268 | struct dcbx_app_priority_feature *p_app; |
| 269 | struct dcbx_app_priority_entry *p_tbl; |
| 270 | struct qed_dcbx_results data = { 0 }; |
| 271 | struct dcbx_ets_feature *p_ets; |
| 272 | struct qed_hw_info *p_info; |
| 273 | u32 pri_tc_tbl, flags; |
| 274 | bool dcbx_enabled; |
| 275 | int num_entries; |
| 276 | int rc = 0; |
| 277 | |
| 278 | /* If DCBx version is non zero, then negotiation was |
| 279 | * successfuly performed |
| 280 | */ |
| 281 | flags = p_hwfn->p_dcbx_info->operational.flags; |
| 282 | dcbx_enabled = !!QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION); |
| 283 | |
| 284 | p_app = &p_hwfn->p_dcbx_info->operational.features.app; |
| 285 | p_tbl = p_app->app_pri_tbl; |
| 286 | |
| 287 | p_ets = &p_hwfn->p_dcbx_info->operational.features.ets; |
| 288 | pri_tc_tbl = p_ets->pri_tc_tbl[0]; |
| 289 | |
| 290 | p_info = &p_hwfn->hw_info; |
| 291 | num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES); |
| 292 | |
| 293 | rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl, |
| 294 | num_entries, dcbx_enabled); |
| 295 | if (rc) |
| 296 | return rc; |
| 297 | |
| 298 | p_info->num_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS); |
| 299 | data.pf_id = p_hwfn->rel_pf_id; |
| 300 | data.dcbx_enabled = dcbx_enabled; |
| 301 | |
| 302 | qed_dcbx_dp_protocol(p_hwfn, &data); |
| 303 | |
| 304 | memcpy(&p_hwfn->p_dcbx_info->results, &data, |
| 305 | sizeof(struct qed_dcbx_results)); |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static int |
| 311 | qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn, |
| 312 | struct qed_ptt *p_ptt, |
| 313 | struct qed_dcbx_mib_meta_data *p_data, |
| 314 | enum qed_mib_read_type type) |
| 315 | { |
| 316 | u32 prefix_seq_num, suffix_seq_num; |
| 317 | int read_count = 0; |
| 318 | int rc = 0; |
| 319 | |
| 320 | /* The data is considered to be valid only if both sequence numbers are |
| 321 | * the same. |
| 322 | */ |
| 323 | do { |
| 324 | if (type == QED_DCBX_REMOTE_LLDP_MIB) { |
| 325 | qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote, |
| 326 | p_data->addr, p_data->size); |
| 327 | prefix_seq_num = p_data->lldp_remote->prefix_seq_num; |
| 328 | suffix_seq_num = p_data->lldp_remote->suffix_seq_num; |
| 329 | } else { |
| 330 | qed_memcpy_from(p_hwfn, p_ptt, p_data->mib, |
| 331 | p_data->addr, p_data->size); |
| 332 | prefix_seq_num = p_data->mib->prefix_seq_num; |
| 333 | suffix_seq_num = p_data->mib->suffix_seq_num; |
| 334 | } |
| 335 | read_count++; |
| 336 | |
| 337 | DP_VERBOSE(p_hwfn, |
| 338 | QED_MSG_DCB, |
| 339 | "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n", |
| 340 | type, read_count, prefix_seq_num, suffix_seq_num); |
| 341 | } while ((prefix_seq_num != suffix_seq_num) && |
| 342 | (read_count < QED_DCBX_MAX_MIB_READ_TRY)); |
| 343 | |
| 344 | if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) { |
| 345 | DP_ERR(p_hwfn, |
| 346 | "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n", |
| 347 | type, read_count, prefix_seq_num, suffix_seq_num); |
| 348 | rc = -EIO; |
| 349 | } |
| 350 | |
| 351 | return rc; |
| 352 | } |
| 353 | |
Sudarsana Reddy Kalluru | 6ad8c63 | 2016-06-08 06:22:10 -0400 | [diff] [blame^] | 354 | #ifdef CONFIG_DCB |
| 355 | static void |
| 356 | qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn, |
| 357 | struct qed_dcbx_app_prio *p_prio, |
| 358 | struct qed_dcbx_results *p_results) |
| 359 | { |
| 360 | u8 val; |
| 361 | |
| 362 | p_prio->roce = QED_DCBX_INVALID_PRIORITY; |
| 363 | p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY; |
| 364 | p_prio->iscsi = QED_DCBX_INVALID_PRIORITY; |
| 365 | p_prio->fcoe = QED_DCBX_INVALID_PRIORITY; |
| 366 | |
| 367 | if (p_results->arr[DCBX_PROTOCOL_ROCE].update && |
| 368 | p_results->arr[DCBX_PROTOCOL_ROCE].enable) |
| 369 | p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority; |
| 370 | |
| 371 | if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update && |
| 372 | p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) { |
| 373 | val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority; |
| 374 | p_prio->roce_v2 = val; |
| 375 | } |
| 376 | |
| 377 | if (p_results->arr[DCBX_PROTOCOL_ISCSI].update && |
| 378 | p_results->arr[DCBX_PROTOCOL_ISCSI].enable) |
| 379 | p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority; |
| 380 | |
| 381 | if (p_results->arr[DCBX_PROTOCOL_FCOE].update && |
| 382 | p_results->arr[DCBX_PROTOCOL_FCOE].enable) |
| 383 | p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority; |
| 384 | |
| 385 | if (p_results->arr[DCBX_PROTOCOL_ETH].update && |
| 386 | p_results->arr[DCBX_PROTOCOL_ETH].enable) |
| 387 | p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority; |
| 388 | |
| 389 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, |
| 390 | "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n", |
| 391 | p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe, |
| 392 | p_prio->eth); |
| 393 | } |
| 394 | |
| 395 | static void |
| 396 | qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn, |
| 397 | struct dcbx_app_priority_feature *p_app, |
| 398 | struct dcbx_app_priority_entry *p_tbl, |
| 399 | struct qed_dcbx_params *p_params) |
| 400 | { |
| 401 | struct qed_app_entry *entry; |
| 402 | u8 pri_map; |
| 403 | int i; |
| 404 | |
| 405 | p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags, |
| 406 | DCBX_APP_WILLING); |
| 407 | p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED); |
| 408 | p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR); |
| 409 | p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags, |
| 410 | DCBX_APP_NUM_ENTRIES); |
| 411 | for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) { |
| 412 | entry = &p_params->app_entry[i]; |
| 413 | entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry, |
| 414 | DCBX_APP_SF)); |
| 415 | pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP); |
| 416 | entry->prio = ffs(pri_map) - 1; |
| 417 | entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry, |
| 418 | DCBX_APP_PROTOCOL_ID); |
| 419 | qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry, |
| 420 | entry->proto_id, |
| 421 | &entry->proto_type); |
| 422 | } |
| 423 | |
| 424 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, |
| 425 | "APP params: willing %d, valid %d error = %d\n", |
| 426 | p_params->app_willing, p_params->app_valid, |
| 427 | p_params->app_error); |
| 428 | } |
| 429 | |
| 430 | static void |
| 431 | qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn, |
| 432 | u32 pfc, struct qed_dcbx_params *p_params) |
| 433 | { |
| 434 | u8 pfc_map; |
| 435 | |
| 436 | p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING); |
| 437 | p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS); |
| 438 | p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED); |
| 439 | pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP); |
| 440 | p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0); |
| 441 | p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1); |
| 442 | p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2); |
| 443 | p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3); |
| 444 | p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4); |
| 445 | p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5); |
| 446 | p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6); |
| 447 | p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7); |
| 448 | |
| 449 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, |
| 450 | "PFC params: willing %d, pfc_bitmap %d\n", |
| 451 | p_params->pfc.willing, pfc_map); |
| 452 | } |
| 453 | |
| 454 | static void |
| 455 | qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn, |
| 456 | struct dcbx_ets_feature *p_ets, |
| 457 | struct qed_dcbx_params *p_params) |
| 458 | { |
| 459 | u32 bw_map[2], tsa_map[2], pri_map; |
| 460 | int i; |
| 461 | |
| 462 | p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags, |
| 463 | DCBX_ETS_WILLING); |
| 464 | p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags, |
| 465 | DCBX_ETS_ENABLED); |
| 466 | p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS); |
| 467 | p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags, |
| 468 | DCBX_ETS_MAX_TCS); |
| 469 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, |
| 470 | "ETS params: willing %d, ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n", |
| 471 | p_params->ets_willing, |
| 472 | p_params->ets_cbs, |
| 473 | p_ets->pri_tc_tbl[0], p_params->max_ets_tc); |
| 474 | |
| 475 | /* 8 bit tsa and bw data corresponding to each of the 8 TC's are |
| 476 | * encoded in a type u32 array of size 2. |
| 477 | */ |
| 478 | bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]); |
| 479 | bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]); |
| 480 | tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]); |
| 481 | tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]); |
| 482 | pri_map = be32_to_cpu(p_ets->pri_tc_tbl[0]); |
| 483 | for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) { |
| 484 | p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i]; |
| 485 | p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i]; |
| 486 | p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i); |
| 487 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, |
| 488 | "elem %d bw_tbl %x tsa_tbl %x\n", |
| 489 | i, p_params->ets_tc_bw_tbl[i], |
| 490 | p_params->ets_tc_tsa_tbl[i]); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | static void |
| 495 | qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn, |
| 496 | struct dcbx_app_priority_feature *p_app, |
| 497 | struct dcbx_app_priority_entry *p_tbl, |
| 498 | struct dcbx_ets_feature *p_ets, |
| 499 | u32 pfc, struct qed_dcbx_params *p_params) |
| 500 | { |
| 501 | qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params); |
| 502 | qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params); |
| 503 | qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params); |
| 504 | } |
| 505 | |
| 506 | static void |
| 507 | qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, |
| 508 | struct qed_ptt *p_ptt, struct qed_dcbx_get *params) |
| 509 | { |
| 510 | struct dcbx_features *p_feat; |
| 511 | |
| 512 | p_feat = &p_hwfn->p_dcbx_info->local_admin.features; |
| 513 | qed_dcbx_get_common_params(p_hwfn, &p_feat->app, |
| 514 | p_feat->app.app_pri_tbl, &p_feat->ets, |
| 515 | p_feat->pfc, ¶ms->local.params); |
| 516 | params->local.valid = true; |
| 517 | } |
| 518 | |
| 519 | static void |
| 520 | qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, |
| 521 | struct qed_ptt *p_ptt, struct qed_dcbx_get *params) |
| 522 | { |
| 523 | struct dcbx_features *p_feat; |
| 524 | |
| 525 | p_feat = &p_hwfn->p_dcbx_info->remote.features; |
| 526 | qed_dcbx_get_common_params(p_hwfn, &p_feat->app, |
| 527 | p_feat->app.app_pri_tbl, &p_feat->ets, |
| 528 | p_feat->pfc, ¶ms->remote.params); |
| 529 | params->remote.valid = true; |
| 530 | } |
| 531 | |
| 532 | static void |
| 533 | qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn, |
| 534 | struct qed_ptt *p_ptt, |
| 535 | struct qed_dcbx_get *params) |
| 536 | { |
| 537 | struct qed_dcbx_operational_params *p_operational; |
| 538 | struct qed_dcbx_results *p_results; |
| 539 | struct dcbx_features *p_feat; |
| 540 | bool enabled, err; |
| 541 | u32 flags; |
| 542 | bool val; |
| 543 | |
| 544 | flags = p_hwfn->p_dcbx_info->operational.flags; |
| 545 | |
| 546 | /* If DCBx version is non zero, then negotiation |
| 547 | * was successfuly performed |
| 548 | */ |
| 549 | p_operational = ¶ms->operational; |
| 550 | enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) != |
| 551 | DCBX_CONFIG_VERSION_DISABLED); |
| 552 | if (!enabled) { |
| 553 | p_operational->enabled = enabled; |
| 554 | p_operational->valid = false; |
| 555 | return; |
| 556 | } |
| 557 | |
| 558 | p_feat = &p_hwfn->p_dcbx_info->operational.features; |
| 559 | p_results = &p_hwfn->p_dcbx_info->results; |
| 560 | |
| 561 | val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) == |
| 562 | DCBX_CONFIG_VERSION_IEEE); |
| 563 | p_operational->ieee = val; |
| 564 | val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) == |
| 565 | DCBX_CONFIG_VERSION_CEE); |
| 566 | p_operational->cee = val; |
| 567 | |
| 568 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Version support: ieee %d, cee %d\n", |
| 569 | p_operational->ieee, p_operational->cee); |
| 570 | |
| 571 | qed_dcbx_get_common_params(p_hwfn, &p_feat->app, |
| 572 | p_feat->app.app_pri_tbl, &p_feat->ets, |
| 573 | p_feat->pfc, ¶ms->operational.params); |
| 574 | qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results); |
| 575 | err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR); |
| 576 | p_operational->err = err; |
| 577 | p_operational->enabled = enabled; |
| 578 | p_operational->valid = true; |
| 579 | } |
| 580 | |
| 581 | static void |
| 582 | qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn, |
| 583 | struct qed_ptt *p_ptt, |
| 584 | struct qed_dcbx_get *params) |
| 585 | { |
| 586 | struct lldp_config_params_s *p_local; |
| 587 | |
| 588 | p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE]; |
| 589 | |
| 590 | memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id, |
| 591 | ARRAY_SIZE(p_local->local_chassis_id)); |
| 592 | memcpy(params->lldp_local.local_port_id, p_local->local_port_id, |
| 593 | ARRAY_SIZE(p_local->local_port_id)); |
| 594 | } |
| 595 | |
| 596 | static void |
| 597 | qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn, |
| 598 | struct qed_ptt *p_ptt, |
| 599 | struct qed_dcbx_get *params) |
| 600 | { |
| 601 | struct lldp_status_params_s *p_remote; |
| 602 | |
| 603 | p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE]; |
| 604 | |
| 605 | memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id, |
| 606 | ARRAY_SIZE(p_remote->peer_chassis_id)); |
| 607 | memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id, |
| 608 | ARRAY_SIZE(p_remote->peer_port_id)); |
| 609 | } |
| 610 | |
| 611 | static int |
| 612 | qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, |
| 613 | struct qed_dcbx_get *p_params, |
| 614 | enum qed_mib_read_type type) |
| 615 | { |
| 616 | switch (type) { |
| 617 | case QED_DCBX_REMOTE_MIB: |
| 618 | qed_dcbx_get_remote_params(p_hwfn, p_ptt, p_params); |
| 619 | break; |
| 620 | case QED_DCBX_LOCAL_MIB: |
| 621 | qed_dcbx_get_local_params(p_hwfn, p_ptt, p_params); |
| 622 | break; |
| 623 | case QED_DCBX_OPERATIONAL_MIB: |
| 624 | qed_dcbx_get_operational_params(p_hwfn, p_ptt, p_params); |
| 625 | break; |
| 626 | case QED_DCBX_REMOTE_LLDP_MIB: |
| 627 | qed_dcbx_get_remote_lldp_params(p_hwfn, p_ptt, p_params); |
| 628 | break; |
| 629 | case QED_DCBX_LOCAL_LLDP_MIB: |
| 630 | qed_dcbx_get_local_lldp_params(p_hwfn, p_ptt, p_params); |
| 631 | break; |
| 632 | default: |
| 633 | DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type); |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | #endif |
| 640 | |
Sudarsana Reddy Kalluru | 39651ab | 2016-05-17 06:44:26 -0400 | [diff] [blame] | 641 | static int |
| 642 | qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 643 | { |
| 644 | struct qed_dcbx_mib_meta_data data; |
| 645 | int rc = 0; |
| 646 | |
| 647 | memset(&data, 0, sizeof(data)); |
| 648 | data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port, |
| 649 | lldp_config_params); |
| 650 | data.lldp_local = p_hwfn->p_dcbx_info->lldp_local; |
| 651 | data.size = sizeof(struct lldp_config_params_s); |
| 652 | qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size); |
| 653 | |
| 654 | return rc; |
| 655 | } |
| 656 | |
| 657 | static int |
| 658 | qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn, |
| 659 | struct qed_ptt *p_ptt, |
| 660 | enum qed_mib_read_type type) |
| 661 | { |
| 662 | struct qed_dcbx_mib_meta_data data; |
| 663 | int rc = 0; |
| 664 | |
| 665 | memset(&data, 0, sizeof(data)); |
| 666 | data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port, |
| 667 | lldp_status_params); |
| 668 | data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote; |
| 669 | data.size = sizeof(struct lldp_status_params_s); |
| 670 | rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type); |
| 671 | |
| 672 | return rc; |
| 673 | } |
| 674 | |
| 675 | static int |
| 676 | qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn, |
| 677 | struct qed_ptt *p_ptt, |
| 678 | enum qed_mib_read_type type) |
| 679 | { |
| 680 | struct qed_dcbx_mib_meta_data data; |
| 681 | int rc = 0; |
| 682 | |
| 683 | memset(&data, 0, sizeof(data)); |
| 684 | data.addr = p_hwfn->mcp_info->port_addr + |
| 685 | offsetof(struct public_port, operational_dcbx_mib); |
| 686 | data.mib = &p_hwfn->p_dcbx_info->operational; |
| 687 | data.size = sizeof(struct dcbx_mib); |
| 688 | rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type); |
| 689 | |
| 690 | return rc; |
| 691 | } |
| 692 | |
| 693 | static int |
| 694 | qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn, |
| 695 | struct qed_ptt *p_ptt, enum qed_mib_read_type type) |
| 696 | { |
| 697 | struct qed_dcbx_mib_meta_data data; |
| 698 | int rc = 0; |
| 699 | |
| 700 | memset(&data, 0, sizeof(data)); |
| 701 | data.addr = p_hwfn->mcp_info->port_addr + |
| 702 | offsetof(struct public_port, remote_dcbx_mib); |
| 703 | data.mib = &p_hwfn->p_dcbx_info->remote; |
| 704 | data.size = sizeof(struct dcbx_mib); |
| 705 | rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type); |
| 706 | |
| 707 | return rc; |
| 708 | } |
| 709 | |
| 710 | static int |
| 711 | qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) |
| 712 | { |
| 713 | struct qed_dcbx_mib_meta_data data; |
| 714 | int rc = 0; |
| 715 | |
| 716 | memset(&data, 0, sizeof(data)); |
| 717 | data.addr = p_hwfn->mcp_info->port_addr + |
| 718 | offsetof(struct public_port, local_admin_dcbx_mib); |
| 719 | data.local_admin = &p_hwfn->p_dcbx_info->local_admin; |
| 720 | data.size = sizeof(struct dcbx_local_params); |
| 721 | qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size); |
| 722 | |
| 723 | return rc; |
| 724 | } |
| 725 | |
| 726 | static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn, |
| 727 | struct qed_ptt *p_ptt, enum qed_mib_read_type type) |
| 728 | { |
| 729 | int rc = -EINVAL; |
| 730 | |
| 731 | switch (type) { |
| 732 | case QED_DCBX_OPERATIONAL_MIB: |
| 733 | rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type); |
| 734 | break; |
| 735 | case QED_DCBX_REMOTE_MIB: |
| 736 | rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type); |
| 737 | break; |
| 738 | case QED_DCBX_LOCAL_MIB: |
| 739 | rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt); |
| 740 | break; |
| 741 | case QED_DCBX_REMOTE_LLDP_MIB: |
| 742 | rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type); |
| 743 | break; |
| 744 | case QED_DCBX_LOCAL_LLDP_MIB: |
| 745 | rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt); |
| 746 | break; |
| 747 | default: |
| 748 | DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type); |
| 749 | } |
| 750 | |
| 751 | return rc; |
| 752 | } |
| 753 | |
| 754 | /* Read updated MIB. |
| 755 | * Reconfigure QM and invoke PF update ramrod command if operational MIB |
| 756 | * change is detected. |
| 757 | */ |
| 758 | int |
| 759 | qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn, |
| 760 | struct qed_ptt *p_ptt, enum qed_mib_read_type type) |
| 761 | { |
| 762 | int rc = 0; |
| 763 | |
| 764 | rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type); |
| 765 | if (rc) |
| 766 | return rc; |
| 767 | |
| 768 | if (type == QED_DCBX_OPERATIONAL_MIB) { |
| 769 | rc = qed_dcbx_process_mib_info(p_hwfn); |
| 770 | if (!rc) { |
| 771 | /* reconfigure tcs of QM queues according |
| 772 | * to negotiation results |
| 773 | */ |
| 774 | qed_qm_reconf(p_hwfn, p_ptt); |
| 775 | |
| 776 | /* update storm FW with negotiation results */ |
| 777 | qed_sp_pf_update(p_hwfn); |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | return rc; |
| 782 | } |
| 783 | |
| 784 | int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn) |
| 785 | { |
| 786 | int rc = 0; |
| 787 | |
| 788 | p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL); |
| 789 | if (!p_hwfn->p_dcbx_info) { |
| 790 | DP_NOTICE(p_hwfn, |
| 791 | "Failed to allocate 'struct qed_dcbx_info'\n"); |
| 792 | rc = -ENOMEM; |
| 793 | } |
| 794 | |
| 795 | return rc; |
| 796 | } |
| 797 | |
| 798 | void qed_dcbx_info_free(struct qed_hwfn *p_hwfn, |
| 799 | struct qed_dcbx_info *p_dcbx_info) |
| 800 | { |
| 801 | kfree(p_hwfn->p_dcbx_info); |
| 802 | } |
| 803 | |
| 804 | static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data, |
| 805 | struct qed_dcbx_results *p_src, |
| 806 | enum dcbx_protocol_type type) |
| 807 | { |
| 808 | p_data->dcb_enable_flag = p_src->arr[type].enable; |
| 809 | p_data->dcb_priority = p_src->arr[type].priority; |
| 810 | p_data->dcb_tc = p_src->arr[type].tc; |
| 811 | } |
| 812 | |
| 813 | /* Set pf update ramrod command params */ |
| 814 | void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src, |
| 815 | struct pf_update_ramrod_data *p_dest) |
| 816 | { |
| 817 | struct protocol_dcb_data *p_dcb_data; |
| 818 | bool update_flag = false; |
| 819 | |
| 820 | p_dest->pf_id = p_src->pf_id; |
| 821 | |
| 822 | update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update; |
| 823 | p_dest->update_fcoe_dcb_data_flag = update_flag; |
| 824 | |
| 825 | update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update; |
| 826 | p_dest->update_roce_dcb_data_flag = update_flag; |
| 827 | update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update; |
| 828 | p_dest->update_roce_dcb_data_flag = update_flag; |
| 829 | |
| 830 | update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update; |
| 831 | p_dest->update_iscsi_dcb_data_flag = update_flag; |
| 832 | update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update; |
| 833 | p_dest->update_eth_dcb_data_flag = update_flag; |
| 834 | |
| 835 | p_dcb_data = &p_dest->fcoe_dcb_data; |
| 836 | qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE); |
| 837 | p_dcb_data = &p_dest->roce_dcb_data; |
| 838 | |
| 839 | if (p_src->arr[DCBX_PROTOCOL_ROCE].update) |
| 840 | qed_dcbx_update_protocol_data(p_dcb_data, p_src, |
| 841 | DCBX_PROTOCOL_ROCE); |
| 842 | if (p_src->arr[DCBX_PROTOCOL_ROCE_V2].update) |
| 843 | qed_dcbx_update_protocol_data(p_dcb_data, p_src, |
| 844 | DCBX_PROTOCOL_ROCE_V2); |
| 845 | |
| 846 | p_dcb_data = &p_dest->iscsi_dcb_data; |
| 847 | qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI); |
| 848 | p_dcb_data = &p_dest->eth_dcb_data; |
| 849 | qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH); |
| 850 | } |
Sudarsana Reddy Kalluru | 6ad8c63 | 2016-06-08 06:22:10 -0400 | [diff] [blame^] | 851 | |
| 852 | #ifdef CONFIG_DCB |
| 853 | static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn, |
| 854 | struct qed_dcbx_get *p_get, |
| 855 | enum qed_mib_read_type type) |
| 856 | { |
| 857 | struct qed_ptt *p_ptt; |
| 858 | int rc; |
| 859 | |
| 860 | p_ptt = qed_ptt_acquire(p_hwfn); |
| 861 | if (!p_ptt) |
| 862 | return -EBUSY; |
| 863 | |
| 864 | rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type); |
| 865 | if (rc) |
| 866 | goto out; |
| 867 | |
| 868 | rc = qed_dcbx_get_params(p_hwfn, p_ptt, p_get, type); |
| 869 | |
| 870 | out: |
| 871 | qed_ptt_release(p_hwfn, p_ptt); |
| 872 | return rc; |
| 873 | } |
| 874 | |
| 875 | static void |
| 876 | qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn, |
| 877 | u32 *pfc, struct qed_dcbx_params *p_params) |
| 878 | { |
| 879 | u8 pfc_map = 0; |
| 880 | int i; |
| 881 | |
| 882 | if (p_params->pfc.willing) |
| 883 | *pfc |= DCBX_PFC_WILLING_MASK; |
| 884 | else |
| 885 | *pfc &= ~DCBX_PFC_WILLING_MASK; |
| 886 | |
| 887 | if (p_params->pfc.enabled) |
| 888 | *pfc |= DCBX_PFC_ENABLED_MASK; |
| 889 | else |
| 890 | *pfc &= ~DCBX_PFC_ENABLED_MASK; |
| 891 | |
| 892 | *pfc &= ~DCBX_PFC_CAPS_MASK; |
| 893 | *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT; |
| 894 | |
| 895 | for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) |
| 896 | if (p_params->pfc.prio[i]) |
| 897 | pfc_map |= BIT(i); |
| 898 | |
| 899 | *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT); |
| 900 | |
| 901 | DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc); |
| 902 | } |
| 903 | |
| 904 | static void |
| 905 | qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn, |
| 906 | struct dcbx_ets_feature *p_ets, |
| 907 | struct qed_dcbx_params *p_params) |
| 908 | { |
| 909 | u8 *bw_map, *tsa_map; |
| 910 | u32 val; |
| 911 | int i; |
| 912 | |
| 913 | if (p_params->ets_willing) |
| 914 | p_ets->flags |= DCBX_ETS_WILLING_MASK; |
| 915 | else |
| 916 | p_ets->flags &= ~DCBX_ETS_WILLING_MASK; |
| 917 | |
| 918 | if (p_params->ets_cbs) |
| 919 | p_ets->flags |= DCBX_ETS_CBS_MASK; |
| 920 | else |
| 921 | p_ets->flags &= ~DCBX_ETS_CBS_MASK; |
| 922 | |
| 923 | if (p_params->ets_enabled) |
| 924 | p_ets->flags |= DCBX_ETS_ENABLED_MASK; |
| 925 | else |
| 926 | p_ets->flags &= ~DCBX_ETS_ENABLED_MASK; |
| 927 | |
| 928 | p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK; |
| 929 | p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT; |
| 930 | |
| 931 | bw_map = (u8 *)&p_ets->tc_bw_tbl[0]; |
| 932 | tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0]; |
| 933 | p_ets->pri_tc_tbl[0] = 0; |
| 934 | for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) { |
| 935 | bw_map[i] = p_params->ets_tc_bw_tbl[i]; |
| 936 | tsa_map[i] = p_params->ets_tc_tsa_tbl[i]; |
| 937 | /* Copy the priority value to the corresponding 4 bits in the |
| 938 | * traffic class table. |
| 939 | */ |
| 940 | val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4)); |
| 941 | p_ets->pri_tc_tbl[0] |= val; |
| 942 | } |
| 943 | p_ets->pri_tc_tbl[0] = cpu_to_be32(p_ets->pri_tc_tbl[0]); |
| 944 | for (i = 0; i < 2; i++) { |
| 945 | p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]); |
| 946 | p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | static void |
| 951 | qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn, |
| 952 | struct dcbx_app_priority_feature *p_app, |
| 953 | struct qed_dcbx_params *p_params) |
| 954 | { |
| 955 | u32 *entry; |
| 956 | int i; |
| 957 | |
| 958 | if (p_params->app_willing) |
| 959 | p_app->flags |= DCBX_APP_WILLING_MASK; |
| 960 | else |
| 961 | p_app->flags &= ~DCBX_APP_WILLING_MASK; |
| 962 | |
| 963 | if (p_params->app_valid) |
| 964 | p_app->flags |= DCBX_APP_ENABLED_MASK; |
| 965 | else |
| 966 | p_app->flags &= ~DCBX_APP_ENABLED_MASK; |
| 967 | |
| 968 | p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK; |
| 969 | p_app->flags |= (u32)p_params->num_app_entries << |
| 970 | DCBX_APP_NUM_ENTRIES_SHIFT; |
| 971 | |
| 972 | for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) { |
| 973 | entry = &p_app->app_pri_tbl[i].entry; |
| 974 | *entry &= ~DCBX_APP_SF_MASK; |
| 975 | if (p_params->app_entry[i].ethtype) |
| 976 | *entry |= ((u32)DCBX_APP_SF_ETHTYPE << |
| 977 | DCBX_APP_SF_SHIFT); |
| 978 | else |
| 979 | *entry |= ((u32)DCBX_APP_SF_PORT << DCBX_APP_SF_SHIFT); |
| 980 | *entry &= ~DCBX_APP_PROTOCOL_ID_MASK; |
| 981 | *entry |= ((u32)p_params->app_entry[i].proto_id << |
| 982 | DCBX_APP_PROTOCOL_ID_SHIFT); |
| 983 | *entry &= ~DCBX_APP_PRI_MAP_MASK; |
| 984 | *entry |= ((u32)(p_params->app_entry[i].prio) << |
| 985 | DCBX_APP_PRI_MAP_SHIFT); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | static void |
| 990 | qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn, |
| 991 | struct dcbx_local_params *local_admin, |
| 992 | struct qed_dcbx_set *params) |
| 993 | { |
| 994 | local_admin->flags = 0; |
| 995 | memcpy(&local_admin->features, |
| 996 | &p_hwfn->p_dcbx_info->operational.features, |
| 997 | sizeof(local_admin->features)); |
| 998 | |
| 999 | if (params->enabled) |
| 1000 | local_admin->config = params->ver_num; |
| 1001 | else |
| 1002 | local_admin->config = DCBX_CONFIG_VERSION_DISABLED; |
| 1003 | |
| 1004 | if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG) |
| 1005 | qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc, |
| 1006 | ¶ms->config.params); |
| 1007 | |
| 1008 | if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG) |
| 1009 | qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets, |
| 1010 | ¶ms->config.params); |
| 1011 | |
| 1012 | if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG) |
| 1013 | qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app, |
| 1014 | ¶ms->config.params); |
| 1015 | } |
| 1016 | |
| 1017 | int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, |
| 1018 | struct qed_dcbx_set *params, bool hw_commit) |
| 1019 | { |
| 1020 | struct dcbx_local_params local_admin; |
| 1021 | struct qed_dcbx_mib_meta_data data; |
| 1022 | u32 resp = 0, param = 0; |
| 1023 | int rc = 0; |
| 1024 | |
| 1025 | if (!hw_commit) { |
| 1026 | memcpy(&p_hwfn->p_dcbx_info->set, params, |
| 1027 | sizeof(struct qed_dcbx_set)); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
| 1031 | /* clear set-parmas cache */ |
| 1032 | memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set)); |
| 1033 | |
| 1034 | memset(&local_admin, 0, sizeof(local_admin)); |
| 1035 | qed_dcbx_set_local_params(p_hwfn, &local_admin, params); |
| 1036 | |
| 1037 | data.addr = p_hwfn->mcp_info->port_addr + |
| 1038 | offsetof(struct public_port, local_admin_dcbx_mib); |
| 1039 | data.local_admin = &local_admin; |
| 1040 | data.size = sizeof(struct dcbx_local_params); |
| 1041 | qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size); |
| 1042 | |
| 1043 | rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX, |
| 1044 | 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, ¶m); |
| 1045 | if (rc) |
| 1046 | DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n"); |
| 1047 | |
| 1048 | return rc; |
| 1049 | } |
| 1050 | |
| 1051 | int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn, |
| 1052 | struct qed_dcbx_set *params) |
| 1053 | { |
| 1054 | struct qed_dcbx_get *dcbx_info; |
| 1055 | int rc; |
| 1056 | |
| 1057 | if (p_hwfn->p_dcbx_info->set.config.valid) { |
| 1058 | memcpy(params, &p_hwfn->p_dcbx_info->set, |
| 1059 | sizeof(struct qed_dcbx_set)); |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | dcbx_info = kmalloc(sizeof(*dcbx_info), GFP_KERNEL); |
| 1064 | if (!dcbx_info) { |
| 1065 | DP_ERR(p_hwfn, "Failed to allocate struct qed_dcbx_info\n"); |
| 1066 | return -ENOMEM; |
| 1067 | } |
| 1068 | |
| 1069 | rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB); |
| 1070 | if (rc) { |
| 1071 | kfree(dcbx_info); |
| 1072 | return rc; |
| 1073 | } |
| 1074 | |
| 1075 | p_hwfn->p_dcbx_info->set.override_flags = 0; |
| 1076 | p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED; |
| 1077 | if (dcbx_info->operational.cee) |
| 1078 | p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE; |
| 1079 | if (dcbx_info->operational.ieee) |
| 1080 | p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE; |
| 1081 | |
| 1082 | p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled; |
| 1083 | memcpy(&p_hwfn->p_dcbx_info->set.config.params, |
| 1084 | &dcbx_info->operational.params, |
| 1085 | sizeof(struct qed_dcbx_admin_params)); |
| 1086 | p_hwfn->p_dcbx_info->set.config.valid = true; |
| 1087 | |
| 1088 | memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set)); |
| 1089 | |
| 1090 | kfree(dcbx_info); |
| 1091 | |
| 1092 | return 0; |
| 1093 | } |
| 1094 | #endif |