net: Add NIC controller driver for OcteonTX
PATCH v3 1/1 net: Add NIC controller driver for OcteonTX
From: Suneel Garapati <[email protected]>
Adds support for Network Interface controllers found on OcteonTX SoC platforms.
---
Series-changes: 3
- Add SoB from Stefan
- Remove spdx.org line from comment
- Remove inclusion of common.h header
- Order header file inclusion
- Misc minor checkpatch fixes
Series-changes: 1
- Change patch subject
- Rebased on latest TOT
- Removed inclusion of common.h
drivers/net/Kconfig | 14 + drivers/net/Makefile | 2 + drivers/net/octeontx/Makefile | 7 + drivers/net/octeontx/bgx.c | 1565 +++++++++++++++++++++++++++ drivers/net/octeontx/bgx.h | 259 +++++ drivers/net/octeontx/nic.h | 508 +++++++++ drivers/net/octeontx/nic_main.c | 778 +++++++++++++ drivers/net/octeontx/nic_reg.h | 250 +++++ drivers/net/octeontx/nicvf_main.c | 581 ++++++++++ drivers/net/octeontx/nicvf_queues.c | 1140 +++++++++++++++++++ drivers/net/octeontx/nicvf_queues.h | 353 ++++++ drivers/net/octeontx/q_struct.h | 695 ++++++++++++ drivers/net/octeontx/smi.c | 380 +++++++ drivers/net/octeontx/xcv.c | 124 +++ 14 files changed, 6656 insertions(+) create mode 100644 drivers/net/octeontx/Makefile create mode 100644 drivers/net/octeontx/bgx.c create mode 100644 drivers/net/octeontx/bgx.h create mode 100644 drivers/net/octeontx/nic.h create mode 100644 drivers/net/octeontx/nic_main.c create mode 100644 drivers/net/octeontx/nic_reg.h create mode 100644 drivers/net/octeontx/nicvf_main.c create mode 100644 drivers/net/octeontx/nicvf_queues.c create mode 100644 drivers/net/octeontx/nicvf_queues.h create mode 100644 drivers/net/octeontx/q_struct.h create mode 100644 drivers/net/octeontx/smi.c create mode 100644 drivers/net/octeontx/xcv.c
drivers/net/Kconfig +14 -0
@@ -407,6 +407,20 @@ config MT7628_ETH The MediaTek MT7628 ethernet interface is used on MT7628 and MT7688 based boards. +config NET_OCTEONTX + bool "OcteonTX Ethernet support" + depends on ARCH_OCTEONTX + depends on PCI_SRIOV + help + You must select Y to enable network device support for + OcteonTX SoCs. If unsure, say n +config OCTEONTX_SMI + bool "OcteonTX SMI Device support" + depends on ARCH_OCTEONTX || ARCH_OCTEONTX2 + help + You must select Y to enable SMI controller support for + OcteonTX or OcteonTX2 SoCs. If unsure, say n + config PCH_GBE bool "Intel Platform Controller Hub EG20T GMAC driver" depends on DM_ETH && DM_PCI
drivers/net/Makefile +2 -0
@@ -65,6 +65,8 @@ obj-$(CONFIG_RENESAS_RAVB) += ravb.o obj-$(CONFIG_SMC91111) += smc91111.o obj-$(CONFIG_SMC911X) += smc911x.o obj-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o +obj-$(CONFIG_NET_OCTEONTX) += octeontx/ +obj-$(CONFIG_OCTEONTX_SMI) += octeontx/smi.o obj-$(CONFIG_FMAN_ENET) += fsl_mdio.o obj-$(CONFIG_ULI526X) += uli526x.o obj-$(CONFIG_VSC7385_ENET) += vsc7385.o
drivers/net/octeontx/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2018 Marvell International Ltd. +# + +obj-$(CONFIG_NET_OCTEONTX) += bgx.o nic_main.o nicvf_queues.o nicvf_main.o \ + xcv.o
drivers/net/octeontx/bgx.c new file +1565 -0
1,565 lines not on this page · raw message
drivers/net/octeontx/bgx.h new file +259 -0
259 lines not on this page · raw message
drivers/net/octeontx/nic.h new file +508 -0
508 lines not on this page · raw message
drivers/net/octeontx/nic_main.c new file +778 -0
633 lines not on this page · raw message
drivers/net/octeontx/nic_reg.h new file +250 -0
250 lines not on this page · raw message
drivers/net/octeontx/nicvf_main.c new file +581 -0
581 lines not on this page · raw message
drivers/net/octeontx/nicvf_queues.c new file +1140 -0
1,140 lines not on this page · raw message
drivers/net/octeontx/nicvf_queues.h new file +353 -0
353 lines not on this page · raw message
drivers/net/octeontx/q_struct.h new file +695 -0
695 lines not on this page · raw message
drivers/net/octeontx/smi.c new file +380 -0
380 lines not on this page · raw message
drivers/net/octeontx/xcv.c new file +124 -0
124 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.28.0
Part of the diff is not shown here. View the raw message.
PATCH v3 1/1 net: Add NIC controller driver for OcteonTX
Quoted 16 lines · Stefan Roese
From: Suneel Garapati <[email protected]>
Adds support for Network Interface controllers found on OcteonTX SoC platforms.
Signed-off-by Suneel Garapati <[email protected]>Signed-off-by Stefan Roese <[email protected]>Cc Joe Hershberger <[email protected]>---
Series-changes: 3
- Add SoB from Stefan
- Remove spdx.org line from comment
- Remove inclusion ofcommon.hheader
- Order header file inclusion
- Misc minor checkpatch fixes
Quoted 4 lines
Series-changes: 1
- Change patch subject
- Rebased on latest TOT
- Removed inclusion ofcommon.h
Applied to u-boot-marvell/master
Thanks,
Stefan
drivers/net/octeontx/xcv.c
Quoted 6,779 lines
drivers/net/Kconfig | 14 + drivers/net/Makefile | 2 + drivers/net/octeontx/Makefile | 7 + drivers/net/octeontx/bgx.c | 1565 +++++++++++++++++++++++++++ drivers/net/octeontx/bgx.h | 259 +++++ drivers/net/octeontx/nic.h | 508 +++++++++ drivers/net/octeontx/nic_main.c | 778 +++++++++++++ drivers/net/octeontx/nic_reg.h | 250 +++++ drivers/net/octeontx/nicvf_main.c | 581 ++++++++++ drivers/net/octeontx/nicvf_queues.c | 1140 +++++++++++++++++++ drivers/net/octeontx/nicvf_queues.h | 353 ++++++ drivers/net/octeontx/q_struct.h | 695 ++++++++++++ drivers/net/octeontx/smi.c | 380 +++++++ drivers/net/octeontx/xcv.c | 124 +++ 14 files changed, 6656 insertions(+)create mode 100644
drivers/net/octeontx/Makefilecreate mode 100644drivers/net/octeontx/bgx.ccreate mode 100644drivers/net/octeontx/bgx.hcreate mode 100644drivers/net/octeontx/nic.hcreate mode 100644drivers/net/octeontx/nic_main.ccreate mode 100644drivers/net/octeontx/nic_reg.hcreate mode 100644drivers/net/octeontx/nicvf_main.ccreate mode 100644drivers/net/octeontx/nicvf_queues.ccreate mode 100644drivers/net/octeontx/nicvf_queues.hcreate mode 100644drivers/net/octeontx/q_struct.hcreate mode 100644drivers/net/octeontx/smi.ccreate mode 100644drivers/net/octeontx/xcv.cdrivers/net/Kconfig +14
-0@@ -407,6 +407,20 @@ config MT7628_ETH The MediaTek MT7628 ethernet interface is used on MT7628 and MT7688 based boards. +config NET_OCTEONTX + bool "OcteonTX Ethernet support" + depends on ARCH_OCTEONTX + depends on PCI_SRIOV + help + You must select Y to enable network device support for + OcteonTX SoCs. If unsure, say n +config OCTEONTX_SMI + bool "OcteonTX SMI Device support" + depends on ARCH_OCTEONTX || ARCH_OCTEONTX2 + help + You must select Y to enable SMI controller support for + OcteonTX or OcteonTX2 SoCs. If unsure, say n + config PCH_GBE bool "Intel Platform Controller Hub EG20T GMAC driver" depends on DM_ETH && DM_PCIdrivers/net/Makefile +2
-0@@ -65,6 +65,8 @@ obj-$(CONFIG_RENESAS_RAVB) += ravb.o obj-$(CONFIG_SMC91111) += smc91111.o obj-$(CONFIG_SMC911X) += smc911x.o obj-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o +obj-$(CONFIG_NET_OCTEONTX) += octeontx/ +obj-$(CONFIG_OCTEONTX_SMI) += octeontx/smi.o obj-$(CONFIG_FMAN_ENET) += fsl_mdio.o obj-$(CONFIG_ULI526X) += uli526x.o obj-$(CONFIG_VSC7385_ENET) += vsc7385.odrivers/net/octeontx/Makefile new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2018 Marvell International Ltd. +# + +obj-$(CONFIG_NET_OCTEONTX) += bgx.o nic_main.o nicvf_queues.o nicvf_main.o \ + xcv.odrivers/net/octeontx/bgx.c new file +1565
-0@@ -0,0 +1,1565 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 Marvell International Ltd. +*/ + +#include <config.h> +#include <dm.h> +#include <errno.h> +#include <fdt_support.h> +#include <malloc.h> +#include <miiphy.h> +#include <misc.h> +#include <net.h> +#include <netdev.h> +#include <pci.h> +#include <pci_ids.h> +#include <asm/io.h> +#include <asm/arch/board.h> +#include <linux/delay.h> +#include <linux/libfdt.h> + +#include "nic_reg.h" +#include "nic.h" +#include "bgx.h" + +static const phy_interface_t if_mode[] = { + [QLM_MODE_SGMII ] =PHY_INTERFACE_MODE_SGMII , + [QLM_MODE_RGMII ] =PHY_INTERFACE_MODE_RGMII , + [QLM_MODE_QSGMII ] =PHY_INTERFACE_MODE_QSGMII , + [QLM_MODE_XAUI ] =PHY_INTERFACE_MODE_XAUI , + [QLM_MODE_RXAUI ] =PHY_INTERFACE_MODE_RXAUI , +}; + +struct lmac { +struct bgx *bgx; +int dmac; +u8 mac[6 ]; +bool link_up; +bool init_pend; +int lmacid;/* ID within BGX */ +int phy_addr;/* ID on board */ +struct udevice *dev; +struct mii_dev *mii_bus; +struct phy_device *phydev; +unsigned int last_duplex; +unsigned int last_link; +unsigned int last_speed; +int lane_to_sds; +int use_training; +int lmac_type; +u8 qlm_mode; +int qlm; +bool is_1gx; +}; + +struct bgx { +u8 bgx_id; +int node; +struct lmac lmac[MAX_LMAC_PER_BGX ]; +int lmac_count; +u8 max_lmac; +void __iomem *reg_base; +struct pci_dev *pdev; +bool is_rgx; +}; + +struct bgx_board_info bgx_board_info[MAX_BGX_PER_NODE ]; + +struct bgx *bgx_vnic[MAX_BGX_PER_NODE ]; + +/* APIs to read/write BGXX CSRs */ +static u64 bgx_reg_read (struct bgx *bgx,uint8_t lmac,u64 offset) +{ +u64 addr = (uintptr_t )bgx->reg_base + + ((uint32_t )lmac <<20 ) + offset; + +return readq ((void *)addr); +} + +static void bgx_reg_write (struct bgx *bgx,uint8_t lmac, +u64 offset,u64 val) +{ +u64 addr = (uintptr_t )bgx->reg_base + + ((uint32_t )lmac <<20 ) + offset; + +writeq (val, (void *)addr); +} + +static void bgx_reg_modify (struct bgx *bgx,uint8_t lmac, +u64 offset,u64 val) +{ +u64 addr = (uintptr_t )bgx->reg_base + + ((uint32_t )lmac <<20 ) + offset; + +writeq (val |bgx_reg_read (bgx, lmac, offset), (void *)addr); +} + +static int bgx_poll_reg (struct bgx *bgx,uint8_t lmac, +u64 reg,u64 mask,bool zero) +{ +int timeout =200 ; +u64 reg_val; + +while (timeout) { + reg_val =bgx_reg_read (bgx, lmac, reg); +if (zero && !(reg_val & mask)) +return 0 ; +if (!zero && (reg_val & mask)) +return 0 ; +mdelay (1 ); + timeout--; + } +return 1 ; +} + +static int gser_poll_reg (u64 reg,int bit,u64 mask,u64 expected_val, +int timeout) +{ +u64 reg_val; + +debug ("%s reg = %#llx, mask = %#llx," , __func__, reg, mask); +debug (" expected_val = %#llx, bit = %d\n" , expected_val, bit); +while (timeout) { + reg_val =readq (reg) >> bit; +if ((reg_val & mask) == (expected_val)) +return 0 ; +mdelay (1 ); + timeout--; + } +return 1 ; +} + +static bool is_bgx_port_valid (int bgx,int lmac) +{ +debug ("%s bgx %d lmac %d valid %d\n" , __func__, bgx, lmac, + bgx_board_info[bgx].lmac_reg[lmac]); + +if (bgx_board_info[bgx].lmac_reg[lmac]) +return 1 ; +else +return 0 ; +} + +struct lmac *bgx_get_lmac (int node,int bgx_idx,int lmacid) +{ +struct bgx *bgx = bgx_vnic[(node *MAX_BGX_PER_NODE ) + bgx_idx]; + +if (bgx) +return &bgx->lmac[lmacid]; + +return NULL ; +} + +const u8 *bgx_get_lmac_mac (int node,int bgx_idx,int lmacid) +{ +struct bgx *bgx = bgx_vnic[(node *MAX_BGX_PER_NODE ) + bgx_idx]; + +if (bgx) +return bgx->lmac[lmacid].mac; + +return NULL ; +} + +void bgx_set_lmac_mac (int node,int bgx_idx,int lmacid,const u8 *mac) +{ +struct bgx *bgx = bgx_vnic[(node *MAX_BGX_PER_NODE ) + bgx_idx]; + +if (!bgx) +return ; + +memcpy (bgx->lmac[lmacid].mac, mac,6 ); +} + +/* Return number of BGX present in HW */ +void bgx_get_count (int node,int *bgx_count) +{ +int i; +struct bgx *bgx; + + *bgx_count =0 ; +for (i =0 ; i <MAX_BGX_PER_NODE ; i++) { + bgx = bgx_vnic[node *MAX_BGX_PER_NODE + i]; +debug ("bgx_vnic[%u]: %p\n" , node *MAX_BGX_PER_NODE + i, + bgx); +if (bgx) + *bgx_count |= (1 << i); + } +} + +/* Return number of LMAC configured for this BGX */ +int bgx_get_lmac_count (int node,int bgx_idx) +{ +struct bgx *bgx; + + bgx = bgx_vnic[(node *MAX_BGX_PER_NODE ) + bgx_idx]; +if (bgx) +return bgx->lmac_count; + +return 0 ; +} + +void bgx_lmac_rx_tx_enable (int node,int bgx_idx,int lmacid,bool enable) +{ +struct bgx *bgx = bgx_vnic[(node *MAX_BGX_PER_NODE ) + bgx_idx]; +u64 cfg; + +if (!bgx) +return ; + + cfg =bgx_reg_read (bgx, lmacid,BGX_CMRX_CFG ); +if (enable) + cfg |=CMR_PKT_RX_EN |CMR_PKT_TX_EN ; +else + cfg &= ~(CMR_PKT_RX_EN |CMR_PKT_TX_EN ); +bgx_reg_write (bgx, lmacid,BGX_CMRX_CFG , cfg); +} + +static void bgx_flush_dmac_addrs (struct bgx *bgx,u64 lmac) +{ +u64 dmac =0x00 ; +u64 offset, addr; + +while (bgx->lmac[lmac].dmac >0 ) { + offset = ((bgx->lmac[lmac].dmac -1 ) *sizeof (dmac)) + + (lmac *MAX_DMAC_PER_LMAC *sizeof (dmac)); + addr = (uintptr_t )bgx->reg_base + +BGX_CMR_RX_DMACX_CAM + offset; +writeq (dmac, (void *)addr); + bgx->lmac[lmac].dmac--; + } +} + +/* Configure BGX LMAC in internal loopback mode */ +void bgx_lmac_internal_loopback (int node,int bgx_idx, +int lmac_idx,bool enable) +{ +struct bgx *bgx; +struct lmac *lmac; +u64 cfg; + + bgx = bgx_vnic[(node *MAX_BGX_PER_NODE ) + bgx_idx]; +if (!bgx) +return ; + + lmac = &bgx->lmac[lmac_idx]; +if (lmac->qlm_mode ==QLM_MODE_SGMII ) { + cfg =bgx_reg_read (bgx, lmac_idx,BGX_GMP_PCS_MRX_CTL ); +if (enable) + cfg |=PCS_MRX_CTL_LOOPBACK1 ; +else + cfg &= ~PCS_MRX_CTL_LOOPBACK1 ; +bgx_reg_write (bgx, lmac_idx,BGX_GMP_PCS_MRX_CTL , cfg); + }else { + cfg =bgx_reg_read (bgx, lmac_idx,BGX_SPUX_CONTROL1 ); +if (enable) + cfg |=SPU_CTL_LOOPBACK ; +else + cfg &= ~SPU_CTL_LOOPBACK ; +bgx_reg_write (bgx, lmac_idx,BGX_SPUX_CONTROL1 , cfg); + } +} + +/* Return the DLM used for the BGX */ +static int get_qlm_for_bgx (int node,int bgx_id,int index) +{ +int qlm =0 ; +u64 cfg; + +if (otx_is_soc (CN81XX )) { + qlm = (bgx_id) ?2 :0 ; + qlm += (index >=2 ) ?1 :0 ; + }else if (otx_is_soc (CN83XX )) { +switch (bgx_id) { +case 0 : + qlm =2 ; +break ; +case 1 : + qlm =3 ; +break ; +case 2 : +if (index >=2 ) + qlm =6 ; +else + qlm =5 ; +break ; +case 3 : + qlm =4 ; +break ; + } + } + + cfg =readq (GSERX_CFG (qlm)) &GSERX_CFG_BGX ; +debug ("%s:qlm%d: cfg = %lld\n" , __func__, qlm, cfg); + +/* Check if DLM is configured as BGX# */ +if (cfg) { +if (readq (GSERX_PHY_CTL (qlm))) +return -1 ; +return qlm; + } +return -1 ; +} + +static int bgx_lmac_sgmii_init (struct bgx *bgx,int lmacid) +{ +u64 cfg; +struct lmac *lmac; + + lmac = &bgx->lmac[lmacid]; + +debug ("%s:bgx_id = %d, lmacid = %d\n" , __func__, bgx->bgx_id, lmacid); + +bgx_reg_modify (bgx, lmacid,BGX_GMP_GMI_TXX_THRESH ,0x30 ); +/* max packet size */ +bgx_reg_modify (bgx, lmacid,BGX_GMP_GMI_RXX_JABBER ,MAX_FRAME_SIZE ); + +/* Disable frame alignment if using preamble */ + cfg =bgx_reg_read (bgx, lmacid,BGX_GMP_GMI_TXX_APPEND ); +if (cfg &1 ) +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_SGMII_CTL ,0 ); + +/* Enable lmac */ +bgx_reg_modify (bgx, lmacid,BGX_CMRX_CFG ,CMR_EN ); + +/* PCS reset */ +bgx_reg_modify (bgx, lmacid,BGX_GMP_PCS_MRX_CTL ,PCS_MRX_CTL_RESET ); +if (bgx_poll_reg (bgx, lmacid,BGX_GMP_PCS_MRX_CTL , +PCS_MRX_CTL_RESET , true)) { +printf ("BGX PCS reset not completed\n" ); +return -1 ; + } + +/* power down, reset autoneg, autoneg enable */ + cfg =bgx_reg_read (bgx, lmacid,BGX_GMP_PCS_MRX_CTL ); + cfg &= ~PCS_MRX_CTL_PWR_DN ; + +if (bgx_board_info[bgx->bgx_id].phy_info[lmacid].autoneg_dis) + cfg |= (PCS_MRX_CTL_RST_AN ); +else + cfg |= (PCS_MRX_CTL_RST_AN |PCS_MRX_CTL_AN_EN ); +bgx_reg_write (bgx, lmacid,BGX_GMP_PCS_MRX_CTL , cfg); + +/* Disable disparity for QSGMII mode, to prevent propogation across +* ports. +*/ + +if (lmac->qlm_mode ==QLM_MODE_QSGMII ) { + cfg =bgx_reg_read (bgx, lmacid,BGX_GMP_PCS_MISCX_CTL ); + cfg &= ~PCS_MISCX_CTL_DISP_EN ; +bgx_reg_write (bgx, lmacid,BGX_GMP_PCS_MISCX_CTL , cfg); +return 0 ;/* Skip checking AN_CPT */ + } + +if (lmac->is_1gx) { + cfg =bgx_reg_read (bgx, lmacid,BGX_GMP_PCS_MISCX_CTL ); + cfg |=PCS_MISC_CTL_MODE ; +bgx_reg_write (bgx, lmacid,BGX_GMP_PCS_MISCX_CTL , cfg); + } + +if (lmac->qlm_mode ==QLM_MODE_SGMII ) { +if (bgx_poll_reg (bgx, lmacid,BGX_GMP_PCS_MRX_STATUS , +PCS_MRX_STATUS_AN_CPT , false)) { +printf ("BGX AN_CPT not completed\n" ); +return -1 ; + } + } + +return 0 ; +} + +static int bgx_lmac_sgmii_set_link_speed (struct lmac *lmac) +{ +u64 prtx_cfg; +u64 pcs_miscx_ctl; +u64 cfg; +struct bgx *bgx = lmac->bgx; +unsigned int lmacid = lmac->lmacid; + +debug ("%s: lmacid %d\n" , __func__, lmac->lmacid); + +/* Disable LMAC before setting up speed */ + cfg =bgx_reg_read (bgx, lmacid,BGX_CMRX_CFG ); + cfg &= ~CMR_EN ; +bgx_reg_write (bgx, lmacid,BGX_CMRX_CFG , cfg); + +/* Read GMX CFG */ + prtx_cfg =bgx_reg_read (bgx, lmacid, +BGX_GMP_GMI_PRTX_CFG ); +/* Read PCS MISCS CTL */ + pcs_miscx_ctl =bgx_reg_read (bgx, lmacid, +BGX_GMP_PCS_MISCX_CTL ); + +/* Use GMXENO to force the link down*/ +if (lmac->link_up) { + pcs_miscx_ctl &= ~PCS_MISC_CTL_GMX_ENO ; +/* change the duplex setting if the link is up */ + prtx_cfg |=GMI_PORT_CFG_DUPLEX ; + }else { + pcs_miscx_ctl |=PCS_MISC_CTL_GMX_ENO ; + } + +/* speed based setting for GMX */ +switch (lmac->last_speed) { +case 10 : + prtx_cfg &= ~GMI_PORT_CFG_SPEED ; + prtx_cfg |=GMI_PORT_CFG_SPEED_MSB ; + prtx_cfg &= ~GMI_PORT_CFG_SLOT_TIME ; + pcs_miscx_ctl |=50 ;/* sampling point */ +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_SLOT ,0x40 ); +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_BURST ,0 ); +break ; +case 100 : + prtx_cfg &= ~GMI_PORT_CFG_SPEED ; + prtx_cfg &= ~GMI_PORT_CFG_SPEED_MSB ; + prtx_cfg &= ~GMI_PORT_CFG_SLOT_TIME ; + pcs_miscx_ctl |=0x5 ;/* sampling point */ +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_SLOT ,0x40 ); +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_BURST ,0 ); +break ; +case 1000 : + prtx_cfg |=GMI_PORT_CFG_SPEED ; + prtx_cfg &= ~GMI_PORT_CFG_SPEED_MSB ; + prtx_cfg |=GMI_PORT_CFG_SLOT_TIME ; + pcs_miscx_ctl |=0x1 ;/* sampling point */ +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_SLOT ,0x200 ); +if (lmac->last_duplex) +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_BURST ,0 ); +else /* half duplex */ +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_BURST , +0x2000 ); +break ; +default : +break ; + } + +/* write back the new PCS misc and GMX settings */ +bgx_reg_write (bgx, lmacid,BGX_GMP_PCS_MISCX_CTL , pcs_miscx_ctl); +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_PRTX_CFG , prtx_cfg); + +/* read back GMX CFG again to check config completion */ +bgx_reg_read (bgx, lmacid,BGX_GMP_GMI_PRTX_CFG ); + +/* enable BGX back */ + cfg =bgx_reg_read (bgx, lmacid,BGX_CMRX_CFG ); + cfg |=CMR_EN ; +bgx_reg_write (bgx, lmacid,BGX_CMRX_CFG , cfg); + +return 0 ; +} + +static int bgx_lmac_xaui_init (struct bgx *bgx,int lmacid,int lmac_type) +{ +u64 cfg; +struct lmac *lmac; + + lmac = &bgx->lmac[lmacid]; + +/* Reset SPU */ +bgx_reg_modify (bgx, lmacid,BGX_SPUX_CONTROL1 ,SPU_CTL_RESET ); +if (bgx_poll_reg (bgx, lmacid,BGX_SPUX_CONTROL1 ,SPU_CTL_RESET , true)) { +printf ("BGX SPU reset not completed\n" ); +return -1 ; + } + +/* Disable LMAC */ + cfg =bgx_reg_read (bgx, lmacid,BGX_CMRX_CFG ); + cfg &= ~CMR_EN ; +bgx_reg_write (bgx, lmacid,BGX_CMRX_CFG , cfg); + +bgx_reg_modify (bgx, lmacid,BGX_SPUX_CONTROL1 ,SPU_CTL_LOW_POWER ); +/* Set interleaved running disparity for RXAUI */ +if (lmac->qlm_mode !=QLM_MODE_RXAUI ) +bgx_reg_modify (bgx, lmacid, +BGX_SPUX_MISC_CONTROL ,SPU_MISC_CTL_RX_DIS ); +else +bgx_reg_modify (bgx, lmacid,BGX_SPUX_MISC_CONTROL , +SPU_MISC_CTL_RX_DIS |SPU_MISC_CTL_INTLV_RDISP ); + +/* clear all interrupts */ + cfg =bgx_reg_read (bgx, lmacid,BGX_SMUX_RX_INT ); +bgx_reg_write (bgx, lmacid,BGX_SMUX_RX_INT , cfg); + cfg =bgx_reg_read (bgx, lmacid,BGX_SMUX_TX_INT ); +bgx_reg_write (bgx, lmacid,BGX_SMUX_TX_INT , cfg); + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_INT ); +bgx_reg_write (bgx, lmacid,BGX_SPUX_INT , cfg); + +if (lmac->use_training) { +bgx_reg_write (bgx, lmacid,BGX_SPUX_BR_PMD_LP_CUP ,0x00 ); +bgx_reg_write (bgx, lmacid,BGX_SPUX_BR_PMD_LD_CUP ,0x00 ); +bgx_reg_write (bgx, lmacid,BGX_SPUX_BR_PMD_LD_REP ,0x00 ); +/* training enable */ +bgx_reg_modify (bgx, lmacid, +BGX_SPUX_BR_PMD_CRTL ,SPU_PMD_CRTL_TRAIN_EN ); + } + +/* Append FCS to each packet */ +bgx_reg_modify (bgx, lmacid,BGX_SMUX_TX_APPEND ,SMU_TX_APPEND_FCS_D ); + +/* Disable forward error correction */ + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_FEC_CONTROL ); + cfg &= ~SPU_FEC_CTL_FEC_EN ; +bgx_reg_write (bgx, lmacid,BGX_SPUX_FEC_CONTROL , cfg); + +/* Disable autoneg */ + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_AN_CONTROL ); + cfg = cfg & ~(SPU_AN_CTL_XNP_EN ); +if (lmac->use_training) + cfg = cfg | (SPU_AN_CTL_AN_EN ); +else + cfg = cfg & ~(SPU_AN_CTL_AN_EN ); +bgx_reg_write (bgx, lmacid,BGX_SPUX_AN_CONTROL , cfg); + + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_AN_ADV ); +/* Clear all KR bits, configure according to the mode */ + cfg &= ~((0xfULL <<22 ) | (1ULL <<12 )); +if (lmac->qlm_mode ==QLM_MODE_10G_KR ) + cfg |= (1 <<23 ); +else if (lmac->qlm_mode ==QLM_MODE_40G_KR4 ) + cfg |= (1 <<24 ); +bgx_reg_write (bgx, lmacid,BGX_SPUX_AN_ADV , cfg); + + cfg =bgx_reg_read (bgx,0 ,BGX_SPU_DBG_CONTROL ); +if (lmac->use_training) + cfg |=SPU_DBG_CTL_AN_ARB_LINK_CHK_EN ; +else + cfg &= ~SPU_DBG_CTL_AN_ARB_LINK_CHK_EN ; +bgx_reg_write (bgx,0 ,BGX_SPU_DBG_CONTROL , cfg); + +/* Enable lmac */ +bgx_reg_modify (bgx, lmacid,BGX_CMRX_CFG ,CMR_EN ); + + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_CONTROL1 ); + cfg &= ~SPU_CTL_LOW_POWER ; +bgx_reg_write (bgx, lmacid,BGX_SPUX_CONTROL1 , cfg); + + cfg =bgx_reg_read (bgx, lmacid,BGX_SMUX_TX_CTL ); + cfg &= ~SMU_TX_CTL_UNI_EN ; + cfg |=SMU_TX_CTL_DIC_EN ; +bgx_reg_write (bgx, lmacid,BGX_SMUX_TX_CTL , cfg); + +/* take lmac_count into account */ +bgx_reg_modify (bgx, lmacid,BGX_SMUX_TX_THRESH , (0x100 -1 )); +/* max packet size */ +bgx_reg_modify (bgx, lmacid,BGX_SMUX_RX_JABBER ,MAX_FRAME_SIZE ); + +debug ("xaui_init: lmacid = %d, qlm = %d, qlm_mode = %d\n" , + lmacid, lmac->qlm, lmac->qlm_mode); +/* RXAUI with Marvell PHY requires some tweaking */ +if (lmac->qlm_mode ==QLM_MODE_RXAUI ) { +char mii_name[20 ]; +struct phy_info *phy; + + phy = &bgx_board_info[bgx->bgx_id].phy_info[lmacid]; +snprintf (mii_name,sizeof (mii_name),"smi%d" , phy->mdio_bus); + +debug ("mii_name: %s\n" , mii_name); + lmac->mii_bus =miiphy_get_dev_by_name (mii_name); + lmac->phy_addr = phy->phy_addr; +rxaui_phy_xs_init (lmac->mii_bus, lmac->phy_addr); + } + +return 0 ; +} + +/* Get max number of lanes present in a given QLM/DLM */ +static int get_qlm_lanes (int qlm) +{ +if (otx_is_soc (CN81XX )) +return 2 ; +else if (otx_is_soc (CN83XX )) +return (qlm >=5 ) ?2 :4 ; +else +return -1 ; +} + +int __rx_equalization (int qlm,int lane) +{ +int max_lanes =get_qlm_lanes (qlm); +int l; +int fail =0 ; + +/* Before completing Rx equalization wait for +* GSERx_RX_EIE_DETSTS[CDRLOCK] to be set +* This ensures the rx data is valid +*/ +if (lane ==-1 ) { +if (gser_poll_reg (GSER_RX_EIE_DETSTS (qlm),GSER_CDRLOCK ,0xf , + (1 << max_lanes) -1 ,100 )) { +debug ("ERROR: CDR Lock not detected" ); +debug (" on DLM%d for 2 lanes\n" , qlm); +return -1 ; + } + }else { +if (gser_poll_reg (GSER_RX_EIE_DETSTS (qlm),GSER_CDRLOCK , + (0xf & (1 << lane)), (1 << lane),100 )) { +debug ("ERROR: DLM%d: CDR Lock not detected" , qlm); +debug (" on %d lane\n" , lane); +return -1 ; + } + } + +for (l =0 ; l < max_lanes; l++) { +u64 rctl, reer; + +if (lane !=-1 && lane != l) +continue ; + +/* Enable software control */ + rctl =readq (GSER_BR_RXX_CTL (qlm, l)); + rctl |=GSER_BR_RXX_CTL_RXT_SWM ; +writeq (rctl,GSER_BR_RXX_CTL (qlm, l)); + +/* Clear the completion flag and initiate a new request */ + reer =readq (GSER_BR_RXX_EER (qlm, l)); + reer &= ~GSER_BR_RXX_EER_RXT_ESV ; + reer |=GSER_BR_RXX_EER_RXT_EER ; +writeq (reer,GSER_BR_RXX_EER (qlm, l)); + } + +/* Wait for RX equalization to complete */ +for (l =0 ; l < max_lanes; l++) { +u64 rctl, reer; + +if (lane !=-1 && lane != l) +continue ; + +gser_poll_reg (GSER_BR_RXX_EER (qlm, l),EER_RXT_ESV ,1 ,1 ,200 ); + reer =readq (GSER_BR_RXX_EER (qlm, l)); + +/* Switch back to hardware control */ + rctl =readq (GSER_BR_RXX_CTL (qlm, l)); + rctl &= ~GSER_BR_RXX_CTL_RXT_SWM ; +writeq (rctl,GSER_BR_RXX_CTL (qlm, l)); + +if (reer &GSER_BR_RXX_EER_RXT_ESV ) { +debug ("Rx equalization completed on DLM%d" , qlm); +debug (" QLM%d rxt_esm = 0x%llx\n" , l, (reer &0x3fff )); + }else { +debug ("Rx equalization timedout on DLM%d" , qlm); +debug (" lane %d\n" , l); + fail =1 ; + } + } + +return (fail) ?-1 :0 ; +} + +static int bgx_xaui_check_link (struct lmac *lmac) +{ +struct bgx *bgx = lmac->bgx; +int lmacid = lmac->lmacid; +int lmac_type = lmac->lmac_type; +u64 cfg; + +bgx_reg_modify (bgx, lmacid,BGX_SPUX_MISC_CONTROL ,SPU_MISC_CTL_RX_DIS ); + +/* check if auto negotiation is complete */ + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_AN_CONTROL ); +if (cfg &SPU_AN_CTL_AN_EN ) { + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_AN_STATUS ); +if (!(cfg &SPU_AN_STS_AN_COMPLETE )) { +/* Restart autonegotiation */ +debug ("restarting auto-neg\n" ); +bgx_reg_modify (bgx, lmacid,BGX_SPUX_AN_CONTROL , +SPU_AN_CTL_AN_RESTART ); +return -1 ; + } + } + +debug ("%s link use_training %d\n" , __func__, lmac->use_training); +if (lmac->use_training) { + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_INT ); +if (!(cfg & (1ull <<13 ))) { +debug ("waiting for link training\n" ); +/* Clear the training interrupts (W1C) */ + cfg = (1ull <<13 ) | (1ull <<14 ); +bgx_reg_write (bgx, lmacid,BGX_SPUX_INT , cfg); + +udelay (2000 ); +/* Restart training */ + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_BR_PMD_CRTL ); + cfg |= (1ull <<0 ); +bgx_reg_write (bgx, lmacid,BGX_SPUX_BR_PMD_CRTL , cfg); +return -1 ; + } + } + +/* Perform RX Equalization. Applies to non-KR interfaces for speeds +* >= 6.25Gbps. +*/ +if (!lmac->use_training) { +int qlm; +bool use_dlm =0 ; + +if (otx_is_soc (CN81XX ) || (otx_is_soc (CN83XX ) && + bgx->bgx_id ==2 )) + use_dlm =1 ; +switch (lmac->lmac_type) { +default : +case BGX_MODE_SGMII : +case BGX_MODE_RGMII : +case BGX_MODE_XAUI : +/* Nothing to do */ +break ; +case BGX_MODE_XLAUI : +if (use_dlm) { +if (__rx_equalization (lmac->qlm,-1 ) || +__rx_equalization (lmac->qlm +1 ,-1 )) { +printf ("BGX%d:%d" , bgx->bgx_id, lmacid); +printf (" Waiting for RX Equalization" ); +printf (" on DLM%d/DLM%d\n" , + lmac->qlm, lmac->qlm +1 ); +return -1 ; + } + }else { +if (__rx_equalization (lmac->qlm,-1 )) { +printf ("BGX%d:%d" , bgx->bgx_id, lmacid); +printf (" Waiting for RX Equalization" ); +printf (" on QLM%d\n" , lmac->qlm); +return -1 ; + } + } +break ; +case BGX_MODE_RXAUI : +/* RXAUI0 uses LMAC0:QLM0/QLM2 and RXAUI1 uses +* LMAC1:QLM1/QLM3 RXAUI requires 2 lanes +* for each interface +*/ + qlm = lmac->qlm; +if (__rx_equalization (qlm,0 )) { +printf ("BGX%d:%d" , bgx->bgx_id, lmacid); +printf (" Waiting for RX Equalization" ); +printf (" on QLM%d, Lane0\n" , qlm); +return -1 ; + } +if (__rx_equalization (qlm,1 )) { +printf ("BGX%d:%d" , bgx->bgx_id, lmacid); +printf (" Waiting for RX Equalization" ); +printf (" on QLM%d, Lane1\n" , qlm); +return -1 ; + } +break ; +case BGX_MODE_XFI : + { +int lid; +bool altpkg =otx_is_altpkg (); + +if (bgx->bgx_id ==0 && altpkg && lmacid) + lid =0 ; +else if ((lmacid >=2 ) && use_dlm) + lid = lmacid -2 ; +else + lid = lmacid; + +if (__rx_equalization (lmac->qlm, lid)) { +printf ("BGX%d:%d" , bgx->bgx_id, lid); +printf (" Waiting for RX Equalization" ); +printf (" on QLM%d\n" , lmac->qlm); + } + } +break ; + } + } + +/* wait for PCS to come out of reset */ +if (bgx_poll_reg (bgx, lmacid,BGX_SPUX_CONTROL1 ,SPU_CTL_RESET , true)) { +printf ("BGX SPU reset not completed\n" ); +return -1 ; + } + +if (lmac_type ==3 || lmac_type ==4 ) { +if (bgx_poll_reg (bgx, lmacid,BGX_SPUX_BR_STATUS1 , +SPU_BR_STATUS_BLK_LOCK , false)) { +printf ("SPU_BR_STATUS_BLK_LOCK not completed\n" ); +return -1 ; + } + }else { +if (bgx_poll_reg (bgx, lmacid,BGX_SPUX_BX_STATUS , +SPU_BX_STATUS_RX_ALIGN , false)) { +printf ("SPU_BX_STATUS_RX_ALIGN not completed\n" ); +return -1 ; + } + } + +/* Clear rcvflt bit (latching high) and read it back */ +bgx_reg_modify (bgx, lmacid,BGX_SPUX_STATUS2 ,SPU_STATUS2_RCVFLT ); +if (bgx_reg_read (bgx, lmacid,BGX_SPUX_STATUS2 ) &SPU_STATUS2_RCVFLT ) { +printf ("Receive fault, retry training\n" ); +if (lmac->use_training) { + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_INT ); +if (!(cfg & (1ull <<13 ))) { + cfg = (1ull <<13 ) | (1ull <<14 ); +bgx_reg_write (bgx, lmacid,BGX_SPUX_INT , cfg); + cfg =bgx_reg_read (bgx, lmacid, +BGX_SPUX_BR_PMD_CRTL ); + cfg |= (1ull <<0 ); +bgx_reg_write (bgx, lmacid, +BGX_SPUX_BR_PMD_CRTL , cfg); +return -1 ; + } + } +return -1 ; + } + +/* Wait for MAC RX to be ready */ +if (bgx_poll_reg (bgx, lmacid,BGX_SMUX_RX_CTL , +SMU_RX_CTL_STATUS , true)) { +printf ("SMU RX link not okay\n" ); +return -1 ; + } + +/* Wait for BGX RX to be idle */ +if (bgx_poll_reg (bgx, lmacid,BGX_SMUX_CTL ,SMU_CTL_RX_IDLE , false)) { +printf ("SMU RX not idle\n" ); +return -1 ; + } + +/* Wait for BGX TX to be idle */ +if (bgx_poll_reg (bgx, lmacid,BGX_SMUX_CTL ,SMU_CTL_TX_IDLE , false)) { +printf ("SMU TX not idle\n" ); +return -1 ; + } + +if (bgx_reg_read (bgx, lmacid,BGX_SPUX_STATUS2 ) &SPU_STATUS2_RCVFLT ) { +printf ("Receive fault\n" ); +return -1 ; + } + +/* Receive link is latching low. Force it high and verify it */ +if (!(bgx_reg_read (bgx, lmacid,BGX_SPUX_STATUS1 ) & +SPU_STATUS1_RCV_LNK )) +bgx_reg_modify (bgx, lmacid,BGX_SPUX_STATUS1 , +SPU_STATUS1_RCV_LNK ); +if (bgx_poll_reg (bgx, lmacid,BGX_SPUX_STATUS1 , +SPU_STATUS1_RCV_LNK , false)) { +printf ("SPU receive link down\n" ); +return -1 ; + } + + cfg =bgx_reg_read (bgx, lmacid,BGX_SPUX_MISC_CONTROL ); + cfg &= ~SPU_MISC_CTL_RX_DIS ; +bgx_reg_write (bgx, lmacid,BGX_SPUX_MISC_CONTROL , cfg); +return 0 ; +} + +static int bgx_lmac_enable (struct bgx *bgx,int8_t lmacid) +{ +struct lmac *lmac; +u64 cfg; + + lmac = &bgx->lmac[lmacid]; + +debug ("%s: lmac: %p, lmacid = %d\n" , __func__, lmac, lmacid); + +if (lmac->qlm_mode ==QLM_MODE_SGMII || + lmac->qlm_mode ==QLM_MODE_RGMII || + lmac->qlm_mode ==QLM_MODE_QSGMII ) { +if (bgx_lmac_sgmii_init (bgx, lmacid)) { +debug ("bgx_lmac_sgmii_init failed\n" ); +return -1 ; + } + cfg =bgx_reg_read (bgx, lmacid,BGX_GMP_GMI_TXX_APPEND ); + cfg |= ((1ull <<2 ) | (1ull <<1 ));/* FCS and PAD */ +bgx_reg_modify (bgx, lmacid,BGX_GMP_GMI_TXX_APPEND , cfg); +bgx_reg_write (bgx, lmacid,BGX_GMP_GMI_TXX_MIN_PKT ,60 -1 ); + }else { +if (bgx_lmac_xaui_init (bgx, lmacid, lmac->lmac_type)) +return -1 ; + cfg =bgx_reg_read (bgx, lmacid,BGX_SMUX_TX_APPEND ); + cfg |= ((1ull <<2 ) | (1ull <<1 ));/* FCS and PAD */ +bgx_reg_modify (bgx, lmacid,BGX_SMUX_TX_APPEND , cfg); +bgx_reg_write (bgx, lmacid,BGX_SMUX_TX_MIN_PKT ,60 +4 ); + } + +/* Enable lmac */ +bgx_reg_modify (bgx, lmacid,BGX_CMRX_CFG , +CMR_EN |CMR_PKT_RX_EN |CMR_PKT_TX_EN ); + +return 0 ; +} + +int bgx_poll_for_link (int node,int bgx_idx,int lmacid) +{ +int ret; +struct lmac *lmac =bgx_get_lmac (node, bgx_idx, lmacid); +char mii_name[10 ]; +struct phy_info *phy; + +if (!lmac) { +printf ("LMAC %d/%d/%d is disabled or doesn't exist\n" , + node, bgx_idx, lmacid); +return 0 ; + } + +debug ("%s: %d, lmac: %d/%d/%d %p\n" , + __FILE__, __LINE__, + node, bgx_idx, lmacid, lmac); +if (lmac->init_pend) { + ret =bgx_lmac_enable (lmac->bgx, lmacid); +if (ret <0 ) { +printf ("BGX%d LMAC%d lmac_enable failed\n" , bgx_idx, + lmacid); +return ret; + } + lmac->init_pend =0 ; +mdelay (100 ); + } +if (lmac->qlm_mode ==QLM_MODE_SGMII || + lmac->qlm_mode ==QLM_MODE_RGMII || + lmac->qlm_mode ==QLM_MODE_QSGMII ) { +if (bgx_board_info[bgx_idx].phy_info[lmacid].phy_addr ==-1 ) { + lmac->link_up =1 ; + lmac->last_speed =1000 ; + lmac->last_duplex =1 ; +printf ("BGX%d:LMAC %u link up\n" , bgx_idx, lmacid); +return lmac->link_up; + } +snprintf (mii_name,sizeof (mii_name),"smi%d" , + bgx_board_info[bgx_idx].phy_info[lmacid].mdio_bus); + +debug ("mii_name: %s\n" , mii_name); + + lmac->mii_bus =miiphy_get_dev_by_name (mii_name); + phy = &bgx_board_info[bgx_idx].phy_info[lmacid]; + lmac->phy_addr = phy->phy_addr; + +debug ("lmac->mii_bus: %p\n" , lmac->mii_bus); +if (!lmac->mii_bus) { +printf ("MDIO device %s not found\n" , mii_name); + ret = -ENODEV ; +return ret; + } + + lmac->phydev =phy_connect (lmac->mii_bus, lmac->phy_addr, + lmac->dev, + if_mode[lmac->qlm_mode]); + +if (!lmac->phydev) { +printf ("%s: No PHY device\n" , __func__); +return -1 ; + } + + ret =phy_config (lmac->phydev); +if (ret) { +printf ("%s: Could not initialize PHY %s\n" , + __func__, lmac->phydev->dev->name); +return ret; + } + + ret =phy_startup (lmac->phydev); +debug ("%s: %d\n" , __FILE__, __LINE__); +if (ret) { +printf ("%s: Could not initialize PHY %s\n" , + __func__, lmac->phydev->dev->name); + } + +#ifdef OCTEONTX_XCV +if (lmac->qlm_mode ==QLM_MODE_RGMII ) +xcv_setup_link (lmac->phydev->link, lmac->phydev->speed); +#endif + + lmac->link_up = lmac->phydev->link; + lmac->last_speed = lmac->phydev->speed; + lmac->last_duplex = lmac->phydev->duplex; + +debug ("%s qlm_mode %d phy link status 0x%x,last speed 0x%x," , + __func__, lmac->qlm_mode, lmac->link_up, + lmac->last_speed); +debug (" duplex 0x%x\n" , lmac->last_duplex); + +if (lmac->qlm_mode !=QLM_MODE_RGMII ) +bgx_lmac_sgmii_set_link_speed (lmac); + + }else { +u64 status1; +u64 tx_ctl; +u64 rx_ctl; + + status1 =bgx_reg_read (lmac->bgx, lmac->lmacid, +BGX_SPUX_STATUS1 ); + tx_ctl =bgx_reg_read (lmac->bgx, lmac->lmacid,BGX_SMUX_TX_CTL ); + rx_ctl =bgx_reg_read (lmac->bgx, lmac->lmacid,BGX_SMUX_RX_CTL ); + +debug ("BGX%d LMAC%d BGX_SPUX_STATUS2: %lx\n" , bgx_idx, lmacid, + (unsigned long )bgx_reg_read (lmac->bgx, lmac->lmacid, +BGX_SPUX_STATUS2 )); +debug ("BGX%d LMAC%d BGX_SPUX_STATUS1: %lx\n" , bgx_idx, lmacid, + (unsigned long )bgx_reg_read (lmac->bgx, lmac->lmacid, +BGX_SPUX_STATUS1 )); +debug ("BGX%d LMAC%d BGX_SMUX_RX_CTL: %lx\n" , bgx_idx, lmacid, + (unsigned long )bgx_reg_read (lmac->bgx, lmac->lmacid, +BGX_SMUX_RX_CTL )); +debug ("BGX%d LMAC%d BGX_SMUX_TX_CTL: %lx\n" , bgx_idx, lmacid, + (unsigned long )bgx_reg_read (lmac->bgx, lmac->lmacid, +BGX_SMUX_TX_CTL )); + +if ((status1 &SPU_STATUS1_RCV_LNK ) && + ((tx_ctl &SMU_TX_CTL_LNK_STATUS ) ==0 ) && + ((rx_ctl &SMU_RX_CTL_STATUS ) ==0 )) { + lmac->link_up =1 ; +if (lmac->lmac_type ==4 ) + lmac->last_speed =40000 ; +else + lmac->last_speed =10000 ; + lmac->last_duplex =1 ; + }else { + lmac->link_up =0 ; + lmac->last_speed =0 ; + lmac->last_duplex =0 ; +return bgx_xaui_check_link (lmac); + } + + lmac->last_link = lmac->link_up; + } + +printf ("BGX%d:LMAC %u link %s\n" , bgx_idx, lmacid, + (lmac->link_up) ?"up" :"down" ); + +return lmac->link_up; +} + +void bgx_lmac_disable (struct bgx *bgx,uint8_t lmacid) +{ +struct lmac *lmac; +u64 cmrx_cfg; + + lmac = &bgx->lmac[lmacid]; + + cmrx_cfg =bgx_reg_read (bgx, lmacid,BGX_CMRX_CFG ); + cmrx_cfg &= ~(1 <<15 ); +bgx_reg_write (bgx, lmacid,BGX_CMRX_CFG , cmrx_cfg); +bgx_flush_dmac_addrs (bgx, lmacid); + +if (lmac->phydev) +phy_shutdown (lmac->phydev); + + lmac->phydev =NULL ; +} + +/* Program BGXX_CMRX_CONFIG.{lmac_type,lane_to_sds} for each interface. +* And the number of LMACs used by this interface. Each lmac can be in +* programmed in a different mode, so parse each lmac one at a time. +*/ +static void bgx_init_hw (struct bgx *bgx) +{ +struct lmac *lmac; +int i, lmacid, count =0 , inc =0 ; +char buf[40 ]; +static int qsgmii_configured; + +for (lmacid =0 ; lmacid <MAX_LMAC_PER_BGX ; lmacid++) { +struct lmac *tlmac; + + lmac = &bgx->lmac[lmacid]; +debug ("%s: lmacid = %d, qlm = %d, mode = %d\n" , + __func__, lmacid, lmac->qlm, lmac->qlm_mode); +/* If QLM is not programmed, skip */ +if (lmac->qlm ==-1 ) +continue ; + +switch (lmac->qlm_mode) { +case QLM_MODE_SGMII : + { +/* EBB8000 (alternative pkg) has only lane0 present on +* DLM0 and DLM1, skip configuring other lanes +*/ +if (bgx->bgx_id ==0 &&otx_is_altpkg ()) { +if (lmacid %2 ) +continue ; + } + lmac->lane_to_sds = lmacid; + lmac->lmac_type =0 ; +snprintf (buf,sizeof (buf), +"BGX%d QLM%d LMAC%d mode: %s\n" , + bgx->bgx_id, lmac->qlm, lmacid, + lmac->is_1gx ?"1000Base-X" :"SGMII" ); +break ; + } +case QLM_MODE_XAUI : +if (lmacid !=0 ) +continue ; + lmac->lmac_type =1 ; + lmac->lane_to_sds =0xE4 ; +snprintf (buf,sizeof (buf), +"BGX%d QLM%d LMAC%d mode: XAUI\n" , + bgx->bgx_id, lmac->qlm, lmacid); +break ; +case QLM_MODE_RXAUI : +if (lmacid ==0 ) { + lmac->lmac_type =2 ; + lmac->lane_to_sds =0x4 ; + }else if (lmacid ==1 ) { +struct lmac *tlmac; + + tlmac = &bgx->lmac[2 ]; +if (tlmac->qlm_mode ==QLM_MODE_RXAUI ) { + lmac->lmac_type =2 ; + lmac->lane_to_sds =0xe ; + lmac->qlm = tlmac->qlm; + } + }else { +continue ; + } +snprintf (buf,sizeof (buf), +"BGX%d QLM%d LMAC%d mode: RXAUI\n" , + bgx->bgx_id, lmac->qlm, lmacid); +break ; +case QLM_MODE_XFI : +/* EBB8000 (alternative pkg) has only lane0 present on +* DLM0 and DLM1, skip configuring other lanes +*/ +if (bgx->bgx_id ==0 &&otx_is_altpkg ()) { +if (lmacid %2 ) +continue ; + } + lmac->lane_to_sds = lmacid; + lmac->lmac_type =3 ; +snprintf (buf,sizeof (buf), +"BGX%d QLM%d LMAC%d mode: XFI\n" , + bgx->bgx_id, lmac->qlm, lmacid); +break ; +case QLM_MODE_XLAUI : +if (lmacid !=0 ) +continue ; + lmac->lmac_type =4 ; + lmac->lane_to_sds =0xE4 ; +snprintf (buf,sizeof (buf), +"BGX%d QLM%d LMAC%d mode: XLAUI\n" , + bgx->bgx_id, lmac->qlm, lmacid); +break ; +case QLM_MODE_10G_KR : +/* EBB8000 (alternative pkg) has only lane0 present on +* DLM0 and DLM1, skip configuring other lanes +*/ +if (bgx->bgx_id ==0 &&otx_is_altpkg ()) { +if (lmacid %2 ) +continue ; + } + lmac->lane_to_sds = lmacid; + lmac->lmac_type =3 ; + lmac->use_training =1 ; +snprintf (buf,sizeof (buf), +"BGX%d QLM%d LMAC%d mode: 10G-KR\n" , + bgx->bgx_id, lmac->qlm, lmacid); +break ; +case QLM_MODE_40G_KR4 : +if (lmacid !=0 ) +continue ; + lmac->lmac_type =4 ; + lmac->lane_to_sds =0xE4 ; + lmac->use_training =1 ; +snprintf (buf,sizeof (buf), +"BGX%d QLM%d LMAC%d mode: 40G-KR4\n" , + bgx->bgx_id, lmac->qlm, lmacid); +break ; +case QLM_MODE_RGMII : +if (lmacid !=0 ) +continue ; + lmac->lmac_type =5 ; + lmac->lane_to_sds =0xE4 ; +snprintf (buf,sizeof (buf), +"BGX%d LMAC%d mode: RGMII\n" , + bgx->bgx_id, lmacid); +break ; +case QLM_MODE_QSGMII : +if (qsgmii_configured) +continue ; +if (lmacid ==0 || lmacid ==2 ) { + count =4 ; +printf ("BGX%d QLM%d LMAC%d mode: QSGMII\n" , + bgx->bgx_id, lmac->qlm, lmacid); +for (i =0 ; i < count; i++) { +struct lmac *l; +int type; + + l = &bgx->lmac[i]; + l->lmac_type =6 ; + type = l->lmac_type; + l->qlm_mode =QLM_MODE_QSGMII ; + l->lane_to_sds = lmacid + i; +if (is_bgx_port_valid (bgx->bgx_id, i)) +bgx_reg_write (bgx, i, +BGX_CMRX_CFG , + (type <<8 ) | + l->lane_to_sds); + } + qsgmii_configured =1 ; + } +continue ; +default : +continue ; + } + +/* Reset lmac to the unused slot */ +if (is_bgx_port_valid (bgx->bgx_id, count) && + lmac->qlm_mode !=QLM_MODE_QSGMII ) { +int lmac_en =0 ; +int tmp, idx; + + tlmac = &bgx->lmac[count]; + tlmac->lmac_type = lmac->lmac_type; + idx = bgx->bgx_id; + tmp = count + inc; +/* Adjust lane_to_sds based on BGX-ENABLE */ +for (; tmp <MAX_LMAC_PER_BGX ; inc++) { + lmac_en = bgx_board_info[idx].lmac_enable[tmp]; +if (lmac_en) +break ; + tmp = count + inc; + } + +if (inc !=0 && inc <MAX_LMAC_PER_BGX && + lmac_en && inc != count) + tlmac->lane_to_sds = + lmac->lane_to_sds +abs (inc - count); +else + tlmac->lane_to_sds = lmac->lane_to_sds; + tlmac->qlm = lmac->qlm; + tlmac->qlm_mode = lmac->qlm_mode; + +printf ("%s" , buf); +/* Initialize lmac_type and lane_to_sds */ +bgx_reg_write (bgx, count,BGX_CMRX_CFG , + (tlmac->lmac_type <<8 ) | + tlmac->lane_to_sds); + +if (tlmac->lmac_type ==BGX_MODE_SGMII ) { +if (tlmac->is_1gx) { +/* This is actually 1000BASE-X, so +* mark the LMAC as such. +*/ +bgx_reg_modify (bgx, count, +BGX_GMP_PCS_MISCX_CTL , +PCS_MISC_CTL_MODE ); + } + +if (!bgx_board_info[bgx->bgx_id].phy_info[lmacid].autoneg_dis) { +/* The Linux DTS does not disable +* autoneg for this LMAC (in SGMII or +* 1000BASE-X mode), so that means +* enable autoneg. +*/ +bgx_reg_modify (bgx, count, +BGX_GMP_PCS_MRX_CTL , +PCS_MRX_CTL_AN_EN ); + } + } + + count +=1 ; + } + } + +/* Done probing all 4 lmacs, now clear qsgmii_configured */ + qsgmii_configured =0 ; + +printf ("BGX%d LMACs: %d\n" , bgx->bgx_id, count); + bgx->lmac_count = count; +bgx_reg_write (bgx,0 ,BGX_CMR_RX_LMACS , count); +bgx_reg_write (bgx,0 ,BGX_CMR_TX_LMACS , count); + +bgx_reg_modify (bgx,0 ,BGX_CMR_GLOBAL_CFG ,CMR_GLOBAL_CFG_FCS_STRIP ); +if (bgx_reg_read (bgx,0 ,BGX_CMR_BIST_STATUS )) +printf ("BGX%d BIST failed\n" , bgx->bgx_id); + +/* Set the backpressure AND mask */ +for (i =0 ; i < bgx->lmac_count; i++) +bgx_reg_modify (bgx,0 ,BGX_CMR_CHAN_MSK_AND , + ((1ULL <<MAX_BGX_CHANS_PER_LMAC ) -1 ) << + (i *MAX_BGX_CHANS_PER_LMAC )); + +/* Disable all MAC filtering */ +for (i =0 ; i <RX_DMAC_COUNT ; i++) +bgx_reg_write (bgx,0 ,BGX_CMR_RX_DMACX_CAM + (i *8 ),0x00 ); + +/* Disable MAC steering (NCSI traffic) */ +for (i =0 ; i <RX_TRAFFIC_STEER_RULE_COUNT ; i++) +bgx_reg_write (bgx,0 ,BGX_CMR_RX_STREERING + (i *8 ),0x00 ); +} + +static void bgx_get_qlm_mode (struct bgx *bgx) +{ +struct lmac *lmac; +int lmacid; + +/* Read LMACx type to figure out QLM mode +* This is configured by low level firmware +*/ +for (lmacid =0 ; lmacid <MAX_LMAC_PER_BGX ; lmacid++) { +int lmac_type; +int train_en; +int index =0 ; + +if (otx_is_soc (CN81XX ) || (otx_is_soc (CN83XX ) && + bgx->bgx_id ==2 )) + index = (lmacid <2 ) ?0 :2 ; + + lmac = &bgx->lmac[lmacid]; + +/* check if QLM is programmed, if not, skip */ +if (lmac->qlm ==-1 ) +continue ; + + lmac_type =bgx_reg_read (bgx, index,BGX_CMRX_CFG ); + lmac->lmac_type = (lmac_type >>8 ) &0x07 ; +debug ("%s:%d:%d: lmac_type = %d, altpkg = %d\n" , __func__, + bgx->bgx_id, lmacid, lmac->lmac_type,otx_is_altpkg ()); + + train_en = (readq (GSERX_SCRATCH (lmac->qlm))) &0xf ; + lmac->is_1gx =bgx_reg_read (bgx, index,BGX_GMP_PCS_MISCX_CTL ) + & (PCS_MISC_CTL_MODE ) ? true : false; + +switch (lmac->lmac_type) { +case BGX_MODE_SGMII : +if (bgx->is_rgx) { +if (lmacid ==0 ) { + lmac->qlm_mode =QLM_MODE_RGMII ; +debug ("BGX%d LMAC%d mode: RGMII\n" , + bgx->bgx_id, lmacid); + } +continue ; + }else { +if (bgx->bgx_id ==0 &&otx_is_altpkg ()) { +if (lmacid %2 ) +continue ; + } + lmac->qlm_mode =QLM_MODE_SGMII ; +debug ("BGX%d QLM%d LMAC%d mode: %s\n" , + bgx->bgx_id, lmac->qlm, lmacid, + lmac->is_1gx ?"1000Base-X" :"SGMII" ); + } +break ; +case BGX_MODE_XAUI : +if (bgx->bgx_id ==0 &&otx_is_altpkg ()) +continue ; + lmac->qlm_mode =QLM_MODE_XAUI ; +if (lmacid !=0 ) +continue ; +debug ("BGX%d QLM%d LMAC%d mode: XAUI\n" , + bgx->bgx_id, lmac->qlm, lmacid); +break ; +case BGX_MODE_RXAUI : +if (bgx->bgx_id ==0 &&otx_is_altpkg ()) +continue ; + lmac->qlm_mode =QLM_MODE_RXAUI ; +if (index == lmacid) { +debug ("BGX%d QLM%d LMAC%d mode: RXAUI\n" , + bgx->bgx_id, lmac->qlm, (index ?1 :0 )); + } +break ; +case BGX_MODE_XFI : +if (bgx->bgx_id ==0 &&otx_is_altpkg ()) { +if (lmacid %2 ) +continue ; + } +if ((lmacid <2 && (train_en & (1 << lmacid))) || + (train_en & (1 << (lmacid -2 )))) { + lmac->qlm_mode =QLM_MODE_10G_KR ; +debug ("BGX%d QLM%d LMAC%d mode: 10G_KR\n" , + bgx->bgx_id, lmac->qlm, lmacid); + }else { + lmac->qlm_mode =QLM_MODE_XFI ; +debug ("BGX%d QLM%d LMAC%d mode: XFI\n" , + bgx->bgx_id, lmac->qlm, lmacid); + } +break ; +case BGX_MODE_XLAUI : +if (bgx->bgx_id ==0 &&otx_is_altpkg ()) +continue ; +if (train_en) { + lmac->qlm_mode =QLM_MODE_40G_KR4 ; +if (lmacid !=0 ) +break ; +debug ("BGX%d QLM%d LMAC%d mode: 40G_KR4\n" , + bgx->bgx_id, lmac->qlm, lmacid); + }else { + lmac->qlm_mode =QLM_MODE_XLAUI ; +if (lmacid !=0 ) +break ; +debug ("BGX%d QLM%d LMAC%d mode: XLAUI\n" , + bgx->bgx_id, lmac->qlm, lmacid); + } +break ; +case BGX_MODE_QSGMII : +/* If QLM is configured as QSGMII, use lmac0 */ +if (otx_is_soc (CN83XX ) && lmacid ==2 && + bgx->bgx_id !=2 ) { +//lmac->qlm_mode = QLM_MODE_DISABLED; +continue ; + } + +if (lmacid ==0 || lmacid ==2 ) { + lmac->qlm_mode =QLM_MODE_QSGMII ; +debug ("BGX%d QLM%d LMAC%d mode: QSGMII\n" , + bgx->bgx_id, lmac->qlm, lmacid); + } +break ; +default : +break ; + } + } +} + +void bgx_set_board_info (int bgx_id,int *mdio_bus, +int *phy_addr,bool *autoneg_dis,bool *lmac_reg, +bool *lmac_enable) +{ +unsigned int i; + +for (i =0 ; i <MAX_LMAC_PER_BGX ; i++) { + bgx_board_info[bgx_id].phy_info[i].phy_addr = phy_addr[i]; + bgx_board_info[bgx_id].phy_info[i].mdio_bus = mdio_bus[i]; + bgx_board_info[bgx_id].phy_info[i].autoneg_dis = autoneg_dis[i]; + bgx_board_info[bgx_id].lmac_reg[i] = lmac_reg[i]; + bgx_board_info[bgx_id].lmac_enable[i] = lmac_enable[i]; +debug ("%s bgx_id %d lmac %d\n" , __func__, bgx_id, i); +debug ("phy addr %x mdio bus %d autoneg_dis %d lmac_reg %d\n" , + bgx_board_info[bgx_id].phy_info[i].phy_addr, + bgx_board_info[bgx_id].phy_info[i].mdio_bus, + bgx_board_info[bgx_id].phy_info[i].autoneg_dis, + bgx_board_info[bgx_id].lmac_reg[i]); +debug ("lmac_enable = %x\n" , + bgx_board_info[bgx_id].lmac_enable[i]); + } +} + +int octeontx_bgx_remove (struct udevice *dev) +{ +int lmacid; +u64 cfg; +int count =MAX_LMAC_PER_BGX ; +struct bgx *bgx =dev_get_priv (dev); + +if (!bgx->reg_base) +return 0 ; + +if (bgx->is_rgx) + count =1 ; + +for (lmacid =0 ; lmacid < count; lmacid++) { +struct lmac *lmac; + + lmac = &bgx->lmac[lmacid]; + cfg =bgx_reg_read (bgx, lmacid,BGX_CMRX_CFG ); + cfg &= ~(CMR_PKT_RX_EN |CMR_PKT_TX_EN ); +bgx_reg_write (bgx, lmacid,BGX_CMRX_CFG , cfg); + +/* Disable PCS for 1G interface */ +if (lmac->lmac_type ==BGX_MODE_SGMII || + lmac->lmac_type ==BGX_MODE_QSGMII ) { + cfg =bgx_reg_read (bgx, lmacid,BGX_GMP_PCS_MRX_CTL ); + cfg |=PCS_MRX_CTL_PWR_DN ; +bgx_reg_write (bgx, lmacid,BGX_GMP_PCS_MRX_CTL , cfg); + } + +debug ("%s disabling bgx%d lmacid%d\n" , __func__, bgx->bgx_id, + lmacid); +bgx_lmac_disable (bgx, lmacid); + } +return 0 ; +} + +int octeontx_bgx_probe (struct udevice *dev) +{ +struct bgx *bgx =dev_get_priv (dev); +u8 lmac =0 ; +int qlm[4 ] = {-1 ,-1 ,-1 ,-1 }; +int bgx_idx, node; +int inc =1 ; + + bgx->reg_base =dm_pci_map_bar (dev,PCI_BASE_ADDRESS_0 , +PCI_REGION_MEM ); +if (!bgx->reg_base) { +debug ("No PCI region found\n" ); +return 0 ; + } + +#ifdef OCTEONTX_XCV +/* Use FAKE BGX2 for RGX interface */ +if ((((uintptr_t )bgx->reg_base >>24 ) &0xf ) ==0x8 ) { + bgx->bgx_id =2 ; + bgx->is_rgx = true; +for (lmac =0 ; lmac <MAX_LMAC_PER_BGX ; lmac++) { +if (lmac ==0 ) { + bgx->lmac[lmac].lmacid =0 ; + bgx->lmac[lmac].qlm =0 ; + }else { + bgx->lmac[lmac].qlm =-1 ; + } + } +xcv_init_hw (); + goto skip_qlm_config; + } +#endif + + node =node_id (bgx->reg_base); + bgx_idx = ((uintptr_t )bgx->reg_base >>24 ) &3 ; + bgx->bgx_id = (node *MAX_BGX_PER_NODE ) + bgx_idx; +if (otx_is_soc (CN81XX )) + inc =2 ; +else if (otx_is_soc (CN83XX ) && (bgx_idx ==2 )) + inc =2 ; + +for (lmac =0 ; lmac <MAX_LMAC_PER_BGX ; lmac += inc) { +/* BGX3 (DLM4), has only 2 lanes */ +if (otx_is_soc (CN83XX ) && bgx_idx ==3 && lmac >=2 ) +continue ; + qlm[lmac +0 ] =get_qlm_for_bgx (node, bgx_idx, lmac); +/* Each DLM has 2 lanes, configure both lanes with +* same qlm configuration +*/ +if (inc ==2 ) + qlm[lmac +1 ] = qlm[lmac]; +debug ("qlm[%d] = %d\n" , lmac, qlm[lmac]); + } + +/* A BGX can take 1 or 2 DLMs, if both the DLMs are not configured +* as BGX, then return, nothing to initialize +*/ +if (otx_is_soc (CN81XX )) +if ((qlm[0 ] ==-1 ) && (qlm[2 ] ==-1 )) +return -ENODEV ; + +/* MAP configuration registers */ +for (lmac =0 ; lmac <MAX_LMAC_PER_BGX ; lmac++) { + bgx->lmac[lmac].qlm = qlm[lmac]; + bgx->lmac[lmac].lmacid = lmac; + } + +#ifdef OCTEONTX_XCV +skip_qlm_config: +#endif + bgx_vnic[bgx->bgx_id] = bgx; +bgx_get_qlm_mode (bgx); +debug ("bgx_vnic[%u]: %p\n" , bgx->bgx_id, bgx); + +bgx_init_hw (bgx); + +/* Init LMACs */ +for (lmac =0 ; lmac < bgx->lmac_count; lmac++) { +struct lmac *tlmac = &bgx->lmac[lmac]; + + tlmac->dev = dev; + tlmac->init_pend =1 ; + tlmac->bgx = bgx; + } + +return 0 ; +} + +U_BOOT_DRIVER (octeontx_bgx) = { + .name ="octeontx_bgx" , + .id =UCLASS_MISC , + .probe = octeontx_bgx_probe, + .remove = octeontx_bgx_remove, + .priv_auto_alloc_size =sizeof (struct bgx ), + .flags =DM_FLAG_OS_PREPARE , +}; + +static struct pci_device_id octeontx_bgx_supported[] = { + {PCI_VDEVICE (CAVIUM ,PCI_DEVICE_ID_CAVIUM_BGX ) }, + {PCI_VDEVICE (CAVIUM ,PCI_DEVICE_ID_CAVIUM_RGX ) }, + {} +}; + +U_BOOT_PCI_DEVICE (octeontx_bgx, octeontx_bgx_supported);drivers/net/octeontx/bgx.h new file +259
-0@@ -0,0 +1,259 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2018 Marvell International Ltd. +*/ + +#ifndef BGX_H +#define BGX_H + +#include <asm/arch/board.h> + +/* PCI device IDs */ +#define PCI_DEVICE_ID_OCTEONTX_BGX 0xA026 +#define PCI_DEVICE_ID_OCTEONTX_RGX 0xA054 + +#define MAX_LMAC_PER_BGX 4 +#define MAX_BGX_CHANS_PER_LMAC 16 +#define MAX_DMAC_PER_LMAC 8 +#define MAX_FRAME_SIZE 9216 + +#define MAX_DMAC_PER_LMAC_TNS_BYPASS_MODE 2 + +#define MAX_LMAC (MAX_BGX_PER_NODE * MAX_LMAC_PER_BGX) + +#define NODE_ID_MASK 0x300000000000 +#define NODE_ID (x) (((x) & NODE_ID_MASK) >> 44) + +/* Registers */ +#define GSERX_CFG (x) (0x87E090000080ull + (x) * 0x1000000ull) +#define GSERX_SCRATCH (x) (0x87E090000020ull + (x) * 0x1000000ull) +#define GSERX_PHY_CTL (x) (0x87E090000000ull + (x) * 0x1000000ull) +#define GSERX_CFG_BGX BIT(2) +#define GSER_RX_EIE_DETSTS (x) (0x87E090000150ull + (x) * 0x1000000ull) +#define GSER_CDRLOCK (8) +#define GSER_BR_RXX_CTL (x, y) (0x87E090000400ull + (x) * 0x1000000ull + \ + (y) * 0x80) +#define GSER_BR_RXX_CTL_RXT_SWM BIT(2) +#define GSER_BR_RXX_EER (x, y) (0x87E090000418ull + (x) * 0x1000000ull + \ + (y) * 0x80) +#define GSER_BR_RXX_EER_RXT_ESV BIT(14) +#define GSER_BR_RXX_EER_RXT_EER BIT(15) +#define EER_RXT_ESV (14) + +#define BGX_CMRX_CFG 0x00 +#define CMR_PKT_TX_EN BIT_ULL(13) +#define CMR_PKT_RX_EN BIT_ULL(14) +#define CMR_EN BIT_ULL(15) +#define BGX_CMR_GLOBAL_CFG 0x08 +#define CMR_GLOBAL_CFG_FCS_STRIP BIT_ULL(6) +#define BGX_CMRX_RX_ID_MAP 0x60 +#define BGX_CMRX_RX_STAT0 0x70 +#define BGX_CMRX_RX_STAT1 0x78 +#define BGX_CMRX_RX_STAT2 0x80 +#define BGX_CMRX_RX_STAT3 0x88 +#define BGX_CMRX_RX_STAT4 0x90 +#define BGX_CMRX_RX_STAT5 0x98 +#define BGX_CMRX_RX_STAT6 0xA0 +#define BGX_CMRX_RX_STAT7 0xA8 +#define BGX_CMRX_RX_STAT8 0xB0 +#define BGX_CMRX_RX_STAT9 0xB8 +#define BGX_CMRX_RX_STAT10 0xC0 +#define BGX_CMRX_RX_BP_DROP 0xC8 +#define BGX_CMRX_RX_DMAC_CTL 0x0E8 +#define BGX_CMR_RX_DMACX_CAM 0x200 +#define RX_DMACX_CAM_EN BIT_ULL(48) +#define RX_DMACX_CAM_LMACID (x) ((x) << 49) +#define RX_DMAC_COUNT 32 +#define BGX_CMR_RX_STREERING 0x300 +#define RX_TRAFFIC_STEER_RULE_COUNT 8 +#define BGX_CMR_CHAN_MSK_AND 0x450 +#define BGX_CMR_BIST_STATUS 0x460 +#define BGX_CMR_RX_LMACS 0x468 +#define BGX_CMRX_TX_STAT0 0x600 +#define BGX_CMRX_TX_STAT1 0x608 +#define BGX_CMRX_TX_STAT2 0x610 +#define BGX_CMRX_TX_STAT3 0x618 +#define BGX_CMRX_TX_STAT4 0x620 +#define BGX_CMRX_TX_STAT5 0x628 +#define BGX_CMRX_TX_STAT6 0x630 +#define BGX_CMRX_TX_STAT7 0x638 +#define BGX_CMRX_TX_STAT8 0x640 +#define BGX_CMRX_TX_STAT9 0x648 +#define BGX_CMRX_TX_STAT10 0x650 +#define BGX_CMRX_TX_STAT11 0x658 +#define BGX_CMRX_TX_STAT12 0x660 +#define BGX_CMRX_TX_STAT13 0x668 +#define BGX_CMRX_TX_STAT14 0x670 +#define BGX_CMRX_TX_STAT15 0x678 +#define BGX_CMRX_TX_STAT16 0x680 +#define BGX_CMRX_TX_STAT17 0x688 +#define BGX_CMR_TX_LMACS 0x1000 + +#define BGX_SPUX_CONTROL1 0x10000 +#define SPU_CTL_LOW_POWER BIT_ULL(11) +#define SPU_CTL_LOOPBACK BIT_ULL(14) +#define SPU_CTL_RESET BIT_ULL(15) +#define BGX_SPUX_STATUS1 0x10008 +#define SPU_STATUS1_RCV_LNK BIT_ULL(2) +#define BGX_SPUX_STATUS2 0x10020 +#define SPU_STATUS2_RCVFLT BIT_ULL(10) +#define BGX_SPUX_BX_STATUS 0x10028 +#define SPU_BX_STATUS_RX_ALIGN BIT_ULL(12) +#define BGX_SPUX_BR_STATUS1 0x10030 +#define SPU_BR_STATUS_BLK_LOCK BIT_ULL(0) +#define SPU_BR_STATUS_RCV_LNK BIT_ULL(12) +#define BGX_SPUX_BR_PMD_CRTL 0x10068 +#define SPU_PMD_CRTL_TRAIN_EN BIT_ULL(1) +#define BGX_SPUX_BR_PMD_LP_CUP 0x10078 +#define BGX_SPUX_BR_PMD_LD_CUP 0x10088 +#define BGX_SPUX_BR_PMD_LD_REP 0x10090 +#define BGX_SPUX_FEC_CONTROL 0x100A0 +#define SPU_FEC_CTL_FEC_EN BIT_ULL(0) +#define SPU_FEC_CTL_ERR_EN BIT_ULL(1) +#define BGX_SPUX_AN_CONTROL 0x100C8 +#define SPU_AN_CTL_AN_EN BIT_ULL(12) +#define SPU_AN_CTL_XNP_EN BIT_ULL(13) +#define SPU_AN_CTL_AN_RESTART BIT_ULL(15) +#define BGX_SPUX_AN_STATUS 0x100D0 +#define SPU_AN_STS_AN_COMPLETE BIT_ULL(5) +#define BGX_SPUX_AN_ADV 0x100D8 +#define BGX_SPUX_MISC_CONTROL 0x10218 +#define SPU_MISC_CTL_INTLV_RDISP BIT_ULL(10) +#define SPU_MISC_CTL_RX_DIS BIT_ULL(12) +#define BGX_SPUX_INT 0x10220/* +(0..3) << 20 */ +#define BGX_SPUX_INT_W1S 0x10228 +#define BGX_SPUX_INT_ENA_W1C 0x10230 +#define BGX_SPUX_INT_ENA_W1S 0x10238 +#define BGX_SPU_DBG_CONTROL 0x10300 +#define SPU_DBG_CTL_AN_ARB_LINK_CHK_EN BIT_ULL(18) +#define SPU_DBG_CTL_AN_NONCE_MCT_DIS BIT_ULL(29) + +#define BGX_SMUX_RX_INT 0x20000 +#define BGX_SMUX_RX_JABBER 0x20030 +#define BGX_SMUX_RX_CTL 0x20048 +#define SMU_RX_CTL_STATUS (3ull << 0) +#define BGX_SMUX_TX_APPEND 0x20100 +#define SMU_TX_APPEND_FCS_D BIT_ULL(2) +#define BGX_SMUX_TX_MIN_PKT 0x20118 +#define BGX_SMUX_TX_INT 0x20140 +#define BGX_SMUX_TX_CTL 0x20178 +#define SMU_TX_CTL_DIC_EN BIT_ULL(0) +#define SMU_TX_CTL_UNI_EN BIT_ULL(1) +#define SMU_TX_CTL_LNK_STATUS (3ull << 4) +#define BGX_SMUX_TX_THRESH 0x20180 +#define BGX_SMUX_CTL 0x20200 +#define SMU_CTL_RX_IDLE BIT_ULL(0) +#define SMU_CTL_TX_IDLE BIT_ULL(1) + +#define BGX_GMP_PCS_MRX_CTL 0x30000 +#define PCS_MRX_CTL_RST_AN BIT_ULL(9) +#define PCS_MRX_CTL_PWR_DN BIT_ULL(11) +#define PCS_MRX_CTL_AN_EN BIT_ULL(12) +#define PCS_MRX_CTL_LOOPBACK1 BIT_ULL(14) +#define PCS_MRX_CTL_RESET BIT_ULL(15) +#define BGX_GMP_PCS_MRX_STATUS 0x30008 +#define PCS_MRX_STATUS_AN_CPT BIT_ULL(5) +#define BGX_GMP_PCS_ANX_AN_RESULTS 0x30020 +#define BGX_GMP_PCS_SGM_AN_ADV 0x30068 +#define BGX_GMP_PCS_MISCX_CTL 0x30078 +#define PCS_MISCX_CTL_DISP_EN BIT_ULL(13) +#define PCS_MISC_CTL_GMX_ENO BIT_ULL(11) +#define PCS_MISC_CTL_SAMP_PT_MASK 0x7Full +#define PCS_MISC_CTL_MODE BIT_ULL(8) +#define BGX_GMP_GMI_PRTX_CFG 0x38020 +#define GMI_PORT_CFG_SPEED BIT_ULL(1) +#define GMI_PORT_CFG_DUPLEX BIT_ULL(2) +#define GMI_PORT_CFG_SLOT_TIME BIT_ULL(3) +#define GMI_PORT_CFG_SPEED_MSB BIT_ULL(8) +#define BGX_GMP_GMI_RXX_JABBER 0x38038 +#define BGX_GMP_GMI_TXX_THRESH 0x38210 +#define BGX_GMP_GMI_TXX_APPEND 0x38218 +#define BGX_GMP_GMI_TXX_SLOT 0x38220 +#define BGX_GMP_GMI_TXX_BURST 0x38228 +#define BGX_GMP_GMI_TXX_MIN_PKT 0x38240 +#define BGX_GMP_GMI_TXX_SGMII_CTL 0x38300 + +#define BGX_MSIX_VEC_0_29_ADDR 0x400000/* +(0..29) << 4 */ +#define BGX_MSIX_VEC_0_29_CTL 0x400008 +#define BGX_MSIX_PBA_0 0x4F0000 + +/* MSI-X interrupts */ +#define BGX_MSIX_VECTORS 30 +#define BGX_LMAC_VEC_OFFSET 7 +#define BGX_MSIX_VEC_SHIFT 4 + +#define CMRX_INT 0 +#define SPUX_INT 1 +#define SMUX_RX_INT 2 +#define SMUX_TX_INT 3 +#define GMPX_PCS_INT 4 +#define GMPX_GMI_RX_INT 5 +#define GMPX_GMI_TX_INT 6 +#define CMR_MEM_INT 28 +#define SPU_MEM_INT 29 + +#define LMAC_INTR_LINK_UP BIT(0) +#define LMAC_INTR_LINK_DOWN BIT(1) + +/* RX_DMAC_CTL configuration*/ +enum MCAST_MODE { +MCAST_MODE_REJECT , +MCAST_MODE_ACCEPT , +MCAST_MODE_CAM_FILTER , +RSVD +}; + +#define BCAST_ACCEPT 1 +#define CAM_ACCEPT 1 + +int octeontx_bgx_initialize (unsigned int bgx_idx,unsigned int node); +void bgx_add_dmac_addr (u64 dmac,int node,int bgx_idx,int lmac); +void bgx_get_count (int node,int *bgx_count); +int bgx_get_lmac_count (int node,int bgx); +void bgx_print_stats (int bgx_idx,int lmac); +void xcv_init_hw (void ); +void xcv_setup_link (bool link_up,int link_speed); + +#undef LINK_INTR_ENABLE + +enum qlm_mode { +QLM_MODE_SGMII ,/* SGMII, each lane independent */ +QLM_MODE_XAUI ,/* 1 XAUI or DXAUI, 4 lanes */ +QLM_MODE_RXAUI ,/* 2 RXAUI, 2 lanes each */ +QLM_MODE_XFI ,/* 4 XFI, 1 lane each */ +QLM_MODE_XLAUI ,/* 1 XLAUI, 4 lanes each */ +QLM_MODE_10G_KR ,/* 4 10GBASE-KR, 1 lane each */ +QLM_MODE_40G_KR4 ,/* 1 40GBASE-KR4, 4 lanes each */ +QLM_MODE_QSGMII ,/* 4 QSGMII, each lane independent */ +QLM_MODE_RGMII ,/* 1 RGX */ +}; + +struct phy_info { +int mdio_bus; +int phy_addr; +bool autoneg_dis; +}; + +struct bgx_board_info { +struct phy_info phy_info[MAX_LMAC_PER_BGX ]; +bool lmac_reg[MAX_LMAC_PER_BGX ]; +bool lmac_enable[MAX_LMAC_PER_BGX ]; +}; + +enum LMAC_TYPE { +BGX_MODE_SGMII =0 ,/* 1 lane, 1.250 Gbaud */ +BGX_MODE_XAUI =1 ,/* 4 lanes, 3.125 Gbaud */ +BGX_MODE_DXAUI =1 ,/* 4 lanes, 6.250 Gbaud */ +BGX_MODE_RXAUI =2 ,/* 2 lanes, 6.250 Gbaud */ +BGX_MODE_XFI =3 ,/* 1 lane, 10.3125 Gbaud */ +BGX_MODE_XLAUI =4 ,/* 4 lanes, 10.3125 Gbaud */ +BGX_MODE_10G_KR =3 ,/* 1 lane, 10.3125 Gbaud */ +BGX_MODE_40G_KR =4 ,/* 4 lanes, 10.3125 Gbaud */ +BGX_MODE_RGMII =5 , +BGX_MODE_QSGMII =6 , +BGX_MODE_INVALID =7 , +}; + +int rxaui_phy_xs_init (struct mii_dev *bus,int phy_addr); + +#endif /* BGX_H */ drivers/net/octeontx/nic.h new file +508
-0@@ -0,0 +1,508 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (C) 2018 Marvell International Ltd. +*/ + +#ifndef NIC_H +#define NIC_H + +#include <linux/netdevice.h> +#include "bgx.h" + +#define PCI_DEVICE_ID_CAVIUM_NICVF_1 0x0011 + +/* Subsystem device IDs */ +#define PCI_SUBSYS_DEVID_88XX_NIC_PF 0xA11E +#define PCI_SUBSYS_DEVID_81XX_NIC_PF 0xA21E +#define PCI_SUBSYS_DEVID_83XX_NIC_PF 0xA31E + +#define PCI_SUBSYS_DEVID_88XX_PASS1_NIC_VF 0xA11E +#define PCI_SUBSYS_DEVID_88XX_NIC_VF 0xA134 +#define PCI_SUBSYS_DEVID_81XX_NIC_VF 0xA234 +#define PCI_SUBSYS_DEVID_83XX_NIC_VF 0xA334 + +#define NIC_INTF_COUNT 2/* Interfaces btw VNIC and TNS/BGX */ +#define NIC_CHANS_PER_INF 128 +#define NIC_MAX_CHANS (NIC_INTF_COUNT * NIC_CHANS_PER_INF) + +/* PCI BAR nos */ +#define PCI_CFG_REG_BAR_NUM 0 +#define PCI_MSIX_REG_BAR_NUM 4 + +/* NIC SRIOV VF count */ +#define MAX_NUM_VFS_SUPPORTED 128 +#define DEFAULT_NUM_VF_ENABLED 8 + +#define NIC_TNS_BYPASS_MODE 0 +#define NIC_TNS_MODE 1 + +/* NIC priv flags */ +#define NIC_SRIOV_ENABLED BIT(0) +#define NIC_TNS_ENABLED BIT(1) + +/* VNIC HW optimiation features */ +#define VNIC_RX_CSUM_OFFLOAD_SUPPORT +#undef VNIC_TX_CSUM_OFFLOAD_SUPPORT +#undef VNIC_SG_SUPPORT +#undef VNIC_TSO_SUPPORT +#undef VNIC_LRO_SUPPORT +#undef VNIC_RSS_SUPPORT + +/* TSO not supported in Thunder pass1 */ +#ifdef VNIC_TSO_SUPPORT +#define VNIC_SW_TSO_SUPPORT +#undef VNIC_HW_TSO_SUPPORT +#endif + +/* ETHTOOL enable or disable, undef this to disable */ +#define NICVF_ETHTOOL_ENABLE + +/* Min/Max packet size */ +#define NIC_HW_MIN_FRS 64 +#define NIC_HW_MAX_FRS 9200/* 9216 max packet including FCS */ + +/* Max pkinds */ +#define NIC_MAX_PKIND 16 + +/* Max when CPI_ALG is IP diffserv */ +#define NIC_MAX_CPI_PER_LMAC 64 + +/* NIC VF Interrupts */ +#define NICVF_INTR_CQ 0 +#define NICVF_INTR_SQ 1 +#define NICVF_INTR_RBDR 2 +#define NICVF_INTR_PKT_DROP 3 +#define NICVF_INTR_TCP_TIMER 4 +#define NICVF_INTR_MBOX 5 +#define NICVF_INTR_QS_ERR 6 + +#define NICVF_INTR_CQ_SHIFT 0 +#define NICVF_INTR_SQ_SHIFT 8 +#define NICVF_INTR_RBDR_SHIFT 16 +#define NICVF_INTR_PKT_DROP_SHIFT 20 +#define NICVF_INTR_TCP_TIMER_SHIFT 21 +#define NICVF_INTR_MBOX_SHIFT 22 +#define NICVF_INTR_QS_ERR_SHIFT 23 + +#define NICVF_INTR_CQ_MASK (0xFF << NICVF_INTR_CQ_SHIFT) +#define NICVF_INTR_SQ_MASK (0xFF << NICVF_INTR_SQ_SHIFT) +#define NICVF_INTR_RBDR_MASK (0x03 << NICVF_INTR_RBDR_SHIFT) +#define NICVF_INTR_PKT_DROP_MASK BIT(NICVF_INTR_PKT_DROP_SHIFT) +#define NICVF_INTR_TCP_TIMER_MASK BIT(NICVF_INTR_TCP_TIMER_SHIFT) +#define NICVF_INTR_MBOX_MASK BIT(NICVF_INTR_MBOX_SHIFT) +#define NICVF_INTR_QS_ERR_MASK BIT(NICVF_INTR_QS_ERR_SHIFT) + +/* MSI-X interrupts */ +#define NIC_PF_MSIX_VECTORS 10 +#define NIC_VF_MSIX_VECTORS 20 + +#define NIC_PF_INTR_ID_ECC0_SBE 0 +#define NIC_PF_INTR_ID_ECC0_DBE 1 +#define NIC_PF_INTR_ID_ECC1_SBE 2 +#define NIC_PF_INTR_ID_ECC1_DBE 3 +#define NIC_PF_INTR_ID_ECC2_SBE 4 +#define NIC_PF_INTR_ID_ECC2_DBE 5 +#define NIC_PF_INTR_ID_ECC3_SBE 6 +#define NIC_PF_INTR_ID_ECC3_DBE 7 +#define NIC_PF_INTR_ID_MBOX0 8 +#define NIC_PF_INTR_ID_MBOX1 9 + +/* Global timer for CQ timer thresh interrupts +* Calculated for SCLK of 700Mhz +* value written should be a 1/16thof what is expected +* +* 1 tick per ms +*/ +#define NICPF_CLK_PER_INT_TICK 43750 + +struct nicvf_cq_poll { +u8 cq_idx;/* Completion queue index */ +}; + +#define NIC_MAX_RSS_HASH_BITS 8 +#define NIC_MAX_RSS_IDR_TBL_SIZE BIT(NIC_MAX_RSS_HASH_BITS) +#define RSS_HASH_KEY_SIZE 5/* 320 bit key */ + +#ifdef VNIC_RSS_SUPPORT +struct nicvf_rss_info { +bool enable; +#define RSS_L2_EXTENDED_HASH_ENA BIT(0) +#define RSS_IP_HASH_ENA BIT(1) +#define RSS_TCP_HASH_ENA BIT(2) +#define RSS_TCP_SYN_DIS BIT(3) +#define RSS_UDP_HASH_ENA BIT(4) +#define RSS_L4_EXTENDED_HASH_ENA BIT(5) +#define RSS_ROCE_ENA BIT(6) +#define RSS_L3_BI_DIRECTION_ENA BIT(7) +#define RSS_L4_BI_DIRECTION_ENA BIT(8) +u64 cfg; +u8 hash_bits; +u16 rss_size; +u8 ind_tbl[NIC_MAX_RSS_IDR_TBL_SIZE ]; +u64 key[RSS_HASH_KEY_SIZE ]; +}; +#endif + +enum rx_stats_reg_offset { +RX_OCTS =0x0 , +RX_UCAST =0x1 , +RX_BCAST =0x2 , +RX_MCAST =0x3 , +RX_RED =0x4 , +RX_RED_OCTS =0x5 , +RX_ORUN =0x6 , +RX_ORUN_OCTS =0x7 , +RX_FCS =0x8 , +RX_L2ERR =0x9 , +RX_DRP_BCAST =0xa , +RX_DRP_MCAST =0xb , +RX_DRP_L3BCAST =0xc , +RX_DRP_L3MCAST =0xd , +RX_STATS_ENUM_LAST , +}; + +enum tx_stats_reg_offset { +TX_OCTS =0x0 , +TX_UCAST =0x1 , +TX_BCAST =0x2 , +TX_MCAST =0x3 , +TX_DROP =0x4 , +TX_STATS_ENUM_LAST , +}; + +struct nicvf_hw_stats { +u64 rx_bytes_ok; +u64 rx_ucast_frames_ok; +u64 rx_bcast_frames_ok; +u64 rx_mcast_frames_ok; +u64 rx_fcs_errors; +u64 rx_l2_errors; +u64 rx_drop_red; +u64 rx_drop_red_bytes; +u64 rx_drop_overrun; +u64 rx_drop_overrun_bytes; +u64 rx_drop_bcast; +u64 rx_drop_mcast; +u64 rx_drop_l3_bcast; +u64 rx_drop_l3_mcast; +u64 tx_bytes_ok; +u64 tx_ucast_frames_ok; +u64 tx_bcast_frames_ok; +u64 tx_mcast_frames_ok; +u64 tx_drops; +}; + +struct nicvf_drv_stats { +/* Rx */ +u64 rx_frames_ok; +u64 rx_frames_64; +u64 rx_frames_127; +u64 rx_frames_255; +u64 rx_frames_511; +u64 rx_frames_1023; +u64 rx_frames_1518; +u64 rx_frames_jumbo; +u64 rx_drops; +/* Tx */ +u64 tx_frames_ok; +u64 tx_drops; +u64 tx_busy; +u64 tx_tso; +}; + +struct hw_info { +u8 bgx_cnt; +u8 chans_per_lmac; +u8 chans_per_bgx;/* Rx/Tx chans */ +u8 chans_per_rgx; +u8 chans_per_lbk; +u16 cpi_cnt; +u16 rssi_cnt; +u16 rss_ind_tbl_size; +u16 tl4_cnt; +u16 tl3_cnt; +u8 tl2_cnt; +u8 tl1_cnt; +bool tl1_per_bgx;/* TL1 per BGX or per LMAC */ +u8 model_id; +}; + +struct nicvf { +struct udevice *dev; +u8 vf_id; +bool sqs_mode:1 ; +bool loopback_supported:1 ; +u8 tns_mode; +u8 node; +u16 mtu; +struct queue_set *qs; +#define MAX_SQS_PER_VF_SINGLE_NODE 5 +#define MAX_SQS_PER_VF 11 +u8 num_qs; +void *addnl_qs; +u16 vf_mtu; +void __iomem *reg_base; +#define MAX_QUEUES_PER_QSET 8 +struct nicvf_cq_poll *napi[8 ]; + +u8 cpi_alg; + +struct nicvf_hw_stats stats; +struct nicvf_drv_stats drv_stats; + +struct nicpf *nicpf; + +/* VF <-> PF mailbox communication */ +bool pf_acked; +bool pf_nacked; +bool set_mac_pending; + +bool link_up; +u8 duplex; +u32 speed; +u8 rev_id; +u8 rx_queues; +u8 tx_queues; + +bool open; +bool rb_alloc_fail; +void *rcv_buf; +bool hw_tso; +}; + +static inline int node_id (void *addr) +{ +return ((uintptr_t )addr >>44 ) &0x3 ; +} + +struct nicpf { +struct udevice *udev; +struct hw_info *hw; +u8 node; +unsigned int flags; +u16 total_vf_cnt;/* Total num of VF supported */ +u16 num_vf_en;/* No of VF enabled */ +void __iomem *reg_base;/* Register start address */ +u16 rss_ind_tbl_size; +u8 num_sqs_en;/* Secondary qsets enabled */ +u64 nicvf[MAX_NUM_VFS_SUPPORTED ]; +u8 vf_sqs[MAX_NUM_VFS_SUPPORTED ][MAX_SQS_PER_VF ]; +u8 pqs_vf[MAX_NUM_VFS_SUPPORTED ]; +bool sqs_used[MAX_NUM_VFS_SUPPORTED ]; +struct pkind_cfg pkind; +u8 bgx_cnt; +u8 rev_id; +#define NIC_SET_VF_LMAC_MAP (bgx, lmac) ((((bgx) & 0xF) << 4) | ((lmac) & 0xF)) +#define NIC_GET_BGX_FROM_VF_LMAC_MAP (map) (((map) >> 4) & 0xF) +#define NIC_GET_LMAC_FROM_VF_LMAC_MAP (map) ((map) & 0xF) +u8 vf_lmac_map[MAX_LMAC ]; +u16 cpi_base[MAX_NUM_VFS_SUPPORTED ]; +u64 mac[MAX_NUM_VFS_SUPPORTED ]; +bool mbx_lock[MAX_NUM_VFS_SUPPORTED ]; +u8 link[MAX_LMAC ]; +u8 duplex[MAX_LMAC ]; +u32 speed[MAX_LMAC ]; +bool vf_enabled[MAX_NUM_VFS_SUPPORTED ]; +u16 rssi_base[MAX_NUM_VFS_SUPPORTED ]; +u8 lmac_cnt; +}; + +/* PF <--> VF Mailbox communication +* Eight 64bit registers are shared between PF and VF. +* Separate set for each VF. +* Writing '1' into last register mbx7 means end of message. +*/ + +/* PF <--> VF mailbox communication */ +#define NIC_PF_VF_MAILBOX_SIZE 2 +#define NIC_PF_VF_MBX_TIMEOUT 2000/* ms */ + +/* Mailbox message types */ +#define NIC_MBOX_MSG_READY 0x01/* Is PF ready to rcv msgs */ +#define NIC_MBOX_MSG_ACK 0x02/* ACK the message received */ +#define NIC_MBOX_MSG_NACK 0x03/* NACK the message received */ +#define NIC_MBOX_MSG_QS_CFG 0x04/* Configure Qset */ +#define NIC_MBOX_MSG_RQ_CFG 0x05/* Configure receive queue */ +#define NIC_MBOX_MSG_SQ_CFG 0x06/* Configure Send queue */ +#define NIC_MBOX_MSG_RQ_DROP_CFG 0x07/* Configure receive queue */ +#define NIC_MBOX_MSG_SET_MAC 0x08/* Add MAC ID to DMAC filter */ +#define NIC_MBOX_MSG_SET_MAX_FRS 0x09/* Set max frame size */ +#define NIC_MBOX_MSG_CPI_CFG 0x0A/* Config CPI, RSSI */ +#define NIC_MBOX_MSG_RSS_SIZE 0x0B/* Get RSS indir_tbl size */ +#define NIC_MBOX_MSG_RSS_CFG 0x0C/* Config RSS table */ +#define NIC_MBOX_MSG_RSS_CFG_CONT 0x0D/* RSS config continuation */ +#define NIC_MBOX_MSG_RQ_BP_CFG 0x0E/* RQ backpressure config */ +#define NIC_MBOX_MSG_RQ_SW_SYNC 0x0F/* Flush inflight pkts to RQ */ +#define NIC_MBOX_MSG_BGX_STATS 0x10/* Get stats from BGX */ +#define NIC_MBOX_MSG_BGX_LINK_CHANGE 0x11/* BGX:LMAC link status */ +#define NIC_MBOX_MSG_ALLOC_SQS 0x12/* Allocate secondary Qset */ +#define NIC_MBOX_MSG_NICVF_PTR 0x13/* Send nicvf ptr to PF */ +#define NIC_MBOX_MSG_PNICVF_PTR 0x14/* Get primary qset nicvf ptr */ +#define NIC_MBOX_MSG_SNICVF_PTR 0x15/* Send sqet nicvf ptr to PVF */ +#define NIC_MBOX_MSG_LOOPBACK 0x16/* Set interface in loopback */ +#define NIC_MBOX_MSG_CFG_DONE 0xF0/* VF configuration done */ +#define NIC_MBOX_MSG_SHUTDOWN 0xF1/* VF is being shutdown */ + +struct nic_cfg_msg { +u8 msg; +u8 vf_id; +u8 node_id; +bool tns_mode:1 ; +bool sqs_mode:1 ; +bool loopback_supported:1 ; +u8 mac_addr[6 ]; +}; + +/* Qset configuration */ +struct qs_cfg_msg { +u8 msg; +u8 num; +u8 sqs_count; +u64 cfg; +}; + +/* Receive queue configuration */ +struct rq_cfg_msg { +u8 msg; +u8 qs_num; +u8 rq_num; +u64 cfg; +}; + +/* Send queue configuration */ +struct sq_cfg_msg { +u8 msg; +u8 qs_num; +u8 sq_num; +bool sqs_mode; +u64 cfg; +}; + +/* Set VF's MAC address */ +struct set_mac_msg { +u8 msg; +u8 vf_id; +u8 mac_addr[6 ]; +}; + +/* Set Maximum frame size */ +struct set_frs_msg { +u8 msg; +u8 vf_id; +u16 max_frs; +}; + +/* Set CPI algorithm type */ +struct cpi_cfg_msg { +u8 msg; +u8 vf_id; +u8 rq_cnt; +u8 cpi_alg; +}; + +/* Get RSS table size */ +struct rss_sz_msg { +u8 msg; +u8 vf_id; +u16 ind_tbl_size; +}; + +/* Set RSS configuration */ +struct rss_cfg_msg { +u8 msg; +u8 vf_id; +u8 hash_bits; +u8 tbl_len; +u8 tbl_offset; +#define RSS_IND_TBL_LEN_PER_MBX_MSG 8 +u8 ind_tbl[RSS_IND_TBL_LEN_PER_MBX_MSG ]; +}; + +struct bgx_stats_msg { +u8 msg; +u8 vf_id; +u8 rx; +u8 idx; +u64 stats; +}; + +/* Physical interface link status */ +struct bgx_link_status { +u8 msg; +u8 link_up; +u8 duplex; +u32 speed; +}; + +#ifdef VNIC_MULTI_QSET_SUPPORT +/* Get Extra Qset IDs */ +struct sqs_alloc { +u8 msg; +u8 vf_id; +u8 qs_count; +}; + +struct nicvf_ptr { +u8 msg; +u8 vf_id; +bool sqs_mode; +u8 sqs_id; +u64 nicvf; +}; +#endif + +/* Set interface in loopback mode */ +struct set_loopback { +u8 msg; +u8 vf_id; +bool enable; +}; + +/* 128 bit shared memory between PF and each VF */ +union nic_mbx { +struct {u8 msg; } msg; +struct nic_cfg_msg nic_cfg; +struct qs_cfg_msg qs; +struct rq_cfg_msg rq; +struct sq_cfg_msg sq; +struct set_mac_msg mac; +struct set_frs_msg frs; +struct cpi_cfg_msg cpi_cfg; +struct rss_sz_msg rss_size; +struct rss_cfg_msg rss_cfg; +struct bgx_stats_msg bgx_stats; +struct bgx_link_status link_status; +#ifdef VNIC_MULTI_QSET_SUPPORT +struct sqs_alloc sqs_alloc; +struct nicvf_ptr nicvf; +#endif +struct set_loopback lbk; +}; + +int nicvf_set_real_num_queues (struct udevice *dev, +int tx_queues,int rx_queues); +int nicvf_open (struct udevice *dev); +void nicvf_stop (struct udevice *dev); +int nicvf_send_msg_to_pf (struct nicvf *vf,union nic_mbx *mbx); +void nicvf_update_stats (struct nicvf *nic); + +void nic_handle_mbx_intr (struct nicpf *nic,int vf); + +int bgx_poll_for_link (int node,int bgx_idx,int lmacid); +const u8 *bgx_get_lmac_mac (int node,int bgx_idx,int lmacid); +void bgx_set_lmac_mac (int node,int bgx_idx,int lmacid,const u8 *mac); +void bgx_lmac_rx_tx_enable (int node,int bgx_idx,int lmacid,bool enable); +void bgx_lmac_internal_loopback (int node,int bgx_idx, +int lmac_idx,bool enable); + +static inline bool pass1_silicon (unsigned int revision,int model_id) +{ +return ((revision <8 ) && (model_id ==0x88 )); +} + +static inline bool pass2_silicon (unsigned int revision,int model_id) +{ +return ((revision >=8 ) && (model_id ==0x88 )); +} + +#endif /* NIC_H */ drivers/net/octeontx/nic_main.c new file +778
-0@@ -0,0 +1,778 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 Marvell International Ltd. +*/ + +#include <config.h> +#include <net.h> +#include <netdev.h> +#include <malloc.h> +#include <miiphy.h> +#include <dm.h> +#include <misc.h> +#include <pci.h> +#include <pci_ids.h> +#include <asm/io.h> +#include <linux/delay.h> + +#include "nic_reg.h" +#include "nic.h" +#include "q_struct.h" + +unsigned long rounddown_pow_of_two (unsigned long n) +{ + n |= n >>1 ; + n |= n >>2 ; + n |= n >>4 ; + n |= n >>8 ; + n |= n >>16 ; + n |= n >>32 ; + +return (n +1 ); +} + +static void nic_config_cpi (struct nicpf *nic,struct cpi_cfg_msg *cfg); +static void nic_tx_channel_cfg (struct nicpf *nic,u8 vnic, +struct sq_cfg_msg *sq); +static int nic_update_hw_frs (struct nicpf *nic,int new_frs,int vf); +static int nic_rcv_queue_sw_sync (struct nicpf *nic); + +/* Register read/write APIs */ +static void nic_reg_write (struct nicpf *nic,u64 offset,u64 val) +{ +writeq (val, nic->reg_base + offset); +} + +static u64 nic_reg_read (struct nicpf *nic,u64 offset) +{ +return readq (nic->reg_base + offset); +} + +static u64 nic_get_mbx_addr (int vf) +{ +return NIC_PF_VF_0_127_MAILBOX_0_1 + (vf <<NIC_VF_NUM_SHIFT ); +} + +static void nic_send_msg_to_vf (struct nicpf *nic,int vf,union nic_mbx *mbx) +{ +void __iomem *mbx_addr = (void *)(nic->reg_base +nic_get_mbx_addr (vf)); +u64 *msg = (u64 *)mbx; + +/* In first revision HW, mbox interrupt is triggerred +* when PF writes to MBOX(1), in next revisions when +* PF writes to MBOX(0) +*/ +if (pass1_silicon (nic->rev_id, nic->hw->model_id)) { +/* see the comment for nic_reg_write()/nic_reg_read() +* functions above +*/ +writeq (msg[0 ], mbx_addr); +writeq (msg[1 ], mbx_addr +8 ); + }else { +writeq (msg[1 ], mbx_addr +8 ); +writeq (msg[0 ], mbx_addr); + } +} + +static void nic_mbx_send_ready (struct nicpf *nic,int vf) +{ +union nic_mbx mbx = {}; +int bgx_idx, lmac, timeout =5 , link =-1 ; +const u8 *mac; + + mbx.nic_cfg.msg =NIC_MBOX_MSG_READY ; + mbx.nic_cfg.vf_id = vf; + +if (nic->flags &NIC_TNS_ENABLED ) + mbx.nic_cfg.tns_mode =NIC_TNS_MODE ; +else + mbx.nic_cfg.tns_mode =NIC_TNS_BYPASS_MODE ; + +if (vf < nic->num_vf_en) { + bgx_idx =NIC_GET_BGX_FROM_VF_LMAC_MAP (nic->vf_lmac_map[vf]); + lmac =NIC_GET_LMAC_FROM_VF_LMAC_MAP (nic->vf_lmac_map[vf]); + + mac =bgx_get_lmac_mac (nic->node, bgx_idx, lmac); +if (mac) +memcpy ((u8 *)&mbx.nic_cfg.mac_addr, mac,6 ); + +while (timeout-- && (link <=0 )) { + link =bgx_poll_for_link (nic->node, bgx_idx, lmac); +debug ("Link status: %d\n" , link); +if (link <=0 ) +mdelay (2000 ); + } + } +#ifdef VNIC_MULTI_QSET_SUPPORT + mbx.nic_cfg.sqs_mode = (vf >= nic->num_vf_en) ? true : false; +#endif + mbx.nic_cfg.node_id = nic->node; + + mbx.nic_cfg.loopback_supported = vf < nic->num_vf_en; + +nic_send_msg_to_vf (nic, vf, &mbx); +} + +/* ACKs VF's mailbox message +* @vf: VF to which ACK to be sent +*/ +static void nic_mbx_send_ack (struct nicpf *nic,int vf) +{ +union nic_mbx mbx = {}; + + mbx.msg.msg =NIC_MBOX_MSG_ACK ; +nic_send_msg_to_vf (nic, vf, &mbx); +} + +/* NACKs VF's mailbox message that PF is not able to +* complete the action +* @vf: VF to which ACK to be sent +*/ +static void nic_mbx_send_nack (struct nicpf *nic,int vf) +{ +union nic_mbx mbx = {}; + + mbx.msg.msg =NIC_MBOX_MSG_NACK ; +nic_send_msg_to_vf (nic, vf, &mbx); +} + +static int nic_config_loopback (struct nicpf *nic,struct set_loopback *lbk) +{ +int bgx_idx, lmac_idx; + +if (lbk->vf_id > nic->num_vf_en) +return -1 ; + + bgx_idx =NIC_GET_BGX_FROM_VF_LMAC_MAP (nic->vf_lmac_map[lbk->vf_id]); + lmac_idx =NIC_GET_LMAC_FROM_VF_LMAC_MAP (nic->vf_lmac_map[lbk->vf_id]); + +bgx_lmac_internal_loopback (nic->node, bgx_idx, lmac_idx, lbk->enable); + +return 0 ; +} + +/* Interrupt handler to handle mailbox messages from VFs */ +void nic_handle_mbx_intr (struct nicpf *nic,int vf) +{ +union nic_mbx mbx = {}; +u64 *mbx_data; +u64 mbx_addr; +u64 reg_addr; +u64 cfg; +int bgx, lmac; +int i; +int ret =0 ; + + nic->mbx_lock[vf] = true; + + mbx_addr =nic_get_mbx_addr (vf); + mbx_data = (u64 *)&mbx; + +for (i =0 ; i <NIC_PF_VF_MAILBOX_SIZE ; i++) { + *mbx_data =nic_reg_read (nic, mbx_addr); + mbx_data++; + mbx_addr +=sizeof (u64); + } + +debug ("%s: Mailbox msg %d from VF%d\n" , __func__, mbx.msg.msg, vf); +switch (mbx.msg.msg) { +case NIC_MBOX_MSG_READY : +nic_mbx_send_ready (nic, vf); +if (vf < nic->num_vf_en) { + nic->link[vf] =0 ; + nic->duplex[vf] =0 ; + nic->speed[vf] =0 ; + } + ret =1 ; +break ; +case NIC_MBOX_MSG_QS_CFG : + reg_addr =NIC_PF_QSET_0_127_CFG | + (mbx.qs.num <<NIC_QS_ID_SHIFT ); + cfg = mbx.qs.cfg; +#ifdef VNIC_MULTI_QSET_SUPPORT +/* Check if its a secondary Qset */ +if (vf >= nic->num_vf_en) { + cfg = cfg & (~0x7FULL ); +/* Assign this Qset to primary Qset's VF */ + cfg |= nic->pqs_vf[vf]; + } +#endif +nic_reg_write (nic, reg_addr, cfg); +break ; +case NIC_MBOX_MSG_RQ_CFG : + reg_addr =NIC_PF_QSET_0_127_RQ_0_7_CFG | + (mbx.rq.qs_num <<NIC_QS_ID_SHIFT ) | + (mbx.rq.rq_num <<NIC_Q_NUM_SHIFT ); +nic_reg_write (nic, reg_addr, mbx.rq.cfg); +/* Enable CQE_RX2_S extension in CQE_RX descriptor. +* This gets appended by default on 81xx/83xx chips, +* for consistency enabling the same on 88xx pass2 +* where this is introduced. +*/ +if (pass2_silicon (nic->rev_id, nic->hw->model_id)) +nic_reg_write (nic,NIC_PF_RX_CFG ,0x01 ); +break ; +case NIC_MBOX_MSG_RQ_BP_CFG : + reg_addr =NIC_PF_QSET_0_127_RQ_0_7_BP_CFG | + (mbx.rq.qs_num <<NIC_QS_ID_SHIFT ) | + (mbx.rq.rq_num <<NIC_Q_NUM_SHIFT ); +nic_reg_write (nic, reg_addr, mbx.rq.cfg); +break ; +case NIC_MBOX_MSG_RQ_SW_SYNC : + ret =nic_rcv_queue_sw_sync (nic); +break ; +case NIC_MBOX_MSG_RQ_DROP_CFG : + reg_addr =NIC_PF_QSET_0_127_RQ_0_7_DROP_CFG | + (mbx.rq.qs_num <<NIC_QS_ID_SHIFT ) | + (mbx.rq.rq_num <<NIC_Q_NUM_SHIFT ); +nic_reg_write (nic, reg_addr, mbx.rq.cfg); +break ; +case NIC_MBOX_MSG_SQ_CFG : + reg_addr =NIC_PF_QSET_0_127_SQ_0_7_CFG | + (mbx.sq.qs_num <<NIC_QS_ID_SHIFT ) | + (mbx.sq.sq_num <<NIC_Q_NUM_SHIFT ); +nic_reg_write (nic, reg_addr, mbx.sq.cfg); +nic_tx_channel_cfg (nic, mbx.qs.num, + (struct sq_cfg_msg *)&mbx.sq); +break ; +case NIC_MBOX_MSG_SET_MAC : +#ifdef VNIC_MULTI_QSET_SUPPORT +if (vf >= nic->num_vf_en) +break ; +#endif + lmac = mbx.mac.vf_id; + bgx =NIC_GET_BGX_FROM_VF_LMAC_MAP (nic->vf_lmac_map[lmac]); + lmac =NIC_GET_LMAC_FROM_VF_LMAC_MAP (nic->vf_lmac_map[lmac]); +bgx_set_lmac_mac (nic->node, bgx, lmac, mbx.mac.mac_addr); +break ; +case NIC_MBOX_MSG_SET_MAX_FRS : + ret =nic_update_hw_frs (nic, mbx.frs.max_frs, + mbx.frs.vf_id); +break ; +case NIC_MBOX_MSG_CPI_CFG : +nic_config_cpi (nic, &mbx.cpi_cfg); +break ; +#ifdef VNIC_RSS_SUPPORT +case NIC_MBOX_MSG_RSS_SIZE : +nic_send_rss_size (nic, vf); + goto unlock; +case NIC_MBOX_MSG_RSS_CFG : +case NIC_MBOX_MSG_RSS_CFG_CONT : +nic_config_rss (nic, &mbx.rss_cfg); +break ; +#endif +case NIC_MBOX_MSG_CFG_DONE : +/* Last message of VF config msg sequence */ + nic->vf_enabled[vf] = true; +if (vf >= nic->lmac_cnt) + goto unlock; + + bgx =NIC_GET_BGX_FROM_VF_LMAC_MAP (nic->vf_lmac_map[vf]); + lmac =NIC_GET_LMAC_FROM_VF_LMAC_MAP (nic->vf_lmac_map[vf]); + +bgx_lmac_rx_tx_enable (nic->node, bgx, lmac, true); + goto unlock; +case NIC_MBOX_MSG_SHUTDOWN : +/* First msg in VF teardown sequence */ + nic->vf_enabled[vf] = false; +#ifdef VNIC_MULTI_QSET_SUPPORT +if (vf >= nic->num_vf_en) + nic->sqs_used[vf - nic->num_vf_en] = false; + nic->pqs_vf[vf] =0 ; +#endif +if (vf >= nic->lmac_cnt) +break ; + + bgx =NIC_GET_BGX_FROM_VF_LMAC_MAP (nic->vf_lmac_map[vf]); + lmac =NIC_GET_LMAC_FROM_VF_LMAC_MAP (nic->vf_lmac_map[vf]); + +bgx_lmac_rx_tx_enable (nic->node, bgx, lmac, false); +break ; +#ifdef VNIC_MULTI_QSET_SUPPORT +case NIC_MBOX_MSG_ALLOC_SQS : +nic_alloc_sqs (nic, &mbx.sqs_alloc); + goto unlock; +case NIC_MBOX_MSG_NICVF_PTR : + nic->nicvf[vf] = mbx.nicvf.nicvf; +break ; +case NIC_MBOX_MSG_PNICVF_PTR : +nic_send_pnicvf (nic, vf); + goto unlock; +case NIC_MBOX_MSG_SNICVF_PTR : +nic_send_snicvf (nic, &mbx.nicvf); + goto unlock; +#endif +case NIC_MBOX_MSG_LOOPBACK : + ret =nic_config_loopback (nic, &mbx.lbk); +break ; +default : +printf ("Invalid msg from VF%d, msg 0x%x\n" , vf, mbx.msg.msg); +break ; + } + +if (!ret) +nic_mbx_send_ack (nic, vf); +else if (mbx.msg.msg !=NIC_MBOX_MSG_READY ) +nic_mbx_send_nack (nic, vf); +unlock: + nic->mbx_lock[vf] = false; +} + +static int nic_rcv_queue_sw_sync (struct nicpf *nic) +{ +int timeout =20 ; + +nic_reg_write (nic,NIC_PF_SW_SYNC_RX ,0x01 ); +while (timeout) { +if (nic_reg_read (nic,NIC_PF_SW_SYNC_RX_DONE ) &0x1 ) +break ; +udelay (2000 ); + timeout--; + } +nic_reg_write (nic,NIC_PF_SW_SYNC_RX ,0x00 ); +if (!timeout) { +printf ("Recevie queue software sync failed" ); +return 1 ; + } +return 0 ; +} + +static int nic_update_hw_frs (struct nicpf *nic,int new_frs,int vf) +{ +u64 *pkind = (u64 *)&nic->pkind; + +if (new_frs >NIC_HW_MAX_FRS || new_frs <NIC_HW_MIN_FRS ) { +printf ("Invalid MTU setting from VF%d rejected," , vf); +printf (" should be between %d and %d\n" ,NIC_HW_MIN_FRS , +NIC_HW_MAX_FRS ); +return 1 ; + } + new_frs +=ETH_HLEN ; +if (new_frs <= nic->pkind.maxlen) +return 0 ; + + nic->pkind.maxlen = new_frs; + +nic_reg_write (nic,NIC_PF_PKIND_0_15_CFG , *pkind); +return 0 ; +} + +/* Set minimum transmit packet size */ +static void nic_set_tx_pkt_pad (struct nicpf *nic,int size) +{ +int lmac; +u64 lmac_cfg; +struct hw_info *hw = nic->hw; +int max_lmac = nic->hw->bgx_cnt *MAX_LMAC_PER_BGX ; + +/* Max value that can be set is 60 */ +if (size >52 ) + size =52 ; + +/* CN81XX has RGX configured as FAKE BGX, adjust mac_lmac accordingly */ +if (hw->chans_per_rgx) + max_lmac = ((nic->hw->bgx_cnt -1 ) *MAX_LMAC_PER_BGX ) +1 ; + +for (lmac =0 ; lmac < max_lmac; lmac++) { + lmac_cfg =nic_reg_read (nic,NIC_PF_LMAC_0_7_CFG | (lmac <<3 )); + lmac_cfg &= ~(0xF <<2 ); + lmac_cfg |= ((size /4 ) <<2 ); +nic_reg_write (nic,NIC_PF_LMAC_0_7_CFG | (lmac <<3 ), lmac_cfg); + } +} + +/* Function to check number of LMACs present and set VF to LMAC mapping. +* Mapping will be used while initializing channels. +*/ +static void nic_set_lmac_vf_mapping (struct nicpf *nic) +{ +int bgx, bgx_count, next_bgx_lmac =0 ; +int lmac, lmac_cnt =0 ; +u64 lmac_credit; + + nic->num_vf_en =0 ; +if (nic->flags &NIC_TNS_ENABLED ) { + nic->num_vf_en =DEFAULT_NUM_VF_ENABLED ; +return ; + } + +bgx_get_count (nic->node, &bgx_count); +debug ("bgx_count: %d\n" , bgx_count); + +for (bgx =0 ; bgx < nic->hw->bgx_cnt; bgx++) { +if (!(bgx_count & (1 << bgx))) +continue ; + nic->bgx_cnt++; + lmac_cnt =bgx_get_lmac_count (nic->node, bgx); +debug ("lmac_cnt: %d for BGX%d\n" , lmac_cnt, bgx); +for (lmac =0 ; lmac < lmac_cnt; lmac++) + nic->vf_lmac_map[next_bgx_lmac++] = +NIC_SET_VF_LMAC_MAP (bgx, lmac); + nic->num_vf_en += lmac_cnt; + +/* Program LMAC credits */ + lmac_credit = (1ull <<1 );/* chennel credit enable */ + lmac_credit |= (0x1ff <<2 ); + lmac_credit |= (((((48 *1024 ) / lmac_cnt) - +NIC_HW_MAX_FRS ) /16 ) <<12 ); + lmac = bgx *MAX_LMAC_PER_BGX ; +for (; lmac < lmac_cnt + (bgx *MAX_LMAC_PER_BGX ); lmac++) +nic_reg_write (nic,NIC_PF_LMAC_0_7_CREDIT + (lmac *8 ), + lmac_credit); + } +} + +static void nic_get_hw_info (struct nicpf *nic) +{ +u16 sdevid; +struct hw_info *hw = nic->hw; + +dm_pci_read_config16 (nic->udev,PCI_SUBSYSTEM_ID , &sdevid); + +switch (sdevid) { +case PCI_SUBSYS_DEVID_88XX_NIC_PF : + hw->bgx_cnt =MAX_BGX_PER_NODE ; + hw->chans_per_lmac =16 ; + hw->chans_per_bgx =128 ; + hw->cpi_cnt =2048 ; + hw->rssi_cnt =4096 ; + hw->rss_ind_tbl_size =NIC_MAX_RSS_IDR_TBL_SIZE ; + hw->tl3_cnt =256 ; + hw->tl2_cnt =64 ; + hw->tl1_cnt =2 ; + hw->tl1_per_bgx = true; + hw->model_id =0x88 ; +break ; +case PCI_SUBSYS_DEVID_81XX_NIC_PF : + hw->bgx_cnt =MAX_BGX_PER_NODE ; + hw->chans_per_lmac =8 ; + hw->chans_per_bgx =32 ; + hw->chans_per_rgx =8 ; + hw->chans_per_lbk =24 ; + hw->cpi_cnt =512 ; + hw->rssi_cnt =256 ; + hw->rss_ind_tbl_size =32 ;/* Max RSSI / Max interfaces */ + hw->tl3_cnt =64 ; + hw->tl2_cnt =16 ; + hw->tl1_cnt =10 ; + hw->tl1_per_bgx = false; + hw->model_id =0x81 ; +break ; +case PCI_SUBSYS_DEVID_83XX_NIC_PF : + hw->bgx_cnt =MAX_BGX_PER_NODE ; + hw->chans_per_lmac =8 ; + hw->chans_per_bgx =32 ; + hw->chans_per_lbk =64 ; + hw->cpi_cnt =2048 ; + hw->rssi_cnt =1024 ; + hw->rss_ind_tbl_size =64 ;/* Max RSSI / Max interfaces */ + hw->tl3_cnt =256 ; + hw->tl2_cnt =64 ; + hw->tl1_cnt =18 ; + hw->tl1_per_bgx = false; + hw->model_id =0x83 ; +break ; + } + + hw->tl4_cnt =MAX_QUEUES_PER_QSET *pci_sriov_get_totalvfs (nic->udev); +} + +static void nic_init_hw (struct nicpf *nic) +{ +int i; +u64 reg; +u64 *pkind = (u64 *)&nic->pkind; + +/* Get HW capability info */ +nic_get_hw_info (nic); + +/* Enable NIC HW block */ +nic_reg_write (nic,NIC_PF_CFG ,0x3 ); + +/* Enable backpressure */ +nic_reg_write (nic,NIC_PF_BP_CFG , (1ULL <<6 ) |0x03 ); +nic_reg_write (nic,NIC_PF_INTF_0_1_BP_CFG , (1ULL <<63 ) |0x08 ); +nic_reg_write (nic,NIC_PF_INTF_0_1_BP_CFG + (1 <<8 ), + (1ULL <<63 ) |0x09 ); + +for (i =0 ; i <NIC_MAX_CHANS ; i++) +nic_reg_write (nic,NIC_PF_CHAN_0_255_TX_CFG | (i <<3 ),1 ); + +if (nic->flags &NIC_TNS_ENABLED ) { + reg =NIC_TNS_MODE <<7 ; + reg |=0x06 ; +nic_reg_write (nic,NIC_PF_INTF_0_1_SEND_CFG , reg); + reg &= ~0xFull ; + reg |=0x07 ; +nic_reg_write (nic,NIC_PF_INTF_0_1_SEND_CFG | (1 <<8 ), reg); + }else { +/* Disable TNS mode on both interfaces */ + reg =NIC_TNS_BYPASS_MODE <<7 ; + reg |=0x08 ;/* Block identifier */ +nic_reg_write (nic,NIC_PF_INTF_0_1_SEND_CFG , reg); + reg &= ~0xFull ; + reg |=0x09 ; +nic_reg_write (nic,NIC_PF_INTF_0_1_SEND_CFG | (1 <<8 ), reg); + } + +/* PKIND configuration */ + nic->pkind.minlen =0 ; + nic->pkind.maxlen =NIC_HW_MAX_FRS +ETH_HLEN ; + nic->pkind.lenerr_en =1 ; + nic->pkind.rx_hdr =0 ; + nic->pkind.hdr_sl =0 ; + +for (i =0 ; i <NIC_MAX_PKIND ; i++) +nic_reg_write (nic,NIC_PF_PKIND_0_15_CFG | (i <<3 ), *pkind); + +nic_set_tx_pkt_pad (nic,NIC_HW_MIN_FRS ); + +/* Timer config */ +nic_reg_write (nic,NIC_PF_INTR_TIMER_CFG ,NICPF_CLK_PER_INT_TICK ); +} + +/* Channel parse index configuration */ +static void nic_config_cpi (struct nicpf *nic,struct cpi_cfg_msg *cfg) +{ +struct hw_info *hw = nic->hw; +u32 vnic, bgx, lmac, chan; +u32 padd, cpi_count =0 ; +u64 cpi_base, cpi, rssi_base, rssi; +u8 qset, rq_idx =0 ; + + vnic = cfg->vf_id; + bgx =NIC_GET_BGX_FROM_VF_LMAC_MAP (nic->vf_lmac_map[vnic]); + lmac =NIC_GET_LMAC_FROM_VF_LMAC_MAP (nic->vf_lmac_map[vnic]); + + chan = (lmac * hw->chans_per_lmac) + (bgx * hw->chans_per_bgx); + cpi_base = vnic *NIC_MAX_CPI_PER_LMAC ; + rssi_base = vnic * hw->rss_ind_tbl_size; + +/* Rx channel configuration */ +nic_reg_write (nic,NIC_PF_CHAN_0_255_RX_BP_CFG | (chan <<3 ), + (1ull <<63 ) | (vnic <<0 )); +nic_reg_write (nic,NIC_PF_CHAN_0_255_RX_CFG | (chan <<3 ), + ((u64 )cfg->cpi_alg <<62 ) | (cpi_base <<48 )); + +if (cfg->cpi_alg ==CPI_ALG_NONE ) + cpi_count =1 ; +else if (cfg->cpi_alg ==CPI_ALG_VLAN )/* 3 bits of PCP */ + cpi_count =8 ; +else if (cfg->cpi_alg ==CPI_ALG_VLAN16 )/* 3 bits PCP + DEI */ + cpi_count =16 ; +else if (cfg->cpi_alg ==CPI_ALG_DIFF )/* 6bits DSCP */ + cpi_count =NIC_MAX_CPI_PER_LMAC ; + +/* RSS Qset, Qidx mapping */ + qset = cfg->vf_id; + rssi = rssi_base; +for (; rssi < (rssi_base + cfg->rq_cnt); rssi++) { +nic_reg_write (nic,NIC_PF_RSSI_0_4097_RQ | (rssi <<3 ), + (qset <<3 ) | rq_idx); + rq_idx++; + } + + rssi =0 ; + cpi = cpi_base; +for (; cpi < (cpi_base + cpi_count); cpi++) { +/* Determine port to channel adder */ +if (cfg->cpi_alg !=CPI_ALG_DIFF ) + padd = cpi % cpi_count; +else + padd = cpi %8 ;/* 3 bits CS out of 6bits DSCP */ + +/* Leave RSS_SIZE as '0' to disable RSS */ +if (pass1_silicon (nic->rev_id, nic->hw->model_id)) { +nic_reg_write (nic,NIC_PF_CPI_0_2047_CFG | (cpi <<3 ), + (vnic <<24 ) | (padd <<16 ) | + (rssi_base + rssi)); + }else { +/* Set MPI_ALG to '0' to disable MCAM parsing */ +nic_reg_write (nic,NIC_PF_CPI_0_2047_CFG | (cpi <<3 ), + (padd <<16 )); +/* MPI index is same as CPI if MPI_ALG is not enabled */ +nic_reg_write (nic,NIC_PF_MPI_0_2047_CFG | (cpi <<3 ), + (vnic <<24 ) | (rssi_base + rssi)); + } + +if ((rssi +1 ) >= cfg->rq_cnt) +continue ; + +if (cfg->cpi_alg ==CPI_ALG_VLAN ) + rssi++; +else if (cfg->cpi_alg ==CPI_ALG_VLAN16 ) + rssi = ((cpi - cpi_base) &0xe ) >>1 ; +else if (cfg->cpi_alg ==CPI_ALG_DIFF ) + rssi = ((cpi - cpi_base) &0x38 ) >>3 ; + } + nic->cpi_base[cfg->vf_id] = cpi_base; + nic->rssi_base[cfg->vf_id] = rssi_base; +} + +/* Transmit channel configuration (TL4 -> TL3 -> Chan) +* VNIC0-SQ0 -> TL4(0) -> TL4A(0) -> TL3[0] -> BGX0/LMAC0/Chan0 +* VNIC1-SQ0 -> TL4(8) -> TL4A(2) -> TL3[2] -> BGX0/LMAC1/Chan0 +* VNIC2-SQ0 -> TL4(16) -> TL4A(4) -> TL3[4] -> BGX0/LMAC2/Chan0 +* VNIC3-SQ0 -> TL4(32) -> TL4A(6) -> TL3[6] -> BGX0/LMAC3/Chan0 +* VNIC4-SQ0 -> TL4(512) -> TL4A(128) -> TL3[128] -> BGX1/LMAC0/Chan0 +* VNIC5-SQ0 -> TL4(520) -> TL4A(130) -> TL3[130] -> BGX1/LMAC1/Chan0 +* VNIC6-SQ0 -> TL4(528) -> TL4A(132) -> TL3[132] -> BGX1/LMAC2/Chan0 +* VNIC7-SQ0 -> TL4(536) -> TL4A(134) -> TL3[134] -> BGX1/LMAC3/Chan0 +*/ +static void nic_tx_channel_cfg (struct nicpf *nic,u8 vnic, +struct sq_cfg_msg *sq) +{ +struct hw_info *hw = nic->hw; +u32 bgx, lmac, chan; +u32 tl2, tl3, tl4; +u32 rr_quantum; +u8 sq_idx = sq->sq_num; +u8 pqs_vnic = vnic; +int svf; +u16 sdevid; +Lines of this file are not shown. View the raw message.
drivers/net/octeontx/nic_reg.h new file +250
-0Lines of this file are not shown. View the raw message.
drivers/net/octeontx/nicvf_main.c new file +581
-0Lines of this file are not shown. View the raw message.
drivers/net/octeontx/nicvf_queues.c new file +1140
-0Lines of this file are not shown. View the raw message.
drivers/net/octeontx/nicvf_queues.h new file +353
-0Lines of this file are not shown. View the raw message.
drivers/net/octeontx/q_struct.h new file +695
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Viele Gr??e,
Stefan
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
Part of the diff is not shown here. View the raw message.