144961713Sgirish /*
244961713Sgirish * CDDL HEADER START
344961713Sgirish *
444961713Sgirish * The contents of this file are subject to the terms of the
544961713Sgirish * Common Development and Distribution License (the "License").
644961713Sgirish * You may not use this file except in compliance with the License.
744961713Sgirish *
844961713Sgirish * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
944961713Sgirish * or http://www.opensolaris.org/os/licensing.
1044961713Sgirish * See the License for the specific language governing permissions
1144961713Sgirish * and limitations under the License.
1244961713Sgirish *
1344961713Sgirish * When distributing Covered Code, include this CDDL HEADER in each
1444961713Sgirish * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1544961713Sgirish * If applicable, add the following below this CDDL HEADER, with the
1644961713Sgirish * fields enclosed by brackets "[]" replaced with your own identifying
1744961713Sgirish * information: Portions Copyright [yyyy] [name of copyright owner]
1844961713Sgirish *
1944961713Sgirish * CDDL HEADER END
2044961713Sgirish */
2144961713Sgirish /*
227b26d9ffSSantwona Behera * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2344961713Sgirish * Use is subject to license terms.
2444961713Sgirish */
2544961713Sgirish
2644961713Sgirish #include <nxge_impl.h>
2744961713Sgirish #include <nxge_mac.h>
2844961713Sgirish #include <npi_espc.h>
2944961713Sgirish #include <nxge_espc.h>
3044961713Sgirish
312e59129aSraghus static void nxge_check_vpd_version(p_nxge_t nxgep);
3244961713Sgirish
3356d930aeSspeer void
nxge_espc_get_next_mac_addr(uint8_t * st_mac,uint8_t nxt_cnt,struct ether_addr * final_mac)3444961713Sgirish nxge_espc_get_next_mac_addr(uint8_t *st_mac, uint8_t nxt_cnt,
3544961713Sgirish struct ether_addr *final_mac)
3644961713Sgirish {
3744961713Sgirish uint64_t mac[ETHERADDRL];
3844961713Sgirish uint64_t mac_addr = 0;
3944961713Sgirish int i, j;
4044961713Sgirish
4144961713Sgirish for (i = ETHERADDRL - 1, j = 0; j < ETHERADDRL; i--, j++) {
4244961713Sgirish mac[j] = st_mac[i];
4344961713Sgirish mac_addr |= (mac[j] << (j*8));
4444961713Sgirish }
4544961713Sgirish
4644961713Sgirish mac_addr += nxt_cnt;
4744961713Sgirish
4844961713Sgirish final_mac->ether_addr_octet[0] = (mac_addr & 0xff0000000000) >> 40;
4944961713Sgirish final_mac->ether_addr_octet[1] = (mac_addr & 0xff00000000) >> 32;
5044961713Sgirish final_mac->ether_addr_octet[2] = (mac_addr & 0xff000000) >> 24;
5144961713Sgirish final_mac->ether_addr_octet[3] = (mac_addr & 0xff0000) >> 16;
5244961713Sgirish final_mac->ether_addr_octet[4] = (mac_addr & 0xff00) >> 8;
5344961713Sgirish final_mac->ether_addr_octet[5] = (mac_addr & 0xff);
5444961713Sgirish }
5544961713Sgirish
5644961713Sgirish nxge_status_t
nxge_espc_mac_addrs_get(p_nxge_t nxgep)5744961713Sgirish nxge_espc_mac_addrs_get(p_nxge_t nxgep)
5844961713Sgirish {
5944961713Sgirish nxge_status_t status = NXGE_OK;
6044961713Sgirish npi_status_t npi_status = NPI_SUCCESS;
6144961713Sgirish uint8_t port_num = nxgep->mac.portnum;
6244961713Sgirish npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep);
6344961713Sgirish uint8_t mac_addr[ETHERADDRL];
6444961713Sgirish
6544961713Sgirish NXGE_DEBUG_MSG((nxgep, MAC_CTL,
6652ccf843Smisaki "==> nxge_espc_mac_addr_get, port[%d]", port_num));
6744961713Sgirish
6844961713Sgirish npi_status = npi_espc_mac_addr_get(handle, mac_addr);
6944961713Sgirish if (npi_status != NPI_SUCCESS) {
7044961713Sgirish status = (NXGE_ERROR | npi_status);
7144961713Sgirish NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL,
7252ccf843Smisaki "nxge_espc_mac_addr_get, port[%d] failed", port_num));
7344961713Sgirish goto exit;
7444961713Sgirish }
7544961713Sgirish
7644961713Sgirish nxge_espc_get_next_mac_addr(mac_addr, port_num, &nxgep->factaddr);
7756d930aeSspeer NXGE_DEBUG_MSG((nxgep, CFG_CTL,
7852ccf843Smisaki "Got MAC Addr: %2x:%2x:%2x:%2x:%2x%:%2x%c \n",
7952ccf843Smisaki mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
8052ccf843Smisaki mac_addr[4], mac_addr[5]));
8144961713Sgirish
8244961713Sgirish exit:
8344961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_espc_mac_addr_get, "
8452ccf843Smisaki "status [0x%x]", status));
8544961713Sgirish
8644961713Sgirish return (status);
8744961713Sgirish }
8844961713Sgirish
8944961713Sgirish nxge_status_t
nxge_espc_num_macs_get(p_nxge_t nxgep,uint8_t * nmacs)9044961713Sgirish nxge_espc_num_macs_get(p_nxge_t nxgep, uint8_t *nmacs)
9144961713Sgirish {
9244961713Sgirish nxge_status_t status = NXGE_OK;
9344961713Sgirish npi_status_t npi_status = NPI_SUCCESS;
9444961713Sgirish npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep);
9544961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_espc_num_macs_get"));
9644961713Sgirish
9744961713Sgirish npi_status = npi_espc_num_macs_get(handle, nmacs);
9844961713Sgirish if (npi_status != NPI_SUCCESS) {
9944961713Sgirish status = (NXGE_ERROR | npi_status);
10044961713Sgirish }
10144961713Sgirish
10244961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_espc_num_macs_get, "
10352ccf843Smisaki "status [0x%x]", status));
10444961713Sgirish
10544961713Sgirish return (status);
10644961713Sgirish }
10744961713Sgirish
10844961713Sgirish nxge_status_t
nxge_espc_num_ports_get(p_nxge_t nxgep)10944961713Sgirish nxge_espc_num_ports_get(p_nxge_t nxgep)
11044961713Sgirish {
11144961713Sgirish nxge_status_t status = NXGE_OK;
11244961713Sgirish npi_status_t npi_status = NPI_SUCCESS;
11344961713Sgirish npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep);
11444961713Sgirish uint8_t nports = 0;
11544961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_espc_num_ports_get"));
11644961713Sgirish
11744961713Sgirish npi_status = npi_espc_num_ports_get(handle, &nports);
11844961713Sgirish if (npi_status != NPI_SUCCESS) {
11944961713Sgirish status = (NXGE_ERROR | npi_status);
12044961713Sgirish }
12144961713Sgirish nxgep->nports = nports;
12244961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, " nxge_espc_num_ports_get "
12352ccf843Smisaki "ports [0x%x]", nports));
12444961713Sgirish
12544961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_espc_num_ports_get, "
12652ccf843Smisaki "status [0x%x]", status));
12744961713Sgirish
12844961713Sgirish return (status);
12944961713Sgirish }
13044961713Sgirish
13144961713Sgirish nxge_status_t
nxge_espc_phy_type_get(p_nxge_t nxgep)13244961713Sgirish nxge_espc_phy_type_get(p_nxge_t nxgep)
13344961713Sgirish {
13444961713Sgirish nxge_status_t status = NXGE_OK;
13544961713Sgirish npi_status_t npi_status = NPI_SUCCESS;
13644961713Sgirish npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep);
13744961713Sgirish uint8_t port_num = nxgep->mac.portnum;
13844961713Sgirish uint8_t phy_type;
13944961713Sgirish
14044961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_espc_phy_type_get, port[%d]",
14152ccf843Smisaki port_num));
14244961713Sgirish
14352ccf843Smisaki npi_status = npi_espc_port_phy_type_get(handle, &phy_type, port_num);
14444961713Sgirish if (npi_status != NPI_SUCCESS) {
14544961713Sgirish status = (NXGE_ERROR | npi_status);
14644961713Sgirish goto exit;
14744961713Sgirish }
14844961713Sgirish
14944961713Sgirish switch (phy_type) {
15044961713Sgirish case ESC_PHY_10G_FIBER:
15144961713Sgirish nxgep->mac.portmode = PORT_10G_FIBER;
15244961713Sgirish nxgep->statsp->mac_stats.xcvr_inuse = XPCS_XCVR;
15344961713Sgirish break;
15444961713Sgirish case ESC_PHY_10G_COPPER:
15544961713Sgirish nxgep->mac.portmode = PORT_10G_COPPER;
15644961713Sgirish nxgep->statsp->mac_stats.xcvr_inuse = XPCS_XCVR;
15744961713Sgirish break;
15844961713Sgirish case ESC_PHY_1G_FIBER:
15944961713Sgirish nxgep->mac.portmode = PORT_1G_FIBER;
16044961713Sgirish nxgep->statsp->mac_stats.xcvr_inuse = PCS_XCVR;
16144961713Sgirish break;
16244961713Sgirish case ESC_PHY_1G_COPPER:
16344961713Sgirish nxgep->mac.portmode = PORT_1G_COPPER;
16444961713Sgirish nxgep->statsp->mac_stats.xcvr_inuse = INT_MII_XCVR;
16544961713Sgirish break;
16644961713Sgirish case ESC_PHY_NONE:
16744961713Sgirish status = NXGE_ERROR;
16856d930aeSspeer NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_espc_phy_type_get:"
16952ccf843Smisaki "No phy type set"));
17044961713Sgirish break;
17144961713Sgirish default:
17244961713Sgirish status = NXGE_ERROR;
17344961713Sgirish NXGE_ERROR_MSG((nxgep, NXGE_ERR_CTL, "nxge_espc_phy_type_get: "
17452ccf843Smisaki "Unknown phy type [%d]", phy_type));
17544961713Sgirish break;
17644961713Sgirish }
17744961713Sgirish
17844961713Sgirish exit:
17944961713Sgirish
18044961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, "<== nxge_espc_phy_type_get, "
18152ccf843Smisaki "status [0x%x]", status));
18244961713Sgirish
18344961713Sgirish return (status);
18444961713Sgirish }
18544961713Sgirish
18644961713Sgirish nxge_status_t
nxge_espc_max_frame_sz_get(p_nxge_t nxgep)18744961713Sgirish nxge_espc_max_frame_sz_get(p_nxge_t nxgep)
18844961713Sgirish {
18944961713Sgirish nxge_status_t status = NXGE_OK;
19044961713Sgirish npi_status_t npi_status = NPI_SUCCESS;
19144961713Sgirish npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep);
19244961713Sgirish
19344961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, "==> nxge_espc_max_frame_sz_get"));
19444961713Sgirish
19544961713Sgirish npi_status = npi_espc_max_frame_get(handle, &nxgep->mac.maxframesize);
19644961713Sgirish if (npi_status != NPI_SUCCESS) {
19744961713Sgirish status = (NXGE_ERROR | npi_status);
19844961713Sgirish }
19944961713Sgirish
20044961713Sgirish NXGE_DEBUG_MSG((nxgep, CFG_CTL, " nxge_espc_max_frame_sz_get, "
20152ccf843Smisaki "status [0x%x]", status));
20244961713Sgirish
20344961713Sgirish return (status);
20444961713Sgirish }
20556d930aeSspeer
2062e59129aSraghus void
nxge_vpd_info_get(p_nxge_t nxgep)20756d930aeSspeer nxge_vpd_info_get(p_nxge_t nxgep)
20856d930aeSspeer {
20956d930aeSspeer npi_status_t status;
21056d930aeSspeer npi_handle_t handle = NXGE_DEV_NPI_HANDLE(nxgep);
21156d930aeSspeer
2122e59129aSraghus if ((nxgep->platform_type == P_NEPTUNE_NIU) ||
2132e59129aSraghus (nxgep->platform_type == P_NEPTUNE_MARAMBA_P0) ||
21423b952a3SSantwona Behera (nxgep->platform_type == P_NEPTUNE_MARAMBA_P1) ||
21523b952a3SSantwona Behera (nxgep->platform_type == P_NEPTUNE_ROCK)) {
2162e59129aSraghus nxgep->vpd_info.present = B_FALSE;
2172e59129aSraghus return;
2182e59129aSraghus }
2192e59129aSraghus
22023b952a3SSantwona Behera NXGE_DEBUG_MSG((nxgep, CFG_CTL, "nxge_vpd_info_get: "
22123b952a3SSantwona Behera "nxgep->platform_type[%d]...reading vpd", nxgep->platform_type));
22223b952a3SSantwona Behera
2232e59129aSraghus nxgep->vpd_info.present = B_TRUE;
2242e59129aSraghus nxgep->vpd_info.ver_valid = B_FALSE;
2252e59129aSraghus
22656d930aeSspeer MUTEX_ENTER(&nxgep->nxge_hw_p->nxge_cfg_lock);
22756d930aeSspeer (void) npi_espc_pio_enable(handle);
22856d930aeSspeer status = npi_espc_vpd_info_get(handle, &nxgep->vpd_info,
2292e59129aSraghus NXGE_EROM_LEN);
23056d930aeSspeer (void) npi_espc_pio_disable(handle);
23156d930aeSspeer MUTEX_EXIT(&nxgep->nxge_hw_p->nxge_cfg_lock);
23256d930aeSspeer
2332e59129aSraghus if (status != NPI_SUCCESS)
2342e59129aSraghus return;
2352e59129aSraghus
2362e59129aSraghus nxge_check_vpd_version(nxgep);
2372e59129aSraghus if (!nxgep->vpd_info.ver_valid)
2382e59129aSraghus return;
2392e59129aSraghus
2402e59129aSraghus /* Determine the platform type */
2412e59129aSraghus if ((strncmp(nxgep->vpd_info.bd_model, NXGE_QGC_LP_BM_STR,
2422e59129aSraghus strlen(NXGE_QGC_LP_BM_STR)) == 0) ||
2432e59129aSraghus (strncmp(nxgep->vpd_info.bd_model, NXGE_QGC_PEM_BM_STR,
2442e59129aSraghus strlen(NXGE_QGC_PEM_BM_STR)) == 0)) {
2452e59129aSraghus nxgep->platform_type = P_NEPTUNE_ATLAS_4PORT;
2462e59129aSraghus } else if ((strncmp(nxgep->vpd_info.bd_model,
2472e59129aSraghus NXGE_2XGF_LP_BM_STR, strlen(NXGE_2XGF_LP_BM_STR)) == 0) ||
2482e59129aSraghus (strncmp(nxgep->vpd_info.bd_model, NXGE_2XGF_PEM_BM_STR,
2492e59129aSraghus strlen(NXGE_2XGF_PEM_BM_STR)) == 0)) {
2502e59129aSraghus nxgep->platform_type = P_NEPTUNE_ATLAS_2PORT;
251d81011f0Ssbehera } else if (strncmp(nxgep->vpd_info.bd_model,
252d81011f0Ssbehera NXGE_ALONSO_BM_STR, strlen(NXGE_ALONSO_BM_STR)) == 0) {
253d81011f0Ssbehera nxgep->platform_type = P_NEPTUNE_ALONSO;
254321febdeSsbehera } else if (strncmp(nxgep->vpd_info.bd_model,
255321febdeSsbehera NXGE_RFEM_BM_STR, strlen(NXGE_RFEM_BM_STR)) == 0) {
256321febdeSsbehera nxgep->hot_swappable_phy = B_TRUE;
257*ef523517SMichael Speer nxgep->platform_type = P_NEPTUNE_GENERIC;
258*ef523517SMichael Speer nxgep->niu_type = NEPTUNE_2_10GF;
2592e59129aSraghus }
2602e59129aSraghus
261d81011f0Ssbehera /* If Alonso platform, replace "mif" for the last 2 ports phy-type */
262d81011f0Ssbehera if ((nxgep->platform_type == P_NEPTUNE_ALONSO) &&
263d81011f0Ssbehera ((nxgep->function_num == 2) || (nxgep->function_num == 3))) {
264d81011f0Ssbehera (void) strcpy(nxgep->vpd_info.phy_type, "mif");
265d81011f0Ssbehera }
26659a835ddSjoycey
26759a835ddSjoycey /* If ARTM card, replace "mif" for the last 2 ports phy-type */
26859a835ddSjoycey if ((strncmp(nxgep->vpd_info.bd_model,
26959a835ddSjoycey NXGE_ARTM_BM_STR, strlen(NXGE_ARTM_BM_STR)) == 0) &&
27059a835ddSjoycey ((nxgep->function_num == 2) || (nxgep->function_num == 3))) {
27159a835ddSjoycey NXGE_DEBUG_MSG((nxgep, NXGE_ERR_CTL,
27259a835ddSjoycey "Replaced phy type as mif"));
27359a835ddSjoycey (void) strcpy(nxgep->vpd_info.phy_type, "mif");
27459a835ddSjoycey }
27556d930aeSspeer }
27656d930aeSspeer
2772e59129aSraghus static void
nxge_check_vpd_version(p_nxge_t nxgep)27856d930aeSspeer nxge_check_vpd_version(p_nxge_t nxgep)
27956d930aeSspeer {
28056d930aeSspeer int i, j;
28156d930aeSspeer const char *fcode_str = NXGE_FCODE_ID_STR;
28256d930aeSspeer int fcode_str_len = strlen(fcode_str);
28356d930aeSspeer char ver_num_str[NXGE_FCODE_VER_STR_LEN];
28456d930aeSspeer char *ver_num_w;
28556d930aeSspeer char *ver_num_f;
28656d930aeSspeer int ver_num_w_len = 0;
28756d930aeSspeer int ver_num_f_len = 0;
28856d930aeSspeer int ver_w = 0;
28956d930aeSspeer int ver_f = 0;
29056d930aeSspeer
29156d930aeSspeer nxgep->vpd_info.ver_valid = B_FALSE;
29256d930aeSspeer ver_num_str[0] = '\0';
29356d930aeSspeer
29456d930aeSspeer for (i = 0; i < NXGE_VPD_VER_LEN; i++) {
29556d930aeSspeer if (nxgep->vpd_info.ver[i] == fcode_str[0]) {
29656d930aeSspeer if ((i + fcode_str_len + NXGE_FCODE_VER_STR_LEN) >
29756d930aeSspeer NXGE_VPD_VER_LEN)
29856d930aeSspeer break;
29956d930aeSspeer for (j = 0; j < fcode_str_len; j++, i++) {
30056d930aeSspeer if (nxgep->vpd_info.ver[i] != fcode_str[j])
30156d930aeSspeer break;
30256d930aeSspeer }
30356d930aeSspeer if (j < fcode_str_len)
30456d930aeSspeer continue;
30556d930aeSspeer
30656d930aeSspeer /* found the Fcode version string */
30756d930aeSspeer for (j = 0; j < NXGE_FCODE_VER_STR_LEN; j++, i++) {
30856d930aeSspeer ver_num_str[j] = nxgep->vpd_info.ver[i];
30956d930aeSspeer if (ver_num_str[j] == ' ')
31056d930aeSspeer break;
31156d930aeSspeer }
3127b26d9ffSSantwona Behera if (j < NXGE_FCODE_VER_STR_LEN)
3137b26d9ffSSantwona Behera ver_num_str[j] = '\0';
31456d930aeSspeer break;
31556d930aeSspeer }
31656d930aeSspeer }
31756d930aeSspeer
31856d930aeSspeer ver_num_w = ver_num_str;
31956d930aeSspeer for (i = 0; i < strlen(ver_num_str); i++) {
32056d930aeSspeer if (ver_num_str[i] == '.') {
32156d930aeSspeer ver_num_f = &ver_num_str[i + 1];
32256d930aeSspeer ver_num_w_len = i;
32356d930aeSspeer ver_num_f_len = strlen(ver_num_str) - (i + 1);
32456d930aeSspeer break;
32556d930aeSspeer }
32656d930aeSspeer }
32756d930aeSspeer
32856d930aeSspeer for (i = 0; i < ver_num_w_len; i++) {
32956d930aeSspeer ver_w = (ver_w * 10) + (ver_num_w[i] - '0');
33056d930aeSspeer }
33156d930aeSspeer
33256d930aeSspeer for (i = 0; i < ver_num_f_len; i++) {
33356d930aeSspeer ver_f = (ver_f * 10) + (ver_num_f[i] - '0');
33456d930aeSspeer }
33556d930aeSspeer
33656d930aeSspeer if ((ver_w > NXGE_VPD_VALID_VER_W) ||
33756d930aeSspeer (ver_w == NXGE_VPD_VALID_VER_W && ver_f >= NXGE_VPD_VALID_VER_F))
33856d930aeSspeer nxgep->vpd_info.ver_valid = B_TRUE;
33956d930aeSspeer
34056d930aeSspeer }
341