mips: octeon: Add ethernet support
Subsystems (2)
PATCH v2 19/52 mips: octeon: Add cvmx-helper-pko3.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-helper-pko3.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-helper-pko3.c | 1088 ++++++++++++++++++++++ 1 file changed, 1088 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-helper-pko3.c
arch/mips/mach-octeon/cvmx-helper-pko3.c new file +1088 -0
@@ -0,0 +1,1088 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* PKOv3 helper file +*/ + +#include <errno.h> +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> +#include <mach/cvmx-range.h> +#include <mach/cvmx-global-resources.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-gserx-defs.h> +#include <mach/cvmx-ilk-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-hwpko.h> +#include <mach/cvmx-ilk.h> +#include <mach/cvmx-ipd.h> +#include <mach/cvmx-pki.h> +#include <mach/cvmx-pko3.h> +#include <mach/cvmx-pko3-queue.h> +#include <mach/cvmx-pko3-resources.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-helper-bgx.h> +#include <mach/cvmx-helper-cfg.h> +#include <mach/cvmx-helper-util.h> +#include <mach/cvmx-helper-pki.h> + +/* channels are present at L2 queue level by default */ +static const enum cvmx_pko3_level_e cvmx_pko_default_channel_level = +CVMX_PKO_L2_QUEUES ; + +static const int debug; + +static int __pko_pkt_budget, __pko_pkt_quota; + +/* These global variables are relevant for boot CPU only */ +static cvmx_fpa3_gaura_t __cvmx_pko3_aura[CVMX_MAX_NODES ]; + +/* This constant can not be modified, defined here for clarity only */ +#define CVMX_PKO3_POOL_BUFFER_SIZE 4096/* 78XX PKO requires 4KB */ + +/** +* @INTERNAL +* +* Build an owner tag based on interface/port +*/ +static int __cvmx_helper_pko3_res_owner (int ipd_port) +{ +int res_owner; +const int res_owner_pfix =0x19d0 <<14 ; + + ipd_port &=0x3fff ;/* 12-bit for local CHAN_E value + node */ + + res_owner = res_owner_pfix | ipd_port; + +return res_owner; +} + +/** +* Configure an AURA/POOL designated for PKO internal use. +* +* This pool is used for (a) memory buffers that store PKO descriptor queues, +* (b) buffers for use with PKO_SEND_JUMP_S sub-header. +* +* The buffers of type (a) are never accessed by software, and their number +* should be at least equal to 4 times the number of descriptor queues +* in use. +* +* Type (b) buffers are consumed by PKO3 command-composition code, +* and are released by the hardware upon completion of transmission. +* +* @returns -1 if the pool could not be established or 12-bit AURA +* that includes the node number for use in PKO3 initialization call. +* +* NOTE: Linux kernel should pass its own aura to PKO3 initialization +* function so that the buffers can be mapped into kernel space +* for when software needs to adccess their contents. +* +*/ +static int __cvmx_pko3_config_memory (unsigned int node) +{ +cvmx_fpa3_gaura_t aura; +int aura_num; +unsigned int buf_count; +bool small_mem; +int i, num_intf =0 ; +const unsigned int pkt_per_buf = + (CVMX_PKO3_POOL_BUFFER_SIZE /sizeof (u64) /16 ); +const unsigned int base_buf_count =1024 *4 ; + +/* Simulator has limited memory, but uses one interface at a time */ +// small_mem = cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM; + small_mem = false; + +/* Count the number of live interfaces */ +for (i =0 ; i <cvmx_helper_get_number_of_interfaces (); i++) { +int xiface =cvmx_helper_node_interface_to_xiface (node, i); + +if (CVMX_HELPER_INTERFACE_MODE_DISABLED != +cvmx_helper_interface_get_mode (xiface)) + num_intf++; + } + + buf_count =1024 ; + __pko_pkt_quota = buf_count * pkt_per_buf; + __pko_pkt_budget = __pko_pkt_quota * num_intf; + (void )small_mem; + (void )base_buf_count; + +if (debug) +debug ("%s: Creating AURA with %u buffers for up to %d total packets, %d packets per interface\n" , + __func__, buf_count, __pko_pkt_budget, __pko_pkt_quota); + + aura =cvmx_fpa3_setup_aura_and_pool (node,-1 ,"PKO3 AURA" ,NULL , +CVMX_PKO3_POOL_BUFFER_SIZE , + buf_count); + +if (!__cvmx_fpa3_aura_valid (aura)) { +printf ("ERROR: %s AURA create failed\n" , __func__); +return -1 ; + } + + aura_num = aura.node <<10 | aura.laura; + +/* Store handle for destruction */ + __cvmx_pko3_aura[node] = aura; + +return aura_num; +} + +/** Initialize a channelized port +* This is intended for LOOP, ILK and NPI interfaces which have one MAC +* per interface and need a channel per subinterface (e.g. ring). +* Each channel then may have 'num_queues' descriptor queues +* attached to it, which can also be prioritized or fair. +*/ +static int __cvmx_pko3_config_chan_interface (int xiface,unsigned int num_chans, +u8 num_queues,bool prioritized) +{ +int l1_q_num; +int l2_q_base; +enum cvmx_pko3_level_e level; +int res; +int parent_q, child_q; +unsigned int chan, dq; +int pko_mac_num; +u16 ipd_port; +int res_owner, prio; +unsigned int i; +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +unsigned int node = xi.node; +char b1[12 ]; + +if (num_queues ==0 ) + num_queues =1 ; +if ((cvmx_pko3_num_level_queues (CVMX_PKO_DESCR_QUEUES ) / num_chans) <3 ) + num_queues =1 ; + +if (prioritized && num_queues >1 ) + prio = num_queues; +else + prio =-1 ; + +if (debug) +debug ("%s: configuring xiface %u:%u with %u chans %u queues each\n" , + __func__, xi.node, xi.interface, num_chans, num_queues); + +/* all channels all go to the same mac */ + pko_mac_num =__cvmx_pko3_get_mac_num (xiface,0 ); +if (pko_mac_num <0 ) { +printf ("ERROR: %s: Invalid interface\n" , __func__); +return -1 ; + } + +/* Resources of all channels on this port have common owner */ + ipd_port =cvmx_helper_get_ipd_port (xiface,0 ); + +/* Build an identifiable owner */ + res_owner =__cvmx_helper_pko3_res_owner (ipd_port); + +/* Start configuration at L1/PQ */ + level =CVMX_PKO_PORT_QUEUES ; + +/* Reserve port queue to make sure the MAC is not already configured */ + l1_q_num =cvmx_pko_alloc_queues (node, level, res_owner,-1 ,1 ); + +if (l1_q_num <0 ) { +printf ("ERROR: %s: Reserving L1 PQ\n" , __func__); +return -1 ; + } + + res =cvmx_pko3_pq_config (node, pko_mac_num, l1_q_num); +if (res <0 ) { +printf ("ERROR: %s: Configuring L1 PQ\n" , __func__); +return -1 ; + } + +/* next queue level = L2/SQ */ + level =__cvmx_pko3_sq_lvl_next (level); + +/* allocate level 2 queues, one per channel */ + l2_q_base = +cvmx_pko_alloc_queues (node, level, res_owner,-1 , num_chans); +if (l2_q_base <0 ) { +printf ("ERROR: %s: allocation L2 SQ\n" , __func__); +return -1 ; + } + +/* Configre <num_chans> L2 children for PQ, non-prioritized */ + res =cvmx_pko3_sq_config_children (node, level, l1_q_num, l2_q_base, + num_chans,-1 ); + +if (res <0 ) { +printf ("ERROR: %s: Failed channel queues\n" , __func__); +return -1 ; + } + +/* map channels to l2 queues */ +for (chan =0 ; chan < num_chans; chan++) { + ipd_port =cvmx_helper_get_ipd_port (xiface, chan); +cvmx_pko3_map_channel (node, l1_q_num, l2_q_base + chan, + ipd_port); + } + +/* next queue level = L3/SQ */ + level =__cvmx_pko3_sq_lvl_next (level); + parent_q = l2_q_base; + +do { + child_q =cvmx_pko_alloc_queues (node, level, res_owner,-1 , + num_chans); + +if (child_q <0 ) { +printf ("ERROR: %s: allocating %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, child_q)); +return -1 ; + } + +for (i =0 ; i < num_chans; i++) { + res =cvmx_pko3_sq_config_children ( + node, level, parent_q + i, child_q + i,1 ,1 ); + +if (res <0 ) { +printf ("ERROR: %s: configuring %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, child_q)); +return -1 ; + } + + }/* for i */ + + parent_q = child_q; + level =__cvmx_pko3_sq_lvl_next (level); + +/* Terminate loop on DQ level, it has special handling */ + }while (level !=CVMX_PKO_DESCR_QUEUES && + level !=CVMX_PKO_LEVEL_INVAL ); + +if (level !=CVMX_PKO_DESCR_QUEUES ) { +printf ("ERROR: %s: level sequence error\n" , __func__); +return -1 ; + } + +/* Configure DQs, num_dqs per chan */ +for (chan =0 ; chan < num_chans; chan++) { + res =cvmx_pko_alloc_queues (node, level, res_owner,-1 , + num_queues); + +if (res <0 ) + goto _fail; + dq = res; + +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_0 ) && (dq &7 )) +debug ("WARNING: %s: DQ# %u not integral of 8\n" , + __func__, dq); + + res =cvmx_pko3_sq_config_children (node, level, parent_q + chan, + dq, num_queues, prio); +if (res <0 ) + goto _fail; + +/* register DQ range with the translation table */ + res =__cvmx_pko3_ipd_dq_register (xiface, chan, dq, num_queues); +if (res <0 ) + goto _fail; + } + +return 0 ; +_fail: +debug ("ERROR: %s: configuring queues for xiface %u:%u chan %u\n" , + __func__, xi.node, xi.interface, i); +return -1 ; +} + +/** Initialize a single Ethernet port with PFC-style channels +* +* One interface can contain multiple ports, this function is per-port +* Here, a physical port is allocated 8 logical channel, one per VLAN +* tag priority, one DQ is assigned to each channel, and all 8 DQs +* are registered for that IPD port. +* Note that the DQs are arrange such that the Ethernet QoS/PCP field +* can be used as an offset to the value returned by cvmx_pko_base_queue_get(). +* +* For HighGig2 mode, 16 channels may be desired, instead of 8, +* but this function does not support that. +*/ +static int __cvmx_pko3_config_pfc_interface (int xiface,unsigned int port) +{ +enum cvmx_pko3_level_e level; +int pko_mac_num; +int l1_q_num, l2_q_base; +int child_q, parent_q; +int dq_base; +int res; +const unsigned int num_chans =8 ; +cvmx_xiface_t xi =cvmx_helper_xiface_to_node_interface (xiface); +unsigned int node = xi.node; +u16 ipd_port; +int res_owner; +char b1[12 ]; +unsigned int i; + +if (debug) +debug ("%s: configuring xiface %u:%u port %u with %u PFC channels\n" , + __func__, node, xi.interface, port, num_chans); + +/* Get MAC number for the iface/port */ + pko_mac_num =__cvmx_pko3_get_mac_num (xiface, port); +if (pko_mac_num <0 ) { +printf ("ERROR: %s: Invalid interface\n" , __func__); +return -1 ; + } + + ipd_port =cvmx_helper_get_ipd_port (xiface, port); + +/* Build an identifiable owner identifier */ + res_owner =__cvmx_helper_pko3_res_owner (ipd_port); + + level =CVMX_PKO_PORT_QUEUES ; + +/* Allocate port queue to make sure the MAC is not already configured */ + l1_q_num =cvmx_pko_alloc_queues (node, level, res_owner,-1 ,1 ); + +if (l1_q_num <0 ) { +printf ("ERROR: %s: allocation L1 PQ\n" , __func__); +return -1 ; + } + + res =cvmx_pko3_pq_config (xi.node, pko_mac_num, l1_q_num); +if (res <0 ) { +printf ("ERROR: %s: Configuring %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, l1_q_num)); +return -1 ; + } + +/* Determine the next queue level */ + level =__cvmx_pko3_sq_lvl_next (level); + +/* Allocate 'num_chans' L2 queues, one per channel */ + l2_q_base = +cvmx_pko_alloc_queues (node, level, res_owner,-1 , num_chans); +if (l2_q_base <0 ) { +printf ("ERROR: %s: allocation L2 SQ\n" , __func__); +return -1 ; + } + +/* Configre <num_chans> L2 children for PQ, with static priority */ + res =cvmx_pko3_sq_config_children (node, level, l1_q_num, l2_q_base, + num_chans, num_chans); + +if (res <0 ) { +printf ("ERROR: %s: Configuring %s for PFC\n" , __func__, +__cvmx_pko3_sq_str (b1, level, l1_q_num)); +return -1 ; + } + +/* Map each of the allocated channels */ +for (i =0 ; i < num_chans; i++) { +u16 chan; + +/* Get CHAN_E value for this PFC channel, PCP in low 3 bits */ + chan = ipd_port |cvmx_helper_prio2qos (i); + +cvmx_pko3_map_channel (node, l1_q_num, l2_q_base + i, chan); + } + +/* Iterate through the levels until DQ and allocate 'num_chans' +* consecutive queues at each level and hook them up +* one-to-one with the parent level queues +*/ + + parent_q = l2_q_base; + level =__cvmx_pko3_sq_lvl_next (level); + +do { + child_q =cvmx_pko_alloc_queues (node, level, res_owner,-1 , + num_chans); + +if (child_q <0 ) { +printf ("ERROR: %s: allocating %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, child_q)); +return -1 ; + } + +for (i =0 ; i < num_chans; i++) { + res =cvmx_pko3_sq_config_children ( + node, level, parent_q + i, child_q + i,1 ,1 ); + +if (res <0 ) { +printf ("ERROR: %s: configuring %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, child_q)); +return -1 ; + } + + }/* for i */ + + parent_q = child_q; + level =__cvmx_pko3_sq_lvl_next (level); + +/* Terminate loop on DQ level, it has special handling */ + }while (level !=CVMX_PKO_DESCR_QUEUES && + level !=CVMX_PKO_LEVEL_INVAL ); + +if (level !=CVMX_PKO_DESCR_QUEUES ) { +printf ("ERROR: %s: level sequence error\n" , __func__); +return -1 ; + } + + dq_base =cvmx_pko_alloc_queues (node, level, res_owner,-1 , num_chans); +if (dq_base <0 ) { +printf ("ERROR: %s: allocating %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, dq_base)); +return -1 ; + } + +/* Configure DQs in QoS order, so that QoS/PCP can be index */ +for (i =0 ; i < num_chans; i++) { +int dq_num = dq_base +cvmx_helper_prio2qos (i); + + res =cvmx_pko3_sq_config_children (node, level, parent_q + i, + dq_num,1 ,1 ); +if (res <0 ) { +printf ("ERROR: %s: configuring %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, dq_num)); +return -1 ; + } + } + +/* register entire DQ range with the IPD translation table */ +__cvmx_pko3_ipd_dq_register (xiface, port, dq_base, num_chans); + +return 0 ; +} + +/** +* Initialize a simple interface with a a given number of +* fair or prioritized queues. +* This function will assign one channel per sub-interface. +*/ +int __cvmx_pko3_config_gen_interface (int xiface,uint8_t subif,u8 num_queues, +bool prioritized) +{ +cvmx_xiface_t xi =cvmx_helper_xiface_to_node_interface (xiface); +u8 node = xi.node; +int l1_q_num; +int parent_q, child_q; +int dq; +int res, res_owner; +int pko_mac_num; +enum cvmx_pko3_level_e level; +u16 ipd_port; +int static_pri; +char b1[12 ]; + + num_queues =1 ; + +if (num_queues ==0 ) { + num_queues =1 ; +printf ("WARNING: %s: xiface %#x misconfigured\n" , __func__, + xiface); + } + +/* Configure DQs relative priority (a.k.a. scheduling) */ +if (prioritized) { +/* With 8 queues or fewer, use static priority, else WRR */ + static_pri = (num_queues <9 ) ? num_queues :0 ; + }else { +/* Set equal-RR scheduling among queues */ + static_pri =-1 ; + } + +if (debug) +debug ("%s: configuring xiface %u:%u/%u nq=%u %s\n" , __func__, + xi.node, xi.interface, subif, num_queues, + (prioritized) ?"qos" :"fair" ); + +/* Get MAC number for the iface/port */ + pko_mac_num =__cvmx_pko3_get_mac_num (xiface, subif); +if (pko_mac_num <0 ) { +printf ("ERROR: %s: Invalid interface %u:%u\n" , __func__, + xi.node, xi.interface); +return -1 ; + } + + ipd_port =cvmx_helper_get_ipd_port (xiface, subif); + +if (debug) +debug ("%s: xiface %u:%u/%u ipd_port=%#03x\n" , __func__, xi.node, + xi.interface, subif, ipd_port); + +/* Build an identifiable owner identifier */ + res_owner =__cvmx_helper_pko3_res_owner (ipd_port); + + level =CVMX_PKO_PORT_QUEUES ; + +/* Reserve port queue to make sure the MAC is not already configured */ + l1_q_num =cvmx_pko_alloc_queues (node, level, res_owner,-1 ,1 ); + +if (l1_q_num <0 ) { +printf ("ERROR %s: xiface %u:%u/%u failed allocation L1 PQ\n" , + __func__, xi.node, xi.interface, subif); +return -1 ; + } + + res =cvmx_pko3_pq_config (node, pko_mac_num, l1_q_num); +if (res <0 ) { +printf ("ERROR %s: Configuring L1 PQ\n" , __func__); +return -1 ; + } + + parent_q = l1_q_num; + +/* Determine the next queue level */ + level =__cvmx_pko3_sq_lvl_next (level); + +/* Simply chain queues 1-to-1 from L2 to one before DQ level */ +do { +/* allocate next level queue */ + child_q =cvmx_pko_alloc_queues (node, level, res_owner,-1 ,1 ); + +if (child_q <0 ) { +printf ("ERROR: %s: allocating %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, child_q)); +return -1 ; + } + +/* Configre newly allocated queue */ + res =cvmx_pko3_sq_config_children (node, level, parent_q, + child_q,1 ,1 ); + +if (res <0 ) { +printf ("ERROR: %s: configuring %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, child_q)); +return -1 ; + } + +/* map IPD/channel to L2/L3 queues */ +if (level == cvmx_pko_default_channel_level) +cvmx_pko3_map_channel (node, l1_q_num, child_q, + ipd_port); + +/* Prepare for next level */ + level =__cvmx_pko3_sq_lvl_next (level); + parent_q = child_q; + +/* Terminate loop on DQ level, it has special handling */ + }while (level !=CVMX_PKO_DESCR_QUEUES && + level !=CVMX_PKO_LEVEL_INVAL ); + +if (level !=CVMX_PKO_DESCR_QUEUES ) { +printf ("ERROR: %s: level sequence error\n" , __func__); +return -1 ; + } + +/* Allocate descriptor queues for the port */ + dq =cvmx_pko_alloc_queues (node, level, res_owner,-1 , num_queues); +if (dq <0 ) { +printf ("ERROR: %s: could not reserve DQs\n" , __func__); +return -1 ; + } + + res =cvmx_pko3_sq_config_children (node, level, parent_q, dq, + num_queues, static_pri); +if (res <0 ) { +printf ("ERROR: %s: configuring %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, dq)); +return -1 ; + } + +/* register DQ/IPD translation */ +__cvmx_pko3_ipd_dq_register (xiface, subif, dq, num_queues); + +if (debug) +debug ("%s: xiface %u:%u/%u qs %u-%u\n" , __func__, xi.node, + xi.interface, subif, dq, dq + num_queues -1 ); +return 0 ; +} + +/** Initialize the NULL interface +* +* A NULL interface is a special case in that it is not +* one of the enumerated interfaces in the system, and does +* not apply to input either. Still, it can be very handy +* for dealing with packets that should be discarded in +* a generic, streamlined way. +* +* The Descriptor Queue 0 will be reserved for the NULL interface +* and the normalized (i.e. IPD) port number has the all-ones value. +*/ +static int __cvmx_pko3_config_null_interface (unsigned int node) +{ +int l1_q_num; +int parent_q, child_q; +enum cvmx_pko3_level_e level; +int i, res, res_owner; +int xiface, ipd_port; +int num_dq =1 ;/* # of DQs for NULL */ +const int dq =0 ;/* Reserve DQ#0 for NULL */ +char pko_mac_num; +char b1[12 ]; + +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) + pko_mac_num =0x1C ;/* MAC# 28 virtual MAC for NULL */ +else if (OCTEON_IS_MODEL (OCTEON_CN73XX )) + pko_mac_num =0x0F ;/* MAC# 16 virtual MAC for NULL */ +else if (OCTEON_IS_MODEL (OCTEON_CNF75XX )) + pko_mac_num =0x0A ;/* MAC# 10 virtual MAC for NULL */ +else +return -1 ; + +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_0 )) + num_dq =8 ; + +if (debug) +debug ("%s: null iface dq=%u-%u\n" , __func__, dq, + dq + num_dq -1 ); + + ipd_port =cvmx_helper_node_to_ipd_port (node,CVMX_PKO3_IPD_PORT_NULL ); + +/* Build an identifiable owner identifier by MAC# for easy release */ + res_owner =__cvmx_helper_pko3_res_owner (ipd_port); +if (res_owner <0 ) { +debug ("%s: ERROR Invalid interface\n" , __func__); +return -1 ; + } + + level =CVMX_PKO_PORT_QUEUES ; + +/* Allocate a port queue */ + l1_q_num =cvmx_pko_alloc_queues (node, level, res_owner,-1 ,1 ); + +if (l1_q_num <0 ) { +debug ("%s: ERROR reserving L1 SQ\n" , __func__); +return -1 ; + } + + res =cvmx_pko3_pq_config (node, pko_mac_num, l1_q_num); +if (res <0 ) { +printf ("ERROR: %s: PQ/L1 queue configuration\n" , __func__); +return -1 ; + } + + parent_q = l1_q_num; + +/* Determine the next queue level */ + level =__cvmx_pko3_sq_lvl_next (level); + +/* Simply chain queues 1-to-1 from L2 to one before DQ level */ +do { +/* allocate next level queue */ + child_q =cvmx_pko_alloc_queues (node, level, res_owner,-1 ,1 ); + +if (child_q <0 ) { +printf ("ERROR: %s: allocating %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, child_q)); +return -1 ; + } + +/* Configre newly allocated queue */ + res =cvmx_pko3_sq_config_children (node, level, parent_q, + child_q,1 ,1 ); + +if (res <0 ) { +printf ("ERROR: %s: configuring %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, child_q)); +return -1 ; + } + +/* Prepare for next level */ + level =__cvmx_pko3_sq_lvl_next (level); + parent_q = child_q; + +/* Terminate loop on DQ level, it has special handling */ + }while (level !=CVMX_PKO_DESCR_QUEUES && + level !=CVMX_PKO_LEVEL_INVAL ); + +if (level !=CVMX_PKO_DESCR_QUEUES ) { +printf ("ERROR: %s: level sequence error\n" , __func__); +return -1 ; + } + +/* Reserve 'num_dq' DQ's at 0 by convention */ + res =cvmx_pko_alloc_queues (node, level, res_owner, dq, num_dq); +if (dq != res) { +debug ("%s: ERROR: could not reserve DQs\n" , __func__); +return -1 ; + } + + res =cvmx_pko3_sq_config_children (node, level, parent_q, dq, num_dq, + num_dq); +if (res <0 ) { +printf ("ERROR: %s: configuring %s\n" , __func__, +__cvmx_pko3_sq_str (b1, level, dq)); +return -1 ; + } + +/* NULL interface does not need to map to a CHAN_E */ + +/* register DQ/IPD translation */ + xiface =cvmx_helper_node_interface_to_xiface (node, __CVMX_XIFACE_NULL); +__cvmx_pko3_ipd_dq_register (xiface,0 , dq, num_dq); + +/* open the null DQs here */ +for (i =0 ; i < num_dq; i++) { +unsigned int limit =128 ;/* NULL never really uses much */ + +cvmx_pko_dq_open (node, dq + i); +cvmx_pko3_dq_set_limit (node, dq + i, limit); + } + +return 0 ; +} + +/** Open all descriptor queues belonging to an interface/port +* @INTERNAL +*/ +int __cvmx_pko3_helper_dqs_activate (int xiface,int index,bool min_pad) +{ +int ipd_port, dq_base, dq_count, i; +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +unsigned int limit; + +/* Get local IPD port for the interface */ + ipd_port =cvmx_helper_get_ipd_port (xiface, index); +if (ipd_port <0 ) { +printf ("ERROR: %s: No IPD port for interface %d port %d\n" , + __func__, xiface, index); +return -1 ; + } + +/* Get DQ# range for the IPD port */ + dq_base =cvmx_pko3_get_queue_base (ipd_port); + dq_count =cvmx_pko3_get_queue_num (ipd_port); +if (dq_base <0 || dq_count <=0 ) { +printf ("ERROR: %s: No descriptor queues for interface %d port %d\n" , + __func__, xiface, index); +return -1 ; + } + +/* Mask out node from global DQ# */ + dq_base &= (1 <<10 ) -1 ; + + limit = __pko_pkt_quota / dq_count / +cvmx_helper_interface_enumerate (xiface); + +for (i =0 ; i < dq_count; i++) { +/* FIXME: 2ms at 1Gbps max packet rate, make speed dependent */ +cvmx_pko_dq_open (xi.node, dq_base + i); +cvmx_pko3_dq_options (xi.node, dq_base + i, min_pad); + +if (debug) +debug ("%s: DQ%u limit %d\n" , __func__, dq_base + i, + limit); + +cvmx_pko3_dq_set_limit (xi.node, dq_base + i, limit); + __pko_pkt_budget -= limit; + } + +if (__pko_pkt_budget <0 ) +printf ("WARNING: %s: PKO buffer deficit %d\n" , __func__, + __pko_pkt_budget); +else if (debug) +debug ("%s: PKO remaining packet budget: %d\n" , __func__, + __pko_pkt_budget); + +return i; +} + +/** Configure and initialize PKO3 for an interface +* +* @param xiface is the interface number to configure +* @return 0 on success. +*/ +int cvmx_helper_pko3_init_interface (int xiface) +{ +cvmx_helper_interface_mode_t mode; +int node, iface, subif, num_ports; +bool fcs_enable, pad_enable, pad_enable_pko; +u8 fcs_sof_off =0 ; +u8 num_queues =1 ; +bool qos = false, pfc = false; +int res =-1 ; +cvmx_xiface_t xi =cvmx_helper_xiface_to_node_interface (xiface); + + node = xi.node; + iface = xi.interface; + mode =cvmx_helper_interface_get_mode (xiface); + num_ports =cvmx_helper_interface_enumerate (xiface); + subif =0 ; + +if ((unsigned int )iface < +NUM_ELEMENTS (__cvmx_pko_queue_static_config[node].pknd.pko_cfg_iface)) { + pfc = __cvmx_pko_queue_static_config[node] + .pknd.pko_cfg_iface[iface] + .pfc_enable; + num_queues = __cvmx_pko_queue_static_config[node] + .pknd.pko_cfg_iface[iface] + .queues_per_port; + qos = __cvmx_pko_queue_static_config[node] + .pknd.pko_cfg_iface[iface] + .qos_enable; + } + +/* Force 8 DQs per port for pass 1.0 to circumvent limitations */ +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_0 )) + num_queues =8 ; + +/* For ILK there is one IPD port per channel */ +if (mode ==CVMX_HELPER_INTERFACE_MODE_ILK ) + num_ports =__cvmx_helper_ilk_enumerate (xiface); + +/* Skip non-existent interfaces */ +if (num_ports <1 ) { +debug ("ERROR: %s: invalid iface %u:%u\n" , __func__, node, + iface); +return -1 ; + } + +if (mode ==CVMX_HELPER_INTERFACE_MODE_LOOP ) { + num_queues = __cvmx_pko_queue_static_config[node] + .pknd.pko_cfg_loop.queues_per_port; + qos = __cvmx_pko_queue_static_config[node] + .pknd.pko_cfg_loop.qos_enable; + +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_0 )) + num_queues =8 ; + + res =__cvmx_pko3_config_chan_interface (xiface, num_ports, + num_queues, qos); +if (res <0 ) + goto __cfg_error; + }else if (mode ==CVMX_HELPER_INTERFACE_MODE_NPI ) { + num_queues = __cvmx_pko_queue_static_config[node] + .pknd.pko_cfg_npi.queues_per_port; + qos = __cvmx_pko_queue_static_config[node] + .pknd.pko_cfg_npi.qos_enable; + +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_0 )) + num_queues =8 ; + + res =__cvmx_pko3_config_chan_interface (xiface, num_ports, + num_queues, qos); +if (res <0 ) + goto __cfg_error; + } +/* ILK-specific queue configuration */ +else if (mode ==CVMX_HELPER_INTERFACE_MODE_ILK ) { +unsigned int num_chans =__cvmx_helper_ilk_enumerate (xiface); + + num_queues =8 ; + qos = true; + pfc = false; + +if (num_chans >=128 ) + num_queues =1 ; +else if (num_chans >=64 ) + num_queues =2 ; +else if (num_chans >=32 ) + num_queues =4 ; +else + num_queues =8 ; + + res =__cvmx_pko3_config_chan_interface (xiface, num_chans, + num_queues, qos); + } +/* Setup all ethernet configured for PFC */ +else if (pfc) { +/* PFC interfaces have 8 prioritized queues */ +for (subif =0 ; subif < num_ports; subif++) { + res =__cvmx_pko3_config_pfc_interface (xiface, subif); +if (res <0 ) + goto __cfg_error; + +/* Enable PFC/CBFC on BGX */ +__cvmx_helper_bgx_xaui_config_pfc (node, iface, subif, + true); + } + }else { +/* All other interfaces follow static configuration */ +for (subif =0 ; subif < num_ports; subif++) { + res =__cvmx_pko3_config_gen_interface (xiface, subif, + num_queues, qos); +if (res <0 ) + goto __cfg_error; + } + } + + fcs_enable =__cvmx_helper_get_has_fcs (xiface); + pad_enable =__cvmx_helper_get_pko_padding (xiface); + +/* Do not use PKO PAD/FCS generation on o78p1.x on BGX interfaces */ +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_X )) + pad_enable_pko = false; +else + pad_enable_pko = pad_enable; + +if (debug) +debug ("%s: iface %u:%u FCS=%d pad=%d pko=%d\n" , __func__, node, + iface, fcs_enable, pad_enable, pad_enable_pko); + +/* Setup interface options */ +for (subif =0 ; subif < num_ports; subif++) { +/* Open interface/port DQs to allow transmission to begin */ + res =__cvmx_pko3_helper_dqs_activate (xiface, subif, + pad_enable_pko); + +if (res <0 ) + goto __cfg_error; + +/* ILK has only one MAC, subif == logical-channel */ +if (mode ==CVMX_HELPER_INTERFACE_MODE_ILK && subif >0 ) +continue ; + +/* LOOP has only one MAC, subif == logical-channel */ +if (mode ==CVMX_HELPER_INTERFACE_MODE_LOOP && subif >0 ) +continue ; + +/* NPI has only one MAC, subif == 'ring' */ +if (mode ==CVMX_HELPER_INTERFACE_MODE_NPI && subif >0 ) +continue ; + +/* for sRIO there is 16 byte sRIO header, outside of FCS */ +if (mode ==CVMX_HELPER_INTERFACE_MODE_SRIO ) + fcs_sof_off =16 ; + +if (iface >=CVMX_HELPER_MAX_GMX ) { +/* Non-BGX interface, use PKO for FCS/PAD */ + res =cvmx_pko3_interface_options (xiface, subif, + fcs_enable, + pad_enable_pko, + fcs_sof_off); + }else if (pad_enable == pad_enable_pko) { +/* BGX interface: FCS/PAD done by PKO */ + res =cvmx_pko3_interface_options (xiface, subif, + fcs_enable, + pad_enable, + fcs_sof_off); +cvmx_helper_bgx_tx_options (node, iface, subif, false, + false); + }else { +/* BGX interface: FCS/PAD done by BGX */ + res =cvmx_pko3_interface_options (xiface, subif, false, + false, fcs_sof_off); +cvmx_helper_bgx_tx_options (node, iface, subif, + fcs_enable, pad_enable); + } + +if (res <0 ) +debug ("WARNING: %s: option set failed on iface %u:%u/%u\n" , + __func__, node, iface, subif); +if (debug) +debug ("%s: face %u:%u/%u fifo size %d\n" , __func__, + node, iface, subif, +cvmx_pko3_port_fifo_size (xiface, subif)); + } +return 0 ; + +__cfg_error: +debug ("ERROR: %s: failed on iface %u:%u/%u\n" , __func__, node, iface, + subif); +return -1 ; +} + +/** +* Global initialization for PKO3 +* +* Should only be called once on each node +* +* TBD: Resolve the kernel case. +* When Linux eats up the entire memory, bootmem will be unable to +* satisfy our request, and the memory needs to come from Linux free pages. +*/ +int __cvmx_helper_pko3_init_global (unsigned int node,uint16_t gaura) +{ +int res; + + res =cvmx_pko3_hw_init_global (node, gaura); +if (res <0 ) { +debug ("ERROR: %s:failed block initialization\n" , __func__); +return res; + } + +/* configure channel level */ +cvmx_pko3_channel_credit_level (node, cvmx_pko_default_channel_level); + +/* add NULL MAC/DQ setup */ + res =__cvmx_pko3_config_null_interface (node); +if (res <0 ) +debug ("ERROR: %s: creating NULL interface\n" , __func__); + +return res; +} + +/** +* Global initialization for PKO3 +* +* Should only be called once on each node +* +* When Linux eats up the entire memory, bootmem will be unable to +* satisfy our request, and the memory needs to come from Linux free pages. +*/ +int cvmx_helper_pko3_init_global (unsigned int node) +{ +void *ptr; +int res =-1 ; +unsigned int aura_num = ~0 ; +cvmx_fpa3_gaura_t aura; + +/* Allocate memory required by PKO3 */ + res =__cvmx_pko3_config_memory (node); +if (res <0 ) { +debug ("ERROR: %s: PKO3 memory allocation error\n" , __func__); +return res; + } + + aura_num = res; + aura = __cvmx_pko3_aura[node]; + +/* Exercise the FPA to make sure the AURA is functional */ + ptr =cvmx_fpa3_alloc (aura); + +if (!ptr) { + res =-1 ; + }else { +cvmx_fpa3_free_nosync (ptr, aura,0 ); + res =0 ; + } + +if (res <0 ) { +debug ("ERROR: %s: FPA failure AURA=%u:%d\n" , __func__, + aura.node, aura.laura); +return -1 ; + } + + res =__cvmx_helper_pko3_init_global (node, aura_num); + +if (res <0 ) +debug ("ERROR: %s: failed to start PPKO\n" , __func__); + +return res; +}
Signature · 1 line
2.35.1
PATCH v2 20/52 mips: octeon: Add cvmx-helper-rgmii.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-helper-rgmii.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-helper-rgmii.c | 398 ++++++++++++++++++++++ 1 file changed, 398 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-helper-rgmii.c
arch/mips/mach-octeon/cvmx-helper-rgmii.c new file +398 -0
@@ -0,0 +1,398 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* Functions for RGMII/GMII/MII initialization, configuration, +* and monitoring. +*/ + +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> + +#include <mach/cvmx-hwpko.h> + +#include <mach/cvmx-asxx-defs.h> +#include <mach/cvmx-dbg-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-npi-defs.h> +#include <mach/cvmx-pko-defs.h> + +/** +* @INTERNAL +* Probe RGMII ports and determine the number present +* +* @param xiface Interface to probe +* +* @return Number of RGMII/GMII/MII ports (0-4). +*/ +int __cvmx_helper_rgmii_probe (int xiface) +{ +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int num_ports =0 ; +union cvmx_gmxx_inf_mode mode; + + mode.u64 =csr_rd (CVMX_GMXX_INF_MODE (xi.interface)); + +if (mode.s.type) +debug ("ERROR: Unsupported Octeon model in %s\n" , __func__); +else +debug ("ERROR: Unsupported Octeon model in %s\n" , __func__); +return num_ports; +} + +/** +* @INTERNAL +* Configure all of the ASX, GMX, and PKO regsiters required +* to get RGMII to function on the supplied interface. +* +* @param xiface PKO Interface to configure (0 or 1) +* +* @return Zero on success +*/ +int __cvmx_helper_rgmii_enable (int xiface) +{ +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface; +int num_ports =cvmx_helper_ports_on_interface (interface); +int port; +union cvmx_gmxx_inf_mode mode; +union cvmx_asxx_tx_prt_en asx_tx; +union cvmx_asxx_rx_prt_en asx_rx; + + mode.u64 =csr_rd (CVMX_GMXX_INF_MODE (interface)); + +if (num_ports ==-1 ) +return -1 ; +if (mode.s.en ==0 ) +return -1 ; + +/* Configure the ASX registers needed to use the RGMII ports */ + asx_tx.u64 =0 ; + asx_tx.s.prt_en =cvmx_build_mask (num_ports); +csr_wr (CVMX_ASXX_TX_PRT_EN (interface), asx_tx.u64); + + asx_rx.u64 =0 ; + asx_rx.s.prt_en =cvmx_build_mask (num_ports); +csr_wr (CVMX_ASXX_RX_PRT_EN (interface), asx_rx.u64); + +/* Configure the GMX registers needed to use the RGMII ports */ +for (port =0 ; port < num_ports; port++) { +/* +* Configure more flexible RGMII preamble +* checking. Pass 1 doesn't support this feature. +*/ +union cvmx_gmxx_rxx_frm_ctl frm_ctl; + + frm_ctl.u64 =csr_rd (CVMX_GMXX_RXX_FRM_CTL (port, interface)); +/* New field, so must be compile time */ + frm_ctl.s.pre_free =1 ; +csr_wr (CVMX_GMXX_RXX_FRM_CTL (port, interface), frm_ctl.u64); + +/* +* Each pause frame transmitted will ask for about 10M +* bit times before resume. If buffer space comes +* available before that time has expired, an XON +* pause frame (0 time) will be transmitted to restart +* the flow. +*/ +csr_wr (CVMX_GMXX_TXX_PAUSE_PKT_TIME (port, interface),20000 ); +csr_wr (CVMX_GMXX_TXX_PAUSE_PKT_INTERVAL (port, interface), +19000 ); + +csr_wr (CVMX_ASXX_TX_CLK_SETX (port, interface),24 ); +csr_wr (CVMX_ASXX_RX_CLK_SETX (port, interface),24 ); + } + +__cvmx_helper_setup_gmx (interface, num_ports); + +/* enable the ports now */ +for (port =0 ; port < num_ports; port++) { +union cvmx_gmxx_prtx_cfg gmx_cfg; + +cvmx_helper_link_autoconf ( +cvmx_helper_get_ipd_port (interface, port)); + gmx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (port, interface)); + gmx_cfg.s.en =1 ; +csr_wr (CVMX_GMXX_PRTX_CFG (port, interface), gmx_cfg.u64); + } +return 0 ; +} + +/** +* @INTERNAL +* Return the link state of an IPD/PKO port as returned by +* auto negotiation. The result of this function may not match +* Octeon's link config if auto negotiation has changed since +* the last call to cvmx_helper_link_set(). +* +* @param ipd_port IPD/PKO port to query +* +* @return Link state +*/ +cvmx_helper_link_info_t __cvmx_helper_rgmii_link_get (int ipd_port) +{ +int interface =cvmx_helper_get_interface_num (ipd_port); +int index =cvmx_helper_get_interface_index_num (ipd_port); +union cvmx_asxx_prt_loop asxx_prt_loop; + + asxx_prt_loop.u64 =csr_rd (CVMX_ASXX_PRT_LOOP (interface)); +if (asxx_prt_loop.s.int_loop & (1 << index)) { +/* Force 1Gbps full duplex on internal loopback */ +cvmx_helper_link_info_t result; + + result.u64 =0 ; + result.s.full_duplex =1 ; + result.s.link_up =1 ; + result.s.speed =1000 ; +return result; + }else { +return __cvmx_helper_board_link_get (ipd_port); + } +} + +/** +* @INTERNAL +* Return the link state of an IPD/PKO port as returned by +* auto negotiation. The result of this function may not match +* Octeon's link config if auto negotiation has changed since +* the last call to cvmx_helper_link_set(). +* +* @param ipd_port IPD/PKO port to query +* +* @return Link state +*/ +cvmx_helper_link_info_t __cvmx_helper_gmii_link_get (int ipd_port) +{ +cvmx_helper_link_info_t result; +int index =cvmx_helper_get_interface_index_num (ipd_port); + +if (index ==0 ) { + result =__cvmx_helper_rgmii_link_get (ipd_port); + }else { + result.s.full_duplex =1 ; + result.s.link_up =1 ; + result.s.speed =1000 ; + } + +return result; +} + +/** +* @INTERNAL +* Configure an IPD/PKO port for the specified link state. This +* function does not influence auto negotiation at the PHY level. +* The passed link state must always match the link state returned +* by cvmx_helper_link_get(). It is normally best to use +* cvmx_helper_link_autoconf() instead. +* +* @param ipd_port IPD/PKO port to configure +* @param link_info The new link state +* +* @return Zero on success, negative on failure +*/ +int __cvmx_helper_rgmii_link_set (int ipd_port, +cvmx_helper_link_info_t link_info) +{ +int result =0 ; +int interface =cvmx_helper_get_interface_num (ipd_port); +int index =cvmx_helper_get_interface_index_num (ipd_port); +union cvmx_gmxx_prtx_cfg original_gmx_cfg; +union cvmx_gmxx_prtx_cfg new_gmx_cfg; +union cvmx_pko_mem_queue_qos pko_mem_queue_qos; +union cvmx_pko_mem_queue_qos pko_mem_queue_qos_save[16 ]; +union cvmx_gmxx_tx_ovr_bp gmx_tx_ovr_bp; +union cvmx_gmxx_tx_ovr_bp gmx_tx_ovr_bp_save; +int i; + +/* Read the current settings so we know the current enable state */ + original_gmx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + new_gmx_cfg = original_gmx_cfg; + +/* Disable the lowest level RX */ +csr_wr (CVMX_ASXX_RX_PRT_EN (interface), +csr_rd (CVMX_ASXX_RX_PRT_EN (interface)) & ~(1 << index)); + +memset (pko_mem_queue_qos_save,0 ,sizeof (pko_mem_queue_qos_save)); +/* Disable all queues so that TX should become idle */ +for (i =0 ; i <cvmx_pko_get_num_queues (ipd_port); i++) { +int queue =cvmx_pko_get_base_queue (ipd_port) + i; + +csr_wr (CVMX_PKO_REG_READ_IDX , queue); + pko_mem_queue_qos.u64 =csr_rd (CVMX_PKO_MEM_QUEUE_QOS ); + pko_mem_queue_qos.s.pid = ipd_port; + pko_mem_queue_qos.s.qid = queue; + pko_mem_queue_qos_save[i] = pko_mem_queue_qos; + pko_mem_queue_qos.s.qos_mask =0 ; +csr_wr (CVMX_PKO_MEM_QUEUE_QOS , pko_mem_queue_qos.u64); + } + +/* Disable backpressure */ + gmx_tx_ovr_bp.u64 =csr_rd (CVMX_GMXX_TX_OVR_BP (interface)); + gmx_tx_ovr_bp_save = gmx_tx_ovr_bp; + gmx_tx_ovr_bp.s.bp &= ~(1 << index); + gmx_tx_ovr_bp.s.en |=1 << index; +csr_wr (CVMX_GMXX_TX_OVR_BP (interface), gmx_tx_ovr_bp.u64); +csr_rd (CVMX_GMXX_TX_OVR_BP (interface)); + +/* +* Poll the GMX state machine waiting for it to become +* idle. Preferably we should only change speed when it is +* idle. If it doesn't become idle we will still do the speed +* change, but there is a slight chance that GMX will +* lockup. +*/ +csr_wr (CVMX_NPI_DBG_SELECT , interface *0x800 + index *0x100 +0x880 ); + CVMX_WAIT_FOR_FIELD64(CVMX_DBG_DATA, cvmx_dbg_data_t, data & 7, ==, 0, +10000 ); + CVMX_WAIT_FOR_FIELD64(CVMX_DBG_DATA, cvmx_dbg_data_t, data & 0xf, ==, 0, +10000 ); + +/* Disable the port before we make any changes */ + new_gmx_cfg.s.en =0 ; +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), new_gmx_cfg.u64); +csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + +/* Set full/half duplex */ +if (!link_info.s.link_up) +/* Force full duplex on down links */ + new_gmx_cfg.s.duplex =1 ; +else + new_gmx_cfg.s.duplex = link_info.s.full_duplex; + +/* Set the link speed. Anything unknown is set to 1Gbps */ +if (link_info.s.speed ==10 ) { + new_gmx_cfg.s.slottime =0 ; + new_gmx_cfg.s.speed =0 ; + }else if (link_info.s.speed ==100 ) { + new_gmx_cfg.s.slottime =0 ; + new_gmx_cfg.s.speed =0 ; + }else { + new_gmx_cfg.s.slottime =1 ; + new_gmx_cfg.s.speed =1 ; + } + +/* Adjust the clocks */ +if (link_info.s.speed ==10 ) { +csr_wr (CVMX_GMXX_TXX_CLK (index, interface),50 ); +csr_wr (CVMX_GMXX_TXX_SLOT (index, interface),0x40 ); +csr_wr (CVMX_GMXX_TXX_BURST (index, interface),0 ); + }else if (link_info.s.speed ==100 ) { +csr_wr (CVMX_GMXX_TXX_CLK (index, interface),5 ); +csr_wr (CVMX_GMXX_TXX_SLOT (index, interface),0x40 ); +csr_wr (CVMX_GMXX_TXX_BURST (index, interface),0 ); + }else { +csr_wr (CVMX_GMXX_TXX_CLK (index, interface),1 ); +csr_wr (CVMX_GMXX_TXX_SLOT (index, interface),0x200 ); +csr_wr (CVMX_GMXX_TXX_BURST (index, interface),0x2000 ); + } + +/* Do a read to make sure all setup stuff is complete */ +csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + +/* Save the new GMX setting without enabling the port */ +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), new_gmx_cfg.u64); + +/* Enable the lowest level RX */ +if (link_info.s.link_up) +csr_wr (CVMX_ASXX_RX_PRT_EN (interface), +csr_rd (CVMX_ASXX_RX_PRT_EN (interface)) | (1 << index)); + +/* Re-enable the TX path */ +for (i =0 ; i <cvmx_pko_get_num_queues (ipd_port); i++) { +int queue =cvmx_pko_get_base_queue (ipd_port) + i; + +csr_wr (CVMX_PKO_REG_READ_IDX , queue); +csr_wr (CVMX_PKO_MEM_QUEUE_QOS , pko_mem_queue_qos_save[i].u64); + } + +/* Restore backpressure */ +csr_wr (CVMX_GMXX_TX_OVR_BP (interface), gmx_tx_ovr_bp_save.u64); + +/* Restore the GMX enable state. Port config is complete */ + new_gmx_cfg.s.en = original_gmx_cfg.s.en; +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), new_gmx_cfg.u64); + +return result; +} + +/** +* @INTERNAL +* Configure a port for internal and/or external loopback. Internal loopback +* causes packets sent by the port to be received by Octeon. External loopback +* causes packets received from the wire to sent out again. +* +* @param ipd_port IPD/PKO port to loopback. +* @param enable_internal +* Non zero if you want internal loopback +* @param enable_external +* Non zero if you want external loopback +* +* @return Zero on success, negative on failure. +*/ +int __cvmx_helper_rgmii_configure_loopback (int ipd_port,int enable_internal, +int enable_external) +{ +int interface =cvmx_helper_get_interface_num (ipd_port); +int index =cvmx_helper_get_interface_index_num (ipd_port); +int original_enable; +union cvmx_gmxx_prtx_cfg gmx_cfg; +union cvmx_asxx_prt_loop asxx_prt_loop; + +/* Read the current enable state and save it */ + gmx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + original_enable = gmx_cfg.s.en; +/* Force port to be disabled */ + gmx_cfg.s.en =0 ; +if (enable_internal) { +/* Force speed if we're doing internal loopback */ + gmx_cfg.s.duplex =1 ; + gmx_cfg.s.slottime =1 ; + gmx_cfg.s.speed =1 ; +csr_wr (CVMX_GMXX_TXX_CLK (index, interface),1 ); +csr_wr (CVMX_GMXX_TXX_SLOT (index, interface),0x200 ); +csr_wr (CVMX_GMXX_TXX_BURST (index, interface),0x2000 ); + } +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), gmx_cfg.u64); + +/* Set the loopback bits */ + asxx_prt_loop.u64 =csr_rd (CVMX_ASXX_PRT_LOOP (interface)); +if (enable_internal) + asxx_prt_loop.s.int_loop |=1 << index; +else + asxx_prt_loop.s.int_loop &= ~(1 << index); +if (enable_external) + asxx_prt_loop.s.ext_loop |=1 << index; +else + asxx_prt_loop.s.ext_loop &= ~(1 << index); +csr_wr (CVMX_ASXX_PRT_LOOP (interface), asxx_prt_loop.u64); + +/* Force enables in internal loopback */ +if (enable_internal) { +u64 tmp; + + tmp =csr_rd (CVMX_ASXX_TX_PRT_EN (interface)); +csr_wr (CVMX_ASXX_TX_PRT_EN (interface), (1 << index) | tmp); + tmp =csr_rd (CVMX_ASXX_RX_PRT_EN (interface)); +csr_wr (CVMX_ASXX_RX_PRT_EN (interface), (1 << index) | tmp); + original_enable =1 ; + } + +/* Restore the enable state */ + gmx_cfg.s.en = original_enable; +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), gmx_cfg.u64); +return 0 ; +}
Signature · 1 line
2.35.1
PATCH v2 21/52 mips: octeon: Add cvmx-helper-sgmii.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-helper-sgmii.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-helper-sgmii.c | 781 ++++++++++++++++++++++ 1 file changed, 781 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-helper-sgmii.c
arch/mips/mach-octeon/cvmx-helper-sgmii.c new file +781 -0
@@ -0,0 +1,781 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* Functions for SGMII initialization, configuration, +* and monitoring. +*/ + +#include <time.h> +#include <log.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +/** +* @INTERNAL +* Perform initialization required only once for an SGMII port. +* +* @param interface to init +* @param index Index of prot on the interface +* +* @return Zero on success, negative on failure +*/ +static int __cvmx_helper_sgmii_hardware_init_one_time (int interface,int index) +{ +const u64 clock_mhz =1200 ;/* todo: fixme */ +union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg; +union cvmx_pcsx_linkx_timer_count_reg pcsx_linkx_timer_count_reg; +union cvmx_gmxx_prtx_cfg gmxx_prtx_cfg; + +if (!cvmx_helper_is_port_valid (interface, index)) +return 0 ; + +/* Disable GMX */ + gmxx_prtx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + gmxx_prtx_cfg.s.en =0 ; +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), gmxx_prtx_cfg.u64); + +/* +* Write PCS*_LINK*_TIMER_COUNT_REG[COUNT] with the +* appropriate value. 1000BASE-X specifies a 10ms +* interval. SGMII specifies a 1.6ms interval. +*/ + pcsx_miscx_ctl_reg.u64 = +csr_rd (CVMX_PCSX_MISCX_CTL_REG (index, interface)); +/* Adjust the MAC mode if requested by device tree */ + pcsx_miscx_ctl_reg.s.mac_phy = +cvmx_helper_get_mac_phy_mode (interface, index); + pcsx_miscx_ctl_reg.s.mode = +cvmx_helper_get_1000x_mode (interface, index); +csr_wr (CVMX_PCSX_MISCX_CTL_REG (index, interface), + pcsx_miscx_ctl_reg.u64); + + pcsx_linkx_timer_count_reg.u64 = +csr_rd (CVMX_PCSX_LINKX_TIMER_COUNT_REG (index, interface)); +if (pcsx_miscx_ctl_reg.s.mode) +/* 1000BASE-X */ + pcsx_linkx_timer_count_reg.s.count = + (10000ull * clock_mhz) >>10 ; +else +/* SGMII */ + pcsx_linkx_timer_count_reg.s.count = + (1600ull * clock_mhz) >>10 ; + +csr_wr (CVMX_PCSX_LINKX_TIMER_COUNT_REG (index, interface), + pcsx_linkx_timer_count_reg.u64); + +/* +* Write the advertisement register to be used as the +* tx_Config_Reg<D15:D0> of the autonegotiation. In +* 1000BASE-X mode, tx_Config_Reg<D15:D0> is PCS*_AN*_ADV_REG. +* In SGMII PHY mode, tx_Config_Reg<D15:D0> is +* PCS*_SGM*_AN_ADV_REG. In SGMII MAC mode, +* tx_Config_Reg<D15:D0> is the fixed value 0x4001, so this +* step can be skipped. +*/ +if (pcsx_miscx_ctl_reg.s.mode) { +/* 1000BASE-X */ +union cvmx_pcsx_anx_adv_reg pcsx_anx_adv_reg; + + pcsx_anx_adv_reg.u64 = +csr_rd (CVMX_PCSX_ANX_ADV_REG (index, interface)); + pcsx_anx_adv_reg.s.rem_flt =0 ; + pcsx_anx_adv_reg.s.pause =3 ; + pcsx_anx_adv_reg.s.hfd =1 ; + pcsx_anx_adv_reg.s.fd =1 ; +csr_wr (CVMX_PCSX_ANX_ADV_REG (index, interface), + pcsx_anx_adv_reg.u64); + }else { +if (pcsx_miscx_ctl_reg.s.mac_phy) { +/* PHY Mode */ +union cvmx_pcsx_sgmx_an_adv_reg pcsx_sgmx_an_adv_reg; + + pcsx_sgmx_an_adv_reg.u64 =csr_rd ( +CVMX_PCSX_SGMX_AN_ADV_REG (index, interface)); + pcsx_sgmx_an_adv_reg.s.dup =1 ; + pcsx_sgmx_an_adv_reg.s.speed =2 ; +csr_wr (CVMX_PCSX_SGMX_AN_ADV_REG (index, interface), + pcsx_sgmx_an_adv_reg.u64); + }else { +/* MAC Mode - Nothing to do */ + } + } +return 0 ; +} + +static int __cvmx_helper_need_g15618 (void ) +{ +if (OCTEON_IS_MODEL (OCTEON_CN63XX ) || +OCTEON_IS_MODEL (OCTEON_CN66XX_PASS1_X ) || +OCTEON_IS_MODEL (OCTEON_CN68XX )) +return 1 ; +else +return 0 ; +} + +/** +* @INTERNAL +* Initialize the SERTES link for the first time or after a loss +* of link. +* +* @param interface to init +* @param index Index of prot on the interface +* +* @return Zero on success, negative on failure +*/ +static int __cvmx_helper_sgmii_hardware_init_link (int interface,int index) +{ +union cvmx_pcsx_mrx_control_reg control_reg; +union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg; +bool phy_mode; +bool an_disable;/** Disable autonegotiation */ +bool mode_1000x;/** 1000Base-X mode */ + +if (!cvmx_helper_is_port_valid (interface, index)) +return 0 ; + +/* +* Take PCS through a reset sequence. +* PCS*_MR*_CONTROL_REG[PWR_DN] should be cleared to zero. +* Write PCS*_MR*_CONTROL_REG[RESET]=1 (while not changing the +* value of the other PCS*_MR*_CONTROL_REG bits). Read +* PCS*_MR*_CONTROL_REG[RESET] until it changes value to +* zero. +*/ + control_reg.u64 =csr_rd (CVMX_PCSX_MRX_CONTROL_REG (index, interface)); + +/* +* Errata G-15618 requires disabling PCS soft reset in CN63XX +* pass upto 2.1. +*/ +if (!__cvmx_helper_need_g15618 ()) { + control_reg.s.reset =1 ; +csr_wr (CVMX_PCSX_MRX_CONTROL_REG (index, interface), + control_reg.u64); +if (CVMX_WAIT_FOR_FIELD64 ( +CVMX_PCSX_MRX_CONTROL_REG (index, interface), + cvmx_pcsx_mrx_control_reg_t, reset, ==, 0, 10000)) { +debug ("SGMII%x: Timeout waiting for port %d to finish reset\n" , + interface, index); +return -1 ; + } + } + +/* +* Write PCS*_MR*_CONTROL_REG[RST_AN]=1 to ensure a fresh +* sgmii negotiation starts. +*/ + phy_mode =cvmx_helper_get_mac_phy_mode (interface, index); + an_disable = (phy_mode || + !cvmx_helper_get_port_autonegotiation (interface, index)); + + control_reg.s.an_en = !an_disable; + +/* Force a PCS reset by powering down the PCS interface +* This is needed to deal with broken Qualcomm/Atheros PHYs and switches +* which never recover if PCS is not power cycled. The alternative +* is to power cycle or hardware reset the Qualcomm devices whenever +* SGMII is initialized. +* +* This is needed for the QCA8033 PHYs as well as the QCA833X switches +* to work. The QCA8337 switch has additional SGMII problems and is +* best avoided if at all possible. Failure to power cycle PCS prevents +* any traffic from flowing between Octeon and Qualcomm devices if there +* is a warm reset. Even a software reset to the Qualcomm device will +* not work. +* +* Note that this problem has been reported between Qualcomm and other +* vendor's processors as well so this problem is not unique to +* Qualcomm and Octeon. +* +* Power cycling PCS doesn't hurt anything with non-Qualcomm devices +* other than adding a 25ms delay during initialization. +*/ + control_reg.s.pwr_dn =1 ; +csr_wr (CVMX_PCSX_MRX_CONTROL_REG (index, interface), control_reg.u64); +csr_rd (CVMX_PCSX_MRX_CONTROL_REG (index, interface)); + +/* 25ms should be enough, 10ms is too short */ +mdelay (25 ); + + control_reg.s.pwr_dn =0 ; +csr_wr (CVMX_PCSX_MRX_CONTROL_REG (index, interface), control_reg.u64); + +/* The Cortina PHY runs in 1000base-X mode */ + mode_1000x =cvmx_helper_get_1000x_mode (interface, index); + pcsx_miscx_ctl_reg.u64 = +csr_rd (CVMX_PCSX_MISCX_CTL_REG (index, interface)); + pcsx_miscx_ctl_reg.s.mode = mode_1000x; + pcsx_miscx_ctl_reg.s.mac_phy = phy_mode; +csr_wr (CVMX_PCSX_MISCX_CTL_REG (index, interface), + pcsx_miscx_ctl_reg.u64); +if (an_disable) +/* In PHY mode we can't query the link status so we just +* assume that the link is up. +*/ +return 0 ; + +/* +* Wait for PCS*_MR*_STATUS_REG[AN_CPT] to be set, indicating +* that sgmii autonegotiation is complete. In MAC mode this +* isn't an ethernet link, but a link between Octeon and the +* PHY. +*/ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_PCSX_MRX_STATUS_REG (index, interface), + union cvmx_pcsx_mrx_status_reg, an_cpt, ==, 1, +10000 )) { +debug ("SGMII%x: Port %d link timeout\n" , interface, index); +return -1 ; + } +return 0 ; +} + +/** +* @INTERNAL +* Configure an SGMII link to the specified speed after the SERTES +* link is up. +* +* @param interface to init +* @param index Index of prot on the interface +* @param link_info Link state to configure +* +* @return Zero on success, negative on failure +*/ +static int +__cvmx_helper_sgmii_hardware_init_link_speed (int interface,int index, +cvmx_helper_link_info_t link_info) +{ +int is_enabled; +union cvmx_gmxx_prtx_cfg gmxx_prtx_cfg; +union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg; + +if (!cvmx_helper_is_port_valid (interface, index)) +return 0 ; + +/* Disable GMX before we make any changes. Remember the enable state */ + gmxx_prtx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + is_enabled = gmxx_prtx_cfg.s.en; + gmxx_prtx_cfg.s.en =0 ; +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), gmxx_prtx_cfg.u64); + +/* Wait for GMX to be idle */ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_GMXX_PRTX_CFG (index, interface), + cvmx_gmxx_prtx_cfg_t, rx_idle, ==, 1, +10000 ) || +CVMX_WAIT_FOR_FIELD64 (CVMX_GMXX_PRTX_CFG (index, interface), + cvmx_gmxx_prtx_cfg_t, tx_idle, ==, 1, +10000 )) { +debug ("SGMII%d: Timeout waiting for port %d to be idle\n" , + interface, index); +return -1 ; + } + +/* Read GMX CFG again to make sure the disable completed */ + gmxx_prtx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + +/* +* Get the misc control for PCS. We will need to set the +* duplication amount. +*/ + pcsx_miscx_ctl_reg.u64 = +csr_rd (CVMX_PCSX_MISCX_CTL_REG (index, interface)); + +/* +* Use GMXENO to force the link down if the status we get says +* it should be down. +*/ + pcsx_miscx_ctl_reg.s.gmxeno = !link_info.s.link_up; + +/* Only change the duplex setting if the link is up */ +if (link_info.s.link_up) + gmxx_prtx_cfg.s.duplex = link_info.s.full_duplex; + +/* Do speed based setting for GMX */ +switch (link_info.s.speed) { +case 10 : + gmxx_prtx_cfg.s.speed =0 ; + gmxx_prtx_cfg.s.speed_msb =1 ; + gmxx_prtx_cfg.s.slottime =0 ; +/* Setting from GMX-603 */ + pcsx_miscx_ctl_reg.s.samp_pt =25 ; +csr_wr (CVMX_GMXX_TXX_SLOT (index, interface),64 ); +csr_wr (CVMX_GMXX_TXX_BURST (index, interface),0 ); +break ; +case 100 : + gmxx_prtx_cfg.s.speed =0 ; + gmxx_prtx_cfg.s.speed_msb =0 ; + gmxx_prtx_cfg.s.slottime =0 ; + pcsx_miscx_ctl_reg.s.samp_pt =0x5 ; +csr_wr (CVMX_GMXX_TXX_SLOT (index, interface),64 ); +csr_wr (CVMX_GMXX_TXX_BURST (index, interface),0 ); +break ; +case 1000 : + gmxx_prtx_cfg.s.speed =1 ; + gmxx_prtx_cfg.s.speed_msb =0 ; + gmxx_prtx_cfg.s.slottime =1 ; + pcsx_miscx_ctl_reg.s.samp_pt =1 ; +csr_wr (CVMX_GMXX_TXX_SLOT (index, interface),512 ); +if (gmxx_prtx_cfg.s.duplex) +/* full duplex */ +csr_wr (CVMX_GMXX_TXX_BURST (index, interface),0 ); +else +/* half duplex */ +csr_wr (CVMX_GMXX_TXX_BURST (index, interface),8192 ); +break ; +default : +break ; + } + +/* Write the new misc control for PCS */ +csr_wr (CVMX_PCSX_MISCX_CTL_REG (index, interface), + pcsx_miscx_ctl_reg.u64); + +/* Write the new GMX settings with the port still disabled */ +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), gmxx_prtx_cfg.u64); + +/* Read GMX CFG again to make sure the config completed */ + gmxx_prtx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + +/* Restore the enabled / disabled state */ + gmxx_prtx_cfg.s.en = is_enabled; +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), gmxx_prtx_cfg.u64); + +return 0 ; +} + +/** +* @INTERNAL +* Bring up the SGMII interface to be ready for packet I/O but +* leave I/O disabled using the GMX override. This function +* follows the bringup documented in 10.6.3 of the manual. +* +* @param interface to bringup +* @param num_ports Number of ports on the interface +* +* @return Zero on success, negative on failure +*/ +static int __cvmx_helper_sgmii_hardware_init (int interface,int num_ports) +{ +int index; +int do_link_set =1 ; + +/* +* CN63XX Pass 1.0 errata G-14395 requires the QLM De-emphasis +* be programmed. +*/ +if (OCTEON_IS_MODEL (OCTEON_CN63XX_PASS1_0 )) { +union cvmx_ciu_qlm2 ciu_qlm; + + ciu_qlm.u64 =csr_rd (CVMX_CIU_QLM2 ); + ciu_qlm.s.txbypass =1 ; + ciu_qlm.s.txdeemph =0xf ; + ciu_qlm.s.txmargin =0xd ; +csr_wr (CVMX_CIU_QLM2 , ciu_qlm.u64); + } + +/* +* CN63XX Pass 2.x errata G-15273 requires the QLM De-emphasis +* be programmed when using a 156.25Mhz ref clock. +*/ +if (OCTEON_IS_MODEL (OCTEON_CN63XX_PASS2_X )) { +/* Read the QLM speed pins */ +union cvmx_mio_rst_boot mio_rst_boot; + + mio_rst_boot.u64 =csr_rd (CVMX_MIO_RST_BOOT ); + +if (mio_rst_boot.cn63xx.qlm2_spd ==4 ) { +union cvmx_ciu_qlm2 ciu_qlm; + + ciu_qlm.u64 =csr_rd (CVMX_CIU_QLM2 ); + ciu_qlm.s.txbypass =1 ; + ciu_qlm.s.txdeemph =0x0 ; + ciu_qlm.s.txmargin =0xf ; +csr_wr (CVMX_CIU_QLM2 , ciu_qlm.u64); + } + } + +__cvmx_helper_setup_gmx (interface, num_ports); + +for (index =0 ; index < num_ports; index++) { +int ipd_port =cvmx_helper_get_ipd_port (interface, index); + +if (!cvmx_helper_is_port_valid (interface, index)) +continue ; +__cvmx_helper_sgmii_hardware_init_one_time (interface, index); +if (do_link_set) +__cvmx_helper_sgmii_link_set (ipd_port, +__cvmx_helper_sgmii_link_get (ipd_port)); + } + +return 0 ; +} + +int __cvmx_helper_sgmii_enumerate (int xiface) +{ +if (OCTEON_IS_MODEL (OCTEON_CNF71XX )) +return 2 ; +if (OCTEON_IS_MODEL (OCTEON_CN70XX )) { +struct cvmx_xiface xi = +cvmx_helper_xiface_to_node_interface (xiface); +enum cvmx_qlm_mode qlm_mode = +cvmx_qlm_get_dlm_mode (0 , xi.interface); + +if (qlm_mode ==CVMX_QLM_MODE_SGMII ) +return 1 ; +else if (qlm_mode ==CVMX_QLM_MODE_QSGMII ) +return 4 ; +return 0 ; + } +return 4 ; +} + +/** +* @INTERNAL +* Probe a SGMII interface and determine the number of ports +* connected to it. The SGMII interface should still be down after +* this call. +* +* @param xiface Interface to probe +* +* @return Number of ports on the interface. Zero to disable. +*/ +int __cvmx_helper_sgmii_probe (int xiface) +{ +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface; +union cvmx_gmxx_inf_mode mode; +int ports; + +/* +* Check if QLM is configured correct for SGMII, verify the +* speed as well as mode. +*/ +if (OCTEON_IS_OCTEON2 ()) { +int qlm =cvmx_qlm_interface (xiface); + +if (cvmx_qlm_get_mode (qlm) !=CVMX_QLM_MODE_SGMII ) +return 0 ; + } + +/* Do not enable the interface if is not in SGMII mode */ + ports =__cvmx_helper_sgmii_enumerate (xiface); + +if (ports <=0 ) +return 0 ; + +/* +* Due to errata GMX-700 on CN56XXp1.x and CN52XXp1.x, the +* interface needs to be enabled before IPD otherwise per port +* backpressure may not work properly. +*/ + mode.u64 =csr_rd (CVMX_GMXX_INF_MODE (interface)); + mode.s.en =1 ; +csr_wr (CVMX_GMXX_INF_MODE (interface), mode.u64); + +return ports; +} + +/** +* @INTERNAL +* Bringup and enable a SGMII interface. After this call packet +* I/O should be fully functional. This is called with IPD +* enabled but PKO disabled. +* +* @param xiface Interface to bring up +* +* @return Zero on success, negative on failure +*/ +int __cvmx_helper_sgmii_enable (int xiface) +{ +int num_ports =cvmx_helper_ports_on_interface (xiface); +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface; +int index; + +/* Setup PKND and BPID */ +if (octeon_has_feature (OCTEON_FEATURE_PKND )) { +for (index =0 ; index < num_ports; index++) { +union cvmx_gmxx_bpid_msk bpid_msk; +union cvmx_gmxx_bpid_mapx bpid_map; +union cvmx_gmxx_prtx_cfg gmxx_prtx_cfg; + +if (!cvmx_helper_is_port_valid (interface, index)) +continue ; +/* Setup PKIND */ + gmxx_prtx_cfg.u64 = +csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + gmxx_prtx_cfg.s.pknd = +cvmx_helper_get_pknd (interface, index); +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), + gmxx_prtx_cfg.u64); + +/* Setup BPID */ + bpid_map.u64 = +csr_rd (CVMX_GMXX_BPID_MAPX (index, interface)); + bpid_map.s.val =1 ; + bpid_map.s.bpid = +cvmx_helper_get_bpid (interface, index); +csr_wr (CVMX_GMXX_BPID_MAPX (index, interface), + bpid_map.u64); + + bpid_msk.u64 =csr_rd (CVMX_GMXX_BPID_MSK (interface)); + bpid_msk.s.msk_or |= (1 << index); + bpid_msk.s.msk_and &= ~(1 << index); +csr_wr (CVMX_GMXX_BPID_MSK (interface), bpid_msk.u64); + } + } + +__cvmx_helper_sgmii_hardware_init (interface, num_ports); + +/* CN68XX adds the padding and FCS in PKO, not GMX */ +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +union cvmx_gmxx_txx_append gmxx_txx_append_cfg; + +for (index =0 ; index < num_ports; index++) { +if (!cvmx_helper_is_port_valid (interface, index)) +continue ; + gmxx_txx_append_cfg.u64 = +csr_rd (CVMX_GMXX_TXX_APPEND (index, interface)); + gmxx_txx_append_cfg.s.fcs =0 ; + gmxx_txx_append_cfg.s.pad =0 ; +csr_wr (CVMX_GMXX_TXX_APPEND (index, interface), + gmxx_txx_append_cfg.u64); + } + } + +/* Enable running disparity check for QSGMII interface */ +if (OCTEON_IS_MODEL (OCTEON_CN70XX ) && num_ports >1 ) { +union cvmx_gmxx_qsgmii_ctl qsgmii_ctl; + + qsgmii_ctl.u64 =0 ; + qsgmii_ctl.s.disparity =1 ; +csr_wr (CVMX_GMXX_QSGMII_CTL (interface), qsgmii_ctl.u64); + } + +for (index =0 ; index < num_ports; index++) { +union cvmx_gmxx_txx_append append_cfg; +union cvmx_gmxx_txx_sgmii_ctl sgmii_ctl; +union cvmx_gmxx_prtx_cfg gmxx_prtx_cfg; + +if (!cvmx_helper_is_port_valid (interface, index)) +continue ; +/* +* Clear the align bit if preamble is set to attain +* maximum tx rate. +*/ + append_cfg.u64 =csr_rd (CVMX_GMXX_TXX_APPEND (index, interface)); + sgmii_ctl.u64 = +csr_rd (CVMX_GMXX_TXX_SGMII_CTL (index, interface)); + sgmii_ctl.s.align = append_cfg.s.preamble ?0 :1 ; +csr_wr (CVMX_GMXX_TXX_SGMII_CTL (index, interface), + sgmii_ctl.u64); + + gmxx_prtx_cfg.u64 = +csr_rd (CVMX_GMXX_PRTX_CFG (index, interface)); + gmxx_prtx_cfg.s.en =1 ; +csr_wr (CVMX_GMXX_PRTX_CFG (index, interface), gmxx_prtx_cfg.u64); + } +return 0 ; +} + +/** +* @INTERNAL +* Return the link state of an IPD/PKO port as returned by +* auto negotiation. The result of this function may not match +* Octeon's link config if auto negotiation has changed since +* the last call to cvmx_helper_link_set(). +* +* @param ipd_port IPD/PKO port to query +* +* @return Link state +*/ +cvmx_helper_link_info_t __cvmx_helper_sgmii_link_get (int ipd_port) +{ +cvmx_helper_link_info_t result; +union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg; +int interface =cvmx_helper_get_interface_num (ipd_port); +int index =cvmx_helper_get_interface_index_num (ipd_port); +union cvmx_pcsx_mrx_control_reg pcsx_mrx_control_reg; +int speed =1000 ; +int qlm; + + result.u64 =0 ; + +if (!cvmx_helper_is_port_valid (interface, index)) +return result; + +if (OCTEON_IS_MODEL (OCTEON_CN66XX )) { +union cvmx_gmxx_inf_mode inf_mode; + + inf_mode.u64 =csr_rd (CVMX_GMXX_INF_MODE (interface)); +if (inf_mode.s.rate & (1 << index)) + speed =2500 ; +else + speed =1000 ; + }else if (OCTEON_IS_MODEL (OCTEON_CN6XXX )) { + qlm =cvmx_qlm_interface (interface); + speed =cvmx_qlm_get_gbaud_mhz (qlm) *8 /10 ; + }else if (OCTEON_IS_MODEL (OCTEON_CNF71XX )) { + speed =cvmx_qlm_get_gbaud_mhz (0 ) *8 /10 ; + }else if (OCTEON_IS_MODEL (OCTEON_CN70XX )) { + speed =cvmx_qlm_get_gbaud_mhz (0 ) *8 /10 ; +if (cvmx_qlm_get_dlm_mode (0 , interface) ==CVMX_QLM_MODE_SGMII ) + speed >>=1 ; +else + speed >>=2 ; + } + + pcsx_mrx_control_reg.u64 = +csr_rd (CVMX_PCSX_MRX_CONTROL_REG (index, interface)); +if (pcsx_mrx_control_reg.s.loopbck1) { +/* Force 1Gbps full duplex link for internal loopback */ + result.s.link_up =1 ; + result.s.full_duplex =1 ; + result.s.speed = speed; +return result; + } + + pcsx_miscx_ctl_reg.u64 = +csr_rd (CVMX_PCSX_MISCX_CTL_REG (index, interface)); +if (pcsx_miscx_ctl_reg.s.mac_phy || +cvmx_helper_get_port_force_link_up (interface, index)) { +/* PHY Mode */ +/* Note that this also works for 1000base-X mode */ + + result.s.speed = speed; + result.s.full_duplex =1 ; + result.s.link_up =1 ; +return result; + } + +/* MAC Mode */ +return __cvmx_helper_board_link_get (ipd_port); +} + +/** +* @INTERNAL +* Configure an IPD/PKO port for the specified link state. This +* function does not influence auto negotiation at the PHY level. +* The passed link state must always match the link state returned +* by cvmx_helper_link_get(). It is normally best to use +* cvmx_helper_link_autoconf() instead. +* +* @param ipd_port IPD/PKO port to configure +* @param link_info The new link state +* +* @return Zero on success, negative on failure +*/ +int __cvmx_helper_sgmii_link_set (int ipd_port, +cvmx_helper_link_info_t link_info) +{ +union cvmx_pcsx_mrx_control_reg control_reg; +int interface =cvmx_helper_get_interface_num (ipd_port); +int index =cvmx_helper_get_interface_index_num (ipd_port); + +if (!cvmx_helper_is_port_valid (interface, index)) +return 0 ; + +/* For some devices, i.e. the Qualcomm QCA8337 switch we need to power +* down the PCS interface when the link goes down and power it back +* up when the link returns. +*/ +if (link_info.s.link_up || !__cvmx_helper_need_g15618 ()) { +__cvmx_helper_sgmii_hardware_init_link (interface, index); + }else { +union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg; + + pcsx_miscx_ctl_reg.u64 = +csr_rd (CVMX_PCSX_MISCX_CTL_REG (index, interface)); + +/* Disable autonegotiation when MAC mode is enabled or +* autonegotiation is disabled. +*/ + control_reg.u64 = +csr_rd (CVMX_PCSX_MRX_CONTROL_REG (index, interface)); +if (pcsx_miscx_ctl_reg.s.mac_phy ==0 || + !cvmx_helper_get_port_autonegotiation (interface, index)) { + control_reg.s.an_en =0 ; + control_reg.s.spdmsb =1 ; + control_reg.s.spdlsb =0 ; + control_reg.s.dup =1 ; + } +csr_wr (CVMX_PCSX_MRX_CONTROL_REG (index, interface), + control_reg.u64); +csr_rd (CVMX_PCSX_MRX_CONTROL_REG (index, interface)); +/* +* Use GMXENO to force the link down it will get +* reenabled later... +*/ + pcsx_miscx_ctl_reg.s.gmxeno =1 ; +csr_wr (CVMX_PCSX_MISCX_CTL_REG (index, interface), + pcsx_miscx_ctl_reg.u64); +csr_rd (CVMX_PCSX_MISCX_CTL_REG (index, interface)); +return 0 ; + } +return __cvmx_helper_sgmii_hardware_init_link_speed (interface, index, + link_info); +} + +/** +* @INTERNAL +* Configure a port for internal and/or external loopback. Internal loopback +* causes packets sent by the port to be received by Octeon. External loopback +* causes packets received from the wire to sent out again. +* +* @param ipd_port IPD/PKO port to loopback. +* @param enable_internal +* Non zero if you want internal loopback +* @param enable_external +* Non zero if you want external loopback +* +* @return Zero on success, negative on failure. +*/ +int __cvmx_helper_sgmii_configure_loopback (int ipd_port,int enable_internal, +int enable_external) +{ +int interface =cvmx_helper_get_interface_num (ipd_port); +int index =cvmx_helper_get_interface_index_num (ipd_port); +union cvmx_pcsx_mrx_control_reg pcsx_mrx_control_reg; +union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg; + +if (!cvmx_helper_is_port_valid (interface, index)) +return 0 ; + + pcsx_mrx_control_reg.u64 = +csr_rd (CVMX_PCSX_MRX_CONTROL_REG (index, interface)); + pcsx_mrx_control_reg.s.loopbck1 = enable_internal; +csr_wr (CVMX_PCSX_MRX_CONTROL_REG (index, interface), + pcsx_mrx_control_reg.u64); + + pcsx_miscx_ctl_reg.u64 = +csr_rd (CVMX_PCSX_MISCX_CTL_REG (index, interface)); + pcsx_miscx_ctl_reg.s.loopbck2 = enable_external; +csr_wr (CVMX_PCSX_MISCX_CTL_REG (index, interface), + pcsx_miscx_ctl_reg.u64); + +__cvmx_helper_sgmii_hardware_init_link (interface, index); +return 0 ; +}
Signature · 1 line
2.35.1
PATCH v2 23/52 mips: octeon: Add cvmx-helper-xaui.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-helper-xaui.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-helper-xaui.c | 518 +++++++++++++++++++++++ 1 file changed, 518 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-helper-xaui.c
arch/mips/mach-octeon/cvmx-helper-xaui.c new file +518 -0
@@ -0,0 +1,518 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* Functions for XAUI initialization, configuration, +* and monitoring. +*/ + +#include <time.h> +#include <log.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +int __cvmx_helper_xaui_enumerate (int xiface) +{ +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface; +union cvmx_gmxx_hg2_control gmx_hg2_control; + +if (OCTEON_IS_MODEL (OCTEON_CN70XX )) { +enum cvmx_qlm_mode qlm_mode = +cvmx_qlm_get_dlm_mode (0 , interface); + +if (qlm_mode ==CVMX_QLM_MODE_RXAUI ) +return 1 ; +return 0 ; + } +/* If HiGig2 is enabled return 16 ports, otherwise return 1 port */ + gmx_hg2_control.u64 =csr_rd (CVMX_GMXX_HG2_CONTROL (interface)); +if (gmx_hg2_control.s.hg2tx_en) +return 16 ; +else +return 1 ; +} + +/** +* @INTERNAL +* Probe a XAUI interface and determine the number of ports +* connected to it. The XAUI interface should still be down +* after this call. +* +* @param xiface Interface to probe +* +* @return Number of ports on the interface. Zero to disable. +*/ +int __cvmx_helper_xaui_probe (int xiface) +{ +int i, ports; +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface; +union cvmx_gmxx_inf_mode mode; + +/* +* CN63XX Pass 1.0 errata G-14395 requires the QLM De-emphasis +* be programmed. +*/ +if (OCTEON_IS_MODEL (OCTEON_CN63XX_PASS1_0 )) { +union cvmx_ciu_qlm2 ciu_qlm; + + ciu_qlm.u64 =csr_rd (CVMX_CIU_QLM2 ); + ciu_qlm.s.txbypass =1 ; + ciu_qlm.s.txdeemph =0x5 ; + ciu_qlm.s.txmargin =0x1a ; +csr_wr (CVMX_CIU_QLM2 , ciu_qlm.u64); + } + +/* +* CN63XX Pass 2.x errata G-15273 requires the QLM De-emphasis +* be programmed when using a 156.25Mhz ref clock. +*/ +if (OCTEON_IS_MODEL (OCTEON_CN63XX_PASS2_X )) { +/* Read the QLM speed pins */ +union cvmx_mio_rst_boot mio_rst_boot; + + mio_rst_boot.u64 =csr_rd (CVMX_MIO_RST_BOOT ); + +if (mio_rst_boot.cn63xx.qlm2_spd ==0xb ) { +union cvmx_ciu_qlm2 ciu_qlm; + + ciu_qlm.u64 =csr_rd (CVMX_CIU_QLM2 ); + ciu_qlm.s.txbypass =1 ; + ciu_qlm.s.txdeemph =0xa ; + ciu_qlm.s.txmargin =0x1f ; +csr_wr (CVMX_CIU_QLM2 , ciu_qlm.u64); + } + } + +/* +* Check if QLM is configured correct for XAUI/RXAUI, verify +* the speed as well as mode. +*/ +if (OCTEON_IS_MODEL (OCTEON_CN6XXX )) { +int qlm =cvmx_qlm_interface (xiface); +enum cvmx_qlm_mode mode =cvmx_qlm_get_mode (qlm); + +if (mode !=CVMX_QLM_MODE_XAUI && mode !=CVMX_QLM_MODE_RXAUI ) +return 0 ; + } + + ports =__cvmx_helper_xaui_enumerate (xiface); + +if (ports <=0 ) +return 0 ; + +/* +* Due to errata GMX-700 on CN56XXp1.x and CN52XXp1.x, the +* interface needs to be enabled before IPD otherwise per port +* backpressure may not work properly. +*/ + mode.u64 =csr_rd (CVMX_GMXX_INF_MODE (interface)); + mode.s.en =1 ; +csr_wr (CVMX_GMXX_INF_MODE (interface), mode.u64); + +if (!OCTEON_IS_MODEL (OCTEON_CN68XX ) && + !OCTEON_IS_MODEL (OCTEON_CN70XX )) { +/* +* Setup PKO to support 16 ports for HiGig2 virtual +* ports. We're pointing all of the PKO packet ports +* for this interface to the XAUI. This allows us to +* use HiGig2 backpressure per port. +*/ +for (i =0 ; i <16 ; i++) { +union cvmx_pko_mem_port_ptrs pko_mem_port_ptrs; + + pko_mem_port_ptrs.u64 =0 ; +/* +* We set each PKO port to have equal priority +* in a round robin fashion. +*/ + pko_mem_port_ptrs.s.static_p =0 ; + pko_mem_port_ptrs.s.qos_mask =0xff ; +/* All PKO ports map to the same XAUI hardware port */ + pko_mem_port_ptrs.s.eid = interface *4 ; + pko_mem_port_ptrs.s.pid = interface *16 + i; + pko_mem_port_ptrs.s.bp_port = interface *16 + i; +csr_wr (CVMX_PKO_MEM_PORT_PTRS , pko_mem_port_ptrs.u64); + } + } + +return ports; +} + +/** +* @INTERNAL +* Bringup XAUI interface. After this call packet I/O should be +* fully functional. +* +* @param interface to bring up +* +* @return Zero on success, negative on failure +*/ +int __cvmx_helper_xaui_link_init (int interface) +{ +union cvmx_gmxx_prtx_cfg gmx_cfg; +union cvmx_pcsxx_control1_reg xaui_ctl; +union cvmx_pcsxx_misc_ctl_reg misc_ctl; +union cvmx_gmxx_tx_xaui_ctl tx_ctl; + +/* (1) Interface has already been enabled. */ + +/* (2) Disable GMX. */ + misc_ctl.u64 =csr_rd (CVMX_PCSXX_MISC_CTL_REG (interface)); + misc_ctl.s.gmxeno =1 ; +csr_wr (CVMX_PCSXX_MISC_CTL_REG (interface), misc_ctl.u64); + +/* (3) Disable GMX and PCSX interrupts. */ +csr_wr (CVMX_GMXX_RXX_INT_EN (0 , interface),0x0 ); +csr_wr (CVMX_GMXX_TX_INT_EN (interface),0x0 ); +csr_wr (CVMX_PCSXX_INT_EN_REG (interface),0x0 ); + +/* (4) Bring up the PCSX and GMX reconciliation layer. */ +/* (4)a Set polarity and lane swapping. */ +/* (4)b */ + tx_ctl.u64 =csr_rd (CVMX_GMXX_TX_XAUI_CTL (interface)); +/* Enable better IFG packing and improves performance */ + tx_ctl.s.dic_en =1 ; + tx_ctl.s.uni_en =0 ; +csr_wr (CVMX_GMXX_TX_XAUI_CTL (interface), tx_ctl.u64); + +/* (4)c Aply reset sequence */ + xaui_ctl.u64 =csr_rd (CVMX_PCSXX_CONTROL1_REG (interface)); + xaui_ctl.s.lo_pwr =0 ; + +/* +* Errata G-15618 requires disabling PCS soft reset in some +* OCTEON II models. +*/ +if (!OCTEON_IS_MODEL (OCTEON_CN63XX ) && + !OCTEON_IS_MODEL (OCTEON_CN66XX_PASS1_X ) && + !OCTEON_IS_MODEL (OCTEON_CN68XX )) + xaui_ctl.s.reset =1 ; +csr_wr (CVMX_PCSXX_CONTROL1_REG (interface), xaui_ctl.u64); + +if (OCTEON_IS_MODEL (OCTEON_CN68XX_PASS2_X ) && interface !=1 ) { +/* +* Note that GMX 1 was skipped as GMX0 is on the same +* QLM and will always be done first +* +* Workaround for Errata (G-16467). +*/ +int qlm = interface; +#ifdef CVMX_QLM_DUMP_STATE +debug ("%s:%d: XAUI%d: Applying workaround for Errata G-16467\n" , + __func__, __LINE__, qlm); +cvmx_qlm_display_registers (qlm); +debug ("\n" ); +#endif +/* +* This workaround only applies to QLMs running XAUI +* at 6.25Ghz +*/ +if ((cvmx_qlm_get_gbaud_mhz (qlm) ==6250 ) && + (cvmx_qlm_jtag_get (qlm,0 ,"clkf_byp" ) !=20 )) { +/* Wait 100us for links to stabalize */ +udelay (100 ); +cvmx_qlm_jtag_set (qlm,-1 ,"clkf_byp" ,20 ); +/* Allow the QLM to exit reset */ +cvmx_qlm_jtag_set (qlm,-1 ,"cfg_rst_n_clr" ,0 ); +/* Wait 100us for links to stabalize */ +udelay (100 ); +/* Allow TX on QLM */ +cvmx_qlm_jtag_set (qlm,-1 ,"cfg_tx_idle_set" ,0 ); + } +#ifdef CVMX_QLM_DUMP_STATE +debug ("%s:%d: XAUI%d: Done applying workaround for Errata G-16467\n" , + __func__, __LINE__, qlm); +cvmx_qlm_display_registers (qlm); +debug ("\n\n" ); +#endif + } + +/* Wait for PCS to come out of reset */ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_PCSXX_CONTROL1_REG (interface), + cvmx_pcsxx_control1_reg_t, reset, ==, 0, +10000 )) +return -1 ; +/* Wait for PCS to be aligned */ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_PCSXX_10GBX_STATUS_REG (interface), + cvmx_pcsxx_10gbx_status_reg_t, alignd, ==, 1, +10000 )) +return -1 ; +/* Wait for RX to be ready */ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_GMXX_RX_XAUI_CTL (interface), + cvmx_gmxx_rx_xaui_ctl_t, status, ==, 0, +10000 )) +return -1 ; + +/* (6) Configure GMX */ + +/* Wait for GMX RX to be idle */ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_GMXX_PRTX_CFG (0 , interface), + cvmx_gmxx_prtx_cfg_t, rx_idle, ==, 1, 10000)) +return -1 ; +/* Wait for GMX TX to be idle */ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_GMXX_PRTX_CFG (0 , interface), + cvmx_gmxx_prtx_cfg_t, tx_idle, ==, 1, 10000)) +return -1 ; + +/* GMX configure */ + gmx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (0 , interface)); + gmx_cfg.s.speed =1 ; + gmx_cfg.s.speed_msb =0 ; + gmx_cfg.s.slottime =1 ; +csr_wr (CVMX_GMXX_TX_PRTS (interface),1 ); +csr_wr (CVMX_GMXX_TXX_SLOT (0 , interface),512 ); +csr_wr (CVMX_GMXX_TXX_BURST (0 , interface),8192 ); +csr_wr (CVMX_GMXX_PRTX_CFG (0 , interface), gmx_cfg.u64); + +/* Wait for receive link */ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_PCSXX_STATUS1_REG (interface), + cvmx_pcsxx_status1_reg_t, rcv_lnk, ==, 1, +10000 )) +return -1 ; +if (CVMX_WAIT_FOR_FIELD64 (CVMX_PCSXX_STATUS2_REG (interface), + cvmx_pcsxx_status2_reg_t, xmtflt, ==, 0, +10000 )) +return -1 ; +if (CVMX_WAIT_FOR_FIELD64 (CVMX_PCSXX_STATUS2_REG (interface), + cvmx_pcsxx_status2_reg_t, rcvflt, ==, 0, +10000 )) +return -1 ; + +/* (8) Enable packet reception */ + misc_ctl.s.gmxeno =0 ; +csr_wr (CVMX_PCSXX_MISC_CTL_REG (interface), misc_ctl.u64); + +/* Clear all error interrupts before enabling the interface. */ +csr_wr (CVMX_GMXX_RXX_INT_REG (0 , interface), ~0x0ull ); +csr_wr (CVMX_GMXX_TX_INT_REG (interface), ~0x0ull ); +csr_wr (CVMX_PCSXX_INT_REG (interface), ~0x0ull ); + +/* Enable GMX */ + gmx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (0 , interface)); + gmx_cfg.s.en =1 ; +csr_wr (CVMX_GMXX_PRTX_CFG (0 , interface), gmx_cfg.u64); + +return 0 ; +} + +/** +* @INTERNAL +* Bringup and enable a XAUI interface. After this call packet +* I/O should be fully functional. This is called with IPD +* enabled but PKO disabled. +* +* @param xiface Interface to bring up +* +* @return Zero on success, negative on failure +*/ +int __cvmx_helper_xaui_enable (int xiface) +{ +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface; + +__cvmx_helper_setup_gmx (interface,1 ); + +/* Setup PKND and BPID */ +if (octeon_has_feature (OCTEON_FEATURE_PKND )) { +union cvmx_gmxx_bpid_msk bpid_msk; +union cvmx_gmxx_bpid_mapx bpid_map; +union cvmx_gmxx_prtx_cfg gmxx_prtx_cfg; +union cvmx_gmxx_txx_append gmxx_txx_append_cfg; + +/* Setup PKIND */ + gmxx_prtx_cfg.u64 =csr_rd (CVMX_GMXX_PRTX_CFG (0 , interface)); + gmxx_prtx_cfg.s.pknd =cvmx_helper_get_pknd (interface,0 ); +csr_wr (CVMX_GMXX_PRTX_CFG (0 , interface), gmxx_prtx_cfg.u64); + +/* Setup BPID */ + bpid_map.u64 =csr_rd (CVMX_GMXX_BPID_MAPX (0 , interface)); + bpid_map.s.val =1 ; + bpid_map.s.bpid =cvmx_helper_get_bpid (interface,0 ); +csr_wr (CVMX_GMXX_BPID_MAPX (0 , interface), bpid_map.u64); + + bpid_msk.u64 =csr_rd (CVMX_GMXX_BPID_MSK (interface)); + bpid_msk.s.msk_or |=1 ; + bpid_msk.s.msk_and &= ~1 ; +csr_wr (CVMX_GMXX_BPID_MSK (interface), bpid_msk.u64); + +/* CN68XX adds the padding and FCS in PKO, not GMX */ + gmxx_txx_append_cfg.u64 = +csr_rd (CVMX_GMXX_TXX_APPEND (0 , interface)); + gmxx_txx_append_cfg.s.fcs =0 ; + gmxx_txx_append_cfg.s.pad =0 ; +csr_wr (CVMX_GMXX_TXX_APPEND (0 , interface), + gmxx_txx_append_cfg.u64); + } + +/* 70XX eval boards use Marvel phy, set disparity accordingly. */ +if (OCTEON_IS_MODEL (OCTEON_CN70XX )) { +union cvmx_gmxx_rxaui_ctl rxaui_ctl; + + rxaui_ctl.u64 =csr_rd (CVMX_GMXX_RXAUI_CTL (interface)); + rxaui_ctl.s.disparity =1 ; +csr_wr (CVMX_GMXX_RXAUI_CTL (interface), rxaui_ctl.u64); + } + +__cvmx_helper_xaui_link_init (interface); + +return 0 ; +} + +/** +* @INTERNAL +* Return the link state of an IPD/PKO port as returned by +* auto negotiation. The result of this function may not match +* Octeon's link config if auto negotiation has changed since +* the last call to cvmx_helper_link_set(). +* +* @param ipd_port IPD/PKO port to query +* +* @return Link state +*/ +cvmx_helper_link_info_t __cvmx_helper_xaui_link_get (int ipd_port) +{ +int interface =cvmx_helper_get_interface_num (ipd_port); +union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl; +union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl; +union cvmx_pcsxx_status1_reg pcsxx_status1_reg; +cvmx_helper_link_info_t result; + + gmxx_tx_xaui_ctl.u64 =csr_rd (CVMX_GMXX_TX_XAUI_CTL (interface)); + gmxx_rx_xaui_ctl.u64 =csr_rd (CVMX_GMXX_RX_XAUI_CTL (interface)); + pcsxx_status1_reg.u64 =csr_rd (CVMX_PCSXX_STATUS1_REG (interface)); + result.u64 =0 ; + +/* Only return a link if both RX and TX are happy */ +if (gmxx_tx_xaui_ctl.s.ls ==0 && gmxx_rx_xaui_ctl.s.status ==0 && + pcsxx_status1_reg.s.rcv_lnk ==1 ) { +union cvmx_pcsxx_misc_ctl_reg misc_ctl; + + result.s.link_up =1 ; + result.s.full_duplex =1 ; +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +union cvmx_mio_qlmx_cfg qlm_cfg; +int lanes; +int qlm = (interface ==1 ) ?0 : interface; + + qlm_cfg.u64 =csr_rd (CVMX_MIO_QLMX_CFG (qlm)); + result.s.speed =cvmx_qlm_get_gbaud_mhz (qlm) *8 /10 ; + lanes = (qlm_cfg.s.qlm_cfg ==7 ) ?2 :4 ; + result.s.speed *= lanes; + }else if (OCTEON_IS_MODEL (OCTEON_CN6XXX )) { +int qlm =cvmx_qlm_interface (interface); + + result.s.speed =cvmx_qlm_get_gbaud_mhz (qlm) *8 /10 ; + result.s.speed *=4 ; + }else { + result.s.speed =10000 ; + } + misc_ctl.u64 =csr_rd (CVMX_PCSXX_MISC_CTL_REG (interface)); +if (misc_ctl.s.gmxeno) +__cvmx_helper_xaui_link_init (interface); + }else { +/* Disable GMX and PCSX interrupts. */ +csr_wr (CVMX_GMXX_RXX_INT_EN (0 , interface),0x0 ); +csr_wr (CVMX_GMXX_TX_INT_EN (interface),0x0 ); +csr_wr (CVMX_PCSXX_INT_EN_REG (interface),0x0 ); + } +return result; +} + +/** +* @INTERNAL +* Configure an IPD/PKO port for the specified link state. This +* function does not influence auto negotiation at the PHY level. +* The passed link state must always match the link state returned +* by cvmx_helper_link_get(). It is normally best to use +* cvmx_helper_link_autoconf() instead. +* +* @param ipd_port IPD/PKO port to configure +* @param link_info The new link state +* +* @return Zero on success, negative on failure +*/ +int __cvmx_helper_xaui_link_set (int ipd_port,cvmx_helper_link_info_t link_info) +{ +int interface =cvmx_helper_get_interface_num (ipd_port); +union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl; +union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl; + + gmxx_tx_xaui_ctl.u64 =csr_rd (CVMX_GMXX_TX_XAUI_CTL (interface)); + gmxx_rx_xaui_ctl.u64 =csr_rd (CVMX_GMXX_RX_XAUI_CTL (interface)); + +/* If the link shouldn't be up, then just return */ +if (!link_info.s.link_up) +return 0 ; + +/* Do nothing if both RX and TX are happy */ +if (gmxx_tx_xaui_ctl.s.ls ==0 && gmxx_rx_xaui_ctl.s.status ==0 ) +return 0 ; + +/* Bring the link up */ +return __cvmx_helper_xaui_link_init (interface); +} + +/** +* @INTERNAL +* Configure a port for internal and/or external loopback. Internal loopback +* causes packets sent by the port to be received by Octeon. External loopback +* causes packets received from the wire to sent out again. +* +* @param ipd_port IPD/PKO port to loopback. +* @param enable_internal +* Non zero if you want internal loopback +* @param enable_external +* Non zero if you want external loopback +* +* @return Zero on success, negative on failure. +*/ +extern int __cvmx_helper_xaui_configure_loopback (int ipd_port, +int enable_internal, +int enable_external) +{ +int interface =cvmx_helper_get_interface_num (ipd_port); +union cvmx_pcsxx_control1_reg pcsxx_control1_reg; +union cvmx_gmxx_xaui_ext_loopback gmxx_xaui_ext_loopback; + +/* Set the internal loop */ + pcsxx_control1_reg.u64 =csr_rd (CVMX_PCSXX_CONTROL1_REG (interface)); + pcsxx_control1_reg.s.loopbck1 = enable_internal; +csr_wr (CVMX_PCSXX_CONTROL1_REG (interface), pcsxx_control1_reg.u64); + +/* Set the external loop */ + gmxx_xaui_ext_loopback.u64 = +csr_rd (CVMX_GMXX_XAUI_EXT_LOOPBACK (interface)); + gmxx_xaui_ext_loopback.s.en = enable_external; +csr_wr (CVMX_GMXX_XAUI_EXT_LOOPBACK (interface), + gmxx_xaui_ext_loopback.u64); + +/* Take the link through a reset */ +return __cvmx_helper_xaui_link_init (interface); +}
Signature · 1 line
2.35.1
PATCH v2 24/52 mips: octeon: Add cvmx-agl.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-agl.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-agl.c | 216 +++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-agl.c
arch/mips/mach-octeon/cvmx-agl.c new file +216 -0
@@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* Functions for RGMII (MGMT) initialization, configuration, +* and monitoring. +*/ + +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-pki.h> +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-agl.h> +#include <mach/cvmx-agl-defs.h> + +/* +* @param port to enable +* +* @return Zero on success, negative on failure +*/ +int cvmx_agl_enable (int port) +{ +cvmx_agl_gmx_rxx_frm_ctl_t rxx_frm_ctl; + + rxx_frm_ctl.u64 =0 ; + rxx_frm_ctl.s.pre_align =1 ; +/* When set, disables the length check for non-min sized pkts with +* padding in the client data +*/ + rxx_frm_ctl.s.pad_len =1 ; +/* When set, disables the length check for VLAN pkts */ + rxx_frm_ctl.s.vlan_len =1 ; +/* When set, PREAMBLE checking is less strict */ + rxx_frm_ctl.s.pre_free =1 ; +/* Control Pause Frames can match station SMAC */ + rxx_frm_ctl.s.ctl_smac =0 ; +/* Control Pause Frames can match globally assign Multicast address */ + rxx_frm_ctl.s.ctl_mcst =1 ; + rxx_frm_ctl.s.ctl_bck =1 ;/* Forward pause information to TX block */ + rxx_frm_ctl.s.ctl_drp =1 ;/* Drop Control Pause Frames */ + rxx_frm_ctl.s.pre_strp =1 ;/* Strip off the preamble */ +/* This port is configured to send PREAMBLE+SFD to begin every frame. +* GMX checks that the PREAMBLE is sent correctly +*/ + rxx_frm_ctl.s.pre_chk =1 ; +csr_wr (CVMX_AGL_GMX_RXX_FRM_CTL (port), rxx_frm_ctl.u64); + +return 0 ; +} + +cvmx_helper_link_info_t cvmx_agl_link_get (int port) +{ +cvmx_helper_link_info_t result; +int interface, port_index; + +/* Fake IPD port is used on some older models. */ +if (port <0 ) +return __cvmx_helper_board_link_get (port); + +/* Simulator does not have PHY, use some defaults. */ + interface =cvmx_helper_get_interface_num (port); + port_index =cvmx_helper_get_interface_index_num (port); +if (cvmx_helper_get_port_force_link_up (interface, port_index)) { + result.u64 =0 ; + result.s.full_duplex =1 ; + result.s.link_up =1 ; + result.s.speed =1000 ; +return result; + } + +return __cvmx_helper_board_link_get (port); +} + +/* +* Set MII/RGMII link based on mode. +* +* @param port interface port to set the link. +* @param link_info Link status +* +* @return 0 on success and 1 on failure +*/ +int cvmx_agl_link_set (int port,cvmx_helper_link_info_t link_info) +{ +cvmx_agl_gmx_prtx_cfg_t agl_gmx_prtx; + +/* Disable GMX before we make any changes. */ + agl_gmx_prtx.u64 =csr_rd (CVMX_AGL_GMX_PRTX_CFG (port)); + agl_gmx_prtx.s.en =0 ; + agl_gmx_prtx.s.tx_en =0 ; + agl_gmx_prtx.s.rx_en =0 ; +csr_wr (CVMX_AGL_GMX_PRTX_CFG (port), agl_gmx_prtx.u64); + +if (OCTEON_IS_MODEL (OCTEON_CN6XXX ) ||OCTEON_IS_OCTEON3 ()) { +u64 one_second =0x1000000 ;/* todo: this needs checking */ + +/* Wait for GMX to be idle */ +if (CVMX_WAIT_FOR_FIELD64 (CVMX_AGL_GMX_PRTX_CFG (port), + cvmx_agl_gmx_prtx_cfg_t, rx_idle, ==, +1 , one_second) || +CVMX_WAIT_FOR_FIELD64 (CVMX_AGL_GMX_PRTX_CFG (port), + cvmx_agl_gmx_prtx_cfg_t, tx_idle, ==, +1 , one_second)) { +debug ("AGL%d: Timeout waiting for GMX to be idle\n" , + port); +return -1 ; + } + } + + agl_gmx_prtx.u64 =csr_rd (CVMX_AGL_GMX_PRTX_CFG (port)); + +/* Set duplex mode */ +if (!link_info.s.link_up) + agl_gmx_prtx.s.duplex =1 ;/* Force full duplex on down links */ +else + agl_gmx_prtx.s.duplex = link_info.s.full_duplex; + +switch (link_info.s.speed) { +case 10 : + agl_gmx_prtx.s.speed =0 ; + agl_gmx_prtx.s.slottime =0 ; +if (OCTEON_IS_MODEL (OCTEON_CN6XXX ) ||OCTEON_IS_OCTEON3 ()) { + agl_gmx_prtx.s.speed_msb =1 ; + agl_gmx_prtx.s.burst =1 ; + } +break ; + +case 100 : + agl_gmx_prtx.s.speed =0 ; + agl_gmx_prtx.s.slottime =0 ; +if (OCTEON_IS_MODEL (OCTEON_CN6XXX ) ||OCTEON_IS_OCTEON3 ()) { + agl_gmx_prtx.s.speed_msb =0 ; + agl_gmx_prtx.s.burst =1 ; + } +break ; + +case 1000 : +/* 1000 MBits is only supported on 6XXX chips */ +if (OCTEON_IS_MODEL (OCTEON_CN6XXX ) ||OCTEON_IS_OCTEON3 ()) { + agl_gmx_prtx.s.speed_msb =0 ; + agl_gmx_prtx.s.speed =1 ; + agl_gmx_prtx.s.slottime = +1 ;/* Only matters for half-duplex */ + agl_gmx_prtx.s.burst = agl_gmx_prtx.s.duplex; + } +break ; + +/* No link */ +case 0 : +default : +break ; + } + +/* Write the new GMX setting with the port still disabled. */ +csr_wr (CVMX_AGL_GMX_PRTX_CFG (port), agl_gmx_prtx.u64); + +/* Read GMX CFG again to make sure the config is completed. */ + agl_gmx_prtx.u64 =csr_rd (CVMX_AGL_GMX_PRTX_CFG (port)); + +if (OCTEON_IS_MODEL (OCTEON_CN6XXX ) ||OCTEON_IS_OCTEON3 ()) { +cvmx_agl_gmx_txx_clk_t agl_clk; +cvmx_agl_prtx_ctl_t prt_ctl; + + prt_ctl.u64 =csr_rd (CVMX_AGL_PRTX_CTL (port)); + agl_clk.u64 =csr_rd (CVMX_AGL_GMX_TXX_CLK (port)); +/* MII (both speeds) and RGMII 1000 setting */ + agl_clk.s.clk_cnt =1 ; +/* Check other speeds for RGMII mode */ +if (prt_ctl.s.mode ==0 ||OCTEON_IS_OCTEON3 ()) { +if (link_info.s.speed ==10 ) + agl_clk.s.clk_cnt =50 ; +else if (link_info.s.speed ==100 ) + agl_clk.s.clk_cnt =5 ; + } +csr_wr (CVMX_AGL_GMX_TXX_CLK (port), agl_clk.u64); + } + +/* Enable transmit and receive ports */ + agl_gmx_prtx.s.tx_en =1 ; + agl_gmx_prtx.s.rx_en =1 ; +csr_wr (CVMX_AGL_GMX_PRTX_CFG (port), agl_gmx_prtx.u64); + +/* Enable the link. */ + agl_gmx_prtx.s.en =1 ; +csr_wr (CVMX_AGL_GMX_PRTX_CFG (port), agl_gmx_prtx.u64); + +if (OCTEON_IS_OCTEON3 ()) { +union cvmx_agl_prtx_ctl agl_prtx_ctl; +/* Enable the interface, set clkrst */ + agl_prtx_ctl.u64 =csr_rd (CVMX_AGL_PRTX_CTL (port)); + agl_prtx_ctl.s.clkrst =1 ; +csr_wr (CVMX_AGL_PRTX_CTL (port), agl_prtx_ctl.u64); +csr_rd (CVMX_AGL_PRTX_CTL (port)); + agl_prtx_ctl.s.enable =1 ; +csr_wr (CVMX_AGL_PRTX_CTL (port), agl_prtx_ctl.u64); +/* Read the value back to force the previous write */ +csr_rd (CVMX_AGL_PRTX_CTL (port)); + } + +return 0 ; +}
Signature · 1 line
2.35.1
PATCH v2 26/52 mips: octeon: Add cvmx-fau-compat.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-fau-compat.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-fau-compat.c | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-fau-compat.c
arch/mips/mach-octeon/cvmx-fau-compat.c new file +53 -0
@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +*/ + +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-global-resources.h> + +#include <mach/cvmx-pki.h> +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-hwfau.h> + +u8 *cvmx_fau_regs_ptr; + +void cvmx_fau_bootmem_init (void *bootmem) +{ +memset (bootmem,0 ,CVMX_FAU_MAX_REGISTERS_8 ); +} + +/** +* Initializes FAU region for devices without FAU unit. +* @return 0 on success -1 on failure +*/ +int cvmx_fau_init (void ) +{ + cvmx_fau_regs_ptr = (u8 *)cvmx_bootmem_alloc_named_range_once ( +CVMX_FAU_MAX_REGISTERS_8 ,0 ,1ull <<31 ,128 , +"cvmx_fau_registers" , cvmx_fau_bootmem_init); + +if (cvmx_fau_regs_ptr ==0ull ) { +debug ("ERROR: Failed to alloc named block for software FAU.\n" ); +return -1 ; + } + +return 0 ; +}
Signature · 1 line
2.35.1
PATCH v2 27/52 mips: octeon: Add cvmx-fpa.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-fpa.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-fpa.c | 1127 ++++++++++++++++++++++++++++++ 1 file changed, 1127 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-fpa.c
arch/mips/mach-octeon/cvmx-fpa.c new file +1127 -0
@@ -0,0 +1,1127 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* Support library for the hardware Free Pool Allocator. +*/ + +#include <errno.h> +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> +#include <mach/cvmx-range.h> +#include <mach/cvmx-global-resources.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-gserx-defs.h> +#include <mach/cvmx-ilk-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-hwpko.h> +#include <mach/cvmx-ilk.h> +#include <mach/cvmx-pki.h> +#include <mach/cvmx-pko3.h> +#include <mach/cvmx-pko3-queue.h> +#include <mach/cvmx-pko3-resources.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-helper-bgx.h> +#include <mach/cvmx-helper-cfg.h> +#include <mach/cvmx-helper-util.h> +#include <mach/cvmx-helper-pki.h> + +static const int debug; + +/* Due to suspected errata, we may not be able to let the FPA_AURAX_CNT +* get too close to 0, to avoid a spurious wrap-around error +*/ +const unsigned int __cvmx_fpa3_cnt_offset =32 ; + +/* For advanced checks, a guard-band is created around the internal +* stack, to make sure the stack is not overwritten. +*/ +const u64 magic_pattern =0xbab4faced095f00d ; +const unsigned int guard_band_size =0 <<10 ;/* 1KiB default*/ + +#define CVMX_CACHE_LINE_SHIFT (7) + +#define CVMX_FPA3_NAME_LEN (16) + +typedef struct { +char name[CVMX_FPA3_NAME_LEN ]; +u64 stack_paddr;/* Internal stack storage */ +u64 bufs_paddr;/* Buffer pool base address */ +u64 stack_psize;/* Internal stack storage size */ +u64 bufs_psize;/* Buffer pool raw size */ +u64 buf_count;/* Number of buffer filled */ +u64 buf_size;/* Buffer size */ +}cvmx_fpa3_poolx_info_t ; + +typedef struct { +char name[CVMX_FPA3_NAME_LEN ]; +unsigned int buf_size;/* Buffer size */ +}cvmx_fpa3_aurax_info_t ; + +typedef struct { +char name[CVMX_FPA1_NAME_SIZE ]; +u64 size;/* Block size of pool buffers */ +u64 buffer_count; +u64 base_paddr;/* Base physical addr */ +/* if buffer is allocated at initialization */ +}cvmx_fpa1_pool_info_t ; + +/** +* FPA1/FPA3 info structure is stored in a named block +* that is allocated once and shared among applications. +*/ +static cvmx_fpa1_pool_info_t *cvmx_fpa1_pool_info; +static cvmx_fpa3_poolx_info_t *cvmx_fpa3_pool_info[CVMX_MAX_NODES ]; +static cvmx_fpa3_aurax_info_t *cvmx_fpa3_aura_info[CVMX_MAX_NODES ]; + +/** +* Return the size of buffers held in a POOL +* +* @param pool is the POOL handle +* @return buffer size in bytes +* +*/ +int cvmx_fpa3_get_pool_buf_size (cvmx_fpa3_pool_t pool) +{ +cvmx_fpa_poolx_cfg_t pool_cfg; + +if (!__cvmx_fpa3_pool_valid (pool)) +return -1 ; + + pool_cfg.u64 =csr_rd_node (pool.node,CVMX_FPA_POOLX_CFG (pool.lpool)); +return pool_cfg.cn78xx.buf_size <<CVMX_CACHE_LINE_SHIFT ; +} + +/** +* Return the size of buffers held in a buffer pool +* +* @param pool is the pool number +* +* This function will work with CN78XX models in backward-compatible mode +*/ +unsigned int cvmx_fpa_get_block_size (int pool) +{ +if (octeon_has_feature (OCTEON_FEATURE_FPA3 )) { +return cvmx_fpa3_get_pool_buf_size (cvmx_fpa3_aura_to_pool ( +cvmx_fpa1_pool_to_fpa3_aura (pool))); + }else { +if ((unsigned int )pool >=CVMX_FPA1_NUM_POOLS ) +return 0 ; +if (!cvmx_fpa1_pool_info) +cvmx_fpa_global_init_node (0 ); +return cvmx_fpa1_pool_info[pool].size; + } +} + +static void cvmx_fpa3_set_aura_name (cvmx_fpa3_gaura_t aura,const char *name) +{ +cvmx_fpa3_aurax_info_t *pinfo; + + pinfo = cvmx_fpa3_aura_info[aura.node]; +if (!pinfo) +return ; + pinfo += aura.laura; +memset (pinfo->name,0 ,sizeof (pinfo->name)); +if (name) +strlcpy (pinfo->name, name,sizeof (pinfo->name)); +} + +static void cvmx_fpa3_set_pool_name (cvmx_fpa3_pool_t pool,const char *name) +{ +cvmx_fpa3_poolx_info_t *pinfo; + + pinfo = cvmx_fpa3_pool_info[pool.node]; +if (!pinfo) +return ; + pinfo += pool.lpool; +memset (pinfo->name,0 ,sizeof (pinfo->name)); +if (name) +strlcpy (pinfo->name, name,sizeof (pinfo->name)); +} + +static void cvmx_fpa_set_name (int pool_num,const char *name) +{ +if (octeon_has_feature (OCTEON_FEATURE_FPA3 )) { +cvmx_fpa3_set_aura_name (cvmx_fpa1_pool_to_fpa3_aura (pool_num), + name); + }else { +cvmx_fpa1_pool_info_t *pinfo; + +if ((unsigned int )pool_num >=CVMX_FPA1_NUM_POOLS ) +return ; +if (!cvmx_fpa1_pool_info) +cvmx_fpa_global_init_node (0 ); + pinfo = &cvmx_fpa1_pool_info[pool_num]; +memset (pinfo->name,0 ,sizeof (pinfo->name)); +if (name) +strlcpy (pinfo->name, name,sizeof (pinfo->name)); + } +} + +static int cvmx_fpa3_aura_cfg (cvmx_fpa3_gaura_t aura,cvmx_fpa3_pool_t pool, +u64 limit,u64 threshold,int ptr_dis) +{ +cvmx_fpa3_aurax_info_t *pinfo; +cvmx_fpa_aurax_cfg_t aura_cfg; +cvmx_fpa_poolx_cfg_t pool_cfg; +cvmx_fpa_aurax_cnt_t cnt_reg; +cvmx_fpa_aurax_cnt_limit_t limit_reg; +cvmx_fpa_aurax_cnt_threshold_t thresh_reg; +cvmx_fpa_aurax_int_t int_reg; +unsigned int block_size; + +if (debug) +debug ("%s: AURA %u:%u POOL %u:%u\n" , __func__, aura.node, + aura.laura, pool.node, pool.lpool); + +if (aura.node != pool.node) { +printf ("ERROR: %s: AURA/POOL node mismatch\n" , __func__); +return -1 ; + } + +if (!__cvmx_fpa3_aura_valid (aura)) { +printf ("ERROR: %s: AURA invalid\n" , __func__); +return -1 ; + } + +if (!__cvmx_fpa3_pool_valid (pool)) { +printf ("ERROR: %s: POOL invalid\n" , __func__); +return -1 ; + } + +/* Record POOL block size in AURA info entry */ + pool_cfg.u64 =csr_rd_node (pool.node,CVMX_FPA_POOLX_CFG (pool.lpool)); + + block_size = pool_cfg.cn78xx.buf_size <<7 ; + pinfo = cvmx_fpa3_aura_info[aura.node]; +if (!pinfo) +return -1 ; + pinfo += aura.laura; + + pinfo->buf_size = block_size; + +/* block_size should be >0 except for POOL=0 which is never enabled*/ +if (pool_cfg.cn78xx.ena && block_size ==0 ) { +printf ("ERROR; %s: POOL buf_size invalid\n" , __func__); +return -1 ; + } + +/* Initialize AURA count, limit and threshold registers */ + cnt_reg.u64 =0 ; + cnt_reg.cn78xx.cnt =0 + __cvmx_fpa3_cnt_offset; + + limit_reg.u64 =0 ; + limit_reg.cn78xx.limit = limit; +/* Apply count offset, unless it cases a wrap-around */ +if ((limit + __cvmx_fpa3_cnt_offset) <CVMX_FPA3_AURAX_LIMIT_MAX ) + limit_reg.cn78xx.limit += __cvmx_fpa3_cnt_offset; + + thresh_reg.u64 =0 ; + thresh_reg.cn78xx.thresh = threshold; +/* Apply count offset, unless it cases a wrap-around */ +if ((threshold + __cvmx_fpa3_cnt_offset) <CVMX_FPA3_AURAX_LIMIT_MAX ) + thresh_reg.cn78xx.thresh += __cvmx_fpa3_cnt_offset; + +csr_wr_node (aura.node,CVMX_FPA_AURAX_CNT (aura.laura), cnt_reg.u64); +csr_wr_node (aura.node,CVMX_FPA_AURAX_CNT_LIMIT (aura.laura), + limit_reg.u64); +csr_wr_node (aura.node,CVMX_FPA_AURAX_CNT_THRESHOLD (aura.laura), + thresh_reg.u64); + +/* Clear any pending error interrupts */ + int_reg.u64 =0 ; + int_reg.cn78xx.thresh =1 ; + +/* Follow a write to clear FPA_AURAX_INT[THRESH] with a read as +* a workaround to Errata FPA-23410. If FPA_AURAX_INT[THRESH] +* isn't clear, try again. +*/ +do { +csr_wr_node (aura.node,CVMX_FPA_AURAX_INT (aura.laura), + int_reg.u64); + int_reg.u64 = +csr_rd_node (aura.node,CVMX_FPA_AURAX_INT (aura.laura)); + }while (int_reg.s.thresh); + +/* Disable backpressure etc.*/ +csr_wr_node (aura.node,CVMX_FPA_AURAX_CNT_LEVELS (aura.laura),0 ); +csr_wr_node (aura.node,CVMX_FPA_AURAX_POOL_LEVELS (aura.laura),0 ); + + aura_cfg.u64 =0 ; + aura_cfg.s.ptr_dis = ptr_dis; +csr_wr_node (aura.node,CVMX_FPA_AURAX_CFG (aura.laura), aura_cfg.u64); +csr_wr_node (aura.node,CVMX_FPA_AURAX_POOL (aura.laura), pool.lpool); + +return 0 ; +} + +/** +* @INTERNAL +* +* Fill a newly created FPA3 POOL with buffers +* using a temporary AURA. +*/ +static int cvmx_fpa3_pool_populate (cvmx_fpa3_pool_t pool,unsigned int buf_cnt, +unsigned int buf_sz,void *mem_ptr, +unsigned int mem_node) +{ +cvmx_fpa3_poolx_info_t *pinfo; +cvmx_fpa3_gaura_t aura; +cvmx_fpa3_pool_t zero_pool; +cvmx_fpa_poolx_cfg_t pool_cfg; +cvmx_fpa_poolx_start_addr_t pool_start_reg; +cvmx_fpa_poolx_end_addr_t pool_end_reg; +cvmx_fpa_poolx_available_t avail_reg; +cvmx_fpa_poolx_threshold_t thresh_reg; +cvmx_fpa_poolx_int_t int_reg; +unsigned int block_size, align; +unsigned long long mem_size; +u64 paddr; +unsigned int i; + +if (debug) +debug ("%s: POOL %u:%u buf_sz=%u count=%d\n" , __func__, + pool.node, pool.lpool, buf_sz, buf_cnt); + +if (!__cvmx_fpa3_pool_valid (pool)) +return -1 ; + + zero_pool =__cvmx_fpa3_pool (pool.node,0 ); + + pool_cfg.u64 =csr_rd_node (pool.node,CVMX_FPA_POOLX_CFG (pool.lpool)); + + block_size = pool_cfg.cn78xx.buf_size <<7 ; + +if (pool_cfg.cn78xx.nat_align) { +/* Assure block_size is legit */ +if (block_size > (1 <<17 )) { +printf ("ERROR: %s: POOL %u:%u block size %u is not valid\n" , + __func__, pool.node, pool.lpool, block_size); +return -1 ; + } + } + align =CVMX_CACHE_LINE_SIZE ; + + pinfo = cvmx_fpa3_pool_info[pool.node]; +if (!pinfo) +return -1 ; + pinfo += pool.lpool; + +if (pinfo->buf_size != block_size || block_size != buf_sz) { +printf ("ERROR: %s: POOL %u:%u buffer size mismatch\n" , __func__, + pool.node, pool.lpool); +return -1 ; + } + +if (!mem_ptr) { +/* When allocating our own memory +* make sure at least 'buf_cnt' blocks +* will fit into it. +*/ + mem_size = (long long )buf_cnt * block_size + (block_size -128 ); + + mem_ptr =cvmx_helper_mem_alloc (mem_node, mem_size, align); + +if (!mem_ptr) { +printf ("ERROR: %s: POOL %u:%u out of memory, could not allocate %llu bytes\n" , + __func__, pool.node, pool.lpool, mem_size); +return -1 ; + } + +/* Record memory base for use in shutdown */ + pinfo->bufs_paddr =cvmx_ptr_to_phys (mem_ptr); + }else { +/* caller-allocated memory is sized simply, may reduce count */ + mem_size = (long long )buf_cnt * block_size; +/* caller responsable to free this memory too */ + } + +/* Recalculate buf_cnt after possible alignment adjustment */ + buf_cnt = mem_size / block_size; + +/* Get temporary AURA */ + aura =cvmx_fpa3_reserve_aura (pool.node,-1 ); +if (!__cvmx_fpa3_aura_valid (aura)) +return -1 ; + +/* Attach the temporary AURA to the POOL */ + (void )cvmx_fpa3_aura_cfg (aura, pool, buf_cnt, buf_cnt +1 ,0 ); + +/* Set AURA count to buffer count to avoid wrap-around */ +csr_wr_node (aura.node,CVMX_FPA_AURAX_CNT (aura.laura), buf_cnt); + +/* Set POOL threshold just above buf count so it does not misfire */ + thresh_reg.u64 =0 ; + thresh_reg.cn78xx.thresh = buf_cnt +1 ; +csr_wr_node (pool.node,CVMX_FPA_POOLX_THRESHOLD (pool.lpool), + thresh_reg.u64); + +/* Set buffer memory region bounds checking */ + paddr = (cvmx_ptr_to_phys (mem_ptr) >>7 ) <<7 ; + pool_start_reg.u64 =0 ; + pool_end_reg.u64 =0 ; + pool_start_reg.cn78xx.addr = paddr >>7 ; + pool_end_reg.cn78xx.addr = (paddr + mem_size +127 ) >>7 ; + +csr_wr_node (pool.node,CVMX_FPA_POOLX_START_ADDR (pool.lpool), + pool_start_reg.u64); +csr_wr_node (pool.node,CVMX_FPA_POOLX_END_ADDR (pool.lpool), + pool_end_reg.u64); + +/* Make sure 'paddr' is divisible by 'block_size' */ + i = (paddr % block_size); +if (i >0 ) { + i = block_size - i; + paddr += i; + mem_size -= i; + } + +/* The above alignment mimics how the FPA3 hardware +* aligns pointers to the buffer size, which only +* needs to be multiple of cache line size +*/ + +if (debug && paddr !=cvmx_ptr_to_phys (mem_ptr)) +debug ("%s: pool mem paddr %#llx adjusted to %#llx for block size %#x\n" , + __func__,CAST_ULL (cvmx_ptr_to_phys (mem_ptr)), +CAST_ULL (paddr), block_size); + +for (i =0 ; i < buf_cnt; i++) { +void *ptr =cvmx_phys_to_ptr (paddr); + +cvmx_fpa3_free_nosync (ptr, aura,0 ); + + paddr += block_size; + +if ((paddr + block_size -1 ) >= (paddr + mem_size)) +break ; + } + +if (debug && i < buf_cnt) { +debug ("%s: buffer count reduced from %u to %u\n" , __func__, + buf_cnt, i); + buf_cnt = i; + } + +/* Wait for all buffers to reach the POOL before removing temp AURA */ +do { +CVMX_SYNC ; + avail_reg.u64 =csr_rd_node ( + pool.node,CVMX_FPA_POOLX_AVAILABLE (pool.lpool)); + }while (avail_reg.cn78xx.count < buf_cnt); + +/* Detach the temporary AURA */ + (void )cvmx_fpa3_aura_cfg (aura, zero_pool,0 ,0 ,0 ); + +/* Release temporary AURA */ + (void )cvmx_fpa3_release_aura (aura); + +/* Clear all POOL interrupts */ + int_reg.u64 =0 ; + int_reg.cn78xx.ovfls =1 ; + int_reg.cn78xx.crcerr =1 ; + int_reg.cn78xx.range =1 ; + int_reg.cn78xx.thresh =1 ; +csr_wr_node (pool.node,CVMX_FPA_POOLX_INT (pool.lpool), int_reg.u64); + +/* Record buffer count for shutdown */ + pinfo->buf_count = buf_cnt; + +return buf_cnt; +} + +/** +* @INTERNAL +* +* Fill a legacy FPA pool with buffers +*/ +static int cvmx_fpa1_fill_pool (cvmx_fpa1_pool_t pool,int num_blocks, +void *buffer) +{ +cvmx_fpa_poolx_start_addr_t pool_start_reg; +cvmx_fpa_poolx_end_addr_t pool_end_reg; +unsigned int block_size =cvmx_fpa_get_block_size (pool); +unsigned int mem_size; +char *bufp; + +if ((unsigned int )pool >=CVMX_FPA1_NUM_POOLS ) +return -1 ; + + mem_size = block_size * num_blocks; + +if (!buffer) { + buffer =cvmx_helper_mem_alloc (0 , mem_size, +CVMX_CACHE_LINE_SIZE ); + + cvmx_fpa1_pool_info[pool].base_paddr =cvmx_ptr_to_phys (buffer); + }else { +/* Align user-supplied buffer to cache line size */ +unsigned int off = + (CVMX_CACHE_LINE_SIZE -1 ) &cvmx_ptr_to_phys (buffer); +if (off >0 ) { +// buffer += CVMX_CACHE_LINE_SIZE - off; + buffer = (char *)buffer +CVMX_CACHE_LINE_SIZE - off; + mem_size -=CVMX_CACHE_LINE_SIZE - off; + num_blocks = mem_size / block_size; + } + } + +if (debug) +debug ("%s: memory at %p size %#x\n" , __func__, buffer, + mem_size); + + pool_start_reg.u64 =0 ; + pool_end_reg.u64 =0 ; + +/* buffer pointer range checks are highly recommended, but optional */ + pool_start_reg.cn61xx.addr =1 ;/* catch NULL pointers */ + pool_end_reg.cn61xx.addr = (1ull << (40 -7 )) -1 ;/* max paddr */ +if (!OCTEON_IS_MODEL (OCTEON_CN63XX )) { +csr_wr (CVMX_FPA_POOLX_START_ADDR (pool), pool_start_reg.u64); +csr_wr (CVMX_FPA_POOLX_END_ADDR (pool), pool_end_reg.u64); + } + + bufp = (char *)buffer; +while (num_blocks--) { +cvmx_fpa1_free (bufp, pool,0 ); + cvmx_fpa1_pool_info[pool].buffer_count++; + bufp += block_size; + } +return 0 ; +} + +/** +* @INTERNAL +* +* Setup a legacy FPA pool +*/ +static int cvmx_fpa1_pool_init (cvmx_fpa1_pool_t pool_id,int num_blocks, +int block_size,void *buffer) +{ +int max_pool =cvmx_fpa_get_max_pools (); + +if (pool_id <0 || pool_id >= max_pool) { +printf ("ERROR: %s pool %d invalid\n" , __func__, pool_id); +return -1 ; + } + +if (!cvmx_fpa1_pool_info) +cvmx_fpa_global_init_node (0 ); + +if (debug) +debug ("%s: initializing info pool %d\n" , __func__, pool_id); + + cvmx_fpa1_pool_info[pool_id].size = block_size; + cvmx_fpa1_pool_info[pool_id].buffer_count =0 ; + +if (debug) +debug ("%s: enabling unit for pool %d\n" , __func__, pool_id); + +return 0 ; +} + +/** +* Initialize global configuration for FPA block for specified node. +* +* @param node is the node number +* +* @note this function sets the initial QoS averaging timing parameters, +* for the entire FPA unit (per node), which may be overridden on a +* per AURA basis. +*/ +int cvmx_fpa_global_init_node (int node) +{ +/* There are just the initial parameter values */ +#define FPA_RED_AVG_DLY 1 +#define FPA_RED_LVL_DLY 3 +#define FPA_QOS_AVRG 0 +/* Setting up avg_dly and prb_dly, enable bits */ +if (octeon_has_feature (OCTEON_FEATURE_FPA3 )) { +char pool_info_name[32 ] ="cvmx_fpa3_pools_" ; +char aura_info_name[32 ] ="cvmx_fpa3_auras_" ; +char ns[2 ] ="0" ; + + ns[0 ] += node; +strcat (pool_info_name, ns); +strcat (aura_info_name, ns); + +cvmx_fpa3_config_red_params (node,FPA_QOS_AVRG ,FPA_RED_LVL_DLY , +FPA_RED_AVG_DLY ); + +/* Allocate the pinfo named block */ + cvmx_fpa3_pool_info[node] = (cvmx_fpa3_poolx_info_t *) +cvmx_bootmem_alloc_named_range_once ( +sizeof (cvmx_fpa3_pool_info[0 ][0 ]) * +cvmx_fpa3_num_pools (), +0 ,0 ,0 , pool_info_name,NULL ); + + cvmx_fpa3_aura_info[node] = (cvmx_fpa3_aurax_info_t *) +cvmx_bootmem_alloc_named_range_once ( +sizeof (cvmx_fpa3_aura_info[0 ][0 ]) * +cvmx_fpa3_num_auras (), +0 ,0 ,0 , aura_info_name,NULL ); + +//XXX add allocation error check + +/* Setup zero_pool on this node */ +cvmx_fpa3_reserve_pool (node,0 ); + cvmx_fpa3_pool_info[node][0 ].buf_count =0 ; + }else { +char pool_info_name[32 ] ="cvmx_fpa_pool" ; + +/* Allocate the pinfo named block */ + cvmx_fpa1_pool_info = (cvmx_fpa1_pool_info_t *) +cvmx_bootmem_alloc_named_range_once ( +sizeof (cvmx_fpa1_pool_info[0 ]) * +CVMX_FPA1_NUM_POOLS , +0 ,0 ,0 , pool_info_name,NULL ); + +cvmx_fpa1_enable (); + } + +return 0 ; +} + +static void __memset_u64 (u64 *ptr,u64 pattern,unsigned int words) +{ +while (words--) + *ptr++ = pattern; +} + +/** +* @INTERNAL +* Initialize pool pointer-storage memory +* +* Unlike legacy FPA, which used free buffers to store pointers that +* exceed on-chip memory, FPA3 requires a dedicated memory buffer for +* free pointer stack back-store. +* +* @param pool - pool to initialize +* @param mem_node - if memory should be allocated from a different node +* @param max_buffer_cnt - maximum block capacity of pool +* @param align - buffer alignment mode, +* current FPA_NATURAL_ALIGNMENT is supported +* @param buffer_sz - size of buffers in pool +*/ +static int cvmx_fpa3_pool_stack_init (cvmx_fpa3_pool_t pool, +unsigned int mem_node, +unsigned int max_buffer_cnt, +enum cvmx_fpa3_pool_alignment_e align, +unsigned int buffer_sz) +{ +cvmx_fpa3_poolx_info_t *pinfo; +u64 stack_paddr; +void *mem_ptr; +unsigned int stack_memory_size; +cvmx_fpa_poolx_cfg_t pool_cfg; +cvmx_fpa_poolx_fpf_marks_t pool_fpf_marks; + +if (debug) +debug ("%s: POOL %u:%u bufsz=%u maxbuf=%u\n" , __func__, + pool.node, pool.lpool, buffer_sz, max_buffer_cnt); + +if (!__cvmx_fpa3_pool_valid (pool)) { +printf ("ERROR: %s: POOL invalid\n" , __func__); +return -1 ; + } + + pinfo = cvmx_fpa3_pool_info[pool.node]; +if (!pinfo) { +printf ("ERROR: %s: FPA on node#%u is not initialized\n" , + __func__, pool.node); +return -1 ; + } + pinfo += pool.lpool; + +/* Calculate stack size based on buffer count with one line to spare */ + stack_memory_size = (max_buffer_cnt *128 ) /29 +128 +127 ; + +/* Increase stack size by band guard */ + stack_memory_size += guard_band_size <<1 ; + +/* Align size to cache line */ + stack_memory_size = (stack_memory_size >>7 ) <<7 ; + +/* Allocate internal stack */ + mem_ptr =cvmx_helper_mem_alloc (mem_node, stack_memory_size, +CVMX_CACHE_LINE_SIZE ); + +if (debug) +debug ("%s: stack_mem=%u ptr=%p\n" , __func__, stack_memory_size, + mem_ptr); + +if (!mem_ptr) { +debug ("ERROR: %sFailed to allocate stack for POOL %u:%u\n" , + __func__, pool.node, pool.lpool); +return -1 ; + } + +/* Initialize guard bands */ +if (guard_band_size >0 ) { +__memset_u64 ((u64 *)mem_ptr, magic_pattern, + guard_band_size >>3 ); +__memset_u64 ((u64 *)((char *)mem_ptr + stack_memory_size - + guard_band_size), + magic_pattern, guard_band_size >>3 ); + } + + pinfo->stack_paddr =cvmx_ptr_to_phys (mem_ptr); + pinfo->stack_psize = stack_memory_size; + +/* Calculate usable stack start */ + stack_paddr =cvmx_ptr_to_phys ((char *)mem_ptr + guard_band_size); + +csr_wr_node (pool.node,CVMX_FPA_POOLX_STACK_BASE (pool.lpool), + stack_paddr); +csr_wr_node (pool.node,CVMX_FPA_POOLX_STACK_ADDR (pool.lpool), + stack_paddr); + +/* Calculate usable stack end - start of last cache line */ + stack_paddr = stack_paddr + stack_memory_size - (guard_band_size <<1 ); + +csr_wr_node (pool.node,CVMX_FPA_POOLX_STACK_END (pool.lpool), + stack_paddr); + +if (debug) +debug ("%s: Stack paddr %#llx - %#llx\n" , __func__, +CAST_ULL (csr_rd_node (pool.node,CVMX_FPA_POOLX_STACK_BASE ( + pool.lpool))), +CAST_ULL (csr_rd_node (pool.node,CVMX_FPA_POOLX_STACK_END ( + pool.lpool)))); + +/* Setup buffer size for this pool until it is shutdown */ + pinfo->buf_size = buffer_sz; + + pool_cfg.u64 =0 ; + pool_cfg.cn78xx.buf_size = buffer_sz >>7 ; + pool_cfg.cn78xx.l_type =0x2 ; + pool_cfg.cn78xx.ena =0 ; +if (align ==FPA_NATURAL_ALIGNMENT ) + pool_cfg.cn78xx.nat_align =1 ; + +/* FPA-26117, FPA-22443 */ + pool_fpf_marks.u64 = +csr_rd_node (pool.node,CVMX_FPA_POOLX_FPF_MARKS (pool.lpool)); + pool_fpf_marks.s.fpf_rd =0x80 ; +csr_wr_node (pool.node,CVMX_FPA_POOLX_FPF_MARKS (pool.lpool), + pool_fpf_marks.u64); + +csr_wr_node (pool.node,CVMX_FPA_POOLX_CFG (pool.lpool), pool_cfg.u64); + pool_cfg.cn78xx.ena =1 ; +csr_wr_node (pool.node,CVMX_FPA_POOLX_CFG (pool.lpool), pool_cfg.u64); + +/* Pool is now ready to be filled up */ +return 0 ; +} + +/** +* Create an FPA POOL and fill it up with buffers +* +* @param node is the node number for the pool and memory location +* @param desired_pool is the local pool number desired +* or -1 for first available +* @param name is the symbolic name to assign the POOL +* @param block_size is the size of all buffers held in this POOL +* @param num_blocks is the number of free buffers to fill into the POOL +* @param buffer is an optionally caller-supplied memory for the buffers +* or NULL to cause the buffer memory to be allocated automatically. +* @return the POOL handle +* +* Note: if the buffer memory is supplied by caller, the application +* will be responsable to free this memory. +* +* Only supported on CN78XX. +*/ +cvmx_fpa3_pool_t cvmx_fpa3_setup_fill_pool (int node,int desired_pool, +const char *name, +unsigned int block_size, +unsigned int num_blocks, +void *buffer) +{ +cvmx_fpa3_pool_t pool; +unsigned int mem_node; +int rc; + +if (node <0 ) + node =cvmx_get_node_num (); + +if (debug) +debug ("%s: desired pool=%d bufsize=%u cnt=%u '%s'\n" , __func__, + desired_pool, block_size, num_blocks, name); + +/* Use memory from the node local to the AURA/POOL */ + mem_node = node; + +if (num_blocks ==0 || num_blocks >1 <<30 ) { +printf ("ERROR: %s: invalid block count %u\n" , __func__, + num_blocks); +return CVMX_FPA3_INVALID_POOL ; + } + +/* +* Check for block size validity: +* With user-supplied buffer, can't increase block size, +* so make sure it is at least 128, and is aligned to 128 +* For all cases make sure it is not too big +*/ +if ((buffer && (block_size <CVMX_CACHE_LINE_SIZE || + (block_size & (CVMX_CACHE_LINE_SIZE -1 )))) || + (block_size > (1 <<17 ))) { +printf ("ERROR: %s: invalid block size %u\n" , __func__, + block_size); +return CVMX_FPA3_INVALID_POOL ; + } + +if (block_size <CVMX_CACHE_LINE_SIZE ) + block_size =CVMX_CACHE_LINE_SIZE ; + +/* Reserve POOL */ + pool =cvmx_fpa3_reserve_pool (node, desired_pool); + +if (!__cvmx_fpa3_pool_valid (pool)) { +printf ("ERROR: %s: POOL %u:%d not available\n" , __func__, node, + desired_pool); +return CVMX_FPA3_INVALID_POOL ; + } + +/* Initialize POOL with stack storage */ + rc =cvmx_fpa3_pool_stack_init (pool, mem_node, num_blocks, +FPA_NATURAL_ALIGNMENT , block_size); +if (rc <0 ) { +printf ("ERROR: %s: POOL %u:%u stack setup failed\n" , __func__, + pool.node, pool.lpool); +cvmx_fpa3_release_pool (pool); +return CVMX_FPA3_INVALID_POOL ; + } + +/* Populate the POOL with buffers */ + rc =cvmx_fpa3_pool_populate (pool, num_blocks, block_size, buffer, + mem_node); +if (rc <0 ) { +printf ("ERROR: %s: POOL %u:%u memory fill failed\n" , __func__, + pool.node, pool.lpool); +cvmx_fpa3_release_pool (pool); +return CVMX_FPA3_INVALID_POOL ; + } + +cvmx_fpa3_set_pool_name (pool, name); + +return pool; +} + +/** +* Attach an AURA to an existing POOL +* +* @param pool is the handle of the POOL to be attached +* @param desired_aura is the number of the AURA resired +* or -1 for the AURA to be automatically assigned +* @param name is a symbolic name for the new AURA +* @param block_size is the size of all buffers that will be handed +* out by this AURA +* @param num_blocks is the maximum number of buffers that can be +* handed out by this AURA, and can not exceed the number +* of buffers filled into the attached POOL +* @return the AURA handle +* +* Only supported on CN78XX. +*/ +cvmx_fpa3_gaura_t cvmx_fpa3_set_aura_for_pool (cvmx_fpa3_pool_t pool, +int desired_aura, +const char *name, +unsigned int block_size, +unsigned int num_blocks) +{ +cvmx_fpa3_gaura_t aura; +cvmx_fpa_poolx_available_t avail_reg; +const char *emsg; +int rc; + +if (debug) +debug ("%s: aura=%d bufsize=%u cnt=%u '%s'\n" , __func__, + desired_aura, block_size, num_blocks, name); + +if (!__cvmx_fpa3_pool_valid (pool)) { +printf ("ERROR: %s: POOL argument invalid\n" , __func__); +return CVMX_FPA3_INVALID_GAURA ; + } + +/* Verify the AURA buffer count limit is not above POOL buffer count */ + avail_reg.u64 = +csr_rd_node (pool.node,CVMX_FPA_POOLX_AVAILABLE (pool.lpool)); +if (avail_reg.cn78xx.count < num_blocks) { +printf ("WARNING: %s: AURA %u:%u buffer count limit %u reduced to POOL available count %u\n" , + __func__, aura.node, aura.laura, num_blocks, + (unsigned int )avail_reg.cn78xx.count); + num_blocks = avail_reg.cn78xx.count; + } + +/* Reserve an AURA number, follow desired number */ + aura =cvmx_fpa3_reserve_aura (pool.node, desired_aura); + +if (!__cvmx_fpa3_aura_valid (aura)) { +printf ("ERROR: %s: AURA %u:%d not available\n" , __func__, + pool.node, desired_aura); +return CVMX_FPA3_INVALID_GAURA ; + } + +/* Initialize AURA attached to the above POOL */ + rc =cvmx_fpa3_aura_cfg (aura, pool, num_blocks, num_blocks +1 ,0 ); +if (rc <0 ) { + emsg ="AURA configuration" ; + goto _fail; + } + +cvmx_fpa3_set_aura_name (aura, name); + +return aura; + +_fail: +printf ("ERROR: %s: %s\n" , __func__, emsg); +cvmx_fpa3_release_aura (aura); +return CVMX_FPA3_INVALID_GAURA ; +} + +/** +* Create a combination of an AURA and a POOL +* +* @param node is the node number for the pool and memory location +* @param desired_aura is the number of the AURA resired +* or -1 for the AURA to be automatically assigned +* @param name is a symbolic name for the new AURA +* @param block_size is the size of all buffers that will be handed +* out by this AURA +* @param num_blocks is the maximum number of buffers that can be +* handed out by this AURA, and can not exceed the number +* of buffers filled into the attached POOL +* @param buffer is an optionally caller-supplied memory for the buffers +* or NULL to cause the buffer memory to be allocated automatically. +* +* @return the AURA handle +* +* Note: if the buffer memory is supplied by caller, the application +* will be responsable to free this memory. +* The POOL number is always automatically assigned. +* +* Only supported on CN78XX. +*/ +cvmx_fpa3_gaura_t cvmx_fpa3_setup_aura_and_pool (int node,int desired_aura, +const char *name,void *buffer, +unsigned int block_size, +unsigned int num_blocks) +{ +cvmx_fpa3_gaura_t aura =CVMX_FPA3_INVALID_GAURA ; +cvmx_fpa3_pool_t pool =CVMX_FPA3_INVALID_POOL ; +const char *emsg ="" ; +unsigned int mem_node; +int rc; + +if (debug) +debug ("%s: aura=%d size=%u cnt=%u '%s'\n" , __func__, + desired_aura, block_size, num_blocks, name); + +if (node <0 ) + node =cvmx_get_node_num (); + +if (num_blocks ==0 || num_blocks >1 <<30 ) { +printf ("ERROR: %s: invalid block count %u\n" , __func__, + num_blocks); +return CVMX_FPA3_INVALID_GAURA ; + } + +/* Use memory from the node local to the AURA/POOL */ + mem_node = node; + +/* Reserve an AURA number, follow desired number */ + aura =cvmx_fpa3_reserve_aura (node, desired_aura); + +if (!__cvmx_fpa3_aura_valid (aura)) { + emsg ="AURA not available" ; + goto _fail; + } + +/* Reserve POOL dynamically to underpin this AURA */ + pool =cvmx_fpa3_reserve_pool (node,-1 ); + +if (!__cvmx_fpa3_pool_valid (pool)) { + emsg ="POOL not available" ; + goto _fail; + } + +/* +* Check for block size validity: +* With user-supplied buffer, can't increase block size, +* so make sure it is at least 128, and is aligned to 128 +* For all cases make sure it is not too big +*/ +if ((buffer && (block_size <CVMX_CACHE_LINE_SIZE || + (block_size & (CVMX_CACHE_LINE_SIZE -1 )))) || + block_size > (1 <<17 )) { +printf ("ERROR: %s: invalid block size %u\n" , __func__, + block_size); + emsg ="invalid block size" ; + goto _fail; + } + +if (block_size <CVMX_CACHE_LINE_SIZE ) + block_size =CVMX_CACHE_LINE_SIZE ; + +/* Initialize POOL with stack storage */ + rc =cvmx_fpa3_pool_stack_init (pool, mem_node, num_blocks, +FPA_NATURAL_ALIGNMENT , block_size); +if (rc <0 ) { + emsg ="POOL Stack setup" ; + goto _fail; + } + +/* Populate the AURA/POOL with buffers */ + rc =cvmx_fpa3_pool_populate (pool, num_blocks, block_size, buffer, + mem_node); +if (rc <0 ) { + emsg ="POOL buffer memory" ; + goto _fail; + } + +/* Initialize AURA attached to the above POOL */ + rc =cvmx_fpa3_aura_cfg (aura, pool, num_blocks, num_blocks +1 ,0 ); +if (rc <0 ) { + emsg ="AURA configuration" ; + goto _fail; + } + +cvmx_fpa3_set_aura_name (aura, name); +cvmx_fpa3_set_pool_name (pool, name); + +if (debug) +debug ("%s: AURA %u:%u ready, avail=%lld\n" , __func__, aura.node, + aura.laura,cvmx_fpa3_get_available (aura)); + +return aura; + +_fail: +printf ("ERROR: %s: Failed in %s\n" , __func__, emsg); +/* These will silently fail if POOL/AURA is not valid */ +cvmx_fpa3_release_aura (aura); +cvmx_fpa3_release_pool (pool); +return CVMX_FPA3_INVALID_GAURA ; +} + +/** +* Setup a legacy FPA pool +* +* @param desired_pool is the POOL number desired or -1 for automatic +* assignment +* @param name is the symbolic POOL name +* @param block_size is the size of all buffers held in this POOL +* @param num_blocks is the number of free buffers to fill into the POOL +* @param buffer is an optionally caller-supplied memory for the buffers +* or NULL to cause the buffer memory to be allocated automatically. +* @return pool number or -1 on error. +* +* Note: if the buffer memory is supplied by caller, the application +* will be responsable to free this memory. +*/ +int cvmx_fpa1_setup_pool (int desired_pool,const char *name,void *buffer, +unsigned int block_size,unsigned int num_blocks) +{ +cvmx_fpa1_pool_t pool =CVMX_FPA1_INVALID_POOL ; +int rc; + +if (debug) +debug ("%s: desired pool %d, name '%s', mem %p size %u count %u\n" , + __func__, desired_pool, name, buffer, block_size, + num_blocks); + +/* Reserve desired pool or get one dynamically */ + pool =cvmx_fpa1_reserve_pool (desired_pool); + +/* Validate reserved pool, if successful */ +if (pool <0 || pool >=cvmx_fpa_get_max_pools ()) { +/* global resources would have printed an error message here */ +return CVMX_FPA1_INVALID_POOL ; + } + +/* Initialize the pool */ + rc =cvmx_fpa1_pool_init (pool, num_blocks, block_size, buffer); +if (rc <0 ) { +printf ("ERROR: %s: failed pool %u init\n" , __func__, pool); +cvmx_fpa1_release_pool (pool); +return CVMX_FPA1_INVALID_POOL ; + } + + rc =cvmx_fpa1_fill_pool (pool, num_blocks, buffer); +if (rc <0 ) { +printf ("ERROR: %s: failed pool %u memory\n" , __func__, pool); +cvmx_fpa1_release_pool (pool); +return CVMX_FPA1_INVALID_POOL ; + } + +if (debug) +debug ("%s: pool %d filled up\b" , __func__, pool); + +cvmx_fpa_set_name (pool, name); +return pool; +} + +/** +* Setup an FPA pool with buffers +* +* @param pool is the POOL number desired or -1 for automatic assignment +* @param name is the symbolic POOL name +* @param buffer is an optionally caller-supplied memory for the buffers +* or NULL to cause the buffer memory to be allocated automatically. +* @param block_size is the size of all buffers held in this POOL +* @param num_blocks is the number of free buffers to fill into the POOL +* @param buffer is an optionally caller-supplied memory for the buffers +* or NULL to cause the buffer memory to be allocated automatically. +* +* @return pool number or -1 on error. +* +* Note: if the buffer memory is supplied by caller, the application +* will be responsable to free this memory. +* This function will work with CN78XX models in backward-compatible mode +*/ +int cvmx_fpa_setup_pool (int pool,const char *name,void *buffer, +u64 block_size,u64 num_blocks) +{ +if (octeon_has_feature (OCTEON_FEATURE_FPA3 )) { +cvmx_fpa3_gaura_t aura; + + aura =cvmx_fpa3_setup_aura_and_pool (-1 , pool, name, buffer, + block_size, num_blocks); +if (!__cvmx_fpa3_aura_valid (aura)) +return -1 ; +if (aura.laura >=CVMX_FPA1_NUM_POOLS && pool >=0 ) +printf ("WARNING: %s: AURA %u is out of range for backward-compatible operation\n" , + __func__, aura.laura); +return aura.laura; + }else { +return cvmx_fpa1_setup_pool (pool, name, buffer, block_size, + num_blocks); + } +}
Signature · 1 line
2.35.1
PATCH v2 30/52 mips: octeon: Add cvmx-ilk.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-ilk.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-ilk.c | 1199 ++++++++++++++++++++++++++++++ 1 file changed, 1199 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-ilk.c
arch/mips/mach-octeon/cvmx-ilk.c new file +1199 -0
@@ -0,0 +1,1199 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* Support library for the ILK +*/ + +#include <time.h> +#include <log.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-gserx-defs.h> +#include <mach/cvmx-ilk-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-hwpko.h> +#include <mach/cvmx-ilk.h> +#include <mach/cvmx-pki.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +/* +* global configurations. +* +* for cn68, the default is {0xf, 0xf0}. to disable the 2nd ILK, set +* cvmx_ilk_lane_mask[CVMX_NUM_ILK_INTF] = {0xff, 0x0} and +* cvmx_ilk_chans[CVMX_NUM_ILK_INTF] = {8, 0} +*/ +unsigned short cvmx_ilk_lane_mask[CVMX_MAX_NODES ][CVMX_NUM_ILK_INTF ] = { + [0 ...CVMX_MAX_NODES -1 ] = {0x000f ,0x00f0 } +}; + +int cvmx_ilk_chans[CVMX_MAX_NODES ][CVMX_NUM_ILK_INTF ] = { + [0 ...CVMX_MAX_NODES -1 ] = {8 ,8 } +}; + +static cvmx_ilk_intf_t cvmx_ilk_intf_cfg[CVMX_MAX_NODES ][CVMX_NUM_ILK_INTF ]; + +cvmx_ilk_LA_mode_t cvmx_ilk_LA_mode[CVMX_NUM_ILK_INTF ] = { {0 ,0 }, {0 ,0 } }; +/** +* User-overrideable callback function that returns whether or not an interface +* should use look-aside mode. +* +* @param interface - interface being checked +* @param channel - channel number, can be 0 or 1 or -1 to see if LA mode +* should be enabled for the interface. +* @return 0 to not use LA-mode, 1 to use LA-mode. +*/ +int cvmx_ilk_use_la_mode (int interface,int channel) +{ +if (OCTEON_IS_MODEL (OCTEON_CN68XX_PASS1_0 )) +return 0 ; + +if (interface >=CVMX_NUM_ILK_INTF ) { +debug ("ERROR: invalid interface=%d in %s\n" , + interface, __func__); +return -1 ; + } +return cvmx_ilk_LA_mode[interface].ilk_LA_mode; +} + +/** +* User-overrideable callback function that returns whether or not an interface +* in look-aside mode should enable the RX calendar. +* +* @param interface - interface to check +* @return 1 to enable RX calendar, 0 to disable RX calendar. +* +* NOTE: For the CN68XX pass 2.0 this will enable the RX calendar for interface +* 0 and not interface 1. It is up to the customer to override this behavior. +*/ +int cvmx_ilk_la_mode_enable_rx_calendar (int interface) +{ +/* There is an errata in the CN68XX pass 2.0 where if connected +* in a loopback configuration or back to back then only one interface +* can have the RX calendar enabled. +*/ +if (interface >=CVMX_NUM_ILK_INTF ) { +debug ("ERROR: invalid interface=%d in %s\n" , + interface, __func__); +return -1 ; + } +return cvmx_ilk_LA_mode[interface].ilk_LA_mode_cal_ena; +} + +/** +* Initialize and start the ILK interface. +* +* @param interface The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param lane_mask the lane group for this interface +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_start_interface (int interface,unsigned short lane_mask) +{ +int res =-1 ; +int other_intf, this_qlm, other_qlm; +unsigned short uni_mask; +cvmx_ilk_txx_cfg0_t ilk_txx_cfg0; +cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0; +cvmx_ilk_ser_cfg_t ilk_ser_cfg; +int node = (interface >>4 ) &0xf ; + + interface &=0xf ; + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +if (lane_mask ==0 ) +return res; + +/* check conflicts between 2 ilk interfaces. 1 lane can be assigned to 1 +* interface only +*/ + other_intf = !interface; +if (cvmx_ilk_lane_mask[node][other_intf] & lane_mask) { +debug ("ILK%d:%d: %s: lane assignment conflict\n" , node, + interface, __func__); +return res; + } + +/* check the legality of the lane mask. interface 0 can have 8 lanes, +* while interface 1 can have 4 lanes at most +*/ + uni_mask = lane_mask >> (interface *4 ); +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +cvmx_mio_qlmx_cfg_t mio_qlmx_cfg, other_mio_qlmx_cfg; + +if ((uni_mask !=0x1 && uni_mask !=0x3 && uni_mask !=0xf && + uni_mask !=0xff ) || + (interface ==1 && lane_mask >0xf0 )) { +debug ("ILK%d: %s: incorrect lane mask: 0x%x\n" , + interface, __func__, uni_mask); +return res; + } +/* check the availability of qlms. qlm_cfg = 001 means the chip +* is fused to give this qlm to ilk +*/ + this_qlm = interface +CVMX_ILK_QLM_BASE (); + other_qlm = other_intf +CVMX_ILK_QLM_BASE (); + mio_qlmx_cfg.u64 =csr_rd (CVMX_MIO_QLMX_CFG (this_qlm)); + other_mio_qlmx_cfg.u64 =csr_rd (CVMX_MIO_QLMX_CFG (other_qlm)); +if (mio_qlmx_cfg.s.qlm_cfg !=1 || + (uni_mask ==0xff && other_mio_qlmx_cfg.s.qlm_cfg !=1 )) { +debug ("ILK%d: %s: qlm unavailable\n" , interface, + __func__); +return res; + } +/* Has 8 lanes */ + lane_mask &=0xff ; + } + +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { +int qlm; +unsigned short lane_mask_all =0 ; + +/* QLM 4 - QLM 7 can be configured for ILK. Get the lane mask +* of all the qlms that are configured for ilk +*/ +for (qlm =4 ; qlm <8 ; qlm++) { +cvmx_gserx_cfg_t gserx_cfg; +cvmx_gserx_phy_ctl_t phy_ctl; + +/* Make sure QLM is powered and out of reset */ + phy_ctl.u64 = +csr_rd_node (node,CVMX_GSERX_PHY_CTL (qlm)); +if (phy_ctl.s.phy_pd || phy_ctl.s.phy_reset) +continue ; + +/* Make sure QLM is in ILK mode */ + gserx_cfg.u64 =csr_rd_node (node,CVMX_GSERX_CFG (qlm)); +if (gserx_cfg.s.ila) + lane_mask_all |= ((1 <<4 ) -1 ) + << (4 * (qlm -4 )); + } + +if ((lane_mask_all & lane_mask) != lane_mask) { +debug ("ILK%d: %s: incorrect lane mask: 0x%x\n" , + interface, __func__, lane_mask); +return res; + } + } + +/* power up the serdes */ + ilk_ser_cfg.u64 =csr_rd_node (node,CVMX_ILK_SER_CFG ); +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +if (ilk_ser_cfg.cn68xx.ser_pwrup ==0 ) { + ilk_ser_cfg.cn68xx.ser_rxpol_auto =1 ; + ilk_ser_cfg.cn68xx.ser_rxpol =0 ; + ilk_ser_cfg.cn68xx.ser_txpol =0 ; + ilk_ser_cfg.cn68xx.ser_reset_n =0xff ; + ilk_ser_cfg.cn68xx.ser_haul =0 ; + } + ilk_ser_cfg.cn68xx.ser_pwrup |= + ((interface ==0 ) && (lane_mask >0xf )) ? +0x3 : + (1 << interface); + } +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { + ilk_ser_cfg.cn78xx.ser_rxpol_auto =1 ; + ilk_ser_cfg.cn78xx.ser_rxpol =0 ; + ilk_ser_cfg.cn78xx.ser_txpol =0 ; + ilk_ser_cfg.cn78xx.ser_reset_n =0xffff ; + } +csr_wr_node (node,CVMX_ILK_SER_CFG , ilk_ser_cfg.u64); + +if (OCTEON_IS_MODEL (OCTEON_CN68XX_PASS2_X )) { +/* Workaround for Errata (G-16467) */ +int qlm = (interface) ?2 :1 ; +int start_qlm, end_qlm; + +/* Apply the workaround to both the QLMs if configured for x8 lanes */ +if (cvmx_pop (lane_mask) >4 ) { + start_qlm =1 ; + end_qlm =2 ; + }else { + start_qlm = qlm; + end_qlm = qlm; + } + +for (qlm = start_qlm; qlm <= end_qlm; qlm++) { +#ifdef CVMX_QLM_DUMP_STATE +debug ("%s:%d: ILK%d: Applying workaround for Errata G-16467\n" , + __func__, __LINE__, qlm); +cvmx_qlm_display_registers (qlm); +debug ("\n" ); +#endif +/* This workaround only applies to QLMs running ILK at 6.25Ghz */ +if ((cvmx_qlm_get_gbaud_mhz (qlm) ==6250 ) && + (cvmx_qlm_jtag_get (qlm,0 ,"clkf_byp" ) !=20 )) { +udelay (100 );/* Wait 100us for links to stabalize */ +cvmx_qlm_jtag_set (qlm,-1 ,"clkf_byp" ,20 ); +/* Allow the QLM to exit reset */ +cvmx_qlm_jtag_set (qlm,-1 ,"cfg_rst_n_clr" ,0 ); +udelay (100 );/* Wait 100us for links to stabalize */ +/* Allow TX on QLM */ +cvmx_qlm_jtag_set (qlm,-1 ,"cfg_tx_idle_set" , +0 ); + } +#ifdef CVMX_QLM_DUMP_STATE +debug ("%s:%d: ILK%d: Done applying workaround for Errata G-16467\n" , + __func__, __LINE__, qlm); +cvmx_qlm_display_registers (qlm); +debug ("\n\n" ); +#endif + } + } + +/* Initialize all calendar entries to xoff state */ +__cvmx_ilk_clear_cal ((node <<4 ) | interface); + +/* Enable ILK LA mode if configured. */ +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +if (cvmx_ilk_use_la_mode (interface,0 )) { +cvmx_ilk_txx_cfg1_t ilk_txx_cfg1; +cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1; + + ilk_txx_cfg1.u64 =csr_rd (CVMX_ILK_TXX_CFG1 (interface)); + ilk_rxx_cfg1.u64 =csr_rd (CVMX_ILK_RXX_CFG1 (interface)); + ilk_txx_cfg1.s.la_mode =1 ; + ilk_txx_cfg1.s.tx_link_fc_jam =1 ; + ilk_txx_cfg1.s.rx_link_fc_ign =1 ; + ilk_rxx_cfg1.s.la_mode =1 ; +csr_wr (CVMX_ILK_TXX_CFG1 (interface), ilk_txx_cfg1.u64); +csr_wr (CVMX_ILK_RXX_CFG1 (interface), ilk_rxx_cfg1.u64); + cvmx_ilk_intf_cfg[node][interface].la_mode = +1 ;/* Enable look-aside mode */ + }else { + cvmx_ilk_intf_cfg[node][interface].la_mode = +0 ;/* Disable look-aside mode */ + } + } +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) + cvmx_ilk_intf_cfg[node][interface].la_mode =0 ; + +/* configure the lane enable of the interface */ + ilk_txx_cfg0.u64 =csr_rd_node (node,CVMX_ILK_TXX_CFG0 (interface)); + ilk_rxx_cfg0.u64 =csr_rd_node (node,CVMX_ILK_RXX_CFG0 (interface)); + ilk_rxx_cfg0.s.lane_ena = lane_mask; + ilk_txx_cfg0.s.lane_ena = lane_mask; +csr_wr_node (node,CVMX_ILK_TXX_CFG0 (interface), ilk_txx_cfg0.u64); +csr_wr_node (node,CVMX_ILK_RXX_CFG0 (interface), ilk_rxx_cfg0.u64); + +/* For 10.3125Gbs data rate, set SER_LIMIT to 0x3ff for x8 & x12 mode */ +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { +cvmx_gserx_lane_mode_t lmode0, lmode1; + + lmode0.u64 =csr_rd_node (node,CVMX_GSERX_LANE_MODE (5 )); + lmode1.u64 =csr_rd_node (node,CVMX_GSERX_LANE_MODE (7 )); +if ((lmode0.s.lmode ==5 || lmode1.s.lmode ==5 ) && + (lane_mask ==0xfff || lane_mask ==0xfff0 || + lane_mask ==0xff || lane_mask ==0xff00 )) { +cvmx_ilk_txx_cfg1_t ilk_txx_cfg1; + + ilk_txx_cfg1.u64 = +csr_rd_node (node,CVMX_ILK_TXX_CFG1 (interface)); + ilk_txx_cfg1.s.ser_limit =0x3ff ; +csr_wr_node (node,CVMX_ILK_TXX_CFG1 (interface), + ilk_txx_cfg1.u64); + } + } + +/* write to local cache. for lane speed, if interface 0 has 8 lanes, +* assume both qlms have the same speed +*/ + cvmx_ilk_intf_cfg[node][interface].intf_en =1 ; + res =0 ; + +return res; +} + +/** +* set pipe group base and length for the interface +* +* @param xiface The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param pipe_base the base of the pipe group +* @param pipe_len the length of the pipe group +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_set_pipe (int xiface,int pipe_base,unsigned int pipe_len) +{ +int res =-1 ; +cvmx_ilk_txx_pipe_t ilk_txx_pipe; +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface -CVMX_ILK_GBL_BASE (); + +if (!(OCTEON_IS_MODEL (OCTEON_CN68XX ))) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +/* set them in ilk tx section */ + ilk_txx_pipe.u64 =csr_rd_node (xi.node,CVMX_ILK_TXX_PIPE (interface)); + ilk_txx_pipe.s.base = pipe_base; + ilk_txx_pipe.s.nump = pipe_len; +csr_wr_node (xi.node,CVMX_ILK_TXX_PIPE (interface), ilk_txx_pipe.u64); + res =0 ; + +return res; +} + +/** +* set logical channels for tx +* +* @param interface The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param pch pointer to an array of pipe-channel pair +* @param num_chs the number of entries in the pipe-channel array +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_tx_set_channel (int interface,cvmx_ilk_pipe_chan_t *pch, +unsigned int num_chs) +{ +int res =-1 ; +cvmx_ilk_txx_idx_pmap_t ilk_txx_idx_pmap; +cvmx_ilk_txx_mem_pmap_t ilk_txx_mem_pmap; +unsigned int i; + +if (!(OCTEON_IS_MODEL (OCTEON_CN68XX ))) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +if (!pch || num_chs >CVMX_ILK_MAX_PIPES ) +return res; + +if (cvmx_ilk_use_la_mode (interface,0 )) { + ilk_txx_idx_pmap.u64 =0 ; + ilk_txx_mem_pmap.u64 =0 ; +for (i =0 ; i < num_chs; i++) { + ilk_txx_idx_pmap.s.index = pch->pipe; + ilk_txx_mem_pmap.s.channel = pch->chan; + ilk_txx_mem_pmap.s.remap =1 ; +csr_wr (CVMX_ILK_TXX_IDX_PMAP (interface), + ilk_txx_idx_pmap.u64); +csr_wr (CVMX_ILK_TXX_MEM_PMAP (interface), + ilk_txx_mem_pmap.u64); + pch++; + } + }else { +/* write the pair to ilk tx */ + ilk_txx_mem_pmap.u64 =0 ; + ilk_txx_idx_pmap.u64 =0 ; +for (i =0 ; i < num_chs; i++) { + ilk_txx_idx_pmap.s.index = pch->pipe; + ilk_txx_mem_pmap.s.channel = pch->chan; +csr_wr (CVMX_ILK_TXX_IDX_PMAP (interface), + ilk_txx_idx_pmap.u64); +csr_wr (CVMX_ILK_TXX_MEM_PMAP (interface), + ilk_txx_mem_pmap.u64); + pch++; + } + } + res =0 ; + +return res; +} + +/** +* set pkind for rx +* +* @param xiface The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param chpknd pointer to an array of channel-pkind pair +* @param num_pknd the number of entries in the channel-pkind array +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_rx_set_pknd (int xiface,cvmx_ilk_chan_pknd_t *chpknd, +unsigned int num_pknd) +{ +int res =-1 ; +cvmx_ilk_rxf_idx_pmap_t ilk_rxf_idx_pmap; +unsigned int i; +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface -CVMX_ILK_GBL_BASE (); + +if (!(OCTEON_IS_MODEL (OCTEON_CN68XX ))) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +if (!chpknd || num_pknd >CVMX_ILK_MAX_PKNDS ) +return res; + + res =0 ; + +for (i =0 ; i < num_pknd; i++) { + ilk_rxf_idx_pmap.u64 =0 ; +/* write the pair to ilk rx. note the channels for different +* interfaces are given in *chpknd and interface is not used +* as a param +*/ +if (chpknd->chan <2 && +cvmx_ilk_use_la_mode (interface, chpknd->chan)) { + ilk_rxf_idx_pmap.s.index = + interface *256 +128 + chpknd->chan; +csr_wr (CVMX_ILK_RXF_IDX_PMAP , ilk_rxf_idx_pmap.u64); +csr_wr (CVMX_ILK_RXF_MEM_PMAP , chpknd->pknd); + } + ilk_rxf_idx_pmap.s.index = interface *256 + chpknd->chan; +csr_wr (CVMX_ILK_RXF_IDX_PMAP , ilk_rxf_idx_pmap.u64); +csr_wr (CVMX_ILK_RXF_MEM_PMAP , chpknd->pknd); + chpknd++; + } + +return res; +} + +/** +* configure calendar for rx +* +* @param intf The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param cal_depth the number of calendar entries +* @param pent pointer to calendar entries +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_rx_cal_conf (int intf,int cal_depth,cvmx_ilk_cal_entry_t *pent) +{ +int res =-1 , i; +cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0; +int num_entries; +int node = (intf >>4 ) &0xf ; +int interface = intf &0xf ; + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +if (cal_depth <CVMX_ILK_RX_MIN_CAL || cal_depth >CVMX_ILK_MAX_CAL || + (OCTEON_IS_MODEL (OCTEON_CN68XX ) && !pent)) +return res; + +/* mandatory link-level fc as workarounds for ILK-15397 and +* ILK-15479 +*/ +/* TODO: test effectiveness */ + +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +/* Update the calendar for each channel */ +if ((cvmx_ilk_use_la_mode (interface,0 ) ==0 ) || + (cvmx_ilk_use_la_mode (interface,0 ) && +cvmx_ilk_la_mode_enable_rx_calendar (interface))) { +for (i =0 ; i < cal_depth; i++) { +__cvmx_ilk_write_rx_cal_entry ( + interface, i, pent[i].pipe_bpid); + } + } + +/* Update the depth */ + ilk_rxx_cfg0.u64 =csr_rd (CVMX_ILK_RXX_CFG0 (interface)); + num_entries =1 + cal_depth + (cal_depth -1 ) /15 ; + ilk_rxx_cfg0.s.cal_depth = num_entries; +if (cvmx_ilk_use_la_mode (interface,0 )) { + ilk_rxx_cfg0.s.mproto_ign =1 ; + ilk_rxx_cfg0.s.lnk_stats_ena =1 ; + ilk_rxx_cfg0.s.lnk_stats_wrap =1 ; + } +csr_wr (CVMX_ILK_RXX_CFG0 (interface), ilk_rxx_cfg0.u64); + } + +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { + ilk_rxx_cfg0.u64 = +csr_rd_node (node,CVMX_ILK_RXX_CFG0 (interface)); +/* +* Make sure cal_ena is 0 for programming the calendar table, +* as per Errata ILK-19398 +*/ + ilk_rxx_cfg0.s.cal_ena =0 ; +csr_wr_node (node,CVMX_ILK_RXX_CFG0 (interface), + ilk_rxx_cfg0.u64); + +for (i =0 ; i < cal_depth; i++) +__cvmx_ilk_write_rx_cal_entry (intf, i,0 ); + + ilk_rxx_cfg0.u64 = +csr_rd_node (node,CVMX_ILK_RXX_CFG0 (interface)); + num_entries =1 + cal_depth + (cal_depth -1 ) /15 ; + ilk_rxx_cfg0.s.cal_depth = num_entries; +csr_wr_node (node,CVMX_ILK_RXX_CFG0 (interface), + ilk_rxx_cfg0.u64); + } + +return 0 ; +} + +/** +* set high water mark for rx +* +* @param intf The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param hi_wm high water mark for this interface +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_rx_set_hwm (int intf,int hi_wm) +{ +int res =-1 ; +cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1; +int node = (intf >>4 ) &0xf ; +int interface = intf &0xf ; + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +if (hi_wm <=0 ) +return res; + +/* set the hwm */ + ilk_rxx_cfg1.u64 =csr_rd_node (node,CVMX_ILK_RXX_CFG1 (interface)); + ilk_rxx_cfg1.s.rx_fifo_hwm = hi_wm; +csr_wr_node (node,CVMX_ILK_RXX_CFG1 (interface), ilk_rxx_cfg1.u64); + res =0 ; + +return res; +} + +/** +* enable calendar for rx +* +* @param intf The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param cal_ena enable or disable calendar +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_rx_cal_ena (int intf,unsigned char cal_ena) +{ +int res =-1 ; +cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0; +int node = (intf >>4 ) &0xf ; +int interface = intf &0xf ; + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +if (cvmx_ilk_use_la_mode (interface,0 ) && + !cvmx_ilk_la_mode_enable_rx_calendar (interface)) +return 0 ; + +/* set the enable */ + ilk_rxx_cfg0.u64 =csr_rd_node (node,CVMX_ILK_RXX_CFG0 (interface)); + ilk_rxx_cfg0.s.cal_ena = cal_ena; +csr_wr_node (node,CVMX_ILK_RXX_CFG0 (interface), ilk_rxx_cfg0.u64); +csr_rd_node (node,CVMX_ILK_RXX_CFG0 (interface)); + res =0 ; + +return res; +} + +/** +* set up calendar for rx +* +* @param intf The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param cal_depth the number of calendar entries +* @param pent pointer to calendar entries +* @param hi_wm high water mark for this interface +* @param cal_ena enable or disable calendar +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_cal_setup_rx (int intf,int cal_depth,cvmx_ilk_cal_entry_t *pent, +int hi_wm,unsigned char cal_ena) +{ +int res =-1 ; + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + + res =cvmx_ilk_rx_cal_conf (intf, cal_depth, pent); +if (res <0 ) +return res; + + res =cvmx_ilk_rx_set_hwm (intf, hi_wm); +if (res <0 ) +return res; + + res =cvmx_ilk_rx_cal_ena (intf, cal_ena); +return res; +} + +/** +* configure calendar for tx +* +* @param intf The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param cal_depth the number of calendar entries +* @param pent pointer to calendar entries +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_tx_cal_conf (int intf,int cal_depth,cvmx_ilk_cal_entry_t *pent) +{ +int res =-1 , i; +cvmx_ilk_txx_cfg0_t ilk_txx_cfg0; +int num_entries; +int node = (intf >>4 ) &0xf ; +int interface = intf &0xf ; + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +if (cal_depth <CVMX_ILK_TX_MIN_CAL || cal_depth >CVMX_ILK_MAX_CAL || + (OCTEON_IS_MODEL (OCTEON_CN68XX ) && !pent)) +return res; + +/* mandatory link-level fc as workarounds for ILK-15397 and +* ILK-15479 +*/ +/* TODO: test effectiveness */ + +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +/* Update the calendar for each channel */ +for (i =0 ; i < cal_depth; i++) { +__cvmx_ilk_write_tx_cal_entry (interface, i, + pent[i].pipe_bpid); + } + +/* Set the depth (must be multiple of 8)*/ + ilk_txx_cfg0.u64 =csr_rd (CVMX_ILK_TXX_CFG0 (interface)); + num_entries =1 + cal_depth + (cal_depth -1 ) /15 ; + ilk_txx_cfg0.s.cal_depth = (num_entries +7 ) & ~7 ; +csr_wr (CVMX_ILK_TXX_CFG0 (interface), ilk_txx_cfg0.u64); + } + +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { + ilk_txx_cfg0.u64 = +csr_rd_node (node,CVMX_ILK_TXX_CFG0 (interface)); +/* +* Make sure cal_ena is 0 for programming the calendar table, +* as per Errata ILK-19398 +*/ + ilk_txx_cfg0.s.cal_ena =0 ; +csr_wr_node (node,CVMX_ILK_TXX_CFG0 (interface), + ilk_txx_cfg0.u64); + +for (i =0 ; i < cal_depth; i++) +__cvmx_ilk_write_tx_cal_entry (intf, i,0 ); + + ilk_txx_cfg0.u64 = +csr_rd_node (node,CVMX_ILK_TXX_CFG0 (interface)); + num_entries =1 + cal_depth + (cal_depth -1 ) /15 ; +/* cal_depth[2:0] needs to be zero, round up */ + ilk_txx_cfg0.s.cal_depth = (num_entries +7 ) &0x1f8 ; +csr_wr_node (node,CVMX_ILK_TXX_CFG0 (interface), + ilk_txx_cfg0.u64); + } + +return 0 ; +} + +/** +* enable calendar for tx +* +* @param intf The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param cal_ena enable or disable calendar +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_tx_cal_ena (int intf,unsigned char cal_ena) +{ +int res =-1 ; +cvmx_ilk_txx_cfg0_t ilk_txx_cfg0; +int node = (intf >>4 ) &0xf ; +int interface = intf &0xf ; + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + +/* set the enable */ + ilk_txx_cfg0.u64 =csr_rd_node (node,CVMX_ILK_TXX_CFG0 (interface)); + ilk_txx_cfg0.s.cal_ena = cal_ena; +csr_wr_node (node,CVMX_ILK_TXX_CFG0 (interface), ilk_txx_cfg0.u64); +csr_rd_node (node,CVMX_ILK_TXX_CFG0 (interface)); + res =0 ; + +return res; +} + +/** +* set up calendar for tx +* +* @param intf The identifier of the packet interface to configure and +* use as a ILK interface. cn68xx has 2 interfaces: ilk0 and +* ilk1. +* +* @param cal_depth the number of calendar entries +* @param pent pointer to calendar entries +* @param cal_ena enable or disable calendar +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_cal_setup_tx (int intf,int cal_depth,cvmx_ilk_cal_entry_t *pent, +unsigned char cal_ena) +{ +int res =-1 ; + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + + res =cvmx_ilk_tx_cal_conf (intf, cal_depth, pent); +if (res <0 ) +return res; + + res =cvmx_ilk_tx_cal_ena (intf, cal_ena); +return res; +} + +/* #define CVMX_ILK_STATS_ENA 1 */ +#ifdef CVMX_ILK_STATS_ENA +static void cvmx_ilk_reg_dump_rx (int intf) +{ +int i; +cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0; +cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1; +cvmx_ilk_rxx_int_t ilk_rxx_int; +cvmx_ilk_rxx_jabber_t ilk_rxx_jabber; +cvmx_ilk_rx_lnex_cfg_t ilk_rx_lnex_cfg; +cvmx_ilk_rx_lnex_int_t ilk_rx_lnex_int; +cvmx_ilk_gbl_cfg_t ilk_gbl_cfg; +cvmx_ilk_ser_cfg_t ilk_ser_cfg; +cvmx_ilk_rxf_idx_pmap_t ilk_rxf_idx_pmap; +cvmx_ilk_rxf_mem_pmap_t ilk_rxf_mem_pmap; +cvmx_ilk_rxx_idx_cal_t ilk_rxx_idx_cal; +cvmx_ilk_rxx_mem_cal0_t ilk_rxx_mem_cal0; +cvmx_ilk_rxx_mem_cal1_t ilk_rxx_mem_cal1; +int node = (intf >>4 ) &0xf ; +int interface = intf &0xf ; + + ilk_rxx_cfg0.u64 =csr_rd_node (node,CVMX_ILK_RXX_CFG0 (interface)); +debug ("ilk rxx cfg0: 0x%16lx\n" , ilk_rxx_cfg0.u64); + + ilk_rxx_cfg1.u64 =csr_rd_node (node,CVMX_ILK_RXX_CFG1 (interface)); +debug ("ilk rxx cfg1: 0x%16lx\n" , ilk_rxx_cfg1.u64); + + ilk_rxx_int.u64 =csr_rd_node (node,CVMX_ILK_RXX_INT (interface)); +debug ("ilk rxx int: 0x%16lx\n" , ilk_rxx_int.u64); +csr_wr_node (node,CVMX_ILK_RXX_INT (interface), ilk_rxx_int.u64); + + ilk_rxx_jabber.u64 =csr_rd_node (node,CVMX_ILK_RXX_JABBER (interface)); +debug ("ilk rxx jabber: 0x%16lx\n" , ilk_rxx_jabber.u64); + +#define LNE_NUM_DBG 4 +for (i =0 ; i <LNE_NUM_DBG ; i++) { + ilk_rx_lnex_cfg.u64 = +csr_rd_node (node,CVMX_ILK_RX_LNEX_CFG (i)); +debug ("ilk rx lnex cfg lane: %d 0x%16lx\n" , i, + ilk_rx_lnex_cfg.u64); + } + +for (i =0 ; i <LNE_NUM_DBG ; i++) { + ilk_rx_lnex_int.u64 = +csr_rd_node (node,CVMX_ILK_RX_LNEX_INT (i)); +debug ("ilk rx lnex int lane: %d 0x%16lx\n" , i, + ilk_rx_lnex_int.u64); +csr_wr_node (node,CVMX_ILK_RX_LNEX_INT (i), ilk_rx_lnex_int.u64); + } + + ilk_gbl_cfg.u64 =csr_rd_node (node,CVMX_ILK_GBL_CFG ); +debug ("ilk gbl cfg: 0x%16lx\n" , ilk_gbl_cfg.u64); + + ilk_ser_cfg.u64 =csr_rd_node (node,CVMX_ILK_SER_CFG ); +debug ("ilk ser cfg: 0x%16lx\n" , ilk_ser_cfg.u64); + +#define CHAN_NUM_DBG 8 +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { + ilk_rxf_idx_pmap.u64 =0 ; + ilk_rxf_idx_pmap.s.index = interface *256 ; + ilk_rxf_idx_pmap.s.inc =1 ; +csr_wr (CVMX_ILK_RXF_IDX_PMAP , ilk_rxf_idx_pmap.u64); +for (i =0 ; i <CHAN_NUM_DBG ; i++) { + ilk_rxf_mem_pmap.u64 =csr_rd (CVMX_ILK_RXF_MEM_PMAP ); +debug ("ilk rxf mem pmap chan: %3d 0x%16lx\n" , i, + ilk_rxf_mem_pmap.u64); + } + } +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { +cvmx_ilk_rxx_chax_t rxx_chax; + +for (i =0 ; i <CHAN_NUM_DBG ; i++) { + rxx_chax.u64 =csr_rd_node ( + node,CVMX_ILK_RXX_CHAX (i, interface)); +debug ("ilk chan: %d pki chan: 0x%x\n" , i, + rxx_chax.s.port_kind); + } + } + +#define CAL_NUM_DBG 2 +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { + ilk_rxx_idx_cal.u64 =0 ; + ilk_rxx_idx_cal.s.inc =1 ; +csr_wr (CVMX_ILK_RXX_IDX_CAL (interface), ilk_rxx_idx_cal.u64); +for (i =0 ; i <CAL_NUM_DBG ; i++) { + ilk_rxx_idx_cal.u64 = +csr_rd (CVMX_ILK_RXX_IDX_CAL (interface)); +debug ("ilk rxx idx cal: 0x%16lx\n" , + ilk_rxx_idx_cal.u64); + + ilk_rxx_mem_cal0.u64 = +csr_rd (CVMX_ILK_RXX_MEM_CAL0 (interface)); +debug ("ilk rxx mem cal0: 0x%16lx\n" , + ilk_rxx_mem_cal0.u64); + ilk_rxx_mem_cal1.u64 = +csr_rd (CVMX_ILK_RXX_MEM_CAL1 (interface)); +debug ("ilk rxx mem cal1: 0x%16lx\n" , + ilk_rxx_mem_cal1.u64); + } + } +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { +cvmx_ilk_rxx_cal_entryx_t rxx_cal_entryx; + +for (i =0 ; i <CAL_NUM_DBG ; i++) { + rxx_cal_entryx.u64 =csr_rd_node ( + node,CVMX_ILK_RXX_CAL_ENTRYX (i, interface)); +debug ("ilk rxx cal idx: %d\n" , i); +debug ("ilk rxx cal ctl: 0x%x\n" , rxx_cal_entryx.s.ctl); +debug ("ilk rxx cal pko chan: 0x%x\n" , + rxx_cal_entryx.s.channel); + } + } +} + +static void cvmx_ilk_reg_dump_tx (int intf) +{ +int i; +cvmx_ilk_txx_cfg0_t ilk_txx_cfg0; +cvmx_ilk_txx_cfg1_t ilk_txx_cfg1; +cvmx_ilk_txx_idx_pmap_t ilk_txx_idx_pmap; +cvmx_ilk_txx_mem_pmap_t ilk_txx_mem_pmap; +cvmx_ilk_txx_int_t ilk_txx_int; +cvmx_ilk_txx_pipe_t ilk_txx_pipe; +cvmx_ilk_txx_idx_cal_t ilk_txx_idx_cal; +cvmx_ilk_txx_mem_cal0_t ilk_txx_mem_cal0; +cvmx_ilk_txx_mem_cal1_t ilk_txx_mem_cal1; +int node = (intf >>4 ) &0xf ; +int interface = intf &0xf ; + + ilk_txx_cfg0.u64 =csr_rd_node (node,CVMX_ILK_TXX_CFG0 (interface)); +debug ("ilk txx cfg0: 0x%16lx\n" , ilk_txx_cfg0.u64); + + ilk_txx_cfg1.u64 =csr_rd_node (node,CVMX_ILK_TXX_CFG1 (interface)); +debug ("ilk txx cfg1: 0x%16lx\n" , ilk_txx_cfg1.u64); + +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { + ilk_txx_pipe.u64 =csr_rd (CVMX_ILK_TXX_PIPE (interface)); +debug ("ilk txx pipe: 0x%16lx\n" , ilk_txx_pipe.u64); + + ilk_txx_idx_pmap.u64 =0 ; + ilk_txx_idx_pmap.s.index = ilk_txx_pipe.s.base; + ilk_txx_idx_pmap.s.inc =1 ; +csr_wr (CVMX_ILK_TXX_IDX_PMAP (interface), ilk_txx_idx_pmap.u64); +for (i =0 ; i <CHAN_NUM_DBG ; i++) { + ilk_txx_mem_pmap.u64 = +csr_rd (CVMX_ILK_TXX_MEM_PMAP (interface)); +debug ("ilk txx mem pmap pipe: %3d 0x%16lx\n" , + ilk_txx_pipe.s.base + i, ilk_txx_mem_pmap.u64); + } + } + + ilk_txx_int.u64 =csr_rd_node (node,CVMX_ILK_TXX_INT (interface)); +debug ("ilk txx int: 0x%16lx\n" , ilk_txx_int.u64); + +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { + ilk_txx_idx_cal.u64 =0 ; + ilk_txx_idx_cal.s.inc =1 ; +csr_wr (CVMX_ILK_TXX_IDX_CAL (interface), ilk_txx_idx_cal.u64); +for (i =0 ; i <CAL_NUM_DBG ; i++) { + ilk_txx_idx_cal.u64 = +csr_rd (CVMX_ILK_TXX_IDX_CAL (interface)); +debug ("ilk txx idx cal: 0x%16lx\n" , + ilk_txx_idx_cal.u64); + + ilk_txx_mem_cal0.u64 = +csr_rd (CVMX_ILK_TXX_MEM_CAL0 (interface)); +debug ("ilk txx mem cal0: 0x%16lx\n" , + ilk_txx_mem_cal0.u64); + ilk_txx_mem_cal1.u64 = +csr_rd (CVMX_ILK_TXX_MEM_CAL1 (interface)); +debug ("ilk txx mem cal1: 0x%16lx\n" , + ilk_txx_mem_cal1.u64); + } + } +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { +cvmx_ilk_txx_cal_entryx_t txx_cal_entryx; + +for (i =0 ; i <CAL_NUM_DBG ; i++) { + txx_cal_entryx.u64 =csr_rd_node ( + node,CVMX_ILK_TXX_CAL_ENTRYX (i, interface)); +debug ("ilk txx cal idx: %d\n" , i); +debug ("ilk txx cal ctl: 0x%x\n" , txx_cal_entryx.s.ctl); +debug ("ilk txx cal pki chan: 0x%x\n" , + txx_cal_entryx.s.channel); + } + } +} +#endif + +/** +* show run time status +* +* @param interface The identifier of the packet interface to enable. cn68xx +* has 2 interfaces: ilk0 and ilk1. +* +* @return nothing +*/ +#ifdef CVMX_ILK_RUNTIME_DBG +void cvmx_ilk_runtime_status (int interface) +{ +cvmx_ilk_txx_cfg1_t ilk_txx_cfg1; +cvmx_ilk_txx_flow_ctl0_t ilk_txx_flow_ctl0; +cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1; +cvmx_ilk_rxx_int_t ilk_rxx_int; +cvmx_ilk_rxx_flow_ctl0_t ilk_rxx_flow_ctl0; +cvmx_ilk_rxx_flow_ctl1_t ilk_rxx_flow_ctl1; +cvmx_ilk_gbl_int_t ilk_gbl_int; + +debug ("\nilk run-time status: interface: %d\n" , interface); + + ilk_txx_cfg1.u64 =csr_rd_node (node,CVMX_ILK_TXX_CFG1 (interface)); +debug ("\nilk txx cfg1: 0x%16lx\n" , ilk_txx_cfg1.u64); +if (ilk_txx_cfg1.s.rx_link_fc) +debug ("link flow control received\n" ); +if (ilk_txx_cfg1.s.tx_link_fc) +debug ("link flow control sent\n" ); + +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { + ilk_txx_flow_ctl0.u64 = +csr_rd (CVMX_ILK_TXX_FLOW_CTL0 (interface)); +debug ("\nilk txx flow ctl0: 0x%16lx\n" , ilk_txx_flow_ctl0.u64); + } +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { +int i; +cvmx_ilk_txx_cha_xonx_t txx_cha_xonx; + +for (i =0 ; i <4 ; i++) { + txx_cha_xonx.u64 =csr_rd_node ( + node,CVMX_ILK_TXX_CHA_XONX (i, interface)); +debug ("\nilk txx cha xon: 0x%16lx\n" , txx_cha_xonx.u64); + } + } + + ilk_rxx_cfg1.u64 =csr_rd_node (node,CVMX_ILK_RXX_CFG1 (interface)); +debug ("\nilk rxx cfg1: 0x%16lx\n" , ilk_rxx_cfg1.u64); +debug ("rx fifo count: %d\n" , ilk_rxx_cfg1.s.rx_fifo_cnt); + + ilk_rxx_int.u64 =csr_rd_node (node,CVMX_ILK_RXX_INT (interface)); +debug ("\nilk rxx int: 0x%16lx\n" , ilk_rxx_int.u64); +if (ilk_rxx_int.s.pkt_drop_rxf) +debug ("rx fifo packet drop\n" ); +if (ilk_rxx_int.u64) +csr_wr_node (node,CVMX_ILK_RXX_INT (interface), ilk_rxx_int.u64); + +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { + ilk_rxx_flow_ctl0.u64 = +csr_rd (CVMX_ILK_RXX_FLOW_CTL0 (interface)); +debug ("\nilk rxx flow ctl0: 0x%16lx\n" , ilk_rxx_flow_ctl0.u64); + + ilk_rxx_flow_ctl1.u64 = +csr_rd (CVMX_ILK_RXX_FLOW_CTL1 (interface)); +debug ("\nilk rxx flow ctl1: 0x%16lx\n" , ilk_rxx_flow_ctl1.u64); + } +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { +int i; +cvmx_ilk_rxx_cha_xonx_t rxx_cha_xonx; + +for (i =0 ; i <4 ; i++) { + rxx_cha_xonx.u64 =csr_rd_node ( + node,CVMX_ILK_RXX_CHA_XONX (i, interface)); +debug ("\nilk rxx cha xon: 0x%16lx\n" , rxx_cha_xonx.u64); + } + } + + ilk_gbl_int.u64 =csr_rd_node (node,CVMX_ILK_GBL_INT ); +debug ("\nilk gbl int: 0x%16lx\n" , ilk_gbl_int.u64); +if (ilk_gbl_int.s.rxf_push_full) +debug ("rx fifo overflow\n" ); +if (ilk_gbl_int.u64) +csr_wr_node (node,CVMX_ILK_GBL_INT , ilk_gbl_int.u64); +} +#endif + +/** +* enable interface +* +* @param xiface The identifier of the packet interface to enable. cn68xx +* has 2 interfaces: ilk0 and ilk1. +* +* @return Zero on success, negative on failure. +*/ +int cvmx_ilk_enable (int xiface) +{ +int res =-1 ; +int retry_count =0 ; +cvmx_helper_link_info_t result; +cvmx_ilk_txx_cfg1_t ilk_txx_cfg1; +cvmx_ilk_rxx_cfg1_t ilk_rxx_cfg1; +#ifdef CVMX_ILK_STATS_ENA +cvmx_ilk_rxx_cfg0_t ilk_rxx_cfg0; +cvmx_ilk_txx_cfg0_t ilk_txx_cfg0; +#endif +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int node = xi.node; +int interface = xi.interface -CVMX_ILK_GBL_BASE (); + +if (!octeon_has_feature (OCTEON_FEATURE_ILK )) +return res; + +if (interface >=CVMX_NUM_ILK_INTF ) +return res; + + result.u64 =0 ; + +#ifdef CVMX_ILK_STATS_ENA +debug ("\n" ); +debug ("<<<< ILK%d: Before enabling ilk\n" , interface); +cvmx_ilk_reg_dump_rx (intf); +cvmx_ilk_reg_dump_tx (intf); +#endif + +/* RX packet will be enabled only if link is up */ + +/* TX side */ + ilk_txx_cfg1.u64 =csr_rd_node (node,CVMX_ILK_TXX_CFG1 (interface)); + ilk_txx_cfg1.s.pkt_ena =1 ; +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +if (cvmx_ilk_use_la_mode (interface,0 )) { + ilk_txx_cfg1.s.la_mode =1 ; + ilk_txx_cfg1.s.tx_link_fc_jam =1 ; + } + } +csr_wr_node (node,CVMX_ILK_TXX_CFG1 (interface), ilk_txx_cfg1.u64); +csr_rd_node (node,CVMX_ILK_TXX_CFG1 (interface)); + +#ifdef CVMX_ILK_STATS_ENA +/* RX side stats */ + ilk_rxx_cfg0.u64 =csr_rd_node (node,CVMX_ILK_RXX_CFG0 (interface)); + ilk_rxx_cfg0.s.lnk_stats_ena =1 ; +csr_wr_node (node,CVMX_ILK_RXX_CFG0 (interface), ilk_rxx_cfg0.u64); + +/* TX side stats */ + ilk_txx_cfg0.u64 =csr_rd_node (node,CVMX_ILK_TXX_CFG0 (interface)); + ilk_txx_cfg0.s.lnk_stats_ena =1 ; +csr_wr_node (node,CVMX_ILK_TXX_CFG0 (interface), ilk_txx_cfg0.u64); +#endif + +retry: + retry_count++; +if (retry_count >10 ) + goto out; + +/* Make sure the link is up, so that packets can be sent. */ + result =__cvmx_helper_ilk_link_get ( +cvmx_helper_get_ipd_port ((interface +CVMX_ILK_GBL_BASE ()),0 )); + +/* Small delay before another retry. */ +udelay (100 ); + + ilk_rxx_cfg1.u64 =csr_rd_node (node,CVMX_ILK_RXX_CFG1 (interface)); +if (ilk_rxx_cfg1.s.pkt_ena ==0 ) + goto retry; + +out: + +#ifdef CVMX_ILK_STATS_ENA +debug (">>>> ILK%d: After ILK is enabled\n" , interface); +cvmx_ilk_reg_dump_rx (intf); +cvmx_ilk_reg_dump_tx (intf); +#endif + +if (result.s.link_up) +return 0 ; + +return -1 ; +} + +/** +* Provide interface enable status +* +* @param xiface The identifier of the packet xiface to disable. cn68xx +* has 2 interfaces: ilk0 and ilk1. +* +* @return Zero, not enabled; One, enabled. +*/ +int cvmx_ilk_get_intf_ena (int xiface) +{ +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); +int interface = xi.interface -CVMX_ILK_GBL_BASE (); +return cvmx_ilk_intf_cfg[xi.node][interface].intf_en; +}
Signature · 1 line
2.35.1
PATCH v2 33/52 mips: octeon: Add cvmx-pki-resources.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-pki-resources.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-pki-resources.c | 285 +++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-pki-resources.c
arch/mips/mach-octeon/cvmx-pki-resources.c new file +285 -0
@@ -0,0 +1,285 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* PKI Support. +*/ + +#include <time.h> +#include <log.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-global-resources.h> + +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> + +#include <mach/cvmx-pki.h> +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +static s32 cvmx_pki_style_refcnt[CVMX_MAX_NODES ][CVMX_PKI_NUM_INTERNAL_STYLE ]; + +/** +* This function allocates/reserves a style from pool of global styles per node. +* @param node node to allocate style from. +* @param style style to allocate, if -1 it will be allocated +* first available style from style resource. If index is positive +* number and in range, it will try to allocate specified style. +* @return style number on success, +* -1 on alloc failure. +* -2 on resource already reserved. +*/ +int cvmx_pki_style_alloc (int node,int style) +{ +int rs; + +if (cvmx_create_global_resource_range (CVMX_GR_TAG_STYLE (node), +CVMX_PKI_NUM_INTERNAL_STYLE )) { +printf ("ERROR: Failed to create styles global resource\n" ); +return -1 ; + } +if (style >=0 ) { +/* Reserving specific style, use refcnt for sharing */ + rs =cvmx_atomic_fetch_and_add32 ( + &cvmx_pki_style_refcnt[node][style],1 ); +if (rs >0 ) +return CVMX_RESOURCE_ALREADY_RESERVED ; + + rs =cvmx_reserve_global_resource_range (CVMX_GR_TAG_STYLE (node), + style, style,1 ); +if (rs ==-1 ) { +/* This means the style is taken by another app */ +printf ("ERROR: style %d is reserved by another app\n" , + style); +cvmx_atomic_fetch_and_add32 ( + &cvmx_pki_style_refcnt[node][style],-1 ); +return CVMX_RESOURCE_ALLOC_FAILED ; + } + }else { +/* Allocate first available style */ + rs =cvmx_allocate_global_resource_range ( +CVMX_GR_TAG_STYLE (node), style,1 ,1 ); +if (rs <0 ) { +printf ("ERROR: Failed to allocate style, none available\n" ); +return CVMX_RESOURCE_ALLOC_FAILED ; + } + style = rs; +/* Increment refcnt for newly created style */ +cvmx_atomic_fetch_and_add32 (&cvmx_pki_style_refcnt[node][style], +1 ); + } +return style; +} + +/** +* This function frees a style from pool of global styles per node. +* @param node node to free style from. +* @param style style to free +* @return 0 on success, -1 on failure or +* if the style is shared a positive count of remaining users for this style. +*/ +int cvmx_pki_style_free (int node,int style) +{ +int rs; + + rs =cvmx_atomic_fetch_and_add32 (&cvmx_pki_style_refcnt[node][style], +-1 ); +if (rs >1 ) +return rs -1 ; + +if (cvmx_free_global_resource_range_with_base (CVMX_GR_TAG_STYLE (node), + style,1 ) ==-1 ) { +printf ("ERROR Failed to release style %d\n" , (int )style); +return -1 ; + } +return 0 ; +} + +/** +* This function allocates/reserves a cluster group from per node +cluster group resources. +* @param node node to allocate cluster group from. +@param cl_grp cluster group to allocate/reserve, if -1 , +* allocate any available cluster group. +* @return cluster group number +* -1 on alloc failure. +* -2 on resource already reserved. +*/ +int cvmx_pki_cluster_grp_alloc (int node,int cl_grp) +{ +int rs; + +if (node >=CVMX_MAX_NODES ) { +printf ("ERROR: Invalid node number %d\n" , node); +return -1 ; + } +if (cvmx_create_global_resource_range (CVMX_GR_TAG_CLUSTER_GRP (node), +CVMX_PKI_NUM_CLUSTER_GROUP )) { +printf ("ERROR: Failed to create Cluster group global resource\n" ); +return -1 ; + } +if (cl_grp >=0 ) { + rs =cvmx_reserve_global_resource_range ( +CVMX_GR_TAG_CLUSTER_GRP (node),0 , cl_grp,1 ); +if (rs ==-1 ) { +debug ("INFO: cl_grp %d is already reserved\n" , + (int )cl_grp); +return CVMX_RESOURCE_ALREADY_RESERVED ; + } + }else { + rs =cvmx_allocate_global_resource_range ( +CVMX_GR_TAG_CLUSTER_GRP (node),0 ,1 ,1 ); +if (rs ==-1 ) { +debug ("Warning: Failed to alloc cluster grp\n" ); +return CVMX_RESOURCE_ALLOC_FAILED ; + } + } + cl_grp = rs; +return cl_grp; +} + +/** +* This function allocates/reserves a pcam entry from node +* @param node node to allocate pcam entry from. +* @param index index of pacm entry (0-191), if -1 , +* allocate any available pcam entry. +* @param bank pcam bank where to allocate/reserve pcan entry from +* @param cluster_mask mask of clusters from which pcam entry is needed. +* @return pcam entry of -1 on failure +*/ +int cvmx_pki_pcam_entry_alloc (int node,int index,int bank,u64 cluster_mask) +{ +int rs =0 ; +unsigned int cluster; + +for (cluster =0 ; cluster <CVMX_PKI_NUM_CLUSTER ; cluster++) { +if ((cluster_mask & (1 << cluster)) ==0 ) +continue ; + rs =cvmx_create_global_resource_range ( +CVMX_GR_TAG_PCAM (node, cluster, bank), +CVMX_PKI_TOTAL_PCAM_ENTRY ); +if (rs !=0 ) { +printf ("ERROR: Failed to create pki pcam global resource\n" ); +return -1 ; + } +if (index >=0 ) + rs =cvmx_reserve_global_resource_range ( +CVMX_GR_TAG_PCAM (node, cluster, bank), cluster, + index,1 ); +else + rs =cvmx_allocate_global_resource_range ( +CVMX_GR_TAG_PCAM (node, cluster, bank), cluster, +1 ,1 ); +if (rs ==-1 ) { +printf ("ERROR: PCAM :index %d not available in cluster %d bank %d" , + (int )index, (int )cluster, bank); +return -1 ; + } + }/* for cluster */ + index = rs; +/* implement cluster handle for pass2, for now assume +all clusters will have same base index*/ +return index; +} + +/** +* This function allocates/reserves QPG table entries per node. +* @param node node number. +* @param base_offset base_offset in qpg table. If -1, first available +* qpg base_offset will be allocated. If base_offset is positive +* number and in range, it will try to allocate specified base_offset. +* @param count number of consecutive qpg entries to allocate. They will be consecutive +* from base offset. +* @return qpg table base offset number on success +* -1 on alloc failure. +* -2 on resource already reserved. +*/ +int cvmx_pki_qpg_entry_alloc (int node,int base_offset,int count) +{ +int rs; + +if (cvmx_create_global_resource_range (CVMX_GR_TAG_QPG_ENTRY (node), +CVMX_PKI_NUM_QPG_ENTRY )) { +printf ("ERROR: Failed to create qpg_entry global resource\n" ); +return -1 ; + } +if (base_offset >=0 ) { + rs =cvmx_reserve_global_resource_range ( +CVMX_GR_TAG_QPG_ENTRY (node), base_offset, base_offset, + count); +if (rs ==-1 ) { +debug ("INFO: qpg entry %d is already reserved\n" , + (int )base_offset); +return CVMX_RESOURCE_ALREADY_RESERVED ; + } + }else { + rs =cvmx_allocate_global_resource_range ( +CVMX_GR_TAG_QPG_ENTRY (node), base_offset, count,1 ); +if (rs ==-1 ) { +printf ("ERROR: Failed to allocate qpg entry\n" ); +return CVMX_RESOURCE_ALLOC_FAILED ; + } + } + base_offset = rs; +return base_offset; +} + +/** +* This function frees QPG table entries per node. +* @param node node number. +* @param base_offset base_offset in qpg table. If -1, first available +* qpg base_offset will be allocated. If base_offset is positive +* number and in range, it will try to allocate specified base_offset. +* @param count number of consecutive qpg entries to allocate. They will be consecutive +* from base offset. +* @return qpg table base offset number on success, -1 on failure. +*/ +int cvmx_pki_qpg_entry_free (int node,int base_offset,int count) +{ +if (cvmx_free_global_resource_range_with_base ( +CVMX_GR_TAG_QPG_ENTRY (node), base_offset, count) ==-1 ) { +printf ("ERROR Failed to release qpg offset %d" , + (int )base_offset); +return -1 ; + } +return 0 ; +} + +int cvmx_pki_mtag_idx_alloc (int node,int idx) +{ +if (cvmx_create_global_resource_range (CVMX_GR_TAG_MTAG_IDX (node), +CVMX_PKI_NUM_MTAG_IDX )) { +printf ("ERROR: Failed to create MTAG-IDX global resource\n" ); +return -1 ; + } +if (idx >=0 ) { + idx =cvmx_reserve_global_resource_range ( +CVMX_GR_TAG_MTAG_IDX (node), idx, idx,1 ); +if (idx ==-1 ) { +debug ("INFO: MTAG index %d is already reserved\n" , + (int )idx); +return CVMX_RESOURCE_ALREADY_RESERVED ; + } + }else { + idx =cvmx_allocate_global_resource_range ( +CVMX_GR_TAG_MTAG_IDX (node), idx,1 ,1 ); +if (idx ==-1 ) { +printf ("ERROR: Failed to allocate MTAG index\n" ); +return CVMX_RESOURCE_ALLOC_FAILED ; + } + } +return idx; +}
Signature · 1 line
2.35.1
PATCH v2 34/52 mips: octeon: Add cvmx-pko.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-pko.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-pko.c | 788 +++++++++++++++++++++++++++++++ 1 file changed, 788 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-pko.c
arch/mips/mach-octeon/cvmx-pko.c new file +788 -0
@@ -0,0 +1,788 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* Support library for the hardware Packet Output unit. +*/ + +#include <errno.h> +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-gserx-defs.h> +#include <mach/cvmx-ilk-defs.h> +#include <mach/cvmx-iob-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-hwpko.h> +#include <mach/cvmx-ilk.h> +#include <mach/cvmx-pki.h> +#include <mach/cvmx-pko3.h> +#include <mach/cvmx-pko3-queue.h> +#include <mach/cvmx-pko3-resources.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-helper-bgx.h> +#include <mach/cvmx-helper-cfg.h> +#include <mach/cvmx-helper-util.h> +#include <mach/cvmx-helper-pki.h> +#include <mach/cvmx-helper-pko.h> + +DECLARE_GLOBAL_DATA_PTR ; + +#define CVMX_PKO_NQ_PER_PORT_MAX 32 + +static cvmx_pko_return_value_t cvmx_pko2_config_port (short ipd_port, +int base_queue, +int num_queues, +const u8 priority[]); + +static const int debug; + +/** +* Internal state of packet output +*/ + +/* +* PKO port iterator +* XXX this macro only works for 68XX +*/ + +#define pko_for_each_port (__p) \ + for (__p = 0; __p < CVMX_HELPER_CFG_MAX_PKO_PORT; __p++) \ + if (__cvmx_helper_cfg_pko_queue_base(__p) != \ + CVMX_HELPER_CFG_INVALID_VALUE) + +/* +* @INTERNAL +* +* Get INT for a port +* +* @param interface +* @param index +* @return the INT value on success and -1 on error +* +* This function is only for CN68XX. +*/ +static int __cvmx_pko_int (int interface,int index) +{ +cvmx_helper_cfg_assert (interface <CVMX_HELPER_MAX_IFACE ); +cvmx_helper_cfg_assert (index >=0 ); + +switch (interface) { +case 0 : +cvmx_helper_cfg_assert (index <4 ); +return index; +case 1 : +cvmx_helper_cfg_assert (index ==0 ); +return 4 ; +case 2 : +cvmx_helper_cfg_assert (index <4 ); +return index +8 ; +case 3 : +cvmx_helper_cfg_assert (index <4 ); +return index +0xC ; +case 4 : +cvmx_helper_cfg_assert (index <4 ); +return index +0x10 ; +case 5 : +cvmx_helper_cfg_assert (index <256 ); +return 0x1C ; +case 6 : +cvmx_helper_cfg_assert (index <256 ); +return 0x1D ; +case 7 : +cvmx_helper_cfg_assert (index <32 ); +return 0x1E ; +case 8 : +cvmx_helper_cfg_assert (index <8 ); +return 0x1F ; + } + +return -1 ; +} + +int cvmx_pko_get_base_pko_port (int interface,int index) +{ +if (octeon_has_feature (OCTEON_FEATURE_CN78XX_WQE )) +return cvmx_helper_get_ipd_port (interface, index); +else if (octeon_has_feature (OCTEON_FEATURE_PKND )) +return __cvmx_helper_cfg_pko_port_base (interface, index); +else +return cvmx_helper_get_ipd_port (interface, index); +} + +int cvmx_pko_get_base_queue (int port) +{ +if (octeon_has_feature (OCTEON_FEATURE_CN78XX_WQE )) { +return cvmx_pko3_get_queue_base (port); + }else if (octeon_has_feature (OCTEON_FEATURE_PKND )) { +return __cvmx_helper_cfg_pko_queue_base ( +cvmx_helper_cfg_ipd2pko_port_base (port)); + }else { +if (port <48 ) +return cvmx_pko_queue_table[port].ccppp_queue_base; +else +return CVMX_PKO_ILLEGAL_QUEUE ; + } +} + +int cvmx_pko_get_num_queues (int port) +{ +if (octeon_has_feature (OCTEON_FEATURE_CN78XX_WQE )) { +return cvmx_pko3_get_queue_num (port); + }else if (octeon_has_feature (OCTEON_FEATURE_PKND )) { +return __cvmx_helper_cfg_pko_queue_num ( +cvmx_helper_cfg_ipd2pko_port_base (port)); + }else { +if (port <48 ) +return cvmx_pko_queue_table[port].ccppp_num_queues; + } +return 0 ; +} + +/* +* Allocate memory for PKO engines. +* +* @param engine is the PKO engine ID. +* @return # of 2KB-chunks allocated to this PKO engine. +*/ +static int __cvmx_pko_memory_per_engine_o68 (int engine) +{ +/* CN68XX has 40KB to devide between the engines in 2KB chunks */ +int max_engine; +int size_per_engine; +int size; + + max_engine =__cvmx_helper_cfg_pko_max_engine (); + size_per_engine =40 /2 / max_engine; + +if (engine >= max_engine) +/* Unused engines get no space */ + size =0 ; +else if (engine == max_engine -1 ) +/* +* The last engine gets all the space lost by rounding. This means +* the ILK gets the most space +*/ + size =40 /2 - engine * size_per_engine; +else +/* All other engines get the same space */ + size = size_per_engine; + +return size; +} + +/* +* Setup one-to-one mapping between PKO2 iport and eport. +* @INTERNAL +*/ +static void __cvmx_pko2_chip_init (void ) +{ +int i; +int interface, index, port; +cvmx_helper_interface_mode_t mode; +union cvmx_pko_mem_iport_ptrs config; + +/* +* Initialize every iport with the invalid eid. +*/ +#define CVMX_O68_PKO2_INVALID_EID 31 + config.u64 =0 ; + config.s.eid =CVMX_O68_PKO2_INVALID_EID ; +for (i =0 ; i <CVMX_HELPER_CFG_MAX_PKO_PORT ; i++) { + config.s.ipid = i; +csr_wr (CVMX_PKO_MEM_IPORT_PTRS , config.u64); + } + +/* +* Set up PKO_MEM_IPORT_PTRS +*/ +pko_for_each_port (port) { + interface =__cvmx_helper_cfg_pko_port_interface (port); + index =__cvmx_helper_cfg_pko_port_index (port); + mode =cvmx_helper_interface_get_mode (interface); + +if (mode ==CVMX_HELPER_INTERFACE_MODE_DISABLED ) +continue ; + + config.s.ipid = port; + config.s.qos_mask =0xff ; + config.s.crc =__cvmx_helper_get_has_fcs (interface); + config.s.min_pkt =__cvmx_helper_get_pko_padding (interface); + config.s.intr =__cvmx_pko_int (interface, index); + config.s.eid =__cvmx_helper_cfg_pko_port_eid (port); + config.s.pipe = (mode ==CVMX_HELPER_INTERFACE_MODE_LOOP ) ? + index : + port; +csr_wr (CVMX_PKO_MEM_IPORT_PTRS , config.u64); + } +} + +int __cvmx_pko_get_pipe (int interface,int index) +{ +/* The loopback ports do not have pipes */ +if (cvmx_helper_interface_get_mode (interface) == +CVMX_HELPER_INTERFACE_MODE_LOOP ) +return -1 ; +/* We use pko_port as the pipe. See __cvmx_pko_port_map_o68(). */ +return cvmx_helper_get_pko_port (interface, index); +} + +static void __cvmx_pko1_chip_init (void ) +{ +int queue; +union cvmx_pko_mem_queue_ptrs config; +union cvmx_pko_reg_queue_ptrs1 config1; +const int port =CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID ; + +/* Initialize all queues to connect to port 63 (ILLEGAL_PID) */ +for (queue =0 ; queue <CVMX_PKO_MAX_OUTPUT_QUEUES ; queue++) { + config1.u64 =0 ; + config1.s.idx3 =0 ; + config1.s.qid7 = queue >>7 ; + + config.u64 =0 ; + config.s.tail =1 ; + config.s.index =0 ; + config.s.port = port; + config.s.queue = queue; + config.s.buf_ptr =0 ; + +csr_wr (CVMX_PKO_REG_QUEUE_PTRS1 , config1.u64); +csr_wr (CVMX_PKO_MEM_QUEUE_PTRS , config.u64); + } +} + +/** +* Call before any other calls to initialize the packet +* output system. This does chip global config, and should only be +* done by one core. +*/ +void cvmx_pko_hw_init (u8 pool,unsigned int bufsize) +{ +union cvmx_pko_reg_cmd_buf config; +union cvmx_iob_fau_timeout fau_to; +int i; + +if (debug) +debug ("%s: pool=%u bufsz=%u\n" , __func__, pool, bufsize); + +/* chip-specific setup. */ +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) +__cvmx_pko2_chip_init (); +else +__cvmx_pko1_chip_init (); + +/* +* Set the size of the PKO command buffers to an odd number of +* 64bit words. This allows the normal two word send to stay +* aligned and never span a command word buffer. +*/ + config.u64 =0 ; + config.s.pool = pool; + config.s.size = bufsize /8 -1 ; +csr_wr (CVMX_PKO_REG_CMD_BUF , config.u64); + +/* +* Disable tagwait FAU timeout. This needs to be done before +* anyone might start packet output using tags. +*/ + fau_to.u64 =0 ; + fau_to.s.tout_val =0xfff ; + fau_to.s.tout_enb =0 ; +csr_wr (CVMX_IOB_FAU_TIMEOUT , fau_to.u64); + +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +union cvmx_pko_reg_min_pkt min_pkt; + + min_pkt.u64 =0 ; + min_pkt.s.size1 =59 ; + min_pkt.s.size2 =59 ; + min_pkt.s.size3 =59 ; + min_pkt.s.size4 =59 ; + min_pkt.s.size5 =59 ; + min_pkt.s.size6 =59 ; + min_pkt.s.size7 =59 ; +csr_wr (CVMX_PKO_REG_MIN_PKT , min_pkt.u64); + } + +/* +* If we aren't using all of the queues optimize PKO's +* internal memory. +*/ +if (OCTEON_IS_OCTEON2 () ||OCTEON_IS_MODEL (OCTEON_CN70XX )) { +int max_queues =__cvmx_helper_cfg_pko_max_queue (); + +if (OCTEON_IS_MODEL (OCTEON_CN68XX ) && max_queues <=32 ) +csr_wr (CVMX_PKO_REG_QUEUE_MODE ,3 ); +else if (max_queues <=64 ) +csr_wr (CVMX_PKO_REG_QUEUE_MODE ,2 ); +else if (max_queues <=128 ) +csr_wr (CVMX_PKO_REG_QUEUE_MODE ,1 ); +else +csr_wr (CVMX_PKO_REG_QUEUE_MODE ,0 ); +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) { +for (i =0 ; i <2 ; i++) { +union cvmx_pko_reg_engine_storagex + engine_storage; + +#define PKO_ASSIGN_ENGINE_STORAGE (index) \ + engine_storage.s.engine##index = \ + __cvmx_pko_memory_per_engine_o68(16 * i + (index)) + + engine_storage.u64 =0 ; +PKO_ASSIGN_ENGINE_STORAGE (0 ); +PKO_ASSIGN_ENGINE_STORAGE (1 ); +PKO_ASSIGN_ENGINE_STORAGE (2 ); +PKO_ASSIGN_ENGINE_STORAGE (3 ); +PKO_ASSIGN_ENGINE_STORAGE (4 ); +PKO_ASSIGN_ENGINE_STORAGE (5 ); +PKO_ASSIGN_ENGINE_STORAGE (6 ); +PKO_ASSIGN_ENGINE_STORAGE (7 ); +PKO_ASSIGN_ENGINE_STORAGE (8 ); +PKO_ASSIGN_ENGINE_STORAGE (9 ); +PKO_ASSIGN_ENGINE_STORAGE (10 ); +PKO_ASSIGN_ENGINE_STORAGE (11 ); +PKO_ASSIGN_ENGINE_STORAGE (12 ); +PKO_ASSIGN_ENGINE_STORAGE (13 ); +PKO_ASSIGN_ENGINE_STORAGE (14 ); +PKO_ASSIGN_ENGINE_STORAGE (15 ); +csr_wr (CVMX_PKO_REG_ENGINE_STORAGEX (i), + engine_storage.u64); + } + } + } +} + +/** +* Enables the packet output hardware. It must already be +* configured. +*/ +void cvmx_pko_enable (void ) +{ +union cvmx_pko_reg_flags flags; + + flags.u64 =csr_rd (CVMX_PKO_REG_FLAGS ); +if (flags.s.ena_pko) +debug ("Warning: Enabling PKO when PKO already enabled.\n" ); + + flags.s.ena_dwb =cvmx_helper_cfg_opt_get (CVMX_HELPER_CFG_OPT_USE_DWB ); + flags.s.ena_pko =1 ; +/* +* always enable big endian for 3-word command. Does nothing +* for 2-word. +*/ + flags.s.store_be =1 ; +csr_wr (CVMX_PKO_REG_FLAGS , flags.u64); +} + +/** +* Configure a output port and the associated queues for use. +* +* @param port Port to configure. +* @param base_queue First queue number to associate with this port. +* @param num_queues Number of queues to associate with this port +* @param priority Array of priority levels for each queue. Values are +* allowed to be 0-8. A value of 8 get 8 times the traffic +* of a value of 1. A value of 0 indicates that no rounds +* will be participated in. These priorities can be changed +* on the fly while the pko is enabled. A priority of 9 +* indicates that static priority should be used. If static +* priority is used all queues with static priority must be +* contiguous starting at the base_queue, and lower numbered +* queues have higher priority than higher numbered queues. +* There must be num_queues elements in the array. +*/ +cvmx_pko_return_value_t cvmx_pko_config_port (int port,int base_queue, +int num_queues, +const u8 priority[]) +{ +cvmx_pko_return_value_t result_code; +int queue; +union cvmx_pko_mem_queue_ptrs config; +union cvmx_pko_reg_queue_ptrs1 config1; +int static_priority_base =-1 ; +int static_priority_end =-1 ; +int outputbuffer_pool = (int )cvmx_fpa_get_pko_pool (); +u64 outputbuffer_pool_size =cvmx_fpa_get_pko_pool_block_size (); + +/* This function is not used for CN68XX */ +if (OCTEON_IS_MODEL (OCTEON_CN68XX )) +return cvmx_pko2_config_port (port, base_queue, num_queues, + priority); + +if (debug) +debug ("%s: port=%d queue=%d-%d pri %#x %#x %#x %#x\n" , __func__, + port, base_queue, (base_queue + num_queues -1 ), + priority[0 ], priority[1 ], priority[2 ], priority[3 ]); + +/* The need to handle ILLEGAL_PID port argument +* is obsolete now, the code here can be simplified. +*/ + +if (port >=CVMX_PKO_NUM_OUTPUT_PORTS && + port !=CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID ) { +debug ("ERROR: %s: Invalid port %llu\n" , __func__, + (unsigned long long )port); +return CVMX_PKO_INVALID_PORT ; + } + +if (base_queue + num_queues >CVMX_PKO_MAX_OUTPUT_QUEUES ) { +debug ("ERROR: %s: Invalid queue range port = %lld base=%llu numques=%lld\n" , + __func__, (unsigned long long )port, + (unsigned long long )base_queue, + (unsigned long long )num_queues); +return CVMX_PKO_INVALID_QUEUE ; + } + +if (port !=CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID ) { +/* +* Validate the static queue priority setup and set +* static_priority_base and static_priority_end +* accordingly. +*/ +for (queue =0 ; queue < num_queues; queue++) { +/* Find first queue of static priority */ +int p_queue = queue %16 ; + +if (static_priority_base ==-1 && + priority[p_queue] ==CVMX_PKO_QUEUE_STATIC_PRIORITY ) + static_priority_base = queue; +/* Find last queue of static priority */ +if (static_priority_base !=-1 && + static_priority_end ==-1 && + priority[p_queue] != +CVMX_PKO_QUEUE_STATIC_PRIORITY && + queue) + static_priority_end = queue -1 ; +else if (static_priority_base !=-1 && + static_priority_end ==-1 && + queue == num_queues -1 ) +/* all queues're static priority */ + static_priority_end = queue; + +/* +* Check to make sure all static priority +* queues are contiguous. Also catches some +* cases of static priorites not starting at +* queue 0. +*/ +if (static_priority_end !=-1 && + (int )queue > static_priority_end && + priority[p_queue] == +CVMX_PKO_QUEUE_STATIC_PRIORITY ) { +debug ("ERROR: %s: Static priority queues aren't contiguous or don't start at base queue. q: %d, eq: %d\n" , + __func__, (int )queue, static_priority_end); +return CVMX_PKO_INVALID_PRIORITY ; + } + } +if (static_priority_base >0 ) { +debug ("ERROR: %s: Static priority queues don't start at base queue. sq: %d\n" , + __func__, static_priority_base); +return CVMX_PKO_INVALID_PRIORITY ; + } + } + +/* +* At this point, static_priority_base and static_priority_end +* are either both -1, or are valid start/end queue numbers +*/ + + result_code =CVMX_PKO_SUCCESS ; + +for (queue =0 ; queue < num_queues; queue++) { +u64 *buf_ptr =NULL ; +int p_queue = queue %16 ; + + config1.u64 =0 ; + config1.s.idx3 = queue >>3 ; + config1.s.qid7 = (base_queue + queue) >>7 ; + + config.u64 =0 ; + config.s.tail = queue == (num_queues -1 ); + config.s.index = queue; + config.s.port = port; + config.s.queue = base_queue + queue; + + config.s.static_p = static_priority_base >=0 ; + config.s.static_q = (int )queue <= static_priority_end; + config.s.s_tail = (int )queue == static_priority_end; +/* +* Convert the priority into an enable bit field. Try +* to space the bits out evenly so the packet don't +* get grouped up. +*/ +switch ((int )priority[p_queue]) { +case 0 : + config.s.qos_mask =0x00 ; +break ; +case 1 : + config.s.qos_mask =0x01 ; +break ; +case 2 : + config.s.qos_mask =0x11 ; +break ; +case 3 : + config.s.qos_mask =0x49 ; +break ; +case 4 : + config.s.qos_mask =0x55 ; +break ; +case 5 : + config.s.qos_mask =0x57 ; +break ; +case 6 : + config.s.qos_mask =0x77 ; +break ; +case 7 : + config.s.qos_mask =0x7f ; +break ; +case 8 : + config.s.qos_mask =0xff ; +break ; +case CVMX_PKO_QUEUE_STATIC_PRIORITY : + config.s.qos_mask =0xff ; +break ; +default : +debug ("ERROR: %s: Invalid priority %llu\n" , __func__, + (unsigned long long )priority[p_queue]); + config.s.qos_mask =0xff ; + result_code =CVMX_PKO_INVALID_PRIORITY ; +break ; + } + +if (port !=CVMX_PKO_MEM_QUEUE_PTRS_ILLEGAL_PID ) { +cvmx_cmd_queue_result_t cmd_res; + + cmd_res =cvmx_cmd_queue_initialize ( +CVMX_CMD_QUEUE_PKO (base_queue + queue), +CVMX_PKO_MAX_QUEUE_DEPTH , outputbuffer_pool, + outputbuffer_pool_size - +CVMX_PKO_COMMAND_BUFFER_SIZE_ADJUST * +8 ); +if (cmd_res !=CVMX_CMD_QUEUE_SUCCESS ) { +switch (cmd_res) { +case CVMX_CMD_QUEUE_NO_MEMORY : +debug ("ERROR: %s: Unable to allocate output buffer\n" , + __func__); +return CVMX_PKO_NO_MEMORY ; +case CVMX_CMD_QUEUE_ALREADY_SETUP : +debug ("ERROR: %s: Port already setup. port=%d\n" , + __func__, (int )port); +return CVMX_PKO_PORT_ALREADY_SETUP ; +case CVMX_CMD_QUEUE_INVALID_PARAM : +default : +debug ("ERROR: %s: Command queue initialization failed.\n" , + __func__); +return CVMX_PKO_CMD_QUEUE_INIT_ERROR ; + } + } + + buf_ptr = (u64 *)cvmx_cmd_queue_buffer ( +CVMX_CMD_QUEUE_PKO (base_queue + queue)); + config.s.buf_ptr =cvmx_ptr_to_phys (buf_ptr); + }else { + config.s.buf_ptr =0 ; + } + +CVMX_SYNCWS ; + +csr_wr (CVMX_PKO_REG_QUEUE_PTRS1 , config1.u64); +csr_wr (CVMX_PKO_MEM_QUEUE_PTRS , config.u64); + } + +return result_code; +} + +/* +* Configure queues for an internal port. +* @INTERNAL +* @param pko_port PKO internal port number +* @note this is the PKO2 equivalent to cvmx_pko_config_port() +*/ +static cvmx_pko_return_value_t cvmx_pko2_config_port (short ipd_port, +int base_queue, +int num_queues, +const u8 priority[]) +{ +int queue, pko_port; +int static_priority_base; +int static_priority_end; +union cvmx_pko_mem_iqueue_ptrs config; +u64 *buf_ptr =NULL ; +int outputbuffer_pool = (int )cvmx_fpa_get_pko_pool (); +u64 outputbuffer_pool_size =cvmx_fpa_get_pko_pool_block_size (); + + pko_port =cvmx_helper_cfg_ipd2pko_port_base (ipd_port); + +if (debug) +debug ("%s: ipd_port %d pko_iport %d qbase %d qnum %d\n" , + __func__, ipd_port, pko_port, base_queue, num_queues); + + static_priority_base =-1 ; + static_priority_end =-1 ; + +/* +* static queue priority validation +*/ +for (queue =0 ; queue < num_queues; queue++) { +int p_queue = queue %16 ; + +if (static_priority_base ==-1 && + priority[p_queue] ==CVMX_PKO_QUEUE_STATIC_PRIORITY ) + static_priority_base = queue; + +if (static_priority_base !=-1 && static_priority_end ==-1 && + priority[p_queue] !=CVMX_PKO_QUEUE_STATIC_PRIORITY && + queue) + static_priority_end = queue -1 ; +else if (static_priority_base !=-1 && + static_priority_end ==-1 && queue == num_queues -1 ) + static_priority_end = + queue;/* all queues are static priority */ + +/* +* Check to make sure all static priority queues are contiguous. +* Also catches some cases of static priorites not starting from +* queue 0. +*/ +if (static_priority_end !=-1 && + (int )queue > static_priority_end && + priority[p_queue] ==CVMX_PKO_QUEUE_STATIC_PRIORITY ) { +debug ("ERROR: %s: Static priority queues aren't contiguous or don't start at base queue. q: %d, eq: %d\n" , + __func__, (int )queue, static_priority_end); + } +if (static_priority_base >0 ) { +debug ("ERROR: %s: Static priority queues don't start at base queue. sq: %d\n" , + __func__, static_priority_base); + } + } + +/* +* main loop to set the fields of CVMX_PKO_MEM_IQUEUE_PTRS for +* each queue +*/ +for (queue =0 ; queue < num_queues; queue++) { +int p_queue = queue %8 ; + + config.u64 =0 ; + config.s.index = queue; + config.s.qid = base_queue + queue; + config.s.ipid = pko_port; + config.s.tail = (queue == (num_queues -1 )); + config.s.s_tail = (queue == static_priority_end); + config.s.static_p = (static_priority_base >=0 ); + config.s.static_q = (queue <= static_priority_end); + +/* +* Convert the priority into an enable bit field. +* Try to space the bits out evenly so the packet +* don't get grouped up. +*/ +switch ((int )priority[p_queue]) { +case 0 : + config.s.qos_mask =0x00 ; +break ; +case 1 : + config.s.qos_mask =0x01 ; +break ; +case 2 : + config.s.qos_mask =0x11 ; +break ; +case 3 : + config.s.qos_mask =0x49 ; +break ; +case 4 : + config.s.qos_mask =0x55 ; +break ; +case 5 : + config.s.qos_mask =0x57 ; +break ; +case 6 : + config.s.qos_mask =0x77 ; +break ; +case 7 : + config.s.qos_mask =0x7f ; +break ; +case 8 : + config.s.qos_mask =0xff ; +break ; +case CVMX_PKO_QUEUE_STATIC_PRIORITY : + config.s.qos_mask =0xff ; +break ; +default : +debug ("ERROR: %s: Invalid priority %llu\n" , __func__, + (unsigned long long )priority[p_queue]); + config.s.qos_mask =0xff ; +break ; + } + +/* +* The command queues +*/ + { +cvmx_cmd_queue_result_t cmd_res; + + cmd_res =cvmx_cmd_queue_initialize ( +CVMX_CMD_QUEUE_PKO (base_queue + queue), +CVMX_PKO_MAX_QUEUE_DEPTH , outputbuffer_pool, + (outputbuffer_pool_size - +CVMX_PKO_COMMAND_BUFFER_SIZE_ADJUST *8 )); + +if (cmd_res !=CVMX_CMD_QUEUE_SUCCESS ) { +switch (cmd_res) { +case CVMX_CMD_QUEUE_NO_MEMORY : +debug ("ERROR: %s: Unable to allocate output buffer\n" , + __func__); +break ; +case CVMX_CMD_QUEUE_ALREADY_SETUP : +debug ("ERROR: %s: Port already setup\n" , + __func__); +break ; +case CVMX_CMD_QUEUE_INVALID_PARAM : +default : +debug ("ERROR: %s: Command queue initialization failed." , + __func__); +break ; + } +debug (" pko_port%d base_queue%d num_queues%d queue%d.\n" , + pko_port, base_queue, num_queues, queue); + } + + buf_ptr = (u64 *)cvmx_cmd_queue_buffer ( +CVMX_CMD_QUEUE_PKO (base_queue + queue)); + config.s.buf_ptr =cvmx_ptr_to_phys (buf_ptr) >>7 ; + } + +CVMX_SYNCWS ; +csr_wr (CVMX_PKO_MEM_IQUEUE_PTRS , config.u64); + } + +/* Error detection is resirable here */ +return 0 ; +}
Signature · 1 line
2.35.1
PATCH v2 35/52 mips: octeon: Add cvmx-pko3.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-pko3.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-pko3.c | 786 ++++++++++++++++++++++++++++++ 1 file changed, 786 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-pko3.c
arch/mips/mach-octeon/cvmx-pko3.c new file +786 -0
@@ -0,0 +1,786 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +*/ + +#include <errno.h> +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-gserx-defs.h> +#include <mach/cvmx-ilk-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-hwpko.h> +#include <mach/cvmx-ilk.h> +#include <mach/cvmx-pki.h> +#include <mach/cvmx-pko3.h> +#include <mach/cvmx-pko3-queue.h> +#include <mach/cvmx-pko3-resources.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-helper-bgx.h> +#include <mach/cvmx-helper-cfg.h> +#include <mach/cvmx-helper-util.h> +#include <mach/cvmx-helper-pki.h> + +static const int debug; + +#define CVMX_DUMP_REGX (reg) \ + if (debug) \ + debug("%s=%#llx\n", #reg, (long long)csr_rd_node(node, reg)) + +static int cvmx_pko_setup_macs (int node); + +/* +* PKO descriptor queue operation error string +* +* @param dqstatus is the enumeration returned from hardware, +* PKO_QUERY_RTN_S[DQSTATUS]. +* +* @return static constant string error description +*/ +const char *pko_dqstatus_error (pko_query_dqstatus_t dqstatus) +{ +char *str ="PKO Undefined error" ; + +switch (dqstatus) { +case PKO_DQSTATUS_PASS : + str ="No error" ; +break ; +case PKO_DQSTATUS_BADSTATE : + str ="PKO queue not ready" ; +break ; +case PKO_DQSTATUS_NOFPABUF : + str ="PKO failed to allocate buffer from FPA" ; +break ; +case PKO_DQSTATUS_NOPKOBUF : + str ="PKO out of buffers" ; +break ; +case PKO_DQSTATUS_FAILRTNPTR : + str ="PKO failed to return buffer to FPA" ; +break ; +case PKO_DQSTATUS_ALREADY : + str ="PKO queue already opened" ; +break ; +case PKO_DQSTATUS_NOTCREATED : + str ="PKO queue has not been created" ; +break ; +case PKO_DQSTATUS_NOTEMPTY : + str ="PKO queue is not empty" ; +break ; +case PKO_DQSTATUS_SENDPKTDROP : + str ="Illegal PKO command construct" ; +break ; + } +return str; +} + +/* +* PKO global initialization for 78XX. +* +* @param node is the node on which PKO block is initialized. +* @return none. +*/ +int cvmx_pko3_hw_init_global (int node,uint16_t aura) +{ +cvmx_pko_dpfi_flush_t pko_flush; +cvmx_pko_dpfi_fpa_aura_t pko_aura; +cvmx_pko_dpfi_ena_t dpfi_enable; +cvmx_pko_ptf_iobp_cfg_t ptf_iobp_cfg; +cvmx_pko_pdm_cfg_t pko_pdm_cfg; +cvmx_pko_enable_t pko_enable; +cvmx_pko_dpfi_status_t dpfi_status; +cvmx_pko_status_t pko_status; +cvmx_pko_shaper_cfg_t shaper_cfg; +u64 cycles; +const unsigned int timeout =100 ;/* 100 milliseconds */ + +if (node != (aura >>10 )) +cvmx_printf ("WARNING: AURA vs PKO node mismatch\n" ); + + pko_enable.u64 =csr_rd_node (node,CVMX_PKO_ENABLE ); +if (pko_enable.s.enable) { +cvmx_printf ("WARNING: %s: PKO already enabled on node %u\n" , + __func__, node); +return 0 ; + } +/* Enable color awareness. */ + shaper_cfg.u64 =csr_rd_node (node,CVMX_PKO_SHAPER_CFG ); + shaper_cfg.s.color_aware =1 ; +csr_wr_node (node,CVMX_PKO_SHAPER_CFG , shaper_cfg.u64); + +/* Clear FLUSH command to be sure */ + pko_flush.u64 =0 ; + pko_flush.s.flush_en =0 ; +csr_wr_node (node,CVMX_PKO_DPFI_FLUSH , pko_flush.u64); + +/* set the aura number in pko, use aura node from parameter */ + pko_aura.u64 =0 ; + pko_aura.s.node = aura >>10 ; + pko_aura.s.laura = aura; +csr_wr_node (node,CVMX_PKO_DPFI_FPA_AURA , pko_aura.u64); + +CVMX_DUMP_REGX (CVMX_PKO_DPFI_FPA_AURA ); + + dpfi_enable.u64 =0 ; + dpfi_enable.s.enable =1 ; +csr_wr_node (node,CVMX_PKO_DPFI_ENA , dpfi_enable.u64); + +/* Prepare timeout */ + cycles =get_timer (0 ); + +/* Wait until all pointers have been returned */ +do { + pko_status.u64 =csr_rd_node (node,CVMX_PKO_STATUS ); +if (get_timer (cycles) > timeout) +break ; + }while (!pko_status.s.pko_rdy); + +if (!pko_status.s.pko_rdy) { + dpfi_status.u64 =csr_rd_node (node,CVMX_PKO_DPFI_STATUS ); +cvmx_printf ("ERROR: %s: PKO DFPI failed, PKO_STATUS=%#llx DPFI_STATUS=%#llx\n" , + __func__, (unsigned long long )pko_status.u64, + (unsigned long long )dpfi_status.u64); +return -1 ; + } + +/* Set max outstanding requests in IOBP for any FIFO.*/ + ptf_iobp_cfg.u64 =csr_rd_node (node,CVMX_PKO_PTF_IOBP_CFG ); +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) + ptf_iobp_cfg.s.max_read_size =0x10 ;/* Recommended by HRM.*/ +else +/* Reduce the value from recommended 0x10 to avoid +* getting "underflow" condition in the BGX TX FIFO. +*/ + ptf_iobp_cfg.s.max_read_size =3 ; +csr_wr_node (node,CVMX_PKO_PTF_IOBP_CFG , ptf_iobp_cfg.u64); + +/* Set minimum packet size per Ethernet standard */ + pko_pdm_cfg.u64 =0 ; + pko_pdm_cfg.s.pko_pad_minlen =0x3c ;/* 60 bytes before FCS */ +csr_wr_node (node,CVMX_PKO_PDM_CFG , pko_pdm_cfg.u64); + +/* Initialize MACs and FIFOs */ +cvmx_pko_setup_macs (node); + +/* enable PKO, although interfaces and queues are not up yet */ + pko_enable.u64 =0 ; + pko_enable.s.enable =1 ; +csr_wr_node (node,CVMX_PKO_ENABLE , pko_enable.u64); + +/* PKO_RDY set indicates successful initialization */ + pko_status.u64 =csr_rd_node (node,CVMX_PKO_STATUS ); +if (pko_status.s.pko_rdy) +return 0 ; + +cvmx_printf ("ERROR: %s: failed, PKO_STATUS=%#llx\n" , __func__, + (unsigned long long )pko_status.u64); +return -1 ; +} + +/* +* Configure Channel credit level in PKO. +* +* @param node is to specify the node to which this configuration is applied. +* @param level specifies the level at which pko channel queues will be configured, +* @return returns 0 if successful and -1 on failure. +*/ +int cvmx_pko3_channel_credit_level (int node,enum cvmx_pko3_level_e level) +{ +union cvmx_pko_channel_level channel_level; + + channel_level.u64 =0 ; + +if (level ==CVMX_PKO_L2_QUEUES ) + channel_level.s.cc_level =0 ; +else if (level ==CVMX_PKO_L3_QUEUES ) + channel_level.s.cc_level =1 ; +else +return -1 ; + +csr_wr_node (node,CVMX_PKO_CHANNEL_LEVEL , channel_level.u64); + +return 0 ; +} + +/** Open configured descriptor queues before queueing packets into them. +* +* @param node is to specify the node to which this configuration is applied. +* @param dq is the descriptor queue number to be opened. +* @return returns 0 on success or -1 on failure. +*/ +int cvmx_pko_dq_open (int node,int dq) +{ +cvmx_pko_query_rtn_t pko_status; +pko_query_dqstatus_t dqstatus; +cvmx_pko3_dq_params_t *p_param; + +if (debug) +debug ("%s: DEBUG: dq %u\n" , __func__, dq); + +__cvmx_pko3_dq_param_setup (node); + + pko_status =__cvmx_pko3_do_dma (node, dq,NULL ,0 ,CVMX_PKO_DQ_OPEN ); + + dqstatus = pko_status.s.dqstatus; + +if (dqstatus ==PKO_DQSTATUS_ALREADY ) +return 0 ; +if (dqstatus !=PKO_DQSTATUS_PASS ) { +cvmx_printf ("%s: ERROR: Failed to open dq :%u: %s\n" , __func__, + dq,pko_dqstatus_error (dqstatus)); +return -1 ; + } + +/* Setup the descriptor queue software parameters */ + p_param =cvmx_pko3_dq_parameters (node, dq); +if (p_param) { + p_param->depth = pko_status.s.depth; +if (p_param->limit ==0 ) + p_param->limit =1024 ;/* last-resort default */ + } + +return 0 ; +} + +/* +* PKO initialization of MACs and FIFOs +* +* All MACs are configured and assigned a specific FIFO, +* and each FIFO is configured with size for a best utilization +* of available FIFO resources. +* +* @param node is to specify which node's pko block for this setup. +* @return returns 0 if successful and -1 on failure. +* +* Note: This function contains model-specific code. +*/ +static int cvmx_pko_setup_macs (int node) +{ +unsigned int interface; +unsigned int port, num_ports; +unsigned int mac_num, fifo, pri, cnt; +cvmx_helper_interface_mode_t mode; +const unsigned int num_interfaces = +cvmx_helper_get_number_of_interfaces (); +u8 fifo_group_cfg[8 ]; +u8 fifo_group_spd[8 ]; +unsigned int fifo_count =0 ; +unsigned int max_fifos =0 , fifo_groups =0 ; +struct { +u8 fifo_cnt; +u8 fifo_id; +u8 pri; +u8 spd; +u8 mac_fifo_cnt; + } cvmx_pko3_mac_table[32 ]; + +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { + max_fifos =28 ;/* exclusive of NULL FIFO */ + fifo_groups =8 ;/* inclusive of NULL PTGF */ + } +if (OCTEON_IS_MODEL (OCTEON_CN73XX ) ||OCTEON_IS_MODEL (OCTEON_CNF75XX )) { + max_fifos =16 ; + fifo_groups =5 ; + } + +/* Initialize FIFO allocation table */ +memset (&fifo_group_cfg,0 ,sizeof (fifo_group_cfg)); +memset (&fifo_group_spd,0 ,sizeof (fifo_group_spd)); +memset (cvmx_pko3_mac_table,0 ,sizeof (cvmx_pko3_mac_table)); + +/* Initialize all MACs as disabled */ +for (mac_num =0 ; mac_num <__cvmx_pko3_num_macs (); mac_num++) { + cvmx_pko3_mac_table[mac_num].pri =0 ; + cvmx_pko3_mac_table[mac_num].fifo_cnt =0 ; + cvmx_pko3_mac_table[mac_num].fifo_id =0x1f ; + } + +for (interface =0 ; interface < num_interfaces; interface++) { +int xiface = +cvmx_helper_node_interface_to_xiface (node, interface); +/* Interface type for ALL interfaces */ + mode =cvmx_helper_interface_get_mode (xiface); + num_ports =cvmx_helper_interface_enumerate (xiface); + +if (mode ==CVMX_HELPER_INTERFACE_MODE_DISABLED ) +continue ; +/* +* Non-BGX interfaces: +* Each of these interfaces has a single MAC really. +*/ +if (mode ==CVMX_HELPER_INTERFACE_MODE_ILK || + mode ==CVMX_HELPER_INTERFACE_MODE_NPI || + mode ==CVMX_HELPER_INTERFACE_MODE_LOOP ) + num_ports =1 ; + +for (port =0 ; port < num_ports; port++) { +int i; + +/* Get the per-port mode for BGX-interfaces */ +if (interface <CVMX_HELPER_MAX_GMX ) + mode =cvmx_helper_bgx_get_mode (xiface, port); +/* In MIXED mode, LMACs can run different protocols */ + +/* convert interface/port to mac number */ + i =__cvmx_pko3_get_mac_num (xiface, port); +if (i <0 || i >= (int )__cvmx_pko3_num_macs ()) { +cvmx_printf ("%s: ERROR: interface %d:%u port %d has no MAC %d/%d\n" , + __func__, node, interface, port, i, +__cvmx_pko3_num_macs ()); +continue ; + } + +if (mode ==CVMX_HELPER_INTERFACE_MODE_RXAUI ) { +unsigned int bgx_fifo_size = +__cvmx_helper_bgx_fifo_size (xiface, + port); + + cvmx_pko3_mac_table[i].mac_fifo_cnt = + bgx_fifo_size / + (CVMX_BGX_TX_FIFO_SIZE /4 ); + cvmx_pko3_mac_table[i].pri =2 ; + cvmx_pko3_mac_table[i].spd =10 ; + cvmx_pko3_mac_table[i].fifo_cnt =2 ; + }else if (mode ==CVMX_HELPER_INTERFACE_MODE_XLAUI ) { +unsigned int bgx_fifo_size = +__cvmx_helper_bgx_fifo_size (xiface, + port); + + cvmx_pko3_mac_table[i].mac_fifo_cnt = + bgx_fifo_size / + (CVMX_BGX_TX_FIFO_SIZE /4 ); + cvmx_pko3_mac_table[i].pri =4 ; + cvmx_pko3_mac_table[i].spd =40 ; + cvmx_pko3_mac_table[i].fifo_cnt =4 ; + }else if (mode ==CVMX_HELPER_INTERFACE_MODE_XAUI ) { +unsigned int bgx_fifo_size = +__cvmx_helper_bgx_fifo_size (xiface, + port); + + cvmx_pko3_mac_table[i].mac_fifo_cnt = + bgx_fifo_size / + (CVMX_BGX_TX_FIFO_SIZE /4 ); + cvmx_pko3_mac_table[i].pri =3 ; + cvmx_pko3_mac_table[i].fifo_cnt =4 ; +/* DXAUI at 20G, or XAU at 10G */ + cvmx_pko3_mac_table[i].spd =20 ; + }else if (mode ==CVMX_HELPER_INTERFACE_MODE_XFI ) { +unsigned int bgx_fifo_size = +__cvmx_helper_bgx_fifo_size (xiface, + port); + + cvmx_pko3_mac_table[i].mac_fifo_cnt = + bgx_fifo_size / + (CVMX_BGX_TX_FIFO_SIZE /4 ); + cvmx_pko3_mac_table[i].pri =3 ; + cvmx_pko3_mac_table[i].fifo_cnt =4 ; + cvmx_pko3_mac_table[i].spd =10 ; + }else if (mode ==CVMX_HELPER_INTERFACE_MODE_LOOP ) { + cvmx_pko3_mac_table[i].fifo_cnt =1 ; + cvmx_pko3_mac_table[i].pri =1 ; + cvmx_pko3_mac_table[i].spd =1 ; + cvmx_pko3_mac_table[i].mac_fifo_cnt =1 ; + }else if (mode ==CVMX_HELPER_INTERFACE_MODE_ILK || + mode ==CVMX_HELPER_INTERFACE_MODE_SRIO ) { + cvmx_pko3_mac_table[i].fifo_cnt =4 ; + cvmx_pko3_mac_table[i].pri =3 ; +/* ILK/SRIO: speed depends on lane count */ + cvmx_pko3_mac_table[i].spd =40 ; + cvmx_pko3_mac_table[i].mac_fifo_cnt =4 ; + }else if (mode ==CVMX_HELPER_INTERFACE_MODE_NPI ) { + cvmx_pko3_mac_table[i].fifo_cnt =4 ; + cvmx_pko3_mac_table[i].pri =2 ; +/* Actual speed depends on PCIe lanes/mode */ + cvmx_pko3_mac_table[i].spd =50 ; +/* SLI Tx FIFO size to be revisitted */ + cvmx_pko3_mac_table[i].mac_fifo_cnt =1 ; + }else { +/* Other BGX interface modes: SGMII/RGMII */ +unsigned int bgx_fifo_size = +__cvmx_helper_bgx_fifo_size (xiface, + port); + + cvmx_pko3_mac_table[i].mac_fifo_cnt = + bgx_fifo_size / + (CVMX_BGX_TX_FIFO_SIZE /4 ); + cvmx_pko3_mac_table[i].fifo_cnt =1 ; + cvmx_pko3_mac_table[i].pri =1 ; + cvmx_pko3_mac_table[i].spd =1 ; + } + +if (debug) +debug ("%s: intf %d:%u port %u %s mac %02u cnt %u macfifo %uk spd %u\n" , + __func__, node, interface, port, +cvmx_helper_interface_mode_to_string (mode), + i, cvmx_pko3_mac_table[i].fifo_cnt, + cvmx_pko3_mac_table[i].mac_fifo_cnt *8 , + cvmx_pko3_mac_table[i].spd); + + }/* for port */ + }/* for interface */ + +/* Count the number of requested FIFOs */ +for (fifo_count = mac_num =0 ; mac_num <__cvmx_pko3_num_macs (); + mac_num++) + fifo_count += cvmx_pko3_mac_table[mac_num].fifo_cnt; + +if (debug) +debug ("%s: initially requested FIFO count %u\n" , __func__, + fifo_count); + +/* Heuristically trim FIFO count to fit in available number */ + pri =1 ; + cnt =4 ; +while (fifo_count > max_fifos) { +for (mac_num =0 ; mac_num <__cvmx_pko3_num_macs (); mac_num++) { +if (cvmx_pko3_mac_table[mac_num].fifo_cnt == cnt && + cvmx_pko3_mac_table[mac_num].pri <= pri) { + cvmx_pko3_mac_table[mac_num].fifo_cnt >>=1 ; + fifo_count -= + cvmx_pko3_mac_table[mac_num].fifo_cnt; + } +if (fifo_count <= max_fifos) +break ; + } +if (pri >=4 ) { + pri =1 ; + cnt >>=1 ; + }else { + pri++; + } +if (cnt ==0 ) +break ; + } + +if (debug) +debug ("%s: adjusted FIFO count %u\n" , __func__, fifo_count); + +/* Special case for NULL Virtual FIFO */ + fifo_group_cfg[fifo_groups -1 ] =0 ; +/* there is no MAC connected to NULL FIFO */ + +/* Configure MAC units, and attach a FIFO to each */ +for (fifo =0 , cnt =4 ; cnt >0 ; cnt >>=1 ) { +unsigned int g; + +for (mac_num =0 ; mac_num <__cvmx_pko3_num_macs (); mac_num++) { +if (cvmx_pko3_mac_table[mac_num].fifo_cnt < cnt || + cvmx_pko3_mac_table[mac_num].fifo_id !=0x1f ) +continue ; + +/* Attach FIFO to MAC */ + cvmx_pko3_mac_table[mac_num].fifo_id = fifo; + g = fifo >>2 ; +/* Sum speed for FIFO group */ + fifo_group_spd[g] += cvmx_pko3_mac_table[mac_num].spd; + +if (cnt ==4 ) + fifo_group_cfg[g] =4 ;/* 10k,0,0,0 */ +else if (cnt ==2 && (fifo &0x3 ) ==0 ) + fifo_group_cfg[g] =3 ;/* 5k,0,5k,0 */ +else if (cnt ==2 && fifo_group_cfg[g] ==3 ) +/* no change */ ; +else if (cnt ==1 && (fifo &0x2 ) && + fifo_group_cfg[g] ==3 ) + fifo_group_cfg[g] =1 ;/* 5k,0,2.5k 2.5k*/ +else if (cnt ==1 && (fifo &0x3 ) ==0x3 ) +/* no change */ ; +else if (cnt ==1 ) + fifo_group_cfg[g] =0 ;/* 2.5k x 4 */ +else +cvmx_printf ("ERROR: %s: internal error\n" , + __func__); + + fifo += cnt; + } + } + +/* Check if there was no error in FIFO allocation */ +if (fifo > max_fifos) { +cvmx_printf ("ERROR: %s: Internal error FIFO %u\n" , __func__, + fifo); +return -1 ; + } + +if (debug) +debug ("%s: used %u of FIFOs\n" , __func__, fifo); + +/* Now configure all FIFO groups */ +for (fifo =0 ; fifo < fifo_groups; fifo++) { +cvmx_pko_ptgfx_cfg_t pko_ptgfx_cfg; + + pko_ptgfx_cfg.u64 =csr_rd_node (node,CVMX_PKO_PTGFX_CFG (fifo)); +if (pko_ptgfx_cfg.s.size != fifo_group_cfg[fifo]) + pko_ptgfx_cfg.s.reset =1 ; + pko_ptgfx_cfg.s.size = fifo_group_cfg[fifo]; +if (fifo_group_spd[fifo] >=40 ) +if (pko_ptgfx_cfg.s.size >=3 ) + pko_ptgfx_cfg.s.rate =3 ;/* 50 Gbps */ +else + pko_ptgfx_cfg.s.rate =2 ;/* 25 Gbps */ +else if (fifo_group_spd[fifo] >=20 ) + pko_ptgfx_cfg.s.rate =2 ;/* 25 Gbps */ +else if (fifo_group_spd[fifo] >=10 ) + pko_ptgfx_cfg.s.rate =1 ;/* 12.5 Gbps */ +else + pko_ptgfx_cfg.s.rate =0 ;/* 6.25 Gbps */ + +if (debug) +debug ("%s: FIFO %#x-%#x size=%u speed=%d rate=%d\n" , + __func__, fifo *4 , fifo *4 +3 , + pko_ptgfx_cfg.s.size, fifo_group_spd[fifo], + pko_ptgfx_cfg.s.rate); + +csr_wr_node (node,CVMX_PKO_PTGFX_CFG (fifo), pko_ptgfx_cfg.u64); + pko_ptgfx_cfg.s.reset =0 ; +csr_wr_node (node,CVMX_PKO_PTGFX_CFG (fifo), pko_ptgfx_cfg.u64); + } + +/* Configure all MACs assigned FIFO number */ +for (mac_num =0 ; mac_num <__cvmx_pko3_num_macs (); mac_num++) { +cvmx_pko_macx_cfg_t pko_mac_cfg; + +if (debug) +debug ("%s: mac#%02u: fifo=%#x cnt=%u speed=%d\n" , + __func__, mac_num, + cvmx_pko3_mac_table[mac_num].fifo_id, + cvmx_pko3_mac_table[mac_num].fifo_cnt, + cvmx_pko3_mac_table[mac_num].spd); + + pko_mac_cfg.u64 =csr_rd_node (node,CVMX_PKO_MACX_CFG (mac_num)); + pko_mac_cfg.s.fifo_num = cvmx_pko3_mac_table[mac_num].fifo_id; +csr_wr_node (node,CVMX_PKO_MACX_CFG (mac_num), pko_mac_cfg.u64); + } + +/* Setup PKO MCI0/MCI1/SKID credits */ +for (mac_num =0 ; mac_num <__cvmx_pko3_num_macs (); mac_num++) { +cvmx_pko_mci0_max_credx_t pko_mci0_max_cred; +cvmx_pko_mci1_max_credx_t pko_mci1_max_cred; +cvmx_pko_macx_cfg_t pko_mac_cfg; +unsigned int fifo_credit, mac_credit, skid_credit; +unsigned int pko_fifo_cnt, fifo_size; +unsigned int mac_fifo_cnt; +unsigned int tmp; +int saved_fifo_num; + + pko_fifo_cnt = cvmx_pko3_mac_table[mac_num].fifo_cnt; + mac_fifo_cnt = cvmx_pko3_mac_table[mac_num].mac_fifo_cnt; + +/* Skip unused MACs */ +if (pko_fifo_cnt ==0 ) +continue ; + +/* Check for sanity */ +if (pko_fifo_cnt >4 ) + pko_fifo_cnt =1 ; + + fifo_size = (2 *1024 ) + (1024 /2 );/* 2.5KiB */ + fifo_credit = pko_fifo_cnt * fifo_size; + +if (mac_num ==0 ) { +/* loopback */ + mac_credit =4096 ;/* From HRM Sec 13.0 */ + skid_credit =0 ; + }else if (mac_num ==1 ) { +/* DPI */ + mac_credit =2 *1024 ; + skid_credit =0 ; + }else if (octeon_has_feature (OCTEON_FEATURE_ILK ) && + (mac_num &0xfe ) ==2 ) { +/* ILK0, ILK1: MAC 2,3 */ + mac_credit =4 *1024 ;/* 4KB fifo */ + skid_credit =0 ; + }else if (octeon_has_feature (OCTEON_FEATURE_SRIO ) && + (mac_num >=6 ) && (mac_num <=9 )) { +/* SRIO0, SRIO1: MAC 6..9 */ + mac_credit =1024 /2 ; + skid_credit =0 ; + }else { +/* BGX */ + mac_credit = mac_fifo_cnt *8 *1024 ; + skid_credit = mac_fifo_cnt *256 ; + } + +if (debug) +debug ("%s: mac %u pko_fifo_credit=%u mac_credit=%u\n" , + __func__, mac_num, fifo_credit, mac_credit); + + tmp = (fifo_credit + mac_credit) /16 ; + pko_mci0_max_cred.u64 =0 ; + pko_mci0_max_cred.s.max_cred_lim = tmp; + +/* Check for overflow */ +if (pko_mci0_max_cred.s.max_cred_lim != tmp) { +cvmx_printf ("WARNING: %s: MCI0 credit overflow\n" , + __func__); + pko_mci0_max_cred.s.max_cred_lim =0xfff ; + } + +/* Pass 2 PKO hardware does not use the MCI0 credits */ +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_X )) +csr_wr_node (node,CVMX_PKO_MCI0_MAX_CREDX (mac_num), + pko_mci0_max_cred.u64); + +/* The original CSR formula is the correct one after all */ + tmp = (mac_credit) /16 ; + pko_mci1_max_cred.u64 =0 ; + pko_mci1_max_cred.s.max_cred_lim = tmp; + +/* Check for overflow */ +if (pko_mci1_max_cred.s.max_cred_lim != tmp) { +cvmx_printf ("WARNING: %s: MCI1 credit overflow\n" , + __func__); + pko_mci1_max_cred.s.max_cred_lim =0xfff ; + } + +csr_wr_node (node,CVMX_PKO_MCI1_MAX_CREDX (mac_num), + pko_mci1_max_cred.u64); + + tmp = (skid_credit /256 ) >>1 ;/* valid 0,1,2 */ + pko_mac_cfg.u64 =csr_rd_node (node,CVMX_PKO_MACX_CFG (mac_num)); + +/* The PKO_MACX_CFG bits cannot be changed unless FIFO_MUM=0x1f (unused fifo) */ + saved_fifo_num = pko_mac_cfg.s.fifo_num; + pko_mac_cfg.s.fifo_num =0x1f ; + pko_mac_cfg.s.skid_max_cnt = tmp; +csr_wr_node (node,CVMX_PKO_MACX_CFG (mac_num), pko_mac_cfg.u64); + + pko_mac_cfg.u64 =csr_rd_node (node,CVMX_PKO_MACX_CFG (mac_num)); + pko_mac_cfg.s.fifo_num = saved_fifo_num; +csr_wr_node (node,CVMX_PKO_MACX_CFG (mac_num), pko_mac_cfg.u64); + +if (debug) { + pko_mci0_max_cred.u64 = +csr_rd_node (node,CVMX_PKO_MCI0_MAX_CREDX (mac_num)); + pko_mci1_max_cred.u64 = +csr_rd_node (node,CVMX_PKO_MCI1_MAX_CREDX (mac_num)); + pko_mac_cfg.u64 = +csr_rd_node (node,CVMX_PKO_MACX_CFG (mac_num)); +debug ("%s: mac %u PKO_MCI0_MAX_CREDX=%u PKO_MCI1_MAX_CREDX=%u PKO_MACX_CFG[SKID_MAX_CNT]=%u\n" , + __func__, mac_num, + pko_mci0_max_cred.s.max_cred_lim, + pko_mci1_max_cred.s.max_cred_lim, + pko_mac_cfg.s.skid_max_cnt); + } + }/* for mac_num */ + +return 0 ; +} + +/** Set MAC options +* +* The options supported are the parameters below: +* +* @param xiface The physical interface number +* @param index The physical sub-interface port +* @param fcs_enable Enable FCS generation +* @param pad_enable Enable padding to minimum packet size +* @param fcs_sop_off Number of bytes at start of packet to exclude from FCS +* +* The typical use for `fcs_sop_off` is when the interface is configured +* to use a header such as HighGig to precede every Ethernet packet, +* such a header usually does not partake in the CRC32 computation stream, +* and its size must be set with this parameter. +* +* @return Returns 0 on success, -1 if interface/port is invalid. +*/ +int cvmx_pko3_interface_options (int xiface,int index,bool fcs_enable, +bool pad_enable,unsigned int fcs_sop_off) +{ +int mac_num; +cvmx_pko_macx_cfg_t pko_mac_cfg; +unsigned int fifo_num; +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); + +if (debug) +debug ("%s: intf %u:%u/%u fcs=%d pad=%d\n" , __func__, xi.node, + xi.interface, index, fcs_enable, pad_enable); + + mac_num =__cvmx_pko3_get_mac_num (xiface, index); +if (mac_num <0 ) { +cvmx_printf ("ERROR: %s: invalid interface %u:%u/%u\n" , __func__, + xi.node, xi.interface, index); +return -1 ; + } + + pko_mac_cfg.u64 =csr_rd_node (xi.node,CVMX_PKO_MACX_CFG (mac_num)); + +/* If MAC is not assigned, return an error */ +if (pko_mac_cfg.s.fifo_num ==0x1f ) { +cvmx_printf ("ERROR: %s: unused interface %u:%u/%u\n" , __func__, + xi.node, xi.interface, index); +return -1 ; + } + +if (pko_mac_cfg.s.min_pad_ena == pad_enable && + pko_mac_cfg.s.fcs_ena == fcs_enable) { +if (debug) +debug ("%s: mac %#x unchanged\n" , __func__, mac_num); +return 0 ; + } + +/* WORKAROUND: Pass1 won't allow change any bits unless FIFO_NUM=0x1f */ + fifo_num = pko_mac_cfg.s.fifo_num; + pko_mac_cfg.s.fifo_num =0x1f ; + + pko_mac_cfg.s.min_pad_ena = pad_enable; + pko_mac_cfg.s.fcs_ena = fcs_enable; + pko_mac_cfg.s.fcs_sop_off = fcs_sop_off; + +csr_wr_node (xi.node,CVMX_PKO_MACX_CFG (mac_num), pko_mac_cfg.u64); + + pko_mac_cfg.s.fifo_num = fifo_num; +csr_wr_node (xi.node,CVMX_PKO_MACX_CFG (mac_num), pko_mac_cfg.u64); + +if (debug) +debug ("%s: PKO_MAC[%u]CFG=%#llx\n" , __func__, mac_num, + (unsigned long long )csr_rd_node (xi.node,CVMX_PKO_MACX_CFG (mac_num))); + +return 0 ; +} + +/** Set Descriptor Queue options +* +* The `min_pad` parameter must be in agreement with the interface-level +* padding option for all descriptor queues assigned to that particular +* interface/port. +* +* @param node on which to operate +* @param dq descriptor queue to set +* @param min_pad minimum padding to set for dq +*/ +void cvmx_pko3_dq_options (unsigned int node,unsigned int dq,bool min_pad) +{ +cvmx_pko_pdm_dqx_minpad_t reg; + + dq &= (1 <<10 ) -1 ; + reg.u64 =csr_rd_node (node,CVMX_PKO_PDM_DQX_MINPAD (dq)); + reg.s.minpad = min_pad; +csr_wr_node (node,CVMX_PKO_PDM_DQX_MINPAD (dq), reg.u64); +}
Signature · 1 line
2.35.1
PATCH v2 37/52 mips: octeon: Add cvmx-pko3-compat.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-pko3-compat.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-pko3-compat.c | 656 +++++++++++++++++++++++ 1 file changed, 656 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-pko3-compat.c
arch/mips/mach-octeon/cvmx-pko3-compat.c new file +656 -0
@@ -0,0 +1,656 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +*/ + +#include <errno.h> +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-gserx-defs.h> +#include <mach/cvmx-ilk-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-scratch.h> +#include <mach/cvmx-hwfau.h> +#include <mach/cvmx-fau.h> + +#include <mach/cvmx-hwpko.h> +#include <mach/cvmx-ilk.h> +#include <mach/cvmx-pki.h> +#include <mach/cvmx-pko3.h> +#include <mach/cvmx-pko3-queue.h> +#include <mach/cvmx-pko3-resources.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-helper-bgx.h> +#include <mach/cvmx-helper-cfg.h> +#include <mach/cvmx-helper-util.h> +#include <mach/cvmx-helper-pki.h> + +/* #undef CVMX_ENABLE_PARAMETER_CHECKING */ +/* #define CVMX_ENABLE_PARAMETER_CHECKING 1 */ +/* #define __PKO3_NATIVE_PTR */ + +static inline u64 cvmx_pko3_legacy_paddr (unsigned int node,u64 addr) +{ +u64 paddr; + + paddr = node; + paddr = (addr & ((1ull <<40 ) -1 )) | (paddr <<40 ); +return paddr; +} + +#if CVMX_ENABLE_PARAMETER_CHECKING +/** +* @INTERNAL +* +* Verify the integrity of a legacy buffer link pointer, +* +* Note that the IPD/PIP/PKO hardware would sometimes +* round-up the buf_ptr->size field of the last buffer in a chain to the next +* cache line size, so the sum of buf_ptr->size +* fields for a packet may exceed total_bytes by up to 127 bytes. +* +* @returns 0 on success, a negative number on error. +*/ +static int cvmx_pko3_legacy_bufptr_validate (cvmx_buf_ptr_t buf_ptr, +unsigned int gather, +unsigned int buffers, +unsigned int total_bytes) +{ +unsigned int node =cvmx_get_node_num (); +unsigned int segs =0 , bytes =0 ; +unsigned int phys_addr; +cvmx_buf_ptr_t ptr; +int delta; + +if (buffers ==0 ) { +return -1 ; + }else if (buffers ==1 ) { + delta = buf_ptr.s.size - total_bytes; +if (delta <0 || delta >127 ) +return -2 ; + }else if (gather) { +cvmx_buf_ptr_t *vptr; +/* Validate gather list */ +if (buf_ptr.s.size < buffers) +return -3 ; + phys_addr =cvmx_pko3_legacy_paddr (node, buf_ptr.s.addr); + vptr =cvmx_phys_to_ptr (phys_addr); +for (segs =0 ; segs < buffers; segs++) + bytes += vptr[segs].s.size; + delta = bytes - total_bytes; +if (delta <0 || delta >127 ) +return -4 ; + }else { +void *vptr; +/* Validate linked buffers */ + ptr = buf_ptr; +for (segs =0 ; segs < buffers; segs++) { + bytes += ptr.s.size; + phys_addr =cvmx_pko3_legacy_paddr (node, ptr.s.addr); + vptr =cvmx_phys_to_ptr (phys_addr); +memcpy (&ptr, vptr -sizeof (u64),sizeof (u64)); + } + delta = bytes - total_bytes; +if (delta <0 || delta >127 ) +return -5 ; + } +return 0 ; +} +#endif /* CVMX_ENABLE_PARAMETER_CHECKING */ + +/* +* @INTERNAL +* +* Implementation note: +* When the packet is sure to not need a jump_buf, +* it will be written directly into cvmseg. +* When the packet might not fit into cvmseg with all +* of its descriptors, a jump_buf is allocated a priori, +* and only header is first placed into cvmseg, all other +* descriptors are placed into jump_buf, and finally +* the PKO_SEND_JUMP_S is written to cvmseg. +* This is because if there are no EXT or TSO descriptors, +* then HDR must be first, and JMP second and that is all +* that should go into cvmseg. +*/ +struct __cvmx_pko3_legacy_desc { +u64 *cmd_words; +u64 *jump_buf_base_ptr; +unsigned short word_count; +short last_pool; +u8 port_node; +u8 aura_node; +u8 jump_buf_size; +}; + +/** +* @INTERNAL +* +* Add a subdescriptor into a command buffer, +* and handle command-buffer overflow by allocating a JUMP_s buffer +* from PKO3 internal AURA. +*/ +static int __cvmx_pko3_cmd_subdc_add (struct __cvmx_pko3_legacy_desc *desc, +u64 subdc) +{ +/* SEND_JUMP_S missing on Pass1.X */ +if (desc->word_count >=15 ) { +printf ("%s: ERROR: too many segments\n" , __func__); +return -EBADF ; + } + +/* Handle small commands simply */ +if (cvmx_likely (!desc->jump_buf_base_ptr)) { + desc->cmd_words[desc->word_count] = subdc; + (desc->word_count)++; +return desc->word_count; + } + +if (cvmx_unlikely (desc->jump_buf_size >=255 )) +return -ENOMEM ; + + desc->jump_buf_base_ptr[desc->jump_buf_size++] = subdc; + +return desc->word_count + desc->jump_buf_size; +} + +/** +* @INTERNAL +* +* Finalize command buffer +* +* @returns: number of command words in command buffer and jump buffer +* or negative number on error. +*/ + +static int __cvmx_pko3_cmd_done (struct __cvmx_pko3_legacy_desc *desc) +{ +short pko_aura; +cvmx_pko_buf_ptr_t jump_s; +cvmx_pko_send_aura_t aura_s; + +/* no jump buffer, nothing to do */ +if (!desc->jump_buf_base_ptr) +return desc->word_count; + + desc->word_count++; + +/* Verify number of words is 15 */ +if (desc->word_count !=2 ) { +printf ("ERROR: %s: internal error, word_count=%d\n" , __func__, + desc->word_count); +return -EINVAL ; + } + +/* Add SEND_AURA_S at the end of jump_buf */ + pko_aura =__cvmx_pko3_aura_get (desc->port_node); + + aura_s.u64 =0 ; + aura_s.s.aura = pko_aura; + aura_s.s.offset =0 ; + aura_s.s.alg =AURAALG_NOP ; + aura_s.s.subdc4 =CVMX_PKO_SENDSUBDC_AURA ; + + desc->jump_buf_base_ptr[desc->jump_buf_size++] = aura_s.u64; + +/* Add SEND_JUMPS to point to jump_buf */ + jump_s.u64 =0 ; + jump_s.s.subdc3 =CVMX_PKO_SENDSUBDC_JUMP ; + jump_s.s.addr =cvmx_ptr_to_phys (desc->jump_buf_base_ptr); + jump_s.s.i =1 ;/* F=1: Free this buffer when done */ + jump_s.s.size = desc->jump_buf_size; + desc->cmd_words[1 ] = jump_s.u64; + +return desc->word_count + desc->jump_buf_size; +} + +/** +* @INTERNAL +* +* Handle buffer pools for PKO legacy transmit operation +*/ +static inline int cvmx_pko3_legacy_pool (struct __cvmx_pko3_legacy_desc *desc, +int pool) +{ +cvmx_pko_send_aura_t aura_s; +unsigned int aura; + +if (cvmx_unlikely (desc->last_pool == pool)) +return 0 ; + + aura = desc->aura_node <<10 ;/* LAURA=AURA[0..9] */ + aura |= pool; + +if (cvmx_likely (desc->last_pool <0 )) { +cvmx_pko_send_hdr_t *hdr_s; + + hdr_s = (void *)&desc->cmd_words[0 ]; +/* Create AURA from legacy pool (assume LAURA==POOL */ + hdr_s->s.aura = aura; + desc->last_pool = pool; +return 0 ; + } + + aura_s.u64 =0 ; + aura_s.s.subdc4 =CVMX_PKO_SENDSUBDC_AURA ; + aura_s.s.offset =0 ; + aura_s.s.alg =AURAALG_NOP ; + aura |= pool; + aura_s.s.aura = aura; + desc->last_pool = pool; +return __cvmx_pko3_cmd_subdc_add (desc, aura_s.u64); +} + +/** +* @INTERNAL +* +* Backward compatibility for packet transmission using legacy PKO command. +* +* NOTE: Only supports output on node-local ports. +* +* TBD: Could embed destination node in extended DQ number. +*/ +cvmx_pko_return_value_t +cvmx_pko3_legacy_xmit (unsigned int dq,cvmx_pko_command_word0_t pko_command, +cvmx_buf_ptr_t packet,u64 addr,bool tag_sw) +{ +cvmx_pko_query_rtn_t pko_status; +cvmx_pko_send_hdr_t *hdr_s; +struct __cvmx_pko3_legacy_desc desc; +u8 *data_ptr; +unsigned int node, seg_cnt; +int res; +cvmx_buf_ptr_pki_t bptr; + + seg_cnt = pko_command.s.segs; + desc.cmd_words =cvmx_pko3_cvmseg_addr (); + +/* Allocate from local aura, assume all old-pools are local */ + node =cvmx_get_node_num (); + desc.aura_node = node; + +/* Derive destination node from dq */ + desc.port_node = dq >>10 ; + dq &= (1 <<10 ) -1 ; + + desc.word_count =1 ; + desc.last_pool =-1 ; + +/* For small packets, write descriptors directly to CVMSEG +* but for longer packets use jump_buf +*/ +if (seg_cnt <7 ||OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_X )) { + desc.jump_buf_size =0 ; + desc.jump_buf_base_ptr =NULL ; + }else { +unsigned int pko_aura =__cvmx_pko3_aura_get (desc.port_node); + +cvmx_fpa3_gaura_t aura = +__cvmx_fpa3_gaura (pko_aura >>10 , pko_aura &0x3ff ); + +/* Allocate from internal AURA, size is 4KiB */ + desc.jump_buf_base_ptr =cvmx_fpa3_alloc (aura); + +if (!desc.jump_buf_base_ptr) +return -ENOMEM ; + desc.jump_buf_size =0 ; + } + +/* Native buffer-pointer for error checiing */ + bptr.u64 = packet.u64; + +#if CVMX_ENABLE_PARAMETER_CHECKING +if (seg_cnt ==1 && bptr.size == pko_command.s.total_bytes) { +/* +* Special case for native buffer pointer: +* This is the only case where the native pointer-style can be +* automatically identified, that is when an entire packet +* fits into a single buffer by the PKI. +* The use of the native buffers with this function +* should be avoided. +*/ +debug ("%s: WARNING: Native buffer-pointer\n" , __func__); + }else { +/* The buffer ptr is assume to be received in legacy format */ + res =cvmx_pko3_legacy_bufptr_validate ( + packet, pko_command.s.gather, pko_command.s.segs, + pko_command.s.total_bytes); +if (res <0 ) { +debug ("%s: ERROR: Not a valid packet pointer <%d>\n" , + __func__, res); +return CVMX_PKO_CMD_QUEUE_INIT_ERROR ; + } + } +#endif /* CVMX_ENABLE_PARAMETER_CHECKING */ + +/* Squash warnings */ + (void )bptr; + +/*** Translate legacy PKO fields into PKO3 PKO_SEND_HDR_S ***/ + +/* PKO_SEND_HDR_S is alwasy the first word in the command */ + hdr_s = (void *)&desc.cmd_words[0 ]; + hdr_s->u64 =0 ; + +/* Copy total packet size */ + hdr_s->s.total = pko_command.s.total_bytes; + +/* Endianness */ + hdr_s->s.le = pko_command.s.le; + +/* N2 is the same meaning */ +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_X )) + hdr_s->s.n2 =0 ;/* L2 allocate everything */ +else + hdr_s->s.n2 = pko_command.s.n2; + +/* DF bit has the same meaning */ + hdr_s->s.df = pko_command.s.dontfree; + +/* II bit has the same meaning */ + hdr_s->s.ii = pko_command.s.ignore_i; + +/* non-zero IP header offset requires L3/L4 checksum calculation */ +if (cvmx_unlikely (pko_command.s.ipoffp1 >0 )) { +u8 ipoff, ip0, l4_proto =0 ; + +/* Get data pointer for header inspection below */ +if (pko_command.s.gather) { +cvmx_buf_ptr_t *p_ptr; +cvmx_buf_ptr_t blk; + + p_ptr =cvmx_phys_to_ptr ( +cvmx_pko3_legacy_paddr (node, packet.s.addr)); + blk = p_ptr[0 ]; + data_ptr =cvmx_phys_to_ptr ( +cvmx_pko3_legacy_paddr (node, blk.s.addr)); + }else { + data_ptr =cvmx_phys_to_ptr ( +cvmx_pko3_legacy_paddr (node, packet.s.addr)); + } + +/* Get IP header offset */ + ipoff = pko_command.s.ipoffp1 -1 ; + +/* Parse IP header, version, L4 protocol */ + hdr_s->s.l3ptr = ipoff; + ip0 = data_ptr[ipoff]; + +/* IPv4 header length, checksum offload */ +if ((ip0 >>4 ) ==4 ) { + hdr_s->s.l4ptr = hdr_s->s.l3ptr + ((ip0 &0xf ) <<2 ); + l4_proto = data_ptr[ipoff +9 ]; + hdr_s->s.ckl3 =1 ;/* Only valid for IPv4 */ + } +/* IPv6 header length is fixed, no checksum */ +if ((ip0 >>4 ) ==6 ) { + hdr_s->s.l4ptr = hdr_s->s.l3ptr +40 ; + l4_proto = data_ptr[ipoff +6 ]; + } +/* Set L4 checksum algo based on L4 protocol */ +if (l4_proto ==6 ) + hdr_s->s.ckl4 =/* TCP */ 2 ; +else if (l4_proto ==17 ) + hdr_s->s.ckl4 =/* UDP */ 1 ; +else if (l4_proto ==132 ) + hdr_s->s.ckl4 =/* SCTP */ 3 ; +else + hdr_s->s.ckl4 =/* Unknown */ 0 ; + } + +if (pko_command.s.gather) { +/* Process legacy gather list */ +cvmx_pko_buf_ptr_t gather_s; +cvmx_buf_ptr_t *p_ptr; +cvmx_buf_ptr_t blk; +unsigned int i; + +/* Get gather list pointer */ + p_ptr =cvmx_phys_to_ptr ( +cvmx_pko3_legacy_paddr (node, packet.s.addr)); + blk = p_ptr[0 ]; +/* setup data_ptr */ + data_ptr =cvmx_phys_to_ptr ( +cvmx_pko3_legacy_paddr (node, blk.s.addr)); + +for (i =0 ; i < seg_cnt; i++) { +if (cvmx_unlikely (cvmx_pko3_legacy_pool ( + &desc, blk.s.pool) <0 )) +return CVMX_PKO_NO_MEMORY ; + +/* Insert PKO_SEND_GATHER_S for the current buffer */ + gather_s.u64 =0 ; + gather_s.s.subdc3 =CVMX_PKO_SENDSUBDC_GATHER ; + gather_s.s.size = blk.s.size; + gather_s.s.i = blk.s.i; + gather_s.s.addr = +cvmx_pko3_legacy_paddr (node, blk.s.addr); + + res =__cvmx_pko3_cmd_subdc_add (&desc, gather_s.u64); +if (res <0 ) +return CVMX_PKO_NO_MEMORY ; + +/* get next bufptr */ + blk = p_ptr[i +1 ]; + }/* for i */ + +/* Free original gather-list buffer */ +if ((pko_command.s.ignore_i && !pko_command.s.dontfree) || + packet.s.i == pko_command.s.dontfree) +cvmx_fpa_free_nosync (p_ptr, packet.s.pool, + (i -1 ) /16 +1 ); + }else { +/* Process legacy linked buffer list */ +cvmx_pko_buf_ptr_t gather_s; +cvmx_buf_ptr_t blk; +void *vptr; + + data_ptr =cvmx_phys_to_ptr ( +cvmx_pko3_legacy_paddr (node, packet.s.addr)); + blk = packet; + +/* +* Legacy linked-buffers converted into flat gather list +* so that the AURA can optionally be changed to reflect +* the POOL number in the legacy pointers +*/ +do { +/* Insert PKO_SEND_AURA_S if pool changes */ +if (cvmx_unlikely (cvmx_pko3_legacy_pool ( + &desc, blk.s.pool) <0 )) +return CVMX_PKO_NO_MEMORY ; + +/* Insert PKO_SEND_GATHER_S for the current buffer */ + gather_s.u64 =0 ; + gather_s.s.subdc3 =CVMX_PKO_SENDSUBDC_GATHER ; + gather_s.s.size = blk.s.size; + gather_s.s.i = blk.s.i; + gather_s.s.addr = +cvmx_pko3_legacy_paddr (node, blk.s.addr); + + res =__cvmx_pko3_cmd_subdc_add (&desc, gather_s.u64); +if (res <0 ) +return CVMX_PKO_NO_MEMORY ; + +/* Get the next buffer pointer */ + vptr =cvmx_phys_to_ptr ( +cvmx_pko3_legacy_paddr (node, blk.s.addr)); +memcpy (&blk, vptr -sizeof (blk),sizeof (blk)); + +/* Decrement segment count */ + seg_cnt--; + + }while (seg_cnt >0 ); + } + +/* This field indicates the presence of 3rd legacy command word */ +/* NOTE: legacy 3rd word may contain CN78XX native phys addr already */ +if (cvmx_unlikely (pko_command.s.rsp)) { +/* PTP bit in word3 is not supported - +* can not be distibguished from larger phys_addr[42..41] +*/ +if (pko_command.s.wqp) { +/* <addr> is an SSO WQE */ +cvmx_wqe_word1_t *wqe_p; +cvmx_pko_send_work_t work_s; + + work_s.u64 =0 ; + work_s.s.subdc4 =CVMX_PKO_SENDSUBDC_WORK ; + work_s.s.addr = addr; +/* Assume WQE is legacy format too */ + wqe_p =cvmx_phys_to_ptr (addr +sizeof (u64)); + work_s.s.grp = wqe_p->cn38xx.grp; + work_s.s.tt = wqe_p->tag_type; + + res =__cvmx_pko3_cmd_subdc_add (&desc, work_s.u64); + }else { +cvmx_pko_send_mem_t mem_s; +/* MEMALG_SET broken on Pass1 */ +if (OCTEON_IS_MODEL (OCTEON_CN78XX_PASS1_0 )) { +debug ("%s: ERROR: PKO byte-clear not supported\n" , + __func__); + } +/* <addr> is a physical address of byte clear */ + mem_s.u64 =0 ; + mem_s.s.subdc4 =CVMX_PKO_SENDSUBDC_MEM ; + mem_s.s.addr = addr; + mem_s.s.dsz =MEMDSZ_B8 ; + mem_s.s.alg =MEMALG_SET ; + mem_s.s.offset =0 ; + + res =__cvmx_pko3_cmd_subdc_add (&desc, mem_s.u64); + } +if (res <0 ) +return CVMX_PKO_NO_MEMORY ; + } + +/* FAU counter binding reg0 */ +if (pko_command.s.reg0) { +cvmx_pko_send_mem_t mem_s; + +debug ("%s: Legacy FAU commands: reg0=%#x sz0=%#x\n" , __func__, + pko_command.s.reg0, pko_command.s.size0); + mem_s.u64 =0 ; + mem_s.s.subdc4 =CVMX_PKO_SENDSUBDC_MEM ; + mem_s.s.addr =cvmx_ptr_to_phys ( +CASTPTR (void,__cvmx_fau_sw_addr (pko_command.s.reg0))); +if (cvmx_likely (pko_command.s.size0 ==CVMX_FAU_OP_SIZE_64 )) + mem_s.s.dsz =MEMDSZ_B64 ; +else if (pko_command.s.size0 ==CVMX_FAU_OP_SIZE_32 ) + mem_s.s.dsz =MEMDSZ_B32 ; +else if (pko_command.s.size0 ==CVMX_FAU_OP_SIZE_16 ) + mem_s.s.dsz =MEMDSZ_B16 ; +else + mem_s.s.dsz =MEMDSZ_B8 ; + +if (mem_s.s.dsz ==MEMDSZ_B16 || mem_s.s.dsz ==MEMDSZ_B8 ) +debug ("%s: ERROR: 8/16 bit decrement unsupported" , + __func__); + + mem_s.s.offset = pko_command.s.subone0; +if (mem_s.s.offset) + mem_s.s.alg =MEMALG_SUB ; +else + mem_s.s.alg =MEMALG_SUBLEN ; + + res =__cvmx_pko3_cmd_subdc_add (&desc, mem_s.u64); +if (res <0 ) +return CVMX_PKO_NO_MEMORY ; + } + +/* FAU counter binding reg1 */ +if (cvmx_unlikely (pko_command.s.reg1)) { +cvmx_pko_send_mem_t mem_s; + +debug ("%s: Legacy FAU commands: reg1=%#x sz1=%#x\n" , __func__, + pko_command.s.reg1, pko_command.s.size1); + mem_s.u64 =0 ; + mem_s.s.subdc4 =CVMX_PKO_SENDSUBDC_MEM ; + mem_s.s.addr =cvmx_ptr_to_phys ( +CASTPTR (void,__cvmx_fau_sw_addr (pko_command.s.reg1))); +if (cvmx_likely (pko_command.s.size1 ==CVMX_FAU_OP_SIZE_64 )) + mem_s.s.dsz =MEMDSZ_B64 ; +else if (pko_command.s.size1 ==CVMX_FAU_OP_SIZE_32 ) + mem_s.s.dsz =MEMDSZ_B32 ; +else if (pko_command.s.size1 ==CVMX_FAU_OP_SIZE_16 ) + mem_s.s.dsz =MEMDSZ_B16 ; +else + mem_s.s.dsz =MEMDSZ_B8 ; + +if (mem_s.s.dsz ==MEMDSZ_B16 || mem_s.s.dsz ==MEMDSZ_B8 ) +printf ("%s: ERROR: 8/16 bit decrement unsupported" , + __func__); + + mem_s.s.offset = pko_command.s.subone1; +if (mem_s.s.offset) + mem_s.s.alg =MEMALG_SUB ; +else + mem_s.s.alg =MEMALG_SUBLEN ; + + res =__cvmx_pko3_cmd_subdc_add (&desc, mem_s.u64); +if (res <0 ) +return CVMX_PKO_NO_MEMORY ; + } + +/* These PKO_HDR_S fields are not used: */ +/* hdr_s->s.ds does not have legacy equivalent, remains 0 */ +/* hdr_s->s.format has no legacy equivalent, remains 0 */ + +/*** Finalize command buffer ***/ + res =__cvmx_pko3_cmd_done (&desc); +if (res <0 ) +return CVMX_PKO_NO_MEMORY ; + +/*** Send the PKO3 command into the Descriptor Queue ***/ + pko_status = +__cvmx_pko3_lmtdma (desc.port_node, dq, desc.word_count, tag_sw); + +/*** Map PKO3 result codes to legacy return values ***/ +if (cvmx_likely (pko_status.s.dqstatus ==PKO_DQSTATUS_PASS )) +return CVMX_PKO_SUCCESS ; + +debug ("%s: ERROR: failed to enqueue: %s\n" , __func__, +pko_dqstatus_error (pko_status.s.dqstatus)); + +if (pko_status.s.dqstatus ==PKO_DQSTATUS_ALREADY ) +return CVMX_PKO_PORT_ALREADY_SETUP ; +if (pko_status.s.dqstatus ==PKO_DQSTATUS_NOFPABUF || + pko_status.s.dqstatus ==PKO_DQSTATUS_NOPKOBUF ) +return CVMX_PKO_NO_MEMORY ; +if (pko_status.s.dqstatus ==PKO_DQSTATUS_NOTCREATED ) +return CVMX_PKO_INVALID_QUEUE ; +if (pko_status.s.dqstatus ==PKO_DQSTATUS_BADSTATE ) +return CVMX_PKO_CMD_QUEUE_INIT_ERROR ; +if (pko_status.s.dqstatus ==PKO_DQSTATUS_SENDPKTDROP ) +return CVMX_PKO_INVALID_PORT ; + +return CVMX_PKO_INVALID_PORT ; +}
Signature · 1 line
2.35.1
PATCH v2 38/52 mips: octeon: Add cvmx-pko3-resources.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-pko3-resources.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-pko3-resources.c | 213 ++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-pko3-resources.c
arch/mips/mach-octeon/cvmx-pko3-resources.c new file +213 -0
@@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +* +* PKO resources. +*/ + +#include <errno.h> +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> +#include <mach/cvmx-range.h> +#include <mach/cvmx-global-resources.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-gserx-defs.h> +#include <mach/cvmx-ilk-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-hwpko.h> +#include <mach/cvmx-ilk.h> +#include <mach/cvmx-pki.h> +#include <mach/cvmx-pko3.h> +#include <mach/cvmx-pko3-queue.h> +#include <mach/cvmx-pko3-resources.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-helper-bgx.h> +#include <mach/cvmx-helper-cfg.h> +#include <mach/cvmx-helper-util.h> +#include <mach/cvmx-helper-pki.h> + +#define CVMX_GR_TAG_PKO_PORT_QUEUES (x) \ + cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', 'p', 'o', 'q', '_', \ + ((x) + '0'), '.', '.', '.', '.') +#define CVMX_GR_TAG_PKO_L2_QUEUES (x) \ + cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', 'l', '2', 'q', '_', \ + ((x) + '0'), '.', '.', '.', '.') +#define CVMX_GR_TAG_PKO_L3_QUEUES (x) \ + cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', 'l', '3', 'q', '_', \ + ((x) + '0'), '.', '.', '.', '.') +#define CVMX_GR_TAG_PKO_L4_QUEUES (x) \ + cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', 'l', '4', 'q', '_', \ + ((x) + '0'), '.', '.', '.', '.') +#define CVMX_GR_TAG_PKO_L5_QUEUES (x) \ + cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', 'l', '5', 'q', '_', \ + ((x) + '0'), '.', '.', '.', '.') +#define CVMX_GR_TAG_PKO_DESCR_QUEUES (x) \ + cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', 'd', 'e', 'q', '_', \ + ((x) + '0'), '.', '.', '.', '.') +#define CVMX_GR_TAG_PKO_PORT_INDEX (x) \ + cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', 'p', 'i', 'd', '_', \ + ((x) + '0'), '.', '.', '.', '.') + +/* +* @INRWENAL +* Per-DQ parameters, current and maximum queue depth counters +*/ +cvmx_pko3_dq_params_t *__cvmx_pko3_dq_params[CVMX_MAX_NODES ]; + +static const short cvmx_pko_num_queues_78XX[256 ] = { + [CVMX_PKO_PORT_QUEUES ] =32 , [CVMX_PKO_L2_QUEUES ] =512 , + [CVMX_PKO_L3_QUEUES ] =512 , [CVMX_PKO_L4_QUEUES ] =1024 , + [CVMX_PKO_L5_QUEUES ] =1024 , [CVMX_PKO_DESCR_QUEUES ] =1024 +}; + +static const short cvmx_pko_num_queues_73XX[256 ] = { + [CVMX_PKO_PORT_QUEUES ] =16 , [CVMX_PKO_L2_QUEUES ] =256 , + [CVMX_PKO_L3_QUEUES ] =256 , [CVMX_PKO_L4_QUEUES ] =0 , + [CVMX_PKO_L5_QUEUES ] =0 , [CVMX_PKO_DESCR_QUEUES ] =256 +}; + +int cvmx_pko3_num_level_queues (enum cvmx_pko3_level_e level) +{ +unsigned int nq =0 , ne =0 ; + +if (OCTEON_IS_MODEL (OCTEON_CN78XX )) { + ne =NUM_ELEMENTS (cvmx_pko_num_queues_78XX); + nq = cvmx_pko_num_queues_78XX[level]; + } +if (OCTEON_IS_MODEL (OCTEON_CN73XX ) ||OCTEON_IS_MODEL (OCTEON_CNF75XX )) { + ne =NUM_ELEMENTS (cvmx_pko_num_queues_73XX); + nq = cvmx_pko_num_queues_73XX[level]; + } + +if (nq ==0 || level >= ne) { +printf ("ERROR: %s: queue level %#x invalid\n" , __func__, level); +return -1 ; + } + +return nq; +} + +static inline struct global_resource_tag +__cvmx_pko_get_queues_resource_tag (int node,enum cvmx_pko3_level_e queue_level) +{ +if (cvmx_pko3_num_level_queues (queue_level) ==0 ) { +printf ("ERROR: %s: queue level %#x invalid\n" , __func__, + queue_level); +return CVMX_GR_TAG_INVALID ; + } + +switch (queue_level) { +case CVMX_PKO_PORT_QUEUES : +return CVMX_GR_TAG_PKO_PORT_QUEUES (node); +case CVMX_PKO_L2_QUEUES : +return CVMX_GR_TAG_PKO_L2_QUEUES (node); +case CVMX_PKO_L3_QUEUES : +return CVMX_GR_TAG_PKO_L3_QUEUES (node); +case CVMX_PKO_L4_QUEUES : +return CVMX_GR_TAG_PKO_L4_QUEUES (node); +case CVMX_PKO_L5_QUEUES : +return CVMX_GR_TAG_PKO_L5_QUEUES (node); +case CVMX_PKO_DESCR_QUEUES : +return CVMX_GR_TAG_PKO_DESCR_QUEUES (node); +default : +printf ("ERROR: %s: queue level %#x invalid\n" , __func__, + queue_level); +return CVMX_GR_TAG_INVALID ; + } +} + +/** +* Allocate or reserve a pko resource - called by wrapper functions +* @param tag processed global resource tag +* @param base_queue if specified the queue to reserve +* @param owner to be specified for resource +* @param num_queues to allocate +* @param max_num_queues for global resource +*/ +int cvmx_pko_alloc_global_resource (struct global_resource_tag tag, +int base_queue,int owner,int num_queues, +int max_num_queues) +{ +int res; + +if (cvmx_create_global_resource_range (tag, max_num_queues)) { +debug ("ERROR: Failed to create PKO3 resource: %lx-%lx\n" , + (unsigned long )tag.hi, (unsigned long )tag.lo); +return -1 ; + } +if (base_queue >=0 ) { + res =cvmx_reserve_global_resource_range (tag, owner, base_queue, + num_queues); + }else { + res =cvmx_allocate_global_resource_range (tag, owner, + num_queues,1 ); + } +if (res <0 ) { +debug ("ERROR: Failed to %s PKO3 tag %lx:%lx, %i %i %i %i.\n" , + ((base_queue <0 ) ?"allocate" :"reserve" ), + (unsigned long )tag.hi, (unsigned long )tag.lo, base_queue, + owner, num_queues, max_num_queues); +return -1 ; + } + +return res; +} + +/** +* Allocate or reserve PKO queues - wrapper for cvmx_pko_alloc_global_resource +* +* @param node on which to allocate/reserve PKO queues +* @param level of PKO queue +* @param owner of reserved/allocated resources +* @param base_queue to start reservation/allocatation +* @param num_queues number of queues to be allocated +* @return 0 on success, -1 on failure +*/ +int cvmx_pko_alloc_queues (int node,int level,int owner,int base_queue, +int num_queues) +{ +struct global_resource_tag tag = +__cvmx_pko_get_queues_resource_tag (node, level); +int max_num_queues =cvmx_pko3_num_level_queues (level); + +return cvmx_pko_alloc_global_resource (tag, base_queue, owner, + num_queues, max_num_queues); +} + +/** +* @INTERNAL +* +* Initialize the pointer to the descriptor queue parameter table. +* The table is one named block per node, and may be shared between +* applications. +*/ +int __cvmx_pko3_dq_param_setup (unsigned int node) +{ +return 0 ; +}
Signature · 1 line
2.35.1
PATCH v2 39/52 mips: octeon: Add cvmx-pko-internal-ports-range.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-pko-internal-ports-range.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- .../cvmx-pko-internal-ports-range.c | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-pko-internal-ports-range.c
arch/mips/mach-octeon/cvmx-pko-internal-ports-range.c new file +99 -0
@@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +*/ + +#include <errno.h> +#include <log.h> +#include <time.h> +#include <linux/delay.h> + +#include <mach/cvmx-regs.h> +#include <mach/cvmx-csr.h> +#include <mach/cvmx-bootmem.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> +#include <mach/cvmx-pcie.h> +#include <mach/cvmx-coremask.h> +#include <mach/cvmx-range.h> +#include <mach/cvmx-global-resources.h> + +#include <mach/cvmx-agl-defs.h> +#include <mach/cvmx-bgxx-defs.h> +#include <mach/cvmx-ciu-defs.h> +#include <mach/cvmx-gmxx-defs.h> +#include <mach/cvmx-gserx-defs.h> +#include <mach/cvmx-ilk-defs.h> +#include <mach/cvmx-ipd-defs.h> +#include <mach/cvmx-pcsx-defs.h> +#include <mach/cvmx-pcsxx-defs.h> +#include <mach/cvmx-pki-defs.h> +#include <mach/cvmx-pko-defs.h> +#include <mach/cvmx-xcv-defs.h> + +#include <mach/cvmx-hwpko.h> +#include <mach/cvmx-ilk.h> +#include <mach/cvmx-ipd.h> +#include <mach/cvmx-pki.h> +#include <mach/cvmx-pko3.h> +#include <mach/cvmx-pko3-queue.h> +#include <mach/cvmx-pko3-resources.h> + +#include <mach/cvmx-helper.h> +#include <mach/cvmx-helper-board.h> +#include <mach/cvmx-helper-cfg.h> + +#include <mach/cvmx-helper-bgx.h> +#include <mach/cvmx-helper-cfg.h> +#include <mach/cvmx-helper-util.h> +#include <mach/cvmx-helper-pki.h> + +union interface_port { +struct { +int port; +int interface; + } s; +u64 u64; +}; + +static int dbg; + +static int port_range_init; + +int __cvmx_pko_internal_ports_range_init (void ) +{ +int rv =0 ; + +if (port_range_init) +return 0 ; + port_range_init =1 ; + rv =cvmx_create_global_resource_range (CVMX_GR_TAG_PKO_IPORTS , +CVMX_HELPER_CFG_MAX_PKO_QUEUES ); +if (rv !=0 ) +debug ("ERROR : Failed to initialize pko internal port range\n" ); +return rv; +} + +int cvmx_pko_internal_ports_alloc (int xiface,int port,u64 count) +{ +int ret_val =-1 ; +union interface_port inf_port; +struct cvmx_xiface xi =cvmx_helper_xiface_to_node_interface (xiface); + +__cvmx_pko_internal_ports_range_init (); + inf_port.s.interface = xi.interface; + inf_port.s.port = port; + ret_val =cvmx_allocate_global_resource_range (CVMX_GR_TAG_PKO_IPORTS , + inf_port.u64, count,1 ); +if (dbg) +debug ("internal port alloc : port=%02d base=%02d count=%02d\n" , + (int )port, ret_val, (int )count); +if (ret_val ==-1 ) +return ret_val; + cvmx_cfg_port[xi.node][xi.interface][port].ccpp_pko_port_base = ret_val; + cvmx_cfg_port[xi.node][xi.interface][port].ccpp_pko_num_ports = count; +return 0 ; +}
Signature · 1 line
2.35.1
PATCH v2 40/52 mips: octeon: Add cvmx-qlm-tables.c
In reply to Stefan RoeseFrom: Aaron Williams <[email protected]>
Import cvmx-qlm-tables.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms.
--- arch/mips/mach-octeon/cvmx-qlm-tables.c | 292 ++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-qlm-tables.c
arch/mips/mach-octeon/cvmx-qlm-tables.c new file +292 -0
@@ -0,0 +1,292 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018-2022 Marvell International Ltd. +*/ + +#include <mach/cvmx-regs.h> +#include <mach/octeon-model.h> +#include <mach/cvmx-fuse.h> +#include <mach/octeon-feature.h> +#include <mach/cvmx-qlm.h> +#include <mach/octeon_qlm.h> + +const __cvmx_qlm_jtag_field_t __cvmx_qlm_jtag_field_cn63xx[] = { + {"prbs_err_cnt" ,299 ,252 },// prbs_err_cnt[47..0] + {"prbs_lock" ,251 ,251 },// prbs_lock + {"jtg_prbs_rst_n" ,250 ,250 },// jtg_prbs_rst_n + {"jtg_run_prbs31" ,249 ,249 },// jtg_run_prbs31 + {"jtg_run_prbs7" ,248 ,248 },// jtg_run_prbs7 + {"Unused1" ,247 ,245 },// 0 + {"cfg_pwrup_set" ,244 ,244 },// cfg_pwrup_set + {"cfg_pwrup_clr" ,243 ,243 },// cfg_pwrup_clr + {"cfg_rst_n_set" ,242 ,242 },// cfg_rst_n_set + {"cfg_rst_n_clr" ,241 ,241 },// cfg_rst_n_clr + {"cfg_tx_idle_set" ,240 ,240 },// cfg_tx_idle_set + {"cfg_tx_idle_clr" ,239 ,239 },// cfg_tx_idle_clr + {"cfg_tx_byp" ,238 ,238 },// cfg_tx_byp + {"cfg_tx_byp_inv" ,237 ,237 },// cfg_tx_byp_inv + {"cfg_tx_byp_val" ,236 ,227 },// cfg_tx_byp_val[9..0] + {"cfg_loopback" ,226 ,226 },// cfg_loopback + {"shlpbck" ,225 ,224 },// shlpbck[1..0] + {"sl_enable" ,223 ,223 },// sl_enable + {"sl_posedge_sample" ,222 ,222 },// sl_posedge_sample + {"trimen" ,221 ,220 },// trimen[1..0] + {"serdes_tx_byp" ,219 ,219 },// serdes_tx_byp + {"serdes_pll_byp" ,218 ,218 },// serdes_pll_byp + {"lowf_byp" ,217 ,217 },// lowf_byp + {"spdsel_byp" ,216 ,216 },// spdsel_byp + {"div4_byp" ,215 ,215 },// div4_byp + {"clkf_byp" ,214 ,208 },// clkf_byp[6..0] + {"Unused2" ,207 ,206 },// 0 + {"biasdrv_hs_ls_byp" ,205 ,201 },// biasdrv_hs_ls_byp[4..0] + {"tcoeff_hf_ls_byp" ,200 ,197 },// tcoeff_hf_ls_byp[3..0] + {"biasdrv_hf_byp" ,196 ,192 },// biasdrv_hf_byp[4..0] + {"tcoeff_hf_byp" ,191 ,188 },// tcoeff_hf_byp[3..0] + {"Unused3" ,187 ,186 },// 0 + {"biasdrv_lf_ls_byp" ,185 ,181 },// biasdrv_lf_ls_byp[4..0] + {"tcoeff_lf_ls_byp" ,180 ,177 },// tcoeff_lf_ls_byp[3..0] + {"biasdrv_lf_byp" ,176 ,172 },// biasdrv_lf_byp[4..0] + {"tcoeff_lf_byp" ,171 ,168 },// tcoeff_lf_byp[3..0] + {"Unused4" ,167 ,167 },// 0 + {"interpbw" ,166 ,162 },// interpbw[4..0] + {"pll_cpb" ,161 ,159 },// pll_cpb[2..0] + {"pll_cps" ,158 ,156 },// pll_cps[2..0] + {"pll_diffamp" ,155 ,152 },// pll_diffamp[3..0] + {"Unused5" ,151 ,150 },// 0 + {"cfg_rx_idle_set" ,149 ,149 },// cfg_rx_idle_set + {"cfg_rx_idle_clr" ,148 ,148 },// cfg_rx_idle_clr + {"cfg_rx_idle_thr" ,147 ,144 },// cfg_rx_idle_thr[3..0] + {"cfg_com_thr" ,143 ,140 },// cfg_com_thr[3..0] + {"cfg_rx_offset" ,139 ,136 },// cfg_rx_offset[3..0] + {"cfg_skp_max" ,135 ,132 },// cfg_skp_max[3..0] + {"cfg_skp_min" ,131 ,128 },// cfg_skp_min[3..0] + {"cfg_fast_pwrup" ,127 ,127 },// cfg_fast_pwrup + {"Unused6" ,126 ,100 },// 0 + {"detected_n" ,99 ,99 },// detected_n + {"detected_p" ,98 ,98 },// detected_p + {"dbg_res_rx" ,97 ,94 },// dbg_res_rx[3..0] + {"dbg_res_tx" ,93 ,90 },// dbg_res_tx[3..0] + {"cfg_tx_pol_set" ,89 ,89 },// cfg_tx_pol_set + {"cfg_tx_pol_clr" ,88 ,88 },// cfg_tx_pol_clr + {"cfg_rx_pol_set" ,87 ,87 },// cfg_rx_pol_set + {"cfg_rx_pol_clr" ,86 ,86 },// cfg_rx_pol_clr + {"cfg_rxd_set" ,85 ,85 },// cfg_rxd_set + {"cfg_rxd_clr" ,84 ,84 },// cfg_rxd_clr + {"cfg_rxd_wait" ,83 ,80 },// cfg_rxd_wait[3..0] + {"cfg_cdr_limit" ,79 ,79 },// cfg_cdr_limit + {"cfg_cdr_rotate" ,78 ,78 },// cfg_cdr_rotate + {"cfg_cdr_bw_ctl" ,77 ,76 },// cfg_cdr_bw_ctl[1..0] + {"cfg_cdr_trunc" ,75 ,74 },// cfg_cdr_trunc[1..0] + {"cfg_cdr_rqoffs" ,73 ,64 },// cfg_cdr_rqoffs[9..0] + {"cfg_cdr_inc2" ,63 ,58 },// cfg_cdr_inc2[5..0] + {"cfg_cdr_inc1" ,57 ,52 },// cfg_cdr_inc1[5..0] + {"fusopt_voter_sync" ,51 ,51 },// fusopt_voter_sync + {"rndt" ,50 ,50 },// rndt + {"hcya" ,49 ,49 },// hcya + {"hyst" ,48 ,48 },// hyst + {"idle_dac" ,47 ,45 },// idle_dac[2..0] + {"bg_ref_sel" ,44 ,44 },// bg_ref_sel + {"ic50dac" ,43 ,39 },// ic50dac[4..0] + {"ir50dac" ,38 ,34 },// ir50dac[4..0] + {"tx_rout_comp_bypass" ,33 ,33 },// tx_rout_comp_bypass + {"tx_rout_comp_value" ,32 ,29 },// tx_rout_comp_value[3..0] + {"tx_res_offset" ,28 ,25 },// tx_res_offset[3..0] + {"rx_rout_comp_bypass" ,24 ,24 },// rx_rout_comp_bypass + {"rx_rout_comp_value" ,23 ,20 },// rx_rout_comp_value[3..0] + {"rx_res_offset" ,19 ,16 },// rx_res_offset[3..0] + {"rx_cap_gen2" ,15 ,12 },// rx_cap_gen2[3..0] + {"rx_eq_gen2" ,11 ,8 },// rx_eq_gen2[3..0] + {"rx_cap_gen1" ,7 ,4 },// rx_cap_gen1[3..0] + {"rx_eq_gen1" ,3 ,0 },// rx_eq_gen1[3..0] + {NULL ,-1 ,-1 } +}; + +const __cvmx_qlm_jtag_field_t __cvmx_qlm_jtag_field_cn66xx[] = { + {"prbs_err_cnt" ,303 ,256 },// prbs_err_cnt[47..0] + {"prbs_lock" ,255 ,255 },// prbs_lock + {"jtg_prbs_rx_rst_n" ,254 ,254 },// jtg_prbs_rx_rst_n + {"jtg_prbs_tx_rst_n" ,253 ,253 },// jtg_prbs_tx_rst_n + {"jtg_prbs_mode" ,252 ,251 },// jtg_prbs_mode[252:251] + {"jtg_prbs_rst_n" ,250 ,250 },// jtg_prbs_rst_n + {"jtg_run_prbs31" ,249 , +249 },// jtg_run_prbs31 - Use jtg_prbs_mode instead + {"jtg_run_prbs7" ,248 , +248 },// jtg_run_prbs7 - Use jtg_prbs_mode instead + {"Unused1" ,247 ,246 },// 0 + {"div5_byp" ,245 ,245 },// div5_byp + {"cfg_pwrup_set" ,244 ,244 },// cfg_pwrup_set + {"cfg_pwrup_clr" ,243 ,243 },// cfg_pwrup_clr + {"cfg_rst_n_set" ,242 ,242 },// cfg_rst_n_set + {"cfg_rst_n_clr" ,241 ,241 },// cfg_rst_n_clr + {"cfg_tx_idle_set" ,240 ,240 },// cfg_tx_idle_set + {"cfg_tx_idle_clr" ,239 ,239 },// cfg_tx_idle_clr + {"cfg_tx_byp" ,238 ,238 },// cfg_tx_byp + {"cfg_tx_byp_inv" ,237 ,237 },// cfg_tx_byp_inv + {"cfg_tx_byp_val" ,236 ,227 },// cfg_tx_byp_val[9..0] + {"cfg_loopback" ,226 ,226 },// cfg_loopback + {"shlpbck" ,225 ,224 },// shlpbck[1..0] + {"sl_enable" ,223 ,223 },// sl_enable + {"sl_posedge_sample" ,222 ,222 },// sl_posedge_sample + {"trimen" ,221 ,220 },// trimen[1..0] + {"serdes_tx_byp" ,219 ,219 },// serdes_tx_byp + {"serdes_pll_byp" ,218 ,218 },// serdes_pll_byp + {"lowf_byp" ,217 ,217 },// lowf_byp + {"spdsel_byp" ,216 ,216 },// spdsel_byp + {"div4_byp" ,215 ,215 },// div4_byp + {"clkf_byp" ,214 ,208 },// clkf_byp[6..0] + {"biasdrv_hs_ls_byp" ,207 ,203 },// biasdrv_hs_ls_byp[4..0] + {"tcoeff_hf_ls_byp" ,202 ,198 },// tcoeff_hf_ls_byp[4..0] + {"biasdrv_hf_byp" ,197 ,193 },// biasdrv_hf_byp[4..0] + {"tcoeff_hf_byp" ,192 ,188 },// tcoeff_hf_byp[4..0] + {"biasdrv_lf_ls_byp" ,187 ,183 },// biasdrv_lf_ls_byp[4..0] + {"tcoeff_lf_ls_byp" ,182 ,178 },// tcoeff_lf_ls_byp[4..0] + {"biasdrv_lf_byp" ,177 ,173 },// biasdrv_lf_byp[4..0] + {"tcoeff_lf_byp" ,172 ,168 },// tcoeff_lf_byp[4..0] + {"Unused4" ,167 ,167 },// 0 + {"interpbw" ,166 ,162 },// interpbw[4..0] + {"pll_cpb" ,161 ,159 },// pll_cpb[2..0] + {"pll_cps" ,158 ,156 },// pll_cps[2..0] + {"pll_diffamp" ,155 ,152 },// pll_diffamp[3..0] + {"cfg_err_thr" ,151 ,150 },// cfg_err_thr + {"cfg_rx_idle_set" ,149 ,149 },// cfg_rx_idle_set + {"cfg_rx_idle_clr" ,148 ,148 },// cfg_rx_idle_clr + {"cfg_rx_idle_thr" ,147 ,144 },// cfg_rx_idle_thr[3..0] + {"cfg_com_thr" ,143 ,140 },// cfg_com_thr[3..0] + {"cfg_rx_offset" ,139 ,136 },// cfg_rx_offset[3..0] + {"cfg_skp_max" ,135 ,132 },// cfg_skp_max[3..0] + {"cfg_skp_min" ,131 ,128 },// cfg_skp_min[3..0] + {"cfg_fast_pwrup" ,127 ,127 },// cfg_fast_pwrup + {"Unused6" ,126 ,101 },// 0 + {"cfg_indep_dis" ,100 ,100 },// cfg_indep_dis + {"detected_n" ,99 ,99 },// detected_n + {"detected_p" ,98 ,98 },// detected_p + {"dbg_res_rx" ,97 ,94 },// dbg_res_rx[3..0] + {"dbg_res_tx" ,93 ,90 },// dbg_res_tx[3..0] + {"cfg_tx_pol_set" ,89 ,89 },// cfg_tx_pol_set + {"cfg_tx_pol_clr" ,88 ,88 },// cfg_tx_pol_clr + {"cfg_rx_pol_set" ,87 ,87 },// cfg_rx_pol_set + {"cfg_rx_pol_clr" ,86 ,86 },// cfg_rx_pol_clr + {"cfg_rxd_set" ,85 ,85 },// cfg_rxd_set + {"cfg_rxd_clr" ,84 ,84 },// cfg_rxd_clr + {"cfg_rxd_wait" ,83 ,80 },// cfg_rxd_wait[3..0] + {"cfg_cdr_limit" ,79 ,79 },// cfg_cdr_limit + {"cfg_cdr_rotate" ,78 ,78 },// cfg_cdr_rotate + {"cfg_cdr_bw_ctl" ,77 ,76 },// cfg_cdr_bw_ctl[1..0] + {"cfg_cdr_trunc" ,75 ,74 },// cfg_cdr_trunc[1..0] + {"cfg_cdr_rqoffs" ,73 ,64 },// cfg_cdr_rqoffs[9..0] + {"cfg_cdr_inc2" ,63 ,58 },// cfg_cdr_inc2[5..0] + {"cfg_cdr_inc1" ,57 ,52 },// cfg_cdr_inc1[5..0] + {"fusopt_voter_sync" ,51 ,51 },// fusopt_voter_sync + {"rndt" ,50 ,50 },// rndt + {"hcya" ,49 ,49 },// hcya + {"hyst" ,48 ,48 },// hyst + {"idle_dac" ,47 ,45 },// idle_dac[2..0] + {"bg_ref_sel" ,44 ,44 },// bg_ref_sel + {"ic50dac" ,43 ,39 },// ic50dac[4..0] + {"ir50dac" ,38 ,34 },// ir50dac[4..0] + {"tx_rout_comp_bypass" ,33 ,33 },// tx_rout_comp_bypass + {"tx_rout_comp_value" ,32 ,29 },// tx_rout_comp_value[3..0] + {"tx_res_offset" ,28 ,25 },// tx_res_offset[3..0] + {"rx_rout_comp_bypass" ,24 ,24 },// rx_rout_comp_bypass + {"rx_rout_comp_value" ,23 ,20 },// rx_rout_comp_value[3..0] + {"rx_res_offset" ,19 ,16 },// rx_res_offset[3..0] + {"rx_cap_gen2" ,15 ,12 },// rx_cap_gen2[3..0] + {"rx_eq_gen2" ,11 ,8 },// rx_eq_gen2[3..0] + {"rx_cap_gen1" ,7 ,4 },// rx_cap_gen1[3..0] + {"rx_eq_gen1" ,3 ,0 },// rx_eq_gen1[3..0] + {NULL ,-1 ,-1 } +}; + +const __cvmx_qlm_jtag_field_t __cvmx_qlm_jtag_field_cn68xx[] = { + {"prbs_err_cnt" ,303 ,256 },// prbs_err_cnt[47..0] + {"prbs_lock" ,255 ,255 },// prbs_lock + {"jtg_prbs_rx_rst_n" ,254 ,254 },// jtg_prbs_rx_rst_n + {"jtg_prbs_tx_rst_n" ,253 ,253 },// jtg_prbs_tx_rst_n + {"jtg_prbs_mode" ,252 ,251 },// jtg_prbs_mode[252:251] + {"jtg_prbs_rst_n" ,250 ,250 },// jtg_prbs_rst_n + {"jtg_run_prbs31" ,249 , +249 },// jtg_run_prbs31 - Use jtg_prbs_mode instead + {"jtg_run_prbs7" ,248 , +248 },// jtg_run_prbs7 - Use jtg_prbs_mode instead + {"Unused1" ,247 ,245 },// 0 + {"cfg_pwrup_set" ,244 ,244 },// cfg_pwrup_set + {"cfg_pwrup_clr" ,243 ,243 },// cfg_pwrup_clr + {"cfg_rst_n_set" ,242 ,242 },// cfg_rst_n_set + {"cfg_rst_n_clr" ,241 ,241 },// cfg_rst_n_clr + {"cfg_tx_idle_set" ,240 ,240 },// cfg_tx_idle_set + {"cfg_tx_idle_clr" ,239 ,239 },// cfg_tx_idle_clr + {"cfg_tx_byp" ,238 ,238 },// cfg_tx_byp + {"cfg_tx_byp_inv" ,237 ,237 },// cfg_tx_byp_inv + {"cfg_tx_byp_val" ,236 ,227 },// cfg_tx_byp_val[9..0] + {"cfg_loopback" ,226 ,226 },// cfg_loopback + {"shlpbck" ,225 ,224 },// shlpbck[1..0] + {"sl_enable" ,223 ,223 },// sl_enable + {"sl_posedge_sample" ,222 ,222 },// sl_posedge_sample + {"trimen" ,221 ,220 },// trimen[1..0] + {"serdes_tx_byp" ,219 ,219 },// serdes_tx_byp + {"serdes_pll_byp" ,218 ,218 },// serdes_pll_byp + {"lowf_byp" ,217 ,217 },// lowf_byp + {"spdsel_byp" ,216 ,216 },// spdsel_byp + {"div4_byp" ,215 ,215 },// div4_byp + {"clkf_byp" ,214 ,208 },// clkf_byp[6..0] + {"biasdrv_hs_ls_byp" ,207 ,203 },// biasdrv_hs_ls_byp[4..0] + {"tcoeff_hf_ls_byp" ,202 ,198 },// tcoeff_hf_ls_byp[4..0] + {"biasdrv_hf_byp" ,197 ,193 },// biasdrv_hf_byp[4..0] + {"tcoeff_hf_byp" ,192 ,188 },// tcoeff_hf_byp[4..0] + {"biasdrv_lf_ls_byp" ,187 ,183 },// biasdrv_lf_ls_byp[4..0] + {"tcoeff_lf_ls_byp" ,182 ,178 },// tcoeff_lf_ls_byp[4..0] + {"biasdrv_lf_byp" ,177 ,173 },// biasdrv_lf_byp[4..0] + {"tcoeff_lf_byp" ,172 ,168 },// tcoeff_lf_byp[4..0] + {"Unused4" ,167 ,167 },// 0 + {"interpbw" ,166 ,162 },// interpbw[4..0] + {"pll_cpb" ,161 ,159 },// pll_cpb[2..0] + {"pll_cps" ,158 ,156 },// pll_cps[2..0] + {"pll_diffamp" ,155 ,152 },// pll_diffamp[3..0] + {"cfg_err_thr" ,151 ,150 },// cfg_err_thr + {"cfg_rx_idle_set" ,149 ,149 },// cfg_rx_idle_set + {"cfg_rx_idle_clr" ,148 ,148 },// cfg_rx_idle_clr + {"cfg_rx_idle_thr" ,147 ,144 },// cfg_rx_idle_thr[3..0] + {"cfg_com_thr" ,143 ,140 },// cfg_com_thr[3..0] + {"cfg_rx_offset" ,139 ,136 },// cfg_rx_offset[3..0] + {"cfg_skp_max" ,135 ,132 },// cfg_skp_max[3..0] + {"cfg_skp_min" ,131 ,128 },// cfg_skp_min[3..0] + {"cfg_fast_pwrup" ,127 ,127 },// cfg_fast_pwrup + {"Unused6" ,126 ,100 },// 0 + {"detected_n" ,99 ,99 },// detected_n + {"detected_p" ,98 ,98 },// detected_p + {"dbg_res_rx" ,97 ,94 },// dbg_res_rx[3..0] + {"dbg_res_tx" ,93 ,90 },// dbg_res_tx[3..0] + {"cfg_tx_pol_set" ,89 ,89 },// cfg_tx_pol_set + {"cfg_tx_pol_clr" ,88 ,88 },// cfg_tx_pol_clr + {"cfg_rx_pol_set" ,87 ,87 },// cfg_rx_pol_set + {"cfg_rx_pol_clr" ,86 ,86 },// cfg_rx_pol_clr + {"cfg_rxd_set" ,85 ,85 },// cfg_rxd_set + {"cfg_rxd_clr" ,84 ,84 },// cfg_rxd_clr + {"cfg_rxd_wait" ,83 ,80 },// cfg_rxd_wait[3..0] + {"cfg_cdr_limit" ,79 ,79 },// cfg_cdr_limit + {"cfg_cdr_rotate" ,78 ,78 },// cfg_cdr_rotate + {"cfg_cdr_bw_ctl" ,77 ,76 },// cfg_cdr_bw_ctl[1..0] + {"cfg_cdr_trunc" ,75 ,74 },// cfg_cdr_trunc[1..0] + {"cfg_cdr_rqoffs" ,73 ,64 },// cfg_cdr_rqoffs[9..0] + {"cfg_cdr_inc2" ,63 ,58 },// cfg_cdr_inc2[5..0] + {"cfg_cdr_inc1" ,57 ,52 },// cfg_cdr_inc1[5..0] + {"fusopt_voter_sync" ,51 ,51 },// fusopt_voter_sync + {"rndt" ,50 ,50 },// rndt + {"hcya" ,49 ,49 },// hcya + {"hyst" ,48 ,48 },// hyst + {"idle_dac" ,47 ,45 },// idle_dac[2..0] + {"bg_ref_sel" ,44 ,44 },// bg_ref_sel + {"ic50dac" ,43 ,39 },// ic50dac[4..0] + {"ir50dac" ,38 ,34 },// ir50dac[4..0] + {"tx_rout_comp_bypass" ,33 ,33 },// tx_rout_comp_bypass + {"tx_rout_comp_value" ,32 ,29 },// tx_rout_comp_value[3..0] + {"tx_res_offset" ,28 ,25 },// tx_res_offset[3..0] + {"rx_rout_comp_bypass" ,24 ,24 },// rx_rout_comp_bypass + {"rx_rout_comp_value" ,23 ,20 },// rx_rout_comp_value[3..0] + {"rx_res_offset" ,19 ,16 },// rx_res_offset[3..0] + {"rx_cap_gen2" ,15 ,12 },// rx_cap_gen2[3..0] + {"rx_eq_gen2" ,11 ,8 },// rx_eq_gen2[3..0] + {"rx_cap_gen1" ,7 ,4 },// rx_cap_gen1[3..0] + {"rx_eq_gen1" ,3 ,0 },// rx_eq_gen1[3..0] + {NULL ,-1 ,-1 } +};
Signature · 1 line
2.35.1
PATCH v2 42/52 mips: octeon: Misc changes to existing C files for upcoming eth support
In reply to Stefan RoeseThis patch includes misc changes to already present Octeon MIPS C files files, which are necessary for the upcoming ethernet support.
The changes are mostly:
- DM GPIO & I2C infrastructure
- Coding style cleanup while reworking of the code
--- arch/mips/mach-octeon/cvmx-bootmem.c | 3 +- arch/mips/mach-octeon/cvmx-helper-cfg.c | 655 +---------------- arch/mips/mach-octeon/cvmx-helper-fdt.c | 898 ++++++----------------- arch/mips/mach-octeon/cvmx-helper-util.c | 248 ------- arch/mips/mach-octeon/cvmx-helper.c | 845 +-------------------- 5 files changed, 230 insertions(+), 2419 deletions(-)
arch/mips/mach-octeon/cvmx-bootmem.c +1 -2
@@ -1189,7 +1189,7 @@ s64 cvmx_bootmem_phy_mem_list_init(u64 mem_size,if (mem_size >OCTEON_DDR1_SIZE ) {__cvmx_bootmem_phy_free (OCTEON_DDR1_BASE ,OCTEON_DDR1_SIZE ,0 );__cvmx_bootmem_phy_free (OCTEON_DDR2_BASE , - mem_size -OCTEON_DDR1_SIZE ,0 ); + mem_size -OCTEON_DDR2_BASE ,0 ); }else {__cvmx_bootmem_phy_free (OCTEON_DDR1_BASE , mem_size,0 ); }
@@ -1349,7 +1349,6 @@ s64 cvmx_bootmem_phy_mem_list_init_multi(u8 node_mask, addr +=sizeof (struct cvmx_bootmem_named_block_desc ); } -// test-only: DEBUG ifdef??? cvmx_bootmem_phy_list_print ();return 1 ;
arch/mips/mach-octeon/cvmx-helper-cfg.c +10 -645
771 lines not on this page · raw message
arch/mips/mach-octeon/cvmx-helper-fdt.c +208 -690
1,083 lines not on this page · raw message
arch/mips/mach-octeon/cvmx-helper-util.c +0 -248
269 lines not on this page · raw message
arch/mips/mach-octeon/cvmx-helper.c +11 -834
862 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.35.1
Part of the diff is not shown here. View the raw message.
PATCH v2 43/52 mips: octeon: Makefile: Enable building of the newly added C files
In reply to Stefan RoeseThis patch adds the newly added C files to the Makefile to enable compilation. This is done in a separate step, to not introduce build breakage while adding the single files with potentially missing externals.
--- arch/mips/mach-octeon/Makefile | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
arch/mips/mach-octeon/Makefile +34 -1
@@ -12,13 +12,46 @@ obj-y += cvmx-coremask.o obj-y += cvmx-bootmem.o obj-y += bootoctlinux.o -# QLM related code +# Misc Octeon C files, mostly for QLM & ethernet support +obj-y += cvmx-agl.o +obj-y += cvmx-fpa.o +obj-y += cvmx-fpa-resource.o +obj-y += cvmx-fau-compat.o +obj-y += cvmx-global-resources.o +obj-y += cvmx-cmd-queue.o +obj-y += cvmx-helper-agl.o +obj-y += cvmx-helper-bgx.o +obj-y += cvmx-helper-board.o obj-y += cvmx-helper-cfg.o obj-y += cvmx-helper-fdt.o +obj-y += cvmx-helper-fpa.o +obj-y += cvmx-helper-ilk.o +obj-y += cvmx-helper-ipd.o obj-y += cvmx-helper-jtag.o +obj-y += cvmx-helper-loop.o +obj-y += cvmx-helper-npi.o +obj-y += cvmx-helper-pki.o +obj-y += cvmx-helper-pko.o +obj-y += cvmx-helper-pko3.o +obj-y += cvmx-helper-rgmii.o +obj-y += cvmx-helper-sfp.o +obj-y += cvmx-helper-sgmii.o obj-y += cvmx-helper-util.o +obj-y += cvmx-helper-xaui.o obj-y += cvmx-helper.o +obj-y += cvmx-ilk.o +obj-y += cvmx-ipd.o obj-y += cvmx-pcie.o +obj-y += cvmx-pki.o +obj-y += cvmx-pki-resources.o +obj-y += cvmx-pko.o +obj-y += cvmx-pko-internal-ports-range.o +obj-y += cvmx-pko3.o +obj-y += cvmx-pko3-compat.o +obj-y += cvmx-pko3-resources.o +obj-y += cvmx-pko3-queue.o +obj-y += cvmx-range.o obj-y += cvmx-qlm.o +obj-y += cvmx-qlm-tables.o obj-y += octeon_fdt.o obj-y += octeon_qlm.o
Signature · 1 line
2.35.1
PATCH v2 44/52 mips: octeon: cpu.c: Move bootmem init to arch_early_init_r()
In reply to Stefan RoeseCall octeon_bootmem_init() earlier in the boot process, so that this bootmemory infrastructure is already initialized when e.g. the networking support gets probed.
--- arch/mips/Kconfig | 1 + arch/mips/mach-octeon/cpu.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
arch/mips/Kconfig +1 -0
@@ -101,6 +101,7 @@ config ARCH_JZ47XX config ARCH_OCTEON bool "Support Marvell Octeon CN7xxx platforms" + select ARCH_EARLY_INIT_R select CPU_CAVIUM_OCTEON select DISPLAY_CPUINFO select DMA_ADDR_T_64BIT
arch/mips/mach-octeon/cpu.c +12 -1
@@ -393,14 +393,25 @@ static int init_bootcmd_console(void)return ret; } -int arch_misc_init (void ) +int arch_early_init_r (void ) {int ret; +/* +* Needs to be called pretty early, so that e.g. networking etc +* can access the bootmem infrastructure +*/ ret =octeon_bootmem_init ();if (ret)return ret; +return 0 ; +} + +int arch_misc_init (void ) +{ +int ret; + ret =octeon_configure_load_memory ();if (ret)return ret;
Signature · 1 line
2.35.1
PATCH v2 45/52 mips: octeon: cpu.c: Implement configure_lmtdma_window()
In reply to Stefan RoeseImport configure_lmtdma_window from Marvell 2013 U-Boot as it's needed for network functionality.
--- arch/mips/mach-octeon/cpu.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
arch/mips/mach-octeon/cpu.c +33 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0+ /* -* Copyright (C) 2020 Marvell International Ltd. +* Copyright (C) 2020-2022 Marvell International Ltd. */ #include <dm.h>
@@ -17,6 +17,8 @@#include <mach/cvmx-bootmem.h> #include <mach/cvmx-regs.h> #include <mach/cvmx-sata-defs.h> +#include <mach/octeon-model.h> +#include <mach/octeon-feature.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -393,6 +395,33 @@ static int init_bootcmd_console(void)return ret; } +static void configure_lmtdma_window (void ) +{ +u64 tmp; +u64 addr; +u64 end_addr; + +CVMX_MF_CVM_MEM_CTL (tmp); + tmp &= ~0x1ffull ; + tmp |=0x104ull ; + +/* enable LMTDMA */ + tmp |= (1ull <<51 ); +/* configure scratch line 2 for LMT */ +/* TODO: reserve this scratch line, so that others will not use it */ +/* TODO: store LMTLINE in global var */ + tmp |= (CVMX_PKO_LMTLINE <<45 ); +/* clear LMTLINE in scratch */ + addr =CVMX_PKO_LMTLINE *CVMX_CACHE_LINE_SIZE ; + end_addr = addr +CVMX_CACHE_LINE_SIZE ; + +while (addr < end_addr) { + *CASTPTR(volatile u64, addr + CVMX_SCRATCH_BASE) = (u64)0; + addr +=8 ; + } +CVMX_MT_CVM_MEM_CTL (tmp); +} +int arch_early_init_r (void ) {int ret;
@@ -405,6 +434,9 @@ int arch_early_init_r(void)if (ret)return ret; +if (octeon_has_feature (OCTEON_FEATURE_PKO3 )) +configure_lmtdma_window (); +return 0 ; }
Signature · 1 line
2.35.1
PATCH v2 46/52 mips: octeon: octeon_common.h: Move init SP because of increased image size
In reply to Stefan RoeseThis patch moves CONFIG_SYS_INIT_SP_OFFSET to a higher address so that it does not interfere with larger U-Boot images. This was noticed, while adding network support to the EBB7304 board.
--- include/configs/octeon_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/octeon_common.h +1 -1
@@ -8,7 +8,7 @@#define __OCTEON_COMMON_H__#if defined(CONFIG_RAM_OCTEON ) -#define CONFIG_SYS_INIT_SP_OFFSET 0x20100000 +#define CONFIG_SYS_INIT_SP_OFFSET 0x20180000#else /* No DDR init -> run in L2 cache with limited resources */ #define CONFIG_SYS_INIT_SP_OFFSET 0x00180000
Signature · 1 line
2.35.1
PATCH v2 47/52 mips: octeon: mrvl, cn73xx.dtsi: Add ethernet (BGX) and SMI DT nodes
In reply to Stefan RoeseAdd the Octeon ethernet (BGX) and SMI DT node to the dtsi file.
--- arch/mips/dts/mrvl,cn73xx.dtsi | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
arch/mips/dts/mrvl,cn73xx.dtsi +35 -0
@@ -267,5 +267,40 @@ interrupts = <0x6c010 4>; }; }; + + /* SMI1 */ + smi1: mdio@1180000003880 { + compatible = "cavium,octeon-3860-mdio"; + reg = <0x11800 0x00003880 0x0 0x40>; + #address-cells = <1>; + #size-cells = <0>; + }; + + /* BGX 0 */ + bgx0: ethernet-mac-nexus@11800e0000000 { + compatible = "cavium,octeon-7890-bgx"; + reg = <0x11800 0xe0000000 0x0 0x1000000>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + /* BGX 1 */ + bgx1: ethernet-mac-nexus@11800e1000000 { + compatible = "cavium,octeon-7890-bgx"; + reg = <0x11800 0xe1000000 0x0 0x1000000>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + /* BGX 2*/ + bgx2: ethernet-mac-nexus@11800e2000000 { + compatible = "cavium,octeon-7890-bgx"; + reg = <0x11800 0xe2000000 0x0 0x1000000>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; }; };
Signature · 1 line
2.35.1
PATCH v2 48/52 mips: octeon: mrvl, octeon-ebb7304.dts: Add ethernet DT support
In reply to Stefan RoeseAdd the Octeon ethernet (BGX), SMI and PHY DT nodes to the EBB7304 dts file to enable ethernet support on this board.
--- arch/mips/dts/mrvl,octeon-ebb7304.dts | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
arch/mips/dts/mrvl,octeon-ebb7304.dts +45 -0
@@ -201,3 +201,48 @@ cd-gpios = <&gpio 25 1>; /* active low */ }; }; + +/* SMI_1 -- Available on rev 2 and later boards */ +&smi1 { + /** + * The phy names are broken down as follows: + * (m)phyxxyzzs + * where: + * xx = 01 for SGMII, 10 for DXAUI, 20 for RXAUI + * and 40 for XFI/LXAUI + * y = QLM/DLM number + * zz = PHY address (decimal) + * s = sub-phy number in the case of the Cortina + * PHY + * a mphy is a nexus phy that contains one or more + * sub-phys, for example the Cortina CS4223. + */ + + /* QLM 2 */ + phy01208: ethernet-phy@01208 { + reg = <8>; + compatible = "marvell,88e1240", "ethernet-phy-ieee802.3-c22"; + + marvell,reg-init = <3 0x10 0 0x8665>, + <3 0x11 0 0x00aa>, + <3 0x12 0 0x4105>, + <3 0x13 0 0x8a08>; + + interrupt-parent = <&gpio>; + interrupts = <12 8>; /* Pin 12, active low */ + }; +}; + +/* BGX 0 */ +&bgx0 { + status = "okay"; + phy-handle = <&phy01208>; /* put phy-handle in BGX node and MAC node */ + + /* SerDes 0, may differ from PCS Lane/LMAC */ + eth0: ethernet-mac@D { + compatible = "cavium,octeon-7890-bgx-port"; + reg = <0>; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-handle = <&phy01208>; + }; +};
Signature · 1 line
2.35.1
PATCH v2 49/52 mips: octeon: mrvl, octeon-nic23.dts: Add ethernet DT support
In reply to Stefan RoeseAdd the Octeon ethernet (BGX) and SFP DT nodes to the NIC23 dts file to enable ethernet support on this board.
--- arch/mips/dts/mrvl,octeon-nic23.dts | 238 ++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+)
arch/mips/dts/mrvl,octeon-nic23.dts +238 -0
@@ -118,11 +118,208 @@ &i2c0 { u-boot,dm-pre-reloc; /* Needed early for DDR SPD EEPROM */ clock-frequency = <100000>; + + sfp0eeprom: eeprom@50 { + compatible = "atmel,24c01"; + reg = <0x50>; + }; + + sfp0alerts: eeprom@51 { + compatible = "atmel,24c01"; + reg = <0x51>; + }; }; &i2c1 { u-boot,dm-pre-reloc; /* Needed early for DDR SPD EEPROM */ clock-frequency = <100000>; + + vitesse@10 { + compatible = "vitesse,vsc7224"; + reg = <0x10>; + #address-cells = <1>; + #size-cells = <0>; + + /* Note that reset is active high with this device */ + reset = <&gpio 7 0>; + + /* LoS pin can be pulled low when there is a loss of signal */ + los = <&gpio 6 0>; + + vitesse,reg-init = + /* Clear all masks */ + /* Page select FSYNC0 (0x30) */ + <0x7f 0x0030>, + /* Set FSYNC0 for 10.3125Gbps */ + <0x80 0x2841>, /* See Table 3. */ + <0x81 0x0008>, + <0x82 0xc000>, + <0x83 0x0010>, + <0x84 0x1d00>, + + /* All channels Rx settings set equally */ + <0x7f 0x0050>, + /* Shrink EQ_BUFF */ + <0x82 0x0014>, + /* Set EQVGA_ADAP = 1 (enable EQVGA circuitry), + * USE_UNIT_GAIN = 1 (EQVGA is in unity gain), + * USE_LPF = 0 (VGA adapt not using LPF), + * USE_EQVGA = 1 + <0x89 0x7f13>, + /* Select min DFE Delay (DFE_DELAY) */ + <0x90 0x5785>, + /* Set DFE 1-3 limit (DXMAX) = 32dec, + * AP Max limit = 127 decimal + */ + <0x92 0x207f>, + /* Set AP Min limit = 32 decimal */ + <0x93 0x2000>, + /* Set DFE Averaging to the slowest (DFE_AVG) */ + <0x94 0x0031>, + /* Set Inductor Bypass OD_IND_BYP = 0 & fastest Rise/Fall */ + <0x9c 0x0000>, + /* Setting DFE Boost = none. Must set for + * rev C (if DFE in adapt mode) + */ + <0xaa 0x0888>, + /* Setting EQ Min = 8 & Max limit = 72 dec. + * Must set for rev C, otherwise EQ is 0 + * (if EQ is in adaptive mode) + */ + <0xa8 0x2408>, + /* Setting EQVGA = 96, when in EQVGA manual mode */ + <0xa9 0x0060>, + /* Setting SW_BFOCM, bits 15:14 to 01 */ + <0x87 0x4021>, + /* Turn off adaptive input equalization + * and VGA adaptive algorithm control. + */ + <0x89 0x7313>, + /* Turn on adaptive input equalization + * and VGA adaptive algorithm control. + */ + <0x89 0x7f13>; + + vitesse-channel@0 { + compatible = "vitesse,vsc7224-channel"; + reg = <0>; + direction-tx; + sfp-mac = <ð0>; + + /* TAP settings. The format of this is as + * follows: + * - cable length in meters, 0 = active or + * optical module + * - maintap value + * - pretap value + * - posttap value + * + * For the cable length, the value will apply + * for that cable length and greater until the + * next largest cable length specified. These + * values must be ordered first by channel mask + * then by cable length. These are typically + * set for the transmit channels, not the + * receive channels. + */ + taps = <0 0x0013 0x000f 0x0000>, + <1 0x001f 0x000f 0x0004>, + <3 0x0014 0x000b 0x0004>, + <5 0x0014 0x0009 0x0006>, + <7 0x0014 0x000f 0x0000>, + <10 0x0012 0x000b 0x0013>; + }; + + vitesse-channel@1 { + compatible = "vitesse,vsc7224-channel"; + reg = <1>; + /* Ignore mod_abs and module */ + direction-rx; + sfp-mac = <ð0>; + + /* Disable pre-tap */ + pretap-disable; + + /* Disable post-tap */ + posttap-disable; + + /* Taps has the following fields: + * - cable length (ignored for rx) + * - main tap value + * - pre tap value + * - post tap value + * + * NOTE: if taps are disabled then they + * are not programmed. + */ + taps = <0 0x0a 0x0b 0x10>; + }; + + vitesse-channel@2 { + compatible = "vitesse,vsc7224-channel"; + reg = <2>; + direction-tx; + sfp-mac = <ð1>; + + /* TAP settings. The format of this is as + * follows: + * - cable length in meters, 0 = active or + * optical module + * - maintap value + * - pretap value + * - posttap value + * + * For the cable length, the value will apply + * for that cable length and greater until the + * next largest cable length specified. These + * values must be ordered first by channel mask + * then by cable length. These are typically + * set for the transmit channels, not the + * receive channels. + */ + taps = <0 0x0013 0x000f 0x0000>, + <1 0x001f 0x000f 0x0004>, + <3 0x0014 0x000b 0x0004>, + <5 0x0014 0x0009 0x0006>, + <7 0x0014 0x000f 0x0000>, + <10 0x0012 0x000b 0x0013>; + }; + + vitesse-channel@3 { + compatible = "vitesse,vsc7224-channel"; + reg = <3>; + /* Ignore mod_abs and module */ + direction-rx; + sfp-mac = <ð1>; + + /* Disable pre-tap */ + pretap-disable; + + /* Disable post-tap */ + posttap-disable; + + /* Taps has the following fields: + * - cable length (ignored for rx) + * - main tap value + * - pre tap value + * - post tap value + * + * NOTE: if taps are disabled then they + * are not programmed. + */ + taps = <0 0x0a 0x0b 0x10>; + }; + }; + + sfp1eeprom: eeprom@50 { + compatible = "atmel,24c01"; + reg = <0x50>; + }; + + sfp1alerts: eeprom@51 { + compatible = "atmel,24c01"; + reg = <0x51>; + }; }; &mmc {
@@ -151,6 +348,26 @@ compatible = "marvell,pci-bootcmd"; status = "okay"; }; + + sfp0: sfp-slot@0 { + compatible = "ethernet,sfp-slot"; + tx_disable = <&gpio 16 0>; + mod_abs = <&gpio 17 0>; + tx_error = <&gpio 19 0>; + rx_los = <&gpio 18 0>; + eeprom = <&sfp0eeprom>; + diag = <&sfp0alerts>; + }; + + sfp1: sfp-slot@1 { + compatible = "ethernet,sfp-slot"; + tx_disable = <&gpio 21 0>; + mod_abs = <&gpio 22 0>; + tx_error = <&gpio 24 0>; + rx_los = <&gpio 23 0>; + eeprom = <&sfp1eeprom>; + diag = <&sfp1alerts>; + }; }; &spi {
@@ -160,3 +377,24 @@ reg = <0>; }; }; + +/* BGX 2 */ +&bgx2 { + status = "okay"; + + /* SerDes 0, may differ from PCS Lane/LMAC */ + eth0: ethernet-mac@0 { + compatible = "cavium,octeon-7890-bgx-port"; + reg = <0>; + local-mac-address = [ 00 00 00 00 00 00 ]; + sfp-slot = <&sfp0>; + }; + + /* SerDes 1, may differ from PCS Lane/LMAC */ + eth1: ethernet-mac@1 { + compatible = "cavium,octeon-7890-bgx-port"; + reg = <1>; + local-mac-address = [ 00 00 00 00 00 00 ]; + sfp-slot = <&sfp1>; + }; +};
Signature · 1 line
2.35.1
PATCH v2 50/52 net: Add ethernet support for MIPS Octeon
In reply to Stefan RoeseThis patchs adds the ethernet & MDIO driver for the MIPS Octeon II / III SoC platform. Please note that these drivers are based on the 2013 U-Boot version from Marvell and make use of the platform supported helper functions for the ethernet functionality, including stuff like SFP handling.
--- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/octeon/Makefile | 6 + drivers/net/octeon/octeon_eth.c | 1060 ++++++++++++++++++++++++++++++ drivers/net/octeon/octeon_mdio.c | 226 +++++++ 5 files changed, 1300 insertions(+) create mode 100644 drivers/net/octeon/Makefile create mode 100644 drivers/net/octeon/octeon_eth.c create mode 100644 drivers/net/octeon/octeon_mdio.c
drivers/net/Kconfig +7 -0
@@ -490,6 +490,13 @@ config MT7628_ETH The MediaTek MT7628 ethernet interface is used on MT7628 and MT7688 based boards. +config NET_OCTEON + bool "MIPS Octeon ethernet support" + depends on ARCH_OCTEON + help + You must select Y to enable network device support for + MIPS Octeon SoCs. If unsure, say n + config NET_OCTEONTX bool "OcteonTX Ethernet support" depends on ARCH_OCTEONTX
drivers/net/Makefile +1 -0
@@ -72,6 +72,7 @@ obj-$(CONFIG_MVNETA) += mvneta.o obj-$(CONFIG_MVPP2) += mvpp2.o obj-$(CONFIG_NATSEMI) += natsemi.o obj-$(CONFIG_NETCONSOLE) += netconsole.o +obj-$(CONFIG_NET_OCTEON) += octeon/ obj-$(CONFIG_NET_OCTEONTX) += octeontx/ obj-$(CONFIG_NET_OCTEONTX2) += octeontx2/ obj-$(CONFIG_NS8382X) += ns8382x.o
drivers/net/octeon/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2018-2022 Marvell International Ltd. +# + +obj-$(CONFIG_NET_OCTEON) += octeon_eth.o octeon_mdio.o
drivers/net/octeon/octeon_eth.c new file +1060 -0
1,060 lines not on this page · raw message
drivers/net/octeon/octeon_mdio.c new file +226 -0
226 lines not on this page · raw message
Signature · 1 line
2.35.1
PATCH v2 51/52 mips: octeon: ebb7304: Enable ethernet support
In reply to Stefan RoeseThis patch enables the Kconfig symbols needed for full ethernet support on the EBB7304. Also the PHY autonegotiation timeout is increased, as the default 5 seconds are sometime a bit short. With this, ethernet can be used on this board. Here an example of a tftp load:
=> tftp ffffffff81000000 big
ethernet-mac-nexus@11800e0000000 Waiting for PHY auto negotiation to complete....... done Using ethernet-mac-nexus@11800e0000000 device
TFTP from server 192.168.1.5; our IP address is 192.168.1.243
Filename 'big'.
Load address: 0xffffffff81000000
Loading: ################################################## 10 MiB
13.2 MiB/s
done
Bytes transferred = 10485760 (a00000 hex)
--- configs/octeon_ebb7304_defconfig | 7 +++++++ include/configs/octeon_ebb7304.h | 2 ++ 2 files changed, 9 insertions(+)
configs/octeon_ebb7304_defconfig +7 -0
@@ -25,6 +25,7 @@ CONFIG_CMD_PART=y CONFIG_CMD_PCI=y CONFIG_CMD_USB=y CONFIG_CMD_DHCP=y +CONFIG_CMD_MII=y CONFIG_CMD_PING=y CONFIG_CMD_RTC=y CONFIG_CMD_TIME=y
@@ -36,6 +37,7 @@ CONFIG_EFI_PARTITION=y CONFIG_PARTITION_TYPE_GUID=y CONFIG_ENV_IS_IN_FLASH=y CONFIG_ENV_ADDR=0x800000001FBFE000 +CONFIG_TFTP_TSIZE=y CONFIG_CLK=y # CONFIG_INPUT is not set CONFIG_MISC=y
@@ -53,7 +55,12 @@ CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_SPANSION=y CONFIG_SPI_FLASH_STMICRO=y +CONFIG_PHYLIB=y +CONFIG_PHY_MARVELL=y +CONFIG_DM_MDIO=y +CONFIG_DM_ETH_PHY=y CONFIG_E1000=y +CONFIG_NET_OCTEON=y CONFIG_PCI=y CONFIG_PCIE_OCTEON=y CONFIG_DM_REGULATOR=y
include/configs/octeon_ebb7304.h +2 -0
@@ -16,4 +16,6 @@#define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_8BIT#define CONFIG_SYS_FLASH_EMPTY_INFO /* flinfo indicates empty blocks */ +#define PHY_ANEG_TIMEOUT 8000/* PHY needs a longer aneg time */ +#endif /* __CONFIG_H__ */
Signature · 1 line
2.35.1
PATCH v2 52/52 mips: octeon: nic23: Enable ethernet support
In reply to Stefan RoeseThis patch enables the Kconfig symbols needed for full ethernet support on the NIC23. Additionally board specific setup is done, mostly GPIOs related to SFP / GPIO configuration. With this, ethernet can be used on this board. Here an example of a tftp load:
=> tftp ffffffff81000000 big
Using ethernet-mac-nexus@11800e2000000 device
TFTP from server 192.168.1.5; our IP address is 192.168.1.247 Filename 'big'.
Load address: 0xffffffff81000000
Loading: ################################################## 10 MiB
9.7 MiB/s
done
Bytes transferred = 10485760 (a00000 hex)
--- board/Marvell/octeon_nic23/board.c | 87 +++++++++++++++++++++++++++++- configs/octeon_nic23_defconfig | 10 +++- 2 files changed, 95 insertions(+), 2 deletions(-)
board/Marvell/octeon_nic23/board.c +86 -1
@@ -1,10 +1,11 @@// SPDX-License-Identifier: GPL-2.0+ /* -* Copyright (C) 2021 Stefan Roese <[email protected]> +* Copyright (C) 2021-2022 Stefan Roese <[email protected]> */ #include <dm.h> #include <ram.h> +#include <asm/gpio.h> #include <mach/octeon_ddr.h> #include <mach/cvmx-qlm.h>
@@ -84,6 +85,52 @@ int board_fix_fdt(void *fdt)return rc; } +int board_early_init_f (void ) +{ +struct gpio_desc gpio = {}; +ofnode node; + +/* Initial GPIO configuration */ + +/* GPIO 7: Vitesse reset */ + node =ofnode_by_compatible (ofnode_null (),"vitesse,vsc7224" ); +if (ofnode_valid (node)) { +gpio_request_by_name_nodev (node,"los" ,0 , &gpio,GPIOD_IS_IN ); +dm_gpio_free (gpio.dev, &gpio); +gpio_request_by_name_nodev (node,"reset" ,0 , &gpio, +GPIOD_IS_OUT ); +if (dm_gpio_is_valid (&gpio)) { +/* Vitesse reset */ +debug ("%s: Setting GPIO 7 to 1\n" , __func__); +dm_gpio_set_value (&gpio,1 ); + } +dm_gpio_free (gpio.dev, &gpio); + } + +/* SFP+ transmitters */ +ofnode_for_each_compatible_node (node,"ethernet,sfp-slot" ) { +gpio_request_by_name_nodev (node,"tx_disable" ,0 , + &gpio,GPIOD_IS_OUT ); +if (dm_gpio_is_valid (&gpio)) { +debug ("%s: Setting GPIO %d to 1\n" , __func__, + gpio.offset); +dm_gpio_set_value (&gpio,1 ); + } +dm_gpio_free (gpio.dev, &gpio); +gpio_request_by_name_nodev (node,"mod_abs" ,0 , &gpio, +GPIOD_IS_IN ); +dm_gpio_free (gpio.dev, &gpio); +gpio_request_by_name_nodev (node,"tx_error" ,0 , &gpio, +GPIOD_IS_IN ); +dm_gpio_free (gpio.dev, &gpio); +gpio_request_by_name_nodev (node,"rx_los" ,0 , &gpio, +GPIOD_IS_IN ); +dm_gpio_free (gpio.dev, &gpio); + } + +return 0 ; +} +void board_configure_qlms (void ) {octeon_configure_qlm (4 ,3000 ,CVMX_QLM_MODE_SATA_2X1 ,0 ,0 ,0 ,0 );
@@ -100,7 +147,45 @@ void board_configure_qlms(void)int board_late_init (void ) { +struct gpio_desc gpio = {}; +ofnode node; + +/* Turn on SFP+ transmitters */ +ofnode_for_each_compatible_node (node,"ethernet,sfp-slot" ) { +gpio_request_by_name_nodev (node,"tx_disable" ,0 , + &gpio,GPIOD_IS_OUT ); +if (dm_gpio_is_valid (&gpio)) { +debug ("%s: Setting GPIO %d to 0\n" , __func__, + gpio.offset); +dm_gpio_set_value (&gpio,0 ); + } +dm_gpio_free (gpio.dev, &gpio); + } +board_configure_qlms ();return 0 ; } + +int last_stage_init (void ) +{ +struct gpio_desc gpio = {}; +ofnode node; + + node =ofnode_by_compatible (ofnode_null (),"vitesse,vsc7224" ); +if (!ofnode_valid (node)) { +printf ("Vitesse SPF DT node not found!" ); +return 0 ; + } + +gpio_request_by_name_nodev (node,"reset" ,0 , &gpio,GPIOD_IS_OUT ); +if (dm_gpio_is_valid (&gpio)) { +/* Take Vitesse retimer out of reset */ +debug ("%s: Setting GPIO 7 to 0\n" , __func__); +dm_gpio_set_value (&gpio,0 ); +mdelay (50 ); + } +dm_gpio_free (gpio.dev, &gpio); + +return 0 ; +}
configs/octeon_nic23_defconfig +9 -1
@@ -12,6 +12,7 @@ CONFIG_ARCH_OCTEON=y CONFIG_TARGET_OCTEON_NIC23=y # CONFIG_MIPS_CACHE_SETUP is not set # CONFIG_MIPS_CACHE_DISABLE is not set +CONFIG_MIPS_RELOCATION_TABLE_SIZE=0xc000 CONFIG_DEBUG_UART=y CONFIG_AHCI=y CONFIG_OF_BOARD_FIXUP=y
@@ -19,7 +20,9 @@ CONFIG_SYS_LOAD_ADDR=0xffffffff80100000 CONFIG_SYS_CONSOLE_ENV_OVERWRITE=y # CONFIG_SYS_DEVICE_NULLDEV is not set CONFIG_ARCH_MISC_INIT=y +CONFIG_BOARD_EARLY_INIT_F=y CONFIG_BOARD_LATE_INIT=y +CONFIG_LAST_STAGE_INIT=y CONFIG_HUSH_PARSER=y # CONFIG_CMD_FLASH is not set CONFIG_CMD_GPIO=y
@@ -37,6 +40,7 @@ CONFIG_CMD_FS_GENERIC=y CONFIG_EFI_PARTITION=y CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_ENV_ADDR=0xe000 +CONFIG_TFTP_TSIZE=y CONFIG_SATA=y CONFIG_AHCI_MVEBU=y CONFIG_CLK=y
@@ -50,7 +54,11 @@ CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_SPANSION=y CONFIG_SPI_FLASH_STMICRO=y -# CONFIG_NETDEVICES is not set +CONFIG_PHYLIB=y +CONFIG_PHYLIB_10G=y +CONFIG_DM_MDIO=y +CONFIG_DM_ETH_PHY=y +CONFIG_NET_OCTEON=y CONFIG_PCI=y CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_FIXED=y
Signature · 1 line
2.35.1
Hi Daniel,
Quoted 35 lines · Stefan Roese
This patchset adds the networking files and drivers including device helper headers and C files. Please excuse the massive amount of files in this patch series. Also the sometimes huge files (mostly headers with register definitions) that I needed to include.
The infrastructure code with all the headers is ported mistly without any intended functional changes from the 2013 Cavium / Marvell U-Boot version. It has undergone many hours of extensive code cleanup and reformatting. Some of it done by using tools (checkpatch, Lindent, clang format etc) and also some of it done manually, as I couldn't find some tools that could do the needed work in a reliable and functional way. The result is that checkpatch now only throws a "few" warnings that are left. Some of those can't be removed without an even more extensive cleanup / rewrite of the code, like the addition of typedefs.
The added header, helper and infrastructure files in the first part of the patch-series (patches 1-43) are the foundation, that is used by the main Octeon U-Boot ethernet driver (patch 50/52). Patches 47-49 add the DT nodes and properties to the corresponding dtsi / dts files. Patches 51 & 52 finally enable the ethernet support both MIPS Octeon boards, EBB7304 & NIC23.
All this is tested on the 2 Cavium / Marvell MIPS Octeon boards:
EBB7304 & NIC23This patchset including the small Marvell PHY patches is available in this gitlab branch:
https://source.denx.de/u-boot/custodians/u-boot-marvell/-/tree/mips-octeon-ethernet-v2-2022-04-07
Changes in v2:
- As suggested by Daniel, remove all unreferenced functions from the source code by manually inspecting u-boot.map [1]
- Rebased on latest TOT
Quoted 6 lines
[1] Here the diffstat comarison between v1 and v2:
v1: 77 files changed, 42315 insertions(+), 586 deletions(-) v2: 78 files changed, 33672 insertions(+), 2524 deletions(-)Thanks,
Stefan
Daniel, do you have any comments on this patchset? Tom has assigned it to me in patchwork and I would really like to get it merged into mainline, if possible. So if you don't have any obejctions, then I would pull it via the Marvell tree soon.
Thanks,
Stefan
Hi Stefan,
Am 02.05.22 um 18:00 schrieb Stefan Roese:
Quoted 44 lines
Hi Daniel,
Quoted 41 lines · Stefan Roese
This patchset adds the networking files and drivers including device helper headers and C files. Please excuse the massive amount of files in this patch series. Also the sometimes huge files (mostly headers with register definitions) that I needed to include.
The infrastructure code with all the headers is ported mistly without any intended functional changes from the 2013 Cavium / Marvell U-Boot version. It has undergone many hours of extensive code cleanup and reformatting. Some of it done by using tools (checkpatch, Lindent, clang format etc) and also some of it done manually, as I couldn't find some tools that could do the needed work in a reliable and functional way. The result is that checkpatch now only throws a "few" warnings that are left. Some of those can't be removed without an even more extensive cleanup / rewrite of the code, like the addition of typedefs.
The added header, helper and infrastructure files in the first part of the patch-series (patches 1-43) are the foundation, that is used by the main Octeon U-Boot ethernet driver (patch 50/52). Patches 47-49 add the DT nodes and properties to the corresponding dtsi / dts files. Patches 51 & 52 finally enable the ethernet support both MIPS Octeon boards, EBB7304 & NIC23.
All this is tested on the 2 Cavium / Marvell MIPS Octeon boards:
EBB7304 & NIC23This patchset including the small Marvell PHY patches is available in this gitlab branch:
https://source.denx.de/u-boot/custodians/u-boot-marvell/-/tree/mips-octeon-ethernet-v2-2022-04-07
Changes in v2:
- As suggested by Daniel, remove all unreferenced functions from the source
code by manually inspecting u-boot.map [1]
- Rebased on latest TOT[1] Here the diffstat comarison between v1 and v2:
v1: 77 files changed, 42315 insertions(+), 586 deletions(-) v2: 78 files changed, 33672 insertions(+), 2524 deletions(-)
Quoted 8 lines
Quoted 2 lines
Thanks,
StefanDaniel, do you have any comments on this patchset? Tom has assigned it to me in patchwork and I would really like to get it merged into mainline, if possible. So if you don't have any obejctions, then I would pull it via the Marvell tree soon.
for the parts that I can reasonably review, I don't have any objections. I'd be happy if you pull it yourself as I'm currently really busy ;)
Signature · 1 line
- Daniel
Quoted 223 lines · Stefan Roese
This patchset adds the networking files and drivers including device helper headers and C files. Please excuse the massive amount of files in this patch series. Also the sometimes huge files (mostly headers with register definitions) that I needed to include.
The infrastructure code with all the headers is ported mistly without any intended functional changes from the 2013 Cavium / Marvell U-Boot version. It has undergone many hours of extensive code cleanup and reformatting. Some of it done by using tools (checkpatch, Lindent, clang format etc) and also some of it done manually, as I couldn't find some tools that could do the needed work in a reliable and functional way. The result is that checkpatch now only throws a "few" warnings that are left. Some of those can't be removed without an even more extensive cleanup / rewrite of the code, like the addition of typedefs.
The added header, helper and infrastructure files in the first part of the patch-series (patches 1-43) are the foundation, that is used by the main Octeon U-Boot ethernet driver (patch 50/52). Patches 47-49 add the DT nodes and properties to the corresponding dtsi / dts files. Patches 51 & 52 finally enable the ethernet support both MIPS Octeon boards, EBB7304 & NIC23.
All this is tested on the 2 Cavium / Marvell MIPS Octeon boards:
EBB7304 & NIC23This patchset including the small Marvell PHY patches is available in this gitlab branch:
https://source.denx.de/u-boot/custodians/u-boot-marvell/-/tree/mips-octeon-ethernet-v2-2022-04-07
Changes in v2:
- As suggested by Daniel, remove all unreferenced functions from the source code by manually inspecting u-boot.map [1]
- Rebased on latest TOT[1] Here the diffstat comarison between v1 and v2:
v1: 77 files changed, 42315 insertions(+), 586 deletions(-) v2: 78 files changed, 33672 insertions(+), 2524 deletions(-)Thanks,
StefanAaron Williams (40):
mips: octeon: Add misc cvmx-* header files
mips: octeon: Addcvmx-ilk-defs.hheader file
mips: octeon: Addcvmx-iob-defs.hheader file
mips: octeon: Addcvmx-lbk-defs.hheader file
mips: octeon: Addcvmx-npei-defs.hheader file
mips: octeon: Addcvmx-pcsxx-defs.hheader file
mips: octeon: Addcvmx-xcv-defs.hheader file
mips: octeon: Addcvmx-helper-agl.c
mips: octeon: Addcvmx-helper-bgx.c
mips: octeon: Addcvmx-helper-board.c
mips: octeon: Addcvmx-helper-fpa.c
mips: octeon: Addcvmx-helper-ilk.c
mips: octeon: Addcvmx-helper-ipd.c
mips: octeon: Addcvmx-helper-loop.c
mips: octeon: Addcvmx-helper-npi.c
mips: octeon: Addcvmx-helper-pki.c
mips: octeon: Addcvmx-helper-pko.c
mips: octeon: Addcvmx-helper-pko3.c
mips: octeon: Addcvmx-helper-rgmii.c
mips: octeon: Addcvmx-helper-sgmii.c
mips: octeon: Addcvmx-helper-sfp.c
mips: octeon: Addcvmx-helper-xaui.c
mips: octeon: Addcvmx-agl.c
mips: octeon: Addcvmx-cmd-queue.c
mips: octeon: Addcvmx-fau-compat.c
mips: octeon: Addcvmx-fpa.c
mips: octeon: Addcvmx-fpa-resource.c
mips: octeon: Addcvmx-global-resource.c
mips: octeon: Addcvmx-ilk.c
mips: octeon: Addcvmx-ipd.c
mips: octeon: Addcvmx-pki.c
mips: octeon: Addcvmx-pki-resources.c
mips: octeon: Addcvmx-pko.c
mips: octeon: Addcvmx-pko3.c
mips: octeon: Addcvmx-pko3-queue.c
mips: octeon: Addcvmx-pko3-compat.c
mips: octeon: Addcvmx-pko3-resources.c
mips: octeon: Addcvmx-pko-internal-ports-range.c
mips: octeon: Addcvmx-qlm-tables.c
mips: octeon: Addcvmx-range.cStefan Roese (12):
mips: octeon: Misc changes to existing headers for upcoming eth
support
mips: octeon: Misc changes to existing C files for upcoming eth
support
mips: octeon:Makefile: Enable building of the newly added C files
mips: octeon:cpu.c: Move bootmem init toarch_early_init_r()
mips: octeon:cpu.c: Implementconfigure_lmtdma_window()
mips: octeon:octeon_common.h: Move init SP because of increased image
size
mips: octeon: mrvl,cn73xx.dtsi: Add ethernet (BGX) and SMI DT nodes
mips: octeon: mrvl,octeon-ebb7304.dts: Add ethernet DT support
mips: octeon: mrvl,octeon-nic23.dts: Add ethernet DT support
net: Add ethernet support for MIPS Octeon
mips: octeon: ebb7304: Enable ethernet support
mips: octeon: nic23: Enable ethernet supportarch/mips/Kconfig | 1 + arch/mips/dts/mrvl,cn73xx.dtsi | 35 + arch/mips/dts/mrvl,octeon-ebb7304.dts | 45 + arch/mips/dts/mrvl,octeon-nic23.dts | 238 ++ arch/mips/mach-octeon/Makefile | 35 +- arch/mips/mach-octeon/cpu.c | 47 +- arch/mips/mach-octeon/cvmx-agl.c | 216 + arch/mips/mach-octeon/cvmx-bootmem.c | 3 +- arch/mips/mach-octeon/cvmx-cmd-queue.c | 355 ++ arch/mips/mach-octeon/cvmx-fau-compat.c | 53 + arch/mips/mach-octeon/cvmx-fpa-resource.c | 219 + arch/mips/mach-octeon/cvmx-fpa.c | 1127 ++++++ arch/mips/mach-octeon/cvmx-global-resources.c | 517 +++ arch/mips/mach-octeon/cvmx-helper-agl.c | 231 ++ arch/mips/mach-octeon/cvmx-helper-bgx.c | 2737 +++++++++++++ arch/mips/mach-octeon/cvmx-helper-board.c | 1824 +++++++++ arch/mips/mach-octeon/cvmx-helper-cfg.c | 655 +-- arch/mips/mach-octeon/cvmx-helper-fdt.c | 898 +---- arch/mips/mach-octeon/cvmx-helper-fpa.c | 76 + arch/mips/mach-octeon/cvmx-helper-ilk.c | 902 +++++ arch/mips/mach-octeon/cvmx-helper-ipd.c | 286 ++ arch/mips/mach-octeon/cvmx-helper-loop.c | 178 + arch/mips/mach-octeon/cvmx-helper-npi.c | 137 + arch/mips/mach-octeon/cvmx-helper-pki.c | 549 +++ arch/mips/mach-octeon/cvmx-helper-pko.c | 203 + arch/mips/mach-octeon/cvmx-helper-pko3.c | 1088 +++++ arch/mips/mach-octeon/cvmx-helper-rgmii.c | 398 ++ arch/mips/mach-octeon/cvmx-helper-sfp.c | 1309 ++++++ arch/mips/mach-octeon/cvmx-helper-sgmii.c | 781 ++++ arch/mips/mach-octeon/cvmx-helper-util.c | 248 -- arch/mips/mach-octeon/cvmx-helper-xaui.c | 518 +++ arch/mips/mach-octeon/cvmx-helper.c | 845 +--- arch/mips/mach-octeon/cvmx-ilk.c | 1199 ++++++ arch/mips/mach-octeon/cvmx-ipd.c | 149 + arch/mips/mach-octeon/cvmx-pki-resources.c | 285 ++ arch/mips/mach-octeon/cvmx-pki.c | 910 +++++ .../cvmx-pko-internal-ports-range.c | 99 + arch/mips/mach-octeon/cvmx-pko.c | 788 ++++ arch/mips/mach-octeon/cvmx-pko3-compat.c | 656 +++ arch/mips/mach-octeon/cvmx-pko3-queue.c | 879 ++++ arch/mips/mach-octeon/cvmx-pko3-resources.c | 213 + arch/mips/mach-octeon/cvmx-pko3.c | 786 ++++ arch/mips/mach-octeon/cvmx-qlm-tables.c | 292 ++ arch/mips/mach-octeon/cvmx-range.c | 259 ++ arch/mips/mach-octeon/include/mach/cvmx-agl.h | 45 + .../mach-octeon/include/mach/cvmx-bootmem.h | 3 +- .../mach-octeon/include/mach/cvmx-config.h | 128 + arch/mips/mach-octeon/include/mach/cvmx-fau.h | 581 +++ arch/mips/mach-octeon/include/mach/cvmx-fpa.h | 3 +- .../mips/mach-octeon/include/mach/cvmx-fpa3.h | 37 - .../include/mach/cvmx-helper-board.h | 6 +- .../include/mach/cvmx-helper-fdt.h | 40 +- .../include/mach/cvmx-helper-pko.h | 2 +- .../mach-octeon/include/mach/cvmx-helper.h | 20 + .../mach-octeon/include/mach/cvmx-ilk-defs.h | 2269 +++++++++++ .../mach-octeon/include/mach/cvmx-iob-defs.h | 1328 ++++++ .../mach-octeon/include/mach/cvmx-lbk-defs.h | 157 + .../mips/mach-octeon/include/mach/cvmx-mdio.h | 516 +++ .../mach-octeon/include/mach/cvmx-npei-defs.h | 3550 +++++++++++++++++ .../include/mach/cvmx-pcsxx-defs.h | 787 ++++ .../include/mach/cvmx-pki-cluster.h | 343 ++ arch/mips/mach-octeon/include/mach/cvmx-pko.h | 213 + .../include/mach/cvmx-pko3-resources.h | 36 + .../mips/mach-octeon/include/mach/cvmx-pko3.h | 1052 +++++ .../mach-octeon/include/mach/cvmx-range.h | 23 + .../mips/mach-octeon/include/mach/cvmx-regs.h | 100 +- .../mach-octeon/include/mach/cvmx-xcv-defs.h | 226 ++ .../mach-octeon/include/mach/octeon_eth.h | 54 +- board/Marvell/octeon_nic23/board.c | 87 +- configs/octeon_ebb7304_defconfig | 7 + configs/octeon_nic23_defconfig | 10 +- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/octeon/Makefile | 6 + drivers/net/octeon/octeon_eth.c | 1060 +++++ drivers/net/octeon/octeon_mdio.c | 226 ++ include/configs/octeon_common.h | 2 +- include/configs/octeon_ebb7304.h | 2 + 78 files changed, 33672 insertions(+), 2524 deletions(-)create mode 100644
arch/mips/mach-octeon/cvmx-agl.c
create mode 100644arch/mips/mach-octeon/cvmx-cmd-queue.ccreate mode 100644arch/mips/mach-octeon/cvmx-fau-compat.ccreate mode 100644arch/mips/mach-octeon/cvmx-fpa-resource.ccreate mode 100644arch/mips/mach-octeon/cvmx-fpa.c
create mode 100644arch/mips/mach-octeon/cvmx-global-resources.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-agl.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-bgx.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-board.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-fpa.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-ilk.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-ipd.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-loop.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-npi.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-pki.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-pko.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-pko3.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-rgmii.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-sfp.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-sgmii.ccreate mode 100644arch/mips/mach-octeon/cvmx-helper-xaui.ccreate mode 100644arch/mips/mach-octeon/cvmx-ilk.c
create mode 100644arch/mips/mach-octeon/cvmx-ipd.c
create mode 100644arch/mips/mach-octeon/cvmx-pki-resources.ccreate mode 100644arch/mips/mach-octeon/cvmx-pki.c
create mode 100644arch/mips/mach-octeon/cvmx-pko-internal-ports-range.ccreate mode 100644arch/mips/mach-octeon/cvmx-pko.c
create mode 100644arch/mips/mach-octeon/cvmx-pko3-compat.ccreate mode 100644arch/mips/mach-octeon/cvmx-pko3-queue.ccreate mode 100644arch/mips/mach-octeon/cvmx-pko3-resources.ccreate mode 100644arch/mips/mach-octeon/cvmx-pko3.c
create mode 100644arch/mips/mach-octeon/cvmx-qlm-tables.ccreate mode 100644arch/mips/mach-octeon/cvmx-range.c
create mode 100644arch/mips/mach-octeon/include/mach/cvmx-agl.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-config.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-fau.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-ilk-defs.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-iob-defs.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-lbk-defs.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-mdio.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-npei-defs.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-pcsxx-defs.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-pki-cluster.h
Quoted 9 lines
create mode 100644
arch/mips/mach-octeon/include/mach/cvmx-pko.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-pko3-resources.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-pko3.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-range.hcreate mode 100644arch/mips/mach-octeon/include/mach/cvmx-xcv-defs.hcreate mode 100644drivers/net/octeon/Makefile
create mode 100644drivers/net/octeon/octeon_eth.c
create mode 100644drivers/net/octeon/octeon_mdio.c
Applied to u-boot-marvell/master
Thanks,
Stefan