add octeon_ep_vf driver
Shinas Rasheed
maintainerv4 cover add octeon_ep_vf driver
This driver implements networking functionality of Marvell's Octeon PCI Endpoint NIC VF.
This driver support following devices:
* Network controller: Cavium, Inc. Device b203
* Network controller: Cavium, Inc. Device b403
* Network controller: Cavium, Inc. Device b103
* Network controller: Cavium, Inc. Device b903
* Network controller: Cavium, Inc. Device ba03
* Network controller: Cavium, Inc. Device bc03
* Network controller: Cavium, Inc. Device bd03
Changes:
V4:
- Moved some stats from ethtool and added more to ndo_get_stats64
- Replaced code in IQ full check function to use helper from net/netdev_queues.h
- Refactored code so that NETDEV_TX_BUSY is avoided
V3: https://lore.kernel.org/all/[email protected]/
- Removed UINT64_MAX, which is unused
- Replaced masks and ULL declarations with GENMASK_ULL(), ULL() and
other linux/bits.h macros, corrected declarations to conform to xmas tree format in patch [2/8]
- Moved vfree and vzalloc null pointer casting corrections to patch
[3/8], and corrected return values to follow standard kernel error codes in same
- Set static budget of 64 for tx completion processing in NAPI
- Replaces napi_complete and build_skb APIs to napi_complete_done and napi_build_skb APIs respectively
- Replaced code with helper from net/netdev_queues.h to wake queues in TX completion processing
- Removed duplicate reporting of TX/RX packets/bytes, which is already
done during ndo_get_stats64
V2: https://lore.kernel.org/all/[email protected]/
- Removed linux/version.h header file from inclusion in octep_vf_main.c
- Corrected Makefile entry to include building octep_vf_mbox.c in
[6/8] patch.
- Removed redundant vzalloc pointer cast and vfree pointer check in
[6/8] patch.V1: https://lore.kernel.org/all/[email protected]/
Shinas Rasheed (8):
octeon_ep_vf: Add driver framework and device initialization
octeon_ep_vf: add hardware configuration APIs
octeon_ep_vf: add VF-PF mailbox communication.
octeon_ep_vf: add Tx/Rx ring resource setup and cleanup
octeon_ep_vf: add support for ndo ops
octeon_ep_vf: add Tx/Rx processing and interrupt support
octeon_ep_vf: add ethtool support
octeon_ep_vf: update MAINTAINERS
.../device_drivers/ethernet/index.rst | 1 + .../ethernet/marvell/octeon_ep_vf.rst | 24 + MAINTAINERS | 9 + drivers/net/ethernet/marvell/Kconfig | 1 + drivers/net/ethernet/marvell/Makefile | 1 + .../net/ethernet/marvell/octeon_ep_vf/Kconfig | 19 + .../ethernet/marvell/octeon_ep_vf/Makefile | 10 + .../marvell/octeon_ep_vf/octep_vf_cn9k.c | 491 +++++++ .../marvell/octeon_ep_vf/octep_vf_cnxk.c | 502 +++++++ .../marvell/octeon_ep_vf/octep_vf_config.h | 160 +++ .../marvell/octeon_ep_vf/octep_vf_ethtool.c | 273 ++++ .../marvell/octeon_ep_vf/octep_vf_main.c | 1240 +++++++++++++++++ .../marvell/octeon_ep_vf/octep_vf_main.h | 334 +++++ .../marvell/octeon_ep_vf/octep_vf_mbox.c | 430 ++++++ .../marvell/octeon_ep_vf/octep_vf_mbox.h | 166 +++ .../marvell/octeon_ep_vf/octep_vf_regs_cn9k.h | 154 ++ .../marvell/octeon_ep_vf/octep_vf_regs_cnxk.h | 162 +++ .../marvell/octeon_ep_vf/octep_vf_rx.c | 510 +++++++ .../marvell/octeon_ep_vf/octep_vf_rx.h | 224 +++ .../marvell/octeon_ep_vf/octep_vf_tx.c | 330 +++++ .../marvell/octeon_ep_vf/octep_vf_tx.h | 276 ++++ 21 files changed, 5317 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/marvell/octeon_ep_vf.rst create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/Kconfig create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/Makefile create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_config.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_ethtool.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_regs_cn9k.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_regs_cnxk.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.h
Signature · 1 line
2.25.1
Shinas Rasheed
maintainerPATCH v4 1/8 octeon_ep_vf: Add driver framework and device initialization
Add driver framework and device setup and initialization for Octeon PCI Endpoint NIC VF.
Add implementation to load module, initialize, register network device, cleanup and unload module.
---
V4:
- No changes
V3: https://lore.kernel.org/all/[email protected]/
- Removed UINT64_MAX, which is unused
V2: https://lore.kernel.org/all/[email protected]/
- Removed linux/version.h header file from inclusion in octep_vf_main.c
V1: https://lore.kernel.org/all/[email protected]/
.../device_drivers/ethernet/index.rst | 1 + .../ethernet/marvell/octeon_ep_vf.rst | 24 + drivers/net/ethernet/marvell/Kconfig | 1 + drivers/net/ethernet/marvell/Makefile | 1 + .../net/ethernet/marvell/octeon_ep_vf/Kconfig | 19 + .../ethernet/marvell/octeon_ep_vf/Makefile | 9 + .../marvell/octeon_ep_vf/octep_vf_cn9k.c | 157 ++++++ .../marvell/octeon_ep_vf/octep_vf_cnxk.c | 158 ++++++ .../marvell/octeon_ep_vf/octep_vf_config.h | 160 ++++++ .../marvell/octeon_ep_vf/octep_vf_main.c | 528 ++++++++++++++++++ .../marvell/octeon_ep_vf/octep_vf_main.h | 332 +++++++++++ .../marvell/octeon_ep_vf/octep_vf_mbox.c | 96 ++++ .../marvell/octeon_ep_vf/octep_vf_mbox.h | 25 + .../marvell/octeon_ep_vf/octep_vf_regs_cn9k.h | 154 +++++ .../marvell/octeon_ep_vf/octep_vf_regs_cnxk.h | 162 ++++++ .../marvell/octeon_ep_vf/octep_vf_rx.c | 42 ++ .../marvell/octeon_ep_vf/octep_vf_rx.h | 224 ++++++++ .../marvell/octeon_ep_vf/octep_vf_tx.c | 43 ++ .../marvell/octeon_ep_vf/octep_vf_tx.h | 276 +++++++++ 19 files changed, 2412 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/marvell/octeon_ep_vf.rst create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/Kconfig create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/Makefile create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_config.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_regs_cn9k.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_regs_cnxk.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.h create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.c create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.h
Documentation/networking/device_drivers/ethernet/index.rst +1 -0
@@ -42,6 +42,7 @@ Contents: intel/ice marvell/octeontx2 marvell/octeon_ep + marvell/octeon_ep_vf mellanox/mlx5/index microsoft/netvsc neterion/s2io
Documentation/networking/device_drivers/ethernet/marvell/octeon_ep_vf.rst new file +24 -0
@@ -0,0 +1,24 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +======================================================================= +Linux kernel networking driver for Marvell's Octeon PCI Endpoint NIC VF +======================================================================= + +Network driver for Marvell's Octeon PCI EndPoint NIC VF. +Copyright (c) 2020 Marvell International Ltd. + +Overview +======== +This driver implements networking functionality of Marvell's Octeon PCI +EndPoint NIC VF. + +Supported Devices +================= +Currently, this driver support following devices: + * Network controller: Cavium, Inc. Device b203 + * Network controller: Cavium, Inc. Device b403 + * Network controller: Cavium, Inc. Device b103 + * Network controller: Cavium, Inc. Device b903 + * Network controller: Cavium, Inc. Device ba03 + * Network controller: Cavium, Inc. Device bc03 + * Network controller: Cavium, Inc. Device bd03
drivers/net/ethernet/marvell/Kconfig +1 -0
@@ -180,6 +180,7 @@ config SKY2_DEBUG source "drivers/net/ethernet/marvell/octeontx2/Kconfig" source "drivers/net/ethernet/marvell/octeon_ep/Kconfig" +source "drivers/net/ethernet/marvell/octeon_ep_vf/Kconfig" source "drivers/net/ethernet/marvell/prestera/Kconfig" endif # NET_VENDOR_MARVELL
drivers/net/ethernet/marvell/Makefile +1 -0
@@ -12,5 +12,6 @@ obj-$(CONFIG_PXA168_ETH) += pxa168_eth.o obj-$(CONFIG_SKGE) += skge.o obj-$(CONFIG_SKY2) += sky2.o obj-y += octeon_ep/ +obj-y += octeon_ep_vf/ obj-y += octeontx2/ obj-y += prestera/
drivers/net/ethernet/marvell/octeon_ep_vf/Kconfig new file +19 -0
@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Marvell's Octeon PCI Endpoint NIC VF Driver Configuration +# + +config OCTEON_EP_VF + tristate "Marvell Octeon PCI Endpoint NIC VF Driver" + depends on 64BIT + depends on PCI + help + This driver supports networking functionality of Marvell's + Octeon PCI Endpoint NIC VF. + + To know the list of devices supported by this driver, refer + documentation in + <file:Documentation/networking/device_drivers/ethernet/marvell/octeon_ep_vf.rst>. + + To compile this drivers as a module, choose M here. Name of the + module is octeon_ep_vf.
drivers/net/ethernet/marvell/octeon_ep_vf/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Network driver for Marvell's Octeon PCI Endpoint NIC VF +# + +obj-$(CONFIG_OCTEON_EP_VF) += octeon_ep_vf.o + +octeon_ep_vf-y := octep_vf_main.o octep_vf_cn9k.o octep_vf_cnxk.o \ + octep_vf_tx.o octep_vf_rx.o octep_vf_mbox.o
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c new file +157 -0
157 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c new file +158 -0
158 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_config.h new file +160 -0
160 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c new file +528 -0
528 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h new file +332 -0
332 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.c new file +96 -0
96 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Marvell Octeon EP (EndPoint) Ethernet Driver +* +* Copyright (C) 2020 Marvell. +* +*/ +#ifndef _OCTEP_VF_MBOX_H_ +#define _OCTEP_VF_MBOX_H_ + +#define OCTEP_PFVF_MBOX_MAX_DATA_BUF_SIZE 256 + +int octep_vf_setup_mbox (struct octep_vf_device *oct); +void octep_vf_delete_mbox (struct octep_vf_device *oct); +int octep_vf_mbox_set_mtu (struct octep_vf_device *oct,int mtu); +int octep_vf_mbox_set_mac_addr (struct octep_vf_device *oct,char *mac_addr); +int octep_vf_mbox_get_mac_addr (struct octep_vf_device *oct,char *mac_addr); +int octep_vf_mbox_version_check (struct octep_vf_device *oct); +int octep_vf_mbox_set_rx_state (struct octep_vf_device *oct,bool state); +int octep_vf_mbox_set_link_status (struct octep_vf_device *oct,bool status); +int octep_vf_mbox_get_link_status (struct octep_vf_device *oct,u8 *oper_up); +int octep_vf_mbox_dev_remove (struct octep_vf_device *oct); +int octep_vf_mbox_get_fw_info (struct octep_vf_device *oct); +int octep_vf_mbox_set_offloads (struct octep_vf_device *oct,u16 tx_offloads,u16 rx_offloads); + +#endif
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_regs_cn9k.h new file +154 -0
154 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_regs_cnxk.h new file +162 -0
162 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c new file +42 -0
42 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.h new file +224 -0
224 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.c new file +43 -0
43 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.h new file +276 -0
276 lines not on this page · raw message
Signature · 1 line
2.25.1
Shinas Rasheed
maintainerPATCH v4 2/8 octeon_ep_vf: add hardware configuration APIs
In reply to Shinas RasheedImplement hardware resource init and shutdown helper APIs, like hardware Tx/Rx queue init/enable/disable/reset.
---
V4:
- No changes
V3: https://lore.kernel.org/all/[email protected]/
- Replaced masks and ULL declarations with GENMASK_ULL(), ULL() and other linux/bits.h macros
- Corrected declarations to conform to xmas tree format
V2: https://lore.kernel.org/all/[email protected]/
- No changes
V1: https://lore.kernel.org/all/[email protected]/
.../marvell/octeon_ep_vf/octep_vf_cn9k.c | 336 ++++++++++++++++- .../marvell/octeon_ep_vf/octep_vf_cnxk.c | 346 +++++++++++++++++- 2 files changed, 680 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +335 -1
@@ -13,9 +13,125 @@#include "octep_vf_main.h" #include "octep_vf_regs_cn9k.h" +/* Dump useful hardware IQ/OQ CSRs for debug purpose */ +static void cn93_vf_dump_q_regs (struct octep_vf_device *oct,int qno) +{ +struct device *dev = &oct->pdev->dev; + +dev_info (dev,"IQ-%d register dump\n" , qno); +dev_info (dev,"R[%d]_IN_INSTR_DBELL[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_INSTR_DBELL (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_DBELL (qno))); +dev_info (dev,"R[%d]_IN_CONTROL[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_CONTROL (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CONTROL (qno))); +dev_info (dev,"R[%d]_IN_ENABLE[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_ENABLE (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (qno))); +dev_info (dev,"R[%d]_IN_INSTR_BADDR[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_INSTR_BADDR (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_BADDR (qno))); +dev_info (dev,"R[%d]_IN_INSTR_RSIZE[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_INSTR_RSIZE (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_RSIZE (qno))); +dev_info (dev,"R[%d]_IN_CNTS[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_CNTS (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CNTS (qno))); +dev_info (dev,"R[%d]_IN_INT_LEVELS[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_INT_LEVELS (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (qno))); +dev_info (dev,"R[%d]_IN_PKT_CNT[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_PKT_CNT (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_PKT_CNT (qno))); +dev_info (dev,"R[%d]_IN_BYTE_CNT[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_BYTE_CNT (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_BYTE_CNT (qno))); + +dev_info (dev,"OQ-%d register dump\n" , qno); +dev_info (dev,"R[%d]_OUT_SLIST_DBELL[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_SLIST_DBELL (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_DBELL (qno))); +dev_info (dev,"R[%d]_OUT_CONTROL[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_CONTROL (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (qno))); +dev_info (dev,"R[%d]_OUT_ENABLE[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_ENABLE (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (qno))); +dev_info (dev,"R[%d]_OUT_SLIST_BADDR[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_SLIST_BADDR (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_BADDR (qno))); +dev_info (dev,"R[%d]_OUT_SLIST_RSIZE[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_SLIST_RSIZE (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_RSIZE (qno))); +dev_info (dev,"R[%d]_OUT_CNTS[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_CNTS (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CNTS (qno))); +dev_info (dev,"R[%d]_OUT_INT_LEVELS[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_INT_LEVELS (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (qno))); +dev_info (dev,"R[%d]_OUT_PKT_CNT[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_PKT_CNT (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_PKT_CNT (qno))); +dev_info (dev,"R[%d]_OUT_BYTE_CNT[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_BYTE_CNT (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_BYTE_CNT (qno))); +} + +/* Reset Hardware Tx queue */ +static int cn93_vf_reset_iq (struct octep_vf_device *oct,int q_no) +{ +u64 val =ULL (0 ); + +dev_dbg (&oct->pdev->dev,"Reset VF IQ-%d\n" , q_no); + +/* Disable the Tx/Instruction Ring */ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (q_no), val); + +/* clear the Instruction Ring packet/byte counts and doorbell CSRs */ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q_no), val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_PKT_CNT (q_no), val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_BYTE_CNT (q_no), val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_BADDR (q_no), val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_RSIZE (q_no), val); + + val =GENMASK_ULL (31 ,0 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_DBELL (q_no), val); + + val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CNTS (q_no)); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_CNTS (q_no), + val &GENMASK_ULL (31 ,0 )); + +return 0 ; +} + +/* Reset Hardware Rx queue */ +static void cn93_vf_reset_oq (struct octep_vf_device *oct,int q_no) +{ +u64 val =ULL (0 ); + +/* Disable Output (Rx) Ring */ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (q_no), val); + +/* Clear count CSRs */ + val =octep_vf_read_csr (oct,CN93_VF_SDP_R_OUT_CNTS (q_no)); +octep_vf_write_csr (oct,CN93_VF_SDP_R_OUT_CNTS (q_no), val); + +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_PKT_CNT (q_no),GENMASK_ULL (35 ,0 )); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_DBELL (q_no),GENMASK_ULL (31 ,0 )); +} +/* Reset all hardware Tx/Rx queues */ static void octep_vf_reset_io_queues_cn93 (struct octep_vf_device *oct) { +struct pci_dev *pdev = oct->pdev; +int q; + +dev_dbg (&pdev->dev,"Reset OCTEP_CN93 VF IO Queues\n" ); + +for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +cn93_vf_reset_iq (oct, q); +cn93_vf_reset_oq (oct, q); + } }/* Initialize configuration limits and initial active config */
@@ -46,78 +162,296 @@ static void octep_vf_init_config_cn93_vf(struct octep_vf_device *oct)/* Setup registers for a hardware Tx Queue */ static void octep_vf_setup_iq_regs_cn93 (struct octep_vf_device *oct,int iq_no) { +struct octep_vf_iq *iq = oct->iq[iq_no]; +u32 reset_instr_cnt; +u64 reg_val; + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CONTROL (iq_no)); + +/* wait for IDLE to set to 1 */ +if (!(reg_val &CN93_VF_R_IN_CTL_IDLE )) { +do { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CONTROL (iq_no)); + }while (!(reg_val &CN93_VF_R_IN_CTL_IDLE )); + } + reg_val |=CN93_VF_R_IN_CTL_RDSIZE ; + reg_val |=CN93_VF_R_IN_CTL_IS_64B ; + reg_val |=CN93_VF_R_IN_CTL_ESR ; +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_CONTROL (iq_no), reg_val); + +/* Write the start of the input queue's ring and its size */ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_BADDR (iq_no), iq->desc_ring_dma); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_RSIZE (iq_no), iq->max_count); + +/* Remember the doorbell & instruction count register addr for this queue */ + iq->doorbell_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_IN_INSTR_DBELL (iq_no); + iq->inst_cnt_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_IN_CNTS (iq_no); + iq->intr_lvl_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_IN_INT_LEVELS (iq_no); + +/* Store the current instruction counter (used in flush_iq calculation) */ + reset_instr_cnt =readl (iq->inst_cnt_reg); +writel (reset_instr_cnt, iq->inst_cnt_reg); + +/* INTR_THRESHOLD is set to max(FFFFFFFF) to disable the INTR */ + reg_val =CFG_GET_IQ_INTR_THRESHOLD (oct->conf) &GENMASK_ULL (31 ,0 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (iq_no), reg_val); }/* Setup registers for a hardware Rx Queue */ static void octep_vf_setup_oq_regs_cn93 (struct octep_vf_device *oct,int oq_no) { +struct octep_vf_oq *oq = oct->oq[oq_no]; +u32 time_threshold =0 ; +u64 oq_ctl =ULL (0 ); +u64 reg_val; + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no)); + +/* wait for IDLE to set to 1 */ +if (!(reg_val &CN93_VF_R_OUT_CTL_IDLE )) { +do { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no)); + }while (!(reg_val &CN93_VF_R_OUT_CTL_IDLE )); + } + + reg_val &= ~(CN93_VF_R_OUT_CTL_IMODE ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ROR_P ); + reg_val &= ~(CN93_VF_R_OUT_CTL_NSR_P ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ROR_I ); + reg_val &= ~(CN93_VF_R_OUT_CTL_NSR_I ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ES_I ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ROR_D ); + reg_val &= ~(CN93_VF_R_OUT_CTL_NSR_D ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ES_D ); + reg_val |= (CN93_VF_R_OUT_CTL_ES_P ); + +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no), reg_val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_BADDR (oq_no), oq->desc_ring_dma); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_RSIZE (oq_no), oq->max_count); + + oq_ctl =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no)); + oq_ctl &= ~GENMASK_ULL (22 ,0 );//clear the ISIZE and BSIZE (22-0) + oq_ctl |= (oq->buffer_size &GENMASK_ULL (15 ,0 ));//populate the BSIZE (15-0) +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no), oq_ctl); + +/* Get the mapped address of the pkt_sent and pkts_credit regs */ + oq->pkts_sent_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_OUT_CNTS (oq_no); + oq->pkts_credit_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_OUT_SLIST_DBELL (oq_no); + + time_threshold =CFG_GET_OQ_INTR_TIME (oct->conf); + reg_val = ((u64 )time_threshold <<32 ) |CFG_GET_OQ_INTR_PKT (oct->conf); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (oq_no), reg_val); }/* Setup registers for a VF mailbox */ static void octep_vf_setup_mbox_regs_cn93 (struct octep_vf_device *oct,int q_no) { +struct octep_vf_mbox *mbox = oct->mbox; + +/* PF to VF DATA reg. VF reads from this reg */ + mbox->mbox_read_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_MBOX_PF_VF_DATA (q_no); + +/* VF mbox interrupt reg */ + mbox->mbox_int_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_MBOX_PF_VF_INT (q_no); + +/* VF to PF DATA reg. VF writes into this reg */ + mbox->mbox_write_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_MBOX_VF_PF_DATA (q_no); +} + +/* Mailbox Interrupt handler */ +static void cn93_handle_vf_mbox_intr (struct octep_vf_device *oct) +{ +if (oct->mbox) +schedule_work (&oct->mbox->wk.work); +else +dev_err (&oct->pdev->dev,"cannot schedule work on invalid mbox\n" ); }/* Tx/Rx queue interrupt handler */ static irqreturn_t octep_vf_ioq_intr_handler_cn93 (void *data) { +struct octep_vf_ioq_vector *vector = data; +struct octep_vf_device *oct; +struct octep_vf_oq *oq; +u64 reg_val =ULL (0 ); + + oct = vector->octep_vf_dev; + oq = vector->oq; +/* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */ +if (oq->q_no ==0 ) { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_MBOX_PF_VF_INT (0 )); +if (reg_val &CN93_VF_SDP_R_MBOX_PF_VF_INT_STATUS ) { +cn93_handle_vf_mbox_intr (oct); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_MBOX_PF_VF_INT (0 ), reg_val); + } + } +napi_schedule_irqoff (oq->napi);return IRQ_HANDLED ; }/* Re-initialize Octeon hardware registers */ static void octep_vf_reinit_regs_cn93 (struct octep_vf_device *oct) { +u32 i; + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) + oct->hw_ops.setup_iq_regs (oct, i); + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) + oct->hw_ops.setup_oq_regs (oct, i); + + oct->hw_ops.enable_interrupts (oct); + oct->hw_ops.enable_io_queues (oct); + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) +writel (oct->oq[i]->max_count, oct->oq[i]->pkts_credit_reg); }/* Enable all interrupts */ static void octep_vf_enable_interrupts_cn93 (struct octep_vf_device *oct) { +int num_rings, q; +u64 reg_val; + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q), reg_val); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (q)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (q), reg_val); + } +/* Enable PF to VF mbox interrupt by setting 2nd bit*/ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_MBOX_PF_VF_INT (0 ), +CN93_VF_SDP_R_MBOX_PF_VF_INT_ENAB ); }/* Disable all interrupts */ static void octep_vf_disable_interrupts_cn93 (struct octep_vf_device *oct) { +int num_rings, q; +u64 reg_val; + +/* Disable PF to VF mbox interrupt by setting 2nd bit*/ +if (oct->mbox) +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_MBOX_PF_VF_INT (0 ),0x0 ); + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q)); + reg_val &= ~BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q), reg_val); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (q)); + reg_val &= ~BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (q), reg_val); + } }/* Get new Octeon Read Index: index of descriptor that Octeon reads next. */ static u32 octep_vf_update_iq_read_index_cn93 (struct octep_vf_iq *iq) { -return 0 ; +u32 pkt_in_done =readl (iq->inst_cnt_reg); +u32 last_done, new_idx; + + last_done = pkt_in_done - iq->pkt_in_done; + iq->pkt_in_done = pkt_in_done; + + new_idx = (iq->octep_vf_read_index + last_done) % iq->max_count; + +return new_idx; }/* Enable a hardware Tx Queue */ static void octep_vf_enable_iq_cn93 (struct octep_vf_device *oct,int iq_no) { +u64 loop =HZ ; +u64 reg_val; + +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_DBELL (iq_no),GENMASK_ULL (31 ,0 )); + +while (octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_DBELL (iq_no)) && + loop--) { +schedule_timeout_interruptible (1 ); + } + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (iq_no)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (iq_no), reg_val); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (iq_no)); + reg_val |=ULL (1 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (iq_no), reg_val); }/* Enable a hardware Rx Queue */ static void octep_vf_enable_oq_cn93 (struct octep_vf_device *oct,int oq_no) { +u64 reg_val =ULL (0 ); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (oq_no)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (oq_no), reg_val); + +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_DBELL (oq_no),GENMASK_ULL (31 ,0 )); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (oq_no)); + reg_val |=ULL (1 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (oq_no), reg_val); }/* Enable all hardware Tx/Rx Queues assigned to VF */ static void octep_vf_enable_io_queues_cn93 (struct octep_vf_device *oct) { +u8 q; + +for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +octep_vf_enable_iq_cn93 (oct, q); +octep_vf_enable_oq_cn93 (oct, q); + } }/* Disable a hardware Tx Queue assigned to VF */ static void octep_vf_disable_iq_cn93 (struct octep_vf_device *oct,int iq_no) { +u64 reg_val =ULL (0 ); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (iq_no)); + reg_val &= ~ULL (1 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (iq_no), reg_val); }/* Disable a hardware Rx Queue assigned to VF */ static void octep_vf_disable_oq_cn93 (struct octep_vf_device *oct,int oq_no) { +u64 reg_val =ULL (0 ); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (oq_no)); + reg_val &= ~ULL (1 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (oq_no), reg_val); }/* Disable all hardware Tx/Rx Queues assigned to VF */ static void octep_vf_disable_io_queues_cn93 (struct octep_vf_device *oct) { +int q =0 ; + +for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +octep_vf_disable_iq_cn93 (oct, q); +octep_vf_disable_oq_cn93 (oct, q); + } }/* Dump hardware registers (including Tx/Rx queues) for debugging. */ static void octep_vf_dump_registers_cn93 (struct octep_vf_device *oct) { +u8 num_rings, q; + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) +cn93_vf_dump_q_regs (oct, q); }/**
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c +345 -1
432 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH net-next v4 2/8] octeon_ep_vf: add hardware configuration APIs
Quoted 87 lines · Shinas Rasheed
Implement hardware resource init and shutdown helper APIs, like hardware Tx/Rx queue
init/enable/disable/reset.Signed-off-by Shinas Rasheed <[email protected]>---
V4:
- No changesV3: https://lore.kernel.org/all/[email protected]/
- Replaced masks and ULL declarations withGENMASK_ULL(),ULL()and otherlinux/bits.hmacros
- Corrected declarations to conform to xmas tree formatV2: https://lore.kernel.org/all/[email protected]/
- No changesV1: https://lore.kernel.org/all/[email protected]/
.../marvell/octeon_ep_vf/octep_vf_cn9k.c | 336 ++++++++++++++++- .../marvell/octeon_ep_vf/octep_vf_cnxk.c | 346 +++++++++++++++++- 2 files changed, 680 insertions(+), 2 deletions(-)drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +56
-0@@ -13,9 +13,125 @@#include "octep_vf_main.h" #include "octep_vf_regs_cn9k.h" +/* Dump useful hardware IQ/OQ CSRs for debug purpose */ +static void cn93_vf_dump_q_regs (struct octep_vf_device *oct,int qno) +{ +struct device *dev = &oct->pdev->dev; + +dev_info (dev,"IQ-%d register dump\n" , qno); +dev_info (dev,"R[%d]_IN_INSTR_DBELL[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_INSTR_DBELL (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_DBELL (qno))); +dev_info (dev,"R[%d]_IN_CONTROL[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_CONTROL (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CONTROL (qno))); +dev_info (dev,"R[%d]_IN_ENABLE[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_ENABLE (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (qno))); +dev_info (dev,"R[%d]_IN_INSTR_BADDR[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_INSTR_BADDR (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_BADDR (qno))); +dev_info (dev,"R[%d]_IN_INSTR_RSIZE[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_INSTR_RSIZE (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_RSIZE (qno))); +dev_info (dev,"R[%d]_IN_CNTS[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_CNTS (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CNTS (qno))); +dev_info (dev,"R[%d]_IN_INT_LEVELS[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_INT_LEVELS (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (qno))); +dev_info (dev,"R[%d]_IN_PKT_CNT[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_PKT_CNT (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_PKT_CNT (qno))); +dev_info (dev,"R[%d]_IN_BYTE_CNT[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_IN_BYTE_CNT (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_BYTE_CNT (qno))); + +dev_info (dev,"OQ-%d register dump\n" , qno); +dev_info (dev,"R[%d]_OUT_SLIST_DBELL[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_SLIST_DBELL (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_DBELL (qno))); +dev_info (dev,"R[%d]_OUT_CONTROL[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_CONTROL (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (qno))); +dev_info (dev,"R[%d]_OUT_ENABLE[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_ENABLE (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (qno))); +dev_info (dev,"R[%d]_OUT_SLIST_BADDR[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_SLIST_BADDR (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_BADDR (qno))); +dev_info (dev,"R[%d]_OUT_SLIST_RSIZE[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_SLIST_RSIZE (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_RSIZE (qno))); +dev_info (dev,"R[%d]_OUT_CNTS[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_CNTS (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CNTS (qno))); +dev_info (dev,"R[%d]_OUT_INT_LEVELS[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_INT_LEVELS (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (qno)));
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c line 81
Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +10
-0+dev_info (dev,"R[%d]_OUT_PKT_CNT[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_PKT_CNT (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_PKT_CNT (qno))); +dev_info (dev,"R[%d]_OUT_BYTE_CNT[0x%llx]: 0x%016llx\n" , + qno,CN93_VF_SDP_R_OUT_BYTE_CNT (qno), +octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_BYTE_CNT (qno))); +} + +/* Reset Hardware Tx queue */ +static int cn93_vf_reset_iq (struct octep_vf_device *oct,int q_no)
[Kalesh] You can change it to a void function as it return 0 always and the caller is not checking return status.
Quoted 162 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +142
-0+{ +u64 val =ULL (0 ); + +dev_dbg (&oct->pdev->dev,"Reset VF IQ-%d\n" , q_no); + +/* Disable the Tx/Instruction Ring */ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (q_no), val); + +/* clear the Instruction Ring packet/byte counts and doorbell CSRs */ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q_no), val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_PKT_CNT (q_no), val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_BYTE_CNT (q_no), val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_BADDR (q_no), val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_RSIZE (q_no), val); + + val =GENMASK_ULL (31 ,0 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_DBELL (q_no), val); + + val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CNTS (q_no)); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_CNTS (q_no), + val &GENMASK_ULL (31 ,0 )); + +return 0 ; +} + +/* Reset Hardware Rx queue */ +static void cn93_vf_reset_oq (struct octep_vf_device *oct,int q_no) +{ +u64 val =ULL (0 ); + +/* Disable Output (Rx) Ring */ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (q_no), val); + +/* Clear count CSRs */ + val =octep_vf_read_csr (oct,CN93_VF_SDP_R_OUT_CNTS (q_no)); +octep_vf_write_csr (oct,CN93_VF_SDP_R_OUT_CNTS (q_no), val); + +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_PKT_CNT (q_no),GENMASK_ULL (35 ,0 )); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_DBELL (q_no),GENMASK_ULL (31 ,0 )); +} +/* Reset all hardware Tx/Rx queues */ static void octep_vf_reset_io_queues_cn93 (struct octep_vf_device *oct) { +struct pci_dev *pdev = oct->pdev; +int q; + +dev_dbg (&pdev->dev,"Reset OCTEP_CN93 VF IO Queues\n" ); + +for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +cn93_vf_reset_iq (oct, q); +cn93_vf_reset_oq (oct, q); + } }/* Initialize configuration limits and initial active config */ @@ -46,78 +162,296 @@ static void octep_vf_init_config_cn93_vf(struct octep_vf_device *oct)/* Setup registers for a hardware Tx Queue */ static void octep_vf_setup_iq_regs_cn93 (struct octep_vf_device *oct,int iq_no) { +struct octep_vf_iq *iq = oct->iq[iq_no]; +u32 reset_instr_cnt; +u64 reg_val; + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CONTROL (iq_no)); + +/* wait for IDLE to set to 1 */ +if (!(reg_val &CN93_VF_R_IN_CTL_IDLE )) { +do { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_CONTROL (iq_no)); + }while (!(reg_val &CN93_VF_R_IN_CTL_IDLE )); + } + reg_val |=CN93_VF_R_IN_CTL_RDSIZE ; + reg_val |=CN93_VF_R_IN_CTL_IS_64B ; + reg_val |=CN93_VF_R_IN_CTL_ESR ; +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_CONTROL (iq_no), reg_val); + +/* Write the start of the input queue's ring and its size */ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_BADDR (iq_no), iq->desc_ring_dma); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_RSIZE (iq_no), iq->max_count); + +/* Remember the doorbell & instruction count register addr for this queue */ + iq->doorbell_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_IN_INSTR_DBELL (iq_no); + iq->inst_cnt_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_IN_CNTS (iq_no); + iq->intr_lvl_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_IN_INT_LEVELS (iq_no); + +/* Store the current instruction counter (used in flush_iq calculation) */ + reset_instr_cnt =readl (iq->inst_cnt_reg); +writel (reset_instr_cnt, iq->inst_cnt_reg); + +/* INTR_THRESHOLD is set to max(FFFFFFFF) to disable the INTR */ + reg_val =CFG_GET_IQ_INTR_THRESHOLD (oct->conf) &GENMASK_ULL (31 ,0 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (iq_no), reg_val); }/* Setup registers for a hardware Rx Queue */ static void octep_vf_setup_oq_regs_cn93 (struct octep_vf_device *oct,int oq_no) { +struct octep_vf_oq *oq = oct->oq[oq_no]; +u32 time_threshold =0 ; +u64 oq_ctl =ULL (0 ); +u64 reg_val; + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no)); + +/* wait for IDLE to set to 1 */ +if (!(reg_val &CN93_VF_R_OUT_CTL_IDLE )) { +do { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no)); + }while (!(reg_val &CN93_VF_R_OUT_CTL_IDLE )); + } + + reg_val &= ~(CN93_VF_R_OUT_CTL_IMODE ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ROR_P ); + reg_val &= ~(CN93_VF_R_OUT_CTL_NSR_P ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ROR_I ); + reg_val &= ~(CN93_VF_R_OUT_CTL_NSR_I ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ES_I ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ROR_D ); + reg_val &= ~(CN93_VF_R_OUT_CTL_NSR_D ); + reg_val &= ~(CN93_VF_R_OUT_CTL_ES_D ); + reg_val |= (CN93_VF_R_OUT_CTL_ES_P ); + +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no), reg_val); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_BADDR (oq_no), oq->desc_ring_dma); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_RSIZE (oq_no), oq->max_count); + + oq_ctl =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no)); + oq_ctl &= ~GENMASK_ULL (22 ,0 );//clear the ISIZE and BSIZE (22-0) + oq_ctl |= (oq->buffer_size &GENMASK_ULL (15 ,0 ));//populate the BSIZE (15-0) +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_CONTROL (oq_no), oq_ctl); + +/* Get the mapped address of the pkt_sent and pkts_credit regs */ + oq->pkts_sent_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_OUT_CNTS (oq_no); + oq->pkts_credit_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_OUT_SLIST_DBELL (oq_no); + + time_threshold =CFG_GET_OQ_INTR_TIME (oct->conf); + reg_val = ((u64 )time_threshold <<32 ) |CFG_GET_OQ_INTR_PKT (oct->conf); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (oq_no), reg_val); }/* Setup registers for a VF mailbox */ static void octep_vf_setup_mbox_regs_cn93 (struct octep_vf_device *oct,int q_no) { +struct octep_vf_mbox *mbox = oct->mbox; + +/* PF to VF DATA reg. VF reads from this reg */ + mbox->mbox_read_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_MBOX_PF_VF_DATA (q_no); + +/* VF mbox interrupt reg */ + mbox->mbox_int_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_MBOX_PF_VF_INT (q_no); + +/* VF to PF DATA reg. VF writes into this reg */ + mbox->mbox_write_reg = oct->mmio.hw_addr +CN93_VF_SDP_R_MBOX_VF_PF_DATA (q_no); +} + +/* Mailbox Interrupt handler */ +static void cn93_handle_vf_mbox_intr (struct octep_vf_device *oct) +{ +if (oct->mbox) +schedule_work (&oct->mbox->wk.work); +else
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c static void octep_vf_init_config_cn93_vf(struct octep_vf_device *oct) · line 276
Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +5
-0+dev_err (&oct->pdev->dev,"cannot schedule work on invalid mbox\n" ); }/* Tx/Rx queue interrupt handler */ static irqreturn_t octep_vf_ioq_intr_handler_cn93 (void *data) { +struct octep_vf_ioq_vector *vector = data; +struct octep_vf_device *oct; +struct octep_vf_oq *oq; +u64 reg_val =ULL (0 );
[Kalesh] Do you really want to initialize reg_val here?
Quoted 107 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +80
-1+ + oct = vector->octep_vf_dev; + oq = vector->oq; +/* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */ +if (oq->q_no ==0 ) { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_MBOX_PF_VF_INT (0 )); +if (reg_val &CN93_VF_SDP_R_MBOX_PF_VF_INT_STATUS ) { +cn93_handle_vf_mbox_intr (oct); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_MBOX_PF_VF_INT (0 ), reg_val); + } + } +napi_schedule_irqoff (oq->napi);return IRQ_HANDLED ; }/* Re-initialize Octeon hardware registers */ static void octep_vf_reinit_regs_cn93 (struct octep_vf_device *oct) { +u32 i; + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) + oct->hw_ops.setup_iq_regs (oct, i); + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) + oct->hw_ops.setup_oq_regs (oct, i); + + oct->hw_ops.enable_interrupts (oct); + oct->hw_ops.enable_io_queues (oct); + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) +writel (oct->oq[i]->max_count, oct->oq[i]->pkts_credit_reg); }/* Enable all interrupts */ static void octep_vf_enable_interrupts_cn93 (struct octep_vf_device *oct) { +int num_rings, q; +u64 reg_val; + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q), reg_val); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (q)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (q), reg_val); + } +/* Enable PF to VF mbox interrupt by setting 2nd bit*/ +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_MBOX_PF_VF_INT (0 ), +CN93_VF_SDP_R_MBOX_PF_VF_INT_ENAB ); }/* Disable all interrupts */ static void octep_vf_disable_interrupts_cn93 (struct octep_vf_device *oct) { +int num_rings, q; +u64 reg_val; + +/* Disable PF to VF mbox interrupt by setting 2nd bit*/ +if (oct->mbox) +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_MBOX_PF_VF_INT (0 ),0x0 ); + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) { + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q)); + reg_val &= ~BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (q), reg_val); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (q)); + reg_val &= ~BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (q), reg_val); + } }/* Get new Octeon Read Index: index of descriptor that Octeon reads next. */ static u32 octep_vf_update_iq_read_index_cn93 (struct octep_vf_iq *iq) { -return 0 ; +u32 pkt_in_done =readl (iq->inst_cnt_reg); +u32 last_done, new_idx; + + last_done = pkt_in_done - iq->pkt_in_done; + iq->pkt_in_done = pkt_in_done; + + new_idx = (iq->octep_vf_read_index + last_done) % iq->max_count; + +return new_idx; }/* Enable a hardware Tx Queue */ static void octep_vf_enable_iq_cn93 (struct octep_vf_device *oct,int iq_no) { +u64 loop =HZ ; +u64 reg_val; + +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_DBELL (iq_no),GENMASK_ULL (31 ,0 )); + +while (octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INSTR_DBELL (iq_no)) && + loop--) { +schedule_timeout_interruptible (1 ); + } + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (iq_no)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_INT_LEVELS (iq_no), reg_val);
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c static void octep_vf_init_config_cn93_vf(struct octep_vf_device *oct) · line 392
Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +5
-0+ + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (iq_no)); + reg_val |=ULL (1 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (iq_no), reg_val); }/* Enable a hardware Rx Queue */ static void octep_vf_enable_oq_cn93 (struct octep_vf_device *oct,int oq_no) { +u64 reg_val =ULL (0 );
[Kalesh] Same comment as above
Quoted 17 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +12
-0+ + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (oq_no)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_INT_LEVELS (oq_no), reg_val); + +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_SLIST_DBELL (oq_no),GENMASK_ULL (31 ,0 )); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (oq_no)); + reg_val |=ULL (1 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (oq_no), reg_val); }/* Enable all hardware Tx/Rx Queues assigned to VF */ static void octep_vf_enable_io_queues_cn93 (struct octep_vf_device *oct) { +u8 q; +
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c static void octep_vf_init_config_cn93_vf(struct octep_vf_device *oct) · line 419
Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +5
-0+for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +octep_vf_enable_iq_cn93 (oct, q); +octep_vf_enable_oq_cn93 (oct, q); + } }/* Disable a hardware Tx Queue assigned to VF */ static void octep_vf_disable_iq_cn93 (struct octep_vf_device *oct,int iq_no) { +u64 reg_val =ULL (0 );
[Kalesh] Same comment as above and function below
Quoted 105 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +20
-0+ + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (iq_no)); + reg_val &= ~ULL (1 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_IN_ENABLE (iq_no), reg_val); }/* Disable a hardware Rx Queue assigned to VF */ static void octep_vf_disable_oq_cn93 (struct octep_vf_device *oct,int oq_no) { +u64 reg_val =ULL (0 ); + + reg_val =octep_vf_read_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (oq_no)); + reg_val &= ~ULL (1 ); +octep_vf_write_csr64 (oct,CN93_VF_SDP_R_OUT_ENABLE (oq_no), reg_val); }/* Disable all hardware Tx/Rx Queues assigned to VF */ static void octep_vf_disable_io_queues_cn93 (struct octep_vf_device *oct) { +int q =0 ; + +for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +octep_vf_disable_iq_cn93 (oct, q); +octep_vf_disable_oq_cn93 (oct, q); + } }/* Dump hardware registers (including Tx/Rx queues) for debugging. */ static void octep_vf_dump_registers_cn93 (struct octep_vf_device *oct) { +u8 num_rings, q; + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) +cn93_vf_dump_q_regs (oct, q); }/** drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c +59
-0@@ -13,9 +13,127 @@#include "octep_vf_main.h" #include "octep_vf_regs_cnxk.h" +/* Dump useful hardware IQ/OQ CSRs for debug purpose */ +static void cnxk_vf_dump_q_regs (struct octep_vf_device *oct,int qno) +{ +struct device *dev = &oct->pdev->dev; + +dev_info (dev,"IQ-%d register dump\n" , qno); +dev_info (dev,"R[%d]_IN_INSTR_DBELL[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_INSTR_DBELL (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_DBELL (qno))); +dev_info (dev,"R[%d]_IN_CONTROL[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_CONTROL (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_CONTROL (qno))); +dev_info (dev,"R[%d]_IN_ENABLE[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_ENABLE (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_ENABLE (qno))); +dev_info (dev,"R[%d]_IN_INSTR_BADDR[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_INSTR_BADDR (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_BADDR (qno))); +dev_info (dev,"R[%d]_IN_INSTR_RSIZE[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_INSTR_RSIZE (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_RSIZE (qno))); +dev_info (dev,"R[%d]_IN_CNTS[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_CNTS (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_CNTS (qno))); +dev_info (dev,"R[%d]_IN_INT_LEVELS[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_INT_LEVELS (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (qno))); +dev_info (dev,"R[%d]_IN_PKT_CNT[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_PKT_CNT (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_PKT_CNT (qno))); +dev_info (dev,"R[%d]_IN_BYTE_CNT[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_IN_BYTE_CNT (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_BYTE_CNT (qno))); + +dev_info (dev,"OQ-%d register dump\n" , qno); +dev_info (dev,"R[%d]_OUT_SLIST_DBELL[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_SLIST_DBELL (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_SLIST_DBELL (qno))); +dev_info (dev,"R[%d]_OUT_CONTROL[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_CONTROL (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_CONTROL (qno))); +dev_info (dev,"R[%d]_OUT_ENABLE[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_ENABLE (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_ENABLE (qno))); +dev_info (dev,"R[%d]_OUT_SLIST_BADDR[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_SLIST_BADDR (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_SLIST_BADDR (qno))); +dev_info (dev,"R[%d]_OUT_SLIST_RSIZE[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_SLIST_RSIZE (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_SLIST_RSIZE (qno))); +dev_info (dev,"R[%d]_OUT_CNTS[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_CNTS (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_CNTS (qno))); +dev_info (dev,"R[%d]_OUT_INT_LEVELS[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_INT_LEVELS (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_INT_LEVELS (qno))); +dev_info (dev,"R[%d]_OUT_PKT_CNT[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_PKT_CNT (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_PKT_CNT (qno)));
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c line 84
Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c +10
-0+dev_info (dev,"R[%d]_OUT_BYTE_CNT[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_OUT_BYTE_CNT (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_BYTE_CNT (qno))); +dev_info (dev,"R[%d]_ERR_TYPE[0x%llx]: 0x%016llx\n" , + qno,CNXK_VF_SDP_R_ERR_TYPE (qno), +octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_ERR_TYPE (qno))); +} + +/* Reset Hardware Tx queue */ +static int cnxk_vf_reset_iq (struct octep_vf_device *oct,int q_no)
[Kalesh] You can change it to a void function as it return 0 always and the caller is not checking return status.
Quoted 365 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c +276
-2+{ +u64 val =ULL (0 ); + +dev_dbg (&oct->pdev->dev,"Reset VF IQ-%d\n" , q_no); + +/* Disable the Tx/Instruction Ring */ +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_ENABLE (q_no), val); + +/* clear the Instruction Ring packet/byte counts and doorbell CSRs */ +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (q_no), val); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_PKT_CNT (q_no), val); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_BYTE_CNT (q_no), val); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_BADDR (q_no), val); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_RSIZE (q_no), val); + + val =GENMASK_ULL (31 ,0 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_DBELL (q_no), val); + + val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_CNTS (q_no)); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_CNTS (q_no), val &GENMASK_ULL (31 ,0 )); + +return 0 ; +} + +/* Reset Hardware Rx queue */ +static void cnxk_vf_reset_oq (struct octep_vf_device *oct,int q_no) +{ +u64 val =ULL (0 ); + +/* Disable Output (Rx) Ring */ +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_ENABLE (q_no), val); + +/* Clear count CSRs */ + val =octep_vf_read_csr (oct,CNXK_VF_SDP_R_OUT_CNTS (q_no)); +octep_vf_write_csr (oct,CNXK_VF_SDP_R_OUT_CNTS (q_no), val); + +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_PKT_CNT (q_no),GENMASK_ULL (35 ,0 )); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_SLIST_DBELL (q_no),GENMASK_ULL (31 ,0 )); +} +/* Reset all hardware Tx/Rx queues */ static void octep_vf_reset_io_queues_cnxk (struct octep_vf_device *oct) { +struct pci_dev *pdev = oct->pdev; +int q; + +dev_dbg (&pdev->dev,"Reset OCTEP_CNXK VF IO Queues\n" ); + +for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +cnxk_vf_reset_iq (oct, q); +cnxk_vf_reset_oq (oct, q); + } }/* Initialize configuration limits and initial active config */ @@ -47,78 +165,304 @@ static void octep_vf_init_config_cnxk_vf(struct octep_vf_device *oct)/* Setup registers for a hardware Tx Queue */ static void octep_vf_setup_iq_regs_cnxk (struct octep_vf_device *oct,int iq_no) { +struct octep_vf_iq *iq = oct->iq[iq_no]; +u32 reset_instr_cnt; +u64 reg_val; + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_CONTROL (iq_no)); + +/* wait for IDLE to set to 1 */ +if (!(reg_val &CNXK_VF_R_IN_CTL_IDLE )) { +do { + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_CONTROL (iq_no)); + }while (!(reg_val &CNXK_VF_R_IN_CTL_IDLE )); + } + reg_val |=CNXK_VF_R_IN_CTL_RDSIZE ; + reg_val |=CNXK_VF_R_IN_CTL_IS_64B ; + reg_val |=CNXK_VF_R_IN_CTL_ESR ; +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_CONTROL (iq_no), reg_val); + +/* Write the start of the input queue's ring and its size */ +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_BADDR (iq_no), iq->desc_ring_dma); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_RSIZE (iq_no), iq->max_count); + +/* Remember the doorbell & instruction count register addr for this queue */ + iq->doorbell_reg = oct->mmio.hw_addr +CNXK_VF_SDP_R_IN_INSTR_DBELL (iq_no); + iq->inst_cnt_reg = oct->mmio.hw_addr +CNXK_VF_SDP_R_IN_CNTS (iq_no); + iq->intr_lvl_reg = oct->mmio.hw_addr +CNXK_VF_SDP_R_IN_INT_LEVELS (iq_no); + +/* Store the current instruction counter (used in flush_iq calculation) */ + reset_instr_cnt =readl (iq->inst_cnt_reg); +writel (reset_instr_cnt, iq->inst_cnt_reg); + +/* INTR_THRESHOLD is set to max(FFFFFFFF) to disable the INTR */ + reg_val =CFG_GET_IQ_INTR_THRESHOLD (oct->conf) &GENMASK_ULL (31 ,0 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (iq_no), reg_val); }/* Setup registers for a hardware Rx Queue */ static void octep_vf_setup_oq_regs_cnxk (struct octep_vf_device *oct,int oq_no) { +struct octep_vf_oq *oq = oct->oq[oq_no]; +u32 time_threshold =0 ; +u64 oq_ctl =ULL (0 ); +u64 reg_val; + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_CONTROL (oq_no)); + +/* wait for IDLE to set to 1 */ +if (!(reg_val &CNXK_VF_R_OUT_CTL_IDLE )) { +do { + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_CONTROL (oq_no)); + }while (!(reg_val &CNXK_VF_R_OUT_CTL_IDLE )); + } + + reg_val &= ~(CNXK_VF_R_OUT_CTL_IMODE ); + reg_val &= ~(CNXK_VF_R_OUT_CTL_ROR_P ); + reg_val &= ~(CNXK_VF_R_OUT_CTL_NSR_P ); + reg_val &= ~(CNXK_VF_R_OUT_CTL_ROR_I ); + reg_val &= ~(CNXK_VF_R_OUT_CTL_NSR_I ); + reg_val &= ~(CNXK_VF_R_OUT_CTL_ES_I ); + reg_val &= ~(CNXK_VF_R_OUT_CTL_ROR_D ); + reg_val &= ~(CNXK_VF_R_OUT_CTL_NSR_D ); + reg_val &= ~(CNXK_VF_R_OUT_CTL_ES_D ); + reg_val |= (CNXK_VF_R_OUT_CTL_ES_P ); + +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_CONTROL (oq_no), reg_val); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_SLIST_BADDR (oq_no), oq->desc_ring_dma); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_SLIST_RSIZE (oq_no), oq->max_count); + + oq_ctl =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_CONTROL (oq_no)); +/* Clear the ISIZE and BSIZE (22-0) */ + oq_ctl &= ~GENMASK_ULL (22 ,0 ); +/* Populate the BSIZE (15-0) */ + oq_ctl |= (oq->buffer_size &GENMASK_ULL (15 ,0 )); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_CONTROL (oq_no), oq_ctl); + +/* Get the mapped address of the pkt_sent and pkts_credit regs */ + oq->pkts_sent_reg = oct->mmio.hw_addr +CNXK_VF_SDP_R_OUT_CNTS (oq_no); + oq->pkts_credit_reg = oct->mmio.hw_addr +CNXK_VF_SDP_R_OUT_SLIST_DBELL (oq_no); + + time_threshold =CFG_GET_OQ_INTR_TIME (oct->conf); + reg_val = ((u64 )time_threshold <<32 ) |CFG_GET_OQ_INTR_PKT (oct->conf); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_INT_LEVELS (oq_no), reg_val); + +/* set watermark for backpressure */ + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_WMARK (oq_no)); + reg_val &= ~GENMASK_ULL (31 ,0 ); + reg_val |=CFG_GET_OQ_WMARK (oct->conf); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_WMARK (oq_no), reg_val); }/* Setup registers for a VF mailbox */ static void octep_vf_setup_mbox_regs_cnxk (struct octep_vf_device *oct,int q_no) { +struct octep_vf_mbox *mbox = oct->mbox; + +/* PF to VF DATA reg. VF reads from this reg */ + mbox->mbox_read_reg = oct->mmio.hw_addr +CNXK_VF_SDP_R_MBOX_PF_VF_DATA (q_no); + +/* VF mbox interrupt reg */ + mbox->mbox_int_reg = oct->mmio.hw_addr +CNXK_VF_SDP_R_MBOX_PF_VF_INT (q_no); + +/* VF to PF DATA reg. VF writes into this reg */ + mbox->mbox_write_reg = oct->mmio.hw_addr +CNXK_VF_SDP_R_MBOX_VF_PF_DATA (q_no); +} + +/* Mailbox Interrupt handler */ +static void cnxk_handle_vf_mbox_intr (struct octep_vf_device *oct) +{ +if (oct->mbox) +schedule_work (&oct->mbox->wk.work); +else +dev_err (&oct->pdev->dev,"cannot schedule work on invalid mbox\n" ); }/* Tx/Rx queue interrupt handler */ static irqreturn_t octep_vf_ioq_intr_handler_cnxk (void *data) { +struct octep_vf_ioq_vector *vector = data; +struct octep_vf_device *oct; +struct octep_vf_oq *oq; +u64 reg_val =ULL (0 ); + + oct = vector->octep_vf_dev; + oq = vector->oq; +/* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */ +if (oq->q_no ==0 ) { + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_MBOX_PF_VF_INT (0 )); +if (reg_val &CNXK_VF_SDP_R_MBOX_PF_VF_INT_STATUS ) { +cnxk_handle_vf_mbox_intr (oct); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_MBOX_PF_VF_INT (0 ), reg_val); + } + } +napi_schedule_irqoff (oq->napi);return IRQ_HANDLED ; }/* Re-initialize Octeon hardware registers */ static void octep_vf_reinit_regs_cnxk (struct octep_vf_device *oct) { +u32 i; + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) + oct->hw_ops.setup_iq_regs (oct, i); + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) + oct->hw_ops.setup_oq_regs (oct, i); + + oct->hw_ops.enable_interrupts (oct); + oct->hw_ops.enable_io_queues (oct); + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) +writel (oct->oq[i]->max_count, oct->oq[i]->pkts_credit_reg); }/* Enable all interrupts */ static void octep_vf_enable_interrupts_cnxk (struct octep_vf_device *oct) { +int num_rings, q; +u64 reg_val; + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) { + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (q)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (q), reg_val); + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_INT_LEVELS (q)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_INT_LEVELS (q), reg_val); + } +/* Enable PF to VF mbox interrupt by setting 2nd bit*/ +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_MBOX_PF_VF_INT (0 ), +CNXK_VF_SDP_R_MBOX_PF_VF_INT_ENAB ); }/* Disable all interrupts */ static void octep_vf_disable_interrupts_cnxk (struct octep_vf_device *oct) { +int num_rings, q; +u64 reg_val; + +/* Disable PF to VF mbox interrupt by setting 2nd bit*/ +if (oct->mbox) +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_MBOX_PF_VF_INT (0 ),0x0 ); + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) { + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (q)); + reg_val &= ~BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (q), reg_val); + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_INT_LEVELS (q)); + reg_val &= ~BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_INT_LEVELS (q), reg_val); + } }/* Get new Octeon Read Index: index of descriptor that Octeon reads next. */ static u32 octep_vf_update_iq_read_index_cnxk (struct octep_vf_iq *iq) { -return 0 ; +u32 pkt_in_done =readl (iq->inst_cnt_reg); +u32 last_done, new_idx; + + last_done = pkt_in_done - iq->pkt_in_done; + iq->pkt_in_done = pkt_in_done; + + new_idx = (iq->octep_vf_read_index + last_done) % iq->max_count; + +return new_idx; }/* Enable a hardware Tx Queue */ static void octep_vf_enable_iq_cnxk (struct octep_vf_device *oct,int iq_no) { +u64 loop =HZ ; +u64 reg_val; + +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_DBELL (iq_no),GENMASK_ULL (31 ,0 )); + +while (octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_INSTR_DBELL (iq_no)) && + loop--) { +schedule_timeout_interruptible (1 ); + } + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (iq_no)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_INT_LEVELS (iq_no), reg_val); + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_ENABLE (iq_no)); + reg_val |=ULL (1 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_ENABLE (iq_no), reg_val); }/* Enable a hardware Rx Queue */ static void octep_vf_enable_oq_cnxk (struct octep_vf_device *oct,int oq_no) { +u64 reg_val =ULL (0 ); + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_INT_LEVELS (oq_no)); + reg_val |=BIT_ULL_MASK (62 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_INT_LEVELS (oq_no), reg_val); + +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_SLIST_DBELL (oq_no),GENMASK_ULL (31 ,0 )); + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_ENABLE (oq_no)); + reg_val |=ULL (1 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_ENABLE (oq_no), reg_val); }/* Enable all hardware Tx/Rx Queues assigned to VF */ static void octep_vf_enable_io_queues_cnxk (struct octep_vf_device *oct) { +u8 q; + +for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +octep_vf_enable_iq_cnxk (oct, q); +octep_vf_enable_oq_cnxk (oct, q); + } }/* Disable a hardware Tx Queue assigned to VF */ static void octep_vf_disable_iq_cnxk (struct octep_vf_device *oct,int iq_no) { +u64 reg_val =ULL (0 ); + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_IN_ENABLE (iq_no)); + reg_val &= ~ULL (1 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_IN_ENABLE (iq_no), reg_val); }/* Disable a hardware Rx Queue assigned to VF */ static void octep_vf_disable_oq_cnxk (struct octep_vf_device *oct,int oq_no) { +u64 reg_val =ULL (0 ); + + reg_val =octep_vf_read_csr64 (oct,CNXK_VF_SDP_R_OUT_ENABLE (oq_no)); + reg_val &= ~ULL (1 ); +octep_vf_write_csr64 (oct,CNXK_VF_SDP_R_OUT_ENABLE (oq_no), reg_val); }/* Disable all hardware Tx/Rx Queues assigned to VF */ static void octep_vf_disable_io_queues_cnxk (struct octep_vf_device *oct) { +int q =0 ; + +for (q =0 ; q <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); q++) { +octep_vf_disable_iq_cnxk (oct, q); +octep_vf_disable_oq_cnxk (oct, q); + } }/* Dump hardware registers (including Tx/Rx queues) for debugging. */ static void octep_vf_dump_registers_cnxk (struct octep_vf_device *oct) { +u8 num_rings, q; + + num_rings =CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); +for (q =0 ; q < num_rings; q++) +cnxk_vf_dump_q_regs (oct, q); }/** -- 2.25.1
Signature · 2 lines
Regards, Kalesh A P
Shinas Rasheed
maintainerPATCH v4 3/8 octeon_ep_vf: add VF-PF mailbox communication.
In reply to Shinas RasheedImplement VF-PF mailbox to send all control commands from VF to PF and receive responses and notifications from PF to VF.
---
V4:
- No changes
V3: https://lore.kernel.org/all/[email protected]/
- No changes
V2: https://lore.kernel.org/all/[email protected]/
- No changes
V1: https://lore.kernel.org/all/[email protected]/
.../marvell/octeon_ep_vf/octep_vf_main.c | 103 ++++++ .../marvell/octeon_ep_vf/octep_vf_main.h | 1 + .../marvell/octeon_ep_vf/octep_vf_mbox.c | 336 +++++++++++++++++- .../marvell/octeon_ep_vf/octep_vf_mbox.h | 143 +++++++- 4 files changed, 581 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c +103 -0
@@ -187,6 +187,19 @@ static netdev_tx_t octep_vf_start_xmit(struct sk_buff *skb,return NETDEV_TX_OK ; } +int octep_vf_get_link_info (struct octep_vf_device *oct) +{ +int ret, size; + + ret =octep_vf_mbox_bulk_read (oct,OCTEP_PFVF_MBOX_CMD_GET_LINK_INFO , + (u8 *)&oct->link_info, &size); +if (ret) { +dev_err (&oct->pdev->dev,"Get VF link info failed via VF Mbox\n" ); +return ret; + } +return 0 ; +} +/** * octep_vf_tx_timeout_task - work queue task to Handle Tx queue timeout. *
@@ -225,11 +238,84 @@ static void octep_vf_tx_timeout(struct net_device *netdev, unsigned int txqueue)queue_work (octep_vf_wq, &oct->tx_timeout_task); } +static int octep_vf_set_mac (struct net_device *netdev,void *p) +{ +struct octep_vf_device *oct =netdev_priv (netdev); +struct sockaddr *addr = (struct sockaddr *)p; +int err; + +if (!is_valid_ether_addr (addr->sa_data)) +return -EADDRNOTAVAIL ; + + err =octep_vf_mbox_set_mac_addr (oct, addr->sa_data); +if (err) +return err; + +memcpy (oct->mac_addr, addr->sa_data,ETH_ALEN ); +eth_hw_addr_set (netdev, addr->sa_data); + +return 0 ; +} + +static int octep_vf_change_mtu (struct net_device *netdev,int new_mtu) +{ +struct octep_vf_device *oct =netdev_priv (netdev); +struct octep_vf_iface_link_info *link_info; +int err; + + link_info = &oct->link_info; +if (link_info->mtu == new_mtu) +return 0 ; + + err =octep_vf_mbox_set_mtu (oct, new_mtu); +if (!err) { + oct->link_info.mtu = new_mtu; + netdev->mtu = new_mtu; + } +return err; +} + +static int octep_vf_set_features (struct net_device *netdev, +netdev_features_t features) +{ +struct octep_vf_device *oct =netdev_priv (netdev); +u16 rx_offloads =0 , tx_offloads =0 ; +int err; + +/* We only support features received from firmware */ +if ((features & netdev->hw_features) != features) +return -EINVAL ; + +if (features &NETIF_F_TSO ) + tx_offloads |=OCTEP_VF_TX_OFFLOAD_TSO ; + +if (features &NETIF_F_TSO6 ) + tx_offloads |=OCTEP_VF_TX_OFFLOAD_TSO ; + +if (features &NETIF_F_IP_CSUM ) + tx_offloads |=OCTEP_VF_TX_OFFLOAD_CKSUM ; + +if (features &NETIF_F_IPV6_CSUM ) + tx_offloads |=OCTEP_VF_TX_OFFLOAD_CKSUM ; + +if (features &NETIF_F_RXCSUM ) + rx_offloads |=OCTEP_VF_RX_OFFLOAD_CKSUM ; + + err =octep_vf_mbox_set_offloads (oct, tx_offloads, rx_offloads); +if (!err) + netdev->features = features; + +return err; +} +static const struct net_device_ops octep_vf_netdev_ops = { .ndo_open = octep_vf_open, .ndo_stop = octep_vf_stop, .ndo_start_xmit = octep_vf_start_xmit, .ndo_tx_timeout = octep_vf_tx_timeout, + .ndo_set_mac_address = octep_vf_set_mac, + .ndo_change_mtu = octep_vf_change_mtu, + .ndo_set_features = octep_vf_set_features, };static const char *octep_vf_devid_to_str (struct octep_vf_device *oct)
@@ -411,11 +497,28 @@ static int octep_vf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_mbox_version; } +if (octep_vf_mbox_get_fw_info (octep_vf_dev)) { +dev_err (&pdev->dev,"unable to get fw info\n" ); + err = -EINVAL ; + goto err_mbox_version; + } + netdev->hw_features =NETIF_F_SG ; +if (OCTEP_VF_TX_IP_CSUM (octep_vf_dev->fw_info.tx_ol_flags)) + netdev->hw_features |= (NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM ); + +if (OCTEP_VF_RX_IP_CSUM (octep_vf_dev->fw_info.rx_ol_flags)) + netdev->hw_features |=NETIF_F_RXCSUM ; + netdev->min_mtu =OCTEP_VF_MIN_MTU ; netdev->max_mtu =OCTEP_VF_MAX_MTU ; netdev->mtu =OCTEP_VF_DEFAULT_MTU ; +if (OCTEP_VF_TX_TSO (octep_vf_dev->fw_info.tx_ol_flags)) { + netdev->hw_features |=NETIF_F_TSO ; +netif_set_tso_max_size (netdev, netdev->max_mtu); + } + netdev->features |= netdev->hw_features;octep_vf_get_mac_addr (octep_vf_dev, octep_vf_dev->mac_addr);eth_hw_addr_set (netdev, octep_vf_dev->mac_addr);
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h +1 -0
@@ -327,6 +327,7 @@ void octep_vf_device_setup_cn93(struct octep_vf_device *oct);void octep_vf_device_setup_cnxk (struct octep_vf_device *oct);int octep_vf_iq_process_completions (struct octep_vf_iq *iq,u16 budget);int octep_vf_oq_process_rx (struct octep_vf_oq *oq,int budget); +int octep_vf_get_link_info (struct octep_vf_device *oct);int octep_vf_get_if_stats (struct octep_vf_device *oct);void octep_vf_mbox_work (struct work_struct *work);#endif /* _OCTEP_VF_MAIN_H_ */
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.c +335 -1
402 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.h +142 -1
152 lines not on this page · raw message
Signature · 1 line
2.25.1
Shinas Rasheed
maintainerPATCH v4 4/8 octeon_ep_vf: add Tx/Rx ring resource setup and cleanup
In reply to Shinas RasheedImplement Tx/Rx ring resource allocation and cleanup.
---
V4:
- No changes
V3: https://lore.kernel.org/all/[email protected]/
- Moved vfree and vzalloc null pointer casting corrections to this patch
- Corrected return values to follow standard kernel error codes
V2: https://lore.kernel.org/all/[email protected]/
- No changes
V1: https://lore.kernel.org/all/[email protected]/
.../marvell/octeon_ep_vf/octep_vf_rx.c | 223 +++++++++++++++++- .../marvell/octeon_ep_vf/octep_vf_tx.c | 216 +++++++++++++++++ 2 files changed, 438 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c +222 -1
@@ -7,10 +7,198 @@#include <linux/pci.h> #include <linux/etherdevice.h> +#include <linux/vmalloc.h> #include "octep_vf_config.h" #include "octep_vf_main.h" +static void octep_vf_oq_reset_indices (struct octep_vf_oq *oq) +{ + oq->host_read_idx =0 ; + oq->host_refill_idx =0 ; + oq->refill_count =0 ; + oq->last_pkt_count =0 ; + oq->pkts_pending =0 ; +} + +/** +* octep_vf_oq_fill_ring_buffers() - fill initial receive buffers for Rx ring. +* +* @oq: Octeon Rx queue data structure. +* +* Return: 0, if successfully filled receive buffers for all descriptors. +* -ENOMEM, if failed to allocate a buffer or failed to map for DMA. +*/ +static int octep_vf_oq_fill_ring_buffers (struct octep_vf_oq *oq) +{ +struct octep_vf_oq_desc_hw *desc_ring = oq->desc_ring; +struct page *page; +u32 i; + +for (i =0 ; i < oq->max_count; i++) { + page =dev_alloc_page (); +if (unlikely (!page)) { +dev_err (oq->dev,"Rx buffer alloc failed\n" ); + goto rx_buf_alloc_err; + } + desc_ring[i].buffer_ptr =dma_map_page (oq->dev, page,0 , +PAGE_SIZE , +DMA_FROM_DEVICE ); +if (dma_mapping_error (oq->dev, desc_ring[i].buffer_ptr)) { +dev_err (oq->dev, +"OQ-%d buffer alloc: DMA mapping error!\n" , + oq->q_no); + goto dma_map_err; + } + oq->buff_info[i].page = page; + } + +return 0 ; + +dma_map_err: +put_page (page); +rx_buf_alloc_err: +while (i) { + i--; +dma_unmap_page (oq->dev, desc_ring[i].buffer_ptr,PAGE_SIZE ,DMA_FROM_DEVICE ); +put_page (oq->buff_info[i].page); + oq->buff_info[i].page =NULL ; + } + +return -ENOMEM ; +} + +/** +* octep_vf_setup_oq() - Setup a Rx queue. +* +* @oct: Octeon device private data structure. +* @q_no: Rx queue number to be setup. +* +* Allocate resources for a Rx queue. +*/ +static int octep_vf_setup_oq (struct octep_vf_device *oct,int q_no) +{ +struct octep_vf_oq *oq; +u32 desc_ring_size; + + oq =vzalloc (sizeof (*oq)); +if (!oq) + goto create_oq_fail; + oct->oq[q_no] = oq; + + oq->octep_vf_dev = oct; + oq->netdev = oct->netdev; + oq->dev = &oct->pdev->dev; + oq->q_no = q_no; + oq->max_count =CFG_GET_OQ_NUM_DESC (oct->conf); + oq->ring_size_mask = oq->max_count -1 ; + oq->buffer_size =CFG_GET_OQ_BUF_SIZE (oct->conf); + oq->max_single_buffer_size = oq->buffer_size -OCTEP_VF_OQ_RESP_HW_SIZE ; + +/* When the hardware/firmware supports additional capabilities, +* additional header is filled-in by Octeon after length field in +* Rx packets. this header contains additional packet information. +*/ +if (oct->fw_info.rx_ol_flags) + oq->max_single_buffer_size -=OCTEP_VF_OQ_RESP_HW_EXT_SIZE ; + + oq->refill_threshold =CFG_GET_OQ_REFILL_THRESHOLD (oct->conf); + + desc_ring_size = oq->max_count *OCTEP_VF_OQ_DESC_SIZE ; + oq->desc_ring =dma_alloc_coherent (oq->dev, desc_ring_size, + &oq->desc_ring_dma,GFP_KERNEL ); + +if (unlikely (!oq->desc_ring)) { +dev_err (oq->dev, +"Failed to allocate DMA memory for OQ-%d !!\n" , q_no); + goto desc_dma_alloc_err; + } + + oq->buff_info =vzalloc (oq->max_count *OCTEP_VF_OQ_RECVBUF_SIZE ); + +if (unlikely (!oq->buff_info)) { +dev_err (&oct->pdev->dev, +"Failed to allocate buffer info for OQ-%d\n" , q_no); + goto buf_list_err; + } + +if (octep_vf_oq_fill_ring_buffers (oq)) + goto oq_fill_buff_err; + +octep_vf_oq_reset_indices (oq); + oct->hw_ops.setup_oq_regs (oct, q_no); + oct->num_oqs++; + +return 0 ; + +oq_fill_buff_err: +vfree (oq->buff_info); + oq->buff_info =NULL ; +buf_list_err: +dma_free_coherent (oq->dev, desc_ring_size, + oq->desc_ring, oq->desc_ring_dma); + oq->desc_ring =NULL ; +desc_dma_alloc_err: +vfree (oq); + oct->oq[q_no] =NULL ; +create_oq_fail: +return -ENOMEM ; +} + +/** +* octep_vf_oq_free_ring_buffers() - Free ring buffers. +* +* @oq: Octeon Rx queue data structure. +* +* Free receive buffers in unused Rx queue descriptors. +*/ +static void octep_vf_oq_free_ring_buffers (struct octep_vf_oq *oq) +{ +struct octep_vf_oq_desc_hw *desc_ring = oq->desc_ring; +int i; + +if (!oq->desc_ring || !oq->buff_info) +return ; + +for (i =0 ; i < oq->max_count; i++) { +if (oq->buff_info[i].page) { +dma_unmap_page (oq->dev, desc_ring[i].buffer_ptr, +PAGE_SIZE ,DMA_FROM_DEVICE ); +put_page (oq->buff_info[i].page); + oq->buff_info[i].page =NULL ; + desc_ring[i].buffer_ptr =0 ; + } + } +octep_vf_oq_reset_indices (oq); +} + +/** +* octep_vf_free_oq() - Free Rx queue resources. +* +* @oq: Octeon Rx queue data structure. +* +* Free all resources of a Rx queue. +*/ +static int octep_vf_free_oq (struct octep_vf_oq *oq) +{ +struct octep_vf_device *oct = oq->octep_vf_dev; +int q_no = oq->q_no; + +octep_vf_oq_free_ring_buffers (oq); + +vfree (oq->buff_info); + +if (oq->desc_ring) +dma_free_coherent (oq->dev, + oq->max_count *OCTEP_VF_OQ_DESC_SIZE , + oq->desc_ring, oq->desc_ring_dma); + +vfree (oq); + oct->oq[q_no] =NULL ; + oct->num_oqs--; +return 0 ; +} +/** * octep_vf_setup_oqs() - setup resources for all Rx queues. *
@@ -18,7 +206,27 @@*/ int octep_vf_setup_oqs (struct octep_vf_device *oct) { -return -1 ; +int i, retval =0 ; + + oct->num_oqs =0 ; +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) { + retval =octep_vf_setup_oq (oct, i); +if (retval) { +dev_err (&oct->pdev->dev, +"Failed to setup OQ(RxQ)-%d.\n" , i); + goto oq_setup_err; + } +dev_dbg (&oct->pdev->dev,"Successfully setup OQ(RxQ)-%d.\n" , i); + } + +return 0 ; + +oq_setup_err: +while (i) { + i--; +octep_vf_free_oq (oct->oq[i]); + } +return retval; }/**
@@ -30,6 +238,10 @@ int octep_vf_setup_oqs(struct octep_vf_device *oct)*/ void octep_vf_oq_dbell_init (struct octep_vf_device *oct) { +int i; + +for (i =0 ; i < oct->num_oqs; i++) +writel (oct->oq[i]->max_count, oct->oq[i]->pkts_credit_reg); }/**
@@ -39,4 +251,13 @@ void octep_vf_oq_dbell_init(struct octep_vf_device *oct)*/ void octep_vf_free_oqs (struct octep_vf_device *oct) { +int i; + +for (i =0 ; i <CFG_GET_PORTS_ACTIVE_IO_RINGS (oct->conf); i++) { +if (!oct->oq[i]) +continue ; +octep_vf_free_oq (oct->oq[i]); +dev_dbg (&oct->pdev->dev, +"Successfully freed OQ(RxQ)-%d.\n" , i); + } }
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.c +216 -0
242 lines not on this page · raw message
Signature · 1 line
2.25.1
Shinas Rasheed
maintainerPATCH v4 5/8 octeon_ep_vf: add support for ndo ops
In reply to Shinas RasheedAdd support for ndo ops to set MAC address, change MTU, get stats. Add control path support to set MAC address, change MTU, get stats, set speed, get and set link mode.
---
V4:
- Provide more stats in ndo_get_stats64 such as tx_dropped, rx_dropped etc.
V3: https://lore.kernel.org/all/[email protected]/
- No changes
V2: https://lore.kernel.org/all/[email protected]/
- No changes
V1: https://lore.kernel.org/all/[email protected]/
.../marvell/octeon_ep_vf/octep_vf_main.c | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c +58 -0
@@ -187,6 +187,23 @@ static netdev_tx_t octep_vf_start_xmit(struct sk_buff *skb,return NETDEV_TX_OK ; } +int octep_vf_get_if_stats (struct octep_vf_device *oct) +{ +struct octep_vf_iface_rxtx_stats vf_stats; +int ret, size; + +memset (&vf_stats,0 ,sizeof (struct octep_vf_iface_rxtx_stats )); + ret =octep_vf_mbox_bulk_read (oct,OCTEP_PFVF_MBOX_CMD_GET_STATS , + (u8 *)&vf_stats, &size); +if (!ret) { +memcpy (&oct->iface_rx_stats, &vf_stats.iface_rx_stats, +sizeof (struct octep_vf_iface_rx_stats )); +memcpy (&oct->iface_tx_stats, &vf_stats.iface_tx_stats, +sizeof (struct octep_vf_iface_tx_stats )); + } +return ret; +} +int octep_vf_get_link_info (struct octep_vf_device *oct) {int ret, size;
@@ -200,6 +217,46 @@ int octep_vf_get_link_info(struct octep_vf_device *oct)return 0 ; } +/** +* octep_vf_get_stats64() - Get Octeon network device statistics. +* +* @netdev: kernel network device. +* @stats: pointer to stats structure to be filled in. +*/ +static void octep_vf_get_stats64 (struct net_device *netdev, +struct rtnl_link_stats64 *stats) +{ +struct octep_vf_device *oct =netdev_priv (netdev); +u64 tx_packets, tx_bytes, rx_packets, rx_bytes; +int q; + + tx_packets =0 ; + tx_bytes =0 ; + rx_packets =0 ; + rx_bytes =0 ; +for (q =0 ; q < oct->num_oqs; q++) { +struct octep_vf_iq *iq = oct->iq[q]; +struct octep_vf_oq *oq = oct->oq[q]; + + tx_packets += iq->stats.instr_completed; + tx_bytes += iq->stats.bytes_sent; + rx_packets += oq->stats.packets; + rx_bytes += oq->stats.bytes; + } + stats->tx_packets = tx_packets; + stats->tx_bytes = tx_bytes; + stats->rx_packets = rx_packets; + stats->rx_bytes = rx_bytes; +if (!octep_vf_get_if_stats (oct)) { + stats->multicast = oct->iface_rx_stats.mcast_pkts; + stats->rx_errors = oct->iface_rx_stats.err_pkts; + stats->rx_dropped = oct->iface_rx_stats.dropped_pkts_fifo_full + + oct->iface_rx_stats.err_pkts; + stats->rx_missed_errors = oct->iface_rx_stats.dropped_pkts_fifo_full; + stats->tx_dropped = oct->iface_tx_stats.dropped; + } +} +/** * octep_vf_tx_timeout_task - work queue task to Handle Tx queue timeout. *
@@ -312,6 +369,7 @@ static const struct net_device_ops octep_vf_netdev_ops = { .ndo_open = octep_vf_open, .ndo_stop = octep_vf_stop, .ndo_start_xmit = octep_vf_start_xmit, + .ndo_get_stats64 = octep_vf_get_stats64, .ndo_tx_timeout = octep_vf_tx_timeout, .ndo_set_mac_address = octep_vf_set_mac, .ndo_change_mtu = octep_vf_change_mtu,
Signature · 1 line
2.25.1
Shinas Rasheed
maintainerPATCH v4 6/8 octeon_ep_vf: add Tx/Rx processing and interrupt support
In reply to Shinas RasheedAdd support to enable MSI-x and register interrupts. Add support to process Tx and Rx traffic. Includes processing Tx completions and Rx refill.
---
V4:
- Replaced code in IQ full check function to use helper from net/netdev_queues.h
- Refactored code so that NETDEV_TX_BUSY is avoided
V3: https://lore.kernel.org/all/[email protected]/
- Set static budget of 64 for tx completion processing in NAPI
- Replaces napi_complete and build_skb APIs to napi_complete_done and napi_build_skb APIs respectively
- Replaced code with helper from net/netdev_queues.h to wake queues in TX completion processing
- Moved null pointer casting corrections to earlier patch
V2: https://lore.kernel.org/all/[email protected]/
- Corrected Makefile entry to include building octep_vf_mbox.c
- Removed redundant vzalloc pointer cast and vfree pointer check
V1: https://lore.kernel.org/all/[email protected]/
.../marvell/octeon_ep_vf/octep_vf_main.c | 550 ++++++++++++++++++ .../marvell/octeon_ep_vf/octep_vf_rx.c | 247 ++++++++ .../marvell/octeon_ep_vf/octep_vf_tx.c | 71 +++ 3 files changed, 868 insertions(+)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c +550 -0
@@ -13,6 +13,7 @@#include <linux/etherdevice.h> #include <linux/rtnetlink.h> #include <linux/vmalloc.h> +#include <net/netdev_queues.h> #include "octep_vf_config.h" #include "octep_vf_main.h"
@@ -36,6 +37,372 @@ MODULE_AUTHOR("Veerasenareddy Burru <[email protected]>");MODULE_DESCRIPTION (OCTEP_VF_DRV_STRING );MODULE_LICENSE ("GPL" ); +/** +* octep_vf_alloc_ioq_vectors() - Allocate Tx/Rx Queue interrupt info. +* +* @oct: Octeon device private data structure. +* +* Allocate resources to hold per Tx/Rx queue interrupt info. +* This is the information passed to interrupt handler, from which napi poll +* is scheduled and includes quick access to private data of Tx/Rx queue +* corresponding to the interrupt being handled. +* +* Return: 0, on successful allocation of resources for all queue interrupts. +* -1, if failed to allocate any resource. +*/ +static int octep_vf_alloc_ioq_vectors (struct octep_vf_device *oct) +{ +struct octep_vf_ioq_vector *ioq_vector; +int i; + +for (i =0 ; i < oct->num_oqs; i++) { + oct->ioq_vector[i] =vzalloc (sizeof (*oct->ioq_vector[i])); +if (!oct->ioq_vector[i]) + goto free_ioq_vector; + + ioq_vector = oct->ioq_vector[i]; + ioq_vector->iq = oct->iq[i]; + ioq_vector->oq = oct->oq[i]; + ioq_vector->octep_vf_dev = oct; + } + +dev_info (&oct->pdev->dev,"Allocated %d IOQ vectors\n" , oct->num_oqs); +return 0 ; + +free_ioq_vector: +while (i) { + i--; +vfree (oct->ioq_vector[i]); + oct->ioq_vector[i] =NULL ; + } +return -1 ; +} + +/** +* octep_vf_free_ioq_vectors() - Free Tx/Rx Queue interrupt vector info. +* +* @oct: Octeon device private data structure. +*/ +static void octep_vf_free_ioq_vectors (struct octep_vf_device *oct) +{ +int i; + +for (i =0 ; i < oct->num_oqs; i++) { +if (oct->ioq_vector[i]) { +vfree (oct->ioq_vector[i]); + oct->ioq_vector[i] =NULL ; + } + } +netdev_info (oct->netdev,"Freed IOQ Vectors\n" ); +} + +/** +* octep_vf_enable_msix_range() - enable MSI-x interrupts. +* +* @oct: Octeon device private data structure. +* +* Allocate and enable all MSI-x interrupts (queue and non-queue interrupts) +* for the Octeon device. +* +* Return: 0, on successfully enabling all MSI-x interrupts. +* -1, if failed to enable any MSI-x interrupt. +*/ +static int octep_vf_enable_msix_range (struct octep_vf_device *oct) +{ +int num_msix, msix_allocated; +int i; + +/* Generic interrupts apart from input/output queues */ +//num_msix = oct->num_oqs + CFG_GET_NON_IOQ_MSIX(oct->conf); + num_msix = oct->num_oqs; + oct->msix_entries =kcalloc (num_msix,sizeof (struct msix_entry ),GFP_KERNEL ); +if (!oct->msix_entries) + goto msix_alloc_err; + +for (i =0 ; i < num_msix; i++) + oct->msix_entries[i].entry = i; + + msix_allocated =pci_enable_msix_range (oct->pdev, oct->msix_entries, + num_msix, num_msix); +if (msix_allocated != num_msix) { +dev_err (&oct->pdev->dev, +"Failed to enable %d msix irqs; got only %d\n" , + num_msix, msix_allocated); + goto enable_msix_err; + } + oct->num_irqs = msix_allocated; +dev_info (&oct->pdev->dev,"MSI-X enabled successfully\n" ); + +return 0 ; + +enable_msix_err: +if (msix_allocated >0 ) +pci_disable_msix (oct->pdev); +kfree (oct->msix_entries); + oct->msix_entries =NULL ; +msix_alloc_err: +return -1 ; +} + +/** +* octep_vf_disable_msix() - disable MSI-x interrupts. +* +* @oct: Octeon device private data structure. +* +* Disable MSI-x on the Octeon device. +*/ +static void octep_vf_disable_msix (struct octep_vf_device *oct) +{ +pci_disable_msix (oct->pdev); +kfree (oct->msix_entries); + oct->msix_entries =NULL ; +dev_info (&oct->pdev->dev,"Disabled MSI-X\n" ); +} + +/** +* octep_vf_ioq_intr_handler() - handler for all Tx/Rx queue interrupts. +* +* @irq: Interrupt number. +* @data: interrupt data contains pointers to Tx/Rx queue private data +* and correspong NAPI context. +* +* this is common handler for all non-queue (generic) interrupts. +*/ +static irqreturn_t octep_vf_ioq_intr_handler (int irq,void *data) +{ +struct octep_vf_ioq_vector *ioq_vector = data; +struct octep_vf_device *oct = ioq_vector->octep_vf_dev; + +return oct->hw_ops.ioq_intr_handler (ioq_vector); +} + +/** +* octep_vf_request_irqs() - Register interrupt handlers. +* +* @oct: Octeon device private data structure. +* +* Register handlers for all queue and non-queue interrupts. +* +* Return: 0, on successful registration of all interrupt handlers. +* -1, on any error. +*/ +static int octep_vf_request_irqs (struct octep_vf_device *oct) +{ +struct net_device *netdev = oct->netdev; +struct octep_vf_ioq_vector *ioq_vector; +struct msix_entry *msix_entry; +int ret, i; + +/* Request IRQs for Tx/Rx queues */ +for (i =0 ; i < oct->num_oqs; i++) { + ioq_vector = oct->ioq_vector[i]; + msix_entry = &oct->msix_entries[i]; + +snprintf (ioq_vector->name,sizeof (ioq_vector->name), +"%s-q%d" , netdev->name, i); + ret =request_irq (msix_entry->vector, + octep_vf_ioq_intr_handler,0 , + ioq_vector->name, ioq_vector); +if (ret) { +netdev_err (netdev, +"request_irq failed for Q-%d; err=%d" , + i, ret); + goto ioq_irq_err; + } + +cpumask_set_cpu (i %num_online_cpus (), + &ioq_vector->affinity_mask); +irq_set_affinity_hint (msix_entry->vector, + &ioq_vector->affinity_mask); + } + +return 0 ; +ioq_irq_err: +while (i) { + --i; +free_irq (oct->msix_entries[i].vector, oct); + } +return -1 ; +} + +/** +* octep_vf_free_irqs() - free all registered interrupts. +* +* @oct: Octeon device private data structure. +* +* Free all queue and non-queue interrupts of the Octeon device. +*/ +static void octep_vf_free_irqs (struct octep_vf_device *oct) +{ +int i; + +for (i =0 ; i < oct->num_irqs; i++) { +irq_set_affinity_hint (oct->msix_entries[i].vector,NULL ); +free_irq (oct->msix_entries[i].vector, oct->ioq_vector[i]); + } +netdev_info (oct->netdev,"IRQs freed\n" ); +} + +/** +* octep_vf_setup_irqs() - setup interrupts for the Octeon device. +* +* @oct: Octeon device private data structure. +* +* Allocate data structures to hold per interrupt information, allocate/enable +* MSI-x interrupt and register interrupt handlers. +* +* Return: 0, on successful allocation and registration of all interrupts. +* -1, on any error. +*/ +static int octep_vf_setup_irqs (struct octep_vf_device *oct) +{ +if (octep_vf_alloc_ioq_vectors (oct)) + goto ioq_vector_err; + +if (octep_vf_enable_msix_range (oct)) + goto enable_msix_err; + +if (octep_vf_request_irqs (oct)) + goto request_irq_err; + +return 0 ; + +request_irq_err: +octep_vf_disable_msix (oct); +enable_msix_err: +octep_vf_free_ioq_vectors (oct); +ioq_vector_err: +return -1 ; +} + +/** +* octep_vf_clean_irqs() - free all interrupts and its resources. +* +* @oct: Octeon device private data structure. +*/ +static void octep_vf_clean_irqs (struct octep_vf_device *oct) +{ +octep_vf_free_irqs (oct); +octep_vf_disable_msix (oct); +octep_vf_free_ioq_vectors (oct); +} + +/** +* octep_vf_enable_ioq_irq() - Enable MSI-x interrupt of a Tx/Rx queue. +* +* @iq: Octeon Tx queue data structure. +* @oq: Octeon Rx queue data structure. +*/ +static void octep_vf_enable_ioq_irq (struct octep_vf_iq *iq,struct octep_vf_oq *oq) +{ +u32 pkts_pend = oq->pkts_pending; + +netdev_dbg (iq->netdev,"enabling intr for Q-%u\n" , iq->q_no); +if (iq->pkts_processed) { +writel (iq->pkts_processed, iq->inst_cnt_reg); + iq->pkt_in_done -= iq->pkts_processed; + iq->pkts_processed =0 ; + } +if (oq->last_pkt_count - pkts_pend) { +writel (oq->last_pkt_count - pkts_pend, oq->pkts_sent_reg); + oq->last_pkt_count = pkts_pend; + } + +/* Flush the previous wrties before writing to RESEND bit */ +smp_wmb (); +writeq (1UL <<OCTEP_VF_OQ_INTR_RESEND_BIT , oq->pkts_sent_reg); +writeq (1UL <<OCTEP_VF_IQ_INTR_RESEND_BIT , iq->inst_cnt_reg); +} + +/** +* octep_vf_napi_poll() - NAPI poll function for Tx/Rx. +* +* @napi: pointer to napi context. +* @budget: max number of packets to be processed in single invocation. +*/ +static int octep_vf_napi_poll (struct napi_struct *napi,int budget) +{ +struct octep_vf_ioq_vector *ioq_vector = + container_of(napi, struct octep_vf_ioq_vector, napi); +u32 tx_pending, rx_done; + + tx_pending =octep_vf_iq_process_completions (ioq_vector->iq,64 ); + rx_done =octep_vf_oq_process_rx (ioq_vector->oq, budget); + +/* need more polling if tx completion processing is still pending or +* processed at least 'budget' number of rx packets. +*/ +if (tx_pending || rx_done >= budget) +return budget; + +if (likely (napi_complete_done (napi, rx_done))) +octep_vf_enable_ioq_irq (ioq_vector->iq, ioq_vector->oq); + +return rx_done; +} + +/** +* octep_vf_napi_add() - Add NAPI poll for all Tx/Rx queues. +* +* @oct: Octeon device private data structure. +*/ +static void octep_vf_napi_add (struct octep_vf_device *oct) +{ +int i; + +for (i =0 ; i < oct->num_oqs; i++) { +netdev_dbg (oct->netdev,"Adding NAPI on Q-%d\n" , i); +netif_napi_add (oct->netdev, &oct->ioq_vector[i]->napi, octep_vf_napi_poll); + oct->oq[i]->napi = &oct->ioq_vector[i]->napi; + } +} + +/** +* octep_vf_napi_delete() - delete NAPI poll callback for all Tx/Rx queues. +* +* @oct: Octeon device private data structure. +*/ +static void octep_vf_napi_delete (struct octep_vf_device *oct) +{ +int i; + +for (i =0 ; i < oct->num_oqs; i++) { +netdev_dbg (oct->netdev,"Deleting NAPI on Q-%d\n" , i); +netif_napi_del (&oct->ioq_vector[i]->napi); + oct->oq[i]->napi =NULL ; + } +} + +/** +* octep_vf_napi_enable() - enable NAPI for all Tx/Rx queues. +* +* @oct: Octeon device private data structure. +*/ +static void octep_vf_napi_enable (struct octep_vf_device *oct) +{ +int i; + +for (i =0 ; i < oct->num_oqs; i++) { +netdev_dbg (oct->netdev,"Enabling NAPI on Q-%d\n" , i); +napi_enable (&oct->ioq_vector[i]->napi); + } +} + +/** +* octep_vf_napi_disable() - disable NAPI for all Tx/Rx queues. +* +* @oct: Octeon device private data structure. +*/ +static void octep_vf_napi_disable (struct octep_vf_device *oct) +{ +int i; + +for (i =0 ; i < oct->num_oqs; i++) { +netdev_dbg (oct->netdev,"Disabling NAPI on Q-%d\n" , i); +napi_disable (&oct->ioq_vector[i]->napi); + } +} +static void octep_vf_link_up (struct net_device *netdev) {netif_carrier_on (netdev);
@@ -98,6 +465,8 @@ static int octep_vf_open(struct net_device *netdev) goto setup_iq_err;if (octep_vf_setup_oqs (oct)) goto setup_oq_err; +if (octep_vf_setup_irqs (oct)) + goto setup_irq_err; err =netif_set_real_num_tx_queues (netdev, oct->num_oqs);if (err)
@@ -106,6 +475,9 @@ static int octep_vf_open(struct net_device *netdev)if (err) goto set_queues_err; +octep_vf_napi_add (oct); +octep_vf_napi_enable (oct); + oct->link_info.admin_up =1 ;octep_vf_set_rx_state (oct, true);
@@ -128,6 +500,10 @@ static int octep_vf_open(struct net_device *netdev)return 0 ; set_queues_err: +octep_vf_napi_disable (oct); +octep_vf_napi_delete (oct); +octep_vf_clean_irqs (oct); +setup_irq_err:octep_vf_free_oqs (oct); setup_oq_err:octep_vf_free_iqs (oct);
@@ -161,7 +537,10 @@ static int octep_vf_stop(struct net_device *netdev) oct->link_info.oper_up =0 ; oct->hw_ops.disable_interrupts (oct); +octep_vf_napi_disable (oct); +octep_vf_napi_delete (oct); +octep_vf_clean_irqs (oct);octep_vf_clean_iqs (oct); oct->hw_ops.disable_io_queues (oct);
@@ -172,6 +551,39 @@ static int octep_vf_stop(struct net_device *netdev)return 0 ; } +/** +* octep_vf_iq_full_check() - check if a Tx queue is full. +* +* @iq: Octeon Tx queue data structure. +* +* Return: 0, if the Tx queue is not full. +* 1, if the Tx queue is full. +*/ +static int octep_vf_iq_full_check (struct octep_vf_iq *iq) +{ +int ret; + + ret =netif_subqueue_maybe_stop (iq->netdev, iq->q_no,IQ_INSTR_SPACE (iq), +OCTEP_VF_WAKE_QUEUE_THRESHOLD , +OCTEP_VF_WAKE_QUEUE_THRESHOLD ); +switch (ret) { +case 0 :/* Stopped the queue, since IQ is full */ +return 1 ; +case -1 :/* +* Pending updates in write index from +* iq_process_completion in other cpus +* caused queues to get re-enabled after +* being stopped +*/ + iq->stats.restart_cnt++; + fallthrough; +case 1 :/* Queue left enabled, since IQ is not yet full*/ +return 0 ; + } + +return 1 ; +} +/** * octep_vf_start_xmit() - Enqueue packet to Octoen hardware Tx Queue. *
@@ -184,6 +596,144 @@ static int octep_vf_stop(struct net_device *netdev)static netdev_tx_t octep_vf_start_xmit (struct sk_buff *skb,struct net_device *netdev) { +struct octep_vf_device *oct =netdev_priv (netdev); +netdev_features_t feat = netdev->features; +struct octep_vf_tx_sglist_desc *sglist; +struct octep_vf_tx_buffer *tx_buffer; +struct octep_vf_tx_desc_hw *hw_desc; +struct skb_shared_info *shinfo; +struct octep_vf_instr_hdr *ih; +struct octep_vf_iq *iq; +skb_frag_t *frag; +u16 nr_frags, si; +int xmit_more; +u16 q_no, wi; + +if (skb_put_padto (skb,ETH_ZLEN )) +return NETDEV_TX_OK ; + + q_no =skb_get_queue_mapping (skb); +if (q_no >= oct->num_iqs) { +netdev_err (netdev,"Invalid Tx skb->queue_mapping=%d\n" , q_no); + q_no = q_no % oct->num_iqs; + } + + iq = oct->iq[q_no]; + + shinfo =skb_shinfo (skb); + nr_frags = shinfo->nr_frags; + + wi = iq->host_write_index; + hw_desc = &iq->desc_ring[wi]; + hw_desc->ih64 =0 ; + + tx_buffer = iq->buff_info + wi; + tx_buffer->skb = skb; + + ih = &hw_desc->ih; + ih->tlen = skb->len; + ih->pkind = oct->fw_info.pkind; + ih->fsz = oct->fw_info.fsz; + ih->tlen = skb->len + ih->fsz; + +if (!nr_frags) { + tx_buffer->gather =0 ; + tx_buffer->dma =dma_map_single (iq->dev, skb->data, + skb->len,DMA_TO_DEVICE ); +if (dma_mapping_error (iq->dev, tx_buffer->dma)) + goto dma_map_err; + hw_desc->dptr = tx_buffer->dma; + }else { +/* Scatter/Gather */ +dma_addr_t dma; +u16 len; + + sglist = tx_buffer->sglist; + + ih->gsz = nr_frags +1 ; + ih->gather =1 ; + tx_buffer->gather =1 ; + + len =skb_headlen (skb); + dma =dma_map_single (iq->dev, skb->data, len,DMA_TO_DEVICE ); +if (dma_mapping_error (iq->dev, dma)) + goto dma_map_err; + +memset (sglist,0 ,OCTEP_VF_SGLIST_SIZE_PER_PKT ); + sglist[0 ].len[3 ] = len; + sglist[0 ].dma_ptr[0 ] = dma; + + si =1 ;/* entry 0 is main skb, mapped above */ + frag = &shinfo->frags[0 ]; +while (nr_frags--) { + len =skb_frag_size (frag); + dma =skb_frag_dma_map (iq->dev, frag,0 , + len,DMA_TO_DEVICE ); +if (dma_mapping_error (iq->dev, dma)) + goto dma_map_sg_err; + + sglist[si >>2 ].len[3 - (si &3 )] = len; + sglist[si >>2 ].dma_ptr[si &3 ] = dma; + + frag++; + si++; + } + hw_desc->dptr = tx_buffer->sglist_dma; + } +if (oct->fw_info.tx_ol_flags) { +if ((feat & (NETIF_F_TSO )) && (skb_is_gso (skb))) { + hw_desc->txm.ol_flags =OCTEP_VF_TX_OFFLOAD_CKSUM ; + hw_desc->txm.ol_flags |=OCTEP_VF_TX_OFFLOAD_TSO ; + hw_desc->txm.gso_size =skb_shinfo (skb)->gso_size; + hw_desc->txm.gso_segs =skb_shinfo (skb)->gso_segs; + }else if (feat & (NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM )) { + hw_desc->txm.ol_flags =OCTEP_VF_TX_OFFLOAD_CKSUM ; + } +/* due to ESR txm will be swapped by hw */ + hw_desc->txm64[0 ] = (__force u64 )cpu_to_be64 (hw_desc->txm64[0 ]); + } + + xmit_more =netdev_xmit_more (); + +netdev_tx_sent_queue (iq->netdev_q, skb->len); + +skb_tx_timestamp (skb); + iq->fill_cnt++; + wi++; + iq->host_write_index = wi & iq->ring_size_mask; + +/* octep_iq_full_check stops the queue and returns +* true if so, in case the queue has become full +* by inserting current packet. If so, we can +* go ahead and ring doorbell. +*/ +if (!octep_vf_iq_full_check (iq) && xmit_more && + iq->fill_cnt < iq->fill_threshold) +return NETDEV_TX_OK ; + + goto ring_dbell; + +dma_map_sg_err: +if (si >0 ) { +dma_unmap_single (iq->dev, sglist[0 ].dma_ptr[0 ], + sglist[0 ].len[0 ],DMA_TO_DEVICE ); + sglist[0 ].len[0 ] =0 ; + } +while (si >1 ) { +dma_unmap_page (iq->dev, sglist[si >>2 ].dma_ptr[si &3 ], + sglist[si >>2 ].len[si &3 ],DMA_TO_DEVICE ); + sglist[si >>2 ].len[si &3 ] =0 ; + si--; + } + tx_buffer->gather =0 ; +dma_map_err: +dev_kfree_skb_any (skb); +ring_dbell: +/* Flush the hw descriptors before writing to doorbell */ +smp_wmb (); +writel (iq->fill_cnt, iq->doorbell_reg); + iq->stats.instr_posted += iq->fill_cnt; + iq->fill_cnt =0 ;return NETDEV_TX_OK ; }
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_rx.c +247 -0
256 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_tx.c +71 -0
83 lines not on this page · raw message
Signature · 1 line
2.25.1
Shinas Rasheed
maintainerPATCH v4 7/8 octeon_ep_vf: add ethtool support
In reply to Shinas RasheedAdd support for the following ethtool commands:
ethtool -i|--driver devname
ethtool devname
ethtool -S|--statistics devname
---
V4:
- Removed stats which are already sent in ndo_get_stats64
V3: https://lore.kernel.org/all/[email protected]/
- Removed duplicate reporting of TX/RX packets/bytes, which is already done during ndo_get_stats64
V2: https://lore.kernel.org/all/[email protected]/
- No changes
V1: https://lore.kernel.org/all/[email protected]/
.../ethernet/marvell/octeon_ep_vf/Makefile | 3 +- .../marvell/octeon_ep_vf/octep_vf_ethtool.c | 273 ++++++++++++++++++ .../marvell/octeon_ep_vf/octep_vf_main.c | 1 + .../marvell/octeon_ep_vf/octep_vf_main.h | 1 + 4 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_ethtool.c
drivers/net/ethernet/marvell/octeon_ep_vf/Makefile +2 -1
@@ -6,4 +6,5 @@ obj-$(CONFIG_OCTEON_EP_VF) += octeon_ep_vf.o octeon_ep_vf-y := octep_vf_main.o octep_vf_cn9k.o octep_vf_cnxk.o \ - octep_vf_tx.o octep_vf_rx.o octep_vf_mbox.o + octep_vf_tx.o octep_vf_rx.o octep_vf_mbox.o \ + octep_vf_ethtool.o
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_ethtool.c new file +273 -0
273 lines not on this page · raw message
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c +1 -0
@@ -1091,6 +1091,7 @@ static int octep_vf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)INIT_WORK (&octep_vf_dev->tx_timeout_task, octep_vf_tx_timeout_task); netdev->netdev_ops = &octep_vf_netdev_ops; +octep_vf_set_ethtool_ops (netdev);netif_carrier_off (netdev);if (octep_vf_setup_mbox (octep_vf_dev)) {
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.h +1 -0
@@ -327,6 +327,7 @@ void octep_vf_device_setup_cn93(struct octep_vf_device *oct);void octep_vf_device_setup_cnxk (struct octep_vf_device *oct);int octep_vf_iq_process_completions (struct octep_vf_iq *iq,u16 budget);int octep_vf_oq_process_rx (struct octep_vf_oq *oq,int budget); +void octep_vf_set_ethtool_ops (struct net_device *netdev);int octep_vf_get_link_info (struct octep_vf_device *oct);int octep_vf_get_if_stats (struct octep_vf_device *oct);void octep_vf_mbox_work (struct work_struct *work);
Signature · 1 line
2.25.1
Shinas Rasheed
maintainerPATCH v4 8/8 octeon_ep_vf: update MAINTAINERS
In reply to Shinas Rasheedadd MAINTAINERS for octeon_ep_vf driver.
---
V4:
- No changes
V3: https://lore.kernel.org/all/[email protected]/
- No changes
V2: https://lore.kernel.org/all/[email protected]/
- No changes
V1: https://lore.kernel.org/all/[email protected]/
MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -12867,6 +12867,15 @@ L: [email protected] S: Supported F: drivers/net/ethernet/marvell/octeon_ep +MARVELL OCTEON ENDPOINT VF DRIVER +M: Veerasenareddy Burru <[email protected]> +M: Sathesh Edara <[email protected]> +M: Shinas Rasheed <[email protected]> +M: Satananda Burla <[email protected]> +L: [email protected] +S: Supported +F: drivers/net/ethernet/marvell/octeon_ep_vf + MARVELL OCTEONTX2 PHYSICAL FUNCTION DRIVER M: Sunil Goutham <[email protected]> M: Geetha sowjanya <[email protected]>
Signature · 1 line
2.25.1