Skip to content

Commit b51dab4

Browse files
Sudarsana Reddy Kallurudavem330
authored andcommitted
qed: Add qed APIs for PHY module query.
This patch adds qed APIs for reading the PHY module. Signed-off-by: Sudarsana Reddy Kalluru <Sudarsana.Kalluru@cavium.com> Signed-off-by: Ariel Elior <ariel.elior@cavium.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 57dc2bf commit b51dab4

5 files changed

Lines changed: 119 additions & 0 deletions

File tree

‎drivers/net/ethernet/qlogic/qed/qed_hsi.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12444,6 +12444,8 @@ struct public_drv_mb {
1244412444
#define DRV_MSG_CODE_STATS_TYPE_ISCSI 3
1244512445
#define DRV_MSG_CODE_STATS_TYPE_RDMA 4
1244612446

12447+
#define DRV_MSG_CODE_TRANSCEIVER_READ 0x00160000
12448+
1244712449
#define DRV_MSG_CODE_MASK_PARITIES 0x001a0000
1244812450

1244912451
#define DRV_MSG_CODE_BIST_TEST 0x001e0000
@@ -12543,6 +12545,15 @@ struct public_drv_mb {
1254312545
#define DRV_MB_PARAM_SET_LED_MODE_ON 0x1
1254412546
#define DRV_MB_PARAM_SET_LED_MODE_OFF 0x2
1254512547

12548+
#define DRV_MB_PARAM_TRANSCEIVER_PORT_OFFSET 0
12549+
#define DRV_MB_PARAM_TRANSCEIVER_PORT_MASK 0x00000003
12550+
#define DRV_MB_PARAM_TRANSCEIVER_SIZE_OFFSET 2
12551+
#define DRV_MB_PARAM_TRANSCEIVER_SIZE_MASK 0x000000FC
12552+
#define DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_OFFSET 8
12553+
#define DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK 0x0000FF00
12554+
#define DRV_MB_PARAM_TRANSCEIVER_OFFSET_OFFSET 16
12555+
#define DRV_MB_PARAM_TRANSCEIVER_OFFSET_MASK 0xFFFF0000
12556+
1254612557
/* Resource Allocation params - Driver version support */
1254712558
#define DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR_MASK 0xFFFF0000
1254812559
#define DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR_SHIFT 16
@@ -12596,6 +12607,9 @@ struct public_drv_mb {
1259612607
#define FW_MSG_CODE_PHY_OK 0x00110000
1259712608
#define FW_MSG_CODE_OK 0x00160000
1259812609
#define FW_MSG_CODE_ERROR 0x00170000
12610+
#define FW_MSG_CODE_TRANSCEIVER_DIAG_OK 0x00160000
12611+
#define FW_MSG_CODE_TRANSCEIVER_DIAG_ERROR 0x00170000
12612+
#define FW_MSG_CODE_TRANSCEIVER_NOT_PRESENT 0x00020000
1259912613

1260012614
#define FW_MSG_CODE_OS_WOL_SUPPORTED 0x00800000
1260112615
#define FW_MSG_CODE_OS_WOL_NOT_SUPPORTED 0x00810000
@@ -12687,6 +12701,8 @@ struct mcp_public_data {
1268712701
struct public_func func[MCP_GLOB_FUNC_MAX];
1268812702
};
1268912703

12704+
#define MAX_I2C_TRANSACTION_SIZE 16
12705+
1269012706
/* OCBB definitions */
1269112707
enum tlvs {
1269212708
/* Category 1: Device Properties */

‎drivers/net/ethernet/qlogic/qed/qed_main.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,28 @@ static int qed_update_mtu(struct qed_dev *cdev, u16 mtu)
21022102
return status;
21032103
}
21042104

2105+
static int qed_read_module_eeprom(struct qed_dev *cdev, char *buf,
2106+
u8 dev_addr, u32 offset, u32 len)
2107+
{
2108+
struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2109+
struct qed_ptt *ptt;
2110+
int rc = 0;
2111+
2112+
if (IS_VF(cdev))
2113+
return 0;
2114+
2115+
ptt = qed_ptt_acquire(hwfn);
2116+
if (!ptt)
2117+
return -EAGAIN;
2118+
2119+
rc = qed_mcp_phy_sfp_read(hwfn, ptt, MFW_PORT(hwfn), dev_addr,
2120+
offset, len, buf);
2121+
2122+
qed_ptt_release(hwfn, ptt);
2123+
2124+
return rc;
2125+
}
2126+
21052127
static struct qed_selftest_ops qed_selftest_ops_pass = {
21062128
.selftest_memory = &qed_selftest_memory,
21072129
.selftest_interrupt = &qed_selftest_interrupt,
@@ -2144,6 +2166,7 @@ const struct qed_common_ops qed_common_ops_pass = {
21442166
.update_mac = &qed_update_mac,
21452167
.update_mtu = &qed_update_mtu,
21462168
.update_wol = &qed_update_wol,
2169+
.read_module_eeprom = &qed_read_module_eeprom,
21472170
};
21482171

21492172
void qed_get_protocol_stats(struct qed_dev *cdev,

‎drivers/net/ethernet/qlogic/qed/qed_mcp.c‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,55 @@ int qed_mcp_nvm_write(struct qed_dev *cdev,
24632463
return rc;
24642464
}
24652465

2466+
int qed_mcp_phy_sfp_read(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
2467+
u32 port, u32 addr, u32 offset, u32 len, u8 *p_buf)
2468+
{
2469+
u32 bytes_left, bytes_to_copy, buf_size, nvm_offset = 0;
2470+
u32 resp, param;
2471+
int rc;
2472+
2473+
nvm_offset |= (port << DRV_MB_PARAM_TRANSCEIVER_PORT_OFFSET) &
2474+
DRV_MB_PARAM_TRANSCEIVER_PORT_MASK;
2475+
nvm_offset |= (addr << DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_OFFSET) &
2476+
DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK;
2477+
2478+
addr = offset;
2479+
offset = 0;
2480+
bytes_left = len;
2481+
while (bytes_left > 0) {
2482+
bytes_to_copy = min_t(u32, bytes_left,
2483+
MAX_I2C_TRANSACTION_SIZE);
2484+
nvm_offset &= (DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK |
2485+
DRV_MB_PARAM_TRANSCEIVER_PORT_MASK);
2486+
nvm_offset |= ((addr + offset) <<
2487+
DRV_MB_PARAM_TRANSCEIVER_OFFSET_OFFSET) &
2488+
DRV_MB_PARAM_TRANSCEIVER_OFFSET_MASK;
2489+
nvm_offset |= (bytes_to_copy <<
2490+
DRV_MB_PARAM_TRANSCEIVER_SIZE_OFFSET) &
2491+
DRV_MB_PARAM_TRANSCEIVER_SIZE_MASK;
2492+
rc = qed_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
2493+
DRV_MSG_CODE_TRANSCEIVER_READ,
2494+
nvm_offset, &resp, &param, &buf_size,
2495+
(u32 *)(p_buf + offset));
2496+
if (rc) {
2497+
DP_NOTICE(p_hwfn,
2498+
"Failed to send a transceiver read command to the MFW. rc = %d.\n",
2499+
rc);
2500+
return rc;
2501+
}
2502+
2503+
if (resp == FW_MSG_CODE_TRANSCEIVER_NOT_PRESENT)
2504+
return -ENODEV;
2505+
else if (resp != FW_MSG_CODE_TRANSCEIVER_DIAG_OK)
2506+
return -EINVAL;
2507+
2508+
offset += buf_size;
2509+
bytes_left -= buf_size;
2510+
}
2511+
2512+
return 0;
2513+
}
2514+
24662515
int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
24672516
{
24682517
u32 drv_mb_param = 0, rsp, param;

‎drivers/net/ethernet/qlogic/qed/qed_mcp.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,22 @@ int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
839839
u32 *o_mcp_resp,
840840
u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
841841

842+
/**
843+
* @brief Read from sfp
844+
*
845+
* @param p_hwfn - hw function
846+
* @param p_ptt - PTT required for register access
847+
* @param port - transceiver port
848+
* @param addr - I2C address
849+
* @param offset - offset in sfp
850+
* @param len - buffer length
851+
* @param p_buf - buffer to read into
852+
*
853+
* @return int - 0 - operation was successful.
854+
*/
855+
int qed_mcp_phy_sfp_read(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
856+
u32 port, u32 addr, u32 offset, u32 len, u8 *p_buf);
857+
842858
/**
843859
* @brief indicates whether the MFW objects [under mcp_info] are accessible
844860
*

‎include/linux/qed/qed_if.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,9 @@ struct qed_generic_tlvs {
759759
u8 mac[QED_TLV_MAC_COUNT][ETH_ALEN];
760760
};
761761

762+
#define QED_I2C_DEV_ADDR_A0 0xA0
763+
#define QED_I2C_DEV_ADDR_A2 0xA2
764+
762765
#define QED_NVM_SIGNATURE 0x12435687
763766

764767
enum qed_nvm_flash_cmd {
@@ -1026,6 +1029,18 @@ struct qed_common_ops {
10261029
* @param enabled - true iff WoL should be enabled.
10271030
*/
10281031
int (*update_wol) (struct qed_dev *cdev, bool enabled);
1032+
1033+
/**
1034+
* @brief read_module_eeprom
1035+
*
1036+
* @param cdev
1037+
* @param buf - buffer
1038+
* @param dev_addr - PHY device memory region
1039+
* @param offset - offset into eeprom contents to be read
1040+
* @param len - buffer length, i.e., max bytes to be read
1041+
*/
1042+
int (*read_module_eeprom)(struct qed_dev *cdev,
1043+
char *buf, u8 dev_addr, u32 offset, u32 len);
10291044
};
10301045

10311046
#define MASK_FIELD(_name, _value) \

0 commit comments

Comments
 (0)