Skip to contentSkip to conversation

Cavium OCTEON-III network driver.

PATCH Superseded David Daney 9 participants 36 messages Nov 29, 2017 – Dec 7, 2017

Subsystems (5)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover Cavium OCTEON-III network driver.

We are adding the Cavium OCTEON-III network driver. But since interacting with the input and output queues is done via special CPU local memory, we also need to add support to the MIPS/Octeon architecture code. Aren't SoCs nice in this way?

The first six patches add the SoC support needed by the driver, the last two add the driver and an entry in MAINTAINERS.

Since these touch several subsystems (mips, staging, netdev), I would propose merging via netdev, but defer to the maintainers if they think something else would work better.

A separate pull request was recently done by Steven Hill for the firmware required by the driver.

Changes from v3:

o Use phy_print_status() instead of open coding the equivalent.

o Print warning on phy mode mismatch.

o Improve dt-bindings and add Acked-by.

Changes from v2:

o Fix PKI (RX path) initialization to work with little endian kernel.

Changes from v1:

o Cleanup and use of standard bindings in the device tree bindings document.

o Added (hopefully) clarifying comments about several OCTEON architectural peculiarities.

o Removed unused testing code from the driver.

o Removed some module parameters that already default to the proper values.

o KConfig cleanup, including testing on x86_64, arm64 and mips.

o Fixed breakage to the driver for previous generation of OCTEON SoCs (in the staging directory still).

o Verified bisectability of the patch set.

Carlos Munoz (5):
dt-bindings: Add Cavium Octeon Common Ethernet Interface.
MIPS: Octeon: Enable LMTDMA/LMTST operations.
MIPS: Octeon: Add a global resource manager.
MIPS: Octeon: Add Free Pointer Unit (FPA) support.
netdev: octeon-ethernet: Add Cavium Octeon III support.

David Daney (3):
MIPS: Octeon: Automatically provision CVMSEG space.
staging: octeon: Remove USE_ASYNC_IOBDMA macro.
MAINTAINERS: Add entry for
drivers/net/ethernet/cavium/octeon/octeon3-*

 .../devicetree/bindings/net/cavium-bgx.txt         |   61 +
 MAINTAINERS                                        |    6 +
 arch/mips/cavium-octeon/Kconfig                    |   35 +-
 arch/mips/cavium-octeon/Makefile                   |    4 +-
 arch/mips/cavium-octeon/octeon-fpa3.c              |  364 ++++
 arch/mips/cavium-octeon/resource-mgr.c             |  371 ++++
 arch/mips/cavium-octeon/setup.c                    |   22 +-
 .../asm/mach-cavium-octeon/kernel-entry-init.h     |   20 +-
 arch/mips/include/asm/mipsregs.h                   |    2 +
 arch/mips/include/asm/octeon/octeon.h              |   47 +-
 arch/mips/include/asm/processor.h                  |    2 +-
 arch/mips/kernel/octeon_switch.S                   |    2 -
 arch/mips/mm/tlbex.c                               |   29 +-
 drivers/net/ethernet/cavium/Kconfig                |   55 +-
 drivers/net/ethernet/cavium/octeon/Makefile        |    6 +
 .../net/ethernet/cavium/octeon/octeon3-bgx-nexus.c |  698 +++++++
 .../net/ethernet/cavium/octeon/octeon3-bgx-port.c  | 2033 +++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-core.c  | 2068 ++++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pki.c   |  832 ++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pko.c   | 1719 ++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-sso.c   |  309 +++
 drivers/net/ethernet/cavium/octeon/octeon3.h       |  411 ++++
 drivers/staging/octeon/ethernet-defines.h          |    6 -
 drivers/staging/octeon/ethernet-rx.c               |   25 +-
 drivers/staging/octeon/ethernet-tx.c               |   85 +-
 25 files changed, 9069 insertions(+), 143 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/cavium-bgx.txt
 create mode 100644 arch/mips/cavium-octeon/octeon-fpa3.c
 create mode 100644 arch/mips/cavium-octeon/resource-mgr.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-core.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pki.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pko.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-sso.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3.h
Signature · 6 lines
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH v4 1/8 dt-bindings: Add Cavium Octeon Common Ethernet Interface.

From: Carlos Munoz <[email protected]>

Add bindings for Common Ethernet Interface (BGX) block.

---
 .../devicetree/bindings/net/cavium-bgx.txt         | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/cavium-bgx.txt
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +61 -0
new file mode 100644
index 000000000000..830c5f08dddd
@@ -0,0 +1,61 @@
+* Common Ethernet Interface (BGX) block
+
+Properties:
+
+- compatible: "cavium,octeon-7890-bgx": Compatibility with all cn7xxx SOCs.
+
+- reg: The base address of the BGX block.
+
+- #address-cells: Must be <1>.
+
+- #size-cells: Must be <0>.  BGX addresses have no size component.
+
+A BGX block has several children, each representing an Ethernet
+interface.
+
+
+* Ethernet Interface (BGX port) connects to PKI/PKO
+
+Properties:
+
+- compatible: "cavium,octeon-7890-bgx-port": Compatibility with all
+	      cn7xxx SOCs.
+
+	      "cavium,octeon-7360-xcv": Compatibility with cn73xx SOCs
+	      for RGMII.
+
+- reg: The index of the interface within the BGX block.
+
+Optional properties:
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.
+
+- phy-mode: described in ethernet.txt.
+
+- fixed-link: described in fixed-link.txt.
+
+Example:
+
+	ethernet-mac-nexus@11800e0000000 {
+		compatible = "cavium,octeon-7890-bgx";
+		reg = <0x00011800 0xe0000000 0x00000000 0x01000000>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		ethernet@0 {
+			compatible = "cavium,octeon-7360-xcv";
+			reg = <0>;
+			local-mac-address = [ 00 01 23 45 67 89 ];
+			phy-handle = <&phy3>;
+			phy-mode = "rgmii-rxid"
+		};
+		ethernet@1 {
+			compatible = "cavium,octeon-7890-bgx-port";
+			reg = <1>;
+			local-mac-address = [ 00 01 23 45 67 8a ];
+			phy-handle = <&phy4>;
+			phy-mode = "sgmii"
+		};
+	};
Signature · 1 line
2.14.3
#2 lore raw

Re: [PATCH v4 1/8] dt-bindings: Add Cavium Octeon Common Ethernet Interface.

Quoted 52 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

Add bindings for Common Ethernet Interface (BGX) block.

---
 .../devicetree/bindings/net/cavium-bgx.txt         | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/cavium-bgx.txt
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +33 -0
new file mode 100644
index 000000000000..830c5f08dddd
@@ -0,0 +1,61 @@
+* Common Ethernet Interface (BGX) block
+
+Properties:
+
+- compatible: "cavium,octeon-7890-bgx": Compatibility with all cn7xxx SOCs.
+
+- reg: The base address of the BGX block.
+
+- #address-cells: Must be <1>.
+
+- #size-cells: Must be <0>.  BGX addresses have no size component.
+
+A BGX block has several children, each representing an Ethernet
+interface.
+
+
+* Ethernet Interface (BGX port) connects to PKI/PKO
+
+Properties:
+
+- compatible: "cavium,octeon-7890-bgx-port": Compatibility with all
+	      cn7xxx SOCs.
+
+	      "cavium,octeon-7360-xcv": Compatibility with cn73xx SOCs
+	      for RGMII.
+
+- reg: The index of the interface within the BGX block.
+
+Optional properties:
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.

Documentation/devicetree/bindings/net/cavium-bgx.txt line 43

Quoted 10 lines
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +10 -0
+
+- phy-mode: described in ethernet.txt.
+
+- fixed-link: described in fixed-link.txt.
+
+Example:
+
+	ethernet-mac-nexus@11800e0000000 {
+		compatible = "cavium,octeon-7890-bgx";
+		reg = <0x00011800 0xe0000000 0x00000000 0x01000000>;

Hi David

In the probe function we have:

+       reg = of_get_property(pdev->dev.of_node, "reg", NULL);
+       addr = of_translate_address(pdev->dev.of_node, reg);
+       interface = (addr >> 24) & 0xf;
+       numa_node = (addr >> 36) & 0x7;

Is this documented somewhere? The numa_node is particularly interesting. MMIO changes depends on what node this is in the cluster?

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH v4 1/8] dt-bindings: Add Cavium Octeon Common Ethernet Interface.

Quoted 73 lines · Andrew Lunn
Quoted 52 lines · David Daney

From: Carlos Munoz <[email protected]>

Add bindings for Common Ethernet Interface (BGX) block.

---
  .../devicetree/bindings/net/cavium-bgx.txt         | 61 ++++++++++++++++++++++
  1 file changed, 61 insertions(+)

create mode 100644 Documentation/devicetree/bindings/net/cavium-bgx.txt

Documentation/devicetree/bindings/net/cavium-bgx.txt new file +33 -0
new file mode 100644
index 000000000000..830c5f08dddd
@@ -0,0 +1,61 @@
+* Common Ethernet Interface (BGX) block
+
+Properties:
+
+- compatible: "cavium,octeon-7890-bgx": Compatibility with all cn7xxx SOCs.
+
+- reg: The base address of the BGX block.
+
+- #address-cells: Must be <1>.
+
+- #size-cells: Must be <0>.  BGX addresses have no size component.
+
+A BGX block has several children, each representing an Ethernet
+interface.
+
+
+* Ethernet Interface (BGX port) connects to PKI/PKO
+
+Properties:
+
+- compatible: "cavium,octeon-7890-bgx-port": Compatibility with all
+	      cn7xxx SOCs.
+
+	      "cavium,octeon-7360-xcv": Compatibility with cn73xx SOCs
+	      for RGMII.
+
+- reg: The index of the interface within the BGX block.
+
+Optional properties:
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.

Documentation/devicetree/bindings/net/cavium-bgx.txt line 43

Quoted 10 lines
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +10 -0
+
+- phy-mode: described in ethernet.txt.
+
+- fixed-link: described in fixed-link.txt.
+
+Example:
+
+	ethernet-mac-nexus@11800e0000000 {
+		compatible = "cavium,octeon-7890-bgx";
+		reg = <0x00011800 0xe0000000 0x00000000 0x01000000>;

Hi David

In the probe function we have:

(quoted diff) +4 -0
+       reg = of_get_property(pdev->dev.of_node, "reg", NULL);
+       addr = of_translate_address(pdev->dev.of_node, reg);
+       interface = (addr >> 24) & 0xf;
+       numa_node = (addr >> 36) & 0x7;
Quoted 1 line

Is this documented somewhere?

In the Hardware Reference Manual for the chips.

Quoted 2 lines

The numa_node is particularly
interesting. MMIO changes depends on what node this is in the cluster?

Yes. Bits 38..36 of MMIO addresses indicate which NUMA node the corresponding hardware device resides on. Some operations can only be performed by a CPU on the same NUMA node as the device (RX or TX-complete interrupts for example) Other operations can cross CPU nodes (TX packet submission for example)

Quoted 3 lines

Andrew

#4 lore raw

PATCH v4 2/8 MIPS: Octeon: Enable LMTDMA/LMTST operations.

In reply to David Daney

From: Carlos Munoz <[email protected]>

LMTDMA/LMTST operations move data between cores and I/O devices:

* LMTST operations can send an address and a variable length (up to 128 bytes) of data to an I/O device.
* LMTDMA operations can send an address and a variable length (up to 128) of data to the I/O device and then return a variable length (up to 128 bytes) response from the IOI device.

---
 arch/mips/cavium-octeon/setup.c       |  6 ++++++
 arch/mips/include/asm/octeon/octeon.h | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
arch/mips/cavium-octeon/setup.c +6 -0
index a8034d0dcade..99e6a68bc652 100644
@@ -609,6 +609,12 @@ void octeon_user_io_init(void)
 #else
 	cvmmemctl.s.cvmsegenak = 0;
 #endif
+	if (OCTEON_IS_OCTEON3()) {
+		/* Enable LMTDMA */
+		cvmmemctl.s.lmtena = 1;
+		/* Scratch line to use for LMT operation */
+		cvmmemctl.s.lmtline = 2;
+	}
 	/* R/W If set, CVMSEG is available for loads/stores in
 	 * supervisor mode. */
 	cvmmemctl.s.cvmsegenas = 0;
arch/mips/include/asm/octeon/octeon.h +10 -2
index c99c4b6a79f4..92a17d67c1fa 100644
@@ -179,7 +179,15 @@ union octeon_cvmemctl {
 		/* RO 1 = BIST fail, 0 = BIST pass */
 		__BITFIELD_FIELD(uint64_t wbfbist:1,
 		/* Reserved */
-		__BITFIELD_FIELD(uint64_t reserved:17,
+		__BITFIELD_FIELD(uint64_t reserved_52_57:6,
+		/* When set, LMTDMA/LMTST operations are permitted */
+		__BITFIELD_FIELD(uint64_t lmtena:1,
+		/* Selects the CVMSEG LM cacheline used by LMTDMA
+		 * LMTST and wide atomic store operations.
+		 */
+		__BITFIELD_FIELD(uint64_t lmtline:6,
+		/* Reserved */
+		__BITFIELD_FIELD(uint64_t reserved_41_44:4,
 		/* OCTEON II - TLB replacement policy: 0 = bitmask LRU; 1 = NLU.
 		 * This field selects between the TLB replacement policies:
 		 * bitmask LRU or NLU. Bitmask LRU maintains a mask of
@@ -275,7 +283,7 @@ union octeon_cvmemctl {
 		/* R/W Size of local memory in cache blocks, 54 (6912
 		 * bytes) is max legal value. */
 		__BITFIELD_FIELD(uint64_t lmemsz:6,
-		;)))))))))))))))))))))))))))))))))
+		;))))))))))))))))))))))))))))))))))))
 	} s;
 };
 
Signature · 1 line
2.14.3
Reviewed-by on v4 2/8
#5 lore raw

Re: [PATCH v4 2/8] MIPS: Octeon: Enable LMTDMA/LMTST operations.

Quoted 9 lines · David Daney

From: Carlos Munoz <[email protected]>

LMTDMA/LMTST operations move data between cores and I/O devices:

* LMTST operations can send an address and a variable length (up to 128 bytes) of data to an I/O device.
* LMTDMA operations can send an address and a variable length (up to 128) of data to the I/O device and then return a variable length (up to 128 bytes) response from the IOI device.

Should that be "I/O"?

Quoted 14 lines
---
 arch/mips/cavium-octeon/setup.c       |  6 ++++++
 arch/mips/include/asm/octeon/octeon.h | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
arch/mips/cavium-octeon/setup.c +0 -0
index a8034d0dcade..99e6a68bc652 100644

arch/mips/cavium-octeon/setup.c void octeon_user_io_init(void) · line 616

Quoted 8 lines
arch/mips/cavium-octeon/setup.c +5 -0
@@ -609,6 +609,12 @@ void octeon_user_io_init(void)
 #else
 	cvmmemctl.s.cvmsegenak = 0;
 #endif
+	if (OCTEON_IS_OCTEON3()) {
+		/* Enable LMTDMA */
+		cvmmemctl.s.lmtena = 1;
+		/* Scratch line to use for LMT operation */
+		cvmmemctl.s.lmtline = 2;

Out of curiosity, is there significance to the value 2 and associated virtual address 0xffffffffffff8100, or is it pretty arbitrary?

Quoted 26 lines
arch/mips/cavium-octeon/setup.c +1 -0
+	}
 	/* R/W If set, CVMSEG is available for loads/stores in
 	 * supervisor mode. */
 	cvmmemctl.s.cvmsegenas = 0;
arch/mips/include/asm/octeon/octeon.h +9 -1
index c99c4b6a79f4..92a17d67c1fa 100644
@@ -179,7 +179,15 @@ union octeon_cvmemctl {
 		/* RO 1 = BIST fail, 0 = BIST pass */
 		__BITFIELD_FIELD(uint64_t wbfbist:1,
 		/* Reserved */
-		__BITFIELD_FIELD(uint64_t reserved:17,
+		__BITFIELD_FIELD(uint64_t reserved_52_57:6,
+		/* When set, LMTDMA/LMTST operations are permitted */
+		__BITFIELD_FIELD(uint64_t lmtena:1,
+		/* Selects the CVMSEG LM cacheline used by LMTDMA
+		 * LMTST and wide atomic store operations.
+		 */
+		__BITFIELD_FIELD(uint64_t lmtline:6,
+		/* Reserved */
+		__BITFIELD_FIELD(uint64_t reserved_41_44:4,
 		/* OCTEON II - TLB replacement policy: 0 = bitmask LRU; 1 = NLU.
 		 * This field selects between the TLB replacement policies:
 		 * bitmask LRU or NLU. Bitmask LRU maintains a mask of

arch/mips/include/asm/octeon/octeon.h union octeon_cvmemctl { · line 288

Quoted 7 lines
arch/mips/include/asm/octeon/octeon.h +1 -1
@@ -275,7 +283,7 @@ union octeon_cvmemctl {
 		/* R/W Size of local memory in cache blocks, 54 (6912
 		 * bytes) is max legal value. */
 		__BITFIELD_FIELD(uint64_t lmemsz:6,
-		;)))))))))))))))))))))))))))))))))
+		;))))))))))))))))))))))))))))))))))))
 	} s;
 };

Regardless, the patch looks good to me.

Cheers
James

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#6 lore raw

Re: [PATCH v4 2/8] MIPS: Octeon: Enable LMTDMA/LMTST operations.

Quoted 5 lines · James Hogan
Quoted 4 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

LMTDMA/LMTST operations move data between cores and I/O devices:

Quoted 7 lines
Quoted 5 lines

* LMTST operations can send an address and a variable length (up to 128 bytes) of data to an I/O device.
* LMTDMA operations can send an address and a variable length (up to 128) of data to the I/O device and then return a variable length (up to 128 bytes) response from the IOI device.

Should that be "I/O"?

Yes, I will fix the changelog.

Quoted 10 lines
Quoted 10 lines
---
  arch/mips/cavium-octeon/setup.c       |  6 ++++++
  arch/mips/include/asm/octeon/octeon.h | 12 ++++++++++--
  2 files changed, 16 insertions(+), 2 deletions(-)
Quoted 16 lines

arch/mips/cavium-octeon/setup.c void octeon_user_io_init(void) · line 616

Quoted 13 lines
arch/mips/cavium-octeon/setup.c +5 -0
index a8034d0dcade..99e6a68bc652 100644
@@ -609,6 +609,12 @@ void octeon_user_io_init(void)
  #else
  	cvmmemctl.s.cvmsegenak = 0;
  #endif
+	if (OCTEON_IS_OCTEON3()) {
+		/* Enable LMTDMA */
+		cvmmemctl.s.lmtena = 1;
+		/* Scratch line to use for LMT operation */
+		cvmmemctl.s.lmtline = 2;

Out of curiosity, is there significance to the value 2 and associated virtual address 0xffffffffffff8100, or is it pretty arbitrary?

Yes, there is significance.

CPU local memory starts at 0xffffffffffff8000, each line is 0x80 bytes. so the 2nd line starts at 0xffffffffffff8100

Quoted 37 lines
Quoted 27 lines
arch/mips/cavium-octeon/setup.c +1 -0
+	}
  	/* R/W If set, CVMSEG is available for loads/stores in
  	 * supervisor mode. */
  	cvmmemctl.s.cvmsegenas = 0;
arch/mips/include/asm/octeon/octeon.h +9 -1
index c99c4b6a79f4..92a17d67c1fa 100644
@@ -179,7 +179,15 @@ union octeon_cvmemctl {
  		/* RO 1 = BIST fail, 0 = BIST pass */
  		__BITFIELD_FIELD(uint64_t wbfbist:1,
  		/* Reserved */
-		__BITFIELD_FIELD(uint64_t reserved:17,
+		__BITFIELD_FIELD(uint64_t reserved_52_57:6,
+		/* When set, LMTDMA/LMTST operations are permitted */
+		__BITFIELD_FIELD(uint64_t lmtena:1,
+		/* Selects the CVMSEG LM cacheline used by LMTDMA
+		 * LMTST and wide atomic store operations.
+		 */
+		__BITFIELD_FIELD(uint64_t lmtline:6,
+		/* Reserved */
+		__BITFIELD_FIELD(uint64_t reserved_41_44:4,
  		/* OCTEON II - TLB replacement policy: 0 = bitmask LRU; 1 = NLU.
  		 * This field selects between the TLB replacement policies:
  		 * bitmask LRU or NLU. Bitmask LRU maintains a mask of

arch/mips/include/asm/octeon/octeon.h union octeon_cvmemctl { · line 288

Quoted 7 lines
arch/mips/include/asm/octeon/octeon.h +1 -1
@@ -275,7 +283,7 @@ union octeon_cvmemctl {
  		/* R/W Size of local memory in cache blocks, 54 (6912
  		 * bytes) is max legal value. */
  		__BITFIELD_FIELD(uint64_t lmemsz:6,
-		;)))))))))))))))))))))))))))))))))
+		;))))))))))))))))))))))))))))))))))))
  	} s;
  };

Regardless, the patch looks good to me.

Quoted 5 lines

Cheers
James

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

Re: [PATCH v4 2/8] MIPS: Octeon: Enable LMTDMA/LMTST operations.

Quoted 27 lines · David Daney
Quoted 9 lines · James Hogan
Quoted 8 lines · David Daney
---
  arch/mips/cavium-octeon/setup.c       |  6 ++++++
  arch/mips/include/asm/octeon/octeon.h | 12 ++++++++++--
  2 files changed, 16 insertions(+), 2 deletions(-)
Quoted 16 lines

arch/mips/cavium-octeon/setup.c void octeon_user_io_init(void) · line 616

Quoted 13 lines
arch/mips/cavium-octeon/setup.c +5 -0
index a8034d0dcade..99e6a68bc652 100644
@@ -609,6 +609,12 @@ void octeon_user_io_init(void)
  #else
  	cvmmemctl.s.cvmsegenak = 0;
  #endif
+	if (OCTEON_IS_OCTEON3()) {
+		/* Enable LMTDMA */
+		cvmmemctl.s.lmtena = 1;
+		/* Scratch line to use for LMT operation */
+		cvmmemctl.s.lmtline = 2;

Out of curiosity, is there significance to the value 2 and associated virtual address 0xffffffffffff8100, or is it pretty arbitrary?

Quoted 4 lines

Yes, there is significance.

CPU local memory starts at 0xffffffffffff8000, each line is 0x80 bytes. so the 2nd line starts at 0xffffffffffff8100

What I mean is, why is 2 chosen instead of any other value?

Cheers
James

#8 lore raw

Re: [PATCH v4 2/8] MIPS: Octeon: Enable LMTDMA/LMTST operations.

Quoted 28 lines · James Hogan
Quoted 27 lines · David Daney
Quoted 25 lines · James Hogan
Quoted 13 lines · David Daney
---
   arch/mips/cavium-octeon/setup.c       |  6 ++++++
   arch/mips/include/asm/octeon/octeon.h | 12 ++++++++++--
   2 files changed, 16 insertions(+), 2 deletions(-)
arch/mips/cavium-octeon/setup.c +0 -0
index a8034d0dcade..99e6a68bc652 100644

arch/mips/cavium-octeon/setup.c void octeon_user_io_init(void) · line 616

Quoted 8 lines
arch/mips/cavium-octeon/setup.c +5 -0
@@ -609,6 +609,12 @@ void octeon_user_io_init(void)
   #else
   	cvmmemctl.s.cvmsegenak = 0;
   #endif
+	if (OCTEON_IS_OCTEON3()) {
+		/* Enable LMTDMA */
+		cvmmemctl.s.lmtena = 1;
+		/* Scratch line to use for LMT operation */
+		cvmmemctl.s.lmtline = 2;

Out of curiosity, is there significance to the value 2 and associated virtual address 0xffffffffffff8100, or is it pretty arbitrary?

Quoted 6 lines
Quoted 4 lines

Yes, there is significance.

CPU local memory starts at 0xffffffffffff8000, each line is 0x80 bytes. so the 2nd line starts at 0xffffffffffff8100

What I mean is, why is 2 chosen instead of any other value?

That is explained in the change log of patch 5/8:

1st 128-bytes: Use by IOBDMA
2nd 128-bytes: Reserved by kernel for scratch/TLS emulation. 3rd 128-bytes: OCTEON-III LMTLINE

Quoted 4 lines

Cheers
James

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

Re: [PATCH v4 2/8] MIPS: Octeon: Enable LMTDMA/LMTST operations.

Quoted 34 lines · David Daney
Quoted 33 lines · James Hogan
Quoted 31 lines · David Daney
Quoted 9 lines · James Hogan
Quoted 8 lines · David Daney
---
   arch/mips/cavium-octeon/setup.c       |  6 ++++++
   arch/mips/include/asm/octeon/octeon.h | 12 ++++++++++--
   2 files changed, 16 insertions(+), 2 deletions(-)
Quoted 16 lines

arch/mips/cavium-octeon/setup.c void octeon_user_io_init(void) · line 616

Quoted 13 lines
arch/mips/cavium-octeon/setup.c +5 -0
index a8034d0dcade..99e6a68bc652 100644
@@ -609,6 +609,12 @@ void octeon_user_io_init(void)
   #else
   	cvmmemctl.s.cvmsegenak = 0;
   #endif
+	if (OCTEON_IS_OCTEON3()) {
+		/* Enable LMTDMA */
+		cvmmemctl.s.lmtena = 1;
+		/* Scratch line to use for LMT operation */
+		cvmmemctl.s.lmtline = 2;

Out of curiosity, is there significance to the value 2 and associated virtual address 0xffffffffffff8100, or is it pretty arbitrary?

Yes, there is significance.

CPU local memory starts at 0xffffffffffff8000, each line is 0x80 bytes. so the 2nd line starts at 0xffffffffffff8100

Quoted 8 lines
Quoted 1 line

What I mean is, why is 2 chosen instead of any other value?

That is explained in the change log of patch 5/8:

1st 128-bytes: Use by IOBDMA
2nd 128-bytes: Reserved by kernel for scratch/TLS emulation. 3rd 128-bytes: OCTEON-III LMTLINE

Ah yes. Perhaps it deserves a brief comment in the code, or even an enum.

Cheers
James

#10 lore raw

PATCH v4 3/8 MIPS: Octeon: Add a global resource manager.

In reply to David Daney

From: Carlos Munoz <[email protected]>

Add a global resource manager to manage tagged pointers within bootmem allocated memory. This is used by various functional blocks in the Octeon core like the FPA, Ethernet nexus, etc.

---
 arch/mips/cavium-octeon/Makefile       |   3 +-
 arch/mips/cavium-octeon/resource-mgr.c | 371 +++++++++++++++++++++++++++++++++
 arch/mips/include/asm/octeon/octeon.h  |  18 ++
 3 files changed, 391 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/cavium-octeon/resource-mgr.c
arch/mips/cavium-octeon/Makefile +2 -1
index 7c02e542959a..0a299ab8719f 100644
@@ -9,7 +9,8 @@
 # Copyright (C) 2005-2009 Cavium Networks
 #
 
-obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o
+obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o \
+	 resource-mgr.o
 obj-y += dma-octeon.o
 obj-y += octeon-memcpy.o
 obj-y += executive/
arch/mips/cavium-octeon/resource-mgr.c new file +371 -0

371 lines not on this page · raw message

arch/mips/include/asm/octeon/octeon.h +18 -0
index 92a17d67c1fa..0411efdb465c 100644
@@ -346,6 +346,24 @@ void octeon_mult_restore3_end(void);
 void octeon_mult_restore2(void);
 void octeon_mult_restore2_end(void);
 
+/*
+ * This definition must be kept in sync with the one in
+ * cvmx-global-resources.c
+ */
+struct global_resource_tag {
+	uint64_t lo;
+	uint64_t hi;
+};
+
+void res_mgr_free(struct global_resource_tag tag, int inst);
+void res_mgr_free_range(struct global_resource_tag tag, const int *inst,
+			int req_cnt);
+int res_mgr_alloc(struct global_resource_tag tag, int req_inst,
+		  bool use_last_avail);
+int res_mgr_alloc_range(struct global_resource_tag tag, int req_inst,
+			int req_cnt, bool use_last_avail, int *inst);
+int res_mgr_create_resource(struct global_resource_tag tag, int inst_cnt);
+
 /**
  * Read a 32bit value from the Octeon NPI register space
  *
Signature · 1 line
2.14.3
#11 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

Quoted 21 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

Add a global resource manager to manage tagged pointers within bootmem allocated memory. This is used by various functional blocks in the Octeon core like the FPA, Ethernet nexus, etc.

---
 arch/mips/cavium-octeon/Makefile       |   3 +-
 arch/mips/cavium-octeon/resource-mgr.c | 371 +++++++++++++++++++++++++++++++++
 arch/mips/include/asm/octeon/octeon.h  |  18 ++
 3 files changed, 391 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/cavium-octeon/resource-mgr.c
arch/mips/cavium-octeon/Makefile +0 -0
index 7c02e542959a..0a299ab8719f 100644

arch/mips/cavium-octeon/Makefile line 13

Quoted 6 lines
arch/mips/cavium-octeon/Makefile +2 -1
@@ -9,7 +9,8 @@
 # Copyright (C) 2005-2009 Cavium Networks
 #
 
-obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o
+obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o \
+	 resource-mgr.o

Maybe put that on a separate line like below.

Quoted 52 lines
arch/mips/cavium-octeon/Makefile +0 -0
 obj-y += dma-octeon.o
 obj-y += octeon-memcpy.o
 obj-y += executive/
arch/mips/cavium-octeon/resource-mgr.c new file +43 -0
new file mode 100644
index 000000000000..ca25fa953402
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2017 Cavium, Inc.
+ */
+#include <linux/module.h>
+
+#include <asm/octeon/octeon.h>
+#include <asm/octeon/cvmx-bootmem.h>
+
+#define RESOURCE_MGR_BLOCK_NAME		"cvmx-global-resources"
+#define MAX_RESOURCES			128
+#define INST_AVAILABLE			-88
+#define OWNER				0xbadc0de
+
+struct global_resource_entry {
+	struct global_resource_tag tag;
+	u64 phys_addr;
+	u64 size;
+};
+
+struct global_resources {
+#ifdef __LITTLE_ENDIAN_BITFIELD
+	u32 rlock;
+	u32 pad;
+#else
+	u32 pad;
+	u32 rlock;
+#endif
+	u64 entry_cnt;
+	struct global_resource_entry resource_entry[];
+};
+
+static struct global_resources *res_mgr_info;
+
+
+/*
+ * The resource manager interacts with software running outside of the

arch/mips/cavium-octeon/resource-mgr.c line 53

Quoted 10 lines
arch/mips/cavium-octeon/resource-mgr.c new file +10 -0
+ * Linux kernel, which necessitates locking to maintain data structure
+ * consistency.  These custom locking functions implement the locking
+ * protocol, and cannot be replaced by kernel locking functions that
+ * may use different in-memory structures.
+ */
+
+static void res_mgr_lock(void)
+{
+	unsigned int tmp;
+	u64 lock = (u64)&res_mgr_info->rlock;

presumably this could be a u32 *, avoid the cast to u64, and still work just fine below.

arch/mips/cavium-octeon/resource-mgr.c line 59

Quoted 6 lines
arch/mips/cavium-octeon/resource-mgr.c new file +6 -0
+
+	__asm__ __volatile__(
+		".set noreorder\n"
+		"1: ll   %[tmp], 0(%[addr])\n"
+		"   bnez %[tmp], 1b\n"
+		"   li   %[tmp], 1\n"

I believe the convention for .S files is for instructions in branch delay slots to be indented an additional space for readability. Maybe that would be worthwhile here.

arch/mips/cavium-octeon/resource-mgr.c line 62

Quoted 3 lines
arch/mips/cavium-octeon/resource-mgr.c new file +3 -0
+		"   sc   %[tmp], 0(%[addr])\n"
+		"   beqz %[tmp], 1b\n"
+		"   nop\n"

and here also.

arch/mips/cavium-octeon/resource-mgr.c line 63

Quoted 1 line
arch/mips/cavium-octeon/resource-mgr.c new file +1 -0
+		".set reorder\n" :

nit: strictly speaking there's no need for \n on the last line.

arch/mips/cavium-octeon/resource-mgr.c line 66

Quoted 3 lines
arch/mips/cavium-octeon/resource-mgr.c new file +3 -0
+		[tmp] "=&r"(tmp) :
+		[addr] "r"(lock) :
+		"memory");

minor style thing: its far more common to have : at the beginning of the line rather than the end.

arch/mips/cavium-octeon/resource-mgr.c line 71

Quoted 5 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
+}
+
+static void res_mgr_unlock(void)
+{
+	u64 lock = (u64)&res_mgr_info->rlock;

same again

Quoted 22 lines
arch/mips/cavium-octeon/resource-mgr.c new file +22 -0
+
+	/* Wait until all resource operations finish before unlocking. */
+	mb();
+	__asm__ __volatile__(
+		"sw $0, 0(%[addr])\n" : :
+		[addr] "r"(lock) :
+		"memory");
+
+	/* Force a write buffer flush. */
+	mb();
+}
+
+static int res_mgr_find_resource(struct global_resource_tag tag)
+{
+	struct global_resource_entry *res_entry;
+	int i;
+
+	for (i = 0; i < res_mgr_info->entry_cnt; i++) {
+		res_entry = &res_mgr_info->resource_entry[i];
+		if (res_entry->tag.lo == tag.lo && res_entry->tag.hi == tag.hi)
+			return i;
+	}

arch/mips/cavium-octeon/resource-mgr.c line 103

Quoted 10 lines
arch/mips/cavium-octeon/resource-mgr.c new file +10 -0
+	return -1;
+}
+
+/**
+ * res_mgr_create_resource - Create a resource.
+ * @tag: Identifies the resource.
+ * @inst_cnt: Number of resource instances to create.
+ *
+ * Returns 0 if the source was created successfully.
+ * Returns <0 for error codes.

Only -1 seems to be returned. Is it worth returning some standard Linux error codes instead?

Quoted 28 lines
arch/mips/cavium-octeon/resource-mgr.c new file +28 -0
+ */
+int res_mgr_create_resource(struct global_resource_tag tag, int inst_cnt)
+{
+	struct global_resource_entry *res_entry;
+	u64 size;
+	u64 *res_addr;
+	int res_index, i, rc = 0;
+
+	res_mgr_lock();
+
+	/* Make sure resource doesn't already exist. */
+	res_index = res_mgr_find_resource(tag);
+	if (res_index >= 0) {
+		rc = -1;
+		goto err;
+	}
+
+	if (res_mgr_info->entry_cnt >= MAX_RESOURCES) {
+		pr_err("Resource max limit reached, not created\n");
+		rc = -1;
+		goto err;
+	}
+
+	/*
+	 * Each instance is kept in an array of u64s. The first array element
+	 * holds the number of allocated instances.
+	 */
+	size = sizeof(u64) * (inst_cnt + 1);

arch/mips/cavium-octeon/resource-mgr.c line 141

Quoted 10 lines
arch/mips/cavium-octeon/resource-mgr.c new file +10 -0
+	res_addr = cvmx_bootmem_alloc_range(size, CVMX_CACHE_LINE_SIZE, 0, 0);
+	if (!res_addr) {
+		pr_err("Failed to allocate resource. not created\n");
+		rc = -1;
+		goto err;
+	}
+
+	/* Initialize the newly created resource. */
+	*res_addr = inst_cnt;
+	for (i = 1; i < inst_cnt + 1; i++)

or "i <= inst_cnt"?

arch/mips/cavium-octeon/resource-mgr.c line 142

Quoted 1 line
arch/mips/cavium-octeon/resource-mgr.c new file +1 -0
+		*(res_addr + i) = INST_AVAILABLE;

Nit: IMO res_addr[i] is marginally more readable

arch/mips/cavium-octeon/resource-mgr.c line 147

Quoted 5 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
+
+	res_index = res_mgr_info->entry_cnt;
+	res_entry = &res_mgr_info->resource_entry[res_index];
+	res_entry->tag.lo = tag.lo;
+	res_entry->tag.hi = tag.hi;

or res_entry->tag = tag;?

arch/mips/cavium-octeon/resource-mgr.c line 160

Quoted 13 lines
arch/mips/cavium-octeon/resource-mgr.c new file +13 -0
+	res_entry->phys_addr = virt_to_phys(res_addr);
+	res_entry->size = size;
+	res_mgr_info->entry_cnt++;
+
+err:
+	res_mgr_unlock();
+
+	return rc;
+}
+EXPORT_SYMBOL(res_mgr_create_resource);
+
+/**
+ * res_mgr_alloc_range - Allocate a range of resource instances.

I don't know how strict kerndoc is on this, but I think it should be res_mgr_alloc_range() here. Same elsewhere.

Quoted 40 lines
arch/mips/cavium-octeon/resource-mgr.c new file +40 -0
+ * @tag: Identifies the resource.
+ * @req_inst: Requested start of instance range to allocate.
+ *	      Range instances are guaranteed to be sequential
+ *	      (-1 for don't care).
+ * @req_cnt: Number of instances to allocate.
+ * @use_last_avail: Set to request the last available instance.
+ * @inst: Updated with the allocated instances.
+ *
+ * Returns 0 if the source was created successfully.
+ * Returns <0 for error codes.
+ */
+int res_mgr_alloc_range(struct global_resource_tag tag, int req_inst,
+			int req_cnt, bool use_last_avail, int *inst)
+{
+	struct global_resource_entry *res_entry;
+	int res_index;
+	u64 *res_addr;
+	u64 inst_cnt;
+	int alloc_cnt, i, rc = -1;
+
+	/* Start with no instances allocated. */
+	for (i = 0; i < req_cnt; i++)
+		inst[i] = INST_AVAILABLE;
+
+	res_mgr_lock();
+
+	/* Find the resource. */
+	res_index = res_mgr_find_resource(tag);
+	if (res_index < 0) {
+		pr_err("Resource not found, can't allocate instance\n");
+		goto err;
+	}
+
+	/* Get resource data. */
+	res_entry = &res_mgr_info->resource_entry[res_index];
+	res_addr = phys_to_virt(res_entry->phys_addr);
+	inst_cnt = *res_addr;
+
+	/* Allocate the requested instances. */
+	if (req_inst >= 0) {

arch/mips/cavium-octeon/resource-mgr.c line 210

Quoted 10 lines
arch/mips/cavium-octeon/resource-mgr.c new file +10 -0
+		/* Specific instance range requested. */
+		if (req_inst + req_cnt >= inst_cnt) {
+			pr_err("Requested instance out of range\n");
+			goto err;
+		}
+
+		for (i = 0; i < req_cnt; i++) {
+			if (*(res_addr + req_inst + 1 + i) == INST_AVAILABLE)
+				inst[i] = req_inst + i;
+			else {

braces on all branches if on any.

Quoted 71 lines
arch/mips/cavium-octeon/resource-mgr.c new file +71 -0
+				inst[0] = INST_AVAILABLE;
+				break;
+			}
+		}
+	} else if (use_last_avail) {
+		/* Last available instance requested. */
+		alloc_cnt = 0;
+		for (i = inst_cnt; i > 0; i--) {
+			if (*(res_addr + i) == INST_AVAILABLE) {
+				/*
+				 * Instance off by 1 (first element holds the
+				 * count).
+				 */
+				inst[alloc_cnt] = i - 1;
+
+				alloc_cnt++;
+				if (alloc_cnt == req_cnt)
+					break;
+			}
+		}
+
+		if (i == 0)
+			inst[0] = INST_AVAILABLE;
+	} else {
+		/* Next available instance requested. */
+		alloc_cnt = 0;
+		for (i = 1; i <= inst_cnt; i++) {
+			if (*(res_addr + i) == INST_AVAILABLE) {
+				/*
+				 * Instance off by 1 (first element holds the
+				 * count).
+				 */
+				inst[alloc_cnt] = i - 1;
+
+				alloc_cnt++;
+				if (alloc_cnt == req_cnt)
+					break;
+			}
+		}
+
+		if (i > inst_cnt)
+			inst[0] = INST_AVAILABLE;
+	}
+
+	if (inst[0] != INST_AVAILABLE) {
+		for (i = 0; i < req_cnt; i++)
+			*(res_addr + inst[i] + 1) = OWNER;
+		rc = 0;
+	}
+
+err:
+	res_mgr_unlock();
+
+	return rc;
+}
+EXPORT_SYMBOL(res_mgr_alloc_range);
+
+/**
+ * res_mgr_alloc - Allocate a resource instance.
+ * @tag: Identifies the resource.
+ * @req_inst: Requested instance to allocate (-1 for don't care).
+ * @use_last_avail: Set to request the last available instance.
+ *
+ * Returns: Allocated resource instance if successful.
+ * Returns <0 for error codes.
+ */
+int res_mgr_alloc(struct global_resource_tag tag, int req_inst, bool use_last_avail)
+{
+	int inst, rc;
+
+	rc = res_mgr_alloc_range(tag, req_inst, 1, use_last_avail, &inst);

arch/mips/cavium-octeon/resource-mgr.c line 291

Quoted 10 lines
arch/mips/cavium-octeon/resource-mgr.c new file +10 -0
+	if (!rc)
+		return inst;
+	return rc;
+}
+EXPORT_SYMBOL(res_mgr_alloc);
+
+/**
+ * res_mgr_free_range - Free a resource instance range.
+ * @tag: Identifies the resource.
+ * @req_inst: Requested instance to free.

the parameter is called inst.

Other than these minor / style comments, it doesn't look unreasonable to me.

Cheers
James

Quoted 112 lines
arch/mips/cavium-octeon/resource-mgr.c new file +80 -0
+ * @req_cnt: Number of instances to free.
+ */
+void res_mgr_free_range(struct global_resource_tag tag, const int *inst, int req_cnt)
+{
+	struct global_resource_entry *res_entry;
+	int res_index, i;
+	u64 *res_addr;
+
+	res_mgr_lock();
+
+	/* Find the resource. */
+	res_index = res_mgr_find_resource(tag);
+	if (res_index < 0) {
+		pr_err("Resource not found, can't free instance\n");
+		goto err;
+	}
+
+	/* Get the resource data. */
+	res_entry = &res_mgr_info->resource_entry[res_index];
+	res_addr = phys_to_virt(res_entry->phys_addr);
+
+	/* Free the resource instances. */
+	for (i = 0; i < req_cnt; i++) {
+		/* Instance off by 1 (first element holds the count). */
+		*(res_addr + inst[i] + 1) = INST_AVAILABLE;
+	}
+
+err:
+	res_mgr_unlock();
+}
+EXPORT_SYMBOL(res_mgr_free_range);
+
+/**
+ * res_mgr_free - Free a resource instance.
+ * @tag: Identifies the resource.
+ * @req_inst: Requested instance to free.
+ */
+void res_mgr_free(struct global_resource_tag tag, int inst)
+{
+	res_mgr_free_range(tag, &inst, 1);
+}
+EXPORT_SYMBOL(res_mgr_free);
+
+static int __init res_mgr_init(void)
+{
+	struct cvmx_bootmem_named_block_desc *block;
+	int block_size;
+	u64 addr;
+
+	cvmx_bootmem_lock();
+
+	/* Search for the resource manager data in boot memory. */
+	block = cvmx_bootmem_phy_named_block_find(RESOURCE_MGR_BLOCK_NAME, CVMX_BOOTMEM_FLAG_NO_LOCKING);
+	if (block) {
+		/* Found. */
+		res_mgr_info = phys_to_virt(block->base_addr);
+	} else {
+		/* Create it. */
+		block_size = sizeof(struct global_resources) +
+			sizeof(struct global_resource_entry) * MAX_RESOURCES;
+		addr = cvmx_bootmem_phy_named_block_alloc(block_size, 0, 0,
+				CVMX_CACHE_LINE_SIZE, RESOURCE_MGR_BLOCK_NAME,
+				CVMX_BOOTMEM_FLAG_NO_LOCKING);
+		if (!addr) {
+			pr_err("Failed to allocate name block %s\n",
+			       RESOURCE_MGR_BLOCK_NAME);
+		} else {
+			res_mgr_info = phys_to_virt(addr);
+			memset(res_mgr_info, 0, block_size);
+		}
+	}
+
+	cvmx_bootmem_unlock();
+
+	return 0;
+}
+device_initcall(res_mgr_init);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Cavium, Inc. Octeon resource manager");
arch/mips/include/asm/octeon/octeon.h +18 -0
index 92a17d67c1fa..0411efdb465c 100644
@@ -346,6 +346,24 @@ void octeon_mult_restore3_end(void);
 void octeon_mult_restore2(void);
 void octeon_mult_restore2_end(void);
 
+/*
+ * This definition must be kept in sync with the one in
+ * cvmx-global-resources.c
+ */
+struct global_resource_tag {
+	uint64_t lo;
+	uint64_t hi;
+};
+
+void res_mgr_free(struct global_resource_tag tag, int inst);
+void res_mgr_free_range(struct global_resource_tag tag, const int *inst,
+			int req_cnt);
+int res_mgr_alloc(struct global_resource_tag tag, int req_inst,
+		  bool use_last_avail);
+int res_mgr_alloc_range(struct global_resource_tag tag, int req_inst,
+			int req_cnt, bool use_last_avail, int *inst);
+int res_mgr_create_resource(struct global_resource_tag tag, int inst_cnt);
+
 /**
  * Read a 32bit value from the Octeon NPI register space
  *
Signature · 1 line
2.14.3
#12 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

Quoted 25 lines · James Hogan
Quoted 24 lines · David Daney

From: Carlos Munoz <[email protected]>

Add a global resource manager to manage tagged pointers within bootmem allocated memory. This is used by various functional blocks in the Octeon core like the FPA, Ethernet nexus, etc.

---
  arch/mips/cavium-octeon/Makefile       |   3 +-
  arch/mips/cavium-octeon/resource-mgr.c | 371 +++++++++++++++++++++++++++++++++
  arch/mips/include/asm/octeon/octeon.h  |  18 ++
  3 files changed, 391 insertions(+), 1 deletion(-)

create mode 100644 arch/mips/cavium-octeon/resource-mgr.c

arch/mips/cavium-octeon/Makefile +0 -0
index 7c02e542959a..0a299ab8719f 100644
@@ -9,7 +9,8 @@
  # Copyright (C) 2005-2009 Cavium Networks
  #
 
Quoted 5 lines

arch/mips/cavium-octeon/Makefile line 13

Quoted 3 lines
arch/mips/cavium-octeon/Makefile +2 -1
-obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o
+obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o \
+	 resource-mgr.o

Maybe put that on a separate line like below.

OK

Quoted 58 lines
Quoted 58 lines
arch/mips/cavium-octeon/Makefile +0 -0
  obj-y += dma-octeon.o
  obj-y += octeon-memcpy.o
  obj-y += executive/
arch/mips/cavium-octeon/resource-mgr.c new file +48 -0
new file mode 100644
index 000000000000..ca25fa953402
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2017 Cavium, Inc.
+ */
+#include <linux/module.h>
+
+#include <asm/octeon/octeon.h>
+#include <asm/octeon/cvmx-bootmem.h>
+
+#define RESOURCE_MGR_BLOCK_NAME		"cvmx-global-resources"
+#define MAX_RESOURCES			128
+#define INST_AVAILABLE			-88
+#define OWNER				0xbadc0de
+
+struct global_resource_entry {
+	struct global_resource_tag tag;
+	u64 phys_addr;
+	u64 size;
+};
+
+struct global_resources {
+#ifdef __LITTLE_ENDIAN_BITFIELD
+	u32 rlock;
+	u32 pad;
+#else
+	u32 pad;
+	u32 rlock;
+#endif
+	u64 entry_cnt;
+	struct global_resource_entry resource_entry[];
+};
+
+static struct global_resources *res_mgr_info;
+
+
+/*
+ * The resource manager interacts with software running outside of the
+ * Linux kernel, which necessitates locking to maintain data structure
+ * consistency.  These custom locking functions implement the locking
+ * protocol, and cannot be replaced by kernel locking functions that
+ * may use different in-memory structures.
+ */
Quoted 8 lines

arch/mips/cavium-octeon/resource-mgr.c line 53

Quoted 5 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
+
+static void res_mgr_lock(void)
+{
+	unsigned int tmp;
+	u64 lock = (u64)&res_mgr_info->rlock;

presumably this could be a u32 *, avoid the cast to u64, and still work just fine below.

I will rewrite to just use cmpxchg()

Quoted 29 lines

arch/mips/cavium-octeon/resource-mgr.c line 59

Quoted 7 lines
arch/mips/cavium-octeon/resource-mgr.c new file +6 -0
+
+	__asm__ __volatile__(
+		".set noreorder\n"
+		"1: ll   %[tmp], 0(%[addr])\n"
+		"   bnez %[tmp], 1b\n"
+		"   li   %[tmp], 1\n"

I believe the convention for .S files is for instructions in branch delay slots to be indented an additional space for readability. Maybe that would be worthwhile here.

arch/mips/cavium-octeon/resource-mgr.c line 62

Quoted 3 lines
arch/mips/cavium-octeon/resource-mgr.c new file +3 -0
+		"   sc   %[tmp], 0(%[addr])\n"
+		"   beqz %[tmp], 1b\n"
+		"   nop\n"

and here also.

arch/mips/cavium-octeon/resource-mgr.c line 63

Quoted 1 line
arch/mips/cavium-octeon/resource-mgr.c new file +1 -0
+		".set reorder\n" :

nit: strictly speaking there's no need for \n on the last line.

arch/mips/cavium-octeon/resource-mgr.c line 66

Quoted 3 lines
arch/mips/cavium-octeon/resource-mgr.c new file +3 -0
+		[tmp] "=&r"(tmp) :
+		[addr] "r"(lock) :
+		"memory");

minor style thing: its far more common to have : at the beginning of the line rather than the end.

Quoted 8 lines

arch/mips/cavium-octeon/resource-mgr.c line 71

Quoted 5 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
+}
+
+static void res_mgr_unlock(void)
+{
+	u64 lock = (u64)&res_mgr_info->rlock;

same again

Will rewrite to use WRITE_ONCE().

Quoted 27 lines
Quoted 27 lines
arch/mips/cavium-octeon/resource-mgr.c new file +27 -0
+
+	/* Wait until all resource operations finish before unlocking. */
+	mb();
+	__asm__ __volatile__(
+		"sw $0, 0(%[addr])\n" : :
+		[addr] "r"(lock) :
+		"memory");
+
+	/* Force a write buffer flush. */
+	mb();
+}
+
+static int res_mgr_find_resource(struct global_resource_tag tag)
+{
+	struct global_resource_entry *res_entry;
+	int i;
+
+	for (i = 0; i < res_mgr_info->entry_cnt; i++) {
+		res_entry = &res_mgr_info->resource_entry[i];
+		if (res_entry->tag.lo == tag.lo && res_entry->tag.hi == tag.hi)
+			return i;
+	}
+	return -1;
+}
+
+/**
+ * res_mgr_create_resource - Create a resource.
Quoted 8 lines

arch/mips/cavium-octeon/resource-mgr.c line 103

Quoted 5 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
+ * @tag: Identifies the resource.
+ * @inst_cnt: Number of resource instances to create.
+ *
+ * Returns 0 if the source was created successfully.
+ * Returns <0 for error codes.

Only -1 seems to be returned. Is it worth returning some standard Linux error codes instead?

Yep. I fixed this and everything below for the next version of the patch set.

Thanks,
David Daney

#13 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

In reply to James Hogan

Carlos,

Quoted 42 lines · James Hogan
Quoted 21 lines · David Daney

From: Carlos Munoz <[email protected]>

Add a global resource manager to manage tagged pointers within bootmem allocated memory. This is used by various functional blocks in the Octeon core like the FPA, Ethernet nexus, etc.

---
 arch/mips/cavium-octeon/Makefile       |   3 +-
 arch/mips/cavium-octeon/resource-mgr.c | 371 +++++++++++++++++++++++++++++++++
 arch/mips/include/asm/octeon/octeon.h  |  18 ++
 3 files changed, 391 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/cavium-octeon/resource-mgr.c
arch/mips/cavium-octeon/Makefile +0 -0
index 7c02e542959a..0a299ab8719f 100644

arch/mips/cavium-octeon/Makefile line 13

Quoted 6 lines
arch/mips/cavium-octeon/Makefile +2 -1
@@ -9,7 +9,8 @@
 # Copyright (C) 2005-2009 Cavium Networks
 #
 
-obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o
+obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o \
+      resource-mgr.o

Maybe put that on a separate line like below.

Quoted 11 lines
arch/mips/cavium-octeon/Makefile +0 -0
 obj-y += dma-octeon.o
 obj-y += octeon-memcpy.o
 obj-y += executive/
arch/mips/cavium-octeon/resource-mgr.c new file +2 -0
new file mode 100644
index 000000000000..ca25fa953402
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
Quoted 8 lines

arch/mips/cavium-octeon/resource-mgr.c line 10

Quoted 8 lines
arch/mips/cavium-octeon/resource-mgr.c new file +8 -0
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2017 Cavium, Inc.
+ */

Since you nicely included an SPDX id, you would not need the boilerplate anymore. e.g. these can go alright?

Quoted 3 lines
Quoted 3 lines
arch/mips/cavium-octeon/resource-mgr.c new file +3 -0
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
Signature · 2 lines
Cordially
Philippe Ombredanne
#14 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

Quoted 48 lines · Philippe Ombredanne

Carlos,

Quoted 45 lines · James Hogan
Quoted 21 lines · David Daney

From: Carlos Munoz <[email protected]>

Add a global resource manager to manage tagged pointers within bootmem allocated memory. This is used by various functional blocks in the Octeon core like the FPA, Ethernet nexus, etc.

---
  arch/mips/cavium-octeon/Makefile       |   3 +-
  arch/mips/cavium-octeon/resource-mgr.c | 371 +++++++++++++++++++++++++++++++++
  arch/mips/include/asm/octeon/octeon.h  |  18 ++
  3 files changed, 391 insertions(+), 1 deletion(-)

create mode 100644 arch/mips/cavium-octeon/resource-mgr.c

arch/mips/cavium-octeon/Makefile +0 -0
index 7c02e542959a..0a299ab8719f 100644

arch/mips/cavium-octeon/Makefile line 13

Quoted 6 lines
arch/mips/cavium-octeon/Makefile +2 -1
@@ -9,7 +9,8 @@
  # Copyright (C) 2005-2009 Cavium Networks
  #
 
-obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o
+obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o \
+      resource-mgr.o

Maybe put that on a separate line like below.

Quoted 14 lines
arch/mips/cavium-octeon/Makefile +0 -0
  obj-y += dma-octeon.o
  obj-y += octeon-memcpy.o
  obj-y += executive/
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
new file mode 100644
index 000000000000..ca25fa953402
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
Quoted 8 lines
Quoted 5 lines

arch/mips/cavium-octeon/resource-mgr.c line 10

Quoted 5 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2017 Cavium, Inc.
+ */

Since you nicely included an SPDX id, you would not need the boilerplate anymore. e.g. these can go alright?

They may not be strictly speaking necessary, but I don't think they hurt anything. Unless there is a requirement to strip out the license text, we would stick with it as is.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
arch/mips/cavium-octeon/resource-mgr.c new file +3 -0
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
#15 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

David, Greg,

Quoted 1 line · David Daney

On 11/30/2017 11:53 PM, Philippe Ombredanne wrote:

[...]

Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU General

Public
+ * License. See the file "COPYING" in the main directory of this archive

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

+ * for more details.
+ *
+ * Copyright (C) 2017 Cavium, Inc.
+ */

Since you nicely included an SPDX id, you would not need the boilerplate anymore. e.g. these can go alright?

Quoted 3 lines

They may not be strictly speaking necessary, but I don't think they hurt anything. Unless there is a requirement to strip out the license text, we would stick with it as is.

I think the requirement is there and that would be much better for
everyone: keeping both is redundant and does not bring any value, does it? Instead it kinda removes the benefits of having the SPDX id in the first place IMHO.

Furthermore, as there have been already ~12K+ files cleaned up and still over 60K files to go, it would really nice if new files could adopt the new style: this way we will not have to revisit and repatch them in the future.

Signature · 2 lines
Cordially
Philippe Ombredanne
#16 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

Quoted 35 lines · Philippe Ombredanne

David, Greg,

Quoted 1 line · David Daney

On 11/30/2017 11:53 PM, Philippe Ombredanne wrote:

[...]

Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU General

Public
+ * License. See the file "COPYING" in the main directory of this archive

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

+ * for more details.
+ *
+ * Copyright (C) 2017 Cavium, Inc.
+ */

Since you nicely included an SPDX id, you would not need the boilerplate anymore. e.g. these can go alright?

Quoted 3 lines

They may not be strictly speaking necessary, but I don't think they hurt anything. Unless there is a requirement to strip out the license text, we would stick with it as is.

I think the requirement is there and that would be much better for
everyone: keeping both is redundant and does not bring any value, does it? Instead it kinda removes the benefits of having the SPDX id in the first place IMHO.

Quoted 5 lines

Furthermore, as there have been already ~12K+ files cleaned up and still over 60K files to go, it would really nice if new files could adopt the new style: this way we will not have to revisit and repatch them in the future.

I am happy to follow any style Greg would suggest. There doesn't seem to be much documentation about how this should be done yet.

David Daney

#17 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

David,

Quoted 46 lines · David Daney
Quoted 45 lines · Philippe Ombredanne

David, Greg,

Quoted 2 lines · David Daney

On 11/30/2017 11:53 PM, Philippe Ombredanne wrote:

[...]

Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU

General
Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

+ *
+ * Copyright (C) 2017 Cavium, Inc.
+ */

Since you nicely included an SPDX id, you would not need the boilerplate anymore. e.g. these can go alright?

Quoted 4 lines

They may not be strictly speaking necessary, but I don't think they hurt anything. Unless there is a requirement to strip out the license text, we
would stick with it as is.

I think the requirement is there and that would be much better for
everyone: keeping both is redundant and does not bring any value, does it? Instead it kinda removes the benefits of having the SPDX id in the first place IMHO.

Quoted 8 lines
Quoted 5 lines

Furthermore, as there have been already ~12K+ files cleaned up and still over 60K files to go, it would really nice if new files could adopt the new style: this way we will not have to revisit and repatch them in the future.

I am happy to follow any style Greg would suggest. There doesn't seem to be much documentation about how this should be done yet.

Thomas (tglx) has already submitted a first series of doc patches a few weeks ago. And AFAIK he might be working on posting the updates soon, whenever his real time clock yields a few cycles away from real time coding work ;)

See also these discussions with Linus [1][2][3], Thomas[4] and Greg[5] on this and mostly related topics

[1] https://lkml.org/lkml/2017/11/2/715
[2] https://lkml.org/lkml/2017/11/25/125
[3] https://lkml.org/lkml/2017/11/25/133
[4] https://lkml.org/lkml/2017/11/2/805
[5] https://lkml.org/lkml/2017/10/19/165

Signature · 2 lines
Cordially
Philippe Ombredanne
#18 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

Quoted 63 lines · Philippe Ombredanne

David,

Quoted 46 lines · David Daney
Quoted 45 lines · Philippe Ombredanne

David, Greg,

Quoted 2 lines · David Daney

On 11/30/2017 11:53 PM, Philippe Ombredanne wrote:

[...]

Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU

General
Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

+ *
+ * Copyright (C) 2017 Cavium, Inc.
+ */

Since you nicely included an SPDX id, you would not need the boilerplate anymore. e.g. these can go alright?

Quoted 4 lines

They may not be strictly speaking necessary, but I don't think they hurt anything. Unless there is a requirement to strip out the license text, we
would stick with it as is.

I think the requirement is there and that would be much better for
everyone: keeping both is redundant and does not bring any value, does it? Instead it kinda removes the benefits of having the SPDX id in the first place IMHO.

Quoted 8 lines
Quoted 5 lines

Furthermore, as there have been already ~12K+ files cleaned up and still over 60K files to go, it would really nice if new files could adopt the new style: this way we will not have to revisit and repatch them in the future.

I am happy to follow any style Greg would suggest. There doesn't seem to be much documentation about how this should be done yet.

Thomas (tglx) has already submitted a first series of doc patches a few weeks ago. And AFAIK he might be working on posting the updates soon, whenever his real time clock yields a few cycles away from real time coding work ;)

Quoted 9 lines

See also these discussions with Linus [1][2][3], Thomas[4] and Greg[5] on this and mostly related topics

[1] https://lkml.org/lkml/2017/11/2/715
[2] https://lkml.org/lkml/2017/11/25/125
[3] https://lkml.org/lkml/2017/11/25/133
[4] https://lkml.org/lkml/2017/11/2/805
[5] https://lkml.org/lkml/2017/10/19/165

OK, you convinced me.

Thanks,
David

#19 lore raw

Re: [PATCH v4 3/8] MIPS: Octeon: Add a global resource manager.

Quoted 87 lines · David Daney
Quoted 76 lines · Philippe Ombredanne

David,

Quoted 61 lines · David Daney
Quoted 53 lines · Philippe Ombredanne

David, Greg,

Quoted 3 lines · David Daney

On 11/30/2017 11:53 PM, Philippe Ombredanne wrote:

[...]

Quoted 28 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Resource manager for Octeon.
+ *
+ * This file is subject to the terms and conditions of the GNU

General
Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

+ * Copyright (C) 2017 Cavium, Inc.
+ */

Since you nicely included an SPDX id, you would not need the boilerplate anymore. e.g. these can go alright?

Quoted 5 lines

They may not be strictly speaking necessary, but I don't think they hurt
anything. Unless there is a requirement to strip out the license text, we
would stick with it as is.

I think the requirement is there and that would be much better for
everyone: keeping both is redundant and does not bring any value, does it? Instead it kinda removes the benefits of having the SPDX id in the first place IMHO.

Quoted 5 lines

Furthermore, as there have been already ~12K+ files cleaned up and still over 60K files to go, it would really nice if new files could adopt the new style: this way we will not have to revisit and repatch them in the future.

Quoted 3 lines

I am happy to follow any style Greg would suggest. There doesn't seem to be
much documentation about how this should be done yet.

Thomas (tglx) has already submitted a first series of doc patches a few weeks ago. And AFAIK he might be working on posting the updates soon, whenever his real time clock yields a few cycles away from real time coding work ;)

Quoted 9 lines

See also these discussions with Linus [1][2][3], Thomas[4] and Greg[5] on this and mostly related topics

[1] https://lkml.org/lkml/2017/11/2/715
[2] https://lkml.org/lkml/2017/11/25/125
[3] https://lkml.org/lkml/2017/11/25/133
[4] https://lkml.org/lkml/2017/11/2/805
[5] https://lkml.org/lkml/2017/10/19/165

Quoted 5 lines

OK, you convinced me.

Thanks,
David

No! Thank you to you: For doing real work on the kernel that makes my servers and laptops run, while I am nitpicking you on comments.

Signature · 6 lines
Cordially
Philippe Ombredanne
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#20 lore raw

PATCH v4 4/8 MIPS: Octeon: Add Free Pointer Unit (FPA) support.

In reply to David Daney

From: Carlos Munoz <[email protected]>

Quoted 1 line

From the hardware user manual: "The FPA is a unit that maintains

pools of pointers to free L2/DRAM memory. To provide QoS, the pools are referenced indirectly through 1024 auras. Both core software and hardware units allocate and free pointers."

---
 arch/mips/cavium-octeon/Kconfig       |   8 +
 arch/mips/cavium-octeon/Makefile      |   1 +
 arch/mips/cavium-octeon/octeon-fpa3.c | 364 ++++++++++++++++++++++++++++++++++
 arch/mips/include/asm/octeon/octeon.h |  15 ++
 4 files changed, 388 insertions(+)
 create mode 100644 arch/mips/cavium-octeon/octeon-fpa3.c
arch/mips/cavium-octeon/Kconfig +8 -0
index 204a1670fd9b..ce469f982134 100644
@@ -87,4 +87,12 @@ config OCTEON_ILM
 	  To compile this driver as a module, choose M here.  The module
 	  will be called octeon-ilm
 
+config OCTEON_FPA3
+	tristate "Octeon III fpa driver"
+	help
+	  This option enables a Octeon III driver for the Free Pool Unit (FPA).
+	  The FPA is a hardware unit that manages pools of pointers to free
+	  L2/DRAM memory. This driver provides an interface to reserve,
+	  initialize, and fill fpa pools.
+
 endif # CAVIUM_OCTEON_SOC
arch/mips/cavium-octeon/Makefile +1 -0
index 0a299ab8719f..0ef967399702 100644
@@ -20,3 +20,4 @@ obj-$(CONFIG_MTD)		      += flash_setup.o
 obj-$(CONFIG_SMP)		      += smp.o
 obj-$(CONFIG_OCTEON_ILM)	      += oct_ilm.o
 obj-$(CONFIG_USB)		      += octeon-usb.o
+obj-$(CONFIG_OCTEON_FPA3)	      += octeon-fpa3.o
arch/mips/cavium-octeon/octeon-fpa3.c new file +364 -0

364 lines not on this page · raw message

arch/mips/include/asm/octeon/octeon.h +15 -0
index 0411efdb465c..d184592e6515 100644
@@ -10,6 +10,7 @@
 
 #include <asm/octeon/cvmx.h>
 #include <asm/bitfield.h>
+#include <linux/slab.h>
 
 extern uint64_t octeon_bootmem_alloc_range_phys(uint64_t size,
 						uint64_t alignment,
@@ -364,6 +365,20 @@ int res_mgr_alloc_range(struct global_resource_tag tag, int req_inst,
 			int req_cnt, bool use_last_avail, int *inst);
 int res_mgr_create_resource(struct global_resource_tag tag, int inst_cnt);
 
+#if IS_ENABLED(CONFIG_OCTEON_FPA3)
+int octeon_fpa3_init(int node);
+int octeon_fpa3_pool_init(int node, int pool_num, int *pool, void **pool_stack,
+			  int num_ptrs);
+int octeon_fpa3_aura_init(int node, int pool, int aura_num, int *aura,
+			  int num_bufs, unsigned int limit);
+int octeon_fpa3_mem_fill(int node, struct kmem_cache *cache, int aura,
+			 int num_bufs);
+void octeon_fpa3_free(u64 node, int aura, const void *buf);
+void *octeon_fpa3_alloc(u64 node, int aura);
+void octeon_fpa3_release_pool(int node, int pool);
+void octeon_fpa3_release_aura(int node, int aura);
+#endif
+
 /**
  * Read a 32bit value from the Octeon NPI register space
  *
Signature · 1 line
2.14.3
#21 lore raw

PATCH v4 5/8 MIPS: Octeon: Automatically provision CVMSEG space.

In reply to David Daney

Remove CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE and automatically calculate the amount of CVMSEG space needed.

1st 128-bytes: Use by IOBDMA
2nd 128-bytes: Reserved by kernel for scratch/TLS emulation. 3rd 128-bytes: OCTEON-III LMTLINE

New config variable CONFIG_CAVIUM_OCTEON_EXTRA_CVMSEG provisions additional lines, defaults to zero.

---
 arch/mips/cavium-octeon/Kconfig                    | 27 ++++++++++++--------
 arch/mips/cavium-octeon/setup.c                    | 16 ++++++------
 .../asm/mach-cavium-octeon/kernel-entry-init.h     | 20 +++++++++------
 arch/mips/include/asm/mipsregs.h                   |  2 ++
 arch/mips/include/asm/octeon/octeon.h              |  2 ++
 arch/mips/include/asm/processor.h                  |  2 +-
 arch/mips/kernel/octeon_switch.S                   |  2 --
 arch/mips/mm/tlbex.c                               | 29 ++++++----------------
 drivers/staging/octeon/ethernet-defines.h          |  2 +-
 9 files changed, 50 insertions(+), 52 deletions(-)
arch/mips/cavium-octeon/Kconfig +16 -11
index ce469f982134..29c4d81364a6 100644
@@ -11,21 +11,26 @@ config CAVIUM_CN63XXP1
 	  non-CN63XXP1 hardware, so it is recommended to select "n"
 	  unless it is known the workarounds are needed.
 
-config CAVIUM_OCTEON_CVMSEG_SIZE
-	int "Number of L1 cache lines reserved for CVMSEG memory"
-	range 0 54
-	default 1
-	help
-	  CVMSEG LM is a segment that accesses portions of the dcache as a
-	  local memory; the larger CVMSEG is, the smaller the cache is.
-	  This selects the size of CVMSEG LM, which is in cache blocks. The
-	  legally range is from zero to 54 cache blocks (i.e. CVMSEG LM is
-	  between zero and 6192 bytes).
-
 endif # CPU_CAVIUM_OCTEON
 
 if CAVIUM_OCTEON_SOC
 
+config CAVIUM_OCTEON_EXTRA_CVMSEG
+	int "Number of extra L1 cache lines reserved for CVMSEG memory"
+	range 0 50
+	default 0
+	help
+	  CVMSEG LM is a segment that accesses portions of the dcache
+	  as a local memory; the larger CVMSEG is, the smaller the
+	  cache is.  The kernel uses two or three blocks (one for TLB
+	  exception handlers, one for driver IOBDMA operations, and on
+	  models that need it, one for LMTDMA operations). This
+	  selects an optional extra number of CVMSEG lines for use by
+	  other software.
+
+	  Normally no extra lines are required, and this parameter
+	  should be set to zero.
+
 config CAVIUM_OCTEON_LOCK_L2
 	bool "Lock often used kernel code in the L2"
 	default "y"
arch/mips/cavium-octeon/setup.c +9 -7
index 99e6a68bc652..51c4d3c3cada 100644
@@ -68,6 +68,12 @@ extern void pci_console_init(const char *arg);
 static unsigned long long max_memory = ULLONG_MAX;
 static unsigned long long reserve_low_mem;
 
+/*
+ * modified in hernel-entry-init.h, must have an initial value to keep
+ * it from being clobbered when bss is zeroed.
+ */
+u32 octeon_cvmseg_lines = 2;
+
 DEFINE_SEMAPHORE(octeon_bootbus_sem);
 EXPORT_SYMBOL(octeon_bootbus_sem);
 
@@ -604,11 +610,7 @@ void octeon_user_io_init(void)
 
 	/* R/W If set, CVMSEG is available for loads/stores in
 	 * kernel/debug mode. */
-#if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
 	cvmmemctl.s.cvmsegenak = 1;
-#else
-	cvmmemctl.s.cvmsegenak = 0;
-#endif
 	if (OCTEON_IS_OCTEON3()) {
 		/* Enable LMTDMA */
 		cvmmemctl.s.lmtena = 1;
@@ -626,9 +628,9 @@ void octeon_user_io_init(void)
 
 	/* Setup of CVMSEG is done in kernel-entry-init.h */
 	if (smp_processor_id() == 0)
-		pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
-			  CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
-			  CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
+		pr_notice("CVMSEG size: %u cache lines (%u bytes)\n",
+			  octeon_cvmseg_lines,
+			  octeon_cvmseg_lines * 128);
 
 	if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
 		union cvmx_iob_fau_timeout fau_timeout;
arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h +12 -8
index c38b38ce5a3d..cdcca60978a2 100644
@@ -26,11 +26,18 @@
 	# a3 = address of boot descriptor block
 	.set push
 	.set arch=octeon
+	mfc0	v1, CP0_PRID_REG
+	andi	v1, 0xff00
+	li	v0, 0x9500		# cn78XX or later
+	subu	v1, v1, v0
+	li	t2, 2 + CONFIG_CAVIUM_OCTEON_EXTRA_CVMSEG
+	bltz	v1, 1f
+	addiu	t2, 1			# t2 has cvmseg_size
+1:
 	# Read the cavium mem control register
 	dmfc0	v0, CP0_CVMMEMCTL_REG
 	# Clear the lower 6 bits, the CVMSEG size
-	dins	v0, $0, 0, 6
-	ori	v0, CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
+	dins	v0, t2, 0, 6
 	dmtc0	v0, CP0_CVMMEMCTL_REG	# Write the cavium mem control register
 	dmfc0	v0, CP0_CVMCTL_REG	# Read the cavium control register
 	# Disable unaligned load/store support but leave HW fixup enabled
@@ -70,7 +77,7 @@
 	# Flush dcache after config change
 	cache	9, 0($0)
 	# Zero all of CVMSEG to make sure parity is correct
-	dli	v0, CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
+	move	v0, t2
 	dsll	v0, 7
 	beqz	v0, 2f
 1:	dsubu	v0, 8
@@ -126,12 +133,7 @@
 	LONG_L	sp, (t0)
 	# Set the SP global variable to zero so the master knows we've started
 	LONG_S	zero, (t0)
-#ifdef __OCTEON__
-	syncw
-	syncw
-#else
 	sync
-#endif
 	# Jump to the normal Linux SMP entry point
 	j   smp_bootstrap
 	nop
@@ -148,6 +150,8 @@
 
 #endif /* CONFIG_SMP */
 octeon_main_processor:
+	dla	v0, octeon_cvmseg_lines
+	sw	t2, 0(v0)
 	.set pop
 .endm
 
arch/mips/include/asm/mipsregs.h +2 -0
index 6b1f1ad0542c..0b588640b65a 100644
@@ -1126,6 +1126,8 @@
 #define FPU_CSR_RD	0x3	/* towards -Infinity */
 
 
+#define CAVIUM_OCTEON_SCRATCH_OFFSET (2 * 128 - 16 - 32768)
+
 #ifndef __ASSEMBLY__
 
 /*
arch/mips/include/asm/octeon/octeon.h +2 -0
index d184592e6515..02eb194b2cdc 100644
@@ -392,6 +392,8 @@ static inline uint32_t octeon_npi_read32(uint64_t address)
 
 extern struct cvmx_bootinfo *octeon_bootinfo;
 
+extern u32 octeon_cvmseg_lines;
+
 extern uint64_t octeon_bootloader_entry_addr;
 
 extern void (*octeon_irq_setup_secondary)(void);
arch/mips/include/asm/processor.h +1 -1
index af34afbc32d9..1a20f9c5509f 100644
@@ -216,7 +216,7 @@ struct octeon_cop2_state {
 	.cp2			= {0,},
 
 struct octeon_cvmseg_state {
-	unsigned long cvmseg[CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE]
+	unsigned long cvmseg[CONFIG_CAVIUM_OCTEON_EXTRA_CVMSEG + 3]
 			    [cpu_dcache_line_size() / sizeof(unsigned long)];
 };
 
arch/mips/kernel/octeon_switch.S +0 -2
index e42113fe2762..4f56902d5ee7 100644
@@ -29,7 +29,6 @@
 	cpu_save_nonscratch a0
 	LONG_S	ra, THREAD_REG31(a0)
 
-#if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
 	/* Check if we need to store CVMSEG state */
 	dmfc0	t0, $11,7	/* CvmMemCtl */
 	bbit0	t0, 6, 3f	/* Is user access enabled? */
@@ -58,7 +57,6 @@
 	dmfc0	t0, $11,7	/* CvmMemCtl */
 	xori	t0, t0, 0x40	/* Bit 6 is CVMSEG user enable */
 	dmtc0	t0, $11,7	/* CvmMemCtl */
-#endif
 3:
 
 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
arch/mips/mm/tlbex.c +7 -22
index 79b9f2ad3ff5..3d3dfba465ae 100644
@@ -115,33 +115,17 @@ static int use_lwx_insns(void)
 		return 0;
 	}
 }
-#if defined(CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE) && \
-    CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
-static bool scratchpad_available(void)
-{
-	return true;
-}
-static int scratchpad_offset(int i)
-{
-	/*
-	 * CVMSEG starts at address -32768 and extends for
-	 * CAVIUM_OCTEON_CVMSEG_SIZE 128 byte cache lines.
-	 */
-	i += 1; /* Kernel use starts at the top and works down. */
-	return CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128 - (8 * i) - 32768;
-}
-#else
-static bool scratchpad_available(void)
-{
-	return false;
-}
+
 static int scratchpad_offset(int i)
 {
+	if (IS_ENABLED(CONFIG_CPU_CAVIUM_OCTEON))
+		return (CAVIUM_OCTEON_SCRATCH_OFFSET - (8 * i));
+
 	BUG();
 	/* Really unreachable, but evidently some GCC want this. */
 	return 0;
 }
-#endif
+
 /*
  * Found by experiment: At least some revisions of the 4kc throw under
  * some circumstances a machine check exception, triggered by invalid
@@ -1302,7 +1286,8 @@ static void build_r4000_tlb_refill_handler(void)
 	memset(relocs, 0, sizeof(relocs));
 	memset(final_handler, 0, sizeof(final_handler));
 
-	if (IS_ENABLED(CONFIG_64BIT) && (scratch_reg >= 0 || scratchpad_available()) && use_bbit_insns()) {
+	if (IS_ENABLED(CONFIG_64BIT) && use_bbit_insns() &&
+	   (scratch_reg >= 0 || IS_ENABLED(CONFIG_CPU_CAVIUM_OCTEON))) {
 		htlb_info = build_fast_tlb_refill_handler(&p, &l, &r, K0, K1,
 							  scratch_reg);
 		vmalloc_mode = refill_scratch;
drivers/staging/octeon/ethernet-defines.h +1 -1
index 07bd2b87f6a0..e898df25b87f 100644
@@ -32,7 +32,7 @@
 #define REUSE_SKBUFFS_WITHOUT_FREE  1
 #endif
 
-#define USE_ASYNC_IOBDMA            (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0)
+#define USE_ASYNC_IOBDMA	1
 
 /* Maximum number of SKBs to try to free per xmit packet. */
 #define MAX_OUT_QUEUE_DEPTH 1000
Signature · 1 line
2.14.3
#22 lore raw

PATCH v4 6/8 staging: octeon: Remove USE_ASYNC_IOBDMA macro.

In reply to David Daney

Previous patch sets USE_ASYNC_IOBDMA to 1 unconditionally. Remove USE_ASYNC_IOBDMA from all if statements. Remove dead code caused by the change.

---
 drivers/staging/octeon/ethernet-defines.h |  6 ---
 drivers/staging/octeon/ethernet-rx.c      | 25 ++++-----
 drivers/staging/octeon/ethernet-tx.c      | 85 ++++++++++---------------------
 3 files changed, 37 insertions(+), 79 deletions(-)
drivers/staging/octeon/ethernet-defines.h +0 -6
index e898df25b87f..21438c804a43 100644
@@ -10,10 +10,6 @@
 
 /*
  * A few defines are used to control the operation of this driver:
- *  USE_ASYNC_IOBDMA
- *      Use asynchronous IO access to hardware. This uses Octeon's asynchronous
- *      IOBDMAs to issue IO accesses without stalling. Set this to zero
- *      to disable this. Note that IOBDMAs require CVMSEG.
  *  REUSE_SKBUFFS_WITHOUT_FREE
  *      Allows the TX path to free an skbuff into the FPA hardware pool. This
  *      can significantly improve performance for forwarding and bridging, but
@@ -32,8 +28,6 @@
 #define REUSE_SKBUFFS_WITHOUT_FREE  1
 #endif
 
-#define USE_ASYNC_IOBDMA	1
-
 /* Maximum number of SKBs to try to free per xmit packet. */
 #define MAX_OUT_QUEUE_DEPTH 1000
 
drivers/staging/octeon/ethernet-rx.c +10 -15
index 1a44291318ee..dd76c99d5ae0 100644
@@ -201,11 +201,9 @@ static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)
 	/* Prefetch cvm_oct_device since we know we need it soon */
 	prefetch(cvm_oct_device);
 
-	if (USE_ASYNC_IOBDMA) {
-		/* Save scratch in case userspace is using it */
-		CVMX_SYNCIOBDMA;
-		old_scratch = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
-	}
+	/* Save scratch in case userspace is using it */
+	CVMX_SYNCIOBDMA;
+	old_scratch = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
 
 	/* Only allow work for our group (and preserve priorities) */
 	if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
@@ -220,10 +218,8 @@ static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)
 			       BIT(rx_group->group));
 	}
 
-	if (USE_ASYNC_IOBDMA) {
-		cvmx_pow_work_request_async(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT);
-		did_work_request = 1;
-	}
+	cvmx_pow_work_request_async(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT);
+	did_work_request = 1;
 
 	while (rx_count < budget) {
 		struct sk_buff *skb = NULL;
@@ -232,7 +228,7 @@ static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)
 		cvmx_wqe_t *work;
 		int port;
 
-		if (USE_ASYNC_IOBDMA && did_work_request)
+		if (did_work_request)
 			work = cvmx_pow_work_response_async(CVMX_SCR_SCRATCH);
 		else
 			work = cvmx_pow_work_request_sync(CVMX_POW_NO_WAIT);
@@ -260,7 +256,7 @@ static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)
 			sizeof(void *));
 		prefetch(pskb);
 
-		if (USE_ASYNC_IOBDMA && rx_count < (budget - 1)) {
+		if (rx_count < (budget - 1)) {
 			cvmx_pow_work_request_async_nocheck(CVMX_SCR_SCRATCH,
 							    CVMX_POW_NO_WAIT);
 			did_work_request = 1;
@@ -403,10 +399,9 @@ static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)
 		cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), old_group_mask);
 	}
 
-	if (USE_ASYNC_IOBDMA) {
-		/* Restore the scratch area */
-		cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch);
-	}
+	/* Restore the scratch area */
+	cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch);
+
 	cvm_oct_rx_refill_pool(0);
 
 	return rx_count;
drivers/staging/octeon/ethernet-tx.c +27 -58

115 lines not on this page · raw message

Signature · 1 line
2.14.3
#24 lore raw

PATCH v4 7/8 netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to David Daney

From: Carlos Munoz <[email protected]>

The Cavium OCTEON cn78xx and cn73xx SoCs have network packet I/O hardware that is significantly different from previous generations of the family.

Add a new driver for this hardware. The Ethernet MAC is called BGX on these devices. Common code for the MAC is in octeon3-bgx-port.c. Four of these BGX MACs are grouped together and managed as a group by octeon3-bgx-nexus.c. Ingress packet classification is done by the PKI unit initialized in octeon3-pki.c. Queue management is done in the SSO, initialized by octeon3-sso.c. Egress is handled by the PKO, initialized in octeon3-pko.c.

---
 drivers/net/ethernet/cavium/Kconfig                |   55 +-
 drivers/net/ethernet/cavium/octeon/Makefile        |    6 +
 .../net/ethernet/cavium/octeon/octeon3-bgx-nexus.c |  698 +++++++
 .../net/ethernet/cavium/octeon/octeon3-bgx-port.c  | 2033 +++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-core.c  | 2068 ++++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pki.c   |  832 ++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pko.c   | 1719 ++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-sso.c   |  309 +++
 drivers/net/ethernet/cavium/octeon/octeon3.h       |  411 ++++
 9 files changed, 8121 insertions(+), 10 deletions(-)
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-core.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pki.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pko.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-sso.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3.h
drivers/net/ethernet/cavium/Kconfig +45 -10
index 63be75eb34d2..decce5178a27 100644
@@ -4,7 +4,7 @@
 
 config NET_VENDOR_CAVIUM
 	bool "Cavium ethernet drivers"
-	depends on PCI
+	depends on PCI || CAVIUM_OCTEON_SOC
 	default y
 	---help---
 	  Select this option if you want enable Cavium network support.
@@ -13,6 +13,12 @@ config NET_VENDOR_CAVIUM
 
 if NET_VENDOR_CAVIUM
 
+#
+# The Thunder* and LiquidIO drivers require PCI.
+#
+
+if PCI
+
 config THUNDER_NIC_PF
 	tristate "Thunder Physical function driver"
 	depends on 64BIT
@@ -64,6 +70,20 @@ config LIQUIDIO
 	  To compile this driver as a module, choose M here: the module
 	  will be called liquidio.  This is recommended.
 
+config LIQUIDIO_VF
+	tristate "Cavium LiquidIO VF support"
+	depends on 64BIT && PCI_MSI
+	imply PTP_1588_CLOCK
+	---help---
+	  This driver supports Cavium LiquidIO Intelligent Server Adapter
+	  based on CN23XX chips.
+
+	  To compile this driver as a module, choose M here: The module
+	  will be called liquidio_vf. MSI-X interrupt support is required
+	  for this driver to work correctly
+
+endif # PCI
+
 config OCTEON_MGMT_ETHERNET
 	tristate "Octeon Management port ethernet driver (CN5XXX, CN6XXX)"
 	depends on CAVIUM_OCTEON_SOC
@@ -75,16 +95,31 @@ config OCTEON_MGMT_ETHERNET
 	  port on Cavium Networks' Octeon CN57XX, CN56XX, CN55XX,
 	  CN54XX, CN52XX, and CN6XXX chips.
 
-config LIQUIDIO_VF
-	tristate "Cavium LiquidIO VF support"
-	depends on 64BIT && PCI_MSI
-	imply PTP_1588_CLOCK
+config OCTEON3_BGX_NEXUS
+	tristate
+	depends on CAVIUM_OCTEON_SOC
+
+config OCTEON3_BGX_PORT
+	tristate "Cavium OCTEON-III BGX port support"
+	depends on CAVIUM_OCTEON_SOC
+	select OCTEON3_BGX_NEXUS
 	---help---
-	  This driver supports Cavium LiquidIO Intelligent Server Adapter
-	  based on CN23XX chips.
+	  Enable the driver for Cavium Octeon III BGX ports. BGX ports
+	  support sgmii, rgmii, xaui, rxaui, xlaui, xfi, 10KR and 40KR modes.
 
-	  To compile this driver as a module, choose M here: The module
-	  will be called liquidio_vf. MSI-X interrupt support is required
-	  for this driver to work correctly
+	  Say Y for support of any Octeon III SoC Ethernet port.
+
+config OCTEON3_ETHERNET
+	tristate "Cavium OCTEON-III PKI/PKO Ethernet support"
+	depends on CAVIUM_OCTEON_SOC
+	select OCTEON_BGX_PORT
+	select OCTEON_FPA3
+	select FW_LOADER
+	---help---
+	  Enable the driver for Cavium Octeon III Ethernet via PKI/PKO
+	  units.  No support for cn70xx chips (use OCTEON_ETHERNET for
+	  cn70xx).
+
+	  Say Y for support of any Octeon III SoC Ethernet port.
 
 endif # NET_VENDOR_CAVIUM
drivers/net/ethernet/cavium/octeon/Makefile +6 -0
index efa41c1d91c5..1eacab1d8dad 100644
@@ -3,3 +3,9 @@
 #
 
 obj-$(CONFIG_OCTEON_MGMT_ETHERNET)	+= octeon_mgmt.o
+obj-$(CONFIG_OCTEON3_BGX_PORT)		+= octeon3-bgx-port.o
+obj-$(CONFIG_OCTEON3_BGX_NEXUS)		+= octeon3-bgx-nexus.o
+obj-$(CONFIG_OCTEON3_ETHERNET)		+= octeon3-ethernet.o
+
+octeon3-ethernet-objs += octeon3-core.o octeon3-pki.o octeon3-sso.o \
+			 octeon3-pko.o
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +698 -0

698 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +2033 -0

2,033 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +2068 -0

180 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-pki.c new file +832 -0

832 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-pko.c new file +1719 -0

1,719 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-sso.c new file +309 -0

309 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3.h new file +411 -0

411 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.14.3

Part of the diff is not shown here. View the raw message.

#25 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

Quoted 1,492 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

The Cavium OCTEON cn78xx and cn73xx SoCs have network packet I/O hardware that is significantly different from previous generations of the family.

Add a new driver for this hardware. The Ethernet MAC is called BGX on these devices. Common code for the MAC is in octeon3-bgx-port.c. Four of these BGX MACs are grouped together and managed as a group by octeon3-bgx-nexus.c. Ingress packet classification is done by the PKI unit initialized in octeon3-pki.c. Queue management is done in the SSO, initialized by octeon3-sso.c. Egress is handled by the PKO, initialized in octeon3-pko.c.

---
 drivers/net/ethernet/cavium/Kconfig                |   55 +-
 drivers/net/ethernet/cavium/octeon/Makefile        |    6 +
 .../net/ethernet/cavium/octeon/octeon3-bgx-nexus.c |  698 +++++++
 .../net/ethernet/cavium/octeon/octeon3-bgx-port.c  | 2033 +++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-core.c  | 2068 ++++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pki.c   |  832 ++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pko.c   | 1719 ++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-sso.c   |  309 +++
 drivers/net/ethernet/cavium/octeon/octeon3.h       |  411 ++++
 9 files changed, 8121 insertions(+), 10 deletions(-)
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-core.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pki.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pko.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-sso.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3.h
drivers/net/ethernet/cavium/Kconfig +45 -10
index 63be75eb34d2..decce5178a27 100644
@@ -4,7 +4,7 @@
 
 config NET_VENDOR_CAVIUM
        bool "Cavium ethernet drivers"
-       depends on PCI
+       depends on PCI || CAVIUM_OCTEON_SOC
        default y
        ---help---
          Select this option if you want enable Cavium network support.
@@ -13,6 +13,12 @@ config NET_VENDOR_CAVIUM
 
 if NET_VENDOR_CAVIUM
 
+#
+# The Thunder* and LiquidIO drivers require PCI.
+#
+
+if PCI
+
 config THUNDER_NIC_PF
        tristate "Thunder Physical function driver"
        depends on 64BIT
@@ -64,6 +70,20 @@ config LIQUIDIO
          To compile this driver as a module, choose M here: the module
          will be called liquidio.  This is recommended.
 
+config LIQUIDIO_VF
+       tristate "Cavium LiquidIO VF support"
+       depends on 64BIT && PCI_MSI
+       imply PTP_1588_CLOCK
+       ---help---
+         This driver supports Cavium LiquidIO Intelligent Server Adapter
+         based on CN23XX chips.
+
+         To compile this driver as a module, choose M here: The module
+         will be called liquidio_vf. MSI-X interrupt support is required
+         for this driver to work correctly
+
+endif # PCI
+
 config OCTEON_MGMT_ETHERNET
        tristate "Octeon Management port ethernet driver (CN5XXX, CN6XXX)"
        depends on CAVIUM_OCTEON_SOC
@@ -75,16 +95,31 @@ config OCTEON_MGMT_ETHERNET
          port on Cavium Networks' Octeon CN57XX, CN56XX, CN55XX,
          CN54XX, CN52XX, and CN6XXX chips.
 
-config LIQUIDIO_VF
-       tristate "Cavium LiquidIO VF support"
-       depends on 64BIT && PCI_MSI
-       imply PTP_1588_CLOCK
+config OCTEON3_BGX_NEXUS
+       tristate
+       depends on CAVIUM_OCTEON_SOC
+
+config OCTEON3_BGX_PORT
+       tristate "Cavium OCTEON-III BGX port support"
+       depends on CAVIUM_OCTEON_SOC
+       select OCTEON3_BGX_NEXUS
        ---help---
-         This driver supports Cavium LiquidIO Intelligent Server Adapter
-         based on CN23XX chips.
+         Enable the driver for Cavium Octeon III BGX ports. BGX ports
+         support sgmii, rgmii, xaui, rxaui, xlaui, xfi, 10KR and 40KR modes.
 
-         To compile this driver as a module, choose M here: The module
-         will be called liquidio_vf. MSI-X interrupt support is required
-         for this driver to work correctly
+         Say Y for support of any Octeon III SoC Ethernet port.
+
+config OCTEON3_ETHERNET
+       tristate "Cavium OCTEON-III PKI/PKO Ethernet support"
+       depends on CAVIUM_OCTEON_SOC
+       select OCTEON_BGX_PORT
+       select OCTEON_FPA3
+       select FW_LOADER
+       ---help---
+         Enable the driver for Cavium Octeon III Ethernet via PKI/PKO
+         units.  No support for cn70xx chips (use OCTEON_ETHERNET for
+         cn70xx).
+
+         Say Y for support of any Octeon III SoC Ethernet port.
 
 endif # NET_VENDOR_CAVIUM
drivers/net/ethernet/cavium/octeon/Makefile +6 -0
index efa41c1d91c5..1eacab1d8dad 100644
@@ -3,3 +3,9 @@
 #
 
 obj-$(CONFIG_OCTEON_MGMT_ETHERNET)     += octeon_mgmt.o
+obj-$(CONFIG_OCTEON3_BGX_PORT)         += octeon3-bgx-port.o
+obj-$(CONFIG_OCTEON3_BGX_NEXUS)                += octeon3-bgx-nexus.o
+obj-$(CONFIG_OCTEON3_ETHERNET)         += octeon3-ethernet.o
+
+octeon3-ethernet-objs += octeon3-core.o octeon3-pki.o octeon3-sso.o \
+                        octeon3-pko.o
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +698 -0
new file mode 100644
index 000000000000..c3dca3337a47
@@ -0,0 +1,698 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2017 Cavium, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+#include <linux/ctype.h>
+
+#include "octeon3.h"
+
+static atomic_t request_mgmt_once;
+static atomic_t load_driver_once;
+static atomic_t pki_id;
+
+static char *mix_port;
+module_param(mix_port, charp, 0444);
+MODULE_PARM_DESC(mix_port, "Specifies which ports connect to MIX interfaces.");
+
+static char *pki_port;
+module_param(pki_port, charp, 0444);
+MODULE_PARM_DESC(pki_port, "Specifies which ports connect to the PKI.");
+
+#define MAX_MIX_PER_NODE       2
+
+#define MAX_MIX                        (MAX_NODES * MAX_MIX_PER_NODE)
+
+/**
+ * struct mix_port_lmac - Describes a lmac that connects to a mix
+ *                       port. The lmac must be on the same node as
+ *                       the mix.
+ * @node:      Node of the lmac.
+ * @bgx:       Bgx of the lmac.
+ * @lmac:      Lmac index.
+ */
+struct mix_port_lmac {
+       int     node;
+       int     bgx;
+       int     lmac;
+};
+
+/* mix_ports_lmacs contains all the lmacs connected to mix ports */
+static struct mix_port_lmac mix_port_lmacs[MAX_MIX];
+
+/* pki_ports keeps track of the lmacs connected to the pki */
+static bool pki_ports[MAX_NODES][MAX_BGX_PER_NODE][MAX_LMAC_PER_BGX];
+
+/* Created platform devices get added to this list */
+static struct list_head pdev_list;
+static struct mutex pdev_list_lock;
+
+/* Created platform device use this structure to add themselves to the list */
+struct pdev_list_item {
+       struct list_head        list;
+       struct platform_device  *pdev;
+};
+
+/**
+ * is_lmac_to_mix - Search the list of lmacs connected to mix'es for a match.
+ * @node: Numa node of lmac to search for.
+ * @bgx: Bgx of lmac to search for.
+ * @lmac: Lmac index to search for.
+ *
+ * Returns true if the lmac is connected to a mix.
+ * Returns false if the lmac is not connected to a mix.
+ */
+static bool is_lmac_to_mix(int node, int bgx, int lmac)
+{
+       int     i;
+
+       for (i = 0; i < MAX_MIX; i++) {
+               if (mix_port_lmacs[i].node == node &&
+                   mix_port_lmacs[i].bgx == bgx &&
+                   mix_port_lmacs[i].lmac == lmac)
+                       return true;
+       }
+
+       return false;
+}
+
+/**
+ * is_lmac_to_pki - Search the list of lmacs connected to the pki for a match.
+ * @node: Numa node of lmac to search for.
+ * @bgx: Bgx of lmac to search for.
+ * @lmac: Lmac index to search for.
+ *
+ * Returns true if the lmac is connected to the pki.
+ * Returns false if the lmac is not connected to the pki.
+ */
+static bool is_lmac_to_pki(int node, int bgx, int lmac)
+{
+       return pki_ports[node][bgx][lmac];
+}
+
+/**
+ * is_lmac_to_xcv - Check if this lmac is connected to the xcv block (rgmii).
+ * @of_node: Device node to check.
+ *
+ * Returns true if the lmac is connected to the xcv port.
+ * Returns false if the lmac is not connected to the xcv port.
+ */
+static bool is_lmac_to_xcv(struct device_node *of_node)
+{
+       return of_device_is_compatible(of_node, "cavium,octeon-7360-xcv");
+}
+
+static int bgx_probe(struct platform_device *pdev)
+{
+       struct mac_platform_data platform_data;
+       const __be32 *reg;
+       u32 port;
+       u64 addr;
+       struct device_node *child;
+       struct platform_device *new_dev;
+       struct platform_device *pki_dev;
+       int numa_node, interface;
+       int i;
+       int r = 0;
+       char id[64];
+       u64 data;
+
+       reg = of_get_property(pdev->dev.of_node, "reg", NULL);
+       addr = of_translate_address(pdev->dev.of_node, reg);
+       interface = (addr >> 24) & 0xf;
+       numa_node = (addr >> 36) & 0x7;
+
+       /* Assign 8 CAM entries per LMAC */
+       for (i = 0; i < 32; i++) {
+               data = i >> 3;
+               oct_csr_write(data, BGX_CMR_RX_ADRX_CAM(numa_node, interface, i));
+       }
+
+       for_each_available_child_of_node(pdev->dev.of_node, child) {
+               bool is_mix = false;
+               bool is_pki = false;
+               bool is_xcv = false;
+               struct pdev_list_item *pdev_item;
+
+               if (!of_device_is_compatible(child, "cavium,octeon-7890-bgx-port") &&
+                   !of_device_is_compatible(child, "cavium,octeon-7360-xcv"))
+                       continue;
+               r = of_property_read_u32(child, "reg", &port);
+               if (r)
+                       return -ENODEV;
+
+               is_mix = is_lmac_to_mix(numa_node, interface, port);
+               is_pki = is_lmac_to_pki(numa_node, interface, port);
+               is_xcv = is_lmac_to_xcv(child);
+
+               /* Check if this port should be configured */
+               if (!is_mix && !is_pki)
+                       continue;
+
+               /* Connect to PKI/PKO */
+               data = oct_csr_read(BGX_CMR_CONFIG(numa_node, interface, port));
+               if (is_mix)
+                       data |= BIT(11);
+               else
+                       data &= ~BIT(11);
+               oct_csr_write(data, BGX_CMR_CONFIG(numa_node, interface, port));
+
+               /* Unreset the mix bgx interface or it will interfare with the
+                * other ports.
+                */
+               if (is_mix) {
+                       data = oct_csr_read(BGX_CMR_GLOBAL_CONFIG(numa_node, interface));
+                       if (!port)
+                               data &= ~BIT(3);
+                       else if (port == 1)
+                               data &= ~BIT(4);
+                       oct_csr_write(data, BGX_CMR_GLOBAL_CONFIG(numa_node, interface));
+               }
+
+               snprintf(id, sizeof(id), "%llx.%u.ethernet-mac",
+                        (unsigned long long)addr, port);
+               new_dev = of_platform_device_create(child, id, &pdev->dev);
+               if (!new_dev) {
+                       dev_err(&pdev->dev, "Error creating %s\n", id);
+                       continue;
+               }
+               platform_data.mac_type = BGX_MAC;
+               platform_data.numa_node = numa_node;
+               platform_data.interface = interface;
+               platform_data.port = port;
+               if (is_xcv)
+                       platform_data.src_type = XCV;
+               else
+                       platform_data.src_type = QLM;
+
+               /* Add device to the list of created devices so we can remove it
+                * on exit.
+                */
+               pdev_item = kmalloc(sizeof(*pdev_item), GFP_KERNEL);
+               pdev_item->pdev = new_dev;
+               mutex_lock(&pdev_list_lock);
+               list_add(&pdev_item->list, &pdev_list);
+               mutex_unlock(&pdev_list_lock);
+
+               i = atomic_inc_return(&pki_id);
+               pki_dev = platform_device_register_data(&new_dev->dev,
+                                                       is_mix ? "octeon_mgmt" : "ethernet-mac-pki",
+                                                       i, &platform_data, sizeof(platform_data));
+               dev_info(&pdev->dev, "Created %s %u: %p\n",
+                        is_mix ? "MIX" : "PKI", pki_dev->id, pki_dev);
+
+               /* Add device to the list of created devices so we can remove it
+                * on exit.
+                */
+               pdev_item = kmalloc(sizeof(*pdev_item), GFP_KERNEL);
+               pdev_item->pdev = pki_dev;
+               mutex_lock(&pdev_list_lock);
+               list_add(&pdev_item->list, &pdev_list);
+               mutex_unlock(&pdev_list_lock);
+
+#ifdef CONFIG_NUMA
+               new_dev->dev.numa_node = pdev->dev.numa_node;
+               pki_dev->dev.numa_node = pdev->dev.numa_node;
+#endif
+               /* One time request driver module */
+               if (is_mix) {
+                       if (atomic_cmpxchg(&request_mgmt_once, 0, 1) == 0)
+                               request_module_nowait("octeon_mgmt");
+               }
+               if (is_pki) {
+                       if (atomic_cmpxchg(&load_driver_once, 0, 1) == 0)
+                               request_module_nowait("octeon3-ethernet");
+               }
+       }
+
+       dev_info(&pdev->dev, "Probed\n");
+       return 0;
+}
+
+/**
+ * bgx_mix_init_from_fdt - Initialize the list of lmacs that connect to mix
+ *                        ports from information in the device tree.
+ *
+ * Returns 0 if successful.
+ * Returns <0 for error codes.
+ */
+static int bgx_mix_init_from_fdt(void)
+{
+       struct device_node      *node;
+       struct device_node      *parent = NULL;
+       int                     mix = 0;
+
+       for_each_compatible_node(node, NULL, "cavium,octeon-7890-mix") {
+               struct device_node      *lmac_fdt_node;
+               const __be32            *reg;
+               u64                     addr;
+
+               /* Get the fdt node of the lmac connected to this mix */
+               lmac_fdt_node = of_parse_phandle(node, "cavium,mac-handle", 0);
+               if (!lmac_fdt_node)
+                       goto err;
+
+               /* Get the numa node and bgx of the lmac */
+               parent = of_get_parent(lmac_fdt_node);
+               if (!parent)
+                       goto err;
+               reg = of_get_property(parent, "reg", NULL);
+               if (!reg)
+                       goto err;
+               addr = of_translate_address(parent, reg);
+               of_node_put(parent);
+               parent = NULL;
+
+               mix_port_lmacs[mix].node = (addr >> 36) & 0x7;
+               mix_port_lmacs[mix].bgx = (addr >> 24) & 0xf;
+
+               /* Get the lmac index */
+               reg = of_get_property(lmac_fdt_node, "reg", NULL);
+               if (!reg)
+                       goto err;
+
+               mix_port_lmacs[mix].lmac = *reg;
+
+               mix++;
+               if (mix >= MAX_MIX)
+                       break;
+       }
+
+       return 0;
+ err:
+       pr_warn("Invalid device tree mix port information\n");
+       for (mix = 0; mix < MAX_MIX; mix++) {
+               mix_port_lmacs[mix].node = -1;
+               mix_port_lmacs[mix].bgx = -1;
+               mix_port_lmacs[mix].lmac = -1;
+       }
+       if (parent)
+               of_node_put(parent);
+
+       return -EINVAL;
+}
+
+/**
+ * bgx_mix_init_from_param - Initialize the list of lmacs that connect to mix
+ *                          ports from information in the "mix_port" parameter.
+ *                          The mix_port parameter format is as follows:
+ *                          mix_port=nbl
+ *                          where:
+ *                             n = node
+ *                             b = bgx
+ *                             l = lmac
+ *                          There can be up to 4 lmacs defined separated by
+ *                          commas. For example to select node0, bgx0, lmac0
+ *                          and node0, bgx4, lamc0, the mix_port parameter
+ *                          would be: mix_port=000,040
+ *
+ * Returns 0 if successful.
+ * Returns <0 for error codes.
+ */
+static int bgx_mix_init_from_param(void)
+{
+       char    *p = mix_port;
+       int     mix = 0;
+       int     i;
+
+       while (*p) {
+               int     node = -1;
+               int     bgx = -1;
+               int     lmac = -1;
+
+               if (strlen(p) < 3)
+                       goto err;
+
+               /* Get the numa node */
+               if (!isdigit(*p))
+                       goto err;
+               node = *p - '0';
+               if (node >= MAX_NODES)
+                       goto err;
+
+               /* Get the bgx */
+               p++;
+               if (!isdigit(*p))
+                       goto err;
+               bgx = *p - '0';
+               if (bgx >= MAX_BGX_PER_NODE)
+                       goto err;
+
+               /* Get the lmac index */
+               p++;
+               if (!isdigit(*p))
+                       goto err;
+               lmac = *p - '0';
+               if (lmac >= 2)
+                       goto err;
+
+               /* Only one lmac0 and one lmac1 per node is supported */
+               for (i = 0; i < MAX_MIX; i++) {
+                       if (mix_port_lmacs[i].node == node &&
+                           mix_port_lmacs[i].lmac == lmac)
+                               goto err;
+               }
+
+               mix_port_lmacs[mix].node = node;
+               mix_port_lmacs[mix].bgx = bgx;
+               mix_port_lmacs[mix].lmac = lmac;
+
+               p++;
+               if (*p == ',')
+                       p++;
+
+               mix++;
+               if (mix >= MAX_MIX)
+                       break;
+       }
+
+       return 0;
+ err:
+       pr_warn("Invalid parameter mix_port=%s\n", mix_port);
+       for (mix = 0; mix < MAX_MIX; mix++) {
+               mix_port_lmacs[mix].node = -1;
+               mix_port_lmacs[mix].bgx = -1;
+               mix_port_lmacs[mix].lmac = -1;
+       }
+       return -EINVAL;
+}
+
+/**
+ * bgx_mix_port_lmacs_init - Initialize the mix_port_lmacs variable with the
+ *                          lmacs that connect to mic ports.
+ *
+ * Returns 0 if successful.
+ * Returns <0 for error codes.
+ */
+static int bgx_mix_port_lmacs_init(void)
+{
+       int     mix;
+
+       /* Start with no mix ports configured */
+       for (mix = 0; mix < MAX_MIX; mix++) {
+               mix_port_lmacs[mix].node = -1;
+               mix_port_lmacs[mix].bgx = -1;
+               mix_port_lmacs[mix].lmac = -1;
+       }
+
+       /* Check if no mix port should be configured */
+       if (mix_port && !strcmp(mix_port, "none"))
+               return 0;
+
+       /* Configure the mix ports using information from the device tree if no
+        * parameter was passed. Otherwise, use the information in the module
+        * parameter.
+        */
+       if (!mix_port)
+               bgx_mix_init_from_fdt();
+       else
+               bgx_mix_init_from_param();
+
+       return 0;
+}
+
+/**
+ * bgx_parse_pki_elem - Parse a single element (node, bgx, or lmac) out a pki
+ *                     lmac string and set its bitmap accordingly.
+ * @str: Pki lmac string to parse.
+ * @bitmap: Updated with the bits selected by str.
+ * @size: Maximum size of the bitmap.
+ *
+ * Returns number of characters processed from str.
+ * Returns <0 for error codes.
+ */
+static int bgx_parse_pki_elem(const char *str, unsigned long *bitmap, int size)
+{
+       const char      *p = str;
+       int             len = -1;
+       int             bit;
+
+       if (*p == 0) {
+               /* If identifier is missing, the whole subset is allowed */
+               bitmap_set(bitmap, 0, size);
+               len = 0;
+       } else if (*p == '*') {
+               /* If identifier is an asterisk, the whole subset is allowed */
+               bitmap_set(bitmap, 0, size);
+               len = 1;
+       } else if (isdigit(*p)) {
+               /* If identifier is a digit, only the bit corresponding to the
+                * digit is set.
+                */
+               bit = *p - '0';
+               if (bit < size) {
+                       bitmap_set(bitmap, bit, 1);
+                       len = 1;
+               }
+       } else if (*p == '[') {
+               /* If identifier is a bracket, all the bits corresponding to
+                * the digits inside the bracket are set.
+                */
+               p++;
+               len = 1;
+               do {
+                       if (isdigit(*p)) {
+                               bit = *p - '0';
+                               if (bit < size)
+                                       bitmap_set(bitmap, bit, 1);
+                               else
+                                       return -1;
+                       } else {
+                               return -1;
+                       }
+                       p++;
+                       len++;
+               } while (*p != ']');
+               len++;
+       } else {
+               len = -1;
+       }
+
+       return len;
+}
+
+/**
+ * bgx_pki_bitmap_set - Set the bitmap bits for all elements (node, bgx, and
+ *                     lmac) selected by a pki lmac string.
+ * @str: Pki lmac string to process.
+ * @node: Updated with the nodes specified in the pki lmac string.
+ * @bgx: Updated with the bgx's specified in the pki lmac string.
+ * @lmac: Updated with the lmacs specified in the pki lmac string.
+ *
+ * Returns 0 if successful.
+ * Returns <0 for error codes.
+ */
+static unsigned long bgx_pki_bitmap_set(const char *str, unsigned long *node,
+                                       unsigned long *bgx, unsigned long *lmac)
+{
+       const char      *p = str;
+       int             len;
+
+       /* Parse the node */
+       len = bgx_parse_pki_elem(p, node, MAX_NODES);
+       if (len < 0)
+               goto err;
+
+       /* Parse the bgx */
+       p += len;
+       len = bgx_parse_pki_elem(p, bgx, MAX_BGX_PER_NODE);
+       if (len < 0)
+               goto err;
+
+       /* Parse the lmac */
+       p += len;
+       len = bgx_parse_pki_elem(p, lmac, MAX_LMAC_PER_BGX);
+       if (len < 0)
+               goto err;
+
+       return 0;
+ err:
+       bitmap_zero(node, MAX_NODES);
+       bitmap_zero(bgx, MAX_BGX_PER_NODE);
+       bitmap_zero(lmac, MAX_LMAC_PER_BGX);
+       return len;
+}
+
+/**
+ * bgx_pki_init_from_param - Initialize the list of lmacs that connect to the
+ *                          pki from information in the "pki_port" parameter.
+ *
+ *                          The pki_port parameter format is as follows:
+ *                          pki_port=nbl
+ *                          where:
+ *                             n = node
+ *                             b = bgx
+ *                             l = lmac
+ *
+ *                          Commas must be used to separate multiple lmacs:
+ *                          pki_port=000,100,110
+ *
+ *                          Asterisks (*) specify all possible characters in
+ *                          the subset:
+ *                          pki_port=00* (all lmacs of node0 bgx0).
+ *
+ *                          Missing lmacs identifiers default to all
+ *                          possible characters in the subset:
+ *                          pki_port=00 (all lmacs on node0 bgx0)
+ *
+ *                          Brackets ('[' and ']') specify the valid
+ *                          characters in the subset:
+ *                          pki_port=00[01] (lmac0 and lmac1 of node0 bgx0).
+ *
+ * Returns 0 if successful.
+ * Returns <0 for error codes.
+ */
+static int bgx_pki_init_from_param(void)
+{
+       char    *cur;
+       char    *next;
+       DECLARE_BITMAP(node_bitmap, MAX_NODES);
+       DECLARE_BITMAP(bgx_bitmap, MAX_BGX_PER_NODE);
+       DECLARE_BITMAP(lmac_bitmap, MAX_LMAC_PER_BGX);
+
+       /* Parse each comma separated lmac specifier */
+       cur = pki_port;
+       while (cur) {
+               unsigned long   node;
+               unsigned long   bgx;
+               unsigned long   lmac;
+
+               bitmap_zero(node_bitmap, BITS_PER_LONG);
+               bitmap_zero(bgx_bitmap, BITS_PER_LONG);
+               bitmap_zero(lmac_bitmap, BITS_PER_LONG);
+
+               next = strchr(cur, ',');
+               if (next)
+                       *next++ = '\0';
+
+               /* Convert the specifier into a bitmap */
+               bgx_pki_bitmap_set(cur, node_bitmap, bgx_bitmap, lmac_bitmap);
+
+               /* Mark the lmacs to be connected to the pki */
+               for_each_set_bit(node, node_bitmap, MAX_NODES) {
+                       for_each_set_bit(bgx, bgx_bitmap, MAX_BGX_PER_NODE) {
+                               for_each_set_bit(lmac, lmac_bitmap,
+                                                MAX_LMAC_PER_BGX)
+                                       pki_ports[node][bgx][lmac] = true;
+                       }
+               }
+
+               cur = next;
+       }
+
+       return 0;
+}
+
+/**
+ * bgx_pki_ports_init - Initialize the pki_ports variable with the lmacs that
+ *                     connect to the pki.
+ *
+ * Returns 0 if successful.
+ * Returns <0 for error codes.
+ */
+static int bgx_pki_ports_init(void)
+{
+       int     i, j, k;
+       bool    def_val;
+
+       /* Whether all ports default to connect to the pki or not depend on the
+        * passed module parameter (if any).
+        */
+       if (pki_port)
+               def_val = false;
+       else
+               def_val = true;
+
+       for (i = 0; i < MAX_NODES; i++) {
+               for (j = 0; j < MAX_BGX_PER_NODE; j++) {
+                       for (k = 0; k < MAX_LMAC_PER_BGX; k++)
+                               pki_ports[i][j][k] = def_val;
+               }
+       }
+
+       /* Check if ports have to be individually configured */
+       if (pki_port && strcmp(pki_port, "none"))
+               bgx_pki_init_from_param();
+
+       return 0;
+}
+
+static int bgx_remove(struct platform_device *pdev)
+{
+       return 0;
+}
+
+static void bgx_shutdown(struct platform_device *pdev)
+{
+}
+
+static const struct of_device_id bgx_match[] = {
+       {
+               .compatible = "cavium,octeon-7890-bgx",
+       },
+       {},
+};
+MODULE_DEVICE_TABLE(of, bgx_match);
+
+static struct platform_driver bgx_driver = {
+       .probe          = bgx_probe,
+       .remove         = bgx_remove,
+       .shutdown       = bgx_shutdown,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = KBUILD_MODNAME,
+               .of_match_table = bgx_match,
+       },
+};
+
+/* Allow bgx_port driver to force this driver to load */
+void bgx_nexus_load(void)
+{
+}
+EXPORT_SYMBOL(bgx_nexus_load);
+
+static int __init bgx_driver_init(void)
+{
+       int r;
+
+       INIT_LIST_HEAD(&pdev_list);
+       mutex_init(&pdev_list_lock);
+
+       bgx_mix_port_lmacs_init();
+       bgx_pki_ports_init();
+
+       r = platform_driver_register(&bgx_driver);
+
+       return r;
+}
+
+static void __exit bgx_driver_exit(void)
+{
+       struct pdev_list_item *pdev_item;
+
+       mutex_lock(&pdev_list_lock);
+       while (!list_empty(&pdev_list)) {
+               pdev_item = list_first_entry(&pdev_list, struct pdev_list_item, list);
+               list_del(&pdev_item->list);
+               platform_device_unregister(pdev_item->pdev);
+               kfree(pdev_item);
+       }
+       mutex_unlock(&pdev_list_lock);
+
+       platform_driver_unregister(&bgx_driver);
+}
+
+module_init(bgx_driver_init);
+module_exit(bgx_driver_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Cavium, Inc. <[email protected]>");
+MODULE_DESCRIPTION("Cavium, Inc. BGX MAC Nexus driver.");
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +644 -0
new file mode 100644
index 000000000000..4dad35fa4270
@@ -0,0 +1,2033 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2017 Cavium, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/platform_device.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/of_mdio.h>
+#include <linux/of_net.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+
+#include <asm/octeon/octeon.h>
+
+#include "octeon3.h"
+
+struct bgx_port_priv {
+       int node;
+       int bgx;
+       int index; /* Port index on BGX block*/
+       enum port_mode mode;
+       int pknd;
+       int qlm;
+       const u8 *mac_addr;
+       struct phy_device *phydev;
+       struct device_node *phy_np;
+       int phy_mode;
+       bool mode_1000basex;
+       bool bgx_as_phy;
+       struct net_device *netdev;
+       struct mutex lock;      /* Serializes delayed work */
+       struct port_status (*get_link)(struct bgx_port_priv *priv);
+       int (*set_link)(struct bgx_port_priv *priv, struct port_status status);
+       struct port_status last_status;
+       struct delayed_work dwork;
+       bool work_queued;
+};
+
+/* lmac_pknd keeps track of the port kinds assigned to the lmacs */
+static int lmac_pknd[MAX_NODES][MAX_BGX_PER_NODE][MAX_LMAC_PER_BGX];
+
+static struct workqueue_struct *check_state_wq;
+static DEFINE_MUTEX(check_state_wq_mutex);
+
+int bgx_port_get_qlm(int node, int bgx, int index)
+{
+       u64     data;
+       int     qlm = -1;
+
+       if (OCTEON_IS_MODEL(OCTEON_CN78XX)) {
+               if (bgx < 2) {
+                       data = oct_csr_read(BGX_CMR_GLOBAL_CONFIG(node, bgx));
+                       if (data & 1)
+                               qlm = bgx + 2;
+                       else
+                               qlm = bgx;
+               } else {
+                       qlm = bgx + 2;
+               }
+       } else if (OCTEON_IS_MODEL(OCTEON_CN73XX)) {
+               if (bgx < 2) {
+                       qlm = bgx + 2;
+               } else {
+                       /* Ports on bgx2 can be connected to qlm5 or qlm6 */
+                       if (index < 2)
+                               qlm = 5;
+                       else
+                               qlm = 6;
+               }
+       } else if (OCTEON_IS_MODEL(OCTEON_CNF75XX)) {
+               /* Ports on bgx0 can be connected to qlm4 or qlm5 */
+               if (index < 2)
+                       qlm = 4;
+               else
+                       qlm = 5;
+       }
+
+       return qlm;
+}
+EXPORT_SYMBOL(bgx_port_get_qlm);
+
+/* Returns the mode of the bgx port */
+enum port_mode bgx_port_get_mode(int node, int bgx, int index)
+{
+       enum port_mode  mode;
+       u64             data;
+
+       data = oct_csr_read(BGX_CMR_CONFIG(node, bgx, index));
+
+       switch ((data >> 8) & 7) {
+       case 0:
+               mode = PORT_MODE_SGMII;
+               break;
+       case 1:
+               mode = PORT_MODE_XAUI;
+               break;
+       case 2:
+               mode = PORT_MODE_RXAUI;
+               break;
+       case 3:
+               data = oct_csr_read(BGX_SPU_BR_PMD_CONTROL(node, bgx, index));
+               /* The use of training differentiates 10G_KR from xfi */
+               if (data & BIT(1))
+                       mode = PORT_MODE_10G_KR;
+               else
+                       mode = PORT_MODE_XFI;
+               break;
+       case 4:
+               data = oct_csr_read(BGX_SPU_BR_PMD_CONTROL(node, bgx, index));
+               /* The use of training differentiates 40G_KR4 from xlaui */
+               if (data & BIT(1))
+                       mode = PORT_MODE_40G_KR4;
+               else
+                       mode = PORT_MODE_XLAUI;
+               break;
+       case 5:
+               mode = PORT_MODE_RGMII;
+               break;
+       default:
+               mode = PORT_MODE_DISABLED;
+               break;
+       }
+
+       return mode;
+}
+EXPORT_SYMBOL(bgx_port_get_mode);
+
+int bgx_port_allocate_pknd(int node)
+{
+       struct global_resource_tag      tag;
+       char                            buf[16];
+       int                             pknd;
+
+       strncpy((char *)&tag.lo, "cvm_pknd", 8);
+       snprintf(buf, 16, "_%d......", node);
+       memcpy(&tag.hi, buf, 8);
+
+       res_mgr_create_resource(tag, 64);
+       pknd = res_mgr_alloc(tag, -1, false);
+       if (pknd < 0) {
+               pr_err("bgx-port: Failed to allocate pknd\n");
+               return -ENODEV;
+       }
+
+       return pknd;
+}
+EXPORT_SYMBOL(bgx_port_allocate_pknd);
+
+int bgx_port_get_pknd(int node, int bgx, int index)
+{
+       return lmac_pknd[node][bgx][index];
+}
+EXPORT_SYMBOL(bgx_port_get_pknd);
+
+/* GSER-20075 */
+static void bgx_port_gser_20075(struct bgx_port_priv   *priv,
+                               int                     qlm,
+                               int                     lane)
+{
+       u64     data;
+       u64     addr;
+
+       if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) &&
+           (lane == -1 || lane == 3)) {
+               /* Enable software control */
+               addr = GSER_BR_RX_CTL(priv->node, qlm, 3);
+               data = oct_csr_read(addr);
+               data |= BIT(2);
+               oct_csr_write(data, addr);
+
+               /* Clear the completion flag */
+               addr = GSER_BR_RX_EER(priv->node, qlm, 3);
+               data = oct_csr_read(addr);
+               data &= ~BIT(14);
+               oct_csr_write(data, addr);
+
+               /* Initiate a new request on lane 2 */
+               if (lane == 3) {
+                       addr = GSER_BR_RX_EER(priv->node, qlm, 2);
+                       data = oct_csr_read(addr);
+                       data |= BIT(15);
+                       oct_csr_write(data, addr);
+               }
+       }
+}
+
+static void bgx_common_init_pknd(struct bgx_port_priv *priv)
+{
+       u64     data;
+       int     num_ports;
+
+       /* Setup pkind */
+       priv->pknd = bgx_port_allocate_pknd(priv->node);
+       lmac_pknd[priv->node][priv->bgx][priv->index] = priv->pknd;
+       data = oct_csr_read(BGX_CMR_RX_ID_MAP(priv->node, priv->bgx, priv->index));
+       data &= ~GENMASK_ULL(7, 0);
+       data |= priv->pknd;
+       if (OCTEON_IS_MODEL(OCTEON_CN73XX)) {
+               /* Change the default reassembly id (max allowed is 14) */
+               data &= ~GENMASK_ULL(14, 8);
+               data |= ((4 * priv->bgx) + 2 + priv->index) << 8;
+       }
+       oct_csr_write(data, BGX_CMR_RX_ID_MAP(priv->node, priv->bgx, priv->index));
+
+       /* Set backpressure channel mask AND/OR registers */
+       data = oct_csr_read(BGX_CMR_CHAN_MSK_AND(priv->node, priv->bgx));
+       data |= 0xffff << (16 * priv->index);
+       oct_csr_write(data, BGX_CMR_CHAN_MSK_AND(priv->node, priv->bgx));
+
+       data = oct_csr_read(BGX_CMR_CHAN_MSK_OR(priv->node, priv->bgx));
+       data |= 0xffff << (16 * priv->index);
+       oct_csr_write(data, BGX_CMR_CHAN_MSK_OR(priv->node, priv->bgx));
+
+       /* Rx back pressure watermark:
+        * Set to 1/4 of the available lmacs buffer (in multiple of 16 bytes)
+        */
+       data = oct_csr_read(BGX_CMR_TX_LMACS(priv->node, priv->bgx));
+       num_ports = data & 7;
+       data = BGX_RX_FIFO_SIZE / (num_ports * 4 * 16);
+       oct_csr_write(data, BGX_CMR_RX_BP_ON(priv->node, priv->bgx, priv->index));
+}
+
+static int bgx_xgmii_hardware_init(struct bgx_port_priv *priv)
+{
+       u64     clock_mhz;
+       u64     data;
+       u64     ctl;
+
+       /* Set TX Threshold */
+       data = 0x20;
+       oct_csr_write(data, BGX_GMP_GMI_TX_THRESH(priv->node, priv->bgx, priv->index));
+
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       data &= ~(BIT(8) | BIT(9));
+       if (priv->mode_1000basex)
+               data |= BIT(8);
+       if (priv->bgx_as_phy)
+               data |= BIT(9);
+       oct_csr_write(data, BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+
+       data = oct_csr_read(BGX_GMP_PCS_LINK_TIMER(priv->node, priv->bgx, priv->index));
+       clock_mhz = octeon_get_io_clock_rate() / 1000000;
+       if (priv->mode_1000basex)
+               data = (10000ull * clock_mhz) >> 10;
+       else
+               data = (1600ull * clock_mhz) >> 10;
+       oct_csr_write(data, BGX_GMP_PCS_LINK_TIMER(priv->node, priv->bgx, priv->index));
+
+       if (priv->mode_1000basex) {
+               data = oct_csr_read(BGX_GMP_PCS_AN_ADV(priv->node, priv->bgx, priv->index));
+               data &= ~(GENMASK_ULL(13, 12) | GENMASK_ULL(8, 7));
+               data |= 3 << 7;
+               data |= BIT(6) | BIT(5);
+               oct_csr_write(data, BGX_GMP_PCS_AN_ADV(priv->node, priv->bgx, priv->index));
+       } else if (priv->bgx_as_phy) {
+               data = oct_csr_read(BGX_GMP_PCS_SGM_AN_ADV(priv->node, priv->bgx, priv->index));
+               data |= BIT(12);
+               data &= ~(GENMASK_ULL(11, 10));
+               data |= 2 << 10;
+               oct_csr_write(data, BGX_GMP_PCS_SGM_AN_ADV(priv->node, priv->bgx, priv->index));
+       }
+
+       data = oct_csr_read(BGX_GMP_GMI_TX_APPEND(priv->node, priv->bgx, priv->index));
+       ctl = oct_csr_read(BGX_GMP_GMI_TX_SGMII_CTL(priv->node, priv->bgx, priv->index));
+       ctl &= ~BIT(0);
+       ctl |= (data & BIT(0)) ? 0 : 1;
+       oct_csr_write(ctl, BGX_GMP_GMI_TX_SGMII_CTL(priv->node, priv->bgx, priv->index));
+
+       if (priv->mode == PORT_MODE_RGMII) {
+               /* Disable XCV interface when initialized */
+               data = oct_csr_read(XCV_RESET(priv->node));
+               data &= ~(BIT(63) | BIT(3) | BIT(1));
+               oct_csr_write(data, XCV_RESET(priv->node));
+       }
+
+       return 0;
+}
+
+int bgx_get_tx_fifo_size(struct bgx_port_priv *priv)
+{
+       u64     data;
+       int     num_ports;
+
+       data = oct_csr_read(BGX_CMR_TX_LMACS(priv->node, priv->bgx));
+       num_ports = data & 7;
+
+       switch (num_ports) {
+       case 1:
+               return BGX_TX_FIFO_SIZE;
+       case 2:
+               return BGX_TX_FIFO_SIZE / 2;
+       case 3:
+       case 4:
+               return BGX_TX_FIFO_SIZE / 4;
+       default:
+               return 0;
+       }
+}
+
+static int bgx_xaui_hardware_init(struct bgx_port_priv *priv)
+{
+       u64     data;
+       u64     clock_mhz;
+       u64     tx_fifo_size;
+
+       if (octeon_is_simulation()) {
+               /* Enable the port */
+               data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+               data |= BIT(15);
+               oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       } else {
+               /* Reset the port */
+               data = oct_csr_read(BGX_SPU_CONTROL1(priv->node, priv->bgx, priv->index));
+               data |= BIT(15);
+               oct_csr_write(data, BGX_SPU_CONTROL1(priv->node, priv->bgx, priv->index));
+
+               /* Wait for reset to complete */
+               udelay(1);
+               data = oct_csr_read(BGX_SPU_CONTROL1(priv->node, priv->bgx, priv->index));
+               if (data & BIT(15)) {
+                       netdev_err(priv->netdev,
+                                  "BGX%d:%d: SPU stuck in reset\n", priv->bgx, priv->node);
+                       return -1;
+               }
+
+               /* Reset the SerDes lanes */
+               data = oct_csr_read(BGX_SPU_CONTROL1(priv->node, priv->bgx, priv->index));
+               data |= BIT(11);
+               oct_csr_write(data, BGX_SPU_CONTROL1(priv->node, priv->bgx, priv->index));
+
+               /* Disable packet reception */
+               data = oct_csr_read(BGX_SPU_MISC_CONTROL(priv->node, priv->bgx, priv->index));
+               data |= BIT(12);
+               oct_csr_write(data, BGX_SPU_MISC_CONTROL(priv->node, priv->bgx, priv->index));
+
+               /* Clear/disable interrupts */
+               data = oct_csr_read(BGX_SMU_RX_INT(priv->node, priv->bgx, priv->index));
+               oct_csr_write(data, BGX_SMU_RX_INT(priv->node, priv->bgx, priv->index));
+               data = oct_csr_read(BGX_SMU_TX_INT(priv->node, priv->bgx, priv->index));
+               oct_csr_write(data, BGX_SMU_TX_INT(priv->node, priv->bgx, priv->index));
+               data = oct_csr_read(BGX_SPU_INT(priv->node, priv->bgx, priv->index));
+               oct_csr_write(data, BGX_SPU_INT(priv->node, priv->bgx, priv->index));
+
+               if ((priv->mode == PORT_MODE_10G_KR ||
+                    priv->mode == PORT_MODE_40G_KR4) &&
+                   !OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X)) {
+                       oct_csr_write(0, BGX_SPU_BR_PMD_LP_CUP(priv->node, priv->bgx, priv->index));
+                       oct_csr_write(0, BGX_SPU_BR_PMD_LD_CUP(priv->node, priv->bgx, priv->index));
+                       oct_csr_write(0, BGX_SPU_BR_PMD_LD_REP(priv->node, priv->bgx, priv->index));
+                       data = oct_csr_read(BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+                       data |= BIT(1);
+                       oct_csr_write(data, BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+               }
+       }
+
+       data = oct_csr_read(BGX_SMU_TX_APPEND(priv->node, priv->bgx, priv->index));
+       data |= BIT(3);
+       oct_csr_write(data, BGX_SMU_TX_APPEND(priv->node, priv->bgx, priv->index));
+
+       if (!octeon_is_simulation()) {
+               /* Disable fec */
+               data = oct_csr_read(BGX_SPU_FEC_CONTROL(priv->node, priv->bgx, priv->index));
+               data &= ~BIT(0);
+               oct_csr_write(data, BGX_SPU_FEC_CONTROL(priv->node, priv->bgx, priv->index));
+
+               /* Disable/configure auto negotiation */
+               data = oct_csr_read(BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+               data &= ~(BIT(13) | BIT(12));
+               oct_csr_write(data, BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+
+               data = oct_csr_read(BGX_SPU_AN_ADV(priv->node, priv->bgx, priv->index));
+               data &= ~(BIT(47) | BIT(26) | BIT(25) | BIT(22) | BIT(21) |
+                         BIT(13) | BIT(12));
+               data |= BIT(46);
+               if (priv->mode == PORT_MODE_40G_KR4)
+                       data |= BIT(24);
+               else
+                       data &= ~BIT(24);
+               if (priv->mode == PORT_MODE_10G_KR)
+                       data |= BIT(23);
+               else
+                       data &= ~BIT(23);
+               oct_csr_write(data, BGX_SPU_AN_ADV(priv->node, priv->bgx, priv->index));
+
+               data = oct_csr_read(BGX_SPU_DBG_CONTROL(priv->node, priv->bgx));
+               data |= BIT(29);
+               if (priv->mode == PORT_MODE_10G_KR ||
+                   priv->mode == PORT_MODE_40G_KR4)
+                       data |= BIT(18);
+               else
+                       data &= ~BIT(18);
+               oct_csr_write(data, BGX_SPU_DBG_CONTROL(priv->node, priv->bgx));
+
+               /* Enable the port */
+               data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+               data |= BIT(15);
+               oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+               if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) && priv->index) {
+                       /* BGX-22429 */
+                       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, 0));
+                       data |= BIT(15);
+                       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, 0));
+               }
+       }
+
+       data = oct_csr_read(BGX_SPU_CONTROL1(priv->node, priv->bgx, priv->index));
+       data &= ~BIT(11);
+       oct_csr_write(data, BGX_SPU_CONTROL1(priv->node, priv->bgx, priv->index));
+
+       data = oct_csr_read(BGX_SMU_TX_CTL(priv->node, priv->bgx, priv->index));
+       data |= BIT(0);
+       data &= ~BIT(1);
+       oct_csr_write(data, BGX_SMU_TX_CTL(priv->node, priv->bgx, priv->index));
+
+       clock_mhz = octeon_get_io_clock_rate() / 1000000;
+       data = oct_csr_read(BGX_SPU_DBG_CONTROL(priv->node, priv->bgx));
+       data &= ~GENMASK_ULL(43, 32);
+       data |= (clock_mhz - 1) << 32;
+       oct_csr_write(data, BGX_SPU_DBG_CONTROL(priv->node, priv->bgx));
+
+       /* Fifo in 16-byte words */
+       tx_fifo_size = bgx_get_tx_fifo_size(priv);
+       tx_fifo_size >>= 4;
+       oct_csr_write(tx_fifo_size - 10, BGX_SMU_TX_THRESH(priv->node, priv->bgx, priv->index));
+
+       if (priv->mode == PORT_MODE_RXAUI && priv->phy_np) {
+               data = oct_csr_read(BGX_SPU_MISC_CONTROL(priv->node, priv->bgx, priv->index));
+               data |= BIT(10);
+               oct_csr_write(data, BGX_SPU_MISC_CONTROL(priv->node, priv->bgx, priv->index));
+       }
+
+       /* Some PHYs take up to 250ms to stabilize */
+       if (!octeon_is_simulation())
+               usleep_range(250000, 300000);
+
+       return 0;
+}
+
+/* Configure/initialize a bgx port. */
+static int bgx_port_init(struct bgx_port_priv *priv)
+{
+       u64     data;
+       int     rc = 0;
+
+       /* GSER-20956 */
+       if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) &&
+           (priv->mode == PORT_MODE_10G_KR ||
+            priv->mode == PORT_MODE_XFI ||
+            priv->mode == PORT_MODE_40G_KR4 ||
+            priv->mode == PORT_MODE_XLAUI)) {
+               /* Disable link training */
+               data = oct_csr_read(BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+               data &= ~(1 << 1);
+               oct_csr_write(data, BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+       }
+
+       bgx_common_init_pknd(priv);
+
+       if (priv->mode == PORT_MODE_SGMII ||
+           priv->mode == PORT_MODE_RGMII)
+               rc = bgx_xgmii_hardware_init(priv);
+       else
+               rc = bgx_xaui_hardware_init(priv);
+
+       return rc;
+}
+
+static int bgx_port_get_qlm_speed(struct bgx_port_priv *priv,
+                                 int                   qlm)
+{
+       enum lane_mode  lmode;
+       u64             data;
+
+       data = oct_csr_read(GSER_LANE_MODE(priv->node, qlm));
+       lmode = data & 0xf;
+
+       switch (lmode) {
+       case R_25G_REFCLK100:
+               return 2500;
+       case R_5G_REFCLK100:
+               return 5000;
+       case R_8G_REFCLK100:
+               return 8000;
+       case R_125G_REFCLK15625_KX:
+               return 1250;
+       case R_3125G_REFCLK15625_XAUI:
+               return 3125;
+       case R_103125G_REFCLK15625_KR:
+               return 10312;
+       case R_125G_REFCLK15625_SGMII:
+               return 1250;
+       case R_5G_REFCLK15625_QSGMII:
+               return 5000;
+       case R_625G_REFCLK15625_RXAUI:
+               return 6250;
+       case R_25G_REFCLK125:
+               return 2500;
+       case R_5G_REFCLK125:
+               return 5000;
+       case R_8G_REFCLK125:
+               return 8000;
+       default:
+               return 0;
+       }
+}
+
+static struct port_status bgx_port_get_sgmii_link(struct bgx_port_priv *priv)
+{
+       struct port_status      status;
+       int                     speed;
+
+       /* The simulator always uses a 1Gbps full duplex port */
+       if (octeon_is_simulation()) {
+               status.link = 1;
+               status.duplex = DUPLEX_FULL;
+               status.speed = 1000;
+       } else {
+               /* Use the qlm speed */
+               speed = bgx_port_get_qlm_speed(priv, priv->qlm);
+               status.link = 1;
+               status.duplex = DUPLEX_FULL;
+               status.speed = speed * 8 / 10;
+       }
+
+       return status;
+}
+
+static int bgx_port_xgmii_set_link_up(struct bgx_port_priv *priv)
+{
+       u64     data;
+       int     timeout;
+
+       if (!octeon_is_simulation()) {
+               /* PCS reset sequence */
+               data = oct_csr_read(BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+               data |= BIT(15);
+               oct_csr_write(data, BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+
+               /* Wait for reset to complete */
+               udelay(1);
+               data = oct_csr_read(BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+               if (data & BIT(15)) {
+                       netdev_err(priv->netdev,
+                                  "BGX%d:%d: PCS stuck in reset\n", priv->bgx, priv->node);
+                       return -1;
+               }
+       }
+
+       /* Autonegotiation */
+       if (priv->phy_np) {
+               data = oct_csr_read(BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+               data |= BIT(9);
+               if (priv->mode != PORT_MODE_RGMII)
+                       data |= BIT(12);
+               else
+                       data &= ~BIT(12);
+               data &= ~BIT(11);
+               oct_csr_write(data, BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+       } else {
+               data = oct_csr_read(BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+               data |= BIT(6);
+               data &= ~(BIT(13) | BIT(12) | BIT(11));
+               oct_csr_write(data, BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+       }
+
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       data &= ~(BIT(9) | BIT(8));
+       if (priv->mode_1000basex)
+               data |= BIT(8);
+       if (priv->bgx_as_phy)
+               data |= BIT(9);
+       oct_csr_write(data, BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+
+       /* Wait for autonegotiation to complete */
+       if (!octeon_is_simulation() && !priv->bgx_as_phy &&
+           priv->mode != PORT_MODE_RGMII) {
+               timeout = 10000;
+               do {
+                       data = oct_csr_read(BGX_GMP_PCS_MR_STATUS(priv->node, priv->bgx, priv->index));
+                       if (data & BIT(5))
+                               break;
+                       timeout--;
+                       udelay(1);
+               } while (timeout);
+               if (!timeout) {
+                       netdev_err(priv->netdev, "BGX%d:%d: AN timeout\n", priv->bgx, priv->node);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+static void bgx_port_rgmii_set_link_down(struct bgx_port_priv *priv)
+{
+       u64     data;
+       int     rx_fifo_len;
+
+       data = oct_csr_read(XCV_RESET(priv->node));
+       data &= ~BIT(1);
+       oct_csr_write(data, XCV_RESET(priv->node));
+       /* Is this read really needed? TODO */
+       data = oct_csr_read(XCV_RESET(priv->node));
+
+       /* Wait for 2 MTUs */
+       mdelay(10);
+
+       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       data &= ~BIT(14);
+       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+       /* Wait for the rx and tx fifos to drain */
+       do {
+               data = oct_csr_read(BGX_CMR_RX_FIFO_LEN(priv->node, priv->bgx, priv->index));
+               rx_fifo_len = data & 0x1fff;
+               data = oct_csr_read(BGX_CMR_TX_FIFO_LEN(priv->node, priv->bgx, priv->index));
+       } while (rx_fifo_len > 0 || !(data & BIT(13)));
+
+       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       data &= ~BIT(13);
+       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+       data = oct_csr_read(XCV_RESET(priv->node));
+       data &= ~BIT(3);
+       oct_csr_write(data, XCV_RESET(priv->node));
+
+       data = oct_csr_read(BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+       data |= BIT(11);
+       oct_csr_write(data, BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+}
+
+static void bgx_port_sgmii_set_link_down(struct bgx_port_priv *priv)
+{
+       u64     data;
+
+       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       data &= ~(BIT(14) | BIT(13));

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 654

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+       data = oct_csr_read(BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+       data &= ~BIT(12);
+       oct_csr_write(data, BGX_GMP_PCS_MR_CONTROL(priv->node, priv->bgx, priv->index));
+
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       data |= BIT(11);
+       oct_csr_write(data, BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));

Any particular reason to read this immediately after write ?

Quoted 30 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +30 -0
+}
+
+static int bgx_port_sgmii_set_link_speed(struct bgx_port_priv *priv, struct port_status status)
+{
+       u64     data;
+       u64     prtx;
+       u64     miscx;
+       int     timeout;
+
+       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       data &= ~(BIT(14) | BIT(13));
+       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+       timeout = 10000;
+       do {
+               prtx = oct_csr_read(BGX_GMP_GMI_PRT_CFG(priv->node, priv->bgx, priv->index));
+               if (prtx & BIT(13) && prtx & BIT(12))
+                       break;
+               timeout--;
+               udelay(1);
+       } while (timeout);
+       if (!timeout) {
+               netdev_err(priv->netdev, "BGX%d:%d: GMP idle timeout\n", priv->bgx, priv->node);
+               return -1;
+       }
+
+       prtx = oct_csr_read(BGX_GMP_GMI_PRT_CFG(priv->node, priv->bgx, priv->index));
+       miscx = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       if (status.link) {
+               miscx &= ~BIT(11);

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 694

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+               if (status.duplex == DUPLEX_FULL)
+                       prtx |= BIT(2);
+               else
+                       prtx &= ~BIT(2);
+       } else {
+               miscx |= BIT(11);
+       }
+
+       switch (status.speed) {
+       case 10:

Instead of hard coding the value, is it fine to use ENUM ? Similar applicable in other places.

Quoted 412 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +410 -0
+               prtx &= ~(BIT(3) | BIT(1));
+               prtx |= BIT(8);
+               miscx &= ~GENMASK_ULL(6, 0);
+               miscx |= 25;
+               oct_csr_write(64, BGX_GMP_GMI_TX_SLOT(priv->node, priv->bgx, priv->index));
+               oct_csr_write(0, BGX_GMP_GMI_TX_BURST(priv->node, priv->bgx, priv->index));
+               break;
+       case 100:
+               prtx &= ~(BIT(8) | BIT(3) | BIT(1));
+               miscx &= ~GENMASK_ULL(6, 0);
+               miscx |= 5;
+               oct_csr_write(64, BGX_GMP_GMI_TX_SLOT(priv->node, priv->bgx, priv->index));
+               oct_csr_write(0, BGX_GMP_GMI_TX_BURST(priv->node, priv->bgx, priv->index));
+               break;
+       case 1000:
+               prtx |= (BIT(3) | BIT(1));
+               prtx &= ~BIT(8);
+               miscx &= ~GENMASK_ULL(6, 0);
+               miscx |= 1;
+               oct_csr_write(512, BGX_GMP_GMI_TX_SLOT(priv->node, priv->bgx, priv->index));
+               if (status.duplex == DUPLEX_FULL)
+                       oct_csr_write(0, BGX_GMP_GMI_TX_BURST(priv->node, priv->bgx, priv->index));
+               else
+                       oct_csr_write(8192, BGX_GMP_GMI_TX_BURST(priv->node, priv->bgx, priv->index));
+               break;
+       default:
+               break;
+       }
+
+       oct_csr_write(miscx, BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       oct_csr_write(prtx, BGX_GMP_GMI_PRT_CFG(priv->node, priv->bgx, priv->index));
+       /* This read verifies the write completed */
+       prtx = oct_csr_read(BGX_GMP_GMI_PRT_CFG(priv->node, priv->bgx, priv->index));
+
+       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       data |= (BIT(14) | BIT(13));
+       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+       return 0;
+}
+
+static int bgx_port_rgmii_set_link_speed(struct bgx_port_priv *priv, struct port_status status)
+{
+       u64     data;
+       int     speed;
+       bool    speed_changed = false;
+       bool    int_lpbk = false;
+       bool    do_credits;
+
+       switch (status.speed) {
+       case 10:
+               speed = 0;
+               break;
+       case 100:
+               speed = 1;
+               break;
+       case 1000:
+       default:
+               speed = 2;
+               break;
+       }
+
+       /* Do credits if link came up */
+       data = oct_csr_read(XCV_RESET(priv->node));
+       do_credits = status.link && !(data & BIT(63));
+
+       /* Was there a speed change */
+       data = oct_csr_read(XCV_CTL(priv->node));
+       if ((data & GENMASK_ULL(1, 0)) != speed)
+               speed_changed = true;
+
+       /* Clear clkrst when in internal loopback */
+       if (data & BIT(2)) {
+               int_lpbk = true;
+               data = oct_csr_read(XCV_RESET(priv->node));
+               data &= ~BIT(15);
+               oct_csr_write(data, XCV_RESET(priv->node));
+       }
+
+       /* Link came up or there was a speed change */
+       data = oct_csr_read(XCV_RESET(priv->node));
+       if (status.link && (!(data & BIT(63)) || speed_changed)) {
+               data |= BIT(63);
+               oct_csr_write(data, XCV_RESET(priv->node));
+
+               data = oct_csr_read(XCV_CTL(priv->node));
+               data &= ~GENMASK_ULL(1, 0);
+               data |= speed;
+               oct_csr_write(data, XCV_CTL(priv->node));
+
+               data = oct_csr_read(XCV_DLL_CTL(priv->node));
+               data |= BIT(23);
+               data &= ~GENMASK_ULL(22, 16);
+               data &= ~BIT(15);
+               oct_csr_write(data, XCV_DLL_CTL(priv->node));
+
+               data = oct_csr_read(XCV_DLL_CTL(priv->node));
+               data &= ~GENMASK_ULL(1, 0);
+               oct_csr_write(data, XCV_DLL_CTL(priv->node));
+
+               data = oct_csr_read(XCV_RESET(priv->node));
+               data &= ~BIT(11);
+               oct_csr_write(data, XCV_RESET(priv->node));
+
+               usleep_range(10, 100);
+
+               data = oct_csr_read(XCV_COMP_CTL(priv->node));
+               data &= ~BIT(63);
+               oct_csr_write(data, XCV_COMP_CTL(priv->node));
+
+               data = oct_csr_read(XCV_RESET(priv->node));
+               data |= BIT(7);
+               oct_csr_write(data, XCV_RESET(priv->node));
+
+               data = oct_csr_read(XCV_RESET(priv->node));
+               if (int_lpbk)
+                       data &= ~BIT(15);
+               else
+                       data |= BIT(15);
+               oct_csr_write(data, XCV_RESET(priv->node));
+
+               data = oct_csr_read(XCV_RESET(priv->node));
+               data |= BIT(2) | BIT(0);
+               oct_csr_write(data, XCV_RESET(priv->node));
+       }
+
+       data = oct_csr_read(XCV_RESET(priv->node));
+       if (status.link)
+               data |= BIT(3) | BIT(1);
+       else
+               data &= ~(BIT(3) | BIT(1));
+       oct_csr_write(data, XCV_RESET(priv->node));
+
+       if (!status.link) {
+               mdelay(10);
+               oct_csr_write(0, XCV_RESET(priv->node));
+       }
+
+       /* Grant pko tx credits */
+       if (do_credits) {
+               data = oct_csr_read(XCV_BATCH_CRD_RET(priv->node));
+               data |= BIT(0);
+               oct_csr_write(data, XCV_BATCH_CRD_RET(priv->node));
+       }
+
+       return 0;
+}
+
+static int bgx_port_set_xgmii_link(struct bgx_port_priv *priv,
+                                  struct port_status status)
+{
+       u64     data;
+       int     rc = 0;
+
+       if (status.link) {
+               /* Link up */
+               data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+               data |= BIT(15);
+               oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+               /* BGX-22429 */
+               if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) && priv->index) {
+                       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, 0));
+                       data |= BIT(15);
+                       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, 0));
+               }
+
+               rc = bgx_port_xgmii_set_link_up(priv);
+               if (rc)
+                       return rc;
+               rc = bgx_port_sgmii_set_link_speed(priv, status);
+               if (rc)
+                       return rc;
+               if (priv->mode == PORT_MODE_RGMII)
+                       rc = bgx_port_rgmii_set_link_speed(priv, status);
+       } else {
+               /* Link down */
+               if (priv->mode == PORT_MODE_RGMII) {
+                       bgx_port_rgmii_set_link_down(priv);
+                       rc = bgx_port_sgmii_set_link_speed(priv, status);
+                       if (rc)
+                               return rc;
+                       rc = bgx_port_rgmii_set_link_speed(priv, status);
+               } else {
+                       bgx_port_sgmii_set_link_down(priv);
+               }
+       }
+
+       return rc;
+}
+
+static struct port_status bgx_port_get_xaui_link(struct bgx_port_priv *priv)
+{
+       struct port_status      status;
+       int                     speed;
+       int                     lanes;
+       u64                     data;
+
+       status.link = 0;
+       status.duplex = DUPLEX_HALF;
+       status.speed = 0;
+
+       /* Get the link state */
+       data = oct_csr_read(BGX_SMU_TX_CTL(priv->node, priv->bgx, priv->index));
+       data &= GENMASK_ULL(5, 4);
+       if (!data) {
+               data = oct_csr_read(BGX_SMU_RX_CTL(priv->node, priv->bgx, priv->index));
+               data &= GENMASK_ULL(1, 0);
+               if (!data) {
+                       data = oct_csr_read(BGX_SPU_STATUS1(priv->node, priv->bgx, priv->index));
+                       if (data & BIT(2))
+                               status.link = 1;
+               }
+       }
+
+       if (status.link) {
+               /* Always full duplex */
+               status.duplex = DUPLEX_FULL;
+
+               /* Speed */
+               speed = bgx_port_get_qlm_speed(priv, priv->qlm);
+               data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+               switch ((data >> 8) & 7) {
+               default:
+               case 1:
+                       speed = (speed * 8 + 5) / 10;
+                       lanes = 4;
+                       break;
+               case 2:
+                       speed = (speed * 8 + 5) / 10;
+                       lanes = 2;
+                       break;
+               case 3:
+                       speed = (speed * 64 + 33) / 66;
+                       lanes = 1;
+                       break;
+               case 4:
+                       if (speed == 6250)
+                               speed = 6445;
+                       speed = (speed * 64 + 33) / 66;
+                       lanes = 4;
+                       break;
+               }
+
+               speed *= lanes;
+               status.speed = speed;
+       }
+
+       return status;
+}
+
+static int bgx_port_init_xaui_an(struct bgx_port_priv *priv)
+{
+       u64     data;
+
+       if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X)) {
+               data = oct_csr_read(BGX_SPU_INT(priv->node, priv->bgx, priv->index));
+               /* If autonegotiation is no good */
+               if (!(data & BIT(11))) {
+                       data = BIT(12) | BIT(11) | BIT(10);
+                       oct_csr_write(data, BGX_SPU_INT(priv->node, priv->bgx, priv->index));
+
+                       data = oct_csr_read(BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+                       data |= BIT(9);
+                       oct_csr_write(data, BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+                       return -1;
+               }
+       } else {
+               data = oct_csr_read(BGX_SPU_AN_STATUS(priv->node, priv->bgx, priv->index));
+               /* If autonegotiation hasn't completed */
+               if (!(data & BIT(5))) {
+                       data = oct_csr_read(BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+                       data |= BIT(9);
+                       oct_csr_write(data, BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+static void bgx_port_xaui_start_training(struct bgx_port_priv *priv)
+{
+       u64     data;
+
+       data = BIT(14) | BIT(13);
+       oct_csr_write(data, BGX_SPU_INT(priv->node, priv->bgx, priv->index));
+
+       /* BGX-20968 */
+       oct_csr_write(0, BGX_SPU_BR_PMD_LP_CUP(priv->node, priv->bgx, priv->index));
+       oct_csr_write(0, BGX_SPU_BR_PMD_LD_CUP(priv->node, priv->bgx, priv->index));
+       oct_csr_write(0, BGX_SPU_BR_PMD_LD_REP(priv->node, priv->bgx, priv->index));
+       data = oct_csr_read(BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+       data &= ~BIT(12);
+       oct_csr_write(data, BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+       udelay(1);
+
+       data = oct_csr_read(BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+       data |= BIT(1);
+       oct_csr_write(data, BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+       udelay(1);
+
+       data = oct_csr_read(BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+       data |= BIT(0);
+       oct_csr_write(data, BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+}
+
+static int bgx_port_gser_27882(struct bgx_port_priv *priv)
+{
+       u64     data;
+       u64     addr;
 
+       int     timeout = 200;
+
+   //    timeout = 200;
 
+       do {
+               data = oct_csr_read(GSER_RX_EIE_DETSTS(priv->node, priv->qlm));
+               if (data & (1 << (priv->index + 8)))
+                       break;
+               timeout--;
+               udelay(1);
+       } while (timeout);
+       if (!timeout)
+               return -1;
+
+       addr = GSER_LANE_PCS_CTLIFC_0(priv->node, priv->qlm, priv->index);
+       data = oct_csr_read(addr);
+       data |= BIT(12);
+       oct_csr_write(data, addr);
+
+       addr = GSER_LANE_PCS_CTLIFC_2(priv->node, priv->qlm, priv->index);
+       data = oct_csr_read(addr);
+       data |= BIT(7);
+       oct_csr_write(data, addr);
+
+       data = oct_csr_read(addr);
+       data |= BIT(15);
+       oct_csr_write(data, addr);
+
+       data = oct_csr_read(addr);
+       data &= ~BIT(7);
+       oct_csr_write(data, addr);
+
+       data = oct_csr_read(addr);
+       data |= BIT(15);
+       oct_csr_write(data, addr);
+
+       return 0;
+}
+
+static void bgx_port_xaui_restart_training(struct bgx_port_priv *priv)
+{
+       u64     data;
+
+       data = BIT(14) | BIT(13);
+       oct_csr_write(data, BGX_SPU_INT(priv->node, priv->bgx, priv->index));
+       usleep_range(1700, 2000);
+
+       /* BGX-20968 */
+       oct_csr_write(0, BGX_SPU_BR_PMD_LP_CUP(priv->node, priv->bgx, priv->index));
+       oct_csr_write(0, BGX_SPU_BR_PMD_LD_CUP(priv->node, priv->bgx, priv->index));
+       oct_csr_write(0, BGX_SPU_BR_PMD_LD_REP(priv->node, priv->bgx, priv->index));
+
+       /* Restart training */
+       data = oct_csr_read(BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+       data |= BIT(0);
+       oct_csr_write(data, BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+}
+
+static int bgx_port_get_max_qlm_lanes(int qlm)
+{
+       if (OCTEON_IS_MODEL(OCTEON_CN73XX))
+               return (qlm < 4) ? 4 : 2;
+       else if (OCTEON_IS_MODEL(OCTEON_CNF75XX))
+               return 2;
+       return 4;
+}
+
+static int bgx_port_qlm_rx_equalization(struct bgx_port_priv *priv, int qlm, int lane)
+{
+       u64     data;
+       u64     addr;
+       u64     lmode;
+       int     max_lanes = bgx_port_get_max_qlm_lanes(qlm);
+       int     lane_mask = lane == -1 ? ((1 << max_lanes) - 1) : (1 << lane);
+       int     timeout;
+       int     i;
+       int     rc = 0;
+
+       /* Nothing to do for qlms in reset */
+       data = oct_csr_read(GSER_PHY_CTL(priv->node, qlm));
+       if (data & (BIT(0) | BIT(1)))
+               return -1;
+
+       for (i = 0; i < max_lanes; i++) {
+               if (!(i & lane_mask))
+                       continue;
+
+               addr = GSER_LANE_LBERT_CFG(priv->node, qlm, i);
+               data = oct_csr_read(addr);
+               /* Rx equalization can't be completed while pattern matcher is
+                * enabled because it causes errors.
+                */
+               if (data & BIT(6))
+                       return -1;
+       }
+
+       lmode = oct_csr_read(GSER_LANE_MODE(priv->node, qlm));
+       lmode &= 0xf;
+       addr = GSER_LANE_P_MODE_1(priv->node, qlm, lmode);
+       data = oct_csr_read(addr);

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1114

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+       /* Don't complete rx equalization if in VMA manual mode */
+       if (data & BIT(14))
+               return 0;
+
+       /* Apply rx equalization for speed > 6250 */
+       if (bgx_port_get_qlm_speed(priv, qlm) < 6250)
+               return 0;
+
+       /* Wait until rx data is valid (CDRLOCK) */
+       timeout = 500;

Min value 500 is required or it can be reduced further ?

Quoted 184 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +184 -0
+       addr = GSER_RX_EIE_DETSTS(priv->node, qlm);
+       do {
+               data = oct_csr_read(addr);
+               data >>= 8;
+               data &= lane_mask;
+               if (data == lane_mask)
+                       break;
+               timeout--;
+               udelay(1);
+       } while (timeout);
+       if (!timeout) {
+               pr_debug("QLM%d:%d: CDRLOCK timeout\n", qlm, priv->node);
+               return -1;
+       }
+
+       bgx_port_gser_20075(priv, qlm, lane);
+
+       for (i = 0; i < max_lanes; i++) {
+               if (!(i & lane_mask))
+                       continue;
+               /* Skip lane 3 on 78p1.x due to gser-20075. Handled above */
+               if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) && i == 3)
+                       continue;
+
+               /* Enable software control */
+               addr = GSER_BR_RX_CTL(priv->node, qlm, i);
+               data = oct_csr_read(addr);
+               data |= BIT(2);
+               oct_csr_write(data, addr);
+
+               /* Clear the completion flag */
+               addr = GSER_BR_RX_EER(priv->node, qlm, i);
+               data = oct_csr_read(addr);
+               data &= ~BIT(14);
+               data |= BIT(15);
+               oct_csr_write(data, addr);
+       }
+
+       /* Wait for rx equalization to complete */
+       for (i = 0; i < max_lanes; i++) {
+               if (!(i & lane_mask))
+                       continue;
+
+               timeout = 250000;
+               addr = GSER_BR_RX_EER(priv->node, qlm, i);
+               do {
+                       data = oct_csr_read(addr);
+                       if (data & BIT(14))
+                               break;
+                       timeout--;
+                       udelay(1);
+               } while (timeout);
+               if (!timeout) {
+                       pr_debug("QLM%d:%d: RXT_ESV timeout\n",
+                                qlm, priv->node);
+                       rc = -1;
+               }
+
+               /* Switch back to hardware control */
+               addr = GSER_BR_RX_CTL(priv->node, qlm, i);
+               data = oct_csr_read(addr);
+               data &= ~BIT(2);
+               oct_csr_write(data, addr);
+       }
+
+       return rc;
+}
+
+static int bgx_port_xaui_equalization(struct bgx_port_priv *priv)
+{
+       u64     data;
+       int     lane;
+
+       /* Nothing to do for loopback mode */
+       data = oct_csr_read(BGX_SPU_CONTROL1(priv->node, priv->bgx,
+                                            priv->index));
+       if (data & BIT(14))
+               return 0;
+
+       if (priv->mode == PORT_MODE_XAUI || priv->mode == PORT_MODE_XLAUI) {
+               if (bgx_port_qlm_rx_equalization(priv, priv->qlm, -1))
+                       return -1;
+
+               /* BGX2 of 73xx uses 2 dlms */
+               if (OCTEON_IS_MODEL(OCTEON_CN73XX) && priv->bgx == 2) {
+                       if (bgx_port_qlm_rx_equalization(priv, priv->qlm + 1, -1))
+                               return -1;
+               }
+       } else if (priv->mode == PORT_MODE_RXAUI) {
+               /* Rxaui always uses 2 lanes */
+               if (bgx_port_qlm_rx_equalization(priv, priv->qlm, -1))
+                       return -1;
+       } else if (priv->mode == PORT_MODE_XFI) {
+               lane = priv->index;
+               if ((OCTEON_IS_MODEL(OCTEON_CN73XX) && priv->qlm == 6) ||
+                   (OCTEON_IS_MODEL(OCTEON_CNF75XX) && priv->qlm == 5))
+                       lane -= 2;
+
+               if (bgx_port_qlm_rx_equalization(priv, priv->qlm, lane))
+                       return -1;
+       }
+
+       return 0;
+}
+
+static int bgx_port_init_xaui_link(struct bgx_port_priv *priv)
+{
+       u64     data;
+       int     use_training = 0;
+       int     use_ber = 0;
+       int     timeout;
+       int     rc = 0;
+
+       if (priv->mode == PORT_MODE_10G_KR || priv->mode == PORT_MODE_40G_KR4)
+               use_training = 1;
+
+       if (!octeon_is_simulation() &&
+           (priv->mode == PORT_MODE_XFI || priv->mode == PORT_MODE_XLAUI ||
+            priv->mode == PORT_MODE_10G_KR || priv->mode == PORT_MODE_40G_KR4))
+               use_ber = 1;
+
+       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       data &= ~(BIT(14) | BIT(13));
+       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+       data = oct_csr_read(BGX_SPU_MISC_CONTROL(priv->node, priv->bgx, priv->index));
+       data |= BIT(12);
+       oct_csr_write(data, BGX_SPU_MISC_CONTROL(priv->node, priv->bgx, priv->index));
+
+       if (!octeon_is_simulation()) {
+               data = oct_csr_read(BGX_SPU_AN_CONTROL(priv->node, priv->bgx, priv->index));
+               /* Restart autonegotiation */
+               if (data & BIT(12)) {
+                       rc = bgx_port_init_xaui_an(priv);
+                       if (rc)
+                               return rc;
+               }
+
+               if (use_training) {
+                       data = oct_csr_read(BGX_SPU_BR_PMD_CONTROL(priv->node, priv->bgx, priv->index));
+                       /* Check if training is enabled */
+                       if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) &&
+                           !(data & BIT(1))) {
+                               bgx_port_xaui_start_training(priv);
+                               return -1;
+                       }
+
+                       if (OCTEON_IS_MODEL(OCTEON_CN73XX) ||
+                           OCTEON_IS_MODEL(OCTEON_CNF75XX) ||
+                           OCTEON_IS_MODEL(OCTEON_CN78XX))
+                               bgx_port_gser_27882(priv);
+
+                       data = oct_csr_read(BGX_SPU_INT(priv->node, priv->bgx, priv->index));
+
+                       /* Restart training if it failed */
+                       if ((data & BIT(14)) &&
+                           !OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X)) {
+                               bgx_port_xaui_restart_training(priv);
+                               return -1;
+                       }
+
+                       if (!(data & BIT(13))) {
+                               pr_debug("Waiting for link training\n");
+                               return -1;
+                       }
+               } else {
+                       bgx_port_xaui_equalization(priv);
+               }
+
+               /* Wait until the reset is complete */
+               timeout = 10000;
+               do {
+                       data = oct_csr_read(BGX_SPU_CONTROL1(priv->node, priv->bgx, priv->index));
+                       if (!(data & BIT(15)))
+                               break;
+                       timeout--;
+                       udelay(1);
+               } while (timeout);
+               if (!timeout) {
+                       pr_debug("BGX%d:%d:%d: Reset timeout\n", priv->bgx,
+                                priv->index, priv->node);
+                       return -1;
+               }
+

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1308

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+               if (use_ber) {
+                       timeout = 10000;
+                       do {
+                               data =
+                               oct_csr_read(BGX_SPU_BR_STATUS1(priv->node, priv->bgx, priv->index));
+                               if (data & BIT(0))
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);

In my opinion, it's better to implement similar loops inside macros.

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +5 -0
+                       if (!timeout) {
+                               pr_debug("BGX%d:%d:%d: BLK_LOCK timeout\n",
+                                        priv->bgx, priv->index, priv->node);
+                               return -1;
+                       }

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1323

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+               } else {
+                       timeout = 10000;
+                       do {
+                               data =
+                               oct_csr_read(BGX_SPU_BX_STATUS(priv->node, priv->bgx, priv->index));
+                               if (data & BIT(12))
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);

same here

Quoted 6,080 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +710 -0
+                       if (!timeout) {
+                               pr_debug("BGX%d:%d:%d: Lanes align timeout\n",
+                                        priv->bgx, priv->index, priv->node);
+                               return -1;
+                       }
+               }
+
+               if (use_ber) {
+                       data = oct_csr_read(BGX_SPU_BR_STATUS2(priv->node, priv->bgx, priv->index));
+                       data |= BIT(15);
+                       oct_csr_write(data, BGX_SPU_BR_STATUS2(priv->node, priv->bgx, priv->index));
+               }
+
+               data = oct_csr_read(BGX_SPU_STATUS2(priv->node, priv->bgx, priv->index));
+               data |= BIT(10);
+               oct_csr_write(data, BGX_SPU_STATUS2(priv->node, priv->bgx, priv->index));
+
+               data = oct_csr_read(BGX_SPU_STATUS2(priv->node, priv->bgx, priv->index));
+               if (data & BIT(10)) {
+                       if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) &&
+                           use_training)
+                               bgx_port_xaui_restart_training(priv);
+                       return -1;
+               }
+
+               /* Wait for mac rx to be ready */
+               timeout = 10000;
+               do {
+                       data = oct_csr_read(BGX_SMU_RX_CTL(priv->node, priv->bgx, priv->index));
+                       data &= GENMASK_ULL(1, 0);
+                       if (!data)
+                               break;
+                       timeout--;
+                       udelay(1);
+               } while (timeout);
+               if (!timeout) {
+                       pr_debug("BGX%d:%d:%d: mac ready timeout\n",
+                                priv->bgx, priv->index, priv->node);
+                       return -1;
+               }
+
+               /* Wait for bgx rx to be idle */
+               timeout = 10000;
+               do {
+                       data = oct_csr_read(BGX_SMU_CTRL(priv->node, priv->bgx, priv->index));
+                       if (data & BIT(0))
+                               break;
+                       timeout--;
+                       udelay(1);
+               } while (timeout);
+               if (!timeout) {
+                       pr_debug("BGX%d:%d:%d: rx idle timeout\n",
+                                priv->bgx, priv->index, priv->node);
+                       return -1;
+               }
+
+               /* Wait for gmx tx to be idle */
+               timeout = 10000;
+               do {
+                       data = oct_csr_read(BGX_SMU_CTRL(priv->node, priv->bgx, priv->index));
+                       if (data & BIT(1))
+                               break;
+                       timeout--;
+                       udelay(1);
+               } while (timeout);
+               if (!timeout) {
+                       pr_debug("BGX%d:%d:%d: tx idle timeout\n",
+                                priv->bgx, priv->index, priv->node);
+                       return -1;
+               }
+
+               /* Check rcvflt is still be 0 */
+               data = oct_csr_read(BGX_SPU_STATUS2(priv->node, priv->bgx, priv->index));
+               if (data & BIT(10)) {
+                       pr_debug("BGX%d:%d:%d: receive fault\n",
+                                priv->bgx, priv->index, priv->node);
+                       return -1;
+               }
+
+               /* Receive link is latching low. Force it high and verify it */
+               data = oct_csr_read(BGX_SPU_STATUS1(priv->node, priv->bgx, priv->index));
+               data |= BIT(2);
+               oct_csr_write(data, BGX_SPU_STATUS1(priv->node, priv->bgx, priv->index));
+               timeout = 10000;
+               do {
+                       data = oct_csr_read(BGX_SPU_STATUS1(priv->node, priv->bgx, priv->index));
+                       if (data & BIT(2))
+                               break;
+                       timeout--;
+                       udelay(1);
+               } while (timeout);
+               if (!timeout) {
+                       pr_debug("BGX%d:%d:%d: rx link down\n",
+                                priv->bgx, priv->index, priv->node);
+                       return -1;
+               }
+       }
+
+       if (use_ber) {
+               /* Read error counters to clear */
+               data = oct_csr_read(BGX_SPU_BR_BIP_ERR_CNT(priv->node, priv->bgx, priv->index));
+               data = oct_csr_read(BGX_SPU_BR_STATUS2(priv->node, priv->bgx, priv->index));
+
+               /* Verify latch lock is set */
+               if (!(data & BIT(15))) {
+                       pr_debug("BGX%d:%d:%d: latch lock lost\n",
+                                priv->bgx, priv->index, priv->node);
+                       return -1;
+               }
+
+               /* LATCHED_BER is cleared by writing 1 to it */
+               if (data & BIT(14))
+                       oct_csr_write(data, BGX_SPU_BR_STATUS2(priv->node, priv->bgx, priv->index));
+
+               usleep_range(1500, 2000);
+               data = oct_csr_read(BGX_SPU_BR_STATUS2(priv->node, priv->bgx, priv->index));
+               if (data & BIT(14)) {
+                       pr_debug("BGX%d:%d:%d: BER test failed\n",
+                                priv->bgx, priv->index, priv->node);
+                       return -1;
+               }
+       }
+
+       /* Enable packet transmit and receive */
+       data = oct_csr_read(BGX_SPU_MISC_CONTROL(priv->node, priv->bgx, priv->index));
+       data &= ~BIT(12);
+       oct_csr_write(data, BGX_SPU_MISC_CONTROL(priv->node, priv->bgx, priv->index));
+       data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       data |= BIT(14) | BIT(13);
+       oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+
+       return 0;
+}
+
+static int bgx_port_set_xaui_link(struct bgx_port_priv *priv,
+                                 struct port_status status)
+{
+       u64     data;
+       bool    smu_tx_ok = false;
+       bool    smu_rx_ok = false;
+       bool    spu_link_ok = false;
+       int     rc = 0;
+
+       /* Initialize hardware if link is up but hardware is not happy */
+       if (status.link) {
+               data = oct_csr_read(BGX_SMU_TX_CTL(priv->node, priv->bgx, priv->index));
+               data &= GENMASK_ULL(5, 4);
+               smu_tx_ok = data == 0;
+
+               data = oct_csr_read(BGX_SMU_RX_CTL(priv->node, priv->bgx, priv->index));
+               data &= GENMASK_ULL(1, 0);
+               smu_rx_ok = data == 0;
+
+               data = oct_csr_read(BGX_SPU_STATUS1(priv->node, priv->bgx, priv->index));
+               data &= BIT(2);
+               spu_link_ok = data == BIT(2);
+
+               if (!smu_tx_ok || !smu_rx_ok || !spu_link_ok)
+                       rc = bgx_port_init_xaui_link(priv);
+       }
+
+       return rc;
+}
+
+static struct bgx_port_priv *bgx_port_netdev2priv(struct net_device *netdev)
+{
+       struct bgx_port_netdev_priv *nd_priv = netdev_priv(netdev);
+
+       return nd_priv->bgx_priv;
+}
+
+void bgx_port_set_netdev(struct device *dev, struct net_device *netdev)
+{
+       struct bgx_port_priv *priv = dev_get_drvdata(dev);
+
+       if (netdev) {
+               struct bgx_port_netdev_priv *nd_priv = netdev_priv(netdev);
+
+               nd_priv->bgx_priv = priv;
+       }
+
+       priv->netdev = netdev;
+}
+EXPORT_SYMBOL(bgx_port_set_netdev);
+
+int bgx_port_ethtool_get_link_ksettings(struct net_device *netdev,
+                                       struct ethtool_link_ksettings *cmd)
+{
+       struct bgx_port_priv    *priv = bgx_port_netdev2priv(netdev);
+
+       if (priv->phydev) {
+               phy_ethtool_ksettings_get(priv->phydev, cmd);
+               return 0;
+       }
+       return -EINVAL;
+}
+EXPORT_SYMBOL(bgx_port_ethtool_get_link_ksettings);
+
+int bgx_port_ethtool_set_settings(struct net_device    *netdev,
+                                 struct ethtool_cmd    *cmd)
+{
+       struct bgx_port_priv *p = bgx_port_netdev2priv(netdev);
+
+       if (!capable(CAP_NET_ADMIN))
+               return -EPERM;
+
+       if (p->phydev)
+               return phy_ethtool_sset(p->phydev, cmd);
+
+       return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(bgx_port_ethtool_set_settings);
+
+int bgx_port_ethtool_nway_reset(struct net_device *netdev)
+{
+       struct bgx_port_priv *p = bgx_port_netdev2priv(netdev);
+
+       if (!capable(CAP_NET_ADMIN))
+               return -EPERM;
+
+       if (p->phydev)
+               return phy_start_aneg(p->phydev);
+
+       return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(bgx_port_ethtool_nway_reset);
+
+const u8 *bgx_port_get_mac(struct net_device *netdev)
+{
+       struct bgx_port_priv *priv = bgx_port_netdev2priv(netdev);
+
+       return priv->mac_addr;
+}
+EXPORT_SYMBOL(bgx_port_get_mac);
+
+int bgx_port_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
+{
+       struct bgx_port_priv *p = bgx_port_netdev2priv(netdev);
+
+       if (p->phydev)
+               return phy_mii_ioctl(p->phydev, ifr, cmd);
+       return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(bgx_port_do_ioctl);
+
+static void bgx_port_write_cam(struct bgx_port_priv    *priv,
+                              int                      cam,
+                              const u8                 *mac)
+{
+       u64     m = 0;
+       int     i;
+
+       if (mac) {
+               for (i = 0; i < 6; i++)
+                       m |= (((u64)mac[i]) << ((5 - i) * 8));
+               m |= BIT(48);
+       }
+
+       m |= (u64)priv->index << 52;
+       oct_csr_write(m, BGX_CMR_RX_ADRX_CAM(priv->node, priv->bgx, priv->index * 8 + cam));
+}
+
+/* Set MAC address for the net_device that is attached. */
+void bgx_port_set_rx_filtering(struct net_device *netdev)
+{
+       u64     data;
+       struct bgx_port_priv *priv = bgx_port_netdev2priv(netdev);
+       int available_cam_entries, current_cam_entry;
+       struct netdev_hw_addr *ha;
+
+       available_cam_entries = 8;
+       data = 0;
+       data |= BIT(0); /* Accept all Broadcast*/
+
+       if ((netdev->flags & IFF_PROMISC) || netdev->uc.count > 7) {
+               data &= ~BIT(3); /* Reject CAM match */
+               available_cam_entries = 0;
+       } else {
+               /* One CAM entry for the primary address, leaves seven
+                * for the secondary addresses.
+                */
+               data |= BIT(3); /* Accept CAM match */
+               available_cam_entries = 7 - netdev->uc.count;
+       }
+
+       if (netdev->flags & IFF_PROMISC) {
+               data |= 1 << 1; /* Accept all Multicast */
+       } else {
+               if (netdev->flags & IFF_MULTICAST) {
+                       if ((netdev->flags & IFF_ALLMULTI) ||
+                           netdev_mc_count(netdev) > available_cam_entries)
+                               data |= 1 << 1; /* Accept all Multicast */
+                       else
+                               data |= 2 << 1; /* Accept all Mcast via CAM */
+               }
+       }
+       current_cam_entry = 0;
+       if (data & BIT(3)) {
+               bgx_port_write_cam(priv, current_cam_entry, netdev->dev_addr);
+               current_cam_entry++;
+               netdev_for_each_uc_addr(ha, netdev) {
+                       bgx_port_write_cam(priv, current_cam_entry, ha->addr);
+                       current_cam_entry++;
+               }
+       }
+       if (((data & GENMASK_ULL(2, 1)) >> 1) == 2) {
+               /* Accept all Multicast via CAM */
+               netdev_for_each_mc_addr(ha, netdev) {
+                       bgx_port_write_cam(priv, current_cam_entry, ha->addr);
+                       current_cam_entry++;
+               }
+       }
+       while (current_cam_entry < 8) {
+               bgx_port_write_cam(priv, current_cam_entry, NULL);
+               current_cam_entry++;
+       }
+       oct_csr_write(data, BGX_CMR_RX_ADR_CTL(priv->node, priv->bgx,
+                                              priv->index));
+}
+EXPORT_SYMBOL(bgx_port_set_rx_filtering);
+
+static void bgx_port_adjust_link(struct net_device *netdev)
+{
+       struct bgx_port_priv    *priv = bgx_port_netdev2priv(netdev);
+       bool                    link_changed = false;
+       unsigned int            link;
+       unsigned int            speed;
+       unsigned int            duplex;
+
+       mutex_lock(&priv->lock);
+
+       if (!priv->phydev->link && priv->last_status.link)
+               link_changed = true;
+
+       if (priv->phydev->link &&
+           (priv->last_status.link != priv->phydev->link ||
+            priv->last_status.duplex != priv->phydev->duplex ||
+            priv->last_status.speed != priv->phydev->speed))
+               link_changed = true;
+
+       link = priv->phydev->link;
+       priv->last_status.link = priv->phydev->link;
+
+       speed = priv->phydev->speed;
+       priv->last_status.speed = priv->phydev->speed;
+
+       duplex = priv->phydev->duplex;
+       priv->last_status.duplex = priv->phydev->duplex;
+
+       mutex_unlock(&priv->lock);
+
+       if (link_changed) {
+               struct port_status status;
+
+               phy_print_status(priv->phydev);
+
+               status.link = link ? 1 : 0;
+               status.duplex = duplex;
+               status.speed = speed;
+               if (!link) {
+                       netif_carrier_off(netdev);
+                        /* Let TX drain. FIXME check that it is drained. */
+                       mdelay(50);
+               }
+               priv->set_link(priv, status);
+               if (link)
+                       netif_carrier_on(netdev);
+       }
+}
+
+static void bgx_port_check_state(struct work_struct *work)
+{
+       struct bgx_port_priv    *priv;
+       struct port_status      status;
+
+       priv = container_of(work, struct bgx_port_priv, dwork.work);
+
+       status = priv->get_link(priv);
+
+       if (!status.link &&
+           priv->mode != PORT_MODE_SGMII && priv->mode != PORT_MODE_RGMII)
+               bgx_port_init_xaui_link(priv);
+
+       if (priv->last_status.link != status.link) {
+               priv->last_status.link = status.link;
+               if (status.link)
+                       netdev_info(priv->netdev, "Link is up - %d/%s\n",
+                                   status.speed,
+                                   status.duplex == DUPLEX_FULL ? "Full" : "Half");
+               else
+                       netdev_info(priv->netdev, "Link is down\n");
+       }
+
+       mutex_lock(&priv->lock);
+       if (priv->work_queued)
+               queue_delayed_work(check_state_wq, &priv->dwork, HZ);
+       mutex_unlock(&priv->lock);
+}
+
+int bgx_port_enable(struct net_device *netdev)
+{
+       struct bgx_port_priv    *priv = bgx_port_netdev2priv(netdev);
+       u64                     data;
+       struct port_status      status;
+       bool                    dont_use_phy;
+
+       if (priv->mode == PORT_MODE_SGMII || priv->mode == PORT_MODE_RGMII) {
+               /* 1G */
+               data = oct_csr_read(BGX_GMP_GMI_TX_APPEND(priv->node, priv->bgx, priv->index));
+               data |= BIT(2) | BIT(1);
+               oct_csr_write(data, BGX_GMP_GMI_TX_APPEND(priv->node, priv->bgx, priv->index));
+
+               /* Packets are padded (without FCS) to MIN_SIZE + 1 in SGMII */
+               data = 60 - 1;
+               oct_csr_write(data, BGX_GMP_GMI_TX_MIN_PKT(priv->node, priv->bgx, priv->index));
+       } else {
+               /* 10G or higher */
+               data = oct_csr_read(BGX_SMU_TX_APPEND(priv->node, priv->bgx, priv->index));
+               data |= BIT(2) | BIT(1);
+               oct_csr_write(data, BGX_SMU_TX_APPEND(priv->node, priv->bgx, priv->index));
+
+               /* Packets are padded(with FCS) to MIN_SIZE  in non-SGMII */
+               data = 60 + 4;
+               oct_csr_write(data, BGX_SMU_TX_MIN_PKT(priv->node, priv->bgx, priv->index));
+       }
+
+       switch (priv->mode) {
+       case PORT_MODE_XLAUI:
+       case PORT_MODE_XFI:
+       case PORT_MODE_10G_KR:
+       case PORT_MODE_40G_KR4:
+               dont_use_phy = true;
+               break;
+       default:
+               dont_use_phy = false;
+               break;
+       }
+
+       if (!priv->phy_np || dont_use_phy) {
+               status = priv->get_link(priv);
+               priv->set_link(priv, status);
+               netif_carrier_on(netdev);
+
+               mutex_lock(&check_state_wq_mutex);
+               if (!check_state_wq) {
+                       check_state_wq =
+                               alloc_workqueue("check_state_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
+               }
+               mutex_unlock(&check_state_wq_mutex);
+               if (!check_state_wq)
+                       return -ENOMEM;
+
+               mutex_lock(&priv->lock);
+               INIT_DELAYED_WORK(&priv->dwork, bgx_port_check_state);
+               queue_delayed_work(check_state_wq, &priv->dwork, 0);
+               priv->work_queued = true;
+               mutex_unlock(&priv->lock);
+
+               netdev_info(priv->netdev, "Link is not ready\n");
+
+       } else {
+               priv->phydev = of_phy_connect(netdev, priv->phy_np,
+                                             bgx_port_adjust_link, 0, priv->phy_mode);
+               if (!priv->phydev)
+                       return -ENODEV;
+
+               netif_carrier_off(netdev);
+
+               if (priv->phydev)
+                       phy_start_aneg(priv->phydev);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(bgx_port_enable);
+
+int bgx_port_disable(struct net_device *netdev)
+{
+       struct bgx_port_priv    *priv = bgx_port_netdev2priv(netdev);
+       struct port_status      status;
+
+       if (priv->phydev) {
+               phy_stop(priv->phydev);
+               phy_disconnect(priv->phydev);
+       }
+       priv->phydev = NULL;
+
+       netif_carrier_off(netdev);
+       memset(&status, 0, sizeof(status));
+       priv->last_status.link = 0;
+       priv->set_link(priv, status);
+
+       mutex_lock(&priv->lock);
+       if (priv->work_queued) {
+               cancel_delayed_work_sync(&priv->dwork);
+               priv->work_queued = false;
+       }
+       mutex_unlock(&priv->lock);
+
+       return 0;
+}
+EXPORT_SYMBOL(bgx_port_disable);
+
+int bgx_port_change_mtu(struct net_device *netdev, int new_mtu)
+{
+       struct bgx_port_priv *priv = bgx_port_netdev2priv(netdev);
+       int max_frame;
+
+       if (new_mtu < 60 || new_mtu > 65392) {
+               netdev_warn(netdev, "Maximum MTU supported is 65392\n");
+               return -EINVAL;
+       }
+
+       netdev->mtu = new_mtu;
+
+       max_frame = round_up(new_mtu + ETH_HLEN + ETH_FCS_LEN, 8);
+
+       if (priv->mode == PORT_MODE_SGMII || priv->mode == PORT_MODE_RGMII) {
+               /* 1G */
+               oct_csr_write(max_frame, BGX_GMP_GMI_RX_JABBER(priv->node, priv->bgx, priv->index));
+       } else {
+               /* 10G or higher */
+               oct_csr_write(max_frame, BGX_SMU_RX_JABBER(priv->node, priv->bgx, priv->index));
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(bgx_port_change_mtu);
+
+void bgx_port_mix_assert_reset(struct net_device *netdev, int mix, bool v)
+{
+       struct bgx_port_priv *priv = bgx_port_netdev2priv(netdev);
+       u64 mask = 1ull << (3 + (mix & 1));
+       u64 data;
+
+       if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) && v) {
+               /* Need to disable the mix before resetting the bgx-mix
+                * interface as not doing so confuses the other already up
+                * lmacs.
+                */
+               data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+               data &= ~BIT(11);
+               oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       }
+
+       data = oct_csr_read(BGX_CMR_GLOBAL_CONFIG(priv->node, priv->bgx));
+       if (v)
+               data |= mask;
+       else
+               data &= ~mask;
+       oct_csr_write(data, BGX_CMR_GLOBAL_CONFIG(priv->node, priv->bgx));
+
+       if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X) && !v) {
+               data = oct_csr_read(BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+               data |= BIT(11);
+               oct_csr_write(data, BGX_CMR_CONFIG(priv->node, priv->bgx, priv->index));
+       }
+}
+EXPORT_SYMBOL(bgx_port_mix_assert_reset);
+
+static int bgx_port_probe(struct platform_device *pdev)
+{
+       u64 addr;
+       const u8 *mac;
+       const __be32 *reg;
+       u32 index;
+       int rc;
+       struct bgx_port_priv *priv;
+       int numa_node;
+
+       reg = of_get_property(pdev->dev.parent->of_node, "reg", NULL);
+       addr = of_translate_address(pdev->dev.parent->of_node, reg);
+       mac = of_get_mac_address(pdev->dev.of_node);
+
+       numa_node = (addr >> 36) & 0x7;
+
+       rc = of_property_read_u32(pdev->dev.of_node, "reg", &index);
+       if (rc)
+               return -ENODEV;
+       priv = kzalloc_node(sizeof(*priv), GFP_KERNEL, numa_node);
+       if (!priv)
+               return -ENOMEM;
+       priv->phy_np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);
+       priv->phy_mode = of_get_phy_mode(pdev->dev.of_node);
+       /* If phy-mode absent, default to SGMII. */
+       if (priv->phy_mode < 0)
+               priv->phy_mode = PHY_INTERFACE_MODE_SGMII;
+
+       if (priv->phy_mode == PHY_INTERFACE_MODE_1000BASEX)
+               priv->mode_1000basex = true;
+
+       if (of_phy_is_fixed_link(pdev->dev.of_node))
+               priv->bgx_as_phy = true;
+
+       mutex_init(&priv->lock);
+       priv->node = numa_node;
+       priv->bgx = (addr >> 24) & 0xf;
+       priv->index = index;
+       if (mac)
+               priv->mac_addr = mac;
+
+       priv->qlm = bgx_port_get_qlm(priv->node, priv->bgx, priv->index);
+       priv->mode = bgx_port_get_mode(priv->node, priv->bgx, priv->index);
+
+       switch (priv->mode) {
+       case PORT_MODE_SGMII:
+               if (priv->phy_np &&
+                   priv->phy_mode != PHY_INTERFACE_MODE_SGMII)
+                       dev_warn(&pdev->dev, "SGMII phy mode mismatch.\n");
+               goto set_link_functions;
+       case PORT_MODE_RGMII:
+               if (priv->phy_np &&
+                   priv->phy_mode != PHY_INTERFACE_MODE_RGMII &&
+                   priv->phy_mode != PHY_INTERFACE_MODE_RGMII_ID &&
+                   priv->phy_mode != PHY_INTERFACE_MODE_RGMII_RXID &&
+                   priv->phy_mode != PHY_INTERFACE_MODE_RGMII_TXID)
+                       dev_warn(&pdev->dev, "RGMII phy mode mismatch.\n");
+set_link_functions:
+               priv->get_link = bgx_port_get_sgmii_link;
+               priv->set_link = bgx_port_set_xgmii_link;
+               break;
+       case PORT_MODE_XAUI:
+       case PORT_MODE_RXAUI:
+       case PORT_MODE_XLAUI:
+       case PORT_MODE_XFI:
+       case PORT_MODE_10G_KR:
+       case PORT_MODE_40G_KR4:
+               priv->get_link = bgx_port_get_xaui_link;
+               priv->set_link = bgx_port_set_xaui_link;
+               break;
+       default:
+               goto err;
+       }
+
+       dev_set_drvdata(&pdev->dev, priv);
+
+       bgx_port_init(priv);
+
+       dev_info(&pdev->dev, "Probed\n");
+       return 0;
+ err:
+       kfree(priv);
+       return rc;
+}
+
+static int bgx_port_remove(struct platform_device *pdev)
+{
+       struct bgx_port_priv *priv = dev_get_drvdata(&pdev->dev);
+
+       kfree(priv);
+       return 0;
+}
+
+static void bgx_port_shutdown(struct platform_device *pdev)
+{
+}
+
+static const struct of_device_id bgx_port_match[] = {
+       {
+               .compatible = "cavium,octeon-7890-bgx-port",
+       },
+       {
+               .compatible = "cavium,octeon-7360-xcv",
+       },
+       {},
+};
+MODULE_DEVICE_TABLE(of, bgx_port_match);
+
+static struct platform_driver bgx_port_driver = {
+       .probe          = bgx_port_probe,
+       .remove         = bgx_port_remove,
+       .shutdown       = bgx_port_shutdown,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = KBUILD_MODNAME,
+               .of_match_table = bgx_port_match,
+       },
+};
+
+static int __init bgx_port_driver_init(void)
+{
+       int r;
+       int i;
+       int j;
+       int k;
+
+       for (i = 0; i < MAX_NODES; i++) {
+               for (j = 0; j < MAX_BGX_PER_NODE; j++) {
+                       for (k = 0; k < MAX_LMAC_PER_BGX; k++)
+                               lmac_pknd[i][j][k] = -1;
+               }
+       }
+
+       bgx_nexus_load();
+       r =  platform_driver_register(&bgx_port_driver);
+       return r;
+}
+module_init(bgx_port_driver_init);
+
+static void __exit bgx_port_driver_exit(void)
+{
+       platform_driver_unregister(&bgx_port_driver);
+       if (check_state_wq)
+               destroy_workqueue(check_state_wq);
+}
+module_exit(bgx_port_driver_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Cavium, Inc. <[email protected]>");
+MODULE_DESCRIPTION("Cavium, Inc. BGX Ethernet MAC driver.");
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +2068 -0
new file mode 100644
index 000000000000..8264c1b2278a
@@ -0,0 +1,2068 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2017 Cavium, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/module.h>
+#include <linux/wait.h>
+#include <linux/rculist.h>
+#include <linux/atomic.h>
+#include <linux/kthread.h>
+#include <linux/interrupt.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/platform_device.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/if_vlan.h>
+#include <linux/rio_drv.h>
+#include <linux/rio_ids.h>
+#include <linux/net_tstamp.h>
+#include <linux/timecounter.h>
+#include <linux/ptp_clock_kernel.h>
+
+#include <asm/octeon/octeon.h>
+
+#include "octeon3.h"
+
+/*  First buffer:
+ *
+ *                            +---SKB---------+
+ *                            |               |
+ *                            |               |
+ *                         +--+--*data        |
+ *                         |  |               |
+ *                         |  |               |
+ *                         |  +---------------+
+ *                         |       /|\
+ *                         |        |
+ *                         |        |
+ *                        \|/       |
+ * WQE - 128 -+-----> +-------------+-------+     -+-
+ *            |       |    *skb ----+       |      |
+ *            |       |                     |      |
+ *            |       |                     |      |
+ *  WQE_SKIP = 128    |                     |      |
+ *            |       |                     |      |
+ *            |       |                     |      |
+ *            |       |                     |      |
+ *            |       |                     |      First Skip
+ * WQE   -----+-----> +---------------------+      |
+ *                    |   word 0            |      |
+ *                    |   word 1            |      |
+ *                    |   word 2            |      |
+ *                    |   word 3            |      |
+ *                    |   word 4            |      |
+ *                    +---------------------+     -+-
+ *               +----+- packet link        |
+ *               |    |  packet data        |
+ *               |    |                     |
+ *               |    |                     |
+ *               |    |         .           |
+ *               |    |         .           |
+ *               |    |         .           |
+ *               |    +---------------------+
+ *               |
+ *               |
+ * Later buffers:|
+ *               |
+ *               |
+ *               |
+ *               |
+ *               |
+ *               |            +---SKB---------+
+ *               |            |               |
+ *               |            |               |
+ *               |         +--+--*data        |
+ *               |         |  |               |
+ *               |         |  |               |
+ *               |         |  +---------------+
+ *               |         |       /|\
+ *               |         |        |
+ *               |         |        |
+ *               |        \|/       |
+ * WQE - 128 ----+--> +-------------+-------+     -+-
+ *               |    |    *skb ----+       |      |
+ *               |    |                     |      |
+ *               |    |                     |      |
+ *               |    |                     |      |
+ *               |    |                     |      LATER_SKIP = 128
+ *               |    |                     |      |
+ *               |    |                     |      |
+ *               |    |                     |      |
+ *               |    +---------------------+     -+-
+ *               |    |  packet link        |
+ *               +--> |  packet data        |
+ *                    |                     |
+ *                    |                     |
+ *                    |         .           |
+ *                    |         .           |
+ *                    |         .           |
+ *                    +---------------------+
+ */
+
+#define MAX_TX_QUEUE_DEPTH 512
+#define SSO_INTSN_EXE 0x61
+#define MAX_RX_QUEUES 32
+
+#define SKB_PTR_OFFSET         0
+
+#define MAX_CORES              48
+#define FPA3_NUM_AURAS         1024
+
+#define USE_ASYNC_IOBDMA       1
+#define SCR_SCRATCH            0ull
+#define SSO_NO_WAIT            0ull
+#define DID_TAG_SWTAG          0x60ull
+#define IOBDMA_SENDSINGLE      0xffffffffffffa200ull
+
+/* Values for the value of wqe word2 [ERRLEV] */
+#define PKI_ERRLEV_LA          0x01
+
+/* Values for the value of wqe word2 [OPCODE] */
+#define PKI_OPCODE_NONE                0x00
+#define PKI_OPCODE_JABBER      0x02
+#define PKI_OPCODE_FCS         0x07
+
+/* Values for the layer type in the wqe */
+#define PKI_LTYPE_IP4          0x08
+#define PKI_LTYPE_IP6          0x0a
+#define PKI_LTYPE_TCP          0x10
+#define PKI_LTYPE_UDP          0x11
+#define PKI_LTYPE_SCTP         0x12
+
+/* Registers are accessed via xkphys */
+#define SSO_BASE                       0x1670000000000ull
+#define SSO_ADDR(node)                 (SET_XKPHYS + NODE_OFFSET(node) +      \
+                                        SSO_BASE)
+#define GRP_OFFSET(grp)                        ((grp) << 16)
+#define GRP_ADDR(n, g)                 (SSO_ADDR(n) + GRP_OFFSET(g))
+#define SSO_GRP_AQ_CNT(n, g)           (GRP_ADDR(n, g)            + 0x20000700)
+
+#define MIO_PTP_BASE                   0x1070000000000ull
+#define MIO_PTP_ADDR(node)             (SET_XKPHYS + NODE_OFFSET(node) +      \
+                                        MIO_PTP_BASE)
+#define MIO_PTP_CLOCK_CFG(node)                (MIO_PTP_ADDR(node)             + 0xf00)
+#define MIO_PTP_CLOCK_HI(node)         (MIO_PTP_ADDR(node)             + 0xf10)
+#define MIO_PTP_CLOCK_COMP(node)       (MIO_PTP_ADDR(node)             + 0xf18)
+
+struct octeon3_ethernet;
+
+struct octeon3_rx {
+       struct napi_struct      napi;
+       struct octeon3_ethernet *parent;
+       int rx_grp;
+       int rx_irq;
+       cpumask_t rx_affinity_hint;
+} ____cacheline_aligned_in_smp;
+
+struct octeon3_ethernet {
+       struct bgx_port_netdev_priv bgx_priv; /* Must be first element. */
+       struct list_head list;
+       struct net_device *netdev;
+       enum octeon3_mac_type mac_type;
+       struct octeon3_rx rx_cxt[MAX_RX_QUEUES];
+       struct ptp_clock_info ptp_info;
+       struct ptp_clock *ptp_clock;
+       struct cyclecounter cc;
+       struct timecounter tc;
+       spinlock_t ptp_lock;            /* Serialize ptp clock adjustments */
+       int num_rx_cxt;
+       int pki_aura;
+       int pknd;
+       int pko_queue;
+       int node;
+       int interface;
+       int index;
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/cavium/octeon/octeon3-pki.c new file +832 -0
new file mode 100644
index 000000000000..fb1435b8612e

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/cavium/octeon/octeon3-pko.c new file +1719 -0
new file mode 100644
index 000000000000..4175b603b485

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/cavium/octeon/octeon3-sso.c new file +309 -0
new file mode 100644
index 000000000000..2d1784a55570

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/cavium/octeon/octeon3.h new file +411 -1
new file mode 100644
index 000000000000..44c0359f6d51

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 2 lines

2.14.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Part of the diff is not shown here. View the raw message.

#26 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

On Wed, Nov 29, 2017 at 04:00:01PM +0530, Souptick Joarder wrote:

Hi Souptick

Please trim the code when giving reviews. We don't want to have to page through 8K lines of code it find a few comments mixed in. Just keep the beginning of the function you are commented on to make the context clear. Cut the rest.

Thanks
Andrew

#27 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to Souptick Joarder
Quoted 53 lines · Souptick Joarder
Quoted 29 lines · David Daney

From: Carlos Munoz <[email protected]>

The Cavium OCTEON cn78xx and cn73xx SoCs have network packet I/O hardware that is significantly different from previous generations of the family.

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +17 -0
new file mode 100644
index 000000000000..4dad35fa4270
@@ -0,0 +1,2033 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2017 Cavium, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/platform_device.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/of_mdio.h>
+#include <linux/of_net.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/list.h>

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +8 -0
+
 
+static void bgx_port_sgmii_set_link_down(struct bgx_port_priv *priv)
+{
+       u64     data;
 
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       data |= BIT(11);
+       oct_csr_write(data, BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));

Any particular reason to read immediately after write ?

Quoted 7 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+static int bgx_port_sgmii_set_link_speed(struct bgx_port_priv *priv, struct port_status status)
+{
+       u64     data;
+       u64     prtx;
+       u64     miscx;
+       int     timeout;
+
Quoted 5 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 694

Quoted 3 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +3 -0
+
+       switch (status.speed) {
+       case 10:

In my opinion, instead of hard coding the value, is it fine to use ENUM ?

Similar comments applicable in other places where hard coded values are used.

Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c

Quoted 8 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+static int bgx_port_gser_27882(struct bgx_port_priv *priv)
+{
+       u64     data;
+       u64     addr;
 
+       int     timeout = 200;
+
+   //    timeout = 200;

Better to initialize the timeout value

Quoted 53 lines
Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +6 -0
+static int bgx_port_qlm_rx_equalization(struct bgx_port_priv *priv, int qlm, int lane)
+{
+       lmode = oct_csr_read(GSER_LANE_MODE(priv->node, qlm));
+       lmode &= 0xf;
+       addr = GSER_LANE_P_MODE_1(priv->node, qlm, lmode);
+       data = oct_csr_read(addr);

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1114

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+       /* Don't complete rx equalization if in VMA manual mode */
+       if (data & BIT(14))
+               return 0;
+
+       /* Apply rx equalization for speed > 6250 */
+       if (bgx_port_get_qlm_speed(priv, qlm) < 6250)
+               return 0;
+
+       /* Wait until rx data is valid (CDRLOCK) */
+       timeout = 500;

500 us is the min required value or it can be further reduced ?

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +3 -0
+static int bgx_port_init_xaui_link(struct bgx_port_priv *priv)
+{
 
+

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1308

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+               if (use_ber) {
+                       timeout = 10000;
+                       do {
+                               data =
+                               oct_csr_read(BGX_SPU_BR_STATUS1(priv->node, priv->bgx, priv->index));
+                               if (data & BIT(0))
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);

In my opinion, it's better to implement similar kind of loops inside macros.

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +5 -0
+                       if (!timeout) {
+                               pr_debug("BGX%d:%d:%d: BLK_LOCK timeout\n",
+                                        priv->bgx, priv->index, priv->node);
+                               return -1;
+                       }

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1323

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+               } else {
+                       timeout = 10000;
+                       do {
+                               data =
+                               oct_csr_read(BGX_SPU_BX_STATUS(priv->node, priv->bgx, priv->index));
+                               if (data & BIT(12))
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);

same here

#28 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

Quoted 8 lines · Souptick Joarder
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+static int bgx_port_sgmii_set_link_speed(struct bgx_port_priv *priv, struct port_status status)
+{
+       u64     data;
+       u64     prtx;
+       u64     miscx;
+       int     timeout;
+
Quoted 7 lines
Quoted 5 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 694

Quoted 3 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +3 -0
+
+       switch (status.speed) {
+       case 10:

In my opinion, instead of hard coding the value, is it fine to use ENUM ?

Similar comments applicable in other places where hard coded values are used.

10 means 10M right? That's not really a magic number. It's fine.

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +13 -0
+static int bgx_port_init_xaui_link(struct bgx_port_priv *priv)
+{
 
+
+               if (use_ber) {
+                       timeout = 10000;
+                       do {
+                               data =
+                               oct_csr_read(BGX_SPU_BR_STATUS1(priv->node, priv->bgx, priv->index));
+                               if (data & BIT(0))
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);
Quoted 1 line
Quoted 1 line

In my opinion, it's better to implement similar kind of loops inside macros.

I don't understand what you mean here. For what it's worth this code seems clear enough to me (except for the bad indenting of oct_csr_read().

It should be something like:

				data = oct_csr_read(BGX_SPU_BR_STATUS1(priv->node,
						priv->bgx, priv->index));

That's over the 80 char limit but so is the original code.

regards,
dan carpenter

#29 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

Quoted 13 lines · Dan Carpenter
Quoted 12 lines · Souptick Joarder
Quoted 12 lines
Quoted 11 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+static int bgx_port_sgmii_set_link_speed(struct bgx_port_priv *priv, struct port_status status)
+{
+       u64     data;
+       u64     prtx;
+       u64     miscx;
+       int     timeout;
+
 
+
+       switch (status.speed) {
+       case 10:
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

In my opinion, instead of hard coding the value, is it fine to use ENUM ?

Similar comments applicable in other places where hard coded values are used.

10 means 10M right? That's not really a magic number. It's fine.

There are also :
uapi/linux/ethtool.h:#define SPEED_10 10
uapi/linux/ethtool.h:#define SPEED_100 100
uapi/linux/ethtool.h:#define SPEED_1000 1000
uapi/linux/ethtool.h:#define SPEED_10000 10000
uapi/linux/ethtool.h:#define SPEED_100000 100000

Andrew

#30 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to Souptick Joarder
Quoted 37 lines · Souptick Joarder
Quoted 35 lines · Souptick Joarder
Quoted 34 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

The Cavium OCTEON cn78xx and cn73xx SoCs have network packet I/O hardware that is significantly different from previous generations of the family.

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +21 -0
new file mode 100644
index 000000000000..4dad35fa4270
@@ -0,0 +1,2033 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2017 Cavium, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/platform_device.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/of_mdio.h>
+#include <linux/of_net.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+
 
+static void bgx_port_sgmii_set_link_down(struct bgx_port_priv *priv)
+{
+       u64     data;
Quoted 7 lines
Quoted 6 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 654

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +4 -0
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       data |= BIT(11);
+       oct_csr_write(data, BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx, priv->index));

Any particular reason to read immediately after write ?

Yes, to ensure the write is committed to hardware before the next step.

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+static int bgx_port_sgmii_set_link_speed(struct bgx_port_priv *priv, struct port_status status)
+{
+       u64     data;
+       u64     prtx;
+       u64     miscx;
+       int     timeout;
+
Quoted 7 lines
Quoted 5 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 694

Quoted 3 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +3 -0
+
+       switch (status.speed) {
+       case 10:

In my opinion, instead of hard coding the value, is it fine to use ENUM ?

Similar comments applicable in other places where hard coded values are used.

There is nothing to be gained by interposing an extra layer of abstraction in this case. The code is more clear with the raw numbers in this particular case.

Quoted 11 lines
Quoted 10 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+static int bgx_port_gser_27882(struct bgx_port_priv *priv)
+{
+       u64     data;
+       u64     addr;
 
+       int     timeout = 200;
+
+   //    timeout = 200;

Better to initialize the timeout value

What are you talking about? It is properly initialized using valid C code.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+static int bgx_port_qlm_rx_equalization(struct bgx_port_priv *priv, int qlm, int lane)
+{
+       lmode = oct_csr_read(GSER_LANE_MODE(priv->node, qlm));
+       lmode &= 0xf;
+       addr = GSER_LANE_P_MODE_1(priv->node, qlm, lmode);
+       data = oct_csr_read(addr);
+       /* Don't complete rx equalization if in VMA manual mode */
+       if (data & BIT(14))
+               return 0;
+
Quoted 9 lines
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1114

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +6 -0
+       /* Apply rx equalization for speed > 6250 */
+       if (bgx_port_get_qlm_speed(priv, qlm) < 6250)
+               return 0;
+
+       /* Wait until rx data is valid (CDRLOCK) */
+       timeout = 500;

500 us is the min required value or it can be further reduced ?

500 uS works well and is shorter than the 2000 uS from the hardware manual.

If you would like to verify shorter timeout values, we could consider merging such a patch. But really, this doesn't matter as it is a very short one-off action when the link is brought up.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +13 -0
+static int bgx_port_init_xaui_link(struct bgx_port_priv *priv)
+{
 
+
+               if (use_ber) {
+                       timeout = 10000;
+                       do {
+                               data =
+                               oct_csr_read(BGX_SPU_BR_STATUS1(priv->node, priv->bgx, priv->index));
+                               if (data & BIT(0))
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);
Quoted 1 line
Quoted 1 line

In my opinion, it's better to implement similar kind of loops inside macros.

Ok, duly noted. I think we are in disagreement with respect to this point.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +15 -0
+                       if (!timeout) {
+                               pr_debug("BGX%d:%d:%d: BLK_LOCK timeout\n",
+                                        priv->bgx, priv->index, priv->node);
+                               return -1;
+                       }
+               } else {
+                       timeout = 10000;
+                       do {
+                               data =
+                               oct_csr_read(BGX_SPU_BX_STATUS(priv->node, priv->bgx, priv->index));
+                               if (data & BIT(12))
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);
Quoted 1 line
Quoted 1 line

same here

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#31 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

Hi David, Dan,

Quoted 83 lines · David Daney
Quoted 57 lines · Souptick Joarder
Quoted 54 lines · Souptick Joarder
Quoted 49 lines · David Daney

From: Carlos Munoz <[email protected]>

The Cavium OCTEON cn78xx and cn73xx SoCs have network packet I/O hardware that is significantly different from previous generations of the family.

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +4 -0
new file mode 100644
index 000000000000..4dad35fa4270
@@ -0,0 +1,2033 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2017 Cavium, Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General

Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +15 -0
+#include <linux/platform_device.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/of_platform.h>
+#include <linux/of_address.h>
+#include <linux/of_mdio.h>
+#include <linux/of_net.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+
 
 
+static void bgx_port_sgmii_set_link_down(struct bgx_port_priv *priv)
+{
+       u64     data;
 
 
+       data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx,

priv->index));

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +2 -0
+       data |= BIT(11);
+       oct_csr_write(data, BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx,

priv->index));
+ data = oct_csr_read(BGX_GMP_PCS_MISC_CTL(priv->node, priv->bgx,
priv->index));

Quoted 3 lines
Quoted 1 line

Any particular reason to read immediately after write ?

Yes, to ensure the write is committed to hardware before the next step.

Quoted 19 lines
Quoted 18 lines
Quoted 5 lines

+static int bgx_port_sgmii_set_link_speed(struct bgx_port_priv *priv, struct port_status status)

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +1 -0
+{

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 694

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +8 -0
+       u64     data;
+       u64     prtx;
+       u64     miscx;
+       int     timeout;
+
 
 
+
+       switch (status.speed) {
+       case 10:

In my opinion, instead of hard coding the value, is it fine to use ENUM ?

Quoted 7 lines
Quoted 3 lines

Similar comments applicable in other places where hard coded values
are used.

There is nothing to be gained by interposing an extra layer of abstraction in this case. The code is more clear with the raw numbers in this particular case.

As mentioned by Andrew, macros defined in uapi/linux/ethtool.h may
be useful here.
Otherwise it's fine to me :)

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+static int bgx_port_gser_27882(struct bgx_port_priv *priv)
+{
+       u64     data;
+       u64     addr;
 
 
+       int     timeout = 200;
+
+   //    timeout = 200;
Quoted 5 lines
Quoted 1 line

Better to initialize the timeout value

What are you talking about? It is properly initialized using valid C code.

      I mean, instead of writing

       int     timeout;
       timeout = 200;

      write,

       int timeout = 200;

Anyway both are correct and there is nothing wrong in your code. Please ignore my comment here.

Quoted 28 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

+static int bgx_port_qlm_rx_equalization(struct bgx_port_priv *priv, int qlm, int lane)

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+{
+       lmode = oct_csr_read(GSER_LANE_MODE(priv->node, qlm));
+       lmode &= 0xf;
+       addr = GSER_LANE_P_MODE_1(priv->node, qlm, lmode);
+       data = oct_csr_read(addr);
+       /* Don't complete rx equalization if in VMA manual mode */
+       if (data & BIT(14))
+               return 0;
+
+       /* Apply rx equalization for speed > 6250 */
Quoted 10 lines
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1114

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +5 -0
+       if (bgx_port_get_qlm_speed(priv, qlm) < 6250)
+               return 0;
+
+       /* Wait until rx data is valid (CDRLOCK) */
+       timeout = 500;

500 us is the min required value or it can be further reduced ?

Quoted 5 lines

500 uS works well and is shorter than the 2000 uS from the hardware manual.

If you would like to verify shorter timeout values, we could consider merging such a patch. But really, this doesn't matter as it is a very short one-off action when the link is brought up.

Ok.

Quoted 24 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +2 -0
+static int bgx_port_init_xaui_link(struct bgx_port_priv *priv)
+{
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +6 -0
+
+               if (use_ber) {
+                       timeout = 10000;
+                       do {
+                               data =
+

oct_csr_read(BGX_SPU_BR_STATUS1(priv->node, priv->bgx, priv->index));
+ if (data & BIT(0))

Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 591

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +4 -0
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);

In my opinion, it's better to implement similar kind of loops inside macros.

Quoted 1 line

Ok, duly noted. I think we are in disagreement with respect to this point.

As similar type loops are implemented in many places, so I suggested to implement those in macros
in header file and include it here.
Anyway if you don't agree with me, I am fine with it :)

Quoted 25 lines
Quoted 23 lines
Quoted 23 lines
Quoted 16 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +2 -0
+                       if (!timeout) {
+                               pr_debug("BGX%d:%d:%d: BLK_LOCK

timeout\n",
+ priv->bgx, priv->index,
priv->node);

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+                               return -1;
+                       }
+               } else {
+                       timeout = 10000;
+                       do {
+                               data =
+

oct_csr_read(BGX_SPU_BX_STATUS(priv->node, priv->bgx, priv->index));

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1323

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +5 -0
+                               if (data & BIT(12))
+                                       break;
+                               timeout--;
+                               udelay(1);
+                       } while (timeout);

same here

#32 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to David Daney
Quoted 9 lines · David Daney
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +9 -0
+static int bgx_probe(struct platform_device *pdev)
+{
+	struct mac_platform_data platform_data;
+	const __be32 *reg;
+	u32 port;
+	u64 addr;
+	struct device_node *child;
+	struct platform_device *new_dev;
+	struct platform_device *pki_dev;

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 131

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +10 -0
+	int numa_node, interface;
+	int i;
+	int r = 0;
+	char id[64];
+	u64 data;
+
+	reg = of_get_property(pdev->dev.of_node, "reg", NULL);
+	addr = of_translate_address(pdev->dev.of_node, reg);
+	interface = (addr >> 24) & 0xf;
+	numa_node = (addr >> 36) & 0x7;

Hi David

You have these two a few times in the code. Maybe add a helper to do it? The NUMA one i assume could go somewhere in the SoC code?

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 282

Quoted 12 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +11 -0
+static int bgx_mix_init_from_fdt(void)
+{
+	struct device_node	*node;
+	struct device_node	*parent = NULL;
+	int			mix = 0;
 
+		/* Get the lmac index */
+		reg = of_get_property(lmac_fdt_node, "reg", NULL);
+		if (!reg)
+			goto err;
+
+		mix_port_lmacs[mix].lmac = *reg;

I don't think of_get_property() deals with endianness. Is there any danger of this driver being used on hardware with the other endianness to what you have tested?

Quoted 25 lines

+/**
+ * bgx_pki_init_from_param - Initialize the list of lmacs that connect to the
+ * pki from information in the "pki_port" parameter.
+ *

+ *			     The pki_port parameter format is as follows:
+ *			     pki_port=nbl
+ *			     where:

+ * n = node
+ * b = bgx
+ * l = lmac
+ *
+ * Commas must be used to separate multiple lmacs:
+ * pki_port=000,100,110
+ *

+ *			     Asterisks (*) specify all possible characters in
+ *			     the subset:
+ *			     pki_port=00* (all lmacs of node0 bgx0).
+ *
+ *			     Missing lmacs identifiers default to all
+ *			     possible characters in the subset:
+ *			     pki_port=00 (all lmacs on node0 bgx0)
+ *
+ *			     Brackets ('[' and ']') specify the valid
+ *			     characters in the subset:
+ *			     pki_port=00[01] (lmac0 and lmac1 of node0 bgx0).
Quoted 3 lines

+ *
+ * Returns 0 if successful.
+ * Returns <0 for error codes.

I've not used kerneldoc much, but i suspect this is wrongly formated:

https://www.kernel.org/doc/html/v4.9/kernel-documentation.html#function-documentation

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1528

Quoted 7 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+int bgx_port_ethtool_set_settings(struct net_device	*netdev,
+				  struct ethtool_cmd	*cmd)
+{
+	struct bgx_port_priv *p = bgx_port_netdev2priv(netdev);
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;

Not required. The enforces this. See dev_ethtool()

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +4 -0
+
+	if (p->phydev)
+		return phy_ethtool_sset(p->phydev, cmd);
+

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1542

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+	return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(bgx_port_ethtool_set_settings);
+
+int bgx_port_ethtool_nway_reset(struct net_device *netdev)
+{
+	struct bgx_port_priv *p = bgx_port_netdev2priv(netdev);
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;

Also not needed.

Quoted 36 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +36 -0
+static void bgx_port_adjust_link(struct net_device *netdev)
+{
+	struct bgx_port_priv	*priv = bgx_port_netdev2priv(netdev);
+	bool			link_changed = false;
+	unsigned int		link;
+	unsigned int		speed;
+	unsigned int		duplex;
+
+	mutex_lock(&priv->lock);
+
+	if (!priv->phydev->link && priv->last_status.link)
+		link_changed = true;
+
+	if (priv->phydev->link &&
+	    (priv->last_status.link != priv->phydev->link ||
+	     priv->last_status.duplex != priv->phydev->duplex ||
+	     priv->last_status.speed != priv->phydev->speed))
+		link_changed = true;
+
+	link = priv->phydev->link;
+	priv->last_status.link = priv->phydev->link;
+
+	speed = priv->phydev->speed;
+	priv->last_status.speed = priv->phydev->speed;
+
+	duplex = priv->phydev->duplex;
+	priv->last_status.duplex = priv->phydev->duplex;
+
+	mutex_unlock(&priv->lock);
+
+	if (link_changed) {
+		struct port_status status;
+
+		phy_print_status(priv->phydev);
+
+		status.link = link ? 1 : 0;

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1690

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+		status.duplex = duplex;
+		status.speed = speed;
+		if (!link) {
+			netif_carrier_off(netdev);
+			 /* Let TX drain. FIXME check that it is drained. */
+			mdelay(50);
+		}
+		priv->set_link(priv, status);
+		if (link)
+			netif_carrier_on(netdev);

The code should do netif_carrier_on/off for you. See phy_link_change()

Quoted 9 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +9 -0
+static void bgx_port_check_state(struct work_struct *work)
+{
+	struct bgx_port_priv	*priv;
+	struct port_status	status;
+
+	priv = container_of(work, struct bgx_port_priv, dwork.work);
+
+	status = priv->get_link(priv);
+

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1712

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+	if (!status.link &&
+	    priv->mode != PORT_MODE_SGMII && priv->mode != PORT_MODE_RGMII)
+		bgx_port_init_xaui_link(priv);
+
+	if (priv->last_status.link != status.link) {
+		priv->last_status.link = status.link;
+		if (status.link)
+			netdev_info(priv->netdev, "Link is up - %d/%s\n",
+				    status.speed,
+				    status.duplex == DUPLEX_FULL ? "Full" : "Half");

You already have phy_print_status() in bgx_port_adjust_link(). Do you need this here?

Quoted 13 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +12 -0
+		else
+			netdev_info(priv->netdev, "Link is down\n");
+	}
+
+	mutex_lock(&priv->lock);
+	if (priv->work_queued)
+		queue_delayed_work(check_state_wq, &priv->dwork, HZ);
+	mutex_unlock(&priv->lock);
+}
+
+int bgx_port_enable(struct net_device *netdev)
+{
 

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1792

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +9 -0
 
+	} else {
+		priv->phydev = of_phy_connect(netdev, priv->phy_np,
+					      bgx_port_adjust_link, 0, priv->phy_mode);
+		if (!priv->phydev)
+			return -ENODEV;
+
+		netif_carrier_off(netdev);
+
+		if (priv->phydev)

You already checked this above.

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1832

Quoted 13 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +13 -0
+			phy_start_aneg(priv->phydev);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(bgx_port_enable);
+
+int bgx_port_change_mtu(struct net_device *netdev, int new_mtu)
+{
+	struct bgx_port_priv *priv = bgx_port_netdev2priv(netdev);
+	int max_frame;
+
+	if (new_mtu < 60 || new_mtu > 65392) {

See dev_set_mtu(). If you have done your initialisation correctly, this won't happen.

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +4 -0
+static int bgx_port_probe(struct platform_device *pdev)
+{
+	switch (priv->mode) {
+	case PORT_MODE_SGMII:

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1939

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+		if (priv->phy_np &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_SGMII)
+			dev_warn(&pdev->dev, "SGMII phy mode mismatch.\n");
+		goto set_link_functions;
+	case PORT_MODE_RGMII:
+		if (priv->phy_np &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_RGMII &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_RGMII_ID &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_RGMII_RXID &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_RGMII_TXID)

phy_interface_mode_is_rgmii()

More later, maybe.

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#33 lore raw

Re: [PATCH v4 7/8] netdev: octeon-ethernet: Add Cavium Octeon III support.

Quoted 23 lines · Andrew Lunn
Quoted 9 lines · David Daney
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +9 -0
+static int bgx_probe(struct platform_device *pdev)
+{
+	struct mac_platform_data platform_data;
+	const __be32 *reg;
+	u32 port;
+	u64 addr;
+	struct device_node *child;
+	struct platform_device *new_dev;
+	struct platform_device *pki_dev;

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 131

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +10 -0
+	int numa_node, interface;
+	int i;
+	int r = 0;
+	char id[64];
+	u64 data;
+
+	reg = of_get_property(pdev->dev.of_node, "reg", NULL);
+	addr = of_translate_address(pdev->dev.of_node, reg);
+	interface = (addr >> 24) & 0xf;
+	numa_node = (addr >> 36) & 0x7;

Hi David

Quoted 3 lines

You have these two a few times in the code. Maybe add a helper to do it? The NUMA one i assume could go somewhere in the SoC code?

Thanks for looking at it, I will try with helpers.

The rest of your comments below raise valid points, I will fix those too.

Quoted 212 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 282

Quoted 12 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +11 -0
+static int bgx_mix_init_from_fdt(void)
+{
+	struct device_node	*node;
+	struct device_node	*parent = NULL;
+	int			mix = 0;
 
+		/* Get the lmac index */
+		reg = of_get_property(lmac_fdt_node, "reg", NULL);
+		if (!reg)
+			goto err;
+
+		mix_port_lmacs[mix].lmac = *reg;

I don't think of_get_property() deals with endianness. Is there any danger of this driver being used on hardware with the other endianness to what you have tested?

Quoted 25 lines

+/**
+ * bgx_pki_init_from_param - Initialize the list of lmacs that connect to the
+ * pki from information in the "pki_port" parameter.
+ *

+ *			     The pki_port parameter format is as follows:
+ *			     pki_port=nbl
+ *			     where:

+ * n = node
+ * b = bgx
+ * l = lmac
+ *
+ * Commas must be used to separate multiple lmacs:
+ * pki_port=000,100,110
+ *

+ *			     Asterisks (*) specify all possible characters in
+ *			     the subset:
+ *			     pki_port=00* (all lmacs of node0 bgx0).
+ *
+ *			     Missing lmacs identifiers default to all
+ *			     possible characters in the subset:
+ *			     pki_port=00 (all lmacs on node0 bgx0)
+ *
+ *			     Brackets ('[' and ']') specify the valid
+ *			     characters in the subset:
+ *			     pki_port=00[01] (lmac0 and lmac1 of node0 bgx0).
Quoted 3 lines

+ *
+ * Returns 0 if successful.
+ * Returns <0 for error codes.

I've not used kerneldoc much, but i suspect this is wrongly formated:

https://www.kernel.org/doc/html/v4.9/kernel-documentation.html#function-documentation

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1528

Quoted 7 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +7 -0
+int bgx_port_ethtool_set_settings(struct net_device	*netdev,
+				  struct ethtool_cmd	*cmd)
+{
+	struct bgx_port_priv *p = bgx_port_netdev2priv(netdev);
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;

Not required. The enforces this. See dev_ethtool()

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +4 -0
+
+	if (p->phydev)
+		return phy_ethtool_sset(p->phydev, cmd);
+

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1542

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+	return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(bgx_port_ethtool_set_settings);
+
+int bgx_port_ethtool_nway_reset(struct net_device *netdev)
+{
+	struct bgx_port_priv *p = bgx_port_netdev2priv(netdev);
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;

Also not needed.

Quoted 36 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +36 -0
+static void bgx_port_adjust_link(struct net_device *netdev)
+{
+	struct bgx_port_priv	*priv = bgx_port_netdev2priv(netdev);
+	bool			link_changed = false;
+	unsigned int		link;
+	unsigned int		speed;
+	unsigned int		duplex;
+
+	mutex_lock(&priv->lock);
+
+	if (!priv->phydev->link && priv->last_status.link)
+		link_changed = true;
+
+	if (priv->phydev->link &&
+	    (priv->last_status.link != priv->phydev->link ||
+	     priv->last_status.duplex != priv->phydev->duplex ||
+	     priv->last_status.speed != priv->phydev->speed))
+		link_changed = true;
+
+	link = priv->phydev->link;
+	priv->last_status.link = priv->phydev->link;
+
+	speed = priv->phydev->speed;
+	priv->last_status.speed = priv->phydev->speed;
+
+	duplex = priv->phydev->duplex;
+	priv->last_status.duplex = priv->phydev->duplex;
+
+	mutex_unlock(&priv->lock);
+
+	if (link_changed) {
+		struct port_status status;
+
+		phy_print_status(priv->phydev);
+
+		status.link = link ? 1 : 0;

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1690

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+		status.duplex = duplex;
+		status.speed = speed;
+		if (!link) {
+			netif_carrier_off(netdev);
+			 /* Let TX drain. FIXME check that it is drained. */
+			mdelay(50);
+		}
+		priv->set_link(priv, status);
+		if (link)
+			netif_carrier_on(netdev);

The code should do netif_carrier_on/off for you. See phy_link_change()

Quoted 9 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +9 -0
+static void bgx_port_check_state(struct work_struct *work)
+{
+	struct bgx_port_priv	*priv;
+	struct port_status	status;
+
+	priv = container_of(work, struct bgx_port_priv, dwork.work);
+
+	status = priv->get_link(priv);
+

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1712

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+	if (!status.link &&
+	    priv->mode != PORT_MODE_SGMII && priv->mode != PORT_MODE_RGMII)
+		bgx_port_init_xaui_link(priv);
+
+	if (priv->last_status.link != status.link) {
+		priv->last_status.link = status.link;
+		if (status.link)
+			netdev_info(priv->netdev, "Link is up - %d/%s\n",
+				    status.speed,
+				    status.duplex == DUPLEX_FULL ? "Full" : "Half");

You already have phy_print_status() in bgx_port_adjust_link(). Do you need this here?

Quoted 13 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +12 -0
+		else
+			netdev_info(priv->netdev, "Link is down\n");
+	}
+
+	mutex_lock(&priv->lock);
+	if (priv->work_queued)
+		queue_delayed_work(check_state_wq, &priv->dwork, HZ);
+	mutex_unlock(&priv->lock);
+}
+
+int bgx_port_enable(struct net_device *netdev)
+{
 

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1792

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +9 -0
 
+	} else {
+		priv->phydev = of_phy_connect(netdev, priv->phy_np,
+					      bgx_port_adjust_link, 0, priv->phy_mode);
+		if (!priv->phydev)
+			return -ENODEV;
+
+		netif_carrier_off(netdev);
+
+		if (priv->phydev)

You already checked this above.

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1832

Quoted 13 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +13 -0
+			phy_start_aneg(priv->phydev);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(bgx_port_enable);
+
+int bgx_port_change_mtu(struct net_device *netdev, int new_mtu)
+{
+	struct bgx_port_priv *priv = bgx_port_netdev2priv(netdev);
+	int max_frame;
+
+	if (new_mtu < 60 || new_mtu > 65392) {

See dev_set_mtu(). If you have done your initialisation correctly, this won't happen.

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +4 -0
+static int bgx_port_probe(struct platform_device *pdev)
+{
+	switch (priv->mode) {
+	case PORT_MODE_SGMII:

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c line 1939

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +10 -0
+		if (priv->phy_np &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_SGMII)
+			dev_warn(&pdev->dev, "SGMII phy mode mismatch.\n");
+		goto set_link_functions;
+	case PORT_MODE_RGMII:
+		if (priv->phy_np &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_RGMII &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_RGMII_ID &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_RGMII_RXID &&
+		    priv->phy_mode != PHY_INTERFACE_MODE_RGMII_TXID)

phy_interface_mode_is_rgmii()

More later, maybe.

Andrew

#34 lore raw

PATCH v4 8/8 MAINTAINERS: Add entry for drivers/net/ethernet/cavium/octeon/octeon3-*

In reply to David Daney
---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index aa71ab52fd76..e9239ff3cf05 100644
@@ -3249,6 +3249,12 @@ W:	http://www.cavium.com
 S:	Supported
 F:	drivers/mmc/host/cavium*
 
+CAVIUM OCTEON-III NETWORK DRIVER
+M:	David Daney <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/net/ethernet/cavium/octeon/octeon3-*
+
 CAVIUM OCTEON-TX CRYPTO DRIVER
 M:	George Cherian <[email protected]>
 L:	[email protected]
Signature · 1 line
2.14.3