1 /* QLogic qed NIC Driver 2 * Copyright (c) 2015-2017 QLogic Corporation 3 * 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. 31 */ 32 33 #include <linux/types.h> 34 #include <asm/byteorder.h> 35 #include <linux/bitops.h> 36 #include <linux/dcbnl.h> 37 #include <linux/errno.h> 38 #include <linux/kernel.h> 39 #include <linux/slab.h> 40 #include <linux/string.h> 41 #include "qed.h" 42 #include "qed_cxt.h" 43 #include "qed_dcbx.h" 44 #include "qed_hsi.h" 45 #include "qed_sp.h" 46 #include "qed_sriov.h" 47 #ifdef CONFIG_DCB 48 #include <linux/qed/qed_eth_if.h> 49 #endif 50 51 #define QED_DCBX_MAX_MIB_READ_TRY (100) 52 #define QED_ETH_TYPE_DEFAULT (0) 53 #define QED_ETH_TYPE_ROCE (0x8915) 54 #define QED_UDP_PORT_TYPE_ROCE_V2 (0x12B7) 55 #define QED_ETH_TYPE_FCOE (0x8906) 56 #define QED_TCP_PORT_ISCSI (0xCBC) 57 58 #define QED_DCBX_INVALID_PRIORITY 0xFF 59 60 /* Get Traffic Class from priority traffic class table, 4 bits represent 61 * the traffic class corresponding to the priority. 62 */ 63 #define QED_DCBX_PRIO2TC(prio_tc_tbl, prio) \ 64 ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7) 65 66 static const struct qed_dcbx_app_metadata qed_dcbx_app_update[] = { 67 {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_DEFAULT}, 68 {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_DEFAULT}, 69 {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_DEFAULT}, 70 {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_DEFAULT}, 71 {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH} 72 }; 73 74 static bool qed_dcbx_app_ethtype(u32 app_info_bitmap) 75 { 76 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) == 77 DCBX_APP_SF_ETHTYPE); 78 } 79 80 static bool qed_dcbx_ieee_app_ethtype(u32 app_info_bitmap) 81 { 82 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE); 83 84 /* Old MFW */ 85 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED) 86 return qed_dcbx_app_ethtype(app_info_bitmap); 87 88 return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE); 89 } 90 91 static bool qed_dcbx_app_port(u32 app_info_bitmap) 92 { 93 return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) == 94 DCBX_APP_SF_PORT); 95 } 96 97 static bool qed_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type) 98 { 99 u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE); 100 101 /* Old MFW */ 102 if (mfw_val == DCBX_APP_SF_IEEE_RESERVED) 103 return qed_dcbx_app_port(app_info_bitmap); 104 105 return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT); 106 } 107 108 static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee) 109 { 110 bool ethtype; 111 112 if (ieee) 113 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap); 114 else 115 ethtype = qed_dcbx_app_ethtype(app_info_bitmap); 116 117 return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT)); 118 } 119 120 static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee) 121 { 122 bool port; 123 124 if (ieee) 125 port = qed_dcbx_ieee_app_port(app_info_bitmap, 126 DCBX_APP_SF_IEEE_TCP_PORT); 127 else 128 port = qed_dcbx_app_port(app_info_bitmap); 129 130 return !!(port && (proto_id == QED_TCP_PORT_ISCSI)); 131 } 132 133 static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee) 134 { 135 bool ethtype; 136 137 if (ieee) 138 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap); 139 else 140 ethtype = qed_dcbx_app_ethtype(app_info_bitmap); 141 142 return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE)); 143 } 144 145 static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee) 146 { 147 bool ethtype; 148 149 if (ieee) 150 ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap); 151 else 152 ethtype = qed_dcbx_app_ethtype(app_info_bitmap); 153 154 return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE)); 155 } 156 157 static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee) 158 { 159 bool port; 160 161 if (ieee) 162 port = qed_dcbx_ieee_app_port(app_info_bitmap, 163 DCBX_APP_SF_IEEE_UDP_PORT); 164 else 165 port = qed_dcbx_app_port(app_info_bitmap); 166 167 return !!(port && (proto_id == QED_UDP_PORT_TYPE_ROCE_V2)); 168 } 169 170 static void 171 qed_dcbx_dp_protocol(struct qed_hwfn *p_hwfn, struct qed_dcbx_results *p_data) 172 { 173 enum dcbx_protocol_type id; 174 int i; 175 176 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "DCBX negotiated: %d\n", 177 p_data->dcbx_enabled); 178 179 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) { 180 id = qed_dcbx_app_update[i].id; 181 182 DP_VERBOSE(p_hwfn, QED_MSG_DCB, 183 "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n", 184 qed_dcbx_app_update[i].name, p_data->arr[id].update, 185 p_data->arr[id].enable, p_data->arr[id].priority, 186 p_data->arr[id].tc, p_hwfn->hw_info.num_tc); 187 } 188 } 189 190 static void 191 qed_dcbx_set_params(struct qed_dcbx_results *p_data, 192 struct qed_hw_info *p_info, 193 bool enable, 194 bool update, 195 u8 prio, 196 u8 tc, 197 enum dcbx_protocol_type type, 198 enum qed_pci_personality personality) 199 { 200 /* PF update ramrod data */ 201 p_data->arr[type].update = update; 202 p_data->arr[type].enable = enable; 203 p_data->arr[type].priority = prio; 204 p_data->arr[type].tc = tc; 205 206 /* QM reconf data */ 207 if (p_info->personality == personality) { 208 if (personality == QED_PCI_ETH) 209 p_info->non_offload_tc = tc; 210 else 211 p_info->offload_tc = tc; 212 } 213 } 214 215 /* Update app protocol data and hw_info fields with the TLV info */ 216 static void 217 qed_dcbx_update_app_info(struct qed_dcbx_results *p_data, 218 struct qed_hwfn *p_hwfn, 219 bool enable, 220 bool update, 221 u8 prio, u8 tc, enum dcbx_protocol_type type) 222 { 223 struct qed_hw_info *p_info = &p_hwfn->hw_info; 224 enum qed_pci_personality personality; 225 enum dcbx_protocol_type id; 226 char *name; 227 int i; 228 229 for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) { 230 id = qed_dcbx_app_update[i].id; 231 232 if (type != id) 233 continue; 234 235 personality = qed_dcbx_app_update[i].personality; 236 name = qed_dcbx_app_update[i].name; 237 238 qed_dcbx_set_params(p_data, p_info, enable, update, 239 prio, tc, type, personality); 240 } 241 } 242 243 static bool 244 qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn, 245 u32 app_prio_bitmap, 246 u16 id, enum dcbx_protocol_type *type, bool ieee) 247 { 248 if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) { 249 *type = DCBX_PROTOCOL_FCOE; 250 } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) { 251 *type = DCBX_PROTOCOL_ROCE; 252 } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) { 253 *type = DCBX_PROTOCOL_ISCSI; 254 } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) { 255 *type = DCBX_PROTOCOL_ETH; 256 } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) { 257 *type = DCBX_PROTOCOL_ROCE_V2; 258 } else { 259 *type = DCBX_MAX_PROTOCOL_TYPE; 260 DP_ERR(p_hwfn, 261 "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n", 262 id, app_prio_bitmap); 263 return false; 264 } 265 266 return true; 267 } 268 269 /* Parse app TLV's to update TC information in hw_info structure for 270 * reconfiguring QM. Get protocol specific data for PF update ramrod command. 271 */ 272 static int 273 qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn, 274 struct qed_dcbx_results *p_data, 275 struct dcbx_app_priority_entry *p_tbl, 276 u32 pri_tc_tbl, int count, u8 dcbx_version) 277 { 278 u8 tc, priority_map; 279 enum dcbx_protocol_type type; 280 bool enable, ieee; 281 u16 protocol_id; 282 int priority; 283 int i; 284 285 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count); 286 287 ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE); 288 /* Parse APP TLV */ 289 for (i = 0; i < count; i++) { 290 protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry, 291 DCBX_APP_PROTOCOL_ID); 292 priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry, 293 DCBX_APP_PRI_MAP); 294 priority = ffs(priority_map) - 1; 295 if (priority < 0) { 296 DP_ERR(p_hwfn, "Invalid priority\n"); 297 return -EINVAL; 298 } 299 300 tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority); 301 if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry, 302 protocol_id, &type, ieee)) { 303 /* ETH always have the enable bit reset, as it gets 304 * vlan information per packet. For other protocols, 305 * should be set according to the dcbx_enabled 306 * indication, but we only got here if there was an 307 * app tlv for the protocol, so dcbx must be enabled. 308 */ 309 enable = !(type == DCBX_PROTOCOL_ETH); 310 311 qed_dcbx_update_app_info(p_data, p_hwfn, enable, true, 312 priority, tc, type); 313 } 314 } 315 316 /* If RoCE-V2 TLV is not detected, driver need to use RoCE app 317 * data for RoCE-v2 not the default app data. 318 */ 319 if (!p_data->arr[DCBX_PROTOCOL_ROCE_V2].update && 320 p_data->arr[DCBX_PROTOCOL_ROCE].update) { 321 tc = p_data->arr[DCBX_PROTOCOL_ROCE].tc; 322 priority = p_data->arr[DCBX_PROTOCOL_ROCE].priority; 323 qed_dcbx_update_app_info(p_data, p_hwfn, true, true, 324 priority, tc, DCBX_PROTOCOL_ROCE_V2); 325 } 326 327 /* Update ramrod protocol data and hw_info fields 328 * with default info when corresponding APP TLV's are not detected. 329 * The enabled field has a different logic for ethernet as only for 330 * ethernet dcb should disabled by default, as the information arrives 331 * from the OS (unless an explicit app tlv was present). 332 */ 333 tc = p_data->arr[DCBX_PROTOCOL_ETH].tc; 334 priority = p_data->arr[DCBX_PROTOCOL_ETH].priority; 335 for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) { 336 if (p_data->arr[type].update) 337 continue; 338 339 enable = !(type == DCBX_PROTOCOL_ETH); 340 qed_dcbx_update_app_info(p_data, p_hwfn, enable, true, 341 priority, tc, type); 342 } 343 344 return 0; 345 } 346 347 /* Parse app TLV's to update TC information in hw_info structure for 348 * reconfiguring QM. Get protocol specific data for PF update ramrod command. 349 */ 350 static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn) 351 { 352 struct dcbx_app_priority_feature *p_app; 353 struct dcbx_app_priority_entry *p_tbl; 354 struct qed_dcbx_results data = { 0 }; 355 struct dcbx_ets_feature *p_ets; 356 struct qed_hw_info *p_info; 357 u32 pri_tc_tbl, flags; 358 u8 dcbx_version; 359 int num_entries; 360 int rc = 0; 361 362 flags = p_hwfn->p_dcbx_info->operational.flags; 363 dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION); 364 365 p_app = &p_hwfn->p_dcbx_info->operational.features.app; 366 p_tbl = p_app->app_pri_tbl; 367 368 p_ets = &p_hwfn->p_dcbx_info->operational.features.ets; 369 pri_tc_tbl = p_ets->pri_tc_tbl[0]; 370 371 p_info = &p_hwfn->hw_info; 372 num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES); 373 374 rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl, 375 num_entries, dcbx_version); 376 if (rc) 377 return rc; 378 379 p_info->num_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS); 380 data.pf_id = p_hwfn->rel_pf_id; 381 data.dcbx_enabled = !!dcbx_version; 382 383 qed_dcbx_dp_protocol(p_hwfn, &data); 384 385 memcpy(&p_hwfn->p_dcbx_info->results, &data, 386 sizeof(struct qed_dcbx_results)); 387 388 return 0; 389 } 390 391 static int 392 qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn, 393 struct qed_ptt *p_ptt, 394 struct qed_dcbx_mib_meta_data *p_data, 395 enum qed_mib_read_type type) 396 { 397 u32 prefix_seq_num, suffix_seq_num; 398 int read_count = 0; 399 int rc = 0; 400 401 /* The data is considered to be valid only if both sequence numbers are 402 * the same. 403 */ 404 do { 405 if (type == QED_DCBX_REMOTE_LLDP_MIB) { 406 qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote, 407 p_data->addr, p_data->size); 408 prefix_seq_num = p_data->lldp_remote->prefix_seq_num; 409 suffix_seq_num = p_data->lldp_remote->suffix_seq_num; 410 } else { 411 qed_memcpy_from(p_hwfn, p_ptt, p_data->mib, 412 p_data->addr, p_data->size); 413 prefix_seq_num = p_data->mib->prefix_seq_num; 414 suffix_seq_num = p_data->mib->suffix_seq_num; 415 } 416 read_count++; 417 418 DP_VERBOSE(p_hwfn, 419 QED_MSG_DCB, 420 "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n", 421 type, read_count, prefix_seq_num, suffix_seq_num); 422 } while ((prefix_seq_num != suffix_seq_num) && 423 (read_count < QED_DCBX_MAX_MIB_READ_TRY)); 424 425 if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) { 426 DP_ERR(p_hwfn, 427 "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n", 428 type, read_count, prefix_seq_num, suffix_seq_num); 429 rc = -EIO; 430 } 431 432 return rc; 433 } 434 435 static void 436 qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn, 437 struct qed_dcbx_app_prio *p_prio, 438 struct qed_dcbx_results *p_results) 439 { 440 u8 val; 441 442 p_prio->roce = QED_DCBX_INVALID_PRIORITY; 443 p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY; 444 p_prio->iscsi = QED_DCBX_INVALID_PRIORITY; 445 p_prio->fcoe = QED_DCBX_INVALID_PRIORITY; 446 447 if (p_results->arr[DCBX_PROTOCOL_ROCE].update && 448 p_results->arr[DCBX_PROTOCOL_ROCE].enable) 449 p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority; 450 451 if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update && 452 p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) { 453 val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority; 454 p_prio->roce_v2 = val; 455 } 456 457 if (p_results->arr[DCBX_PROTOCOL_ISCSI].update && 458 p_results->arr[DCBX_PROTOCOL_ISCSI].enable) 459 p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority; 460 461 if (p_results->arr[DCBX_PROTOCOL_FCOE].update && 462 p_results->arr[DCBX_PROTOCOL_FCOE].enable) 463 p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority; 464 465 if (p_results->arr[DCBX_PROTOCOL_ETH].update && 466 p_results->arr[DCBX_PROTOCOL_ETH].enable) 467 p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority; 468 469 DP_VERBOSE(p_hwfn, QED_MSG_DCB, 470 "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n", 471 p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe, 472 p_prio->eth); 473 } 474 475 static void 476 qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn, 477 struct dcbx_app_priority_feature *p_app, 478 struct dcbx_app_priority_entry *p_tbl, 479 struct qed_dcbx_params *p_params, bool ieee) 480 { 481 struct qed_app_entry *entry; 482 u8 pri_map; 483 int i; 484 485 p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags, 486 DCBX_APP_WILLING); 487 p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED); 488 p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR); 489 p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags, 490 DCBX_APP_NUM_ENTRIES); 491 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) { 492 entry = &p_params->app_entry[i]; 493 if (ieee) { 494 u8 sf_ieee; 495 u32 val; 496 497 sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry, 498 DCBX_APP_SF_IEEE); 499 switch (sf_ieee) { 500 case DCBX_APP_SF_IEEE_RESERVED: 501 /* Old MFW */ 502 val = QED_MFW_GET_FIELD(p_tbl[i].entry, 503 DCBX_APP_SF); 504 entry->sf_ieee = val ? 505 QED_DCBX_SF_IEEE_TCP_UDP_PORT : 506 QED_DCBX_SF_IEEE_ETHTYPE; 507 break; 508 case DCBX_APP_SF_IEEE_ETHTYPE: 509 entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE; 510 break; 511 case DCBX_APP_SF_IEEE_TCP_PORT: 512 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT; 513 break; 514 case DCBX_APP_SF_IEEE_UDP_PORT: 515 entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT; 516 break; 517 case DCBX_APP_SF_IEEE_TCP_UDP_PORT: 518 entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT; 519 break; 520 } 521 } else { 522 entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry, 523 DCBX_APP_SF)); 524 } 525 526 pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP); 527 entry->prio = ffs(pri_map) - 1; 528 entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry, 529 DCBX_APP_PROTOCOL_ID); 530 qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry, 531 entry->proto_id, 532 &entry->proto_type, ieee); 533 } 534 535 DP_VERBOSE(p_hwfn, QED_MSG_DCB, 536 "APP params: willing %d, valid %d error = %d\n", 537 p_params->app_willing, p_params->app_valid, 538 p_params->app_error); 539 } 540 541 static void 542 qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn, 543 u32 pfc, struct qed_dcbx_params *p_params) 544 { 545 u8 pfc_map; 546 547 p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING); 548 p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS); 549 p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED); 550 pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP); 551 p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0); 552 p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1); 553 p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2); 554 p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3); 555 p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4); 556 p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5); 557 p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6); 558 p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7); 559 560 DP_VERBOSE(p_hwfn, QED_MSG_DCB, 561 "PFC params: willing %d, pfc_bitmap %d\n", 562 p_params->pfc.willing, pfc_map); 563 } 564 565 static void 566 qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn, 567 struct dcbx_ets_feature *p_ets, 568 struct qed_dcbx_params *p_params) 569 { 570 u32 bw_map[2], tsa_map[2], pri_map; 571 int i; 572 573 p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags, 574 DCBX_ETS_WILLING); 575 p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags, 576 DCBX_ETS_ENABLED); 577 p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS); 578 p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags, 579 DCBX_ETS_MAX_TCS); 580 DP_VERBOSE(p_hwfn, QED_MSG_DCB, 581 "ETS params: willing %d, ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n", 582 p_params->ets_willing, 583 p_params->ets_cbs, 584 p_ets->pri_tc_tbl[0], p_params->max_ets_tc); 585 586 /* 8 bit tsa and bw data corresponding to each of the 8 TC's are 587 * encoded in a type u32 array of size 2. 588 */ 589 bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]); 590 bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]); 591 tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]); 592 tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]); 593 pri_map = p_ets->pri_tc_tbl[0]; 594 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) { 595 p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i]; 596 p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i]; 597 p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i); 598 DP_VERBOSE(p_hwfn, QED_MSG_DCB, 599 "elem %d bw_tbl %x tsa_tbl %x\n", 600 i, p_params->ets_tc_bw_tbl[i], 601 p_params->ets_tc_tsa_tbl[i]); 602 } 603 } 604 605 static void 606 qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn, 607 struct dcbx_app_priority_feature *p_app, 608 struct dcbx_app_priority_entry *p_tbl, 609 struct dcbx_ets_feature *p_ets, 610 u32 pfc, struct qed_dcbx_params *p_params, bool ieee) 611 { 612 qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee); 613 qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params); 614 qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params); 615 } 616 617 static void 618 qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, 619 struct qed_ptt *p_ptt, struct qed_dcbx_get *params) 620 { 621 struct dcbx_features *p_feat; 622 623 p_feat = &p_hwfn->p_dcbx_info->local_admin.features; 624 qed_dcbx_get_common_params(p_hwfn, &p_feat->app, 625 p_feat->app.app_pri_tbl, &p_feat->ets, 626 p_feat->pfc, ¶ms->local.params, false); 627 params->local.valid = true; 628 } 629 630 static void 631 qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, 632 struct qed_ptt *p_ptt, struct qed_dcbx_get *params) 633 { 634 struct dcbx_features *p_feat; 635 636 p_feat = &p_hwfn->p_dcbx_info->remote.features; 637 qed_dcbx_get_common_params(p_hwfn, &p_feat->app, 638 p_feat->app.app_pri_tbl, &p_feat->ets, 639 p_feat->pfc, ¶ms->remote.params, false); 640 params->remote.valid = true; 641 } 642 643 static void 644 qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn, 645 struct qed_ptt *p_ptt, 646 struct qed_dcbx_get *params) 647 { 648 struct qed_dcbx_operational_params *p_operational; 649 struct qed_dcbx_results *p_results; 650 struct dcbx_features *p_feat; 651 bool enabled, err; 652 u32 flags; 653 bool val; 654 655 flags = p_hwfn->p_dcbx_info->operational.flags; 656 657 /* If DCBx version is non zero, then negotiation 658 * was successfuly performed 659 */ 660 p_operational = ¶ms->operational; 661 enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) != 662 DCBX_CONFIG_VERSION_DISABLED); 663 if (!enabled) { 664 p_operational->enabled = enabled; 665 p_operational->valid = false; 666 return; 667 } 668 669 p_feat = &p_hwfn->p_dcbx_info->operational.features; 670 p_results = &p_hwfn->p_dcbx_info->results; 671 672 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) == 673 DCBX_CONFIG_VERSION_IEEE); 674 p_operational->ieee = val; 675 val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) == 676 DCBX_CONFIG_VERSION_CEE); 677 p_operational->cee = val; 678 679 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Version support: ieee %d, cee %d\n", 680 p_operational->ieee, p_operational->cee); 681 682 qed_dcbx_get_common_params(p_hwfn, &p_feat->app, 683 p_feat->app.app_pri_tbl, &p_feat->ets, 684 p_feat->pfc, ¶ms->operational.params, 685 p_operational->ieee); 686 qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results); 687 err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR); 688 p_operational->err = err; 689 p_operational->enabled = enabled; 690 p_operational->valid = true; 691 } 692 693 static void 694 qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn, 695 struct qed_ptt *p_ptt, 696 struct qed_dcbx_get *params) 697 { 698 struct lldp_config_params_s *p_local; 699 700 p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE]; 701 702 memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id, 703 ARRAY_SIZE(p_local->local_chassis_id)); 704 memcpy(params->lldp_local.local_port_id, p_local->local_port_id, 705 ARRAY_SIZE(p_local->local_port_id)); 706 } 707 708 static void 709 qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn, 710 struct qed_ptt *p_ptt, 711 struct qed_dcbx_get *params) 712 { 713 struct lldp_status_params_s *p_remote; 714 715 p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE]; 716 717 memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id, 718 ARRAY_SIZE(p_remote->peer_chassis_id)); 719 memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id, 720 ARRAY_SIZE(p_remote->peer_port_id)); 721 } 722 723 static int 724 qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, 725 struct qed_dcbx_get *p_params, 726 enum qed_mib_read_type type) 727 { 728 switch (type) { 729 case QED_DCBX_REMOTE_MIB: 730 qed_dcbx_get_remote_params(p_hwfn, p_ptt, p_params); 731 break; 732 case QED_DCBX_LOCAL_MIB: 733 qed_dcbx_get_local_params(p_hwfn, p_ptt, p_params); 734 break; 735 case QED_DCBX_OPERATIONAL_MIB: 736 qed_dcbx_get_operational_params(p_hwfn, p_ptt, p_params); 737 break; 738 case QED_DCBX_REMOTE_LLDP_MIB: 739 qed_dcbx_get_remote_lldp_params(p_hwfn, p_ptt, p_params); 740 break; 741 case QED_DCBX_LOCAL_LLDP_MIB: 742 qed_dcbx_get_local_lldp_params(p_hwfn, p_ptt, p_params); 743 break; 744 default: 745 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type); 746 return -EINVAL; 747 } 748 749 return 0; 750 } 751 752 static int 753 qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 754 { 755 struct qed_dcbx_mib_meta_data data; 756 int rc = 0; 757 758 memset(&data, 0, sizeof(data)); 759 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port, 760 lldp_config_params); 761 data.lldp_local = p_hwfn->p_dcbx_info->lldp_local; 762 data.size = sizeof(struct lldp_config_params_s); 763 qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size); 764 765 return rc; 766 } 767 768 static int 769 qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn, 770 struct qed_ptt *p_ptt, 771 enum qed_mib_read_type type) 772 { 773 struct qed_dcbx_mib_meta_data data; 774 int rc = 0; 775 776 memset(&data, 0, sizeof(data)); 777 data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port, 778 lldp_status_params); 779 data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote; 780 data.size = sizeof(struct lldp_status_params_s); 781 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type); 782 783 return rc; 784 } 785 786 static int 787 qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn, 788 struct qed_ptt *p_ptt, 789 enum qed_mib_read_type type) 790 { 791 struct qed_dcbx_mib_meta_data data; 792 int rc = 0; 793 794 memset(&data, 0, sizeof(data)); 795 data.addr = p_hwfn->mcp_info->port_addr + 796 offsetof(struct public_port, operational_dcbx_mib); 797 data.mib = &p_hwfn->p_dcbx_info->operational; 798 data.size = sizeof(struct dcbx_mib); 799 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type); 800 801 return rc; 802 } 803 804 static int 805 qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn, 806 struct qed_ptt *p_ptt, enum qed_mib_read_type type) 807 { 808 struct qed_dcbx_mib_meta_data data; 809 int rc = 0; 810 811 memset(&data, 0, sizeof(data)); 812 data.addr = p_hwfn->mcp_info->port_addr + 813 offsetof(struct public_port, remote_dcbx_mib); 814 data.mib = &p_hwfn->p_dcbx_info->remote; 815 data.size = sizeof(struct dcbx_mib); 816 rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type); 817 818 return rc; 819 } 820 821 static int 822 qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) 823 { 824 struct qed_dcbx_mib_meta_data data; 825 int rc = 0; 826 827 memset(&data, 0, sizeof(data)); 828 data.addr = p_hwfn->mcp_info->port_addr + 829 offsetof(struct public_port, local_admin_dcbx_mib); 830 data.local_admin = &p_hwfn->p_dcbx_info->local_admin; 831 data.size = sizeof(struct dcbx_local_params); 832 qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size); 833 834 return rc; 835 } 836 837 static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn, 838 struct qed_ptt *p_ptt, enum qed_mib_read_type type) 839 { 840 int rc = -EINVAL; 841 842 switch (type) { 843 case QED_DCBX_OPERATIONAL_MIB: 844 rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type); 845 break; 846 case QED_DCBX_REMOTE_MIB: 847 rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type); 848 break; 849 case QED_DCBX_LOCAL_MIB: 850 rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt); 851 break; 852 case QED_DCBX_REMOTE_LLDP_MIB: 853 rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type); 854 break; 855 case QED_DCBX_LOCAL_LLDP_MIB: 856 rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt); 857 break; 858 default: 859 DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type); 860 } 861 862 return rc; 863 } 864 865 void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type) 866 { 867 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common; 868 void *cookie = hwfn->cdev->ops_cookie; 869 870 if (cookie && op->dcbx_aen) 871 op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type); 872 } 873 874 /* Read updated MIB. 875 * Reconfigure QM and invoke PF update ramrod command if operational MIB 876 * change is detected. 877 */ 878 int 879 qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn, 880 struct qed_ptt *p_ptt, enum qed_mib_read_type type) 881 { 882 int rc = 0; 883 884 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type); 885 if (rc) 886 return rc; 887 888 if (type == QED_DCBX_OPERATIONAL_MIB) { 889 rc = qed_dcbx_process_mib_info(p_hwfn); 890 if (!rc) { 891 /* reconfigure tcs of QM queues according 892 * to negotiation results 893 */ 894 qed_qm_reconf(p_hwfn, p_ptt); 895 896 /* update storm FW with negotiation results */ 897 qed_sp_pf_update(p_hwfn); 898 } 899 } 900 qed_dcbx_get_params(p_hwfn, p_ptt, &p_hwfn->p_dcbx_info->get, type); 901 qed_dcbx_aen(p_hwfn, type); 902 903 return rc; 904 } 905 906 int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn) 907 { 908 int rc = 0; 909 910 p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL); 911 if (!p_hwfn->p_dcbx_info) 912 rc = -ENOMEM; 913 914 return rc; 915 } 916 917 void qed_dcbx_info_free(struct qed_hwfn *p_hwfn, 918 struct qed_dcbx_info *p_dcbx_info) 919 { 920 kfree(p_hwfn->p_dcbx_info); 921 } 922 923 static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data, 924 struct qed_dcbx_results *p_src, 925 enum dcbx_protocol_type type) 926 { 927 p_data->dcb_enable_flag = p_src->arr[type].enable; 928 p_data->dcb_priority = p_src->arr[type].priority; 929 p_data->dcb_tc = p_src->arr[type].tc; 930 } 931 932 /* Set pf update ramrod command params */ 933 void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src, 934 struct pf_update_ramrod_data *p_dest) 935 { 936 struct protocol_dcb_data *p_dcb_data; 937 bool update_flag = false; 938 939 p_dest->pf_id = p_src->pf_id; 940 941 update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update; 942 p_dest->update_fcoe_dcb_data_flag = update_flag; 943 944 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update; 945 p_dest->update_roce_dcb_data_flag = update_flag; 946 update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update; 947 p_dest->update_roce_dcb_data_flag = update_flag; 948 949 update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update; 950 p_dest->update_iscsi_dcb_data_flag = update_flag; 951 update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update; 952 p_dest->update_eth_dcb_data_flag = update_flag; 953 954 p_dcb_data = &p_dest->fcoe_dcb_data; 955 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE); 956 p_dcb_data = &p_dest->roce_dcb_data; 957 958 if (p_src->arr[DCBX_PROTOCOL_ROCE].update) 959 qed_dcbx_update_protocol_data(p_dcb_data, p_src, 960 DCBX_PROTOCOL_ROCE); 961 if (p_src->arr[DCBX_PROTOCOL_ROCE_V2].update) 962 qed_dcbx_update_protocol_data(p_dcb_data, p_src, 963 DCBX_PROTOCOL_ROCE_V2); 964 965 p_dcb_data = &p_dest->iscsi_dcb_data; 966 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI); 967 p_dcb_data = &p_dest->eth_dcb_data; 968 qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH); 969 } 970 971 #ifdef CONFIG_DCB 972 static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn, 973 struct qed_dcbx_get *p_get, 974 enum qed_mib_read_type type) 975 { 976 struct qed_ptt *p_ptt; 977 int rc; 978 979 if (IS_VF(p_hwfn->cdev)) 980 return -EINVAL; 981 982 p_ptt = qed_ptt_acquire(p_hwfn); 983 if (!p_ptt) 984 return -EBUSY; 985 986 rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type); 987 if (rc) 988 goto out; 989 990 rc = qed_dcbx_get_params(p_hwfn, p_ptt, p_get, type); 991 992 out: 993 qed_ptt_release(p_hwfn, p_ptt); 994 return rc; 995 } 996 997 static void 998 qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn, 999 u32 *pfc, struct qed_dcbx_params *p_params) 1000 { 1001 u8 pfc_map = 0; 1002 int i; 1003 1004 if (p_params->pfc.willing) 1005 *pfc |= DCBX_PFC_WILLING_MASK; 1006 else 1007 *pfc &= ~DCBX_PFC_WILLING_MASK; 1008 1009 if (p_params->pfc.enabled) 1010 *pfc |= DCBX_PFC_ENABLED_MASK; 1011 else 1012 *pfc &= ~DCBX_PFC_ENABLED_MASK; 1013 1014 *pfc &= ~DCBX_PFC_CAPS_MASK; 1015 *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT; 1016 1017 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) 1018 if (p_params->pfc.prio[i]) 1019 pfc_map |= BIT(i); 1020 1021 *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK; 1022 *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT); 1023 1024 DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc); 1025 } 1026 1027 static void 1028 qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn, 1029 struct dcbx_ets_feature *p_ets, 1030 struct qed_dcbx_params *p_params) 1031 { 1032 u8 *bw_map, *tsa_map; 1033 u32 val; 1034 int i; 1035 1036 if (p_params->ets_willing) 1037 p_ets->flags |= DCBX_ETS_WILLING_MASK; 1038 else 1039 p_ets->flags &= ~DCBX_ETS_WILLING_MASK; 1040 1041 if (p_params->ets_cbs) 1042 p_ets->flags |= DCBX_ETS_CBS_MASK; 1043 else 1044 p_ets->flags &= ~DCBX_ETS_CBS_MASK; 1045 1046 if (p_params->ets_enabled) 1047 p_ets->flags |= DCBX_ETS_ENABLED_MASK; 1048 else 1049 p_ets->flags &= ~DCBX_ETS_ENABLED_MASK; 1050 1051 p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK; 1052 p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT; 1053 1054 bw_map = (u8 *)&p_ets->tc_bw_tbl[0]; 1055 tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0]; 1056 p_ets->pri_tc_tbl[0] = 0; 1057 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) { 1058 bw_map[i] = p_params->ets_tc_bw_tbl[i]; 1059 tsa_map[i] = p_params->ets_tc_tsa_tbl[i]; 1060 /* Copy the priority value to the corresponding 4 bits in the 1061 * traffic class table. 1062 */ 1063 val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4)); 1064 p_ets->pri_tc_tbl[0] |= val; 1065 } 1066 for (i = 0; i < 2; i++) { 1067 p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]); 1068 p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]); 1069 } 1070 } 1071 1072 static void 1073 qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn, 1074 struct dcbx_app_priority_feature *p_app, 1075 struct qed_dcbx_params *p_params, bool ieee) 1076 { 1077 u32 *entry; 1078 int i; 1079 1080 if (p_params->app_willing) 1081 p_app->flags |= DCBX_APP_WILLING_MASK; 1082 else 1083 p_app->flags &= ~DCBX_APP_WILLING_MASK; 1084 1085 if (p_params->app_valid) 1086 p_app->flags |= DCBX_APP_ENABLED_MASK; 1087 else 1088 p_app->flags &= ~DCBX_APP_ENABLED_MASK; 1089 1090 p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK; 1091 p_app->flags |= (u32)p_params->num_app_entries << 1092 DCBX_APP_NUM_ENTRIES_SHIFT; 1093 1094 for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) { 1095 entry = &p_app->app_pri_tbl[i].entry; 1096 *entry = 0; 1097 if (ieee) { 1098 *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK); 1099 switch (p_params->app_entry[i].sf_ieee) { 1100 case QED_DCBX_SF_IEEE_ETHTYPE: 1101 *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE << 1102 DCBX_APP_SF_IEEE_SHIFT); 1103 *entry |= ((u32)DCBX_APP_SF_ETHTYPE << 1104 DCBX_APP_SF_SHIFT); 1105 break; 1106 case QED_DCBX_SF_IEEE_TCP_PORT: 1107 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT << 1108 DCBX_APP_SF_IEEE_SHIFT); 1109 *entry |= ((u32)DCBX_APP_SF_PORT << 1110 DCBX_APP_SF_SHIFT); 1111 break; 1112 case QED_DCBX_SF_IEEE_UDP_PORT: 1113 *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT << 1114 DCBX_APP_SF_IEEE_SHIFT); 1115 *entry |= ((u32)DCBX_APP_SF_PORT << 1116 DCBX_APP_SF_SHIFT); 1117 break; 1118 case QED_DCBX_SF_IEEE_TCP_UDP_PORT: 1119 *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT << 1120 DCBX_APP_SF_IEEE_SHIFT); 1121 *entry |= ((u32)DCBX_APP_SF_PORT << 1122 DCBX_APP_SF_SHIFT); 1123 break; 1124 } 1125 } else { 1126 *entry &= ~DCBX_APP_SF_MASK; 1127 if (p_params->app_entry[i].ethtype) 1128 *entry |= ((u32)DCBX_APP_SF_ETHTYPE << 1129 DCBX_APP_SF_SHIFT); 1130 else 1131 *entry |= ((u32)DCBX_APP_SF_PORT << 1132 DCBX_APP_SF_SHIFT); 1133 } 1134 1135 *entry &= ~DCBX_APP_PROTOCOL_ID_MASK; 1136 *entry |= ((u32)p_params->app_entry[i].proto_id << 1137 DCBX_APP_PROTOCOL_ID_SHIFT); 1138 *entry &= ~DCBX_APP_PRI_MAP_MASK; 1139 *entry |= ((u32)(p_params->app_entry[i].prio) << 1140 DCBX_APP_PRI_MAP_SHIFT); 1141 } 1142 } 1143 1144 static void 1145 qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn, 1146 struct dcbx_local_params *local_admin, 1147 struct qed_dcbx_set *params) 1148 { 1149 bool ieee = false; 1150 1151 local_admin->flags = 0; 1152 memcpy(&local_admin->features, 1153 &p_hwfn->p_dcbx_info->operational.features, 1154 sizeof(local_admin->features)); 1155 1156 if (params->enabled) { 1157 local_admin->config = params->ver_num; 1158 ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE); 1159 } else { 1160 local_admin->config = DCBX_CONFIG_VERSION_DISABLED; 1161 } 1162 1163 if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG) 1164 qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc, 1165 ¶ms->config.params); 1166 1167 if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG) 1168 qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets, 1169 ¶ms->config.params); 1170 1171 if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG) 1172 qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app, 1173 ¶ms->config.params, ieee); 1174 } 1175 1176 int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, 1177 struct qed_dcbx_set *params, bool hw_commit) 1178 { 1179 struct dcbx_local_params local_admin; 1180 struct qed_dcbx_mib_meta_data data; 1181 u32 resp = 0, param = 0; 1182 int rc = 0; 1183 1184 if (!hw_commit) { 1185 memcpy(&p_hwfn->p_dcbx_info->set, params, 1186 sizeof(struct qed_dcbx_set)); 1187 return 0; 1188 } 1189 1190 /* clear set-parmas cache */ 1191 memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set)); 1192 1193 memset(&local_admin, 0, sizeof(local_admin)); 1194 qed_dcbx_set_local_params(p_hwfn, &local_admin, params); 1195 1196 data.addr = p_hwfn->mcp_info->port_addr + 1197 offsetof(struct public_port, local_admin_dcbx_mib); 1198 data.local_admin = &local_admin; 1199 data.size = sizeof(struct dcbx_local_params); 1200 qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size); 1201 1202 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX, 1203 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, ¶m); 1204 if (rc) 1205 DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n"); 1206 1207 return rc; 1208 } 1209 1210 int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn, 1211 struct qed_dcbx_set *params) 1212 { 1213 struct qed_dcbx_get *dcbx_info; 1214 int rc; 1215 1216 if (p_hwfn->p_dcbx_info->set.config.valid) { 1217 memcpy(params, &p_hwfn->p_dcbx_info->set, 1218 sizeof(struct qed_dcbx_set)); 1219 return 0; 1220 } 1221 1222 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL); 1223 if (!dcbx_info) 1224 return -ENOMEM; 1225 1226 memset(dcbx_info, 0, sizeof(*dcbx_info)); 1227 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB); 1228 if (rc) { 1229 kfree(dcbx_info); 1230 return rc; 1231 } 1232 1233 p_hwfn->p_dcbx_info->set.override_flags = 0; 1234 p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED; 1235 if (dcbx_info->operational.cee) 1236 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE; 1237 if (dcbx_info->operational.ieee) 1238 p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE; 1239 1240 p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled; 1241 memcpy(&p_hwfn->p_dcbx_info->set.config.params, 1242 &dcbx_info->operational.params, 1243 sizeof(struct qed_dcbx_admin_params)); 1244 p_hwfn->p_dcbx_info->set.config.valid = true; 1245 1246 memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set)); 1247 1248 kfree(dcbx_info); 1249 1250 return 0; 1251 } 1252 1253 static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn, 1254 enum qed_mib_read_type type) 1255 { 1256 struct qed_dcbx_get *dcbx_info; 1257 1258 dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL); 1259 if (!dcbx_info) 1260 return NULL; 1261 1262 memset(dcbx_info, 0, sizeof(*dcbx_info)); 1263 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) { 1264 kfree(dcbx_info); 1265 return NULL; 1266 } 1267 1268 if ((type == QED_DCBX_OPERATIONAL_MIB) && 1269 !dcbx_info->operational.enabled) { 1270 DP_INFO(hwfn, "DCBX is not enabled/operational\n"); 1271 kfree(dcbx_info); 1272 return NULL; 1273 } 1274 1275 return dcbx_info; 1276 } 1277 1278 static u8 qed_dcbnl_getstate(struct qed_dev *cdev) 1279 { 1280 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1281 struct qed_dcbx_get *dcbx_info; 1282 bool enabled; 1283 1284 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1285 if (!dcbx_info) 1286 return 0; 1287 1288 enabled = dcbx_info->operational.enabled; 1289 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled); 1290 kfree(dcbx_info); 1291 1292 return enabled; 1293 } 1294 1295 static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state) 1296 { 1297 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1298 struct qed_dcbx_set dcbx_set; 1299 struct qed_ptt *ptt; 1300 int rc; 1301 1302 DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state); 1303 1304 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1305 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1306 if (rc) 1307 return 1; 1308 1309 dcbx_set.enabled = !!state; 1310 1311 ptt = qed_ptt_acquire(hwfn); 1312 if (!ptt) 1313 return 1; 1314 1315 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1316 1317 qed_ptt_release(hwfn, ptt); 1318 1319 return rc ? 1 : 0; 1320 } 1321 1322 static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type, 1323 u8 *pgid, u8 *bw_pct, u8 *up_map) 1324 { 1325 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1326 struct qed_dcbx_get *dcbx_info; 1327 1328 DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc); 1329 *prio_type = *pgid = *bw_pct = *up_map = 0; 1330 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) { 1331 DP_INFO(hwfn, "Invalid tc %d\n", tc); 1332 return; 1333 } 1334 1335 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1336 if (!dcbx_info) 1337 return; 1338 1339 *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc]; 1340 kfree(dcbx_info); 1341 } 1342 1343 static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct) 1344 { 1345 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1346 struct qed_dcbx_get *dcbx_info; 1347 1348 *bw_pct = 0; 1349 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid); 1350 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) { 1351 DP_INFO(hwfn, "Invalid pgid %d\n", pgid); 1352 return; 1353 } 1354 1355 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1356 if (!dcbx_info) 1357 return; 1358 1359 *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid]; 1360 DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct); 1361 kfree(dcbx_info); 1362 } 1363 1364 static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio, 1365 u8 *bwg_id, u8 *bw_pct, u8 *up_map) 1366 { 1367 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n"); 1368 *prio = *bwg_id = *bw_pct = *up_map = 0; 1369 } 1370 1371 static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev, 1372 int bwg_id, u8 *bw_pct) 1373 { 1374 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n"); 1375 *bw_pct = 0; 1376 } 1377 1378 static void qed_dcbnl_getpfccfg(struct qed_dev *cdev, 1379 int priority, u8 *setting) 1380 { 1381 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1382 struct qed_dcbx_get *dcbx_info; 1383 1384 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority); 1385 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) { 1386 DP_INFO(hwfn, "Invalid priority %d\n", priority); 1387 return; 1388 } 1389 1390 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1391 if (!dcbx_info) 1392 return; 1393 1394 *setting = dcbx_info->operational.params.pfc.prio[priority]; 1395 DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting); 1396 kfree(dcbx_info); 1397 } 1398 1399 static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting) 1400 { 1401 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1402 struct qed_dcbx_set dcbx_set; 1403 struct qed_ptt *ptt; 1404 int rc; 1405 1406 DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n", 1407 priority, setting); 1408 if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) { 1409 DP_INFO(hwfn, "Invalid priority %d\n", priority); 1410 return; 1411 } 1412 1413 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1414 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1415 if (rc) 1416 return; 1417 1418 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG; 1419 dcbx_set.config.params.pfc.prio[priority] = !!setting; 1420 1421 ptt = qed_ptt_acquire(hwfn); 1422 if (!ptt) 1423 return; 1424 1425 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1426 1427 qed_ptt_release(hwfn, ptt); 1428 } 1429 1430 static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap) 1431 { 1432 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1433 struct qed_dcbx_get *dcbx_info; 1434 int rc = 0; 1435 1436 DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid); 1437 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1438 if (!dcbx_info) 1439 return 1; 1440 1441 switch (capid) { 1442 case DCB_CAP_ATTR_PG: 1443 case DCB_CAP_ATTR_PFC: 1444 case DCB_CAP_ATTR_UP2TC: 1445 case DCB_CAP_ATTR_GSP: 1446 *cap = true; 1447 break; 1448 case DCB_CAP_ATTR_PG_TCS: 1449 case DCB_CAP_ATTR_PFC_TCS: 1450 *cap = 0x80; 1451 break; 1452 case DCB_CAP_ATTR_DCBX: 1453 *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE | 1454 DCB_CAP_DCBX_VER_IEEE); 1455 break; 1456 default: 1457 *cap = false; 1458 rc = 1; 1459 } 1460 1461 DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap); 1462 kfree(dcbx_info); 1463 1464 return rc; 1465 } 1466 1467 static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num) 1468 { 1469 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1470 struct qed_dcbx_get *dcbx_info; 1471 int rc = 0; 1472 1473 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid); 1474 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1475 if (!dcbx_info) 1476 return -EINVAL; 1477 1478 switch (tcid) { 1479 case DCB_NUMTCS_ATTR_PG: 1480 *num = dcbx_info->operational.params.max_ets_tc; 1481 break; 1482 case DCB_NUMTCS_ATTR_PFC: 1483 *num = dcbx_info->operational.params.pfc.max_tc; 1484 break; 1485 default: 1486 rc = -EINVAL; 1487 } 1488 1489 kfree(dcbx_info); 1490 DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num); 1491 1492 return rc; 1493 } 1494 1495 static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev) 1496 { 1497 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1498 struct qed_dcbx_get *dcbx_info; 1499 bool enabled; 1500 1501 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1502 if (!dcbx_info) 1503 return 0; 1504 1505 enabled = dcbx_info->operational.params.pfc.enabled; 1506 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled); 1507 kfree(dcbx_info); 1508 1509 return enabled; 1510 } 1511 1512 static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev) 1513 { 1514 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1515 struct qed_dcbx_get *dcbx_info; 1516 u8 mode = 0; 1517 1518 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1519 if (!dcbx_info) 1520 return 0; 1521 1522 if (dcbx_info->operational.enabled) 1523 mode |= DCB_CAP_DCBX_LLD_MANAGED; 1524 if (dcbx_info->operational.ieee) 1525 mode |= DCB_CAP_DCBX_VER_IEEE; 1526 if (dcbx_info->operational.cee) 1527 mode |= DCB_CAP_DCBX_VER_CEE; 1528 1529 DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode); 1530 kfree(dcbx_info); 1531 1532 return mode; 1533 } 1534 1535 static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev, 1536 int tc, 1537 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map) 1538 { 1539 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1540 struct qed_dcbx_set dcbx_set; 1541 struct qed_ptt *ptt; 1542 int rc; 1543 1544 DP_VERBOSE(hwfn, QED_MSG_DCB, 1545 "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n", 1546 tc, pri_type, pgid, bw_pct, up_map); 1547 1548 if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) { 1549 DP_INFO(hwfn, "Invalid tc %d\n", tc); 1550 return; 1551 } 1552 1553 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1554 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1555 if (rc) 1556 return; 1557 1558 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG; 1559 dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid; 1560 1561 ptt = qed_ptt_acquire(hwfn); 1562 if (!ptt) 1563 return; 1564 1565 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1566 1567 qed_ptt_release(hwfn, ptt); 1568 } 1569 1570 static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio, 1571 u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map) 1572 { 1573 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n"); 1574 } 1575 1576 static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct) 1577 { 1578 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1579 struct qed_dcbx_set dcbx_set; 1580 struct qed_ptt *ptt; 1581 int rc; 1582 1583 DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct); 1584 if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) { 1585 DP_INFO(hwfn, "Invalid pgid %d\n", pgid); 1586 return; 1587 } 1588 1589 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1590 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1591 if (rc) 1592 return; 1593 1594 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG; 1595 dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct; 1596 1597 ptt = qed_ptt_acquire(hwfn); 1598 if (!ptt) 1599 return; 1600 1601 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1602 1603 qed_ptt_release(hwfn, ptt); 1604 } 1605 1606 static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct) 1607 { 1608 DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n"); 1609 } 1610 1611 static u8 qed_dcbnl_setall(struct qed_dev *cdev) 1612 { 1613 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1614 struct qed_dcbx_set dcbx_set; 1615 struct qed_ptt *ptt; 1616 int rc; 1617 1618 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1619 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1620 if (rc) 1621 return 1; 1622 1623 ptt = qed_ptt_acquire(hwfn); 1624 if (!ptt) 1625 return 1; 1626 1627 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1); 1628 1629 qed_ptt_release(hwfn, ptt); 1630 1631 return rc; 1632 } 1633 1634 static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num) 1635 { 1636 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1637 struct qed_dcbx_set dcbx_set; 1638 struct qed_ptt *ptt; 1639 int rc; 1640 1641 DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num); 1642 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1643 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1644 if (rc) 1645 return 1; 1646 1647 switch (tcid) { 1648 case DCB_NUMTCS_ATTR_PG: 1649 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG; 1650 dcbx_set.config.params.max_ets_tc = num; 1651 break; 1652 case DCB_NUMTCS_ATTR_PFC: 1653 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG; 1654 dcbx_set.config.params.pfc.max_tc = num; 1655 break; 1656 default: 1657 DP_INFO(hwfn, "Invalid tcid %d\n", tcid); 1658 return -EINVAL; 1659 } 1660 1661 ptt = qed_ptt_acquire(hwfn); 1662 if (!ptt) 1663 return -EINVAL; 1664 1665 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1666 1667 qed_ptt_release(hwfn, ptt); 1668 1669 return 0; 1670 } 1671 1672 static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state) 1673 { 1674 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1675 struct qed_dcbx_set dcbx_set; 1676 struct qed_ptt *ptt; 1677 int rc; 1678 1679 DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state); 1680 1681 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1682 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1683 if (rc) 1684 return; 1685 1686 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG; 1687 dcbx_set.config.params.pfc.enabled = !!state; 1688 1689 ptt = qed_ptt_acquire(hwfn); 1690 if (!ptt) 1691 return; 1692 1693 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1694 1695 qed_ptt_release(hwfn, ptt); 1696 } 1697 1698 static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval) 1699 { 1700 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1701 struct qed_dcbx_get *dcbx_info; 1702 struct qed_app_entry *entry; 1703 bool ethtype; 1704 u8 prio = 0; 1705 int i; 1706 1707 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1708 if (!dcbx_info) 1709 return -EINVAL; 1710 1711 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE); 1712 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) { 1713 entry = &dcbx_info->operational.params.app_entry[i]; 1714 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) { 1715 prio = entry->prio; 1716 break; 1717 } 1718 } 1719 1720 if (i == QED_DCBX_MAX_APP_PROTOCOL) { 1721 DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval); 1722 kfree(dcbx_info); 1723 return -EINVAL; 1724 } 1725 1726 kfree(dcbx_info); 1727 1728 return prio; 1729 } 1730 1731 static int qed_dcbnl_setapp(struct qed_dev *cdev, 1732 u8 idtype, u16 idval, u8 pri_map) 1733 { 1734 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1735 struct qed_dcbx_set dcbx_set; 1736 struct qed_app_entry *entry; 1737 struct qed_ptt *ptt; 1738 bool ethtype; 1739 int rc, i; 1740 1741 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1742 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1743 if (rc) 1744 return -EINVAL; 1745 1746 ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE); 1747 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) { 1748 entry = &dcbx_set.config.params.app_entry[i]; 1749 if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) 1750 break; 1751 /* First empty slot */ 1752 if (!entry->proto_id) { 1753 dcbx_set.config.params.num_app_entries++; 1754 break; 1755 } 1756 } 1757 1758 if (i == QED_DCBX_MAX_APP_PROTOCOL) { 1759 DP_ERR(cdev, "App table is full\n"); 1760 return -EBUSY; 1761 } 1762 1763 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG; 1764 dcbx_set.config.params.app_entry[i].ethtype = ethtype; 1765 dcbx_set.config.params.app_entry[i].proto_id = idval; 1766 dcbx_set.config.params.app_entry[i].prio = pri_map; 1767 1768 ptt = qed_ptt_acquire(hwfn); 1769 if (!ptt) 1770 return -EBUSY; 1771 1772 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1773 1774 qed_ptt_release(hwfn, ptt); 1775 1776 return rc; 1777 } 1778 1779 static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode) 1780 { 1781 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1782 struct qed_dcbx_set dcbx_set; 1783 struct qed_ptt *ptt; 1784 int rc; 1785 1786 DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode); 1787 1788 if (!(mode & DCB_CAP_DCBX_VER_IEEE) && !(mode & DCB_CAP_DCBX_VER_CEE)) { 1789 DP_INFO(hwfn, "Allowed mode is cee, ieee or both\n"); 1790 return 1; 1791 } 1792 1793 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1794 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1795 if (rc) 1796 return 1; 1797 1798 dcbx_set.ver_num = 0; 1799 if (mode & DCB_CAP_DCBX_VER_CEE) { 1800 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE; 1801 dcbx_set.enabled = true; 1802 } 1803 1804 if (mode & DCB_CAP_DCBX_VER_IEEE) { 1805 dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE; 1806 dcbx_set.enabled = true; 1807 } 1808 1809 ptt = qed_ptt_acquire(hwfn); 1810 if (!ptt) 1811 return 1; 1812 1813 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1814 1815 qed_ptt_release(hwfn, ptt); 1816 1817 return 0; 1818 } 1819 1820 static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags) 1821 { 1822 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1823 struct qed_dcbx_get *dcbx_info; 1824 1825 DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid); 1826 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 1827 if (!dcbx_info) 1828 return 1; 1829 1830 *flags = 0; 1831 switch (featid) { 1832 case DCB_FEATCFG_ATTR_PG: 1833 if (dcbx_info->operational.params.ets_enabled) 1834 *flags = DCB_FEATCFG_ENABLE; 1835 else 1836 *flags = DCB_FEATCFG_ERROR; 1837 break; 1838 case DCB_FEATCFG_ATTR_PFC: 1839 if (dcbx_info->operational.params.pfc.enabled) 1840 *flags = DCB_FEATCFG_ENABLE; 1841 else 1842 *flags = DCB_FEATCFG_ERROR; 1843 break; 1844 case DCB_FEATCFG_ATTR_APP: 1845 if (dcbx_info->operational.params.app_valid) 1846 *flags = DCB_FEATCFG_ENABLE; 1847 else 1848 *flags = DCB_FEATCFG_ERROR; 1849 break; 1850 default: 1851 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid); 1852 kfree(dcbx_info); 1853 return 1; 1854 } 1855 1856 DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags); 1857 kfree(dcbx_info); 1858 1859 return 0; 1860 } 1861 1862 static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags) 1863 { 1864 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1865 struct qed_dcbx_set dcbx_set; 1866 bool enabled, willing; 1867 struct qed_ptt *ptt; 1868 int rc; 1869 1870 DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n", 1871 featid, flags); 1872 memset(&dcbx_set, 0, sizeof(dcbx_set)); 1873 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 1874 if (rc) 1875 return 1; 1876 1877 enabled = !!(flags & DCB_FEATCFG_ENABLE); 1878 willing = !!(flags & DCB_FEATCFG_WILLING); 1879 switch (featid) { 1880 case DCB_FEATCFG_ATTR_PG: 1881 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG; 1882 dcbx_set.config.params.ets_enabled = enabled; 1883 dcbx_set.config.params.ets_willing = willing; 1884 break; 1885 case DCB_FEATCFG_ATTR_PFC: 1886 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG; 1887 dcbx_set.config.params.pfc.enabled = enabled; 1888 dcbx_set.config.params.pfc.willing = willing; 1889 break; 1890 case DCB_FEATCFG_ATTR_APP: 1891 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG; 1892 dcbx_set.config.params.app_willing = willing; 1893 break; 1894 default: 1895 DP_INFO(hwfn, "Invalid feature-ID %d\n", featid); 1896 return 1; 1897 } 1898 1899 ptt = qed_ptt_acquire(hwfn); 1900 if (!ptt) 1901 return 1; 1902 1903 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 1904 1905 qed_ptt_release(hwfn, ptt); 1906 1907 return 0; 1908 } 1909 1910 static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev, 1911 struct dcb_peer_app_info *info, 1912 u16 *app_count) 1913 { 1914 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1915 struct qed_dcbx_get *dcbx_info; 1916 1917 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB); 1918 if (!dcbx_info) 1919 return -EINVAL; 1920 1921 info->willing = dcbx_info->remote.params.app_willing; 1922 info->error = dcbx_info->remote.params.app_error; 1923 *app_count = dcbx_info->remote.params.num_app_entries; 1924 kfree(dcbx_info); 1925 1926 return 0; 1927 } 1928 1929 static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev, 1930 struct dcb_app *table) 1931 { 1932 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1933 struct qed_dcbx_get *dcbx_info; 1934 int i; 1935 1936 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB); 1937 if (!dcbx_info) 1938 return -EINVAL; 1939 1940 for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) { 1941 if (dcbx_info->remote.params.app_entry[i].ethtype) 1942 table[i].selector = DCB_APP_IDTYPE_ETHTYPE; 1943 else 1944 table[i].selector = DCB_APP_IDTYPE_PORTNUM; 1945 table[i].priority = dcbx_info->remote.params.app_entry[i].prio; 1946 table[i].protocol = 1947 dcbx_info->remote.params.app_entry[i].proto_id; 1948 } 1949 1950 kfree(dcbx_info); 1951 1952 return 0; 1953 } 1954 1955 static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc) 1956 { 1957 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1958 struct qed_dcbx_get *dcbx_info; 1959 int i; 1960 1961 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB); 1962 if (!dcbx_info) 1963 return -EINVAL; 1964 1965 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) 1966 if (dcbx_info->remote.params.pfc.prio[i]) 1967 pfc->pfc_en |= BIT(i); 1968 1969 pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc; 1970 DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n", 1971 pfc->pfc_en, pfc->tcs_supported); 1972 kfree(dcbx_info); 1973 1974 return 0; 1975 } 1976 1977 static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg) 1978 { 1979 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 1980 struct qed_dcbx_get *dcbx_info; 1981 int i; 1982 1983 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB); 1984 if (!dcbx_info) 1985 return -EINVAL; 1986 1987 pg->willing = dcbx_info->remote.params.ets_willing; 1988 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) { 1989 pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i]; 1990 pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i]; 1991 } 1992 1993 DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing); 1994 kfree(dcbx_info); 1995 1996 return 0; 1997 } 1998 1999 static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev, 2000 struct ieee_pfc *pfc, bool remote) 2001 { 2002 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 2003 struct qed_dcbx_params *params; 2004 struct qed_dcbx_get *dcbx_info; 2005 int rc, i; 2006 2007 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 2008 if (!dcbx_info) 2009 return -EINVAL; 2010 2011 if (!dcbx_info->operational.ieee) { 2012 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n"); 2013 kfree(dcbx_info); 2014 return -EINVAL; 2015 } 2016 2017 if (remote) { 2018 memset(dcbx_info, 0, sizeof(*dcbx_info)); 2019 rc = qed_dcbx_query_params(hwfn, dcbx_info, 2020 QED_DCBX_REMOTE_MIB); 2021 if (rc) { 2022 kfree(dcbx_info); 2023 return -EINVAL; 2024 } 2025 2026 params = &dcbx_info->remote.params; 2027 } else { 2028 params = &dcbx_info->operational.params; 2029 } 2030 2031 pfc->pfc_cap = params->pfc.max_tc; 2032 pfc->pfc_en = 0; 2033 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) 2034 if (params->pfc.prio[i]) 2035 pfc->pfc_en |= BIT(i); 2036 2037 kfree(dcbx_info); 2038 2039 return 0; 2040 } 2041 2042 static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc) 2043 { 2044 return qed_dcbnl_get_ieee_pfc(cdev, pfc, false); 2045 } 2046 2047 static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc) 2048 { 2049 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 2050 struct qed_dcbx_get *dcbx_info; 2051 struct qed_dcbx_set dcbx_set; 2052 struct qed_ptt *ptt; 2053 int rc, i; 2054 2055 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 2056 if (!dcbx_info) 2057 return -EINVAL; 2058 2059 if (!dcbx_info->operational.ieee) { 2060 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n"); 2061 kfree(dcbx_info); 2062 return -EINVAL; 2063 } 2064 2065 kfree(dcbx_info); 2066 2067 memset(&dcbx_set, 0, sizeof(dcbx_set)); 2068 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 2069 if (rc) 2070 return -EINVAL; 2071 2072 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG; 2073 for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) 2074 dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i)); 2075 2076 ptt = qed_ptt_acquire(hwfn); 2077 if (!ptt) 2078 return -EINVAL; 2079 2080 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 2081 2082 qed_ptt_release(hwfn, ptt); 2083 2084 return rc; 2085 } 2086 2087 static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev, 2088 struct ieee_ets *ets, bool remote) 2089 { 2090 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 2091 struct qed_dcbx_get *dcbx_info; 2092 struct qed_dcbx_params *params; 2093 int rc; 2094 2095 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 2096 if (!dcbx_info) 2097 return -EINVAL; 2098 2099 if (!dcbx_info->operational.ieee) { 2100 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n"); 2101 kfree(dcbx_info); 2102 return -EINVAL; 2103 } 2104 2105 if (remote) { 2106 memset(dcbx_info, 0, sizeof(*dcbx_info)); 2107 rc = qed_dcbx_query_params(hwfn, dcbx_info, 2108 QED_DCBX_REMOTE_MIB); 2109 if (rc) { 2110 kfree(dcbx_info); 2111 return -EINVAL; 2112 } 2113 2114 params = &dcbx_info->remote.params; 2115 } else { 2116 params = &dcbx_info->operational.params; 2117 } 2118 2119 ets->ets_cap = params->max_ets_tc; 2120 ets->willing = params->ets_willing; 2121 ets->cbs = params->ets_cbs; 2122 memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw)); 2123 memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa)); 2124 memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc)); 2125 kfree(dcbx_info); 2126 2127 return 0; 2128 } 2129 2130 static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets) 2131 { 2132 return qed_dcbnl_get_ieee_ets(cdev, ets, false); 2133 } 2134 2135 static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets) 2136 { 2137 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 2138 struct qed_dcbx_get *dcbx_info; 2139 struct qed_dcbx_set dcbx_set; 2140 struct qed_ptt *ptt; 2141 int rc; 2142 2143 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 2144 if (!dcbx_info) 2145 return -EINVAL; 2146 2147 if (!dcbx_info->operational.ieee) { 2148 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n"); 2149 kfree(dcbx_info); 2150 return -EINVAL; 2151 } 2152 2153 kfree(dcbx_info); 2154 2155 memset(&dcbx_set, 0, sizeof(dcbx_set)); 2156 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 2157 if (rc) 2158 return -EINVAL; 2159 2160 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG; 2161 dcbx_set.config.params.max_ets_tc = ets->ets_cap; 2162 dcbx_set.config.params.ets_willing = ets->willing; 2163 dcbx_set.config.params.ets_cbs = ets->cbs; 2164 memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw, 2165 sizeof(ets->tc_tx_bw)); 2166 memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa, 2167 sizeof(ets->tc_tsa)); 2168 memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc, 2169 sizeof(ets->prio_tc)); 2170 2171 ptt = qed_ptt_acquire(hwfn); 2172 if (!ptt) 2173 return -EINVAL; 2174 2175 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 2176 2177 qed_ptt_release(hwfn, ptt); 2178 2179 return rc; 2180 } 2181 2182 static int 2183 qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets) 2184 { 2185 return qed_dcbnl_get_ieee_ets(cdev, ets, true); 2186 } 2187 2188 static int 2189 qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc) 2190 { 2191 return qed_dcbnl_get_ieee_pfc(cdev, pfc, true); 2192 } 2193 2194 static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app) 2195 { 2196 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 2197 struct qed_dcbx_get *dcbx_info; 2198 struct qed_app_entry *entry; 2199 bool ethtype; 2200 u8 prio = 0; 2201 int i; 2202 2203 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 2204 if (!dcbx_info) 2205 return -EINVAL; 2206 2207 if (!dcbx_info->operational.ieee) { 2208 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n"); 2209 kfree(dcbx_info); 2210 return -EINVAL; 2211 } 2212 2213 /* ieee defines the selector field value for ethertype to be 1 */ 2214 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE); 2215 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) { 2216 entry = &dcbx_info->operational.params.app_entry[i]; 2217 if ((entry->ethtype == ethtype) && 2218 (entry->proto_id == app->protocol)) { 2219 prio = entry->prio; 2220 break; 2221 } 2222 } 2223 2224 if (i == QED_DCBX_MAX_APP_PROTOCOL) { 2225 DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector, 2226 app->protocol); 2227 kfree(dcbx_info); 2228 return -EINVAL; 2229 } 2230 2231 app->priority = ffs(prio) - 1; 2232 2233 kfree(dcbx_info); 2234 2235 return 0; 2236 } 2237 2238 static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app) 2239 { 2240 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev); 2241 struct qed_dcbx_get *dcbx_info; 2242 struct qed_dcbx_set dcbx_set; 2243 struct qed_app_entry *entry; 2244 struct qed_ptt *ptt; 2245 bool ethtype; 2246 int rc, i; 2247 2248 if (app->priority < 0 || app->priority >= QED_MAX_PFC_PRIORITIES) { 2249 DP_INFO(hwfn, "Invalid priority %d\n", app->priority); 2250 return -EINVAL; 2251 } 2252 2253 dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB); 2254 if (!dcbx_info) 2255 return -EINVAL; 2256 2257 if (!dcbx_info->operational.ieee) { 2258 DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n"); 2259 kfree(dcbx_info); 2260 return -EINVAL; 2261 } 2262 2263 kfree(dcbx_info); 2264 2265 memset(&dcbx_set, 0, sizeof(dcbx_set)); 2266 rc = qed_dcbx_get_config_params(hwfn, &dcbx_set); 2267 if (rc) 2268 return -EINVAL; 2269 2270 /* ieee defines the selector field value for ethertype to be 1 */ 2271 ethtype = !!((app->selector - 1) == DCB_APP_IDTYPE_ETHTYPE); 2272 for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) { 2273 entry = &dcbx_set.config.params.app_entry[i]; 2274 if ((entry->ethtype == ethtype) && 2275 (entry->proto_id == app->protocol)) 2276 break; 2277 /* First empty slot */ 2278 if (!entry->proto_id) { 2279 dcbx_set.config.params.num_app_entries++; 2280 break; 2281 } 2282 } 2283 2284 if (i == QED_DCBX_MAX_APP_PROTOCOL) { 2285 DP_ERR(cdev, "App table is full\n"); 2286 return -EBUSY; 2287 } 2288 2289 dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG; 2290 dcbx_set.config.params.app_entry[i].ethtype = ethtype; 2291 dcbx_set.config.params.app_entry[i].proto_id = app->protocol; 2292 dcbx_set.config.params.app_entry[i].prio = BIT(app->priority); 2293 2294 ptt = qed_ptt_acquire(hwfn); 2295 if (!ptt) 2296 return -EBUSY; 2297 2298 rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0); 2299 2300 qed_ptt_release(hwfn, ptt); 2301 2302 return rc; 2303 } 2304 2305 const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = { 2306 .getstate = qed_dcbnl_getstate, 2307 .setstate = qed_dcbnl_setstate, 2308 .getpgtccfgtx = qed_dcbnl_getpgtccfgtx, 2309 .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx, 2310 .getpgtccfgrx = qed_dcbnl_getpgtccfgrx, 2311 .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx, 2312 .getpfccfg = qed_dcbnl_getpfccfg, 2313 .setpfccfg = qed_dcbnl_setpfccfg, 2314 .getcap = qed_dcbnl_getcap, 2315 .getnumtcs = qed_dcbnl_getnumtcs, 2316 .getpfcstate = qed_dcbnl_getpfcstate, 2317 .getdcbx = qed_dcbnl_getdcbx, 2318 .setpgtccfgtx = qed_dcbnl_setpgtccfgtx, 2319 .setpgtccfgrx = qed_dcbnl_setpgtccfgrx, 2320 .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx, 2321 .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx, 2322 .setall = qed_dcbnl_setall, 2323 .setnumtcs = qed_dcbnl_setnumtcs, 2324 .setpfcstate = qed_dcbnl_setpfcstate, 2325 .setapp = qed_dcbnl_setapp, 2326 .setdcbx = qed_dcbnl_setdcbx, 2327 .setfeatcfg = qed_dcbnl_setfeatcfg, 2328 .getfeatcfg = qed_dcbnl_getfeatcfg, 2329 .getapp = qed_dcbnl_getapp, 2330 .peer_getappinfo = qed_dcbnl_peer_getappinfo, 2331 .peer_getapptable = qed_dcbnl_peer_getapptable, 2332 .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc, 2333 .cee_peer_getpg = qed_dcbnl_cee_peer_getpg, 2334 .ieee_getpfc = qed_dcbnl_ieee_getpfc, 2335 .ieee_setpfc = qed_dcbnl_ieee_setpfc, 2336 .ieee_getets = qed_dcbnl_ieee_getets, 2337 .ieee_setets = qed_dcbnl_ieee_setets, 2338 .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc, 2339 .ieee_peer_getets = qed_dcbnl_ieee_peer_getets, 2340 .ieee_getapp = qed_dcbnl_ieee_getapp, 2341 .ieee_setapp = qed_dcbnl_ieee_setapp, 2342 }; 2343 2344 #endif 2345