1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright(c) 2024 Intel Corporation. */ 3 4 #include "ixgbe_common.h" 5 #include "ixgbe_e610.h" 6 #include "ixgbe_x550.h" 7 #include "ixgbe_type.h" 8 #include "ixgbe_x540.h" 9 #include "ixgbe_mbx.h" 10 #include "ixgbe_phy.h" 11 12 /** 13 * ixgbe_should_retry_aci_send_cmd_execute - decide if ACI command should 14 * be resent 15 * @opcode: ACI opcode 16 * 17 * Check if ACI command should be sent again depending on the provided opcode. 18 * It may happen when CSR is busy during link state changes. 19 * 20 * Return: true if the sending command routine should be repeated, 21 * otherwise false. 22 */ 23 static bool ixgbe_should_retry_aci_send_cmd_execute(u16 opcode) 24 { 25 switch (opcode) { 26 case ixgbe_aci_opc_disable_rxen: 27 case ixgbe_aci_opc_get_phy_caps: 28 case ixgbe_aci_opc_get_link_status: 29 case ixgbe_aci_opc_get_link_topo: 30 return true; 31 } 32 33 return false; 34 } 35 36 /** 37 * ixgbe_aci_send_cmd_execute - execute sending FW Admin Command to FW Admin 38 * Command Interface 39 * @hw: pointer to the HW struct 40 * @desc: descriptor describing the command 41 * @buf: buffer to use for indirect commands (NULL for direct commands) 42 * @buf_size: size of buffer for indirect commands (0 for direct commands) 43 * 44 * Admin Command is sent using CSR by setting descriptor and buffer in specific 45 * registers. 46 * 47 * Return: the exit code of the operation. 48 * * - 0 - success. 49 * * - -EIO - CSR mechanism is not enabled. 50 * * - -EBUSY - CSR mechanism is busy. 51 * * - -EINVAL - buf_size is too big or 52 * invalid argument buf or buf_size. 53 * * - -ETIME - Admin Command X command timeout. 54 * * - -EIO - Admin Command X invalid state of HICR register or 55 * Admin Command failed because of bad opcode was returned or 56 * Admin Command failed with error Y. 57 */ 58 static int ixgbe_aci_send_cmd_execute(struct ixgbe_hw *hw, 59 struct libie_aq_desc *desc, 60 void *buf, u16 buf_size) 61 { 62 u16 opcode, buf_tail_size = buf_size % 4; 63 u32 *raw_desc = (u32 *)desc; 64 u32 hicr, i, buf_tail = 0; 65 bool valid_buf = false; 66 67 hw->aci.last_status = LIBIE_AQ_RC_OK; 68 69 /* It's necessary to check if mechanism is enabled */ 70 hicr = IXGBE_READ_REG(hw, IXGBE_PF_HICR); 71 72 if (!(hicr & IXGBE_PF_HICR_EN)) 73 return -EIO; 74 75 if (hicr & IXGBE_PF_HICR_C) { 76 hw->aci.last_status = LIBIE_AQ_RC_EBUSY; 77 return -EBUSY; 78 } 79 80 opcode = le16_to_cpu(desc->opcode); 81 82 if (buf_size > IXGBE_ACI_MAX_BUFFER_SIZE) 83 return -EINVAL; 84 85 if (buf) 86 desc->flags |= cpu_to_le16(LIBIE_AQ_FLAG_BUF); 87 88 if (desc->flags & cpu_to_le16(LIBIE_AQ_FLAG_BUF)) { 89 if ((buf && !buf_size) || 90 (!buf && buf_size)) 91 return -EINVAL; 92 if (buf && buf_size) 93 valid_buf = true; 94 } 95 96 if (valid_buf) { 97 if (buf_tail_size) 98 memcpy(&buf_tail, buf + buf_size - buf_tail_size, 99 buf_tail_size); 100 101 if (((buf_size + 3) & ~0x3) > LIBIE_AQ_LG_BUF) 102 desc->flags |= cpu_to_le16(LIBIE_AQ_FLAG_LB); 103 104 desc->datalen = cpu_to_le16(buf_size); 105 106 if (desc->flags & cpu_to_le16(LIBIE_AQ_FLAG_RD)) { 107 for (i = 0; i < buf_size / 4; i++) 108 IXGBE_WRITE_REG(hw, IXGBE_PF_HIBA(i), ((u32 *)buf)[i]); 109 if (buf_tail_size) 110 IXGBE_WRITE_REG(hw, IXGBE_PF_HIBA(i), buf_tail); 111 } 112 } 113 114 /* Descriptor is written to specific registers */ 115 for (i = 0; i < IXGBE_ACI_DESC_SIZE_IN_DWORDS; i++) 116 IXGBE_WRITE_REG(hw, IXGBE_PF_HIDA(i), raw_desc[i]); 117 118 /* SW has to set PF_HICR.C bit and clear PF_HICR.SV and 119 * PF_HICR_EV 120 */ 121 hicr = (IXGBE_READ_REG(hw, IXGBE_PF_HICR) | IXGBE_PF_HICR_C) & 122 ~(IXGBE_PF_HICR_SV | IXGBE_PF_HICR_EV); 123 IXGBE_WRITE_REG(hw, IXGBE_PF_HICR, hicr); 124 125 #define MAX_SLEEP_RESP_US 1000 126 #define MAX_TMOUT_RESP_SYNC_US 100000000 127 128 /* Wait for sync Admin Command response */ 129 read_poll_timeout(IXGBE_READ_REG, hicr, 130 (hicr & IXGBE_PF_HICR_SV) || 131 !(hicr & IXGBE_PF_HICR_C), 132 MAX_SLEEP_RESP_US, MAX_TMOUT_RESP_SYNC_US, true, hw, 133 IXGBE_PF_HICR); 134 135 #define MAX_TMOUT_RESP_ASYNC_US 150000000 136 137 /* Wait for async Admin Command response */ 138 read_poll_timeout(IXGBE_READ_REG, hicr, 139 (hicr & IXGBE_PF_HICR_EV) || 140 !(hicr & IXGBE_PF_HICR_C), 141 MAX_SLEEP_RESP_US, MAX_TMOUT_RESP_ASYNC_US, true, hw, 142 IXGBE_PF_HICR); 143 144 /* Read sync Admin Command response */ 145 if ((hicr & IXGBE_PF_HICR_SV)) 146 for (i = 0; i < IXGBE_ACI_DESC_SIZE_IN_DWORDS; i++) 147 raw_desc[i] = IXGBE_READ_REG(hw, IXGBE_PF_HIDA(i)); 148 149 /* Read async Admin Command response */ 150 if ((hicr & IXGBE_PF_HICR_EV) && !(hicr & IXGBE_PF_HICR_C)) 151 for (i = 0; i < IXGBE_ACI_DESC_SIZE_IN_DWORDS; i++) 152 raw_desc[i] = IXGBE_READ_REG(hw, IXGBE_PF_HIDA_2(i)); 153 154 /* Handle timeout and invalid state of HICR register */ 155 if (hicr & IXGBE_PF_HICR_C) 156 return -ETIME; 157 158 if (!(hicr & IXGBE_PF_HICR_SV) && !(hicr & IXGBE_PF_HICR_EV)) 159 return -EIO; 160 161 /* For every command other than 0x0014 treat opcode mismatch 162 * as an error. Response to 0x0014 command read from HIDA_2 163 * is a descriptor of an event which is expected to contain 164 * different opcode than the command. 165 */ 166 if (desc->opcode != cpu_to_le16(opcode) && 167 opcode != ixgbe_aci_opc_get_fw_event) 168 return -EIO; 169 170 if (desc->retval) { 171 hw->aci.last_status = (enum libie_aq_err) 172 le16_to_cpu(desc->retval); 173 return -EIO; 174 } 175 176 /* Write a response values to a buf */ 177 if (valid_buf) { 178 for (i = 0; i < buf_size / 4; i++) 179 ((u32 *)buf)[i] = IXGBE_READ_REG(hw, IXGBE_PF_HIBA(i)); 180 if (buf_tail_size) { 181 buf_tail = IXGBE_READ_REG(hw, IXGBE_PF_HIBA(i)); 182 memcpy(buf + buf_size - buf_tail_size, &buf_tail, 183 buf_tail_size); 184 } 185 } 186 187 return 0; 188 } 189 190 /** 191 * ixgbe_aci_send_cmd - send FW Admin Command to FW Admin Command Interface 192 * @hw: pointer to the HW struct 193 * @desc: descriptor describing the command 194 * @buf: buffer to use for indirect commands (NULL for direct commands) 195 * @buf_size: size of buffer for indirect commands (0 for direct commands) 196 * 197 * Helper function to send FW Admin Commands to the FW Admin Command Interface. 198 * 199 * Retry sending the FW Admin Command multiple times to the FW ACI 200 * if the EBUSY Admin Command error is returned. 201 * 202 * Return: the exit code of the operation. 203 */ 204 int ixgbe_aci_send_cmd(struct ixgbe_hw *hw, struct libie_aq_desc *desc, 205 void *buf, u16 buf_size) 206 { 207 u16 opcode = le16_to_cpu(desc->opcode); 208 struct libie_aq_desc desc_cpy; 209 enum libie_aq_err last_status; 210 u8 idx = 0, *buf_cpy = NULL; 211 bool is_cmd_for_retry; 212 unsigned long timeout; 213 int err; 214 215 is_cmd_for_retry = ixgbe_should_retry_aci_send_cmd_execute(opcode); 216 if (is_cmd_for_retry) { 217 if (buf) { 218 buf_cpy = kmalloc(buf_size, GFP_KERNEL); 219 if (!buf_cpy) 220 return -ENOMEM; 221 *buf_cpy = *(u8 *)buf; 222 } 223 desc_cpy = *desc; 224 } 225 226 timeout = jiffies + msecs_to_jiffies(IXGBE_ACI_SEND_TIMEOUT_MS); 227 do { 228 mutex_lock(&hw->aci.lock); 229 err = ixgbe_aci_send_cmd_execute(hw, desc, buf, buf_size); 230 last_status = hw->aci.last_status; 231 mutex_unlock(&hw->aci.lock); 232 233 if (!is_cmd_for_retry || !err || 234 last_status != LIBIE_AQ_RC_EBUSY) 235 break; 236 237 if (buf) 238 memcpy(buf, buf_cpy, buf_size); 239 *desc = desc_cpy; 240 241 msleep(IXGBE_ACI_SEND_DELAY_TIME_MS); 242 } while (++idx < IXGBE_ACI_SEND_MAX_EXECUTE && 243 time_before(jiffies, timeout)); 244 245 kfree(buf_cpy); 246 247 return err; 248 } 249 250 /** 251 * ixgbe_aci_check_event_pending - check if there are any pending events 252 * @hw: pointer to the HW struct 253 * 254 * Determine if there are any pending events. 255 * 256 * Return: true if there are any currently pending events 257 * otherwise false. 258 */ 259 bool ixgbe_aci_check_event_pending(struct ixgbe_hw *hw) 260 { 261 u32 ep_bit_mask = hw->bus.func ? GL_FWSTS_EP_PF1 : GL_FWSTS_EP_PF0; 262 u32 fwsts = IXGBE_READ_REG(hw, GL_FWSTS); 263 264 return (fwsts & ep_bit_mask) ? true : false; 265 } 266 267 /** 268 * ixgbe_aci_get_event - get an event from ACI 269 * @hw: pointer to the HW struct 270 * @e: event information structure 271 * @pending: optional flag signaling that there are more pending events 272 * 273 * Obtain an event from ACI and return its content 274 * through 'e' using ACI command (0x0014). 275 * Provide information if there are more events 276 * to retrieve through 'pending'. 277 * 278 * Return: the exit code of the operation. 279 */ 280 int ixgbe_aci_get_event(struct ixgbe_hw *hw, struct ixgbe_aci_event *e, 281 bool *pending) 282 { 283 struct libie_aq_desc desc; 284 int err; 285 286 if (!e || (!e->msg_buf && e->buf_len)) 287 return -EINVAL; 288 289 mutex_lock(&hw->aci.lock); 290 291 /* Check if there are any events pending */ 292 if (!ixgbe_aci_check_event_pending(hw)) { 293 err = -ENOENT; 294 goto aci_get_event_exit; 295 } 296 297 /* Obtain pending event */ 298 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_get_fw_event); 299 err = ixgbe_aci_send_cmd_execute(hw, &desc, e->msg_buf, e->buf_len); 300 if (err) 301 goto aci_get_event_exit; 302 303 /* Returned 0x0014 opcode indicates that no event was obtained */ 304 if (desc.opcode == cpu_to_le16(ixgbe_aci_opc_get_fw_event)) { 305 err = -ENOENT; 306 goto aci_get_event_exit; 307 } 308 309 /* Determine size of event data */ 310 e->msg_len = min_t(u16, le16_to_cpu(desc.datalen), e->buf_len); 311 /* Write event descriptor to event info structure */ 312 memcpy(&e->desc, &desc, sizeof(e->desc)); 313 314 /* Check if there are any further events pending */ 315 if (pending) 316 *pending = ixgbe_aci_check_event_pending(hw); 317 318 aci_get_event_exit: 319 mutex_unlock(&hw->aci.lock); 320 321 return err; 322 } 323 324 /** 325 * ixgbe_fill_dflt_direct_cmd_desc - fill ACI descriptor with default values. 326 * @desc: pointer to the temp descriptor (non DMA mem) 327 * @opcode: the opcode can be used to decide which flags to turn off or on 328 * 329 * Helper function to fill the descriptor desc with default values 330 * and the provided opcode. 331 */ 332 void ixgbe_fill_dflt_direct_cmd_desc(struct libie_aq_desc *desc, u16 opcode) 333 { 334 /* Zero out the desc. */ 335 memset(desc, 0, sizeof(*desc)); 336 desc->opcode = cpu_to_le16(opcode); 337 desc->flags = cpu_to_le16(LIBIE_AQ_FLAG_SI); 338 } 339 340 /** 341 * ixgbe_aci_get_fw_ver - Get the firmware version 342 * @hw: pointer to the HW struct 343 * 344 * Get the firmware version using ACI command (0x0001). 345 * 346 * Return: the exit code of the operation. 347 */ 348 static int ixgbe_aci_get_fw_ver(struct ixgbe_hw *hw) 349 { 350 struct libie_aqc_get_ver *resp; 351 struct libie_aq_desc desc; 352 int err; 353 354 resp = &desc.params.get_ver; 355 356 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_get_ver); 357 358 err = ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 359 if (!err) { 360 hw->fw_branch = resp->fw_branch; 361 hw->fw_maj_ver = resp->fw_major; 362 hw->fw_min_ver = resp->fw_minor; 363 hw->fw_patch = resp->fw_patch; 364 hw->fw_build = le32_to_cpu(resp->fw_build); 365 hw->api_branch = resp->api_branch; 366 hw->api_maj_ver = resp->api_major; 367 hw->api_min_ver = resp->api_minor; 368 hw->api_patch = resp->api_patch; 369 } 370 371 return err; 372 } 373 374 /** 375 * ixgbe_aci_req_res - request a common resource 376 * @hw: pointer to the HW struct 377 * @res: resource ID 378 * @access: access type 379 * @sdp_number: resource number 380 * @timeout: the maximum time in ms that the driver may hold the resource 381 * 382 * Requests a common resource using the ACI command (0x0008). 383 * Specifies the maximum time the driver may hold the resource. 384 * If the requested resource is currently occupied by some other driver, 385 * a busy return value is returned and the timeout field value indicates the 386 * maximum time the current owner has to free it. 387 * 388 * Return: the exit code of the operation. 389 */ 390 static int ixgbe_aci_req_res(struct ixgbe_hw *hw, enum libie_aq_res_id res, 391 enum libie_aq_res_access_type access, 392 u8 sdp_number, u32 *timeout) 393 { 394 struct libie_aqc_req_res *cmd_resp; 395 struct libie_aq_desc desc; 396 int err; 397 398 cmd_resp = &desc.params.res_owner; 399 400 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_req_res); 401 402 cmd_resp->res_id = cpu_to_le16(res); 403 cmd_resp->access_type = cpu_to_le16(access); 404 cmd_resp->res_number = cpu_to_le32(sdp_number); 405 cmd_resp->timeout = cpu_to_le32(*timeout); 406 *timeout = 0; 407 408 err = ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 409 410 /* If the resource is held by some other driver, the command completes 411 * with a busy return value and the timeout field indicates the maximum 412 * time the current owner of the resource has to free it. 413 */ 414 if (!err || hw->aci.last_status == LIBIE_AQ_RC_EBUSY) 415 *timeout = le32_to_cpu(cmd_resp->timeout); 416 417 return err; 418 } 419 420 /** 421 * ixgbe_aci_release_res - release a common resource using ACI 422 * @hw: pointer to the HW struct 423 * @res: resource ID 424 * @sdp_number: resource number 425 * 426 * Release a common resource using ACI command (0x0009). 427 * 428 * Return: the exit code of the operation. 429 */ 430 static int ixgbe_aci_release_res(struct ixgbe_hw *hw, enum libie_aq_res_id res, 431 u8 sdp_number) 432 { 433 struct libie_aqc_req_res *cmd; 434 struct libie_aq_desc desc; 435 436 cmd = &desc.params.res_owner; 437 438 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_release_res); 439 440 cmd->res_id = cpu_to_le16(res); 441 cmd->res_number = cpu_to_le32(sdp_number); 442 443 return ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 444 } 445 446 /** 447 * ixgbe_acquire_res - acquire the ownership of a resource 448 * @hw: pointer to the HW structure 449 * @res: resource ID 450 * @access: access type (read or write) 451 * @timeout: timeout in milliseconds 452 * 453 * Make an attempt to acquire the ownership of a resource using 454 * the ixgbe_aci_req_res to utilize ACI. 455 * In case if some other driver has previously acquired the resource and 456 * performed any necessary updates, the -EALREADY is returned, 457 * and the caller does not obtain the resource and has no further work to do. 458 * If needed, the function will poll until the current lock owner timeouts. 459 * 460 * Return: the exit code of the operation. 461 */ 462 int ixgbe_acquire_res(struct ixgbe_hw *hw, enum libie_aq_res_id res, 463 enum libie_aq_res_access_type access, u32 timeout) 464 { 465 #define IXGBE_RES_POLLING_DELAY_MS 10 466 u32 delay = IXGBE_RES_POLLING_DELAY_MS; 467 u32 res_timeout = timeout; 468 u32 retry_timeout; 469 int err; 470 471 err = ixgbe_aci_req_res(hw, res, access, 0, &res_timeout); 472 473 /* A return code of -EALREADY means that another driver has 474 * previously acquired the resource and performed any necessary updates; 475 * in this case the caller does not obtain the resource and has no 476 * further work to do. 477 */ 478 if (err == -EALREADY) 479 return err; 480 481 /* If necessary, poll until the current lock owner timeouts. 482 * Set retry_timeout to the timeout value reported by the FW in the 483 * response to the "Request Resource Ownership" (0x0008) Admin Command 484 * as it indicates the maximum time the current owner of the resource 485 * is allowed to hold it. 486 */ 487 retry_timeout = res_timeout; 488 while (err && retry_timeout && res_timeout) { 489 msleep(delay); 490 retry_timeout = (retry_timeout > delay) ? 491 retry_timeout - delay : 0; 492 err = ixgbe_aci_req_res(hw, res, access, 0, &res_timeout); 493 494 /* Success - lock acquired. 495 * -EALREADY - lock free, no work to do. 496 */ 497 if (!err || err == -EALREADY) 498 break; 499 } 500 501 return err; 502 } 503 504 /** 505 * ixgbe_release_res - release a common resource 506 * @hw: pointer to the HW structure 507 * @res: resource ID 508 * 509 * Release a common resource using ixgbe_aci_release_res. 510 */ 511 void ixgbe_release_res(struct ixgbe_hw *hw, enum libie_aq_res_id res) 512 { 513 u32 total_delay = 0; 514 int err; 515 516 err = ixgbe_aci_release_res(hw, res, 0); 517 518 /* There are some rare cases when trying to release the resource 519 * results in an admin command timeout, so handle them correctly. 520 */ 521 while (err == -ETIME && 522 total_delay < IXGBE_ACI_RELEASE_RES_TIMEOUT) { 523 usleep_range(1000, 1500); 524 err = ixgbe_aci_release_res(hw, res, 0); 525 total_delay++; 526 } 527 } 528 529 /** 530 * ixgbe_parse_e610_caps - Parse common device/function capabilities 531 * @hw: pointer to the HW struct 532 * @caps: pointer to common capabilities structure 533 * @elem: the capability element to parse 534 * @prefix: message prefix for tracing capabilities 535 * 536 * Given a capability element, extract relevant details into the common 537 * capability structure. 538 * 539 * Return: true if the capability matches one of the common capability ids, 540 * false otherwise. 541 */ 542 static bool ixgbe_parse_e610_caps(struct ixgbe_hw *hw, 543 struct ixgbe_hw_caps *caps, 544 struct libie_aqc_list_caps_elem *elem, 545 const char *prefix) 546 { 547 u32 logical_id = le32_to_cpu(elem->logical_id); 548 u32 phys_id = le32_to_cpu(elem->phys_id); 549 u32 number = le32_to_cpu(elem->number); 550 u16 cap = le16_to_cpu(elem->cap); 551 552 switch (cap) { 553 case LIBIE_AQC_CAPS_VALID_FUNCTIONS: 554 caps->valid_functions = number; 555 break; 556 case LIBIE_AQC_CAPS_SRIOV: 557 caps->sr_iov_1_1 = (number == 1); 558 break; 559 case LIBIE_AQC_CAPS_VMDQ: 560 caps->vmdq = (number == 1); 561 break; 562 case LIBIE_AQC_CAPS_DCB: 563 caps->dcb = (number == 1); 564 caps->active_tc_bitmap = logical_id; 565 caps->maxtc = phys_id; 566 break; 567 case LIBIE_AQC_CAPS_RSS: 568 caps->rss_table_size = number; 569 caps->rss_table_entry_width = logical_id; 570 break; 571 case LIBIE_AQC_CAPS_RXQS: 572 caps->num_rxq = number; 573 caps->rxq_first_id = phys_id; 574 break; 575 case LIBIE_AQC_CAPS_TXQS: 576 caps->num_txq = number; 577 caps->txq_first_id = phys_id; 578 break; 579 case LIBIE_AQC_CAPS_MSIX: 580 caps->num_msix_vectors = number; 581 caps->msix_vector_first_id = phys_id; 582 break; 583 case LIBIE_AQC_CAPS_NVM_VER: 584 break; 585 case LIBIE_AQC_CAPS_PENDING_NVM_VER: 586 caps->nvm_update_pending_nvm = true; 587 break; 588 case LIBIE_AQC_CAPS_PENDING_OROM_VER: 589 caps->nvm_update_pending_orom = true; 590 break; 591 case LIBIE_AQC_CAPS_PENDING_NET_VER: 592 caps->nvm_update_pending_netlist = true; 593 break; 594 case LIBIE_AQC_CAPS_NVM_MGMT: 595 caps->nvm_unified_update = 596 (number & IXGBE_NVM_MGMT_UNIFIED_UPD_SUPPORT) ? 597 true : false; 598 break; 599 case LIBIE_AQC_CAPS_MAX_MTU: 600 caps->max_mtu = number; 601 break; 602 case LIBIE_AQC_CAPS_PCIE_RESET_AVOIDANCE: 603 caps->pcie_reset_avoidance = (number > 0); 604 break; 605 case LIBIE_AQC_CAPS_POST_UPDATE_RESET_RESTRICT: 606 caps->reset_restrict_support = (number == 1); 607 break; 608 case LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG0: 609 case LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG1: 610 case LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG2: 611 case LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG3: 612 { 613 u8 index = cap - LIBIE_AQC_CAPS_EXT_TOPO_DEV_IMG0; 614 615 caps->ext_topo_dev_img_ver_high[index] = number; 616 caps->ext_topo_dev_img_ver_low[index] = logical_id; 617 caps->ext_topo_dev_img_part_num[index] = 618 FIELD_GET(IXGBE_EXT_TOPO_DEV_IMG_PART_NUM_M, phys_id); 619 caps->ext_topo_dev_img_load_en[index] = 620 (phys_id & IXGBE_EXT_TOPO_DEV_IMG_LOAD_EN) != 0; 621 caps->ext_topo_dev_img_prog_en[index] = 622 (phys_id & IXGBE_EXT_TOPO_DEV_IMG_PROG_EN) != 0; 623 break; 624 } 625 case LIBIE_AQC_CAPS_EEE: 626 caps->eee_support = (u8)number; 627 break; 628 default: 629 /* Not one of the recognized common capabilities */ 630 return false; 631 } 632 633 return true; 634 } 635 636 /** 637 * ixgbe_parse_valid_functions_cap - Parse LIBIE_AQC_CAPS_VALID_FUNCTIONS caps 638 * @hw: pointer to the HW struct 639 * @dev_p: pointer to device capabilities structure 640 * @cap: capability element to parse 641 * 642 * Parse LIBIE_AQC_CAPS_VALID_FUNCTIONS for device capabilities. 643 */ 644 static void 645 ixgbe_parse_valid_functions_cap(struct ixgbe_hw *hw, 646 struct ixgbe_hw_dev_caps *dev_p, 647 struct libie_aqc_list_caps_elem *cap) 648 { 649 dev_p->num_funcs = hweight32(le32_to_cpu(cap->number)); 650 } 651 652 /** 653 * ixgbe_parse_vf_dev_caps - Parse LIBIE_AQC_CAPS_VF device caps 654 * @hw: pointer to the HW struct 655 * @dev_p: pointer to device capabilities structure 656 * @cap: capability element to parse 657 * 658 * Parse LIBIE_AQC_CAPS_VF for device capabilities. 659 */ 660 static void ixgbe_parse_vf_dev_caps(struct ixgbe_hw *hw, 661 struct ixgbe_hw_dev_caps *dev_p, 662 struct libie_aqc_list_caps_elem *cap) 663 { 664 dev_p->num_vfs_exposed = le32_to_cpu(cap->number); 665 } 666 667 /** 668 * ixgbe_parse_vsi_dev_caps - Parse LIBIE_AQC_CAPS_VSI device caps 669 * @hw: pointer to the HW struct 670 * @dev_p: pointer to device capabilities structure 671 * @cap: capability element to parse 672 * 673 * Parse LIBIE_AQC_CAPS_VSI for device capabilities. 674 */ 675 static void ixgbe_parse_vsi_dev_caps(struct ixgbe_hw *hw, 676 struct ixgbe_hw_dev_caps *dev_p, 677 struct libie_aqc_list_caps_elem *cap) 678 { 679 dev_p->num_vsi_allocd_to_host = le32_to_cpu(cap->number); 680 } 681 682 /** 683 * ixgbe_parse_fdir_dev_caps - Parse LIBIE_AQC_CAPS_FD device caps 684 * @hw: pointer to the HW struct 685 * @dev_p: pointer to device capabilities structure 686 * @cap: capability element to parse 687 * 688 * Parse LIBIE_AQC_CAPS_FD for device capabilities. 689 */ 690 static void ixgbe_parse_fdir_dev_caps(struct ixgbe_hw *hw, 691 struct ixgbe_hw_dev_caps *dev_p, 692 struct libie_aqc_list_caps_elem *cap) 693 { 694 dev_p->num_flow_director_fltr = le32_to_cpu(cap->number); 695 } 696 697 /** 698 * ixgbe_parse_dev_caps - Parse device capabilities 699 * @hw: pointer to the HW struct 700 * @dev_p: pointer to device capabilities structure 701 * @buf: buffer containing the device capability records 702 * @cap_count: the number of capabilities 703 * 704 * Helper device to parse device (0x000B) capabilities list. For 705 * capabilities shared between device and function, this relies on 706 * ixgbe_parse_e610_caps. 707 * 708 * Loop through the list of provided capabilities and extract the relevant 709 * data into the device capabilities structured. 710 */ 711 static void ixgbe_parse_dev_caps(struct ixgbe_hw *hw, 712 struct ixgbe_hw_dev_caps *dev_p, 713 void *buf, u32 cap_count) 714 { 715 struct libie_aqc_list_caps_elem *cap_resp; 716 u32 i; 717 718 cap_resp = (struct libie_aqc_list_caps_elem *)buf; 719 720 memset(dev_p, 0, sizeof(*dev_p)); 721 722 for (i = 0; i < cap_count; i++) { 723 u16 cap = le16_to_cpu(cap_resp[i].cap); 724 725 ixgbe_parse_e610_caps(hw, &dev_p->common_cap, &cap_resp[i], 726 "dev caps"); 727 728 switch (cap) { 729 case LIBIE_AQC_CAPS_VALID_FUNCTIONS: 730 ixgbe_parse_valid_functions_cap(hw, dev_p, 731 &cap_resp[i]); 732 break; 733 case LIBIE_AQC_CAPS_VF: 734 ixgbe_parse_vf_dev_caps(hw, dev_p, &cap_resp[i]); 735 break; 736 case LIBIE_AQC_CAPS_VSI: 737 ixgbe_parse_vsi_dev_caps(hw, dev_p, &cap_resp[i]); 738 break; 739 case LIBIE_AQC_CAPS_FD: 740 ixgbe_parse_fdir_dev_caps(hw, dev_p, &cap_resp[i]); 741 break; 742 default: 743 /* Don't list common capabilities as unknown */ 744 break; 745 } 746 } 747 } 748 749 /** 750 * ixgbe_parse_vf_func_caps - Parse LIBIE_AQC_CAPS_VF function caps 751 * @hw: pointer to the HW struct 752 * @func_p: pointer to function capabilities structure 753 * @cap: pointer to the capability element to parse 754 * 755 * Extract function capabilities for LIBIE_AQC_CAPS_VF. 756 */ 757 static void ixgbe_parse_vf_func_caps(struct ixgbe_hw *hw, 758 struct ixgbe_hw_func_caps *func_p, 759 struct libie_aqc_list_caps_elem *cap) 760 { 761 func_p->num_allocd_vfs = le32_to_cpu(cap->number); 762 func_p->vf_base_id = le32_to_cpu(cap->logical_id); 763 } 764 765 /** 766 * ixgbe_get_num_per_func - determine number of resources per PF 767 * @hw: pointer to the HW structure 768 * @max: value to be evenly split between each PF 769 * 770 * Determine the number of valid functions by going through the bitmap returned 771 * from parsing capabilities and use this to calculate the number of resources 772 * per PF based on the max value passed in. 773 * 774 * Return: the number of resources per PF or 0, if no PFs are available. 775 */ 776 static u32 ixgbe_get_num_per_func(struct ixgbe_hw *hw, u32 max) 777 { 778 #define IXGBE_CAPS_VALID_FUNCS_M GENMASK(7, 0) 779 u8 funcs = hweight8(hw->dev_caps.common_cap.valid_functions & 780 IXGBE_CAPS_VALID_FUNCS_M); 781 782 return funcs ? (max / funcs) : 0; 783 } 784 785 /** 786 * ixgbe_parse_vsi_func_caps - Parse LIBIE_AQC_CAPS_VSI function caps 787 * @hw: pointer to the HW struct 788 * @func_p: pointer to function capabilities structure 789 * @cap: pointer to the capability element to parse 790 * 791 * Extract function capabilities for LIBIE_AQC_CAPS_VSI. 792 */ 793 static void ixgbe_parse_vsi_func_caps(struct ixgbe_hw *hw, 794 struct ixgbe_hw_func_caps *func_p, 795 struct libie_aqc_list_caps_elem *cap) 796 { 797 func_p->guar_num_vsi = ixgbe_get_num_per_func(hw, IXGBE_MAX_VSI); 798 } 799 800 /** 801 * ixgbe_parse_func_caps - Parse function capabilities 802 * @hw: pointer to the HW struct 803 * @func_p: pointer to function capabilities structure 804 * @buf: buffer containing the function capability records 805 * @cap_count: the number of capabilities 806 * 807 * Helper function to parse function (0x000A) capabilities list. For 808 * capabilities shared between device and function, this relies on 809 * ixgbe_parse_e610_caps. 810 * 811 * Loop through the list of provided capabilities and extract the relevant 812 * data into the function capabilities structured. 813 */ 814 static void ixgbe_parse_func_caps(struct ixgbe_hw *hw, 815 struct ixgbe_hw_func_caps *func_p, 816 void *buf, u32 cap_count) 817 { 818 struct libie_aqc_list_caps_elem *cap_resp; 819 u32 i; 820 821 cap_resp = (struct libie_aqc_list_caps_elem *)buf; 822 823 memset(func_p, 0, sizeof(*func_p)); 824 825 for (i = 0; i < cap_count; i++) { 826 u16 cap = le16_to_cpu(cap_resp[i].cap); 827 828 ixgbe_parse_e610_caps(hw, &func_p->common_cap, 829 &cap_resp[i], "func caps"); 830 831 switch (cap) { 832 case LIBIE_AQC_CAPS_VF: 833 ixgbe_parse_vf_func_caps(hw, func_p, &cap_resp[i]); 834 break; 835 case LIBIE_AQC_CAPS_VSI: 836 ixgbe_parse_vsi_func_caps(hw, func_p, &cap_resp[i]); 837 break; 838 default: 839 /* Don't list common capabilities as unknown */ 840 break; 841 } 842 } 843 } 844 845 /** 846 * ixgbe_aci_list_caps - query function/device capabilities 847 * @hw: pointer to the HW struct 848 * @buf: a buffer to hold the capabilities 849 * @buf_size: size of the buffer 850 * @cap_count: if not NULL, set to the number of capabilities reported 851 * @opc: capabilities type to discover, device or function 852 * 853 * Get the function (0x000A) or device (0x000B) capabilities description from 854 * firmware and store it in the buffer. 855 * 856 * If the cap_count pointer is not NULL, then it is set to the number of 857 * capabilities firmware will report. Note that if the buffer size is too 858 * small, it is possible the command will return -ENOMEM. The 859 * cap_count will still be updated in this case. It is recommended that the 860 * buffer size be set to IXGBE_ACI_MAX_BUFFER_SIZE (the largest possible 861 * buffer that firmware could return) to avoid this. 862 * 863 * Return: the exit code of the operation. 864 * Exit code of -ENOMEM means the buffer size is too small. 865 */ 866 int ixgbe_aci_list_caps(struct ixgbe_hw *hw, void *buf, u16 buf_size, 867 u32 *cap_count, enum ixgbe_aci_opc opc) 868 { 869 struct libie_aqc_list_caps *cmd; 870 struct libie_aq_desc desc; 871 int err; 872 873 cmd = &desc.params.get_cap; 874 875 if (opc != ixgbe_aci_opc_list_func_caps && 876 opc != ixgbe_aci_opc_list_dev_caps) 877 return -EINVAL; 878 879 ixgbe_fill_dflt_direct_cmd_desc(&desc, opc); 880 err = ixgbe_aci_send_cmd(hw, &desc, buf, buf_size); 881 882 if (cap_count) 883 *cap_count = le32_to_cpu(cmd->count); 884 885 return err; 886 } 887 888 /** 889 * ixgbe_discover_dev_caps - Read and extract device capabilities 890 * @hw: pointer to the hardware structure 891 * @dev_caps: pointer to device capabilities structure 892 * 893 * Read the device capabilities and extract them into the dev_caps structure 894 * for later use. 895 * 896 * Return: the exit code of the operation. 897 */ 898 int ixgbe_discover_dev_caps(struct ixgbe_hw *hw, 899 struct ixgbe_hw_dev_caps *dev_caps) 900 { 901 u32 cap_count; 902 u8 *cbuf; 903 int err; 904 905 cbuf = kzalloc(IXGBE_ACI_MAX_BUFFER_SIZE, GFP_KERNEL); 906 if (!cbuf) 907 return -ENOMEM; 908 909 /* Although the driver doesn't know the number of capabilities the 910 * device will return, we can simply send a 4KB buffer, the maximum 911 * possible size that firmware can return. 912 */ 913 cap_count = IXGBE_ACI_MAX_BUFFER_SIZE / 914 sizeof(struct libie_aqc_list_caps_elem); 915 916 err = ixgbe_aci_list_caps(hw, cbuf, IXGBE_ACI_MAX_BUFFER_SIZE, 917 &cap_count, 918 ixgbe_aci_opc_list_dev_caps); 919 if (!err) 920 ixgbe_parse_dev_caps(hw, dev_caps, cbuf, cap_count); 921 922 kfree(cbuf); 923 924 return 0; 925 } 926 927 /** 928 * ixgbe_discover_func_caps - Read and extract function capabilities 929 * @hw: pointer to the hardware structure 930 * @func_caps: pointer to function capabilities structure 931 * 932 * Read the function capabilities and extract them into the func_caps structure 933 * for later use. 934 * 935 * Return: the exit code of the operation. 936 */ 937 int ixgbe_discover_func_caps(struct ixgbe_hw *hw, 938 struct ixgbe_hw_func_caps *func_caps) 939 { 940 u32 cap_count; 941 u8 *cbuf; 942 int err; 943 944 cbuf = kzalloc(IXGBE_ACI_MAX_BUFFER_SIZE, GFP_KERNEL); 945 if (!cbuf) 946 return -ENOMEM; 947 948 /* Although the driver doesn't know the number of capabilities the 949 * device will return, we can simply send a 4KB buffer, the maximum 950 * possible size that firmware can return. 951 */ 952 cap_count = IXGBE_ACI_MAX_BUFFER_SIZE / 953 sizeof(struct libie_aqc_list_caps_elem); 954 955 err = ixgbe_aci_list_caps(hw, cbuf, IXGBE_ACI_MAX_BUFFER_SIZE, 956 &cap_count, 957 ixgbe_aci_opc_list_func_caps); 958 if (!err) 959 ixgbe_parse_func_caps(hw, func_caps, cbuf, cap_count); 960 961 kfree(cbuf); 962 963 return 0; 964 } 965 966 /** 967 * ixgbe_get_caps - get info about the HW 968 * @hw: pointer to the hardware structure 969 * 970 * Retrieve both device and function capabilities. 971 * 972 * Return: the exit code of the operation. 973 */ 974 int ixgbe_get_caps(struct ixgbe_hw *hw) 975 { 976 int err; 977 978 err = ixgbe_discover_dev_caps(hw, &hw->dev_caps); 979 if (err) 980 return err; 981 982 return ixgbe_discover_func_caps(hw, &hw->func_caps); 983 } 984 985 /** 986 * ixgbe_aci_disable_rxen - disable RX 987 * @hw: pointer to the HW struct 988 * 989 * Request a safe disable of Receive Enable using ACI command (0x000C). 990 * 991 * Return: the exit code of the operation. 992 */ 993 int ixgbe_aci_disable_rxen(struct ixgbe_hw *hw) 994 { 995 struct ixgbe_aci_cmd_disable_rxen *cmd; 996 struct libie_aq_desc desc; 997 998 cmd = libie_aq_raw(&desc); 999 1000 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_disable_rxen); 1001 1002 cmd->lport_num = hw->bus.func; 1003 1004 return ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 1005 } 1006 1007 /** 1008 * ixgbe_aci_get_phy_caps - returns PHY capabilities 1009 * @hw: pointer to the HW struct 1010 * @qual_mods: report qualified modules 1011 * @report_mode: report mode capabilities 1012 * @pcaps: structure for PHY capabilities to be filled 1013 * 1014 * Returns the various PHY capabilities supported on the Port 1015 * using ACI command (0x0600). 1016 * 1017 * Return: the exit code of the operation. 1018 */ 1019 int ixgbe_aci_get_phy_caps(struct ixgbe_hw *hw, bool qual_mods, u8 report_mode, 1020 struct ixgbe_aci_cmd_get_phy_caps_data *pcaps) 1021 { 1022 struct ixgbe_aci_cmd_get_phy_caps *cmd; 1023 u16 pcaps_size = sizeof(*pcaps); 1024 struct libie_aq_desc desc; 1025 int err; 1026 1027 cmd = libie_aq_raw(&desc); 1028 1029 if (!pcaps || (report_mode & ~IXGBE_ACI_REPORT_MODE_M)) 1030 return -EINVAL; 1031 1032 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_get_phy_caps); 1033 1034 if (qual_mods) 1035 cmd->param0 |= cpu_to_le16(IXGBE_ACI_GET_PHY_RQM); 1036 1037 cmd->param0 |= cpu_to_le16(report_mode); 1038 err = ixgbe_aci_send_cmd(hw, &desc, pcaps, pcaps_size); 1039 if (!err && report_mode == IXGBE_ACI_REPORT_TOPO_CAP_MEDIA) { 1040 hw->phy.phy_type_low = le64_to_cpu(pcaps->phy_type_low); 1041 hw->phy.phy_type_high = le64_to_cpu(pcaps->phy_type_high); 1042 memcpy(hw->link.link_info.module_type, &pcaps->module_type, 1043 sizeof(hw->link.link_info.module_type)); 1044 } 1045 1046 return err; 1047 } 1048 1049 /** 1050 * ixgbe_copy_phy_caps_to_cfg - Copy PHY ability data to configuration data 1051 * @caps: PHY ability structure to copy data from 1052 * @cfg: PHY configuration structure to copy data to 1053 * 1054 * Helper function to copy data from PHY capabilities data structure 1055 * to PHY configuration data structure 1056 */ 1057 void ixgbe_copy_phy_caps_to_cfg(struct ixgbe_aci_cmd_get_phy_caps_data *caps, 1058 struct ixgbe_aci_cmd_set_phy_cfg_data *cfg) 1059 { 1060 if (!caps || !cfg) 1061 return; 1062 1063 memset(cfg, 0, sizeof(*cfg)); 1064 cfg->phy_type_low = caps->phy_type_low; 1065 cfg->phy_type_high = caps->phy_type_high; 1066 cfg->caps = caps->caps; 1067 cfg->low_power_ctrl_an = caps->low_power_ctrl_an; 1068 cfg->eee_cap = caps->eee_cap; 1069 cfg->eeer_value = caps->eeer_value; 1070 cfg->link_fec_opt = caps->link_fec_options; 1071 cfg->module_compliance_enforcement = 1072 caps->module_compliance_enforcement; 1073 cfg->eee_entry_delay = caps->eee_entry_delay; 1074 } 1075 1076 /** 1077 * ixgbe_aci_set_phy_cfg - set PHY configuration 1078 * @hw: pointer to the HW struct 1079 * @cfg: structure with PHY configuration data to be set 1080 * 1081 * Set the various PHY configuration parameters supported on the Port 1082 * using ACI command (0x0601). 1083 * One or more of the Set PHY config parameters may be ignored in an MFP 1084 * mode as the PF may not have the privilege to set some of the PHY Config 1085 * parameters. 1086 * 1087 * Return: the exit code of the operation. 1088 */ 1089 int ixgbe_aci_set_phy_cfg(struct ixgbe_hw *hw, 1090 struct ixgbe_aci_cmd_set_phy_cfg_data *cfg) 1091 { 1092 struct ixgbe_aci_cmd_set_phy_cfg *cmd; 1093 struct libie_aq_desc desc; 1094 bool use_buff_eee_field; 1095 u16 buf_size; 1096 int err; 1097 1098 if (!cfg) 1099 return -EINVAL; 1100 1101 /* If FW supports EEE, we have to use buffer with EEE field. */ 1102 use_buff_eee_field = hw->dev_caps.common_cap.eee_support; 1103 1104 cmd = libie_aq_raw(&desc); 1105 /* Ensure that only valid bits of cfg->caps can be turned on. */ 1106 cfg->caps &= IXGBE_ACI_PHY_ENA_VALID_MASK; 1107 1108 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_set_phy_cfg); 1109 cmd->lport_num = hw->bus.func; 1110 desc.flags |= cpu_to_le16(LIBIE_AQ_FLAG_RD); 1111 1112 if (use_buff_eee_field) 1113 buf_size = sizeof(*cfg); 1114 else 1115 /* Buffer w/o eee_entry_delay field is 2B smaller. */ 1116 buf_size = sizeof(*cfg) - sizeof(u16); 1117 1118 err = ixgbe_aci_send_cmd(hw, &desc, cfg, buf_size); 1119 1120 /* 1.40 config format is compatible with pre-1.40, just extends 1121 * it at the end. 1122 */ 1123 if (!err) 1124 hw->phy.curr_user_phy_cfg = *cfg; 1125 1126 return err; 1127 } 1128 1129 /** 1130 * ixgbe_aci_set_link_restart_an - set up link and restart AN 1131 * @hw: pointer to the HW struct 1132 * @ena_link: if true: enable link, if false: disable link 1133 * 1134 * Function sets up the link and restarts the Auto-Negotiation over the link. 1135 * 1136 * Return: the exit code of the operation. 1137 */ 1138 int ixgbe_aci_set_link_restart_an(struct ixgbe_hw *hw, bool ena_link) 1139 { 1140 struct ixgbe_aci_cmd_restart_an *cmd; 1141 struct libie_aq_desc desc; 1142 1143 cmd = libie_aq_raw(&desc); 1144 1145 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_restart_an); 1146 1147 cmd->cmd_flags = IXGBE_ACI_RESTART_AN_LINK_RESTART; 1148 cmd->lport_num = hw->bus.func; 1149 if (ena_link) 1150 cmd->cmd_flags |= IXGBE_ACI_RESTART_AN_LINK_ENABLE; 1151 else 1152 cmd->cmd_flags &= ~IXGBE_ACI_RESTART_AN_LINK_ENABLE; 1153 1154 return ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 1155 } 1156 1157 /** 1158 * ixgbe_is_media_cage_present - check if media cage is present 1159 * @hw: pointer to the HW struct 1160 * 1161 * Identify presence of media cage using the ACI command (0x06E0). 1162 * 1163 * Return: true if media cage is present, else false. If no cage, then 1164 * media type is backplane or BASE-T. 1165 */ 1166 static bool ixgbe_is_media_cage_present(struct ixgbe_hw *hw) 1167 { 1168 struct ixgbe_aci_cmd_get_link_topo *cmd; 1169 struct libie_aq_desc desc; 1170 1171 cmd = libie_aq_raw(&desc); 1172 1173 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_get_link_topo); 1174 1175 cmd->addr.topo_params.node_type_ctx = 1176 FIELD_PREP(IXGBE_ACI_LINK_TOPO_NODE_CTX_M, 1177 IXGBE_ACI_LINK_TOPO_NODE_CTX_PORT); 1178 1179 /* Set node type. */ 1180 cmd->addr.topo_params.node_type_ctx |= 1181 FIELD_PREP(IXGBE_ACI_LINK_TOPO_NODE_TYPE_M, 1182 IXGBE_ACI_LINK_TOPO_NODE_TYPE_CAGE); 1183 1184 /* Node type cage can be used to determine if cage is present. If AQC 1185 * returns error (ENOENT), then no cage present. If no cage present then 1186 * connection type is backplane or BASE-T. 1187 */ 1188 return !ixgbe_aci_get_netlist_node(hw, cmd, NULL, NULL); 1189 } 1190 1191 /** 1192 * ixgbe_get_media_type_from_phy_type - Gets media type based on phy type 1193 * @hw: pointer to the HW struct 1194 * 1195 * Try to identify the media type based on the phy type. 1196 * If more than one media type, the ixgbe_media_type_unknown is returned. 1197 * First, phy_type_low is checked, then phy_type_high. 1198 * If none are identified, the ixgbe_media_type_unknown is returned 1199 * 1200 * Return: type of a media based on phy type in form of enum. 1201 */ 1202 static enum ixgbe_media_type 1203 ixgbe_get_media_type_from_phy_type(struct ixgbe_hw *hw) 1204 { 1205 struct ixgbe_link_status *hw_link_info; 1206 1207 if (!hw) 1208 return ixgbe_media_type_unknown; 1209 1210 hw_link_info = &hw->link.link_info; 1211 if (hw_link_info->phy_type_low && hw_link_info->phy_type_high) 1212 /* If more than one media type is selected, report unknown */ 1213 return ixgbe_media_type_unknown; 1214 1215 if (hw_link_info->phy_type_low) { 1216 /* 1G SGMII is a special case where some DA cable PHYs 1217 * may show this as an option when it really shouldn't 1218 * be since SGMII is meant to be between a MAC and a PHY 1219 * in a backplane. Try to detect this case and handle it 1220 */ 1221 if (hw_link_info->phy_type_low == IXGBE_PHY_TYPE_LOW_1G_SGMII && 1222 (hw_link_info->module_type[IXGBE_ACI_MOD_TYPE_IDENT] == 1223 IXGBE_ACI_MOD_TYPE_BYTE1_SFP_PLUS_CU_ACTIVE || 1224 hw_link_info->module_type[IXGBE_ACI_MOD_TYPE_IDENT] == 1225 IXGBE_ACI_MOD_TYPE_BYTE1_SFP_PLUS_CU_PASSIVE)) 1226 return ixgbe_media_type_da; 1227 1228 switch (hw_link_info->phy_type_low) { 1229 case IXGBE_PHY_TYPE_LOW_1000BASE_SX: 1230 case IXGBE_PHY_TYPE_LOW_1000BASE_LX: 1231 case IXGBE_PHY_TYPE_LOW_10GBASE_SR: 1232 case IXGBE_PHY_TYPE_LOW_10GBASE_LR: 1233 case IXGBE_PHY_TYPE_LOW_25GBASE_SR: 1234 case IXGBE_PHY_TYPE_LOW_25GBASE_LR: 1235 return ixgbe_media_type_fiber; 1236 case IXGBE_PHY_TYPE_LOW_10G_SFI_AOC_ACC: 1237 case IXGBE_PHY_TYPE_LOW_25G_AUI_AOC_ACC: 1238 return ixgbe_media_type_fiber; 1239 case IXGBE_PHY_TYPE_LOW_100BASE_TX: 1240 case IXGBE_PHY_TYPE_LOW_1000BASE_T: 1241 case IXGBE_PHY_TYPE_LOW_2500BASE_T: 1242 case IXGBE_PHY_TYPE_LOW_5GBASE_T: 1243 case IXGBE_PHY_TYPE_LOW_10GBASE_T: 1244 case IXGBE_PHY_TYPE_LOW_25GBASE_T: 1245 return ixgbe_media_type_copper; 1246 case IXGBE_PHY_TYPE_LOW_10G_SFI_DA: 1247 case IXGBE_PHY_TYPE_LOW_25GBASE_CR: 1248 case IXGBE_PHY_TYPE_LOW_25GBASE_CR_S: 1249 case IXGBE_PHY_TYPE_LOW_25GBASE_CR1: 1250 return ixgbe_media_type_da; 1251 case IXGBE_PHY_TYPE_LOW_25G_AUI_C2C: 1252 if (ixgbe_is_media_cage_present(hw)) 1253 return ixgbe_media_type_aui; 1254 fallthrough; 1255 case IXGBE_PHY_TYPE_LOW_1000BASE_KX: 1256 case IXGBE_PHY_TYPE_LOW_2500BASE_KX: 1257 case IXGBE_PHY_TYPE_LOW_2500BASE_X: 1258 case IXGBE_PHY_TYPE_LOW_5GBASE_KR: 1259 case IXGBE_PHY_TYPE_LOW_10GBASE_KR_CR1: 1260 case IXGBE_PHY_TYPE_LOW_10G_SFI_C2C: 1261 case IXGBE_PHY_TYPE_LOW_25GBASE_KR: 1262 case IXGBE_PHY_TYPE_LOW_25GBASE_KR1: 1263 case IXGBE_PHY_TYPE_LOW_25GBASE_KR_S: 1264 return ixgbe_media_type_backplane; 1265 } 1266 } else { 1267 switch (hw_link_info->phy_type_high) { 1268 case IXGBE_PHY_TYPE_HIGH_10BASE_T: 1269 return ixgbe_media_type_copper; 1270 } 1271 } 1272 return ixgbe_media_type_unknown; 1273 } 1274 1275 /** 1276 * ixgbe_update_link_info - update status of the HW network link 1277 * @hw: pointer to the HW struct 1278 * 1279 * Update the status of the HW network link. 1280 * 1281 * Return: the exit code of the operation. 1282 */ 1283 int ixgbe_update_link_info(struct ixgbe_hw *hw) 1284 { 1285 struct ixgbe_aci_cmd_get_phy_caps_data *pcaps; 1286 struct ixgbe_link_status *li; 1287 int err; 1288 1289 if (!hw) 1290 return -EINVAL; 1291 1292 li = &hw->link.link_info; 1293 1294 err = ixgbe_aci_get_link_info(hw, true, NULL); 1295 if (err) 1296 return err; 1297 1298 if (!(li->link_info & IXGBE_ACI_MEDIA_AVAILABLE)) 1299 return 0; 1300 1301 pcaps = kzalloc_obj(*pcaps); 1302 if (!pcaps) 1303 return -ENOMEM; 1304 1305 err = ixgbe_aci_get_phy_caps(hw, false, IXGBE_ACI_REPORT_TOPO_CAP_MEDIA, 1306 pcaps); 1307 1308 if (!err) 1309 memcpy(li->module_type, &pcaps->module_type, 1310 sizeof(li->module_type)); 1311 1312 kfree(pcaps); 1313 1314 return err; 1315 } 1316 1317 /** 1318 * ixgbe_get_link_status - get status of the HW network link 1319 * @hw: pointer to the HW struct 1320 * @link_up: pointer to bool (true/false = linkup/linkdown) 1321 * 1322 * Variable link_up is true if link is up, false if link is down. 1323 * The variable link_up is invalid if status is non zero. As a 1324 * result of this call, link status reporting becomes enabled 1325 * 1326 * Return: the exit code of the operation. 1327 */ 1328 int ixgbe_get_link_status(struct ixgbe_hw *hw, bool *link_up) 1329 { 1330 if (!hw || !link_up) 1331 return -EINVAL; 1332 1333 if (hw->link.get_link_info) { 1334 int err = ixgbe_update_link_info(hw); 1335 1336 if (err) 1337 return err; 1338 } 1339 1340 *link_up = hw->link.link_info.link_info & IXGBE_ACI_LINK_UP; 1341 1342 return 0; 1343 } 1344 1345 /** 1346 * ixgbe_aci_get_link_info - get the link status 1347 * @hw: pointer to the HW struct 1348 * @ena_lse: enable/disable LinkStatusEvent reporting 1349 * @link: pointer to link status structure - optional 1350 * 1351 * Get the current Link Status using ACI command (0x607). 1352 * The current link can be optionally provided to update 1353 * the status. 1354 * 1355 * Return: the link status of the adapter. 1356 */ 1357 int ixgbe_aci_get_link_info(struct ixgbe_hw *hw, bool ena_lse, 1358 struct ixgbe_link_status *link) 1359 { 1360 struct ixgbe_aci_cmd_get_link_status_data link_data = {}; 1361 struct ixgbe_aci_cmd_get_link_status *resp; 1362 struct ixgbe_link_status *li_old, *li; 1363 struct ixgbe_fc_info *hw_fc_info; 1364 struct libie_aq_desc desc; 1365 bool tx_pause, rx_pause; 1366 u8 cmd_flags; 1367 int err; 1368 1369 if (!hw) 1370 return -EINVAL; 1371 1372 li_old = &hw->link.link_info_old; 1373 li = &hw->link.link_info; 1374 hw_fc_info = &hw->fc; 1375 1376 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_get_link_status); 1377 cmd_flags = (ena_lse) ? IXGBE_ACI_LSE_ENA : IXGBE_ACI_LSE_DIS; 1378 resp = libie_aq_raw(&desc); 1379 resp->cmd_flags = cpu_to_le16(cmd_flags); 1380 resp->lport_num = hw->bus.func; 1381 1382 err = ixgbe_aci_send_cmd(hw, &desc, &link_data, sizeof(link_data)); 1383 if (err) 1384 return err; 1385 1386 /* Save off old link status information. */ 1387 *li_old = *li; 1388 1389 /* Update current link status information. */ 1390 li->link_speed = le16_to_cpu(link_data.link_speed); 1391 li->phy_type_low = le64_to_cpu(link_data.phy_type_low); 1392 li->phy_type_high = le64_to_cpu(link_data.phy_type_high); 1393 li->link_info = link_data.link_info; 1394 li->link_cfg_err = link_data.link_cfg_err; 1395 li->an_info = link_data.an_info; 1396 li->ext_info = link_data.ext_info; 1397 li->max_frame_size = le16_to_cpu(link_data.max_frame_size); 1398 li->fec_info = link_data.cfg & IXGBE_ACI_FEC_MASK; 1399 li->topo_media_conflict = link_data.topo_media_conflict; 1400 li->pacing = link_data.cfg & (IXGBE_ACI_CFG_PACING_M | 1401 IXGBE_ACI_CFG_PACING_TYPE_M); 1402 li->eee_status = link_data.eee_status; 1403 1404 /* Update fc info. */ 1405 tx_pause = !!(link_data.an_info & IXGBE_ACI_LINK_PAUSE_TX); 1406 rx_pause = !!(link_data.an_info & IXGBE_ACI_LINK_PAUSE_RX); 1407 if (tx_pause && rx_pause) 1408 hw_fc_info->current_mode = ixgbe_fc_full; 1409 else if (tx_pause) 1410 hw_fc_info->current_mode = ixgbe_fc_tx_pause; 1411 else if (rx_pause) 1412 hw_fc_info->current_mode = ixgbe_fc_rx_pause; 1413 else 1414 hw_fc_info->current_mode = ixgbe_fc_none; 1415 1416 li->lse_ena = !!(le16_to_cpu(resp->cmd_flags) & 1417 IXGBE_ACI_LSE_IS_ENABLED); 1418 1419 /* Save link status information. */ 1420 if (link) 1421 *link = *li; 1422 1423 /* Flag cleared so calling functions don't call AQ again. */ 1424 hw->link.get_link_info = false; 1425 1426 return 0; 1427 } 1428 1429 /** 1430 * ixgbe_aci_set_event_mask - set event mask 1431 * @hw: pointer to the HW struct 1432 * @port_num: port number of the physical function 1433 * @mask: event mask to be set 1434 * 1435 * Set the event mask using ACI command (0x0613). 1436 * 1437 * Return: the exit code of the operation. 1438 */ 1439 int ixgbe_aci_set_event_mask(struct ixgbe_hw *hw, u8 port_num, u16 mask) 1440 { 1441 struct ixgbe_aci_cmd_set_event_mask *cmd; 1442 struct libie_aq_desc desc; 1443 1444 cmd = libie_aq_raw(&desc); 1445 1446 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_set_event_mask); 1447 1448 cmd->lport_num = port_num; 1449 1450 cmd->event_mask = cpu_to_le16(mask); 1451 return ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 1452 } 1453 1454 /** 1455 * ixgbe_configure_lse - enable/disable link status events 1456 * @hw: pointer to the HW struct 1457 * @activate: true for enable lse, false otherwise 1458 * @mask: event mask to be set; a set bit means deactivation of the 1459 * corresponding event 1460 * 1461 * Set the event mask and then enable or disable link status events 1462 * 1463 * Return: the exit code of the operation. 1464 */ 1465 int ixgbe_configure_lse(struct ixgbe_hw *hw, bool activate, u16 mask) 1466 { 1467 int err; 1468 1469 err = ixgbe_aci_set_event_mask(hw, (u8)hw->bus.func, mask); 1470 if (err) 1471 return err; 1472 1473 /* Enabling link status events generation by fw. */ 1474 return ixgbe_aci_get_link_info(hw, activate, NULL); 1475 } 1476 1477 /** 1478 * ixgbe_start_hw_e610 - Prepare hardware for Tx/Rx 1479 * @hw: pointer to hardware structure 1480 * 1481 * Get firmware version and start the hardware using the generic 1482 * start_hw() and ixgbe_start_hw_gen2() functions. 1483 * 1484 * Return: the exit code of the operation. 1485 */ 1486 static int ixgbe_start_hw_e610(struct ixgbe_hw *hw) 1487 { 1488 int err; 1489 1490 err = ixgbe_aci_get_fw_ver(hw); 1491 if (err) 1492 return err; 1493 1494 err = ixgbe_start_hw_generic(hw); 1495 if (err) 1496 return err; 1497 1498 ixgbe_start_hw_gen2(hw); 1499 1500 return 0; 1501 } 1502 1503 /** 1504 * ixgbe_aci_set_port_id_led - set LED value for the given port 1505 * @hw: pointer to the HW struct 1506 * @orig_mode: set LED original mode 1507 * 1508 * Set LED value for the given port (0x06E9) 1509 * 1510 * Return: the exit code of the operation. 1511 */ 1512 int ixgbe_aci_set_port_id_led(struct ixgbe_hw *hw, bool orig_mode) 1513 { 1514 struct ixgbe_aci_cmd_set_port_id_led *cmd; 1515 struct libie_aq_desc desc; 1516 1517 cmd = libie_aq_raw(&desc); 1518 1519 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_set_port_id_led); 1520 1521 cmd->lport_num = (u8)hw->bus.func; 1522 cmd->lport_num_valid = IXGBE_ACI_PORT_ID_PORT_NUM_VALID; 1523 1524 if (orig_mode) 1525 cmd->ident_mode = IXGBE_ACI_PORT_IDENT_LED_ORIG; 1526 else 1527 cmd->ident_mode = IXGBE_ACI_PORT_IDENT_LED_BLINK; 1528 1529 return ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 1530 } 1531 1532 /** 1533 * ixgbe_get_media_type_e610 - Gets media type 1534 * @hw: pointer to the HW struct 1535 * 1536 * In order to get the media type, the function gets PHY 1537 * capabilities and later on use them to identify the PHY type 1538 * checking phy_type_high and phy_type_low. 1539 * 1540 * Return: the type of media in form of ixgbe_media_type enum 1541 * or ixgbe_media_type_unknown in case of an error. 1542 */ 1543 enum ixgbe_media_type ixgbe_get_media_type_e610(struct ixgbe_hw *hw) 1544 { 1545 struct ixgbe_aci_cmd_get_phy_caps_data pcaps; 1546 int rc; 1547 1548 rc = ixgbe_update_link_info(hw); 1549 if (rc) 1550 return ixgbe_media_type_unknown; 1551 1552 /* If there is no link but PHY (dongle) is available SW should use 1553 * Get PHY Caps admin command instead of Get Link Status, find most 1554 * significant bit that is set in PHY types reported by the command 1555 * and use it to discover media type. 1556 */ 1557 if (!(hw->link.link_info.link_info & IXGBE_ACI_LINK_UP) && 1558 (hw->link.link_info.link_info & IXGBE_ACI_MEDIA_AVAILABLE)) { 1559 int highest_bit; 1560 1561 /* Get PHY Capabilities */ 1562 rc = ixgbe_aci_get_phy_caps(hw, false, 1563 IXGBE_ACI_REPORT_TOPO_CAP_MEDIA, 1564 &pcaps); 1565 if (rc) 1566 return ixgbe_media_type_unknown; 1567 1568 highest_bit = fls64(le64_to_cpu(pcaps.phy_type_high)); 1569 if (highest_bit) { 1570 hw->link.link_info.phy_type_high = 1571 BIT_ULL(highest_bit - 1); 1572 hw->link.link_info.phy_type_low = 0; 1573 } else { 1574 highest_bit = fls64(le64_to_cpu(pcaps.phy_type_low)); 1575 if (highest_bit) { 1576 hw->link.link_info.phy_type_low = 1577 BIT_ULL(highest_bit - 1); 1578 hw->link.link_info.phy_type_high = 0; 1579 } 1580 } 1581 } 1582 1583 /* Based on link status or search above try to discover media type. */ 1584 hw->phy.media_type = ixgbe_get_media_type_from_phy_type(hw); 1585 1586 return hw->phy.media_type; 1587 } 1588 1589 /** 1590 * ixgbe_setup_link_e610 - Set up link 1591 * @hw: pointer to hardware structure 1592 * @speed: new link speed 1593 * @autoneg_wait: true when waiting for completion is needed 1594 * 1595 * Set up the link with the specified speed. 1596 * 1597 * Return: the exit code of the operation. 1598 */ 1599 int ixgbe_setup_link_e610(struct ixgbe_hw *hw, ixgbe_link_speed speed, 1600 bool autoneg_wait) 1601 { 1602 /* Simply request FW to perform proper PHY setup */ 1603 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait); 1604 } 1605 1606 /** 1607 * ixgbe_check_link_e610 - Determine link and speed status 1608 * @hw: pointer to hardware structure 1609 * @speed: pointer to link speed 1610 * @link_up: true when link is up 1611 * @link_up_wait_to_complete: bool used to wait for link up or not 1612 * 1613 * Determine if the link is up and the current link speed 1614 * using ACI command (0x0607). 1615 * 1616 * Return: the exit code of the operation. 1617 */ 1618 int ixgbe_check_link_e610(struct ixgbe_hw *hw, ixgbe_link_speed *speed, 1619 bool *link_up, bool link_up_wait_to_complete) 1620 { 1621 int err; 1622 u32 i; 1623 1624 if (!speed || !link_up) 1625 return -EINVAL; 1626 1627 /* Set get_link_info flag to ensure that fresh 1628 * link information will be obtained from FW 1629 * by sending Get Link Status admin command. 1630 */ 1631 hw->link.get_link_info = true; 1632 1633 /* Update link information in adapter context. */ 1634 err = ixgbe_get_link_status(hw, link_up); 1635 if (err) 1636 return err; 1637 1638 /* Wait for link up if it was requested. */ 1639 if (link_up_wait_to_complete && !(*link_up)) { 1640 for (i = 0; i < hw->mac.max_link_up_time; i++) { 1641 msleep(100); 1642 hw->link.get_link_info = true; 1643 err = ixgbe_get_link_status(hw, link_up); 1644 if (err) 1645 return err; 1646 if (*link_up) 1647 break; 1648 } 1649 } 1650 1651 /* Use link information in adapter context updated by the call 1652 * to ixgbe_get_link_status() to determine current link speed. 1653 * Link speed information is valid only when link up was 1654 * reported by FW. 1655 */ 1656 if (*link_up) { 1657 switch (hw->link.link_info.link_speed) { 1658 case IXGBE_ACI_LINK_SPEED_10MB: 1659 *speed = IXGBE_LINK_SPEED_10_FULL; 1660 break; 1661 case IXGBE_ACI_LINK_SPEED_100MB: 1662 *speed = IXGBE_LINK_SPEED_100_FULL; 1663 break; 1664 case IXGBE_ACI_LINK_SPEED_1000MB: 1665 *speed = IXGBE_LINK_SPEED_1GB_FULL; 1666 break; 1667 case IXGBE_ACI_LINK_SPEED_2500MB: 1668 *speed = IXGBE_LINK_SPEED_2_5GB_FULL; 1669 break; 1670 case IXGBE_ACI_LINK_SPEED_5GB: 1671 *speed = IXGBE_LINK_SPEED_5GB_FULL; 1672 break; 1673 case IXGBE_ACI_LINK_SPEED_10GB: 1674 *speed = IXGBE_LINK_SPEED_10GB_FULL; 1675 break; 1676 default: 1677 *speed = IXGBE_LINK_SPEED_UNKNOWN; 1678 break; 1679 } 1680 } else { 1681 *speed = IXGBE_LINK_SPEED_UNKNOWN; 1682 } 1683 1684 return 0; 1685 } 1686 1687 /** 1688 * ixgbe_get_link_capabilities_e610 - Determine link capabilities 1689 * @hw: pointer to hardware structure 1690 * @speed: pointer to link speed 1691 * @autoneg: true when autoneg or autotry is enabled 1692 * 1693 * Determine speed and AN parameters of a link. 1694 * 1695 * Return: the exit code of the operation. 1696 */ 1697 int ixgbe_get_link_capabilities_e610(struct ixgbe_hw *hw, 1698 ixgbe_link_speed *speed, 1699 bool *autoneg) 1700 { 1701 if (!speed || !autoneg) 1702 return -EINVAL; 1703 1704 *autoneg = true; 1705 *speed = hw->phy.speeds_supported; 1706 1707 return 0; 1708 } 1709 1710 /** 1711 * ixgbe_cfg_phy_fc - Configure PHY Flow Control (FC) data based on FC mode 1712 * @hw: pointer to hardware structure 1713 * @cfg: PHY configuration data to set FC mode 1714 * @req_mode: FC mode to configure 1715 * 1716 * Configures PHY Flow Control according to the provided configuration. 1717 * 1718 * Return: the exit code of the operation. 1719 */ 1720 int ixgbe_cfg_phy_fc(struct ixgbe_hw *hw, 1721 struct ixgbe_aci_cmd_set_phy_cfg_data *cfg, 1722 enum ixgbe_fc_mode req_mode) 1723 { 1724 u8 pause_mask = 0x0; 1725 1726 if (!cfg) 1727 return -EINVAL; 1728 1729 switch (req_mode) { 1730 case ixgbe_fc_full: 1731 pause_mask |= IXGBE_ACI_PHY_EN_TX_LINK_PAUSE; 1732 pause_mask |= IXGBE_ACI_PHY_EN_RX_LINK_PAUSE; 1733 break; 1734 case ixgbe_fc_rx_pause: 1735 pause_mask |= IXGBE_ACI_PHY_EN_RX_LINK_PAUSE; 1736 break; 1737 case ixgbe_fc_tx_pause: 1738 pause_mask |= IXGBE_ACI_PHY_EN_TX_LINK_PAUSE; 1739 break; 1740 default: 1741 break; 1742 } 1743 1744 /* Clear the old pause settings. */ 1745 cfg->caps &= ~(IXGBE_ACI_PHY_EN_TX_LINK_PAUSE | 1746 IXGBE_ACI_PHY_EN_RX_LINK_PAUSE); 1747 1748 /* Set the new capabilities. */ 1749 cfg->caps |= pause_mask; 1750 1751 return 0; 1752 } 1753 1754 /** 1755 * ixgbe_setup_fc_e610 - Set up flow control 1756 * @hw: pointer to hardware structure 1757 * 1758 * Set up flow control. This has to be done during init time. 1759 * 1760 * Return: the exit code of the operation. 1761 */ 1762 int ixgbe_setup_fc_e610(struct ixgbe_hw *hw) 1763 { 1764 struct ixgbe_aci_cmd_get_phy_caps_data pcaps = {}; 1765 struct ixgbe_aci_cmd_set_phy_cfg_data cfg = {}; 1766 int err; 1767 1768 /* Get the current PHY config */ 1769 err = ixgbe_aci_get_phy_caps(hw, false, 1770 IXGBE_ACI_REPORT_ACTIVE_CFG, &pcaps); 1771 if (err) 1772 return err; 1773 1774 ixgbe_copy_phy_caps_to_cfg(&pcaps, &cfg); 1775 1776 /* Configure the set PHY data */ 1777 err = ixgbe_cfg_phy_fc(hw, &cfg, hw->fc.requested_mode); 1778 if (err) 1779 return err; 1780 1781 /* If the capabilities have changed, then set the new config */ 1782 if (cfg.caps != pcaps.caps) { 1783 cfg.caps |= IXGBE_ACI_PHY_ENA_AUTO_LINK_UPDT; 1784 1785 err = ixgbe_aci_set_phy_cfg(hw, &cfg); 1786 if (err) 1787 return err; 1788 } 1789 1790 return err; 1791 } 1792 1793 /** 1794 * ixgbe_fc_autoneg_e610 - Configure flow control 1795 * @hw: pointer to hardware structure 1796 * 1797 * Configure Flow Control. 1798 */ 1799 void ixgbe_fc_autoneg_e610(struct ixgbe_hw *hw) 1800 { 1801 int err; 1802 1803 /* Get current link err. 1804 * Current FC mode will be stored in the hw context. 1805 */ 1806 err = ixgbe_aci_get_link_info(hw, false, NULL); 1807 if (err) 1808 goto no_autoneg; 1809 1810 /* Check if the link is up */ 1811 if (!(hw->link.link_info.link_info & IXGBE_ACI_LINK_UP)) 1812 goto no_autoneg; 1813 1814 /* Check if auto-negotiation has completed */ 1815 if (!(hw->link.link_info.an_info & IXGBE_ACI_AN_COMPLETED)) 1816 goto no_autoneg; 1817 1818 hw->fc.fc_was_autonegged = true; 1819 return; 1820 1821 no_autoneg: 1822 hw->fc.fc_was_autonegged = false; 1823 hw->fc.current_mode = hw->fc.requested_mode; 1824 } 1825 1826 /** 1827 * ixgbe_disable_rx_e610 - Disable RX unit 1828 * @hw: pointer to hardware structure 1829 * 1830 * Disable RX DMA unit on E610 with use of ACI command (0x000C). 1831 * 1832 * Return: the exit code of the operation. 1833 */ 1834 void ixgbe_disable_rx_e610(struct ixgbe_hw *hw) 1835 { 1836 u32 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); 1837 u32 pfdtxgswc; 1838 int err; 1839 1840 if (!(rxctrl & IXGBE_RXCTRL_RXEN)) 1841 return; 1842 1843 pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC); 1844 if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) { 1845 pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN; 1846 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc); 1847 hw->mac.set_lben = true; 1848 } else { 1849 hw->mac.set_lben = false; 1850 } 1851 1852 err = ixgbe_aci_disable_rxen(hw); 1853 1854 /* If we fail - disable RX using register write */ 1855 if (err) { 1856 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); 1857 if (rxctrl & IXGBE_RXCTRL_RXEN) { 1858 rxctrl &= ~IXGBE_RXCTRL_RXEN; 1859 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl); 1860 } 1861 } 1862 } 1863 1864 /** 1865 * ixgbe_fw_recovery_mode_e610 - Check FW NVM recovery mode 1866 * @hw: pointer to hardware structure 1867 * 1868 * Check FW NVM recovery mode by reading the value of 1869 * the dedicated register. 1870 * 1871 * Return: true if FW is in recovery mode, otherwise false. 1872 */ 1873 static bool ixgbe_fw_recovery_mode_e610(struct ixgbe_hw *hw) 1874 { 1875 u32 fwsm = IXGBE_READ_REG(hw, IXGBE_GL_MNG_FWSM); 1876 1877 return !!(fwsm & IXGBE_GL_MNG_FWSM_RECOVERY_M); 1878 } 1879 1880 /** 1881 * ixgbe_fw_rollback_mode_e610 - Check FW NVM rollback mode 1882 * @hw: pointer to hardware structure 1883 * 1884 * Check FW NVM rollback mode by reading the value of 1885 * the dedicated register. 1886 * 1887 * Return: true if FW is in rollback mode, otherwise false. 1888 */ 1889 static bool ixgbe_fw_rollback_mode_e610(struct ixgbe_hw *hw) 1890 { 1891 u32 fwsm = IXGBE_READ_REG(hw, IXGBE_GL_MNG_FWSM); 1892 1893 return !!(fwsm & IXGBE_GL_MNG_FWSM_ROLLBACK_M); 1894 } 1895 1896 /** 1897 * ixgbe_init_phy_ops_e610 - PHY specific init 1898 * @hw: pointer to hardware structure 1899 * 1900 * Initialize any function pointers that were not able to be 1901 * set during init_shared_code because the PHY type was not known. 1902 * 1903 * Return: the exit code of the operation. 1904 */ 1905 int ixgbe_init_phy_ops_e610(struct ixgbe_hw *hw) 1906 { 1907 struct ixgbe_mac_info *mac = &hw->mac; 1908 struct ixgbe_phy_info *phy = &hw->phy; 1909 1910 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) 1911 phy->ops.set_phy_power = ixgbe_set_phy_power_e610; 1912 else 1913 phy->ops.set_phy_power = NULL; 1914 1915 /* Identify the PHY */ 1916 return phy->ops.identify(hw); 1917 } 1918 1919 /** 1920 * ixgbe_identify_phy_e610 - Identify PHY 1921 * @hw: pointer to hardware structure 1922 * 1923 * Determine PHY type, supported speeds and PHY ID. 1924 * 1925 * Return: the exit code of the operation. 1926 */ 1927 int ixgbe_identify_phy_e610(struct ixgbe_hw *hw) 1928 { 1929 struct ixgbe_aci_cmd_get_phy_caps_data pcaps; 1930 u64 phy_type_low, phy_type_high; 1931 int err; 1932 1933 /* Set PHY type */ 1934 hw->phy.type = ixgbe_phy_fw; 1935 1936 err = ixgbe_aci_get_phy_caps(hw, false, 1937 IXGBE_ACI_REPORT_TOPO_CAP_MEDIA, &pcaps); 1938 if (err) 1939 return err; 1940 1941 if (!(pcaps.module_compliance_enforcement & 1942 IXGBE_ACI_MOD_ENFORCE_STRICT_MODE)) { 1943 /* Handle lenient mode */ 1944 err = ixgbe_aci_get_phy_caps(hw, false, 1945 IXGBE_ACI_REPORT_TOPO_CAP_NO_MEDIA, 1946 &pcaps); 1947 if (err) 1948 return err; 1949 } 1950 1951 /* Determine supported speeds */ 1952 hw->phy.speeds_supported = IXGBE_LINK_SPEED_UNKNOWN; 1953 phy_type_high = le64_to_cpu(pcaps.phy_type_high); 1954 phy_type_low = le64_to_cpu(pcaps.phy_type_low); 1955 1956 if (phy_type_high & IXGBE_PHY_TYPE_HIGH_10BASE_T || 1957 phy_type_high & IXGBE_PHY_TYPE_HIGH_10M_SGMII) 1958 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10_FULL; 1959 if (phy_type_low & IXGBE_PHY_TYPE_LOW_100BASE_TX || 1960 phy_type_low & IXGBE_PHY_TYPE_LOW_100M_SGMII || 1961 phy_type_high & IXGBE_PHY_TYPE_HIGH_100M_USXGMII) 1962 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_100_FULL; 1963 if (phy_type_low & IXGBE_PHY_TYPE_LOW_1000BASE_T || 1964 phy_type_low & IXGBE_PHY_TYPE_LOW_1000BASE_SX || 1965 phy_type_low & IXGBE_PHY_TYPE_LOW_1000BASE_LX || 1966 phy_type_low & IXGBE_PHY_TYPE_LOW_1000BASE_KX || 1967 phy_type_low & IXGBE_PHY_TYPE_LOW_1G_SGMII || 1968 phy_type_high & IXGBE_PHY_TYPE_HIGH_1G_USXGMII) 1969 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_1GB_FULL; 1970 if (phy_type_low & IXGBE_PHY_TYPE_LOW_2500BASE_T || 1971 phy_type_low & IXGBE_PHY_TYPE_LOW_2500BASE_X || 1972 phy_type_low & IXGBE_PHY_TYPE_LOW_2500BASE_KX || 1973 phy_type_high & IXGBE_PHY_TYPE_HIGH_2500M_SGMII || 1974 phy_type_high & IXGBE_PHY_TYPE_HIGH_2500M_USXGMII) 1975 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_2_5GB_FULL; 1976 if (phy_type_low & IXGBE_PHY_TYPE_LOW_5GBASE_T || 1977 phy_type_low & IXGBE_PHY_TYPE_LOW_5GBASE_KR || 1978 phy_type_high & IXGBE_PHY_TYPE_HIGH_5G_USXGMII) 1979 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_5GB_FULL; 1980 if (phy_type_low & IXGBE_PHY_TYPE_LOW_10GBASE_T || 1981 phy_type_low & IXGBE_PHY_TYPE_LOW_10G_SFI_DA || 1982 phy_type_low & IXGBE_PHY_TYPE_LOW_10GBASE_SR || 1983 phy_type_low & IXGBE_PHY_TYPE_LOW_10GBASE_LR || 1984 phy_type_low & IXGBE_PHY_TYPE_LOW_10GBASE_KR_CR1 || 1985 phy_type_low & IXGBE_PHY_TYPE_LOW_10G_SFI_AOC_ACC || 1986 phy_type_low & IXGBE_PHY_TYPE_LOW_10G_SFI_C2C || 1987 phy_type_high & IXGBE_PHY_TYPE_HIGH_10G_USXGMII) 1988 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10GB_FULL; 1989 1990 /* Initialize autoneg speeds */ 1991 if (!hw->phy.autoneg_advertised) 1992 hw->phy.autoneg_advertised = hw->phy.speeds_supported; 1993 1994 /* Set PHY ID */ 1995 memcpy(&hw->phy.id, pcaps.phy_id_oui, sizeof(u32)); 1996 1997 /* E610 supports EEE only for speeds above 1G */ 1998 if (hw->device_id == IXGBE_DEV_ID_E610_2_5G_T) 1999 hw->phy.eee_speeds_supported = IXGBE_LINK_SPEED_2_5GB_FULL; 2000 else 2001 hw->phy.eee_speeds_supported = IXGBE_LINK_SPEED_2_5GB_FULL | 2002 IXGBE_LINK_SPEED_5GB_FULL | 2003 IXGBE_LINK_SPEED_10GB_FULL; 2004 2005 hw->phy.eee_speeds_advertised = hw->phy.eee_speeds_supported; 2006 2007 return 0; 2008 } 2009 2010 /** 2011 * ixgbe_setup_eee_e610 - Enable/disable EEE support 2012 * @hw: pointer to the HW structure 2013 * @enable_eee: boolean flag to enable EEE 2014 * 2015 * Enable/disable EEE based on @enable_eee. 2016 * 2017 * Return: the exit code of the operation. 2018 */ 2019 int ixgbe_setup_eee_e610(struct ixgbe_hw *hw, bool enable_eee) 2020 { 2021 struct ixgbe_aci_cmd_get_phy_caps_data phy_caps = {}; 2022 struct ixgbe_aci_cmd_set_phy_cfg_data phy_cfg = {}; 2023 u16 eee_cap = 0; 2024 int err; 2025 2026 err = ixgbe_aci_get_phy_caps(hw, false, 2027 IXGBE_ACI_REPORT_ACTIVE_CFG, &phy_caps); 2028 if (err) 2029 return err; 2030 2031 ixgbe_copy_phy_caps_to_cfg(&phy_caps, &phy_cfg); 2032 phy_cfg.caps |= (IXGBE_ACI_PHY_ENA_LINK | 2033 IXGBE_ACI_PHY_ENA_AUTO_LINK_UPDT); 2034 2035 if (enable_eee) { 2036 if (hw->phy.eee_speeds_advertised & IXGBE_LINK_SPEED_2_5GB_FULL) 2037 eee_cap |= IXGBE_ACI_PHY_EEE_EN_2_5GBASE_T; 2038 if (hw->phy.eee_speeds_advertised & IXGBE_LINK_SPEED_5GB_FULL) 2039 eee_cap |= IXGBE_ACI_PHY_EEE_EN_5GBASE_T; 2040 if (hw->phy.eee_speeds_advertised & IXGBE_LINK_SPEED_10GB_FULL) 2041 eee_cap |= IXGBE_ACI_PHY_EEE_EN_10GBASE_T; 2042 } 2043 2044 phy_cfg.eee_cap = cpu_to_le16(eee_cap); 2045 2046 return ixgbe_aci_set_phy_cfg(hw, &phy_cfg); 2047 } 2048 2049 /** 2050 * ixgbe_identify_module_e610 - Identify SFP module type 2051 * @hw: pointer to hardware structure 2052 * 2053 * Identify the SFP module type. 2054 * 2055 * Return: the exit code of the operation. 2056 */ 2057 int ixgbe_identify_module_e610(struct ixgbe_hw *hw) 2058 { 2059 bool media_available; 2060 u8 module_type; 2061 int err; 2062 2063 err = ixgbe_update_link_info(hw); 2064 if (err) 2065 return err; 2066 2067 media_available = 2068 (hw->link.link_info.link_info & IXGBE_ACI_MEDIA_AVAILABLE); 2069 2070 if (media_available) { 2071 hw->phy.sfp_type = ixgbe_sfp_type_unknown; 2072 2073 /* Get module type from hw context updated by 2074 * ixgbe_update_link_info() 2075 */ 2076 module_type = hw->link.link_info.module_type[IXGBE_ACI_MOD_TYPE_IDENT]; 2077 2078 if ((module_type & IXGBE_ACI_MOD_TYPE_BYTE1_SFP_PLUS_CU_PASSIVE) || 2079 (module_type & IXGBE_ACI_MOD_TYPE_BYTE1_SFP_PLUS_CU_ACTIVE)) { 2080 hw->phy.sfp_type = ixgbe_sfp_type_da_cu; 2081 } else if (module_type & IXGBE_ACI_MOD_TYPE_BYTE1_10G_BASE_SR) { 2082 hw->phy.sfp_type = ixgbe_sfp_type_sr; 2083 } else if ((module_type & IXGBE_ACI_MOD_TYPE_BYTE1_10G_BASE_LR) || 2084 (module_type & IXGBE_ACI_MOD_TYPE_BYTE1_10G_BASE_LRM)) { 2085 hw->phy.sfp_type = ixgbe_sfp_type_lr; 2086 } 2087 } else { 2088 hw->phy.sfp_type = ixgbe_sfp_type_not_present; 2089 return -ENOENT; 2090 } 2091 2092 return 0; 2093 } 2094 2095 /** 2096 * ixgbe_setup_phy_link_e610 - Sets up firmware-controlled PHYs 2097 * @hw: pointer to hardware structure 2098 * 2099 * Set the parameters for the firmware-controlled PHYs. 2100 * 2101 * Return: the exit code of the operation. 2102 */ 2103 int ixgbe_setup_phy_link_e610(struct ixgbe_hw *hw) 2104 { 2105 struct ixgbe_aci_cmd_get_phy_caps_data pcaps; 2106 struct ixgbe_aci_cmd_set_phy_cfg_data pcfg; 2107 u8 rmode = IXGBE_ACI_REPORT_TOPO_CAP_MEDIA; 2108 u64 sup_phy_type_low, sup_phy_type_high; 2109 u64 phy_type_low = 0, phy_type_high = 0; 2110 int err; 2111 2112 err = ixgbe_aci_get_link_info(hw, false, NULL); 2113 if (err) 2114 return err; 2115 2116 /* If media is not available get default config. */ 2117 if (!(hw->link.link_info.link_info & IXGBE_ACI_MEDIA_AVAILABLE)) 2118 rmode = IXGBE_ACI_REPORT_DFLT_CFG; 2119 2120 err = ixgbe_aci_get_phy_caps(hw, false, rmode, &pcaps); 2121 if (err) 2122 return err; 2123 2124 sup_phy_type_low = le64_to_cpu(pcaps.phy_type_low); 2125 sup_phy_type_high = le64_to_cpu(pcaps.phy_type_high); 2126 2127 /* Get Active configuration to avoid unintended changes. */ 2128 err = ixgbe_aci_get_phy_caps(hw, false, IXGBE_ACI_REPORT_ACTIVE_CFG, 2129 &pcaps); 2130 if (err) 2131 return err; 2132 2133 ixgbe_copy_phy_caps_to_cfg(&pcaps, &pcfg); 2134 2135 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10_FULL) { 2136 phy_type_high |= IXGBE_PHY_TYPE_HIGH_10BASE_T; 2137 phy_type_high |= IXGBE_PHY_TYPE_HIGH_10M_SGMII; 2138 } 2139 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) { 2140 phy_type_low |= IXGBE_PHY_TYPE_LOW_100BASE_TX; 2141 phy_type_low |= IXGBE_PHY_TYPE_LOW_100M_SGMII; 2142 phy_type_high |= IXGBE_PHY_TYPE_HIGH_100M_USXGMII; 2143 } 2144 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) { 2145 phy_type_low |= IXGBE_PHY_TYPE_LOW_1000BASE_T; 2146 phy_type_low |= IXGBE_PHY_TYPE_LOW_1000BASE_SX; 2147 phy_type_low |= IXGBE_PHY_TYPE_LOW_1000BASE_LX; 2148 phy_type_low |= IXGBE_PHY_TYPE_LOW_1000BASE_KX; 2149 phy_type_low |= IXGBE_PHY_TYPE_LOW_1G_SGMII; 2150 phy_type_high |= IXGBE_PHY_TYPE_HIGH_1G_USXGMII; 2151 } 2152 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_2_5GB_FULL) { 2153 phy_type_low |= IXGBE_PHY_TYPE_LOW_2500BASE_T; 2154 phy_type_low |= IXGBE_PHY_TYPE_LOW_2500BASE_X; 2155 phy_type_low |= IXGBE_PHY_TYPE_LOW_2500BASE_KX; 2156 phy_type_high |= IXGBE_PHY_TYPE_HIGH_2500M_SGMII; 2157 phy_type_high |= IXGBE_PHY_TYPE_HIGH_2500M_USXGMII; 2158 } 2159 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_5GB_FULL) { 2160 phy_type_low |= IXGBE_PHY_TYPE_LOW_5GBASE_T; 2161 phy_type_low |= IXGBE_PHY_TYPE_LOW_5GBASE_KR; 2162 phy_type_high |= IXGBE_PHY_TYPE_HIGH_5G_USXGMII; 2163 } 2164 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) { 2165 phy_type_low |= IXGBE_PHY_TYPE_LOW_10GBASE_T; 2166 phy_type_low |= IXGBE_PHY_TYPE_LOW_10G_SFI_DA; 2167 phy_type_low |= IXGBE_PHY_TYPE_LOW_10GBASE_SR; 2168 phy_type_low |= IXGBE_PHY_TYPE_LOW_10GBASE_LR; 2169 phy_type_low |= IXGBE_PHY_TYPE_LOW_10GBASE_KR_CR1; 2170 phy_type_low |= IXGBE_PHY_TYPE_LOW_10G_SFI_AOC_ACC; 2171 phy_type_low |= IXGBE_PHY_TYPE_LOW_10G_SFI_C2C; 2172 phy_type_high |= IXGBE_PHY_TYPE_HIGH_10G_USXGMII; 2173 } 2174 2175 /* Mask the set values to avoid requesting unsupported link types. */ 2176 phy_type_low &= sup_phy_type_low; 2177 pcfg.phy_type_low = cpu_to_le64(phy_type_low); 2178 phy_type_high &= sup_phy_type_high; 2179 pcfg.phy_type_high = cpu_to_le64(phy_type_high); 2180 2181 if (pcfg.phy_type_high != pcaps.phy_type_high || 2182 pcfg.phy_type_low != pcaps.phy_type_low || 2183 pcfg.caps != pcaps.caps) { 2184 pcfg.caps |= IXGBE_ACI_PHY_ENA_LINK; 2185 pcfg.caps |= IXGBE_ACI_PHY_ENA_AUTO_LINK_UPDT; 2186 2187 err = ixgbe_aci_set_phy_cfg(hw, &pcfg); 2188 if (err) 2189 return err; 2190 } 2191 2192 return 0; 2193 } 2194 2195 /** 2196 * ixgbe_set_phy_power_e610 - Control power for copper PHY 2197 * @hw: pointer to hardware structure 2198 * @on: true for on, false for off 2199 * 2200 * Set the power on/off of the PHY 2201 * by getting its capabilities and setting the appropriate 2202 * configuration parameters. 2203 * 2204 * Return: the exit code of the operation. 2205 */ 2206 int ixgbe_set_phy_power_e610(struct ixgbe_hw *hw, bool on) 2207 { 2208 struct ixgbe_aci_cmd_get_phy_caps_data phy_caps = {}; 2209 struct ixgbe_aci_cmd_set_phy_cfg_data phy_cfg = {}; 2210 int err; 2211 2212 err = ixgbe_aci_get_phy_caps(hw, false, 2213 IXGBE_ACI_REPORT_ACTIVE_CFG, 2214 &phy_caps); 2215 if (err) 2216 return err; 2217 2218 ixgbe_copy_phy_caps_to_cfg(&phy_caps, &phy_cfg); 2219 2220 if (on) 2221 phy_cfg.caps &= ~IXGBE_ACI_PHY_ENA_LOW_POWER; 2222 else 2223 phy_cfg.caps |= IXGBE_ACI_PHY_ENA_LOW_POWER; 2224 2225 /* PHY is already in requested power mode. */ 2226 if (phy_caps.caps == phy_cfg.caps) 2227 return 0; 2228 2229 phy_cfg.caps |= IXGBE_ACI_PHY_ENA_LINK; 2230 phy_cfg.caps |= IXGBE_ACI_PHY_ENA_AUTO_LINK_UPDT; 2231 2232 return ixgbe_aci_set_phy_cfg(hw, &phy_cfg); 2233 } 2234 2235 /** 2236 * ixgbe_enter_lplu_e610 - Transition to low power states 2237 * @hw: pointer to hardware structure 2238 * 2239 * Configures Low Power Link Up on transition to low power states 2240 * (from D0 to non-D0). Link is required to enter LPLU so avoid resetting the 2241 * X557 PHY immediately prior to entering LPLU. 2242 * 2243 * Return: the exit code of the operation. 2244 */ 2245 int ixgbe_enter_lplu_e610(struct ixgbe_hw *hw) 2246 { 2247 struct ixgbe_aci_cmd_get_phy_caps_data phy_caps = {}; 2248 struct ixgbe_aci_cmd_set_phy_cfg_data phy_cfg = {}; 2249 int err; 2250 2251 err = ixgbe_aci_get_phy_caps(hw, false, 2252 IXGBE_ACI_REPORT_ACTIVE_CFG, 2253 &phy_caps); 2254 if (err) 2255 return err; 2256 2257 ixgbe_copy_phy_caps_to_cfg(&phy_caps, &phy_cfg); 2258 2259 phy_cfg.low_power_ctrl_an |= IXGBE_ACI_PHY_EN_D3COLD_LOW_POWER_AUTONEG; 2260 2261 return ixgbe_aci_set_phy_cfg(hw, &phy_cfg); 2262 } 2263 2264 /** 2265 * ixgbe_init_eeprom_params_e610 - Initialize EEPROM params 2266 * @hw: pointer to hardware structure 2267 * 2268 * Initialize the EEPROM parameters ixgbe_eeprom_info within the ixgbe_hw 2269 * struct in order to set up EEPROM access. 2270 * 2271 * Return: the operation exit code. 2272 */ 2273 int ixgbe_init_eeprom_params_e610(struct ixgbe_hw *hw) 2274 { 2275 struct ixgbe_eeprom_info *eeprom = &hw->eeprom; 2276 u32 gens_stat; 2277 u8 sr_size; 2278 2279 if (eeprom->type != ixgbe_eeprom_uninitialized) 2280 return 0; 2281 2282 eeprom->type = ixgbe_flash; 2283 2284 gens_stat = IXGBE_READ_REG(hw, GLNVM_GENS); 2285 sr_size = FIELD_GET(GLNVM_GENS_SR_SIZE_M, gens_stat); 2286 2287 /* Switching to words (sr_size contains power of 2). */ 2288 eeprom->word_size = BIT(sr_size) * IXGBE_SR_WORDS_IN_1KB; 2289 2290 hw_dbg(hw, "Eeprom params: type = %d, size = %d\n", eeprom->type, 2291 eeprom->word_size); 2292 2293 return 0; 2294 } 2295 2296 /** 2297 * ixgbe_aci_get_netlist_node - get a node handle 2298 * @hw: pointer to the hw struct 2299 * @cmd: get_link_topo AQ structure 2300 * @node_part_number: output node part number if node found 2301 * @node_handle: output node handle parameter if node found 2302 * 2303 * Get the netlist node and assigns it to 2304 * the provided handle using ACI command (0x06E0). 2305 * 2306 * Return: the exit code of the operation. 2307 */ 2308 int ixgbe_aci_get_netlist_node(struct ixgbe_hw *hw, 2309 struct ixgbe_aci_cmd_get_link_topo *cmd, 2310 u8 *node_part_number, u16 *node_handle) 2311 { 2312 struct ixgbe_aci_cmd_get_link_topo *resp; 2313 struct libie_aq_desc desc; 2314 2315 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_get_link_topo); 2316 resp = libie_aq_raw(&desc); 2317 *resp = *cmd; 2318 2319 if (ixgbe_aci_send_cmd(hw, &desc, NULL, 0)) 2320 return -EOPNOTSUPP; 2321 2322 if (node_handle) 2323 *node_handle = le16_to_cpu(resp->addr.handle); 2324 if (node_part_number) 2325 *node_part_number = resp->node_part_num; 2326 2327 return 0; 2328 } 2329 2330 /** 2331 * ixgbe_acquire_nvm - Generic request for acquiring the NVM ownership 2332 * @hw: pointer to the HW structure 2333 * @access: NVM access type (read or write) 2334 * 2335 * Request NVM ownership. 2336 * 2337 * Return: the exit code of the operation. 2338 */ 2339 int ixgbe_acquire_nvm(struct ixgbe_hw *hw, enum libie_aq_res_access_type access) 2340 { 2341 u32 fla; 2342 2343 /* Skip if we are in blank NVM programming mode */ 2344 fla = IXGBE_READ_REG(hw, IXGBE_GLNVM_FLA); 2345 if ((fla & IXGBE_GLNVM_FLA_LOCKED_M) == 0) 2346 return 0; 2347 2348 return ixgbe_acquire_res(hw, LIBIE_AQC_RES_ID_NVM, access, 2349 IXGBE_NVM_TIMEOUT); 2350 } 2351 2352 /** 2353 * ixgbe_release_nvm - Generic request for releasing the NVM ownership 2354 * @hw: pointer to the HW structure 2355 * 2356 * Release NVM ownership. 2357 */ 2358 void ixgbe_release_nvm(struct ixgbe_hw *hw) 2359 { 2360 u32 fla; 2361 2362 /* Skip if we are in blank NVM programming mode */ 2363 fla = IXGBE_READ_REG(hw, IXGBE_GLNVM_FLA); 2364 if ((fla & IXGBE_GLNVM_FLA_LOCKED_M) == 0) 2365 return; 2366 2367 ixgbe_release_res(hw, LIBIE_AQC_RES_ID_NVM); 2368 } 2369 2370 /** 2371 * ixgbe_aci_read_nvm - read NVM 2372 * @hw: pointer to the HW struct 2373 * @module_typeid: module pointer location in words from the NVM beginning 2374 * @offset: byte offset from the module beginning 2375 * @length: length of the section to be read (in bytes from the offset) 2376 * @data: command buffer (size [bytes] = length) 2377 * @last_command: tells if this is the last command in a series 2378 * @read_shadow_ram: tell if this is a shadow RAM read 2379 * 2380 * Read the NVM using ACI command (0x0701). 2381 * 2382 * Return: the exit code of the operation. 2383 */ 2384 int ixgbe_aci_read_nvm(struct ixgbe_hw *hw, u16 module_typeid, u32 offset, 2385 u16 length, void *data, bool last_command, 2386 bool read_shadow_ram) 2387 { 2388 struct ixgbe_aci_cmd_nvm *cmd; 2389 struct libie_aq_desc desc; 2390 2391 if (offset > IXGBE_ACI_NVM_MAX_OFFSET) 2392 return -EINVAL; 2393 2394 cmd = libie_aq_raw(&desc); 2395 2396 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_nvm_read); 2397 2398 if (!read_shadow_ram && module_typeid == IXGBE_ACI_NVM_START_POINT) 2399 cmd->cmd_flags |= IXGBE_ACI_NVM_FLASH_ONLY; 2400 2401 /* If this is the last command in a series, set the proper flag. */ 2402 if (last_command) 2403 cmd->cmd_flags |= IXGBE_ACI_NVM_LAST_CMD; 2404 cmd->module_typeid = cpu_to_le16(module_typeid); 2405 cmd->offset_low = cpu_to_le16(offset & 0xFFFF); 2406 cmd->offset_high = (offset >> 16) & 0xFF; 2407 cmd->length = cpu_to_le16(length); 2408 2409 return ixgbe_aci_send_cmd(hw, &desc, data, length); 2410 } 2411 2412 /** 2413 * ixgbe_aci_erase_nvm - erase NVM sector 2414 * @hw: pointer to the HW struct 2415 * @module_typeid: module pointer location in words from the NVM beginning 2416 * 2417 * Erase the NVM sector using the ACI command (0x0702). 2418 * 2419 * Return: the exit code of the operation. 2420 */ 2421 int ixgbe_aci_erase_nvm(struct ixgbe_hw *hw, u16 module_typeid) 2422 { 2423 struct ixgbe_aci_cmd_nvm *cmd; 2424 struct libie_aq_desc desc; 2425 __le16 len; 2426 int err; 2427 2428 /* Read a length value from SR, so module_typeid is equal to 0, 2429 * calculate offset where module size is placed from bytes to words 2430 * set last command and read from SR values to true. 2431 */ 2432 err = ixgbe_aci_read_nvm(hw, 0, 2 * module_typeid + 2, 2, &len, true, 2433 true); 2434 if (err) 2435 return err; 2436 2437 cmd = libie_aq_raw(&desc); 2438 2439 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_nvm_erase); 2440 2441 cmd->module_typeid = cpu_to_le16(module_typeid); 2442 cmd->length = len; 2443 cmd->offset_low = 0; 2444 cmd->offset_high = 0; 2445 2446 return ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 2447 } 2448 2449 /** 2450 * ixgbe_aci_update_nvm - update NVM 2451 * @hw: pointer to the HW struct 2452 * @module_typeid: module pointer location in words from the NVM beginning 2453 * @offset: byte offset from the module beginning 2454 * @length: length of the section to be written (in bytes from the offset) 2455 * @data: command buffer (size [bytes] = length) 2456 * @last_command: tells if this is the last command in a series 2457 * @command_flags: command parameters 2458 * 2459 * Update the NVM using the ACI command (0x0703). 2460 * 2461 * Return: the exit code of the operation. 2462 */ 2463 int ixgbe_aci_update_nvm(struct ixgbe_hw *hw, u16 module_typeid, 2464 u32 offset, u16 length, void *data, 2465 bool last_command, u8 command_flags) 2466 { 2467 struct ixgbe_aci_cmd_nvm *cmd; 2468 struct libie_aq_desc desc; 2469 2470 cmd = libie_aq_raw(&desc); 2471 2472 /* In offset the highest byte must be zeroed. */ 2473 if (offset & 0xFF000000) 2474 return -EINVAL; 2475 2476 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_nvm_write); 2477 2478 cmd->cmd_flags |= command_flags; 2479 2480 /* If this is the last command in a series, set the proper flag. */ 2481 if (last_command) 2482 cmd->cmd_flags |= IXGBE_ACI_NVM_LAST_CMD; 2483 cmd->module_typeid = cpu_to_le16(module_typeid); 2484 cmd->offset_low = cpu_to_le16(offset & 0xFFFF); 2485 cmd->offset_high = FIELD_GET(IXGBE_ACI_NVM_OFFSET_HI_U_MASK, offset); 2486 cmd->length = cpu_to_le16(length); 2487 2488 desc.flags |= cpu_to_le16(LIBIE_AQ_FLAG_RD); 2489 2490 return ixgbe_aci_send_cmd(hw, &desc, data, length); 2491 } 2492 2493 /** 2494 * ixgbe_nvm_write_activate - NVM activate write 2495 * @hw: pointer to the HW struct 2496 * @cmd_flags: flags for write activate command 2497 * @response_flags: response indicators from firmware 2498 * 2499 * Update the control word with the required banks' validity bits 2500 * and dumps the Shadow RAM to flash using ACI command (0x0707). 2501 * 2502 * cmd_flags controls which banks to activate, the preservation level to use 2503 * when activating the NVM bank, and whether an EMP reset is required for 2504 * activation. 2505 * 2506 * Note that the 16bit cmd_flags value is split between two separate 1 byte 2507 * flag values in the descriptor. 2508 * 2509 * On successful return of the firmware command, the response_flags variable 2510 * is updated with the flags reported by firmware indicating certain status, 2511 * such as whether EMP reset is enabled. 2512 * 2513 * Return: the exit code of the operation. 2514 */ 2515 int ixgbe_nvm_write_activate(struct ixgbe_hw *hw, u16 cmd_flags, 2516 u8 *response_flags) 2517 { 2518 struct ixgbe_aci_cmd_nvm *cmd; 2519 struct libie_aq_desc desc; 2520 s32 err; 2521 2522 cmd = libie_aq_raw(&desc); 2523 ixgbe_fill_dflt_direct_cmd_desc(&desc, 2524 ixgbe_aci_opc_nvm_write_activate); 2525 2526 cmd->cmd_flags = (u8)(cmd_flags & 0xFF); 2527 cmd->offset_high = (u8)FIELD_GET(IXGBE_ACI_NVM_OFFSET_HI_A_MASK, 2528 cmd_flags); 2529 2530 err = ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 2531 if (!err && response_flags) 2532 *response_flags = cmd->cmd_flags; 2533 2534 return err; 2535 } 2536 2537 /** 2538 * ixgbe_nvm_validate_checksum - validate checksum 2539 * @hw: pointer to the HW struct 2540 * 2541 * Verify NVM PFA checksum validity using ACI command (0x0706). 2542 * If the checksum verification failed, IXGBE_ERR_NVM_CHECKSUM is returned. 2543 * The function acquires and then releases the NVM ownership. 2544 * 2545 * Return: the exit code of the operation. 2546 */ 2547 int ixgbe_nvm_validate_checksum(struct ixgbe_hw *hw) 2548 { 2549 struct ixgbe_aci_cmd_nvm_checksum *cmd; 2550 struct libie_aq_desc desc; 2551 int err; 2552 2553 err = ixgbe_acquire_nvm(hw, LIBIE_AQC_RES_ACCESS_READ); 2554 if (err) 2555 return err; 2556 2557 cmd = libie_aq_raw(&desc); 2558 2559 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_nvm_checksum); 2560 cmd->flags = IXGBE_ACI_NVM_CHECKSUM_VERIFY; 2561 2562 err = ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 2563 2564 ixgbe_release_nvm(hw); 2565 2566 if (!err && cmd->checksum != 2567 cpu_to_le16(IXGBE_ACI_NVM_CHECKSUM_CORRECT)) { 2568 struct ixgbe_adapter *adapter = container_of(hw, struct ixgbe_adapter, 2569 hw); 2570 2571 err = -EIO; 2572 netdev_err(adapter->netdev, "Invalid Shadow Ram checksum"); 2573 } 2574 2575 return err; 2576 } 2577 2578 /** 2579 * ixgbe_discover_flash_size - Discover the available flash size 2580 * @hw: pointer to the HW struct 2581 * 2582 * The device flash could be up to 16MB in size. However, it is possible that 2583 * the actual size is smaller. Use bisection to determine the accessible size 2584 * of flash memory. 2585 * 2586 * Return: the exit code of the operation. 2587 */ 2588 static int ixgbe_discover_flash_size(struct ixgbe_hw *hw) 2589 { 2590 u32 min_size = 0, max_size = IXGBE_ACI_NVM_MAX_OFFSET + 1; 2591 int err; 2592 2593 err = ixgbe_acquire_nvm(hw, LIBIE_AQC_RES_ACCESS_READ); 2594 if (err) 2595 return err; 2596 2597 while ((max_size - min_size) > 1) { 2598 u32 offset = (max_size + min_size) / 2; 2599 u32 len = 1; 2600 u8 data; 2601 2602 err = ixgbe_read_flat_nvm(hw, offset, &len, &data, false); 2603 if (err == -EIO && 2604 hw->aci.last_status == LIBIE_AQ_RC_EINVAL) { 2605 err = 0; 2606 max_size = offset; 2607 } else if (!err) { 2608 min_size = offset; 2609 } else { 2610 /* an unexpected error occurred */ 2611 goto err_read_flat_nvm; 2612 } 2613 } 2614 2615 hw->flash.flash_size = max_size; 2616 2617 err_read_flat_nvm: 2618 ixgbe_release_nvm(hw); 2619 2620 return err; 2621 } 2622 2623 /** 2624 * ixgbe_read_sr_base_address - Read the value of a Shadow RAM pointer word 2625 * @hw: pointer to the HW structure 2626 * @offset: the word offset of the Shadow RAM word to read 2627 * @pointer: pointer value read from Shadow RAM 2628 * 2629 * Read the given Shadow RAM word, and convert it to a pointer value specified 2630 * in bytes. This function assumes the specified offset is a valid pointer 2631 * word. 2632 * 2633 * Each pointer word specifies whether it is stored in word size or 4KB 2634 * sector size by using the highest bit. The reported pointer value will be in 2635 * bytes, intended for flat NVM reads. 2636 * 2637 * Return: the exit code of the operation. 2638 */ 2639 static int ixgbe_read_sr_base_address(struct ixgbe_hw *hw, u16 offset, 2640 u32 *pointer) 2641 { 2642 u16 value; 2643 int err; 2644 2645 err = ixgbe_read_ee_aci_e610(hw, offset, &value); 2646 if (err) 2647 return err; 2648 2649 /* Determine if the pointer is in 4KB or word units */ 2650 if (value & IXGBE_SR_NVM_PTR_4KB_UNITS) 2651 *pointer = (value & ~IXGBE_SR_NVM_PTR_4KB_UNITS) * SZ_4K; 2652 else 2653 *pointer = value * sizeof(u16); 2654 2655 return 0; 2656 } 2657 2658 /** 2659 * ixgbe_read_sr_area_size - Read an area size from a Shadow RAM word 2660 * @hw: pointer to the HW structure 2661 * @offset: the word offset of the Shadow RAM to read 2662 * @size: size value read from the Shadow RAM 2663 * 2664 * Read the given Shadow RAM word, and convert it to an area size value 2665 * specified in bytes. This function assumes the specified offset is a valid 2666 * area size word. 2667 * 2668 * Each area size word is specified in 4KB sector units. This function reports 2669 * the size in bytes, intended for flat NVM reads. 2670 * 2671 * Return: the exit code of the operation. 2672 */ 2673 static int ixgbe_read_sr_area_size(struct ixgbe_hw *hw, u16 offset, u32 *size) 2674 { 2675 u16 value; 2676 int err; 2677 2678 err = ixgbe_read_ee_aci_e610(hw, offset, &value); 2679 if (err) 2680 return err; 2681 2682 /* Area sizes are always specified in 4KB units */ 2683 *size = value * SZ_4K; 2684 2685 return 0; 2686 } 2687 2688 /** 2689 * ixgbe_determine_active_flash_banks - Discover active bank for each module 2690 * @hw: pointer to the HW struct 2691 * 2692 * Read the Shadow RAM control word and determine which banks are active for 2693 * the NVM, OROM, and Netlist modules. Also read and calculate the associated 2694 * pointer and size. These values are then cached into the ixgbe_flash_info 2695 * structure for later use in order to calculate the correct offset to read 2696 * from the active module. 2697 * 2698 * Return: the exit code of the operation. 2699 */ 2700 static int ixgbe_determine_active_flash_banks(struct ixgbe_hw *hw) 2701 { 2702 struct ixgbe_bank_info *banks = &hw->flash.banks; 2703 u16 ctrl_word; 2704 int err; 2705 2706 err = ixgbe_read_ee_aci_e610(hw, IXGBE_E610_SR_NVM_CTRL_WORD, 2707 &ctrl_word); 2708 if (err) 2709 return err; 2710 2711 if (FIELD_GET(IXGBE_SR_CTRL_WORD_1_M, ctrl_word) != 2712 IXGBE_SR_CTRL_WORD_VALID) 2713 return -ENODATA; 2714 2715 if (!(ctrl_word & IXGBE_SR_CTRL_WORD_NVM_BANK)) 2716 banks->nvm_bank = IXGBE_1ST_FLASH_BANK; 2717 else 2718 banks->nvm_bank = IXGBE_2ND_FLASH_BANK; 2719 2720 if (!(ctrl_word & IXGBE_SR_CTRL_WORD_OROM_BANK)) 2721 banks->orom_bank = IXGBE_1ST_FLASH_BANK; 2722 else 2723 banks->orom_bank = IXGBE_2ND_FLASH_BANK; 2724 2725 if (!(ctrl_word & IXGBE_SR_CTRL_WORD_NETLIST_BANK)) 2726 banks->netlist_bank = IXGBE_1ST_FLASH_BANK; 2727 else 2728 banks->netlist_bank = IXGBE_2ND_FLASH_BANK; 2729 2730 err = ixgbe_read_sr_base_address(hw, IXGBE_E610_SR_1ST_NVM_BANK_PTR, 2731 &banks->nvm_ptr); 2732 if (err) 2733 return err; 2734 2735 err = ixgbe_read_sr_area_size(hw, IXGBE_E610_SR_NVM_BANK_SIZE, 2736 &banks->nvm_size); 2737 if (err) 2738 return err; 2739 2740 err = ixgbe_read_sr_base_address(hw, IXGBE_E610_SR_1ST_OROM_BANK_PTR, 2741 &banks->orom_ptr); 2742 if (err) 2743 return err; 2744 2745 err = ixgbe_read_sr_area_size(hw, IXGBE_E610_SR_OROM_BANK_SIZE, 2746 &banks->orom_size); 2747 if (err) 2748 return err; 2749 2750 err = ixgbe_read_sr_base_address(hw, IXGBE_E610_SR_NETLIST_BANK_PTR, 2751 &banks->netlist_ptr); 2752 if (err) 2753 return err; 2754 2755 err = ixgbe_read_sr_area_size(hw, IXGBE_E610_SR_NETLIST_BANK_SIZE, 2756 &banks->netlist_size); 2757 2758 return err; 2759 } 2760 2761 /** 2762 * ixgbe_get_flash_bank_offset - Get offset into requested flash bank 2763 * @hw: pointer to the HW structure 2764 * @bank: whether to read from the active or inactive flash bank 2765 * @module: the module to read from 2766 * 2767 * Based on the module, lookup the module offset from the beginning of the 2768 * flash. 2769 * 2770 * Return: the flash offset. Note that a value of zero is invalid and must be 2771 * treated as an error. 2772 */ 2773 static int ixgbe_get_flash_bank_offset(struct ixgbe_hw *hw, 2774 enum ixgbe_bank_select bank, 2775 u16 module) 2776 { 2777 struct ixgbe_bank_info *banks = &hw->flash.banks; 2778 enum ixgbe_flash_bank active_bank; 2779 bool second_bank_active; 2780 u32 offset, size; 2781 2782 switch (module) { 2783 case IXGBE_E610_SR_1ST_NVM_BANK_PTR: 2784 offset = banks->nvm_ptr; 2785 size = banks->nvm_size; 2786 active_bank = banks->nvm_bank; 2787 break; 2788 case IXGBE_E610_SR_1ST_OROM_BANK_PTR: 2789 offset = banks->orom_ptr; 2790 size = banks->orom_size; 2791 active_bank = banks->orom_bank; 2792 break; 2793 case IXGBE_E610_SR_NETLIST_BANK_PTR: 2794 offset = banks->netlist_ptr; 2795 size = banks->netlist_size; 2796 active_bank = banks->netlist_bank; 2797 break; 2798 default: 2799 return 0; 2800 } 2801 2802 switch (active_bank) { 2803 case IXGBE_1ST_FLASH_BANK: 2804 second_bank_active = false; 2805 break; 2806 case IXGBE_2ND_FLASH_BANK: 2807 second_bank_active = true; 2808 break; 2809 default: 2810 return 0; 2811 } 2812 2813 /* The second flash bank is stored immediately following the first 2814 * bank. Based on whether the 1st or 2nd bank is active, and whether 2815 * we want the active or inactive bank, calculate the desired offset. 2816 */ 2817 switch (bank) { 2818 case IXGBE_ACTIVE_FLASH_BANK: 2819 return offset + (second_bank_active ? size : 0); 2820 case IXGBE_INACTIVE_FLASH_BANK: 2821 return offset + (second_bank_active ? 0 : size); 2822 } 2823 2824 return 0; 2825 } 2826 2827 /** 2828 * ixgbe_read_flash_module - Read a word from one of the main NVM modules 2829 * @hw: pointer to the HW structure 2830 * @bank: which bank of the module to read 2831 * @module: the module to read 2832 * @offset: the offset into the module in bytes 2833 * @data: storage for the word read from the flash 2834 * @length: bytes of data to read 2835 * 2836 * Read data from the specified flash module. The bank parameter indicates 2837 * whether or not to read from the active bank or the inactive bank of that 2838 * module. 2839 * 2840 * The word will be read using flat NVM access, and relies on the 2841 * hw->flash.banks data being setup by ixgbe_determine_active_flash_banks() 2842 * during initialization. 2843 * 2844 * Return: the exit code of the operation. 2845 */ 2846 static int ixgbe_read_flash_module(struct ixgbe_hw *hw, 2847 enum ixgbe_bank_select bank, 2848 u16 module, u32 offset, u8 *data, u32 length) 2849 { 2850 u32 start; 2851 int err; 2852 2853 start = ixgbe_get_flash_bank_offset(hw, bank, module); 2854 if (!start) 2855 return -EINVAL; 2856 2857 err = ixgbe_acquire_nvm(hw, LIBIE_AQC_RES_ACCESS_READ); 2858 if (err) 2859 return err; 2860 2861 err = ixgbe_read_flat_nvm(hw, start + offset, &length, data, false); 2862 2863 ixgbe_release_nvm(hw); 2864 2865 return err; 2866 } 2867 2868 /** 2869 * ixgbe_read_nvm_module - Read from the active main NVM module 2870 * @hw: pointer to the HW structure 2871 * @bank: whether to read from active or inactive NVM module 2872 * @offset: offset into the NVM module to read, in words 2873 * @data: storage for returned word value 2874 * 2875 * Read the specified word from the active NVM module. This includes the CSS 2876 * header at the start of the NVM module. 2877 * 2878 * Return: the exit code of the operation. 2879 */ 2880 static int ixgbe_read_nvm_module(struct ixgbe_hw *hw, 2881 enum ixgbe_bank_select bank, 2882 u32 offset, u16 *data) 2883 { 2884 __le16 data_local; 2885 int err; 2886 2887 err = ixgbe_read_flash_module(hw, bank, IXGBE_E610_SR_1ST_NVM_BANK_PTR, 2888 offset * sizeof(data_local), 2889 (u8 *)&data_local, 2890 sizeof(data_local)); 2891 if (!err) 2892 *data = le16_to_cpu(data_local); 2893 2894 return err; 2895 } 2896 2897 /** 2898 * ixgbe_read_netlist_module - Read data from the netlist module area 2899 * @hw: pointer to the HW structure 2900 * @bank: whether to read from the active or inactive module 2901 * @offset: offset into the netlist to read from 2902 * @data: storage for returned word value 2903 * 2904 * Read a word from the specified netlist bank. 2905 * 2906 * Return: the exit code of the operation. 2907 */ 2908 static int ixgbe_read_netlist_module(struct ixgbe_hw *hw, 2909 enum ixgbe_bank_select bank, 2910 u32 offset, u16 *data) 2911 { 2912 __le16 data_local; 2913 int err; 2914 2915 err = ixgbe_read_flash_module(hw, bank, IXGBE_E610_SR_NETLIST_BANK_PTR, 2916 offset * sizeof(data_local), 2917 (u8 *)&data_local, sizeof(data_local)); 2918 if (!err) 2919 *data = le16_to_cpu(data_local); 2920 2921 return err; 2922 } 2923 2924 /** 2925 * ixgbe_read_orom_module - Read from the active Option ROM module 2926 * @hw: pointer to the HW structure 2927 * @bank: whether to read from active or inactive OROM module 2928 * @offset: offset into the OROM module to read, in words 2929 * @data: storage for returned word value 2930 * 2931 * Read the specified word from the active Option ROM module of the flash. 2932 * Note that unlike the NVM module, the CSS data is stored at the end of the 2933 * module instead of at the beginning. 2934 * 2935 * Return: the exit code of the operation. 2936 */ 2937 static int ixgbe_read_orom_module(struct ixgbe_hw *hw, 2938 enum ixgbe_bank_select bank, 2939 u32 offset, u16 *data) 2940 { 2941 __le16 data_local; 2942 int err; 2943 2944 err = ixgbe_read_flash_module(hw, bank, IXGBE_E610_SR_1ST_OROM_BANK_PTR, 2945 offset * sizeof(data_local), 2946 (u8 *)&data_local, sizeof(data_local)); 2947 if (!err) 2948 *data = le16_to_cpu(data_local); 2949 2950 return err; 2951 } 2952 2953 /** 2954 * ixgbe_get_nvm_css_hdr_len - Read the CSS header length 2955 * @hw: pointer to the HW struct 2956 * @bank: whether to read from the active or inactive flash bank 2957 * @hdr_len: storage for header length in words 2958 * 2959 * Read the CSS header length from the NVM CSS header and add the 2960 * Authentication header size, and then convert to words. 2961 * 2962 * Return: the exit code of the operation. 2963 */ 2964 static int ixgbe_get_nvm_css_hdr_len(struct ixgbe_hw *hw, 2965 enum ixgbe_bank_select bank, 2966 u32 *hdr_len) 2967 { 2968 u16 hdr_len_l, hdr_len_h; 2969 u32 hdr_len_dword; 2970 int err; 2971 2972 err = ixgbe_read_nvm_module(hw, bank, IXGBE_NVM_CSS_HDR_LEN_L, 2973 &hdr_len_l); 2974 if (err) 2975 return err; 2976 2977 err = ixgbe_read_nvm_module(hw, bank, IXGBE_NVM_CSS_HDR_LEN_H, 2978 &hdr_len_h); 2979 if (err) 2980 return err; 2981 2982 /* CSS header length is in DWORD, so convert to words and add 2983 * authentication header size. 2984 */ 2985 hdr_len_dword = (hdr_len_h << 16) | hdr_len_l; 2986 *hdr_len = hdr_len_dword * 2 + IXGBE_NVM_AUTH_HEADER_LEN; 2987 2988 return 0; 2989 } 2990 2991 /** 2992 * ixgbe_read_nvm_sr_copy - Read a word from the Shadow RAM copy 2993 * @hw: pointer to the HW structure 2994 * @bank: whether to read from the active or inactive NVM module 2995 * @offset: offset into the Shadow RAM copy to read, in words 2996 * @data: storage for returned word value 2997 * 2998 * Read the specified word from the copy of the Shadow RAM found in the 2999 * specified NVM module. 3000 * 3001 * Return: the exit code of the operation. 3002 */ 3003 static int ixgbe_read_nvm_sr_copy(struct ixgbe_hw *hw, 3004 enum ixgbe_bank_select bank, 3005 u32 offset, u16 *data) 3006 { 3007 u32 hdr_len; 3008 int err; 3009 3010 err = ixgbe_get_nvm_css_hdr_len(hw, bank, &hdr_len); 3011 if (err) 3012 return err; 3013 3014 hdr_len = round_up(hdr_len, IXGBE_HDR_LEN_ROUNDUP); 3015 3016 return ixgbe_read_nvm_module(hw, bank, hdr_len + offset, data); 3017 } 3018 3019 /** 3020 * ixgbe_get_nvm_srev - Read the security revision from the NVM CSS header 3021 * @hw: pointer to the HW struct 3022 * @bank: whether to read from the active or inactive flash bank 3023 * @srev: storage for security revision 3024 * 3025 * Read the security revision out of the CSS header of the active NVM module 3026 * bank. 3027 * 3028 * Return: the exit code of the operation. 3029 */ 3030 static int ixgbe_get_nvm_srev(struct ixgbe_hw *hw, 3031 enum ixgbe_bank_select bank, u32 *srev) 3032 { 3033 u16 srev_l, srev_h; 3034 int err; 3035 3036 err = ixgbe_read_nvm_module(hw, bank, IXGBE_NVM_CSS_SREV_L, &srev_l); 3037 if (err) 3038 return err; 3039 3040 err = ixgbe_read_nvm_module(hw, bank, IXGBE_NVM_CSS_SREV_H, &srev_h); 3041 if (err) 3042 return err; 3043 3044 *srev = (srev_h << 16) | srev_l; 3045 3046 return 0; 3047 } 3048 3049 /** 3050 * ixgbe_get_orom_civd_data - Get the combo version information from Option ROM 3051 * @hw: pointer to the HW struct 3052 * @bank: whether to read from the active or inactive flash module 3053 * @civd: storage for the Option ROM CIVD data. 3054 * 3055 * Searches through the Option ROM flash contents to locate the CIVD data for 3056 * the image. 3057 * 3058 * Return: -ENOMEM when cannot allocate memory, -EDOM for checksum violation, 3059 * -ENODATA when cannot find proper data, -EIO for faulty read or 3060 * 0 on success. 3061 * 3062 * On success @civd stores collected data. 3063 */ 3064 static int 3065 ixgbe_get_orom_civd_data(struct ixgbe_hw *hw, enum ixgbe_bank_select bank, 3066 struct ixgbe_orom_civd_info *civd) 3067 { 3068 u32 orom_size = hw->flash.banks.orom_size; 3069 u8 *orom_data; 3070 u32 offset; 3071 int err; 3072 3073 orom_data = kzalloc(orom_size, GFP_KERNEL); 3074 if (!orom_data) 3075 return -ENOMEM; 3076 3077 err = ixgbe_read_flash_module(hw, bank, 3078 IXGBE_E610_SR_1ST_OROM_BANK_PTR, 0, 3079 orom_data, orom_size); 3080 if (err) { 3081 err = -EIO; 3082 goto cleanup; 3083 } 3084 3085 /* The CIVD section is located in the Option ROM aligned to 512 bytes. 3086 * The first 4 bytes must contain the ASCII characters "$CIV". 3087 * A simple modulo 256 sum of all of the bytes of the structure must 3088 * equal 0. 3089 */ 3090 for (offset = 0; offset + SZ_512 <= orom_size; offset += SZ_512) { 3091 struct ixgbe_orom_civd_info *tmp; 3092 u8 sum = 0; 3093 u32 i; 3094 3095 BUILD_BUG_ON(sizeof(*tmp) > SZ_512); 3096 3097 tmp = (struct ixgbe_orom_civd_info *)&orom_data[offset]; 3098 3099 /* Skip forward until we find a matching signature */ 3100 if (memcmp(IXGBE_OROM_CIV_SIGNATURE, tmp->signature, 3101 sizeof(tmp->signature))) 3102 continue; 3103 3104 /* Verify that the simple checksum is zero */ 3105 for (i = 0; i < sizeof(*tmp); i++) 3106 sum += ((u8 *)tmp)[i]; 3107 3108 if (sum) { 3109 err = -EDOM; 3110 goto cleanup; 3111 } 3112 3113 *civd = *tmp; 3114 err = 0; 3115 3116 goto cleanup; 3117 } 3118 3119 err = -ENODATA; 3120 cleanup: 3121 kfree(orom_data); 3122 return err; 3123 } 3124 3125 /** 3126 * ixgbe_get_orom_srev - Read the security revision from the OROM CSS header 3127 * @hw: pointer to the HW struct 3128 * @bank: whether to read from active or inactive flash module 3129 * @srev: storage for security revision 3130 * 3131 * Read the security revision out of the CSS header of the active OROM module 3132 * bank. 3133 * 3134 * Return: the exit code of the operation. 3135 */ 3136 static int ixgbe_get_orom_srev(struct ixgbe_hw *hw, 3137 enum ixgbe_bank_select bank, 3138 u32 *srev) 3139 { 3140 u32 orom_size_word = hw->flash.banks.orom_size / 2; 3141 u32 css_start, hdr_len; 3142 u16 srev_l, srev_h; 3143 int err; 3144 3145 err = ixgbe_get_nvm_css_hdr_len(hw, bank, &hdr_len); 3146 if (err) 3147 return err; 3148 3149 if (orom_size_word < hdr_len) 3150 return -EINVAL; 3151 3152 /* Calculate how far into the Option ROM the CSS header starts. Note 3153 * that ixgbe_read_orom_module takes a word offset. 3154 */ 3155 css_start = orom_size_word - hdr_len; 3156 err = ixgbe_read_orom_module(hw, bank, 3157 css_start + IXGBE_NVM_CSS_SREV_L, 3158 &srev_l); 3159 if (err) 3160 return err; 3161 3162 err = ixgbe_read_orom_module(hw, bank, 3163 css_start + IXGBE_NVM_CSS_SREV_H, 3164 &srev_h); 3165 if (err) 3166 return err; 3167 3168 *srev = srev_h << 16 | srev_l; 3169 3170 return 0; 3171 } 3172 3173 /** 3174 * ixgbe_get_orom_ver_info - Read Option ROM version information 3175 * @hw: pointer to the HW struct 3176 * @bank: whether to read from the active or inactive flash module 3177 * @orom: pointer to Option ROM info structure 3178 * 3179 * Read Option ROM version and security revision from the Option ROM flash 3180 * section. 3181 * 3182 * Return: the exit code of the operation. 3183 */ 3184 static int ixgbe_get_orom_ver_info(struct ixgbe_hw *hw, 3185 enum ixgbe_bank_select bank, 3186 struct ixgbe_orom_info *orom) 3187 { 3188 struct ixgbe_orom_civd_info civd; 3189 u32 combo_ver; 3190 int err; 3191 3192 err = ixgbe_get_orom_civd_data(hw, bank, &civd); 3193 if (err) 3194 return err; 3195 3196 combo_ver = get_unaligned_le32(&civd.combo_ver); 3197 3198 orom->major = (u8)FIELD_GET(IXGBE_OROM_VER_MASK, combo_ver); 3199 orom->patch = (u8)FIELD_GET(IXGBE_OROM_VER_PATCH_MASK, combo_ver); 3200 orom->build = (u16)FIELD_GET(IXGBE_OROM_VER_BUILD_MASK, combo_ver); 3201 3202 return ixgbe_get_orom_srev(hw, bank, &orom->srev); 3203 } 3204 3205 /** 3206 * ixgbe_get_inactive_orom_ver - Read Option ROM version from the inactive bank 3207 * @hw: pointer to the HW structure 3208 * @orom: storage for Option ROM version information 3209 * 3210 * Read the Option ROM version and security revision data for the inactive 3211 * section of flash. Used to access version data for a pending update that has 3212 * not yet been activated. 3213 * 3214 * Return: the exit code of the operation. 3215 */ 3216 int ixgbe_get_inactive_orom_ver(struct ixgbe_hw *hw, 3217 struct ixgbe_orom_info *orom) 3218 { 3219 return ixgbe_get_orom_ver_info(hw, IXGBE_INACTIVE_FLASH_BANK, orom); 3220 } 3221 3222 /** 3223 * ixgbe_get_nvm_ver_info - Read NVM version information 3224 * @hw: pointer to the HW struct 3225 * @bank: whether to read from the active or inactive flash bank 3226 * @nvm: pointer to NVM info structure 3227 * 3228 * Read the NVM EETRACK ID and map version of the main NVM image bank, filling 3229 * in the nvm info structure. 3230 * 3231 * Return: the exit code of the operation. 3232 */ 3233 static int ixgbe_get_nvm_ver_info(struct ixgbe_hw *hw, 3234 enum ixgbe_bank_select bank, 3235 struct ixgbe_nvm_info *nvm) 3236 { 3237 u16 eetrack_lo, eetrack_hi, ver; 3238 int err; 3239 3240 err = ixgbe_read_nvm_sr_copy(hw, bank, 3241 IXGBE_E610_SR_NVM_DEV_STARTER_VER, &ver); 3242 if (err) 3243 return err; 3244 3245 nvm->major = FIELD_GET(IXGBE_E610_NVM_VER_HI_MASK, ver); 3246 nvm->minor = FIELD_GET(IXGBE_E610_NVM_VER_LO_MASK, ver); 3247 3248 err = ixgbe_read_nvm_sr_copy(hw, bank, IXGBE_E610_SR_NVM_EETRACK_LO, 3249 &eetrack_lo); 3250 if (err) 3251 return err; 3252 3253 err = ixgbe_read_nvm_sr_copy(hw, bank, IXGBE_E610_SR_NVM_EETRACK_HI, 3254 &eetrack_hi); 3255 if (err) 3256 return err; 3257 3258 nvm->eetrack = (eetrack_hi << 16) | eetrack_lo; 3259 3260 ixgbe_get_nvm_srev(hw, bank, &nvm->srev); 3261 3262 return 0; 3263 } 3264 3265 /** 3266 * ixgbe_get_inactive_nvm_ver - Read Option ROM version from the inactive bank 3267 * @hw: pointer to the HW structure 3268 * @nvm: storage for Option ROM version information 3269 * 3270 * Read the NVM EETRACK ID, Map version, and security revision of the 3271 * inactive NVM bank. Used to access version data for a pending update that 3272 * has not yet been activated. 3273 * 3274 * Return: the exit code of the operation. 3275 */ 3276 int ixgbe_get_inactive_nvm_ver(struct ixgbe_hw *hw, struct ixgbe_nvm_info *nvm) 3277 { 3278 return ixgbe_get_nvm_ver_info(hw, IXGBE_INACTIVE_FLASH_BANK, nvm); 3279 } 3280 3281 /** 3282 * ixgbe_get_active_nvm_ver - Read Option ROM version from the active bank 3283 * @hw: pointer to the HW structure 3284 * @nvm: storage for Option ROM version information 3285 * 3286 * Reads the NVM EETRACK ID, Map version, and security revision of the 3287 * active NVM bank. 3288 * 3289 * Return: the exit code of the operation. 3290 */ 3291 static int ixgbe_get_active_nvm_ver(struct ixgbe_hw *hw, 3292 struct ixgbe_nvm_info *nvm) 3293 { 3294 return ixgbe_get_nvm_ver_info(hw, IXGBE_ACTIVE_FLASH_BANK, nvm); 3295 } 3296 3297 /** 3298 * ixgbe_get_netlist_info - Read the netlist version information 3299 * @hw: pointer to the HW struct 3300 * @bank: whether to read from the active or inactive flash bank 3301 * @netlist: pointer to netlist version info structure 3302 * 3303 * Get the netlist version information from the requested bank. Reads the Link 3304 * Topology section to find the Netlist ID block and extract the relevant 3305 * information into the netlist version structure. 3306 * 3307 * Return: the exit code of the operation. 3308 */ 3309 static int ixgbe_get_netlist_info(struct ixgbe_hw *hw, 3310 enum ixgbe_bank_select bank, 3311 struct ixgbe_netlist_info *netlist) 3312 { 3313 u16 module_id, length, node_count, i; 3314 u16 *id_blk; 3315 int err; 3316 3317 err = ixgbe_read_netlist_module(hw, bank, IXGBE_NETLIST_TYPE_OFFSET, 3318 &module_id); 3319 if (err) 3320 return err; 3321 3322 if (module_id != IXGBE_NETLIST_LINK_TOPO_MOD_ID) 3323 return -EIO; 3324 3325 err = ixgbe_read_netlist_module(hw, bank, IXGBE_LINK_TOPO_MODULE_LEN, 3326 &length); 3327 if (err) 3328 return err; 3329 3330 /* Sanity check that we have at least enough words to store the 3331 * netlist ID block. 3332 */ 3333 if (length < IXGBE_NETLIST_ID_BLK_SIZE) 3334 return -EIO; 3335 3336 err = ixgbe_read_netlist_module(hw, bank, IXGBE_LINK_TOPO_NODE_COUNT, 3337 &node_count); 3338 if (err) 3339 return err; 3340 3341 node_count &= IXGBE_LINK_TOPO_NODE_COUNT_M; 3342 3343 id_blk = kcalloc(IXGBE_NETLIST_ID_BLK_SIZE, sizeof(*id_blk), GFP_KERNEL); 3344 if (!id_blk) 3345 return -ENOMEM; 3346 3347 /* Read out the entire Netlist ID Block at once. */ 3348 err = ixgbe_read_flash_module(hw, bank, IXGBE_E610_SR_NETLIST_BANK_PTR, 3349 IXGBE_NETLIST_ID_BLK_OFFSET(node_count) * 3350 sizeof(*id_blk), (u8 *)id_blk, 3351 IXGBE_NETLIST_ID_BLK_SIZE * 3352 sizeof(*id_blk)); 3353 if (err) 3354 goto free_id_blk; 3355 3356 for (i = 0; i < IXGBE_NETLIST_ID_BLK_SIZE; i++) 3357 id_blk[i] = le16_to_cpu(((__le16 *)id_blk)[i]); 3358 3359 netlist->major = id_blk[IXGBE_NETLIST_ID_BLK_MAJOR_VER_HIGH] << 16 | 3360 id_blk[IXGBE_NETLIST_ID_BLK_MAJOR_VER_LOW]; 3361 netlist->minor = id_blk[IXGBE_NETLIST_ID_BLK_MINOR_VER_HIGH] << 16 | 3362 id_blk[IXGBE_NETLIST_ID_BLK_MINOR_VER_LOW]; 3363 netlist->type = id_blk[IXGBE_NETLIST_ID_BLK_TYPE_HIGH] << 16 | 3364 id_blk[IXGBE_NETLIST_ID_BLK_TYPE_LOW]; 3365 netlist->rev = id_blk[IXGBE_NETLIST_ID_BLK_REV_HIGH] << 16 | 3366 id_blk[IXGBE_NETLIST_ID_BLK_REV_LOW]; 3367 netlist->cust_ver = id_blk[IXGBE_NETLIST_ID_BLK_CUST_VER]; 3368 /* Read the left most 4 bytes of SHA */ 3369 netlist->hash = id_blk[IXGBE_NETLIST_ID_BLK_SHA_HASH_WORD(15)] << 16 | 3370 id_blk[IXGBE_NETLIST_ID_BLK_SHA_HASH_WORD(14)]; 3371 3372 free_id_blk: 3373 kfree(id_blk); 3374 return err; 3375 } 3376 3377 /** 3378 * ixgbe_get_inactive_netlist_ver - Read netlist version from the inactive bank 3379 * @hw: pointer to the HW struct 3380 * @netlist: pointer to netlist version info structure 3381 * 3382 * Read the netlist version data from the inactive netlist bank. Used to 3383 * extract version data of a pending flash update in order to display the 3384 * version data. 3385 * 3386 * Return: the exit code of the operation. 3387 */ 3388 int ixgbe_get_inactive_netlist_ver(struct ixgbe_hw *hw, 3389 struct ixgbe_netlist_info *netlist) 3390 { 3391 return ixgbe_get_netlist_info(hw, IXGBE_INACTIVE_FLASH_BANK, netlist); 3392 } 3393 3394 /** 3395 * ixgbe_get_flash_data - get flash data 3396 * @hw: pointer to the HW struct 3397 * 3398 * Read and populate flash data such as Shadow RAM size, 3399 * max_timeout and blank_nvm_mode 3400 * 3401 * Return: the exit code of the operation. 3402 */ 3403 int ixgbe_get_flash_data(struct ixgbe_hw *hw) 3404 { 3405 struct ixgbe_flash_info *flash = &hw->flash; 3406 u32 fla, gens_stat; 3407 u8 sr_size; 3408 int err; 3409 3410 /* The SR size is stored regardless of the NVM programming mode 3411 * as the blank mode may be used in the factory line. 3412 */ 3413 gens_stat = IXGBE_READ_REG(hw, GLNVM_GENS); 3414 sr_size = FIELD_GET(GLNVM_GENS_SR_SIZE_M, gens_stat); 3415 3416 /* Switching to words (sr_size contains power of 2) */ 3417 flash->sr_words = BIT(sr_size) * (SZ_1K / sizeof(u16)); 3418 3419 /* Check if we are in the normal or blank NVM programming mode */ 3420 fla = IXGBE_READ_REG(hw, IXGBE_GLNVM_FLA); 3421 if (fla & IXGBE_GLNVM_FLA_LOCKED_M) { 3422 flash->blank_nvm_mode = false; 3423 } else { 3424 flash->blank_nvm_mode = true; 3425 return -EIO; 3426 } 3427 3428 err = ixgbe_discover_flash_size(hw); 3429 if (err) 3430 return err; 3431 3432 err = ixgbe_determine_active_flash_banks(hw); 3433 if (err) 3434 return err; 3435 3436 err = ixgbe_get_nvm_ver_info(hw, IXGBE_ACTIVE_FLASH_BANK, 3437 &flash->nvm); 3438 if (err) 3439 return err; 3440 3441 err = ixgbe_get_orom_ver_info(hw, IXGBE_ACTIVE_FLASH_BANK, 3442 &flash->orom); 3443 if (err) 3444 return err; 3445 3446 err = ixgbe_get_netlist_info(hw, IXGBE_ACTIVE_FLASH_BANK, 3447 &flash->netlist); 3448 return err; 3449 } 3450 3451 /** 3452 * ixgbe_aci_nvm_update_empr - update NVM using EMPR 3453 * @hw: pointer to the HW struct 3454 * 3455 * Force EMP reset using ACI command (0x0709). This command allows SW to 3456 * request an EMPR to activate new FW. 3457 * 3458 * Return: the exit code of the operation. 3459 */ 3460 int ixgbe_aci_nvm_update_empr(struct ixgbe_hw *hw) 3461 { 3462 struct libie_aq_desc desc; 3463 3464 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_nvm_update_empr); 3465 3466 return ixgbe_aci_send_cmd(hw, &desc, NULL, 0); 3467 } 3468 3469 /* ixgbe_nvm_set_pkg_data - NVM set package data 3470 * @hw: pointer to the HW struct 3471 * @del_pkg_data_flag: If is set then the current pkg_data store by FW 3472 * is deleted. 3473 * If bit is set to 1, then buffer should be size 0. 3474 * @data: pointer to buffer 3475 * @length: length of the buffer 3476 * 3477 * Set package data using ACI command (0x070A). 3478 * This command is equivalent to the reception of 3479 * a PLDM FW Update GetPackageData cmd. This command should be sent 3480 * as part of the NVM update as the first cmd in the flow. 3481 * 3482 * Return: the exit code of the operation. 3483 */ 3484 int ixgbe_nvm_set_pkg_data(struct ixgbe_hw *hw, bool del_pkg_data_flag, 3485 u8 *data, u16 length) 3486 { 3487 struct ixgbe_aci_cmd_nvm_pkg_data *cmd; 3488 struct libie_aq_desc desc; 3489 3490 if (length != 0 && !data) 3491 return -EINVAL; 3492 3493 cmd = libie_aq_raw(&desc); 3494 3495 ixgbe_fill_dflt_direct_cmd_desc(&desc, ixgbe_aci_opc_nvm_pkg_data); 3496 desc.flags |= cpu_to_le16(LIBIE_AQ_FLAG_RD); 3497 3498 if (del_pkg_data_flag) 3499 cmd->cmd_flags |= IXGBE_ACI_NVM_PKG_DELETE; 3500 3501 return ixgbe_aci_send_cmd(hw, &desc, data, length); 3502 } 3503 3504 /* ixgbe_nvm_pass_component_tbl - NVM pass component table 3505 * @hw: pointer to the HW struct 3506 * @data: pointer to buffer 3507 * @length: length of the buffer 3508 * @transfer_flag: parameter for determining stage of the update 3509 * @comp_response: a pointer to the response from the 0x070B ACI. 3510 * @comp_response_code: a pointer to the response code from the 0x070B ACI. 3511 * 3512 * Pass component table using ACI command (0x070B). This command is equivalent 3513 * to the reception of a PLDM FW Update PassComponentTable cmd. 3514 * This command should be sent once per component. It can be only sent after 3515 * Set Package Data cmd and before actual update. FW will assume these 3516 * commands are going to be sent until the TransferFlag is set to End or 3517 * StartAndEnd. 3518 * 3519 * Return: the exit code of the operation. 3520 */ 3521 int ixgbe_nvm_pass_component_tbl(struct ixgbe_hw *hw, u8 *data, u16 length, 3522 u8 transfer_flag, u8 *comp_response, 3523 u8 *comp_response_code) 3524 { 3525 struct ixgbe_aci_cmd_nvm_pass_comp_tbl *cmd; 3526 struct libie_aq_desc desc; 3527 int err; 3528 3529 if (!data || !comp_response || !comp_response_code) 3530 return -EINVAL; 3531 3532 cmd = libie_aq_raw(&desc); 3533 3534 ixgbe_fill_dflt_direct_cmd_desc(&desc, 3535 ixgbe_aci_opc_nvm_pass_component_tbl); 3536 desc.flags |= cpu_to_le16(LIBIE_AQ_FLAG_RD); 3537 3538 cmd->transfer_flag = transfer_flag; 3539 err = ixgbe_aci_send_cmd(hw, &desc, data, length); 3540 if (!err) { 3541 *comp_response = cmd->component_response; 3542 *comp_response_code = cmd->component_response_code; 3543 } 3544 3545 return err; 3546 } 3547 3548 /** 3549 * ixgbe_read_sr_word_aci - Reads Shadow RAM via ACI 3550 * @hw: pointer to the HW structure 3551 * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF) 3552 * @data: word read from the Shadow RAM 3553 * 3554 * Reads one 16 bit word from the Shadow RAM using ixgbe_read_flat_nvm. 3555 * 3556 * Return: the exit code of the operation. 3557 */ 3558 int ixgbe_read_sr_word_aci(struct ixgbe_hw *hw, u16 offset, u16 *data) 3559 { 3560 u32 bytes = sizeof(u16); 3561 u16 data_local; 3562 int err; 3563 3564 err = ixgbe_read_flat_nvm(hw, offset * sizeof(u16), &bytes, 3565 (u8 *)&data_local, true); 3566 if (err) 3567 return err; 3568 3569 *data = data_local; 3570 return 0; 3571 } 3572 3573 /** 3574 * ixgbe_read_flat_nvm - Read portion of NVM by flat offset 3575 * @hw: pointer to the HW struct 3576 * @offset: offset from beginning of NVM 3577 * @length: (in) number of bytes to read; (out) number of bytes actually read 3578 * @data: buffer to return data in (sized to fit the specified length) 3579 * @read_shadow_ram: if true, read from shadow RAM instead of NVM 3580 * 3581 * Reads a portion of the NVM, as a flat memory space. This function correctly 3582 * breaks read requests across Shadow RAM sectors, prevents Shadow RAM size 3583 * from being exceeded in case of Shadow RAM read requests and ensures that no 3584 * single read request exceeds the maximum 4KB read for a single admin command. 3585 * 3586 * Returns an error code on failure. Note that the data pointer may be 3587 * partially updated if some reads succeed before a failure. 3588 * 3589 * Return: the exit code of the operation. 3590 */ 3591 int ixgbe_read_flat_nvm(struct ixgbe_hw *hw, u32 offset, u32 *length, 3592 u8 *data, bool read_shadow_ram) 3593 { 3594 u32 inlen = *length; 3595 u32 bytes_read = 0; 3596 bool last_cmd; 3597 int err; 3598 3599 /* Verify the length of the read if this is for the Shadow RAM */ 3600 if (read_shadow_ram && ((offset + inlen) > 3601 (hw->eeprom.word_size * 2u))) 3602 return -EINVAL; 3603 3604 do { 3605 u32 read_size, sector_offset; 3606 3607 /* ixgbe_aci_read_nvm cannot read more than 4KB at a time. 3608 * Additionally, a read from the Shadow RAM may not cross over 3609 * a sector boundary. Conveniently, the sector size is also 4KB. 3610 */ 3611 sector_offset = offset % IXGBE_ACI_MAX_BUFFER_SIZE; 3612 read_size = min_t(u32, 3613 IXGBE_ACI_MAX_BUFFER_SIZE - sector_offset, 3614 inlen - bytes_read); 3615 3616 last_cmd = !(bytes_read + read_size < inlen); 3617 3618 /* ixgbe_aci_read_nvm takes the length as a u16. Our read_size 3619 * is calculated using a u32, but the IXGBE_ACI_MAX_BUFFER_SIZE 3620 * maximum size guarantees that it will fit within the 2 bytes. 3621 */ 3622 err = ixgbe_aci_read_nvm(hw, IXGBE_ACI_NVM_START_POINT, 3623 offset, (u16)read_size, 3624 data + bytes_read, last_cmd, 3625 read_shadow_ram); 3626 if (err) 3627 break; 3628 3629 bytes_read += read_size; 3630 offset += read_size; 3631 } while (!last_cmd); 3632 3633 *length = bytes_read; 3634 return err; 3635 } 3636 3637 /** 3638 * ixgbe_read_sr_buf_aci - Read Shadow RAM buffer via ACI 3639 * @hw: pointer to the HW structure 3640 * @offset: offset of the Shadow RAM words to read (0x000000 - 0x001FFF) 3641 * @words: (in) number of words to read; (out) number of words actually read 3642 * @data: words read from the Shadow RAM 3643 * 3644 * Read 16 bit words (data buf) from the Shadow RAM. Acquire/release the NVM 3645 * ownership. 3646 * 3647 * Return: the operation exit code. 3648 */ 3649 int ixgbe_read_sr_buf_aci(struct ixgbe_hw *hw, u16 offset, u16 *words, 3650 u16 *data) 3651 { 3652 u32 bytes = *words * 2; 3653 int err; 3654 3655 err = ixgbe_read_flat_nvm(hw, offset * 2, &bytes, (u8 *)data, true); 3656 if (err) 3657 return err; 3658 3659 *words = bytes / 2; 3660 3661 for (int i = 0; i < *words; i++) 3662 data[i] = le16_to_cpu(((__le16 *)data)[i]); 3663 3664 return 0; 3665 } 3666 3667 /** 3668 * ixgbe_read_ee_aci_e610 - Read EEPROM word using the admin command. 3669 * @hw: pointer to hardware structure 3670 * @offset: offset of word in the EEPROM to read 3671 * @data: word read from the EEPROM 3672 * 3673 * Reads a 16 bit word from the EEPROM using the ACI. 3674 * If the EEPROM params are not initialized, the function 3675 * initialize them before proceeding with reading. 3676 * The function acquires and then releases the NVM ownership. 3677 * 3678 * Return: the exit code of the operation. 3679 */ 3680 int ixgbe_read_ee_aci_e610(struct ixgbe_hw *hw, u16 offset, u16 *data) 3681 { 3682 int err; 3683 3684 if (hw->eeprom.type == ixgbe_eeprom_uninitialized) { 3685 err = hw->eeprom.ops.init_params(hw); 3686 if (err) 3687 return err; 3688 } 3689 3690 err = ixgbe_acquire_nvm(hw, LIBIE_AQC_RES_ACCESS_READ); 3691 if (err) 3692 return err; 3693 3694 err = ixgbe_read_sr_word_aci(hw, offset, data); 3695 ixgbe_release_nvm(hw); 3696 3697 return err; 3698 } 3699 3700 /** 3701 * ixgbe_read_ee_aci_buffer_e610 - Read EEPROM words via ACI 3702 * @hw: pointer to hardware structure 3703 * @offset: offset of words in the EEPROM to read 3704 * @words: number of words to read 3705 * @data: words to read from the EEPROM 3706 * 3707 * Read 16 bit words from the EEPROM via the ACI. Initialize the EEPROM params 3708 * prior to the read. Acquire/release the NVM ownership. 3709 * 3710 * Return: the operation exit code. 3711 */ 3712 int ixgbe_read_ee_aci_buffer_e610(struct ixgbe_hw *hw, u16 offset, 3713 u16 words, u16 *data) 3714 { 3715 int err; 3716 3717 if (hw->eeprom.type == ixgbe_eeprom_uninitialized) { 3718 err = hw->eeprom.ops.init_params(hw); 3719 if (err) 3720 return err; 3721 } 3722 3723 err = ixgbe_acquire_nvm(hw, LIBIE_AQC_RES_ACCESS_READ); 3724 if (err) 3725 return err; 3726 3727 err = ixgbe_read_sr_buf_aci(hw, offset, &words, data); 3728 ixgbe_release_nvm(hw); 3729 3730 return err; 3731 } 3732 3733 /** 3734 * ixgbe_validate_eeprom_checksum_e610 - Validate EEPROM checksum 3735 * @hw: pointer to hardware structure 3736 * @checksum_val: calculated checksum 3737 * 3738 * Performs checksum calculation and validates the EEPROM checksum. If the 3739 * caller does not need checksum_val, the value can be NULL. 3740 * If the EEPROM params are not initialized, the function 3741 * initialize them before proceeding. 3742 * The function acquires and then releases the NVM ownership. 3743 * 3744 * Return: the exit code of the operation. 3745 */ 3746 int ixgbe_validate_eeprom_checksum_e610(struct ixgbe_hw *hw, u16 *checksum_val) 3747 { 3748 int err; 3749 3750 if (hw->eeprom.type == ixgbe_eeprom_uninitialized) { 3751 err = hw->eeprom.ops.init_params(hw); 3752 if (err) 3753 return err; 3754 } 3755 3756 err = ixgbe_nvm_validate_checksum(hw); 3757 if (err) 3758 return err; 3759 3760 if (checksum_val) { 3761 u16 tmp_checksum; 3762 3763 err = ixgbe_acquire_nvm(hw, LIBIE_AQC_RES_ACCESS_READ); 3764 if (err) 3765 return err; 3766 3767 err = ixgbe_read_sr_word_aci(hw, IXGBE_E610_SR_SW_CHECKSUM_WORD, 3768 &tmp_checksum); 3769 ixgbe_release_nvm(hw); 3770 3771 if (!err) 3772 *checksum_val = tmp_checksum; 3773 } 3774 3775 return err; 3776 } 3777 3778 /** 3779 * ixgbe_reset_hw_e610 - Perform hardware reset 3780 * @hw: pointer to hardware structure 3781 * 3782 * Resets the hardware by resetting the transmit and receive units, masks 3783 * and clears all interrupts, and performs a reset. 3784 * 3785 * Return: the exit code of the operation. 3786 */ 3787 int ixgbe_reset_hw_e610(struct ixgbe_hw *hw) 3788 { 3789 u32 swfw_mask = hw->phy.phy_semaphore_mask; 3790 u32 ctrl, i; 3791 int err; 3792 3793 /* Call adapter stop to disable tx/rx and clear interrupts */ 3794 err = hw->mac.ops.stop_adapter(hw); 3795 if (err) 3796 goto reset_hw_out; 3797 3798 /* Flush pending Tx transactions. */ 3799 ixgbe_clear_tx_pending(hw); 3800 3801 hw->phy.ops.init(hw); 3802 mac_reset_top: 3803 err = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask); 3804 if (err) 3805 return -EBUSY; 3806 ctrl = IXGBE_CTRL_RST; 3807 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL); 3808 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); 3809 IXGBE_WRITE_FLUSH(hw); 3810 hw->mac.ops.release_swfw_sync(hw, swfw_mask); 3811 3812 /* Poll for reset bit to self-clear indicating reset is complete */ 3813 for (i = 0; i < 10; i++) { 3814 udelay(1); 3815 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); 3816 if (!(ctrl & IXGBE_CTRL_RST_MASK)) 3817 break; 3818 } 3819 3820 if (ctrl & IXGBE_CTRL_RST_MASK) { 3821 struct ixgbe_adapter *adapter = container_of(hw, struct ixgbe_adapter, 3822 hw); 3823 3824 err = -EIO; 3825 netdev_err(adapter->netdev, "Reset polling failed to complete."); 3826 } 3827 3828 /* Double resets are required for recovery from certain error 3829 * conditions. Between resets, it is necessary to stall to allow time 3830 * for any pending HW events to complete. 3831 */ 3832 msleep(100); 3833 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) { 3834 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED; 3835 goto mac_reset_top; 3836 } 3837 3838 /* Set the Rx packet buffer size. */ 3839 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), GENMASK(18, 17)); 3840 3841 /* Store the permanent mac address */ 3842 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr); 3843 3844 /* Maximum number of Receive Address Registers. */ 3845 #define IXGBE_MAX_NUM_RAR 128 3846 3847 /* Store MAC address from RAR0, clear receive address registers, and 3848 * clear the multicast table. Also reset num_rar_entries to the 3849 * maximum number of Receive Address Registers, since we modify this 3850 * value when programming the SAN MAC address. 3851 */ 3852 hw->mac.num_rar_entries = IXGBE_MAX_NUM_RAR; 3853 hw->mac.ops.init_rx_addrs(hw); 3854 3855 /* Initialize bus function number */ 3856 hw->mac.ops.set_lan_id(hw); 3857 3858 reset_hw_out: 3859 return err; 3860 } 3861 3862 /** 3863 * ixgbe_get_pfa_module_tlv - Read sub module TLV from NVM PFA 3864 * @hw: pointer to hardware structure 3865 * @module_tlv: pointer to module TLV to return 3866 * @module_tlv_len: pointer to module TLV length to return 3867 * @module_type: module type requested 3868 * 3869 * Find the requested sub module TLV type from the Preserved Field 3870 * Area (PFA) and returns the TLV pointer and length. The caller can 3871 * use these to read the variable length TLV value. 3872 * 3873 * Return: the exit code of the operation. 3874 */ 3875 static int ixgbe_get_pfa_module_tlv(struct ixgbe_hw *hw, u16 *module_tlv, 3876 u16 *module_tlv_len, u16 module_type) 3877 { 3878 u16 pfa_len, pfa_ptr, pfa_end_ptr; 3879 u16 next_tlv; 3880 int err; 3881 3882 err = ixgbe_read_ee_aci_e610(hw, IXGBE_E610_SR_PFA_PTR, &pfa_ptr); 3883 if (err) 3884 return err; 3885 3886 err = ixgbe_read_ee_aci_e610(hw, pfa_ptr, &pfa_len); 3887 if (err) 3888 return err; 3889 3890 /* Starting with first TLV after PFA length, iterate through the list 3891 * of TLVs to find the requested one. 3892 */ 3893 next_tlv = pfa_ptr + 1; 3894 pfa_end_ptr = pfa_ptr + pfa_len; 3895 while (next_tlv < pfa_end_ptr) { 3896 u16 tlv_sub_module_type, tlv_len; 3897 3898 /* Read TLV type */ 3899 err = ixgbe_read_ee_aci_e610(hw, next_tlv, 3900 &tlv_sub_module_type); 3901 if (err) 3902 break; 3903 3904 /* Read TLV length */ 3905 err = ixgbe_read_ee_aci_e610(hw, next_tlv + 1, &tlv_len); 3906 if (err) 3907 break; 3908 3909 if (tlv_sub_module_type == module_type) { 3910 if (tlv_len) { 3911 *module_tlv = next_tlv; 3912 *module_tlv_len = tlv_len; 3913 return 0; 3914 } 3915 return -EIO; 3916 } 3917 /* Check next TLV, i.e. current TLV pointer + length + 2 words 3918 * (for current TLV's type and length). 3919 */ 3920 next_tlv = next_tlv + tlv_len + 2; 3921 } 3922 /* Module does not exist */ 3923 return -ENODATA; 3924 } 3925 3926 /** 3927 * ixgbe_read_pba_string_e610 - Read PBA string from NVM 3928 * @hw: pointer to hardware structure 3929 * @pba_num: stores the part number string from the NVM 3930 * @pba_num_size: part number string buffer length 3931 * 3932 * Read the part number string from the NVM. 3933 * 3934 * Return: the exit code of the operation. 3935 */ 3936 static int ixgbe_read_pba_string_e610(struct ixgbe_hw *hw, u8 *pba_num, 3937 u32 pba_num_size) 3938 { 3939 u16 pba_tlv, pba_tlv_len; 3940 u16 pba_word, pba_size; 3941 int err; 3942 3943 *pba_num = '\0'; 3944 3945 err = ixgbe_get_pfa_module_tlv(hw, &pba_tlv, &pba_tlv_len, 3946 IXGBE_E610_SR_PBA_BLOCK_PTR); 3947 if (err) 3948 return err; 3949 3950 /* pba_size is the next word */ 3951 err = ixgbe_read_ee_aci_e610(hw, (pba_tlv + 2), &pba_size); 3952 if (err) 3953 return err; 3954 3955 if (pba_tlv_len < pba_size) 3956 return -EINVAL; 3957 3958 /* Subtract one to get PBA word count (PBA Size word is included in 3959 * total size). 3960 */ 3961 pba_size--; 3962 3963 if (pba_num_size < (((u32)pba_size * 2) + 1)) 3964 return -EINVAL; 3965 3966 for (u16 i = 0; i < pba_size; i++) { 3967 err = ixgbe_read_ee_aci_e610(hw, (pba_tlv + 2 + 1) + i, 3968 &pba_word); 3969 if (err) 3970 return err; 3971 3972 pba_num[(i * 2)] = FIELD_GET(IXGBE_E610_SR_PBA_BLOCK_MASK, 3973 pba_word); 3974 pba_num[(i * 2) + 1] = pba_word & 0xFF; 3975 } 3976 3977 pba_num[(pba_size * 2)] = '\0'; 3978 3979 return err; 3980 } 3981 3982 static int __fwlog_send_cmd(void *priv, struct libie_aq_desc *desc, void *buf, 3983 u16 size) 3984 { 3985 struct ixgbe_hw *hw = priv; 3986 3987 return ixgbe_aci_send_cmd(hw, desc, buf, size); 3988 } 3989 3990 int ixgbe_fwlog_init(struct ixgbe_hw *hw) 3991 { 3992 struct ixgbe_adapter *adapter = hw->back; 3993 struct libie_fwlog_api api = { 3994 .pdev = adapter->pdev, 3995 .send_cmd = __fwlog_send_cmd, 3996 .debugfs_root = adapter->ixgbe_dbg_adapter, 3997 .priv = hw, 3998 }; 3999 4000 if (hw->mac.type != ixgbe_mac_e610) 4001 return -EOPNOTSUPP; 4002 4003 return libie_fwlog_init(&hw->fwlog, &api); 4004 } 4005 4006 void ixgbe_fwlog_deinit(struct ixgbe_hw *hw) 4007 { 4008 if (hw->mac.type != ixgbe_mac_e610) 4009 return; 4010 4011 libie_fwlog_deinit(&hw->fwlog); 4012 } 4013 4014 static const struct ixgbe_mac_operations mac_ops_e610 = { 4015 .init_hw = ixgbe_init_hw_generic, 4016 .start_hw = ixgbe_start_hw_e610, 4017 .clear_hw_cntrs = ixgbe_clear_hw_cntrs_generic, 4018 .enable_rx_dma = ixgbe_enable_rx_dma_generic, 4019 .get_mac_addr = ixgbe_get_mac_addr_generic, 4020 .get_device_caps = ixgbe_get_device_caps_generic, 4021 .stop_adapter = ixgbe_stop_adapter_generic, 4022 .set_lan_id = ixgbe_set_lan_id_multi_port_pcie, 4023 .set_rxpba = ixgbe_set_rxpba_generic, 4024 .check_link = ixgbe_check_link_e610, 4025 .blink_led_start = ixgbe_blink_led_start_X540, 4026 .blink_led_stop = ixgbe_blink_led_stop_X540, 4027 .set_rar = ixgbe_set_rar_generic, 4028 .clear_rar = ixgbe_clear_rar_generic, 4029 .set_vmdq = ixgbe_set_vmdq_generic, 4030 .set_vmdq_san_mac = ixgbe_set_vmdq_san_mac_generic, 4031 .clear_vmdq = ixgbe_clear_vmdq_generic, 4032 .init_rx_addrs = ixgbe_init_rx_addrs_generic, 4033 .update_mc_addr_list = ixgbe_update_mc_addr_list_generic, 4034 .enable_mc = ixgbe_enable_mc_generic, 4035 .disable_mc = ixgbe_disable_mc_generic, 4036 .clear_vfta = ixgbe_clear_vfta_generic, 4037 .set_vfta = ixgbe_set_vfta_generic, 4038 .fc_enable = ixgbe_fc_enable_generic, 4039 .set_fw_drv_ver = ixgbe_set_fw_drv_ver_x550, 4040 .init_uta_tables = ixgbe_init_uta_tables_generic, 4041 .set_mac_anti_spoofing = ixgbe_set_mac_anti_spoofing, 4042 .set_vlan_anti_spoofing = ixgbe_set_vlan_anti_spoofing, 4043 .set_source_address_pruning = 4044 ixgbe_set_source_address_pruning_x550, 4045 .set_ethertype_anti_spoofing = 4046 ixgbe_set_ethertype_anti_spoofing_x550, 4047 .disable_rx_buff = ixgbe_disable_rx_buff_generic, 4048 .enable_rx_buff = ixgbe_enable_rx_buff_generic, 4049 .enable_rx = ixgbe_enable_rx_generic, 4050 .disable_rx = ixgbe_disable_rx_e610, 4051 .led_on = ixgbe_led_on_generic, 4052 .led_off = ixgbe_led_off_generic, 4053 .init_led_link_act = ixgbe_init_led_link_act_generic, 4054 .reset_hw = ixgbe_reset_hw_e610, 4055 .get_fw_ver = ixgbe_aci_get_fw_ver, 4056 .get_media_type = ixgbe_get_media_type_e610, 4057 .setup_link = ixgbe_setup_link_e610, 4058 .fw_recovery_mode = ixgbe_fw_recovery_mode_e610, 4059 .fw_rollback_mode = ixgbe_fw_rollback_mode_e610, 4060 .get_nvm_ver = ixgbe_get_active_nvm_ver, 4061 .get_link_capabilities = ixgbe_get_link_capabilities_e610, 4062 .setup_eee = ixgbe_setup_eee_e610, 4063 .get_bus_info = ixgbe_get_bus_info_generic, 4064 .acquire_swfw_sync = ixgbe_acquire_swfw_sync_X540, 4065 .release_swfw_sync = ixgbe_release_swfw_sync_X540, 4066 .init_swfw_sync = ixgbe_init_swfw_sync_X540, 4067 .prot_autoc_read = prot_autoc_read_generic, 4068 .prot_autoc_write = prot_autoc_write_generic, 4069 .setup_fc = ixgbe_setup_fc_e610, 4070 .fc_autoneg = ixgbe_fc_autoneg_e610, 4071 .enable_mdd = ixgbe_enable_mdd_x550, 4072 .disable_mdd = ixgbe_disable_mdd_x550, 4073 .restore_mdd_vf = ixgbe_restore_mdd_vf_x550, 4074 .handle_mdd = ixgbe_handle_mdd_x550, 4075 }; 4076 4077 static const struct ixgbe_phy_operations phy_ops_e610 = { 4078 .init = ixgbe_init_phy_ops_e610, 4079 .identify = ixgbe_identify_phy_e610, 4080 .identify_sfp = ixgbe_identify_module_e610, 4081 .setup_link_speed = ixgbe_setup_phy_link_speed_generic, 4082 .setup_link = ixgbe_setup_phy_link_e610, 4083 .enter_lplu = ixgbe_enter_lplu_e610, 4084 }; 4085 4086 static const struct ixgbe_eeprom_operations eeprom_ops_e610 = { 4087 .read = ixgbe_read_ee_aci_e610, 4088 .read_buffer = ixgbe_read_ee_aci_buffer_e610, 4089 .validate_checksum = ixgbe_validate_eeprom_checksum_e610, 4090 .read_pba_string = ixgbe_read_pba_string_e610, 4091 .init_params = ixgbe_init_eeprom_params_e610, 4092 }; 4093 4094 const struct ixgbe_info ixgbe_e610_info = { 4095 .mac = ixgbe_mac_e610, 4096 .get_invariants = ixgbe_get_invariants_X540, 4097 .mac_ops = &mac_ops_e610, 4098 .eeprom_ops = &eeprom_ops_e610, 4099 .phy_ops = &phy_ops_e610, 4100 .mbx_ops = &mbx_ops_generic, 4101 .mvals = ixgbe_mvals_x550em_a, 4102 }; 4103