Skip to content

Commit

Permalink
octeontx2-af: cn10k: Add support for programmable channels
Browse files Browse the repository at this point in the history
NIX uses unique channel numbers to identify the packet sources/sinks
like CGX,LBK and SDP. The channel numbers assigned to each block are
hardwired in CN9xxx silicon.
The fixed channel numbers in CN9xxx are:

0x0 | a << 8 | b            - LBK(0..3)_CH(0..63)
0x0 | a << 8                - Reserved
0x700 | a                   - SDP_CH(0..255)
0x800 | a << 8 | b << 4 | c - CGX(0..7)_LMAC(0..3)_CH(0..15)

All the channels in the above fixed enumerator(with maximum
number of blocks) are not required since some chips
have less number of blocks.
For CN10K silicon the channel numbers need to be programmed by
software in each block with the base channel number and range of
channels. This patch calculates and assigns the channel numbers
to efficiently distribute the channel number range(0-4095) among
all the blocks. The assignment is made based on the actual number of
blocks present and also contiguously leaving no holes.
The channel numbers remaining after the math are used as new CPT
replay channels present in CN10K. Also since channel numbers are
not fixed the transmit channel link number needed by AF consumers
is calculated by AF and sent along with nix_lf_alloc mailbox response.

Signed-off-by: Subbaraya Sundeep <sbhatta@marvell.com>
Signed-off-by: Geetha sowjanya <gakula@marvell.com>
Signed-off-by: Sunil Goutham <sgoutham@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Subbaraya Sundeep authored and David S. Miller committed Feb 11, 2021
1 parent 91c6945 commit 242da43
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 17 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -10720,6 +10720,7 @@ M: Linu Cherian <lcherian@marvell.com>
M: Geetha sowjanya <gakula@marvell.com>
M: Jerin Jacob <jerinj@marvell.com>
M: hariprasad <hkelam@marvell.com>
M: Subbaraya Sundeep <sbhatta@marvell.com>
L: netdev@vger.kernel.org
S: Supported
F: Documentation/networking/device_drivers/ethernet/marvell/octeontx2.rst
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/marvell/octeontx2/af/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ obj-$(CONFIG_OCTEONTX2_AF) += octeontx2_af.o
octeontx2_mbox-y := mbox.o rvu_trace.o
octeontx2_af-y := cgx.o rvu.o rvu_cgx.o rvu_npa.o rvu_nix.o \
rvu_reg.o rvu_npc.o rvu_debugfs.o ptp.o rvu_npc_fs.o \
rvu_cpt.o rvu_devlink.o rpm.o
rvu_cpt.o rvu_devlink.o rpm.o rvu_cn10k.o
14 changes: 14 additions & 0 deletions drivers/net/ethernet/marvell/octeontx2/af/cgx.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ void *cgx_get_pdata(int cgx_id)
return NULL;
}

void cgx_lmac_write(int cgx_id, int lmac_id, u64 offset, u64 val)
{
struct cgx *cgx_dev = cgx_get_pdata(cgx_id);

cgx_write(cgx_dev, lmac_id, offset, val);
}

u64 cgx_lmac_read(int cgx_id, int lmac_id, u64 offset)
{
struct cgx *cgx_dev = cgx_get_pdata(cgx_id);

return cgx_read(cgx_dev, lmac_id, offset);
}

int cgx_get_cgxid(void *cgxd)
{
struct cgx *cgx = cgxd;
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ethernet/marvell/octeontx2/af/cgx.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,6 @@ struct mac_ops *get_mac_ops(void *cgxd);
int cgx_get_nr_lmacs(void *cgxd);
u8 cgx_get_lmacid(void *cgxd, u8 lmac_index);
unsigned long cgx_get_lmac_bmap(void *cgxd);
void cgx_lmac_write(int cgx_id, int lmac_id, u64 offset, u64 val);
u64 cgx_lmac_read(int cgx_id, int lmac_id, u64 offset);
#endif /* CGX_H */
3 changes: 3 additions & 0 deletions drivers/net/ethernet/marvell/octeontx2/af/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ enum nix_scheduler {
#define NIX_LINK_LBK(a) (12 + (a))
#define NIX_CHAN_CGX_LMAC_CHX(a, b, c) (0x800 + 0x100 * (a) + 0x10 * (b) + (c))
#define NIX_CHAN_LBK_CHX(a, b) (0 + 0x100 * (a) + (b))
#define NIX_CHAN_SDP_CH_START (0x700ull)

#define SDP_CHANNELS 256

/* NIX LSO format indices.
* As of now TSO is the only one using, so statically assigning indices.
Expand Down
6 changes: 6 additions & 0 deletions drivers/net/ethernet/marvell/octeontx2/af/rpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
#ifndef RPM_H
#define RPM_H

#include <linux/bits.h>

/* PCI device IDs */
#define PCI_DEVID_CN10K_RPM 0xA060

/* Registers */
#define RPMX_CMRX_SW_INT 0x180
#define RPMX_CMRX_SW_INT_W1S 0x188
#define RPMX_CMRX_SW_INT_ENA_W1S 0x198
#define RPMX_CMRX_LINK_CFG 0x1070

#define RPMX_CMRX_LINK_RANGE_MASK GENMASK_ULL(19, 16)
#define RPMX_CMRX_LINK_BASE_MASK GENMASK_ULL(11, 0)

#define RPM_LMAC_FWI 0xa

Expand Down
8 changes: 6 additions & 2 deletions drivers/net/ethernet/marvell/octeontx2/af/rvu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,10 @@ static int rvu_setup_hw_resources(struct rvu *rvu)
rvu_scan_block(rvu, block);
}

err = rvu_set_channels_base(rvu);
if (err)
goto msix_err;

err = rvu_npc_init(rvu);
if (err)
goto npc_err;
Expand All @@ -1025,6 +1029,8 @@ static int rvu_setup_hw_resources(struct rvu *rvu)
if (err)
goto nix_err;

rvu_program_channels(rvu);

return 0;

nix_err:
Expand Down Expand Up @@ -2721,8 +2727,6 @@ static void rvu_enable_afvf_intr(struct rvu *rvu)
rvupf_write64(rvu, RVU_PF_VFME_INT_ENA_W1SX(1), INTR_MASK(vfs - 64));
}

#define PCI_DEVID_OCTEONTX2_LBK 0xA061

int rvu_get_num_lbk_chans(void)
{
struct pci_dev *pdev;
Expand Down
44 changes: 44 additions & 0 deletions drivers/net/ethernet/marvell/octeontx2/af/rvu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
#include "common.h"
#include "mbox.h"
#include "npc.h"
#include "rvu_reg.h"

/* PCI device IDs */
#define PCI_DEVID_OCTEONTX2_RVU_AF 0xA065
#define PCI_DEVID_OCTEONTX2_LBK 0xA061

/* Subsystem Device ID */
#define PCI_SUBSYS_DEVID_96XX 0xB200
Expand Down Expand Up @@ -305,6 +307,7 @@ struct hw_cap {
bool nix_tx_link_bp; /* Can link backpressure TL queues ? */
bool nix_rx_multicast; /* Rx packet replication support */
bool per_pf_mbox_regs; /* PF mbox specified in per PF registers ? */
bool programmable_chans; /* Channels programmable ? */
};

struct rvu_hwinfo {
Expand All @@ -313,9 +316,14 @@ struct rvu_hwinfo {
u16 max_vfs_per_pf; /* Max VFs that can be attached to a PF */
u8 cgx;
u8 lmac_per_cgx;
u16 cgx_chan_base; /* CGX base channel number */
u16 lbk_chan_base; /* LBK base channel number */
u16 sdp_chan_base; /* SDP base channel number */
u16 cpt_chan_base; /* CPT base channel number */
u8 cgx_links;
u8 lbk_links;
u8 sdp_links;
u8 cpt_links; /* Number of CPT links */
u8 npc_kpus; /* No of parser units */
u8 npc_pkinds; /* No of port kinds */
u8 npc_intfs; /* No of interfaces */
Expand Down Expand Up @@ -499,6 +507,38 @@ static inline bool is_rvu_otx2(struct rvu *rvu)
midr == PCI_REVISION_ID_95XXMM);
}

static inline u16 rvu_nix_chan_cgx(struct rvu *rvu, u8 cgxid,
u8 lmacid, u8 chan)
{
u64 nix_const = rvu_read64(rvu, BLKADDR_NIX0, NIX_AF_CONST);
u16 cgx_chans = nix_const & 0xFFULL;
struct rvu_hwinfo *hw = rvu->hw;

if (!hw->cap.programmable_chans)
return NIX_CHAN_CGX_LMAC_CHX(cgxid, lmacid, chan);

return rvu->hw->cgx_chan_base +
(cgxid * hw->lmac_per_cgx + lmacid) * cgx_chans + chan;
}

static inline u16 rvu_nix_chan_lbk(struct rvu *rvu, u8 lbkid,
u8 chan)
{
u64 nix_const = rvu_read64(rvu, BLKADDR_NIX0, NIX_AF_CONST);
u16 lbk_chans = (nix_const >> 16) & 0xFFULL;
struct rvu_hwinfo *hw = rvu->hw;

if (!hw->cap.programmable_chans)
return NIX_CHAN_LBK_CHX(lbkid, chan);

return rvu->hw->lbk_chan_base + lbkid * lbk_chans + chan;
}

static inline u16 rvu_nix_chan_cpt(struct rvu *rvu, u8 chan)
{
return rvu->hw->cpt_chan_base + chan;
}

/* Function Prototypes
* RVU
*/
Expand Down Expand Up @@ -640,6 +680,10 @@ bool is_mac_feature_supported(struct rvu *rvu, int pf, int feature);
/* CPT APIs */
int rvu_cpt_lf_teardown(struct rvu *rvu, u16 pcifunc, int lf, int slot);

/* CN10K RVU */
int rvu_set_channels_base(struct rvu *rvu);
void rvu_program_channels(struct rvu *rvu);

#ifdef CONFIG_DEBUG_FS
void rvu_dbg_init(struct rvu *rvu);
void rvu_dbg_exit(struct rvu *rvu);
Expand Down
Loading

0 comments on commit 242da43

Please sign in to comment.